summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-hlsl.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-05-02 20:29:38 -0700
committerGitHub <noreply@github.com>2023-05-02 20:29:38 -0700
commitd52376a65f37fcbbb67428b917fd3819436b6dfb (patch)
treeda25b3c9a00bd003b1970b4a6c4eb38eccf62aa1 /source/slang/slang-emit-hlsl.cpp
parent55291b0bf6d729fcbaf75a01926da7da8975b8e9 (diff)
Various dxc/fxc compatibility fixes. (#2863)
* Various dxc/fxc compatibility fixes. * Cleanup. * Fix test cases. * Fix comments. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-emit-hlsl.cpp')
-rw-r--r--source/slang/slang-emit-hlsl.cpp49
1 files changed, 47 insertions, 2 deletions
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<IRStructType>(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<IRSemanticDecoration>())
{
@@ -997,6 +1007,33 @@ void HLSLSourceEmitter::emitSemanticsImpl(IRInst* inst)
m_writer->emit(semanticDecoration->getSemanticName());
return;
}
+ else if (auto packOffsetDecoration = inst->findDecoration<IRPackOffsetDecoration>())
+ {
+ 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<IRStageReadAccessDecoration>())
_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<IRMeshOutputDecoration>())