diff options
| author | Yong He <yonghe@outlook.com> | 2024-03-23 10:54:01 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-23 10:54:01 -0700 |
| commit | a23adc221b1ea26db3f3313226b629eb9e308b0f (patch) | |
| tree | 6f758d64201f2c606dc3e61394899bff4fa72f51 /source/slang/slang-emit-hlsl.cpp | |
| parent | 9b0df14cdf9d9ea8857b5b9d59505b18020f8414 (diff) | |
Make `-no-mangle` option work, add `-no-hlsl-binding`. (#3817)
Diffstat (limited to 'source/slang/slang-emit-hlsl.cpp')
| -rw-r--r-- | source/slang/slang-emit-hlsl.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 3d45394d3..92866f9c4 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -37,7 +37,7 @@ void HLSLSourceEmitter::_emitHLSLDecorationSingleInt(const char* name, IRFunc* e m_writer->emit(")]\n"); } -void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitVarChain* chain, char const* uniformSemanticSpelling) +void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitVarChain* chain, IRInst* inst, char const* uniformSemanticSpelling) { if (!chain) return; @@ -100,6 +100,16 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitV break; default: { + if (m_codeGenContext->getTargetProgram()->getOptionSet().getBoolOption(CompilerOptionName::NoHLSLBinding)) + { + // If we are told not to emit hlsl binding, and the user has not provided explicit binding, + // then skip emitting the `: register` semantics here. + // + if (!inst || !inst->findDecoration<IRHasExplicitHLSLBindingDecoration>()) + { + break; + } + } m_writer->emit(" : register("); switch (kind) { @@ -130,7 +140,7 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantic(LayoutResourceKind kind, EmitV } } -void HLSLSourceEmitter::_emitHLSLRegisterSemantics(EmitVarChain* chain, char const* uniformSemanticSpelling) +void HLSLSourceEmitter::_emitHLSLRegisterSemantics(EmitVarChain* chain, IRInst* inst, char const* uniformSemanticSpelling) { if (!chain) return; @@ -147,17 +157,17 @@ void HLSLSourceEmitter::_emitHLSLRegisterSemantics(EmitVarChain* chain, char con for (auto rr : layout->getOffsetAttrs()) { - _emitHLSLRegisterSemantic(rr->getResourceKind(), chain, uniformSemanticSpelling); + _emitHLSLRegisterSemantic(rr->getResourceKind(), chain, inst, uniformSemanticSpelling); } } -void HLSLSourceEmitter::_emitHLSLRegisterSemantics(IRVarLayout* varLayout, char const* uniformSemanticSpelling) +void HLSLSourceEmitter::_emitHLSLRegisterSemantics(IRVarLayout* varLayout, IRInst* inst, char const* uniformSemanticSpelling) { if (!varLayout) return; EmitVarChain chain(varLayout); - _emitHLSLRegisterSemantics(&chain, uniformSemanticSpelling); + _emitHLSLRegisterSemantics(&chain, inst, uniformSemanticSpelling); } void HLSLSourceEmitter::_emitHLSLParameterGroupFieldLayoutSemantics(EmitVarChain* chain) @@ -168,7 +178,7 @@ void HLSLSourceEmitter::_emitHLSLParameterGroupFieldLayoutSemantics(EmitVarChain auto layout = chain->varLayout; for (auto rr : layout->getOffsetAttrs()) { - _emitHLSLRegisterSemantic(rr->getResourceKind(), chain, "packoffset"); + _emitHLSLRegisterSemantic(rr->getResourceKind(), chain, nullptr, "packoffset"); } } @@ -207,7 +217,7 @@ void HLSLSourceEmitter::_emitHLSLParameterGroup(IRGlobalParam* varDecl, IRUnifor typeLayout = parameterGroupTypeLayout->getElementVarLayout()->getTypeLayout(); } - _emitHLSLRegisterSemantic(LayoutResourceKind::ConstantBuffer, &containerChain); + _emitHLSLRegisterSemantic(LayoutResourceKind::ConstantBuffer, &containerChain, varDecl); auto elementType = type->getElementType(); if (hasExplicitConstantBufferOffset(type)) @@ -299,7 +309,7 @@ void HLSLSourceEmitter::emitLayoutSemanticsImpl(IRInst* inst, char const* unifor auto layout = getVarLayout(inst); if (layout) { - _emitHLSLRegisterSemantics(layout, uniformSemanticSpelling); + _emitHLSLRegisterSemantics(layout, inst, uniformSemanticSpelling); } } |
