Graphics Reference
In-Depth Information
They can also contain members with array types, or with other custom structure types.
Listing 6.8 demonstrates a simple structure declaration.
struct MyStructure
{
float4 Vec;
int Scalar;
float4x4 Mat;
float Array [8];
Listing 6.8. Structure declaration syntax.
6.3.5 Functions
HLSL allows for declaration of free functions in a manner similar to C/C++. Functions can
have any return type (including void), and can accept an arbitrary number of parameters.
Since HLSL does not support reference or pointer types, it has its own syntax for providing
input/output semantics for parameters. This syntax includes four modifiers for parameters,
which are listed in Table 6.2.
Modifier
Description
Parameter is an input to the function. Any changes to the parameter value
are temporary, and are not reflected in the calling code. Similar to pass-by-
value in C++. This is the default modifier.
in
Parameter is an output of the function. The value of the parameter must be
set by the function, and this change is reflected in the calling code.
out
Parameter is both an input and an output to the function. The function can
access the value of the parameter set by the calling code, and changes that
occur in the function are reflected in the calling code. Similar to pass-by-
reference in C++.
inout
Parameter is constant for the duration of execution. For functions that
aren't entry points, this modifier is equivalent to in. For entry point func-
tions, the parameter is declared as part of the SParam default constant
buffer.
uniform
Table 6.2. Function parameter modifiers.
Search WWH ::




Custom Search