From 4eb7a27ac4532a49b9d383d2b0d80bc0ec317b4c Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 19 Mar 2025 11:44:04 -0700 Subject: Fix reinterpret and bitcast and generic arg parsing. (#6627) * Fix reinterpret and bitcast. * Fix warning. * Fix. * Fix. --------- Co-authored-by: Ellie Hermaszewska --- .../bit-cast/struct-bit-cast-2.slang | 49 ++++++++++++++++++++++ .../bit-cast/struct-reinterpret.slang | 47 +++++++++++++++++++++ .../narrowing-reinterpret-warning.slang | 12 ------ .../reinterpret/widening-reinterpret-warning.slang | 12 ------ 4 files changed, 96 insertions(+), 24 deletions(-) create mode 100644 tests/language-feature/bit-cast/struct-bit-cast-2.slang create mode 100644 tests/language-feature/bit-cast/struct-reinterpret.slang delete mode 100644 tests/language-feature/reinterpret/narrowing-reinterpret-warning.slang delete mode 100644 tests/language-feature/reinterpret/widening-reinterpret-warning.slang (limited to 'tests') diff --git a/tests/language-feature/bit-cast/struct-bit-cast-2.slang b/tests/language-feature/bit-cast/struct-bit-cast-2.slang new file mode 100644 index 000000000..edf91e00b --- /dev/null +++ b/tests/language-feature/bit-cast/struct-bit-cast-2.slang @@ -0,0 +1,49 @@ +// struct-bit-cast-2.slang +// Test bit casts for read across boundaries of scalar types. + +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -shaderobj +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cuda -shaderobj + +// Test that bit_cast works for bit-reinterpreting one struct type as another. + +struct Foo +{ + uint16_t a; + uint16_t b; + uint32_t c; +} + +struct Bar +{ + uint64_t d; +} + + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + Bar b = { 0x1122334455667788 }; + + Foo f = bit_cast(b); + // CHECK: 7788 + outputBuffer[0] = f.a; + // CHECK: 5566 + outputBuffer[1] = f.b; + // CHECK: 11223344 + outputBuffer[2] = f.c; + + uint8_t4 v = {0x10, 0x20, 0x30, 0x40}; + uint32_t u = bit_cast(v); + + // CHECK: 40302010 + outputBuffer[3] = u; + + int* ptr = bit_cast(b.d); + Foo f1 = bit_cast(ptr); + // CHECK: 11223344 + outputBuffer[4] = f1.c; +} diff --git a/tests/language-feature/bit-cast/struct-reinterpret.slang b/tests/language-feature/bit-cast/struct-reinterpret.slang new file mode 100644 index 000000000..6be359d79 --- /dev/null +++ b/tests/language-feature/bit-cast/struct-reinterpret.slang @@ -0,0 +1,47 @@ +// struct-bit-cast-2.slang +// Test bit casts for read across boundaries of scalar types. + +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk -shaderobj +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu -shaderobj +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cuda -shaderobj + +// Test that bit_cast works for bit-reinterpreting one struct type as another. + +struct Foo +{ + uint16_t a; + uint16_t b; + uint32_t c; +} + +struct Bar +{ + uint64_t d; +} + + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + Bar b = { 0x1122334455667788 }; + Foo f = reinterpret(b); + // CHECK: 7788 + outputBuffer[0] = f.a; + // CHECK: 5566 + outputBuffer[1] = f.b; + // CHECK: 11223344 + outputBuffer[2] = f.c; + + uint8_t4 v = {0x10, 0x20, 0x30, 0x40}; + uint32_t u = reinterpret(v); + + // CHECK: 40302010 + outputBuffer[3] = u; + int* ptr = reinterpret(b.d); + Foo f1 = reinterpret(ptr); + // CHECK: 11223344 + outputBuffer[4] = f1.c; +} diff --git a/tests/language-feature/reinterpret/narrowing-reinterpret-warning.slang b/tests/language-feature/reinterpret/narrowing-reinterpret-warning.slang deleted file mode 100644 index 98ed71165..000000000 --- a/tests/language-feature/reinterpret/narrowing-reinterpret-warning.slang +++ /dev/null @@ -1,12 +0,0 @@ -//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -stage compute -entry computeMain - -uniform StructuredBuffer in; -uniform RWStructuredBuffer out; - -// CHECK: warning 41203{{.*}}8{{.*}}4 - -[numthreads(4, 1, 1)] -[shader("compute")] -void computeMain() { - out[0] = reinterpret(in[0]); -} \ No newline at end of file diff --git a/tests/language-feature/reinterpret/widening-reinterpret-warning.slang b/tests/language-feature/reinterpret/widening-reinterpret-warning.slang deleted file mode 100644 index 2f643cc3f..000000000 --- a/tests/language-feature/reinterpret/widening-reinterpret-warning.slang +++ /dev/null @@ -1,12 +0,0 @@ -//TEST:SIMPLE(filecheck=CHECK): -target spirv -emit-spirv-directly -stage compute -entry computeMain - -uniform StructuredBuffer in; -uniform RWStructuredBuffer out; - -//CHECK: warning 41203{{.*}}4{{.*}}8 - -[numthreads(4, 1, 1)] -[shader("compute")] -void computeMain() { - out[0] = reinterpret(in[0]); -} \ No newline at end of file -- cgit v1.2.3