Skip to content
Tiago Jose Sousa Magalhães edited this page Dec 22, 2019 · 2 revisions

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

Public Member Data

Name Type Description
initial_value UINT64 Initial value the Fence was created with

Private Member Data

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

Public Methods

Constructor

Prototypes

Fence(UINT64 initialValue,GraphicsDevice& device);

Description

Default constructor for the Fence class.

Parameters

Parameter Name Type Description
initialValue UINT64 Initial value to create the fence with
device GraphicsDevice Graphics Device to create the fence with and in

Usage

...
DXR::Fence fence = {0,device};
...

Advance

Prototypes

void Advance();

Description

Advances the current value of the fence on the CPU side.

Usage

...
fence.Advance();
...

Signal

Prototypes

void Signal(CommandQueue& queue) const;

Description

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.

Parameters

Parameter Name Type Description
queue CommandQueue Command queue to send the signal command into

Usage

...
fence.Advance();
fence.Signal(command_queue);
...

GetCompletedValue

Prototypes

UINT64 GetCompletedValue() const;

Description

Fetches the current GPU side value of the fence.

Return Value

Usage

...
UINT64 gpu_value = fence.GetCompletedValue();
...

WaitForFence

Prototypes

void WaitForFence() const;

Description

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.

Usage

...
// 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();
}
...