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