From bc7231bbcf32819bed37012db3f01b34b5dd856a Mon Sep 17 00:00:00 2001 From: Jay Kwak <82421531+jkwak-work@users.noreply.github.com> Date: Thu, 25 Apr 2024 16:14:08 -0700 Subject: Fix unpackUnorm4x8 and unpackSnorm4x8 (#4033) Fixes #4031 Each component of unpackU/Snorm4x8 had to be masked for 8bits. --- tests/bugs/gh-4031.slang | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/bugs/gh-4031.slang (limited to 'tests/bugs') diff --git a/tests/bugs/gh-4031.slang b/tests/bugs/gh-4031.slang new file mode 100644 index 000000000..015eeefc6 --- /dev/null +++ b/tests/bugs/gh-4031.slang @@ -0,0 +1,54 @@ +//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-dx12 -compute -entry computeMain -allow-glsl -profile cs_6_6 -use-dxil -shaderobj -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -output-using-type +//TEST(compute, vulkan):COMPARE_COMPUTE(filecheck-buffer=BUF):-vk -compute -entry computeMain -allow-glsl -output-using-type -emit-spirv-directly + +//TEST_INPUT: ubuffer(data=[0], stride=4):out,name outputBuffer +RWStructuredBuffer outputBuffer; + +bool Test_unpackUnorm4x8() +{ + vector val; + val[0] = 1.f / 1.f; + val[1] = 1.f / 2.f; + val[2] = 1.f / 4.f; + val[3] = 1.f / 8.f; + + const uint32_t packed = packUnorm4x8(val); + const vector unpacked = unpackUnorm4x8(packed); + + return true + && int(unpacked[0] * 1.f) == 1 + && int(unpacked[1] * 2.f) == 1 + && int(unpacked[2] * 4.f) == 1 + && int(unpacked[3] * 8.f) == 1 + ; +} + +bool Test_unpackSnorm4x8() +{ + vector val; + val[0] = 1.f / 1.f; + val[1] = 1.f / 2.f; + val[2] = 1.f / 4.f; + val[3] = 1.f / 8.f; + + const uint32_t packed = packSnorm4x8(val); + const vector unpacked = unpackSnorm4x8(packed); + + return true + && int(unpacked[0] * 1.f) == 1 + && int(unpacked[1] * 2.f) == 1 + && int(unpacked[2] * 4.f) == 1 + && int(unpacked[3] * 8.f) == 1 + ; +} + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + //BUF:1 + outputBuffer[0] = int(true + && Test_unpackUnorm4x8() + && Test_unpackSnorm4x8() + ); +} -- cgit v1.2.3