yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
d10732742
master
1//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -compute -shaderobj -output-using-type 2//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type 3//TEST(compute):COMPARE_COMPUTE_EX:-cuda -compute -shaderobj -output-using-type 4 5//TEST_INPUT:ubuffer(data=[0 0 0 0 0 0 0 0 0 0], stride=4):out,name=outputBuffer 6RWStructuredBuffer<float> outputBuffer; 7 8typedef DifferentialPair<float> dpfloat; 9typedef DifferentialPair<float2> dpfloat2; 10typedef DifferentialPair<float3> dpfloat3; 11 12[BackwardDifferentiable] 13float diffAtan2(float x, float y) 14{ 15 return atan2(x, y); 16} 17 18[numthreads(1, 1, 1)] 19void computeMain(uint3 dispatchThreadID: SV_DispatchThreadID) 20{ 21 float eps = 1e-4; 22 { 23 dpfloat dpx = dpfloat(5.0, 1.0); 24 dpfloat dpy = dpfloat(3.0, 0.0); 25 dpfloat res = __fwd_diff(diffAtan2)(dpx, dpy); 26 outputBuffer[0] = res.d; 27 } 28 29 { 30 dpfloat dpx = dpfloat(5.0, 0.0); 31 dpfloat dpy = dpfloat(3.0, 1.0); 32 dpfloat res = __fwd_diff(diffAtan2)(dpx, dpy); 33 outputBuffer[1] = res.d; 34 } 35 36 // Test the other 3 quadrants 37 { 38 dpfloat dpx = dpfloat(-5.0, 1.0); 39 dpfloat dpy = dpfloat(3.0, 0.0); 40 dpfloat res = __fwd_diff(diffAtan2)(dpx, dpy); 41 outputBuffer[2] = res.d; 42 } 43 44 { 45 dpfloat dpx = dpfloat(-5.0, 0.0); 46 dpfloat dpy = dpfloat(3.0, 1.0); 47 dpfloat res = __fwd_diff(diffAtan2)(dpx, dpy); 48 outputBuffer[3] = res.d; 49 } 50 51 { 52 dpfloat dpx = dpfloat(-5.0, 1.0); 53 dpfloat dpy = dpfloat(-3.0, 0.0); 54 dpfloat res = __fwd_diff(diffAtan2)(dpx, dpy); 55 outputBuffer[4] = res.d; 56 } 57 58 { 59 dpfloat dpx = dpfloat(-5.0, 0.0); 60 dpfloat dpy = dpfloat(-3.0, 1.0); 61 dpfloat res = __fwd_diff(diffAtan2)(dpx, dpy); 62 outputBuffer[5] = res.d; 63 } 64 65 { 66 dpfloat dpx = dpfloat(5.0, 1.0); 67 dpfloat dpy = dpfloat(-3.0, 0.0); 68 dpfloat res = __fwd_diff(diffAtan2)(dpx, dpy); 69 outputBuffer[6] = res.d; 70 } 71 72 { 73 dpfloat dpx = dpfloat(5.0, 0.0); 74 dpfloat dpy = dpfloat(-3.0, 1.0); 75 dpfloat res = __fwd_diff(diffAtan2)(dpx, dpy); 76 outputBuffer[7] = res.d; 77 } 78 79 { 80 dpfloat dpx = diffPair(5.0); 81 dpfloat dpy = diffPair(3.0); 82 __bwd_diff(diffAtan2)(dpx, dpy, 1.0); 83 outputBuffer[8] = dpx.d; // Should be equal to outputBuffer[0] 84 outputBuffer[9] = dpy.d; // Should be equal to outputBuffer[2] 85 } 86}