cmp

DirectX8

Microsoft DirectX 8.1 (pixel shader versions 1.2, 1.3, 1.4)

cmp

Conditionally chooses between src1 and src2, based on the comparison src0 >= 0.

cmp dest, src0, src1, src2

Registers

Argument Description RegistersVersion
vn cn tn rn
dest Destination register x x 1.2, 1.3
x 1.4
src0, src1, src2 Source register x x x x 1.2, 1.3
x x 1.4 phase 1
x x x 1.4 phase 2

To learn more about registers, see Registers.

Remarks

The comparison is done per channel.

For pixel shader version 1.2 and 1.3, cmp counts as two arithmetic instructions. Unfortunately, this was discovered too late in the development cycle, and therefore is not validated properly when calling CreatePixelShader. It is incorrectly being counted as consuming only one arithmetic instruction. Be sure to manually count this instruction as two arithmetic instructions toward the maximum instruction count. For more information about instruction counts, see Counting Instructions.

In addition, for pixel shader version 1.2 and 1.3, the destination register for cmp cannot be the same as any of the source registers. Validation does not catch this, so be sure to keep this in mind.

Example

This example does a four-channel comparison.

// Compares all four components.
ps.1.4
def c0, -0.6, 0.6, 0, 0.6
def c1  0,0,0,0
def c2  1,1,1,1

cmp r0, c0, c1, c2   // r0 is assigned 1,0,0,0 based on the following:
// r0.x = c2.x because c0.x <  0
// r0.y = c1.y because c0.y >= 0
// r0.z = c1.z because c0.z >= 0
// r0.w = c1.w because c0.w >= 0