From 92ee2927d0012dd454dff7bb53b900f5240073d5 Mon Sep 17 00:00:00 2001 From: venkataram-nv Date: Wed, 30 Jul 2025 09:27:38 -0700 Subject: Lowering unsupported matrix types for GLSL/WGSL/Metal targets (#7936) * Add emit cases for WGSL and GLSL * Fix compilation warnings Modify short cutting test to reflect change in emit logic Lower matrix for metal as well Add emit matrix logic for metal Fix compiler warning Brace initializer for lowered matrices Fix compiler warnings * Tests for metal * Fix mult, any, and determinant * Fix matrix-matrix multiplication * Fix mat mul to be element-wise * Fix compiler warning * Move makeMatrix to legalization * Move unary and binary arithmetic operator lowering to legalization * Remove emit logic and move final comparison operators to legalization * Handle vector/matrix negation for WGSL * Restore older SPIR-V emit logic * Address PR comments * Revert to zero minus for negation * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- tests/spirv/matrix-bool-lowering.slang | 2 +- tests/spirv/matrix-integer-lowering.slang | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'tests/spirv') diff --git a/tests/spirv/matrix-bool-lowering.slang b/tests/spirv/matrix-bool-lowering.slang index 63b7caacf..f903fbf17 100644 --- a/tests/spirv/matrix-bool-lowering.slang +++ b/tests/spirv/matrix-bool-lowering.slang @@ -1,6 +1,6 @@ //TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=CHECK):-slang -compute -vk -shaderobj -xslang -emit-spirv-directly -//TEST_INPUT:ubuffer(data=[1 0], stride=4):in,name inputBuffer +//TEST_INPUT:ubuffer(data=[1 0], stride=4):name inputBuffer //TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer RWStructuredBuffer inputBuffer; RWStructuredBuffer outputBuffer; diff --git a/tests/spirv/matrix-integer-lowering.slang b/tests/spirv/matrix-integer-lowering.slang index 518d0f78b..fded652a4 100644 --- a/tests/spirv/matrix-integer-lowering.slang +++ b/tests/spirv/matrix-integer-lowering.slang @@ -10,8 +10,10 @@ typealias m2x3 = matrix; typealias m3x3 = matrix; typealias m2x4 = matrix; -//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer +//TEST_INPUT:ubuffer(data=[-1 4], stride=4):name expectedBuffer RWStructuredBuffer outputBuffer; +RWStructuredBuffer expectedBuffer; struct matrixWrapper { m2x2 mat1 = m2x2(1, 2, 3, 4); @@ -103,6 +105,10 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) matrix equal_to = comp_mat1 == comp_mat2; matrix not_equal = comp_mat1 != comp_mat2; + // Test matrix negation operations + m2x2 neg_mat = m2x2(1, -2, 3, -4); + m2x2 negated = -neg_mat; + // Store results outputBuffer[0] = val1; // CHECK: 1 @@ -186,4 +192,8 @@ void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) // CHECK-NEXT: 0 outputBuffer[37] = TYPE(not_equal[0][0]); // CHECK-NEXT: 1 + outputBuffer[38] = TYPE(negated[0][0] == expectedBuffer[0]); + // CHECK-NEXT: 1 + outputBuffer[39] = TYPE(negated[1][1] == expectedBuffer[1]); + // CHECK-NEXT: 1 } \ No newline at end of file -- cgit v1.2.3