From a23adc221b1ea26db3f3313226b629eb9e308b0f Mon Sep 17 00:00:00 2001 From: Yong He Date: Sat, 23 Mar 2024 10:54:01 -0700 Subject: Make `-no-mangle` option work, add `-no-hlsl-binding`. (#3817) --- source/slang/slang-emit-hlsl.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'source/slang/slang-emit-hlsl.cpp') 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()) + { + 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); } } -- cgit v1.2.3