yum-mirror/slang

Making it easier to work with shaders

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

Sai Praveen BangaruExplicitly detach derivative when forming a non-differentiable struct out of differentiable args (#4901)d40c143eb

master
1.1 KiB43 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:-cpu -compute -output-using-type -shaderobj
4
5//TEST_INPUT:ubuffer(data=[0 0 0 0 0], stride=4):out,name=outputBuffer
6RWStructuredBuffer<float> outputBuffer;
7
8// This test checks to ensure that expressions of the form FieldExtract(MakeStruct(...))
9// are handled correctly in the presence of differentiation. 
10// Such expressions are often optimized out, and the non-differentiability of the struct 
11// type can be accidentally overlooked.
12//
13
14typedef DifferentialPair<float> dpfloat;
15typedef float.Differential dfloat;
16
17struct Data
18{
19    [PreferRecompute]
20    __init(float tin)
21    {
22        this.t = tin;
23    }
24    float t;
25};
26
27[BackwardDifferentiable]
28float test_make_struct(float y)
29{
30    Data d = { y };
31    return d.t;
32}
33
34[numthreads(1, 1, 1)]
35void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
36{
37    {
38        dpfloat dpa = dpfloat(1.0, 0.0);
39
40        bwd_diff(test_make_struct)(dpa, 1.0f);
41        outputBuffer[0] = dpa.d; // Expect: 0.0
42    }
43}