switch (sm4 - asm)

Transfers control to a different statement block within the switch body depending on the value of a selector.

switch src0.selected_component
Item Description
src0
[in] The selector for the switch statement.

Remarks

A switch/endswitch construct behaves exactly as a switch construct in the C language, with the following exception: for D3D11 case/default statements that fall through to the next case/default without a break cannot have any code in them. It is permitted for multiple case statements, including default, to appear sequentially, sharing the same code block.

The condition must be a 32-bit register component or immediate quantity. The equality comparison is bitwise (integer).

As with any Shader instruction in the D3D11, hardware may or may not implement the switch construct directly.

Switch statements can be nested. Each switch block counts as 1 level against the flow control nesting depth limit of 64 per subroutine and main, independent of the number of case statements. The HLSL compiler will not generate subroutines that exceed this limit. Behavior of control flow instructions beyond 64 levels deep per subroutine is undefined.

The following example shows how to use this instruction.

                ...
                switch r0.x
                default: // falling through
                case 3
                    switch r1.x
                    case 4
                        ...
                        break
                    case 5
                        ...
                        break
                    endswitch
                    break
                case 0
                    break
                endswitch

This instruction applies to the following shader stages:

Vertex Shader Geometry Shader Pixel Shader
x x x

Minimum Shader Model

This function is supported in the following shader models.

Shader Model Supported
Shader Model 5 yes
Shader Model 4.1 yes
Shader Model 4 yes
Shader Model 3 (DirectX HLSL) no
Shader Model 2 (DirectX HLSL) no
Shader Model 1 (DirectX HLSL) no

Shader Model 4 Assembly (DirectX HLSL)