OSDN Git Service

0a5b2274a9a5e210ee4ea59ed2bd7bcc452bb1d2
[android-x86/external-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:`Double Opcodes`.
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 type only the negate modifier is supported. This
36 includes instructions which are otherwise ignorant if the type is signed or
37 unsigned, such as TGSI_OPCODE_UADD.
38
39 For inputs with unsigned type no modifiers are allowed.
40
41 Instruction Set
42 ---------------
43
44 Core ISA
45 ^^^^^^^^^^^^^^^^^^^^^^^^^
46
47 These opcodes are guaranteed to be available regardless of the driver being
48 used.
49
50 .. opcode:: ARL - Address Register Load
51
52 .. math::
53
54   dst.x = \lfloor src.x\rfloor
55
56   dst.y = \lfloor src.y\rfloor
57
58   dst.z = \lfloor src.z\rfloor
59
60   dst.w = \lfloor src.w\rfloor
61
62
63 .. opcode:: MOV - Move
64
65 .. math::
66
67   dst.x = src.x
68
69   dst.y = src.y
70
71   dst.z = src.z
72
73   dst.w = src.w
74
75
76 .. opcode:: LIT - Light Coefficients
77
78 .. math::
79
80   dst.x = 1
81
82   dst.y = max(src.x, 0)
83
84   dst.z = (src.x > 0) ? max(src.y, 0)^{clamp(src.w, -128, 128))} : 0
85
86   dst.w = 1
87
88
89 .. opcode:: RCP - Reciprocal
90
91 This instruction replicates its result.
92
93 .. math::
94
95   dst = \frac{1}{src.x}
96
97
98 .. opcode:: RSQ - Reciprocal Square Root
99
100 This instruction replicates its result.
101
102 .. math::
103
104   dst = \frac{1}{\sqrt{|src.x|}}
105
106
107 .. opcode:: SQRT - Square Root
108
109 This instruction replicates its result.
110
111 .. math::
112
113   dst = {\sqrt{src.x}}
114
115
116 .. opcode:: EXP - Approximate Exponential Base 2
117
118 .. math::
119
120   dst.x = 2^{\lfloor src.x\rfloor}
121
122   dst.y = src.x - \lfloor src.x\rfloor
123
124   dst.z = 2^{src.x}
125
126   dst.w = 1
127
128
129 .. opcode:: LOG - Approximate Logarithm Base 2
130
131 .. math::
132
133   dst.x = \lfloor\log_2{|src.x|}\rfloor
134
135   dst.y = \frac{|src.x|}{2^{\lfloor\log_2{|src.x|}\rfloor}}
136
137   dst.z = \log_2{|src.x|}
138
139   dst.w = 1
140
141
142 .. opcode:: MUL - Multiply
143
144 .. math::
145
146   dst.x = src0.x \times src1.x
147
148   dst.y = src0.y \times src1.y
149
150   dst.z = src0.z \times src1.z
151
152   dst.w = src0.w \times src1.w
153
154
155 .. opcode:: ADD - Add
156
157 .. math::
158
159   dst.x = src0.x + src1.x
160
161   dst.y = src0.y + src1.y
162
163   dst.z = src0.z + src1.z
164
165   dst.w = src0.w + src1.w
166
167
168 .. opcode:: DP3 - 3-component Dot Product
169
170 This instruction replicates its result.
171
172 .. math::
173
174   dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z
175
176
177 .. opcode:: DP4 - 4-component Dot Product
178
179 This instruction replicates its result.
180
181 .. math::
182
183   dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src0.w \times src1.w
184
185
186 .. opcode:: DST - Distance Vector
187
188 .. math::
189
190   dst.x = 1
191
192   dst.y = src0.y \times src1.y
193
194   dst.z = src0.z
195
196   dst.w = src1.w
197
198
199 .. opcode:: MIN - Minimum
200
201 .. math::
202
203   dst.x = min(src0.x, src1.x)
204
205   dst.y = min(src0.y, src1.y)
206
207   dst.z = min(src0.z, src1.z)
208
209   dst.w = min(src0.w, src1.w)
210
211
212 .. opcode:: MAX - Maximum
213
214 .. math::
215
216   dst.x = max(src0.x, src1.x)
217
218   dst.y = max(src0.y, src1.y)
219
220   dst.z = max(src0.z, src1.z)
221
222   dst.w = max(src0.w, src1.w)
223
224
225 .. opcode:: SLT - Set On Less Than
226
227 .. math::
228
229   dst.x = (src0.x < src1.x) ? 1 : 0
230
231   dst.y = (src0.y < src1.y) ? 1 : 0
232
233   dst.z = (src0.z < src1.z) ? 1 : 0
234
235   dst.w = (src0.w < src1.w) ? 1 : 0
236
237
238 .. opcode:: SGE - Set On Greater Equal Than
239
240 .. math::
241
242   dst.x = (src0.x >= src1.x) ? 1 : 0
243
244   dst.y = (src0.y >= src1.y) ? 1 : 0
245
246   dst.z = (src0.z >= src1.z) ? 1 : 0
247
248   dst.w = (src0.w >= src1.w) ? 1 : 0
249
250
251 .. opcode:: MAD - Multiply And Add
252
253 .. math::
254
255   dst.x = src0.x \times src1.x + src2.x
256
257   dst.y = src0.y \times src1.y + src2.y
258
259   dst.z = src0.z \times src1.z + src2.z
260
261   dst.w = src0.w \times src1.w + src2.w
262
263
264 .. opcode:: SUB - Subtract
265
266 .. math::
267
268   dst.x = src0.x - src1.x
269
270   dst.y = src0.y - src1.y
271
272   dst.z = src0.z - src1.z
273
274   dst.w = src0.w - src1.w
275
276
277 .. opcode:: LRP - Linear Interpolate
278
279 .. math::
280
281   dst.x = src0.x \times src1.x + (1 - src0.x) \times src2.x
282
283   dst.y = src0.y \times src1.y + (1 - src0.y) \times src2.y
284
285   dst.z = src0.z \times src1.z + (1 - src0.z) \times src2.z
286
287   dst.w = src0.w \times src1.w + (1 - src0.w) \times src2.w
288
289
290 .. opcode:: CND - Condition
291
292 .. math::
293
294   dst.x = (src2.x > 0.5) ? src0.x : src1.x
295
296   dst.y = (src2.y > 0.5) ? src0.y : src1.y
297
298   dst.z = (src2.z > 0.5) ? src0.z : src1.z
299
300   dst.w = (src2.w > 0.5) ? src0.w : src1.w
301
302
303 .. opcode:: DP2A - 2-component Dot Product And Add
304
305 .. math::
306
307   dst.x = src0.x \times src1.x + src0.y \times src1.y + src2.x
308
309   dst.y = src0.x \times src1.x + src0.y \times src1.y + src2.x
310
311   dst.z = src0.x \times src1.x + src0.y \times src1.y + src2.x
312
313   dst.w = src0.x \times src1.x + src0.y \times src1.y + src2.x
314
315
316 .. opcode:: FRC - Fraction
317
318 .. math::
319
320   dst.x = src.x - \lfloor src.x\rfloor
321
322   dst.y = src.y - \lfloor src.y\rfloor
323
324   dst.z = src.z - \lfloor src.z\rfloor
325
326   dst.w = src.w - \lfloor src.w\rfloor
327
328
329 .. opcode:: CLAMP - Clamp
330
331 .. math::
332
333   dst.x = clamp(src0.x, src1.x, src2.x)
334
335   dst.y = clamp(src0.y, src1.y, src2.y)
336
337   dst.z = clamp(src0.z, src1.z, src2.z)
338
339   dst.w = clamp(src0.w, src1.w, src2.w)
340
341
342 .. opcode:: FLR - Floor
343
344 This is identical to :opcode:`ARL`.
345
346 .. math::
347
348   dst.x = \lfloor src.x\rfloor
349
350   dst.y = \lfloor src.y\rfloor
351
352   dst.z = \lfloor src.z\rfloor
353
354   dst.w = \lfloor src.w\rfloor
355
356
357 .. opcode:: ROUND - Round
358
359 .. math::
360
361   dst.x = round(src.x)
362
363   dst.y = round(src.y)
364
365   dst.z = round(src.z)
366
367   dst.w = round(src.w)
368
369
370 .. opcode:: EX2 - Exponential Base 2
371
372 This instruction replicates its result.
373
374 .. math::
375
376   dst = 2^{src.x}
377
378
379 .. opcode:: LG2 - Logarithm Base 2
380
381 This instruction replicates its result.
382
383 .. math::
384
385   dst = \log_2{src.x}
386
387
388 .. opcode:: POW - Power
389
390 This instruction replicates its result.
391
392 .. math::
393
394   dst = src0.x^{src1.x}
395
396 .. opcode:: XPD - Cross Product
397
398 .. math::
399
400   dst.x = src0.y \times src1.z - src1.y \times src0.z
401
402   dst.y = src0.z \times src1.x - src1.z \times src0.x
403
404   dst.z = src0.x \times src1.y - src1.x \times src0.y
405
406   dst.w = 1
407
408
409 .. opcode:: ABS - Absolute
410
411 .. math::
412
413   dst.x = |src.x|
414
415   dst.y = |src.y|
416
417   dst.z = |src.z|
418
419   dst.w = |src.w|
420
421
422 .. opcode:: RCC - Reciprocal Clamped
423
424 This instruction replicates its result.
425
426 XXX cleanup on aisle three
427
428 .. math::
429
430   dst = (1 / src.x) > 0 ? clamp(1 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1 / src.x, -1.884467e+019, -5.42101e-020)
431
432
433 .. opcode:: DPH - Homogeneous Dot Product
434
435 This instruction replicates its result.
436
437 .. math::
438
439   dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src1.w
440
441
442 .. opcode:: COS - Cosine
443
444 This instruction replicates its result.
445
446 .. math::
447
448   dst = \cos{src.x}
449
450
451 .. opcode:: DDX - Derivative Relative To X
452
453 .. math::
454
455   dst.x = partialx(src.x)
456
457   dst.y = partialx(src.y)
458
459   dst.z = partialx(src.z)
460
461   dst.w = partialx(src.w)
462
463
464 .. opcode:: DDY - Derivative Relative To Y
465
466 .. math::
467
468   dst.x = partialy(src.x)
469
470   dst.y = partialy(src.y)
471
472   dst.z = partialy(src.z)
473
474   dst.w = partialy(src.w)
475
476
477 .. opcode:: KILP - Predicated Discard
478
479   discard
480
481
482 .. opcode:: PK2H - Pack Two 16-bit Floats
483
484   TBD
485
486
487 .. opcode:: PK2US - Pack Two Unsigned 16-bit Scalars
488
489   TBD
490
491
492 .. opcode:: PK4B - Pack Four Signed 8-bit Scalars
493
494   TBD
495
496
497 .. opcode:: PK4UB - Pack Four Unsigned 8-bit Scalars
498
499   TBD
500
501
502 .. opcode:: RFL - Reflection Vector
503
504 .. math::
505
506   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
507
508   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
509
510   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
511
512   dst.w = 1
513
514 .. note::
515
516    Considered for removal.
517
518
519 .. opcode:: SEQ - Set On Equal
520
521 .. math::
522
523   dst.x = (src0.x == src1.x) ? 1 : 0
524
525   dst.y = (src0.y == src1.y) ? 1 : 0
526
527   dst.z = (src0.z == src1.z) ? 1 : 0
528
529   dst.w = (src0.w == src1.w) ? 1 : 0
530
531
532 .. opcode:: SFL - Set On False
533
534 This instruction replicates its result.
535
536 .. math::
537
538   dst = 0
539
540 .. note::
541
542    Considered for removal.
543
544
545 .. opcode:: SGT - Set On Greater Than
546
547 .. math::
548
549   dst.x = (src0.x > src1.x) ? 1 : 0
550
551   dst.y = (src0.y > src1.y) ? 1 : 0
552
553   dst.z = (src0.z > src1.z) ? 1 : 0
554
555   dst.w = (src0.w > src1.w) ? 1 : 0
556
557
558 .. opcode:: SIN - Sine
559
560 This instruction replicates its result.
561
562 .. math::
563
564   dst = \sin{src.x}
565
566
567 .. opcode:: SLE - Set On Less Equal Than
568
569 .. math::
570
571   dst.x = (src0.x <= src1.x) ? 1 : 0
572
573   dst.y = (src0.y <= src1.y) ? 1 : 0
574
575   dst.z = (src0.z <= src1.z) ? 1 : 0
576
577   dst.w = (src0.w <= src1.w) ? 1 : 0
578
579
580 .. opcode:: SNE - Set On Not Equal
581
582 .. math::
583
584   dst.x = (src0.x != src1.x) ? 1 : 0
585
586   dst.y = (src0.y != src1.y) ? 1 : 0
587
588   dst.z = (src0.z != src1.z) ? 1 : 0
589
590   dst.w = (src0.w != src1.w) ? 1 : 0
591
592
593 .. opcode:: STR - Set On True
594
595 This instruction replicates its result.
596
597 .. math::
598
599   dst = 1
600
601
602 .. opcode:: TEX - Texture Lookup
603
604 .. math::
605
606   coord = src0
607
608   bias = 0.0
609
610   dst = texture_sample(unit, coord, bias)
611
612   for array textures src0.y contains the slice for 1D,
613   and src0.z contain the slice for 2D.
614   for shadow textures with no arrays, src0.z contains
615   the reference value.
616   for shadow textures with arrays, src0.z contains
617   the reference value for 1D arrays, and src0.w contains
618   the reference value for 2D arrays.
619   There is no way to pass a bias in the .w value for
620   shadow arrays, and GLSL doesn't allow this.
621   GLSL does allow cube shadows maps to take a bias value,
622   and we have to determine how this will look in TGSI.
623
624 .. opcode:: TXD - Texture Lookup with Derivatives
625
626 .. math::
627
628   coord = src0
629
630   ddx = src1
631
632   ddy = src2
633
634   bias = 0.0
635
636   dst = texture_sample_deriv(unit, coord, bias, ddx, ddy)
637
638
639 .. opcode:: TXP - Projective Texture Lookup
640
641 .. math::
642
643   coord.x = src0.x / src.w
644
645   coord.y = src0.y / src.w
646
647   coord.z = src0.z / src.w
648
649   coord.w = src0.w
650
651   bias = 0.0
652
653   dst = texture_sample(unit, coord, bias)
654
655
656 .. opcode:: UP2H - Unpack Two 16-Bit Floats
657
658   TBD
659
660 .. note::
661
662    Considered for removal.
663
664 .. opcode:: UP2US - Unpack Two Unsigned 16-Bit Scalars
665
666   TBD
667
668 .. note::
669
670    Considered for removal.
671
672 .. opcode:: UP4B - Unpack Four Signed 8-Bit Values
673
674   TBD
675
676 .. note::
677
678    Considered for removal.
679
680 .. opcode:: UP4UB - Unpack Four Unsigned 8-Bit Scalars
681
682   TBD
683
684 .. note::
685
686    Considered for removal.
687
688 .. opcode:: X2D - 2D Coordinate Transformation
689
690 .. math::
691
692   dst.x = src0.x + src1.x \times src2.x + src1.y \times src2.y
693
694   dst.y = src0.y + src1.x \times src2.z + src1.y \times src2.w
695
696   dst.z = src0.x + src1.x \times src2.x + src1.y \times src2.y
697
698   dst.w = src0.y + src1.x \times src2.z + src1.y \times src2.w
699
700 .. note::
701
702    Considered for removal.
703
704
705 .. opcode:: ARA - Address Register Add
706
707   TBD
708
709 .. note::
710
711    Considered for removal.
712
713 .. opcode:: ARR - Address Register Load With Round
714
715 .. math::
716
717   dst.x = round(src.x)
718
719   dst.y = round(src.y)
720
721   dst.z = round(src.z)
722
723   dst.w = round(src.w)
724
725
726 .. opcode:: BRA - Branch
727
728   pc = target
729
730 .. note::
731
732    Considered for removal.
733
734 .. opcode:: CAL - Subroutine Call
735
736   push(pc)
737   pc = target
738
739
740 .. opcode:: RET - Subroutine Call Return
741
742   pc = pop()
743
744
745 .. opcode:: SSG - Set Sign
746
747 .. math::
748
749   dst.x = (src.x > 0) ? 1 : (src.x < 0) ? -1 : 0
750
751   dst.y = (src.y > 0) ? 1 : (src.y < 0) ? -1 : 0
752
753   dst.z = (src.z > 0) ? 1 : (src.z < 0) ? -1 : 0
754
755   dst.w = (src.w > 0) ? 1 : (src.w < 0) ? -1 : 0
756
757
758 .. opcode:: CMP - Compare
759
760 .. math::
761
762   dst.x = (src0.x < 0) ? src1.x : src2.x
763
764   dst.y = (src0.y < 0) ? src1.y : src2.y
765
766   dst.z = (src0.z < 0) ? src1.z : src2.z
767
768   dst.w = (src0.w < 0) ? src1.w : src2.w
769
770
771 .. opcode:: KIL - Conditional Discard
772
773 .. math::
774
775   if (src.x < 0 || src.y < 0 || src.z < 0 || src.w < 0)
776     discard
777   endif
778
779
780 .. opcode:: SCS - Sine Cosine
781
782 .. math::
783
784   dst.x = \cos{src.x}
785
786   dst.y = \sin{src.x}
787
788   dst.z = 0
789
790   dst.w = 1
791
792
793 .. opcode:: TXB - Texture Lookup With Bias
794
795 .. math::
796
797   coord.x = src.x
798
799   coord.y = src.y
800
801   coord.z = src.z
802
803   coord.w = 1.0
804
805   bias = src.z
806
807   dst = texture_sample(unit, coord, bias)
808
809
810 .. opcode:: NRM - 3-component Vector Normalise
811
812 .. math::
813
814   dst.x = src.x / (src.x \times src.x + src.y \times src.y + src.z \times src.z)
815
816   dst.y = src.y / (src.x \times src.x + src.y \times src.y + src.z \times src.z)
817
818   dst.z = src.z / (src.x \times src.x + src.y \times src.y + src.z \times src.z)
819
820   dst.w = 1
821
822
823 .. opcode:: DIV - Divide
824
825 .. math::
826
827   dst.x = \frac{src0.x}{src1.x}
828
829   dst.y = \frac{src0.y}{src1.y}
830
831   dst.z = \frac{src0.z}{src1.z}
832
833   dst.w = \frac{src0.w}{src1.w}
834
835
836 .. opcode:: DP2 - 2-component Dot Product
837
838 This instruction replicates its result.
839
840 .. math::
841
842   dst = src0.x \times src1.x + src0.y \times src1.y
843
844
845 .. opcode:: TXL - Texture Lookup With explicit LOD
846
847 .. math::
848
849   coord.x = src0.x
850
851   coord.y = src0.y
852
853   coord.z = src0.z
854
855   coord.w = 1.0
856
857   lod = src0.w
858
859   dst = texture_sample(unit, coord, lod)
860
861
862 .. opcode:: BRK - Break
863
864   Unconditionally moves the point of execution to the instruction after the
865   next endloop or endswitch. The instruction must appear within a loop/endloop
866   or switch/endswitch.
867
868
869 .. opcode:: BREAKC - Break Conditional
870
871   Conditionally moves the point of execution to the instruction after the
872   next endloop or endswitch. The instruction must appear within a loop/endloop
873   or switch/endswitch.
874   Condition evaluates to true if src0.x != 0 where src0.x is interpreted
875   as an integer register.
876
877
878 .. opcode:: IF - Float If
879
880   Start an IF ... ELSE .. ENDIF block.  Condition evaluates to true if
881
882     src0.x != 0.0
883
884   where src0.x is interpreted as a floating point register.
885
886
887 .. opcode:: UIF - Bitwise If
888
889   Start an UIF ... ELSE .. ENDIF block. Condition evaluates to true if
890
891     src0.x != 0
892
893   where src0.x is interpreted as an integer register.
894
895
896 .. opcode:: ELSE - Else
897
898   Starts an else block, after an IF or UIF statement.
899
900
901 .. opcode:: ENDIF - End If
902
903   Ends an IF or UIF block.
904
905
906 .. opcode:: SWITCH - Switch
907
908    Starts a C-style switch expression. The switch consists of one or multiple
909    CASE statements, and at most one DEFAULT statement. Execution of a statement
910    ends when a BRK is hit, but just like in C falling through to other cases
911    without a break is allowed. Similarly, DEFAULT label is allowed anywhere not
912    just as last statement, and fallthrough is allowed into/from it.
913    CASE src arguments are evaluated at bit level against the SWITCH src argument.
914
915    Example:
916    SWITCH src[0].x
917    CASE src[0].x
918    (some instructions here)
919    (optional BRK here)
920    DEFAULT
921    (some instructions here)
922    (optional BRK here)
923    CASE src[0].x
924    (some instructions here)
925    (optional BRK here)
926    ENDSWITCH
927
928
929 .. opcode:: CASE - Switch case
930
931    This represents a switch case label. The src arg must be an integer immediate.
932
933
934 .. opcode:: DEFAULT - Switch default
935
936    This represents the default case in the switch, which is taken if no other
937    case matches.
938
939
940 .. opcode:: ENDSWITCH - End of switch
941
942    Ends a switch expression.
943
944
945 .. opcode:: PUSHA - Push Address Register On Stack
946
947   push(src.x)
948   push(src.y)
949   push(src.z)
950   push(src.w)
951
952 .. note::
953
954    Considered for cleanup.
955
956 .. note::
957
958    Considered for removal.
959
960 .. opcode:: POPA - Pop Address Register From Stack
961
962   dst.w = pop()
963   dst.z = pop()
964   dst.y = pop()
965   dst.x = pop()
966
967 .. note::
968
969    Considered for cleanup.
970
971 .. note::
972
973    Considered for removal.
974
975
976 Compute ISA
977 ^^^^^^^^^^^^^^^^^^^^^^^^
978
979 These opcodes are primarily provided for special-use computational shaders.
980 Support for these opcodes indicated by a special pipe capability bit (TBD).
981
982 XXX so let's discuss it, yeah?
983
984 .. opcode:: CEIL - Ceiling
985
986 .. math::
987
988   dst.x = \lceil src.x\rceil
989
990   dst.y = \lceil src.y\rceil
991
992   dst.z = \lceil src.z\rceil
993
994   dst.w = \lceil src.w\rceil
995
996
997 .. opcode:: I2F - Integer To Float
998
999 .. math::
1000
1001   dst.x = (float) src.x
1002
1003   dst.y = (float) src.y
1004
1005   dst.z = (float) src.z
1006
1007   dst.w = (float) src.w
1008
1009
1010 .. opcode:: NOT - Bitwise Not
1011
1012 .. math::
1013
1014   dst.x = ~src.x
1015
1016   dst.y = ~src.y
1017
1018   dst.z = ~src.z
1019
1020   dst.w = ~src.w
1021
1022
1023 .. opcode:: TRUNC - Truncate
1024
1025 .. math::
1026
1027   dst.x = trunc(src.x)
1028
1029   dst.y = trunc(src.y)
1030
1031   dst.z = trunc(src.z)
1032
1033   dst.w = trunc(src.w)
1034
1035
1036 .. opcode:: SHL - Shift Left
1037
1038 .. math::
1039
1040   dst.x = src0.x << src1.x
1041
1042   dst.y = src0.y << src1.x
1043
1044   dst.z = src0.z << src1.x
1045
1046   dst.w = src0.w << src1.x
1047
1048
1049 .. opcode:: SHR - Shift Right
1050
1051 .. math::
1052
1053   dst.x = src0.x >> src1.x
1054
1055   dst.y = src0.y >> src1.x
1056
1057   dst.z = src0.z >> src1.x
1058
1059   dst.w = src0.w >> src1.x
1060
1061
1062 .. opcode:: AND - Bitwise And
1063
1064 .. math::
1065
1066   dst.x = src0.x & src1.x
1067
1068   dst.y = src0.y & src1.y
1069
1070   dst.z = src0.z & src1.z
1071
1072   dst.w = src0.w & src1.w
1073
1074
1075 .. opcode:: OR - Bitwise Or
1076
1077 .. math::
1078
1079   dst.x = src0.x | src1.x
1080
1081   dst.y = src0.y | src1.y
1082
1083   dst.z = src0.z | src1.z
1084
1085   dst.w = src0.w | src1.w
1086
1087
1088 .. opcode:: MOD - Modulus
1089
1090 .. math::
1091
1092   dst.x = src0.x \bmod src1.x
1093
1094   dst.y = src0.y \bmod src1.y
1095
1096   dst.z = src0.z \bmod src1.z
1097
1098   dst.w = src0.w \bmod src1.w
1099
1100
1101 .. opcode:: XOR - Bitwise Xor
1102
1103 .. math::
1104
1105   dst.x = src0.x \oplus src1.x
1106
1107   dst.y = src0.y \oplus src1.y
1108
1109   dst.z = src0.z \oplus src1.z
1110
1111   dst.w = src0.w \oplus src1.w
1112
1113
1114 .. opcode:: UCMP - Integer Conditional Move
1115
1116 .. math::
1117
1118   dst.x = src0.x ? src1.x : src2.x
1119
1120   dst.y = src0.y ? src1.y : src2.y
1121
1122   dst.z = src0.z ? src1.z : src2.z
1123
1124   dst.w = src0.w ? src1.w : src2.w
1125
1126
1127 .. opcode:: UARL - Integer Address Register Load
1128
1129   Moves the contents of the source register, assumed to be an integer, into the
1130   destination register, which is assumed to be an address (ADDR) register.
1131
1132
1133 .. opcode:: IABS - Integer Absolute Value
1134
1135 .. math::
1136
1137   dst.x = |src.x|
1138
1139   dst.y = |src.y|
1140
1141   dst.z = |src.z|
1142
1143   dst.w = |src.w|
1144
1145
1146 .. opcode:: SAD - Sum Of Absolute Differences
1147
1148 .. math::
1149
1150   dst.x = |src0.x - src1.x| + src2.x
1151
1152   dst.y = |src0.y - src1.y| + src2.y
1153
1154   dst.z = |src0.z - src1.z| + src2.z
1155
1156   dst.w = |src0.w - src1.w| + src2.w
1157
1158
1159 .. opcode:: TXF - Texel Fetch (as per NV_gpu_shader4), extract a single texel
1160                   from a specified texture image. The source sampler may
1161                   not be a CUBE or SHADOW.
1162                   src 0 is a four-component signed integer vector used to
1163                   identify the single texel accessed. 3 components + level.
1164                   src 1 is a 3 component constant signed integer vector,
1165                   with each component only have a range of
1166                   -8..+8 (hw only seems to deal with this range, interface
1167                   allows for up to unsigned int).
1168                   TXF(uint_vec coord, int_vec offset).
1169
1170
1171 .. opcode:: TXQ - Texture Size Query (as per NV_gpu_program4)
1172                   retrieve the dimensions of the texture
1173                   depending on the target. For 1D (width), 2D/RECT/CUBE
1174                   (width, height), 3D (width, height, depth),
1175                   1D array (width, layers), 2D array (width, height, layers)
1176
1177 .. math::
1178
1179   lod = src0
1180
1181   dst.x = texture_width(unit, lod)
1182
1183   dst.y = texture_height(unit, lod)
1184
1185   dst.z = texture_depth(unit, lod)
1186
1187
1188 .. opcode:: CONT - Continue
1189
1190   TBD
1191
1192 .. note::
1193
1194    Support for CONT is determined by a special capability bit,
1195    ``TGSI_CONT_SUPPORTED``. See :ref:`Screen` for more information.
1196
1197
1198 Geometry ISA
1199 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1200
1201 These opcodes are only supported in geometry shaders; they have no meaning
1202 in any other type of shader.
1203
1204 .. opcode:: EMIT - Emit
1205
1206   TBD
1207
1208
1209 .. opcode:: ENDPRIM - End Primitive
1210
1211   TBD
1212
1213
1214 GLSL ISA
1215 ^^^^^^^^^^
1216
1217 These opcodes are part of :term:`GLSL`'s opcode set. Support for these
1218 opcodes is determined by a special capability bit, ``GLSL``.
1219
1220 .. opcode:: BGNLOOP - Begin a Loop
1221
1222   TBD
1223
1224
1225 .. opcode:: BGNSUB - Begin Subroutine
1226
1227   TBD
1228
1229
1230 .. opcode:: ENDLOOP - End a Loop
1231
1232   TBD
1233
1234
1235 .. opcode:: ENDSUB - End Subroutine
1236
1237   TBD
1238
1239
1240 .. opcode:: NOP - No Operation
1241
1242   Do nothing.
1243
1244
1245 .. opcode:: NRM4 - 4-component Vector Normalise
1246
1247 This instruction replicates its result.
1248
1249 .. math::
1250
1251   dst = \frac{src.x}{src.x \times src.x + src.y \times src.y + src.z \times src.z + src.w \times src.w}
1252
1253
1254 ps_2_x
1255 ^^^^^^^^^^^^
1256
1257 XXX wait what
1258
1259 .. opcode:: CALLNZ - Subroutine Call If Not Zero
1260
1261   TBD
1262
1263 .. _doubleopcodes:
1264
1265 Double ISA
1266 ^^^^^^^^^^^^^^^
1267
1268 The double-precision opcodes reinterpret four-component vectors into
1269 two-component vectors with doubled precision in each component.
1270
1271 Support for these opcodes is XXX undecided. :T
1272
1273 .. opcode:: DADD - Add
1274
1275 .. math::
1276
1277   dst.xy = src0.xy + src1.xy
1278
1279   dst.zw = src0.zw + src1.zw
1280
1281
1282 .. opcode:: DDIV - Divide
1283
1284 .. math::
1285
1286   dst.xy = src0.xy / src1.xy
1287
1288   dst.zw = src0.zw / src1.zw
1289
1290 .. opcode:: DSEQ - Set on Equal
1291
1292 .. math::
1293
1294   dst.xy = src0.xy == src1.xy ? 1.0F : 0.0F
1295
1296   dst.zw = src0.zw == src1.zw ? 1.0F : 0.0F
1297
1298 .. opcode:: DSLT - Set on Less than
1299
1300 .. math::
1301
1302   dst.xy = src0.xy < src1.xy ? 1.0F : 0.0F
1303
1304   dst.zw = src0.zw < src1.zw ? 1.0F : 0.0F
1305
1306 .. opcode:: DFRAC - Fraction
1307
1308 .. math::
1309
1310   dst.xy = src.xy - \lfloor src.xy\rfloor
1311
1312   dst.zw = src.zw - \lfloor src.zw\rfloor
1313
1314
1315 .. opcode:: DFRACEXP - Convert Number to Fractional and Integral Components
1316
1317 Like the ``frexp()`` routine in many math libraries, this opcode stores the
1318 exponent of its source to ``dst0``, and the significand to ``dst1``, such that
1319 :math:`dst1 \times 2^{dst0} = src` .
1320
1321 .. math::
1322
1323   dst0.xy = exp(src.xy)
1324
1325   dst1.xy = frac(src.xy)
1326
1327   dst0.zw = exp(src.zw)
1328
1329   dst1.zw = frac(src.zw)
1330
1331 .. opcode:: DLDEXP - Multiply Number by Integral Power of 2
1332
1333 This opcode is the inverse of :opcode:`DFRACEXP`.
1334
1335 .. math::
1336
1337   dst.xy = src0.xy \times 2^{src1.xy}
1338
1339   dst.zw = src0.zw \times 2^{src1.zw}
1340
1341 .. opcode:: DMIN - Minimum
1342
1343 .. math::
1344
1345   dst.xy = min(src0.xy, src1.xy)
1346
1347   dst.zw = min(src0.zw, src1.zw)
1348
1349 .. opcode:: DMAX - Maximum
1350
1351 .. math::
1352
1353   dst.xy = max(src0.xy, src1.xy)
1354
1355   dst.zw = max(src0.zw, src1.zw)
1356
1357 .. opcode:: DMUL - Multiply
1358
1359 .. math::
1360
1361   dst.xy = src0.xy \times src1.xy
1362
1363   dst.zw = src0.zw \times src1.zw
1364
1365
1366 .. opcode:: DMAD - Multiply And Add
1367
1368 .. math::
1369
1370   dst.xy = src0.xy \times src1.xy + src2.xy
1371
1372   dst.zw = src0.zw \times src1.zw + src2.zw
1373
1374
1375 .. opcode:: DRCP - Reciprocal
1376
1377 .. math::
1378
1379    dst.xy = \frac{1}{src.xy}
1380
1381    dst.zw = \frac{1}{src.zw}
1382
1383 .. opcode:: DSQRT - Square Root
1384
1385 .. math::
1386
1387    dst.xy = \sqrt{src.xy}
1388
1389    dst.zw = \sqrt{src.zw}
1390
1391
1392 .. _samplingopcodes:
1393
1394 Resource Sampling Opcodes
1395 ^^^^^^^^^^^^^^^^^^^^^^^^^
1396
1397 Those opcodes follow very closely semantics of the respective Direct3D
1398 instructions. If in doubt double check Direct3D documentation.
1399
1400 .. opcode:: SAMPLE - Using provided address, sample data from the
1401                specified texture using the filtering mode identified
1402                by the gven sampler. The source data may come from
1403                any resource type other than buffers.
1404                SAMPLE dst, address, sampler_view, sampler
1405                e.g.
1406                SAMPLE TEMP[0], TEMP[1], SVIEW[0], SAMP[0]
1407
1408 .. opcode:: SAMPLE_I - Simplified alternative to the SAMPLE instruction.
1409                Using the provided integer address, SAMPLE_I fetches data
1410                from the specified sampler view without any filtering.
1411                The source data may come from any resource type other
1412                than CUBE.
1413                SAMPLE_I dst, address, sampler_view
1414                e.g.
1415                SAMPLE_I TEMP[0], TEMP[1], SVIEW[0]
1416                The 'address' is specified as unsigned integers. If the
1417                'address' is out of range [0...(# texels - 1)] the
1418                result of the fetch is always 0 in all components.
1419                As such the instruction doesn't honor address wrap
1420                modes, in cases where that behavior is desirable
1421                'SAMPLE' instruction should be used.
1422                address.w always provides an unsigned integer mipmap
1423                level. If the value is out of the range then the
1424                instruction always returns 0 in all components.
1425                address.yz are ignored for buffers and 1d textures.
1426                address.z is ignored for 1d texture arrays and 2d
1427                textures.
1428                For 1D texture arrays address.y provides the array
1429                index (also as unsigned integer). If the value is
1430                out of the range of available array indices
1431                [0... (array size - 1)] then the opcode always returns
1432                0 in all components.
1433                For 2D texture arrays address.z provides the array
1434                index, otherwise it exhibits the same behavior as in
1435                the case for 1D texture arrays.
1436                The exact semantics of the source address are presented
1437                in the table below:
1438                resource type         X     Y     Z       W
1439                -------------         ------------------------
1440                PIPE_BUFFER           x                ignored
1441                PIPE_TEXTURE_1D       x                  mpl
1442                PIPE_TEXTURE_2D       x     y            mpl
1443                PIPE_TEXTURE_3D       x     y     z      mpl
1444                PIPE_TEXTURE_RECT     x     y            mpl
1445                PIPE_TEXTURE_CUBE     not allowed as source
1446                PIPE_TEXTURE_1D_ARRAY x    idx           mpl
1447                PIPE_TEXTURE_2D_ARRAY x     y    idx     mpl
1448
1449                Where 'mpl' is a mipmap level and 'idx' is the
1450                array index.
1451
1452 .. opcode:: SAMPLE_I_MS - Just like SAMPLE_I but allows fetch data from
1453                multi-sampled surfaces.
1454                SAMPLE_I_MS dst, address, sampler_view, sample
1455
1456 .. opcode:: SAMPLE_B - Just like the SAMPLE instruction with the
1457                exception that an additional bias is applied to the
1458                level of detail computed as part of the instruction
1459                execution.
1460                SAMPLE_B dst, address, sampler_view, sampler, lod_bias
1461                e.g.
1462                SAMPLE_B TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2].x
1463
1464 .. opcode:: SAMPLE_C - Similar to the SAMPLE instruction but it
1465                performs a comparison filter. The operands to SAMPLE_C
1466                are identical to SAMPLE, except that there is an additional
1467                float32 operand, reference value, which must be a register
1468                with single-component, or a scalar literal.
1469                SAMPLE_C makes the hardware use the current samplers
1470                compare_func (in pipe_sampler_state) to compare
1471                reference value against the red component value for the
1472                surce resource at each texel that the currently configured
1473                texture filter covers based on the provided coordinates.
1474                SAMPLE_C dst, address, sampler_view.r, sampler, ref_value
1475                e.g.
1476                SAMPLE_C TEMP[0], TEMP[1], SVIEW[0].r, SAMP[0], TEMP[2].x
1477
1478 .. opcode:: SAMPLE_C_LZ - Same as SAMPLE_C, but LOD is 0 and derivatives
1479                are ignored. The LZ stands for level-zero.
1480                SAMPLE_C_LZ dst, address, sampler_view.r, sampler, ref_value
1481                e.g.
1482                SAMPLE_C_LZ TEMP[0], TEMP[1], SVIEW[0].r, SAMP[0], TEMP[2].x
1483
1484
1485 .. opcode:: SAMPLE_D - SAMPLE_D is identical to the SAMPLE opcode except
1486                that the derivatives for the source address in the x
1487                direction and the y direction are provided by extra
1488                parameters.
1489                SAMPLE_D dst, address, sampler_view, sampler, der_x, der_y
1490                e.g.
1491                SAMPLE_D TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2], TEMP[3]
1492
1493 .. opcode:: SAMPLE_L - SAMPLE_L is identical to the SAMPLE opcode except
1494                that the LOD is provided directly as a scalar value,
1495                representing no anisotropy.
1496                SAMPLE_L dst, address, sampler_view, sampler, explicit_lod
1497                e.g.
1498                SAMPLE_L TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2].x
1499
1500 .. opcode:: GATHER4 - Gathers the four texels to be used in a bi-linear
1501                filtering operation and packs them into a single register.
1502                Only works with 2D, 2D array, cubemaps, and cubemaps arrays.
1503                For 2D textures, only the addressing modes of the sampler and
1504                the top level of any mip pyramid are used. Set W to zero.
1505                It behaves like the SAMPLE instruction, but a filtered
1506                sample is not generated. The four samples that contribute
1507                to filtering are placed into xyzw in counter-clockwise order,
1508                starting with the (u,v) texture coordinate delta at the
1509                following locations (-, +), (+, +), (+, -), (-, -), where
1510                the magnitude of the deltas are half a texel.
1511
1512
1513 .. opcode:: SVIEWINFO - query the dimensions of a given sampler view.
1514                dst receives width, height, depth or array size and
1515                number of mipmap levels as int4. The dst can have a writemask
1516                which will specify what info is the caller interested
1517                in.
1518                SVIEWINFO dst, src_mip_level, sampler_view
1519                e.g.
1520                SVIEWINFO TEMP[0], TEMP[1].x, SVIEW[0]
1521                src_mip_level is an unsigned integer scalar. If it's
1522                out of range then returns 0 for width, height and
1523                depth/array size but the total number of mipmap is
1524                still returned correctly for the given sampler view.
1525                The returned width, height and depth values are for
1526                the mipmap level selected by the src_mip_level and
1527                are in the number of texels.
1528                For 1d texture array width is in dst.x, array size
1529                is in dst.y and dst.zw are always 0.
1530
1531 .. opcode:: SAMPLE_POS - query the position of a given sample.
1532                dst receives float4 (x, y, 0, 0) indicated where the
1533                sample is located. If the resource is not a multi-sample
1534                resource and not a render target, the result is 0.
1535
1536 .. opcode:: SAMPLE_INFO - dst receives number of samples in x.
1537                If the resource is not a multi-sample resource and
1538                not a render target, the result is 0.
1539
1540
1541 .. _resourceopcodes:
1542
1543 Resource Access Opcodes
1544 ^^^^^^^^^^^^^^^^^^^^^^^
1545
1546 .. opcode:: LOAD - Fetch data from a shader resource
1547
1548                Syntax: ``LOAD dst, resource, address``
1549
1550                Example: ``LOAD TEMP[0], RES[0], TEMP[1]``
1551
1552                Using the provided integer address, LOAD fetches data
1553                from the specified buffer or texture without any
1554                filtering.
1555
1556                The 'address' is specified as a vector of unsigned
1557                integers.  If the 'address' is out of range the result
1558                is unspecified.
1559
1560                Only the first mipmap level of a resource can be read
1561                from using this instruction.
1562
1563                For 1D or 2D texture arrays, the array index is
1564                provided as an unsigned integer in address.y or
1565                address.z, respectively.  address.yz are ignored for
1566                buffers and 1D textures.  address.z is ignored for 1D
1567                texture arrays and 2D textures.  address.w is always
1568                ignored.
1569
1570 .. opcode:: STORE - Write data to a shader resource
1571
1572                Syntax: ``STORE resource, address, src``
1573
1574                Example: ``STORE RES[0], TEMP[0], TEMP[1]``
1575
1576                Using the provided integer address, STORE writes data
1577                to the specified buffer or texture.
1578
1579                The 'address' is specified as a vector of unsigned
1580                integers.  If the 'address' is out of range the result
1581                is unspecified.
1582
1583                Only the first mipmap level of a resource can be
1584                written to using this instruction.
1585
1586                For 1D or 2D texture arrays, the array index is
1587                provided as an unsigned integer in address.y or
1588                address.z, respectively.  address.yz are ignored for
1589                buffers and 1D textures.  address.z is ignored for 1D
1590                texture arrays and 2D textures.  address.w is always
1591                ignored.
1592
1593
1594 .. _threadsyncopcodes:
1595
1596 Inter-thread synchronization opcodes
1597 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1598
1599 These opcodes are intended for communication between threads running
1600 within the same compute grid.  For now they're only valid in compute
1601 programs.
1602
1603 .. opcode:: MFENCE - Memory fence
1604
1605   Syntax: ``MFENCE resource``
1606
1607   Example: ``MFENCE RES[0]``
1608
1609   This opcode forces strong ordering between any memory access
1610   operations that affect the specified resource.  This means that
1611   previous loads and stores (and only those) will be performed and
1612   visible to other threads before the program execution continues.
1613
1614
1615 .. opcode:: LFENCE - Load memory fence
1616
1617   Syntax: ``LFENCE resource``
1618
1619   Example: ``LFENCE RES[0]``
1620
1621   Similar to MFENCE, but it only affects the ordering of memory loads.
1622
1623
1624 .. opcode:: SFENCE - Store memory fence
1625
1626   Syntax: ``SFENCE resource``
1627
1628   Example: ``SFENCE RES[0]``
1629
1630   Similar to MFENCE, but it only affects the ordering of memory stores.
1631
1632
1633 .. opcode:: BARRIER - Thread group barrier
1634
1635   ``BARRIER``
1636
1637   This opcode suspends the execution of the current thread until all
1638   the remaining threads in the working group reach the same point of
1639   the program.  Results are unspecified if any of the remaining
1640   threads terminates or never reaches an executed BARRIER instruction.
1641
1642
1643 .. _atomopcodes:
1644
1645 Atomic opcodes
1646 ^^^^^^^^^^^^^^
1647
1648 These opcodes provide atomic variants of some common arithmetic and
1649 logical operations.  In this context atomicity means that another
1650 concurrent memory access operation that affects the same memory
1651 location is guaranteed to be performed strictly before or after the
1652 entire execution of the atomic operation.
1653
1654 For the moment they're only valid in compute programs.
1655
1656 .. opcode:: ATOMUADD - Atomic integer addition
1657
1658   Syntax: ``ATOMUADD dst, resource, offset, src``
1659
1660   Example: ``ATOMUADD TEMP[0], RES[0], TEMP[1], TEMP[2]``
1661
1662   The following operation is performed atomically on each component:
1663
1664 .. math::
1665
1666   dst_i = resource[offset]_i
1667
1668   resource[offset]_i = dst_i + src_i
1669
1670
1671 .. opcode:: ATOMXCHG - Atomic exchange
1672
1673   Syntax: ``ATOMXCHG dst, resource, offset, src``
1674
1675   Example: ``ATOMXCHG TEMP[0], RES[0], TEMP[1], TEMP[2]``
1676
1677   The following operation is performed atomically on each component:
1678
1679 .. math::
1680
1681   dst_i = resource[offset]_i
1682
1683   resource[offset]_i = src_i
1684
1685
1686 .. opcode:: ATOMCAS - Atomic compare-and-exchange
1687
1688   Syntax: ``ATOMCAS dst, resource, offset, cmp, src``
1689
1690   Example: ``ATOMCAS TEMP[0], RES[0], TEMP[1], TEMP[2], TEMP[3]``
1691
1692   The following operation is performed atomically on each component:
1693
1694 .. math::
1695
1696   dst_i = resource[offset]_i
1697
1698   resource[offset]_i = (dst_i == cmp_i ? src_i : dst_i)
1699
1700
1701 .. opcode:: ATOMAND - Atomic bitwise And
1702
1703   Syntax: ``ATOMAND dst, resource, offset, src``
1704
1705   Example: ``ATOMAND TEMP[0], RES[0], TEMP[1], TEMP[2]``
1706
1707   The following operation is performed atomically on each component:
1708
1709 .. math::
1710
1711   dst_i = resource[offset]_i
1712
1713   resource[offset]_i = dst_i \& src_i
1714
1715
1716 .. opcode:: ATOMOR - Atomic bitwise Or
1717
1718   Syntax: ``ATOMOR dst, resource, offset, src``
1719
1720   Example: ``ATOMOR TEMP[0], RES[0], TEMP[1], TEMP[2]``
1721
1722   The following operation is performed atomically on each component:
1723
1724 .. math::
1725
1726   dst_i = resource[offset]_i
1727
1728   resource[offset]_i = dst_i | src_i
1729
1730
1731 .. opcode:: ATOMXOR - Atomic bitwise Xor
1732
1733   Syntax: ``ATOMXOR dst, resource, offset, src``
1734
1735   Example: ``ATOMXOR TEMP[0], RES[0], TEMP[1], TEMP[2]``
1736
1737   The following operation is performed atomically on each component:
1738
1739 .. math::
1740
1741   dst_i = resource[offset]_i
1742
1743   resource[offset]_i = dst_i \oplus src_i
1744
1745
1746 .. opcode:: ATOMUMIN - Atomic unsigned minimum
1747
1748   Syntax: ``ATOMUMIN dst, resource, offset, src``
1749
1750   Example: ``ATOMUMIN TEMP[0], RES[0], TEMP[1], TEMP[2]``
1751
1752   The following operation is performed atomically on each component:
1753
1754 .. math::
1755
1756   dst_i = resource[offset]_i
1757
1758   resource[offset]_i = (dst_i < src_i ? dst_i : src_i)
1759
1760
1761 .. opcode:: ATOMUMAX - Atomic unsigned maximum
1762
1763   Syntax: ``ATOMUMAX dst, resource, offset, src``
1764
1765   Example: ``ATOMUMAX TEMP[0], RES[0], TEMP[1], TEMP[2]``
1766
1767   The following operation is performed atomically on each component:
1768
1769 .. math::
1770
1771   dst_i = resource[offset]_i
1772
1773   resource[offset]_i = (dst_i > src_i ? dst_i : src_i)
1774
1775
1776 .. opcode:: ATOMIMIN - Atomic signed minimum
1777
1778   Syntax: ``ATOMIMIN dst, resource, offset, src``
1779
1780   Example: ``ATOMIMIN TEMP[0], RES[0], TEMP[1], TEMP[2]``
1781
1782   The following operation is performed atomically on each component:
1783
1784 .. math::
1785
1786   dst_i = resource[offset]_i
1787
1788   resource[offset]_i = (dst_i < src_i ? dst_i : src_i)
1789
1790
1791 .. opcode:: ATOMIMAX - Atomic signed maximum
1792
1793   Syntax: ``ATOMIMAX dst, resource, offset, src``
1794
1795   Example: ``ATOMIMAX TEMP[0], RES[0], TEMP[1], TEMP[2]``
1796
1797   The following operation is performed atomically on each component:
1798
1799 .. math::
1800
1801   dst_i = resource[offset]_i
1802
1803   resource[offset]_i = (dst_i > src_i ? dst_i : src_i)
1804
1805
1806
1807 Explanation of symbols used
1808 ------------------------------
1809
1810
1811 Functions
1812 ^^^^^^^^^^^^^^
1813
1814
1815   :math:`|x|`       Absolute value of `x`.
1816
1817   :math:`\lceil x \rceil` Ceiling of `x`.
1818
1819   clamp(x,y,z)      Clamp x between y and z.
1820                     (x < y) ? y : (x > z) ? z : x
1821
1822   :math:`\lfloor x\rfloor` Floor of `x`.
1823
1824   :math:`\log_2{x}` Logarithm of `x`, base 2.
1825
1826   max(x,y)          Maximum of x and y.
1827                     (x > y) ? x : y
1828
1829   min(x,y)          Minimum of x and y.
1830                     (x < y) ? x : y
1831
1832   partialx(x)       Derivative of x relative to fragment's X.
1833
1834   partialy(x)       Derivative of x relative to fragment's Y.
1835
1836   pop()             Pop from stack.
1837
1838   :math:`x^y`       `x` to the power `y`.
1839
1840   push(x)           Push x on stack.
1841
1842   round(x)          Round x.
1843
1844   trunc(x)          Truncate x, i.e. drop the fraction bits.
1845
1846
1847 Keywords
1848 ^^^^^^^^^^^^^
1849
1850
1851   discard           Discard fragment.
1852
1853   pc                Program counter.
1854
1855   target            Label of target instruction.
1856
1857
1858 Other tokens
1859 ---------------
1860
1861
1862 Declaration
1863 ^^^^^^^^^^^
1864
1865
1866 Declares a register that is will be referenced as an operand in Instruction
1867 tokens.
1868
1869 File field contains register file that is being declared and is one
1870 of TGSI_FILE.
1871
1872 UsageMask field specifies which of the register components can be accessed
1873 and is one of TGSI_WRITEMASK.
1874
1875 The Local flag specifies that a given value isn't intended for
1876 subroutine parameter passing and, as a result, the implementation
1877 isn't required to give any guarantees of it being preserved across
1878 subroutine boundaries.  As it's merely a compiler hint, the
1879 implementation is free to ignore it.
1880
1881 If Dimension flag is set to 1, a Declaration Dimension token follows.
1882
1883 If Semantic flag is set to 1, a Declaration Semantic token follows.
1884
1885 If Interpolate flag is set to 1, a Declaration Interpolate token follows.
1886
1887 If file is TGSI_FILE_RESOURCE, a Declaration Resource token follows.
1888
1889 If Array flag is set to 1, a Declaration Array token follows.
1890
1891 Array Declaration
1892 ^^^^^^^^^^^^^^^^^^^^^^^^
1893
1894 Declarations can optional have an ArrayID attribute which can be referred by
1895 indirect addressing operands. An ArrayID of zero is reserved and treaded as
1896 if no ArrayID is specified.
1897
1898 If an indirect addressing operand refers to a specific declaration by using
1899 an ArrayID only the registers in this declaration are guaranteed to be
1900 accessed, accessing any register outside this declaration results in undefined
1901 behavior. Note that for compatibility the effective index is zero-based and
1902 not relative to the specified declaration
1903
1904 If no ArrayID is specified with an indirect addressing operand the whole
1905 register file might be accessed by this operand. This is strongly discouraged
1906 and will prevent packing of scalar/vec2 arrays and effective alias analysis.
1907
1908 Declaration Semantic
1909 ^^^^^^^^^^^^^^^^^^^^^^^^
1910
1911   Vertex and fragment shader input and output registers may be labeled
1912   with semantic information consisting of a name and index.
1913
1914   Follows Declaration token if Semantic bit is set.
1915
1916   Since its purpose is to link a shader with other stages of the pipeline,
1917   it is valid to follow only those Declaration tokens that declare a register
1918   either in INPUT or OUTPUT file.
1919
1920   SemanticName field contains the semantic name of the register being declared.
1921   There is no default value.
1922
1923   SemanticIndex is an optional subscript that can be used to distinguish
1924   different register declarations with the same semantic name. The default value
1925   is 0.
1926
1927   The meanings of the individual semantic names are explained in the following
1928   sections.
1929
1930 TGSI_SEMANTIC_POSITION
1931 """"""""""""""""""""""
1932
1933 For vertex shaders, TGSI_SEMANTIC_POSITION indicates the vertex shader
1934 output register which contains the homogeneous vertex position in the clip
1935 space coordinate system.  After clipping, the X, Y and Z components of the
1936 vertex will be divided by the W value to get normalized device coordinates.
1937
1938 For fragment shaders, TGSI_SEMANTIC_POSITION is used to indicate that
1939 fragment shader input contains the fragment's window position.  The X
1940 component starts at zero and always increases from left to right.
1941 The Y component starts at zero and always increases but Y=0 may either
1942 indicate the top of the window or the bottom depending on the fragment
1943 coordinate origin convention (see TGSI_PROPERTY_FS_COORD_ORIGIN).
1944 The Z coordinate ranges from 0 to 1 to represent depth from the front
1945 to the back of the Z buffer.  The W component contains the reciprocol
1946 of the interpolated vertex position W component.
1947
1948 Fragment shaders may also declare an output register with
1949 TGSI_SEMANTIC_POSITION.  Only the Z component is writable.  This allows
1950 the fragment shader to change the fragment's Z position.
1951
1952
1953
1954 TGSI_SEMANTIC_COLOR
1955 """""""""""""""""""
1956
1957 For vertex shader outputs or fragment shader inputs/outputs, this
1958 label indicates that the resister contains an R,G,B,A color.
1959
1960 Several shader inputs/outputs may contain colors so the semantic index
1961 is used to distinguish them.  For example, color[0] may be the diffuse
1962 color while color[1] may be the specular color.
1963
1964 This label is needed so that the flat/smooth shading can be applied
1965 to the right interpolants during rasterization.
1966
1967
1968
1969 TGSI_SEMANTIC_BCOLOR
1970 """"""""""""""""""""
1971
1972 Back-facing colors are only used for back-facing polygons, and are only valid
1973 in vertex shader outputs. After rasterization, all polygons are front-facing
1974 and COLOR and BCOLOR end up occupying the same slots in the fragment shader,
1975 so all BCOLORs effectively become regular COLORs in the fragment shader.
1976
1977
1978 TGSI_SEMANTIC_FOG
1979 """""""""""""""""
1980
1981 Vertex shader inputs and outputs and fragment shader inputs may be
1982 labeled with TGSI_SEMANTIC_FOG to indicate that the register contains
1983 a fog coordinate in the form (F, 0, 0, 1).  Typically, the fragment
1984 shader will use the fog coordinate to compute a fog blend factor which
1985 is used to blend the normal fragment color with a constant fog color.
1986
1987 Only the first component matters when writing from the vertex shader;
1988 the driver will ensure that the coordinate is in this format when used
1989 as a fragment shader input.
1990
1991
1992 TGSI_SEMANTIC_PSIZE
1993 """""""""""""""""""
1994
1995 Vertex shader input and output registers may be labeled with
1996 TGIS_SEMANTIC_PSIZE to indicate that the register contains a point size
1997 in the form (S, 0, 0, 1).  The point size controls the width or diameter
1998 of points for rasterization.  This label cannot be used in fragment
1999 shaders.
2000
2001 When using this semantic, be sure to set the appropriate state in the
2002 :ref:`rasterizer` first.
2003
2004
2005 TGSI_SEMANTIC_TEXCOORD
2006 """"""""""""""""""""""
2007
2008 Only available if PIPE_CAP_TGSI_TEXCOORD is exposed !
2009
2010 Vertex shader outputs and fragment shader inputs may be labeled with
2011 this semantic to make them replaceable by sprite coordinates via the
2012 sprite_coord_enable state in the :ref:`rasterizer`.
2013 The semantic index permitted with this semantic is limited to <= 7.
2014
2015 If the driver does not support TEXCOORD, sprite coordinate replacement
2016 applies to inputs with the GENERIC semantic instead.
2017
2018 The intended use case for this semantic is gl_TexCoord.
2019
2020
2021 TGSI_SEMANTIC_PCOORD
2022 """"""""""""""""""""
2023
2024 Only available if PIPE_CAP_TGSI_TEXCOORD is exposed !
2025
2026 Fragment shader inputs may be labeled with TGSI_SEMANTIC_PCOORD to indicate
2027 that the register contains sprite coordinates in the form (x, y, 0, 1), if
2028 the current primitive is a point and point sprites are enabled. Otherwise,
2029 the contents of the register are undefined.
2030
2031 The intended use case for this semantic is gl_PointCoord.
2032
2033
2034 TGSI_SEMANTIC_GENERIC
2035 """""""""""""""""""""
2036
2037 All vertex/fragment shader inputs/outputs not labeled with any other
2038 semantic label can be considered to be generic attributes.  Typical
2039 uses of generic inputs/outputs are texcoords and user-defined values.
2040
2041
2042 TGSI_SEMANTIC_NORMAL
2043 """"""""""""""""""""
2044
2045 Indicates that a vertex shader input is a normal vector.  This is
2046 typically only used for legacy graphics APIs.
2047
2048
2049 TGSI_SEMANTIC_FACE
2050 """"""""""""""""""
2051
2052 This label applies to fragment shader inputs only and indicates that
2053 the register contains front/back-face information of the form (F, 0,
2054 0, 1).  The first component will be positive when the fragment belongs
2055 to a front-facing polygon, and negative when the fragment belongs to a
2056 back-facing polygon.
2057
2058
2059 TGSI_SEMANTIC_EDGEFLAG
2060 """"""""""""""""""""""
2061
2062 For vertex shaders, this sematic label indicates that an input or
2063 output is a boolean edge flag.  The register layout is [F, x, x, x]
2064 where F is 0.0 or 1.0 and x = don't care.  Normally, the vertex shader
2065 simply copies the edge flag input to the edgeflag output.
2066
2067 Edge flags are used to control which lines or points are actually
2068 drawn when the polygon mode converts triangles/quads/polygons into
2069 points or lines.
2070
2071 TGSI_SEMANTIC_STENCIL
2072 """"""""""""""""""""""
2073
2074 For fragment shaders, this semantic label indicates than an output
2075 is a writable stencil reference value. Only the Y component is writable.
2076 This allows the fragment shader to change the fragments stencilref value.
2077
2078
2079 Declaration Interpolate
2080 ^^^^^^^^^^^^^^^^^^^^^^^
2081
2082 This token is only valid for fragment shader INPUT declarations.
2083
2084 The Interpolate field specifes the way input is being interpolated by
2085 the rasteriser and is one of TGSI_INTERPOLATE_*.
2086
2087 The CylindricalWrap bitfield specifies which register components
2088 should be subject to cylindrical wrapping when interpolating by the
2089 rasteriser. If TGSI_CYLINDRICAL_WRAP_X is set to 1, the X component
2090 should be interpolated according to cylindrical wrapping rules.
2091
2092
2093 Declaration Sampler View
2094 ^^^^^^^^^^^^^^^^^^^^^^^^
2095
2096    Follows Declaration token if file is TGSI_FILE_SAMPLER_VIEW.
2097
2098    DCL SVIEW[#], resource, type(s)
2099
2100    Declares a shader input sampler view and assigns it to a SVIEW[#]
2101    register.
2102
2103    resource can be one of BUFFER, 1D, 2D, 3D, 1DArray and 2DArray.
2104
2105    type must be 1 or 4 entries (if specifying on a per-component
2106    level) out of UNORM, SNORM, SINT, UINT and FLOAT.
2107
2108
2109 Declaration Resource
2110 ^^^^^^^^^^^^^^^^^^^^
2111
2112    Follows Declaration token if file is TGSI_FILE_RESOURCE.
2113
2114    DCL RES[#], resource [, WR] [, RAW]
2115
2116    Declares a shader input resource and assigns it to a RES[#]
2117    register.
2118
2119    resource can be one of BUFFER, 1D, 2D, 3D, CUBE, 1DArray and
2120    2DArray.
2121
2122    If the RAW keyword is not specified, the texture data will be
2123    subject to conversion, swizzling and scaling as required to yield
2124    the specified data type from the physical data format of the bound
2125    resource.
2126
2127    If the RAW keyword is specified, no channel conversion will be
2128    performed: the values read for each of the channels (X,Y,Z,W) will
2129    correspond to consecutive words in the same order and format
2130    they're found in memory.  No element-to-address conversion will be
2131    performed either: the value of the provided X coordinate will be
2132    interpreted in byte units instead of texel units.  The result of
2133    accessing a misaligned address is undefined.
2134
2135    Usage of the STORE opcode is only allowed if the WR (writable) flag
2136    is set.
2137
2138
2139 Properties
2140 ^^^^^^^^^^^^^^^^^^^^^^^^
2141
2142
2143   Properties are general directives that apply to the whole TGSI program.
2144
2145 FS_COORD_ORIGIN
2146 """""""""""""""
2147
2148 Specifies the fragment shader TGSI_SEMANTIC_POSITION coordinate origin.
2149 The default value is UPPER_LEFT.
2150
2151 If UPPER_LEFT, the position will be (0,0) at the upper left corner and
2152 increase downward and rightward.
2153 If LOWER_LEFT, the position will be (0,0) at the lower left corner and
2154 increase upward and rightward.
2155
2156 OpenGL defaults to LOWER_LEFT, and is configurable with the
2157 GL_ARB_fragment_coord_conventions extension.
2158
2159 DirectX 9/10 use UPPER_LEFT.
2160
2161 FS_COORD_PIXEL_CENTER
2162 """""""""""""""""""""
2163
2164 Specifies the fragment shader TGSI_SEMANTIC_POSITION pixel center convention.
2165 The default value is HALF_INTEGER.
2166
2167 If HALF_INTEGER, the fractionary part of the position will be 0.5
2168 If INTEGER, the fractionary part of the position will be 0.0
2169
2170 Note that this does not affect the set of fragments generated by
2171 rasterization, which is instead controlled by half_pixel_center in the
2172 rasterizer.
2173
2174 OpenGL defaults to HALF_INTEGER, and is configurable with the
2175 GL_ARB_fragment_coord_conventions extension.
2176
2177 DirectX 9 uses INTEGER.
2178 DirectX 10 uses HALF_INTEGER.
2179
2180 FS_COLOR0_WRITES_ALL_CBUFS
2181 """"""""""""""""""""""""""
2182 Specifies that writes to the fragment shader color 0 are replicated to all
2183 bound cbufs. This facilitates OpenGL's fragColor output vs fragData[0] where
2184 fragData is directed to a single color buffer, but fragColor is broadcast.
2185
2186 VS_PROHIBIT_UCPS
2187 """"""""""""""""""""""""""
2188 If this property is set on the program bound to the shader stage before the
2189 fragment shader, user clip planes should have no effect (be disabled) even if
2190 that shader does not write to any clip distance outputs and the rasterizer's
2191 clip_plane_enable is non-zero.
2192 This property is only supported by drivers that also support shader clip
2193 distance outputs.
2194 This is useful for APIs that don't have UCPs and where clip distances written
2195 by a shader cannot be disabled.
2196
2197
2198 Texture Sampling and Texture Formats
2199 ------------------------------------
2200
2201 This table shows how texture image components are returned as (x,y,z,w) tuples
2202 by TGSI texture instructions, such as :opcode:`TEX`, :opcode:`TXD`, and
2203 :opcode:`TXP`. For reference, OpenGL and Direct3D conventions are shown as
2204 well.
2205
2206 +--------------------+--------------+--------------------+--------------+
2207 | Texture Components | Gallium      | OpenGL             | Direct3D 9   |
2208 +====================+==============+====================+==============+
2209 | R                  | (r, 0, 0, 1) | (r, 0, 0, 1)       | (r, 1, 1, 1) |
2210 +--------------------+--------------+--------------------+--------------+
2211 | RG                 | (r, g, 0, 1) | (r, g, 0, 1)       | (r, g, 1, 1) |
2212 +--------------------+--------------+--------------------+--------------+
2213 | RGB                | (r, g, b, 1) | (r, g, b, 1)       | (r, g, b, 1) |
2214 +--------------------+--------------+--------------------+--------------+
2215 | RGBA               | (r, g, b, a) | (r, g, b, a)       | (r, g, b, a) |
2216 +--------------------+--------------+--------------------+--------------+
2217 | A                  | (0, 0, 0, a) | (0, 0, 0, a)       | (0, 0, 0, a) |
2218 +--------------------+--------------+--------------------+--------------+
2219 | L                  | (l, l, l, 1) | (l, l, l, 1)       | (l, l, l, 1) |
2220 +--------------------+--------------+--------------------+--------------+
2221 | LA                 | (l, l, l, a) | (l, l, l, a)       | (l, l, l, a) |
2222 +--------------------+--------------+--------------------+--------------+
2223 | I                  | (i, i, i, i) | (i, i, i, i)       | N/A          |
2224 +--------------------+--------------+--------------------+--------------+
2225 | UV                 | XXX TBD      | (0, 0, 0, 1)       | (u, v, 1, 1) |
2226 |                    |              | [#envmap-bumpmap]_ |              |
2227 +--------------------+--------------+--------------------+--------------+
2228 | Z                  | XXX TBD      | (z, z, z, 1)       | (0, z, 0, 1) |
2229 |                    |              | [#depth-tex-mode]_ |              |
2230 +--------------------+--------------+--------------------+--------------+
2231 | S                  | (s, s, s, s) | unknown            | unknown      |
2232 +--------------------+--------------+--------------------+--------------+
2233
2234 .. [#envmap-bumpmap] http://www.opengl.org/registry/specs/ATI/envmap_bumpmap.txt
2235 .. [#depth-tex-mode] the default is (z, z, z, 1) but may also be (0, 0, 0, z)
2236    or (z, z, z, z) depending on the value of GL_DEPTH_TEXTURE_MODE.