ID3D12CommandAllocator interface

Represents the allocations of storage for graphics processing unit (GPU) commands.

Methods

The ID3D12CommandAllocator interface has these methods.

Method Description
ID3D12CommandAllocator::Reset Indicates to re-use the memory that is associated with the command allocator.

Remarks

Use ID3D12Device::CreateCommandAllocator to create a command allocator object.

The command allocator object corresponds to the underlying allocations in which GPU commands are stored. The command allocator object applies to both direct command lists and bundles. You must use a command allocator object in a DirectX 12 app.

Examples

The D3D12nBodyGravity sample uses ID3D12CommandAllocator as follows:

Header file declarations.

C++
D3D12_VIEWPORT m_viewport;
D3D12_RECT m_scissorRect;
ComPtr m_swapChain;
ComPtr m_device;
ComPtr m_renderTargets[FrameCount];
ComPtr m_commandAllocator;
ComPtr m_commandQueue;
ComPtr m_rootSignature;
ComPtr m_rtvHeap;
ComPtr m_pipelineState;
ComPtr m_commandList;
UINT m_rtvDescriptorSize;

Asynchronous compute thread.

C++
DWORD D3D12nBodyGravity::AsyncComputeThreadProc(int threadIndex)
{
    ID3D12CommandQueue* pCommandQueue = m_computeCommandQueue[threadIndex].Get();
    ID3D12CommandAllocator* pCommandAllocator = m_computeAllocator[threadIndex].Get();
    ID3D12GraphicsCommandList* pCommandList = m_computeCommandList[threadIndex].Get();
    ID3D12Fence* pFence = m_threadFences[threadIndex].Get();
while (0 == InterlockedGetValue(&m_terminating))
{
    // Run the particle simulation.
    Simulate(threadIndex);

    // Close and execute the command list.
    ThrowIfFailed(pCommandList->Close());
    ID3D12CommandList* ppCommandLists[] = { pCommandList };

    pCommandQueue->ExecuteCommandLists(1, ppCommandLists);

    // Wait for the compute shader to complete the simulation.
    UINT64 threadFenceValue = InterlockedIncrement(&m_threadFenceValues[threadIndex]);
    ThrowIfFailed(pCommandQueue->Signal(pFence, threadFenceValue));
    ThrowIfFailed(pFence->SetEventOnCompletion(threadFenceValue, m_threadFenceEvents[threadIndex]));
    WaitForSingleObject(m_threadFenceEvents[threadIndex], INFINITE);

    // Wait for the render thread to be done with the SRV so that
    // the next frame in the simulation can run.
    UINT64 renderContextFenceValue = InterlockedGetValue(&m_renderContextFenceValues[threadIndex]);
    if (m_renderContextFence->GetCompletedValue() < renderContextFenceValue)
    {
        ThrowIfFailed(pCommandQueue->Wait(m_renderContextFence.Get(), renderContextFenceValue));
        InterlockedExchange(&m_renderContextFenceValues[threadIndex], 0);
    }

    // Swap the indices to the SRV and UAV.
    m_srvIndex[threadIndex] = 1 - m_srvIndex[threadIndex];

    // Prepare for the next frame.
    ThrowIfFailed(pCommandAllocator->Reset());
    ThrowIfFailed(pCommandList->Reset(pCommandAllocator, m_computeState.Get()));
}

return 0;

}

Refer to the Example Code in the D3D12 Reference.

Requirements

   
Target Platform Windows
Header d3d12.h

See Also

Core Interfaces

ID3D12Pageable