diff options
| author | Yong He <yonghe@outlook.com> | 2024-09-05 10:26:59 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-05 10:26:59 -0700 |
| commit | a88055c6f5190ca62bb4aa853b4f0fa11546278f (patch) | |
| tree | 0f4a417153110d43cf361c0abe29c8996b806f3c /source/slang/slang-emit-hlsl.cpp | |
| parent | 959f55de964ff108947db72a3f8d25b39995f2c8 (diff) | |
Respect matrix layout in uniform and in/out parameters for HLSL target. (#5013)
* Respect matrix layout in uniform and in/out parameters for HLSL target.
* Update test.
* Fix test.
* fix test.
* Fix metal layout calculation.
* Fix compile error.
* Fix compiler error.
---------
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.cpp | 71 |
1 files changed, 46 insertions, 25 deletions
diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index a867d4c06..f9765a555 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -959,15 +959,37 @@ void HLSLSourceEmitter::emitSimpleTypeImpl(IRType* type) case kIROp_MatrixType: { auto matType = (IRMatrixType*)type; - - // TODO(tfoley): should really emit these with sugar - m_writer->emit("matrix<"); - emitType(matType->getElementType()); - m_writer->emit(","); - emitVal(matType->getRowCount(), getInfo(EmitOp::General)); - m_writer->emit(","); - emitVal(matType->getColumnCount(), getInfo(EmitOp::General)); - m_writer->emit("> "); + bool canUseSugar = true; + switch (matType->getElementType()->getOp()) + { + case kIROp_IntType: + case kIROp_UIntType: + case kIROp_FloatType: + canUseSugar = true; + break; + default: + canUseSugar = false; + break; + } + if (!as<IRIntLit>(matType->getRowCount()) || !as<IRIntLit>(matType->getColumnCount())) + canUseSugar = false; + if (canUseSugar) + { + emitType(matType->getElementType()); + m_writer->emitInt64(getIntVal(matType->getRowCount())); + m_writer->emit("x"); + m_writer->emitInt64(getIntVal(matType->getColumnCount())); + } + else + { + m_writer->emit("matrix<"); + emitType(matType->getElementType()); + m_writer->emit(","); + emitVal(matType->getRowCount(), getInfo(EmitOp::General)); + m_writer->emit(","); + emitVal(matType->getColumnCount(), getInfo(EmitOp::General)); + m_writer->emit("> "); + } return; } case kIROp_SamplerStateType: @@ -1306,25 +1328,24 @@ void HLSLSourceEmitter::emitVarDecorationsImpl(IRInst* varDecl) } } -void HLSLSourceEmitter::emitMatrixLayoutModifiersImpl(IRVarLayout* layout) +void HLSLSourceEmitter::emitMatrixLayoutModifiersImpl(IRType* type) { - // When a variable has a matrix type, we want to emit an explicit - // layout qualifier based on what the layout has been computed to be. - // - - auto typeLayout = layout->getTypeLayout()->unwrapArray(); - - if (auto matrixTypeLayout = as<IRMatrixTypeLayout>(typeLayout)) + auto matType = as<IRMatrixType>(type); + if (!matType) + return; + auto matrixLayout = getIntVal(matType->getLayout()); + if (getTargetProgram()->getOptionSet().getMatrixLayoutMode() != (MatrixLayoutMode)matrixLayout) { - switch (matrixTypeLayout->getMode()) + switch (matrixLayout) { - case kMatrixLayoutMode_ColumnMajor: - m_writer->emit("column_major "); - break; - - case kMatrixLayoutMode_RowMajor: - m_writer->emit("row_major "); - break; + 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; } } } |
