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