From edc85fc4631782d42e113f00dfbbd113dcd8c96f Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 12 Mar 2024 13:47:14 -0700 Subject: Make type names spec-conformant in SPIRV reflect. (#3748) * Preserve ByteAddressBuffer user type name. * Make user type lowercase. * Make typenames conform to spec. * Use `SpvOpDecorateString`. --- source/slang/slang-ir-user-type-hint.cpp | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 source/slang/slang-ir-user-type-hint.cpp (limited to 'source/slang/slang-ir-user-type-hint.cpp') 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(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())); + } + } + } +} + +} -- cgit v1.2.3