From c7e5601bb67d2a5ebadb7f84c6968b5912e7566d Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Thu, 13 Apr 2023 23:49:00 +0800 Subject: 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 --- .../swizzles/matrix-swizzle-write-array.slang | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/language-feature/swizzles/matrix-swizzle-write-array.slang (limited to 'tests/language-feature/swizzles/matrix-swizzle-write-array.slang') 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 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; +} -- cgit v1.2.3