gallium: Remove TGSI_SEMANTIC_NORMAL.
[mesa/mesa-lb.git] / src / gallium / docs / source / tgsi.rst
blobd5e022000fa2c7b5ff4aeb89f1668ee158536388
1 TGSI
2 ====
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.
9 Basics
10 ------
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.
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`.
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.
26 Instruction Set
27 ---------------
29 From GL_NV_vertex_program
30 ^^^^^^^^^^^^^^^^^^^^^^^^^
33 .. opcode:: ARL - Address Register Load
35 .. math::
37   dst.x = \lfloor src.x\rfloor
39   dst.y = \lfloor src.y\rfloor
41   dst.z = \lfloor src.z\rfloor
43   dst.w = \lfloor src.w\rfloor
46 .. opcode:: MOV - Move
48 .. math::
50   dst.x = src.x
52   dst.y = src.y
54   dst.z = src.z
56   dst.w = src.w
59 .. opcode:: LIT - Light Coefficients
61 .. math::
63   dst.x = 1
65   dst.y = max(src.x, 0)
67   dst.z = (src.x > 0) ? max(src.y, 0)^{clamp(src.w, -128, 128))} : 0
69   dst.w = 1
72 .. opcode:: RCP - Reciprocal
74 This instruction replicates its result.
76 .. math::
78   dst = \frac{1}{src.x}
81 .. opcode:: RSQ - Reciprocal Square Root
83 This instruction replicates its result.
85 .. math::
87   dst = \frac{1}{\sqrt{|src.x|}}
90 .. opcode:: EXP - Approximate Exponential Base 2
92 .. math::
94   dst.x = 2^{\lfloor src.x\rfloor}
96   dst.y = src.x - \lfloor src.x\rfloor
98   dst.z = 2^{src.x}
100   dst.w = 1
103 .. opcode:: LOG - Approximate Logarithm Base 2
105 .. math::
107   dst.x = \lfloor\log_2{|src.x|}\rfloor
109   dst.y = \frac{|src.x|}{2^{\lfloor\log_2{|src.x|}\rfloor}}
111   dst.z = \log_2{|src.x|}
113   dst.w = 1
116 .. opcode:: MUL - Multiply
118 .. math::
120   dst.x = src0.x \times src1.x
122   dst.y = src0.y \times src1.y
124   dst.z = src0.z \times src1.z
126   dst.w = src0.w \times src1.w
129 .. opcode:: ADD - Add
131 .. math::
133   dst.x = src0.x + src1.x
135   dst.y = src0.y + src1.y
137   dst.z = src0.z + src1.z
139   dst.w = src0.w + src1.w
142 .. opcode:: DP3 - 3-component Dot Product
144 This instruction replicates its result.
146 .. math::
148   dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z
151 .. opcode:: DP4 - 4-component Dot Product
153 This instruction replicates its result.
155 .. math::
157   dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src0.w \times src1.w
160 .. opcode:: DST - Distance Vector
162 .. math::
164   dst.x = 1
166   dst.y = src0.y \times src1.y
168   dst.z = src0.z
170   dst.w = src1.w
173 .. opcode:: MIN - Minimum
175 .. math::
177   dst.x = min(src0.x, src1.x)
179   dst.y = min(src0.y, src1.y)
181   dst.z = min(src0.z, src1.z)
183   dst.w = min(src0.w, src1.w)
186 .. opcode:: MAX - Maximum
188 .. math::
190   dst.x = max(src0.x, src1.x)
192   dst.y = max(src0.y, src1.y)
194   dst.z = max(src0.z, src1.z)
196   dst.w = max(src0.w, src1.w)
199 .. opcode:: SLT - Set On Less Than
201 .. math::
203   dst.x = (src0.x < src1.x) ? 1 : 0
205   dst.y = (src0.y < src1.y) ? 1 : 0
207   dst.z = (src0.z < src1.z) ? 1 : 0
209   dst.w = (src0.w < src1.w) ? 1 : 0
212 .. opcode:: SGE - Set On Greater Equal Than
214 .. math::
216   dst.x = (src0.x >= src1.x) ? 1 : 0
218   dst.y = (src0.y >= src1.y) ? 1 : 0
220   dst.z = (src0.z >= src1.z) ? 1 : 0
222   dst.w = (src0.w >= src1.w) ? 1 : 0
225 .. opcode:: MAD - Multiply And Add
227 .. math::
229   dst.x = src0.x \times src1.x + src2.x
231   dst.y = src0.y \times src1.y + src2.y
233   dst.z = src0.z \times src1.z + src2.z
235   dst.w = src0.w \times src1.w + src2.w
238 .. opcode:: SUB - Subtract
240 .. math::
242   dst.x = src0.x - src1.x
244   dst.y = src0.y - src1.y
246   dst.z = src0.z - src1.z
248   dst.w = src0.w - src1.w
251 .. opcode:: LRP - Linear Interpolate
253 .. math::
255   dst.x = src0.x \times src1.x + (1 - src0.x) \times src2.x
257   dst.y = src0.y \times src1.y + (1 - src0.y) \times src2.y
259   dst.z = src0.z \times src1.z + (1 - src0.z) \times src2.z
261   dst.w = src0.w \times src1.w + (1 - src0.w) \times src2.w
264 .. opcode:: CND - Condition
266 .. math::
268   dst.x = (src2.x > 0.5) ? src0.x : src1.x
270   dst.y = (src2.y > 0.5) ? src0.y : src1.y
272   dst.z = (src2.z > 0.5) ? src0.z : src1.z
274   dst.w = (src2.w > 0.5) ? src0.w : src1.w
277 .. opcode:: DP2A - 2-component Dot Product And Add
279 .. math::
281   dst.x = src0.x \times src1.x + src0.y \times src1.y + src2.x
283   dst.y = src0.x \times src1.x + src0.y \times src1.y + src2.x
285   dst.z = src0.x \times src1.x + src0.y \times src1.y + src2.x
287   dst.w = src0.x \times src1.x + src0.y \times src1.y + src2.x
290 .. opcode:: FRAC - Fraction
292 .. math::
294   dst.x = src.x - \lfloor src.x\rfloor
296   dst.y = src.y - \lfloor src.y\rfloor
298   dst.z = src.z - \lfloor src.z\rfloor
300   dst.w = src.w - \lfloor src.w\rfloor
303 .. opcode:: CLAMP - Clamp
305 .. math::
307   dst.x = clamp(src0.x, src1.x, src2.x)
309   dst.y = clamp(src0.y, src1.y, src2.y)
311   dst.z = clamp(src0.z, src1.z, src2.z)
313   dst.w = clamp(src0.w, src1.w, src2.w)
316 .. opcode:: FLR - Floor
318 This is identical to :opcode:`ARL`.
320 .. math::
322   dst.x = \lfloor src.x\rfloor
324   dst.y = \lfloor src.y\rfloor
326   dst.z = \lfloor src.z\rfloor
328   dst.w = \lfloor src.w\rfloor
331 .. opcode:: ROUND - Round
333 .. math::
335   dst.x = round(src.x)
337   dst.y = round(src.y)
339   dst.z = round(src.z)
341   dst.w = round(src.w)
344 .. opcode:: EX2 - Exponential Base 2
346 This instruction replicates its result.
348 .. math::
350   dst = 2^{src.x}
353 .. opcode:: LG2 - Logarithm Base 2
355 This instruction replicates its result.
357 .. math::
359   dst = \log_2{src.x}
362 .. opcode:: POW - Power
364 This instruction replicates its result.
366 .. math::
368   dst = src0.x^{src1.x}
370 .. opcode:: XPD - Cross Product
372 .. math::
374   dst.x = src0.y \times src1.z - src1.y \times src0.z
376   dst.y = src0.z \times src1.x - src1.z \times src0.x
378   dst.z = src0.x \times src1.y - src1.x \times src0.y
380   dst.w = 1
383 .. opcode:: ABS - Absolute
385 .. math::
387   dst.x = |src.x|
389   dst.y = |src.y|
391   dst.z = |src.z|
393   dst.w = |src.w|
396 .. opcode:: RCC - Reciprocal Clamped
398 This instruction replicates its result.
400 XXX cleanup on aisle three
402 .. math::
404   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)
407 .. opcode:: DPH - Homogeneous Dot Product
409 This instruction replicates its result.
411 .. math::
413   dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src1.w
416 .. opcode:: COS - Cosine
418 This instruction replicates its result.
420 .. math::
422   dst = \cos{src.x}
425 .. opcode:: DDX - Derivative Relative To X
427 .. math::
429   dst.x = partialx(src.x)
431   dst.y = partialx(src.y)
433   dst.z = partialx(src.z)
435   dst.w = partialx(src.w)
438 .. opcode:: DDY - Derivative Relative To Y
440 .. math::
442   dst.x = partialy(src.x)
444   dst.y = partialy(src.y)
446   dst.z = partialy(src.z)
448   dst.w = partialy(src.w)
451 .. opcode:: KILP - Predicated Discard
453   discard
456 .. opcode:: PK2H - Pack Two 16-bit Floats
458   TBD
461 .. opcode:: PK2US - Pack Two Unsigned 16-bit Scalars
463   TBD
466 .. opcode:: PK4B - Pack Four Signed 8-bit Scalars
468   TBD
471 .. opcode:: PK4UB - Pack Four Unsigned 8-bit Scalars
473   TBD
476 .. opcode:: RFL - Reflection Vector
478 .. math::
480   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
482   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
484   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
486   dst.w = 1
488 .. note::
490    Considered for removal.
493 .. opcode:: SEQ - Set On Equal
495 .. math::
497   dst.x = (src0.x == src1.x) ? 1 : 0
499   dst.y = (src0.y == src1.y) ? 1 : 0
501   dst.z = (src0.z == src1.z) ? 1 : 0
503   dst.w = (src0.w == src1.w) ? 1 : 0
506 .. opcode:: SFL - Set On False
508 This instruction replicates its result.
510 .. math::
512   dst = 0
514 .. note::
516    Considered for removal.
519 .. opcode:: SGT - Set On Greater Than
521 .. math::
523   dst.x = (src0.x > src1.x) ? 1 : 0
525   dst.y = (src0.y > src1.y) ? 1 : 0
527   dst.z = (src0.z > src1.z) ? 1 : 0
529   dst.w = (src0.w > src1.w) ? 1 : 0
532 .. opcode:: SIN - Sine
534 This instruction replicates its result.
536 .. math::
538   dst = \sin{src.x}
541 .. opcode:: SLE - Set On Less Equal Than
543 .. math::
545   dst.x = (src0.x <= src1.x) ? 1 : 0
547   dst.y = (src0.y <= src1.y) ? 1 : 0
549   dst.z = (src0.z <= src1.z) ? 1 : 0
551   dst.w = (src0.w <= src1.w) ? 1 : 0
554 .. opcode:: SNE - Set On Not Equal
556 .. math::
558   dst.x = (src0.x != src1.x) ? 1 : 0
560   dst.y = (src0.y != src1.y) ? 1 : 0
562   dst.z = (src0.z != src1.z) ? 1 : 0
564   dst.w = (src0.w != src1.w) ? 1 : 0
567 .. opcode:: STR - Set On True
569 This instruction replicates its result.
571 .. math::
573   dst = 1
576 .. opcode:: TEX - Texture Lookup
578   TBD
581 .. opcode:: TXD - Texture Lookup with Derivatives
583   TBD
586 .. opcode:: TXP - Projective Texture Lookup
588   TBD
591 .. opcode:: UP2H - Unpack Two 16-Bit Floats
593   TBD
595 .. note::
597    Considered for removal.
599 .. opcode:: UP2US - Unpack Two Unsigned 16-Bit Scalars
601   TBD
603 .. note::
605    Considered for removal.
607 .. opcode:: UP4B - Unpack Four Signed 8-Bit Values
609   TBD
611 .. note::
613    Considered for removal.
615 .. opcode:: UP4UB - Unpack Four Unsigned 8-Bit Scalars
617   TBD
619 .. note::
621    Considered for removal.
623 .. opcode:: X2D - 2D Coordinate Transformation
625 .. math::
627   dst.x = src0.x + src1.x \times src2.x + src1.y \times src2.y
629   dst.y = src0.y + src1.x \times src2.z + src1.y \times src2.w
631   dst.z = src0.x + src1.x \times src2.x + src1.y \times src2.y
633   dst.w = src0.y + src1.x \times src2.z + src1.y \times src2.w
635 .. note::
637    Considered for removal.
640 From GL_NV_vertex_program2
641 ^^^^^^^^^^^^^^^^^^^^^^^^^^
644 .. opcode:: ARA - Address Register Add
646   TBD
648 .. note::
650    Considered for removal.
652 .. opcode:: ARR - Address Register Load With Round
654 .. math::
656   dst.x = round(src.x)
658   dst.y = round(src.y)
660   dst.z = round(src.z)
662   dst.w = round(src.w)
665 .. opcode:: BRA - Branch
667   pc = target
669 .. note::
671    Considered for removal.
673 .. opcode:: CAL - Subroutine Call
675   push(pc)
676   pc = target
679 .. opcode:: RET - Subroutine Call Return
681   pc = pop()
683   Potential restrictions:  
684   * Only occurs at end of function.
686 .. opcode:: SSG - Set Sign
688 .. math::
690   dst.x = (src.x > 0) ? 1 : (src.x < 0) ? -1 : 0
692   dst.y = (src.y > 0) ? 1 : (src.y < 0) ? -1 : 0
694   dst.z = (src.z > 0) ? 1 : (src.z < 0) ? -1 : 0
696   dst.w = (src.w > 0) ? 1 : (src.w < 0) ? -1 : 0
699 .. opcode:: CMP - Compare
701 .. math::
703   dst.x = (src0.x < 0) ? src1.x : src2.x
705   dst.y = (src0.y < 0) ? src1.y : src2.y
707   dst.z = (src0.z < 0) ? src1.z : src2.z
709   dst.w = (src0.w < 0) ? src1.w : src2.w
712 .. opcode:: KIL - Conditional Discard
714 .. math::
716   if (src.x < 0 || src.y < 0 || src.z < 0 || src.w < 0)
717     discard
718   endif
721 .. opcode:: SCS - Sine Cosine
723 .. math::
725   dst.x = \cos{src.x}
727   dst.y = \sin{src.x}
729   dst.z = 0
731   dst.y = 1
734 .. opcode:: TXB - Texture Lookup With Bias
736   TBD
739 .. opcode:: NRM - 3-component Vector Normalise
741 .. math::
743   dst.x = src.x / (src.x \times src.x + src.y \times src.y + src.z \times src.z)
745   dst.y = src.y / (src.x \times src.x + src.y \times src.y + src.z \times src.z)
747   dst.z = src.z / (src.x \times src.x + src.y \times src.y + src.z \times src.z)
749   dst.w = 1
752 .. opcode:: DIV - Divide
754 .. math::
756   dst.x = \frac{src0.x}{src1.x}
758   dst.y = \frac{src0.y}{src1.y}
760   dst.z = \frac{src0.z}{src1.z}
762   dst.w = \frac{src0.w}{src1.w}
765 .. opcode:: DP2 - 2-component Dot Product
767 This instruction replicates its result.
769 .. math::
771   dst = src0.x \times src1.x + src0.y \times src1.y
774 .. opcode:: TXL - Texture Lookup With LOD
776   TBD
779 .. opcode:: BRK - Break
781   TBD
784 .. opcode:: IF - If
786   TBD
789 .. opcode:: BGNFOR - Begin a For-Loop
791   dst.x = floor(src.x)
792   dst.y = floor(src.y)
793   dst.z = floor(src.z)
795   if (dst.y <= 0)
796     pc = [matching ENDFOR] + 1
797   endif
799   Note: The destination must be a loop register.
800         The source must be a constant register.
802 .. note::
804    Considered for cleanup.
806 .. note::
808    Considered for removal.
811 .. opcode:: REP - Repeat
813   TBD
816 .. opcode:: ELSE - Else
818   TBD
821 .. opcode:: ENDIF - End If
823   TBD
826 .. opcode:: ENDFOR - End a For-Loop
828   dst.x = dst.x + dst.z
829   dst.y = dst.y - 1.0
831   if (dst.y > 0)
832     pc = [matching BGNFOR instruction] + 1
833   endif
835   Note: The destination must be a loop register.
837 .. note::
839    Considered for cleanup.
841 .. note::
843    Considered for removal.
845 .. opcode:: ENDREP - End Repeat
847   TBD
850 .. opcode:: PUSHA - Push Address Register On Stack
852   push(src.x)
853   push(src.y)
854   push(src.z)
855   push(src.w)
857 .. note::
859    Considered for cleanup.
861 .. note::
863    Considered for removal.
865 .. opcode:: POPA - Pop Address Register From Stack
867   dst.w = pop()
868   dst.z = pop()
869   dst.y = pop()
870   dst.x = pop()
872 .. note::
874    Considered for cleanup.
876 .. note::
878    Considered for removal.
881 From GL_NV_gpu_program4
882 ^^^^^^^^^^^^^^^^^^^^^^^^
884 Support for these opcodes indicated by a special pipe capability bit (TBD).
886 .. opcode:: CEIL - Ceiling
888 .. math::
890   dst.x = \lceil src.x\rceil
892   dst.y = \lceil src.y\rceil
894   dst.z = \lceil src.z\rceil
896   dst.w = \lceil src.w\rceil
899 .. opcode:: I2F - Integer To Float
901 .. math::
903   dst.x = (float) src.x
905   dst.y = (float) src.y
907   dst.z = (float) src.z
909   dst.w = (float) src.w
912 .. opcode:: NOT - Bitwise Not
914 .. math::
916   dst.x = ~src.x
918   dst.y = ~src.y
920   dst.z = ~src.z
922   dst.w = ~src.w
925 .. opcode:: TRUNC - Truncate
927 .. math::
929   dst.x = trunc(src.x)
931   dst.y = trunc(src.y)
933   dst.z = trunc(src.z)
935   dst.w = trunc(src.w)
938 .. opcode:: SHL - Shift Left
940 .. math::
942   dst.x = src0.x << src1.x
944   dst.y = src0.y << src1.x
946   dst.z = src0.z << src1.x
948   dst.w = src0.w << src1.x
951 .. opcode:: SHR - Shift Right
953 .. math::
955   dst.x = src0.x >> src1.x
957   dst.y = src0.y >> src1.x
959   dst.z = src0.z >> src1.x
961   dst.w = src0.w >> src1.x
964 .. opcode:: AND - Bitwise And
966 .. math::
968   dst.x = src0.x & src1.x
970   dst.y = src0.y & src1.y
972   dst.z = src0.z & src1.z
974   dst.w = src0.w & src1.w
977 .. opcode:: OR - Bitwise Or
979 .. math::
981   dst.x = src0.x | src1.x
983   dst.y = src0.y | src1.y
985   dst.z = src0.z | src1.z
987   dst.w = src0.w | src1.w
990 .. opcode:: MOD - Modulus
992 .. math::
994   dst.x = src0.x \bmod src1.x
996   dst.y = src0.y \bmod src1.y
998   dst.z = src0.z \bmod src1.z
1000   dst.w = src0.w \bmod src1.w
1003 .. opcode:: XOR - Bitwise Xor
1005 .. math::
1007   dst.x = src0.x \oplus src1.x
1009   dst.y = src0.y \oplus src1.y
1011   dst.z = src0.z \oplus src1.z
1013   dst.w = src0.w \oplus src1.w
1016 .. opcode:: SAD - Sum Of Absolute Differences
1018 .. math::
1020   dst.x = |src0.x - src1.x| + src2.x
1022   dst.y = |src0.y - src1.y| + src2.y
1024   dst.z = |src0.z - src1.z| + src2.z
1026   dst.w = |src0.w - src1.w| + src2.w
1029 .. opcode:: TXF - Texel Fetch
1031   TBD
1034 .. opcode:: TXQ - Texture Size Query
1036   TBD
1039 .. opcode:: CONT - Continue
1041   TBD
1044 From GL_NV_geometry_program4
1045 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1048 .. opcode:: EMIT - Emit
1050   TBD
1053 .. opcode:: ENDPRIM - End Primitive
1055   TBD
1058 From GLSL
1059 ^^^^^^^^^^
1062 .. opcode:: BGNLOOP - Begin a Loop
1064   TBD
1067 .. opcode:: BGNSUB - Begin Subroutine
1069   TBD
1072 .. opcode:: ENDLOOP - End a Loop
1074   TBD
1077 .. opcode:: ENDSUB - End Subroutine
1079   TBD
1082 .. opcode:: NOP - No Operation
1084   Do nothing.
1087 .. opcode:: NRM4 - 4-component Vector Normalise
1089 This instruction replicates its result.
1091 .. math::
1093   dst = \frac{src.x}{src.x \times src.x + src.y \times src.y + src.z \times src.z + src.w \times src.w}
1096 ps_2_x
1097 ^^^^^^^^^^^^
1100 .. opcode:: CALLNZ - Subroutine Call If Not Zero
1102   TBD
1105 .. opcode:: IFC - If
1107   TBD
1110 .. opcode:: BREAKC - Break Conditional
1112   TBD
1114 .. _doubleopcodes:
1116 Double Opcodes
1117 ^^^^^^^^^^^^^^^
1119 .. opcode:: DADD - Add Double
1121 .. math::
1123   dst.xy = src0.xy + src1.xy
1125   dst.zw = src0.zw + src1.zw
1128 .. opcode:: DDIV - Divide Double
1130 .. math::
1132   dst.xy = src0.xy / src1.xy
1134   dst.zw = src0.zw / src1.zw
1136 .. opcode:: DSEQ - Set Double on Equal
1138 .. math::
1140   dst.xy = src0.xy == src1.xy ? 1.0F : 0.0F
1142   dst.zw = src0.zw == src1.zw ? 1.0F : 0.0F
1144 .. opcode:: DSLT - Set Double on Less than
1146 .. math::
1148   dst.xy = src0.xy < src1.xy ? 1.0F : 0.0F
1150   dst.zw = src0.zw < src1.zw ? 1.0F : 0.0F
1152 .. opcode:: DFRAC - Double Fraction
1154 .. math::
1156   dst.xy = src.xy - \lfloor src.xy\rfloor
1158   dst.zw = src.zw - \lfloor src.zw\rfloor
1161 .. opcode:: DFRACEXP - Convert Double Number to Fractional and Integral Components
1163 .. math::
1165   dst0.xy = frexp(src.xy, dst1.xy)
1167   dst0.zw = frexp(src.zw, dst1.zw)
1169 .. opcode:: DLDEXP - Multiple Double Number by Integral Power of 2
1171 .. math::
1173   dst.xy = ldexp(src0.xy, src1.xy)
1175   dst.zw = ldexp(src0.zw, src1.zw)
1177 .. opcode:: DMIN - Minimum Double
1179 .. math::
1181   dst.xy = min(src0.xy, src1.xy)
1183   dst.zw = min(src0.zw, src1.zw)
1185 .. opcode:: DMAX - Maximum Double
1187 .. math::
1189   dst.xy = max(src0.xy, src1.xy)
1191   dst.zw = max(src0.zw, src1.zw)
1193 .. opcode:: DMUL - Multiply Double
1195 .. math::
1197   dst.xy = src0.xy \times src1.xy
1199   dst.zw = src0.zw \times src1.zw
1202 .. opcode:: DMAD - Multiply And Add Doubles
1204 .. math::
1206   dst.xy = src0.xy \times src1.xy + src2.xy
1208   dst.zw = src0.zw \times src1.zw + src2.zw
1211 .. opcode:: DRCP - Reciprocal Double
1213 .. math::
1215    dst.xy = \frac{1}{src.xy}
1217    dst.zw = \frac{1}{src.zw}
1219 .. opcode:: DSQRT - Square root double
1221 .. math::
1223    dst.xy = \sqrt{src.xy}
1225    dst.zw = \sqrt{src.zw}
1228 Explanation of symbols used
1229 ------------------------------
1232 Functions
1233 ^^^^^^^^^^^^^^
1236   :math:`|x|`       Absolute value of `x`.
1238   :math:`\lceil x \rceil` Ceiling of `x`.
1240   clamp(x,y,z)      Clamp x between y and z.
1241                     (x < y) ? y : (x > z) ? z : x
1243   :math:`\lfloor x\rfloor` Floor of `x`.
1245   :math:`\log_2{x}` Logarithm of `x`, base 2.
1247   max(x,y)          Maximum of x and y.
1248                     (x > y) ? x : y
1250   min(x,y)          Minimum of x and y.
1251                     (x < y) ? x : y
1253   partialx(x)       Derivative of x relative to fragment's X.
1255   partialy(x)       Derivative of x relative to fragment's Y.
1257   pop()             Pop from stack.
1259   :math:`x^y`       `x` to the power `y`.
1261   push(x)           Push x on stack.
1263   round(x)          Round x.
1265   trunc(x)          Truncate x, i.e. drop the fraction bits.
1268 Keywords
1269 ^^^^^^^^^^^^^
1272   discard           Discard fragment.
1274   pc                Program counter.
1276   target            Label of target instruction.
1279 Other tokens
1280 ---------------
1283 Declaration
1284 ^^^^^^^^^^^
1287 Declares a register that is will be referenced as an operand in Instruction
1288 tokens.
1290 File field contains register file that is being declared and is one
1291 of TGSI_FILE.
1293 UsageMask field specifies which of the register components can be accessed
1294 and is one of TGSI_WRITEMASK.
1296 Interpolate field is only valid for fragment shader INPUT register files.
1297 It specifes the way input is being interpolated by the rasteriser and is one
1298 of TGSI_INTERPOLATE.
1300 If Dimension flag is set to 1, a Declaration Dimension token follows.
1302 If Semantic flag is set to 1, a Declaration Semantic token follows.
1304 CylindricalWrap bitfield is only valid for fragment shader INPUT register
1305 files. It specifies which register components should be subject to cylindrical
1306 wrapping when interpolating by the rasteriser. If TGSI_CYLINDRICAL_WRAP_X
1307 is set to 1, the X component should be interpolated according to cylindrical
1308 wrapping rules.
1311 Declaration Semantic
1312 ^^^^^^^^^^^^^^^^^^^^^^^^
1315   Follows Declaration token if Semantic bit is set.
1317   Since its purpose is to link a shader with other stages of the pipeline,
1318   it is valid to follow only those Declaration tokens that declare a register
1319   either in INPUT or OUTPUT file.
1321   SemanticName field contains the semantic name of the register being declared.
1322   There is no default value.
1324   SemanticIndex is an optional subscript that can be used to distinguish
1325   different register declarations with the same semantic name. The default value
1326   is 0.
1328   The meanings of the individual semantic names are explained in the following
1329   sections.
1331 TGSI_SEMANTIC_POSITION
1332 """"""""""""""""""""""
1334 Position, sometimes known as HPOS or WPOS for historical reasons, is the
1335 location of the vertex in space, in ``(x, y, z, w)`` format. ``x``, ``y``, and ``z``
1336 are the Cartesian coordinates, and ``w`` is the homogenous coordinate and used
1337 for the perspective divide, if enabled.
1339 As a vertex shader output, position should be scaled to the viewport. When
1340 used in fragment shaders, position will be in window coordinates. The convention
1341 used depends on the FS_COORD_ORIGIN and FS_COORD_PIXEL_CENTER properties.
1343 XXX additionally, is there a way to configure the perspective divide? it's
1344 accelerated on most chipsets AFAIK...
1346 Position, if not specified, usually defaults to ``(0, 0, 0, 1)``, and can
1347 be partially specified as ``(x, y, 0, 1)`` or ``(x, y, z, 1)``.
1349 XXX usually? can we solidify that?
1351 TGSI_SEMANTIC_COLOR
1352 """""""""""""""""""
1354 Colors are used to, well, color the primitives. Colors are always in
1355 ``(r, g, b, a)`` format.
1357 If alpha is not specified, it defaults to 1.
1359 TGSI_SEMANTIC_BCOLOR
1360 """"""""""""""""""""
1362 Back-facing colors are only used for back-facing polygons, and are only valid
1363 in vertex shader outputs. After rasterization, all polygons are front-facing
1364 and COLOR and BCOLOR end up occupying the same slots in the fragment, so
1365 all BCOLORs effectively become regular COLORs in the fragment shader.
1367 TGSI_SEMANTIC_FOG
1368 """""""""""""""""
1370 The fog coordinate historically has been used to replace the depth coordinate
1371 for generation of fog in dedicated fog blocks. Gallium, however, does not use
1372 dedicated fog acceleration, placing it entirely in the fragment shader
1373 instead.
1375 The fog coordinate should be written in ``(f, 0, 0, 1)`` format. Only the first
1376 component matters when writing from the vertex shader; the driver will ensure
1377 that the coordinate is in this format when used as a fragment shader input.
1379 TGSI_SEMANTIC_PSIZE
1380 """""""""""""""""""
1382 PSIZE, or point size, is used to specify point sizes per-vertex. It should
1383 be in ``(s, 0, 0, 1)`` format, where ``s`` is the (possibly clamped) point size.
1384 Only the first component matters when writing from the vertex shader.
1386 When using this semantic, be sure to set the appropriate state in the
1387 :ref:`rasterizer` first.
1389 TGSI_SEMANTIC_GENERIC
1390 """""""""""""""""""""
1392 Generic semantics are nearly always used for texture coordinate attributes,
1393 in ``(s, t, r, q)`` format. ``t`` and ``r`` may be unused for certain kinds
1394 of lookups, and ``q`` is the level-of-detail bias for biased sampling.
1396 These attributes are called "generic" because they may be used for anything
1397 else, including parameters, texture generation information, or anything that
1398 can be stored inside a four-component vector.
1400 TGSI_SEMANTIC_FACE
1401 """"""""""""""""""
1403 FACE is the facing bit, to store the facing information for the fragment
1404 shader. ``(f, 0, 0, 1)`` is the format. The first component will be positive
1405 when the fragment is front-facing, and negative when the component is
1406 back-facing.
1408 TGSI_SEMANTIC_EDGEFLAG
1409 """"""""""""""""""""""
1411 XXX no clue
1414 Properties
1415 ^^^^^^^^^^^^^^^^^^^^^^^^
1418   Properties are general directives that apply to the whole TGSI program.
1420 FS_COORD_ORIGIN
1421 """""""""""""""
1423 Specifies the fragment shader TGSI_SEMANTIC_POSITION coordinate origin.
1424 The default value is UPPER_LEFT.
1426 If UPPER_LEFT, the position will be (0,0) at the upper left corner and
1427 increase downward and rightward.
1428 If LOWER_LEFT, the position will be (0,0) at the lower left corner and
1429 increase upward and rightward.
1431 OpenGL defaults to LOWER_LEFT, and is configurable with the
1432 GL_ARB_fragment_coord_conventions extension.
1434 DirectX 9/10 use UPPER_LEFT.
1436 FS_COORD_PIXEL_CENTER
1437 """""""""""""""""""""
1439 Specifies the fragment shader TGSI_SEMANTIC_POSITION pixel center convention.
1440 The default value is HALF_INTEGER.
1442 If HALF_INTEGER, the fractionary part of the position will be 0.5
1443 If INTEGER, the fractionary part of the position will be 0.0
1445 Note that this does not affect the set of fragments generated by
1446 rasterization, which is instead controlled by gl_rasterization_rules in the
1447 rasterizer.
1449 OpenGL defaults to HALF_INTEGER, and is configurable with the
1450 GL_ARB_fragment_coord_conventions extension.
1452 DirectX 9 uses INTEGER.
1453 DirectX 10 uses HALF_INTEGER.
1457 Texture Sampling and Texture Formats
1458 ------------------------------------
1460 This table shows how texture image components are returned as (x,y,z,w) tuples
1461 by TGSI texture instructions, such as :opcode:`TEX`, :opcode:`TXD`, and
1462 :opcode:`TXP`. For reference, OpenGL and Direct3D conventions are shown as
1463 well.
1465 +--------------------+--------------+--------------------+--------------+
1466 | Texture Components | Gallium      | OpenGL             | Direct3D 9   |
1467 +====================+==============+====================+==============+
1468 | R                  | XXX TBD      | (r, 0, 0, 1)       | (r, 1, 1, 1) |
1469 +--------------------+--------------+--------------------+--------------+
1470 | RG                 | XXX TBD      | (r, g, 0, 1)       | (r, g, 1, 1) |
1471 +--------------------+--------------+--------------------+--------------+
1472 | RGB                | (r, g, b, 1) | (r, g, b, 1)       | (r, g, b, 1) |
1473 +--------------------+--------------+--------------------+--------------+
1474 | RGBA               | (r, g, b, a) | (r, g, b, a)       | (r, g, b, a) |
1475 +--------------------+--------------+--------------------+--------------+
1476 | A                  | (0, 0, 0, a) | (0, 0, 0, a)       | (0, 0, 0, a) |
1477 +--------------------+--------------+--------------------+--------------+
1478 | L                  | (l, l, l, 1) | (l, l, l, 1)       | (l, l, l, 1) |
1479 +--------------------+--------------+--------------------+--------------+
1480 | LA                 | (l, l, l, a) | (l, l, l, a)       | (l, l, l, a) |
1481 +--------------------+--------------+--------------------+--------------+
1482 | I                  | (i, i, i, i) | (i, i, i, i)       | N/A          |
1483 +--------------------+--------------+--------------------+--------------+
1484 | UV                 | XXX TBD      | (0, 0, 0, 1)       | (u, v, 1, 1) |
1485 |                    |              | [#envmap-bumpmap]_ |              |
1486 +--------------------+--------------+--------------------+--------------+
1487 | Z                  | XXX TBD      | (z, z, z, 1)       | (0, z, 0, 1) |
1488 |                    |              | [#depth-tex-mode]_ |              |
1489 +--------------------+--------------+--------------------+--------------+
1491 .. [#envmap-bumpmap] http://www.opengl.org/registry/specs/ATI/envmap_bumpmap.txt
1492 .. [#depth-tex-mode] the default is (z, z, z, 1) but may also be (0, 0, 0, z)
1493    or (z, z, z, z) depending on the value of GL_DEPTH_TEXTURE_MODE.