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