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
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
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.
29 From GL_NV_vertex_program
30 ^^^^^^^^^^^^^^^^^^^^^^^^^
33 .. opcode:: ARL - Address Register Load
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
59 .. opcode:: LIT - Light Coefficients
67 dst.z = (src.x > 0) ? max(src.y, 0)^{clamp(src.w, -128, 128))} : 0
72 .. opcode:: RCP - Reciprocal
74 This instruction replicates its result.
81 .. opcode:: RSQ - Reciprocal Square Root
83 This instruction replicates its result.
87 dst = \frac{1}{\sqrt{|src.x|}}
90 .. opcode:: EXP - Approximate Exponential Base 2
94 dst.x = 2^{\lfloor src.x\rfloor}
96 dst.y = src.x - \lfloor src.x\rfloor
103 .. opcode:: LOG - Approximate Logarithm Base 2
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|}
116 .. opcode:: MUL - Multiply
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
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.
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.
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
166 dst.y = src0.y \times src1.y
173 .. opcode:: MIN - Minimum
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
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
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
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
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
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
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
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
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:: FRC - Fraction
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
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`.
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
344 .. opcode:: EX2 - Exponential Base 2
346 This instruction replicates its result.
353 .. opcode:: LG2 - Logarithm Base 2
355 This instruction replicates its result.
362 .. opcode:: POW - Power
364 This instruction replicates its result.
368 dst = src0.x^{src1.x}
370 .. opcode:: XPD - Cross Product
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
383 .. opcode:: ABS - Absolute
396 .. opcode:: RCC - Reciprocal Clamped
398 This instruction replicates its result.
400 XXX cleanup on aisle three
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.
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.
425 .. opcode:: DDX - Derivative Relative To X
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
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
456 .. opcode:: PK2H - Pack Two 16-bit Floats
461 .. opcode:: PK2US - Pack Two Unsigned 16-bit Scalars
466 .. opcode:: PK4B - Pack Four Signed 8-bit Scalars
471 .. opcode:: PK4UB - Pack Four Unsigned 8-bit Scalars
476 .. opcode:: RFL - Reflection Vector
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
490 Considered for removal.
493 .. opcode:: SEQ - Set On Equal
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.
516 Considered for removal.
519 .. opcode:: SGT - Set On Greater Than
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.
541 .. opcode:: SLE - Set On Less Equal Than
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
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.
576 .. opcode:: TEX - Texture Lookup
581 .. opcode:: TXD - Texture Lookup with Derivatives
586 .. opcode:: TXP - Projective Texture Lookup
591 .. opcode:: UP2H - Unpack Two 16-Bit Floats
597 Considered for removal.
599 .. opcode:: UP2US - Unpack Two Unsigned 16-Bit Scalars
605 Considered for removal.
607 .. opcode:: UP4B - Unpack Four Signed 8-Bit Values
613 Considered for removal.
615 .. opcode:: UP4UB - Unpack Four Unsigned 8-Bit Scalars
621 Considered for removal.
623 .. opcode:: X2D - 2D Coordinate Transformation
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
637 Considered for removal.
640 From GL_NV_vertex_program2
641 ^^^^^^^^^^^^^^^^^^^^^^^^^^
644 .. opcode:: ARA - Address Register Add
650 Considered for removal.
652 .. opcode:: ARR - Address Register Load With Round
665 .. opcode:: BRA - Branch
671 Considered for removal.
673 .. opcode:: CAL - Subroutine Call
679 .. opcode:: RET - Subroutine Call Return
683 Potential restrictions:
684 * Only occurs at end of function.
686 .. opcode:: SSG - Set Sign
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
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
716 if (src.x < 0 || src.y < 0 || src.z < 0 || src.w < 0)
721 .. opcode:: SCS - Sine Cosine
734 .. opcode:: TXB - Texture Lookup With Bias
739 .. opcode:: NRM - 3-component Vector Normalise
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)
752 .. opcode:: DIV - Divide
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.
771 dst = src0.x \times src1.x + src0.y \times src1.y
774 .. opcode:: TXL - Texture Lookup With LOD
779 .. opcode:: BRK - Break
789 .. opcode:: ELSE - Else
794 .. opcode:: ENDIF - End If
799 .. opcode:: PUSHA - Push Address Register On Stack
808 Considered for cleanup.
812 Considered for removal.
814 .. opcode:: POPA - Pop Address Register From Stack
823 Considered for cleanup.
827 Considered for removal.
830 From GL_NV_gpu_program4
831 ^^^^^^^^^^^^^^^^^^^^^^^^
833 Support for these opcodes indicated by a special pipe capability bit (TBD).
835 .. opcode:: CEIL - Ceiling
839 dst.x = \lceil src.x\rceil
841 dst.y = \lceil src.y\rceil
843 dst.z = \lceil src.z\rceil
845 dst.w = \lceil src.w\rceil
848 .. opcode:: I2F - Integer To Float
852 dst.x = (float) src.x
854 dst.y = (float) src.y
856 dst.z = (float) src.z
858 dst.w = (float) src.w
861 .. opcode:: NOT - Bitwise Not
874 .. opcode:: TRUNC - Truncate
887 .. opcode:: SHL - Shift Left
891 dst.x = src0.x << src1.x
893 dst.y = src0.y << src1.x
895 dst.z = src0.z << src1.x
897 dst.w = src0.w << src1.x
900 .. opcode:: SHR - Shift Right
904 dst.x = src0.x >> src1.x
906 dst.y = src0.y >> src1.x
908 dst.z = src0.z >> src1.x
910 dst.w = src0.w >> src1.x
913 .. opcode:: AND - Bitwise And
917 dst.x = src0.x & src1.x
919 dst.y = src0.y & src1.y
921 dst.z = src0.z & src1.z
923 dst.w = src0.w & src1.w
926 .. opcode:: OR - Bitwise Or
930 dst.x = src0.x | src1.x
932 dst.y = src0.y | src1.y
934 dst.z = src0.z | src1.z
936 dst.w = src0.w | src1.w
939 .. opcode:: MOD - Modulus
943 dst.x = src0.x \bmod src1.x
945 dst.y = src0.y \bmod src1.y
947 dst.z = src0.z \bmod src1.z
949 dst.w = src0.w \bmod src1.w
952 .. opcode:: XOR - Bitwise Xor
956 dst.x = src0.x \oplus src1.x
958 dst.y = src0.y \oplus src1.y
960 dst.z = src0.z \oplus src1.z
962 dst.w = src0.w \oplus src1.w
965 .. opcode:: SAD - Sum Of Absolute Differences
969 dst.x = |src0.x - src1.x| + src2.x
971 dst.y = |src0.y - src1.y| + src2.y
973 dst.z = |src0.z - src1.z| + src2.z
975 dst.w = |src0.w - src1.w| + src2.w
978 .. opcode:: TXF - Texel Fetch
983 .. opcode:: TXQ - Texture Size Query
988 .. opcode:: CONT - Continue
993 From GL_NV_geometry_program4
994 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
997 .. opcode:: EMIT - Emit
1002 .. opcode:: ENDPRIM - End Primitive
1011 .. opcode:: BGNLOOP - Begin a Loop
1016 .. opcode:: BGNSUB - Begin Subroutine
1021 .. opcode:: ENDLOOP - End a Loop
1026 .. opcode:: ENDSUB - End Subroutine
1031 .. opcode:: NOP - No Operation
1036 .. opcode:: NRM4 - 4-component Vector Normalise
1038 This instruction replicates its result.
1042 dst = \frac{src.x}{src.x \times src.x + src.y \times src.y + src.z \times src.z + src.w \times src.w}
1049 .. opcode:: CALLNZ - Subroutine Call If Not Zero
1054 .. opcode:: IFC - If
1059 .. opcode:: BREAKC - Break Conditional
1068 .. opcode:: DADD - Add Double
1072 dst.xy = src0.xy + src1.xy
1074 dst.zw = src0.zw + src1.zw
1077 .. opcode:: DDIV - Divide Double
1081 dst.xy = src0.xy / src1.xy
1083 dst.zw = src0.zw / src1.zw
1085 .. opcode:: DSEQ - Set Double on Equal
1089 dst.xy = src0.xy == src1.xy ? 1.0F : 0.0F
1091 dst.zw = src0.zw == src1.zw ? 1.0F : 0.0F
1093 .. opcode:: DSLT - Set Double on Less than
1097 dst.xy = src0.xy < src1.xy ? 1.0F : 0.0F
1099 dst.zw = src0.zw < src1.zw ? 1.0F : 0.0F
1101 .. opcode:: DFRAC - Double Fraction
1105 dst.xy = src.xy - \lfloor src.xy\rfloor
1107 dst.zw = src.zw - \lfloor src.zw\rfloor
1110 .. opcode:: DFRACEXP - Convert Double Number to Fractional and Integral Components
1114 dst0.xy = frexp(src.xy, dst1.xy)
1116 dst0.zw = frexp(src.zw, dst1.zw)
1118 .. opcode:: DLDEXP - Multiple Double Number by Integral Power of 2
1122 dst.xy = ldexp(src0.xy, src1.xy)
1124 dst.zw = ldexp(src0.zw, src1.zw)
1126 .. opcode:: DMIN - Minimum Double
1130 dst.xy = min(src0.xy, src1.xy)
1132 dst.zw = min(src0.zw, src1.zw)
1134 .. opcode:: DMAX - Maximum Double
1138 dst.xy = max(src0.xy, src1.xy)
1140 dst.zw = max(src0.zw, src1.zw)
1142 .. opcode:: DMUL - Multiply Double
1146 dst.xy = src0.xy \times src1.xy
1148 dst.zw = src0.zw \times src1.zw
1151 .. opcode:: DMAD - Multiply And Add Doubles
1155 dst.xy = src0.xy \times src1.xy + src2.xy
1157 dst.zw = src0.zw \times src1.zw + src2.zw
1160 .. opcode:: DRCP - Reciprocal Double
1164 dst.xy = \frac{1}{src.xy}
1166 dst.zw = \frac{1}{src.zw}
1168 .. opcode:: DSQRT - Square root double
1172 dst.xy = \sqrt{src.xy}
1174 dst.zw = \sqrt{src.zw}
1177 Explanation of symbols used
1178 ------------------------------
1185 :math:`|x|` Absolute value of `x`.
1187 :math:`\lceil x \rceil` Ceiling of `x`.
1189 clamp(x,y,z) Clamp x between y and z.
1190 (x < y) ? y : (x > z) ? z : x
1192 :math:`\lfloor x\rfloor` Floor of `x`.
1194 :math:`\log_2{x}` Logarithm of `x`, base 2.
1196 max(x,y) Maximum of x and y.
1199 min(x,y) Minimum of x and y.
1202 partialx(x) Derivative of x relative to fragment's X.
1204 partialy(x) Derivative of x relative to fragment's Y.
1206 pop() Pop from stack.
1208 :math:`x^y` `x` to the power `y`.
1210 push(x) Push x on stack.
1214 trunc(x) Truncate x, i.e. drop the fraction bits.
1221 discard Discard fragment.
1225 target Label of target instruction.
1236 Declares a register that is will be referenced as an operand in Instruction
1239 File field contains register file that is being declared and is one
1242 UsageMask field specifies which of the register components can be accessed
1243 and is one of TGSI_WRITEMASK.
1245 Interpolate field is only valid for fragment shader INPUT register files.
1246 It specifes the way input is being interpolated by the rasteriser and is one
1247 of TGSI_INTERPOLATE.
1249 If Dimension flag is set to 1, a Declaration Dimension token follows.
1251 If Semantic flag is set to 1, a Declaration Semantic token follows.
1253 CylindricalWrap bitfield is only valid for fragment shader INPUT register
1254 files. It specifies which register components should be subject to cylindrical
1255 wrapping when interpolating by the rasteriser. If TGSI_CYLINDRICAL_WRAP_X
1256 is set to 1, the X component should be interpolated according to cylindrical
1260 Declaration Semantic
1261 ^^^^^^^^^^^^^^^^^^^^^^^^
1264 Follows Declaration token if Semantic bit is set.
1266 Since its purpose is to link a shader with other stages of the pipeline,
1267 it is valid to follow only those Declaration tokens that declare a register
1268 either in INPUT or OUTPUT file.
1270 SemanticName field contains the semantic name of the register being declared.
1271 There is no default value.
1273 SemanticIndex is an optional subscript that can be used to distinguish
1274 different register declarations with the same semantic name. The default value
1277 The meanings of the individual semantic names are explained in the following
1280 TGSI_SEMANTIC_POSITION
1281 """"""""""""""""""""""
1283 Position, sometimes known as HPOS or WPOS for historical reasons, is the
1284 location of the vertex in space, in ``(x, y, z, w)`` format. ``x``, ``y``, and ``z``
1285 are the Cartesian coordinates, and ``w`` is the homogenous coordinate and used
1286 for the perspective divide, if enabled.
1288 As a vertex shader output, position should be scaled to the viewport. When
1289 used in fragment shaders, position will be in window coordinates. The convention
1290 used depends on the FS_COORD_ORIGIN and FS_COORD_PIXEL_CENTER properties.
1292 XXX additionally, is there a way to configure the perspective divide? it's
1293 accelerated on most chipsets AFAIK...
1295 Position, if not specified, usually defaults to ``(0, 0, 0, 1)``, and can
1296 be partially specified as ``(x, y, 0, 1)`` or ``(x, y, z, 1)``.
1298 XXX usually? can we solidify that?
1303 Colors are used to, well, color the primitives. Colors are always in
1304 ``(r, g, b, a)`` format.
1306 If alpha is not specified, it defaults to 1.
1308 TGSI_SEMANTIC_BCOLOR
1309 """"""""""""""""""""
1311 Back-facing colors are only used for back-facing polygons, and are only valid
1312 in vertex shader outputs. After rasterization, all polygons are front-facing
1313 and COLOR and BCOLOR end up occupying the same slots in the fragment, so
1314 all BCOLORs effectively become regular COLORs in the fragment shader.
1319 The fog coordinate historically has been used to replace the depth coordinate
1320 for generation of fog in dedicated fog blocks. Gallium, however, does not use
1321 dedicated fog acceleration, placing it entirely in the fragment shader
1324 The fog coordinate should be written in ``(f, 0, 0, 1)`` format. Only the first
1325 component matters when writing from the vertex shader; the driver will ensure
1326 that the coordinate is in this format when used as a fragment shader input.
1331 PSIZE, or point size, is used to specify point sizes per-vertex. It should
1332 be in ``(s, 0, 0, 1)`` format, where ``s`` is the (possibly clamped) point size.
1333 Only the first component matters when writing from the vertex shader.
1335 When using this semantic, be sure to set the appropriate state in the
1336 :ref:`rasterizer` first.
1338 TGSI_SEMANTIC_GENERIC
1339 """""""""""""""""""""
1341 Generic semantics are nearly always used for texture coordinate attributes,
1342 in ``(s, t, r, q)`` format. ``t`` and ``r`` may be unused for certain kinds
1343 of lookups, and ``q`` is the level-of-detail bias for biased sampling.
1345 These attributes are called "generic" because they may be used for anything
1346 else, including parameters, texture generation information, or anything that
1347 can be stored inside a four-component vector.
1349 TGSI_SEMANTIC_NORMAL
1350 """"""""""""""""""""
1352 Vertex normal; could be used to implement per-pixel lighting for legacy APIs
1353 that allow mixing fixed-function and programmable stages.
1358 FACE is the facing bit, to store the facing information for the fragment
1359 shader. ``(f, 0, 0, 1)`` is the format. The first component will be positive
1360 when the fragment is front-facing, and negative when the component is
1363 TGSI_SEMANTIC_EDGEFLAG
1364 """"""""""""""""""""""
1370 ^^^^^^^^^^^^^^^^^^^^^^^^
1373 Properties are general directives that apply to the whole TGSI program.
1378 Specifies the fragment shader TGSI_SEMANTIC_POSITION coordinate origin.
1379 The default value is UPPER_LEFT.
1381 If UPPER_LEFT, the position will be (0,0) at the upper left corner and
1382 increase downward and rightward.
1383 If LOWER_LEFT, the position will be (0,0) at the lower left corner and
1384 increase upward and rightward.
1386 OpenGL defaults to LOWER_LEFT, and is configurable with the
1387 GL_ARB_fragment_coord_conventions extension.
1389 DirectX 9/10 use UPPER_LEFT.
1391 FS_COORD_PIXEL_CENTER
1392 """""""""""""""""""""
1394 Specifies the fragment shader TGSI_SEMANTIC_POSITION pixel center convention.
1395 The default value is HALF_INTEGER.
1397 If HALF_INTEGER, the fractionary part of the position will be 0.5
1398 If INTEGER, the fractionary part of the position will be 0.0
1400 Note that this does not affect the set of fragments generated by
1401 rasterization, which is instead controlled by gl_rasterization_rules in the
1404 OpenGL defaults to HALF_INTEGER, and is configurable with the
1405 GL_ARB_fragment_coord_conventions extension.
1407 DirectX 9 uses INTEGER.
1408 DirectX 10 uses HALF_INTEGER.
1412 Texture Sampling and Texture Formats
1413 ------------------------------------
1415 This table shows how texture image components are returned as (x,y,z,w) tuples
1416 by TGSI texture instructions, such as :opcode:`TEX`, :opcode:`TXD`, and
1417 :opcode:`TXP`. For reference, OpenGL and Direct3D conventions are shown as
1420 +--------------------+--------------+--------------------+--------------+
1421 | Texture Components | Gallium | OpenGL | Direct3D 9 |
1422 +====================+==============+====================+==============+
1423 | R | (r, 0, 0, 1) | (r, 0, 0, 1) | (r, 1, 1, 1) |
1424 +--------------------+--------------+--------------------+--------------+
1425 | RG | (r, g, 0, 1) | (r, g, 0, 1) | (r, g, 1, 1) |
1426 +--------------------+--------------+--------------------+--------------+
1427 | RGB | (r, g, b, 1) | (r, g, b, 1) | (r, g, b, 1) |
1428 +--------------------+--------------+--------------------+--------------+
1429 | RGBA | (r, g, b, a) | (r, g, b, a) | (r, g, b, a) |
1430 +--------------------+--------------+--------------------+--------------+
1431 | A | (0, 0, 0, a) | (0, 0, 0, a) | (0, 0, 0, a) |
1432 +--------------------+--------------+--------------------+--------------+
1433 | L | (l, l, l, 1) | (l, l, l, 1) | (l, l, l, 1) |
1434 +--------------------+--------------+--------------------+--------------+
1435 | LA | (l, l, l, a) | (l, l, l, a) | (l, l, l, a) |
1436 +--------------------+--------------+--------------------+--------------+
1437 | I | (i, i, i, i) | (i, i, i, i) | N/A |
1438 +--------------------+--------------+--------------------+--------------+
1439 | UV | XXX TBD | (0, 0, 0, 1) | (u, v, 1, 1) |
1440 | | | [#envmap-bumpmap]_ | |
1441 +--------------------+--------------+--------------------+--------------+
1442 | Z | XXX TBD | (z, z, z, 1) | (0, z, 0, 1) |
1443 | | | [#depth-tex-mode]_ | |
1444 +--------------------+--------------+--------------------+--------------+
1446 .. [#envmap-bumpmap] http://www.opengl.org/registry/specs/ATI/envmap_bumpmap.txt
1447 .. [#depth-tex-mode] the default is (z, z, z, 1) but may also be (0, 0, 0, z)
1448 or (z, z, z, z) depending on the value of GL_DEPTH_TEXTURE_MODE.