Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
command_queue.h
1 #pragma once
2 
3 #include "renderer/d3d12_includes.h"
4 
5 namespace blowbox
6 {
7  class CommandAllocatorPool;
8 
24  {
25  public:
30  CommandQueue(D3D12_COMMAND_LIST_TYPE type);
31 
33  ~CommandQueue();
34 
42  bool IsFenceComplete(uint64_t fence_value);
43 
45  uint64_t IncrementFence();
46 
54  void WaitForFence(uint64_t fence_value);
55 
57  void WaitForIdle();
58 
66  void StallForFence(uint64_t fence_value);
67 
72  void StallForProducer(CommandQueue* producer);
73 
82  uint64_t ExecuteCommandList(ID3D12CommandList* list);
83 
85  ID3D12CommandQueue* Get() { return queue_; };
86 
91  ID3D12CommandAllocator* RequestAllocator();
92 
101  void DiscardAllocator(uint64_t fence_value, ID3D12CommandAllocator* allocator);
102 
103  private:
104  D3D12_COMMAND_LIST_TYPE type_;
105  ID3D12CommandQueue* queue_;
107 
108  ID3D12Fence* fence_;
110  uint64_t next_fence_value_;
112  };
113 }
void WaitForFence(uint64_t fence_value)
Makes the CommandQueue wait for a given fence value.
Definition: command_queue.cc:68
bool IsFenceComplete(uint64_t fence_value)
Checks if a certain fence value has been passed.
Definition: command_queue.cc:52
~CommandQueue()
Destructs the CommandQueue.
Definition: command_queue.cc:39
HANDLE fence_event_handle_
A handle to an event that we use to synchronize the CPU with the GPU.
Definition: command_queue.h:111
void DiscardAllocator(uint64_t fence_value, ID3D12CommandAllocator *allocator)
Discards a ID3D12CommandAllocator back into the CommandAllocatorPool as soon as the given fence_value...
Definition: command_queue.cc:114
ID3D12CommandQueue * Get()
Definition: command_queue.h:85
uint64_t last_completed_fence_value_
The fence value that was most recently completed by the GPU.
Definition: command_queue.h:109
void WaitForIdle()
Makes the CommandQueue wait for until it is completely empty (i.e. the GPU finished all the work subm...
Definition: command_queue.cc:79
uint64_t next_fence_value_
The next fence value that should be used when we want to submit a new unit of work.
Definition: command_queue.h:110
ID3D12CommandAllocator * RequestAllocator()
Requests a ID3D12CommandAllocator from the underlying CommandAllocatorPool.
Definition: command_queue.cc:108
void StallForProducer(CommandQueue *producer)
Makes this CommandQueue wait with execution until a given CommandQueue is finished executing work...
Definition: command_queue.cc:92
void StallForFence(uint64_t fence_value)
Makes this CommandQueue wait with execution until the given fence value is hit. See remarks! ...
Definition: command_queue.cc:85
Controls a pool of allocators of a certain type.
Definition: command_allocator_pool.h:18
uint64_t IncrementFence()
Increments the current fence and signals the CommandQueue.
Definition: command_queue.cc:61
CommandAllocatorPool * allocator_pool_
The CommandAllocatorPool that is controlled by this CommandQueue.
Definition: command_queue.h:106
ID3D12Fence * fence_
The ID3D12Fence object that we use to synchronize the CPU with the GPU.
Definition: command_queue.h:108
The main Blowbox namespace.
Definition: image.cc:8
D3D12_COMMAND_LIST_TYPE type_
The type of CommandQueue this is.
Definition: command_queue.h:104
Manages a ID3D12CommandQueue.
Definition: command_queue.h:23
CommandQueue(D3D12_COMMAND_LIST_TYPE type)
Constructs a CommandQueue of a certain type.
Definition: command_queue.cc:14
ID3D12CommandQueue * queue_
The actual ID3D12CommandQueue.
Definition: command_queue.h:105
uint64_t ExecuteCommandList(ID3D12CommandList *list)
Submits a command list to the CommandQueue.
Definition: command_queue.cc:99