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 KiB41 linesraw
1//TEST(compute):COMPARE_COMPUTE_EX:-slang -compute -shaderobj -output-using-type
2//TEST(compute, vulkan):COMPARE_COMPUTE_EX:-vk -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], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8typedef DifferentialPair<float3> dpfloat3;
9typedef float3.Differential dfloat3;
10
11typedef DifferentialPair<float2> dpfloat2;
12typedef float2.Differential dfloat2;
13
14// This test case should hit a lot of conversion insts
15// kIROp_MakeVectorFromScalar (both uint and float), 
16// kIROp_CastIntToFloat, etc..
17// 
18[BackwardDifferentiable]
19float3 test_uint_offset(float3 x, float3 y)
20{
21    uint3 u4 = 1;
22
23    uint3 u5 = u4 + 2;
24
25    return x + y + u5;
26}
27
28
29[numthreads(1, 1, 1)]
30void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
31{
32    {
33        dpfloat3 dpx = dpfloat3(float3(2.0, 3.0, 4.0), float3(0.0, 0.0, 0.0));
34        dpfloat3 dpy = dpfloat3(float3(1.5, 2.5, 3.5), float3(0.0, 0.0, 0.0));
35
36        __bwd_diff(test_uint_offset)(dpx, dpy, dfloat3(1.0, 2.0, 3.0));
37        outputBuffer[0] = dpx.d.y; // Expect: 2
38        outputBuffer[1] = dpy.d.y; // Expect: 2
39    }
40
41}