Debian Codegraph @

IGC/AdaptorOCL/ocl_igc_shared/raytracing/ocl_raytracing_structures.h

raw
1 /*========================== begin_copyright_notice ============================
2
3 Copyright (C) 2019-2021 Intel Corporation
4
5 SPDX-License-Identifier: MIT
6
7 ============================= end_copyright_notice ===========================*/
8
9 #pragma once
10
11 // TODO: can we reuse RTStackFormat.h?
12
13 using Vec3f = float[3];
14
15 enum NodeType {
16 NODE_TYPE_MIXED = 0x0, // identifies a mixed internal node where each child can have a different type
17 NODE_TYPE_INTERNAL = 0x0, // internal BVH node with 6 children
18 NODE_TYPE_INSTANCE = 0x1, // instance leaf
19 NODE_TYPE_PROCEDURAL = 0x3, // procedural leaf
20 NODE_TYPE_QUAD = 0x4, // quad leaf
21 NODE_TYPE_MESHLET = 0x6, // meshlet leaf
22 NODE_TYPE_INVALID = 0x7 // indicates invalid node
23 };
24
25 struct MemRay {
26 // 32 B
27 Vec3f org; // the origin of the ray
28 Vec3f dir; // the direction of the ray
29 float tnear; // the start of the ray
30 float tfar; // the end of the ray
31
32 // 32 B
33 uint64_t rootNodePtr : 48; // root node to start traversal at
34 uint64_t rayFlags : 16; // ray flags (see RayFlag structure)
35
36 uint64_t hitGroupSRBasePtr : 48; // base of hit group shader record array (16-bytes alignment)
37 uint64_t hitGroupSRStride : 16; // stride of hit group shader record array (16-bytes alignment)
38
39 uint64_t missSRPtr : 48; // pointer to miss shader record to invoke on a miss (8-bytes alignment)
40 uint64_t pad : 8;
41 uint64_t shaderIndexMultiplier : 8; // shader index multiplier
42
43 uint64_t instLeafPtr : 48; // the pointer to instance leaf in case we traverse an instance (64-bytes alignment)
44 uint64_t rayMask : 8; // ray mask used for ray masking
45 };
46 static_assert(sizeof(MemRay) == 64, "Wrong MemRay size");
47
48 struct MemHit {
49 float t; // hit distance of current hit (or initial traversal distance)
50 float u, v; // barycentric hit coordinates
51
52 uint32_t primIndexDelta : 16; // prim index delta for compressed meshlets and quads
53 uint32_t valid : 1; // set if there is a hit
54 uint32_t leafType : 3; // type of node primLeafPtr is pointing to
55 uint32_t primLeafIndex : 4; // index of the hit primitive inside the leaf
56 uint32_t bvhLevel : 3; // the instancing level at which the hit occured
57 uint32_t frontFace : 1; // whether we hit the front-facing side of a triangle (also used to pass opaque flag when
58 // calling intersection shaders)
59 uint32_t done : 1; // used in sync mode to indicate that traversal is done
60 uint32_t pad0 : 3; // unused bits
61
62 uint64_t primLeafPtr : 42; // pointer to BVH leaf node (multiple of 64 bytes)
63 uint64_t hitGroupRecPtr0 : 22; // LSB of hit group record of the hit triangle (multiple of 16 bytes)
64 uint64_t instLeafPtr : 42; // pointer to BVH instance leaf node (in multiple of 64 bytes)
65 uint64_t hitGroupRecPtr1 : 22; // MSB of hit group record of the hit triangle (multiple of 16 bytes)
66 };
67 static_assert(sizeof(MemHit) == 32, "Wrong MemHit size");
68
69 struct NodeInfo {
70 uint8_t type : 3;
71 uint8_t parent : 1; // Indicates a culled stack entry where a single parent node
72 // is stored in place of multiple child nodes
73 uint8_t cur_prim : 4;
74 };
75 static_assert(sizeof(NodeInfo) == 1, "Wrong NodeInfo size");
76
77 static const uint32_t MEM_STACK_SIZE = 4;
78
79 struct MemTravStack {
80 uint64_t curDepth : 5; // current depth in the restart trail
81 uint64_t restartTrail0 : 29; // lower bits of restart trail
82 uint64_t restartTrail1 : 29; // higher bits of restart trail
83 uint64_t lastChild0 : 1; // last child bit for node 0
84 uint32_t restartTrail2 : 29; // highest bits of restart trail
85 uint32_t lastChild123 : 3; // last child bit for nodes 1/2/3
86
87 int32_t offset[MEM_STACK_SIZE]; // Signed offset relative to BVH root in multiples of 64B.
88 NodeInfo nodeInfo[MEM_STACK_SIZE];
89 };
90 static_assert(sizeof(MemTravStack) == 32, "Wrong MemTravStack size");
91
92 struct alignas(32) RTDispatchGlobals {
93 // Cached by HW
94 public:
95 uint64_t rtMemBasePtr; // base address of the allocated stack memory
96 uint64_t
97 callStackHandlerKSP; // this is the KSP of the continuation handler that is invoked by BTD when the read KSP is 0
98 uint32_t stackSizePerRay; // maximal stack size of a ray in 64 byte blocks
99 uint32_t numDSSRTStacks; // number of stacks per DSS
100 // TODO: update with:
101 // uint32_t maxBVHLevels : 3; // the maximal number of supported instancing levels, 0->8, 1->1, 2->2, etc.
102 // uint32_t hitGroupStride : 13; // stride of hit group shader records (16-bytes alignment)
103 // uint32_t missShaderStride : 13; // stride of miss shader records (8-bytes alignment)
104 // uint32_t _pad2_mbz : 3;
105 uint32_t maxBVHLevels;
106 uint32_t flags : 1;
107 uint32_t pad_mbz : 31;
108
109 // Not cached by HW
110 public:
111 uint64_t hitGroupBasePtr; // base pointer of hit group shader record array (16-bytes alignment)
112 uint64_t missShaderBasePtr; // base pointer of miss shader record array (8-bytes alignment)
113 uint32_t _align_mbz[4]; // pad hardware section to 64 bytes
114 };