summaryrefslogtreecommitdiffstats
path: root/tests/hlsl-intrinsic/shader-execution-reordering/hit-object-array.slang
blob: 8c2519daf621145491bd3204d87951dddb6c5d31 (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// hit-object-array.slang

//TEST:SIMPLE: -target dxil -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -DNV_SHADER_EXTN_SLOT=u0 

/* This doesn't work correctly currently because it produces assignments to the HitObject array in GLSL output. 
But that is not valid for hitObjectNV int he extension */

//DISABLE_TEST:SIMPLE: -target glsl -entry rayGenerationMain -stage raygeneration -profile sm_6_5 -line-directive-mode none 

//DISABLE_TEST(compute):COMPARE_COMPUTE:-d3d12 -output-using-type -profile sm_6_5 -render-feature ray-query
//DISABLE_TEST(compute):COMPARE_COMPUTE:-vk -output-using-type -render-feature ray-query

//TEST_INPUT: set scene = AccelerationStructure
uniform RaytracingAccelerationStructure scene;

//TEST_INPUT:set outputBuffer = out ubuffer(data=[0, 0, 0, 0], stride=4)
RWStructuredBuffer<uint> outputBuffer;

struct SomeValues
{
    int a;
    float b;
};

uint calcValue(HitObject hit)
{
    uint r = 0;
    
    if (hit.IsHit())
    {
        uint instanceIndex = hit.GetInstanceIndex();
        uint instanceID = hit.GetInstanceID();
        uint geometryIndex = hit.GetGeometryIndex();
        uint primitiveIndex = hit.GetPrimitiveIndex();
        uint hitKind = hit.GetHitKind();
        
        r += hitKind;
        r += instanceIndex;
        r += instanceID;
        r += geometryIndex;
        r += primitiveIndex;

        RayDesc ray = hit.GetRayDesc();

        r += uint(ray.TMin > 0);
        r += uint(ray.TMax < ray.TMin);
        
        SomeValues objSomeValues = hit.GetAttributes<SomeValues>();
        
        r += objSomeValues.a;
    }
    else if (hit.IsMiss())
    {
        r += 1;
    }
    
    return r;
}

void rayGenerationMain() 
{
    int2 launchID = int2(DispatchRaysIndex().xy);
    int2 launchSize = int2(DispatchRaysDimensions().xy);

    int idx = launchID.x;

    SomeValues someValues = { idx, idx * 2.0f };

    RayDesc ray;  
    ray.Origin = float3(idx, 0, 0);
    ray.TMin = 0.01f;
    ray.Direction = float3(0, 1, 0);
    ray.TMax = 1e4f;
    
    uint hitKind = 0;

    HitObject hitObjs[2];
    
    hitObjs[0] = HitObject::MakeHit(0, scene, idx, idx * 2, idx * 3, hitKind, ray, someValues);
   
    {
        int rayContributionToHitGroupIndex = 0;
        int multiplierForGeometryContributionToHitGroupIndex = 4;
        
        hitObjs[1] = HitObject::MakeHit(scene, 
            idx, 
            idx * 2, 
            idx * 3, 
            hitKind, 
            rayContributionToHitGroupIndex, 
            multiplierForGeometryContributionToHitGroupIndex, 
            ray, 
            someValues);
    }


    uint r = calcValue(hitObjs[0]) + calcValue(hitObjs[1]);
      
    outputBuffer[idx] = r;
}