diff options
| author | Yong He <yonghe@outlook.com> | 2023-08-14 16:23:19 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-14 16:23:19 -0700 |
| commit | 661d6198bbb9857d3fdc6df477e0742ed0b0765c (patch) | |
| tree | 974a57cfa2e43624e91502e9e652a0cc78105b3a /source/slang/slang-ir-specialize-matrix-layout.cpp | |
| parent | 0403e0556b470f6b316153caea2dc6f5c314da5b (diff) | |
Support per field matrix layout (#3101)
* Support per field matrix layout
* Fix warnings.
* Fix.
* Fix tests.
* Fix spiv gen.
* Fix.
* More test fixes.
* Fix.
* Run only GPU tests on self-hosted servers.
* Remove -use-glsl-matrix-layout-modifier.
* Fix.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-specialize-matrix-layout.cpp')
| -rw-r--r-- | source/slang/slang-ir-specialize-matrix-layout.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/source/slang/slang-ir-specialize-matrix-layout.cpp b/source/slang/slang-ir-specialize-matrix-layout.cpp new file mode 100644 index 000000000..5ce61f4cf --- /dev/null +++ b/source/slang/slang-ir-specialize-matrix-layout.cpp @@ -0,0 +1,46 @@ +#include "slang-ir-specialize-matrix-layout.h" +#include "slang-ir.h" +#include "slang-ir-insts.h" +#include "slang-compiler.h" + +namespace Slang +{ + + void visitParent(List<IRMatrixType*>& typeWorkList, IRInst* parent) + { + for (auto child : parent->getChildren()) + { + if (auto matrixType = as<IRMatrixType>(child)) + { + if (auto constLayout = as<IRIntLit>(matrixType->getLayout())) + { + if (constLayout->getValue() == SLANG_MATRIX_LAYOUT_MODE_UNKNOWN) + { + typeWorkList.add(matrixType); + } + } + } + visitParent(typeWorkList, child); + } + } + + void specializeMatrixLayout(TargetRequest* target, IRModule* module) + { + List<IRMatrixType*> typeWorkList; + visitParent(typeWorkList, module->getModuleInst()); + + IRIntegerValue defaultLayout = target->getDefaultMatrixLayoutMode(); + if (defaultLayout == SLANG_MATRIX_LAYOUT_MODE_UNKNOWN) + defaultLayout = SLANG_MATRIX_LAYOUT_ROW_MAJOR; + + IRBuilder builder(module); + for (auto matrixType : typeWorkList) + { + builder.setInsertBefore(matrixType); + auto replacementMatrixType = builder.getMatrixType(matrixType->getElementType(), matrixType->getRowCount(), matrixType->getColumnCount(), + builder.getIntValue(builder.getIntType(), defaultLayout)); + matrixType->replaceUsesWith(replacementMatrixType); + } + } + +} |
