diff options
| author | Yong He <yonghe@outlook.com> | 2025-03-19 11:44:04 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-19 11:44:04 -0700 |
| commit | 4eb7a27ac4532a49b9d383d2b0d80bc0ec317b4c (patch) | |
| tree | 3219e185674c04423e3306437e2a31223fadeb49 /tests | |
| parent | eee974d74617944ca2b6f6ac424e98a12a51b82c (diff) | |
Fix reinterpret and bitcast and generic arg parsing. (#6627)
* Fix reinterpret and bitcast.
* Fix warning.
* Fix.
* Fix.
---------
Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
Diffstat (limited to 'tests')
4 files changed, 96 insertions, 24 deletions
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<int> outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + Bar b = { 0x1122334455667788 }; + + Foo f = bit_cast<Foo>(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<uint32_t>(v); + + // CHECK: 40302010 + outputBuffer[3] = u; + + int* ptr = bit_cast<int*>(b.d); + Foo f1 = bit_cast<Foo>(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<int> outputBuffer; + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID : SV_DispatchThreadID) +{ + Bar b = { 0x1122334455667788 }; + Foo f = reinterpret<Foo>(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<uint32_t>(v); + + // CHECK: 40302010 + outputBuffer[3] = u; + int* ptr = reinterpret<int*>(b.d); + Foo f1 = reinterpret<Foo>(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<uint32_t[2]> in; -uniform RWStructuredBuffer<uint32_t> out; - -// CHECK: warning 41203{{.*}}8{{.*}}4 - -[numthreads(4, 1, 1)] -[shader("compute")] -void computeMain() { - out[0] = reinterpret<uint32_t>(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<uint32_t> in; -uniform RWStructuredBuffer<uint32_t[2]> out; - -//CHECK: warning 41203{{.*}}4{{.*}}8 - -[numthreads(4, 1, 1)] -[shader("compute")] -void computeMain() { - out[0] = reinterpret<uint32_t[2]>(in[0]); -}
\ No newline at end of file |
