yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
master
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type 2//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type 3//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type 4//TEST:SIMPLE(filecheck=CHECK): -target hlsl -profile cs_5_0 -entry computeMain -line-directive-mode none 5 6//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer 7RWStructuredBuffer<float> outputBuffer; 8 9[BackwardDifferentiable] 10float sin_series(float x, int iterations) 11{ 12 float result = x; 13 float term = x; 14 int i = 1; 15 [MaxIters(30)] 16 do 17 { 18 term *= -1.0f * x * x / ((2 * i) * (2 * i + 1)); 19 result += term; 20 if(result > 1000000) 21 { 22 i += 1; 23 if(result > 2000000) 24 { 25 term += 1; 26 i += 1; 27 } 28 else 29 { 30 i += 1; 31 } 32 } 33 else 34 { 35 i += 2; 36 } 37 i += -1; 38 } while (i < iterations); 39 return result; 40} 41 42// Check that the intermediate context of sin_series does not have an array for `i`. 43// This test inparticular checks that can identify induction variables through 44// branching control flow 45 46// CHECK: struct s_bwd_prop_sin_series_Intermediates 47// CHECK-NOT: int {{[A-Za-z0-9_]+}}[{{.*}}] 48// CHECK: } 49 50[numthreads(1, 1, 1)] 51void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 52{ 53 var x = diffPair(float.getPi(), 1.0); 54 55 __bwd_diff(sin_series)(x, 30, 1.0f); 56 57 outputBuffer[0] = x.d; // -1.0 58}