yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
5ceb8569b
master
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type 2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type 3//TEST(compute):COMPARE_COMPUTE_EX:-cpu -compute -output-using-type -shaderobj 4 5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8typedef DifferentialPair<float> dpfloat; 9typedef float.Differential dfloat; 10 11struct P 12{ 13 bool terminated; 14 bool isTerminated() { return terminated; } 15 bool isHit() { return !terminated; } 16} 17 18[BackwardDifferentiable] 19float test_simple_while(float y) 20{ 21 float t = y; 22 P p; 23 p.terminated = false; 24 int i = 2; 25 26 [MaxIters(3)] 27 while (!p.isTerminated()) 28 { 29 i++; 30 if (p.isHit()) 31 { 32 if (p.isTerminated()) break; 33 t = t * t; 34 p.terminated = (i < 5); 35 } 36 else 37 { 38 t = t + 1.0; 39 } 40 } 41 42 return t; 43} 44 45[numthreads(1, 1, 1)] 46void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 47{ 48 { 49 dpfloat dpa = dpfloat(1.0, 0.0); 50 51 __bwd_diff(test_simple_while)(dpa, 1.0f); 52 outputBuffer[0] = dpa.d; // Expect: 8.0 53 } 54}