summaryrefslogtreecommitdiff
path: root/source/slang/lower-to-ir.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-04-19 09:34:54 -0700
committerGitHub <noreply@github.com>2018-04-19 09:34:54 -0700
commitc68c6fa02690012f54928202811050cee649d81e (patch)
tree614447345c070429b1b2ea0c3639cdc4ffbf81a9 /source/slang/lower-to-ir.cpp
parent17fa424a195ed562e0c9d87cee57577c90c1fc37 (diff)
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.
Diffstat (limited to 'source/slang/lower-to-ir.cpp')
-rw-r--r--source/slang/lower-to-ir.cpp57
1 files changed, 41 insertions, 16 deletions
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 : ValVisitor<ValLoweringVisitor, LoweredValInfo, Lower
IRType* visitDeclRefType(DeclRefType* type)
{
+ auto declRef = type->declRef;
+ auto decl = declRef.getDecl();
+
+ // Check for types with teh `__intrinsic_type` modifier.
+ if(decl->FindModifier<IntrinsicTypeModifier>())
+ {
+ return lowerSimpleIntrinsicType(type);
+ }
+
+
return (IRType*) getSimpleVal(
context,
- emitDeclRef(context, type->declRef,
+ emitDeclRef(context, declRef,
context->irBuilder->getTypeKind()));
}
@@ -3500,6 +3510,12 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
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<DeclLoweringVisitor, LoweredValInfo>
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<TargetIntrinsicModifier>())
+ {
+ auto decoration = getBuilder()->addDecoration<IRTargetIntrinsicDecoration>(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<DeclLoweringVisitor, LoweredValInfo>
// If this declaration was marked as having a target-specific lowering
// for a particular target, then handle that here.
- for (auto targetMod : decl->GetModifiersOfType<TargetIntrinsicModifier>())
- {
- auto decoration = getBuilder()->addDecoration<IRTargetIntrinsicDecoration>(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