Graphics Reference
In-Depth Information
a constant performance penalty, due to the overhead incurred from executing the actual
branch instructions. The basic texture Sample method also cannot be used within a dy-
namic branch in a pixel shader, since the partial derivatives may not be available, because
pixels in a quad may potentially take different branches. Consequently, it is important to
weigh the additional overhead of dynamic branching against the number of potentially
skipped instructions, while also considering the coherency of the branch.
By default, the compiler will automatically choose between predication and dynamic
branching, using heuristics. However, it is possible to override the compiler's decision-
using attributes. See the "Attributes" section in this chapter for more information.
6.3.9 Loops
HLSL supports for, while, and do while looping constructs. Like the conditional state-
ments, their syntax and usage is identical to their C/C++ equivalents. They are also simi-
lar to conditionals, in that they can potentially produce dynamic flow control instructions
when looping based on runtime values, and they thus have the same performance charac-
teristics with regard to coherency.
6.3.10 Semantics
In HLSL, semantics are string metadata attached to variables. They serve three primary
purposes when used in shader programs:
1. To specify the binding of variables used for passing values between shader stages
2. To allow shader programs to accept special system values generated by the pipeline
3. To allow shader programs to pass special system values interpreted by the pipeline
The code in listing 6.11 demonstrates these three use cases.
cbuffer PSConstants
{
float4x4 WVPMatrix;
}
Search WWH ::




Custom Search