-
The Rendering Pipeline - Before TessellationCS/게임 프로그래밍 2024. 2. 4. 22:25
Input Assembler
Input of Input Assembler
- Vertex buffer : there are a total of 16 input slots that the application can set.
void ID3D11DeviceContext::IASetVertexBuffers( // A index of the first slot to connect resources among vertex buffer slots UINT StartSlot, // The total number of buffers to be connected to slots UINT NumBuffers, // A continuous array of pointers indicating buffer resources to be connected ID3D11Buffer* const *ppVertexBuffers, // A stride for each vertex buffer, which means the distance from the vertex to the next vertex const UINT *pStrides, // Offsets to designate the location of the vertex to be used for the first time const UINT *pOffsets );
- Index buffer : there are a total of 1 input slots that the application can set.
void ID3D11DeviceContext::IASetIndexBuffer( // A pointer indicating the index buffer ID3D11Buffer* pBuffer, // The format of the index stored in the buffer DXGI_FORMAT Format, // The offset of the first index to be used to create a basic figure in the index buffer UINT offset );
- Disconnect the buffer : call the same method by setting the NULL pointer value in the input slot.
Status Description of Input Assembler
- Input layout object : make vertex streams.
- Define how attributes of vertices are placed in memory.
- Specify the compiled shader byte code when creating the input layout object.
- To ensure that the vertices assembled by the input assembler match the vertices required to execute the vertex shader program.
- The burden of verifying the validity of the shader is reduced at runtime.
struct D3D11_INPUT_ELEMENT_DESC { // Fields for data by vertex LPCSTR SemanticName; UINT SemanticIndex; DXGI_FORMAT Format; UINT InputSlot; UINT AlignedByteOffset; // Fields for each instance D3D11_INPUT_CLASSIFICATION InputSlotClass; UINT InstanceDataStepRate; };
- Primitive topology : make primitive streams.
- Provide a method of creating various basic figures from the assembled vertex stream.
- Point list
- Line list / line strip
- Triangle list / triangle strip
- Topology including adjacent basic figure information
- Control point patch list
- Provide a method of creating various basic figures from the assembled vertex stream.
Process of Input Assembler
- Basic draw method
- Construct vertices based on a given input layout. (vertex stream)
- Refine the vertex stream to create primitives. (primitive stream)
- The most basic vertex and primitive construction process.
- Indexed draw method
- The vertices used to construct the primitives are determined by the indices.
- Instanced draw method
- The vertex and index stream are repeated for each instance of the model. (object)
- Vertex components for each instance are updated each time one instance is completed.
- The number of instances is determined by the parameters given to the draw method call.
- Indirect draw method
- Parameters of the draw method are indirectly specified through buffer resources rather than directly specified in code.
- To dynamically control the rendering method by filling the input parameter buffer in the GPU.
Output of Input Assembler
- The array of input layout must match the input signature declared on the vertex shader.
- Examples of input signature
- float3 position : the position of the input vertex
- float3 normal : the normal vector of the input vertex
- float3 tangent : the tangential vector of the input vertex
- float3 bitangent : the overlapping
- float4 boneIDs
- float4 boneWeight
- System value semantics
- SV_VertexID : unsigned interger; a means of simply identifying individual vertices in subsequent stages.
- SV_PrimitiveID : a means of identifying each primitives of a primitive stream.
- SV_InstanceID : a means of identifying each instance of the geometry in an instnaced draw method.
Vertex Shader
Input of Vertex Shader
- Assembled vertices that meet the format required by the vertex shader program.
- Input signature set by input layout object : ID3D11InputLayout
- System value semantics : SV_VertexID, SV_InstanceID
Status Description of Vertex Shader
// Set a shader program to the vertex shader void ID3D11DeviceContext::VSSetShader( // Pointer to a vertex shader // Passing in NULL disables the shader for this pipeline stage ID3D11VertexShader *pVertexShader, // A pointer to an array of class-instance interfaces ID3D11ClassInstance * const *ppClassInstances, // The number of class-instance interfaces in the array UINT NumClassInstances ); // Get the shader program currently set on the vertex shader void ID3D11DeviceContext::VSGetShader( ID3D11VertexShader **pVertexShader, ID3D11ClassInstance **ppClassInstances, UINT *pNumClassInstances );
- Constant buffer : useful when trying to convey unchanged values throughout one pipeline execution to the shader program.
// Set the constant buffers used by the vertex shader pipeline stage void ID3D11DeviceContext::VSSetConstantBuffers( UINT StartSlot, UINT NumBuffers, ID3D11Buffer * const *ppConstantBuffers );
- Shader resource veiw : the resources must be connected to the vertex shader stage using the shader reousrce view to access read-only resources in the vertex shader program.
// Bind an array of shader resources to the vertex shader stage void ID3D11DeviceContext::VSSetShaderResources( UINT StartSlot, UINT NumViews, ID3D11ShaderResourceView * const * ppShaderResourceViews );
- Sampler status object : provide the ability to perform various filtering operation when reading texels from a texture resource
// Set an array of sampler states to the vertex shader pipeline stage void ID3D11DeviceContext::VSSetSamplers( UINT StartSlot, UINT NumSamplers, ID3D11SamplerState * const *ppSamplers );
Process of Vertex Shader
- Geometric manipulation
- Apply the transformation matrix to the vertex position.
- Vertex skinning
- Per-vertex lighting
- Efficient because of calculating the illumination formula for vertices, not for every pixel.
- Cover the defects caused by the low resolution of the calculation, since the calculated values are subsequently interpolated between the vertices.
- General per-vertex calculation
- Beneficial to perform the calculation in the vertex shader stage, if it is okay to use the value obtained by interpolating data for each vertex in pixel-level processing.
- Per-vertex calculation = per-pixel calculation if given calculation is a linear combination of inputs.
- Control patch
- Deal with the control points of the higher order primitive (control patch), not the vertex.
- The control points are evaluated in the tessellation stage to produce vertices that actually define the geometric surface of the mesh.
- Vertex caching
- Several primitives can share the results of processing one vertex.
- Caching operations depend on the hardware. (GPU)
- Important to ensure that shared vertices are referenced as close as possible within vertex input data.
Output of Vertex Shader
- Stages to be connected
- Tessellation stages : control points must be provided in the hull shader stage.
- Geometry shader
- Rasterizer : the final clipping space position should be included in the SV_Position
- SV_Position
- The final location of the clip space position.
- The last activation stage prior to the rasterizer must provide a SV_Position
- SV_ClipDistance[n], SV_CullDistance[n]
- All previous stages of the rasterizer, including the vertex shader, can change the values.
- Used in the rasterizer to perform clipping and culling operations.
- Up to two can be used in one pipeline, combining the clipping and culling semantics.
'CS > 게임 프로그래밍' 카테고리의 다른 글
The Tessellation Pipeline (0) 2024.02.12 The Rendering Pipeline - After Tessellation (0) 2024.02.05 The Rendering Pipeline - Background (0) 2024.02.04 Direct3D 11 Resources (0) 2024.02.02 Overview of Direct3D 11 (0) 2024.01.29