xref: /aosp_15_r20/external/mesa3d/src/intel/compiler/brw_rt.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker  * Copyright © 2020 Intel Corporation
3*61046927SAndroid Build Coastguard Worker  *
4*61046927SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a
5*61046927SAndroid Build Coastguard Worker  * copy of this software and associated documentation files (the "Software"),
6*61046927SAndroid Build Coastguard Worker  * to deal in the Software without restriction, including without limitation
7*61046927SAndroid Build Coastguard Worker  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*61046927SAndroid Build Coastguard Worker  * and/or sell copies of the Software, and to permit persons to whom the
9*61046927SAndroid Build Coastguard Worker  * Software is furnished to do so, subject to the following conditions:
10*61046927SAndroid Build Coastguard Worker  *
11*61046927SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice (including the next
12*61046927SAndroid Build Coastguard Worker  * paragraph) shall be included in all copies or substantial portions of the
13*61046927SAndroid Build Coastguard Worker  * Software.
14*61046927SAndroid Build Coastguard Worker  *
15*61046927SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*61046927SAndroid Build Coastguard Worker  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*61046927SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*61046927SAndroid Build Coastguard Worker  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*61046927SAndroid Build Coastguard Worker  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*61046927SAndroid Build Coastguard Worker  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21*61046927SAndroid Build Coastguard Worker  * IN THE SOFTWARE.
22*61046927SAndroid Build Coastguard Worker  */
23*61046927SAndroid Build Coastguard Worker 
24*61046927SAndroid Build Coastguard Worker #ifndef BRW_RT_H
25*61046927SAndroid Build Coastguard Worker #define BRW_RT_H
26*61046927SAndroid Build Coastguard Worker 
27*61046927SAndroid Build Coastguard Worker #include <stdint.h>
28*61046927SAndroid Build Coastguard Worker 
29*61046927SAndroid Build Coastguard Worker #include "compiler/shader_enums.h"
30*61046927SAndroid Build Coastguard Worker #include "util/macros.h"
31*61046927SAndroid Build Coastguard Worker 
32*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
33*61046927SAndroid Build Coastguard Worker extern "C" {
34*61046927SAndroid Build Coastguard Worker #endif
35*61046927SAndroid Build Coastguard Worker 
36*61046927SAndroid Build Coastguard Worker /** Vulkan defines shaderGroupHandleSize = 32 */
37*61046927SAndroid Build Coastguard Worker #define BRW_RT_SBT_HANDLE_SIZE 32
38*61046927SAndroid Build Coastguard Worker 
39*61046927SAndroid Build Coastguard Worker /** RT_DISPATCH_GLOBALS size (see gen_rt.xml) */
40*61046927SAndroid Build Coastguard Worker #define BRW_RT_DISPATCH_GLOBALS_SIZE 80
41*61046927SAndroid Build Coastguard Worker 
42*61046927SAndroid Build Coastguard Worker /** Offset after the RT dispatch globals at which "push" constants live */
43*61046927SAndroid Build Coastguard Worker #define BRW_RT_PUSH_CONST_OFFSET 128
44*61046927SAndroid Build Coastguard Worker 
45*61046927SAndroid Build Coastguard Worker /** Stride of the resume SBT */
46*61046927SAndroid Build Coastguard Worker #define BRW_BTD_RESUME_SBT_STRIDE 8
47*61046927SAndroid Build Coastguard Worker 
48*61046927SAndroid Build Coastguard Worker /* Vulkan always uses exactly two levels of BVH: world and object.  At the API
49*61046927SAndroid Build Coastguard Worker  * level, these are referred to as top and bottom.
50*61046927SAndroid Build Coastguard Worker  */
51*61046927SAndroid Build Coastguard Worker enum brw_rt_bvh_level {
52*61046927SAndroid Build Coastguard Worker    BRW_RT_BVH_LEVEL_WORLD = 0,
53*61046927SAndroid Build Coastguard Worker    BRW_RT_BVH_LEVEL_OBJECT = 1,
54*61046927SAndroid Build Coastguard Worker };
55*61046927SAndroid Build Coastguard Worker #define BRW_RT_MAX_BVH_LEVELS 2
56*61046927SAndroid Build Coastguard Worker 
57*61046927SAndroid Build Coastguard Worker enum brw_rt_bvh_node_type {
58*61046927SAndroid Build Coastguard Worker    BRW_RT_BVH_NODE_TYPE_INTERNAL = 0,
59*61046927SAndroid Build Coastguard Worker    BRW_RT_BVH_NODE_TYPE_INSTANCE = 1,
60*61046927SAndroid Build Coastguard Worker    BRW_RT_BVH_NODE_TYPE_PROCEDURAL = 3,
61*61046927SAndroid Build Coastguard Worker    BRW_RT_BVH_NODE_TYPE_QUAD = 4,
62*61046927SAndroid Build Coastguard Worker };
63*61046927SAndroid Build Coastguard Worker 
64*61046927SAndroid Build Coastguard Worker /** HitKind values returned for triangle geometry
65*61046927SAndroid Build Coastguard Worker  *
66*61046927SAndroid Build Coastguard Worker  * This enum must match the SPIR-V enum.
67*61046927SAndroid Build Coastguard Worker  */
68*61046927SAndroid Build Coastguard Worker enum brw_rt_hit_kind {
69*61046927SAndroid Build Coastguard Worker    BRW_RT_HIT_KIND_FRONT_FACE = 0xfe,
70*61046927SAndroid Build Coastguard Worker    BRW_RT_HIT_KIND_BACK_FACE = 0xff,
71*61046927SAndroid Build Coastguard Worker };
72*61046927SAndroid Build Coastguard Worker 
73*61046927SAndroid Build Coastguard Worker /** Ray flags
74*61046927SAndroid Build Coastguard Worker  *
75*61046927SAndroid Build Coastguard Worker  * This enum must match the SPIR-V RayFlags enum.
76*61046927SAndroid Build Coastguard Worker  */
77*61046927SAndroid Build Coastguard Worker enum brw_rt_ray_flags {
78*61046927SAndroid Build Coastguard Worker    BRW_RT_RAY_FLAG_FORCE_OPAQUE                    = 0x01,
79*61046927SAndroid Build Coastguard Worker    BRW_RT_RAY_FLAG_FORCE_NON_OPAQUE                = 0x02,
80*61046927SAndroid Build Coastguard Worker    BRW_RT_RAY_FLAG_TERMINATE_ON_FIRST_HIT          = 0x04,
81*61046927SAndroid Build Coastguard Worker    BRW_RT_RAY_FLAG_SKIP_CLOSEST_HIT_SHADER         = 0x08,
82*61046927SAndroid Build Coastguard Worker    BRW_RT_RAY_FLAG_CULL_BACK_FACING_TRIANGLES      = 0x10,
83*61046927SAndroid Build Coastguard Worker    BRW_RT_RAY_FLAG_CULL_FRONT_FACING_TRIANGLES     = 0x20,
84*61046927SAndroid Build Coastguard Worker    BRW_RT_RAY_FLAG_CULL_OPAQUE                     = 0x40,
85*61046927SAndroid Build Coastguard Worker    BRW_RT_RAY_FLAG_CULL_NON_OPAQUE                 = 0x80,
86*61046927SAndroid Build Coastguard Worker    BRW_RT_RAY_FLAG_SKIP_TRIANGLES                  = 0x100,
87*61046927SAndroid Build Coastguard Worker    BRW_RT_RAY_FLAG_SKIP_AABBS                      = 0x200,
88*61046927SAndroid Build Coastguard Worker };
89*61046927SAndroid Build Coastguard Worker 
90*61046927SAndroid Build Coastguard Worker struct brw_rt_scratch_layout {
91*61046927SAndroid Build Coastguard Worker    /** Number of stack IDs per DSS */
92*61046927SAndroid Build Coastguard Worker    uint32_t stack_ids_per_dss;
93*61046927SAndroid Build Coastguard Worker 
94*61046927SAndroid Build Coastguard Worker    /** Start offset (in bytes) of the hardware MemRay stack */
95*61046927SAndroid Build Coastguard Worker    uint32_t ray_stack_start;
96*61046927SAndroid Build Coastguard Worker 
97*61046927SAndroid Build Coastguard Worker    /** Stride (in bytes) of the hardware MemRay stack */
98*61046927SAndroid Build Coastguard Worker    uint32_t ray_stack_stride;
99*61046927SAndroid Build Coastguard Worker 
100*61046927SAndroid Build Coastguard Worker    /** Start offset (in bytes) of the SW stacks */
101*61046927SAndroid Build Coastguard Worker    uint64_t sw_stack_start;
102*61046927SAndroid Build Coastguard Worker 
103*61046927SAndroid Build Coastguard Worker    /** Size (in bytes) of the SW stack for a single shader invocation */
104*61046927SAndroid Build Coastguard Worker    uint32_t sw_stack_size;
105*61046927SAndroid Build Coastguard Worker 
106*61046927SAndroid Build Coastguard Worker    /** Total size (in bytes) of the RT scratch memory area */
107*61046927SAndroid Build Coastguard Worker    uint64_t total_size;
108*61046927SAndroid Build Coastguard Worker };
109*61046927SAndroid Build Coastguard Worker 
110*61046927SAndroid Build Coastguard Worker /** Parameters passed to the raygen trampoline shader
111*61046927SAndroid Build Coastguard Worker  *
112*61046927SAndroid Build Coastguard Worker  * This struct is carefully construected to be 32B and must be passed to the
113*61046927SAndroid Build Coastguard Worker  * raygen trampoline shader as as inline constant data.
114*61046927SAndroid Build Coastguard Worker  */
115*61046927SAndroid Build Coastguard Worker struct brw_rt_raygen_trampoline_params {
116*61046927SAndroid Build Coastguard Worker    /** The GPU address of the RT_DISPATCH_GLOBALS */
117*61046927SAndroid Build Coastguard Worker    uint64_t rt_disp_globals_addr;
118*61046927SAndroid Build Coastguard Worker 
119*61046927SAndroid Build Coastguard Worker    /** The GPU address of the BINDLESS_SHADER_RECORD for the raygen shader */
120*61046927SAndroid Build Coastguard Worker    uint64_t raygen_bsr_addr;
121*61046927SAndroid Build Coastguard Worker 
122*61046927SAndroid Build Coastguard Worker    /** 1 if this is an indirect dispatch, 0 otherwise */
123*61046927SAndroid Build Coastguard Worker    uint8_t is_indirect;
124*61046927SAndroid Build Coastguard Worker 
125*61046927SAndroid Build Coastguard Worker    /** The integer log2 of the local group size
126*61046927SAndroid Build Coastguard Worker     *
127*61046927SAndroid Build Coastguard Worker     * Ray-tracing shaders don't have a concept of local vs. global workgroup
128*61046927SAndroid Build Coastguard Worker     * size.  They only have a single 3D launch size.  The raygen trampoline
129*61046927SAndroid Build Coastguard Worker     * shader is always dispatched with a local workgroup size equal to the
130*61046927SAndroid Build Coastguard Worker     * SIMD width but the shape of the local workgroup is determined at
131*61046927SAndroid Build Coastguard Worker     * dispatch time based on the shape of the launch and passed to the
132*61046927SAndroid Build Coastguard Worker     * trampoline via this field.  (There's no sense having a Z dimension on
133*61046927SAndroid Build Coastguard Worker     * the local workgroup if the launch is 2D.)
134*61046927SAndroid Build Coastguard Worker     *
135*61046927SAndroid Build Coastguard Worker     * We use the integer log2 of the size because there's no point in
136*61046927SAndroid Build Coastguard Worker     * non-power-of-two sizes and  shifts are cheaper than division.
137*61046927SAndroid Build Coastguard Worker     */
138*61046927SAndroid Build Coastguard Worker    uint8_t local_group_size_log2[3];
139*61046927SAndroid Build Coastguard Worker 
140*61046927SAndroid Build Coastguard Worker    uint32_t pad[3];
141*61046927SAndroid Build Coastguard Worker };
142*61046927SAndroid Build Coastguard Worker 
143*61046927SAndroid Build Coastguard Worker /** Size of the "hot zone" in bytes
144*61046927SAndroid Build Coastguard Worker  *
145*61046927SAndroid Build Coastguard Worker  * The hot zone is a SW-defined data structure which is a single uvec4
146*61046927SAndroid Build Coastguard Worker  * containing two bits of information:
147*61046927SAndroid Build Coastguard Worker  *
148*61046927SAndroid Build Coastguard Worker  *  - hotzone.x: Stack offset (in bytes)
149*61046927SAndroid Build Coastguard Worker  *
150*61046927SAndroid Build Coastguard Worker  *    This is the offset (in bytes) into the per-thread scratch space at which
151*61046927SAndroid Build Coastguard Worker  *    the current shader's stack starts.  This is incremented by the calling
152*61046927SAndroid Build Coastguard Worker  *    shader prior to any shader call type instructions and gets decremented
153*61046927SAndroid Build Coastguard Worker  *    by the resume shader as part of completing the return operation.
154*61046927SAndroid Build Coastguard Worker  *
155*61046927SAndroid Build Coastguard Worker  *
156*61046927SAndroid Build Coastguard Worker  *  - hotzone.yzw: The launch ID associated with the current thread
157*61046927SAndroid Build Coastguard Worker  *
158*61046927SAndroid Build Coastguard Worker  *    Inside a bindless shader, the only information we have is the DSS ID
159*61046927SAndroid Build Coastguard Worker  *    from the hardware EU and a per-DSS stack ID.  In particular, the three-
160*61046927SAndroid Build Coastguard Worker  *    dimensional launch ID is lost the moment we leave the raygen trampoline.
161*61046927SAndroid Build Coastguard Worker  */
162*61046927SAndroid Build Coastguard Worker #define BRW_RT_SIZEOF_HOTZONE 16
163*61046927SAndroid Build Coastguard Worker 
164*61046927SAndroid Build Coastguard Worker /* From the BSpec "Address Computation for Memory Based Data Structures:
165*61046927SAndroid Build Coastguard Worker  * Ray and TraversalStack (Async Ray Tracing)":
166*61046927SAndroid Build Coastguard Worker  *
167*61046927SAndroid Build Coastguard Worker  *    sizeof(Ray) = 64B, sizeof(HitInfo) = 32B, sizeof(TravStack) = 32B.
168*61046927SAndroid Build Coastguard Worker  */
169*61046927SAndroid Build Coastguard Worker #define BRW_RT_SIZEOF_RAY 64
170*61046927SAndroid Build Coastguard Worker #define BRW_RT_SIZEOF_HIT_INFO 32
171*61046927SAndroid Build Coastguard Worker #define BRW_RT_SIZEOF_TRAV_STACK 32
172*61046927SAndroid Build Coastguard Worker 
173*61046927SAndroid Build Coastguard Worker /* From the BSpec:
174*61046927SAndroid Build Coastguard Worker  *
175*61046927SAndroid Build Coastguard Worker  *    syncStackSize = (maxBVHLevels % 2 == 1) ?
176*61046927SAndroid Build Coastguard Worker  *       (sizeof(HitInfo) * 2 +
177*61046927SAndroid Build Coastguard Worker  *          (sizeof(Ray) + sizeof(TravStack)) * maxBVHLevels + 32B) :
178*61046927SAndroid Build Coastguard Worker  *       (sizeof(HitInfo) * 2 +
179*61046927SAndroid Build Coastguard Worker  *          (sizeof(Ray) + sizeof(TravStack)) * maxBVHLevels);
180*61046927SAndroid Build Coastguard Worker  *
181*61046927SAndroid Build Coastguard Worker  * The select is just to align to 64B.
182*61046927SAndroid Build Coastguard Worker  */
183*61046927SAndroid Build Coastguard Worker #define BRW_RT_SIZEOF_RAY_QUERY \
184*61046927SAndroid Build Coastguard Worker    (BRW_RT_SIZEOF_HIT_INFO * 2 + \
185*61046927SAndroid Build Coastguard Worker     (BRW_RT_SIZEOF_RAY + BRW_RT_SIZEOF_TRAV_STACK) * BRW_RT_MAX_BVH_LEVELS + \
186*61046927SAndroid Build Coastguard Worker     (BRW_RT_MAX_BVH_LEVELS % 2 ? 32 : 0))
187*61046927SAndroid Build Coastguard Worker 
188*61046927SAndroid Build Coastguard Worker #define BRW_RT_SIZEOF_SHADOW_RAY_QUERY  \
189*61046927SAndroid Build Coastguard Worker    (BRW_RT_SIZEOF_HIT_INFO * 2 + \
190*61046927SAndroid Build Coastguard Worker     (BRW_RT_SIZEOF_RAY + BRW_RT_SIZEOF_TRAV_STACK) * BRW_RT_MAX_BVH_LEVELS)
191*61046927SAndroid Build Coastguard Worker 
192*61046927SAndroid Build Coastguard Worker #define BRW_RT_SIZEOF_HW_STACK \
193*61046927SAndroid Build Coastguard Worker    (BRW_RT_SIZEOF_HIT_INFO * 2 + \
194*61046927SAndroid Build Coastguard Worker     BRW_RT_SIZEOF_RAY * BRW_RT_MAX_BVH_LEVELS + \
195*61046927SAndroid Build Coastguard Worker     BRW_RT_SIZEOF_TRAV_STACK * BRW_RT_MAX_BVH_LEVELS)
196*61046927SAndroid Build Coastguard Worker 
197*61046927SAndroid Build Coastguard Worker /* This is a mesa-defined region for hit attribute data */
198*61046927SAndroid Build Coastguard Worker #define BRW_RT_SIZEOF_HIT_ATTRIB_DATA 64
199*61046927SAndroid Build Coastguard Worker #define BRW_RT_OFFSETOF_HIT_ATTRIB_DATA BRW_RT_SIZEOF_HW_STACK
200*61046927SAndroid Build Coastguard Worker 
201*61046927SAndroid Build Coastguard Worker #define BRW_RT_ASYNC_STACK_STRIDE \
202*61046927SAndroid Build Coastguard Worker    ALIGN_POT(BRW_RT_OFFSETOF_HIT_ATTRIB_DATA + \
203*61046927SAndroid Build Coastguard Worker              BRW_RT_SIZEOF_HIT_ATTRIB_DATA, 64)
204*61046927SAndroid Build Coastguard Worker 
205*61046927SAndroid Build Coastguard Worker static inline void
brw_rt_compute_scratch_layout(struct brw_rt_scratch_layout * layout,const struct intel_device_info * devinfo,uint32_t stack_ids_per_dss,uint32_t sw_stack_size)206*61046927SAndroid Build Coastguard Worker brw_rt_compute_scratch_layout(struct brw_rt_scratch_layout *layout,
207*61046927SAndroid Build Coastguard Worker                               const struct intel_device_info *devinfo,
208*61046927SAndroid Build Coastguard Worker                               uint32_t stack_ids_per_dss,
209*61046927SAndroid Build Coastguard Worker                               uint32_t sw_stack_size)
210*61046927SAndroid Build Coastguard Worker {
211*61046927SAndroid Build Coastguard Worker    layout->stack_ids_per_dss = stack_ids_per_dss;
212*61046927SAndroid Build Coastguard Worker 
213*61046927SAndroid Build Coastguard Worker    const uint32_t dss_count = intel_device_info_dual_subslice_id_bound(devinfo);
214*61046927SAndroid Build Coastguard Worker    const uint32_t num_stack_ids = dss_count * stack_ids_per_dss;
215*61046927SAndroid Build Coastguard Worker 
216*61046927SAndroid Build Coastguard Worker    uint64_t size = 0;
217*61046927SAndroid Build Coastguard Worker 
218*61046927SAndroid Build Coastguard Worker    /* The first thing in our scratch area is an array of "hot zones" which
219*61046927SAndroid Build Coastguard Worker     * store the stack offset as well as the launch IDs for each active
220*61046927SAndroid Build Coastguard Worker     * invocation.
221*61046927SAndroid Build Coastguard Worker     */
222*61046927SAndroid Build Coastguard Worker    size += BRW_RT_SIZEOF_HOTZONE * num_stack_ids;
223*61046927SAndroid Build Coastguard Worker 
224*61046927SAndroid Build Coastguard Worker    /* Next, we place the HW ray stacks */
225*61046927SAndroid Build Coastguard Worker    assert(size % 64 == 0); /* Cache-line aligned */
226*61046927SAndroid Build Coastguard Worker    assert(size < UINT32_MAX);
227*61046927SAndroid Build Coastguard Worker    layout->ray_stack_start = size;
228*61046927SAndroid Build Coastguard Worker    layout->ray_stack_stride = BRW_RT_ASYNC_STACK_STRIDE;
229*61046927SAndroid Build Coastguard Worker    size += num_stack_ids * layout->ray_stack_stride;
230*61046927SAndroid Build Coastguard Worker 
231*61046927SAndroid Build Coastguard Worker    /* Finally, we place the SW stacks for the individual ray-tracing shader
232*61046927SAndroid Build Coastguard Worker     * invocations.  We align these to 64B to ensure that we don't have any
233*61046927SAndroid Build Coastguard Worker     * shared cache lines which could hurt performance.
234*61046927SAndroid Build Coastguard Worker     */
235*61046927SAndroid Build Coastguard Worker    assert(size % 64 == 0);
236*61046927SAndroid Build Coastguard Worker    layout->sw_stack_start = size;
237*61046927SAndroid Build Coastguard Worker    layout->sw_stack_size = ALIGN(sw_stack_size, 64);
238*61046927SAndroid Build Coastguard Worker 
239*61046927SAndroid Build Coastguard Worker    /* Currently it's always the case that sw_stack_size is a power of
240*61046927SAndroid Build Coastguard Worker     * two, but power-of-two SW stack sizes are prone to causing
241*61046927SAndroid Build Coastguard Worker     * collisions in the hashing function used by the L3 to map memory
242*61046927SAndroid Build Coastguard Worker     * addresses to banks, which can cause stack accesses from most
243*61046927SAndroid Build Coastguard Worker     * DSSes to bottleneck on a single L3 bank.  Fix it by padding the
244*61046927SAndroid Build Coastguard Worker     * SW stack by a single cacheline if it was a power of two.
245*61046927SAndroid Build Coastguard Worker     */
246*61046927SAndroid Build Coastguard Worker    if (layout->sw_stack_size > 64 &&
247*61046927SAndroid Build Coastguard Worker        util_is_power_of_two_nonzero(layout->sw_stack_size))
248*61046927SAndroid Build Coastguard Worker       layout->sw_stack_size += 64;
249*61046927SAndroid Build Coastguard Worker 
250*61046927SAndroid Build Coastguard Worker    size += num_stack_ids * layout->sw_stack_size;
251*61046927SAndroid Build Coastguard Worker 
252*61046927SAndroid Build Coastguard Worker    layout->total_size = size;
253*61046927SAndroid Build Coastguard Worker }
254*61046927SAndroid Build Coastguard Worker 
255*61046927SAndroid Build Coastguard Worker static inline uint32_t
brw_rt_ray_queries_hw_stacks_size(const struct intel_device_info * devinfo)256*61046927SAndroid Build Coastguard Worker brw_rt_ray_queries_hw_stacks_size(const struct intel_device_info *devinfo)
257*61046927SAndroid Build Coastguard Worker {
258*61046927SAndroid Build Coastguard Worker    /* Maximum slice/subslice/EU ID can be computed from the max_scratch_ids
259*61046927SAndroid Build Coastguard Worker     * which includes all the threads.
260*61046927SAndroid Build Coastguard Worker     */
261*61046927SAndroid Build Coastguard Worker    uint32_t max_eu_id = devinfo->max_scratch_ids[MESA_SHADER_COMPUTE];
262*61046927SAndroid Build Coastguard Worker    uint32_t max_simd_size = 16; /* Cannot run in SIMD32 with ray queries */
263*61046927SAndroid Build Coastguard Worker    return max_eu_id * max_simd_size * BRW_RT_SIZEOF_RAY_QUERY;
264*61046927SAndroid Build Coastguard Worker }
265*61046927SAndroid Build Coastguard Worker 
266*61046927SAndroid Build Coastguard Worker static inline uint32_t
brw_rt_ray_queries_shadow_stack_size(const struct intel_device_info * devinfo)267*61046927SAndroid Build Coastguard Worker brw_rt_ray_queries_shadow_stack_size(const struct intel_device_info *devinfo)
268*61046927SAndroid Build Coastguard Worker {
269*61046927SAndroid Build Coastguard Worker    /* Maximum slice/subslice/EU ID can be computed from the max_scratch_ids
270*61046927SAndroid Build Coastguard Worker     * which includes all the threads.
271*61046927SAndroid Build Coastguard Worker     */
272*61046927SAndroid Build Coastguard Worker    uint32_t max_eu_id = devinfo->max_scratch_ids[MESA_SHADER_COMPUTE];
273*61046927SAndroid Build Coastguard Worker    uint32_t max_simd_size = 16; /* Cannot run in SIMD32 with ray queries */
274*61046927SAndroid Build Coastguard Worker    return max_eu_id * max_simd_size * BRW_RT_SIZEOF_SHADOW_RAY_QUERY;
275*61046927SAndroid Build Coastguard Worker }
276*61046927SAndroid Build Coastguard Worker 
277*61046927SAndroid Build Coastguard Worker static inline uint32_t
brw_rt_ray_queries_shadow_stacks_size(const struct intel_device_info * devinfo,uint32_t ray_queries)278*61046927SAndroid Build Coastguard Worker brw_rt_ray_queries_shadow_stacks_size(const struct intel_device_info *devinfo,
279*61046927SAndroid Build Coastguard Worker                                       uint32_t ray_queries)
280*61046927SAndroid Build Coastguard Worker {
281*61046927SAndroid Build Coastguard Worker    /* Don't bother a shadow stack if we only have a single query. We can
282*61046927SAndroid Build Coastguard Worker     * directly write in the HW buffer.
283*61046927SAndroid Build Coastguard Worker     */
284*61046927SAndroid Build Coastguard Worker    return (ray_queries > 1 ? ray_queries : 0) * brw_rt_ray_queries_shadow_stack_size(devinfo) +
285*61046927SAndroid Build Coastguard Worker           ray_queries * 4; /* Ctrl + Level data */
286*61046927SAndroid Build Coastguard Worker }
287*61046927SAndroid Build Coastguard Worker 
288*61046927SAndroid Build Coastguard Worker #ifdef __cplusplus
289*61046927SAndroid Build Coastguard Worker }
290*61046927SAndroid Build Coastguard Worker #endif
291*61046927SAndroid Build Coastguard Worker 
292*61046927SAndroid Build Coastguard Worker #endif /* BRW_RT_H */
293