yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f02b08490
master
1//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj -emit-spirv-via-glsl -allow-glsl 2//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-vk -compute -shaderobj -emit-spirv-directly -allow-glsl 3//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-slang -compute -profile cs_6_6 -dx12 -shaderobj -render-feature hardware-device -allow-glsl 4//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-metal -compute -shaderobj -allow-glsl 5//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cpu -compute -shaderobj -allow-glsl 6//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-wgpu -compute -shaderobj -allow-glsl 7//TEST(compute):COMPARE_COMPUTE_EX(filecheck-buffer=BUF):-cuda -compute -g0 -allow-glsl 8 9//TEST_INPUT:ubuffer(data=[0x12345678], stride=4):name inputBuffer 10StructuredBuffer<uint> inputBuffer; 11 12//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name outputBuffer 13RWStructuredBuffer<uint> outputBuffer; 14 15bool verifyResult<T: IFloat> (T expected, T actual, T tolerance) 16{ 17 return (expected - tolerance) <= actual && actual <= (expected + tolerance); 18} 19 20bool verifyResultVector<T: IFloat, let N: int>(vector<T, N> expected, vector<T, N> actual, T tolerance = T(0.01)) 21{ 22 bool isValid = true; 23 for (int i = 0; i < N; ++i) 24 isValid = isValid && verifyResult(expected[i], actual[i], tolerance); 25 return isValid; 26} 27 28[numthreads(1, 1, 1)] 29void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 30{ 31 uint packed = inputBuffer[0]; 32 uint index = 0U; 33 34 // 35 // Test GLSL intrinsics for unpacking floating points. 36 // Packing intrinsics are tested in `tests/hlsl-intrinsic/packed/pack-unpack-float.slang`. 37 // 38 39 float4 u4x8Expected = float4(0.4706, 0.3373, 0.2039, 0.0706); 40 float4 u4x8Float = unpackUnorm4x8(packed); 41 // BUF: 1 42 outputBuffer[index++] = verifyResultVector(u4x8Expected, u4x8Float); 43 44 float4 s4x8Expected = float4(0.9449, 0.6772, 0.4094, 0.1417); 45 float4 s4x8Float = unpackSnorm4x8(packed); 46 // BUF-NEXT: 1 47 outputBuffer[index++] = verifyResultVector(s4x8Expected, s4x8Float); 48 49 float2 u2x16Expected = float2(0.3377, 0.0711); 50 float2 u2x16Float = unpackUnorm2x16(packed); 51 // BUF-NEXT: 1 52 outputBuffer[index++] = verifyResultVector(u2x16Expected, u2x16Float); 53 54 float2 s2x16Expected = float2(0.6756, 0.1422); 55 float2 s2x16Float = unpackSnorm2x16(packed); 56 // BUF-NEXT: 1 57 outputBuffer[index++] = verifyResultVector(s2x16Expected, s2x16Float); 58 59 float2 h2x16Expected = float2(103.5, 0.000757); 60 float2 h2x16Float = unpackHalf2x16(packed); 61 // BUF-NEXT: 1 62 outputBuffer[index++] = verifyResultVector(h2x16Expected, h2x16Float); 63}