diff options
| author | Yong He <yonghe@outlook.com> | 2024-01-19 18:02:40 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-19 18:02:40 -0800 |
| commit | fdc17a974970559d8ff76d52c3ce40aaa056d441 (patch) | |
| tree | a7b2264776982707b36f901ac50acd4e047fd2bd /source/slang/slang-emit-spirv.cpp | |
| parent | 84b214389cacde9f3c94d61b3d4ca6a927cecd04 (diff) | |
Add `-fspv-reflect` support. (#3464)
* Add `-fspv-reflect` support.
Closes #3462.
* Fix.
* Fix.
* Remove use of `SPV_GOOGLE_hlsl_functionality1`.
* Fix spirv validation error.
* Fix test.
* Update typename hints.
* Update commandline options doc.
* Remove superfluous empty lines.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
| -rw-r--r-- | source/slang/slang-emit-spirv.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp index 07f8a4cd2..a600d4b10 100644 --- a/source/slang/slang-emit-spirv.cpp +++ b/source/slang/slang-emit-spirv.cpp @@ -1237,6 +1237,13 @@ struct SPIRVEmitContext Dictionary<SpvTypeInstKey, SpvInst*> m_spvTypeInsts; + bool shouldEmitSPIRVReflectionInfo() + { + if (!m_targetRequest->getHLSLToVulkanLayoutOptions()) + return false; + return m_targetRequest->getHLSLToVulkanLayoutOptions()->shouldEmitSPIRVReflectionInfo(); + } + // Next, let's look at emitting some of the instructions // that can occur at global scope. @@ -1958,6 +1965,7 @@ struct SPIRVEmitContext if (auto layout = getVarLayout(param)) emitVarLayout(param, varInst, layout); maybeEmitName(varInst, param); + emitDecorations(param, getID(varInst)); return varInst; } @@ -2833,6 +2841,42 @@ struct SPIRVEmitContext break; // ... } + + if (shouldEmitSPIRVReflectionInfo()) + { + switch (decoration->getOp()) + { + default: + break; + case kIROp_SemanticDecoration: + { + emitOpDecorateString(getSection(SpvLogicalSectionID::Annotations), + decoration, + dstID, + SpvDecorationUserSemantic, + cast<IRSemanticDecoration>(decoration)->getSemanticName()); + } + break; + case kIROp_UserTypeNameDecoration: + { + ensureExtensionDeclaration(toSlice("SPV_GOOGLE_user_type")); + emitOpDecorateString(getSection(SpvLogicalSectionID::Annotations), + decoration, + dstID, + SpvDecorationUserTypeGOOGLE, + cast<IRUserTypeNameDecoration>(decoration)->getUserTypeName()->getStringSlice()); + } + break; + case kIROp_CounterBufferDecoration: + { + emitOpDecorateCounterBuffer(getSection(SpvLogicalSectionID::Annotations), + decoration, + dstID, + as<IRCounterBufferDecoration>(decoration)->getCounterBuffer()); + } + break; + } + } } void emitLayoutDecorations(IRStructType* structType, SpvWord spvStructID) @@ -2948,6 +2992,19 @@ struct SPIRVEmitContext SpvLiteralInteger::from32(id), SpvLiteralInteger::from32((int32_t)matrixStride)); } + if (shouldEmitSPIRVReflectionInfo()) + { + if (auto semanticDecor = field->getKey()->findDecoration<IRSemanticDecoration>()) + { + emitOpMemberDecorateString( + getSection(SpvLogicalSectionID::Annotations), + nullptr, + spvStructID, + SpvLiteralInteger::from32(id), + SpvDecorationUserSemantic, + semanticDecor->getSemanticName()); + } + } id++; } } |
