共用方式為


ifAny (HLSL)

Note

This HLSL attribute is available only when developing for the Xbox 360.

Executes the conditional part of an if statement when the condition is true for any thread on which the current shader is running.

Syntax

[ifAny]

Parameters

None.

Scope

Applies to if statements.

Remarks

Apply the ifAny attribute to if statements to make a dynamic branch behave more like a static branch. This causes all threads to branch together. The ifAny attribute executes conditional statements if the condition is true on any thread.

On static branches, the ifAny attribute is similar to the branch attribute. However, the ifAny attribute does not permit optimizations that need to invert the original branch condition.

On dynamic branches, the ifAny attribute differs from the branch attribute. When you apply the branch attribute to a dynamic if statement, the conditional statements are predicated. They are skipped only if no thread needs to execute the code. The branch attribute allows each thread to execute different instructions for an if statement. The ifAny attribute forces every thread to execute the same instructions.

Note that you cannot apply the ifAny attribute to a nested dynamic branch.

Examples

The following HLSL code snippet shows how to apply the ifAny attribute.

float x = tex2D( sampler, coord );
float result = g_value1;
[ifAny]
if (x > 0)
{
  result = g_value2;
}
    

See Also

Concepts

HLSL Attributes (Xbox 360)
Attribute Syntax
Attribute Categories

Reference

ifAll (HLSL)
branch (HLSL)
HLSL Attributes Reference (Xbox 360)