-
Notifications
You must be signed in to change notification settings - Fork 3
Fence
This page contains all information regarding the Fence abstraction API.
The class Fence is an abstraction layer around the Direct3D 12 Fence API, fences are a constructed introduced in version 12 of Direct3D to allow us to synchronize commands issues to the command queue.
Namespace:DXR
Header:Core/Components/Fence.hpp
Name | Type | Description |
---|---|---|
initial_value |
UINT64 |
Initial value the Fence was created with |
Name | Type | Description |
---|---|---|
current_value |
UINT64 |
Current value the Fence holds |
m_fence |
WRL::ComPtr<ID3D12Fence> |
COM interface smart pointer to the Direct3D 12 Fence the class instance represents |
Fence(UINT64 initialValue,GraphicsDevice& device);
Default constructor for the Fence class.
Parameter Name | Type | Description |
---|---|---|
initialValue |
UINT64 |
Initial value to create the fence with |
device |
GraphicsDevice |
Graphics Device to create the fence with and in |
...
DXR::Fence fence = {0,device};
...
void Advance();
Advances the current value of the fence on the CPU side.
...
fence.Advance();
...
void Signal(CommandQueue& queue) const;
Signals the command queue, entering a command into it that will set a new value into the fence. This new value is not set until the previous commands in the queue are executed.
Parameter Name | Type | Description |
---|---|---|
queue |
CommandQueue |
Command queue to send the signal command into |
...
fence.Advance();
fence.Signal(command_queue);
...
UINT64 GetCompletedValue() const;
Fetches the current GPU side value of the fence.
...
UINT64 gpu_value = fence.GetCompletedValue();
...
void WaitForFence() const;
Waits for the current GPU side value of the fence to be equal to or higher than the current CPU side value of the fence.
...
// before continuing into the next iteration of the loop, we wait for the fence
// to reach the specified value.
while(true)
{
fence.Advance();
fence.Signal(command_queue);
fence.WaitForFence();
}
...