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