> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CreateCommittedResource

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

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.

## Syntax

```cpp theme={null}
HRESULT CreateCommittedResource(
    const D3D12_HEAP_PROPERTIES  pHeapProperties,
    D3D12_HEAP_FLAGS HeapFlags,
    const D3D12_RESOURCE_DESC* pDesc,
    D3D12_RESOURCE_STATES InitialResourceState,
    const D3D12_CLEAR_VALUE  pOptimizedClearValue,
    const IID & riidResource,
    void  ppvResource
)
```

### Parameters

*pHeapProperties \[in]*<br />Type: const D3D12\_HEAP\_PROPERTIES \*

A pointer to a **D3D12\_HEAP\_PROPERTIES** structure that provides properties for the resource's heap.

*HeapFlags \[in]*<br />Type: D3D12\_HEAP\_FLAGS

Heap options, as a bitwise-OR'd combination of **D3D12\_HEAP\_FLAGS** enumeration constants.

*pDesc \[in]*<br />Type: **const [D3D12\_RESOURCE\_DESC](/reference/graphics/d3d12/structs/d3d12_resource_desc_public)\***

A pointer to a **D3D12\_RESOURCE\_DESC** structure that describes the resource.

*InitialResourceState \[in]*<br />Type: [**D3D12\_RESOURCE\_STATES**](/reference/graphics/d3d12_x/enums/d3d12_resource_states)

The initial state of the resource, as a bitwise-OR'd combination of **D3D12\_RESOURCE\_STATES** enumeration constants.

When you create a resource together with a [D3D12\_HEAP\_TYPE\_UPLOAD](/reference/graphics/d3d12/enums/d3d12_heap_type_public) heap, you must set *InitialResourceState* to [D3D12\_RESOURCE\_STATE\_GENERIC\_READ](/reference/graphics/d3d12_x/enums/d3d12_resource_states).

When you create a resource together with a [D3D12\_HEAP\_TYPE\_READBACK](/reference/graphics/d3d12/enums/d3d12_heap_type_public) heap, you must set *InitialResourceState* to [D3D12\_RESOURCE\_STATE\_COPY\_DEST](/reference/graphics/d3d12_x/enums/d3d12_resource_states).

*pOptimizedClearValue \[in, optional]*<br />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](/reference/graphics/d3d12_x/enums/d3d12_resource_flags) 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](/reference/graphics/d3d12_x/enums/d3d12_resource_dimension), you must set *pOptimizedClearValue* to `nullptr`.

*riidResource \[in]*<br />Type: const IID &

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](/reference/graphics/d3d12_xs/interfaces/ID3D12Resource/id3d12resource_xs), 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**.

*ppvResource \[out, optional]*<br />Type: void \*\*

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.

### Return value

Type: HRESULT

If the function succeeds, it returns **S\_OK**. Otherwise, it returns an [**HRESULT**](https://learn.microsoft.com/en-us/windows/desktop/com/structure-of-com-error-codes) [error code](https://learn.microsoft.com/en-us/windows/win32/com/com-error-codes-10).

| Return value   | Description                                          |
| -------------- | ---------------------------------------------------- |
| E\_OUTOFMEMORY | There is insufficient memory to create the resource. |

See [Direct3D 12 return codes](https://learn.microsoft.com/en-us/windows/win32/direct3d12/d3d12-graphics-reference-returnvalues) for other possible return values.

## Remarks

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](https://learn.microsoft.com/en-us/windows/win32/direct3d12/residency).

The resource GPU VA mapping can't be changed. See [ID3D12CommandQueue::UpdateTileMappings](/reference/graphics/d3d12/interfaces/id3d12commandqueue/methods/id3d12commandqueue_updatetilemappings_public) and [Volume tiled resources](https://learn.microsoft.com/en-us/windows/win32/direct3d12/volume-tiled-resources).

This method may be called by multiple threads concurrently.

## Examples

The [D3D12Bundles](https://learn.microsoft.com/en-us/windows/win32/direct3d12/working-samples) sample uses **ID3D12Device::CreateCommittedResource** as follows:

Create a vertex buffer.

```cpp theme={null}
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)));
```

See [Example code in the Direct3D 12 reference](https://learn.microsoft.com/en-us/windows/win32/direct3d12/notes-on-example-code).

## Requirements

**Header:** d3d12\_xs.h or d3d12\_x.h<br />**Library:** d3d12\_xs.lib or d3d12\_x.lib<br />**Supported Platforms**: XBOX Series consoles and XBOX One family

## See Also

[CreatePlacedResource](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createplacedresource_public)

[CreateReservedResource](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createreservedresource_public)

[D3D12\_HEAP\_FLAGS](/reference/graphics/d3d12_x/enums/d3d12_heap_flags)

[ID3D12Device](/reference/graphics/d3d12_x/interfaces/id3d12device/id3d12device)


## Related topics

- [CreateCommittedResource1 (XBOX Series consoles)](/reference/graphics/d3d12/interfaces/id3d12device4/methods/id3d12device4_createcommittedresource1_public.md)
- [CreateReservedResource](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createreservedresource_public.md)
- [CreatePlacedResource](/reference/graphics/d3d12/interfaces/id3d12device/methods/id3d12device_createplacedresource_public.md)
- [CreateReservedResource2 (XBOX Series consoles)](/reference/graphics/d3d12/interfaces/id3d12device10/methods/id3d12device10_createreservedresource2_public.md)
- [CreatePlacedResource2 (XBOX Series consoles)](/reference/graphics/d3d12/interfaces/id3d12device10/methods/id3d12device10_createplacedresource2_public.md)
