Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
Public Member Functions | Private Attributes | List of all members
blowbox::CommandQueue Class Reference

#include <command_queue.h>

Public Member Functions

 CommandQueue (D3D12_COMMAND_LIST_TYPE type)
 
 ~CommandQueue ()
 
bool IsFenceComplete (uint64_t fence_value)
 
uint64_t IncrementFence ()
 
void WaitForFence (uint64_t fence_value)
 
void WaitForIdle ()
 
void StallForFence (uint64_t fence_value)
 
void StallForProducer (CommandQueue *producer)
 
uint64_t ExecuteCommandList (ID3D12CommandList *list)
 
ID3D12CommandQueue * Get ()
 
ID3D12CommandAllocator * RequestAllocator ()
 
void DiscardAllocator (uint64_t fence_value, ID3D12CommandAllocator *allocator)
 

Private Attributes

D3D12_COMMAND_LIST_TYPE type_
 
ID3D12CommandQueue * queue_
 
CommandAllocatorPoolallocator_pool_
 
ID3D12Fence * fence_
 
uint64_t last_completed_fence_value_
 
uint64_t next_fence_value_
 
HANDLE fence_event_handle_
 

Detailed Description

Manages a ID3D12CommandQueue.

The CommandQueue wraps all functionality from a ID3D12CommandQueue. It handles the CommandQueue in a way that allows for smart CPU/GPU synchronization. It generates a fence value specifically for this type of CommandQueue. See remarks for an explanation of fence values. Additionally, the CommandQueue manages a CommandAllocatorPool for the type of CommandQueue that this is. If you need a CommandAllocator, you should request it through the CommandQueue.

Remarks
Remember, a fence_value is in fact two values. The first (highest-order) 8 bits represent the type of CommandQueue that generated the fence value. The remaining 56 bits are the actual value of the fence point. A fence point is essentially a point in time. After a command list is submitted, a fence point is generated for the correct command queue. That means that after every command list submission, a new point in time is "generated".

Constructor & Destructor Documentation

blowbox::CommandQueue::CommandQueue ( D3D12_COMMAND_LIST_TYPE  type)

Constructs a CommandQueue of a certain type.

Parameters
[in]typeThe type of command queue that should be created.
blowbox::CommandQueue::~CommandQueue ( )

Destructs the CommandQueue.

Member Function Documentation

void blowbox::CommandQueue::DiscardAllocator ( uint64_t  fence_value,
ID3D12CommandAllocator *  allocator 
)

Discards a ID3D12CommandAllocator back into the CommandAllocatorPool as soon as the given fence_value has been passed.

Parameters
[in]fence_valueThe fence value that needs to be passed before the ID3D12CommandAllocator can be repurposed.
[in]allocatorThe allocator that you want to release back into the CommandAllocatorPool.
Remarks
Remember, a fence_value is in fact two values. The first (highest-order) 8 bits represent the type of CommandQueue that generated the fence value. The remaining 56 bits are the actual value of the fence point. A fence point is essentially a point in time. After a command list is submitted, a fence point is generated for the correct command queue. That means that after every command list submission, a new point in time is "generated".
uint64_t blowbox::CommandQueue::ExecuteCommandList ( ID3D12CommandList *  list)

Submits a command list to the CommandQueue.

Parameters
[in]listThe list you want to submit
Returns
A fence value that, once passed, means that the submitted command list has been completed.
Remarks
Remember, a fence_value is in fact two values. The first (highest-order) 8 bits represent the type of CommandQueue that generated the fence value. The remaining 56 bits are the actual value of the fence point. A fence point is essentially a point in time. After a command list is submitted, a fence point is generated for the correct command queue. That means that after every command list submission, a new point in time is "generated".
ID3D12CommandQueue* blowbox::CommandQueue::Get ( )
inline
Returns
The underlying ID3D12CommandQueue.
uint64_t blowbox::CommandQueue::IncrementFence ( )

Increments the current fence and signals the CommandQueue.

bool blowbox::CommandQueue::IsFenceComplete ( uint64_t  fence_value)

Checks if a certain fence value has been passed.

Parameters
[in]fence_valueThe fence value you want to check if it was passed.
Remarks
Remember, a fence_value is in fact two values. The first (highest-order) 8 bits represent the type of CommandQueue that generated the fence value. The remaining 56 bits are the actual value of the fence point. A fence point is essentially a point in time. After a command list is submitted, a fence point is generated for the correct command queue. That means that after every command list submission, a new point in time is "generated".
ID3D12CommandAllocator * blowbox::CommandQueue::RequestAllocator ( )

Requests a ID3D12CommandAllocator from the underlying CommandAllocatorPool.

Returns
A ID3D12CommandAllocator which is ready for use.
void blowbox::CommandQueue::StallForFence ( uint64_t  fence_value)

Makes this CommandQueue wait with execution until the given fence value is hit. See remarks!

Parameters
[in]fence_valueThe fence value you want this CommandQueue to wait for.
Remarks
Remember, a fence_value is in fact two values. The first (highest-order) 8 bits represent the type of CommandQueue that generated the fence value. The remaining 56 bits are the actual value of the fence point. A fence point is essentially a point in time. After a command list is submitted, a fence point is generated for the correct command queue. That means that after every command list submission, a new point in time is "generated".
void blowbox::CommandQueue::StallForProducer ( CommandQueue producer)

Makes this CommandQueue wait with execution until a given CommandQueue is finished executing work.

Parameters
[in]producerThe other CommandQueue that has to be waited on.
void blowbox::CommandQueue::WaitForFence ( uint64_t  fence_value)

Makes the CommandQueue wait for a given fence value.

Parameters
[in]fence_valueThe fence value you want to wait on.
Remarks
Remember, a fence_value is in fact two values. The first (highest-order) 8 bits represent the type of CommandQueue that generated the fence value. The remaining 56 bits are the actual value of the fence point. A fence point is essentially a point in time. After a command list is submitted, a fence point is generated for the correct command queue. That means that after every command list submission, a new point in time is "generated".
void blowbox::CommandQueue::WaitForIdle ( )

Makes the CommandQueue wait for until it is completely empty (i.e. the GPU finished all the work submitted to this CommandQueue).

Member Data Documentation

CommandAllocatorPool* blowbox::CommandQueue::allocator_pool_
private

The CommandAllocatorPool that is controlled by this CommandQueue.

ID3D12Fence* blowbox::CommandQueue::fence_
private

The ID3D12Fence object that we use to synchronize the CPU with the GPU.

HANDLE blowbox::CommandQueue::fence_event_handle_
private

A handle to an event that we use to synchronize the CPU with the GPU.

uint64_t blowbox::CommandQueue::last_completed_fence_value_
private

The fence value that was most recently completed by the GPU.

uint64_t blowbox::CommandQueue::next_fence_value_
private

The next fence value that should be used when we want to submit a new unit of work.

ID3D12CommandQueue* blowbox::CommandQueue::queue_
private

The actual ID3D12CommandQueue.

D3D12_COMMAND_LIST_TYPE blowbox::CommandQueue::type_
private

The type of CommandQueue this is.


The documentation for this class was generated from the following files: