1/*
2 * Copyright (C) 2016 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24
25/* Instructions, enums and structures for RT.
26 *
27 * This file has been generated, do not hand edit.
28 */
29
30#ifndef GFX_PACK_H
31#define GFX_PACK_H
32
33#include <stdio.h>
34#include <stdint.h>
35#include <stdbool.h>
36#include <assert.h>
37#include <math.h>
38
39#ifndef __gen_validate_value
40#define __gen_validate_value(x)
41#endif
42
43#ifndef __intel_field_functions
44#define __intel_field_functions
45
46#ifdef NDEBUG
47#define NDEBUG_UNUSED __attribute__((unused))
48#else
49#define NDEBUG_UNUSED
50#endif
51
52union __intel_value {
53   float f;
54   uint32_t dw;
55};
56
57static inline __attribute__((always_inline)) uint64_t
58__gen_mbo(uint32_t start, uint32_t end)
59{
60   return (~0ull >> (64 - (end - start + 1))) << start;
61}
62
63static inline __attribute__((always_inline)) uint64_t
64__gen_uint(uint64_t v, uint32_t start, NDEBUG_UNUSED uint32_t end)
65{
66   __gen_validate_value(v);
67
68#ifndef NDEBUG
69   const int width = end - start + 1;
70   if (width < 64) {
71      const uint64_t max = (1ull << width) - 1;
72      assert(v <= max);
73   }
74#endif
75
76   return v << start;
77}
78
79static inline __attribute__((always_inline)) uint64_t
80__gen_sint(int64_t v, uint32_t start, uint32_t end)
81{
82   const int width = end - start + 1;
83
84   __gen_validate_value(v);
85
86#ifndef NDEBUG
87   if (width < 64) {
88      const int64_t max = (1ll << (width - 1)) - 1;
89      const int64_t min = -(1ll << (width - 1));
90      assert(min <= v && v <= max);
91   }
92#endif
93
94   const uint64_t mask = ~0ull >> (64 - width);
95
96   return (v & mask) << start;
97}
98
99static inline __attribute__((always_inline)) uint64_t
100__gen_offset(uint64_t v, NDEBUG_UNUSED uint32_t start, NDEBUG_UNUSED uint32_t end)
101{
102   __gen_validate_value(v);
103#ifndef NDEBUG
104   uint64_t mask = (~0ull >> (64 - (end - start + 1))) << start;
105
106   assert((v & ~mask) == 0);
107#endif
108
109   return v;
110}
111
112static inline __attribute__((always_inline)) uint64_t
113__gen_address(__gen_user_data *data, void *location,
114              __gen_address_type address, uint32_t delta,
115              __attribute__((unused)) uint32_t start, uint32_t end)
116{
117   uint64_t addr_u64 = __gen_combine_address(data, location, address, delta);
118   if (end == 31) {
119      return addr_u64;
120   } else if (end < 63) {
121      const unsigned shift = 63 - end;
122      return (addr_u64 << shift) >> shift;
123   } else {
124      return addr_u64;
125   }
126}
127
128static inline __attribute__((always_inline)) uint32_t
129__gen_float(float v)
130{
131   __gen_validate_value(v);
132   return ((union __intel_value) { .f = (v) }).dw;
133}
134
135static inline __attribute__((always_inline)) uint64_t
136__gen_sfixed(float v, uint32_t start, uint32_t end, uint32_t fract_bits)
137{
138   __gen_validate_value(v);
139
140   const float factor = (1 << fract_bits);
141
142#ifndef NDEBUG
143   const float max = ((1 << (end - start)) - 1) / factor;
144   const float min = -(1 << (end - start)) / factor;
145   assert(min <= v && v <= max);
146#endif
147
148   const int64_t int_val = llroundf(v * factor);
149   const uint64_t mask = ~0ull >> (64 - (end - start + 1));
150
151   return (int_val & mask) << start;
152}
153
154static inline __attribute__((always_inline)) uint64_t
155__gen_ufixed(float v, uint32_t start, NDEBUG_UNUSED uint32_t end, uint32_t fract_bits)
156{
157   __gen_validate_value(v);
158
159   const float factor = (1 << fract_bits);
160
161#ifndef NDEBUG
162   const float max = ((1 << (end - start + 1)) - 1) / factor;
163   const float min = 0.0f;
164   assert(min <= v && v <= max);
165#endif
166
167   const uint64_t uint_val = llroundf(v * factor);
168
169   return uint_val << start;
170}
171
172#ifndef __gen_address_type
173#error #define __gen_address_type before including this file
174#endif
175
176#ifndef __gen_user_data
177#error #define __gen_combine_address before including this file
178#endif
179
180#undef NDEBUG_UNUSED
181
182#endif
183
184
185#define GFX_BINDLESS_SHADER_RECORD_length      2
186struct GFX_BINDLESS_SHADER_RECORD {
187   uint32_t                             OffsetToLocalArguments;
188   uint32_t                             BindlessShaderDispatchMode;
189#define RT_SIMD16                                0
190#define RT_SIMD8                                 1
191   uint64_t                             KernelStartPointer;
192};
193
194static inline __attribute__((always_inline)) void
195GFX_BINDLESS_SHADER_RECORD_pack(__attribute__((unused)) __gen_user_data *data,
196                                __attribute__((unused)) void * restrict dst,
197                                __attribute__((unused)) const struct GFX_BINDLESS_SHADER_RECORD * restrict values)
198{
199   uint32_t * restrict dw = (uint32_t * restrict) dst;
200
201   dw[0] =
202      __gen_uint(values->OffsetToLocalArguments, 0, 2) |
203      __gen_uint(values->BindlessShaderDispatchMode, 4, 4) |
204      __gen_offset(values->KernelStartPointer, 6, 31);
205
206   dw[1] = 0;
207}
208
209#define GFX_RT_GENERAL_SBT_HANDLE_length       8
210struct GFX_RT_GENERAL_SBT_HANDLE {
211   struct GFX_BINDLESS_SHADER_RECORD    General;
212};
213
214static inline __attribute__((always_inline)) void
215GFX_RT_GENERAL_SBT_HANDLE_pack(__attribute__((unused)) __gen_user_data *data,
216                               __attribute__((unused)) void * restrict dst,
217                               __attribute__((unused)) const struct GFX_RT_GENERAL_SBT_HANDLE * restrict values)
218{
219   uint32_t * restrict dw = (uint32_t * restrict) dst;
220
221   GFX_BINDLESS_SHADER_RECORD_pack(data, &dw[0], &values->General);
222
223   dw[2] = 0;
224
225   dw[3] = 0;
226
227   dw[4] = 0;
228
229   dw[5] = 0;
230
231   dw[6] = 0;
232
233   dw[7] = 0;
234}
235
236#define GFX_RT_TRIANGLES_SBT_HANDLE_length      8
237struct GFX_RT_TRIANGLES_SBT_HANDLE {
238   struct GFX_BINDLESS_SHADER_RECORD    ClosestHit;
239   struct GFX_BINDLESS_SHADER_RECORD    AnyHit;
240};
241
242static inline __attribute__((always_inline)) void
243GFX_RT_TRIANGLES_SBT_HANDLE_pack(__attribute__((unused)) __gen_user_data *data,
244                                 __attribute__((unused)) void * restrict dst,
245                                 __attribute__((unused)) const struct GFX_RT_TRIANGLES_SBT_HANDLE * restrict values)
246{
247   uint32_t * restrict dw = (uint32_t * restrict) dst;
248
249   GFX_BINDLESS_SHADER_RECORD_pack(data, &dw[0], &values->ClosestHit);
250
251   GFX_BINDLESS_SHADER_RECORD_pack(data, &dw[2], &values->AnyHit);
252
253   dw[4] = 0;
254
255   dw[5] = 0;
256
257   dw[6] = 0;
258
259   dw[7] = 0;
260}
261
262#define GFX_RT_PROCEDURAL_SBT_HANDLE_length      8
263struct GFX_RT_PROCEDURAL_SBT_HANDLE {
264   struct GFX_BINDLESS_SHADER_RECORD    ClosestHit;
265   struct GFX_BINDLESS_SHADER_RECORD    Intersection;
266};
267
268static inline __attribute__((always_inline)) void
269GFX_RT_PROCEDURAL_SBT_HANDLE_pack(__attribute__((unused)) __gen_user_data *data,
270                                  __attribute__((unused)) void * restrict dst,
271                                  __attribute__((unused)) const struct GFX_RT_PROCEDURAL_SBT_HANDLE * restrict values)
272{
273   uint32_t * restrict dw = (uint32_t * restrict) dst;
274
275   GFX_BINDLESS_SHADER_RECORD_pack(data, &dw[0], &values->ClosestHit);
276
277   GFX_BINDLESS_SHADER_RECORD_pack(data, &dw[2], &values->Intersection);
278
279   dw[4] = 0;
280
281   dw[5] = 0;
282
283   dw[6] = 0;
284
285   dw[7] = 0;
286}
287
288#define GFX_RT_SHADER_TABLE_length             2
289struct GFX_RT_SHADER_TABLE {
290   __gen_address_type                   BaseAddress;
291   uint32_t                             Stride;
292};
293
294static inline __attribute__((always_inline)) void
295GFX_RT_SHADER_TABLE_pack(__attribute__((unused)) __gen_user_data *data,
296                         __attribute__((unused)) void * restrict dst,
297                         __attribute__((unused)) const struct GFX_RT_SHADER_TABLE * restrict values)
298{
299   uint32_t * restrict dw = (uint32_t * restrict) dst;
300
301   const uint64_t v0 =
302      __gen_uint(values->Stride, 48, 63);
303   const uint64_t v0_address =
304      __gen_address(data, &dw[0], values->BaseAddress, v0, 0, 47);
305   dw[0] = v0_address;
306   dw[1] = (v0_address >> 32) | (v0 >> 32);
307}
308
309#define GFX_RT_DISPATCH_GLOBALS_length        20
310struct GFX_RT_DISPATCH_GLOBALS {
311   __gen_address_type                   MemBaseAddress;
312   struct GFX_BINDLESS_SHADER_RECORD    CallStackHandler;
313   uint32_t                             AsyncRTStackSize;
314   uint32_t                             NumDSSRTStacks;
315   uint32_t                             MaxBVHLevels;
316   uint32_t                             Flags;
317#define RT_DEPTH_TEST_LESS_EQUAL                 1
318   struct GFX_RT_SHADER_TABLE           HitGroupTable;
319   struct GFX_RT_SHADER_TABLE           MissGroupTable;
320   uint32_t                             SWStackSize;
321   uint32_t                             LaunchWidth;
322   uint32_t                             LaunchHeight;
323   uint32_t                             LaunchDepth;
324   struct GFX_RT_SHADER_TABLE           CallableGroupTable;
325   __gen_address_type                   ResumeShaderTable;
326};
327
328static inline __attribute__((always_inline)) void
329GFX_RT_DISPATCH_GLOBALS_pack(__attribute__((unused)) __gen_user_data *data,
330                             __attribute__((unused)) void * restrict dst,
331                             __attribute__((unused)) const struct GFX_RT_DISPATCH_GLOBALS * restrict values)
332{
333   uint32_t * restrict dw = (uint32_t * restrict) dst;
334
335   const uint64_t v0_address =
336      __gen_address(data, &dw[0], values->MemBaseAddress, 0, 0, 63);
337   dw[0] = v0_address;
338   dw[1] = v0_address >> 32;
339
340   GFX_BINDLESS_SHADER_RECORD_pack(data, &dw[2], &values->CallStackHandler);
341
342   dw[4] =
343      __gen_uint(values->AsyncRTStackSize, 0, 31);
344
345   dw[5] =
346      __gen_uint(values->NumDSSRTStacks, 0, 15);
347
348   dw[6] =
349      __gen_uint(values->MaxBVHLevels, 0, 2);
350
351   dw[7] =
352      __gen_uint(values->Flags, 0, 0);
353
354   GFX_RT_SHADER_TABLE_pack(data, &dw[8], &values->HitGroupTable);
355
356   GFX_RT_SHADER_TABLE_pack(data, &dw[10], &values->MissGroupTable);
357
358   dw[12] =
359      __gen_uint(values->SWStackSize, 0, 31);
360
361   dw[13] =
362      __gen_uint(values->LaunchWidth, 0, 31);
363
364   dw[14] =
365      __gen_uint(values->LaunchHeight, 0, 31);
366
367   dw[15] =
368      __gen_uint(values->LaunchDepth, 0, 31);
369
370   GFX_RT_SHADER_TABLE_pack(data, &dw[16], &values->CallableGroupTable);
371
372   const uint64_t v18_address =
373      __gen_address(data, &dw[18], values->ResumeShaderTable, 0, 0, 63);
374   dw[18] = v18_address;
375   dw[19] = v18_address >> 32;
376}
377
378#define GFX_RT_BVH_VEC3_length                 3
379struct GFX_RT_BVH_VEC3 {
380   float                                X;
381   float                                Y;
382   float                                Z;
383};
384
385static inline __attribute__((always_inline)) void
386GFX_RT_BVH_VEC3_pack(__attribute__((unused)) __gen_user_data *data,
387                     __attribute__((unused)) void * restrict dst,
388                     __attribute__((unused)) const struct GFX_RT_BVH_VEC3 * restrict values)
389{
390   uint32_t * restrict dw = (uint32_t * restrict) dst;
391
392   dw[0] =
393      __gen_float(values->X);
394
395   dw[1] =
396      __gen_float(values->Y);
397
398   dw[2] =
399      __gen_float(values->Z);
400}
401
402#define GFX_RT_BVH_length                     16
403struct GFX_RT_BVH {
404   uint64_t                             RootNodeOffset;
405   struct GFX_RT_BVH_VEC3               BoundsMin;
406   struct GFX_RT_BVH_VEC3               BoundsMax;
407};
408
409static inline __attribute__((always_inline)) void
410GFX_RT_BVH_pack(__attribute__((unused)) __gen_user_data *data,
411                __attribute__((unused)) void * restrict dst,
412                __attribute__((unused)) const struct GFX_RT_BVH * restrict values)
413{
414   uint32_t * restrict dw = (uint32_t * restrict) dst;
415
416   const uint64_t v0 =
417      __gen_offset(values->RootNodeOffset, 0, 63);
418   dw[0] = v0;
419   dw[1] = v0 >> 32;
420
421   GFX_RT_BVH_VEC3_pack(data, &dw[2], &values->BoundsMin);
422
423   GFX_RT_BVH_VEC3_pack(data, &dw[5], &values->BoundsMax);
424
425   dw[8] = 0;
426
427   dw[9] = 0;
428
429   dw[10] = 0;
430
431   dw[11] = 0;
432
433   dw[12] = 0;
434
435   dw[13] = 0;
436
437   dw[14] = 0;
438
439   dw[15] = 0;
440}
441
442#define GFX_RT_BVH_INTERNAL_NODE_length       16
443struct GFX_RT_BVH_INTERNAL_NODE {
444   struct GFX_RT_BVH_VEC3               Origin;
445   int32_t                              ChildOffset;
446   uint32_t                             NodeType;
447#define NODE_TYPE_INTERNAL                       0
448#define NODE_TYPE_INSTANCE                       1
449#define NODE_TYPE_PROCEDURAL                     3
450#define NODE_TYPE_QUAD                           4
451#define NODE_TYPE_INVALID                        7
452   int32_t                              ChildBoundsExponentX;
453   int32_t                              ChildBoundsExponentY;
454   int32_t                              ChildBoundsExponentZ;
455   uint32_t                             NodeRayMask;
456   uint32_t                             ChildSize[6];
457   uint32_t                             ChildType[6];
458   uint32_t                             StartPrimitive[6];
459   uint32_t                             ChildLowerXBound[6];
460   uint32_t                             ChildUpperXBound[6];
461   uint32_t                             ChildLowerYBound[6];
462   uint32_t                             ChildUpperYBound[6];
463   uint32_t                             ChildLowerZBound[6];
464   uint32_t                             ChildUpperZBound[6];
465};
466
467static inline __attribute__((always_inline)) void
468GFX_RT_BVH_INTERNAL_NODE_pack(__attribute__((unused)) __gen_user_data *data,
469                              __attribute__((unused)) void * restrict dst,
470                              __attribute__((unused)) const struct GFX_RT_BVH_INTERNAL_NODE * restrict values)
471{
472   uint32_t * restrict dw = (uint32_t * restrict) dst;
473
474   GFX_RT_BVH_VEC3_pack(data, &dw[0], &values->Origin);
475
476   dw[3] =
477      __gen_sint(values->ChildOffset, 0, 31);
478
479   dw[4] =
480      __gen_uint(values->NodeType, 0, 7) |
481      __gen_sint(values->ChildBoundsExponentX, 16, 23) |
482      __gen_sint(values->ChildBoundsExponentY, 24, 31);
483
484   dw[5] =
485      __gen_sint(values->ChildBoundsExponentZ, 0, 8) |
486      __gen_uint(values->NodeRayMask, 8, 15) |
487      __gen_uint(values->ChildSize[0], 16, 17) |
488      __gen_uint(values->ChildType[0], 18, 21) |
489      __gen_uint(values->StartPrimitive[0], 18, 21) |
490      __gen_uint(values->ChildSize[1], 24, 25) |
491      __gen_uint(values->ChildType[1], 26, 29) |
492      __gen_uint(values->StartPrimitive[1], 26, 29);
493
494   dw[6] =
495      __gen_uint(values->ChildSize[2], 0, 1) |
496      __gen_uint(values->ChildType[2], 2, 5) |
497      __gen_uint(values->StartPrimitive[2], 2, 5) |
498      __gen_uint(values->ChildSize[3], 8, 9) |
499      __gen_uint(values->ChildType[3], 10, 13) |
500      __gen_uint(values->StartPrimitive[3], 10, 13) |
501      __gen_uint(values->ChildSize[4], 16, 17) |
502      __gen_uint(values->ChildType[4], 18, 21) |
503      __gen_uint(values->StartPrimitive[4], 18, 21) |
504      __gen_uint(values->ChildSize[5], 24, 25) |
505      __gen_uint(values->ChildType[5], 26, 29) |
506      __gen_uint(values->StartPrimitive[5], 26, 29);
507
508   dw[7] =
509      __gen_uint(values->ChildLowerXBound[0], 0, 7) |
510      __gen_uint(values->ChildLowerXBound[1], 8, 15) |
511      __gen_uint(values->ChildLowerXBound[2], 16, 23) |
512      __gen_uint(values->ChildLowerXBound[3], 24, 31);
513
514   dw[8] =
515      __gen_uint(values->ChildLowerXBound[4], 0, 7) |
516      __gen_uint(values->ChildLowerXBound[5], 8, 15) |
517      __gen_uint(values->ChildUpperXBound[0], 16, 23) |
518      __gen_uint(values->ChildUpperXBound[1], 24, 31);
519
520   dw[9] =
521      __gen_uint(values->ChildUpperXBound[2], 0, 7) |
522      __gen_uint(values->ChildUpperXBound[3], 8, 15) |
523      __gen_uint(values->ChildUpperXBound[4], 16, 23) |
524      __gen_uint(values->ChildUpperXBound[5], 24, 31);
525
526   dw[10] =
527      __gen_uint(values->ChildLowerYBound[0], 0, 7) |
528      __gen_uint(values->ChildLowerYBound[1], 8, 15) |
529      __gen_uint(values->ChildLowerYBound[2], 16, 23) |
530      __gen_uint(values->ChildLowerYBound[3], 24, 31);
531
532   dw[11] =
533      __gen_uint(values->ChildLowerYBound[4], 0, 7) |
534      __gen_uint(values->ChildLowerYBound[5], 8, 15) |
535      __gen_uint(values->ChildUpperYBound[0], 16, 23) |
536      __gen_uint(values->ChildUpperYBound[1], 24, 31);
537
538   dw[12] =
539      __gen_uint(values->ChildUpperYBound[2], 0, 7) |
540      __gen_uint(values->ChildUpperYBound[3], 8, 15) |
541      __gen_uint(values->ChildUpperYBound[4], 16, 23) |
542      __gen_uint(values->ChildUpperYBound[5], 24, 31);
543
544   dw[13] =
545      __gen_uint(values->ChildLowerZBound[0], 0, 7) |
546      __gen_uint(values->ChildLowerZBound[1], 8, 15) |
547      __gen_uint(values->ChildLowerZBound[2], 16, 23) |
548      __gen_uint(values->ChildLowerZBound[3], 24, 31);
549
550   dw[14] =
551      __gen_uint(values->ChildLowerZBound[4], 0, 7) |
552      __gen_uint(values->ChildLowerZBound[5], 8, 15) |
553      __gen_uint(values->ChildUpperZBound[0], 16, 23) |
554      __gen_uint(values->ChildUpperZBound[1], 24, 31);
555
556   dw[15] =
557      __gen_uint(values->ChildUpperZBound[2], 0, 7) |
558      __gen_uint(values->ChildUpperZBound[3], 8, 15) |
559      __gen_uint(values->ChildUpperZBound[4], 16, 23) |
560      __gen_uint(values->ChildUpperZBound[5], 24, 31);
561}
562
563#define GFX_RT_BVH_PRIMITIVE_LEAF_DESCRIPTOR_length      2
564struct GFX_RT_BVH_PRIMITIVE_LEAF_DESCRIPTOR {
565   uint32_t                             ShaderIndex;
566   uint32_t                             GeometryRayMask;
567   uint32_t                             GeometryIndex;
568   uint32_t                             LeafType;
569#define TYPE_QUAD                                0
570#define TYPE_OPAQUE_CULLING_ENABLED              0
571#define TYPE_OPAQUE_CULLING_DISABLED             1
572   uint32_t                             GeometryFlags;
573#define GEOMETRY_OPAQUE                          1
574};
575
576static inline __attribute__((always_inline)) void
577GFX_RT_BVH_PRIMITIVE_LEAF_DESCRIPTOR_pack(__attribute__((unused)) __gen_user_data *data,
578                                          __attribute__((unused)) void * restrict dst,
579                                          __attribute__((unused)) const struct GFX_RT_BVH_PRIMITIVE_LEAF_DESCRIPTOR * restrict values)
580{
581   uint32_t * restrict dw = (uint32_t * restrict) dst;
582
583   dw[0] =
584      __gen_uint(values->ShaderIndex, 0, 23) |
585      __gen_uint(values->GeometryRayMask, 24, 31);
586
587   dw[1] =
588      __gen_uint(values->GeometryIndex, 0, 28) |
589      __gen_uint(values->LeafType, 29, 29) |
590      __gen_uint(values->GeometryFlags, 30, 31);
591}
592
593#define GFX_RT_BVH_QUAD_LEAF_length           16
594struct GFX_RT_BVH_QUAD_LEAF {
595   struct GFX_RT_BVH_PRIMITIVE_LEAF_DESCRIPTOR LeafDescriptor;
596   uint32_t                             PrimitiveIndex0;
597   uint32_t                             PrimitiveIndex1Delta;
598   uint32_t                             j0;
599   uint32_t                             j1;
600   uint32_t                             j2;
601   bool                                 LastQuad;
602   struct GFX_RT_BVH_VEC3               QuadVertex[4];
603};
604
605static inline __attribute__((always_inline)) void
606GFX_RT_BVH_QUAD_LEAF_pack(__attribute__((unused)) __gen_user_data *data,
607                          __attribute__((unused)) void * restrict dst,
608                          __attribute__((unused)) const struct GFX_RT_BVH_QUAD_LEAF * restrict values)
609{
610   uint32_t * restrict dw = (uint32_t * restrict) dst;
611
612   GFX_RT_BVH_PRIMITIVE_LEAF_DESCRIPTOR_pack(data, &dw[0], &values->LeafDescriptor);
613
614   dw[2] =
615      __gen_uint(values->PrimitiveIndex0, 0, 31);
616
617   dw[3] =
618      __gen_uint(values->PrimitiveIndex1Delta, 0, 16) |
619      __gen_uint(values->j0, 16, 17) |
620      __gen_uint(values->j1, 18, 19) |
621      __gen_uint(values->j2, 20, 21) |
622      __gen_uint(values->LastQuad, 22, 22);
623
624   GFX_RT_BVH_VEC3_pack(data, &dw[4], &values->QuadVertex[0]);
625
626   GFX_RT_BVH_VEC3_pack(data, &dw[7], &values->QuadVertex[1]);
627
628   GFX_RT_BVH_VEC3_pack(data, &dw[10], &values->QuadVertex[2]);
629
630   GFX_RT_BVH_VEC3_pack(data, &dw[13], &values->QuadVertex[3]);
631}
632
633#define GFX_RT_BVH_INSTANCE_LEAF_length       32
634struct GFX_RT_BVH_INSTANCE_LEAF {
635   uint32_t                             ShaderIndex;
636   uint32_t                             GeometryRayMask;
637   uint32_t                             InstanceContributionToHitGroupIndex;
638   uint32_t                             LeafType;
639#define TYPE_OPAQUE_CULLING_ENABLED              0
640#define TYPE_OPAQUE_CULLING_DISABLED             1
641   uint32_t                             GeometryFlags;
642#define GEOMETRY_OPAQUE                          1
643   __gen_address_type                   StartNodeAddress;
644   uint32_t                             InstanceFlags;
645#define TRIANGLE_CULL_DISABLE                    1
646#define TRIANGLE_FRONT_COUNTERCLOCKWISE          2
647#define FORCE_OPAQUE                             4
648#define FORCE_NON_OPAQUE                         8
649   float                                WorldToObjectm00;
650   float                                WorldToObjectm01;
651   float                                WorldToObjectm02;
652   float                                WorldToObjectm10;
653   float                                WorldToObjectm11;
654   float                                WorldToObjectm12;
655   float                                WorldToObjectm20;
656   float                                WorldToObjectm21;
657   float                                WorldToObjectm22;
658   float                                ObjectToWorldm30;
659   float                                ObjectToWorldm31;
660   float                                ObjectToWorldm32;
661   __gen_address_type                   BVHAddress;
662   uint32_t                             InstanceID;
663   uint32_t                             InstanceIndex;
664   float                                ObjectToWorldm00;
665   float                                ObjectToWorldm01;
666   float                                ObjectToWorldm02;
667   float                                ObjectToWorldm10;
668   float                                ObjectToWorldm11;
669   float                                ObjectToWorldm12;
670   float                                ObjectToWorldm20;
671   float                                ObjectToWorldm21;
672   float                                ObjectToWorldm22;
673   float                                WorldToObjectm30;
674   float                                WorldToObjectm31;
675   float                                WorldToObjectm32;
676};
677
678static inline __attribute__((always_inline)) void
679GFX_RT_BVH_INSTANCE_LEAF_pack(__attribute__((unused)) __gen_user_data *data,
680                              __attribute__((unused)) void * restrict dst,
681                              __attribute__((unused)) const struct GFX_RT_BVH_INSTANCE_LEAF * restrict values)
682{
683   uint32_t * restrict dw = (uint32_t * restrict) dst;
684
685   dw[0] =
686      __gen_uint(values->ShaderIndex, 0, 23) |
687      __gen_uint(values->GeometryRayMask, 24, 31);
688
689   dw[1] =
690      __gen_uint(values->InstanceContributionToHitGroupIndex, 0, 23) |
691      __gen_uint(values->LeafType, 29, 29) |
692      __gen_uint(values->GeometryFlags, 30, 31);
693
694   const uint64_t v2 =
695      __gen_uint(values->InstanceFlags, 48, 55);
696   const uint64_t v2_address =
697      __gen_address(data, &dw[2], values->StartNodeAddress, v2, 0, 47);
698   dw[2] = v2_address;
699   dw[3] = (v2_address >> 32) | (v2 >> 32);
700
701   dw[4] =
702      __gen_float(values->WorldToObjectm00);
703
704   dw[5] =
705      __gen_float(values->WorldToObjectm01);
706
707   dw[6] =
708      __gen_float(values->WorldToObjectm02);
709
710   dw[7] =
711      __gen_float(values->WorldToObjectm10);
712
713   dw[8] =
714      __gen_float(values->WorldToObjectm11);
715
716   dw[9] =
717      __gen_float(values->WorldToObjectm12);
718
719   dw[10] =
720      __gen_float(values->WorldToObjectm20);
721
722   dw[11] =
723      __gen_float(values->WorldToObjectm21);
724
725   dw[12] =
726      __gen_float(values->WorldToObjectm22);
727
728   dw[13] =
729      __gen_float(values->ObjectToWorldm30);
730
731   dw[14] =
732      __gen_float(values->ObjectToWorldm31);
733
734   dw[15] =
735      __gen_float(values->ObjectToWorldm32);
736
737   const uint64_t v16_address =
738      __gen_address(data, &dw[16], values->BVHAddress, 0, 0, 47);
739   dw[16] = v16_address;
740   dw[17] = v16_address >> 32;
741
742   dw[18] =
743      __gen_uint(values->InstanceID, 0, 31);
744
745   dw[19] =
746      __gen_uint(values->InstanceIndex, 0, 31);
747
748   dw[20] =
749      __gen_float(values->ObjectToWorldm00);
750
751   dw[21] =
752      __gen_float(values->ObjectToWorldm01);
753
754   dw[22] =
755      __gen_float(values->ObjectToWorldm02);
756
757   dw[23] =
758      __gen_float(values->ObjectToWorldm10);
759
760   dw[24] =
761      __gen_float(values->ObjectToWorldm11);
762
763   dw[25] =
764      __gen_float(values->ObjectToWorldm12);
765
766   dw[26] =
767      __gen_float(values->ObjectToWorldm20);
768
769   dw[27] =
770      __gen_float(values->ObjectToWorldm21);
771
772   dw[28] =
773      __gen_float(values->ObjectToWorldm22);
774
775   dw[29] =
776      __gen_float(values->WorldToObjectm30);
777
778   dw[30] =
779      __gen_float(values->WorldToObjectm31);
780
781   dw[31] =
782      __gen_float(values->WorldToObjectm32);
783}
784
785#define GFX_RT_BVH_PROCEDURAL_LEAF_length     16
786struct GFX_RT_BVH_PROCEDURAL_LEAF {
787   struct GFX_RT_BVH_PRIMITIVE_LEAF_DESCRIPTOR LeafDescriptor;
788   uint32_t                             NumPrimitives;
789   uint32_t                             LastPrimitive;
790   uint32_t                             PrimitiveIndex[13];
791};
792
793static inline __attribute__((always_inline)) void
794GFX_RT_BVH_PROCEDURAL_LEAF_pack(__attribute__((unused)) __gen_user_data *data,
795                                __attribute__((unused)) void * restrict dst,
796                                __attribute__((unused)) const struct GFX_RT_BVH_PROCEDURAL_LEAF * restrict values)
797{
798   uint32_t * restrict dw = (uint32_t * restrict) dst;
799
800   GFX_RT_BVH_PRIMITIVE_LEAF_DESCRIPTOR_pack(data, &dw[0], &values->LeafDescriptor);
801
802   dw[2] =
803      __gen_uint(values->NumPrimitives, 0, 3) |
804      __gen_uint(values->LastPrimitive, 19, 31);
805
806   dw[3] =
807      __gen_uint(values->PrimitiveIndex[0], 0, 31);
808
809   dw[4] =
810      __gen_uint(values->PrimitiveIndex[1], 0, 31);
811
812   dw[5] =
813      __gen_uint(values->PrimitiveIndex[2], 0, 31);
814
815   dw[6] =
816      __gen_uint(values->PrimitiveIndex[3], 0, 31);
817
818   dw[7] =
819      __gen_uint(values->PrimitiveIndex[4], 0, 31);
820
821   dw[8] =
822      __gen_uint(values->PrimitiveIndex[5], 0, 31);
823
824   dw[9] =
825      __gen_uint(values->PrimitiveIndex[6], 0, 31);
826
827   dw[10] =
828      __gen_uint(values->PrimitiveIndex[7], 0, 31);
829
830   dw[11] =
831      __gen_uint(values->PrimitiveIndex[8], 0, 31);
832
833   dw[12] =
834      __gen_uint(values->PrimitiveIndex[9], 0, 31);
835
836   dw[13] =
837      __gen_uint(values->PrimitiveIndex[10], 0, 31);
838
839   dw[14] =
840      __gen_uint(values->PrimitiveIndex[11], 0, 31);
841
842   dw[15] =
843      __gen_uint(values->PrimitiveIndex[12], 0, 31);
844}
845
846#endif /* GFX_PACK_H */
847