gallium: remove TGSI opcode BREAKC
[mesa.git] / src / gallium / docs / source / tgsi.rst
1 TGSI
2 ====
3
4 TGSI, Tungsten Graphics Shader Infrastructure, is an intermediate language
5 for describing shaders. Since Gallium is inherently shaderful, shaders are
6 an important part of the API. TGSI is the only intermediate representation
7 used by all drivers.
8
9 Basics
10 ------
11
12 All TGSI instructions, known as *opcodes*, operate on arbitrary-precision
13 floating-point four-component vectors. An opcode may have up to one
14 destination register, known as *dst*, and between zero and three source
15 registers, called *src0* through *src2*, or simply *src* if there is only
16 one.
17
18 Some instructions, like :opcode:`I2F`, permit re-interpretation of vector
19 components as integers. Other instructions permit using registers as
20 two-component vectors with double precision; see :ref:`doubleopcodes`.
21
22 When an instruction has a scalar result, the result is usually copied into
23 each of the components of *dst*. When this happens, the result is said to be
24 *replicated* to *dst*. :opcode:`RCP` is one such instruction.
25
26 Modifiers
27 ^^^^^^^^^^^^^^^
28
29 TGSI supports modifiers on inputs (as well as saturate and precise modifier
30 on instructions).
31
32 For arithmetic instruction having a precise modifier certain optimizations
33 which may alter the result are disallowed. Example: *add(mul(a,b),c)* can't be
34 optimized to TGSI_OPCODE_MAD, because some hardware only supports the fused
35 MAD instruction.
36
37 For inputs which have a floating point type, both absolute value and
38 negation modifiers are supported (with absolute value being applied
39 first). The only source of TGSI_OPCODE_MOV and the second and third
40 sources of TGSI_OPCODE_UCMP are considered to have float type for
41 applying modifiers.
42
43 For inputs which have signed or unsigned type only the negate modifier is
44 supported.
45
46 Instruction Set
47 ---------------
48
49 Core ISA
50 ^^^^^^^^^^^^^^^^^^^^^^^^^
51
52 These opcodes are guaranteed to be available regardless of the driver being
53 used.
54
55 .. opcode:: ARL - Address Register Load
56
57 .. math::
58
59 dst.x = (int) \lfloor src.x\rfloor
60
61 dst.y = (int) \lfloor src.y\rfloor
62
63 dst.z = (int) \lfloor src.z\rfloor
64
65 dst.w = (int) \lfloor src.w\rfloor
66
67
68 .. opcode:: MOV - Move
69
70 .. math::
71
72 dst.x = src.x
73
74 dst.y = src.y
75
76 dst.z = src.z
77
78 dst.w = src.w
79
80
81 .. opcode:: LIT - Light Coefficients
82
83 .. math::
84
85 dst.x &= 1 \\
86 dst.y &= max(src.x, 0) \\
87 dst.z &= (src.x > 0) ? max(src.y, 0)^{clamp(src.w, -128, 128))} : 0 \\
88 dst.w &= 1
89
90
91 .. opcode:: RCP - Reciprocal
92
93 This instruction replicates its result.
94
95 .. math::
96
97 dst = \frac{1}{src.x}
98
99
100 .. opcode:: RSQ - Reciprocal Square Root
101
102 This instruction replicates its result. The results are undefined for src <= 0.
103
104 .. math::
105
106 dst = \frac{1}{\sqrt{src.x}}
107
108
109 .. opcode:: SQRT - Square Root
110
111 This instruction replicates its result. The results are undefined for src < 0.
112
113 .. math::
114
115 dst = {\sqrt{src.x}}
116
117
118 .. opcode:: EXP - Approximate Exponential Base 2
119
120 .. math::
121
122 dst.x &= 2^{\lfloor src.x\rfloor} \\
123 dst.y &= src.x - \lfloor src.x\rfloor \\
124 dst.z &= 2^{src.x} \\
125 dst.w &= 1
126
127
128 .. opcode:: LOG - Approximate Logarithm Base 2
129
130 .. math::
131
132 dst.x &= \lfloor\log_2{|src.x|}\rfloor \\
133 dst.y &= \frac{|src.x|}{2^{\lfloor\log_2{|src.x|}\rfloor}} \\
134 dst.z &= \log_2{|src.x|} \\
135 dst.w &= 1
136
137
138 .. opcode:: MUL - Multiply
139
140 .. math::
141
142 dst.x = src0.x \times src1.x
143
144 dst.y = src0.y \times src1.y
145
146 dst.z = src0.z \times src1.z
147
148 dst.w = src0.w \times src1.w
149
150
151 .. opcode:: ADD - Add
152
153 .. math::
154
155 dst.x = src0.x + src1.x
156
157 dst.y = src0.y + src1.y
158
159 dst.z = src0.z + src1.z
160
161 dst.w = src0.w + src1.w
162
163
164 .. opcode:: DP3 - 3-component Dot Product
165
166 This instruction replicates its result.
167
168 .. math::
169
170 dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z
171
172
173 .. opcode:: DP4 - 4-component Dot Product
174
175 This instruction replicates its result.
176
177 .. math::
178
179 dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src0.w \times src1.w
180
181
182 .. opcode:: DST - Distance Vector
183
184 .. math::
185
186 dst.x &= 1\\
187 dst.y &= src0.y \times src1.y\\
188 dst.z &= src0.z\\
189 dst.w &= src1.w
190
191
192 .. opcode:: MIN - Minimum
193
194 .. math::
195
196 dst.x = min(src0.x, src1.x)
197
198 dst.y = min(src0.y, src1.y)
199
200 dst.z = min(src0.z, src1.z)
201
202 dst.w = min(src0.w, src1.w)
203
204
205 .. opcode:: MAX - Maximum
206
207 .. math::
208
209 dst.x = max(src0.x, src1.x)
210
211 dst.y = max(src0.y, src1.y)
212
213 dst.z = max(src0.z, src1.z)
214
215 dst.w = max(src0.w, src1.w)
216
217
218 .. opcode:: SLT - Set On Less Than
219
220 .. math::
221
222 dst.x = (src0.x < src1.x) ? 1.0F : 0.0F
223
224 dst.y = (src0.y < src1.y) ? 1.0F : 0.0F
225
226 dst.z = (src0.z < src1.z) ? 1.0F : 0.0F
227
228 dst.w = (src0.w < src1.w) ? 1.0F : 0.0F
229
230
231 .. opcode:: SGE - Set On Greater Equal Than
232
233 .. math::
234
235 dst.x = (src0.x >= src1.x) ? 1.0F : 0.0F
236
237 dst.y = (src0.y >= src1.y) ? 1.0F : 0.0F
238
239 dst.z = (src0.z >= src1.z) ? 1.0F : 0.0F
240
241 dst.w = (src0.w >= src1.w) ? 1.0F : 0.0F
242
243
244 .. opcode:: MAD - Multiply And Add
245
246 Perform a * b + c. The implementation is free to decide whether there is an
247 intermediate rounding step or not.
248
249 .. math::
250
251 dst.x = src0.x \times src1.x + src2.x
252
253 dst.y = src0.y \times src1.y + src2.y
254
255 dst.z = src0.z \times src1.z + src2.z
256
257 dst.w = src0.w \times src1.w + src2.w
258
259
260 .. opcode:: LRP - Linear Interpolate
261
262 .. math::
263
264 dst.x = src0.x \times src1.x + (1 - src0.x) \times src2.x
265
266 dst.y = src0.y \times src1.y + (1 - src0.y) \times src2.y
267
268 dst.z = src0.z \times src1.z + (1 - src0.z) \times src2.z
269
270 dst.w = src0.w \times src1.w + (1 - src0.w) \times src2.w
271
272
273 .. opcode:: FMA - Fused Multiply-Add
274
275 Perform a * b + c with no intermediate rounding step.
276
277 .. math::
278
279 dst.x = src0.x \times src1.x + src2.x
280
281 dst.y = src0.y \times src1.y + src2.y
282
283 dst.z = src0.z \times src1.z + src2.z
284
285 dst.w = src0.w \times src1.w + src2.w
286
287
288 .. opcode:: FRC - Fraction
289
290 .. math::
291
292 dst.x = src.x - \lfloor src.x\rfloor
293
294 dst.y = src.y - \lfloor src.y\rfloor
295
296 dst.z = src.z - \lfloor src.z\rfloor
297
298 dst.w = src.w - \lfloor src.w\rfloor
299
300
301 .. opcode:: FLR - Floor
302
303 .. math::
304
305 dst.x = \lfloor src.x\rfloor
306
307 dst.y = \lfloor src.y\rfloor
308
309 dst.z = \lfloor src.z\rfloor
310
311 dst.w = \lfloor src.w\rfloor
312
313
314 .. opcode:: ROUND - Round
315
316 .. math::
317
318 dst.x = round(src.x)
319
320 dst.y = round(src.y)
321
322 dst.z = round(src.z)
323
324 dst.w = round(src.w)
325
326
327 .. opcode:: EX2 - Exponential Base 2
328
329 This instruction replicates its result.
330
331 .. math::
332
333 dst = 2^{src.x}
334
335
336 .. opcode:: LG2 - Logarithm Base 2
337
338 This instruction replicates its result.
339
340 .. math::
341
342 dst = \log_2{src.x}
343
344
345 .. opcode:: POW - Power
346
347 This instruction replicates its result.
348
349 .. math::
350
351 dst = src0.x^{src1.x}
352
353
354 .. opcode:: COS - Cosine
355
356 This instruction replicates its result.
357
358 .. math::
359
360 dst = \cos{src.x}
361
362
363 .. opcode:: DDX, DDX_FINE - Derivative Relative To X
364
365 The fine variant is only used when ``PIPE_CAP_TGSI_FS_FINE_DERIVATIVE`` is
366 advertised. When it is, the fine version guarantees one derivative per row
367 while DDX is allowed to be the same for the entire 2x2 quad.
368
369 .. math::
370
371 dst.x = partialx(src.x)
372
373 dst.y = partialx(src.y)
374
375 dst.z = partialx(src.z)
376
377 dst.w = partialx(src.w)
378
379
380 .. opcode:: DDY, DDY_FINE - Derivative Relative To Y
381
382 The fine variant is only used when ``PIPE_CAP_TGSI_FS_FINE_DERIVATIVE`` is
383 advertised. When it is, the fine version guarantees one derivative per column
384 while DDY is allowed to be the same for the entire 2x2 quad.
385
386 .. math::
387
388 dst.x = partialy(src.x)
389
390 dst.y = partialy(src.y)
391
392 dst.z = partialy(src.z)
393
394 dst.w = partialy(src.w)
395
396
397 .. opcode:: PK2H - Pack Two 16-bit Floats
398
399 This instruction replicates its result.
400
401 .. math::
402
403 dst = f32\_to\_f16(src.x) | f32\_to\_f16(src.y) << 16
404
405
406 .. opcode:: PK2US - Pack Two Unsigned 16-bit Scalars
407
408 TBD
409
410
411 .. opcode:: PK4B - Pack Four Signed 8-bit Scalars
412
413 TBD
414
415
416 .. opcode:: PK4UB - Pack Four Unsigned 8-bit Scalars
417
418 TBD
419
420
421 .. opcode:: SEQ - Set On Equal
422
423 .. math::
424
425 dst.x = (src0.x == src1.x) ? 1.0F : 0.0F
426
427 dst.y = (src0.y == src1.y) ? 1.0F : 0.0F
428
429 dst.z = (src0.z == src1.z) ? 1.0F : 0.0F
430
431 dst.w = (src0.w == src1.w) ? 1.0F : 0.0F
432
433
434 .. opcode:: SGT - Set On Greater Than
435
436 .. math::
437
438 dst.x = (src0.x > src1.x) ? 1.0F : 0.0F
439
440 dst.y = (src0.y > src1.y) ? 1.0F : 0.0F
441
442 dst.z = (src0.z > src1.z) ? 1.0F : 0.0F
443
444 dst.w = (src0.w > src1.w) ? 1.0F : 0.0F
445
446
447 .. opcode:: SIN - Sine
448
449 This instruction replicates its result.
450
451 .. math::
452
453 dst = \sin{src.x}
454
455
456 .. opcode:: SLE - Set On Less Equal Than
457
458 .. math::
459
460 dst.x = (src0.x <= src1.x) ? 1.0F : 0.0F
461
462 dst.y = (src0.y <= src1.y) ? 1.0F : 0.0F
463
464 dst.z = (src0.z <= src1.z) ? 1.0F : 0.0F
465
466 dst.w = (src0.w <= src1.w) ? 1.0F : 0.0F
467
468
469 .. opcode:: SNE - Set On Not Equal
470
471 .. math::
472
473 dst.x = (src0.x != src1.x) ? 1.0F : 0.0F
474
475 dst.y = (src0.y != src1.y) ? 1.0F : 0.0F
476
477 dst.z = (src0.z != src1.z) ? 1.0F : 0.0F
478
479 dst.w = (src0.w != src1.w) ? 1.0F : 0.0F
480
481
482 .. opcode:: TEX - Texture Lookup
483
484 for array textures src0.y contains the slice for 1D,
485 and src0.z contain the slice for 2D.
486
487 for shadow textures with no arrays (and not cube map),
488 src0.z contains the reference value.
489
490 for shadow textures with arrays, src0.z contains
491 the reference value for 1D arrays, and src0.w contains
492 the reference value for 2D arrays and cube maps.
493
494 for cube map array shadow textures, the reference value
495 cannot be passed in src0.w, and TEX2 must be used instead.
496
497 .. math::
498
499 coord = src0
500
501 shadow_ref = src0.z or src0.w (optional)
502
503 unit = src1
504
505 dst = texture\_sample(unit, coord, shadow_ref)
506
507
508 .. opcode:: TEX2 - Texture Lookup (for shadow cube map arrays only)
509
510 this is the same as TEX, but uses another reg to encode the
511 reference value.
512
513 .. math::
514
515 coord = src0
516
517 shadow_ref = src1.x
518
519 unit = src2
520
521 dst = texture\_sample(unit, coord, shadow_ref)
522
523
524
525
526 .. opcode:: TXD - Texture Lookup with Derivatives
527
528 .. math::
529
530 coord = src0
531
532 ddx = src1
533
534 ddy = src2
535
536 unit = src3
537
538 dst = texture\_sample\_deriv(unit, coord, ddx, ddy)
539
540
541 .. opcode:: TXP - Projective Texture Lookup
542
543 .. math::
544
545 coord.x = src0.x / src0.w
546
547 coord.y = src0.y / src0.w
548
549 coord.z = src0.z / src0.w
550
551 coord.w = src0.w
552
553 unit = src1
554
555 dst = texture\_sample(unit, coord)
556
557
558 .. opcode:: UP2H - Unpack Two 16-Bit Floats
559
560 .. math::
561
562 dst.x = f16\_to\_f32(src0.x \& 0xffff)
563
564 dst.y = f16\_to\_f32(src0.x >> 16)
565
566 dst.z = f16\_to\_f32(src0.x \& 0xffff)
567
568 dst.w = f16\_to\_f32(src0.x >> 16)
569
570 .. note::
571
572 Considered for removal.
573
574 .. opcode:: UP2US - Unpack Two Unsigned 16-Bit Scalars
575
576 TBD
577
578 .. note::
579
580 Considered for removal.
581
582 .. opcode:: UP4B - Unpack Four Signed 8-Bit Values
583
584 TBD
585
586 .. note::
587
588 Considered for removal.
589
590 .. opcode:: UP4UB - Unpack Four Unsigned 8-Bit Scalars
591
592 TBD
593
594 .. note::
595
596 Considered for removal.
597
598
599 .. opcode:: ARR - Address Register Load With Round
600
601 .. math::
602
603 dst.x = (int) round(src.x)
604
605 dst.y = (int) round(src.y)
606
607 dst.z = (int) round(src.z)
608
609 dst.w = (int) round(src.w)
610
611
612 .. opcode:: SSG - Set Sign
613
614 .. math::
615
616 dst.x = (src.x > 0) ? 1 : (src.x < 0) ? -1 : 0
617
618 dst.y = (src.y > 0) ? 1 : (src.y < 0) ? -1 : 0
619
620 dst.z = (src.z > 0) ? 1 : (src.z < 0) ? -1 : 0
621
622 dst.w = (src.w > 0) ? 1 : (src.w < 0) ? -1 : 0
623
624
625 .. opcode:: CMP - Compare
626
627 .. math::
628
629 dst.x = (src0.x < 0) ? src1.x : src2.x
630
631 dst.y = (src0.y < 0) ? src1.y : src2.y
632
633 dst.z = (src0.z < 0) ? src1.z : src2.z
634
635 dst.w = (src0.w < 0) ? src1.w : src2.w
636
637
638 .. opcode:: KILL_IF - Conditional Discard
639
640 Conditional discard. Allowed in fragment shaders only.
641
642 .. math::
643
644 if (src.x < 0 || src.y < 0 || src.z < 0 || src.w < 0)
645 discard
646 endif
647
648
649 .. opcode:: KILL - Discard
650
651 Unconditional discard. Allowed in fragment shaders only.
652
653
654 .. opcode:: SCS - Sine Cosine
655
656 .. math::
657
658 dst.x = \cos{src.x}
659
660 dst.y = \sin{src.x}
661
662 dst.z = 0
663
664 dst.w = 1
665
666
667 .. opcode:: TXB - Texture Lookup With Bias
668
669 for cube map array textures and shadow cube maps, the bias value
670 cannot be passed in src0.w, and TXB2 must be used instead.
671
672 if the target is a shadow texture, the reference value is always
673 in src.z (this prevents shadow 3d and shadow 2d arrays from
674 using this instruction, but this is not needed).
675
676 .. math::
677
678 coord.x = src0.x
679
680 coord.y = src0.y
681
682 coord.z = src0.z
683
684 coord.w = none
685
686 bias = src0.w
687
688 unit = src1
689
690 dst = texture\_sample(unit, coord, bias)
691
692
693 .. opcode:: TXB2 - Texture Lookup With Bias (some cube maps only)
694
695 this is the same as TXB, but uses another reg to encode the
696 lod bias value for cube map arrays and shadow cube maps.
697 Presumably shadow 2d arrays and shadow 3d targets could use
698 this encoding too, but this is not legal.
699
700 shadow cube map arrays are neither possible nor required.
701
702 .. math::
703
704 coord = src0
705
706 bias = src1.x
707
708 unit = src2
709
710 dst = texture\_sample(unit, coord, bias)
711
712
713 .. opcode:: DIV - Divide
714
715 .. math::
716
717 dst.x = \frac{src0.x}{src1.x}
718
719 dst.y = \frac{src0.y}{src1.y}
720
721 dst.z = \frac{src0.z}{src1.z}
722
723 dst.w = \frac{src0.w}{src1.w}
724
725
726 .. opcode:: DP2 - 2-component Dot Product
727
728 This instruction replicates its result.
729
730 .. math::
731
732 dst = src0.x \times src1.x + src0.y \times src1.y
733
734
735 .. opcode:: TEX_LZ - Texture Lookup With LOD = 0
736
737 This is the same as TXL with LOD = 0. Like every texture opcode, it obeys
738 pipe_sampler_view::u.tex.first_level and pipe_sampler_state::min_lod.
739 There is no way to override those two in shaders.
740
741 .. math::
742
743 coord.x = src0.x
744
745 coord.y = src0.y
746
747 coord.z = src0.z
748
749 coord.w = none
750
751 lod = 0
752
753 unit = src1
754
755 dst = texture\_sample(unit, coord, lod)
756
757
758 .. opcode:: TXL - Texture Lookup With explicit LOD
759
760 for cube map array textures, the explicit lod value
761 cannot be passed in src0.w, and TXL2 must be used instead.
762
763 if the target is a shadow texture, the reference value is always
764 in src.z (this prevents shadow 3d / 2d array / cube targets from
765 using this instruction, but this is not needed).
766
767 .. math::
768
769 coord.x = src0.x
770
771 coord.y = src0.y
772
773 coord.z = src0.z
774
775 coord.w = none
776
777 lod = src0.w
778
779 unit = src1
780
781 dst = texture\_sample(unit, coord, lod)
782
783
784 .. opcode:: TXL2 - Texture Lookup With explicit LOD (for cube map arrays only)
785
786 this is the same as TXL, but uses another reg to encode the
787 explicit lod value.
788 Presumably shadow 3d / 2d array / cube targets could use
789 this encoding too, but this is not legal.
790
791 shadow cube map arrays are neither possible nor required.
792
793 .. math::
794
795 coord = src0
796
797 lod = src1.x
798
799 unit = src2
800
801 dst = texture\_sample(unit, coord, lod)
802
803
804 Compute ISA
805 ^^^^^^^^^^^^^^^^^^^^^^^^
806
807 These opcodes are primarily provided for special-use computational shaders.
808 Support for these opcodes indicated by a special pipe capability bit (TBD).
809
810 XXX doesn't look like most of the opcodes really belong here.
811
812 .. opcode:: CEIL - Ceiling
813
814 .. math::
815
816 dst.x = \lceil src.x\rceil
817
818 dst.y = \lceil src.y\rceil
819
820 dst.z = \lceil src.z\rceil
821
822 dst.w = \lceil src.w\rceil
823
824
825 .. opcode:: TRUNC - Truncate
826
827 .. math::
828
829 dst.x = trunc(src.x)
830
831 dst.y = trunc(src.y)
832
833 dst.z = trunc(src.z)
834
835 dst.w = trunc(src.w)
836
837
838 .. opcode:: MOD - Modulus
839
840 .. math::
841
842 dst.x = src0.x \bmod src1.x
843
844 dst.y = src0.y \bmod src1.y
845
846 dst.z = src0.z \bmod src1.z
847
848 dst.w = src0.w \bmod src1.w
849
850
851 .. opcode:: UARL - Integer Address Register Load
852
853 Moves the contents of the source register, assumed to be an integer, into the
854 destination register, which is assumed to be an address (ADDR) register.
855
856
857 .. opcode:: TXF - Texel Fetch
858
859 As per NV_gpu_shader4, extract a single texel from a specified texture
860 image or PIPE_BUFFER resource. The source sampler may not be a CUBE or
861 SHADOW. src 0 is a
862 four-component signed integer vector used to identify the single texel
863 accessed. 3 components + level. If the texture is multisampled, then
864 the fourth component indicates the sample, not the mipmap level.
865 Just like texture instructions, an optional
866 offset vector is provided, which is subject to various driver restrictions
867 (regarding range, source of offsets). This instruction ignores the sampler
868 state.
869
870 TXF(uint_vec coord, int_vec offset).
871
872
873 .. opcode:: TXQ - Texture Size Query
874
875 As per NV_gpu_program4, retrieve the dimensions of the texture depending on
876 the target. For 1D (width), 2D/RECT/CUBE (width, height), 3D (width, height,
877 depth), 1D array (width, layers), 2D array (width, height, layers).
878 Also return the number of accessible levels (last_level - first_level + 1)
879 in W.
880
881 For components which don't return a resource dimension, their value
882 is undefined.
883
884 .. math::
885
886 lod = src0.x
887
888 dst.x = texture\_width(unit, lod)
889
890 dst.y = texture\_height(unit, lod)
891
892 dst.z = texture\_depth(unit, lod)
893
894 dst.w = texture\_levels(unit)
895
896
897 .. opcode:: TXQS - Texture Samples Query
898
899 This retrieves the number of samples in the texture, and stores it
900 into the x component as an unsigned integer. The other components are
901 undefined. If the texture is not multisampled, this function returns
902 (1, undef, undef, undef).
903
904 .. math::
905
906 dst.x = texture\_samples(unit)
907
908
909 .. opcode:: TG4 - Texture Gather
910
911 As per ARB_texture_gather, gathers the four texels to be used in a bi-linear
912 filtering operation and packs them into a single register. Only works with
913 2D, 2D array, cubemaps, and cubemaps arrays. For 2D textures, only the
914 addressing modes of the sampler and the top level of any mip pyramid are
915 used. Set W to zero. It behaves like the TEX instruction, but a filtered
916 sample is not generated. The four samples that contribute to filtering are
917 placed into xyzw in clockwise order, starting with the (u,v) texture
918 coordinate delta at the following locations (-, +), (+, +), (+, -), (-, -),
919 where the magnitude of the deltas are half a texel.
920
921 PIPE_CAP_TEXTURE_SM5 enhances this instruction to support shadow per-sample
922 depth compares, single component selection, and a non-constant offset. It
923 doesn't allow support for the GL independent offset to get i0,j0. This would
924 require another CAP is hw can do it natively. For now we lower that before
925 TGSI.
926
927 .. math::
928
929 coord = src0
930
931 component = src1
932
933 dst = texture\_gather4 (unit, coord, component)
934
935 (with SM5 - cube array shadow)
936
937 .. math::
938
939 coord = src0
940
941 compare = src1
942
943 dst = texture\_gather (uint, coord, compare)
944
945 .. opcode:: LODQ - level of detail query
946
947 Compute the LOD information that the texture pipe would use to access the
948 texture. The Y component contains the computed LOD lambda_prime. The X
949 component contains the LOD that will be accessed, based on min/max lod's
950 and mipmap filters.
951
952 .. math::
953
954 coord = src0
955
956 dst.xy = lodq(uint, coord);
957
958 .. opcode:: CLOCK - retrieve the current shader time
959
960 Invoking this instruction multiple times in the same shader should
961 cause monotonically increasing values to be returned. The values
962 are implicitly 64-bit, so if fewer than 64 bits of precision are
963 available, to provide expected wraparound semantics, the value
964 should be shifted up so that the most significant bit of the time
965 is the most significant bit of the 64-bit value.
966
967 .. math::
968
969 dst.xy = clock()
970
971
972 Integer ISA
973 ^^^^^^^^^^^^^^^^^^^^^^^^
974 These opcodes are used for integer operations.
975 Support for these opcodes indicated by PIPE_SHADER_CAP_INTEGERS (all of them?)
976
977
978 .. opcode:: I2F - Signed Integer To Float
979
980 Rounding is unspecified (round to nearest even suggested).
981
982 .. math::
983
984 dst.x = (float) src.x
985
986 dst.y = (float) src.y
987
988 dst.z = (float) src.z
989
990 dst.w = (float) src.w
991
992
993 .. opcode:: U2F - Unsigned Integer To Float
994
995 Rounding is unspecified (round to nearest even suggested).
996
997 .. math::
998
999 dst.x = (float) src.x
1000
1001 dst.y = (float) src.y
1002
1003 dst.z = (float) src.z
1004
1005 dst.w = (float) src.w
1006
1007
1008 .. opcode:: F2I - Float to Signed Integer
1009
1010 Rounding is towards zero (truncate).
1011 Values outside signed range (including NaNs) produce undefined results.
1012
1013 .. math::
1014
1015 dst.x = (int) src.x
1016
1017 dst.y = (int) src.y
1018
1019 dst.z = (int) src.z
1020
1021 dst.w = (int) src.w
1022
1023
1024 .. opcode:: F2U - Float to Unsigned Integer
1025
1026 Rounding is towards zero (truncate).
1027 Values outside unsigned range (including NaNs) produce undefined results.
1028
1029 .. math::
1030
1031 dst.x = (unsigned) src.x
1032
1033 dst.y = (unsigned) src.y
1034
1035 dst.z = (unsigned) src.z
1036
1037 dst.w = (unsigned) src.w
1038
1039
1040 .. opcode:: UADD - Integer Add
1041
1042 This instruction works the same for signed and unsigned integers.
1043 The low 32bit of the result is returned.
1044
1045 .. math::
1046
1047 dst.x = src0.x + src1.x
1048
1049 dst.y = src0.y + src1.y
1050
1051 dst.z = src0.z + src1.z
1052
1053 dst.w = src0.w + src1.w
1054
1055
1056 .. opcode:: UMAD - Integer Multiply And Add
1057
1058 This instruction works the same for signed and unsigned integers.
1059 The multiplication returns the low 32bit (as does the result itself).
1060
1061 .. math::
1062
1063 dst.x = src0.x \times src1.x + src2.x
1064
1065 dst.y = src0.y \times src1.y + src2.y
1066
1067 dst.z = src0.z \times src1.z + src2.z
1068
1069 dst.w = src0.w \times src1.w + src2.w
1070
1071
1072 .. opcode:: UMUL - Integer Multiply
1073
1074 This instruction works the same for signed and unsigned integers.
1075 The low 32bit of the result is returned.
1076
1077 .. math::
1078
1079 dst.x = src0.x \times src1.x
1080
1081 dst.y = src0.y \times src1.y
1082
1083 dst.z = src0.z \times src1.z
1084
1085 dst.w = src0.w \times src1.w
1086
1087
1088 .. opcode:: IMUL_HI - Signed Integer Multiply High Bits
1089
1090 The high 32bits of the multiplication of 2 signed integers are returned.
1091
1092 .. math::
1093
1094 dst.x = (src0.x \times src1.x) >> 32
1095
1096 dst.y = (src0.y \times src1.y) >> 32
1097
1098 dst.z = (src0.z \times src1.z) >> 32
1099
1100 dst.w = (src0.w \times src1.w) >> 32
1101
1102
1103 .. opcode:: UMUL_HI - Unsigned Integer Multiply High Bits
1104
1105 The high 32bits of the multiplication of 2 unsigned integers are returned.
1106
1107 .. math::
1108
1109 dst.x = (src0.x \times src1.x) >> 32
1110
1111 dst.y = (src0.y \times src1.y) >> 32
1112
1113 dst.z = (src0.z \times src1.z) >> 32
1114
1115 dst.w = (src0.w \times src1.w) >> 32
1116
1117
1118 .. opcode:: IDIV - Signed Integer Division
1119
1120 TBD: behavior for division by zero.
1121
1122 .. math::
1123
1124 dst.x = \frac{src0.x}{src1.x}
1125
1126 dst.y = \frac{src0.y}{src1.y}
1127
1128 dst.z = \frac{src0.z}{src1.z}
1129
1130 dst.w = \frac{src0.w}{src1.w}
1131
1132
1133 .. opcode:: UDIV - Unsigned Integer Division
1134
1135 For division by zero, 0xffffffff is returned.
1136
1137 .. math::
1138
1139 dst.x = \frac{src0.x}{src1.x}
1140
1141 dst.y = \frac{src0.y}{src1.y}
1142
1143 dst.z = \frac{src0.z}{src1.z}
1144
1145 dst.w = \frac{src0.w}{src1.w}
1146
1147
1148 .. opcode:: UMOD - Unsigned Integer Remainder
1149
1150 If second arg is zero, 0xffffffff is returned.
1151
1152 .. math::
1153
1154 dst.x = src0.x \bmod src1.x
1155
1156 dst.y = src0.y \bmod src1.y
1157
1158 dst.z = src0.z \bmod src1.z
1159
1160 dst.w = src0.w \bmod src1.w
1161
1162
1163 .. opcode:: NOT - Bitwise Not
1164
1165 .. math::
1166
1167 dst.x = \sim src.x
1168
1169 dst.y = \sim src.y
1170
1171 dst.z = \sim src.z
1172
1173 dst.w = \sim src.w
1174
1175
1176 .. opcode:: AND - Bitwise And
1177
1178 .. math::
1179
1180 dst.x = src0.x \& src1.x
1181
1182 dst.y = src0.y \& src1.y
1183
1184 dst.z = src0.z \& src1.z
1185
1186 dst.w = src0.w \& src1.w
1187
1188
1189 .. opcode:: OR - Bitwise Or
1190
1191 .. math::
1192
1193 dst.x = src0.x | src1.x
1194
1195 dst.y = src0.y | src1.y
1196
1197 dst.z = src0.z | src1.z
1198
1199 dst.w = src0.w | src1.w
1200
1201
1202 .. opcode:: XOR - Bitwise Xor
1203
1204 .. math::
1205
1206 dst.x = src0.x \oplus src1.x
1207
1208 dst.y = src0.y \oplus src1.y
1209
1210 dst.z = src0.z \oplus src1.z
1211
1212 dst.w = src0.w \oplus src1.w
1213
1214
1215 .. opcode:: IMAX - Maximum of Signed Integers
1216
1217 .. math::
1218
1219 dst.x = max(src0.x, src1.x)
1220
1221 dst.y = max(src0.y, src1.y)
1222
1223 dst.z = max(src0.z, src1.z)
1224
1225 dst.w = max(src0.w, src1.w)
1226
1227
1228 .. opcode:: UMAX - Maximum of Unsigned Integers
1229
1230 .. math::
1231
1232 dst.x = max(src0.x, src1.x)
1233
1234 dst.y = max(src0.y, src1.y)
1235
1236 dst.z = max(src0.z, src1.z)
1237
1238 dst.w = max(src0.w, src1.w)
1239
1240
1241 .. opcode:: IMIN - Minimum of Signed Integers
1242
1243 .. math::
1244
1245 dst.x = min(src0.x, src1.x)
1246
1247 dst.y = min(src0.y, src1.y)
1248
1249 dst.z = min(src0.z, src1.z)
1250
1251 dst.w = min(src0.w, src1.w)
1252
1253
1254 .. opcode:: UMIN - Minimum of Unsigned Integers
1255
1256 .. math::
1257
1258 dst.x = min(src0.x, src1.x)
1259
1260 dst.y = min(src0.y, src1.y)
1261
1262 dst.z = min(src0.z, src1.z)
1263
1264 dst.w = min(src0.w, src1.w)
1265
1266
1267 .. opcode:: SHL - Shift Left
1268
1269 The shift count is masked with 0x1f before the shift is applied.
1270
1271 .. math::
1272
1273 dst.x = src0.x << (0x1f \& src1.x)
1274
1275 dst.y = src0.y << (0x1f \& src1.y)
1276
1277 dst.z = src0.z << (0x1f \& src1.z)
1278
1279 dst.w = src0.w << (0x1f \& src1.w)
1280
1281
1282 .. opcode:: ISHR - Arithmetic Shift Right (of Signed Integer)
1283
1284 The shift count is masked with 0x1f before the shift is applied.
1285
1286 .. math::
1287
1288 dst.x = src0.x >> (0x1f \& src1.x)
1289
1290 dst.y = src0.y >> (0x1f \& src1.y)
1291
1292 dst.z = src0.z >> (0x1f \& src1.z)
1293
1294 dst.w = src0.w >> (0x1f \& src1.w)
1295
1296
1297 .. opcode:: USHR - Logical Shift Right
1298
1299 The shift count is masked with 0x1f before the shift is applied.
1300
1301 .. math::
1302
1303 dst.x = src0.x >> (unsigned) (0x1f \& src1.x)
1304
1305 dst.y = src0.y >> (unsigned) (0x1f \& src1.y)
1306
1307 dst.z = src0.z >> (unsigned) (0x1f \& src1.z)
1308
1309 dst.w = src0.w >> (unsigned) (0x1f \& src1.w)
1310
1311
1312 .. opcode:: UCMP - Integer Conditional Move
1313
1314 .. math::
1315
1316 dst.x = src0.x ? src1.x : src2.x
1317
1318 dst.y = src0.y ? src1.y : src2.y
1319
1320 dst.z = src0.z ? src1.z : src2.z
1321
1322 dst.w = src0.w ? src1.w : src2.w
1323
1324
1325
1326 .. opcode:: ISSG - Integer Set Sign
1327
1328 .. math::
1329
1330 dst.x = (src0.x < 0) ? -1 : (src0.x > 0) ? 1 : 0
1331
1332 dst.y = (src0.y < 0) ? -1 : (src0.y > 0) ? 1 : 0
1333
1334 dst.z = (src0.z < 0) ? -1 : (src0.z > 0) ? 1 : 0
1335
1336 dst.w = (src0.w < 0) ? -1 : (src0.w > 0) ? 1 : 0
1337
1338
1339
1340 .. opcode:: FSLT - Float Set On Less Than (ordered)
1341
1342 Same comparison as SLT but returns integer instead of 1.0/0.0 float
1343
1344 .. math::
1345
1346 dst.x = (src0.x < src1.x) ? \sim 0 : 0
1347
1348 dst.y = (src0.y < src1.y) ? \sim 0 : 0
1349
1350 dst.z = (src0.z < src1.z) ? \sim 0 : 0
1351
1352 dst.w = (src0.w < src1.w) ? \sim 0 : 0
1353
1354
1355 .. opcode:: ISLT - Signed Integer Set On Less Than
1356
1357 .. math::
1358
1359 dst.x = (src0.x < src1.x) ? \sim 0 : 0
1360
1361 dst.y = (src0.y < src1.y) ? \sim 0 : 0
1362
1363 dst.z = (src0.z < src1.z) ? \sim 0 : 0
1364
1365 dst.w = (src0.w < src1.w) ? \sim 0 : 0
1366
1367
1368 .. opcode:: USLT - Unsigned Integer Set On Less Than
1369
1370 .. math::
1371
1372 dst.x = (src0.x < src1.x) ? \sim 0 : 0
1373
1374 dst.y = (src0.y < src1.y) ? \sim 0 : 0
1375
1376 dst.z = (src0.z < src1.z) ? \sim 0 : 0
1377
1378 dst.w = (src0.w < src1.w) ? \sim 0 : 0
1379
1380
1381 .. opcode:: FSGE - Float Set On Greater Equal Than (ordered)
1382
1383 Same comparison as SGE but returns integer instead of 1.0/0.0 float
1384
1385 .. math::
1386
1387 dst.x = (src0.x >= src1.x) ? \sim 0 : 0
1388
1389 dst.y = (src0.y >= src1.y) ? \sim 0 : 0
1390
1391 dst.z = (src0.z >= src1.z) ? \sim 0 : 0
1392
1393 dst.w = (src0.w >= src1.w) ? \sim 0 : 0
1394
1395
1396 .. opcode:: ISGE - Signed Integer Set On Greater Equal Than
1397
1398 .. math::
1399
1400 dst.x = (src0.x >= src1.x) ? \sim 0 : 0
1401
1402 dst.y = (src0.y >= src1.y) ? \sim 0 : 0
1403
1404 dst.z = (src0.z >= src1.z) ? \sim 0 : 0
1405
1406 dst.w = (src0.w >= src1.w) ? \sim 0 : 0
1407
1408
1409 .. opcode:: USGE - Unsigned Integer Set On Greater Equal Than
1410
1411 .. math::
1412
1413 dst.x = (src0.x >= src1.x) ? \sim 0 : 0
1414
1415 dst.y = (src0.y >= src1.y) ? \sim 0 : 0
1416
1417 dst.z = (src0.z >= src1.z) ? \sim 0 : 0
1418
1419 dst.w = (src0.w >= src1.w) ? \sim 0 : 0
1420
1421
1422 .. opcode:: FSEQ - Float Set On Equal (ordered)
1423
1424 Same comparison as SEQ but returns integer instead of 1.0/0.0 float
1425
1426 .. math::
1427
1428 dst.x = (src0.x == src1.x) ? \sim 0 : 0
1429
1430 dst.y = (src0.y == src1.y) ? \sim 0 : 0
1431
1432 dst.z = (src0.z == src1.z) ? \sim 0 : 0
1433
1434 dst.w = (src0.w == src1.w) ? \sim 0 : 0
1435
1436
1437 .. opcode:: USEQ - Integer Set On Equal
1438
1439 .. math::
1440
1441 dst.x = (src0.x == src1.x) ? \sim 0 : 0
1442
1443 dst.y = (src0.y == src1.y) ? \sim 0 : 0
1444
1445 dst.z = (src0.z == src1.z) ? \sim 0 : 0
1446
1447 dst.w = (src0.w == src1.w) ? \sim 0 : 0
1448
1449
1450 .. opcode:: FSNE - Float Set On Not Equal (unordered)
1451
1452 Same comparison as SNE but returns integer instead of 1.0/0.0 float
1453
1454 .. math::
1455
1456 dst.x = (src0.x != src1.x) ? \sim 0 : 0
1457
1458 dst.y = (src0.y != src1.y) ? \sim 0 : 0
1459
1460 dst.z = (src0.z != src1.z) ? \sim 0 : 0
1461
1462 dst.w = (src0.w != src1.w) ? \sim 0 : 0
1463
1464
1465 .. opcode:: USNE - Integer Set On Not Equal
1466
1467 .. math::
1468
1469 dst.x = (src0.x != src1.x) ? \sim 0 : 0
1470
1471 dst.y = (src0.y != src1.y) ? \sim 0 : 0
1472
1473 dst.z = (src0.z != src1.z) ? \sim 0 : 0
1474
1475 dst.w = (src0.w != src1.w) ? \sim 0 : 0
1476
1477
1478 .. opcode:: INEG - Integer Negate
1479
1480 Two's complement.
1481
1482 .. math::
1483
1484 dst.x = -src.x
1485
1486 dst.y = -src.y
1487
1488 dst.z = -src.z
1489
1490 dst.w = -src.w
1491
1492
1493 .. opcode:: IABS - Integer Absolute Value
1494
1495 .. math::
1496
1497 dst.x = |src.x|
1498
1499 dst.y = |src.y|
1500
1501 dst.z = |src.z|
1502
1503 dst.w = |src.w|
1504
1505 Bitwise ISA
1506 ^^^^^^^^^^^
1507 These opcodes are used for bit-level manipulation of integers.
1508
1509 .. opcode:: IBFE - Signed Bitfield Extract
1510
1511 Like GLSL bitfieldExtract. Extracts a set of bits from the input, and
1512 sign-extends them if the high bit of the extracted window is set.
1513
1514 Pseudocode::
1515
1516 def ibfe(value, offset, bits):
1517 if offset < 0 or bits < 0 or offset + bits > 32:
1518 return undefined
1519 if bits == 0: return 0
1520 # Note: >> sign-extends
1521 return (value << (32 - offset - bits)) >> (32 - bits)
1522
1523 .. opcode:: UBFE - Unsigned Bitfield Extract
1524
1525 Like GLSL bitfieldExtract. Extracts a set of bits from the input, without
1526 any sign-extension.
1527
1528 Pseudocode::
1529
1530 def ubfe(value, offset, bits):
1531 if offset < 0 or bits < 0 or offset + bits > 32:
1532 return undefined
1533 if bits == 0: return 0
1534 # Note: >> does not sign-extend
1535 return (value << (32 - offset - bits)) >> (32 - bits)
1536
1537 .. opcode:: BFI - Bitfield Insert
1538
1539 Like GLSL bitfieldInsert. Replaces a bit region of 'base' with the low bits
1540 of 'insert'.
1541
1542 Pseudocode::
1543
1544 def bfi(base, insert, offset, bits):
1545 if offset < 0 or bits < 0 or offset + bits > 32:
1546 return undefined
1547 # << defined such that mask == ~0 when bits == 32, offset == 0
1548 mask = ((1 << bits) - 1) << offset
1549 return ((insert << offset) & mask) | (base & ~mask)
1550
1551 .. opcode:: BREV - Bitfield Reverse
1552
1553 See SM5 instruction BFREV. Reverses the bits of the argument.
1554
1555 .. opcode:: POPC - Population Count
1556
1557 See SM5 instruction COUNTBITS. Counts the number of set bits in the argument.
1558
1559 .. opcode:: LSB - Index of lowest set bit
1560
1561 See SM5 instruction FIRSTBIT_LO. Computes the 0-based index of the first set
1562 bit of the argument. Returns -1 if none are set.
1563
1564 .. opcode:: IMSB - Index of highest non-sign bit
1565
1566 See SM5 instruction FIRSTBIT_SHI. Computes the 0-based index of the highest
1567 non-sign bit of the argument (i.e. highest 0 bit for negative numbers,
1568 highest 1 bit for positive numbers). Returns -1 if all bits are the same
1569 (i.e. for inputs 0 and -1).
1570
1571 .. opcode:: UMSB - Index of highest set bit
1572
1573 See SM5 instruction FIRSTBIT_HI. Computes the 0-based index of the highest
1574 set bit of the argument. Returns -1 if none are set.
1575
1576 Geometry ISA
1577 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1578
1579 These opcodes are only supported in geometry shaders; they have no meaning
1580 in any other type of shader.
1581
1582 .. opcode:: EMIT - Emit
1583
1584 Generate a new vertex for the current primitive into the specified vertex
1585 stream using the values in the output registers.
1586
1587
1588 .. opcode:: ENDPRIM - End Primitive
1589
1590 Complete the current primitive in the specified vertex stream (consisting of
1591 the emitted vertices), and start a new one.
1592
1593
1594 GLSL ISA
1595 ^^^^^^^^^^
1596
1597 These opcodes are part of :term:`GLSL`'s opcode set. Support for these
1598 opcodes is determined by a special capability bit, ``GLSL``.
1599 Some require glsl version 1.30 (UIF/SWITCH/CASE/DEFAULT/ENDSWITCH).
1600
1601 .. opcode:: CAL - Subroutine Call
1602
1603 push(pc)
1604 pc = target
1605
1606
1607 .. opcode:: RET - Subroutine Call Return
1608
1609 pc = pop()
1610
1611
1612 .. opcode:: CONT - Continue
1613
1614 Unconditionally moves the point of execution to the instruction after the
1615 last bgnloop. The instruction must appear within a bgnloop/endloop.
1616
1617 .. note::
1618
1619 Support for CONT is determined by a special capability bit,
1620 ``TGSI_CONT_SUPPORTED``. See :ref:`Screen` for more information.
1621
1622
1623 .. opcode:: BGNLOOP - Begin a Loop
1624
1625 Start a loop. Must have a matching endloop.
1626
1627
1628 .. opcode:: BGNSUB - Begin Subroutine
1629
1630 Starts definition of a subroutine. Must have a matching endsub.
1631
1632
1633 .. opcode:: ENDLOOP - End a Loop
1634
1635 End a loop started with bgnloop.
1636
1637
1638 .. opcode:: ENDSUB - End Subroutine
1639
1640 Ends definition of a subroutine.
1641
1642
1643 .. opcode:: NOP - No Operation
1644
1645 Do nothing.
1646
1647
1648 .. opcode:: BRK - Break
1649
1650 Unconditionally moves the point of execution to the instruction after the
1651 next endloop or endswitch. The instruction must appear within a loop/endloop
1652 or switch/endswitch.
1653
1654
1655 .. opcode:: IF - Float If
1656
1657 Start an IF ... ELSE .. ENDIF block. Condition evaluates to true if
1658
1659 src0.x != 0.0
1660
1661 where src0.x is interpreted as a floating point register.
1662
1663
1664 .. opcode:: UIF - Bitwise If
1665
1666 Start an UIF ... ELSE .. ENDIF block. Condition evaluates to true if
1667
1668 src0.x != 0
1669
1670 where src0.x is interpreted as an integer register.
1671
1672
1673 .. opcode:: ELSE - Else
1674
1675 Starts an else block, after an IF or UIF statement.
1676
1677
1678 .. opcode:: ENDIF - End If
1679
1680 Ends an IF or UIF block.
1681
1682
1683 .. opcode:: SWITCH - Switch
1684
1685 Starts a C-style switch expression. The switch consists of one or multiple
1686 CASE statements, and at most one DEFAULT statement. Execution of a statement
1687 ends when a BRK is hit, but just like in C falling through to other cases
1688 without a break is allowed. Similarly, DEFAULT label is allowed anywhere not
1689 just as last statement, and fallthrough is allowed into/from it.
1690 CASE src arguments are evaluated at bit level against the SWITCH src argument.
1691
1692 Example::
1693
1694 SWITCH src[0].x
1695 CASE src[0].x
1696 (some instructions here)
1697 (optional BRK here)
1698 DEFAULT
1699 (some instructions here)
1700 (optional BRK here)
1701 CASE src[0].x
1702 (some instructions here)
1703 (optional BRK here)
1704 ENDSWITCH
1705
1706
1707 .. opcode:: CASE - Switch case
1708
1709 This represents a switch case label. The src arg must be an integer immediate.
1710
1711
1712 .. opcode:: DEFAULT - Switch default
1713
1714 This represents the default case in the switch, which is taken if no other
1715 case matches.
1716
1717
1718 .. opcode:: ENDSWITCH - End of switch
1719
1720 Ends a switch expression.
1721
1722
1723 Interpolation ISA
1724 ^^^^^^^^^^^^^^^^^
1725
1726 The interpolation instructions allow an input to be interpolated in a
1727 different way than its declaration. This corresponds to the GLSL 4.00
1728 interpolateAt* functions. The first argument of each of these must come from
1729 ``TGSI_FILE_INPUT``.
1730
1731 .. opcode:: INTERP_CENTROID - Interpolate at the centroid
1732
1733 Interpolates the varying specified by src0 at the centroid
1734
1735 .. opcode:: INTERP_SAMPLE - Interpolate at the specified sample
1736
1737 Interpolates the varying specified by src0 at the sample id specified by
1738 src1.x (interpreted as an integer)
1739
1740 .. opcode:: INTERP_OFFSET - Interpolate at the specified offset
1741
1742 Interpolates the varying specified by src0 at the offset src1.xy from the
1743 pixel center (interpreted as floats)
1744
1745
1746 .. _doubleopcodes:
1747
1748 Double ISA
1749 ^^^^^^^^^^^^^^^
1750
1751 The double-precision opcodes reinterpret four-component vectors into
1752 two-component vectors with doubled precision in each component.
1753
1754 .. opcode:: DABS - Absolute
1755
1756 .. math::
1757
1758 dst.xy = |src0.xy|
1759
1760 dst.zw = |src0.zw|
1761
1762 .. opcode:: DADD - Add
1763
1764 .. math::
1765
1766 dst.xy = src0.xy + src1.xy
1767
1768 dst.zw = src0.zw + src1.zw
1769
1770 .. opcode:: DSEQ - Set on Equal
1771
1772 .. math::
1773
1774 dst.x = src0.xy == src1.xy ? \sim 0 : 0
1775
1776 dst.z = src0.zw == src1.zw ? \sim 0 : 0
1777
1778 .. opcode:: DSNE - Set on Equal
1779
1780 .. math::
1781
1782 dst.x = src0.xy != src1.xy ? \sim 0 : 0
1783
1784 dst.z = src0.zw != src1.zw ? \sim 0 : 0
1785
1786 .. opcode:: DSLT - Set on Less than
1787
1788 .. math::
1789
1790 dst.x = src0.xy < src1.xy ? \sim 0 : 0
1791
1792 dst.z = src0.zw < src1.zw ? \sim 0 : 0
1793
1794 .. opcode:: DSGE - Set on Greater equal
1795
1796 .. math::
1797
1798 dst.x = src0.xy >= src1.xy ? \sim 0 : 0
1799
1800 dst.z = src0.zw >= src1.zw ? \sim 0 : 0
1801
1802 .. opcode:: DFRAC - Fraction
1803
1804 .. math::
1805
1806 dst.xy = src.xy - \lfloor src.xy\rfloor
1807
1808 dst.zw = src.zw - \lfloor src.zw\rfloor
1809
1810 .. opcode:: DTRUNC - Truncate
1811
1812 .. math::
1813
1814 dst.xy = trunc(src.xy)
1815
1816 dst.zw = trunc(src.zw)
1817
1818 .. opcode:: DCEIL - Ceiling
1819
1820 .. math::
1821
1822 dst.xy = \lceil src.xy\rceil
1823
1824 dst.zw = \lceil src.zw\rceil
1825
1826 .. opcode:: DFLR - Floor
1827
1828 .. math::
1829
1830 dst.xy = \lfloor src.xy\rfloor
1831
1832 dst.zw = \lfloor src.zw\rfloor
1833
1834 .. opcode:: DROUND - Fraction
1835
1836 .. math::
1837
1838 dst.xy = round(src.xy)
1839
1840 dst.zw = round(src.zw)
1841
1842 .. opcode:: DSSG - Set Sign
1843
1844 .. math::
1845
1846 dst.xy = (src.xy > 0) ? 1.0 : (src.xy < 0) ? -1.0 : 0.0
1847
1848 dst.zw = (src.zw > 0) ? 1.0 : (src.zw < 0) ? -1.0 : 0.0
1849
1850 .. opcode:: DFRACEXP - Convert Number to Fractional and Integral Components
1851
1852 Like the ``frexp()`` routine in many math libraries, this opcode stores the
1853 exponent of its source to ``dst0``, and the significand to ``dst1``, such that
1854 :math:`dst1 \times 2^{dst0} = src` .
1855
1856 .. math::
1857
1858 dst0.xy = exp(src.xy)
1859
1860 dst1.xy = frac(src.xy)
1861
1862 dst0.zw = exp(src.zw)
1863
1864 dst1.zw = frac(src.zw)
1865
1866 .. opcode:: DLDEXP - Multiply Number by Integral Power of 2
1867
1868 This opcode is the inverse of :opcode:`DFRACEXP`. The second
1869 source is an integer.
1870
1871 .. math::
1872
1873 dst.xy = src0.xy \times 2^{src1.x}
1874
1875 dst.zw = src0.zw \times 2^{src1.y}
1876
1877 .. opcode:: DMIN - Minimum
1878
1879 .. math::
1880
1881 dst.xy = min(src0.xy, src1.xy)
1882
1883 dst.zw = min(src0.zw, src1.zw)
1884
1885 .. opcode:: DMAX - Maximum
1886
1887 .. math::
1888
1889 dst.xy = max(src0.xy, src1.xy)
1890
1891 dst.zw = max(src0.zw, src1.zw)
1892
1893 .. opcode:: DMUL - Multiply
1894
1895 .. math::
1896
1897 dst.xy = src0.xy \times src1.xy
1898
1899 dst.zw = src0.zw \times src1.zw
1900
1901
1902 .. opcode:: DMAD - Multiply And Add
1903
1904 .. math::
1905
1906 dst.xy = src0.xy \times src1.xy + src2.xy
1907
1908 dst.zw = src0.zw \times src1.zw + src2.zw
1909
1910
1911 .. opcode:: DFMA - Fused Multiply-Add
1912
1913 Perform a * b + c with no intermediate rounding step.
1914
1915 .. math::
1916
1917 dst.xy = src0.xy \times src1.xy + src2.xy
1918
1919 dst.zw = src0.zw \times src1.zw + src2.zw
1920
1921
1922 .. opcode:: DDIV - Divide
1923
1924 .. math::
1925
1926 dst.xy = \frac{src0.xy}{src1.xy}
1927
1928 dst.zw = \frac{src0.zw}{src1.zw}
1929
1930
1931 .. opcode:: DRCP - Reciprocal
1932
1933 .. math::
1934
1935 dst.xy = \frac{1}{src.xy}
1936
1937 dst.zw = \frac{1}{src.zw}
1938
1939 .. opcode:: DSQRT - Square Root
1940
1941 .. math::
1942
1943 dst.xy = \sqrt{src.xy}
1944
1945 dst.zw = \sqrt{src.zw}
1946
1947 .. opcode:: DRSQ - Reciprocal Square Root
1948
1949 .. math::
1950
1951 dst.xy = \frac{1}{\sqrt{src.xy}}
1952
1953 dst.zw = \frac{1}{\sqrt{src.zw}}
1954
1955 .. opcode:: F2D - Float to Double
1956
1957 .. math::
1958
1959 dst.xy = double(src0.x)
1960
1961 dst.zw = double(src0.y)
1962
1963 .. opcode:: D2F - Double to Float
1964
1965 .. math::
1966
1967 dst.x = float(src0.xy)
1968
1969 dst.y = float(src0.zw)
1970
1971 .. opcode:: I2D - Int to Double
1972
1973 .. math::
1974
1975 dst.xy = double(src0.x)
1976
1977 dst.zw = double(src0.y)
1978
1979 .. opcode:: D2I - Double to Int
1980
1981 .. math::
1982
1983 dst.x = int(src0.xy)
1984
1985 dst.y = int(src0.zw)
1986
1987 .. opcode:: U2D - Unsigned Int to Double
1988
1989 .. math::
1990
1991 dst.xy = double(src0.x)
1992
1993 dst.zw = double(src0.y)
1994
1995 .. opcode:: D2U - Double to Unsigned Int
1996
1997 .. math::
1998
1999 dst.x = unsigned(src0.xy)
2000
2001 dst.y = unsigned(src0.zw)
2002
2003 64-bit Integer ISA
2004 ^^^^^^^^^^^^^^^^^^
2005
2006 The 64-bit integer opcodes reinterpret four-component vectors into
2007 two-component vectors with 64-bits in each component.
2008
2009 .. opcode:: I64ABS - 64-bit Integer Absolute Value
2010
2011 .. math::
2012
2013 dst.xy = |src0.xy|
2014
2015 dst.zw = |src0.zw|
2016
2017 .. opcode:: I64NEG - 64-bit Integer Negate
2018
2019 Two's complement.
2020
2021 .. math::
2022
2023 dst.xy = -src.xy
2024
2025 dst.zw = -src.zw
2026
2027 .. opcode:: I64SSG - 64-bit Integer Set Sign
2028
2029 .. math::
2030
2031 dst.xy = (src0.xy < 0) ? -1 : (src0.xy > 0) ? 1 : 0
2032
2033 dst.zw = (src0.zw < 0) ? -1 : (src0.zw > 0) ? 1 : 0
2034
2035 .. opcode:: U64ADD - 64-bit Integer Add
2036
2037 .. math::
2038
2039 dst.xy = src0.xy + src1.xy
2040
2041 dst.zw = src0.zw + src1.zw
2042
2043 .. opcode:: U64MUL - 64-bit Integer Multiply
2044
2045 .. math::
2046
2047 dst.xy = src0.xy * src1.xy
2048
2049 dst.zw = src0.zw * src1.zw
2050
2051 .. opcode:: U64SEQ - 64-bit Integer Set on Equal
2052
2053 .. math::
2054
2055 dst.x = src0.xy == src1.xy ? \sim 0 : 0
2056
2057 dst.z = src0.zw == src1.zw ? \sim 0 : 0
2058
2059 .. opcode:: U64SNE - 64-bit Integer Set on Not Equal
2060
2061 .. math::
2062
2063 dst.x = src0.xy != src1.xy ? \sim 0 : 0
2064
2065 dst.z = src0.zw != src1.zw ? \sim 0 : 0
2066
2067 .. opcode:: U64SLT - 64-bit Unsigned Integer Set on Less Than
2068
2069 .. math::
2070
2071 dst.x = src0.xy < src1.xy ? \sim 0 : 0
2072
2073 dst.z = src0.zw < src1.zw ? \sim 0 : 0
2074
2075 .. opcode:: U64SGE - 64-bit Unsigned Integer Set on Greater Equal
2076
2077 .. math::
2078
2079 dst.x = src0.xy >= src1.xy ? \sim 0 : 0
2080
2081 dst.z = src0.zw >= src1.zw ? \sim 0 : 0
2082
2083 .. opcode:: I64SLT - 64-bit Signed Integer Set on Less Than
2084
2085 .. math::
2086
2087 dst.x = src0.xy < src1.xy ? \sim 0 : 0
2088
2089 dst.z = src0.zw < src1.zw ? \sim 0 : 0
2090
2091 .. opcode:: I64SGE - 64-bit Signed Integer Set on Greater Equal
2092
2093 .. math::
2094
2095 dst.x = src0.xy >= src1.xy ? \sim 0 : 0
2096
2097 dst.z = src0.zw >= src1.zw ? \sim 0 : 0
2098
2099 .. opcode:: I64MIN - Minimum of 64-bit Signed Integers
2100
2101 .. math::
2102
2103 dst.xy = min(src0.xy, src1.xy)
2104
2105 dst.zw = min(src0.zw, src1.zw)
2106
2107 .. opcode:: U64MIN - Minimum of 64-bit Unsigned Integers
2108
2109 .. math::
2110
2111 dst.xy = min(src0.xy, src1.xy)
2112
2113 dst.zw = min(src0.zw, src1.zw)
2114
2115 .. opcode:: I64MAX - Maximum of 64-bit Signed Integers
2116
2117 .. math::
2118
2119 dst.xy = max(src0.xy, src1.xy)
2120
2121 dst.zw = max(src0.zw, src1.zw)
2122
2123 .. opcode:: U64MAX - Maximum of 64-bit Unsigned Integers
2124
2125 .. math::
2126
2127 dst.xy = max(src0.xy, src1.xy)
2128
2129 dst.zw = max(src0.zw, src1.zw)
2130
2131 .. opcode:: U64SHL - Shift Left 64-bit Unsigned Integer
2132
2133 The shift count is masked with 0x3f before the shift is applied.
2134
2135 .. math::
2136
2137 dst.xy = src0.xy << (0x3f \& src1.x)
2138
2139 dst.zw = src0.zw << (0x3f \& src1.y)
2140
2141 .. opcode:: I64SHR - Arithmetic Shift Right (of 64-bit Signed Integer)
2142
2143 The shift count is masked with 0x3f before the shift is applied.
2144
2145 .. math::
2146
2147 dst.xy = src0.xy >> (0x3f \& src1.x)
2148
2149 dst.zw = src0.zw >> (0x3f \& src1.y)
2150
2151 .. opcode:: U64SHR - Logical Shift Right (of 64-bit Unsigned Integer)
2152
2153 The shift count is masked with 0x3f before the shift is applied.
2154
2155 .. math::
2156
2157 dst.xy = src0.xy >> (unsigned) (0x3f \& src1.x)
2158
2159 dst.zw = src0.zw >> (unsigned) (0x3f \& src1.y)
2160
2161 .. opcode:: I64DIV - 64-bit Signed Integer Division
2162
2163 .. math::
2164
2165 dst.xy = \frac{src0.xy}{src1.xy}
2166
2167 dst.zw = \frac{src0.zw}{src1.zw}
2168
2169 .. opcode:: U64DIV - 64-bit Unsigned Integer Division
2170
2171 .. math::
2172
2173 dst.xy = \frac{src0.xy}{src1.xy}
2174
2175 dst.zw = \frac{src0.zw}{src1.zw}
2176
2177 .. opcode:: U64MOD - 64-bit Unsigned Integer Remainder
2178
2179 .. math::
2180
2181 dst.xy = src0.xy \bmod src1.xy
2182
2183 dst.zw = src0.zw \bmod src1.zw
2184
2185 .. opcode:: I64MOD - 64-bit Signed Integer Remainder
2186
2187 .. math::
2188
2189 dst.xy = src0.xy \bmod src1.xy
2190
2191 dst.zw = src0.zw \bmod src1.zw
2192
2193 .. opcode:: F2U64 - Float to 64-bit Unsigned Int
2194
2195 .. math::
2196
2197 dst.xy = (uint64_t) src0.x
2198
2199 dst.zw = (uint64_t) src0.y
2200
2201 .. opcode:: F2I64 - Float to 64-bit Int
2202
2203 .. math::
2204
2205 dst.xy = (int64_t) src0.x
2206
2207 dst.zw = (int64_t) src0.y
2208
2209 .. opcode:: U2I64 - Unsigned Integer to 64-bit Integer
2210
2211 This is a zero extension.
2212
2213 .. math::
2214
2215 dst.xy = (uint64_t) src0.x
2216
2217 dst.zw = (uint64_t) src0.y
2218
2219 .. opcode:: I2I64 - Signed Integer to 64-bit Integer
2220
2221 This is a sign extension.
2222
2223 .. math::
2224
2225 dst.xy = (int64_t) src0.x
2226
2227 dst.zw = (int64_t) src0.y
2228
2229 .. opcode:: D2U64 - Double to 64-bit Unsigned Int
2230
2231 .. math::
2232
2233 dst.xy = (uint64_t) src0.xy
2234
2235 dst.zw = (uint64_t) src0.zw
2236
2237 .. opcode:: D2I64 - Double to 64-bit Int
2238
2239 .. math::
2240
2241 dst.xy = (int64_t) src0.xy
2242
2243 dst.zw = (int64_t) src0.zw
2244
2245 .. opcode:: U642F - 64-bit unsigned integer to float
2246
2247 .. math::
2248
2249 dst.x = (float) src0.xy
2250
2251 dst.y = (float) src0.zw
2252
2253 .. opcode:: I642F - 64-bit Int to Float
2254
2255 .. math::
2256
2257 dst.x = (float) src0.xy
2258
2259 dst.y = (float) src0.zw
2260
2261 .. opcode:: U642D - 64-bit unsigned integer to double
2262
2263 .. math::
2264
2265 dst.xy = (double) src0.xy
2266
2267 dst.zw = (double) src0.zw
2268
2269 .. opcode:: I642D - 64-bit Int to double
2270
2271 .. math::
2272
2273 dst.xy = (double) src0.xy
2274
2275 dst.zw = (double) src0.zw
2276
2277 .. _samplingopcodes:
2278
2279 Resource Sampling Opcodes
2280 ^^^^^^^^^^^^^^^^^^^^^^^^^
2281
2282 Those opcodes follow very closely semantics of the respective Direct3D
2283 instructions. If in doubt double check Direct3D documentation.
2284 Note that the swizzle on SVIEW (src1) determines texel swizzling
2285 after lookup.
2286
2287 .. opcode:: SAMPLE
2288
2289 Using provided address, sample data from the specified texture using the
2290 filtering mode identified by the given sampler. The source data may come from
2291 any resource type other than buffers.
2292
2293 Syntax: ``SAMPLE dst, address, sampler_view, sampler``
2294
2295 Example: ``SAMPLE TEMP[0], TEMP[1], SVIEW[0], SAMP[0]``
2296
2297 .. opcode:: SAMPLE_I
2298
2299 Simplified alternative to the SAMPLE instruction. Using the provided
2300 integer address, SAMPLE_I fetches data from the specified sampler view
2301 without any filtering. The source data may come from any resource type
2302 other than CUBE.
2303
2304 Syntax: ``SAMPLE_I dst, address, sampler_view``
2305
2306 Example: ``SAMPLE_I TEMP[0], TEMP[1], SVIEW[0]``
2307
2308 The 'address' is specified as unsigned integers. If the 'address' is out of
2309 range [0...(# texels - 1)] the result of the fetch is always 0 in all
2310 components. As such the instruction doesn't honor address wrap modes, in
2311 cases where that behavior is desirable 'SAMPLE' instruction should be used.
2312 address.w always provides an unsigned integer mipmap level. If the value is
2313 out of the range then the instruction always returns 0 in all components.
2314 address.yz are ignored for buffers and 1d textures. address.z is ignored
2315 for 1d texture arrays and 2d textures.
2316
2317 For 1D texture arrays address.y provides the array index (also as unsigned
2318 integer). If the value is out of the range of available array indices
2319 [0... (array size - 1)] then the opcode always returns 0 in all components.
2320 For 2D texture arrays address.z provides the array index, otherwise it
2321 exhibits the same behavior as in the case for 1D texture arrays. The exact
2322 semantics of the source address are presented in the table below:
2323
2324 +---------------------------+----+-----+-----+---------+
2325 | resource type | X | Y | Z | W |
2326 +===========================+====+=====+=====+=========+
2327 | ``PIPE_BUFFER`` | x | | | ignored |
2328 +---------------------------+----+-----+-----+---------+
2329 | ``PIPE_TEXTURE_1D`` | x | | | mpl |
2330 +---------------------------+----+-----+-----+---------+
2331 | ``PIPE_TEXTURE_2D`` | x | y | | mpl |
2332 +---------------------------+----+-----+-----+---------+
2333 | ``PIPE_TEXTURE_3D`` | x | y | z | mpl |
2334 +---------------------------+----+-----+-----+---------+
2335 | ``PIPE_TEXTURE_RECT`` | x | y | | mpl |
2336 +---------------------------+----+-----+-----+---------+
2337 | ``PIPE_TEXTURE_CUBE`` | not allowed as source |
2338 +---------------------------+----+-----+-----+---------+
2339 | ``PIPE_TEXTURE_1D_ARRAY`` | x | idx | | mpl |
2340 +---------------------------+----+-----+-----+---------+
2341 | ``PIPE_TEXTURE_2D_ARRAY`` | x | y | idx | mpl |
2342 +---------------------------+----+-----+-----+---------+
2343
2344 Where 'mpl' is a mipmap level and 'idx' is the array index.
2345
2346 .. opcode:: SAMPLE_I_MS
2347
2348 Just like SAMPLE_I but allows fetch data from multi-sampled surfaces.
2349
2350 Syntax: ``SAMPLE_I_MS dst, address, sampler_view, sample``
2351
2352 .. opcode:: SAMPLE_B
2353
2354 Just like the SAMPLE instruction with the exception that an additional bias
2355 is applied to the level of detail computed as part of the instruction
2356 execution.
2357
2358 Syntax: ``SAMPLE_B dst, address, sampler_view, sampler, lod_bias``
2359
2360 Example: ``SAMPLE_B TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2].x``
2361
2362 .. opcode:: SAMPLE_C
2363
2364 Similar to the SAMPLE instruction but it performs a comparison filter. The
2365 operands to SAMPLE_C are identical to SAMPLE, except that there is an
2366 additional float32 operand, reference value, which must be a register with
2367 single-component, or a scalar literal. SAMPLE_C makes the hardware use the
2368 current samplers compare_func (in pipe_sampler_state) to compare reference
2369 value against the red component value for the surce resource at each texel
2370 that the currently configured texture filter covers based on the provided
2371 coordinates.
2372
2373 Syntax: ``SAMPLE_C dst, address, sampler_view.r, sampler, ref_value``
2374
2375 Example: ``SAMPLE_C TEMP[0], TEMP[1], SVIEW[0].r, SAMP[0], TEMP[2].x``
2376
2377 .. opcode:: SAMPLE_C_LZ
2378
2379 Same as SAMPLE_C, but LOD is 0 and derivatives are ignored. The LZ stands
2380 for level-zero.
2381
2382 Syntax: ``SAMPLE_C_LZ dst, address, sampler_view.r, sampler, ref_value``
2383
2384 Example: ``SAMPLE_C_LZ TEMP[0], TEMP[1], SVIEW[0].r, SAMP[0], TEMP[2].x``
2385
2386
2387 .. opcode:: SAMPLE_D
2388
2389 SAMPLE_D is identical to the SAMPLE opcode except that the derivatives for
2390 the source address in the x direction and the y direction are provided by
2391 extra parameters.
2392
2393 Syntax: ``SAMPLE_D dst, address, sampler_view, sampler, der_x, der_y``
2394
2395 Example: ``SAMPLE_D TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2], TEMP[3]``
2396
2397 .. opcode:: SAMPLE_L
2398
2399 SAMPLE_L is identical to the SAMPLE opcode except that the LOD is provided
2400 directly as a scalar value, representing no anisotropy.
2401
2402 Syntax: ``SAMPLE_L dst, address, sampler_view, sampler, explicit_lod``
2403
2404 Example: ``SAMPLE_L TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2].x``
2405
2406 .. opcode:: GATHER4
2407
2408 Gathers the four texels to be used in a bi-linear filtering operation and
2409 packs them into a single register. Only works with 2D, 2D array, cubemaps,
2410 and cubemaps arrays. For 2D textures, only the addressing modes of the
2411 sampler and the top level of any mip pyramid are used. Set W to zero. It
2412 behaves like the SAMPLE instruction, but a filtered sample is not
2413 generated. The four samples that contribute to filtering are placed into
2414 xyzw in counter-clockwise order, starting with the (u,v) texture coordinate
2415 delta at the following locations (-, +), (+, +), (+, -), (-, -), where the
2416 magnitude of the deltas are half a texel.
2417
2418
2419 .. opcode:: SVIEWINFO
2420
2421 Query the dimensions of a given sampler view. dst receives width, height,
2422 depth or array size and number of mipmap levels as int4. The dst can have a
2423 writemask which will specify what info is the caller interested in.
2424
2425 Syntax: ``SVIEWINFO dst, src_mip_level, sampler_view``
2426
2427 Example: ``SVIEWINFO TEMP[0], TEMP[1].x, SVIEW[0]``
2428
2429 src_mip_level is an unsigned integer scalar. If it's out of range then
2430 returns 0 for width, height and depth/array size but the total number of
2431 mipmap is still returned correctly for the given sampler view. The returned
2432 width, height and depth values are for the mipmap level selected by the
2433 src_mip_level and are in the number of texels. For 1d texture array width
2434 is in dst.x, array size is in dst.y and dst.z is 0. The number of mipmaps is
2435 still in dst.w. In contrast to d3d10 resinfo, there's no way in the tgsi
2436 instruction encoding to specify the return type (float/rcpfloat/uint), hence
2437 always using uint. Also, unlike the SAMPLE instructions, the swizzle on src1
2438 resinfo allowing swizzling dst values is ignored (due to the interaction
2439 with rcpfloat modifier which requires some swizzle handling in the state
2440 tracker anyway).
2441
2442 .. opcode:: SAMPLE_POS
2443
2444 Query the position of a sample in the given resource or render target
2445 when per-sample fragment shading is in effect.
2446
2447 Syntax: ``SAMPLE_POS dst, source, sample_index``
2448
2449 dst receives float4 (x, y, undef, undef) indicated where the sample is
2450 located. Sample locations are in the range [0, 1] where 0.5 is the center
2451 of the fragment.
2452
2453 source is either a sampler view (to indicate a shader resource) or temp
2454 register (to indicate the render target). The source register may have
2455 an optional swizzle to apply to the returned result
2456
2457 sample_index is an integer scalar indicating which sample position is to
2458 be queried.
2459
2460 If per-sample shading is not in effect or the source resource or render
2461 target is not multisampled, the result is (0.5, 0.5, undef, undef).
2462
2463 NOTE: no driver has implemented this opcode yet (and no state tracker
2464 emits it). This information is subject to change.
2465
2466 .. opcode:: SAMPLE_INFO
2467
2468 Query the number of samples in a multisampled resource or render target.
2469
2470 Syntax: ``SAMPLE_INFO dst, source``
2471
2472 dst receives int4 (n, 0, 0, 0) where n is the number of samples in a
2473 resource or the render target.
2474
2475 source is either a sampler view (to indicate a shader resource) or temp
2476 register (to indicate the render target). The source register may have
2477 an optional swizzle to apply to the returned result
2478
2479 If per-sample shading is not in effect or the source resource or render
2480 target is not multisampled, the result is (1, 0, 0, 0).
2481
2482 NOTE: no driver has implemented this opcode yet (and no state tracker
2483 emits it). This information is subject to change.
2484
2485 .. _resourceopcodes:
2486
2487 Resource Access Opcodes
2488 ^^^^^^^^^^^^^^^^^^^^^^^
2489
2490 For these opcodes, the resource can be a BUFFER, IMAGE, or MEMORY.
2491
2492 .. opcode:: LOAD - Fetch data from a shader buffer or image
2493
2494 Syntax: ``LOAD dst, resource, address``
2495
2496 Example: ``LOAD TEMP[0], BUFFER[0], TEMP[1]``
2497
2498 Using the provided integer address, LOAD fetches data
2499 from the specified buffer or texture without any
2500 filtering.
2501
2502 The 'address' is specified as a vector of unsigned
2503 integers. If the 'address' is out of range the result
2504 is unspecified.
2505
2506 Only the first mipmap level of a resource can be read
2507 from using this instruction.
2508
2509 For 1D or 2D texture arrays, the array index is
2510 provided as an unsigned integer in address.y or
2511 address.z, respectively. address.yz are ignored for
2512 buffers and 1D textures. address.z is ignored for 1D
2513 texture arrays and 2D textures. address.w is always
2514 ignored.
2515
2516 A swizzle suffix may be added to the resource argument
2517 this will cause the resource data to be swizzled accordingly.
2518
2519 .. opcode:: STORE - Write data to a shader resource
2520
2521 Syntax: ``STORE resource, address, src``
2522
2523 Example: ``STORE BUFFER[0], TEMP[0], TEMP[1]``
2524
2525 Using the provided integer address, STORE writes data
2526 to the specified buffer or texture.
2527
2528 The 'address' is specified as a vector of unsigned
2529 integers. If the 'address' is out of range the result
2530 is unspecified.
2531
2532 Only the first mipmap level of a resource can be
2533 written to using this instruction.
2534
2535 For 1D or 2D texture arrays, the array index is
2536 provided as an unsigned integer in address.y or
2537 address.z, respectively. address.yz are ignored for
2538 buffers and 1D textures. address.z is ignored for 1D
2539 texture arrays and 2D textures. address.w is always
2540 ignored.
2541
2542 .. opcode:: RESQ - Query information about a resource
2543
2544 Syntax: ``RESQ dst, resource``
2545
2546 Example: ``RESQ TEMP[0], BUFFER[0]``
2547
2548 Returns information about the buffer or image resource. For buffer
2549 resources, the size (in bytes) is returned in the x component. For
2550 image resources, .xyz will contain the width/height/layers of the
2551 image, while .w will contain the number of samples for multi-sampled
2552 images.
2553
2554 .. opcode:: FBFETCH - Load data from framebuffer
2555
2556 Syntax: ``FBFETCH dst, output``
2557
2558 Example: ``FBFETCH TEMP[0], OUT[0]``
2559
2560 This is only valid on ``COLOR`` semantic outputs. Returns the color
2561 of the current position in the framebuffer from before this fragment
2562 shader invocation. May return the same value from multiple calls for
2563 a particular output within a single invocation. Note that result may
2564 be undefined if a fragment is drawn multiple times without a blend
2565 barrier in between.
2566
2567
2568 .. _threadsyncopcodes:
2569
2570 Inter-thread synchronization opcodes
2571 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2572
2573 These opcodes are intended for communication between threads running
2574 within the same compute grid. For now they're only valid in compute
2575 programs.
2576
2577 .. opcode:: BARRIER - Thread group barrier
2578
2579 ``BARRIER``
2580
2581 This opcode suspends the execution of the current thread until all
2582 the remaining threads in the working group reach the same point of
2583 the program. Results are unspecified if any of the remaining
2584 threads terminates or never reaches an executed BARRIER instruction.
2585
2586 .. opcode:: MEMBAR - Memory barrier
2587
2588 ``MEMBAR type``
2589
2590 This opcode waits for the completion of all memory accesses based on
2591 the type passed in. The type is an immediate bitfield with the following
2592 meaning:
2593
2594 Bit 0: Shader storage buffers
2595 Bit 1: Atomic buffers
2596 Bit 2: Images
2597 Bit 3: Shared memory
2598 Bit 4: Thread group
2599
2600 These may be passed in in any combination. An implementation is free to not
2601 distinguish between these as it sees fit. However these map to all the
2602 possibilities made available by GLSL.
2603
2604 .. _atomopcodes:
2605
2606 Atomic opcodes
2607 ^^^^^^^^^^^^^^
2608
2609 These opcodes provide atomic variants of some common arithmetic and
2610 logical operations. In this context atomicity means that another
2611 concurrent memory access operation that affects the same memory
2612 location is guaranteed to be performed strictly before or after the
2613 entire execution of the atomic operation. The resource may be a BUFFER,
2614 IMAGE, or MEMORY. In the case of an image, the offset works the same as for
2615 ``LOAD`` and ``STORE``, specified above. These atomic operations may
2616 only be used with 32-bit integer image formats.
2617
2618 .. opcode:: ATOMUADD - Atomic integer addition
2619
2620 Syntax: ``ATOMUADD dst, resource, offset, src``
2621
2622 Example: ``ATOMUADD TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2623
2624 The following operation is performed atomically:
2625
2626 .. math::
2627
2628 dst_x = resource[offset]
2629
2630 resource[offset] = dst_x + src_x
2631
2632
2633 .. opcode:: ATOMXCHG - Atomic exchange
2634
2635 Syntax: ``ATOMXCHG dst, resource, offset, src``
2636
2637 Example: ``ATOMXCHG TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2638
2639 The following operation is performed atomically:
2640
2641 .. math::
2642
2643 dst_x = resource[offset]
2644
2645 resource[offset] = src_x
2646
2647
2648 .. opcode:: ATOMCAS - Atomic compare-and-exchange
2649
2650 Syntax: ``ATOMCAS dst, resource, offset, cmp, src``
2651
2652 Example: ``ATOMCAS TEMP[0], BUFFER[0], TEMP[1], TEMP[2], TEMP[3]``
2653
2654 The following operation is performed atomically:
2655
2656 .. math::
2657
2658 dst_x = resource[offset]
2659
2660 resource[offset] = (dst_x == cmp_x ? src_x : dst_x)
2661
2662
2663 .. opcode:: ATOMAND - Atomic bitwise And
2664
2665 Syntax: ``ATOMAND dst, resource, offset, src``
2666
2667 Example: ``ATOMAND TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2668
2669 The following operation is performed atomically:
2670
2671 .. math::
2672
2673 dst_x = resource[offset]
2674
2675 resource[offset] = dst_x \& src_x
2676
2677
2678 .. opcode:: ATOMOR - Atomic bitwise Or
2679
2680 Syntax: ``ATOMOR dst, resource, offset, src``
2681
2682 Example: ``ATOMOR TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2683
2684 The following operation is performed atomically:
2685
2686 .. math::
2687
2688 dst_x = resource[offset]
2689
2690 resource[offset] = dst_x | src_x
2691
2692
2693 .. opcode:: ATOMXOR - Atomic bitwise Xor
2694
2695 Syntax: ``ATOMXOR dst, resource, offset, src``
2696
2697 Example: ``ATOMXOR TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2698
2699 The following operation is performed atomically:
2700
2701 .. math::
2702
2703 dst_x = resource[offset]
2704
2705 resource[offset] = dst_x \oplus src_x
2706
2707
2708 .. opcode:: ATOMUMIN - Atomic unsigned minimum
2709
2710 Syntax: ``ATOMUMIN dst, resource, offset, src``
2711
2712 Example: ``ATOMUMIN TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2713
2714 The following operation is performed atomically:
2715
2716 .. math::
2717
2718 dst_x = resource[offset]
2719
2720 resource[offset] = (dst_x < src_x ? dst_x : src_x)
2721
2722
2723 .. opcode:: ATOMUMAX - Atomic unsigned maximum
2724
2725 Syntax: ``ATOMUMAX dst, resource, offset, src``
2726
2727 Example: ``ATOMUMAX TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2728
2729 The following operation is performed atomically:
2730
2731 .. math::
2732
2733 dst_x = resource[offset]
2734
2735 resource[offset] = (dst_x > src_x ? dst_x : src_x)
2736
2737
2738 .. opcode:: ATOMIMIN - Atomic signed minimum
2739
2740 Syntax: ``ATOMIMIN dst, resource, offset, src``
2741
2742 Example: ``ATOMIMIN TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2743
2744 The following operation is performed atomically:
2745
2746 .. math::
2747
2748 dst_x = resource[offset]
2749
2750 resource[offset] = (dst_x < src_x ? dst_x : src_x)
2751
2752
2753 .. opcode:: ATOMIMAX - Atomic signed maximum
2754
2755 Syntax: ``ATOMIMAX dst, resource, offset, src``
2756
2757 Example: ``ATOMIMAX TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2758
2759 The following operation is performed atomically:
2760
2761 .. math::
2762
2763 dst_x = resource[offset]
2764
2765 resource[offset] = (dst_x > src_x ? dst_x : src_x)
2766
2767
2768 .. _interlaneopcodes:
2769
2770 Inter-lane opcodes
2771 ^^^^^^^^^^^^^^^^^^
2772
2773 These opcodes reduce the given value across the shader invocations
2774 running in the current SIMD group. Every thread in the subgroup will receive
2775 the same result. The BALLOT operations accept a single-channel argument that
2776 is treated as a boolean and produce a 64-bit value.
2777
2778 .. opcode:: VOTE_ANY - Value is set in any of the active invocations
2779
2780 Syntax: ``VOTE_ANY dst, value``
2781
2782 Example: ``VOTE_ANY TEMP[0].x, TEMP[1].x``
2783
2784
2785 .. opcode:: VOTE_ALL - Value is set in all of the active invocations
2786
2787 Syntax: ``VOTE_ALL dst, value``
2788
2789 Example: ``VOTE_ALL TEMP[0].x, TEMP[1].x``
2790
2791
2792 .. opcode:: VOTE_EQ - Value is the same in all of the active invocations
2793
2794 Syntax: ``VOTE_EQ dst, value``
2795
2796 Example: ``VOTE_EQ TEMP[0].x, TEMP[1].x``
2797
2798
2799 .. opcode:: BALLOT - Lanemask of whether the value is set in each active
2800 invocation
2801
2802 Syntax: ``BALLOT dst, value``
2803
2804 Example: ``BALLOT TEMP[0].xy, TEMP[1].x``
2805
2806 When the argument is a constant true, this produces a bitmask of active
2807 invocations. In fragment shaders, this can include helper invocations
2808 (invocations whose outputs and writes to memory are discarded, but which
2809 are used to compute derivatives).
2810
2811
2812 .. opcode:: READ_FIRST - Broadcast the value from the first active
2813 invocation to all active lanes
2814
2815 Syntax: ``READ_FIRST dst, value``
2816
2817 Example: ``READ_FIRST TEMP[0], TEMP[1]``
2818
2819
2820 .. opcode:: READ_INVOC - Retrieve the value from the given invocation
2821 (need not be uniform)
2822
2823 Syntax: ``READ_INVOC dst, value, invocation``
2824
2825 Example: ``READ_INVOC TEMP[0].xy, TEMP[1].xy, TEMP[2].x``
2826
2827 invocation.x controls the invocation number to read from for all channels.
2828 The invocation number must be the same across all active invocations in a
2829 sub-group; otherwise, the results are undefined.
2830
2831
2832 Explanation of symbols used
2833 ------------------------------
2834
2835
2836 Functions
2837 ^^^^^^^^^^^^^^
2838
2839
2840 :math:`|x|` Absolute value of `x`.
2841
2842 :math:`\lceil x \rceil` Ceiling of `x`.
2843
2844 clamp(x,y,z) Clamp x between y and z.
2845 (x < y) ? y : (x > z) ? z : x
2846
2847 :math:`\lfloor x\rfloor` Floor of `x`.
2848
2849 :math:`\log_2{x}` Logarithm of `x`, base 2.
2850
2851 max(x,y) Maximum of x and y.
2852 (x > y) ? x : y
2853
2854 min(x,y) Minimum of x and y.
2855 (x < y) ? x : y
2856
2857 partialx(x) Derivative of x relative to fragment's X.
2858
2859 partialy(x) Derivative of x relative to fragment's Y.
2860
2861 pop() Pop from stack.
2862
2863 :math:`x^y` `x` to the power `y`.
2864
2865 push(x) Push x on stack.
2866
2867 round(x) Round x.
2868
2869 trunc(x) Truncate x, i.e. drop the fraction bits.
2870
2871
2872 Keywords
2873 ^^^^^^^^^^^^^
2874
2875
2876 discard Discard fragment.
2877
2878 pc Program counter.
2879
2880 target Label of target instruction.
2881
2882
2883 Other tokens
2884 ---------------
2885
2886
2887 Declaration
2888 ^^^^^^^^^^^
2889
2890
2891 Declares a register that is will be referenced as an operand in Instruction
2892 tokens.
2893
2894 File field contains register file that is being declared and is one
2895 of TGSI_FILE.
2896
2897 UsageMask field specifies which of the register components can be accessed
2898 and is one of TGSI_WRITEMASK.
2899
2900 The Local flag specifies that a given value isn't intended for
2901 subroutine parameter passing and, as a result, the implementation
2902 isn't required to give any guarantees of it being preserved across
2903 subroutine boundaries. As it's merely a compiler hint, the
2904 implementation is free to ignore it.
2905
2906 If Dimension flag is set to 1, a Declaration Dimension token follows.
2907
2908 If Semantic flag is set to 1, a Declaration Semantic token follows.
2909
2910 If Interpolate flag is set to 1, a Declaration Interpolate token follows.
2911
2912 If file is TGSI_FILE_RESOURCE, a Declaration Resource token follows.
2913
2914 If Array flag is set to 1, a Declaration Array token follows.
2915
2916 Array Declaration
2917 ^^^^^^^^^^^^^^^^^^^^^^^^
2918
2919 Declarations can optional have an ArrayID attribute which can be referred by
2920 indirect addressing operands. An ArrayID of zero is reserved and treated as
2921 if no ArrayID is specified.
2922
2923 If an indirect addressing operand refers to a specific declaration by using
2924 an ArrayID only the registers in this declaration are guaranteed to be
2925 accessed, accessing any register outside this declaration results in undefined
2926 behavior. Note that for compatibility the effective index is zero-based and
2927 not relative to the specified declaration
2928
2929 If no ArrayID is specified with an indirect addressing operand the whole
2930 register file might be accessed by this operand. This is strongly discouraged
2931 and will prevent packing of scalar/vec2 arrays and effective alias analysis.
2932 This is only legal for TEMP and CONST register files.
2933
2934 Declaration Semantic
2935 ^^^^^^^^^^^^^^^^^^^^^^^^
2936
2937 Vertex and fragment shader input and output registers may be labeled
2938 with semantic information consisting of a name and index.
2939
2940 Follows Declaration token if Semantic bit is set.
2941
2942 Since its purpose is to link a shader with other stages of the pipeline,
2943 it is valid to follow only those Declaration tokens that declare a register
2944 either in INPUT or OUTPUT file.
2945
2946 SemanticName field contains the semantic name of the register being declared.
2947 There is no default value.
2948
2949 SemanticIndex is an optional subscript that can be used to distinguish
2950 different register declarations with the same semantic name. The default value
2951 is 0.
2952
2953 The meanings of the individual semantic names are explained in the following
2954 sections.
2955
2956 TGSI_SEMANTIC_POSITION
2957 """"""""""""""""""""""
2958
2959 For vertex shaders, TGSI_SEMANTIC_POSITION indicates the vertex shader
2960 output register which contains the homogeneous vertex position in the clip
2961 space coordinate system. After clipping, the X, Y and Z components of the
2962 vertex will be divided by the W value to get normalized device coordinates.
2963
2964 For fragment shaders, TGSI_SEMANTIC_POSITION is used to indicate that
2965 fragment shader input (or system value, depending on which one is
2966 supported by the driver) contains the fragment's window position. The X
2967 component starts at zero and always increases from left to right.
2968 The Y component starts at zero and always increases but Y=0 may either
2969 indicate the top of the window or the bottom depending on the fragment
2970 coordinate origin convention (see TGSI_PROPERTY_FS_COORD_ORIGIN).
2971 The Z coordinate ranges from 0 to 1 to represent depth from the front
2972 to the back of the Z buffer. The W component contains the interpolated
2973 reciprocal of the vertex position W component (corresponding to gl_Fragcoord,
2974 but unlike d3d10 which interpolates the same 1/w but then gives back
2975 the reciprocal of the interpolated value).
2976
2977 Fragment shaders may also declare an output register with
2978 TGSI_SEMANTIC_POSITION. Only the Z component is writable. This allows
2979 the fragment shader to change the fragment's Z position.
2980
2981
2982
2983 TGSI_SEMANTIC_COLOR
2984 """""""""""""""""""
2985
2986 For vertex shader outputs or fragment shader inputs/outputs, this
2987 label indicates that the register contains an R,G,B,A color.
2988
2989 Several shader inputs/outputs may contain colors so the semantic index
2990 is used to distinguish them. For example, color[0] may be the diffuse
2991 color while color[1] may be the specular color.
2992
2993 This label is needed so that the flat/smooth shading can be applied
2994 to the right interpolants during rasterization.
2995
2996
2997
2998 TGSI_SEMANTIC_BCOLOR
2999 """"""""""""""""""""
3000
3001 Back-facing colors are only used for back-facing polygons, and are only valid
3002 in vertex shader outputs. After rasterization, all polygons are front-facing
3003 and COLOR and BCOLOR end up occupying the same slots in the fragment shader,
3004 so all BCOLORs effectively become regular COLORs in the fragment shader.
3005
3006
3007 TGSI_SEMANTIC_FOG
3008 """""""""""""""""
3009
3010 Vertex shader inputs and outputs and fragment shader inputs may be
3011 labeled with TGSI_SEMANTIC_FOG to indicate that the register contains
3012 a fog coordinate. Typically, the fragment shader will use the fog coordinate
3013 to compute a fog blend factor which is used to blend the normal fragment color
3014 with a constant fog color. But fog coord really is just an ordinary vec4
3015 register like regular semantics.
3016
3017
3018 TGSI_SEMANTIC_PSIZE
3019 """""""""""""""""""
3020
3021 Vertex shader input and output registers may be labeled with
3022 TGIS_SEMANTIC_PSIZE to indicate that the register contains a point size
3023 in the form (S, 0, 0, 1). The point size controls the width or diameter
3024 of points for rasterization. This label cannot be used in fragment
3025 shaders.
3026
3027 When using this semantic, be sure to set the appropriate state in the
3028 :ref:`rasterizer` first.
3029
3030
3031 TGSI_SEMANTIC_TEXCOORD
3032 """"""""""""""""""""""
3033
3034 Only available if PIPE_CAP_TGSI_TEXCOORD is exposed !
3035
3036 Vertex shader outputs and fragment shader inputs may be labeled with
3037 this semantic to make them replaceable by sprite coordinates via the
3038 sprite_coord_enable state in the :ref:`rasterizer`.
3039 The semantic index permitted with this semantic is limited to <= 7.
3040
3041 If the driver does not support TEXCOORD, sprite coordinate replacement
3042 applies to inputs with the GENERIC semantic instead.
3043
3044 The intended use case for this semantic is gl_TexCoord.
3045
3046
3047 TGSI_SEMANTIC_PCOORD
3048 """"""""""""""""""""
3049
3050 Only available if PIPE_CAP_TGSI_TEXCOORD is exposed !
3051
3052 Fragment shader inputs may be labeled with TGSI_SEMANTIC_PCOORD to indicate
3053 that the register contains sprite coordinates in the form (x, y, 0, 1), if
3054 the current primitive is a point and point sprites are enabled. Otherwise,
3055 the contents of the register are undefined.
3056
3057 The intended use case for this semantic is gl_PointCoord.
3058
3059
3060 TGSI_SEMANTIC_GENERIC
3061 """""""""""""""""""""
3062
3063 All vertex/fragment shader inputs/outputs not labeled with any other
3064 semantic label can be considered to be generic attributes. Typical
3065 uses of generic inputs/outputs are texcoords and user-defined values.
3066
3067
3068 TGSI_SEMANTIC_NORMAL
3069 """"""""""""""""""""
3070
3071 Indicates that a vertex shader input is a normal vector. This is
3072 typically only used for legacy graphics APIs.
3073
3074
3075 TGSI_SEMANTIC_FACE
3076 """"""""""""""""""
3077
3078 This label applies to fragment shader inputs (or system values,
3079 depending on which one is supported by the driver) and indicates that
3080 the register contains front/back-face information.
3081
3082 If it is an input, it will be a floating-point vector in the form (F, 0, 0, 1),
3083 where F will be positive when the fragment belongs to a front-facing polygon,
3084 and negative when the fragment belongs to a back-facing polygon.
3085
3086 If it is a system value, it will be an integer vector in the form (F, 0, 0, 1),
3087 where F is 0xffffffff when the fragment belongs to a front-facing polygon and
3088 0 when the fragment belongs to a back-facing polygon.
3089
3090
3091 TGSI_SEMANTIC_EDGEFLAG
3092 """"""""""""""""""""""
3093
3094 For vertex shaders, this sematic label indicates that an input or
3095 output is a boolean edge flag. The register layout is [F, x, x, x]
3096 where F is 0.0 or 1.0 and x = don't care. Normally, the vertex shader
3097 simply copies the edge flag input to the edgeflag output.
3098
3099 Edge flags are used to control which lines or points are actually
3100 drawn when the polygon mode converts triangles/quads/polygons into
3101 points or lines.
3102
3103
3104 TGSI_SEMANTIC_STENCIL
3105 """""""""""""""""""""
3106
3107 For fragment shaders, this semantic label indicates that an output
3108 is a writable stencil reference value. Only the Y component is writable.
3109 This allows the fragment shader to change the fragments stencilref value.
3110
3111
3112 TGSI_SEMANTIC_VIEWPORT_INDEX
3113 """"""""""""""""""""""""""""
3114
3115 For geometry shaders, this semantic label indicates that an output
3116 contains the index of the viewport (and scissor) to use.
3117 This is an integer value, and only the X component is used.
3118
3119 If PIPE_CAP_TGSI_VS_LAYER_VIEWPORT or PIPE_CAP_TGSI_TES_LAYER_VIEWPORT is
3120 supported, then this semantic label can also be used in vertex or
3121 tessellation evaluation shaders, respectively. Only the value written in the
3122 last vertex processing stage is used.
3123
3124
3125 TGSI_SEMANTIC_LAYER
3126 """""""""""""""""""
3127
3128 For geometry shaders, this semantic label indicates that an output
3129 contains the layer value to use for the color and depth/stencil surfaces.
3130 This is an integer value, and only the X component is used.
3131 (Also known as rendertarget array index.)
3132
3133 If PIPE_CAP_TGSI_VS_LAYER_VIEWPORT or PIPE_CAP_TGSI_TES_LAYER_VIEWPORT is
3134 supported, then this semantic label can also be used in vertex or
3135 tessellation evaluation shaders, respectively. Only the value written in the
3136 last vertex processing stage is used.
3137
3138
3139 TGSI_SEMANTIC_CULLDIST
3140 """"""""""""""""""""""
3141
3142 Used as distance to plane for performing application-defined culling
3143 of individual primitives against a plane. When components of vertex
3144 elements are given this label, these values are assumed to be a
3145 float32 signed distance to a plane. Primitives will be completely
3146 discarded if the plane distance for all of the vertices in the
3147 primitive are < 0. If a vertex has a cull distance of NaN, that
3148 vertex counts as "out" (as if its < 0);
3149 The limits on both clip and cull distances are bound
3150 by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT define which defines
3151 the maximum number of components that can be used to hold the
3152 distances and by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
3153 which specifies the maximum number of registers which can be
3154 annotated with those semantics.
3155
3156
3157 TGSI_SEMANTIC_CLIPDIST
3158 """"""""""""""""""""""
3159
3160 Note this covers clipping and culling distances.
3161
3162 When components of vertex elements are identified this way, these
3163 values are each assumed to be a float32 signed distance to a plane.
3164
3165 For clip distances:
3166 Primitive setup only invokes rasterization on pixels for which
3167 the interpolated plane distances are >= 0.
3168
3169 For cull distances:
3170 Primitives will be completely discarded if the plane distance
3171 for all of the vertices in the primitive are < 0.
3172 If a vertex has a cull distance of NaN, that vertex counts as "out"
3173 (as if its < 0);
3174
3175 Multiple clip/cull planes can be implemented simultaneously, by
3176 annotating multiple components of one or more vertex elements with
3177 the above specified semantic.
3178 The limits on both clip and cull distances are bound
3179 by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT define which defines
3180 the maximum number of components that can be used to hold the
3181 distances and by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
3182 which specifies the maximum number of registers which can be
3183 annotated with those semantics.
3184 The properties NUM_CLIPDIST_ENABLED and NUM_CULLDIST_ENABLED
3185 are used to divide up the 2 x vec4 space between clipping and culling.
3186
3187 TGSI_SEMANTIC_SAMPLEID
3188 """"""""""""""""""""""
3189
3190 For fragment shaders, this semantic label indicates that a system value
3191 contains the current sample id (i.e. gl_SampleID) as an unsigned int.
3192 Only the X component is used. If per-sample shading is not enabled,
3193 the result is (0, undef, undef, undef).
3194
3195 Note that if the fragment shader uses this system value, the fragment
3196 shader is automatically executed at per sample frequency.
3197
3198 TGSI_SEMANTIC_SAMPLEPOS
3199 """""""""""""""""""""""
3200
3201 For fragment shaders, this semantic label indicates that a system
3202 value contains the current sample's position as float4(x, y, undef, undef)
3203 in the render target (i.e. gl_SamplePosition) when per-fragment shading
3204 is in effect. Position values are in the range [0, 1] where 0.5 is
3205 the center of the fragment.
3206
3207 Note that if the fragment shader uses this system value, the fragment
3208 shader is automatically executed at per sample frequency.
3209
3210 TGSI_SEMANTIC_SAMPLEMASK
3211 """"""""""""""""""""""""
3212
3213 For fragment shaders, this semantic label can be applied to either a
3214 shader system value input or output.
3215
3216 For a system value, the sample mask indicates the set of samples covered by
3217 the current primitive. If MSAA is not enabled, the value is (1, 0, 0, 0).
3218
3219 For an output, the sample mask is used to disable further sample processing.
3220
3221 For both, the register type is uint[4] but only the X component is used
3222 (i.e. gl_SampleMask[0]). Each bit corresponds to one sample position (up
3223 to 32x MSAA is supported).
3224
3225 TGSI_SEMANTIC_INVOCATIONID
3226 """"""""""""""""""""""""""
3227
3228 For geometry shaders, this semantic label indicates that a system value
3229 contains the current invocation id (i.e. gl_InvocationID).
3230 This is an integer value, and only the X component is used.
3231
3232 TGSI_SEMANTIC_INSTANCEID
3233 """"""""""""""""""""""""
3234
3235 For vertex shaders, this semantic label indicates that a system value contains
3236 the current instance id (i.e. gl_InstanceID). It does not include the base
3237 instance. This is an integer value, and only the X component is used.
3238
3239 TGSI_SEMANTIC_VERTEXID
3240 """"""""""""""""""""""
3241
3242 For vertex shaders, this semantic label indicates that a system value contains
3243 the current vertex id (i.e. gl_VertexID). It does (unlike in d3d10) include the
3244 base vertex. This is an integer value, and only the X component is used.
3245
3246 TGSI_SEMANTIC_VERTEXID_NOBASE
3247 """""""""""""""""""""""""""""""
3248
3249 For vertex shaders, this semantic label indicates that a system value contains
3250 the current vertex id without including the base vertex (this corresponds to
3251 d3d10 vertex id, so TGSI_SEMANTIC_VERTEXID_NOBASE + TGSI_SEMANTIC_BASEVERTEX
3252 == TGSI_SEMANTIC_VERTEXID). This is an integer value, and only the X component
3253 is used.
3254
3255 TGSI_SEMANTIC_BASEVERTEX
3256 """"""""""""""""""""""""
3257
3258 For vertex shaders, this semantic label indicates that a system value contains
3259 the base vertex (i.e. gl_BaseVertex). Note that for non-indexed draw calls,
3260 this contains the first (or start) value instead.
3261 This is an integer value, and only the X component is used.
3262
3263 TGSI_SEMANTIC_PRIMID
3264 """"""""""""""""""""
3265
3266 For geometry and fragment shaders, this semantic label indicates the value
3267 contains the primitive id (i.e. gl_PrimitiveID). This is an integer value,
3268 and only the X component is used.
3269 FIXME: This right now can be either a ordinary input or a system value...
3270
3271
3272 TGSI_SEMANTIC_PATCH
3273 """""""""""""""""""
3274
3275 For tessellation evaluation/control shaders, this semantic label indicates a
3276 generic per-patch attribute. Such semantics will not implicitly be per-vertex
3277 arrays.
3278
3279 TGSI_SEMANTIC_TESSCOORD
3280 """""""""""""""""""""""
3281
3282 For tessellation evaluation shaders, this semantic label indicates the
3283 coordinates of the vertex being processed. This is available in XYZ; W is
3284 undefined.
3285
3286 TGSI_SEMANTIC_TESSOUTER
3287 """""""""""""""""""""""
3288
3289 For tessellation evaluation/control shaders, this semantic label indicates the
3290 outer tessellation levels of the patch. Isoline tessellation will only have XY
3291 defined, triangle will have XYZ and quads will have XYZW defined. This
3292 corresponds to gl_TessLevelOuter.
3293
3294 TGSI_SEMANTIC_TESSINNER
3295 """""""""""""""""""""""
3296
3297 For tessellation evaluation/control shaders, this semantic label indicates the
3298 inner tessellation levels of the patch. The X value is only defined for
3299 triangle tessellation, while quads will have XY defined. This is entirely
3300 undefined for isoline tessellation.
3301
3302 TGSI_SEMANTIC_VERTICESIN
3303 """"""""""""""""""""""""
3304
3305 For tessellation evaluation/control shaders, this semantic label indicates the
3306 number of vertices provided in the input patch. Only the X value is defined.
3307
3308 TGSI_SEMANTIC_HELPER_INVOCATION
3309 """""""""""""""""""""""""""""""
3310
3311 For fragment shaders, this semantic indicates whether the current
3312 invocation is covered or not. Helper invocations are created in order
3313 to properly compute derivatives, however it may be desirable to skip
3314 some of the logic in those cases. See ``gl_HelperInvocation`` documentation.
3315
3316 TGSI_SEMANTIC_BASEINSTANCE
3317 """"""""""""""""""""""""""
3318
3319 For vertex shaders, the base instance argument supplied for this
3320 draw. This is an integer value, and only the X component is used.
3321
3322 TGSI_SEMANTIC_DRAWID
3323 """"""""""""""""""""
3324
3325 For vertex shaders, the zero-based index of the current draw in a
3326 ``glMultiDraw*`` invocation. This is an integer value, and only the X
3327 component is used.
3328
3329
3330 TGSI_SEMANTIC_WORK_DIM
3331 """"""""""""""""""""""
3332
3333 For compute shaders started via opencl this retrieves the work_dim
3334 parameter to the clEnqueueNDRangeKernel call with which the shader
3335 was started.
3336
3337
3338 TGSI_SEMANTIC_GRID_SIZE
3339 """""""""""""""""""""""
3340
3341 For compute shaders, this semantic indicates the maximum (x, y, z) dimensions
3342 of a grid of thread blocks.
3343
3344
3345 TGSI_SEMANTIC_BLOCK_ID
3346 """"""""""""""""""""""
3347
3348 For compute shaders, this semantic indicates the (x, y, z) coordinates of the
3349 current block inside of the grid.
3350
3351
3352 TGSI_SEMANTIC_BLOCK_SIZE
3353 """"""""""""""""""""""""
3354
3355 For compute shaders, this semantic indicates the maximum (x, y, z) dimensions
3356 of a block in threads.
3357
3358
3359 TGSI_SEMANTIC_THREAD_ID
3360 """""""""""""""""""""""
3361
3362 For compute shaders, this semantic indicates the (x, y, z) coordinates of the
3363 current thread inside of the block.
3364
3365
3366 TGSI_SEMANTIC_SUBGROUP_SIZE
3367 """""""""""""""""""""""""""
3368
3369 This semantic indicates the subgroup size for the current invocation. This is
3370 an integer of at most 64, as it indicates the width of lanemasks. It does not
3371 depend on the number of invocations that are active.
3372
3373
3374 TGSI_SEMANTIC_SUBGROUP_INVOCATION
3375 """""""""""""""""""""""""""""""""
3376
3377 The index of the current invocation within its subgroup.
3378
3379
3380 TGSI_SEMANTIC_SUBGROUP_EQ_MASK
3381 """"""""""""""""""""""""""""""
3382
3383 A bit mask of ``bit index == TGSI_SEMANTIC_SUBGROUP_INVOCATION``, i.e.
3384 ``1 << subgroup_invocation`` in arbitrary precision arithmetic.
3385
3386
3387 TGSI_SEMANTIC_SUBGROUP_GE_MASK
3388 """"""""""""""""""""""""""""""
3389
3390 A bit mask of ``bit index >= TGSI_SEMANTIC_SUBGROUP_INVOCATION``, i.e.
3391 ``((1 << (subgroup_size - subgroup_invocation)) - 1) << subgroup_invocation``
3392 in arbitrary precision arithmetic.
3393
3394
3395 TGSI_SEMANTIC_SUBGROUP_GT_MASK
3396 """"""""""""""""""""""""""""""
3397
3398 A bit mask of ``bit index > TGSI_SEMANTIC_SUBGROUP_INVOCATION``, i.e.
3399 ``((1 << (subgroup_size - subgroup_invocation - 1)) - 1) << (subgroup_invocation + 1)``
3400 in arbitrary precision arithmetic.
3401
3402
3403 TGSI_SEMANTIC_SUBGROUP_LE_MASK
3404 """"""""""""""""""""""""""""""
3405
3406 A bit mask of ``bit index <= TGSI_SEMANTIC_SUBGROUP_INVOCATION``, i.e.
3407 ``(1 << (subgroup_invocation + 1)) - 1`` in arbitrary precision arithmetic.
3408
3409
3410 TGSI_SEMANTIC_SUBGROUP_LT_MASK
3411 """"""""""""""""""""""""""""""
3412
3413 A bit mask of ``bit index > TGSI_SEMANTIC_SUBGROUP_INVOCATION``, i.e.
3414 ``(1 << subgroup_invocation) - 1`` in arbitrary precision arithmetic.
3415
3416
3417 Declaration Interpolate
3418 ^^^^^^^^^^^^^^^^^^^^^^^
3419
3420 This token is only valid for fragment shader INPUT declarations.
3421
3422 The Interpolate field specifes the way input is being interpolated by
3423 the rasteriser and is one of TGSI_INTERPOLATE_*.
3424
3425 The Location field specifies the location inside the pixel that the
3426 interpolation should be done at, one of ``TGSI_INTERPOLATE_LOC_*``. Note that
3427 when per-sample shading is enabled, the implementation may choose to
3428 interpolate at the sample irrespective of the Location field.
3429
3430 The CylindricalWrap bitfield specifies which register components
3431 should be subject to cylindrical wrapping when interpolating by the
3432 rasteriser. If TGSI_CYLINDRICAL_WRAP_X is set to 1, the X component
3433 should be interpolated according to cylindrical wrapping rules.
3434
3435
3436 Declaration Sampler View
3437 ^^^^^^^^^^^^^^^^^^^^^^^^
3438
3439 Follows Declaration token if file is TGSI_FILE_SAMPLER_VIEW.
3440
3441 DCL SVIEW[#], resource, type(s)
3442
3443 Declares a shader input sampler view and assigns it to a SVIEW[#]
3444 register.
3445
3446 resource can be one of BUFFER, 1D, 2D, 3D, 1DArray and 2DArray.
3447
3448 type must be 1 or 4 entries (if specifying on a per-component
3449 level) out of UNORM, SNORM, SINT, UINT and FLOAT.
3450
3451 For TEX\* style texture sample opcodes (as opposed to SAMPLE\* opcodes
3452 which take an explicit SVIEW[#] source register), there may be optionally
3453 SVIEW[#] declarations. In this case, the SVIEW index is implied by the
3454 SAMP index, and there must be a corresponding SVIEW[#] declaration for
3455 each SAMP[#] declaration. Drivers are free to ignore this if they wish.
3456 But note in particular that some drivers need to know the sampler type
3457 (float/int/unsigned) in order to generate the correct code, so cases
3458 where integer textures are sampled, SVIEW[#] declarations should be
3459 used.
3460
3461 NOTE: It is NOT legal to mix SAMPLE\* style opcodes and TEX\* opcodes
3462 in the same shader.
3463
3464 Declaration Resource
3465 ^^^^^^^^^^^^^^^^^^^^
3466
3467 Follows Declaration token if file is TGSI_FILE_RESOURCE.
3468
3469 DCL RES[#], resource [, WR] [, RAW]
3470
3471 Declares a shader input resource and assigns it to a RES[#]
3472 register.
3473
3474 resource can be one of BUFFER, 1D, 2D, 3D, CUBE, 1DArray and
3475 2DArray.
3476
3477 If the RAW keyword is not specified, the texture data will be
3478 subject to conversion, swizzling and scaling as required to yield
3479 the specified data type from the physical data format of the bound
3480 resource.
3481
3482 If the RAW keyword is specified, no channel conversion will be
3483 performed: the values read for each of the channels (X,Y,Z,W) will
3484 correspond to consecutive words in the same order and format
3485 they're found in memory. No element-to-address conversion will be
3486 performed either: the value of the provided X coordinate will be
3487 interpreted in byte units instead of texel units. The result of
3488 accessing a misaligned address is undefined.
3489
3490 Usage of the STORE opcode is only allowed if the WR (writable) flag
3491 is set.
3492
3493
3494 Properties
3495 ^^^^^^^^^^^^^^^^^^^^^^^^
3496
3497 Properties are general directives that apply to the whole TGSI program.
3498
3499 FS_COORD_ORIGIN
3500 """""""""""""""
3501
3502 Specifies the fragment shader TGSI_SEMANTIC_POSITION coordinate origin.
3503 The default value is UPPER_LEFT.
3504
3505 If UPPER_LEFT, the position will be (0,0) at the upper left corner and
3506 increase downward and rightward.
3507 If LOWER_LEFT, the position will be (0,0) at the lower left corner and
3508 increase upward and rightward.
3509
3510 OpenGL defaults to LOWER_LEFT, and is configurable with the
3511 GL_ARB_fragment_coord_conventions extension.
3512
3513 DirectX 9/10 use UPPER_LEFT.
3514
3515 FS_COORD_PIXEL_CENTER
3516 """""""""""""""""""""
3517
3518 Specifies the fragment shader TGSI_SEMANTIC_POSITION pixel center convention.
3519 The default value is HALF_INTEGER.
3520
3521 If HALF_INTEGER, the fractionary part of the position will be 0.5
3522 If INTEGER, the fractionary part of the position will be 0.0
3523
3524 Note that this does not affect the set of fragments generated by
3525 rasterization, which is instead controlled by half_pixel_center in the
3526 rasterizer.
3527
3528 OpenGL defaults to HALF_INTEGER, and is configurable with the
3529 GL_ARB_fragment_coord_conventions extension.
3530
3531 DirectX 9 uses INTEGER.
3532 DirectX 10 uses HALF_INTEGER.
3533
3534 FS_COLOR0_WRITES_ALL_CBUFS
3535 """"""""""""""""""""""""""
3536 Specifies that writes to the fragment shader color 0 are replicated to all
3537 bound cbufs. This facilitates OpenGL's fragColor output vs fragData[0] where
3538 fragData is directed to a single color buffer, but fragColor is broadcast.
3539
3540 VS_PROHIBIT_UCPS
3541 """"""""""""""""""""""""""
3542 If this property is set on the program bound to the shader stage before the
3543 fragment shader, user clip planes should have no effect (be disabled) even if
3544 that shader does not write to any clip distance outputs and the rasterizer's
3545 clip_plane_enable is non-zero.
3546 This property is only supported by drivers that also support shader clip
3547 distance outputs.
3548 This is useful for APIs that don't have UCPs and where clip distances written
3549 by a shader cannot be disabled.
3550
3551 GS_INVOCATIONS
3552 """"""""""""""
3553
3554 Specifies the number of times a geometry shader should be executed for each
3555 input primitive. Each invocation will have a different
3556 TGSI_SEMANTIC_INVOCATIONID system value set. If not specified, assumed to
3557 be 1.
3558
3559 VS_WINDOW_SPACE_POSITION
3560 """"""""""""""""""""""""""
3561 If this property is set on the vertex shader, the TGSI_SEMANTIC_POSITION output
3562 is assumed to contain window space coordinates.
3563 Division of X,Y,Z by W and the viewport transformation are disabled, and 1/W is
3564 directly taken from the 4-th component of the shader output.
3565 Naturally, clipping is not performed on window coordinates either.
3566 The effect of this property is undefined if a geometry or tessellation shader
3567 are in use.
3568
3569 TCS_VERTICES_OUT
3570 """"""""""""""""
3571
3572 The number of vertices written by the tessellation control shader. This
3573 effectively defines the patch input size of the tessellation evaluation shader
3574 as well.
3575
3576 TES_PRIM_MODE
3577 """""""""""""
3578
3579 This sets the tessellation primitive mode, one of ``PIPE_PRIM_TRIANGLES``,
3580 ``PIPE_PRIM_QUADS``, or ``PIPE_PRIM_LINES``. (Unlike in GL, there is no
3581 separate isolines settings, the regular lines is assumed to mean isolines.)
3582
3583 TES_SPACING
3584 """""""""""
3585
3586 This sets the spacing mode of the tessellation generator, one of
3587 ``PIPE_TESS_SPACING_*``.
3588
3589 TES_VERTEX_ORDER_CW
3590 """""""""""""""""""
3591
3592 This sets the vertex order to be clockwise if the value is 1, or
3593 counter-clockwise if set to 0.
3594
3595 TES_POINT_MODE
3596 """"""""""""""
3597
3598 If set to a non-zero value, this turns on point mode for the tessellator,
3599 which means that points will be generated instead of primitives.
3600
3601 NUM_CLIPDIST_ENABLED
3602 """"""""""""""""""""
3603
3604 How many clip distance scalar outputs are enabled.
3605
3606 NUM_CULLDIST_ENABLED
3607 """"""""""""""""""""
3608
3609 How many cull distance scalar outputs are enabled.
3610
3611 FS_EARLY_DEPTH_STENCIL
3612 """"""""""""""""""""""
3613
3614 Whether depth test, stencil test, and occlusion query should run before
3615 the fragment shader (regardless of fragment shader side effects). Corresponds
3616 to GLSL early_fragment_tests.
3617
3618 NEXT_SHADER
3619 """""""""""
3620
3621 Which shader stage will MOST LIKELY follow after this shader when the shader
3622 is bound. This is only a hint to the driver and doesn't have to be precise.
3623 Only set for VS and TES.
3624
3625 CS_FIXED_BLOCK_WIDTH / HEIGHT / DEPTH
3626 """""""""""""""""""""""""""""""""""""
3627
3628 Threads per block in each dimension, if known at compile time. If the block size
3629 is known all three should be at least 1. If it is unknown they should all be set
3630 to 0 or not set.
3631
3632 MUL_ZERO_WINS
3633 """""""""""""
3634
3635 The MUL TGSI operation (FP32 multiplication) will return 0 if either
3636 of the operands are equal to 0. That means that 0 * Inf = 0. This
3637 should be set the same way for an entire pipeline. Note that this
3638 applies not only to the literal MUL TGSI opcode, but all FP32
3639 multiplications implied by other operations, such as MAD, FMA, DP2,
3640 DP3, DP4, DST, LOG, LRP, and possibly others. If there is a
3641 mismatch between shaders, then it is unspecified whether this behavior
3642 will be enabled.
3643
3644 FS_POST_DEPTH_COVERAGE
3645 """"""""""""""""""""""
3646
3647 When enabled, the input for TGSI_SEMANTIC_SAMPLEMASK will exclude samples
3648 that have failed the depth/stencil tests. This is only valid when
3649 FS_EARLY_DEPTH_STENCIL is also specified.
3650
3651
3652 Texture Sampling and Texture Formats
3653 ------------------------------------
3654
3655 This table shows how texture image components are returned as (x,y,z,w) tuples
3656 by TGSI texture instructions, such as :opcode:`TEX`, :opcode:`TXD`, and
3657 :opcode:`TXP`. For reference, OpenGL and Direct3D conventions are shown as
3658 well.
3659
3660 +--------------------+--------------+--------------------+--------------+
3661 | Texture Components | Gallium | OpenGL | Direct3D 9 |
3662 +====================+==============+====================+==============+
3663 | R | (r, 0, 0, 1) | (r, 0, 0, 1) | (r, 1, 1, 1) |
3664 +--------------------+--------------+--------------------+--------------+
3665 | RG | (r, g, 0, 1) | (r, g, 0, 1) | (r, g, 1, 1) |
3666 +--------------------+--------------+--------------------+--------------+
3667 | RGB | (r, g, b, 1) | (r, g, b, 1) | (r, g, b, 1) |
3668 +--------------------+--------------+--------------------+--------------+
3669 | RGBA | (r, g, b, a) | (r, g, b, a) | (r, g, b, a) |
3670 +--------------------+--------------+--------------------+--------------+
3671 | A | (0, 0, 0, a) | (0, 0, 0, a) | (0, 0, 0, a) |
3672 +--------------------+--------------+--------------------+--------------+
3673 | L | (l, l, l, 1) | (l, l, l, 1) | (l, l, l, 1) |
3674 +--------------------+--------------+--------------------+--------------+
3675 | LA | (l, l, l, a) | (l, l, l, a) | (l, l, l, a) |
3676 +--------------------+--------------+--------------------+--------------+
3677 | I | (i, i, i, i) | (i, i, i, i) | N/A |
3678 +--------------------+--------------+--------------------+--------------+
3679 | UV | XXX TBD | (0, 0, 0, 1) | (u, v, 1, 1) |
3680 | | | [#envmap-bumpmap]_ | |
3681 +--------------------+--------------+--------------------+--------------+
3682 | Z | XXX TBD | (z, z, z, 1) | (0, z, 0, 1) |
3683 | | | [#depth-tex-mode]_ | |
3684 +--------------------+--------------+--------------------+--------------+
3685 | S | (s, s, s, s) | unknown | unknown |
3686 +--------------------+--------------+--------------------+--------------+
3687
3688 .. [#envmap-bumpmap] http://www.opengl.org/registry/specs/ATI/envmap_bumpmap.txt
3689 .. [#depth-tex-mode] the default is (z, z, z, 1) but may also be (0, 0, 0, z)
3690 or (z, z, z, z) depending on the value of GL_DEPTH_TEXTURE_MODE.