yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
3c32dd951
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 11[BackwardDifferentiable] 12float test_simple_while(float y) 13{ 14 float t = y; 15 16 bool keepGoing = true; 17 int i = 2; 18 19 [MaxIters(3)] 20 do 21 { 22 i++; 23 t = t * t; 24 25 keepGoing = (i < 5); 26 } while (keepGoing); 27 28 return t; 29} 30 31[numthreads(1, 1, 1)] 32void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID) 33{ 34 { 35 dpfloat dpa = dpfloat(1.0, 0.0); 36 37 __bwd_diff(test_simple_while)(dpa, 1.0f); 38 outputBuffer[0] = dpa.d; // Expect: 8.0 39 } 40 41 { 42 dpfloat dpa = dpfloat(0.4, 0.0); 43 44 __bwd_diff(test_simple_while)(dpa, 1.0f); 45 outputBuffer[1] = dpa.d; // Expect: 0.0131072 46 } 47}