Merge branch '7.8'
[mesa.git] / src / gallium / docs / source / tgsi.rst
index a30729073b2446dbc4d36b0d59eff3d05b9f8b5c..e2c8602da0254832a92ec3aa8524c08d250e8ad7 100644 (file)
 TGSI
 ====
 
-TGSI, Tungsten Graphics Shader Instructions, is an intermediate language
+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.
 
+Basics
+------
 
-TGSI Instruction Specification
-==============================
+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 :opcode:`I2F`, permit re-interpretation of vector
+components as integers. Other instructions permit using registers as
+two-component vectors with double precision; see :ref:`Double Opcodes`.
 
-1  Instruction Set Operations
-=============================
+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*. :opcode:`RCP` is one such instruction.
 
+Instruction Set
+---------------
 
-1.1  GL_NV_vertex_program
--------------------------
+From GL_NV_vertex_program
+^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
-1.1.1  ARL - Address Register Load
+.. opcode:: ARL - Address Register Load
 
-  dst.x = floor(src.x)
-  dst.y = floor(src.y)
-  dst.z = floor(src.z)
-  dst.w = floor(src.w)
+.. math::
 
+  dst.x = \lfloor src.x\rfloor
 
-1.1.2  MOV - Move
+  dst.y = \lfloor src.y\rfloor
+
+  dst.z = \lfloor src.z\rfloor
+
+  dst.w = \lfloor src.w\rfloor
+
+
+.. opcode:: MOV - Move
+
+.. math::
 
   dst.x = src.x
+
   dst.y = src.y
+
   dst.z = src.z
+
   dst.w = src.w
 
 
-1.1.3  LIT - Light Coefficients
+.. opcode:: LIT - Light Coefficients
+
+.. math::
+
+  dst.x = 1
+
+  dst.y = max(src.x, 0)
+
+  dst.z = (src.x > 0) ? max(src.y, 0)^{clamp(src.w, -128, 128))} : 0
+
+  dst.w = 1
+
+
+.. opcode:: RCP - Reciprocal
+
+This instruction replicates its result.
+
+.. math::
+
+  dst = \frac{1}{src.x}
+
+
+.. opcode:: RSQ - Reciprocal Square Root
+
+This instruction replicates its result.
+
+.. math::
 
-  dst.x = 1.0
-  dst.y = max(src.x, 0.0)
-  dst.z = (src.x > 0.0) ? pow(max(src.y, 0.0), clamp(src.w, -128.0, 128.0)) : 0.0
-  dst.w = 1.0
+  dst = \frac{1}{\sqrt{|src.x|}}
 
 
-1.1.4  RCP - Reciprocal
+.. opcode:: EXP - Approximate Exponential Base 2
 
-  dst.x = 1.0 / src.x
-  dst.y = 1.0 / src.x
-  dst.z = 1.0 / src.x
-  dst.w = 1.0 / src.x
+.. math::
 
+  dst.x = 2^{\lfloor src.x\rfloor}
 
-1.1.5  RSQ - Reciprocal Square Root
+  dst.y = src.x - \lfloor src.x\rfloor
 
-  dst.x = 1.0 / sqrt(abs(src.x))
-  dst.y = 1.0 / sqrt(abs(src.x))
-  dst.z = 1.0 / sqrt(abs(src.x))
-  dst.w = 1.0 / sqrt(abs(src.x))
+  dst.z = 2^{src.x}
 
+  dst.w = 1
 
-1.1.6  EXP - Approximate Exponential Base 2
 
-  dst.x = pow(2.0, floor(src.x))
-  dst.y = src.x - floor(src.x)
-  dst.z = pow(2.0, src.x)
-  dst.w = 1.0
+.. opcode:: LOG - Approximate Logarithm Base 2
 
+.. math::
 
-1.1.7  LOG - Approximate Logarithm Base 2
+  dst.x = \lfloor\log_2{|src.x|}\rfloor
 
-  dst.x = floor(lg2(abs(src.x)))
-  dst.y = abs(src.x) / pow(2.0, floor(lg2(abs(src.x))))
-  dst.z = lg2(abs(src.x))
-  dst.w = 1.0
+  dst.y = \frac{|src.x|}{2^{\lfloor\log_2{|src.x|}\rfloor}}
 
+  dst.z = \log_2{|src.x|}
 
-1.1.8  MUL - Multiply
+  dst.w = 1
 
-  dst.x = src0.x * src1.x
-  dst.y = src0.y * src1.y
-  dst.z = src0.z * src1.z
-  dst.w = src0.w * src1.w
 
+.. opcode:: MUL - Multiply
 
-1.1.9  ADD - Add
+.. math::
+
+  dst.x = src0.x \times src1.x
+
+  dst.y = src0.y \times src1.y
+
+  dst.z = src0.z \times src1.z
+
+  dst.w = src0.w \times src1.w
+
+
+.. opcode:: ADD - Add
+
+.. math::
 
   dst.x = src0.x + src1.x
+
   dst.y = src0.y + src1.y
+
   dst.z = src0.z + src1.z
+
   dst.w = src0.w + src1.w
 
 
-1.1.10  DP3 - 3-component Dot Product
+.. opcode:: DP3 - 3-component Dot Product
+
+This instruction replicates its result.
 
-  dst.x = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z
-  dst.y = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z
-  dst.z = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z
-  dst.w = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z
+.. math::
 
+  dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z
 
-1.1.11  DP4 - 4-component Dot Product
 
-  dst.x = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src0.w * src1.w
-  dst.y = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src0.w * src1.w
-  dst.z = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src0.w * src1.w
-  dst.w = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src0.w * src1.w
+.. opcode:: DP4 - 4-component Dot Product
 
+This instruction replicates its result.
 
-1.1.12  DST - Distance Vector
+.. math::
+
+  dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src0.w \times src1.w
+
+
+.. opcode:: DST - Distance Vector
+
+.. math::
+
+  dst.x = 1
+
+  dst.y = src0.y \times src1.y
 
-  dst.x = 1.0
-  dst.y = src0.y * src1.y
   dst.z = src0.z
+
   dst.w = src1.w
 
 
-1.1.13  MIN - Minimum
+.. opcode:: MIN - Minimum
+
+.. math::
 
   dst.x = min(src0.x, src1.x)
+
   dst.y = min(src0.y, src1.y)
+
   dst.z = min(src0.z, src1.z)
+
   dst.w = min(src0.w, src1.w)
 
 
-1.1.14  MAX - Maximum
+.. opcode:: MAX - Maximum
+
+.. math::
 
   dst.x = max(src0.x, src1.x)
+
   dst.y = max(src0.y, src1.y)
+
   dst.z = max(src0.z, src1.z)
+
   dst.w = max(src0.w, src1.w)
 
 
-1.1.15  SLT - Set On Less Than
+.. opcode:: SLT - Set On Less Than
+
+.. math::
+
+  dst.x = (src0.x < src1.x) ? 1 : 0
+
+  dst.y = (src0.y < src1.y) ? 1 : 0
+
+  dst.z = (src0.z < src1.z) ? 1 : 0
+
+  dst.w = (src0.w < src1.w) ? 1 : 0
+
+
+.. opcode:: SGE - Set On Greater Equal Than
 
-  dst.x = (src0.x < src1.x) ? 1.0 : 0.0
-  dst.y = (src0.y < src1.y) ? 1.0 : 0.0
-  dst.z = (src0.z < src1.z) ? 1.0 : 0.0
-  dst.w = (src0.w < src1.w) ? 1.0 : 0.0
+.. math::
 
+  dst.x = (src0.x >= src1.x) ? 1 : 0
 
-1.1.16  SGE - Set On Greater Equal Than
+  dst.y = (src0.y >= src1.y) ? 1 : 0
 
-  dst.x = (src0.x >= src1.x) ? 1.0 : 0.0
-  dst.y = (src0.y >= src1.y) ? 1.0 : 0.0
-  dst.z = (src0.z >= src1.z) ? 1.0 : 0.0
-  dst.w = (src0.w >= src1.w) ? 1.0 : 0.0
+  dst.z = (src0.z >= src1.z) ? 1 : 0
 
+  dst.w = (src0.w >= src1.w) ? 1 : 0
 
-1.1.17  MAD - Multiply And Add
 
-  dst.x = src0.x * src1.x + src2.x
-  dst.y = src0.y * src1.y + src2.y
-  dst.z = src0.z * src1.z + src2.z
-  dst.w = src0.w * src1.w + src2.w
+.. opcode:: MAD - Multiply And Add
 
+.. math::
 
-1.2.1  SUB - Subtract
+  dst.x = src0.x \times src1.x + src2.x
+
+  dst.y = src0.y \times src1.y + src2.y
+
+  dst.z = src0.z \times src1.z + src2.z
+
+  dst.w = src0.w \times src1.w + src2.w
+
+
+.. opcode:: SUB - Subtract
+
+.. math::
 
   dst.x = src0.x - src1.x
+
   dst.y = src0.y - src1.y
+
   dst.z = src0.z - src1.z
+
   dst.w = src0.w - src1.w
 
 
-1.2.4  LRP - Linear Interpolate
+.. opcode:: LRP - Linear Interpolate
+
+.. math::
+
+  dst.x = src0.x \times src1.x + (1 - src0.x) \times src2.x
 
-  dst.x = src0.x * (src1.x - src2.x) + src2.x
-  dst.y = src0.y * (src1.y - src2.y) + src2.y
-  dst.z = src0.z * (src1.z - src2.z) + src2.z
-  dst.w = src0.w * (src1.w - src2.w) + src2.w
+  dst.y = src0.y \times src1.y + (1 - src0.y) \times src2.y
 
+  dst.z = src0.z \times src1.z + (1 - src0.z) \times src2.z
 
-1.2.5  CND - Condition
+  dst.w = src0.w \times src1.w + (1 - src0.w) \times src2.w
+
+
+.. opcode:: CND - Condition
+
+.. math::
 
   dst.x = (src2.x > 0.5) ? src0.x : src1.x
+
   dst.y = (src2.y > 0.5) ? src0.y : src1.y
+
   dst.z = (src2.z > 0.5) ? src0.z : src1.z
+
   dst.w = (src2.w > 0.5) ? src0.w : src1.w
 
 
-1.2.7  DP2A - 2-component Dot Product And Add
+.. opcode:: DP2A - 2-component Dot Product And Add
+
+.. math::
+
+  dst.x = src0.x \times src1.x + src0.y \times src1.y + src2.x
+
+  dst.y = src0.x \times src1.x + src0.y \times src1.y + src2.x
+
+  dst.z = src0.x \times src1.x + src0.y \times src1.y + src2.x
+
+  dst.w = src0.x \times src1.x + src0.y \times src1.y + src2.x
 
-  dst.x = src0.x * src1.x + src0.y * src1.y + src2.x
-  dst.y = src0.x * src1.x + src0.y * src1.y + src2.x
-  dst.z = src0.x * src1.x + src0.y * src1.y + src2.x
-  dst.w = src0.x * src1.x + src0.y * src1.y + src2.x
 
+.. opcode:: FRAC - Fraction
 
-1.3.4  FRAC - Fraction
+.. math::
 
-  dst.x = src.x - floor(src.x)
-  dst.y = src.y - floor(src.y)
-  dst.z = src.z - floor(src.z)
-  dst.w = src.w - floor(src.w)
+  dst.x = src.x - \lfloor src.x\rfloor
 
+  dst.y = src.y - \lfloor src.y\rfloor
 
-1.3.7  CLAMP - Clamp
+  dst.z = src.z - \lfloor src.z\rfloor
+
+  dst.w = src.w - \lfloor src.w\rfloor
+
+
+.. opcode:: CLAMP - Clamp
+
+.. math::
 
   dst.x = clamp(src0.x, src1.x, src2.x)
+
   dst.y = clamp(src0.y, src1.y, src2.y)
+
   dst.z = clamp(src0.z, src1.z, src2.z)
+
   dst.w = clamp(src0.w, src1.w, src2.w)
 
 
-1.3.8  FLR - Floor
+.. opcode:: FLR - Floor
+
+This is identical to :opcode:`ARL`.
+
+.. math::
+
+  dst.x = \lfloor src.x\rfloor
 
-  dst.x = floor(src.x)
-  dst.y = floor(src.y)
-  dst.z = floor(src.z)
-  dst.w = floor(src.w)
+  dst.y = \lfloor src.y\rfloor
 
+  dst.z = \lfloor src.z\rfloor
 
-1.3.9  ROUND - Round
+  dst.w = \lfloor src.w\rfloor
+
+
+.. opcode:: ROUND - Round
+
+.. math::
 
   dst.x = round(src.x)
+
   dst.y = round(src.y)
+
   dst.z = round(src.z)
+
   dst.w = round(src.w)
 
 
-1.3.10  EX2 - Exponential Base 2
+.. opcode:: EX2 - Exponential Base 2
+
+This instruction replicates its result.
+
+.. math::
+
+  dst = 2^{src.x}
+
+
+.. opcode:: LG2 - Logarithm Base 2
+
+This instruction replicates its result.
+
+.. math::
+
+  dst = \log_2{src.x}
+
+
+.. opcode:: POW - Power
+
+This instruction replicates its result.
+
+.. math::
+
+  dst = src0.x^{src1.x}
+
+.. opcode:: XPD - Cross Product
+
+.. math::
+
+  dst.x = src0.y \times src1.z - src1.y \times src0.z
 
-  dst.x = pow(2.0, src.x)
-  dst.y = pow(2.0, src.x)
-  dst.z = pow(2.0, src.x)
-  dst.w = pow(2.0, src.x)
+  dst.y = src0.z \times src1.x - src1.z \times src0.x
 
+  dst.z = src0.x \times src1.y - src1.x \times src0.y
 
-1.3.11  LG2 - Logarithm Base 2
+  dst.w = 1
 
-  dst.x = lg2(src.x)
-  dst.y = lg2(src.x)
-  dst.z = lg2(src.x)
-  dst.w = lg2(src.x)
 
+.. opcode:: ABS - Absolute
 
-1.3.12  POW - Power
+.. math::
 
-  dst.x = pow(src0.x, src1.x)
-  dst.y = pow(src0.x, src1.x)
-  dst.z = pow(src0.x, src1.x)
-  dst.w = pow(src0.x, src1.x)
+  dst.x = |src.x|
 
-1.3.15  XPD - Cross Product
+  dst.y = |src.y|
 
-  dst.x = src0.y * src1.z - src1.y * src0.z
-  dst.y = src0.z * src1.x - src1.z * src0.x
-  dst.z = src0.x * src1.y - src1.x * src0.y
-  dst.w = 1.0
+  dst.z = |src.z|
 
+  dst.w = |src.w|
 
-1.4.1  ABS - Absolute
 
-  dst.x = abs(src.x)
-  dst.y = abs(src.y)
-  dst.z = abs(src.z)
-  dst.w = abs(src.w)
+.. opcode:: RCC - Reciprocal Clamped
 
+This instruction replicates its result.
 
-1.4.2  RCC - Reciprocal Clamped
+XXX cleanup on aisle three
 
-  dst.x = (1.0 / src.x) > 0.0 ? clamp(1.0 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1.0 / src.x, -1.884467e+019, -5.42101e-020)
-  dst.y = (1.0 / src.x) > 0.0 ? clamp(1.0 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1.0 / src.x, -1.884467e+019, -5.42101e-020)
-  dst.z = (1.0 / src.x) > 0.0 ? clamp(1.0 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1.0 / src.x, -1.884467e+019, -5.42101e-020)
-  dst.w = (1.0 / src.x) > 0.0 ? clamp(1.0 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1.0 / src.x, -1.884467e+019, -5.42101e-020)
+.. math::
 
+  dst = (1 / src.x) > 0 ? clamp(1 / src.x, 5.42101e-020, 1.884467e+019) : clamp(1 / src.x, -1.884467e+019, -5.42101e-020)
 
-1.4.3  DPH - Homogeneous Dot Product
 
-  dst.x = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src1.w
-  dst.y = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src1.w
-  dst.z = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src1.w
-  dst.w = src0.x * src1.x + src0.y * src1.y + src0.z * src1.z + src1.w
+.. opcode:: DPH - Homogeneous Dot Product
 
+This instruction replicates its result.
 
-1.5.1  COS - Cosine
+.. math::
 
-  dst.x = cos(src.x)
-  dst.y = cos(src.x)
-  dst.z = cos(src.x)
-  dst.w = cos(src.w)
+  dst = src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z + src1.w
 
 
-1.5.2  DDX - Derivative Relative To X
+.. opcode:: COS - Cosine
+
+This instruction replicates its result.
+
+.. math::
+
+  dst = \cos{src.x}
+
+
+.. opcode:: DDX - Derivative Relative To X
+
+.. math::
 
   dst.x = partialx(src.x)
+
   dst.y = partialx(src.y)
+
   dst.z = partialx(src.z)
+
   dst.w = partialx(src.w)
 
 
-1.5.3  DDY - Derivative Relative To Y
+.. opcode:: DDY - Derivative Relative To Y
+
+.. math::
 
   dst.x = partialy(src.x)
+
   dst.y = partialy(src.y)
+
   dst.z = partialy(src.z)
+
   dst.w = partialy(src.w)
 
 
-1.5.7  KILP - Predicated Discard
+.. opcode:: KILP - Predicated Discard
 
   discard
 
 
-1.5.10  PK2H - Pack Two 16-bit Floats
+.. opcode:: PK2H - Pack Two 16-bit Floats
 
   TBD
 
 
-1.5.11  PK2US - Pack Two Unsigned 16-bit Scalars
+.. opcode:: PK2US - Pack Two Unsigned 16-bit Scalars
 
   TBD
 
 
-1.5.12  PK4B - Pack Four Signed 8-bit Scalars
+.. opcode:: PK4B - Pack Four Signed 8-bit Scalars
 
   TBD
 
 
-1.5.13  PK4UB - Pack Four Unsigned 8-bit Scalars
+.. opcode:: PK4UB - Pack Four Unsigned 8-bit Scalars
 
   TBD
 
 
-1.5.15  RFL - Reflection Vector
+.. opcode:: RFL - Reflection Vector
+
+.. math::
+
+  dst.x = 2 \times (src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z) / (src0.x \times src0.x + src0.y \times src0.y + src0.z \times src0.z) \times src0.x - src1.x
+
+  dst.y = 2 \times (src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z) / (src0.x \times src0.x + src0.y \times src0.y + src0.z \times src0.z) \times src0.y - src1.y
+
+  dst.z = 2 \times (src0.x \times src1.x + src0.y \times src1.y + src0.z \times src1.z) / (src0.x \times src0.x + src0.y \times src0.y + src0.z \times src0.z) \times src0.z - src1.z
+
+  dst.w = 1
+
+.. note::
+
+   Considered for removal.
+
 
-  dst.x = 2.0 * (src0.x * src1.x + src0.y * src1.y + src0.z * src1.z) / (src0.x * src0.x + src0.y * src0.y + src0.z * src0.z) * src0.x - src1.x
-  dst.y = 2.0 * (src0.x * src1.x + src0.y * src1.y + src0.z * src1.z) / (src0.x * src0.x + src0.y * src0.y + src0.z * src0.z) * src0.y - src1.y
-  dst.z = 2.0 * (src0.x * src1.x + src0.y * src1.y + src0.z * src1.z) / (src0.x * src0.x + src0.y * src0.y + src0.z * src0.z) * src0.z - src1.z
-  dst.w = 1.0
+.. opcode:: SEQ - Set On Equal
 
- Considered for removal.
+.. math::
 
+  dst.x = (src0.x == src1.x) ? 1 : 0
 
-1.5.16  SEQ - Set On Equal
+  dst.y = (src0.y == src1.y) ? 1 : 0
 
-  dst.x = (src0.x == src1.x) ? 1.0 : 0.0
-  dst.y = (src0.y == src1.y) ? 1.0 : 0.0
-  dst.z = (src0.z == src1.z) ? 1.0 : 0.0
-  dst.w = (src0.w == src1.w) ? 1.0 : 0.0
+  dst.z = (src0.z == src1.z) ? 1 : 0
 
+  dst.w = (src0.w == src1.w) ? 1 : 0
 
-1.5.17  SFL - Set On False
 
-  dst.x = 0.0
-  dst.y = 0.0
-  dst.z = 0.0
-  dst.w = 0.0
+.. opcode:: SFL - Set On False
 
- Considered for removal.
+This instruction replicates its result.
 
-1.5.18  SGT - Set On Greater Than
+.. math::
 
-  dst.x = (src0.x > src1.x) ? 1.0 : 0.0
-  dst.y = (src0.y > src1.y) ? 1.0 : 0.0
-  dst.z = (src0.z > src1.z) ? 1.0 : 0.0
-  dst.w = (src0.w > src1.w) ? 1.0 : 0.0
+  dst = 0
 
+.. note::
 
-1.5.19  SIN - Sine
+   Considered for removal.
 
-  dst.x = sin(src.x)
-  dst.y = sin(src.x)
-  dst.z = sin(src.x)
-  dst.w = sin(src.w)
 
+.. opcode:: SGT - Set On Greater Than
 
-1.5.20  SLE - Set On Less Equal Than
+.. math::
 
-  dst.x = (src0.x <= src1.x) ? 1.0 : 0.0
-  dst.y = (src0.y <= src1.y) ? 1.0 : 0.0
-  dst.z = (src0.z <= src1.z) ? 1.0 : 0.0
-  dst.w = (src0.w <= src1.w) ? 1.0 : 0.0
+  dst.x = (src0.x > src1.x) ? 1 : 0
 
+  dst.y = (src0.y > src1.y) ? 1 : 0
 
-1.5.21  SNE - Set On Not Equal
+  dst.z = (src0.z > src1.z) ? 1 : 0
 
-  dst.x = (src0.x != src1.x) ? 1.0 : 0.0
-  dst.y = (src0.y != src1.y) ? 1.0 : 0.0
-  dst.z = (src0.z != src1.z) ? 1.0 : 0.0
-  dst.w = (src0.w != src1.w) ? 1.0 : 0.0
+  dst.w = (src0.w > src1.w) ? 1 : 0
 
 
-1.5.22  STR - Set On True
+.. opcode:: SIN - Sine
 
-  dst.x = 1.0
-  dst.y = 1.0
-  dst.z = 1.0
-  dst.w = 1.0
+This instruction replicates its result.
 
+.. math::
 
-1.5.23  TEX - Texture Lookup
+  dst = \sin{src.x}
+
+
+.. opcode:: SLE - Set On Less Equal Than
+
+.. math::
+
+  dst.x = (src0.x <= src1.x) ? 1 : 0
+
+  dst.y = (src0.y <= src1.y) ? 1 : 0
+
+  dst.z = (src0.z <= src1.z) ? 1 : 0
+
+  dst.w = (src0.w <= src1.w) ? 1 : 0
+
+
+.. opcode:: SNE - Set On Not Equal
+
+.. math::
+
+  dst.x = (src0.x != src1.x) ? 1 : 0
+
+  dst.y = (src0.y != src1.y) ? 1 : 0
+
+  dst.z = (src0.z != src1.z) ? 1 : 0
+
+  dst.w = (src0.w != src1.w) ? 1 : 0
+
+
+.. opcode:: STR - Set On True
+
+This instruction replicates its result.
+
+.. math::
+
+  dst = 1
+
+
+.. opcode:: TEX - Texture Lookup
 
   TBD
 
 
-1.5.24  TXD - Texture Lookup with Derivatives
+.. opcode:: TXD - Texture Lookup with Derivatives
 
   TBD
 
 
-1.5.25  TXP - Projective Texture Lookup
+.. opcode:: TXP - Projective Texture Lookup
 
   TBD
 
 
-1.5.26  UP2H - Unpack Two 16-Bit Floats
+.. opcode:: UP2H - Unpack Two 16-Bit Floats
 
   TBD
 
-  Considered for removal.
+.. note::
+
+   Considered for removal.
 
-1.5.27  UP2US - Unpack Two Unsigned 16-Bit Scalars
+.. opcode:: UP2US - Unpack Two Unsigned 16-Bit Scalars
 
   TBD
 
-  Considered for removal.
+.. note::
 
-1.5.28  UP4B - Unpack Four Signed 8-Bit Values
+   Considered for removal.
+
+.. opcode:: UP4B - Unpack Four Signed 8-Bit Values
 
   TBD
 
-  Considered for removal.
+.. note::
+
+   Considered for removal.
 
-1.5.29  UP4UB - Unpack Four Unsigned 8-Bit Scalars
+.. opcode:: UP4UB - Unpack Four Unsigned 8-Bit Scalars
 
   TBD
 
-  Considered for removal.
+.. note::
+
+   Considered for removal.
+
+.. opcode:: X2D - 2D Coordinate Transformation
+
+.. math::
+
+  dst.x = src0.x + src1.x \times src2.x + src1.y \times src2.y
 
-1.5.30  X2D - 2D Coordinate Transformation
+  dst.y = src0.y + src1.x \times src2.z + src1.y \times src2.w
 
-  dst.x = src0.x + src1.x * src2.x + src1.y * src2.y
-  dst.y = src0.y + src1.x * src2.z + src1.y * src2.w
-  dst.z = src0.x + src1.x * src2.x + src1.y * src2.y
-  dst.w = src0.y + src1.x * src2.z + src1.y * src2.w
+  dst.z = src0.x + src1.x \times src2.x + src1.y \times src2.y
 
-  Considered for removal.
+  dst.w = src0.y + src1.x \times src2.z + src1.y \times src2.w
 
+.. note::
 
-1.6  GL_NV_vertex_program2
---------------------------
+   Considered for removal.
 
 
-1.6.1  ARA - Address Register Add
+From GL_NV_vertex_program2
+^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+
+.. opcode:: ARA - Address Register Add
 
   TBD
 
-  Considered for removal.
+.. note::
+
+   Considered for removal.
 
-1.6.2  ARR - Address Register Load With Round
+.. opcode:: ARR - Address Register Load With Round
+
+.. math::
 
   dst.x = round(src.x)
+
   dst.y = round(src.y)
+
   dst.z = round(src.z)
+
   dst.w = round(src.w)
 
 
-1.6.3  BRA - Branch
+.. opcode:: BRA - Branch
 
   pc = target
 
-  Considered for removal.
+.. note::
+
+   Considered for removal.
 
-1.6.4  CAL - Subroutine Call
+.. opcode:: CAL - Subroutine Call
 
   push(pc)
   pc = target
 
 
-1.6.5  RET - Subroutine Call Return
+.. opcode:: RET - Subroutine Call Return
 
   pc = pop()
 
   Potential restrictions:  
   * Only occurs at end of function.
 
-1.6.6  SSG - Set Sign
+.. opcode:: SSG - Set Sign
 
-  dst.x = (src.x > 0.0) ? 1.0 : (src.x < 0.0) ? -1.0 : 0.0
-  dst.y = (src.y > 0.0) ? 1.0 : (src.y < 0.0) ? -1.0 : 0.0
-  dst.z = (src.z > 0.0) ? 1.0 : (src.z < 0.0) ? -1.0 : 0.0
-  dst.w = (src.w > 0.0) ? 1.0 : (src.w < 0.0) ? -1.0 : 0.0
+.. math::
 
+  dst.x = (src.x > 0) ? 1 : (src.x < 0) ? -1 : 0
 
-1.8.1  CMP - Compare
+  dst.y = (src.y > 0) ? 1 : (src.y < 0) ? -1 : 0
 
-  dst.x = (src0.x < 0.0) ? src1.x : src2.x
-  dst.y = (src0.y < 0.0) ? src1.y : src2.y
-  dst.z = (src0.z < 0.0) ? src1.z : src2.z
-  dst.w = (src0.w < 0.0) ? src1.w : src2.w
+  dst.z = (src.z > 0) ? 1 : (src.z < 0) ? -1 : 0
 
+  dst.w = (src.w > 0) ? 1 : (src.w < 0) ? -1 : 0
 
-1.8.2  KIL - Conditional Discard
 
-  if (src.x < 0.0 || src.y < 0.0 || src.z < 0.0 || src.w < 0.0)
-    discard
-  endif
+.. opcode:: CMP - Compare
 
+.. math::
 
-1.8.3  SCS - Sine Cosine
+  dst.x = (src0.x < 0) ? src1.x : src2.x
 
-  dst.x = cos(src.x)
-  dst.y = sin(src.x)
-  dst.z = 0.0
-  dst.y = 1.0
+  dst.y = (src0.y < 0) ? src1.y : src2.y
 
+  dst.z = (src0.z < 0) ? src1.z : src2.z
 
-1.8.4  TXB - Texture Lookup With Bias
+  dst.w = (src0.w < 0) ? src1.w : src2.w
 
-  TBD
 
+.. opcode:: KIL - Conditional Discard
 
-1.9.1  NRM - 3-component Vector Normalise
+.. math::
 
-  dst.x = src.x / (src.x * src.x + src.y * src.y + src.z * src.z)
-  dst.y = src.y / (src.x * src.x + src.y * src.y + src.z * src.z)
-  dst.z = src.z / (src.x * src.x + src.y * src.y + src.z * src.z)
-  dst.w = 1.0
+  if (src.x < 0 || src.y < 0 || src.z < 0 || src.w < 0)
+    discard
+  endif
 
 
-1.9.2  DIV - Divide
+.. opcode:: SCS - Sine Cosine
 
-  dst.x = src0.x / src1.x
-  dst.y = src0.y / src1.y
-  dst.z = src0.z / src1.z
-  dst.w = src0.w / src1.w
+.. math::
 
+  dst.x = \cos{src.x}
 
-1.9.3  DP2 - 2-component Dot Product
+  dst.y = \sin{src.x}
 
-  dst.x = src0.x * src1.x + src0.y * src1.y
-  dst.y = src0.x * src1.x + src0.y * src1.y
-  dst.z = src0.x * src1.x + src0.y * src1.y
-  dst.w = src0.x * src1.x + src0.y * src1.y
+  dst.z = 0
 
+  dst.y = 1
 
-1.9.5  TXL - Texture Lookup With LOD
+
+.. opcode:: TXB - Texture Lookup With Bias
 
   TBD
 
 
-1.9.6  BRK - Break
+.. opcode:: NRM - 3-component Vector Normalise
 
-  TBD
+.. math::
 
+  dst.x = src.x / (src.x \times src.x + src.y \times src.y + src.z \times src.z)
 
-1.9.7  IF - If
+  dst.y = src.y / (src.x \times src.x + src.y \times src.y + src.z \times src.z)
 
-  TBD
+  dst.z = src.z / (src.x \times src.x + src.y \times src.y + src.z \times src.z)
 
+  dst.w = 1
 
-1.9.8  BGNFOR - Begin a For-Loop
 
-  dst.x = floor(src.x)
-  dst.y = floor(src.y)
-  dst.z = floor(src.z)
+.. opcode:: DIV - Divide
 
-  if (dst.y <= 0)
-    pc = [matching ENDFOR] + 1
-  endif
+.. math::
 
-  Note: The destination must be a loop register.
-        The source must be a constant register.
+  dst.x = \frac{src0.x}{src1.x}
 
-  Considered for cleanup / removal.
+  dst.y = \frac{src0.y}{src1.y}
 
+  dst.z = \frac{src0.z}{src1.z}
 
-1.9.9  REP - Repeat
+  dst.w = \frac{src0.w}{src1.w}
 
-  TBD
 
+.. opcode:: DP2 - 2-component Dot Product
+
+This instruction replicates its result.
+
+.. math::
+
+  dst = src0.x \times src1.x + src0.y \times src1.y
 
-1.9.10  ELSE - Else
+
+.. opcode:: TXL - Texture Lookup With LOD
 
   TBD
 
 
-1.9.11  ENDIF - End If
+.. opcode:: BRK - Break
 
   TBD
 
 
-1.9.12  ENDFOR - End a For-Loop
+.. opcode:: IF - If
 
-  dst.x = dst.x + dst.z
-  dst.y = dst.y - 1.0
+  TBD
 
-  if (dst.y > 0)
-    pc = [matching BGNFOR instruction] + 1
-  endif
 
-  Note: The destination must be a loop register.
+.. opcode:: ELSE - Else
+
+  TBD
 
-  Considered for cleanup / removal.
 
-1.9.13  ENDREP - End Repeat
+.. opcode:: ENDIF - End If
 
   TBD
 
 
-1.10.1  PUSHA - Push Address Register On Stack
+.. opcode:: PUSHA - Push Address Register On Stack
 
   push(src.x)
   push(src.y)
   push(src.z)
   push(src.w)
 
-  Considered for cleanup / removal.
+.. note::
 
-1.10.2  POPA - Pop Address Register From Stack
+   Considered for cleanup.
+
+.. note::
+
+   Considered for removal.
+
+.. opcode:: POPA - Pop Address Register From Stack
 
   dst.w = pop()
   dst.z = pop()
   dst.y = pop()
   dst.x = pop()
 
-  Considered for cleanup / removal.
+.. note::
+
+   Considered for cleanup.
+
+.. note::
+
+   Considered for removal.
 
 
-1.11  GL_NV_gpu_program4
-------------------------
+From GL_NV_gpu_program4
+^^^^^^^^^^^^^^^^^^^^^^^^
 
 Support for these opcodes indicated by a special pipe capability bit (TBD).
 
-1.11.1  CEIL - Ceiling
+.. opcode:: CEIL - Ceiling
+
+.. math::
+
+  dst.x = \lceil src.x\rceil
+
+  dst.y = \lceil src.y\rceil
+
+  dst.z = \lceil src.z\rceil
+
+  dst.w = \lceil src.w\rceil
 
-  dst.x = ceil(src.x)
-  dst.y = ceil(src.y)
-  dst.z = ceil(src.z)
-  dst.w = ceil(src.w)
 
+.. opcode:: I2F - Integer To Float
 
-1.11.2  I2F - Integer To Float
+.. math::
 
   dst.x = (float) src.x
+
   dst.y = (float) src.y
+
   dst.z = (float) src.z
+
   dst.w = (float) src.w
 
 
-1.11.3  NOT - Bitwise Not
+.. opcode:: NOT - Bitwise Not
+
+.. math::
 
   dst.x = ~src.x
+
   dst.y = ~src.y
+
   dst.z = ~src.z
+
   dst.w = ~src.w
 
 
-1.11.4  TRUNC - Truncate
+.. opcode:: TRUNC - Truncate
+
+.. math::
 
   dst.x = trunc(src.x)
+
   dst.y = trunc(src.y)
+
   dst.z = trunc(src.z)
+
   dst.w = trunc(src.w)
 
 
-1.11.5  SHL - Shift Left
+.. opcode:: SHL - Shift Left
+
+.. math::
 
   dst.x = src0.x << src1.x
+
   dst.y = src0.y << src1.x
+
   dst.z = src0.z << src1.x
+
   dst.w = src0.w << src1.x
 
 
-1.11.6  SHR - Shift Right
+.. opcode:: SHR - Shift Right
+
+.. math::
 
   dst.x = src0.x >> src1.x
+
   dst.y = src0.y >> src1.x
+
   dst.z = src0.z >> src1.x
+
   dst.w = src0.w >> src1.x
 
 
-1.11.7  AND - Bitwise And
+.. opcode:: AND - Bitwise And
+
+.. math::
 
   dst.x = src0.x & src1.x
+
   dst.y = src0.y & src1.y
+
   dst.z = src0.z & src1.z
+
   dst.w = src0.w & src1.w
 
 
-1.11.8  OR - Bitwise Or
+.. opcode:: OR - Bitwise Or
+
+.. math::
 
   dst.x = src0.x | src1.x
+
   dst.y = src0.y | src1.y
+
   dst.z = src0.z | src1.z
+
   dst.w = src0.w | src1.w
 
 
-1.11.9  MOD - Modulus
+.. opcode:: MOD - Modulus
+
+.. math::
+
+  dst.x = src0.x \bmod src1.x
+
+  dst.y = src0.y \bmod src1.y
+
+  dst.z = src0.z \bmod src1.z
+
+  dst.w = src0.w \bmod src1.w
+
 
-  dst.x = src0.x % src1.x
-  dst.y = src0.y % src1.y
-  dst.z = src0.z % src1.z
-  dst.w = src0.w % src1.w
+.. opcode:: XOR - Bitwise Xor
 
+.. math::
 
-1.11.10  XOR - Bitwise Xor
+  dst.x = src0.x \oplus src1.x
 
-  dst.x = src0.x ^ src1.x
-  dst.y = src0.y ^ src1.y
-  dst.z = src0.z ^ src1.z
-  dst.w = src0.w ^ src1.w
+  dst.y = src0.y \oplus src1.y
 
+  dst.z = src0.z \oplus src1.z
 
-1.11.11  SAD - Sum Of Absolute Differences
+  dst.w = src0.w \oplus src1.w
 
-  dst.x = abs(src0.x - src1.x) + src2.x
-  dst.y = abs(src0.y - src1.y) + src2.y
-  dst.z = abs(src0.z - src1.z) + src2.z
-  dst.w = abs(src0.w - src1.w) + src2.w
 
+.. opcode:: SAD - Sum Of Absolute Differences
 
-1.11.12  TXF - Texel Fetch
+.. math::
+
+  dst.x = |src0.x - src1.x| + src2.x
+
+  dst.y = |src0.y - src1.y| + src2.y
+
+  dst.z = |src0.z - src1.z| + src2.z
+
+  dst.w = |src0.w - src1.w| + src2.w
+
+
+.. opcode:: TXF - Texel Fetch
 
   TBD
 
 
-1.11.13  TXQ - Texture Size Query
+.. opcode:: TXQ - Texture Size Query
 
   TBD
 
 
-1.11.14  CONT - Continue
+.. opcode:: CONT - Continue
 
   TBD
 
 
-1.12  GL_NV_geometry_program4
------------------------------
+From GL_NV_geometry_program4
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 
-1.12.1  EMIT - Emit
+.. opcode:: EMIT - Emit
 
   TBD
 
 
-1.12.2  ENDPRIM - End Primitive
+.. opcode:: ENDPRIM - End Primitive
 
   TBD
 
 
-1.13  GLSL
-----------
+From GLSL
+^^^^^^^^^^
 
 
-1.13.1  BGNLOOP - Begin a Loop
+.. opcode:: BGNLOOP - Begin a Loop
 
   TBD
 
 
-1.13.2  BGNSUB - Begin Subroutine
+.. opcode:: BGNSUB - Begin Subroutine
 
   TBD
 
 
-1.13.3  ENDLOOP - End a Loop
+.. opcode:: ENDLOOP - End a Loop
 
   TBD
 
 
-1.13.4  ENDSUB - End Subroutine
+.. opcode:: ENDSUB - End Subroutine
 
   TBD
 
 
-
-1.13.10  NOP - No Operation
+.. opcode:: NOP - No Operation
 
   Do nothing.
 
 
+.. opcode:: NRM4 - 4-component Vector Normalise
+
+This instruction replicates its result.
 
-1.16.7  NRM4 - 4-component Vector Normalise
+.. math::
 
-  dst.x = src.x / (src.x * src.x + src.y * src.y + src.z * src.z + src.w * src.w)
-  dst.y = src.y / (src.x * src.x + src.y * src.y + src.z * src.z + src.w * src.w)
-  dst.z = src.z / (src.x * src.x + src.y * src.y + src.z * src.z + src.w * src.w)
-  dst.w = src.w / (src.x * src.x + src.y * src.y + src.z * src.z + src.w * src.w)
+  dst = \frac{src.x}{src.x \times src.x + src.y \times src.y + src.z \times src.z + src.w \times src.w}
 
 
-1.17  ps_2_x
-------------
+ps_2_x
+^^^^^^^^^^^^
 
 
-1.17.2  CALLNZ - Subroutine Call If Not Zero
+.. opcode:: CALLNZ - Subroutine Call If Not Zero
 
   TBD
 
 
-1.17.3  IFC - If
+.. opcode:: IFC - If
 
   TBD
 
 
-1.17.5  BREAKC - Break Conditional
+.. opcode:: BREAKC - Break Conditional
 
   TBD
 
+.. _doubleopcodes:
+
+Double Opcodes
+^^^^^^^^^^^^^^^
+
+.. opcode:: DADD - Add Double
+
+.. math::
+
+  dst.xy = src0.xy + src1.xy
+
+  dst.zw = src0.zw + src1.zw
+
+
+.. opcode:: DDIV - Divide Double
+
+.. math::
+
+  dst.xy = src0.xy / src1.xy
+
+  dst.zw = src0.zw / src1.zw
+
+.. opcode:: DSEQ - Set Double on Equal
+
+.. math::
+
+  dst.xy = src0.xy == src1.xy ? 1.0F : 0.0F
+
+  dst.zw = src0.zw == src1.zw ? 1.0F : 0.0F
+
+.. opcode:: DSLT - Set Double on Less than
+
+.. math::
+
+  dst.xy = src0.xy < src1.xy ? 1.0F : 0.0F
+
+  dst.zw = src0.zw < src1.zw ? 1.0F : 0.0F
+
+.. opcode:: DFRAC - Double Fraction
+
+.. math::
+
+  dst.xy = src.xy - \lfloor src.xy\rfloor
+
+  dst.zw = src.zw - \lfloor src.zw\rfloor
+
+
+.. opcode:: DFRACEXP - Convert Double Number to Fractional and Integral Components
 
-2  Explanation of symbols used
-==============================
+.. math::
 
+  dst0.xy = frexp(src.xy, dst1.xy)
 
-2.1  Functions
---------------
+  dst0.zw = frexp(src.zw, dst1.zw)
 
+.. opcode:: DLDEXP - Multiple Double Number by Integral Power of 2
 
-  abs(x)            Absolute value of x.
-                    '|x|'
-                    (x < 0.0) ? -x : x
+.. math::
 
-  ceil(x)           Ceiling of x.
+  dst.xy = ldexp(src0.xy, src1.xy)
+
+  dst.zw = ldexp(src0.zw, src1.zw)
+
+.. opcode:: DMIN - Minimum Double
+
+.. math::
+
+  dst.xy = min(src0.xy, src1.xy)
+
+  dst.zw = min(src0.zw, src1.zw)
+
+.. opcode:: DMAX - Maximum Double
+
+.. math::
+
+  dst.xy = max(src0.xy, src1.xy)
+
+  dst.zw = max(src0.zw, src1.zw)
+
+.. opcode:: DMUL - Multiply Double
+
+.. math::
+
+  dst.xy = src0.xy \times src1.xy
+
+  dst.zw = src0.zw \times src1.zw
+
+
+.. opcode:: DMAD - Multiply And Add Doubles
+
+.. math::
+
+  dst.xy = src0.xy \times src1.xy + src2.xy
+
+  dst.zw = src0.zw \times src1.zw + src2.zw
+
+
+.. opcode:: DRCP - Reciprocal Double
+
+.. math::
+
+   dst.xy = \frac{1}{src.xy}
+
+   dst.zw = \frac{1}{src.zw}
+
+.. opcode:: DSQRT - Square root double
+
+.. math::
+
+   dst.xy = \sqrt{src.xy}
+
+   dst.zw = \sqrt{src.zw}
+
+
+Explanation of symbols used
+------------------------------
+
+
+Functions
+^^^^^^^^^^^^^^
+
+
+  :math:`|x|`       Absolute value of `x`.
+
+  :math:`\lceil x \rceil` Ceiling of `x`.
 
   clamp(x,y,z)      Clamp x between y and z.
                     (x < y) ? y : (x > z) ? z : x
 
-  cos(x)            Cosine of x.
-
-  floor(x)          Floor of x.
+  :math:`\lfloor x\rfloor` Floor of `x`.
 
-  lg2(x)            Logarithm base 2 of x.
+  :math:`\log_2{x}` Logarithm of `x`, base 2.
 
   max(x,y)          Maximum of x and y.
                     (x > y) ? x : y
@@ -834,48 +1205,60 @@ Support for these opcodes indicated by a special pipe capability bit (TBD).
 
   pop()             Pop from stack.
 
-  pow(x,y)          Raise x to power of y.
+  :math:`x^y`       `x` to the power `y`.
 
   push(x)           Push x on stack.
 
   round(x)          Round x.
 
-  sin(x)            Sine of x.
+  trunc(x)          Truncate x, i.e. drop the fraction bits.
 
-  sqrt(x)           Square root of x.
 
-  trunc(x)          Truncate x.
+Keywords
+^^^^^^^^^^^^^
 
 
-2.2  Keywords
--------------
+  discard           Discard fragment.
 
+  pc                Program counter.
 
-  discard           Discard fragment.
+  target            Label of target instruction.
 
-  dst               First destination register.
 
-  dst0              First destination register.
+Other tokens
+---------------
 
-  pc                Program counter.
 
-  src               First source register.
+Declaration
+^^^^^^^^^^^
 
-  src0              First source register.
 
-  src1              Second source register.
+Declares a register that is will be referenced as an operand in Instruction
+tokens.
 
-  src2              Third source register.
+File field contains register file that is being declared and is one
+of TGSI_FILE.
 
-  target            Label of target instruction.
+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.
 
-3  Other tokens
-===============
+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.
 
 
-3.1  Declaration Semantic
--------------------------
+Declaration Semantic
+^^^^^^^^^^^^^^^^^^^^^^^^
 
 
   Follows Declaration token if Semantic bit is set.
@@ -894,10 +1277,172 @@ Support for these opcodes indicated by a special pipe capability bit (TBD).
   The meanings of the individual semantic names are explained in the following
   sections.
 
+TGSI_SEMANTIC_POSITION
+""""""""""""""""""""""
+
+Position, sometimes known as HPOS or WPOS for historical reasons, is the
+location of the vertex in space, in ``(x, y, z, w)`` format. ``x``, ``y``, and ``z``
+are the Cartesian coordinates, and ``w`` is the homogenous coordinate and used
+for the perspective divide, if enabled.
+
+As a vertex shader output, position should be scaled to the viewport. When
+used in fragment shaders, position will be in window coordinates. The convention
+used depends on the FS_COORD_ORIGIN and FS_COORD_PIXEL_CENTER properties.
+
+XXX additionally, is there a way to configure the perspective divide? it's
+accelerated on most chipsets AFAIK...
+
+Position, if not specified, usually defaults to ``(0, 0, 0, 1)``, and can
+be partially specified as ``(x, y, 0, 1)`` or ``(x, y, z, 1)``.
+
+XXX usually? can we solidify that?
+
+TGSI_SEMANTIC_COLOR
+"""""""""""""""""""
+
+Colors are used to, well, color the primitives. Colors are always in
+``(r, g, b, a)`` format.
+
+If alpha is not specified, it defaults to 1.
+
+TGSI_SEMANTIC_BCOLOR
+""""""""""""""""""""
+
+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, so
+all BCOLORs effectively become regular COLORs in the fragment shader.
+
+TGSI_SEMANTIC_FOG
+"""""""""""""""""
+
+The fog coordinate historically has been used to replace the depth coordinate
+for generation of fog in dedicated fog blocks. Gallium, however, does not use
+dedicated fog acceleration, placing it entirely in the fragment shader
+instead.
+
+The fog coordinate should be written in ``(f, 0, 0, 1)`` format. 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.
+
+TGSI_SEMANTIC_PSIZE
+"""""""""""""""""""
+
+PSIZE, or point size, is used to specify point sizes per-vertex. It should
+be in ``(s, 0, 0, 1)`` format, where ``s`` is the (possibly clamped) point size.
+Only the first component matters when writing from the vertex shader.
+
+When using this semantic, be sure to set the appropriate state in the
+:ref:`rasterizer` first.
+
+TGSI_SEMANTIC_GENERIC
+"""""""""""""""""""""
+
+Generic semantics are nearly always used for texture coordinate attributes,
+in ``(s, t, r, q)`` format. ``t`` and ``r`` may be unused for certain kinds
+of lookups, and ``q`` is the level-of-detail bias for biased sampling.
+
+These attributes are called "generic" because they may be used for anything
+else, including parameters, texture generation information, or anything that
+can be stored inside a four-component vector.
+
+TGSI_SEMANTIC_NORMAL
+""""""""""""""""""""
+
+Vertex normal; could be used to implement per-pixel lighting for legacy APIs
+that allow mixing fixed-function and programmable stages.
+
+TGSI_SEMANTIC_FACE
+""""""""""""""""""
+
+FACE is the facing bit, to store the facing information for the fragment
+shader. ``(f, 0, 0, 1)`` is the format. The first component will be positive
+when the fragment is front-facing, and negative when the component is
+back-facing.
+
+TGSI_SEMANTIC_EDGEFLAG
+""""""""""""""""""""""
+
+XXX no clue
+
+
+Properties
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+
+  Properties are general directives that apply to the whole TGSI program.
+
+FS_COORD_ORIGIN
+"""""""""""""""
+
+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.
+
+FS_COORD_PIXEL_CENTER
+"""""""""""""""""""""
+
+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.
+
+
+
+Texture Sampling and Texture Formats
+------------------------------------
 
-3.1.1  FACE
+This table shows how texture image components are returned as (x,y,z,w) tuples
+by TGSI texture instructions, such as :opcode:`TEX`, :opcode:`TXD`, and
+:opcode:`TXP`. For reference, OpenGL and Direct3D conventions are shown as
+well.
 
-  Valid only in a fragment shader INPUT declaration.
++--------------------+--------------+--------------------+--------------+
+| Texture Components | Gallium      | OpenGL             | Direct3D 9   |
++====================+==============+====================+==============+
+| R                  | XXX TBD      | (r, 0, 0, 1)       | (r, 1, 1, 1) |
++--------------------+--------------+--------------------+--------------+
+| RG                 | XXX TBD      | (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)       | (u, v, 1, 1) |
+|                    |              | [#envmap-bumpmap]_ |              |
++--------------------+--------------+--------------------+--------------+
+| Z                  | XXX TBD      | (z, z, z, 1)       | (0, z, 0, 1) |
+|                    |              | [#depth-tex-mode]_ |              |
++--------------------+--------------+--------------------+--------------+
 
-  FACE.x is negative when the primitive is back facing. FACE.x is positive
-  when the primitive is front facing.
+.. [#envmap-bumpmap] http://www.opengl.org/registry/specs/ATI/envmap_bumpmap.txt
+.. [#depth-tex-mode] 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.