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