ID3D12Device::CreateCommittedResource method (d3d12.h)
Creates both a resource and an implicit heap, such that the heap is big enough to contain the entire resource, and the resource is mapped to the heap.
HRESULT CreateCommittedResource( [in] const D3D12_HEAP_PROPERTIES *pHeapProperties, [in] D3D12_HEAP_FLAGS HeapFlags, [in] const D3D12_RESOURCE_DESC *pDesc, [in] D3D12_RESOURCE_STATES InitialResourceState, [in, optional] const D3D12_CLEAR_VALUE *pOptimizedClearValue, [in] REFIID riidResource, [out, optional] void **ppvResource );
Type: const D3D12_HEAP_PROPERTIES*
A pointer to a D3D12_HEAP_PROPERTIES structure that provides properties for the resource's heap.
Heap options, as a bitwise-OR'd combination of D3D12_HEAP_FLAGS enumeration constants.
Type: const D3D12_RESOURCE_DESC*
A pointer to a D3D12_RESOURCE_DESC structure that describes the resource.
The initial state of the resource, as a bitwise-OR'd combination of D3D12_RESOURCE_STATES enumeration constants.
[in, optional] pOptimizedClearValue
Type: const D3D12_CLEAR_VALUE*
Specifies a D3D12_CLEAR_VALUE structure that describes the default value for a clear color.
pOptimizedClearValue specifies a value for which clear operations are most optimal. When the created resource is a texture with either the D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET or D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL flags, you should choose the value with which the clear operation will most commonly be called. You can call the clear operation with other values, but those operations won't be as efficient as when the value matches the one passed in to resource creation.
When you use D3D12_RESOURCE_DIMENSION_BUFFER, you must set pOptimizedClearValue to
A reference to the globally unique identifier (GUID) of the resource interface to return in ppvResource.
While riidResource is most commonly the GUID of ID3D12Resource, it may be the GUID of any interface. If the resource object doesn't support the interface for this GUID, then creation fails with E_NOINTERFACE.
[out, optional] ppvResource
An optional pointer to a memory block that receives the requested interface pointer to the created resource object.
ppvResource can be
nullptr, to enable capability testing. When ppvResource is
nullptr, no object is created, and S_FALSE is returned when pDesc is valid.
|E_OUTOFMEMORY||There is insufficient memory to create the resource.|
See Direct3D 12 return codes for other possible return values.
This method creates both a resource and a heap, such that the heap is big enough to contain the entire resource, and the resource is mapped to the heap. The created heap is known as an implicit heap, because the heap object can't be obtained by the application. Before releasing the final reference on the resource, your application must ensure that the GPU will no longer read nor write to this resource.
The implicit heap is made resident for GPU access before the method returns control to your application. Also see Residency.
This method may be called by multiple threads concurrently.
The D3D12Bundles sample uses ID3D12Device::CreateCommittedResource as follows:
Create a vertex buffer.
auto heapProperties = CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT); auto resourceDesc = CD3DX12_RESOURCE_DESC::Buffer(SampleAssets::VertexDataSize); ThrowIfFailed(m_device->CreateCommittedResource( &heapProperties, D3D12_HEAP_FLAG_NONE, &resourceDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, IID_PPV_ARGS(&m_vertexBuffer)));