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-emit-spirv.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-emit-spirv.cpp')
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 252f0e917..79f324988 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -2919,6 +2919,24 @@ struct SPIRVEmitContext } } + // Make user type name conform to `SPV_GOOGLE_user_type` spec. + // https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/GOOGLE/SPV_GOOGLE_user_type.asciidoc + String legalizeUserTypeName(UnownedStringSlice typeName) + { + String result = typeName; + auto index = typeName.indexOf('<'); + if (index == -1) + index = typeName.getLength(); + StringBuilder sb; + sb << String(typeName.head(index)).toLower(); + if (index != typeName.getLength()) + { + sb << ":"; + sb << typeName.tail(index); + } + return sb.produceString(); + } + /// Emit an appropriate SPIR-V decoration for the given IR `decoration`, if necessary and possible. /// /// The given `dstID` should be the `<id>` of the SPIR-V instruction being decorated, @@ -3246,7 +3264,7 @@ struct SPIRVEmitContext decoration, dstID, SpvDecorationUserTypeGOOGLE, - cast<IRUserTypeNameDecoration>(decoration)->getUserTypeName()->getStringSlice()); + legalizeUserTypeName(cast<IRUserTypeNameDecoration>(decoration)->getUserTypeName()->getStringSlice()).getUnownedSlice()); } break; case kIROp_CounterBufferDecoration: |
