From c68c6fa02690012f54928202811050cee649d81e Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 19 Apr 2018 09:34:54 -0700 Subject: Fix up DXR type emission from IR type system (#498) * There was a simple typo where we were emitting `RaytracingAccelerationStructureType` instead of `RaytracingAccelerationStructure` * The IR lowering logic was failing to handle types with an `__intrinsic_type` modifier (which maps them to a single IR opcode) that weren't in one of the various special cases. I added a catch-all case to the handling of `DeclRefType`. This notably affected the `RayDesc` type. * Even if we lower `RayDesc` to an intrinsic type, we still need to lower its *fields* too, and these were getting emitted with mangled names (as would happen for any user-defined fields). The solution I implemented was to allow for fields to have `__target_intrinsic` modifiers in the stdlib, to specify the un-mangled name they should use on each target. I'm not 100% happy with this solution, because it seems odd to have `RayDesc` be an intrinsic type, but then to also have field keys used in `getField` instructions as if it were an ordinary `struct`. It seems like a better solution would be to have it lower to an IR `struct`, just with an appropriate modifier. --- source/slang/lower-to-ir.cpp | 57 +++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 16 deletions(-) (limited to 'source/slang/lower-to-ir.cpp') diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp index 3953490fe..e5cf19a10 100644 --- a/source/slang/lower-to-ir.cpp +++ b/source/slang/lower-to-ir.cpp @@ -1030,9 +1030,19 @@ struct ValLoweringVisitor : ValVisitordeclRef; + auto decl = declRef.getDecl(); + + // Check for types with teh `__intrinsic_type` modifier. + if(decl->FindModifier()) + { + return lowerSimpleIntrinsicType(type); + } + + return (IRType*) getSimpleVal( context, - emitDeclRef(context, type->declRef, + emitDeclRef(context, declRef, context->irBuilder->getTypeKind())); } @@ -3500,6 +3510,12 @@ struct DeclLoweringVisitor : DeclVisitor semanticDecoration->semanticName = semanticModifier->name.getName(); } + // We allow a field to be marked as a target intrinsic, + // so that we can override its mangled name in the + // output for the chosen target. + addTargetIntrinsicDecorations(irFieldKey, fieldDecl); + + return LoweredValInfo::simple(irFieldKey); } @@ -3967,6 +3983,29 @@ struct DeclLoweringVisitor : DeclVisitor return v; } + // Attach target-intrinsic decorations to an instruction, + // based on modifiers on an AST declaration. + void addTargetIntrinsicDecorations( + IRInst* irInst, + Decl* decl) + { + for (auto targetMod : decl->GetModifiersOfType()) + { + auto decoration = getBuilder()->addDecoration(irInst); + decoration->targetName = targetMod->targetToken.Content; + + auto definitionToken = targetMod->definitionToken; + if (definitionToken.type == TokenType::StringLiteral) + { + decoration->definition = getStringLiteralTokenValue(definitionToken); + } + else + { + decoration->definition = definitionToken.Content; + } + } + } + LoweredValInfo lowerFuncDecl(FunctionDeclBase* decl) { // We are going to use a nested builder, because we will @@ -4259,21 +4298,7 @@ struct DeclLoweringVisitor : DeclVisitor // If this declaration was marked as having a target-specific lowering // for a particular target, then handle that here. - for (auto targetMod : decl->GetModifiersOfType()) - { - auto decoration = getBuilder()->addDecoration(irFunc); - decoration->targetName = targetMod->targetToken.Content; - - auto definitionToken = targetMod->definitionToken; - if (definitionToken.type == TokenType::StringLiteral) - { - decoration->definition = getStringLiteralTokenValue(definitionToken); - } - else - { - decoration->definition = definitionToken.Content; - } - } + addTargetIntrinsicDecorations(irFunc, decl); // For convenience, ensure that any additional global // values that were emitted while outputting the function -- cgit v1.2.3