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