diff options
| author | Jay Kwak <82421531+jkwak-work@users.noreply.github.com> | 2024-07-24 17:00:27 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-24 17:00:27 -0700 |
| commit | 7ea47f9a7cb2a6dd8f9b1da909ed8a2e98216438 (patch) | |
| tree | 64743277b1840caaf4fc7533ec2bbbec95342359 /source | |
| parent | efe110580343521ba6ff61ebb7d0db252598651d (diff) | |
Support 1-dimensional matrix for HLSL (#4728)
Closes #4395
This commit allows Slang to use 1-dimensional matrix when targetting
HLSL. The 1-dimensional matrix is supported by DXC natively.
GLSL/Vulkan doesn't support the 1-dimensional matrix natively. It is
not trivial for Slang to convert all of matrix functions to vector or
scalar at the emitting step. We can implement this later if there are
needs. This commit disallows the use of 1-dimensional matrix for
targetting GLSL/Vulkan by the capability system; in other words, the
new 1-dimentional functions have "[require(hlsl)]".
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/core.meta.slang | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/source/slang/core.meta.slang b/source/slang/core.meta.slang index 30513074b..2da0fa523 100644 --- a/source/slang/core.meta.slang +++ b/source/slang/core.meta.slang @@ -1275,8 +1275,8 @@ for (int tt = 0; tt < kTypeCount; ++tt) } // Declare HLSL matrix types - for (int rr = 2; rr <= 4; ++rr) - for (int cc = 2; cc <= 4; ++cc) + for (int rr = 1; rr <= 4; ++rr) + for (int cc = 1; cc <= 4; ++cc) { sb << "typedef matrix<" << kTypes[tt].name << "," << rr << "," << cc << "> " << kTypes[tt].name << rr << "x" << cc << ";\n"; } @@ -1461,12 +1461,14 @@ for (int tt = 0; tt < kBaseTypeCount; ++tt) sb << "}\n"; } -for( int R = 2; R <= 4; ++R ) -for( int C = 2; C <= 4; ++C ) +for( int R = 1; R <= 4; ++R ) +for( int C = 1; C <= 4; ++C ) { sb << "__generic<T, let L:int> __extension matrix<T, " << R << "," << C << ", L>\n{\n"; // initialize from R*C scalars + if (R == 1 || C == 1) + sb << "[require(hlsl)]\n"; sb << "__intrinsic_op(" << int(kIROp_MakeMatrix) << ") __init("; for( int ii = 0; ii < R; ++ii ) for( int jj = 0; jj < C; ++jj ) @@ -1477,6 +1479,8 @@ for( int C = 2; C <= 4; ++C ) sb << ");\n"; // Initialize from R C-vectors + if (R == 1 || C == 1) + sb << "[require(hlsl)]\n"; sb << "__intrinsic_op(" << int(kIROp_MakeMatrix) << ") __init("; for (int ii = 0; ii < R; ++ii) { @@ -1490,6 +1494,8 @@ for( int C = 2; C <= 4; ++C ) for( int cc = C; cc <= 4; ++cc ) { if(rr == R && cc == C) continue; + if (R == 1 || C == 1) + sb << "[require(hlsl)]\n"; sb << "__intrinsic_op(" << int(kIROp_MatrixReshape) << ") __init(matrix<T," << rr << "," << cc << ", L> value);\n"; } |
