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:`doubleopcodes`.
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 TGSI supports modifiers on inputs (as well as saturate modifier on instructions).
31 For inputs which have a floating point type, both absolute value and
32 negation modifiers are supported (with absolute value being applied
33 first). The only source of TGSI_OPCODE_MOV and the second and third
34 sources of TGSI_OPCODE_UCMP are considered to have float type for
37 For inputs which have signed or unsigned type only the negate modifier is
44 ^^^^^^^^^^^^^^^^^^^^^^^^^
46 These opcodes are guaranteed to be available regardless of the driver being
49 .. opcode:: ARL - Address Register Load
53 dst.x = (int) \lfloor src.x\rfloor
55 dst.y = (int) \lfloor src.y\rfloor
57 dst.z = (int) \lfloor src.z\rfloor
59 dst.w = (int) \lfloor src.w\rfloor
62 .. opcode:: MOV - Move
75 .. opcode:: LIT - Light Coefficients
80 dst.y &= max(src.x, 0) \\
81 dst.z &= (src.x > 0) ? max(src.y, 0)^{clamp(src.w, -128, 128))} : 0 \\
85 .. opcode:: RCP - Reciprocal
87 This instruction replicates its result.
94 .. opcode:: RSQ - Reciprocal Square Root
96 This instruction replicates its result. The results are undefined for src <= 0.
100 dst = \frac{1}{\sqrt{src.x}}
103 .. opcode:: SQRT - Square Root
105 This instruction replicates its result. The results are undefined for src < 0.
112 .. opcode:: EXP - Approximate Exponential Base 2
116 dst.x &= 2^{\lfloor src.x\rfloor} \\
117 dst.y &= src.x - \lfloor src.x\rfloor \\
118 dst.z &= 2^{src.x} \\
122 .. opcode:: LOG - Approximate Logarithm Base 2
126 dst.x &= \lfloor\log_2{|src.x|}\rfloor \\
127 dst.y &= \frac{|src.x|}{2^{\lfloor\log_2{|src.x|}\rfloor}} \\
128 dst.z &= \log_2{|src.x|} \\
132 .. opcode:: MUL - Multiply
136 dst.x = src0.x \times src1.x
138 dst.y = src0.y \times src1.y
140 dst.z = src0.z \times src1.z
142 dst.w = src0.w \times src1.w
145 .. opcode:: ADD - Add
149 dst.x = src0.x + src1.x
151 dst.y = src0.y + src1.y
153 dst.z = src0.z + src1.z
155 dst.w = src0.w + src1.w
158 .. opcode:: DP3 - 3-component Dot Product
160 This instruction replicates its result.
164 dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z
167 .. opcode:: DP4 - 4-component Dot Product
169 This instruction replicates its result.
173 dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src0.w \times src1.w
176 .. opcode:: DST - Distance Vector
181 dst.y &= src0.y \times src1.y\\
186 .. opcode:: MIN - Minimum
190 dst.x = min(src0.x, src1.x)
192 dst.y = min(src0.y, src1.y)
194 dst.z = min(src0.z, src1.z)
196 dst.w = min(src0.w, src1.w)
199 .. opcode:: MAX - Maximum
203 dst.x = max(src0.x, src1.x)
205 dst.y = max(src0.y, src1.y)
207 dst.z = max(src0.z, src1.z)
209 dst.w = max(src0.w, src1.w)
212 .. opcode:: SLT - Set On Less Than
216 dst.x = (src0.x < src1.x) ? 1.0F : 0.0F
218 dst.y = (src0.y < src1.y) ? 1.0F : 0.0F
220 dst.z = (src0.z < src1.z) ? 1.0F : 0.0F
222 dst.w = (src0.w < src1.w) ? 1.0F : 0.0F
225 .. opcode:: SGE - Set On Greater Equal Than
229 dst.x = (src0.x >= src1.x) ? 1.0F : 0.0F
231 dst.y = (src0.y >= src1.y) ? 1.0F : 0.0F
233 dst.z = (src0.z >= src1.z) ? 1.0F : 0.0F
235 dst.w = (src0.w >= src1.w) ? 1.0F : 0.0F
238 .. opcode:: MAD - Multiply And Add
242 dst.x = src0.x \times src1.x + src2.x
244 dst.y = src0.y \times src1.y + src2.y
246 dst.z = src0.z \times src1.z + src2.z
248 dst.w = src0.w \times src1.w + src2.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:: FMA - Fused Multiply-Add
266 Perform a * b + c with no intermediate rounding step.
270 dst.x = src0.x \times src1.x + src2.x
272 dst.y = src0.y \times src1.y + src2.y
274 dst.z = src0.z \times src1.z + src2.z
276 dst.w = src0.w \times src1.w + src2.w
279 .. opcode:: DP2A - 2-component Dot Product And Add
283 dst.x = src0.x \times src1.x + src0.y \times src1.y + src2.x
285 dst.y = src0.x \times src1.x + src0.y \times src1.y + src2.x
287 dst.z = src0.x \times src1.x + src0.y \times src1.y + src2.x
289 dst.w = src0.x \times src1.x + src0.y \times src1.y + src2.x
292 .. opcode:: FRC - Fraction
296 dst.x = src.x - \lfloor src.x\rfloor
298 dst.y = src.y - \lfloor src.y\rfloor
300 dst.z = src.z - \lfloor src.z\rfloor
302 dst.w = src.w - \lfloor src.w\rfloor
305 .. opcode:: FLR - Floor
309 dst.x = \lfloor src.x\rfloor
311 dst.y = \lfloor src.y\rfloor
313 dst.z = \lfloor src.z\rfloor
315 dst.w = \lfloor src.w\rfloor
318 .. opcode:: ROUND - Round
331 .. opcode:: EX2 - Exponential Base 2
333 This instruction replicates its result.
340 .. opcode:: LG2 - Logarithm Base 2
342 This instruction replicates its result.
349 .. opcode:: POW - Power
351 This instruction replicates its result.
355 dst = src0.x^{src1.x}
357 .. opcode:: XPD - Cross Product
361 dst.x = src0.y \times src1.z - src1.y \times src0.z
363 dst.y = src0.z \times src1.x - src1.z \times src0.x
365 dst.z = src0.x \times src1.y - src1.x \times src0.y
370 .. opcode:: DPH - Homogeneous Dot Product
372 This instruction replicates its result.
376 dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src1.w
379 .. opcode:: COS - Cosine
381 This instruction replicates its result.
388 .. opcode:: DDX, DDX_FINE - Derivative Relative To X
390 The fine variant is only used when ``PIPE_CAP_TGSI_FS_FINE_DERIVATIVE`` is
391 advertised. When it is, the fine version guarantees one derivative per row
392 while DDX is allowed to be the same for the entire 2x2 quad.
396 dst.x = partialx(src.x)
398 dst.y = partialx(src.y)
400 dst.z = partialx(src.z)
402 dst.w = partialx(src.w)
405 .. opcode:: DDY, DDY_FINE - Derivative Relative To Y
407 The fine variant is only used when ``PIPE_CAP_TGSI_FS_FINE_DERIVATIVE`` is
408 advertised. When it is, the fine version guarantees one derivative per column
409 while DDY is allowed to be the same for the entire 2x2 quad.
413 dst.x = partialy(src.x)
415 dst.y = partialy(src.y)
417 dst.z = partialy(src.z)
419 dst.w = partialy(src.w)
422 .. opcode:: PK2H - Pack Two 16-bit Floats
424 This instruction replicates its result.
428 dst = f32\_to\_f16(src.x) | f32\_to\_f16(src.y) << 16
431 .. opcode:: PK2US - Pack Two Unsigned 16-bit Scalars
436 .. opcode:: PK4B - Pack Four Signed 8-bit Scalars
441 .. opcode:: PK4UB - Pack Four Unsigned 8-bit Scalars
446 .. opcode:: SEQ - Set On Equal
450 dst.x = (src0.x == src1.x) ? 1.0F : 0.0F
452 dst.y = (src0.y == src1.y) ? 1.0F : 0.0F
454 dst.z = (src0.z == src1.z) ? 1.0F : 0.0F
456 dst.w = (src0.w == src1.w) ? 1.0F : 0.0F
459 .. opcode:: SGT - Set On Greater Than
463 dst.x = (src0.x > src1.x) ? 1.0F : 0.0F
465 dst.y = (src0.y > src1.y) ? 1.0F : 0.0F
467 dst.z = (src0.z > src1.z) ? 1.0F : 0.0F
469 dst.w = (src0.w > src1.w) ? 1.0F : 0.0F
472 .. opcode:: SIN - Sine
474 This instruction replicates its result.
481 .. opcode:: SLE - Set On Less Equal Than
485 dst.x = (src0.x <= src1.x) ? 1.0F : 0.0F
487 dst.y = (src0.y <= src1.y) ? 1.0F : 0.0F
489 dst.z = (src0.z <= src1.z) ? 1.0F : 0.0F
491 dst.w = (src0.w <= src1.w) ? 1.0F : 0.0F
494 .. opcode:: SNE - Set On Not Equal
498 dst.x = (src0.x != src1.x) ? 1.0F : 0.0F
500 dst.y = (src0.y != src1.y) ? 1.0F : 0.0F
502 dst.z = (src0.z != src1.z) ? 1.0F : 0.0F
504 dst.w = (src0.w != src1.w) ? 1.0F : 0.0F
507 .. opcode:: TEX - Texture Lookup
509 for array textures src0.y contains the slice for 1D,
510 and src0.z contain the slice for 2D.
512 for shadow textures with no arrays (and not cube map),
513 src0.z contains the reference value.
515 for shadow textures with arrays, src0.z contains
516 the reference value for 1D arrays, and src0.w contains
517 the reference value for 2D arrays and cube maps.
519 for cube map array shadow textures, the reference value
520 cannot be passed in src0.w, and TEX2 must be used instead.
526 shadow_ref = src0.z or src0.w (optional)
530 dst = texture\_sample(unit, coord, shadow_ref)
533 .. opcode:: TEX2 - Texture Lookup (for shadow cube map arrays only)
535 this is the same as TEX, but uses another reg to encode the
546 dst = texture\_sample(unit, coord, shadow_ref)
551 .. opcode:: TXD - Texture Lookup with Derivatives
563 dst = texture\_sample\_deriv(unit, coord, ddx, ddy)
566 .. opcode:: TXP - Projective Texture Lookup
570 coord.x = src0.x / src0.w
572 coord.y = src0.y / src0.w
574 coord.z = src0.z / src0.w
580 dst = texture\_sample(unit, coord)
583 .. opcode:: UP2H - Unpack Two 16-Bit Floats
587 dst.x = f16\_to\_f32(src0.x \& 0xffff)
589 dst.y = f16\_to\_f32(src0.x >> 16)
591 dst.z = f16\_to\_f32(src0.x \& 0xffff)
593 dst.w = f16\_to\_f32(src0.x >> 16)
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.
624 .. opcode:: ARR - Address Register Load With Round
628 dst.x = (int) round(src.x)
630 dst.y = (int) round(src.y)
632 dst.z = (int) round(src.z)
634 dst.w = (int) round(src.w)
637 .. opcode:: SSG - Set Sign
641 dst.x = (src.x > 0) ? 1 : (src.x < 0) ? -1 : 0
643 dst.y = (src.y > 0) ? 1 : (src.y < 0) ? -1 : 0
645 dst.z = (src.z > 0) ? 1 : (src.z < 0) ? -1 : 0
647 dst.w = (src.w > 0) ? 1 : (src.w < 0) ? -1 : 0
650 .. opcode:: CMP - Compare
654 dst.x = (src0.x < 0) ? src1.x : src2.x
656 dst.y = (src0.y < 0) ? src1.y : src2.y
658 dst.z = (src0.z < 0) ? src1.z : src2.z
660 dst.w = (src0.w < 0) ? src1.w : src2.w
663 .. opcode:: KILL_IF - Conditional Discard
665 Conditional discard. Allowed in fragment shaders only.
669 if (src.x < 0 || src.y < 0 || src.z < 0 || src.w < 0)
674 .. opcode:: KILL - Discard
676 Unconditional discard. Allowed in fragment shaders only.
679 .. opcode:: SCS - Sine Cosine
692 .. opcode:: TXB - Texture Lookup With Bias
694 for cube map array textures and shadow cube maps, the bias value
695 cannot be passed in src0.w, and TXB2 must be used instead.
697 if the target is a shadow texture, the reference value is always
698 in src.z (this prevents shadow 3d and shadow 2d arrays from
699 using this instruction, but this is not needed).
715 dst = texture\_sample(unit, coord, bias)
718 .. opcode:: TXB2 - Texture Lookup With Bias (some cube maps only)
720 this is the same as TXB, but uses another reg to encode the
721 lod bias value for cube map arrays and shadow cube maps.
722 Presumably shadow 2d arrays and shadow 3d targets could use
723 this encoding too, but this is not legal.
725 shadow cube map arrays are neither possible nor required.
735 dst = texture\_sample(unit, coord, bias)
738 .. opcode:: DIV - Divide
742 dst.x = \frac{src0.x}{src1.x}
744 dst.y = \frac{src0.y}{src1.y}
746 dst.z = \frac{src0.z}{src1.z}
748 dst.w = \frac{src0.w}{src1.w}
751 .. opcode:: DP2 - 2-component Dot Product
753 This instruction replicates its result.
757 dst = src0.x \times src1.x + src0.y \times src1.y
760 .. opcode:: TEX_LZ - Texture Lookup With LOD = 0
762 This is the same as TXL with LOD = 0. Like every texture opcode, it obeys
763 pipe_sampler_view::u.tex.first_level and pipe_sampler_state::min_lod.
764 There is no way to override those two in shaders.
780 dst = texture\_sample(unit, coord, lod)
783 .. opcode:: TXL - Texture Lookup With explicit LOD
785 for cube map array textures, the explicit lod value
786 cannot be passed in src0.w, and TXL2 must be used instead.
788 if the target is a shadow texture, the reference value is always
789 in src.z (this prevents shadow 3d / 2d array / cube targets from
790 using this instruction, but this is not needed).
806 dst = texture\_sample(unit, coord, lod)
809 .. opcode:: TXL2 - Texture Lookup With explicit LOD (for cube map arrays only)
811 this is the same as TXL, but uses another reg to encode the
813 Presumably shadow 3d / 2d array / cube targets could use
814 this encoding too, but this is not legal.
816 shadow cube map arrays are neither possible nor required.
826 dst = texture\_sample(unit, coord, lod)
829 .. opcode:: PUSHA - Push Address Register On Stack
838 Considered for cleanup.
842 Considered for removal.
844 .. opcode:: POPA - Pop Address Register From Stack
853 Considered for cleanup.
857 Considered for removal.
860 .. opcode:: CALLNZ - Subroutine Call If Not Zero
866 Considered for cleanup.
870 Considered for removal.
874 ^^^^^^^^^^^^^^^^^^^^^^^^
876 These opcodes are primarily provided for special-use computational shaders.
877 Support for these opcodes indicated by a special pipe capability bit (TBD).
879 XXX doesn't look like most of the opcodes really belong here.
881 .. opcode:: CEIL - Ceiling
885 dst.x = \lceil src.x\rceil
887 dst.y = \lceil src.y\rceil
889 dst.z = \lceil src.z\rceil
891 dst.w = \lceil src.w\rceil
894 .. opcode:: TRUNC - Truncate
907 .. opcode:: MOD - Modulus
911 dst.x = src0.x \bmod src1.x
913 dst.y = src0.y \bmod src1.y
915 dst.z = src0.z \bmod src1.z
917 dst.w = src0.w \bmod src1.w
920 .. opcode:: UARL - Integer Address Register Load
922 Moves the contents of the source register, assumed to be an integer, into the
923 destination register, which is assumed to be an address (ADDR) register.
926 .. opcode:: SAD - Sum Of Absolute Differences
930 dst.x = |src0.x - src1.x| + src2.x
932 dst.y = |src0.y - src1.y| + src2.y
934 dst.z = |src0.z - src1.z| + src2.z
936 dst.w = |src0.w - src1.w| + src2.w
939 .. opcode:: TXF - Texel Fetch
941 As per NV_gpu_shader4, extract a single texel from a specified texture
942 image. The source sampler may not be a CUBE or SHADOW. src 0 is a
943 four-component signed integer vector used to identify the single texel
944 accessed. 3 components + level. Just like texture instructions, an optional
945 offset vector is provided, which is subject to various driver restrictions
946 (regarding range, source of offsets). This instruction ignores the sampler
949 TXF(uint_vec coord, int_vec offset).
952 .. opcode:: TXF_LZ - Texel Fetch
954 This is the same as TXF with level = 0. Like TXF, it obeys
955 pipe_sampler_view::u.tex.first_level.
958 .. opcode:: TXQ - Texture Size Query
960 As per NV_gpu_program4, retrieve the dimensions of the texture depending on
961 the target. For 1D (width), 2D/RECT/CUBE (width, height), 3D (width, height,
962 depth), 1D array (width, layers), 2D array (width, height, layers).
963 Also return the number of accessible levels (last_level - first_level + 1)
966 For components which don't return a resource dimension, their value
973 dst.x = texture\_width(unit, lod)
975 dst.y = texture\_height(unit, lod)
977 dst.z = texture\_depth(unit, lod)
979 dst.w = texture\_levels(unit)
982 .. opcode:: TXQS - Texture Samples Query
984 This retrieves the number of samples in the texture, and stores it
985 into the x component. The other components are undefined.
989 dst.x = texture\_samples(unit)
992 .. opcode:: TG4 - Texture Gather
994 As per ARB_texture_gather, gathers the four texels to be used in a bi-linear
995 filtering operation and packs them into a single register. Only works with
996 2D, 2D array, cubemaps, and cubemaps arrays. For 2D textures, only the
997 addressing modes of the sampler and the top level of any mip pyramid are
998 used. Set W to zero. It behaves like the TEX instruction, but a filtered
999 sample is not generated. The four samples that contribute to filtering are
1000 placed into xyzw in clockwise order, starting with the (u,v) texture
1001 coordinate delta at the following locations (-, +), (+, +), (+, -), (-, -),
1002 where the magnitude of the deltas are half a texel.
1004 PIPE_CAP_TEXTURE_SM5 enhances this instruction to support shadow per-sample
1005 depth compares, single component selection, and a non-constant offset. It
1006 doesn't allow support for the GL independent offset to get i0,j0. This would
1007 require another CAP is hw can do it natively. For now we lower that before
1016 dst = texture\_gather4 (unit, coord, component)
1018 (with SM5 - cube array shadow)
1026 dst = texture\_gather (uint, coord, compare)
1028 .. opcode:: LODQ - level of detail query
1030 Compute the LOD information that the texture pipe would use to access the
1031 texture. The Y component contains the computed LOD lambda_prime. The X
1032 component contains the LOD that will be accessed, based on min/max lod's
1039 dst.xy = lodq(uint, coord);
1042 ^^^^^^^^^^^^^^^^^^^^^^^^
1043 These opcodes are used for integer operations.
1044 Support for these opcodes indicated by PIPE_SHADER_CAP_INTEGERS (all of them?)
1047 .. opcode:: I2F - Signed Integer To Float
1049 Rounding is unspecified (round to nearest even suggested).
1053 dst.x = (float) src.x
1055 dst.y = (float) src.y
1057 dst.z = (float) src.z
1059 dst.w = (float) src.w
1062 .. opcode:: U2F - Unsigned Integer To Float
1064 Rounding is unspecified (round to nearest even suggested).
1068 dst.x = (float) src.x
1070 dst.y = (float) src.y
1072 dst.z = (float) src.z
1074 dst.w = (float) src.w
1077 .. opcode:: F2I - Float to Signed Integer
1079 Rounding is towards zero (truncate).
1080 Values outside signed range (including NaNs) produce undefined results.
1093 .. opcode:: F2U - Float to Unsigned Integer
1095 Rounding is towards zero (truncate).
1096 Values outside unsigned range (including NaNs) produce undefined results.
1100 dst.x = (unsigned) src.x
1102 dst.y = (unsigned) src.y
1104 dst.z = (unsigned) src.z
1106 dst.w = (unsigned) src.w
1109 .. opcode:: UADD - Integer Add
1111 This instruction works the same for signed and unsigned integers.
1112 The low 32bit of the result is returned.
1116 dst.x = src0.x + src1.x
1118 dst.y = src0.y + src1.y
1120 dst.z = src0.z + src1.z
1122 dst.w = src0.w + src1.w
1125 .. opcode:: UMAD - Integer Multiply And Add
1127 This instruction works the same for signed and unsigned integers.
1128 The multiplication returns the low 32bit (as does the result itself).
1132 dst.x = src0.x \times src1.x + src2.x
1134 dst.y = src0.y \times src1.y + src2.y
1136 dst.z = src0.z \times src1.z + src2.z
1138 dst.w = src0.w \times src1.w + src2.w
1141 .. opcode:: UMUL - Integer Multiply
1143 This instruction works the same for signed and unsigned integers.
1144 The low 32bit of the result is returned.
1148 dst.x = src0.x \times src1.x
1150 dst.y = src0.y \times src1.y
1152 dst.z = src0.z \times src1.z
1154 dst.w = src0.w \times src1.w
1157 .. opcode:: IMUL_HI - Signed Integer Multiply High Bits
1159 The high 32bits of the multiplication of 2 signed integers are returned.
1163 dst.x = (src0.x \times src1.x) >> 32
1165 dst.y = (src0.y \times src1.y) >> 32
1167 dst.z = (src0.z \times src1.z) >> 32
1169 dst.w = (src0.w \times src1.w) >> 32
1172 .. opcode:: UMUL_HI - Unsigned Integer Multiply High Bits
1174 The high 32bits of the multiplication of 2 unsigned integers are returned.
1178 dst.x = (src0.x \times src1.x) >> 32
1180 dst.y = (src0.y \times src1.y) >> 32
1182 dst.z = (src0.z \times src1.z) >> 32
1184 dst.w = (src0.w \times src1.w) >> 32
1187 .. opcode:: IDIV - Signed Integer Division
1189 TBD: behavior for division by zero.
1193 dst.x = src0.x \ src1.x
1195 dst.y = src0.y \ src1.y
1197 dst.z = src0.z \ src1.z
1199 dst.w = src0.w \ src1.w
1202 .. opcode:: UDIV - Unsigned Integer Division
1204 For division by zero, 0xffffffff is returned.
1208 dst.x = src0.x \ src1.x
1210 dst.y = src0.y \ src1.y
1212 dst.z = src0.z \ src1.z
1214 dst.w = src0.w \ src1.w
1217 .. opcode:: UMOD - Unsigned Integer Remainder
1219 If second arg is zero, 0xffffffff is returned.
1223 dst.x = src0.x \ src1.x
1225 dst.y = src0.y \ src1.y
1227 dst.z = src0.z \ src1.z
1229 dst.w = src0.w \ src1.w
1232 .. opcode:: NOT - Bitwise Not
1245 .. opcode:: AND - Bitwise And
1249 dst.x = src0.x \& src1.x
1251 dst.y = src0.y \& src1.y
1253 dst.z = src0.z \& src1.z
1255 dst.w = src0.w \& src1.w
1258 .. opcode:: OR - Bitwise Or
1262 dst.x = src0.x | src1.x
1264 dst.y = src0.y | src1.y
1266 dst.z = src0.z | src1.z
1268 dst.w = src0.w | src1.w
1271 .. opcode:: XOR - Bitwise Xor
1275 dst.x = src0.x \oplus src1.x
1277 dst.y = src0.y \oplus src1.y
1279 dst.z = src0.z \oplus src1.z
1281 dst.w = src0.w \oplus src1.w
1284 .. opcode:: IMAX - Maximum of Signed Integers
1288 dst.x = max(src0.x, src1.x)
1290 dst.y = max(src0.y, src1.y)
1292 dst.z = max(src0.z, src1.z)
1294 dst.w = max(src0.w, src1.w)
1297 .. opcode:: UMAX - Maximum of Unsigned Integers
1301 dst.x = max(src0.x, src1.x)
1303 dst.y = max(src0.y, src1.y)
1305 dst.z = max(src0.z, src1.z)
1307 dst.w = max(src0.w, src1.w)
1310 .. opcode:: IMIN - Minimum of Signed Integers
1314 dst.x = min(src0.x, src1.x)
1316 dst.y = min(src0.y, src1.y)
1318 dst.z = min(src0.z, src1.z)
1320 dst.w = min(src0.w, src1.w)
1323 .. opcode:: UMIN - Minimum of Unsigned Integers
1327 dst.x = min(src0.x, src1.x)
1329 dst.y = min(src0.y, src1.y)
1331 dst.z = min(src0.z, src1.z)
1333 dst.w = min(src0.w, src1.w)
1336 .. opcode:: SHL - Shift Left
1338 The shift count is masked with 0x1f before the shift is applied.
1342 dst.x = src0.x << (0x1f \& src1.x)
1344 dst.y = src0.y << (0x1f \& src1.y)
1346 dst.z = src0.z << (0x1f \& src1.z)
1348 dst.w = src0.w << (0x1f \& src1.w)
1351 .. opcode:: ISHR - Arithmetic Shift Right (of Signed Integer)
1353 The shift count is masked with 0x1f before the shift is applied.
1357 dst.x = src0.x >> (0x1f \& src1.x)
1359 dst.y = src0.y >> (0x1f \& src1.y)
1361 dst.z = src0.z >> (0x1f \& src1.z)
1363 dst.w = src0.w >> (0x1f \& src1.w)
1366 .. opcode:: USHR - Logical Shift Right
1368 The shift count is masked with 0x1f before the shift is applied.
1372 dst.x = src0.x >> (unsigned) (0x1f \& src1.x)
1374 dst.y = src0.y >> (unsigned) (0x1f \& src1.y)
1376 dst.z = src0.z >> (unsigned) (0x1f \& src1.z)
1378 dst.w = src0.w >> (unsigned) (0x1f \& src1.w)
1381 .. opcode:: UCMP - Integer Conditional Move
1385 dst.x = src0.x ? src1.x : src2.x
1387 dst.y = src0.y ? src1.y : src2.y
1389 dst.z = src0.z ? src1.z : src2.z
1391 dst.w = src0.w ? src1.w : src2.w
1395 .. opcode:: ISSG - Integer Set Sign
1399 dst.x = (src0.x < 0) ? -1 : (src0.x > 0) ? 1 : 0
1401 dst.y = (src0.y < 0) ? -1 : (src0.y > 0) ? 1 : 0
1403 dst.z = (src0.z < 0) ? -1 : (src0.z > 0) ? 1 : 0
1405 dst.w = (src0.w < 0) ? -1 : (src0.w > 0) ? 1 : 0
1409 .. opcode:: FSLT - Float Set On Less Than (ordered)
1411 Same comparison as SLT but returns integer instead of 1.0/0.0 float
1415 dst.x = (src0.x < src1.x) ? \sim 0 : 0
1417 dst.y = (src0.y < src1.y) ? \sim 0 : 0
1419 dst.z = (src0.z < src1.z) ? \sim 0 : 0
1421 dst.w = (src0.w < src1.w) ? \sim 0 : 0
1424 .. opcode:: ISLT - Signed Integer Set On Less Than
1428 dst.x = (src0.x < src1.x) ? \sim 0 : 0
1430 dst.y = (src0.y < src1.y) ? \sim 0 : 0
1432 dst.z = (src0.z < src1.z) ? \sim 0 : 0
1434 dst.w = (src0.w < src1.w) ? \sim 0 : 0
1437 .. opcode:: USLT - Unsigned Integer Set On Less Than
1441 dst.x = (src0.x < src1.x) ? \sim 0 : 0
1443 dst.y = (src0.y < src1.y) ? \sim 0 : 0
1445 dst.z = (src0.z < src1.z) ? \sim 0 : 0
1447 dst.w = (src0.w < src1.w) ? \sim 0 : 0
1450 .. opcode:: FSGE - Float Set On Greater Equal Than (ordered)
1452 Same comparison as SGE but returns integer instead of 1.0/0.0 float
1456 dst.x = (src0.x >= src1.x) ? \sim 0 : 0
1458 dst.y = (src0.y >= src1.y) ? \sim 0 : 0
1460 dst.z = (src0.z >= src1.z) ? \sim 0 : 0
1462 dst.w = (src0.w >= src1.w) ? \sim 0 : 0
1465 .. opcode:: ISGE - Signed Integer Set On Greater Equal Than
1469 dst.x = (src0.x >= src1.x) ? \sim 0 : 0
1471 dst.y = (src0.y >= src1.y) ? \sim 0 : 0
1473 dst.z = (src0.z >= src1.z) ? \sim 0 : 0
1475 dst.w = (src0.w >= src1.w) ? \sim 0 : 0
1478 .. opcode:: USGE - Unsigned Integer Set On Greater Equal Than
1482 dst.x = (src0.x >= src1.x) ? \sim 0 : 0
1484 dst.y = (src0.y >= src1.y) ? \sim 0 : 0
1486 dst.z = (src0.z >= src1.z) ? \sim 0 : 0
1488 dst.w = (src0.w >= src1.w) ? \sim 0 : 0
1491 .. opcode:: FSEQ - Float Set On Equal (ordered)
1493 Same comparison as SEQ but returns integer instead of 1.0/0.0 float
1497 dst.x = (src0.x == src1.x) ? \sim 0 : 0
1499 dst.y = (src0.y == src1.y) ? \sim 0 : 0
1501 dst.z = (src0.z == src1.z) ? \sim 0 : 0
1503 dst.w = (src0.w == src1.w) ? \sim 0 : 0
1506 .. opcode:: USEQ - Integer Set On Equal
1510 dst.x = (src0.x == src1.x) ? \sim 0 : 0
1512 dst.y = (src0.y == src1.y) ? \sim 0 : 0
1514 dst.z = (src0.z == src1.z) ? \sim 0 : 0
1516 dst.w = (src0.w == src1.w) ? \sim 0 : 0
1519 .. opcode:: FSNE - Float Set On Not Equal (unordered)
1521 Same comparison as SNE but returns integer instead of 1.0/0.0 float
1525 dst.x = (src0.x != src1.x) ? \sim 0 : 0
1527 dst.y = (src0.y != src1.y) ? \sim 0 : 0
1529 dst.z = (src0.z != src1.z) ? \sim 0 : 0
1531 dst.w = (src0.w != src1.w) ? \sim 0 : 0
1534 .. opcode:: USNE - Integer Set On Not Equal
1538 dst.x = (src0.x != src1.x) ? \sim 0 : 0
1540 dst.y = (src0.y != src1.y) ? \sim 0 : 0
1542 dst.z = (src0.z != src1.z) ? \sim 0 : 0
1544 dst.w = (src0.w != src1.w) ? \sim 0 : 0
1547 .. opcode:: INEG - Integer Negate
1562 .. opcode:: IABS - Integer Absolute Value
1576 These opcodes are used for bit-level manipulation of integers.
1578 .. opcode:: IBFE - Signed Bitfield Extract
1580 Like GLSL bitfieldExtract. Extracts a set of bits from the input, and
1581 sign-extends them if the high bit of the extracted window is set.
1585 def ibfe(value, offset, bits):
1586 if offset < 0 or bits < 0 or offset + bits > 32:
1588 if bits == 0: return 0
1589 # Note: >> sign-extends
1590 return (value << (32 - offset - bits)) >> (32 - bits)
1592 .. opcode:: UBFE - Unsigned Bitfield Extract
1594 Like GLSL bitfieldExtract. Extracts a set of bits from the input, without
1599 def ubfe(value, offset, bits):
1600 if offset < 0 or bits < 0 or offset + bits > 32:
1602 if bits == 0: return 0
1603 # Note: >> does not sign-extend
1604 return (value << (32 - offset - bits)) >> (32 - bits)
1606 .. opcode:: BFI - Bitfield Insert
1608 Like GLSL bitfieldInsert. Replaces a bit region of 'base' with the low bits
1613 def bfi(base, insert, offset, bits):
1614 if offset < 0 or bits < 0 or offset + bits > 32:
1616 # << defined such that mask == ~0 when bits == 32, offset == 0
1617 mask = ((1 << bits) - 1) << offset
1618 return ((insert << offset) & mask) | (base & ~mask)
1620 .. opcode:: BREV - Bitfield Reverse
1622 See SM5 instruction BFREV. Reverses the bits of the argument.
1624 .. opcode:: POPC - Population Count
1626 See SM5 instruction COUNTBITS. Counts the number of set bits in the argument.
1628 .. opcode:: LSB - Index of lowest set bit
1630 See SM5 instruction FIRSTBIT_LO. Computes the 0-based index of the first set
1631 bit of the argument. Returns -1 if none are set.
1633 .. opcode:: IMSB - Index of highest non-sign bit
1635 See SM5 instruction FIRSTBIT_SHI. Computes the 0-based index of the highest
1636 non-sign bit of the argument (i.e. highest 0 bit for negative numbers,
1637 highest 1 bit for positive numbers). Returns -1 if all bits are the same
1638 (i.e. for inputs 0 and -1).
1640 .. opcode:: UMSB - Index of highest set bit
1642 See SM5 instruction FIRSTBIT_HI. Computes the 0-based index of the highest
1643 set bit of the argument. Returns -1 if none are set.
1646 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1648 These opcodes are only supported in geometry shaders; they have no meaning
1649 in any other type of shader.
1651 .. opcode:: EMIT - Emit
1653 Generate a new vertex for the current primitive into the specified vertex
1654 stream using the values in the output registers.
1657 .. opcode:: ENDPRIM - End Primitive
1659 Complete the current primitive in the specified vertex stream (consisting of
1660 the emitted vertices), and start a new one.
1666 These opcodes are part of :term:`GLSL`'s opcode set. Support for these
1667 opcodes is determined by a special capability bit, ``GLSL``.
1668 Some require glsl version 1.30 (UIF/BREAKC/SWITCH/CASE/DEFAULT/ENDSWITCH).
1670 .. opcode:: CAL - Subroutine Call
1676 .. opcode:: RET - Subroutine Call Return
1681 .. opcode:: CONT - Continue
1683 Unconditionally moves the point of execution to the instruction after the
1684 last bgnloop. The instruction must appear within a bgnloop/endloop.
1688 Support for CONT is determined by a special capability bit,
1689 ``TGSI_CONT_SUPPORTED``. See :ref:`Screen` for more information.
1692 .. opcode:: BGNLOOP - Begin a Loop
1694 Start a loop. Must have a matching endloop.
1697 .. opcode:: BGNSUB - Begin Subroutine
1699 Starts definition of a subroutine. Must have a matching endsub.
1702 .. opcode:: ENDLOOP - End a Loop
1704 End a loop started with bgnloop.
1707 .. opcode:: ENDSUB - End Subroutine
1709 Ends definition of a subroutine.
1712 .. opcode:: NOP - No Operation
1717 .. opcode:: BRK - Break
1719 Unconditionally moves the point of execution to the instruction after the
1720 next endloop or endswitch. The instruction must appear within a loop/endloop
1721 or switch/endswitch.
1724 .. opcode:: BREAKC - Break Conditional
1726 Conditionally moves the point of execution to the instruction after the
1727 next endloop or endswitch. The instruction must appear within a loop/endloop
1728 or switch/endswitch.
1729 Condition evaluates to true if src0.x != 0 where src0.x is interpreted
1730 as an integer register.
1734 Considered for removal as it's quite inconsistent wrt other opcodes
1735 (could emulate with UIF/BRK/ENDIF).
1738 .. opcode:: IF - Float If
1740 Start an IF ... ELSE .. ENDIF block. Condition evaluates to true if
1744 where src0.x is interpreted as a floating point register.
1747 .. opcode:: UIF - Bitwise If
1749 Start an UIF ... ELSE .. ENDIF block. Condition evaluates to true if
1753 where src0.x is interpreted as an integer register.
1756 .. opcode:: ELSE - Else
1758 Starts an else block, after an IF or UIF statement.
1761 .. opcode:: ENDIF - End If
1763 Ends an IF or UIF block.
1766 .. opcode:: SWITCH - Switch
1768 Starts a C-style switch expression. The switch consists of one or multiple
1769 CASE statements, and at most one DEFAULT statement. Execution of a statement
1770 ends when a BRK is hit, but just like in C falling through to other cases
1771 without a break is allowed. Similarly, DEFAULT label is allowed anywhere not
1772 just as last statement, and fallthrough is allowed into/from it.
1773 CASE src arguments are evaluated at bit level against the SWITCH src argument.
1779 (some instructions here)
1782 (some instructions here)
1785 (some instructions here)
1790 .. opcode:: CASE - Switch case
1792 This represents a switch case label. The src arg must be an integer immediate.
1795 .. opcode:: DEFAULT - Switch default
1797 This represents the default case in the switch, which is taken if no other
1801 .. opcode:: ENDSWITCH - End of switch
1803 Ends a switch expression.
1809 The interpolation instructions allow an input to be interpolated in a
1810 different way than its declaration. This corresponds to the GLSL 4.00
1811 interpolateAt* functions. The first argument of each of these must come from
1812 ``TGSI_FILE_INPUT``.
1814 .. opcode:: INTERP_CENTROID - Interpolate at the centroid
1816 Interpolates the varying specified by src0 at the centroid
1818 .. opcode:: INTERP_SAMPLE - Interpolate at the specified sample
1820 Interpolates the varying specified by src0 at the sample id specified by
1821 src1.x (interpreted as an integer)
1823 .. opcode:: INTERP_OFFSET - Interpolate at the specified offset
1825 Interpolates the varying specified by src0 at the offset src1.xy from the
1826 pixel center (interpreted as floats)
1834 The double-precision opcodes reinterpret four-component vectors into
1835 two-component vectors with doubled precision in each component.
1837 .. opcode:: DABS - Absolute
1845 .. opcode:: DADD - Add
1849 dst.xy = src0.xy + src1.xy
1851 dst.zw = src0.zw + src1.zw
1853 .. opcode:: DSEQ - Set on Equal
1857 dst.x = src0.xy == src1.xy ? \sim 0 : 0
1859 dst.z = src0.zw == src1.zw ? \sim 0 : 0
1861 .. opcode:: DSNE - Set on Equal
1865 dst.x = src0.xy != src1.xy ? \sim 0 : 0
1867 dst.z = src0.zw != src1.zw ? \sim 0 : 0
1869 .. opcode:: DSLT - Set on Less than
1873 dst.x = src0.xy < src1.xy ? \sim 0 : 0
1875 dst.z = src0.zw < src1.zw ? \sim 0 : 0
1877 .. opcode:: DSGE - Set on Greater equal
1881 dst.x = src0.xy >= src1.xy ? \sim 0 : 0
1883 dst.z = src0.zw >= src1.zw ? \sim 0 : 0
1885 .. opcode:: DFRAC - Fraction
1889 dst.xy = src.xy - \lfloor src.xy\rfloor
1891 dst.zw = src.zw - \lfloor src.zw\rfloor
1893 .. opcode:: DTRUNC - Truncate
1897 dst.xy = trunc(src.xy)
1899 dst.zw = trunc(src.zw)
1901 .. opcode:: DCEIL - Ceiling
1905 dst.xy = \lceil src.xy\rceil
1907 dst.zw = \lceil src.zw\rceil
1909 .. opcode:: DFLR - Floor
1913 dst.xy = \lfloor src.xy\rfloor
1915 dst.zw = \lfloor src.zw\rfloor
1917 .. opcode:: DROUND - Fraction
1921 dst.xy = round(src.xy)
1923 dst.zw = round(src.zw)
1925 .. opcode:: DSSG - Set Sign
1929 dst.xy = (src.xy > 0) ? 1.0 : (src.xy < 0) ? -1.0 : 0.0
1931 dst.zw = (src.zw > 0) ? 1.0 : (src.zw < 0) ? -1.0 : 0.0
1933 .. opcode:: DFRACEXP - Convert Number to Fractional and Integral Components
1935 Like the ``frexp()`` routine in many math libraries, this opcode stores the
1936 exponent of its source to ``dst0``, and the significand to ``dst1``, such that
1937 :math:`dst1 \times 2^{dst0} = src` .
1941 dst0.xy = exp(src.xy)
1943 dst1.xy = frac(src.xy)
1945 dst0.zw = exp(src.zw)
1947 dst1.zw = frac(src.zw)
1949 .. opcode:: DLDEXP - Multiply Number by Integral Power of 2
1951 This opcode is the inverse of :opcode:`DFRACEXP`. The second
1952 source is an integer.
1956 dst.xy = src0.xy \times 2^{src1.x}
1958 dst.zw = src0.zw \times 2^{src1.y}
1960 .. opcode:: DMIN - Minimum
1964 dst.xy = min(src0.xy, src1.xy)
1966 dst.zw = min(src0.zw, src1.zw)
1968 .. opcode:: DMAX - Maximum
1972 dst.xy = max(src0.xy, src1.xy)
1974 dst.zw = max(src0.zw, src1.zw)
1976 .. opcode:: DMUL - Multiply
1980 dst.xy = src0.xy \times src1.xy
1982 dst.zw = src0.zw \times src1.zw
1985 .. opcode:: DMAD - Multiply And Add
1989 dst.xy = src0.xy \times src1.xy + src2.xy
1991 dst.zw = src0.zw \times src1.zw + src2.zw
1994 .. opcode:: DFMA - Fused Multiply-Add
1996 Perform a * b + c with no intermediate rounding step.
2000 dst.xy = src0.xy \times src1.xy + src2.xy
2002 dst.zw = src0.zw \times src1.zw + src2.zw
2005 .. opcode:: DDIV - Divide
2009 dst.xy = \frac{src0.xy}{src1.xy}
2011 dst.zw = \frac{src0.zw}{src1.zw}
2014 .. opcode:: DRCP - Reciprocal
2018 dst.xy = \frac{1}{src.xy}
2020 dst.zw = \frac{1}{src.zw}
2022 .. opcode:: DSQRT - Square Root
2026 dst.xy = \sqrt{src.xy}
2028 dst.zw = \sqrt{src.zw}
2030 .. opcode:: DRSQ - Reciprocal Square Root
2034 dst.xy = \frac{1}{\sqrt{src.xy}}
2036 dst.zw = \frac{1}{\sqrt{src.zw}}
2038 .. opcode:: F2D - Float to Double
2042 dst.xy = double(src0.x)
2044 dst.zw = double(src0.y)
2046 .. opcode:: D2F - Double to Float
2050 dst.x = float(src0.xy)
2052 dst.y = float(src0.zw)
2054 .. opcode:: I2D - Int to Double
2058 dst.xy = double(src0.x)
2060 dst.zw = double(src0.y)
2062 .. opcode:: D2I - Double to Int
2066 dst.x = int(src0.xy)
2068 dst.y = int(src0.zw)
2070 .. opcode:: U2D - Unsigned Int to Double
2074 dst.xy = double(src0.x)
2076 dst.zw = double(src0.y)
2078 .. opcode:: D2U - Double to Unsigned Int
2082 dst.x = unsigned(src0.xy)
2084 dst.y = unsigned(src0.zw)
2089 The 64-bit integer opcodes reinterpret four-component vectors into
2090 two-component vectors with 64-bits in each component.
2092 .. opcode:: I64ABS - 64-bit Integer Absolute Value
2100 .. opcode:: I64NEG - 64-bit Integer Negate
2110 .. opcode:: I64SSG - 64-bit Integer Set Sign
2114 dst.xy = (src0.xy < 0) ? -1 : (src0.xy > 0) ? 1 : 0
2116 dst.zw = (src0.zw < 0) ? -1 : (src0.zw > 0) ? 1 : 0
2118 .. opcode:: U64ADD - 64-bit Integer Add
2122 dst.xy = src0.xy + src1.xy
2124 dst.zw = src0.zw + src1.zw
2126 .. opcode:: U64MUL - 64-bit Integer Multiply
2130 dst.xy = src0.xy * src1.xy
2132 dst.zw = src0.zw * src1.zw
2134 .. opcode:: U64SEQ - 64-bit Integer Set on Equal
2138 dst.x = src0.xy == src1.xy ? \sim 0 : 0
2140 dst.z = src0.zw == src1.zw ? \sim 0 : 0
2142 .. opcode:: U64SNE - 64-bit Integer Set on Not Equal
2146 dst.x = src0.xy != src1.xy ? \sim 0 : 0
2148 dst.z = src0.zw != src1.zw ? \sim 0 : 0
2150 .. opcode:: U64SLT - 64-bit Unsigned Integer Set on Less Than
2154 dst.x = src0.xy < src1.xy ? \sim 0 : 0
2156 dst.z = src0.zw < src1.zw ? \sim 0 : 0
2158 .. opcode:: U64SGE - 64-bit Unsigned Integer Set on Greater Equal
2162 dst.x = src0.xy >= src1.xy ? \sim 0 : 0
2164 dst.z = src0.zw >= src1.zw ? \sim 0 : 0
2166 .. opcode:: I64SLT - 64-bit Signed Integer Set on Less Than
2170 dst.x = src0.xy < src1.xy ? \sim 0 : 0
2172 dst.z = src0.zw < src1.zw ? \sim 0 : 0
2174 .. opcode:: I64SGE - 64-bit Signed Integer Set on Greater Equal
2178 dst.x = src0.xy >= src1.xy ? \sim 0 : 0
2180 dst.z = src0.zw >= src1.zw ? \sim 0 : 0
2182 .. opcode:: I64MIN - Minimum of 64-bit Signed Integers
2186 dst.xy = min(src0.xy, src1.xy)
2188 dst.zw = min(src0.zw, src1.zw)
2190 .. opcode:: U64MIN - Minimum of 64-bit Unsigned Integers
2194 dst.xy = min(src0.xy, src1.xy)
2196 dst.zw = min(src0.zw, src1.zw)
2198 .. opcode:: I64MAX - Maximum of 64-bit Signed Integers
2202 dst.xy = max(src0.xy, src1.xy)
2204 dst.zw = max(src0.zw, src1.zw)
2206 .. opcode:: U64MAX - Maximum of 64-bit Unsigned Integers
2210 dst.xy = max(src0.xy, src1.xy)
2212 dst.zw = max(src0.zw, src1.zw)
2214 .. opcode:: U64SHL - Shift Left 64-bit Unsigned Integer
2216 The shift count is masked with 0x3f before the shift is applied.
2220 dst.xy = src0.xy << (0x3f \& src1.x)
2222 dst.zw = src0.zw << (0x3f \& src1.y)
2224 .. opcode:: I64SHR - Arithmetic Shift Right (of 64-bit Signed Integer)
2226 The shift count is masked with 0x3f before the shift is applied.
2230 dst.xy = src0.xy >> (0x3f \& src1.x)
2232 dst.zw = src0.zw >> (0x3f \& src1.y)
2234 .. opcode:: U64SHR - Logical Shift Right (of 64-bit Unsigned Integer)
2236 The shift count is masked with 0x3f before the shift is applied.
2240 dst.xy = src0.xy >> (unsigned) (0x3f \& src1.x)
2242 dst.zw = src0.zw >> (unsigned) (0x3f \& src1.y)
2244 .. opcode:: I64DIV - 64-bit Signed Integer Division
2248 dst.xy = src0.xy \ src1.xy
2250 dst.zw = src0.zw \ src1.zw
2252 .. opcode:: U64DIV - 64-bit Unsigned Integer Division
2256 dst.xy = src0.xy \ src1.xy
2258 dst.zw = src0.zw \ src1.zw
2260 .. opcode:: U64MOD - 64-bit Unsigned Integer Remainder
2264 dst.xy = src0.xy \bmod src1.xy
2266 dst.zw = src0.zw \bmod src1.zw
2268 .. opcode:: I64MOD - 64-bit Signed Integer Remainder
2272 dst.xy = src0.xy \bmod src1.xy
2274 dst.zw = src0.zw \bmod src1.zw
2276 .. opcode:: F2U64 - Float to 64-bit Unsigned Int
2280 dst.xy = (uint64_t) src0.x
2282 dst.zw = (uint64_t) src0.y
2284 .. opcode:: F2I64 - Float to 64-bit Int
2288 dst.xy = (int64_t) src0.x
2290 dst.zw = (int64_t) src0.y
2292 .. opcode:: U2I64 - Unsigned Integer to 64-bit Integer
2294 This is a zero extension.
2298 dst.xy = (uint64_t) src0.x
2300 dst.zw = (uint64_t) src0.y
2302 .. opcode:: I2I64 - Signed Integer to 64-bit Integer
2304 This is a sign extension.
2308 dst.xy = (int64_t) src0.x
2310 dst.zw = (int64_t) src0.y
2312 .. opcode:: D2U64 - Double to 64-bit Unsigned Int
2316 dst.xy = (uint64_t) src0.xy
2318 dst.zw = (uint64_t) src0.zw
2320 .. opcode:: D2I64 - Double to 64-bit Int
2324 dst.xy = (int64_t) src0.xy
2326 dst.zw = (int64_t) src0.zw
2328 .. opcode:: U642F - 64-bit unsigned integer to float
2332 dst.x = (float) src0.xy
2334 dst.y = (float) src0.zw
2336 .. opcode:: I642F - 64-bit Int to Float
2340 dst.x = (float) src0.xy
2342 dst.y = (float) src0.zw
2344 .. opcode:: U642D - 64-bit unsigned integer to double
2348 dst.xy = (double) src0.xy
2350 dst.zw = (double) src0.zw
2352 .. opcode:: I642D - 64-bit Int to double
2356 dst.xy = (double) src0.xy
2358 dst.zw = (double) src0.zw
2360 .. _samplingopcodes:
2362 Resource Sampling Opcodes
2363 ^^^^^^^^^^^^^^^^^^^^^^^^^
2365 Those opcodes follow very closely semantics of the respective Direct3D
2366 instructions. If in doubt double check Direct3D documentation.
2367 Note that the swizzle on SVIEW (src1) determines texel swizzling
2372 Using provided address, sample data from the specified texture using the
2373 filtering mode identified by the given sampler. The source data may come from
2374 any resource type other than buffers.
2376 Syntax: ``SAMPLE dst, address, sampler_view, sampler``
2378 Example: ``SAMPLE TEMP[0], TEMP[1], SVIEW[0], SAMP[0]``
2380 .. opcode:: SAMPLE_I
2382 Simplified alternative to the SAMPLE instruction. Using the provided
2383 integer address, SAMPLE_I fetches data from the specified sampler view
2384 without any filtering. The source data may come from any resource type
2387 Syntax: ``SAMPLE_I dst, address, sampler_view``
2389 Example: ``SAMPLE_I TEMP[0], TEMP[1], SVIEW[0]``
2391 The 'address' is specified as unsigned integers. If the 'address' is out of
2392 range [0...(# texels - 1)] the result of the fetch is always 0 in all
2393 components. As such the instruction doesn't honor address wrap modes, in
2394 cases where that behavior is desirable 'SAMPLE' instruction should be used.
2395 address.w always provides an unsigned integer mipmap level. If the value is
2396 out of the range then the instruction always returns 0 in all components.
2397 address.yz are ignored for buffers and 1d textures. address.z is ignored
2398 for 1d texture arrays and 2d textures.
2400 For 1D texture arrays address.y provides the array index (also as unsigned
2401 integer). If the value is out of the range of available array indices
2402 [0... (array size - 1)] then the opcode always returns 0 in all components.
2403 For 2D texture arrays address.z provides the array index, otherwise it
2404 exhibits the same behavior as in the case for 1D texture arrays. The exact
2405 semantics of the source address are presented in the table below:
2407 +---------------------------+----+-----+-----+---------+
2408 | resource type | X | Y | Z | W |
2409 +===========================+====+=====+=====+=========+
2410 | ``PIPE_BUFFER`` | x | | | ignored |
2411 +---------------------------+----+-----+-----+---------+
2412 | ``PIPE_TEXTURE_1D`` | x | | | mpl |
2413 +---------------------------+----+-----+-----+---------+
2414 | ``PIPE_TEXTURE_2D`` | x | y | | mpl |
2415 +---------------------------+----+-----+-----+---------+
2416 | ``PIPE_TEXTURE_3D`` | x | y | z | mpl |
2417 +---------------------------+----+-----+-----+---------+
2418 | ``PIPE_TEXTURE_RECT`` | x | y | | mpl |
2419 +---------------------------+----+-----+-----+---------+
2420 | ``PIPE_TEXTURE_CUBE`` | not allowed as source |
2421 +---------------------------+----+-----+-----+---------+
2422 | ``PIPE_TEXTURE_1D_ARRAY`` | x | idx | | mpl |
2423 +---------------------------+----+-----+-----+---------+
2424 | ``PIPE_TEXTURE_2D_ARRAY`` | x | y | idx | mpl |
2425 +---------------------------+----+-----+-----+---------+
2427 Where 'mpl' is a mipmap level and 'idx' is the array index.
2429 .. opcode:: SAMPLE_I_MS
2431 Just like SAMPLE_I but allows fetch data from multi-sampled surfaces.
2433 Syntax: ``SAMPLE_I_MS dst, address, sampler_view, sample``
2435 .. opcode:: SAMPLE_B
2437 Just like the SAMPLE instruction with the exception that an additional bias
2438 is applied to the level of detail computed as part of the instruction
2441 Syntax: ``SAMPLE_B dst, address, sampler_view, sampler, lod_bias``
2443 Example: ``SAMPLE_B TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2].x``
2445 .. opcode:: SAMPLE_C
2447 Similar to the SAMPLE instruction but it performs a comparison filter. The
2448 operands to SAMPLE_C are identical to SAMPLE, except that there is an
2449 additional float32 operand, reference value, which must be a register with
2450 single-component, or a scalar literal. SAMPLE_C makes the hardware use the
2451 current samplers compare_func (in pipe_sampler_state) to compare reference
2452 value against the red component value for the surce resource at each texel
2453 that the currently configured texture filter covers based on the provided
2456 Syntax: ``SAMPLE_C dst, address, sampler_view.r, sampler, ref_value``
2458 Example: ``SAMPLE_C TEMP[0], TEMP[1], SVIEW[0].r, SAMP[0], TEMP[2].x``
2460 .. opcode:: SAMPLE_C_LZ
2462 Same as SAMPLE_C, but LOD is 0 and derivatives are ignored. The LZ stands
2465 Syntax: ``SAMPLE_C_LZ dst, address, sampler_view.r, sampler, ref_value``
2467 Example: ``SAMPLE_C_LZ TEMP[0], TEMP[1], SVIEW[0].r, SAMP[0], TEMP[2].x``
2470 .. opcode:: SAMPLE_D
2472 SAMPLE_D is identical to the SAMPLE opcode except that the derivatives for
2473 the source address in the x direction and the y direction are provided by
2476 Syntax: ``SAMPLE_D dst, address, sampler_view, sampler, der_x, der_y``
2478 Example: ``SAMPLE_D TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2], TEMP[3]``
2480 .. opcode:: SAMPLE_L
2482 SAMPLE_L is identical to the SAMPLE opcode except that the LOD is provided
2483 directly as a scalar value, representing no anisotropy.
2485 Syntax: ``SAMPLE_L dst, address, sampler_view, sampler, explicit_lod``
2487 Example: ``SAMPLE_L TEMP[0], TEMP[1], SVIEW[0], SAMP[0], TEMP[2].x``
2491 Gathers the four texels to be used in a bi-linear filtering operation and
2492 packs them into a single register. Only works with 2D, 2D array, cubemaps,
2493 and cubemaps arrays. For 2D textures, only the addressing modes of the
2494 sampler and the top level of any mip pyramid are used. Set W to zero. It
2495 behaves like the SAMPLE instruction, but a filtered sample is not
2496 generated. The four samples that contribute to filtering are placed into
2497 xyzw in counter-clockwise order, starting with the (u,v) texture coordinate
2498 delta at the following locations (-, +), (+, +), (+, -), (-, -), where the
2499 magnitude of the deltas are half a texel.
2502 .. opcode:: SVIEWINFO
2504 Query the dimensions of a given sampler view. dst receives width, height,
2505 depth or array size and number of mipmap levels as int4. The dst can have a
2506 writemask which will specify what info is the caller interested in.
2508 Syntax: ``SVIEWINFO dst, src_mip_level, sampler_view``
2510 Example: ``SVIEWINFO TEMP[0], TEMP[1].x, SVIEW[0]``
2512 src_mip_level is an unsigned integer scalar. If it's out of range then
2513 returns 0 for width, height and depth/array size but the total number of
2514 mipmap is still returned correctly for the given sampler view. The returned
2515 width, height and depth values are for the mipmap level selected by the
2516 src_mip_level and are in the number of texels. For 1d texture array width
2517 is in dst.x, array size is in dst.y and dst.z is 0. The number of mipmaps is
2518 still in dst.w. In contrast to d3d10 resinfo, there's no way in the tgsi
2519 instruction encoding to specify the return type (float/rcpfloat/uint), hence
2520 always using uint. Also, unlike the SAMPLE instructions, the swizzle on src1
2521 resinfo allowing swizzling dst values is ignored (due to the interaction
2522 with rcpfloat modifier which requires some swizzle handling in the state
2525 .. opcode:: SAMPLE_POS
2527 Query the position of a given sample. dst receives float4 (x, y, 0, 0)
2528 indicated where the sample is located. If the resource is not a multi-sample
2529 resource and not a render target, the result is 0.
2531 .. opcode:: SAMPLE_INFO
2533 dst receives number of samples in x. If the resource is not a multi-sample
2534 resource and not a render target, the result is 0.
2537 .. _resourceopcodes:
2539 Resource Access Opcodes
2540 ^^^^^^^^^^^^^^^^^^^^^^^
2542 .. opcode:: LOAD - Fetch data from a shader buffer or image
2544 Syntax: ``LOAD dst, resource, address``
2546 Example: ``LOAD TEMP[0], BUFFER[0], TEMP[1]``
2548 Using the provided integer address, LOAD fetches data
2549 from the specified buffer or texture without any
2552 The 'address' is specified as a vector of unsigned
2553 integers. If the 'address' is out of range the result
2556 Only the first mipmap level of a resource can be read
2557 from using this instruction.
2559 For 1D or 2D texture arrays, the array index is
2560 provided as an unsigned integer in address.y or
2561 address.z, respectively. address.yz are ignored for
2562 buffers and 1D textures. address.z is ignored for 1D
2563 texture arrays and 2D textures. address.w is always
2566 A swizzle suffix may be added to the resource argument
2567 this will cause the resource data to be swizzled accordingly.
2569 .. opcode:: STORE - Write data to a shader resource
2571 Syntax: ``STORE resource, address, src``
2573 Example: ``STORE BUFFER[0], TEMP[0], TEMP[1]``
2575 Using the provided integer address, STORE writes data
2576 to the specified buffer or texture.
2578 The 'address' is specified as a vector of unsigned
2579 integers. If the 'address' is out of range the result
2582 Only the first mipmap level of a resource can be
2583 written to using this instruction.
2585 For 1D or 2D texture arrays, the array index is
2586 provided as an unsigned integer in address.y or
2587 address.z, respectively. address.yz are ignored for
2588 buffers and 1D textures. address.z is ignored for 1D
2589 texture arrays and 2D textures. address.w is always
2592 .. opcode:: RESQ - Query information about a resource
2594 Syntax: ``RESQ dst, resource``
2596 Example: ``RESQ TEMP[0], BUFFER[0]``
2598 Returns information about the buffer or image resource. For buffer
2599 resources, the size (in bytes) is returned in the x component. For
2600 image resources, .xyz will contain the width/height/layers of the
2601 image, while .w will contain the number of samples for multi-sampled
2604 .. opcode:: FBFETCH - Load data from framebuffer
2606 Syntax: ``FBFETCH dst, output``
2608 Example: ``FBFETCH TEMP[0], OUT[0]``
2610 This is only valid on ``COLOR`` semantic outputs. Returns the color
2611 of the current position in the framebuffer from before this fragment
2612 shader invocation. May return the same value from multiple calls for
2613 a particular output within a single invocation. Note that result may
2614 be undefined if a fragment is drawn multiple times without a blend
2618 .. _threadsyncopcodes:
2620 Inter-thread synchronization opcodes
2621 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2623 These opcodes are intended for communication between threads running
2624 within the same compute grid. For now they're only valid in compute
2627 .. opcode:: MFENCE - Memory fence
2629 Syntax: ``MFENCE resource``
2631 Example: ``MFENCE RES[0]``
2633 This opcode forces strong ordering between any memory access
2634 operations that affect the specified resource. This means that
2635 previous loads and stores (and only those) will be performed and
2636 visible to other threads before the program execution continues.
2639 .. opcode:: LFENCE - Load memory fence
2641 Syntax: ``LFENCE resource``
2643 Example: ``LFENCE RES[0]``
2645 Similar to MFENCE, but it only affects the ordering of memory loads.
2648 .. opcode:: SFENCE - Store memory fence
2650 Syntax: ``SFENCE resource``
2652 Example: ``SFENCE RES[0]``
2654 Similar to MFENCE, but it only affects the ordering of memory stores.
2657 .. opcode:: BARRIER - Thread group barrier
2661 This opcode suspends the execution of the current thread until all
2662 the remaining threads in the working group reach the same point of
2663 the program. Results are unspecified if any of the remaining
2664 threads terminates or never reaches an executed BARRIER instruction.
2666 .. opcode:: MEMBAR - Memory barrier
2670 This opcode waits for the completion of all memory accesses based on
2671 the type passed in. The type is an immediate bitfield with the following
2674 Bit 0: Shader storage buffers
2675 Bit 1: Atomic buffers
2677 Bit 3: Shared memory
2680 These may be passed in in any combination. An implementation is free to not
2681 distinguish between these as it sees fit. However these map to all the
2682 possibilities made available by GLSL.
2689 These opcodes provide atomic variants of some common arithmetic and
2690 logical operations. In this context atomicity means that another
2691 concurrent memory access operation that affects the same memory
2692 location is guaranteed to be performed strictly before or after the
2693 entire execution of the atomic operation. The resource may be a buffer
2694 or an image. In the case of an image, the offset works the same as for
2695 ``LOAD`` and ``STORE``, specified above. These atomic operations may
2696 only be used with 32-bit integer image formats.
2698 .. opcode:: ATOMUADD - Atomic integer addition
2700 Syntax: ``ATOMUADD dst, resource, offset, src``
2702 Example: ``ATOMUADD TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2704 The following operation is performed atomically:
2708 dst_x = resource[offset]
2710 resource[offset] = dst_x + src_x
2713 .. opcode:: ATOMXCHG - Atomic exchange
2715 Syntax: ``ATOMXCHG dst, resource, offset, src``
2717 Example: ``ATOMXCHG TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2719 The following operation is performed atomically:
2723 dst_x = resource[offset]
2725 resource[offset] = src_x
2728 .. opcode:: ATOMCAS - Atomic compare-and-exchange
2730 Syntax: ``ATOMCAS dst, resource, offset, cmp, src``
2732 Example: ``ATOMCAS TEMP[0], BUFFER[0], TEMP[1], TEMP[2], TEMP[3]``
2734 The following operation is performed atomically:
2738 dst_x = resource[offset]
2740 resource[offset] = (dst_x == cmp_x ? src_x : dst_x)
2743 .. opcode:: ATOMAND - Atomic bitwise And
2745 Syntax: ``ATOMAND dst, resource, offset, src``
2747 Example: ``ATOMAND TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2749 The following operation is performed atomically:
2753 dst_x = resource[offset]
2755 resource[offset] = dst_x \& src_x
2758 .. opcode:: ATOMOR - Atomic bitwise Or
2760 Syntax: ``ATOMOR dst, resource, offset, src``
2762 Example: ``ATOMOR TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2764 The following operation is performed atomically:
2768 dst_x = resource[offset]
2770 resource[offset] = dst_x | src_x
2773 .. opcode:: ATOMXOR - Atomic bitwise Xor
2775 Syntax: ``ATOMXOR dst, resource, offset, src``
2777 Example: ``ATOMXOR TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2779 The following operation is performed atomically:
2783 dst_x = resource[offset]
2785 resource[offset] = dst_x \oplus src_x
2788 .. opcode:: ATOMUMIN - Atomic unsigned minimum
2790 Syntax: ``ATOMUMIN dst, resource, offset, src``
2792 Example: ``ATOMUMIN TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2794 The following operation is performed atomically:
2798 dst_x = resource[offset]
2800 resource[offset] = (dst_x < src_x ? dst_x : src_x)
2803 .. opcode:: ATOMUMAX - Atomic unsigned maximum
2805 Syntax: ``ATOMUMAX dst, resource, offset, src``
2807 Example: ``ATOMUMAX TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2809 The following operation is performed atomically:
2813 dst_x = resource[offset]
2815 resource[offset] = (dst_x > src_x ? dst_x : src_x)
2818 .. opcode:: ATOMIMIN - Atomic signed minimum
2820 Syntax: ``ATOMIMIN dst, resource, offset, src``
2822 Example: ``ATOMIMIN TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2824 The following operation is performed atomically:
2828 dst_x = resource[offset]
2830 resource[offset] = (dst_x < src_x ? dst_x : src_x)
2833 .. opcode:: ATOMIMAX - Atomic signed maximum
2835 Syntax: ``ATOMIMAX dst, resource, offset, src``
2837 Example: ``ATOMIMAX TEMP[0], BUFFER[0], TEMP[1], TEMP[2]``
2839 The following operation is performed atomically:
2843 dst_x = resource[offset]
2845 resource[offset] = (dst_x > src_x ? dst_x : src_x)
2853 These opcodes compare the given value across the shader invocations
2854 running in the current SIMD group. The details of exactly which
2855 invocations get compared are implementation-defined, and it would be a
2856 correct implementation to only ever consider the current thread's
2857 value. (i.e. SIMD group of 1). The argument is treated as a boolean.
2859 .. opcode:: VOTE_ANY - Value is set in any of the current invocations
2861 .. opcode:: VOTE_ALL - Value is set in all of the current invocations
2863 .. opcode:: VOTE_EQ - Value is the same in all of the current invocations
2866 Explanation of symbols used
2867 ------------------------------
2874 :math:`|x|` Absolute value of `x`.
2876 :math:`\lceil x \rceil` Ceiling of `x`.
2878 clamp(x,y,z) Clamp x between y and z.
2879 (x < y) ? y : (x > z) ? z : x
2881 :math:`\lfloor x\rfloor` Floor of `x`.
2883 :math:`\log_2{x}` Logarithm of `x`, base 2.
2885 max(x,y) Maximum of x and y.
2888 min(x,y) Minimum of x and y.
2891 partialx(x) Derivative of x relative to fragment's X.
2893 partialy(x) Derivative of x relative to fragment's Y.
2895 pop() Pop from stack.
2897 :math:`x^y` `x` to the power `y`.
2899 push(x) Push x on stack.
2903 trunc(x) Truncate x, i.e. drop the fraction bits.
2910 discard Discard fragment.
2914 target Label of target instruction.
2925 Declares a register that is will be referenced as an operand in Instruction
2928 File field contains register file that is being declared and is one
2931 UsageMask field specifies which of the register components can be accessed
2932 and is one of TGSI_WRITEMASK.
2934 The Local flag specifies that a given value isn't intended for
2935 subroutine parameter passing and, as a result, the implementation
2936 isn't required to give any guarantees of it being preserved across
2937 subroutine boundaries. As it's merely a compiler hint, the
2938 implementation is free to ignore it.
2940 If Dimension flag is set to 1, a Declaration Dimension token follows.
2942 If Semantic flag is set to 1, a Declaration Semantic token follows.
2944 If Interpolate flag is set to 1, a Declaration Interpolate token follows.
2946 If file is TGSI_FILE_RESOURCE, a Declaration Resource token follows.
2948 If Array flag is set to 1, a Declaration Array token follows.
2951 ^^^^^^^^^^^^^^^^^^^^^^^^
2953 Declarations can optional have an ArrayID attribute which can be referred by
2954 indirect addressing operands. An ArrayID of zero is reserved and treated as
2955 if no ArrayID is specified.
2957 If an indirect addressing operand refers to a specific declaration by using
2958 an ArrayID only the registers in this declaration are guaranteed to be
2959 accessed, accessing any register outside this declaration results in undefined
2960 behavior. Note that for compatibility the effective index is zero-based and
2961 not relative to the specified declaration
2963 If no ArrayID is specified with an indirect addressing operand the whole
2964 register file might be accessed by this operand. This is strongly discouraged
2965 and will prevent packing of scalar/vec2 arrays and effective alias analysis.
2966 This is only legal for TEMP and CONST register files.
2968 Declaration Semantic
2969 ^^^^^^^^^^^^^^^^^^^^^^^^
2971 Vertex and fragment shader input and output registers may be labeled
2972 with semantic information consisting of a name and index.
2974 Follows Declaration token if Semantic bit is set.
2976 Since its purpose is to link a shader with other stages of the pipeline,
2977 it is valid to follow only those Declaration tokens that declare a register
2978 either in INPUT or OUTPUT file.
2980 SemanticName field contains the semantic name of the register being declared.
2981 There is no default value.
2983 SemanticIndex is an optional subscript that can be used to distinguish
2984 different register declarations with the same semantic name. The default value
2987 The meanings of the individual semantic names are explained in the following
2990 TGSI_SEMANTIC_POSITION
2991 """"""""""""""""""""""
2993 For vertex shaders, TGSI_SEMANTIC_POSITION indicates the vertex shader
2994 output register which contains the homogeneous vertex position in the clip
2995 space coordinate system. After clipping, the X, Y and Z components of the
2996 vertex will be divided by the W value to get normalized device coordinates.
2998 For fragment shaders, TGSI_SEMANTIC_POSITION is used to indicate that
2999 fragment shader input (or system value, depending on which one is
3000 supported by the driver) contains the fragment's window position. The X
3001 component starts at zero and always increases from left to right.
3002 The Y component starts at zero and always increases but Y=0 may either
3003 indicate the top of the window or the bottom depending on the fragment
3004 coordinate origin convention (see TGSI_PROPERTY_FS_COORD_ORIGIN).
3005 The Z coordinate ranges from 0 to 1 to represent depth from the front
3006 to the back of the Z buffer. The W component contains the interpolated
3007 reciprocal of the vertex position W component (corresponding to gl_Fragcoord,
3008 but unlike d3d10 which interpolates the same 1/w but then gives back
3009 the reciprocal of the interpolated value).
3011 Fragment shaders may also declare an output register with
3012 TGSI_SEMANTIC_POSITION. Only the Z component is writable. This allows
3013 the fragment shader to change the fragment's Z position.
3020 For vertex shader outputs or fragment shader inputs/outputs, this
3021 label indicates that the register contains an R,G,B,A color.
3023 Several shader inputs/outputs may contain colors so the semantic index
3024 is used to distinguish them. For example, color[0] may be the diffuse
3025 color while color[1] may be the specular color.
3027 This label is needed so that the flat/smooth shading can be applied
3028 to the right interpolants during rasterization.
3032 TGSI_SEMANTIC_BCOLOR
3033 """"""""""""""""""""
3035 Back-facing colors are only used for back-facing polygons, and are only valid
3036 in vertex shader outputs. After rasterization, all polygons are front-facing
3037 and COLOR and BCOLOR end up occupying the same slots in the fragment shader,
3038 so all BCOLORs effectively become regular COLORs in the fragment shader.
3044 Vertex shader inputs and outputs and fragment shader inputs may be
3045 labeled with TGSI_SEMANTIC_FOG to indicate that the register contains
3046 a fog coordinate. Typically, the fragment shader will use the fog coordinate
3047 to compute a fog blend factor which is used to blend the normal fragment color
3048 with a constant fog color. But fog coord really is just an ordinary vec4
3049 register like regular semantics.
3055 Vertex shader input and output registers may be labeled with
3056 TGIS_SEMANTIC_PSIZE to indicate that the register contains a point size
3057 in the form (S, 0, 0, 1). The point size controls the width or diameter
3058 of points for rasterization. This label cannot be used in fragment
3061 When using this semantic, be sure to set the appropriate state in the
3062 :ref:`rasterizer` first.
3065 TGSI_SEMANTIC_TEXCOORD
3066 """"""""""""""""""""""
3068 Only available if PIPE_CAP_TGSI_TEXCOORD is exposed !
3070 Vertex shader outputs and fragment shader inputs may be labeled with
3071 this semantic to make them replaceable by sprite coordinates via the
3072 sprite_coord_enable state in the :ref:`rasterizer`.
3073 The semantic index permitted with this semantic is limited to <= 7.
3075 If the driver does not support TEXCOORD, sprite coordinate replacement
3076 applies to inputs with the GENERIC semantic instead.
3078 The intended use case for this semantic is gl_TexCoord.
3081 TGSI_SEMANTIC_PCOORD
3082 """"""""""""""""""""
3084 Only available if PIPE_CAP_TGSI_TEXCOORD is exposed !
3086 Fragment shader inputs may be labeled with TGSI_SEMANTIC_PCOORD to indicate
3087 that the register contains sprite coordinates in the form (x, y, 0, 1), if
3088 the current primitive is a point and point sprites are enabled. Otherwise,
3089 the contents of the register are undefined.
3091 The intended use case for this semantic is gl_PointCoord.
3094 TGSI_SEMANTIC_GENERIC
3095 """""""""""""""""""""
3097 All vertex/fragment shader inputs/outputs not labeled with any other
3098 semantic label can be considered to be generic attributes. Typical
3099 uses of generic inputs/outputs are texcoords and user-defined values.
3102 TGSI_SEMANTIC_NORMAL
3103 """"""""""""""""""""
3105 Indicates that a vertex shader input is a normal vector. This is
3106 typically only used for legacy graphics APIs.
3112 This label applies to fragment shader inputs (or system values,
3113 depending on which one is supported by the driver) and indicates that
3114 the register contains front/back-face information.
3116 If it is an input, it will be a floating-point vector in the form (F, 0, 0, 1),
3117 where F will be positive when the fragment belongs to a front-facing polygon,
3118 and negative when the fragment belongs to a back-facing polygon.
3120 If it is a system value, it will be an integer vector in the form (F, 0, 0, 1),
3121 where F is 0xffffffff when the fragment belongs to a front-facing polygon and
3122 0 when the fragment belongs to a back-facing polygon.
3125 TGSI_SEMANTIC_EDGEFLAG
3126 """"""""""""""""""""""
3128 For vertex shaders, this sematic label indicates that an input or
3129 output is a boolean edge flag. The register layout is [F, x, x, x]
3130 where F is 0.0 or 1.0 and x = don't care. Normally, the vertex shader
3131 simply copies the edge flag input to the edgeflag output.
3133 Edge flags are used to control which lines or points are actually
3134 drawn when the polygon mode converts triangles/quads/polygons into
3138 TGSI_SEMANTIC_STENCIL
3139 """""""""""""""""""""
3141 For fragment shaders, this semantic label indicates that an output
3142 is a writable stencil reference value. Only the Y component is writable.
3143 This allows the fragment shader to change the fragments stencilref value.
3146 TGSI_SEMANTIC_VIEWPORT_INDEX
3147 """"""""""""""""""""""""""""
3149 For geometry shaders, this semantic label indicates that an output
3150 contains the index of the viewport (and scissor) to use.
3151 This is an integer value, and only the X component is used.
3157 For geometry shaders, this semantic label indicates that an output
3158 contains the layer value to use for the color and depth/stencil surfaces.
3159 This is an integer value, and only the X component is used.
3160 (Also known as rendertarget array index.)
3163 TGSI_SEMANTIC_CULLDIST
3164 """"""""""""""""""""""
3166 Used as distance to plane for performing application-defined culling
3167 of individual primitives against a plane. When components of vertex
3168 elements are given this label, these values are assumed to be a
3169 float32 signed distance to a plane. Primitives will be completely
3170 discarded if the plane distance for all of the vertices in the
3171 primitive are < 0. If a vertex has a cull distance of NaN, that
3172 vertex counts as "out" (as if its < 0);
3173 The limits on both clip and cull distances are bound
3174 by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT define which defines
3175 the maximum number of components that can be used to hold the
3176 distances and by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
3177 which specifies the maximum number of registers which can be
3178 annotated with those semantics.
3181 TGSI_SEMANTIC_CLIPDIST
3182 """"""""""""""""""""""
3184 Note this covers clipping and culling distances.
3186 When components of vertex elements are identified this way, these
3187 values are each assumed to be a float32 signed distance to a plane.
3190 Primitive setup only invokes rasterization on pixels for which
3191 the interpolated plane distances are >= 0.
3194 Primitives will be completely discarded if the plane distance
3195 for all of the vertices in the primitive are < 0.
3196 If a vertex has a cull distance of NaN, that vertex counts as "out"
3199 Multiple clip/cull planes can be implemented simultaneously, by
3200 annotating multiple components of one or more vertex elements with
3201 the above specified semantic.
3202 The limits on both clip and cull distances are bound
3203 by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_COUNT define which defines
3204 the maximum number of components that can be used to hold the
3205 distances and by the PIPE_MAX_CLIP_OR_CULL_DISTANCE_ELEMENT_COUNT
3206 which specifies the maximum number of registers which can be
3207 annotated with those semantics.
3208 The properties NUM_CLIPDIST_ENABLED and NUM_CULLDIST_ENABLED
3209 are used to divide up the 2 x vec4 space between clipping and culling.
3211 TGSI_SEMANTIC_SAMPLEID
3212 """"""""""""""""""""""
3214 For fragment shaders, this semantic label indicates that a system value
3215 contains the current sample id (i.e. gl_SampleID).
3216 This is an integer value, and only the X component is used.
3218 TGSI_SEMANTIC_SAMPLEPOS
3219 """""""""""""""""""""""
3221 For fragment shaders, this semantic label indicates that a system value
3222 contains the current sample's position (i.e. gl_SamplePosition). Only the X
3223 and Y values are used.
3225 TGSI_SEMANTIC_SAMPLEMASK
3226 """"""""""""""""""""""""
3228 For fragment shaders, this semantic label indicates that an output contains
3229 the sample mask used to disable further sample processing
3230 (i.e. gl_SampleMask). Only the X value is used, up to 32x MS.
3232 TGSI_SEMANTIC_INVOCATIONID
3233 """"""""""""""""""""""""""
3235 For geometry shaders, this semantic label indicates that a system value
3236 contains the current invocation id (i.e. gl_InvocationID).
3237 This is an integer value, and only the X component is used.
3239 TGSI_SEMANTIC_INSTANCEID
3240 """"""""""""""""""""""""
3242 For vertex shaders, this semantic label indicates that a system value contains
3243 the current instance id (i.e. gl_InstanceID). It does not include the base
3244 instance. This is an integer value, and only the X component is used.
3246 TGSI_SEMANTIC_VERTEXID
3247 """"""""""""""""""""""
3249 For vertex shaders, this semantic label indicates that a system value contains
3250 the current vertex id (i.e. gl_VertexID). It does (unlike in d3d10) include the
3251 base vertex. This is an integer value, and only the X component is used.
3253 TGSI_SEMANTIC_VERTEXID_NOBASE
3254 """""""""""""""""""""""""""""""
3256 For vertex shaders, this semantic label indicates that a system value contains
3257 the current vertex id without including the base vertex (this corresponds to
3258 d3d10 vertex id, so TGSI_SEMANTIC_VERTEXID_NOBASE + TGSI_SEMANTIC_BASEVERTEX
3259 == TGSI_SEMANTIC_VERTEXID). This is an integer value, and only the X component
3262 TGSI_SEMANTIC_BASEVERTEX
3263 """"""""""""""""""""""""
3265 For vertex shaders, this semantic label indicates that a system value contains
3266 the base vertex (i.e. gl_BaseVertex). Note that for non-indexed draw calls,
3267 this contains the first (or start) value instead.
3268 This is an integer value, and only the X component is used.
3270 TGSI_SEMANTIC_PRIMID
3271 """"""""""""""""""""
3273 For geometry and fragment shaders, this semantic label indicates the value
3274 contains the primitive id (i.e. gl_PrimitiveID). This is an integer value,
3275 and only the X component is used.
3276 FIXME: This right now can be either a ordinary input or a system value...
3282 For tessellation evaluation/control shaders, this semantic label indicates a
3283 generic per-patch attribute. Such semantics will not implicitly be per-vertex
3286 TGSI_SEMANTIC_TESSCOORD
3287 """""""""""""""""""""""
3289 For tessellation evaluation shaders, this semantic label indicates the
3290 coordinates of the vertex being processed. This is available in XYZ; W is
3293 TGSI_SEMANTIC_TESSOUTER
3294 """""""""""""""""""""""
3296 For tessellation evaluation/control shaders, this semantic label indicates the
3297 outer tessellation levels of the patch. Isoline tessellation will only have XY
3298 defined, triangle will have XYZ and quads will have XYZW defined. This
3299 corresponds to gl_TessLevelOuter.
3301 TGSI_SEMANTIC_TESSINNER
3302 """""""""""""""""""""""
3304 For tessellation evaluation/control shaders, this semantic label indicates the
3305 inner tessellation levels of the patch. The X value is only defined for
3306 triangle tessellation, while quads will have XY defined. This is entirely
3307 undefined for isoline tessellation.
3309 TGSI_SEMANTIC_VERTICESIN
3310 """"""""""""""""""""""""
3312 For tessellation evaluation/control shaders, this semantic label indicates the
3313 number of vertices provided in the input patch. Only the X value is defined.
3315 TGSI_SEMANTIC_HELPER_INVOCATION
3316 """""""""""""""""""""""""""""""
3318 For fragment shaders, this semantic indicates whether the current
3319 invocation is covered or not. Helper invocations are created in order
3320 to properly compute derivatives, however it may be desirable to skip
3321 some of the logic in those cases. See ``gl_HelperInvocation`` documentation.
3323 TGSI_SEMANTIC_BASEINSTANCE
3324 """"""""""""""""""""""""""
3326 For vertex shaders, the base instance argument supplied for this
3327 draw. This is an integer value, and only the X component is used.
3329 TGSI_SEMANTIC_DRAWID
3330 """"""""""""""""""""
3332 For vertex shaders, the zero-based index of the current draw in a
3333 ``glMultiDraw*`` invocation. This is an integer value, and only the X
3337 TGSI_SEMANTIC_WORK_DIM
3338 """"""""""""""""""""""
3340 For compute shaders started via opencl this retrieves the work_dim
3341 parameter to the clEnqueueNDRangeKernel call with which the shader
3345 TGSI_SEMANTIC_GRID_SIZE
3346 """""""""""""""""""""""
3348 For compute shaders, this semantic indicates the maximum (x, y, z) dimensions
3349 of a grid of thread blocks.
3352 TGSI_SEMANTIC_BLOCK_ID
3353 """"""""""""""""""""""
3355 For compute shaders, this semantic indicates the (x, y, z) coordinates of the
3356 current block inside of the grid.
3359 TGSI_SEMANTIC_BLOCK_SIZE
3360 """"""""""""""""""""""""
3362 For compute shaders, this semantic indicates the maximum (x, y, z) dimensions
3363 of a block in threads.
3366 TGSI_SEMANTIC_THREAD_ID
3367 """""""""""""""""""""""
3369 For compute shaders, this semantic indicates the (x, y, z) coordinates of the
3370 current thread inside of the block.
3373 Declaration Interpolate
3374 ^^^^^^^^^^^^^^^^^^^^^^^
3376 This token is only valid for fragment shader INPUT declarations.
3378 The Interpolate field specifes the way input is being interpolated by
3379 the rasteriser and is one of TGSI_INTERPOLATE_*.
3381 The Location field specifies the location inside the pixel that the
3382 interpolation should be done at, one of ``TGSI_INTERPOLATE_LOC_*``. Note that
3383 when per-sample shading is enabled, the implementation may choose to
3384 interpolate at the sample irrespective of the Location field.
3386 The CylindricalWrap bitfield specifies which register components
3387 should be subject to cylindrical wrapping when interpolating by the
3388 rasteriser. If TGSI_CYLINDRICAL_WRAP_X is set to 1, the X component
3389 should be interpolated according to cylindrical wrapping rules.
3392 Declaration Sampler View
3393 ^^^^^^^^^^^^^^^^^^^^^^^^
3395 Follows Declaration token if file is TGSI_FILE_SAMPLER_VIEW.
3397 DCL SVIEW[#], resource, type(s)
3399 Declares a shader input sampler view and assigns it to a SVIEW[#]
3402 resource can be one of BUFFER, 1D, 2D, 3D, 1DArray and 2DArray.
3404 type must be 1 or 4 entries (if specifying on a per-component
3405 level) out of UNORM, SNORM, SINT, UINT and FLOAT.
3407 For TEX\* style texture sample opcodes (as opposed to SAMPLE\* opcodes
3408 which take an explicit SVIEW[#] source register), there may be optionally
3409 SVIEW[#] declarations. In this case, the SVIEW index is implied by the
3410 SAMP index, and there must be a corresponding SVIEW[#] declaration for
3411 each SAMP[#] declaration. Drivers are free to ignore this if they wish.
3412 But note in particular that some drivers need to know the sampler type
3413 (float/int/unsigned) in order to generate the correct code, so cases
3414 where integer textures are sampled, SVIEW[#] declarations should be
3417 NOTE: It is NOT legal to mix SAMPLE\* style opcodes and TEX\* opcodes
3420 Declaration Resource
3421 ^^^^^^^^^^^^^^^^^^^^
3423 Follows Declaration token if file is TGSI_FILE_RESOURCE.
3425 DCL RES[#], resource [, WR] [, RAW]
3427 Declares a shader input resource and assigns it to a RES[#]
3430 resource can be one of BUFFER, 1D, 2D, 3D, CUBE, 1DArray and
3433 If the RAW keyword is not specified, the texture data will be
3434 subject to conversion, swizzling and scaling as required to yield
3435 the specified data type from the physical data format of the bound
3438 If the RAW keyword is specified, no channel conversion will be
3439 performed: the values read for each of the channels (X,Y,Z,W) will
3440 correspond to consecutive words in the same order and format
3441 they're found in memory. No element-to-address conversion will be
3442 performed either: the value of the provided X coordinate will be
3443 interpreted in byte units instead of texel units. The result of
3444 accessing a misaligned address is undefined.
3446 Usage of the STORE opcode is only allowed if the WR (writable) flag
3451 ^^^^^^^^^^^^^^^^^^^^^^^^
3453 Properties are general directives that apply to the whole TGSI program.
3458 Specifies the fragment shader TGSI_SEMANTIC_POSITION coordinate origin.
3459 The default value is UPPER_LEFT.
3461 If UPPER_LEFT, the position will be (0,0) at the upper left corner and
3462 increase downward and rightward.
3463 If LOWER_LEFT, the position will be (0,0) at the lower left corner and
3464 increase upward and rightward.
3466 OpenGL defaults to LOWER_LEFT, and is configurable with the
3467 GL_ARB_fragment_coord_conventions extension.
3469 DirectX 9/10 use UPPER_LEFT.
3471 FS_COORD_PIXEL_CENTER
3472 """""""""""""""""""""
3474 Specifies the fragment shader TGSI_SEMANTIC_POSITION pixel center convention.
3475 The default value is HALF_INTEGER.
3477 If HALF_INTEGER, the fractionary part of the position will be 0.5
3478 If INTEGER, the fractionary part of the position will be 0.0
3480 Note that this does not affect the set of fragments generated by
3481 rasterization, which is instead controlled by half_pixel_center in the
3484 OpenGL defaults to HALF_INTEGER, and is configurable with the
3485 GL_ARB_fragment_coord_conventions extension.
3487 DirectX 9 uses INTEGER.
3488 DirectX 10 uses HALF_INTEGER.
3490 FS_COLOR0_WRITES_ALL_CBUFS
3491 """"""""""""""""""""""""""
3492 Specifies that writes to the fragment shader color 0 are replicated to all
3493 bound cbufs. This facilitates OpenGL's fragColor output vs fragData[0] where
3494 fragData is directed to a single color buffer, but fragColor is broadcast.
3497 """"""""""""""""""""""""""
3498 If this property is set on the program bound to the shader stage before the
3499 fragment shader, user clip planes should have no effect (be disabled) even if
3500 that shader does not write to any clip distance outputs and the rasterizer's
3501 clip_plane_enable is non-zero.
3502 This property is only supported by drivers that also support shader clip
3504 This is useful for APIs that don't have UCPs and where clip distances written
3505 by a shader cannot be disabled.
3510 Specifies the number of times a geometry shader should be executed for each
3511 input primitive. Each invocation will have a different
3512 TGSI_SEMANTIC_INVOCATIONID system value set. If not specified, assumed to
3515 VS_WINDOW_SPACE_POSITION
3516 """"""""""""""""""""""""""
3517 If this property is set on the vertex shader, the TGSI_SEMANTIC_POSITION output
3518 is assumed to contain window space coordinates.
3519 Division of X,Y,Z by W and the viewport transformation are disabled, and 1/W is
3520 directly taken from the 4-th component of the shader output.
3521 Naturally, clipping is not performed on window coordinates either.
3522 The effect of this property is undefined if a geometry or tessellation shader
3528 The number of vertices written by the tessellation control shader. This
3529 effectively defines the patch input size of the tessellation evaluation shader
3535 This sets the tessellation primitive mode, one of ``PIPE_PRIM_TRIANGLES``,
3536 ``PIPE_PRIM_QUADS``, or ``PIPE_PRIM_LINES``. (Unlike in GL, there is no
3537 separate isolines settings, the regular lines is assumed to mean isolines.)
3542 This sets the spacing mode of the tessellation generator, one of
3543 ``PIPE_TESS_SPACING_*``.
3548 This sets the vertex order to be clockwise if the value is 1, or
3549 counter-clockwise if set to 0.
3554 If set to a non-zero value, this turns on point mode for the tessellator,
3555 which means that points will be generated instead of primitives.
3557 NUM_CLIPDIST_ENABLED
3558 """"""""""""""""""""
3560 How many clip distance scalar outputs are enabled.
3562 NUM_CULLDIST_ENABLED
3563 """"""""""""""""""""
3565 How many cull distance scalar outputs are enabled.
3567 FS_EARLY_DEPTH_STENCIL
3568 """"""""""""""""""""""
3570 Whether depth test, stencil test, and occlusion query should run before
3571 the fragment shader (regardless of fragment shader side effects). Corresponds
3572 to GLSL early_fragment_tests.
3577 Which shader stage will MOST LIKELY follow after this shader when the shader
3578 is bound. This is only a hint to the driver and doesn't have to be precise.
3579 Only set for VS and TES.
3581 CS_FIXED_BLOCK_WIDTH / HEIGHT / DEPTH
3582 """""""""""""""""""""""""""""""""""""
3584 Threads per block in each dimension, if known at compile time. If the block size
3585 is known all three should be at least 1. If it is unknown they should all be set
3591 The MUL TGSI operation (FP32 multiplication) will return 0 if either
3592 of the operands are equal to 0. That means that 0 * Inf = 0. This
3593 should be set the same way for an entire pipeline. Note that this
3594 applies not only to the literal MUL TGSI opcode, but all FP32
3595 multiplications implied by other operations, such as MAD, FMA, DP2,
3596 DP3, DP4, DPH, DST, LOG, LRP, XPD, and possibly others. If there is a
3597 mismatch between shaders, then it is unspecified whether this behavior
3601 Texture Sampling and Texture Formats
3602 ------------------------------------
3604 This table shows how texture image components are returned as (x,y,z,w) tuples
3605 by TGSI texture instructions, such as :opcode:`TEX`, :opcode:`TXD`, and
3606 :opcode:`TXP`. For reference, OpenGL and Direct3D conventions are shown as
3609 +--------------------+--------------+--------------------+--------------+
3610 | Texture Components | Gallium | OpenGL | Direct3D 9 |
3611 +====================+==============+====================+==============+
3612 | R | (r, 0, 0, 1) | (r, 0, 0, 1) | (r, 1, 1, 1) |
3613 +--------------------+--------------+--------------------+--------------+
3614 | RG | (r, g, 0, 1) | (r, g, 0, 1) | (r, g, 1, 1) |
3615 +--------------------+--------------+--------------------+--------------+
3616 | RGB | (r, g, b, 1) | (r, g, b, 1) | (r, g, b, 1) |
3617 +--------------------+--------------+--------------------+--------------+
3618 | RGBA | (r, g, b, a) | (r, g, b, a) | (r, g, b, a) |
3619 +--------------------+--------------+--------------------+--------------+
3620 | A | (0, 0, 0, a) | (0, 0, 0, a) | (0, 0, 0, a) |
3621 +--------------------+--------------+--------------------+--------------+
3622 | L | (l, l, l, 1) | (l, l, l, 1) | (l, l, l, 1) |
3623 +--------------------+--------------+--------------------+--------------+
3624 | LA | (l, l, l, a) | (l, l, l, a) | (l, l, l, a) |
3625 +--------------------+--------------+--------------------+--------------+
3626 | I | (i, i, i, i) | (i, i, i, i) | N/A |
3627 +--------------------+--------------+--------------------+--------------+
3628 | UV | XXX TBD | (0, 0, 0, 1) | (u, v, 1, 1) |
3629 | | | [#envmap-bumpmap]_ | |
3630 +--------------------+--------------+--------------------+--------------+
3631 | Z | XXX TBD | (z, z, z, 1) | (0, z, 0, 1) |
3632 | | | [#depth-tex-mode]_ | |
3633 +--------------------+--------------+--------------------+--------------+
3634 | S | (s, s, s, s) | unknown | unknown |
3635 +--------------------+--------------+--------------------+--------------+
3637 .. [#envmap-bumpmap] http://www.opengl.org/registry/specs/ATI/envmap_bumpmap.txt
3638 .. [#depth-tex-mode] the default is (z, z, z, 1) but may also be (0, 0, 0, z)
3639 or (z, z, z, z) depending on the value of GL_DEPTH_TEXTURE_MODE.