xref: /aosp_15_r20/external/mesa3d/src/intel/vulkan/grl/gpu/shared.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 //
2 // Copyright (C) 2009-2021 Intel Corporation
3 //
4 // SPDX-License-Identifier: MIT
5 //
6 //
7 
8 #include "GRLGen12.h"
9 #pragma once
10 
11 #define sizeof_Quad 64
12 #define sizeof_Procedural 64
13 #define sizeof_PrimRef 32
14 #define sizeof_PresplitItem 8
15 #define sizeof_HwInstanceLeaf 128
16 #define MORTON_BUILDER_SUBTREE_THRESHOLD 256
17 #define MORTON_BUILDER_P2_ELEMENTS_IN_SLM 16 * 1024 / 32
18 // Temporarily disable localized phase2 due to issues in ELG presi
19 // This implementation would be replaced with bottom_up + bounding box approach without the need for phase2 refit
20 #define MORTON_BUILDER_P2_SINGLE_WG_THRESHOLD /*100000*/ 0
21 
22 #define BVH_QUAD_NODE 4
23 #define BVH_INSTANCE_NODE 1
24 #define BVH_INTERNAL_NODE 0
25 #define BVH_PROCEDURAL_NODE 3
26 #define BUILDRECORD_STACK_SIZE 48
27 #define BINS 16
28 
29 GRL_NAMESPACE_BEGIN(GRL)
30 GRL_NAMESPACE_BEGIN(RTAS)
31 GRL_NAMESPACE_BEGIN(GPUBVHBuilder)
32 
33 struct AABB
34 {
35     float4 lower;
36     float4 upper;
37 };
38 
39 typedef struct BlockAllocator
40 {
41     unsigned int start;
42     unsigned int cur;
43 } BlockAllocator;
44 
45 struct Globals
46 {
47     struct AABB centroidBounds;
48 
49     unsigned int build_record_start;
50     unsigned int numPrimitives;
51     unsigned int leafPrimType;
52     unsigned int leafSize;
53 
54     unsigned int numSplittedPrimitives;
55     unsigned int numBuildRecords;
56 
57     // spatial split sate
58     unsigned int numOriginalPrimitives;
59     float presplitPrioritySum;
60     float probThreshold;
61 
62     // binned-sah bfs state
63     unsigned int counter;
64     unsigned int numBuildRecords_extended;
65 
66     // sync variable used for global-sync on work groups
67     unsigned int sync;
68 
69 
70     /* morton code builder state */
71     unsigned int shift;      // used by adaptive mc-builder
72     unsigned int shift_mask; // used by adaptive mc-builder
73     unsigned int binary_hierarchy_root;
74     unsigned int p0_allocated_num;
75     unsigned int p0_created_num;
76     unsigned int morton_sort_in_flight;
77     unsigned int sort_iterations;
78 
79     gpuva_t binary_hierarchy_buffer; // pointer to the binary morton code hierarchy.  Stashed here as a debug aid
80 };
81 
82 struct Range
83 {
84     unsigned int start, end;
85 };
86 
87 struct Triangle
88 {
89     unsigned int vtx[3];
90     //unsigned int primID;
91     //unsigned int geomID;
92 };
93 
94 struct MortonCodePrimitive
95 {
96     uint64_t index_code; // 64bit code + index combo
97 };
98 
99 struct BuildRecord
100 {
101     struct AABB centroidBounds;
102     unsigned int start, end;
103     __global void *current;
104 };
105 
106 struct BinaryMortonCodeHierarchy
107 {
108     struct Range range;
109     unsigned int leftChild;
110     unsigned int rightChild;
111    // unsigned int flag;
112 };
113 
114 typedef struct MortonFlattenedBoxlessNode {
115     uint binary_hierarchy_index; // only needed when type != BVH_INTERNAL_NODE
116     uint childOffset_type;       // childOffset : 26, type : 6
117     uint backPointer;            // same usage as in bvh
118 } MortonFlattenedBoxlessNode;
119 
120 struct StatStackEntry
121 {
122     struct AABB aabb;
123     unsigned int node;
124     unsigned int type;
125     unsigned int depth;
126     float area;
127 };
128 
129 struct BuildRecordMorton
130 {
131     unsigned int nodeID;
132     unsigned int items;
133     unsigned int current_index;
134     unsigned int parent_index;
135 };
136 
137 struct Split
138 {
139     float sah;
140     int dim;
141     int pos;
142 };
143 
144 struct BinMapping
145 {
146     float4 ofs, scale;
147 };
148 
149 struct BinInfo
150 {
151     struct AABB3f boundsX[BINS];
152     struct AABB3f boundsY[BINS];
153     struct AABB3f boundsZ[BINS];
154     uint3 counts[BINS];
155 };
156 
157 struct BinInfo2
158 {
159     struct AABB3f boundsX[BINS * 2];
160     struct AABB3f boundsY[BINS * 2];
161     struct AABB3f boundsZ[BINS * 2];
162     uint3 counts[BINS * 2];
163 };
164 
165 struct GlobalBuildRecord
166 {
167     struct BinInfo2 binInfo;
168     struct BinMapping binMapping;
169     struct Split split;
170     struct Range range;
171     struct AABB leftCentroid;
172     struct AABB rightCentroid;
173     struct AABB leftGeometry;
174     struct AABB rightGeometry;
175     unsigned int atomicCountLeft;
176     unsigned int atomicCountRight;
177     unsigned int buildRecordID;
178 };
179 
180 GRL_NAMESPACE_END(GPUBVHBuilder)
181 GRL_NAMESPACE_END(RTAS)
182 GRL_NAMESPACE_END(GRL)
183