-
Notifications
You must be signed in to change notification settings - Fork 102
/
GLSL_NV_shader_invocation_reorder.txt
849 lines (561 loc) · 29.3 KB
/
GLSL_NV_shader_invocation_reorder.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
Name
NV_shader_invocation_reorder
Name Strings
GL_NV_shader_invocation_reorder
Contact
Ashwin Lele (alele 'at' nvidia.com), NVIDIA
Contributors
Eric Werness, NVIDIA
Daniel Koch, NVIDIA
Status
Complete
Version
Last Modified Date: 2022-09-01
Revision: 1
Dependencies
This extension can be applied to OpenGL GLSL versions 4.60
(#version 460) and higher.
This extension is written against revision 5 of the OpenGL Shading Language
version 4.60, dated September 4, 2017.
This extension interacts with revision 43 of the GL_KHR_vulkan_glsl
extension, dated October 25, 2017.
This extension requires GLSL_EXT_ray_tracing.
This extension interacts with GLSL_NV_ray_tracing_motion_blur.
This extension requires GLSL_EXT_buffer_reference_uvec2.
This extension interacts with GL_EXT_nonuniform_qualifier.
Overview
Ray tracing workloads are known to suffer from divergent shader execution
and data divergence. The current ray tracing pipeline API allows implementations
to dynamically schedule work triggered on execution of 'traceRayEXT'
or 'executeCallableEXT' but this does not allow applications any control
over it. Furthermore not all real world use cases require tight coupling
of ray tracing traversal and shading.
This extension document modifies GLSL for ray tracing stages to add support
for 'hitObjectNV' which is an opaque type which encapsulates the state of
traversal and allows queries to read this state. Additionally new functions
using this hitobject, enable user explicit control over ray tracing traversal and shading.
Furthermore new builtins are added to explicitly communicate reordering
information to implementations to allow them to reorder threads to minimize
shader and data divergence and improving coherent execution.
This extension document adds support for the following extensions to be used
within GLSL:
- GL_NV_shader_invocation_reorder - enables reordering operations
Mapping to SPIR-V
-----------------
For informational purposes (non-normative), the following is an
expected way for an implementation to map GLSL constructs to SPIR-V
constructs:
hitObjectNV type -> OpTypeHitObjectNV instruction
hitObjectNV variable -> OpVariable instruction with type OpTypeHitObjectNV
hitObjectTraceRayNV -> OpHitObjectTraceRayNV instruction
hitObjectTraceRayMotionNV -> OpHitObjectTraceRayMotionNV instruction
hitObjectRecordHitNV -> OpHitObjectRecordHitNV instruction
hitObjectRecordHitMotionNV -> OpHitObjectRecordHitMotionNV instruction
hitObjectRecordHitWithIndexNV -> OpHitObjectRecordHitWithIndexNV instruction
hitObjectRecordHitWithIndexMotionNV -> OpHitObjectRecordHitWithIndexMotionNV instruction
hitObjectRecordMissNV -> OpHitObjectRecordMissNV instruction
hitObjectRecordMissMotionNV -> OpHitObjectRecordMissMotionNV instruction
hitObjectRecordNopNV -> OpHitObjectRecordNopNV instruction
hitObjectExecuteShaderNV -> OpHitObjectExecuteShaderNV instruction
hitObjectIsHitNV -> OpHitObjectIsHitNV instruction
hitObjectIsMissNV -> OpHitObjectIsMissNV instruction
hitObjectIsNopNV -> OpHitObjectIsNopNV instruction
hitObjectGetRayTMinNV -> OpHitObjectGetRayTMinNV instruction
hitObjectGetRayTMaxNV -> OpHitObjectGetRayTMaxNV instruction
hitObjectGetWorldRayOriginNV -> OpHitObjectGetWorldRayOriginNV instruction
hitObjectGetWorldRayDirectionNV -> OpHitObjectGetWorldDirectionNV instruction
hitObjectGetObjectRayOriginNV -> OpHitObjectGetObjectRayOriginNV instruction
hitObjectGetObjectRayDirectionNV -> OpHitObjectGetObjectDirectionNV instruction
hitObjectGetObjectToWorldNV -> OpHitObjectGetObjectToWorldNV instruction
hitObjectGetWorldToObjectNV -> OpHitObjectGetWorldToObjectNV instruction
hitObjectGetInstanceIdNV -> OpHitObjectGetInstanceIdNV instruction
hitObjectGetInstanceCustomIndexNV -> OpHitObjectGetInstanceCustomIndexNV instruction
hitObjectGetGeometryIndexNV -> OpHitObjectGetGeometryIndexNV instruction
hitObjectGetPrimitiveIndexNV -> OpHitObjectGetPrimitiveIndexNV instruction
hitObjectGetHitKindNV -> OpHitObjectGetHitKindNV instruction
hitObjectGetShaderBindingTableRecordIndexNV ->
OpHitObjectGetShaderBindingTableRecordIndexNV instruction
hitObjectGetShaderRecordBufferHandleNV ->
OpHitObjectGetShaderRecordBufferHandleNV instruction
reorderThreadNV ->
OpReorderThreadWithHintNV/OpReorderThreadWithHitObjectNV instruction
Modifications to the OpenGL Shading Language Specification, Version 4.60
Including the following line in a shader can be used to control the
language features described in this extension:
#extension GL_NV_shader_invocation_reorder : <behavior>
where <behavior> is as specified in section 3.3.
New preprocessor #defines are added:
#define GL_NV_shader_invocation_reorder 1
Changes to Chapter 3 of The OpenGL Shading Language Specification, Version 4.60
Modify Section 3.6, (Keywords)
(add the following to the list of reserved keywords)
hitObjectNV
Changes to Chapter 4 of The OpenGL Shading Language Specification, Version 4.60
Add following to Section 4.1 (Basic Types)
Hit Object Opaque Types
Types Meaning
----- -------
hitObjectNV A handle representing the state
captured during traversal through
acceleration structure or populated
via builtins.
This is available only in ray-generation,
closest-hit and miss shading stages.
Change the following sentence in the first paragraph of 4.1.7 (Opaque
Types) from
They can only be declared as function parameters or in uniform-
qualified variables (see Uniform Variables).
to
With the exception of hitObjectNV (see "Hit Object Type"), they can
only be declared as function parameters or in uniform-qualified
variables (see Uniform Variables).
Add two new sub-sections under Section 4.1.7 (Opaque Types)
4.1.7.y Hit Object Type
hitObjectNV is an opaque type representing the state captured during
traversal of acceleration structures or manually populated via builtins.
It is declared and behaves like above described opaque types. When aggregated
into arrays within a shader, hitObjectNV can only be indexed with
a dynamically uniform integral expression, otherwise results are undefined.
Unlike other opaque types, hitObjectNV variables are declared with no storage
qualifiers, either in the global scope or within function scope.
[[If GL_EXT_nonuniform_qualifier]] is supported
When aggregated into arrays within a shader, hitObjectNV can
be indexed with a non-uniform integral expressions, when decorated with the
nonuniformEXT qualifier.
[[end]]
This type is used in various hit object builtins described in Section 8.19
Members of a structure cannot be declared with this type.
Modify Section 4.3 (Storage Qualifiers)
Storage Qualifier Meaning
----------------- -------
hitObjectAttributeNV Ray-generation, closest-hit or miss shader only.
Storage associated with attibutes for
geometry intersected by a ray when used for
a hit object.
4.3.X hitObjectAttributeNV Variables
These are allowed only in ray-generation, closest-hit, and miss shaders.
It is a compile-time error to use them in any other stage. They can be
both read from and written to. They cannot have any other storage qualifiers.
It is a compile-time error to declare unsized arrays of this type.
Modify table in Section 4.4 (Layout Qualifiers)
Layout Qualifier Qualifier Individual Block Block Allowed
Only Variable Member Interface
----------------- --------- ---------- ------ ------ ---------
hitobjectshaderrecordnv X buffer
Add a new subsection to Section 4.4
4.4.10 Hit Object Shader Record Buffer
This allows a buffer reference to be used in context of reading from
data section of a shader record as it is encoded in a hit object.
This layout qualifier can only be used on a buffer interface block
which is a buffer reference i.e annotated with
layout qualifier 'buffer_reference'
It is a compile-time error to use this qualifier with any other
interface-qualifier or member of an interface block.
Additions to Chapter 8 of the OpenGL Shading Language Specification
(Built-in Functions)
Add Section 8.19, Hit Object Functions
(Modify section 8.19 from Ray Tracing functions from EXT_ray_tracing
to add following)
The hitObjectTraceRayNV(), hitObjectTraceRayMotionNV(),
hitObjectExecuteShaderNV() are considered shader call functions.
reorderThreadNV() and reorderThreadWithHintNV() are considered as
invocation repack functions.
Syntax:
void hitObjectTraceRayNV(hitObjectNV hitobject,
accelerationStructureEXT topLevel,
uint rayFlags,
uint cullMask,
uint sbtRecordOffset,
uint sbtRecordStride,
uint missIndex,
vec3 origin,
float Tmin,
vec3 direction,
float Tmax,
int payload);
This function is only available in the ray generation, closest-hit, and
miss shaders.
Initiates a ray query against a top-level <accelerationStructureEXT>
structure, triggering the execution of various intersection and any-hit
shaders as ray-geometry intersections are being evaluated, and returns the
resulting hit or miss information in the hit object. This does not
execute any closest-hit or miss shaders. No thread reordering
or user-observable driver side scheduling occurs.
Refer to 'traceRayEXT' for various parameter definitions.
Syntax:
void hitObjectTraceRayMotionNV(hitObjectNV hitobject,
accelerationStructureEXT topLevel,
uint rayFlags,
uint cullMask,
uint sbtRecordOffset,
uint sbtRecordStride,
uint missIndex,
vec3 origin,
float Tmin,
vec3 direction,
float Tmax,
float currentTime,
int payload);
This function is only available in the ray generation, closest-hit, and
miss shaders.
Initiates a ray query against a top-level <accelerationStructureEXT>
structure, triggering the execution of various intersection and any-hit
shaders as ray-geometry intersections are being evaluated, and returns the
resulting hit or miss information in the hit object. This does not
execute any closest-hit or miss shaders. No thread reordering
or user-observable driver side scheduling occurs.
'hitObjectTraceRayMotionNV' operates the same as 'hitObjectTraceRayNV',
with the exception of <currentTime> parameter.
This function is allowed only when GLSL_NV_ray_tracing_motion_blur
extension is present.
Refer to 'traceRayMotionNV' for various parameter definitions.
Syntax:
void hitObjectRecordHitNV(hitObjectNV hitobject,
accelerationStructureEXT topLevel,
int instanceid,
int primitiveid,
int geometryindex,
uint hitKind,
uint sbtRecordOffset,
uint sbtRecordStride,
vec3 origin,
float Tmin,
vec3 direction,
float Tmax,
int attributeLocation)
Populates 'hitobject' representing a hit without tracing a ray.
It is legal to construct a hit which is not the closest hit along the ray
or a hit which is not located along the ray.
<instanceid> refers to the index of the instance within <topLevel>
acceleration structure for which this hit object is created.
Result are undefined for negative or out of bounds index.
<primitiveid> refers to the index of the primitive (triangle or bounding
box) within <topLevel> acceleration structure for which this hit object is created.
Results are undefined for negative or out of bounds index.
<geometryindex> refers to the index of the geometry within <topLevel>
acceleration structure for which this hit object is created.
Results are undefined for negative or out of bounds index.
<hitKind> is used to describe the kind of intersection for which this hit
object is created. Refer to 'Fixed Constants' for details
<sbtRecordOffset> and <sbtRecordStride> parameters influence the
computation of record indices of the <shader binding table> that locate
the closest-hit shaders for which this hit object is created.
Refer to shader binding table, hit shader indexing of the Vulkan specification
for more information.
<attributeLocation> is a compile-time constant to select
a shader defined structure containing attributes which is used to populate
this hit object.
It is possible for a shader to contain multiple invocations 'hitObjectRecordHitNV'
with different attribute types. Different attribute types are chosen based on the
different values of the compile-time constant <attributeLocation> which correspond
to the hitObjectAttributeNV qualified variables having the same value for the
location layout qualifier.
Syntax:
void hitObjectRecordHitMotionNV(hitObjectNV hitobject,
accelerationStructureEXT topLevel,
int instanceid,
int primitiveid,
int geometryindex,
uint hitKind,
uint sbtRecordOffset,
uint sbtRecordStride,
vec3 origin,
float Tmin,
vec3 direction,
float Tmax,
float currentTime,
int attributeLocation)
Populates 'hitobject' representing a hit without tracing a ray.
It is legal to construct a hit which is not the closest hit along the ray
or a hit which is not located along the ray.
Refer to 'hitObjectRecordHitNV' for various parameter definitions
Refer to 'traceRayMotionNV' for defintion of <currentTime>
This function is allowed only when GLSL_NV_ray_tracing_motion_blur
extension is present.
Syntax:
void hitObjectRecordHitWithIndexNV(hitObjectNV hitobject,
accelerationStructureEXT topLevel,
int instanceid,
int primitiveid,
int geometryindex,
uint hitKind,
uint sbtRecordIndex,
vec3 origin,
float Tmin,
vec3 direction,
float Tmax,
int attributeLocation)
Populates 'hitobject' representing a hit without tracing a ray.
It is legal to construct a hit which is not the closest hit along the ray
or a hit which is not located along the ray.
<instanceid> refers to the index of the instance within <topLevel>
acceleration structure for which this hit object is created.
Results are undefined for negative or out of bounds index.
<primitiveid> refers to the index of the primitive (triangle or bounding
box) within <topLevel> acceleration structure for which this hit object is created.
Results are undefined for negative or out of bounds index.
<geometryindex> refers to the index of the geometry within <topLevel>
acceleration structure for which this hit object is created.
Results are undefined for negative or out of bounds index.
<hitKind> is used to describe the kind of intersection for which this hit
object is created. Refer to 'Fixed Constants' in EXT_ray_tracing for details
<sbtRecordIndex> refers to the record index of the closest-hit shader of
the <shader binding table> for which this hit object is created
Only the 4 least-significant bits are used; other bits are ignored.
Refer to shader binding table, hit shader indexing of the Vulkan specification
for more information.
<attributeLocation> is a compile-time constant to select
a shader defined structure containing attributes which is used to populate
this hit object.
It is possible for a shader to contain multiple invocations 'hitObjectRecordHitNV'
with different attribute types. Different attribute types are chosen based on the
different values of the compile-time constant <attributeLocation> which correspond
to the hitObjectAttributeNV qualified variables having the same value for the
location layout qualifier.
Syntax:
void hitObjectRecordHitWithIndexMotionNV(hitObjectNV hitobject,
accelerationStructureEXT topLevel,
int instanceid,
int primitiveid,
int geometryindex,
uint hitKind,
uint sbtRecordIndex,
vec3 origin,
float Tmin,
vec3 direction,
float Tmax,
float currentTime,
int attributeLocation)
Populates 'hitobject' representing a hit without tracing a ray.
It is legal to construct a hit which is not the closest hit along the ray
or a hit which is not located along the ray.
Refer to 'hitObjectRecordHitWithIndexNV' for various parameter definitions
Refer to 'traceRayMotionNV' for defintion of <currentTime>
This function is allowed only when GLSL_NV_ray_tracing_motion_blur
extension is present.
Syntax:
void hitObjectRecordMissNV(hitObjectNV hitObject,
uint sbtRecordIndex,
vec3 origin,
float Tmin,
vec3 direction,
float TMax)
Populates 'hitobject' representing a miss without tracing a ray
It is legal to construct a miss in a hit object for a ray that
could have hit some geometry if traced.
<sbtRecordIndex> refers to the record index of the miss shader of
the <shader binding table> for which this hit object is created.
Refer to shader binding table, hit shader indexing of the Vulkan
specification for more information.
Syntax:
void hitObjectRecordMissMotionNV(hitObjectNV hitObject,
uint sbtRecordIndex,
vec3 origin,
float Tmin,
vec3 direction,
float TMax,
float currentTime)
Populates 'hitobject' representing a miss without tracing a ray
It is legal to construct a miss in a hit object for a ray that
could have hit some geometry if traced.
Refer to 'hitObjectRecordMissNV' for various parameter definitions.
Refer to 'traceRayMotionNV' for defintion of <currentTime>
This function is allowed only when GLSL_NV_ray_tracing_motion_blur
extension is present.
Syntax:
void hitObjectRecordEmptyNV(hitObjectNV hitObject)
Encodes the hitobject to represent an empty hit object which represents
neither a hit nor a miss.
Syntax:
void hitObjectExecuteShaderNV(hitObjectNV hitObject,
int payload)
Execute the closest-hit or miss shader encoded in the 'hitobject'
This call does not trigger reordering of threads.
Syntax:
bool hitObjectIsEmptyNV(hitObjectNV hitObject)
Returns 'true' if <hitObject> encodes a nop, 'false' otherwise.
Syntax:
bool hitObjectIsMissNV(hitObjectNV hitObject)
Returns 'true' if <hitobject> encodes a miss, 'false' otherwise.
Syntax:
bool hitObjectIsHitNV(hitObjectNV hitObject)
Returns 'true' if <hitobject> encodes a hit, 'false' otherwise.
Syntax:
float hitObjectGetRayTMinNV(hitObjectNV hitObject)
Returns the parametric <tMin> value encoded in the hit object.
Refer to the semantics of gl_RayTMinEXT as defined in EXT_ray_tracing.
Syntax:
float hitObjectGetRayTMaxNV(hitObjectNV hitObject)
Returns the parametric <tMax> value encoded in the hit object.
Refer to the semantics of gl_RayTMaxEXT as defined in EXT_ray_tracing.
Syntax:
vec3 hitObjectGetObjectRayOriginNV(hitObjectNV hitObject)
Returns the object-space origin of ray encoded in the hit object.
Syntax:
vec3 hitObjectGetObjectRayDirectionNV(hitObjectNV hitObject)
Returns the object-space direction of ray encoded in the hit object.
Syntax:
vec3 hitObjectGetWorldRayOriginNV(hitObjectNV hitObject)
Returns the world-space origin of ray encoded in the hit object.
Syntax:
vec3 hitObjectGetWorldRayDirectionNV(hitObjectNV hitObject)
Returns the world-space direction of ray encoded in the hit object.
Syntax:
mat4x3 hitObjectGetObjectToWorldNV(hitObjectNV hitObject)
Returns the object to world transformation matrix as encoded in the hit object.
Syntax:
mat4x3 hitObjectGetWorldToObjectNV(hitObjectNV hitObject)
Returns the world to object transformation matrix as encoded in the hit object.
Syntax:
int hitObjectGetInstanceCustomIndexNV(hitObjectNV hitObject);
Returns the custom index of the instance encoded in the hit object.
Syntax:
int hitObjectGetInstanceIdNV(hitObjectNV hitObject);
Returns the index of the instance encoded in the hit object.
Syntax:
int hitObjectGetGeometryIndexNV(hitObjectNV hitObject);
Returns implementation defined index of geometry encoded in the hit
object.
Syntax:
int hitObjectGetPrimitiveIndexNV(hitObjectNV hitObject);
Returns the index of the primitive (triangle or bounding box) within the
geometry as encoded in the hit object.
Syntax:
uint hitObjectGetHitKindNV(hitObjectNV hitObject);
Returns values as defined in EXT_ray_tracing specification for
gl_HitKindEXT.
Syntax:
void hitObjectGetAttributesNV(hitObjectNV hitObject, int attributeLocation);
Extracts the attributes encoded in the hit object and writes to
'hitObjectAttributeNV' storage class decorated variable selected using
'attributeLocation' as specified below.
<attributeLocation> is a compile-time constant to select
a shader defined structure used to populate with attributes associated
with this hit object.
It is possible for a shader to contain multiple invocations
'hitObjectGetAttributesNV'
with different attribute types. Different attribute types are chosen based on the
different values of the compile-time constant <attributeLocation> which correspond
to the hitObjectAttributeNV qualified variables having the same value for the
location layout qualifier.
Syntax:
uvec2 hitObjectGetShaderRecordBufferHandleNV(hitObjectNV hitObject);
Returns a uvec2 handle representing the address for data for a record in
the shader binding table as encoded in the hit object.
This can be used with a buffer reference with additional layout qualifier
'hitobjectshaderrecordnv' as defined in EXT_buffer_reference_uvec2.
Syntax:
uint hitObjectGetShaderBindingTableRecordIndexNV(hitObjectNV hitObject);
Returns the index for the record in shader binding table as encoded in hit
object. For a hit, returns index within hit group for a miss the index within
miss table.
Syntax:
float hitObjectGetCurrentTimeNV(hitObjectNV hitObject);
Returns the current time as encoded in the hit object.
Only applicable if hit object was constructed for hitObjectTraceRayMotionNV
Add Section 8.20, Reorder Functions
Reorder functions allow implementations to reorder threads based
on input given to these builtins to so that subsequent code can
execute with improved coherence.
For reorder functions providing a hint, the implementation will reorder
based on the unsigned numerical value of the number of bits provided.
The sorting may be coarse, be bucketed rather than sorted, or only use
the high bits of the hint provided. If both the hint and the hit object
are provided the implementation should reorder based on the hint after
the shader being executed.
These functions are available only in ray-generation shader stage.
Syntax:
void reorderThreadNV(uint hint, uint bits);
Reorder threads based on user provided <hint>. Similar hint values
indicate similarity of subsequent work done after this call. Behavior
is implementation defined.
<hint> determines desired ordering of threads relative to others.
<bits> indicates number of least significant bits an implementation
should take into account from <hint> in determining ordering.
Value of <bits> should be <= 32. Values greater than 32 will
lead to undefined behavior.
Syntax:
void reorderThreadNV(hitObjectNV hitObject)
Reorder threads based on provided <hitObject>. The exact properties
from hit object which are used to reorder the threads is implementation
defined.
Syntax:
void reorderThreadNV(hitObjectNV hitObject, uint hint, uint bits)
Reorder threads based on provided <hitObject> supplemented by additional
information based on user provided <hint>. The exact properties from
hit object and user specified hint which are used to reorder theads is
implementation defined.
<hint> determines desired ordering of threads relative to others.
<bits> indicates number of least significant bits an implementation
should take into account from <hint> in determining ordering.
Value of <bits> should be <= 32. Values greater than 32 will
lead to undefined behavior.
Interactions with GLSL_EXT_ray_tracing
This extension requires acceleration structures, shader stages,
storage qualifiers and the various ray flags added by GLSL_EXT_ray_tracing.
Interactions with GL_EXT_nonuniform_qualifier
If GL_EXT_nonuniform_qualifier is supported, arrays of
hitObjectNV can be indexed with non-unform integral
expressions when they are decorated with the nonuniformEXT qualifier.
Interactions with GL_EXT_scalar_block_layout
If GL_EXT_scalar_block_layout is supported, buffer references with
a layout of hitobjectshaderrecordnv can also be laid out using the scalar
block layout.
Example
#version 460
#extension GL_EXT_ray_tracing : enable
#extension GL_EXT_buffer_reference_uvec2 : enable
#extension GL_NV_shader_invocation_reorder : enable
layout(binding = 0) uniform accelerationStructureEXT as;
layout(binding = 1, rgba32f) uniform image2D img;
layout(binding = 2) uniform RayParams { vec3 origin;};
layout(location = 0) rayPayloadEXT vec4 Color;
layout(buffer_reference, hitobjectshaderrecordnv) buffer SRB
{
uint materialId;
};
layout(location = 0) hitObjectAttributeNV vec3 sphereAABB;
void main()
{
//Trace rays executing custom intersection/any-hit
vec4 outputColor = vec4(0);
hitObjectNV hObj;
//Initialize to an empty hit object
hitObjectRecordEmptyNV(hObj);
hitObjectTraceRayNV(hObj,
as,
0,
0,
0,
4,
0,
origin + vec3(gl_LaunchIDEXT.xyz),
0.0f,
origin + vec3(gl_LaunchIDEXT.xyz) + vec3(0,0,1.0f),
1.0f,
0);
uint materialIdHint = 0;
if (hitObjectIsHitNV(hObj)) {
uvec2 handle = hitObjectGetShaderRecordBufferHandleNV(hObj);
materialIdHint = SRB(handle).materialId;
}
//Reorder threads based on hit object and additional hint on material type
//Use 3 LSB bits only
reorderThreadNV(hObj, materialIdHint, 3);
//Execute closest-hit shaders only
if (hitObjectIsHitNV(hObj)) {
//Get Attributes of intersection
hitObjectGetAttributesNV(hObj, 0);
hitObjectExecuteShaderNV(hObj, 0);
outputColor = vec4(Color.x + distance(sphereAABB, vec3(0)));
}
imageStore(img, ivec2(gl_LaunchIDEXT.xy), outputColor);
}
Issues
1) What is the point of empty hit object?
A) Can use them to participate in reordering when state of hitobject of
thread represents neither a hit nor a miss.
Revision History
Rev. Date Author Changes
---- ----------- ------ -------------------------------------------
1 2022-09-01 alele Initial revisions