Graphics Reference
In-Depth Information
already seen for the other programmable stages using the ID3DllDevice: :CreateGeometry
Shader(...) method. However, if the stream output stage will be used, the shader object
must be created with the ID3DllDevice: :CreateGeometryShaderWithStreamOutput(...)
method. This method takes several additional parameters, which configure the stream output
stage and the way that data will be streamed to the buffers attached to it. The details of how
to configure these parameters for the stream output version will be discussed in the "Stream
Output" stage section of this chapter. Simply keep in mind for now that there are two different
ways to create the shader object, depending on whether the stream output will be used.
Once the geometry shader object has been created, it can be set in the geometry
shader stage with the usual ID3DllDeviceContext method. Similarly, the constant buffers,
shader resource views, and samplers required for the geometry shader program are ma-
nipulated in the standard common shader core methods. They are listed here for reference.
ID3D11DeviceContext::GSSetShader()
ID3D11DeviceContext::GSSetConstantBuffers()
ID3D11DeviceContext::GSSetShaderResources()
ID3D11DeviceContext::GSSetSamplers()
Function Attributes
The geometry shader stage also supports two function attributes that must be declared
prior to the geometry shader function in the HLSL source file. The first attribute is the
maxvertexcount parameter, which allows the developer to specify just that—the maxi-
mum number of vertices that an invocation of the geometry shader will emit into its output
stream. This is required to ensure that the geometry shader doesn't output an erroneous
number of vertices if it has a logic error. It also lets the GPU properly allocate memory for
the number of vertices it expects to be produced by each invocation of the geometry shader.
This attribute is mandatory and must be provided for the geometry shader function to com-
pile properly. An example of this function attribute can be seen in Listing 3.16.
There is a limit to how much data that can be produced by a single geometry shader
invocation. The number of scalar values may not exceed 1024. This means that the num-
ber of scalar values used in a vertex structure must be summed, and then multiplied by the
maximum number of vertices provided in the maxvertexcount attribute. This value must
be less than or equal to 1024. We will see later that up to four different streams can be used
simultaneously when using the stream output functionality, but for the purposes of this
maximum output calculation, we can simply take the largest vertex size of all of the output
streams being used and multiply that by the maxvertexcount attribute.
Search WWH ::




Custom Search