From 661d6198bbb9857d3fdc6df477e0742ed0b0765c Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 14 Aug 2023 16:23:19 -0700 Subject: 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 --- source/slang/slang-ir-specialize-matrix-layout.cpp | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 source/slang/slang-ir-specialize-matrix-layout.cpp (limited to 'source/slang/slang-ir-specialize-matrix-layout.cpp') 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& typeWorkList, IRInst* parent) + { + for (auto child : parent->getChildren()) + { + if (auto matrixType = as(child)) + { + if (auto constLayout = as(matrixType->getLayout())) + { + if (constLayout->getValue() == SLANG_MATRIX_LAYOUT_MODE_UNKNOWN) + { + typeWorkList.add(matrixType); + } + } + } + visitParent(typeWorkList, child); + } + } + + void specializeMatrixLayout(TargetRequest* target, IRModule* module) + { + List 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); + } + } + +} -- cgit v1.2.3