diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2023-04-13 23:49:00 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-13 08:49:00 -0700 |
| commit | c7e5601bb67d2a5ebadb7f84c6968b5912e7566d (patch) | |
| tree | 311903d485d42617288198ea45f46c50e150f082 /tests/language-feature | |
| parent | 6fbd892a0e015fd07d1c41983676713aa6f09333 (diff) | |
Matrix swizzle writes (#2713)
* Add a bunch of builder emit wrappers for constant indices
To avoid cluttering any calling code with int instruction construction
* Matrix swizzle stores
Closes https://github.com/shader-slang/slang/issues/2512
* Matrix swizzle store tests
* Squash vs warnings
* Select scalar for singular swizzles
* Test singular swizzle materialization
* Use IRIntegerValue over UInt for IR wrappers
* Correct size of swizzle vector type
* Remove variable shadowing
Diffstat (limited to 'tests/language-feature')
8 files changed, 123 insertions, 0 deletions
diff --git a/tests/language-feature/swizzles/matrix-swizzle-write-array.slang b/tests/language-feature/swizzles/matrix-swizzle-write-array.slang new file mode 100644 index 000000000..7d266b8cd --- /dev/null +++ b/tests/language-feature/swizzles/matrix-swizzle-write-array.slang @@ -0,0 +1,36 @@ +//TEST(compute):COMPARE_COMPUTE: -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE: -vk -compute -shaderobj -output-using-type + +// Test that matrix swizzle writes work correctly +// Matrix swizzles can either be one or zero indexed +// Reference: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-per-component-math + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float2x2> outputBuffer; + +struct MySubscriptable +{ + float2x2 m; + __subscript() -> float2x2 + { + get { return m; } + set { m = newValue; } + } +}; + +[numthreads(1, 1, 1)] +void computeMain(uint tid : SV_GroupIndex) +{ + MySubscriptable s; + s.m = float2x2(0,0,0,0); + + // _ 1 + // 4 5 + s[]._12_21_22 = float3(1, 4, 5); + + // 2 1 + // 4 3 + s[]._m00_m11 = float2(2, 3); + + outputBuffer[tid] = s.m; +} diff --git a/tests/language-feature/swizzles/matrix-swizzle-write-array.slang.expected.txt b/tests/language-feature/swizzles/matrix-swizzle-write-array.slang.expected.txt new file mode 100644 index 000000000..089d975fe --- /dev/null +++ b/tests/language-feature/swizzles/matrix-swizzle-write-array.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +2.000000 +1.000000 +4.000000 +3.000000 diff --git a/tests/language-feature/swizzles/matrix-swizzle-write-single.slang b/tests/language-feature/swizzles/matrix-swizzle-write-single.slang new file mode 100644 index 000000000..e622d216c --- /dev/null +++ b/tests/language-feature/swizzles/matrix-swizzle-write-single.slang @@ -0,0 +1,21 @@ +//TEST(compute):COMPARE_COMPUTE: -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE: -vk -compute -shaderobj -output-using-type + +// Test that writes to single matrix elements with swizzles work + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint tid : SV_GroupIndex) +{ + // 0 0 + // 0 0 + float2x2 m = float2x2(0); + + // 0 2 + // 0 0 + const float x = m._m01 = 2; + + outputBuffer[tid] = x + m[tid/2][tid%2]; +} diff --git a/tests/language-feature/swizzles/matrix-swizzle-write-single.slang.expected.txt b/tests/language-feature/swizzles/matrix-swizzle-write-single.slang.expected.txt new file mode 100644 index 000000000..16af82e12 --- /dev/null +++ b/tests/language-feature/swizzles/matrix-swizzle-write-single.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +2.000000 +4.000000 +2.000000 +2.000000 diff --git a/tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang b/tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang new file mode 100644 index 000000000..a0d267c7a --- /dev/null +++ b/tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang @@ -0,0 +1,19 @@ +//TEST(compute):COMPARE_COMPUTE: -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE: -vk -compute -shaderobj -output-using-type + +// Test that writing to swizzles of matrix swizzles works correctly + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint tid : SV_GroupIndex) +{ + float2x2 m = float2x2(0); + + // 1 4 + // 3 2 + m._m00_m01_m10_m11.xwzy.wzyx.wzyx = float4(1,2,3,4); + + outputBuffer[tid] = m[tid/2][tid%2]; +} diff --git a/tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang.expected.txt b/tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang.expected.txt new file mode 100644 index 000000000..e8f3f9609 --- /dev/null +++ b/tests/language-feature/swizzles/matrix-swizzle-write-swizzle.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +1.000000 +4.000000 +3.000000 +2.000000 diff --git a/tests/language-feature/swizzles/matrix-swizzle-write.slang b/tests/language-feature/swizzles/matrix-swizzle-write.slang new file mode 100644 index 000000000..5baa4407c --- /dev/null +++ b/tests/language-feature/swizzles/matrix-swizzle-write.slang @@ -0,0 +1,27 @@ +//TEST(compute):COMPARE_COMPUTE: -compute -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE: -vk -compute -shaderobj -output-using-type + +// Test that matrix swizzle writes work correctly +// Matrix swizzles can either be one or zero indexed +// Reference: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-per-component-math + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<float> outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint tid : SV_GroupIndex) +{ + // 0 0 + // 0 0 + float2x2 m = float2x2(0); + + // 0 1 + // 4 0 + m._12_21 = float2(1, 4); + + // 2 1 + // 4 3 + m._m00_m11 = float2(2, 3); + + outputBuffer[tid] = m[tid/2][tid%2]; +} diff --git a/tests/language-feature/swizzles/matrix-swizzle-write.slang.expected.txt b/tests/language-feature/swizzles/matrix-swizzle-write.slang.expected.txt new file mode 100644 index 000000000..089d975fe --- /dev/null +++ b/tests/language-feature/swizzles/matrix-swizzle-write.slang.expected.txt @@ -0,0 +1,5 @@ +type: float +2.000000 +1.000000 +4.000000 +3.000000 |
