Graphics Reference
In-Depth Information
float3 Method1( )
{
return Member1;
}
};
float2 MyClass: :Method2( float2 param )
{
return Memberl.xy + param.xy;
}
Listing 6.10. Class declaration syntax.
While instances of classes can be declared and have methods called on them in nor-
mal shader programs, they are primarily used to enable dynamic shader linkage. See the
"Dynamic Shader Linkage" section for more information on using classes in HLSL.
6.3.8 Conditionals
Conditional code execution is supported through the if and case statements, which work
in the same manner as in C/C++. All if statements operate on a single Boolean value,
which can be created through the use of logical and comparison operators. It should be
noted that the Boolean result of vector operations cannot be directly used, because such
operations produce a vector result, rather than a single Boolean value. By extension this
same principle applies to switch statements.
It should be noted that conditional branching based on values that are only known
during the execution of a program can be expressed by the compiled shader assembly in
one of two ways: predication or dynamic branching. When predication is used, the com-
piler will emit code that evaluates the expressions on both sides of the branch. A compare
instruction is then used to "select" the correct value, based on the result of a comparison.
Dynamic branching, on the other hand, emits branching instructions that actually control
the flow of execution in the shader program. Thus, it can be used to potentially skip un-
needed calculations and memory accesses.
Whether or not instructions in a branch are skipped is based on the coherency of
the branching. In other words, simultaneous executions of a shader program must all
choose the same branch, to prevent the hardware from executing both sides of the branch.
Typically, the hardware will simultaneously execute a number of consecutive vertices in
the vertex shader, consecutive primitives in the geometry shader, and consecutive grids of
pixels in the pixel shader. For compute shaders, the threads are explicitly mapped to thread
groups, requiring coherency within each group. In addition, dynamic branching can impose
Search WWH ::




Custom Search