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 [MaxIters(35)] 15 for (int i = 1; i < iterations; i++) 16 { 17 if(i == 32) 18 i += 1; 19 term *= -1.0f * x * x / ((2 * i) * (2 * i + 1)); 20 result += term; 21 } 22 return result; 23} 24 25// Check that the intermediate context of sin_series still has an array for 26// `i`. This test checks that the induction variable finder doesn't 27// accidentally succeed all the time 28 29// CHECK: struct s_bwd_prop_sin_series_Intermediates 30// CHECK: int {{[A-Za-z0-9_]+}}[{{.*}}] 31// CHECK: } 32 33[numthreads(1, 1, 1)] 34void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 35{ 36 var x = diffPair(float.getPi(), 1.0); 37 38 __bwd_diff(sin_series)(x, 30, 1.0f); 39 40 outputBuffer[0] = x.d; // -1.0 41}