TGSI, Tungsten Graphics Shader Infrastructure, is an intermediate language for describing shaders. Since Gallium is inherently shaderful, shaders are an important part of the API. TGSI is the only intermediate representation used by all drivers.
All TGSI instructions, known as opcodes, operate on arbitrary-precision floating-point four-component vectors. An opcode may have up to one destination register, known as dst, and between zero and three source registers, called src0 through src2, or simply src if there is only one.
Some instructions, like I2F, permit re-interpretation of vector components as integers. Other instructions permit using registers as two-component vectors with double precision; see Double ISA.
When an instruction has a scalar result, the result is usually copied into each of the components of dst. When this happens, the result is said to be replicated to dst. RCP is one such instruction.
These opcodes are guaranteed to be available regardless of the driver being used.



This instruction replicates its result.

This instruction replicates its result.





This instruction replicates its result.

This instruction replicates its result.













This is identical to ARL.


This instruction replicates its result.

This instruction replicates its result.

This instruction replicates its result.



This instruction replicates its result.
XXX cleanup on aisle three

This instruction replicates its result.

This instruction replicates its result.




Note
Considered for removal.

This instruction replicates its result.

Note
Considered for removal.

This instruction replicates its result.



This instruction replicates its result.

Note
Considered for removal.
Note
Considered for removal.
Note
Considered for removal.
Note
Considered for removal.

Note
Considered for removal.
Note
Considered for removal.

Note
Considered for removal.
pc = pop()
Potential restrictions: * Only occurs at end of function.






This instruction replicates its result.

Note
Considered for cleanup.
Note
Considered for removal.
Note
Considered for cleanup.
Note
Considered for removal.
These opcodes are primarily provided for special-use computational shaders. Support for these opcodes indicated by a special pipe capability bit (TBD).
XXX so let’s discuss it, yeah?











Note
Support for CONT is determined by a special capability bit, TGSI_CONT_SUPPORTED. See Screen for more information.
These opcodes are only supported in geometry shaders; they have no meaning in any other type of shader.
These opcodes are part of GLSL‘s opcode set. Support for these opcodes is determined by a special capability bit, GLSL.
This instruction replicates its result.

XXX wait what
The double-precision opcodes reinterpret four-component vectors into two-component vectors with doubled precision in each component.
Support for these opcodes is XXX undecided. :T





Like the frexp() routine in many math libraries, this opcode stores the
exponent of its source to dst0, and the significand to dst1, such that
.

This opcode is the inverse of DFRACEXP.







Absolute value of x.
Ceiling of x.
- clamp(x,y,z) Clamp x between y and z.
- (x < y) ? y : (x > z) ? z : x
Floor of x.
Logarithm of x, base 2.
- max(x,y) Maximum of x and y.
- (x > y) ? x : y
- min(x,y) Minimum of x and y.
- (x < y) ? x : y
partialx(x) Derivative of x relative to fragment’s X.
partialy(x) Derivative of x relative to fragment’s Y.
pop() Pop from stack.
x to the power y.
push(x) Push x on stack.
round(x) Round x.
trunc(x) Truncate x, i.e. drop the fraction bits.
discard Discard fragment.
pc Program counter.
target Label of target instruction.
Declares a register that is will be referenced as an operand in Instruction tokens.
File field contains register file that is being declared and is one of TGSI_FILE.
UsageMask field specifies which of the register components can be accessed and is one of TGSI_WRITEMASK.
Interpolate field is only valid for fragment shader INPUT register files. It specifes the way input is being interpolated by the rasteriser and is one of TGSI_INTERPOLATE.
If Dimension flag is set to 1, a Declaration Dimension token follows.
If Semantic flag is set to 1, a Declaration Semantic token follows.
CylindricalWrap bitfield is only valid for fragment shader INPUT register files. It specifies which register components should be subject to cylindrical wrapping when interpolating by the rasteriser. If TGSI_CYLINDRICAL_WRAP_X is set to 1, the X component should be interpolated according to cylindrical wrapping rules.
Vertex and fragment shader input and output registers may be labeled with semantic information consisting of a name and index.
Follows Declaration token if Semantic bit is set.
Since its purpose is to link a shader with other stages of the pipeline, it is valid to follow only those Declaration tokens that declare a register either in INPUT or OUTPUT file.
SemanticName field contains the semantic name of the register being declared. There is no default value.
SemanticIndex is an optional subscript that can be used to distinguish different register declarations with the same semantic name. The default value is 0.
The meanings of the individual semantic names are explained in the following sections.
For vertex shaders, TGSI_SEMANTIC_POSITION indicates the vertex shader output register which contains the homogeneous vertex position in the clip space coordinate system. After clipping, the X, Y and Z components of the vertex will be divided by the W value to get normalized device coordinates.
For fragment shaders, TGSI_SEMANTIC_POSITION is used to indicate that fragment shader input contains the fragment’s window position. The X component starts at zero and always increases from left to right. The Y component starts at zero and always increases but Y=0 may either indicate the top of the window or the bottom depending on the fragment coordinate origin convention (see TGSI_PROPERTY_FS_COORD_ORIGIN). The Z coordinate ranges from 0 to 1 to represent depth from the front to the back of the Z buffer. The W component contains the reciprocol of the interpolated vertex position W component.
Fragment shaders may also declare an output register with TGSI_SEMANTIC_POSITION. Only the Z component is writable. This allows the fragment shader to change the fragment’s Z position.
For vertex shader outputs or fragment shader inputs/outputs, this label indicates that the resister contains an R,G,B,A color.
Several shader inputs/outputs may contain colors so the semantic index is used to distinguish them. For example, color[0] may be the diffuse color while color[1] may be the specular color.
This label is needed so that the flat/smooth shading can be applied to the right interpolants during rasterization.
Back-facing colors are only used for back-facing polygons, and are only valid in vertex shader outputs. After rasterization, all polygons are front-facing and COLOR and BCOLOR end up occupying the same slots in the fragment shader, so all BCOLORs effectively become regular COLORs in the fragment shader.
Vertex shader inputs and outputs and fragment shader inputs may be labeled with TGSI_SEMANTIC_FOG to indicate that the register contains a fog coordinate in the form (F, 0, 0, 1). Typically, the fragment shader will use the fog coordinate to compute a fog blend factor which is used to blend the normal fragment color with a constant fog color.
Only the first component matters when writing from the vertex shader; the driver will ensure that the coordinate is in this format when used as a fragment shader input.
Vertex shader input and output registers may be labeled with TGIS_SEMANTIC_PSIZE to indicate that the register contains a point size in the form (S, 0, 0, 1). The point size controls the width or diameter of points for rasterization. This label cannot be used in fragment shaders.
When using this semantic, be sure to set the appropriate state in the Rasterizer first.
All vertex/fragment shader inputs/outputs not labeled with any other semantic label can be considered to be generic attributes. Typical uses of generic inputs/outputs are texcoords and user-defined values.
Indicates that a vertex shader input is a normal vector. This is typically only used for legacy graphics APIs.
This label applies to fragment shader inputs only and indicates that the register contains front/back-face information of the form (F, 0, 0, 1). The first component will be positive when the fragment belongs to a front-facing polygon, and negative when the fragment belongs to a back-facing polygon.
For vertex shaders, this sematic label indicates that an input or output is a boolean edge flag. The register layout is [F, x, x, x] where F is 0.0 or 1.0 and x = don’t care. Normally, the vertex shader simply copies the edge flag input to the edgeflag output.
Edge flags are used to control which lines or points are actually drawn when the polygon mode converts triangles/quads/polygons into points or lines.
Properties are general directives that apply to the whole TGSI program.
Specifies the fragment shader TGSI_SEMANTIC_POSITION coordinate origin. The default value is UPPER_LEFT.
If UPPER_LEFT, the position will be (0,0) at the upper left corner and increase downward and rightward. If LOWER_LEFT, the position will be (0,0) at the lower left corner and increase upward and rightward.
OpenGL defaults to LOWER_LEFT, and is configurable with the GL_ARB_fragment_coord_conventions extension.
DirectX 9/10 use UPPER_LEFT.
Specifies the fragment shader TGSI_SEMANTIC_POSITION pixel center convention. The default value is HALF_INTEGER.
If HALF_INTEGER, the fractionary part of the position will be 0.5 If INTEGER, the fractionary part of the position will be 0.0
Note that this does not affect the set of fragments generated by rasterization, which is instead controlled by gl_rasterization_rules in the rasterizer.
OpenGL defaults to HALF_INTEGER, and is configurable with the GL_ARB_fragment_coord_conventions extension.
DirectX 9 uses INTEGER. DirectX 10 uses HALF_INTEGER.
This table shows how texture image components are returned as (x,y,z,w) tuples by TGSI texture instructions, such as TEX, TXD, and TXP. For reference, OpenGL and Direct3D conventions are shown as well.
| Texture Components | Gallium | OpenGL | Direct3D 9 |
|---|---|---|---|
| R | (r, 0, 0, 1) | (r, 0, 0, 1) | (r, 1, 1, 1) |
| RG | (r, g, 0, 1) | (r, g, 0, 1) | (r, g, 1, 1) |
| RGB | (r, g, b, 1) | (r, g, b, 1) | (r, g, b, 1) |
| RGBA | (r, g, b, a) | (r, g, b, a) | (r, g, b, a) |
| A | (0, 0, 0, a) | (0, 0, 0, a) | (0, 0, 0, a) |
| L | (l, l, l, 1) | (l, l, l, 1) | (l, l, l, 1) |
| LA | (l, l, l, a) | (l, l, l, a) | (l, l, l, a) |
| I | (i, i, i, i) | (i, i, i, i) | N/A |
| UV | XXX TBD | (0, 0, 0, 1) [1] | (u, v, 1, 1) |
| Z | XXX TBD | (z, z, z, 1) [2] | (0, z, 0, 1) |
| [1] | http://www.opengl.org/registry/specs/ATI/envmap_bumpmap.txt |
| [2] | the default is (z, z, z, 1) but may also be (0, 0, 0, z) or (z, z, z, z) depending on the value of GL_DEPTH_TEXTURE_MODE. |