gallium: Drop the unused ARA opcode.
[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 = \lfloor src.x\rfloor
52
53 dst.y = \lfloor src.y\rfloor
54
55 dst.z = \lfloor src.z\rfloor
56
57 dst.w = \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:: SUB - Subtract
250
251 .. math::
252
253 dst.x = src0.x - src1.x
254
255 dst.y = src0.y - src1.y
256
257 dst.z = src0.z - src1.z
258
259 dst.w = src0.w - src1.w
260
261
262 .. opcode:: LRP - Linear Interpolate
263
264 .. math::
265
266 dst.x = src0.x \times src1.x + (1 - src0.x) \times src2.x
267
268 dst.y = src0.y \times src1.y + (1 - src0.y) \times src2.y
269
270 dst.z = src0.z \times src1.z + (1 - src0.z) \times src2.z
271
272 dst.w = src0.w \times src1.w + (1 - src0.w) \times src2.w
273
274
275 .. opcode:: CND - Condition
276
277 .. math::
278
279 dst.x = (src2.x > 0.5) ? src0.x : src1.x
280
281 dst.y = (src2.y > 0.5) ? src0.y : src1.y
282
283 dst.z = (src2.z > 0.5) ? src0.z : src1.z
284
285 dst.w = (src2.w > 0.5) ? src0.w : src1.w
286
287
288 .. opcode:: DP2A - 2-component Dot Product And Add
289
290 .. math::
291
292 dst.x = src0.x \times src1.x + src0.y \times src1.y + src2.x
293
294 dst.y = src0.x \times src1.x + src0.y \times src1.y + src2.x
295
296 dst.z = src0.x \times src1.x + src0.y \times src1.y + src2.x
297
298 dst.w = src0.x \times src1.x + src0.y \times src1.y + src2.x
299
300
301 .. opcode:: FRC - Fraction
302
303 .. math::
304
305 dst.x = src.x - \lfloor src.x\rfloor
306
307 dst.y = src.y - \lfloor src.y\rfloor
308
309 dst.z = src.z - \lfloor src.z\rfloor
310
311 dst.w = src.w - \lfloor src.w\rfloor
312
313
314 .. opcode:: CLAMP - Clamp
315
316 .. math::
317
318 dst.x = clamp(src0.x, src1.x, src2.x)
319
320 dst.y = clamp(src0.y, src1.y, src2.y)
321
322 dst.z = clamp(src0.z, src1.z, src2.z)
323
324 dst.w = clamp(src0.w, src1.w, src2.w)
325
326
327 .. opcode:: FLR - Floor
328
329 This is identical to :opcode:`ARL`.
330
331 .. math::
332
333 dst.x = \lfloor src.x\rfloor
334
335 dst.y = \lfloor src.y\rfloor
336
337 dst.z = \lfloor src.z\rfloor
338
339 dst.w = \lfloor src.w\rfloor
340
341
342 .. opcode:: ROUND - Round
343
344 .. math::
345
346 dst.x = round(src.x)
347
348 dst.y = round(src.y)
349
350 dst.z = round(src.z)
351
352 dst.w = round(src.w)
353
354
355 .. opcode:: EX2 - Exponential Base 2
356
357 This instruction replicates its result.
358
359 .. math::
360
361 dst = 2^{src.x}
362
363
364 .. opcode:: LG2 - Logarithm Base 2
365
366 This instruction replicates its result.
367
368 .. math::
369
370 dst = \log_2{src.x}
371
372
373 .. opcode:: POW - Power
374
375 This instruction replicates its result.
376
377 .. math::
378
379 dst = src0.x^{src1.x}
380
381 .. opcode:: XPD - Cross Product
382
383 .. math::
384
385 dst.x = src0.y \times src1.z - src1.y \times src0.z
386
387 dst.y = src0.z \times src1.x - src1.z \times src0.x
388
389 dst.z = src0.x \times src1.y - src1.x \times src0.y
390
391 dst.w = 1
392
393
394 .. opcode:: ABS - Absolute
395
396 .. math::
397
398 dst.x = |src.x|
399
400 dst.y = |src.y|
401
402 dst.z = |src.z|
403
404 dst.w = |src.w|
405
406
407 .. opcode:: DPH - Homogeneous Dot Product
408
409 This instruction replicates its result.
410
411 .. math::
412
413 dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src1.w
414
415
416 .. opcode:: COS - Cosine
417
418 This instruction replicates its result.
419
420 .. math::
421
422 dst = \cos{src.x}
423
424
425 .. opcode:: DDX, DDX_FINE - Derivative Relative To X
426
427 The fine variant is only used when ``PIPE_CAP_TGSI_FS_FINE_DERIVATIVE`` is
428 advertised. When it is, the fine version guarantees one derivative per row
429 while DDX is allowed to be the same for the entire 2x2 quad.
430
431 .. math::
432
433 dst.x = partialx(src.x)
434
435 dst.y = partialx(src.y)
436
437 dst.z = partialx(src.z)
438
439 dst.w = partialx(src.w)
440
441
442 .. opcode:: DDY, DDY_FINE - Derivative Relative To Y
443
444 The fine variant is only used when ``PIPE_CAP_TGSI_FS_FINE_DERIVATIVE`` is
445 advertised. When it is, the fine version guarantees one derivative per column
446 while DDY is allowed to be the same for the entire 2x2 quad.
447
448 .. math::
449
450 dst.x = partialy(src.x)
451
452 dst.y = partialy(src.y)
453
454 dst.z = partialy(src.z)
455
456 dst.w = partialy(src.w)
457
458
459 .. opcode:: PK2H - Pack Two 16-bit Floats
460
461 TBD
462
463
464 .. opcode:: PK2US - Pack Two Unsigned 16-bit Scalars
465
466 TBD
467
468
469 .. opcode:: PK4B - Pack Four Signed 8-bit Scalars
470
471 TBD
472
473
474 .. opcode:: PK4UB - Pack Four Unsigned 8-bit Scalars
475
476 TBD
477
478
479 .. opcode:: RFL - Reflection Vector
480
481 .. math::
482
483 dst.x = 2 \times (src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z) / (src0.x \times src0.x + src0.y \times src0.y + src0.z \times src0.z) \times src0.x - src1.x
484
485 dst.y = 2 \times (src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z) / (src0.x \times src0.x + src0.y \times src0.y + src0.z \times src0.z) \times src0.y - src1.y
486
487 dst.z = 2 \times (src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z) / (src0.x \times src0.x + src0.y \times src0.y + src0.z \times src0.z) \times src0.z - src1.z
488
489 dst.w = 1
490
491 .. note::
492
493 Considered for removal.
494
495
496 .. opcode:: SEQ - Set On Equal
497
498 .. math::
499
500 dst.x = (src0.x == src1.x) ? 1.0F : 0.0F
501
502 dst.y = (src0.y == src1.y) ? 1.0F : 0.0F
503
504 dst.z = (src0.z == src1.z) ? 1.0F : 0.0F
505
506 dst.w = (src0.w == src1.w) ? 1.0F : 0.0F
507
508
509 .. opcode:: SFL - Set On False
510
511 This instruction replicates its result.
512
513 .. math::
514
515 dst = 0.0F
516
517 .. note::
518
519 Considered for removal.
520
521
522 .. opcode:: SGT - Set On Greater Than
523
524 .. math::
525
526 dst.x = (src0.x > src1.x) ? 1.0F : 0.0F
527
528 dst.y = (src0.y > src1.y) ? 1.0F : 0.0F
529
530 dst.z = (src0.z > src1.z) ? 1.0F : 0.0F
531
532 dst.w = (src0.w > src1.w) ? 1.0F : 0.0F
533
534
535 .. opcode:: SIN - Sine
536
537 This instruction replicates its result.
538
539 .. math::
540
541 dst = \sin{src.x}
542
543
544 .. opcode:: SLE - Set On Less Equal Than
545
546 .. math::
547
548 dst.x = (src0.x <= src1.x) ? 1.0F : 0.0F
549
550 dst.y = (src0.y <= src1.y) ? 1.0F : 0.0F
551
552 dst.z = (src0.z <= src1.z) ? 1.0F : 0.0F
553
554 dst.w = (src0.w <= src1.w) ? 1.0F : 0.0F
555
556
557 .. opcode:: SNE - Set On Not Equal
558
559 .. math::
560
561 dst.x = (src0.x != src1.x) ? 1.0F : 0.0F
562
563 dst.y = (src0.y != src1.y) ? 1.0F : 0.0F
564
565 dst.z = (src0.z != src1.z) ? 1.0F : 0.0F
566
567 dst.w = (src0.w != src1.w) ? 1.0F : 0.0F
568
569
570 .. opcode:: STR - Set On True
571
572 This instruction replicates its result.
573
574 .. math::
575
576 dst = 1.0F
577
578
579 .. opcode:: TEX - Texture Lookup
580
581 for array textures src0.y contains the slice for 1D,
582 and src0.z contain the slice for 2D.
583
584 for shadow textures with no arrays (and not cube map),
585 src0.z contains the reference value.
586
587 for shadow textures with arrays, src0.z contains
588 the reference value for 1D arrays, and src0.w contains
589 the reference value for 2D arrays and cube maps.
590
591 for cube map array shadow textures, the reference value
592 cannot be passed in src0.w, and TEX2 must be used instead.
593
594 .. math::
595
596 coord = src0
597
598 shadow_ref = src0.z or src0.w (optional)
599
600 unit = src1
601
602 dst = texture\_sample(unit, coord, shadow_ref)
603
604
605 .. opcode:: TEX2 - Texture Lookup (for shadow cube map arrays only)
606
607 this is the same as TEX, but uses another reg to encode the
608 reference value.
609
610 .. math::
611
612 coord = src0
613
614 shadow_ref = src1.x
615
616 unit = src2
617
618 dst = texture\_sample(unit, coord, shadow_ref)
619
620
621
622
623 .. opcode:: TXD - Texture Lookup with Derivatives
624
625 .. math::
626
627 coord = src0
628
629 ddx = src1
630
631 ddy = src2
632
633 unit = src3
634
635 dst = texture\_sample\_deriv(unit, coord, ddx, ddy)
636
637
638 .. opcode:: TXP - Projective Texture Lookup
639
640 .. math::
641
642 coord.x = src0.x / src0.w
643
644 coord.y = src0.y / src0.w
645
646 coord.z = src0.z / src0.w
647
648 coord.w = src0.w
649
650 unit = src1
651
652 dst = texture\_sample(unit, coord)
653
654
655 .. opcode:: UP2H - Unpack Two 16-Bit Floats
656
657 TBD
658
659 .. note::
660
661 Considered for removal.
662
663 .. opcode:: UP2US - Unpack Two Unsigned 16-Bit Scalars
664
665 TBD
666
667 .. note::
668
669 Considered for removal.
670
671 .. opcode:: UP4B - Unpack Four Signed 8-Bit Values
672
673 TBD
674
675 .. note::
676
677 Considered for removal.
678
679 .. opcode:: UP4UB - Unpack Four Unsigned 8-Bit Scalars
680
681 TBD
682
683 .. note::
684
685 Considered for removal.
686
687 .. opcode:: X2D - 2D Coordinate Transformation
688
689 .. math::
690
691 dst.x = src0.x + src1.x \times src2.x + src1.y \times src2.y
692
693 dst.y = src0.y + src1.x \times src2.z + src1.y \times src2.w
694
695 dst.z = src0.x + src1.x \times src2.x + src1.y \times src2.y
696
697 dst.w = src0.y + src1.x \times src2.z + src1.y \times src2.w
698
699 .. note::
700
701 Considered for removal.
702
703
704 .. opcode:: ARR - Address Register Load With Round
705
706 .. math::
707
708 dst.x = round(src.x)
709
710 dst.y = round(src.y)
711
712 dst.z = round(src.z)
713
714 dst.w = round(src.w)
715
716
717 .. opcode:: SSG - Set Sign
718
719 .. math::
720
721 dst.x = (src.x > 0) ? 1 : (src.x < 0) ? -1 : 0
722
723 dst.y = (src.y > 0) ? 1 : (src.y < 0) ? -1 : 0
724
725 dst.z = (src.z > 0) ? 1 : (src.z < 0) ? -1 : 0
726
727 dst.w = (src.w > 0) ? 1 : (src.w < 0) ? -1 : 0
728
729
730 .. opcode:: CMP - Compare
731
732 .. math::
733
734 dst.x = (src0.x < 0) ? src1.x : src2.x
735
736 dst.y = (src0.y < 0) ? src1.y : src2.y
737
738 dst.z = (src0.z < 0) ? src1.z : src2.z
739
740 dst.w = (src0.w < 0) ? src1.w : src2.w
741
742
743 .. opcode:: KILL_IF - Conditional Discard
744
745 Conditional discard. Allowed in fragment shaders only.
746
747 .. math::
748
749 if (src.x < 0 || src.y < 0 || src.z < 0 || src.w < 0)
750 discard
751 endif
752
753
754 .. opcode:: KILL - Discard
755
756 Unconditional discard. Allowed in fragment shaders only.
757
758
759 .. opcode:: SCS - Sine Cosine
760
761 .. math::
762
763 dst.x = \cos{src.x}
764
765 dst.y = \sin{src.x}
766
767 dst.z = 0
768
769 dst.w = 1
770
771
772 .. opcode:: TXB - Texture Lookup With Bias
773
774 for cube map array textures and shadow cube maps, the bias value
775 cannot be passed in src0.w, and TXB2 must be used instead.
776
777 if the target is a shadow texture, the reference value is always
778 in src.z (this prevents shadow 3d and shadow 2d arrays from
779 using this instruction, but this is not needed).
780
781 .. math::
782
783 coord.x = src0.x
784
785 coord.y = src0.y
786
787 coord.z = src0.z
788
789 coord.w = none
790
791 bias = src0.w
792
793 unit = src1
794
795 dst = texture\_sample(unit, coord, bias)
796
797
798 .. opcode:: TXB2 - Texture Lookup With Bias (some cube maps only)
799
800 this is the same as TXB, but uses another reg to encode the
801 lod bias value for cube map arrays and shadow cube maps.
802 Presumably shadow 2d arrays and shadow 3d targets could use
803 this encoding too, but this is not legal.
804
805 shadow cube map arrays are neither possible nor required.
806
807 .. math::
808
809 coord = src0
810
811 bias = src1.x
812
813 unit = src2
814
815 dst = texture\_sample(unit, coord, bias)
816
817
818 .. opcode:: DIV - Divide
819
820 .. math::
821
822 dst.x = \frac{src0.x}{src1.x}
823
824 dst.y = \frac{src0.y}{src1.y}
825
826 dst.z = \frac{src0.z}{src1.z}
827
828 dst.w = \frac{src0.w}{src1.w}
829
830
831 .. opcode:: DP2 - 2-component Dot Product
832
833 This instruction replicates its result.
834
835 .. math::
836
837 dst = src0.x \times src1.x + src0.y \times src1.y
838
839
840 .. opcode:: TXL - Texture Lookup With explicit LOD
841
842 for cube map array textures, the explicit lod value
843 cannot be passed in src0.w, and TXL2 must be used instead.
844
845 if the target is a shadow texture, the reference value is always
846 in src.z (this prevents shadow 3d / 2d array / cube targets from
847 using this instruction, but this is not needed).
848
849 .. math::
850
851 coord.x = src0.x
852
853 coord.y = src0.y
854
855 coord.z = src0.z
856
857 coord.w = none
858
859 lod = src0.w
860
861 unit = src1
862
863 dst = texture\_sample(unit, coord, lod)
864
865
866 .. opcode:: TXL2 - Texture Lookup With explicit LOD (for cube map arrays only)
867
868 this is the same as TXL, but uses another reg to encode the
869 explicit lod value.
870 Presumably shadow 3d / 2d array / cube targets could use
871 this encoding too, but this is not legal.
872
873 shadow cube map arrays are neither possible nor required.
874
875 .. math::
876
877 coord = src0
878
879 lod = src1.x
880
881 unit = src2
882
883 dst = texture\_sample(unit, coord, lod)
884
885
886 .. opcode:: PUSHA - Push Address Register On Stack
887
888 push(src.x)
889 push(src.y)
890 push(src.z)
891 push(src.w)
892
893 .. note::
894
895 Considered for cleanup.
896
897 .. note::
898
899 Considered for removal.
900
901 .. opcode:: POPA - Pop Address Register From Stack
902
903 dst.w = pop()
904 dst.z = pop()
905 dst.y = pop()
906 dst.x = pop()
907
908 .. note::
909
910 Considered for cleanup.
911
912 .. note::
913
914 Considered for removal.
915
916
917 .. opcode:: BRA - Branch
918
919 pc = target
920
921 .. note::
922
923 Considered for removal.
924
925
926 .. opcode:: CALLNZ - Subroutine Call If Not Zero
927
928 TBD
929
930 .. note::
931
932 Considered for cleanup.
933
934 .. note::
935
936 Considered for removal.
937
938
939 Compute ISA
940 ^^^^^^^^^^^^^^^^^^^^^^^^
941
942 These opcodes are primarily provided for special-use computational shaders.
943 Support for these opcodes indicated by a special pipe capability bit (TBD).
944
945 XXX doesn't look like most of the opcodes really belong here.
946
947 .. opcode:: CEIL - Ceiling
948
949 .. math::
950
951 dst.x = \lceil src.x\rceil
952
953 dst.y = \lceil src.y\rceil
954
955 dst.z = \lceil src.z\rceil
956
957 dst.w = \lceil src.w\rceil
958
959
960 .. opcode:: TRUNC - Truncate
961
962 .. math::
963
964 dst.x = trunc(src.x)
965
966 dst.y = trunc(src.y)
967
968 dst.z = trunc(src.z)
969
970 dst.w = trunc(src.w)
971
972
973 .. opcode:: MOD - Modulus
974
975 .. math::
976
977 dst.x = src0.x \bmod src1.x
978
979 dst.y = src0.y \bmod src1.y
980
981 dst.z = src0.z \bmod src1.z
982
983 dst.w = src0.w \bmod src1.w
984
985
986 .. opcode:: UARL - Integer Address Register Load
987
988 Moves the contents of the source register, assumed to be an integer, into the
989 destination register, which is assumed to be an address (ADDR) register.
990
991
992 .. opcode:: SAD - Sum Of Absolute Differences
993
994 .. math::
995
996 dst.x = |src0.x - src1.x| + src2.x
997
998 dst.y = |src0.y - src1.y| + src2.y
999
1000 dst.z = |src0.z - src1.z| + src2.z
1001
1002 dst.w = |src0.w - src1.w| + src2.w
1003
1004
1005 .. opcode:: TXF - Texel Fetch
1006
1007 As per NV_gpu_shader4, extract a single texel from a specified texture
1008 image. The source sampler may not be a CUBE or SHADOW. src 0 is a
1009 four-component signed integer vector used to identify the single texel
1010 accessed. 3 components + level. Just like texture instructions, an optional
1011 offset vector is provided, which is subject to various driver restrictions
1012 (regarding range, source of offsets).
1013 TXF(uint_vec coord, int_vec offset).
1014
1015
1016 .. opcode:: TXQ - Texture Size Query
1017
1018 As per NV_gpu_program4, retrieve the dimensions of the texture depending on
1019 the target. For 1D (width), 2D/RECT/CUBE (width, height), 3D (width, height,
1020 depth), 1D array (width, layers), 2D array (width, height, layers).
1021 Also return the number of accessible levels (last_level - first_level + 1)
1022 in W.
1023
1024 For components which don't return a resource dimension, their value
1025 is undefined.
1026
1027
1028 .. math::
1029
1030 lod = src0.x
1031
1032 dst.x = texture\_width(unit, lod)
1033
1034 dst.y = texture\_height(unit, lod)
1035
1036 dst.z = texture\_depth(unit, lod)
1037
1038 dst.w = texture\_levels(unit)
1039
1040 .. opcode:: TG4 - Texture Gather
1041
1042 As per ARB_texture_gather, gathers the four texels to be used in a bi-linear
1043 filtering operation and packs them into a single register. Only works with
1044 2D, 2D array, cubemaps, and cubemaps arrays. For 2D textures, only the
1045 addressing modes of the sampler and the top level of any mip pyramid are
1046 used. Set W to zero. It behaves like the TEX instruction, but a filtered
1047 sample is not generated. The four samples that contribute to filtering are
1048 placed into xyzw in clockwise order, starting with the (u,v) texture
1049 coordinate delta at the following locations (-, +), (+, +), (+, -), (-, -),
1050 where the magnitude of the deltas are half a texel.
1051
1052 PIPE_CAP_TEXTURE_SM5 enhances this instruction to support shadow per-sample
1053 depth compares, single component selection, and a non-constant offset. It
1054 doesn't allow support for the GL independent offset to get i0,j0. This would
1055 require another CAP is hw can do it natively. For now we lower that before
1056 TGSI.
1057
1058 .. math::
1059
1060 coord = src0
1061
1062 component = src1
1063
1064 dst = texture\_gather4 (unit, coord, component)
1065
1066 (with SM5 - cube array shadow)
1067
1068 .. math::
1069
1070 coord = src0
1071
1072 compare = src1
1073
1074 dst = texture\_gather (uint, coord, compare)
1075
1076 .. opcode:: LODQ - level of detail query
1077
1078 Compute the LOD information that the texture pipe would use to access the
1079 texture. The Y component contains the computed LOD lambda_prime. The X
1080 component contains the LOD that will be accessed, based on min/max lod's
1081 and mipmap filters.
1082
1083 .. math::
1084
1085 coord = src0
1086
1087 dst.xy = lodq(uint, coord);
1088
1089 Integer ISA
1090 ^^^^^^^^^^^^^^^^^^^^^^^^
1091 These opcodes are used for integer operations.
1092 Support for these opcodes indicated by PIPE_SHADER_CAP_INTEGERS (all of them?)
1093
1094
1095 .. opcode:: I2F - Signed Integer To Float
1096
1097 Rounding is unspecified (round to nearest even suggested).
1098
1099 .. math::
1100
1101 dst.x = (float) src.x
1102
1103 dst.y = (float) src.y
1104
1105 dst.z = (float) src.z
1106
1107 dst.w = (float) src.w
1108
1109
1110 .. opcode:: U2F - Unsigned Integer To Float
1111
1112 Rounding is unspecified (round to nearest even suggested).
1113
1114 .. math::
1115
1116 dst.x = (float) src.x
1117
1118 dst.y = (float) src.y
1119
1120 dst.z = (float) src.z
1121
1122 dst.w = (float) src.w
1123
1124
1125 .. opcode:: F2I - Float to Signed Integer
1126
1127 Rounding is towards zero (truncate).
1128 Values outside signed range (including NaNs) produce undefined results.
1129
1130 .. math::
1131
1132 dst.x = (int) src.x
1133
1134 dst.y = (int) src.y
1135
1136 dst.z = (int) src.z
1137
1138 dst.w = (int) src.w
1139
1140
1141 .. opcode:: F2U - Float to Unsigned Integer
1142
1143 Rounding is towards zero (truncate).
1144 Values outside unsigned range (including NaNs) produce undefined results.
1145
1146 .. math::
1147
1148 dst.x = (unsigned) src.x
1149
1150 dst.y = (unsigned) src.y
1151
1152 dst.z = (unsigned) src.z
1153
1154 dst.w = (unsigned) src.w
1155
1156
1157 .. opcode:: UADD - Integer Add
1158
1159 This instruction works the same for signed and unsigned integers.
1160 The low 32bit of the result is returned.
1161
1162 .. math::
1163
1164 dst.x = src0.x + src1.x
1165
1166 dst.y = src0.y + src1.y
1167
1168 dst.z = src0.z + src1.z
1169
1170 dst.w = src0.w + src1.w
1171
1172
1173 .. opcode:: UMAD - Integer Multiply And Add
1174
1175 This instruction works the same for signed and unsigned integers.
1176 The multiplication returns the low 32bit (as does the result itself).
1177
1178 .. math::
1179
1180 dst.x = src0.x \times src1.x + src2.x
1181
1182 dst.y = src0.y \times src1.y + src2.y
1183
1184 dst.z = src0.z \times src1.z + src2.z
1185
1186 dst.w = src0.w \times src1.w + src2.w
1187
1188
1189 .. opcode:: UMUL - Integer Multiply
1190
1191 This instruction works the same for signed and unsigned integers.
1192 The low 32bit of the result is returned.
1193
1194 .. math::
1195
1196 dst.x = src0.x \times src1.x
1197
1198 dst.y = src0.y \times src1.y
1199
1200 dst.z = src0.z \times src1.z
1201
1202 dst.w = src0.w \times src1.w
1203
1204
1205 .. opcode:: IMUL_HI - Signed Integer Multiply High Bits
1206
1207 The high 32bits of the multiplication of 2 signed integers are returned.
1208
1209 .. math::
1210
1211 dst.x = (src0.x \times src1.x) >> 32
1212
1213 dst.y = (src0.y \times src1.y) >> 32
1214
1215 dst.z = (src0.z \times src1.z) >> 32
1216
1217 dst.w = (src0.w \times src1.w) >> 32
1218
1219
1220 .. opcode:: UMUL_HI - Unsigned Integer Multiply High Bits
1221
1222 The high 32bits of the multiplication of 2 unsigned integers are returned.
1223
1224 .. math::
1225
1226 dst.x = (src0.x \times src1.x) >> 32
1227
1228 dst.y = (src0.y \times src1.y) >> 32
1229
1230 dst.z = (src0.z \times src1.z) >> 32
1231
1232 dst.w = (src0.w \times src1.w) >> 32
1233
1234
1235 .. opcode:: IDIV - Signed Integer Division
1236
1237 TBD: behavior for division by zero.
1238
1239 .. math::
1240
1241 dst.x = src0.x \ src1.x
1242
1243 dst.y = src0.y \ src1.y
1244
1245 dst.z = src0.z \ src1.z
1246
1247 dst.w = src0.w \ src1.w
1248
1249
1250 .. opcode:: UDIV - Unsigned Integer Division
1251
1252 For division by zero, 0xffffffff is returned.
1253
1254 .. math::
1255
1256 dst.x = src0.x \ src1.x
1257
1258 dst.y = src0.y \ src1.y
1259
1260 dst.z = src0.z \ src1.z
1261
1262 dst.w = src0.w \ src1.w
1263
1264
1265 .. opcode:: UMOD - Unsigned Integer Remainder
1266
1267 If second arg is zero, 0xffffffff is returned.
1268
1269 .. math::
1270
1271 dst.x = src0.x \ src1.x
1272
1273 dst.y = src0.y \ src1.y
1274
1275 dst.z = src0.z \ src1.z
1276
1277 dst.w = src0.w \ src1.w
1278
1279
1280 .. opcode:: NOT - Bitwise Not
1281
1282 .. math::
1283
1284 dst.x = \sim src.x
1285
1286 dst.y = \sim src.y
1287
1288 dst.z = \sim src.z
1289
1290 dst.w = \sim src.w
1291
1292
1293 .. opcode:: AND - Bitwise And
1294
1295 .. math::
1296
1297 dst.x = src0.x \& src1.x
1298
1299 dst.y = src0.y \& src1.y
1300
1301 dst.z = src0.z \& src1.z
1302
1303 dst.w = src0.w \& src1.w
1304
1305
1306 .. opcode:: OR - Bitwise Or
1307
1308 .. math::
1309
1310 dst.x = src0.x | src1.x
1311
1312 dst.y = src0.y | src1.y
1313
1314 dst.z = src0.z | src1.z
1315
1316 dst.w = src0.w | src1.w
1317
1318
1319 .. opcode:: XOR - Bitwise Xor
1320
1321 .. math::
1322
1323 dst.x = src0.x \oplus src1.x
1324
1325 dst.y = src0.y \oplus src1.y
1326
1327 dst.z = src0.z \oplus src1.z
1328
1329 dst.w = src0.w \oplus src1.w
1330
1331
1332 .. opcode:: IMAX - Maximum of Signed Integers
1333
1334 .. math::
1335
1336 dst.x = max(src0.x, src1.x)
1337
1338 dst.y = max(src0.y, src1.y)
1339
1340 dst.z = max(src0.z, src1.z)
1341
1342 dst.w = max(src0.w, src1.w)
1343
1344
1345 .. opcode:: UMAX - Maximum of Unsigned Integers
1346
1347 .. math::
1348
1349 dst.x = max(src0.x, src1.x)
1350
1351 dst.y = max(src0.y, src1.y)
1352
1353 dst.z = max(src0.z, src1.z)
1354
1355 dst.w = max(src0.w, src1.w)
1356
1357
1358 .. opcode:: IMIN - Minimum of Signed Integers
1359
1360 .. math::
1361
1362 dst.x = min(src0.x, src1.x)
1363
1364 dst.y = min(src0.y, src1.y)
1365
1366 dst.z = min(src0.z, src1.z)
1367
1368 dst.w = min(src0.w, src1.w)
1369
1370
1371 .. opcode:: UMIN - Minimum of Unsigned Integers
1372
1373 .. math::
1374
1375 dst.x = min(src0.x, src1.x)
1376
1377 dst.y = min(src0.y, src1.y)
1378
1379 dst.z = min(src0.z, src1.z)
1380
1381 dst.w = min(src0.w, src1.w)
1382
1383
1384 .. opcode:: SHL - Shift Left
1385
1386 The shift count is masked with 0x1f before the shift is applied.
1387
1388 .. math::
1389
1390 dst.x = src0.x << (0x1f \& src1.x)
1391
1392 dst.y = src0.y << (0x1f \& src1.y)
1393
1394 dst.z = src0.z << (0x1f \& src1.z)
1395
1396 dst.w = src0.w << (0x1f \& src1.w)
1397
1398
1399 .. opcode:: ISHR - Arithmetic Shift Right (of Signed Integer)
1400
1401 The shift count is masked with 0x1f before the shift is applied.
1402
1403 .. math::
1404
1405 dst.x = src0.x >> (0x1f \& src1.x)
1406
1407 dst.y = src0.y >> (0x1f \& src1.y)
1408
1409 dst.z = src0.z >> (0x1f \& src1.z)
1410
1411 dst.w = src0.w >> (0x1f \& src1.w)
1412
1413
1414 .. opcode:: USHR - Logical Shift Right
1415
1416 The shift count is masked with 0x1f before the shift is applied.
1417
1418 .. math::
1419
1420 dst.x = src0.x >> (unsigned) (0x1f \& src1.x)
1421
1422 dst.y = src0.y >> (unsigned) (0x1f \& src1.y)
1423
1424 dst.z = src0.z >> (unsigned) (0x1f \& src1.z)
1425
1426 dst.w = src0.w >> (unsigned) (0x1f \& src1.w)
1427
1428
1429 .. opcode:: UCMP - Integer Conditional Move
1430
1431 .. math::
1432
1433 dst.x = src0.x ? src1.x : src2.x
1434
1435 dst.y = src0.y ? src1.y : src2.y
1436
1437 dst.z = src0.z ? src1.z : src2.z
1438
1439 dst.w = src0.w ? src1.w : src2.w
1440
1441
1442
1443 .. opcode:: ISSG - Integer Set Sign
1444
1445 .. math::
1446
1447 dst.x = (src0.x < 0) ? -1 : (src0.x > 0) ? 1 : 0
1448
1449 dst.y = (src0.y < 0) ? -1 : (src0.y > 0) ? 1 : 0
1450
1451 dst.z = (src0.z < 0) ? -1 : (src0.z > 0) ? 1 : 0
1452
1453 dst.w = (src0.w < 0) ? -1 : (src0.w > 0) ? 1 : 0
1454
1455
1456
1457 .. opcode:: FSLT - Float Set On Less Than (ordered)
1458
1459 Same comparison as SLT but returns integer instead of 1.0/0.0 float
1460
1461 .. math::
1462
1463 dst.x = (src0.x < src1.x) ? \sim 0 : 0
1464
1465 dst.y = (src0.y < src1.y) ? \sim 0 : 0
1466
1467 dst.z = (src0.z < src1.z) ? \sim 0 : 0
1468
1469 dst.w = (src0.w < src1.w) ? \sim 0 : 0
1470
1471
1472 .. opcode:: ISLT - Signed Integer Set On Less Than
1473
1474 .. math::
1475
1476 dst.x = (src0.x < src1.x) ? \sim 0 : 0
1477
1478 dst.y = (src0.y < src1.y) ? \sim 0 : 0
1479
1480 dst.z = (src0.z < src1.z) ? \sim 0 : 0
1481
1482 dst.w = (src0.w < src1.w) ? \sim 0 : 0
1483
1484
1485 .. opcode:: USLT - Unsigned Integer Set On Less Than
1486
1487 .. math::
1488
1489 dst.x = (src0.x < src1.x) ? \sim 0 : 0
1490
1491 dst.y = (src0.y < src1.y) ? \sim 0 : 0
1492
1493 dst.z = (src0.z < src1.z) ? \sim 0 : 0
1494
1495 dst.w = (src0.w < src1.w) ? \sim 0 : 0
1496
1497
1498 .. opcode:: FSGE - Float Set On Greater Equal Than (ordered)
1499
1500 Same comparison as SGE but returns integer instead of 1.0/0.0 float
1501
1502 .. math::
1503
1504 dst.x = (src0.x >= src1.x) ? \sim 0 : 0
1505
1506 dst.y = (src0.y >= src1.y) ? \sim 0 : 0
1507
1508 dst.z = (src0.z >= src1.z) ? \sim 0 : 0
1509
1510 dst.w = (src0.w >= src1.w) ? \sim 0 : 0
1511
1512
1513 .. opcode:: ISGE - Signed Integer Set On Greater Equal Than
1514
1515 .. math::
1516
1517 dst.x = (src0.x >= src1.x) ? \sim 0 : 0
1518
1519 dst.y = (src0.y >= src1.y) ? \sim 0 : 0
1520
1521 dst.z = (src0.z >= src1.z) ? \sim 0 : 0
1522
1523 dst.w = (src0.w >= src1.w) ? \sim 0 : 0
1524
1525
1526 .. opcode:: USGE - Unsigned Integer Set On Greater Equal Than
1527
1528 .. math::
1529
1530 dst.x = (src0.x >= src1.x) ? \sim 0 : 0
1531
1532 dst.y = (src0.y >= src1.y) ? \sim 0 : 0
1533
1534 dst.z = (src0.z >= src1.z) ? \sim 0 : 0
1535
1536 dst.w = (src0.w >= src1.w) ? \sim 0 : 0
1537
1538
1539 .. opcode:: FSEQ - Float Set On Equal (ordered)
1540
1541 Same comparison as SEQ but returns integer instead of 1.0/0.0 float
1542
1543 .. math::
1544
1545 dst.x = (src0.x == src1.x) ? \sim 0 : 0
1546
1547 dst.y = (src0.y == src1.y) ? \sim 0 : 0
1548
1549 dst.z = (src0.z == src1.z) ? \sim 0 : 0
1550
1551 dst.w = (src0.w == src1.w) ? \sim 0 : 0
1552
1553
1554 .. opcode:: USEQ - Integer Set On Equal
1555
1556 .. math::
1557
1558 dst.x = (src0.x == src1.x) ? \sim 0 : 0
1559
1560 dst.y = (src0.y == src1.y) ? \sim 0 : 0
1561
1562 dst.z = (src0.z == src1.z) ? \sim 0 : 0
1563
1564 dst.w = (src0.w == src1.w) ? \sim 0 : 0
1565
1566
1567 .. opcode:: FSNE - Float Set On Not Equal (unordered)
1568
1569 Same comparison as SNE but returns integer instead of 1.0/0.0 float
1570
1571 .. math::
1572
1573 dst.x = (src0.x != src1.x) ? \sim 0 : 0
1574
1575 dst.y = (src0.y != src1.y) ? \sim 0 : 0
1576
1577 dst.z = (src0.z != src1.z) ? \sim 0 : 0
1578
1579 dst.w = (src0.w != src1.w) ? \sim 0 : 0
1580
1581
1582 .. opcode:: USNE - Integer Set On Not Equal
1583
1584 .. math::
1585
1586 dst.x = (src0.x != src1.x) ? \sim 0 : 0
1587
1588 dst.y = (src0.y != src1.y) ? \sim 0 : 0
1589
1590 dst.z = (src0.z != src1.z) ? \sim 0 : 0
1591
1592 dst.w = (src0.w != src1.w) ? \sim 0 : 0
1593
1594
1595 .. opcode:: INEG - Integer Negate
1596
1597 Two's complement.
1598
1599 .. math::
1600
1601 dst.x = -src.x
1602
1603 dst.y = -src.y
1604
1605 dst.z = -src.z
1606
1607 dst.w = -src.w
1608
1609
1610 .. opcode:: IABS - Integer Absolute Value
1611
1612 .. math::
1613
1614 dst.x = |src.x|
1615
1616 dst.y = |src.y|
1617
1618 dst.z = |src.z|
1619
1620 dst.w = |src.w|
1621
1622 Bitwise ISA
1623 ^^^^^^^^^^^
1624 These opcodes are used for bit-level manipulation of integers.
1625
1626 .. opcode:: IBFE - Signed Bitfield Extract
1627
1628 See SM5 instruction of the same name. Extracts a set of bits from the input,
1629 and sign-extends them if the high bit of the extracted window is set.
1630
1631 Pseudocode::
1632
1633 def ibfe(value, offset, bits):
1634 offset = offset & 0x1f
1635 bits = bits & 0x1f
1636 if bits == 0: return 0
1637 # Note: >> sign-extends
1638 if width + offset < 32:
1639 return (value << (32 - offset - bits)) >> (32 - bits)
1640 else:
1641 return value >> offset
1642
1643 .. opcode:: UBFE - Unsigned Bitfield Extract
1644
1645 See SM5 instruction of the same name. Extracts a set of bits from the input,
1646 without any sign-extension.
1647
1648 Pseudocode::
1649
1650 def ubfe(value, offset, bits):
1651 offset = offset & 0x1f
1652 bits = bits & 0x1f
1653 if bits == 0: return 0
1654 # Note: >> does not sign-extend
1655 if width + offset < 32:
1656 return (value << (32 - offset - bits)) >> (32 - bits)
1657 else:
1658 return value >> offset
1659
1660 .. opcode:: BFI - Bitfield Insert
1661
1662 See SM5 instruction of the same name. Replaces a bit region of 'base' with
1663 the low bits of 'insert'.
1664
1665 Pseudocode::
1666
1667 def bfi(base, insert, offset, bits):
1668 offset = offset & 0x1f
1669 bits = bits & 0x1f
1670 mask = ((1 << bits) - 1) << offset
1671 return ((insert << offset) & mask) | (base & ~mask)
1672
1673 .. opcode:: BREV - Bitfield Reverse
1674
1675 See SM5 instruction BFREV. Reverses the bits of the argument.
1676
1677 .. opcode:: POPC - Population Count
1678
1679 See SM5 instruction COUNTBITS. Counts the number of set bits in the argument.
1680
1681 .. opcode:: LSB - Index of lowest set bit
1682
1683 See SM5 instruction FIRSTBIT_LO. Computes the 0-based index of the first set
1684 bit of the argument. Returns -1 if none are set.
1685
1686 .. opcode:: IMSB - Index of highest non-sign bit
1687
1688 See SM5 instruction FIRSTBIT_SHI. Computes the 0-based index of the highest
1689 non-sign bit of the argument (i.e. highest 0 bit for negative numbers,
1690 highest 1 bit for positive numbers). Returns -1 if all bits are the same
1691 (i.e. for inputs 0 and -1).
1692
1693 .. opcode:: UMSB - Index of highest set bit
1694
1695 See SM5 instruction FIRSTBIT_HI. Computes the 0-based index of the highest
1696 set bit of the argument. Returns -1 if none are set.
1697
1698 Geometry ISA
1699 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1700
1701 These opcodes are only supported in geometry shaders; they have no meaning
1702 in any other type of shader.
1703
1704 .. opcode:: EMIT - Emit
1705
1706 Generate a new vertex for the current primitive into the specified vertex
1707 stream using the values in the output registers.
1708
1709
1710 .. opcode:: ENDPRIM - End Primitive
1711
1712 Complete the current primitive in the specified vertex stream (consisting of
1713 the emitted vertices), and start a new one.
1714
1715
1716 GLSL ISA
1717 ^^^^^^^^^^
1718
1719 These opcodes are part of :term:`GLSL`'s opcode set. Support for these
1720 opcodes is determined by a special capability bit, ``GLSL``.
1721 Some require glsl version 1.30 (UIF/BREAKC/SWITCH/CASE/DEFAULT/ENDSWITCH).
1722
1723 .. opcode:: CAL - Subroutine Call
1724
1725 push(pc)
1726 pc = target
1727
1728
1729 .. opcode:: RET - Subroutine Call Return
1730
1731 pc = pop()
1732
1733
1734 .. opcode:: CONT - Continue
1735
1736 Unconditionally moves the point of execution to the instruction after the
1737 last bgnloop. The instruction must appear within a bgnloop/endloop.
1738
1739 .. note::
1740
1741 Support for CONT is determined by a special capability bit,
1742 ``TGSI_CONT_SUPPORTED``. See :ref:`Screen` for more information.
1743
1744
1745 .. opcode:: BGNLOOP - Begin a Loop
1746
1747 Start a loop. Must have a matching endloop.
1748
1749
1750 .. opcode:: BGNSUB - Begin Subroutine
1751
1752 Starts definition of a subroutine. Must have a matching endsub.
1753
1754
1755 .. opcode:: ENDLOOP - End a Loop
1756
1757 End a loop started with bgnloop.
1758
1759
1760 .. opcode:: ENDSUB - End Subroutine
1761
1762 Ends definition of a subroutine.
1763
1764
1765 .. opcode:: NOP - No Operation
1766
1767 Do nothing.
1768
1769
1770 .. opcode:: BRK - Break
1771
1772 Unconditionally moves the point of execution to the instruction after the
1773 next endloop or endswitch. The instruction must appear within a loop/endloop
1774 or switch/endswitch.
1775
1776
1777 .. opcode:: BREAKC - Break Conditional
1778
1779 Conditionally moves the point of execution to the instruction after the
1780 next endloop or endswitch. The instruction must appear within a loop/endloop
1781 or switch/endswitch.
1782 Condition evaluates to true if src0.x != 0 where src0.x is interpreted
1783 as an integer register.
1784
1785 .. note::
1786
1787 Considered for removal as it's quite inconsistent wrt other opcodes
1788 (could emulate with UIF/BRK/ENDIF).
1789
1790
1791 .. opcode:: IF - Float If
1792
1793 Start an IF ... ELSE .. ENDIF block. Condition evaluates to true if
1794
1795 src0.x != 0.0
1796
1797 where src0.x is interpreted as a floating point register.
1798
1799
1800 .. opcode:: UIF - Bitwise If
1801
1802 Start an UIF ... ELSE .. ENDIF block. Condition evaluates to true if
1803
1804 src0.x != 0
1805
1806 where src0.x is interpreted as an integer register.
1807
1808
1809 .. opcode:: ELSE - Else
1810
1811 Starts an else block, after an IF or UIF statement.
1812
1813
1814 .. opcode:: ENDIF - End If
1815
1816 Ends an IF or UIF block.
1817
1818
1819 .. opcode:: SWITCH - Switch
1820
1821 Starts a C-style switch expression. The switch consists of one or multiple
1822 CASE statements, and at most one DEFAULT statement. Execution of a statement
1823 ends when a BRK is hit, but just like in C falling through to other cases
1824 without a break is allowed. Similarly, DEFAULT label is allowed anywhere not
1825 just as last statement, and fallthrough is allowed into/from it.
1826 CASE src arguments are evaluated at bit level against the SWITCH src argument.
1827
1828 Example::
1829
1830 SWITCH src[0].x
1831 CASE src[0].x
1832 (some instructions here)
1833 (optional BRK here)
1834 DEFAULT
1835 (some instructions here)
1836 (optional BRK here)
1837 CASE src[0].x
1838 (some instructions here)
1839 (optional BRK here)
1840 ENDSWITCH
1841
1842
1843 .. opcode:: CASE - Switch case
1844
1845 This represents a switch case label. The src arg must be an integer immediate.
1846
1847
1848 .. opcode:: DEFAULT - Switch default
1849
1850 This represents the default case in the switch, which is taken if no other
1851 case matches.
1852
1853
1854 .. opcode:: ENDSWITCH - End of switch
1855
1856 Ends a switch expression.
1857
1858
1859 Interpolation ISA
1860 ^^^^^^^^^^^^^^^^^
1861
1862 The interpolation instructions allow an input to be interpolated in a
1863 different way than its declaration. This corresponds to the GLSL 4.00
1864 interpolateAt* functions. The first argument of each of these must come from
1865 ``TGSI_FILE_INPUT``.
1866
1867 .. opcode:: INTERP_CENTROID - Interpolate at the centroid
1868
1869 Interpolates the varying specified by src0 at the centroid
1870
1871 .. opcode:: INTERP_SAMPLE - Interpolate at the specified sample
1872
1873 Interpolates the varying specified by src0 at the sample id specified by
1874 src1.x (interpreted as an integer)
1875
1876 .. opcode:: INTERP_OFFSET - Interpolate at the specified offset
1877
1878 Interpolates the varying specified by src0 at the offset src1.xy from the
1879 pixel center (interpreted as floats)
1880
1881
1882 .. _doubleopcodes:
1883
1884 Double ISA
1885 ^^^^^^^^^^^^^^^
1886
1887 The double-precision opcodes reinterpret four-component vectors into
1888 two-component vectors with doubled precision in each component.
1889
1890 Support for these opcodes is XXX undecided. :T
1891
1892 .. opcode:: DADD - Add
1893
1894 .. math::
1895
1896 dst.xy = src0.xy + src1.xy
1897
1898 dst.zw = src0.zw + src1.zw
1899
1900
1901 .. opcode:: DDIV - Divide
1902
1903 .. math::
1904
1905 dst.xy = src0.xy / src1.xy
1906
1907 dst.zw = src0.zw / src1.zw
1908
1909 .. opcode:: DSEQ - Set on Equal
1910
1911 .. math::
1912
1913 dst.xy = src0.xy == src1.xy ? 1.0F : 0.0F
1914
1915 dst.zw = src0.zw == src1.zw ? 1.0F : 0.0F
1916
1917 .. opcode:: DSLT - Set on Less than
1918
1919 .. math::
1920
1921 dst.xy = src0.xy < src1.xy ? 1.0F : 0.0F
1922
1923 dst.zw = src0.zw < src1.zw ? 1.0F : 0.0F
1924
1925 .. opcode:: DFRAC - Fraction
1926
1927 .. math::
1928
1929 dst.xy = src.xy - \lfloor src.xy\rfloor
1930
1931 dst.zw = src.zw - \lfloor src.zw\rfloor
1932
1933
1934 .. opcode:: DFRACEXP - Convert Number to Fractional and Integral Components
1935
1936 Like the ``frexp()`` routine in many math libraries, this opcode stores the
1937 exponent of its source to ``dst0``, and the significand to ``dst1``, such that
1938 :math:`dst1 \times 2^{dst0} = src` .
1939
1940 .. math::
1941
1942 dst0.xy = exp(src.xy)
1943
1944 dst1.xy = frac(src.xy)
1945
1946 dst0.zw = exp(src.zw)
1947
1948 dst1.zw = frac(src.zw)
1949
1950 .. opcode:: DLDEXP - Multiply Number by Integral Power of 2
1951
1952 This opcode is the inverse of :opcode:`DFRACEXP`.
1953
1954 .. math::
1955
1956 dst.xy = src0.xy \times 2^{src1.xy}
1957
1958 dst.zw = src0.zw \times 2^{src1.zw}
1959
1960 .. opcode:: DMIN - Minimum
1961
1962 .. math::
1963
1964 dst.xy = min(src0.xy, src1.xy)
1965
1966 dst.zw = min(src0.zw, src1.zw)
1967
1968 .. opcode:: DMAX - Maximum
1969
1970 .. math::
1971
1972 dst.xy = max(src0.xy, src1.xy)
1973
1974 dst.zw = max(src0.zw, src1.zw)
1975
1976 .. opcode:: DMUL - Multiply
1977
1978 .. math::
1979
1980 dst.xy = src0.xy \times src1.xy
1981
1982 dst.zw = src0.zw \times src1.zw
1983
1984
1985 .. opcode:: DMAD - Multiply And Add
1986
1987 .. math::
1988
1989 dst.xy = src0.xy \times src1.xy + src2.xy
1990
1991 dst.zw = src0.zw \times src1.zw + src2.zw
1992
1993
1994 .. opcode:: DRCP - Reciprocal
1995
1996 .. math::
1997
1998 dst.xy = \frac{1}{src.xy}
1999
2000 dst.zw = \frac{1}{src.zw}
2001
2002 .. opcode:: DSQRT - Square Root
2003
2004 .. math::
2005
2006 dst.xy = \sqrt{src.xy}
2007
2008 dst.zw = \sqrt{src.zw}
2009
2010
2011 .. _samplingopcodes:
2012
2013 Resource Sampling Opcodes
2014 ^^^^^^^^^^^^^^^^^^^^^^^^^
2015
2016 Those opcodes follow very closely semantics of the respective Direct3D
2017 instructions. If in doubt double check Direct3D documentation.
2018 Note that the swizzle on SVIEW (src1) determines texel swizzling
2019 after lookup.
2020
2021 .. opcode:: SAMPLE
2022
2023 Using provided address, sample data from the specified texture using the
2024 filtering mode identified by the gven sampler. The source data may come from
2025 any resource type other than buffers.
2026
2027 Syntax: ``SAMPLE dst, address, sampler_view, sampler``
2028
2029 Example: ``SAMPLE TEMP[0], TEMP[1], SVIEW[0], SAMP[0]``
2030
2031 .. opcode:: SAMPLE_I
2032
2033 Simplified alternative to the SAMPLE instruction. Using the provided
2034 integer address, SAMPLE_I fetches data from the specified sampler view
2035 without any filtering. The source data may come from any resource type
2036 other than CUBE.
2037
2038 Syntax: ``SAMPLE_I dst, address, sampler_view``
2039
2040 Example: ``SAMPLE_I TEMP[0], TEMP[1], SVIEW[0]``
2041
2042 The 'address' is specified as unsigned integers. If the 'address' is out of
2043 range [0...(# texels - 1)] the result of the fetch is always 0 in all
2044 components. As such the instruction doesn't honor address wrap modes, in
2045 cases where that behavior is desirable 'SAMPLE' instruction should be used.
2046 address.w always provides an unsigned integer mipmap level. If the value is
2047 out of the range then the instruction always returns 0 in all components.
2048 address.yz are ignored for buffers and 1d textures. address.z is ignored
2049 for 1d texture arrays and 2d textures.
2050
2051 For 1D texture arrays address.y provides the array index (also as unsigned
2052 integer). If the value is out of the range of available array indices
2053 [0... (array size - 1)] then the opcode always returns 0 in all components.
2054 For 2D texture arrays address.z provides the array index, otherwise it
2055 exhibits the same behavior as in the case for 1D texture arrays. The exact
2056 semantics of the source address are presented in the table below:
2057
2058 +---------------------------+----+-----+-----+---------+
2059 | resource type | X | Y | Z | W |
2060 +===========================+====+=====+=====+=========+
2061 | ``PIPE_BUFFER`` | x | | | ignored |
2062 +---------------------------+----+-----+-----+---------+
2063 | ``PIPE_TEXTURE_1D`` | x | | | mpl |
2064 +---------------------------+----+-----+-----+---------+
2065 | ``PIPE_TEXTURE_2D`` | x | y | | mpl |
2066 +---------------------------+----+-----+-----+---------+
2067 | ``PIPE_TEXTURE_3D`` | x | y | z | mpl |
2068 +---------------------------+----+-----+-----+---------+
2069 | ``PIPE_TEXTURE_RECT`` | x | y | | mpl |
2070 +---------------------------+----+-----+-----+---------+
2071 | ``PIPE_TEXTURE_CUBE`` | not allowed as source |
2072 +---------------------------+----+-----+-----+---------+
2073 | ``PIPE_TEXTURE_1D_ARRAY`` | x | idx | | mpl |
2074 +---------------------------+----+-----+-----+---------+
2075 | ``PIPE_TEXTURE_2D_ARRAY`` | x | y | idx | mpl |
2076 +---------------------------+----+-----+-----+---------+
2077
2078 Where 'mpl' is a mipmap level and 'idx' is the array index.
2079
2080 .. opcode:: SAMPLE_I_MS
2081
2082 Just like SAMPLE_I but allows fetch data from multi-sampled surfaces.
2083
2084 Syntax: ``SAMPLE_I_MS dst, address, sampler_view, sample``
2085
2086 .. opcode:: SAMPLE_B
2087
2088 Just like the SAMPLE instruction with the exception that an additional bias
2089 is applied to the level of detail computed as part of the instruction
2090 execution.
2091
2092 Syntax: ``SAMPLE_B dst, address, sampler_view, sampler, lod_bias``
2093
2094 Example: ``SAMPLE_B TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2].x``
2095
2096 .. opcode:: SAMPLE_C
2097
2098 Similar to the SAMPLE instruction but it performs a comparison filter. The
2099 operands to SAMPLE_C are identical to SAMPLE, except that there is an
2100 additional float32 operand, reference value, which must be a register with
2101 single-component, or a scalar literal. SAMPLE_C makes the hardware use the
2102 current samplers compare_func (in pipe_sampler_state) to compare reference
2103 value against the red component value for the surce resource at each texel
2104 that the currently configured texture filter covers based on the provided
2105 coordinates.
2106
2107 Syntax: ``SAMPLE_C dst, address, sampler_view.r, sampler, ref_value``
2108
2109 Example: ``SAMPLE_C TEMP[0], TEMP[1], SVIEW[0].r, SAMP[0], TEMP[2].x``
2110
2111 .. opcode:: SAMPLE_C_LZ
2112
2113 Same as SAMPLE_C, but LOD is 0 and derivatives are ignored. The LZ stands
2114 for level-zero.
2115
2116 Syntax: ``SAMPLE_C_LZ dst, address, sampler_view.r, sampler, ref_value``
2117
2118 Example: ``SAMPLE_C_LZ TEMP[0], TEMP[1], SVIEW[0].r, SAMP[0], TEMP[2].x``
2119
2120
2121 .. opcode:: SAMPLE_D
2122
2123 SAMPLE_D is identical to the SAMPLE opcode except that the derivatives for
2124 the source address in the x direction and the y direction are provided by
2125 extra parameters.
2126
2127 Syntax: ``SAMPLE_D dst, address, sampler_view, sampler, der_x, der_y``
2128
2129 Example: ``SAMPLE_D TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2], TEMP[3]``
2130
2131 .. opcode:: SAMPLE_L
2132
2133 SAMPLE_L is identical to the SAMPLE opcode except that the LOD is provided
2134 directly as a scalar value, representing no anisotropy.
2135
2136 Syntax: ``SAMPLE_L dst, address, sampler_view, sampler, explicit_lod``
2137
2138 Example: ``SAMPLE_L TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2].x``
2139
2140 .. opcode:: GATHER4
2141
2142 Gathers the four texels to be used in a bi-linear filtering operation and
2143 packs them into a single register. Only works with 2D, 2D array, cubemaps,
2144 and cubemaps arrays. For 2D textures, only the addressing modes of the
2145 sampler and the top level of any mip pyramid are used. Set W to zero. It
2146 behaves like the SAMPLE instruction, but a filtered sample is not
2147 generated. The four samples that contribute to filtering are placed into
2148 xyzw in counter-clockwise order, starting with the (u,v) texture coordinate
2149 delta at the following locations (-, +), (+, +), (+, -), (-, -), where the
2150 magnitude of the deltas are half a texel.
2151
2152
2153 .. opcode:: SVIEWINFO
2154
2155 Query the dimensions of a given sampler view. dst receives width, height,
2156 depth or array size and number of mipmap levels as int4. The dst can have a
2157 writemask which will specify what info is the caller interested in.
2158
2159 Syntax: ``SVIEWINFO dst, src_mip_level, sampler_view``
2160
2161 Example: ``SVIEWINFO TEMP[0], TEMP[1].x, SVIEW[0]``
2162
2163 src_mip_level is an unsigned integer scalar. If it's out of range then
2164 returns 0 for width, height and depth/array size but the total number of
2165 mipmap is still returned correctly for the given sampler view. The returned
2166 width, height and depth values are for the mipmap level selected by the
2167 src_mip_level and are in the number of texels. For 1d texture array width
2168 is in dst.x, array size is in dst.y and dst.z is 0. The number of mipmaps is
2169 still in dst.w. In contrast to d3d10 resinfo, there's no way in the tgsi
2170 instruction encoding to specify the return type (float/rcpfloat/uint), hence
2171 always using uint. Also, unlike the SAMPLE instructions, the swizzle on src1
2172 resinfo allowing swizzling dst values is ignored (due to the interaction
2173 with rcpfloat modifier which requires some swizzle handling in the state
2174 tracker anyway).
2175
2176 .. opcode:: SAMPLE_POS
2177
2178 Query the position of a given sample. dst receives float4 (x, y, 0, 0)
2179 indicated where the sample is located. If the resource is not a multi-sample
2180 resource and not a render target, the result is 0.
2181
2182 .. opcode:: SAMPLE_INFO
2183
2184 dst receives number of samples in x. If the resource is not a multi-sample
2185 resource and not a render target, the result is 0.
2186
2187
2188 .. _resourceopcodes:
2189
2190 Resource Access Opcodes
2191 ^^^^^^^^^^^^^^^^^^^^^^^
2192
2193 .. opcode:: LOAD - Fetch data from a shader resource
2194
2195 Syntax: ``LOAD dst, resource, address``
2196
2197 Example: ``LOAD TEMP[0], RES[0], TEMP[1]``
2198
2199 Using the provided integer address, LOAD fetches data
2200 from the specified buffer or texture without any
2201 filtering.
2202
2203 The 'address' is specified as a vector of unsigned
2204 integers. If the 'address' is out of range the result
2205 is unspecified.
2206
2207 Only the first mipmap level of a resource can be read
2208 from using this instruction.
2209
2210 For 1D or 2D texture arrays, the array index is
2211 provided as an unsigned integer in address.y or
2212 address.z, respectively. address.yz are ignored for
2213 buffers and 1D textures. address.z is ignored for 1D
2214 texture arrays and 2D textures. address.w is always
2215 ignored.
2216
2217 .. opcode:: STORE - Write data to a shader resource
2218
2219 Syntax: ``STORE resource, address, src``
2220
2221 Example: ``STORE RES[0], TEMP[0], TEMP[1]``
2222
2223 Using the provided integer address, STORE writes data
2224 to the specified buffer or texture.
2225
2226 The 'address' is specified as a vector of unsigned
2227 integers. If the 'address' is out of range the result
2228 is unspecified.
2229
2230 Only the first mipmap level of a resource can be
2231 written to using this instruction.
2232
2233 For 1D or 2D texture arrays, the array index is
2234 provided as an unsigned integer in address.y or
2235 address.z, respectively. address.yz are ignored for
2236 buffers and 1D textures. address.z is ignored for 1D
2237 texture arrays and 2D textures. address.w is always
2238 ignored.
2239
2240
2241 .. _threadsyncopcodes:
2242
2243 Inter-thread synchronization opcodes
2244 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2245
2246 These opcodes are intended for communication between threads running
2247 within the same compute grid. For now they're only valid in compute
2248 programs.
2249
2250 .. opcode:: MFENCE - Memory fence
2251
2252 Syntax: ``MFENCE resource``
2253
2254 Example: ``MFENCE RES[0]``
2255
2256 This opcode forces strong ordering between any memory access
2257 operations that affect the specified resource. This means that
2258 previous loads and stores (and only those) will be performed and
2259 visible to other threads before the program execution continues.
2260
2261
2262 .. opcode:: LFENCE - Load memory fence
2263
2264 Syntax: ``LFENCE resource``
2265
2266 Example: ``LFENCE RES[0]``
2267
2268 Similar to MFENCE, but it only affects the ordering of memory loads.
2269
2270
2271 .. opcode:: SFENCE - Store memory fence
2272
2273 Syntax: ``SFENCE resource``
2274
2275 Example: ``SFENCE RES[0]``
2276
2277 Similar to MFENCE, but it only affects the ordering of memory stores.
2278
2279
2280 .. opcode:: BARRIER - Thread group barrier
2281
2282 ``BARRIER``
2283
2284 This opcode suspends the execution of the current thread until all
2285 the remaining threads in the working group reach the same point of
2286 the program. Results are unspecified if any of the remaining
2287 threads terminates or never reaches an executed BARRIER instruction.
2288
2289
2290 .. _atomopcodes:
2291
2292 Atomic opcodes
2293 ^^^^^^^^^^^^^^
2294
2295 These opcodes provide atomic variants of some common arithmetic and
2296 logical operations. In this context atomicity means that another
2297 concurrent memory access operation that affects the same memory
2298 location is guaranteed to be performed strictly before or after the
2299 entire execution of the atomic operation.
2300
2301 For the moment they're only valid in compute programs.
2302
2303 .. opcode:: ATOMUADD - Atomic integer addition
2304
2305 Syntax: ``ATOMUADD dst, resource, offset, src``
2306
2307 Example: ``ATOMUADD TEMP[0], RES[0], TEMP[1], TEMP[2]``
2308
2309 The following operation is performed atomically on each component:
2310
2311 .. math::
2312
2313 dst_i = resource[offset]_i
2314
2315 resource[offset]_i = dst_i + src_i
2316
2317
2318 .. opcode:: ATOMXCHG - Atomic exchange
2319
2320 Syntax: ``ATOMXCHG dst, resource, offset, src``
2321
2322 Example: ``ATOMXCHG TEMP[0], RES[0], TEMP[1], TEMP[2]``
2323
2324 The following operation is performed atomically on each component:
2325
2326 .. math::
2327
2328 dst_i = resource[offset]_i
2329
2330 resource[offset]_i = src_i
2331
2332
2333 .. opcode:: ATOMCAS - Atomic compare-and-exchange
2334
2335 Syntax: ``ATOMCAS dst, resource, offset, cmp, src``
2336
2337 Example: ``ATOMCAS TEMP[0], RES[0], TEMP[1], TEMP[2], TEMP[3]``
2338
2339 The following operation is performed atomically on each component:
2340
2341 .. math::
2342
2343 dst_i = resource[offset]_i
2344
2345 resource[offset]_i = (dst_i == cmp_i ? src_i : dst_i)
2346
2347
2348 .. opcode:: ATOMAND - Atomic bitwise And
2349
2350 Syntax: ``ATOMAND dst, resource, offset, src``
2351
2352 Example: ``ATOMAND TEMP[0], RES[0], TEMP[1], TEMP[2]``
2353
2354 The following operation is performed atomically on each component:
2355
2356 .. math::
2357
2358 dst_i = resource[offset]_i
2359
2360 resource[offset]_i = dst_i \& src_i
2361
2362
2363 .. opcode:: ATOMOR - Atomic bitwise Or
2364
2365 Syntax: ``ATOMOR dst, resource, offset, src``
2366
2367 Example: ``ATOMOR TEMP[0], RES[0], TEMP[1], TEMP[2]``
2368
2369 The following operation is performed atomically on each component:
2370
2371 .. math::
2372
2373 dst_i = resource[offset]_i
2374
2375 resource[offset]_i = dst_i | src_i
2376
2377
2378 .. opcode:: ATOMXOR - Atomic bitwise Xor
2379
2380 Syntax: ``ATOMXOR dst, resource, offset, src``
2381
2382 Example: ``ATOMXOR TEMP[0], RES[0], TEMP[1], TEMP[2]``
2383
2384 The following operation is performed atomically on each component:
2385
2386 .. math::
2387
2388 dst_i = resource[offset]_i
2389
2390 resource[offset]_i = dst_i \oplus src_i
2391
2392
2393 .. opcode:: ATOMUMIN - Atomic unsigned minimum
2394
2395 Syntax: ``ATOMUMIN dst, resource, offset, src``
2396
2397 Example: ``ATOMUMIN TEMP[0], RES[0], TEMP[1], TEMP[2]``
2398
2399 The following operation is performed atomically on each component:
2400
2401 .. math::
2402
2403 dst_i = resource[offset]_i
2404
2405 resource[offset]_i = (dst_i < src_i ? dst_i : src_i)
2406
2407
2408 .. opcode:: ATOMUMAX - Atomic unsigned maximum
2409
2410 Syntax: ``ATOMUMAX dst, resource, offset, src``
2411
2412 Example: ``ATOMUMAX TEMP[0], RES[0], TEMP[1], TEMP[2]``
2413
2414 The following operation is performed atomically on each component:
2415
2416 .. math::
2417
2418 dst_i = resource[offset]_i
2419
2420 resource[offset]_i = (dst_i > src_i ? dst_i : src_i)
2421
2422
2423 .. opcode:: ATOMIMIN - Atomic signed minimum
2424
2425 Syntax: ``ATOMIMIN dst, resource, offset, src``
2426
2427 Example: ``ATOMIMIN TEMP[0], RES[0], TEMP[1], TEMP[2]``
2428
2429 The following operation is performed atomically on each component:
2430
2431 .. math::
2432
2433 dst_i = resource[offset]_i
2434
2435 resource[offset]_i = (dst_i < src_i ? dst_i : src_i)
2436
2437
2438 .. opcode:: ATOMIMAX - Atomic signed maximum
2439
2440 Syntax: ``ATOMIMAX dst, resource, offset, src``
2441
2442 Example: ``ATOMIMAX TEMP[0], RES[0], TEMP[1], TEMP[2]``
2443
2444 The following operation is performed atomically on each component:
2445
2446 .. math::
2447
2448 dst_i = resource[offset]_i
2449
2450 resource[offset]_i = (dst_i > src_i ? dst_i : src_i)
2451
2452
2453
2454 Explanation of symbols used
2455 ------------------------------
2456
2457
2458 Functions
2459 ^^^^^^^^^^^^^^
2460
2461
2462 :math:`|x|` Absolute value of `x`.
2463
2464 :math:`\lceil x \rceil` Ceiling of `x`.
2465
2466 clamp(x,y,z) Clamp x between y and z.
2467 (x < y) ? y : (x > z) ? z : x
2468
2469 :math:`\lfloor x\rfloor` Floor of `x`.
2470
2471 :math:`\log_2{x}` Logarithm of `x`, base 2.
2472
2473 max(x,y) Maximum of x and y.
2474 (x > y) ? x : y
2475
2476 min(x,y) Minimum of x and y.
2477 (x < y) ? x : y
2478
2479 partialx(x) Derivative of x relative to fragment's X.
2480
2481 partialy(x) Derivative of x relative to fragment's Y.
2482
2483 pop() Pop from stack.
2484
2485 :math:`x^y` `x` to the power `y`.
2486
2487 push(x) Push x on stack.
2488
2489 round(x) Round x.
2490
2491 trunc(x) Truncate x, i.e. drop the fraction bits.
2492
2493
2494 Keywords
2495 ^^^^^^^^^^^^^
2496
2497
2498 discard Discard fragment.
2499
2500 pc Program counter.
2501
2502 target Label of target instruction.
2503
2504
2505 Other tokens
2506 ---------------
2507
2508
2509 Declaration
2510 ^^^^^^^^^^^
2511
2512
2513 Declares a register that is will be referenced as an operand in Instruction
2514 tokens.
2515
2516 File field contains register file that is being declared and is one
2517 of TGSI_FILE.
2518
2519 UsageMask field specifies which of the register components can be accessed
2520 and is one of TGSI_WRITEMASK.
2521
2522 The Local flag specifies that a given value isn't intended for
2523 subroutine parameter passing and, as a result, the implementation
2524 isn't required to give any guarantees of it being preserved across
2525 subroutine boundaries. As it's merely a compiler hint, the
2526 implementation is free to ignore it.
2527
2528 If Dimension flag is set to 1, a Declaration Dimension token follows.
2529
2530 If Semantic flag is set to 1, a Declaration Semantic token follows.
2531
2532 If Interpolate flag is set to 1, a Declaration Interpolate token follows.
2533
2534 If file is TGSI_FILE_RESOURCE, a Declaration Resource token follows.
2535
2536 If Array flag is set to 1, a Declaration Array token follows.
2537
2538 Array Declaration
2539 ^^^^^^^^^^^^^^^^^^^^^^^^
2540
2541 Declarations can optional have an ArrayID attribute which can be referred by
2542 indirect addressing operands. An ArrayID of zero is reserved and treaded as
2543 if no ArrayID is specified.
2544
2545 If an indirect addressing operand refers to a specific declaration by using
2546 an ArrayID only the registers in this declaration are guaranteed to be
2547 accessed, accessing any register outside this declaration results in undefined
2548 behavior. Note that for compatibility the effective index is zero-based and
2549 not relative to the specified declaration
2550
2551 If no ArrayID is specified with an indirect addressing operand the whole
2552 register file might be accessed by this operand. This is strongly discouraged
2553 and will prevent packing of scalar/vec2 arrays and effective alias analysis.
2554
2555 Declaration Semantic
2556 ^^^^^^^^^^^^^^^^^^^^^^^^
2557
2558 Vertex and fragment shader input and output registers may be labeled
2559 with semantic information consisting of a name and index.
2560
2561 Follows Declaration token if Semantic bit is set.
2562
2563 Since its purpose is to link a shader with other stages of the pipeline,
2564 it is valid to follow only those Declaration tokens that declare a register
2565 either in INPUT or OUTPUT file.
2566
2567 SemanticName field contains the semantic name of the register being declared.
2568 There is no default value.
2569
2570 SemanticIndex is an optional subscript that can be used to distinguish
2571 different register declarations with the same semantic name. The default value
2572 is 0.
2573
2574 The meanings of the individual semantic names are explained in the following
2575 sections.
2576
2577 TGSI_SEMANTIC_POSITION
2578 """"""""""""""""""""""
2579
2580 For vertex shaders, TGSI_SEMANTIC_POSITION indicates the vertex shader
2581 output register which contains the homogeneous vertex position in the clip
2582 space coordinate system. After clipping, the X, Y and Z components of the
2583 vertex will be divided by the W value to get normalized device coordinates.
2584
2585 For fragment shaders, TGSI_SEMANTIC_POSITION is used to indicate that
2586 fragment shader input contains the fragment's window position. The X
2587 component starts at zero and always increases from left to right.
2588 The Y component starts at zero and always increases but Y=0 may either
2589 indicate the top of the window or the bottom depending on the fragment
2590 coordinate origin convention (see TGSI_PROPERTY_FS_COORD_ORIGIN).
2591 The Z coordinate ranges from 0 to 1 to represent depth from the front
2592 to the back of the Z buffer. The W component contains the reciprocol
2593 of the interpolated vertex position W component.
2594
2595 Fragment shaders may also declare an output register with
2596 TGSI_SEMANTIC_POSITION. Only the Z component is writable. This allows
2597 the fragment shader to change the fragment's Z position.
2598
2599
2600
2601 TGSI_SEMANTIC_COLOR
2602 """""""""""""""""""
2603
2604 For vertex shader outputs or fragment shader inputs/outputs, this
2605 label indicates that the resister contains an R,G,B,A color.
2606
2607 Several shader inputs/outputs may contain colors so the semantic index
2608 is used to distinguish them. For example, color[0] may be the diffuse
2609 color while color[1] may be the specular color.
2610
2611 This label is needed so that the flat/smooth shading can be applied
2612 to the right interpolants during rasterization.
2613
2614
2615
2616 TGSI_SEMANTIC_BCOLOR
2617 """"""""""""""""""""
2618
2619 Back-facing colors are only used for back-facing polygons, and are only valid
2620 in vertex shader outputs. After rasterization, all polygons are front-facing
2621 and COLOR and BCOLOR end up occupying the same slots in the fragment shader,
2622 so all BCOLORs effectively become regular COLORs in the fragment shader.
2623
2624
2625 TGSI_SEMANTIC_FOG
2626 """""""""""""""""
2627
2628 Vertex shader inputs and outputs and fragment shader inputs may be
2629 labeled with TGSI_SEMANTIC_FOG to indicate that the register contains
2630 a fog coordinate. Typically, the fragment shader will use the fog coordinate
2631 to compute a fog blend factor which is used to blend the normal fragment color
2632 with a constant fog color. But fog coord really is just an ordinary vec4
2633 register like regular semantics.
2634
2635
2636 TGSI_SEMANTIC_PSIZE
2637 """""""""""""""""""
2638
2639 Vertex shader input and output registers may be labeled with
2640 TGIS_SEMANTIC_PSIZE to indicate that the register contains a point size
2641 in the form (S, 0, 0, 1). The point size controls the width or diameter
2642 of points for rasterization. This label cannot be used in fragment
2643 shaders.
2644
2645 When using this semantic, be sure to set the appropriate state in the
2646 :ref:`rasterizer` first.
2647
2648
2649 TGSI_SEMANTIC_TEXCOORD
2650 """"""""""""""""""""""
2651
2652 Only available if PIPE_CAP_TGSI_TEXCOORD is exposed !
2653
2654 Vertex shader outputs and fragment shader inputs may be labeled with
2655 this semantic to make them replaceable by sprite coordinates via the
2656 sprite_coord_enable state in the :ref:`rasterizer`.
2657 The semantic index permitted with this semantic is limited to <= 7.
2658
2659 If the driver does not support TEXCOORD, sprite coordinate replacement
2660 applies to inputs with the GENERIC semantic instead.
2661
2662 The intended use case for this semantic is gl_TexCoord.
2663
2664
2665 TGSI_SEMANTIC_PCOORD
2666 """"""""""""""""""""
2667
2668 Only available if PIPE_CAP_TGSI_TEXCOORD is exposed !
2669
2670 Fragment shader inputs may be labeled with TGSI_SEMANTIC_PCOORD to indicate
2671 that the register contains sprite coordinates in the form (x, y, 0, 1), if
2672 the current primitive is a point and point sprites are enabled. Otherwise,
2673 the contents of the register are undefined.
2674
2675 The intended use case for this semantic is gl_PointCoord.
2676
2677
2678 TGSI_SEMANTIC_GENERIC
2679 """""""""""""""""""""
2680
2681 All vertex/fragment shader inputs/outputs not labeled with any other
2682 semantic label can be considered to be generic attributes. Typical
2683 uses of generic inputs/outputs are texcoords and user-defined values.
2684
2685
2686 TGSI_SEMANTIC_NORMAL
2687 """"""""""""""""""""
2688
2689 Indicates that a vertex shader input is a normal vector. This is
2690 typically only used for legacy graphics APIs.
2691
2692
2693 TGSI_SEMANTIC_FACE
2694 """"""""""""""""""
2695
2696 This label applies to fragment shader inputs only and indicates that
2697 the register contains front/back-face information of the form (F, 0,
2698 0, 1). The first component will be positive when the fragment belongs
2699 to a front-facing polygon, and negative when the fragment belongs to a
2700 back-facing polygon.
2701
2702
2703 TGSI_SEMANTIC_EDGEFLAG
2704 """"""""""""""""""""""
2705
2706 For vertex shaders, this sematic label indicates that an input or
2707 output is a boolean edge flag. The register layout is [F, x, x, x]
2708 where F is 0.0 or 1.0 and x = don't care. Normally, the vertex shader
2709 simply copies the edge flag input to the edgeflag output.
2710
2711 Edge flags are used to control which lines or points are actually
2712 drawn when the polygon mode converts triangles/quads/polygons into
2713 points or lines.
2714
2715
2716 TGSI_SEMANTIC_STENCIL
2717 """""""""""""""""""""
2718
2719 For fragment shaders, this semantic label indicates that an output
2720 is a writable stencil reference value. Only the Y component is writable.
2721 This allows the fragment shader to change the fragments stencilref value.
2722
2723
2724 TGSI_SEMANTIC_VIEWPORT_INDEX
2725 """"""""""""""""""""""""""""
2726
2727 For geometry shaders, this semantic label indicates that an output
2728 contains the index of the viewport (and scissor) to use.
2729 Only the X value is used.
2730
2731
2732 TGSI_SEMANTIC_LAYER
2733 """""""""""""""""""
2734
2735 For geometry shaders, this semantic label indicates that an output
2736 contains the layer value to use for the color and depth/stencil surfaces.
2737 Only the X value is used. (Also known as rendertarget array index.)
2738
2739
2740 TGSI_SEMANTIC_CULLDIST
2741 """"""""""""""""""""""
2742
2743 Used as distance to plane for performing application-defined culling
2744 of individual primitives against a plane. When components of vertex
2745 elements are given this label, these values are assumed to be a
2746 float32 signed distance to a plane. Primitives will be completely
2747 discarded if the plane distance for all of the vertices in the
2748 primitive are < 0. If a vertex has a cull distance of NaN, that
2749 vertex counts as "out" (as if its < 0);
2750 The limits on both clip and cull distances are bound
2751 by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT define which defines
2752 the maximum number of components that can be used to hold the
2753 distances and by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
2754 which specifies the maximum number of registers which can be
2755 annotated with those semantics.
2756
2757
2758 TGSI_SEMANTIC_CLIPDIST
2759 """"""""""""""""""""""
2760
2761 When components of vertex elements are identified this way, these
2762 values are each assumed to be a float32 signed distance to a plane.
2763 Primitive setup only invokes rasterization on pixels for which
2764 the interpolated plane distances are >= 0. Multiple clip planes
2765 can be implemented simultaneously, by annotating multiple
2766 components of one or more vertex elements with the above specified
2767 semantic. The limits on both clip and cull distances are bound
2768 by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT define which defines
2769 the maximum number of components that can be used to hold the
2770 distances and by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
2771 which specifies the maximum number of registers which can be
2772 annotated with those semantics.
2773
2774 TGSI_SEMANTIC_SAMPLEID
2775 """"""""""""""""""""""
2776
2777 For fragment shaders, this semantic label indicates that a system value
2778 contains the current sample id (i.e. gl_SampleID). Only the X value is used.
2779
2780 TGSI_SEMANTIC_SAMPLEPOS
2781 """""""""""""""""""""""
2782
2783 For fragment shaders, this semantic label indicates that a system value
2784 contains the current sample's position (i.e. gl_SamplePosition). Only the X
2785 and Y values are used.
2786
2787 TGSI_SEMANTIC_SAMPLEMASK
2788 """"""""""""""""""""""""
2789
2790 For fragment shaders, this semantic label indicates that an output contains
2791 the sample mask used to disable further sample processing
2792 (i.e. gl_SampleMask). Only the X value is used, up to 32x MS.
2793
2794 TGSI_SEMANTIC_INVOCATIONID
2795 """"""""""""""""""""""""""
2796
2797 For geometry shaders, this semantic label indicates that a system value
2798 contains the current invocation id (i.e. gl_InvocationID). Only the X value is
2799 used.
2800
2801 Declaration Interpolate
2802 ^^^^^^^^^^^^^^^^^^^^^^^
2803
2804 This token is only valid for fragment shader INPUT declarations.
2805
2806 The Interpolate field specifes the way input is being interpolated by
2807 the rasteriser and is one of TGSI_INTERPOLATE_*.
2808
2809 The Location field specifies the location inside the pixel that the
2810 interpolation should be done at, one of ``TGSI_INTERPOLATE_LOC_*``. Note that
2811 when per-sample shading is enabled, the implementation may choose to
2812 interpolate at the sample irrespective of the Location field.
2813
2814 The CylindricalWrap bitfield specifies which register components
2815 should be subject to cylindrical wrapping when interpolating by the
2816 rasteriser. If TGSI_CYLINDRICAL_WRAP_X is set to 1, the X component
2817 should be interpolated according to cylindrical wrapping rules.
2818
2819
2820 Declaration Sampler View
2821 ^^^^^^^^^^^^^^^^^^^^^^^^
2822
2823 Follows Declaration token if file is TGSI_FILE_SAMPLER_VIEW.
2824
2825 DCL SVIEW[#], resource, type(s)
2826
2827 Declares a shader input sampler view and assigns it to a SVIEW[#]
2828 register.
2829
2830 resource can be one of BUFFER, 1D, 2D, 3D, 1DArray and 2DArray.
2831
2832 type must be 1 or 4 entries (if specifying on a per-component
2833 level) out of UNORM, SNORM, SINT, UINT and FLOAT.
2834
2835
2836 Declaration Resource
2837 ^^^^^^^^^^^^^^^^^^^^
2838
2839 Follows Declaration token if file is TGSI_FILE_RESOURCE.
2840
2841 DCL RES[#], resource [, WR] [, RAW]
2842
2843 Declares a shader input resource and assigns it to a RES[#]
2844 register.
2845
2846 resource can be one of BUFFER, 1D, 2D, 3D, CUBE, 1DArray and
2847 2DArray.
2848
2849 If the RAW keyword is not specified, the texture data will be
2850 subject to conversion, swizzling and scaling as required to yield
2851 the specified data type from the physical data format of the bound
2852 resource.
2853
2854 If the RAW keyword is specified, no channel conversion will be
2855 performed: the values read for each of the channels (X,Y,Z,W) will
2856 correspond to consecutive words in the same order and format
2857 they're found in memory. No element-to-address conversion will be
2858 performed either: the value of the provided X coordinate will be
2859 interpreted in byte units instead of texel units. The result of
2860 accessing a misaligned address is undefined.
2861
2862 Usage of the STORE opcode is only allowed if the WR (writable) flag
2863 is set.
2864
2865
2866 Properties
2867 ^^^^^^^^^^^^^^^^^^^^^^^^
2868
2869 Properties are general directives that apply to the whole TGSI program.
2870
2871 FS_COORD_ORIGIN
2872 """""""""""""""
2873
2874 Specifies the fragment shader TGSI_SEMANTIC_POSITION coordinate origin.
2875 The default value is UPPER_LEFT.
2876
2877 If UPPER_LEFT, the position will be (0,0) at the upper left corner and
2878 increase downward and rightward.
2879 If LOWER_LEFT, the position will be (0,0) at the lower left corner and
2880 increase upward and rightward.
2881
2882 OpenGL defaults to LOWER_LEFT, and is configurable with the
2883 GL_ARB_fragment_coord_conventions extension.
2884
2885 DirectX 9/10 use UPPER_LEFT.
2886
2887 FS_COORD_PIXEL_CENTER
2888 """""""""""""""""""""
2889
2890 Specifies the fragment shader TGSI_SEMANTIC_POSITION pixel center convention.
2891 The default value is HALF_INTEGER.
2892
2893 If HALF_INTEGER, the fractionary part of the position will be 0.5
2894 If INTEGER, the fractionary part of the position will be 0.0
2895
2896 Note that this does not affect the set of fragments generated by
2897 rasterization, which is instead controlled by half_pixel_center in the
2898 rasterizer.
2899
2900 OpenGL defaults to HALF_INTEGER, and is configurable with the
2901 GL_ARB_fragment_coord_conventions extension.
2902
2903 DirectX 9 uses INTEGER.
2904 DirectX 10 uses HALF_INTEGER.
2905
2906 FS_COLOR0_WRITES_ALL_CBUFS
2907 """"""""""""""""""""""""""
2908 Specifies that writes to the fragment shader color 0 are replicated to all
2909 bound cbufs. This facilitates OpenGL's fragColor output vs fragData[0] where
2910 fragData is directed to a single color buffer, but fragColor is broadcast.
2911
2912 VS_PROHIBIT_UCPS
2913 """"""""""""""""""""""""""
2914 If this property is set on the program bound to the shader stage before the
2915 fragment shader, user clip planes should have no effect (be disabled) even if
2916 that shader does not write to any clip distance outputs and the rasterizer's
2917 clip_plane_enable is non-zero.
2918 This property is only supported by drivers that also support shader clip
2919 distance outputs.
2920 This is useful for APIs that don't have UCPs and where clip distances written
2921 by a shader cannot be disabled.
2922
2923 GS_INVOCATIONS
2924 """"""""""""""
2925
2926 Specifies the number of times a geometry shader should be executed for each
2927 input primitive. Each invocation will have a different
2928 TGSI_SEMANTIC_INVOCATIONID system value set. If not specified, assumed to
2929 be 1.
2930
2931 VS_WINDOW_SPACE_POSITION
2932 """"""""""""""""""""""""""
2933 If this property is set on the vertex shader, the TGSI_SEMANTIC_POSITION output
2934 is assumed to contain window space coordinates.
2935 Division of X,Y,Z by W and the viewport transformation are disabled, and 1/W is
2936 directly taken from the 4-th component of the shader output.
2937 Naturally, clipping is not performed on window coordinates either.
2938 The effect of this property is undefined if a geometry or tessellation shader
2939 are in use.
2940
2941 Texture Sampling and Texture Formats
2942 ------------------------------------
2943
2944 This table shows how texture image components are returned as (x,y,z,w) tuples
2945 by TGSI texture instructions, such as :opcode:`TEX`, :opcode:`TXD`, and
2946 :opcode:`TXP`. For reference, OpenGL and Direct3D conventions are shown as
2947 well.
2948
2949 +--------------------+--------------+--------------------+--------------+
2950 | Texture Components | Gallium | OpenGL | Direct3D 9 |
2951 +====================+==============+====================+==============+
2952 | R | (r, 0, 0, 1) | (r, 0, 0, 1) | (r, 1, 1, 1) |
2953 +--------------------+--------------+--------------------+--------------+
2954 | RG | (r, g, 0, 1) | (r, g, 0, 1) | (r, g, 1, 1) |
2955 +--------------------+--------------+--------------------+--------------+
2956 | RGB | (r, g, b, 1) | (r, g, b, 1) | (r, g, b, 1) |
2957 +--------------------+--------------+--------------------+--------------+
2958 | RGBA | (r, g, b, a) | (r, g, b, a) | (r, g, b, a) |
2959 +--------------------+--------------+--------------------+--------------+
2960 | A | (0, 0, 0, a) | (0, 0, 0, a) | (0, 0, 0, a) |
2961 +--------------------+--------------+--------------------+--------------+
2962 | L | (l, l, l, 1) | (l, l, l, 1) | (l, l, l, 1) |
2963 +--------------------+--------------+--------------------+--------------+
2964 | LA | (l, l, l, a) | (l, l, l, a) | (l, l, l, a) |
2965 +--------------------+--------------+--------------------+--------------+
2966 | I | (i, i, i, i) | (i, i, i, i) | N/A |
2967 +--------------------+--------------+--------------------+--------------+
2968 | UV | XXX TBD | (0, 0, 0, 1) | (u, v, 1, 1) |
2969 | | | [#envmap-bumpmap]_ | |
2970 +--------------------+--------------+--------------------+--------------+
2971 | Z | XXX TBD | (z, z, z, 1) | (0, z, 0, 1) |
2972 | | | [#depth-tex-mode]_ | |
2973 +--------------------+--------------+--------------------+--------------+
2974 | S | (s, s, s, s) | unknown | unknown |
2975 +--------------------+--------------+--------------------+--------------+
2976
2977 .. [#envmap-bumpmap] http://www.opengl.org/registry/specs/ATI/envmap_bumpmap.txt
2978 .. [#depth-tex-mode] the default is (z, z, z, 1) but may also be (0, 0, 0, z)
2979 or (z, z, z, z) depending on the value of GL_DEPTH_TEXTURE_MODE.