Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Instruction modifiers affect the result of the instruction before it is written into the destination register. For instance, use them to multiply or divide the result by a factor of two, or to clamp the result between zero and one. Instruction modifiers are applied after the instruction runs but before writing the result to the destination register.
A list of the modifiers is shown below.
Modifier | Description | Syntax | Version 1_1 | Version 1_2 | Version 1_3 | Version 1_4 |
---|---|---|---|---|---|---|
_x2 | Multiply by 2 | instruction_x2 | X | X | X | X |
_x4 | Multiply by 4 | instruction_x4 | X | X | X | X |
_x8 | Multiply by 8 | instruction_x8 | X | |||
_d2 | Divide by 2 | instruction_d2 | X | X | X | X |
_d4 | Divide by 4 | instruction_d4 | X | |||
_d8 | Divide by 8 | instruction_d8 | X | |||
_sat | Saturate (clamp from 0 and 1) | instruction_sat | X | X | X | X |
Instruction modifiers can be used on arithmetic instructions. They may not be used on texture address instructions.
Multiply modifier
This example loads the destination register (dest) with the sum of the two colors in the source operands (src0 and src1) and multiplies the result by two.
add_x2 dest, src0, src1
This example combines two instruction modifiers. First, two colors in the source operands (src0 and src1) are added. The result is then multiplied by two, and clamped between 0.0 to 1.0 for each component. The result is saved in the destination register.
add_x2_sat dest, src0, src1
Divide modifier
This example loads the destination register (dest) with the sum of the two colors in the source operands (src0 and src1) and divides the result by two.
add_d2 dest, src0, src1
Saturate modifier
For arithmetic instructions, the saturation modifier clamps the result of this instruction into the range 0.0 to 1.0 for each component. The following example shows how to use this instruction modifier.
dp3_sat r0, t0_bx2, v0_bx2 ; t0 is bump, v0 is light direction
This operation occurs after any multiply or divide instruction modifier. _sat is most often used to clamp dot product results. However, it also enables consistent emulation of multipass methods where the frame buffer is always in the range 0 to 1, and of DirectX 6 and 7.0 multitexture syntax, in which saturation is defined to occur at every stage.
This example loads the destination register (dest) with the sum of the two colors in the source operands (src0 and src1), and clamps the result into the range 0.0 to 1.0 for each component.
add_sat dest, src0, src1
This example combines two instruction modifiers. First, two colors in the source operands (src0 and src1) are added. The result is multiplied by two and clamped between 0.0 to 1.0 for each component. The result is saved in the destination register.
add_x2_sat dest, src0, src1
Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register today