summaryrefslogtreecommitdiff
path: root/source/slang/lower-to-ir.cpp
diff options
context:
space:
mode:
authorTim Foley <tfoleyNV@users.noreply.github.com>2018-02-07 13:41:43 -0800
committerGitHub <noreply@github.com>2018-02-07 13:41:43 -0800
commit1fbc73d96fbc0a199d823dfb38fc8f02bf7ada0a (patch)
treeb4d894f1179a66219631539a95e422ba62988b04 /source/slang/lower-to-ir.cpp
parent662f43fff6721c6cd013a8f1b2639c2e29fe6be3 (diff)
Support __target_intrinsic modifiers in IR codegen (#401)
The standard library already has a bunch of these decorations, since they were added to support Slang->Vulkan codegen on the AST-to-AST path. This change makes the IR code generator able to exploit the modifiers so that we pick up a bunch of Vulkan support "for free" in the short term. The basic change is in `lower-to-ir.cpp` where we copy over any `TargetIntrinsicModifier`s to become `IRTargetIntrinsicDecoration`s with the same information. We then need a bit of logic in `ir.cpp` to make sure we clone them as needed. The core work of using the modifiers is in `emit.cpp`, where I basically just copy-pasted the existing logic that applied in the AST path (all the AST-related code there is dead, and we should clean it up soon). The big change that comes with this logic is that when dealing with a member function, the numbering of the argument used in the intrinsic definition string changes, so that `$0` refers to the base object (whereas before the base object was looked up via the base expression of a `MemberExpr` used for the function). This requires a bunch of the definitions in the library to be updated; hopefully I caught them all. For kicks, I've re-enabled a cross-compilation test just to confirm that we are generating valid SPIR-V for code that performs texture-fetch operations. I don't expect us to keep that test enabled as-is in the long term, though, because it would be much better to instead use render-test to do the same thing. Alas, beefing up the Vulkan support in render-test is an outstanding work item, and I didn't want to pollute this change with more work along those lines.
Diffstat (limited to 'source/slang/lower-to-ir.cpp')
-rw-r--r--source/slang/lower-to-ir.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/source/slang/lower-to-ir.cpp b/source/slang/lower-to-ir.cpp
index 4eb762333..bde50aa89 100644
--- a/source/slang/lower-to-ir.cpp
+++ b/source/slang/lower-to-ir.cpp
@@ -3757,6 +3757,24 @@ struct DeclLoweringVisitor : DeclVisitor<DeclLoweringVisitor, LoweredValInfo>
decoration->targetName = targetMod->targetToken.Content;
}
+ // 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;
+ }
+ }
+
// For convenience, ensure that any additional global
// values that were emitted while outputting the function
// body appear before the function itself in the list