ID3D11Device::CreateBuffer method (d3d11.h)

Creates a buffer (vertex buffer, index buffer, or shader-constant buffer).

Syntax

HRESULT CreateBuffer(
  [in]            const D3D11_BUFFER_DESC      *pDesc,
  [in, optional]  const D3D11_SUBRESOURCE_DATA *pInitialData,
  [out, optional] ID3D11Buffer                 **ppBuffer
);

Parameters

[in] pDesc

Type: const D3D11_BUFFER_DESC*

A pointer to a D3D11_BUFFER_DESC structure that describes the buffer.

[in, optional] pInitialData

Type: const D3D11_SUBRESOURCE_DATA*

A pointer to a D3D11_SUBRESOURCE_DATA structure that describes the initialization data; use NULL to allocate space only (with the exception that it cannot be NULL if the usage flag is D3D11_USAGE_IMMUTABLE).

If you don't pass anything to pInitialData, the initial content of the memory for the buffer is undefined. In this case, you need to write the buffer content some other way before the resource is read.

[out, optional] ppBuffer

Type: ID3D11Buffer**

Address of a pointer to the ID3D11Buffer interface for the buffer object created. Set this parameter to NULL to validate the other input parameters (S_FALSE indicates a pass).

Return value

Type: HRESULT

This method returns E_OUTOFMEMORY if there is insufficient memory to create the buffer. See Direct3D 11 Return Codes for other possible return values.

Remarks

For example code, see How to: Create a Vertex Buffer, How to: Create an Index Buffer or How to: Create a Constant Buffer.

For a constant buffer (BindFlags of D3D11_BUFFER_DESC set to D3D11_BIND_CONSTANT_BUFFER), you must set the ByteWidth value of D3D11_BUFFER_DESC in multiples of 16, and less than or equal to D3D11_REQ_CONSTANT_BUFFER_ELEMENT_COUNT.

The Direct3D 11.1 runtime, which is available on Windows 8 and later operating systems, provides the following new functionality for CreateBuffer:

You can create a constant buffer that is larger than the maximum constant buffer size that a shader can access (4096 32-bit*4-component constants – 64KB). When you bind the constant buffer to the pipeline (for example, via PSSetConstantBuffers or PSSetConstantBuffers1), you can define a range of the buffer that the shader can access that fits within the 4096 constant limit.

The Direct3D 11.1 runtime (available in Windows 8 and later operating systems) emulates this feature for feature level 9.1, 9.2, and 9.3; therefore, this feature is supported for feature level 9.1, 9.2, and 9.3.

This feature is always available on new drivers for feature level 10 and higher.

On runtimes older than Direct3D 11.1, a call to CreateBuffer to request a constant buffer that is larger than 4096 fails.

Requirements

Requirement Value
Target Platform Windows
Header d3d11.h
Library D3D11.lib

See also

ID3D11Device