summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-hlsl.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-01-07 22:26:31 -0800
committerGitHub <noreply@github.com>2025-01-07 22:26:31 -0800
commitc43f6fa55aca23365c86c6ec1737d42be74d9d3e (patch)
tree2c49bc1dbd12ae5f46d682a3f240465931471060 /source/slang/slang-emit-hlsl.cpp
parent1a56f58fdd0c704e6dc0fad0f0ec33a25a35e60b (diff)
Lower varying parameters as pointers instead of SSA values. (#5919)
* Add executable test on matrix-typed vertex input. * Fix emit logic of matrix layout qualifier. * Pass fragment shader varying input by constref to allow EvaluateAttributeAtCentroid etc. to be implemented correctly.
Diffstat (limited to 'source/slang/slang-emit-hlsl.cpp')
-rw-r--r--source/slang/slang-emit-hlsl.cpp55
1 files changed, 33 insertions, 22 deletions
diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp
index 40d6f75d9..83eec17b4 100644
--- a/source/slang/slang-emit-hlsl.cpp
+++ b/source/slang/slang-emit-hlsl.cpp
@@ -1180,6 +1180,34 @@ void HLSLSourceEmitter::emitSimpleValueImpl(IRInst* inst)
Super::emitSimpleValueImpl(inst);
}
+void HLSLSourceEmitter::emitSimpleTypeAndDeclaratorImpl(IRType* type, DeclaratorInfo* declarator)
+{
+ if (declarator)
+ {
+ // HLSL only allow matrix layout modifier when declaring a variable or struct field.
+ if (auto matType = as<IRMatrixType>(type))
+ {
+ auto matrixLayout = getIntVal(matType->getLayout());
+ if (getTargetProgram()->getOptionSet().getMatrixLayoutMode() !=
+ (MatrixLayoutMode)matrixLayout)
+ {
+ switch (matrixLayout)
+ {
+ case SLANG_MATRIX_LAYOUT_COLUMN_MAJOR:
+ m_writer->emit("column_major ");
+ break;
+ case SLANG_MATRIX_LAYOUT_ROW_MAJOR:
+ m_writer->emit("row_major ");
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ Super::emitSimpleTypeAndDeclaratorImpl(type, declarator);
+}
+
void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type)
{
switch (type->getOp())
@@ -1313,6 +1341,11 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type)
emitSimpleTypeImpl(cast<IRAtomicType>(type)->getElementType());
return;
}
+ case kIROp_ConstRefType:
+ {
+ emitSimpleTypeImpl(as<IRConstRefType>(type)->getValueType());
+ return;
+ }
default:
break;
}
@@ -1671,28 +1704,6 @@ void HLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl)
}
}
-void HLSLSourceEmitter::emitMatrixLayoutModifiersImpl(IRType* type)
-{
- auto matType = as<IRMatrixType>(type);
- if (!matType)
- return;
- auto matrixLayout = getIntVal(matType->getLayout());
- if (getTargetProgram()->getOptionSet().getMatrixLayoutMode() != (MatrixLayoutMode)matrixLayout)
- {
- switch (matrixLayout)
- {
- case SLANG_MATRIX_LAYOUT_COLUMN_MAJOR:
- m_writer->emit("column_major ");
- break;
- case SLANG_MATRIX_LAYOUT_ROW_MAJOR:
- m_writer->emit("row_major ");
- break;
- default:
- break;
- }
- }
-}
-
void HLSLSourceEmitter::handleRequiredCapabilitiesImpl(IRInst* inst)
{
if (inst->findDecoration<IRRequiresNVAPIDecoration>())