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)]". --- tests/bugs/gh-4395.slang | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/bugs/gh-4395.slang (limited to 'tests') diff --git a/tests/bugs/gh-4395.slang b/tests/bugs/gh-4395.slang new file mode 100644 index 000000000..2239fd9f4 --- /dev/null +++ b/tests/bugs/gh-4395.slang @@ -0,0 +1,88 @@ +//TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-dx12 -compute -output-using-type -use-dxil + +// Vulkan/GLSL doesn't support 1-dimensional matrix. +//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -compute -output-using-type -emit-spirv-via-glsl +//DISABLE_TEST(compute, vulkan):COMPARE_COMPUTE_EX(filecheck-buffer=CHK):-vk -compute -output-using-type -emit-spirv-directly + +//TEST_INPUT: ubuffer(data=[0.0 1.0 2.0 3.0], stride=4):name=inputBuffer +RWStructuredBuffer inputBuffer; + +//TEST_INPUT: ubuffer(data=[0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1,1,1)] +void computeMain() +{ + float v0 = inputBuffer[0]; + float v1 = inputBuffer[1]; + float v2 = inputBuffer[2]; + float v3 = inputBuffer[3]; + float result = 0.f; + + { + float1x1 a = v0; + float1x1 b = v1; + b += a; + result += b[0][0]; + + float1x1 c = v2; + float1x1 d = v3; + d -= c; + result += d[0][0]; + + float1x1 e = v0; + float1x1 f = v1; + f *= e; + result += f[0][0]; + + float1x1 g = v2; + float1x1 h = v3; + g /= h; + result += g[0][0]; + } + { + float1x2 a = float1x2(v0, v1); + float1x2 b = float1x2(v2, v3); + b += a; + result += b[0][0] + b[0][1]; + + float1x2 c = float1x2(v0, v1); + float1x2 d = float1x2(v2, v3); + d -= c; + result += d[0][0] + d[0][1]; + + float1x2 e = float1x2(v0, v1); + float1x2 f = float1x2(v2, v3); + f *= e; + result += f[0][0] + f[0][1]; + + float1x2 g = float1x2(v0, v1); + float1x2 h = float1x2(v2, v3); + g /= h; + result += g[0][0] + g[0][1]; + } + { + float2x1 a = float2x1(v0, v1); + float2x1 b = float2x1(v2, v3); + b += a; + result += b[0][0] + b[0][1]; + + float2x1 c = float2x1(v0, v1); + float2x1 d = float2x1(v2, v3); + d -= c; + result += d[0][0] + d[0][1]; + + float2x1 e = float2x1(v0, v1); + float2x1 f = float2x1(v2, v3); + f *= e; + result += f[0][0] + f[0][1]; + + float2x1 g = float2x1(v0, v1); + float2x1 h = float2x1(v2, v3); + g /= h; + result += g[0][0] + g[0][1]; + } + + //CHK:24 + outputBuffer[0] = int(result); +} -- cgit v1.2.3