Direct3D 11 API Reference
Introduction to Direct3D 11
Direct3D 11 is a powerful graphics API that provides a consistent interface for interacting with graphics hardware on Windows. It builds upon previous versions by introducing new features, improving performance, and simplifying the graphics programming model.
This section provides a comprehensive reference to the Direct3D 11 application programming interface (API), covering core concepts, objects, functions, structures, and enumerations necessary for developing high-performance graphics applications.
Core Concepts
Understanding these core concepts is fundamental to working with Direct3D 11:
- Device: Represents the graphics adapter and provides methods to create and manage resources, shaders, and other Direct3D objects.
- Device Context: Used to set the rendering pipeline state, bind resources, and issue rendering commands. There are immediate contexts and deferred contexts.
- Resources: Graphics objects like textures, vertex buffers, index buffers, constant buffers, and render targets.
- Shaders: Small programs that run on the GPU, responsible for tasks like vertex transformation, pixel coloring, and computation. Direct3D 11 introduces shader model 5.0.
- Graphics Pipeline: The sequence of operations that data goes through from input to output, managed and configured through the device context.
Device and Context
The ID3D11Device interface represents the graphics adapter. You typically create this object using D3D11CreateDevice.
The ID3D11DeviceContext interface is used to interact with the GPU. A device has an immediate context (ID3D11DeviceContext) and can create deferred contexts (also ID3D11DeviceContext) for multithreaded rendering.
Key Functions
Resources
Direct3D 11 utilizes various resource interfaces for different data types:
- ID3D11Buffer: For vertex buffers, index buffers, constant buffers, and stream-output buffers.
- ID3D11Texture1D, ID3D11Texture2D, ID3D11Texture3D: For 1D, 2D, and 3D textures, including render targets and depth-stencil surfaces.
- ID3D11ShaderResourceView: Represents a resource that can be read by shaders.
- ID3D11RenderTargetView: Represents a resource that can be written to by the pixel shader.
- ID3D11DepthStencilView: Represents a depth-stencil surface.
- ID3D11UnorderedAccessView: Allows shaders to read and write to resources, enabling GPGPU computations.
Key Structures for Resources
Structure Name | Description |
---|---|
D3D11_BUFFER_DESC | Describes a buffer resource. |
D3D11_TEXTURE2D_DESC | Describes a 2D texture resource. |
D3D11_SUBRESOURCE_DATA | Contains subresource data for resource creation. |
D3D11_SHADER_RESOURCE_VIEW_DESC | Describes a shader resource view. |
D3D11_RENDER_TARGET_VIEW_DESC | Describes a render target view. |
Shaders
Direct3D 11 supports various shader stages:
- Vertex Shader (VS)
- Hull Shader (HS)
- Domain Shader (DS)
- Geometry Shader (GS)
- Pixel Shader (PS)
- Compute Shader (CS)
Shaders are typically written in High-Level Shading Language (HLSL) and compiled into binary bytecode.
Key Functions for Shaders
Graphics Pipeline Stages
The rendering pipeline is configured by binding various objects to the device context. Key stages include:
- Input Assembler (IA): Fetches vertex data from buffers.
- Vertex Shader (VS): Processes vertices.
- Stream Output (SO): Outputs vertex data.
- Rasterizer (RS): Primitives clipping, culling, and perspective division.
- Pixel Shader (PS): Processes pixels.
- Output Merger (OM): Blends pixels, depth/stencil testing.
Key Functions for Pipeline State
Function Name | Description |
---|---|
VSSetShaderResources | Binds shader resource views to the vertex shader stage. |
PSSetSamplers | Binds sampler states to the pixel shader stage. |
IASetPrimitiveTopology | Sets the primitive topology for the Input Assembler. |
OMSetRenderTargets | Binds render target views and a depth-stencil view to the Output Merger stage. |
Key Enumerations
Enumerations define various states and flags for Direct3D objects:
- D3D_PRIMITIVE_TOPOLOGY: Defines primitive types like triangles, lines, and points.
- D3D11_BIND_FLAG: Specifies how a resource will be used (e.g., vertex buffer, shader resource).
- D3D11_CPU_ACCESS_FLAG: Defines CPU access for resources.
- D3D11_USAGE: Specifies resource memory usage patterns.