yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
53dd5928c
master
1//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -shaderobj 2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj 3//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -dx12 -shaderobj 4//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj 5//DISABLED_TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj 6//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj 7//TEST(compute):COMPARE_COMPUTE_EX:-wgpu -compute -shaderobj 8 9//TEST_INPUT:ubuffer(data=[0 0 0 0], stride=4):out,name outputBuffer 10RWStructuredBuffer<int> outputBuffer; 11 12[numthreads(4, 1, 1)] 13void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 14{ 15 int idx = int(dispatchThreadID.x); 16 17 float f = idx * (1.0f / (4.0f)); 18 19 float ft = 0.0f; 20 21 // fmod 22 ft += int(((f % 0.11f) * 100) + 0.5); 23 24 ft += sin(f); 25 ft += cos(f); 26 ft += tan(f); 27 28 ft += asin(f); 29 ft += acos(f); 30 ft += atan(f); 31 32 ft += length(f - 0.5); 33 34 ft += atan2(f, 2.0); 35 36 { 37 float sf, cf; 38 sincos(f, sf, cf); 39 40 ft += sf; 41 ft += cf; 42 } 43 44 ft += rcp(1.0 + f); 45 ft += sign(f - 0.5); 46 47 ft += saturate(f * 4 - 2.0); 48 49 ft += sqrt(f); 50 ft += rsqrt(1.0f + f); 51 52 ft += exp2(f); 53 ft += exp(f); 54 55 56 ft += frac(f * 3); 57 ft += ceil(f * 5 - 3); 58 59 ft += floor(f * 10 - 7); 60 ft += trunc(f * 7); 61 62 63 ft += log(f + 10.0); 64 ft += log2(f * 3 + 2); 65 66 { 67 float v[] = { 1, 10, 100, 1000 }; 68 ft += int(log10(v[idx]) + 0.5f); 69 } 70 71 ft += abs(f * 4 - 2.0f); 72 73 ft += min(0.5, f); 74 ft += max(f, 0.75); 75 76 ft += pow(0.5, f); 77 78 ft += smoothstep(0.2, 0.7, f); 79 ft += lerp(-100, 100, f); 80 81 82 ft += clamp(f, 0.1, 0.3); 83 84 ft += step(f, 0.5); 85 86 int vi = asint(f - f) + idx; 87 88 ft += float(vi); 89 90 ft += ldexp(23.2, f); 91 92 uint vu = asuint(f); 93 ft += asfloat(vu); 94 95 outputBuffer[idx] = int(ft * 16); 96}