yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Harsh Aggarwal (NVIDIA)Fix 7723 - Add autodiff tests (#7919)d10732742

master
1.2 KiB37 linesraw
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], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8float lengthDiffX(float3 x)
9{
10    return (length(float3(x.x + 0.001, x.yz)) - length(float3(x.x - 0.001, x.yz))) / 0.002;
11}
12float lengthDiffY(float3 x)
13{
14    return (length(float3(x.x, x.y + 0.001, x.z)) - length(float3(x.x, x.y - 0.001, x.z))) / 0.002;
15}
16float lengthDiffZ(float3 x)
17{
18    return (length(float3(x.xy, x.z + 0.001)) - length(float3(x.xy, x.z - 0.001))) / 0.002;
19}
20
21[numthreads(1, 1, 1)]
22void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
23{
24    {
25        let x = float3(12, 23, 31);
26        var dpx = diffPair(x);
27        __bwd_diff(length)(dpx, 1.0);
28        outputBuffer[0] = dpx.d[0];
29        outputBuffer[1] = dpx.d[1];
30        outputBuffer[2] = dpx.d[2];
31
32        // for reference:
33        //outputBuffer[3] = lengthDiffX(x);
34        //outputBuffer[4] = lengthDiffY(x);
35        //outputBuffer[5] = lengthDiffZ(x);
36    }
37}