summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-user-type-hint.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ir-user-type-hint.cpp')
-rw-r--r--source/slang/slang-ir-user-type-hint.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/source/slang/slang-ir-user-type-hint.cpp b/source/slang/slang-ir-user-type-hint.cpp
new file mode 100644
index 000000000..3003d56f6
--- /dev/null
+++ b/source/slang/slang-ir-user-type-hint.cpp
@@ -0,0 +1,34 @@
+#include "slang-ir-user-type-hint.h"
+
+#include "slang-ir.h"
+#include "slang-ir-insts.h"
+#include "slang-ir-util.h"
+
+namespace Slang
+{
+
+void addUserTypeHintDecorations(IRModule* module)
+{
+ for (auto globalInst : module->getGlobalInsts())
+ {
+ auto inst = as<IRGlobalParam>(globalInst);
+ if (!inst)
+ continue;
+ if (inst->getDataType())
+ {
+ // Preserve the original type name as a decoration before we do any type lowering.
+ // This is needed to implement -fspv-reflect, which allows the compiler to output the
+ // original user-friendly type name of each shader parameter as a SPIRV decoration.
+ //
+ StringBuilder sb;
+ getTypeNameHint(sb, inst->getDataType());
+ if (sb.getLength())
+ {
+ IRBuilder builder(inst);
+ builder.addDecoration(inst, kIROp_UserTypeNameDecoration, builder.getStringValue(sb.produceString().getUnownedSlice()));
+ }
+ }
+ }
+}
+
+}