diff options
| author | Yong He <yonghe@outlook.com> | 2024-03-12 13:47:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-12 13:47:14 -0700 |
| commit | edc85fc4631782d42e113f00dfbbd113dcd8c96f (patch) | |
| tree | 8d6ce10d7ea4d62633d9ce74d78ae2d41578fffb /source/slang/slang-ir-user-type-hint.cpp | |
| parent | 8b5196033ae5e8113e6d06cb64c7cbe570496c51 (diff) | |
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`.
Diffstat (limited to 'source/slang/slang-ir-user-type-hint.cpp')
| -rw-r--r-- | source/slang/slang-ir-user-type-hint.cpp | 34 |
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())); + } + } + } +} + +} |
