summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics/uninitialized-fields-delegated.slang
blob: 75a76eac6ddf2bf5ce242fd1bf84d9c711801374 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//TEST:SIMPLE(filecheck=CHK): -target spirv -entry computeMain

// Delegated constructors
struct Impl
{
    float x;

    __init(float val)
    {
        x = val;
    }

    __init()
    {
        float val = 2.0;

        // Shouldn't trigger a warning here
        return Impl(val);
    }
}

// Calling a method from a constructor to initialize fields
struct HitInfo
{
    float3 barycentrics;
    uint primitiveIndex;
    
    [[mutating]] void init(float2 hitBarycentrics, uint hitPrimitiveIndex)
    {
        barycentrics = { 1.0 - hitBarycentrics.x - hitBarycentrics.y, hitBarycentrics.x, hitBarycentrics.y };
        primitiveIndex = hitPrimitiveIndex;
    }

    __init(float2 hitBarycentrics, uint hitPrimitiveIndex)
    {
        init(hitBarycentrics, hitPrimitiveIndex);
    }

    __init(BuiltInTriangleIntersectionAttributes attr)
    {
        init(attr.barycentrics, PrimitiveIndex());
    }
}

//CHK-NOT: warning 41020
//CHK-NOT: warning 41021


[Shader("compute")]
[NumThreads(4, 1, 1)]
void computeMain(int3 dispatchThreadID : SV_DispatchThreadID)
{
}