MSDN Documentation

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 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

D3D11CreateDevice( _In_opt_ IDXGIAdapter* pAdapter, _In_ D3D_DRIVER_TYPE DriverType, _In_opt_ HMODULE Software, _In_ UINT Flags, _In_reads_opt_(_In_reads_(FeatureLevels.Count)) const D3D_FEATURE_LEVEL* pFeatureLevels, _In_ UINT FeatureLevels.Count, _In_ UINT SDKVersion, _Out_opt_ ID3D11Device** ppDevice, _Out_opt_ D3D_FEATURE_LEVEL* pFeatureLevel, _Out_opt_ ID3D11DeviceContext** ppImmediateContext );

Resources

Direct3D 11 utilizes various resource interfaces for different data types:

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:

Shaders are typically written in High-Level Shading Language (HLSL) and compiled into binary bytecode.

Key Functions for Shaders

// Creating a vertex shader ID3D11VertexShader* pVS; pDevice->CreateVertexShader(bytecode, bytecodeLength, nullptr, &pVS); // Creating a pixel shader ID3D11PixelShader* pPS; pDevice->CreatePixelShader(bytecode, bytecodeLength, nullptr, &pPS); // Binding shaders to the pipeline pImmediateContext->VSSetShader(pVS, nullptr, 0); pImmediateContext->PSSetShader(pPS, nullptr, 0);

Graphics Pipeline Stages

The rendering pipeline is configured by binding various objects to the device context. Key stages include:

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:

Example Enumeration Value

D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_SHADER_RESOURCE