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(30)] 15 for (int i = 1; i < iterations * 10; i += 10) 16 { 17 term *= -1.0f * x * x / ((2 * i / 10 + 1) * (2 * i / 10 + 2)); 18 result += term; 19 } 20 return result; 21} 22 23// Check that the intermediate context of sin_series does not have an array for `i`. 24// This test differs from ./long-loop.slang in that the loop counter is 25// relative to a multiple of the loop iteration 26 27// CHECK: struct s_bwd_prop_sin_series_Intermediates 28// CHECK-NOT: int {{[A-Za-z0-9_]+}}[{{.*}}] 29// CHECK: } 30 31[numthreads(1, 1, 1)] 32void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 33{ 34 var x = diffPair(float.getPi(), 1.0); 35 36 __bwd_diff(sin_series)(x, 30, 1.0f); 37 38 outputBuffer[0] = x.d; // -1.0 39} 40 41 42