yum-mirror/slang

Making it easier to work with shaders

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

ArielG-NVImplement raytracing extension(s); resolves #3560 for GLSL & SPIR-V targets (#3675)9b434e50f

master
4.0 KiB106 linesraw
1//TEST:SIMPLE(filecheck=CHECK_GLSL): -allow-glsl -stage compute -entry computeMain -target glsl
2//TEST:SIMPLE(filecheck=CHECK_SPV): -allow-glsl -emit-spirv-directly -stage compute -entry computeMain -target spirv-assembly
3
4//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF): -allow-glsl -vk -compute -output-using-type -render-feature ray-query -entry computeMain 
5//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=BUF): -allow-glsl -vk -compute -output-using-type -render-feature ray-query -emit-spirv-directly -entry computeMain 
6
7// note: the referenced input data is in render-test-main kVertexData; 1 triangle at {(0,0,0.5),(0,1,0.5),(1,0,0.5)}
8//TEST_INPUT: set scene = AccelerationStructure
9layout(binding = 0) uniform accelerationStructureEXT scene;
10
11//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer
12buffer MyBlockName
13{
14    uint data[];
15} outputBuffer;
16
17__generic<T : __BuiltinFloatingPointType, let N : int, let M : int>
18bool equals(matrix<T, N, M> lhs, matrix<T, N, M> rhs)
19{
20    for (int i = 0; i < N; i++)
21    {
22        for (int j = 0; j < M; j++)
23        {
24            if (
25                lhs[i][j] 
26                !=
27                rhs[i][j]
28                )
29            {
30                return false;
31            }
32        }
33    }
34    return true;
35}
36
37bool testAbortRayTrace() {
38    rayQueryEXT q;
39    rayQueryInitializeEXT(q, scene, gl_RayFlagsNoneEXT, 0xff, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f);
40    rayQueryTerminateEXT(q);
41
42    return true
43        && rayQueryGetIntersectionTypeEXT(q, true) == gl_RayQueryCommittedIntersectionNoneEXT
44        ;
45}
46
47bool testProceedRayTrace() {
48    rayQueryEXT q;
49    rayQueryInitializeEXT(q, scene, gl_RayFlagsNoneEXT, 0xff, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f);
50    rayQueryProceedEXT(q);
51
52    return true
53        && rayQueryGetIntersectionTypeEXT(q, true) == gl_RayQueryCommittedIntersectionTriangleEXT
54        && rayQueryGetIntersectionTEXT(q, true) == 0.5
55        ;
56}
57
58bool testProceedRayAuxInfo() {
59    rayQueryEXT q;
60    rayQueryInitializeEXT(q, scene, gl_RayFlagsNoneEXT, 0xff, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f);
61    rayQueryProceedEXT(q);
62
63    return true
64        && rayQueryGetRayTMinEXT(q) == 0.01f
65        && rayQueryGetRayFlagsEXT(q) == gl_RayFlagsNoneEXT
66        && rayQueryGetWorldRayOriginEXT(q) == vec3(0.1, 0.1, 0.0)
67        && rayQueryGetWorldRayDirectionEXT(q) == vec3(0, 0, 1)
68        && rayQueryGetIntersectionInstanceCustomIndexEXT(q, true) == 0
69        && rayQueryGetIntersectionInstanceIdEXT(q, true) == 0
70        && rayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetEXT(q, true) == 0
71        && rayQueryGetIntersectionGeometryIndexEXT(q, true) == 0
72        && rayQueryGetIntersectionPrimitiveIndexEXT(q, true) == 0
73        && rayQueryGetIntersectionBarycentricsEXT(q, true) == vec2(0.1)
74        && rayQueryGetIntersectionFrontFaceEXT(q, true) == true
75        && rayQueryGetIntersectionCandidateAABBOpaqueEXT(q) == true
76        && rayQueryGetIntersectionObjectRayDirectionEXT(q, true) == vec3(0, 0, 1)
77        && rayQueryGetIntersectionObjectRayOriginEXT(q, true) == vec3(0.1, 0.1, 0.0)
78        && !equals(rayQueryGetIntersectionObjectToWorldEXT(q, true), mat4x3(0)) // some compile error to sort later
79        && !equals(rayQueryGetIntersectionWorldToObjectEXT(q, true), mat4x3(0))
80        ;
81}
82bool testRayTraceGenerate() {
83    rayQueryEXT q;
84    rayQueryInitializeEXT(q, scene, gl_RayFlagsNoneEXT, 0xff, vec3(0.1, 0.1, 0.0), 0.01f, vec3(0, 0, 1), 1e4f);
85    rayQueryGenerateIntersectionEXT(q, 0.5);
86    rayQueryConfirmIntersectionEXT(q);
87
88    return true
89        && rayQueryGetIntersectionTypeEXT(q, true) == gl_RayQueryCommittedIntersectionTriangleEXT
90        ;
91}
92
93// CHECK_GLSL-DAG: main
94// CHECK_SPV-DAG: OpEntryPoint
95layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
96void computeMain()
97{
98    outputBuffer.data[0] = true
99        && testAbortRayTrace()
100        //&& testProceedRayTrace()
101        //&& testProceedRayAuxInfo()
102        //&& testRayTraceGenerate()
103        ;
104    // BUF: 1
105}
106