From 7ea47f9a7cb2a6dd8f9b1da909ed8a2e98216438 Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Wed, 24 Jul 2024 17:00:27 -0700 Subject: 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)]". --- source/slang/core.meta.slang | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'source') 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 __extension matrix\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 value);\n"; } -- cgit v1.2.3