From a2401a6ae6c50aeb6ffc196144569bb5253cdf95 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 12 Feb 2021 12:20:17 -0800 Subject: Support `bit_cast` between complex types. (#1702) * Support `bit_cast` between complex types. * Fix vs project file * Fix clang build error * fix * fix * Fix * FIx * Fix * Fix * Fix * Fix * Fix linux compile error Co-authored-by: Tim Foley --- .../bit-cast/struct-bit-cast.slang | 68 ++++++++++++++++++++++ .../bit-cast/struct-bit-cast.slang.expected.txt | 4 ++ 2 files changed, 72 insertions(+) create mode 100644 tests/language-feature/bit-cast/struct-bit-cast.slang create mode 100644 tests/language-feature/bit-cast/struct-bit-cast.slang.expected.txt (limited to 'tests') diff --git a/tests/language-feature/bit-cast/struct-bit-cast.slang b/tests/language-feature/bit-cast/struct-bit-cast.slang new file mode 100644 index 000000000..9c4a039c0 --- /dev/null +++ b/tests/language-feature/bit-cast/struct-bit-cast.slang @@ -0,0 +1,68 @@ +// struct-bit-cast.slang + +//TEST(compute):COMPARE_COMPUTE: -shaderobj + +// Test that bit_cast works for bit-reinterpreting one struct type as another. + +struct Foo +{ + uint a; + float b; + float2 fvec; +} + +struct Inner +{ + int v; + uint s; +} + +struct Bar +{ + int u; + Inner i; + uint t; +} + +int test0(int val) +{ + Bar b; + b.u = val; + b.i.v = asint(2.0f); + b.i.s = asuint(1.25); + b.t = asuint(0.25); + Foo f = bit_cast(b); + return f.a + (int)f.b + int(float(f.fvec.x / f.fvec.y)); // val + 2 + 5 +} + +struct Smaller +{ + int s; +} + +struct Larger +{ + int x, y; +} + +int test1() +{ + Smaller s = {1}; + int v0 = bit_cast(s).y; // 0. + Larger l = {1, 2}; + int v1 = bit_cast(l).s; // 1. + return v0 + v1; +} + + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + uint tid = dispatchThreadID.x; + int inVal = tid; + int outVal = test0(inVal) + test1(); + outputBuffer[tid] = outVal; +} diff --git a/tests/language-feature/bit-cast/struct-bit-cast.slang.expected.txt b/tests/language-feature/bit-cast/struct-bit-cast.slang.expected.txt new file mode 100644 index 000000000..9ace6947d --- /dev/null +++ b/tests/language-feature/bit-cast/struct-bit-cast.slang.expected.txt @@ -0,0 +1,4 @@ +8 +9 +A +B -- cgit v1.2.3