From df9dc5710725d00630831b77ca7005e390383aa6 Mon Sep 17 00:00:00 2001 From: jsmall-nvidia Date: Mon, 28 Jan 2019 12:28:05 -0500 Subject: Feature/bit cast glsl (#808) * First attempt at asint, asuint, asfloat intrinsics. * Test with countbits * Placing glsl definitions first makes them get picked up. * Some more improvements around asint. * Add support for vector versions of asint/asunit * Fix some typos in asuint/asint intrinsics for glsl. Simplified and increased coverage of as/u/int tests. * Added bit-cast-double test. Added notional support for asdouble bit casts to glsl - but couldn't test because glslang doesn't seem to support the extension. * Try to get double bit casts working - doesn't work cos of block issue. * Only output parents on intrinic replacement if return type is not void. --- tests/compute/bit-cast-double.slang | 21 ++++++++++++ tests/compute/bit-cast-double.slang.expected.txt | 4 +++ tests/compute/bit-cast.slang | 42 ++++++++++++++++++++++++ tests/compute/bit-cast.slang.expected.txt | 12 +++++++ 4 files changed, 79 insertions(+) create mode 100644 tests/compute/bit-cast-double.slang create mode 100644 tests/compute/bit-cast-double.slang.expected.txt create mode 100644 tests/compute/bit-cast.slang create mode 100644 tests/compute/bit-cast.slang.expected.txt (limited to 'tests') diff --git a/tests/compute/bit-cast-double.slang b/tests/compute/bit-cast-double.slang new file mode 100644 index 000000000..27d0b48cf --- /dev/null +++ b/tests/compute/bit-cast-double.slang @@ -0,0 +1,21 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute + +//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + double d = double(dispatchThreadID.x); + + uint hi, low; + asuint(d, low, hi); + + // Reconstruct + double r = asdouble(low, hi); + + outputBuffer[dispatchThreadID.x] = int(r); +} \ No newline at end of file diff --git a/tests/compute/bit-cast-double.slang.expected.txt b/tests/compute/bit-cast-double.slang.expected.txt new file mode 100644 index 000000000..bc856dafa --- /dev/null +++ b/tests/compute/bit-cast-double.slang.expected.txt @@ -0,0 +1,4 @@ +0 +1 +2 +3 diff --git a/tests/compute/bit-cast.slang b/tests/compute/bit-cast.slang new file mode 100644 index 000000000..050b84f30 --- /dev/null +++ b/tests/compute/bit-cast.slang @@ -0,0 +1,42 @@ +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute +//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 +//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute + +//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0], stride=4):dxbinding(0),glbinding(0),out + +RWStructuredBuffer outputBuffer; + +[numthreads(4, 1, 1)] +void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) +{ + const int id = asint(dispatchThreadID.x); + + { + int4 i4 = int4(id, id + 1, id + 2, id + 3); + uint3 u3 = asuint(i4.xyz); + int2 i2 = asint(u3.xy); + uint u1 = asuint(i2.x); + + outputBuffer[id + 0] = int(u1); + } + + { + uint v = asuint(id); + uint4 u4 = uint4(v, v + 1, v + 2, v + 3); + int3 i3 = asint(u4.xyz); + uint2 u2 = asuint(i3.xy); + int i1 = asint(u2.x); + + outputBuffer[id + 4] = i1; + } + + { + int4 i4 = int4(id, id + 1, id + 2, id + 3); + float4 f4 = asfloat(i4); + uint3 u3 = asuint(f4.xyz); + float2 f2 = asfloat(u3.xy); + int i1 = asint(id); + + outputBuffer[id + 8] = i1; + } +} \ No newline at end of file diff --git a/tests/compute/bit-cast.slang.expected.txt b/tests/compute/bit-cast.slang.expected.txt new file mode 100644 index 000000000..f5414793f --- /dev/null +++ b/tests/compute/bit-cast.slang.expected.txt @@ -0,0 +1,12 @@ +0 +1 +2 +3 +0 +1 +2 +3 +0 +1 +2 +3 \ No newline at end of file -- cgit v1.2.3