yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
712ce653d
master
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj 3//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj 4 5//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], stride=4):out,name outputBuffer 6RWStructuredBuffer<int> outputBuffer; 7 8[numthreads(4,4,1)] 9void computeMain(int2 pixelIndex : SV_DispatchThreadID) 10{ 11 12 // We will test floats, uints, and int vectors 13 // We need all comparisons < > <= >= == != 14 15 int x = pixelIndex.x; 16 int y = pixelIndex.y; 17 18 int uintBits; 19 { 20 uint2 v = { uint(x), uint(y) }; 21 uint2 test = { 1, 3 }; 22 23 int bits = 0; 24 bits |= any(v < test) ? 0x01 : 0; 25 bits |= any(v <= test) ? 0x02 : 0; 26 bits |= any(v == test) ? 0x04 : 0; 27 bits |= any(v > test) ? 0x08 : 0; 28 bits |= any(v >= test) ? 0x10 : 0; 29 bits |= any(v != test) ? 0x20 : 0; 30 uintBits = bits; 31 } 32 33 int intBits; 34 { 35 int2 v = { x, y }; 36 int2 test = { 2, 0 }; 37 38 int bits = 0; 39 bits |= any(v < test) ? 0x01 : 0; 40 bits |= any(v <= test) ? 0x02 : 0; 41 bits |= any(v == test) ? 0x04 : 0; 42 bits |= any(v > test) ? 0x08 : 0; 43 bits |= any(v >= test) ? 0x10 : 0; 44 bits |= any(v != test) ? 0x20 : 0; 45 intBits = bits; 46 } 47 48 int floatBits; 49 { 50 float2 v = { float(x), float(y) }; 51 float2 test = { 1, 2 }; 52 53 int bits = 0; 54 bits |= any(v < test) ? 0x01 : 0; 55 bits |= any(v <= test) ? 0x02 : 0; 56 bits |= any(v == test) ? 0x04 : 0; 57 bits |= any(v > test) ? 0x08 : 0; 58 bits |= any(v >= test) ? 0x10 : 0; 59 bits |= any(v != test) ? 0x20 : 0; 60 floatBits = bits; 61 } 62 63 int coerceBits; 64 { 65 float2 v = { float(x), float(y) }; 66 int2 test = { 1, 2 }; 67 68 int bits = 0; 69 bits |= any(v < test) ? 0x01 : 0; 70 bits |= any(v <= test) ? 0x02 : 0; 71 bits |= any(v == test) ? 0x04 : 0; 72 bits |= any(v > test) ? 0x08 : 0; 73 bits |= any(v >= test) ? 0x10 : 0; 74 bits |= any(v != test) ? 0x20 : 0; 75 coerceBits = bits; 76 } 77 78 outputBuffer[pixelIndex.x + pixelIndex.y * 4] = (coerceBits << 24) | (floatBits << 16) | (intBits << 8) | (uintBits); 79}