From d52376a65f37fcbbb67428b917fd3819436b6dfb Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 2 May 2023 20:29:38 -0700 Subject: Various dxc/fxc compatibility fixes. (#2863) * Various dxc/fxc compatibility fixes. * Cleanup. * Fix test cases. * Fix comments. --------- Co-authored-by: Yong He --- source/slang/slang-emit-hlsl.cpp | 49 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 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 e07d9facc..434f0803e 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -208,10 +208,20 @@ void HLSLSourceEmitter::_emitHLSLParameterGroup(IRGlobalParam* varDecl, IRUnifor _emitHLSLRegisterSemantic(LayoutResourceKind::ConstantBuffer, &containerChain); + auto elementType = type->getElementType(); + if (hasExplicitConstantBufferOffset(type)) + { + // If the user has provided any explicit `packoffset` modifiers, + // we have to unwrap the struct and emit the fields directly. + emitStructDeclarationsBlock(as(elementType), true); + m_writer->emit("\n"); + return; + } + + m_writer->emit("\n{\n"); m_writer->indent(); - auto elementType = type->getElementType(); emitType(elementType, getName(varDecl)); m_writer->emit(";\n"); @@ -989,7 +999,7 @@ void HLSLSourceEmitter::emitRateQualifiersImpl(IRRate* rate) } } -void HLSLSourceEmitter::emitSemanticsImpl(IRInst* inst) +void HLSLSourceEmitter::emitSemanticsImpl(IRInst* inst, bool allowOffsets) { if (auto semanticDecoration = inst->findDecoration()) { @@ -997,6 +1007,33 @@ void HLSLSourceEmitter::emitSemanticsImpl(IRInst* inst) m_writer->emit(semanticDecoration->getSemanticName()); return; } + else if (auto packOffsetDecoration = inst->findDecoration()) + { + if (allowOffsets) + { + m_writer->emit(" : packoffset(c"); + m_writer->emit(packOffsetDecoration->getRegisterOffset()->getValue()); + if (packOffsetDecoration->getComponentOffset()) + { + switch (packOffsetDecoration->getComponentOffset()->getValue()) + { + case 0: + break; + case 1: + m_writer->emit(".y"); + break; + case 2: + m_writer->emit(".z"); + break; + case 3: + m_writer->emit(".w"); + break; + } + } + m_writer->emit(")"); + return; + } + } if( auto readAccessSemantic = inst->findDecoration()) _emitStageAccessSemantic(readAccessSemantic, "read"); @@ -1114,6 +1151,14 @@ void HLSLSourceEmitter::emitInterpolationModifiersImpl(IRInst* varInst, IRType* } } +void HLSLSourceEmitter::emitPackOffsetModifier(IRInst* varInst, IRType* valueType, IRPackOffsetDecoration* layout) +{ + SLANG_UNUSED(varInst); + SLANG_UNUSED(valueType); + SLANG_UNUSED(layout); + // We emit packoffset as a semantic in `emitSemantic`, so nothing to do here. +} + void HLSLSourceEmitter::emitMeshOutputModifiersImpl(IRInst* varInst) { if(auto modifier = varInst->findDecoration()) -- cgit v1.2.3