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

#include <command_context.h>

Public Member Functions

 ~CommandContext ()
 
GraphicsContextGetGraphicsContext ()
 
ComputeContext & GetComputeContext ()
 
void Initialize ()
 
void CopyBuffer (GpuResource &dest_resource, UploadBuffer &source_resource)
 
void CopyBuffer (GpuResource &dest_resource, GpuResource &source_resource)
 
void CopyBufferRegion (GpuResource &dest_resource, UINT dest_offset, GpuResource &source_resource, UINT source_offset, UINT num_bytes)
 
void CopySubresource (GpuResource &dest_resource, UINT dest_subresource_index, GpuResource &source_resource, UINT source_subresource_index)
 
void CopyCounter (GpuResource &dest_resource, UINT dest_offset, StructuredBuffer &source_resource)
 
uint64_t Flush (bool wait_for_completion=false)
 
uint64_t Finish (bool wait_for_completion=false)
 
void TransitionResource (GpuResource &resource, const D3D12_RESOURCE_STATES &new_state, bool flush_immediate=false)
 
void BeginResourceTransition (GpuResource &resource, const D3D12_RESOURCE_STATES &new_state, bool flush_immediate=false)
 
void InsertUAVBarrier (GpuResource &resource, bool flush_immediate=false)
 
void InsertAliasBuffer (GpuResource &before, GpuResource &after, bool flush_immediate=false)
 
void FlushResourceBarriers ()
 
void InsertTimeStamp (ID3D12QueryHeap *query_heap, UINT query_idx)
 
void ResolveTimeStamps (ID3D12Resource *read_back_heap, ID3D12QueryHeap *query_heap, UINT num_queries)
 
void SetDescriptorHeap (D3D12_DESCRIPTOR_HEAP_TYPE type, ID3D12DescriptorHeap *heap)
 
void SetDescriptorHeaps (UINT heap_count, D3D12_DESCRIPTOR_HEAP_TYPE heap_types[], ID3D12DescriptorHeap *heaps[])
 
void SetPredication (ID3D12Resource *buffer, UINT64 buffer_offset, D3D12_PREDICATION_OP op)
 
ID3D12GraphicsCommandList * Get ()
 

Static Public Member Functions

static CommandContextBegin (const WString &name=L"")
 
static void InitializeTexture (GpuResource &dest_resource, UINT num_subresources, D3D12_SUBRESOURCE_DATA subresource_data[])
 
static void InitializeBuffer (GpuResource &dest_resource, const void *data, UINT num_bytes, bool use_offset=false, UINT offset=0)
 

Protected Member Functions

void BindDescriptorHeaps ()
 
void SetName (const WString &name)
 

Protected Attributes

WString name_
 
D3D12_COMMAND_LIST_TYPE type_
 
ID3D12GraphicsCommandList * list_
 
ID3D12CommandAllocator * allocator_
 
UINT num_flushable_barriers_
 
D3D12_RESOURCE_BARRIER resource_barrier_buffer_ [COMMAND_CONTEXT_BARRIER_BUFFER_SIZE]
 
ID3D12DescriptorHeap * descriptor_heaps_ [4]
 
ID3D12RootSignature * graphics_root_signature_
 
ID3D12PipelineState * graphics_pipeline_state_
 
ID3D12RootSignature * compute_root_signature_
 
ID3D12PipelineState * compute_pipeline_state_
 

Private Member Functions

 CommandContext (D3D12_COMMAND_LIST_TYPE type)
 
void Reset ()
 
- Private Member Functions inherited from blowbox::NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 

Friends

class CommandContextManager
 

Detailed Description

Wrapper around D3D12 command lists.

This is a wrapper that makes it very simple and straightforward to interact with command lists. Start a new CommandContext by calling CommandContext::Begin(name) and complete it by calling ComandContext::Finish() or CommandContext::Flush().

Inheritance diagram for blowbox::CommandContext:
blowbox::NonCopyable blowbox::GraphicsContext

Constructor & Destructor Documentation

blowbox::CommandContext::CommandContext ( D3D12_COMMAND_LIST_TYPE  type)
private

Constructs a CommandContext.

Parameters
[in]typeThe type of command list this CommandContext should represent.
blowbox::CommandContext::~CommandContext ( )

Destructs the CommandContext.

Member Function Documentation

CommandContext & blowbox::CommandContext::Begin ( const WString name = L"")
static

Begins a new CommandContext.

Use this function to start a new CommandContext. It will collect all necessary resources for you to start using it.

Parameters
[in]nameThe name of this new CommandContext.
void blowbox::CommandContext::BeginResourceTransition ( GpuResource resource,
const D3D12_RESOURCE_STATES &  new_state,
bool  flush_immediate = false 
)

Begins to transition a GpuResource into another state.

Parameters
[in]resourceThe resource that should be transitioned.
[in]new_stateThe new state that the resource should be in.
[in]flush_immediateWhether the transition should be pushed through immediately to the command list.
void blowbox::CommandContext::BindDescriptorHeaps ( )
protected

Actually binds the descriptor heaps to the pipeline.

void blowbox::CommandContext::CopyBuffer ( GpuResource dest_resource,
UploadBuffer source_resource 
)

Copies a resource into another resource.

Parameters
[in]dest_resourceThe resource into which the source_resource should be copied.
[in]source_resourceThe resource that contains the data to be copied over into the dest_resource.
void blowbox::CommandContext::CopyBuffer ( GpuResource dest_resource,
GpuResource source_resource 
)

Copies a resource into another resource.

Parameters
[in]dest_resourceThe resource into which the source_resource should be copied.
[in]source_resourceThe resource that contains the data to be copied over into the dest_resource.
void blowbox::CommandContext::CopyBufferRegion ( GpuResource dest_resource,
UINT  dest_offset,
GpuResource source_resource,
UINT  source_offset,
UINT  num_bytes 
)

Copies a region of a resource into another resource.

Parameters
[in]dest_resourceThe resource into which the source_resource should be copied.
[in]dest_offsetThe offset in the dest_resource into which will be copied.
[in]source_resourceThe resource that contains the data to be copied over into the dest_resource.
[in]source_offsetThe offset in the source_resource from where will be copied.
[in]num_bytesThe number of bytes from the offset on that should be copied.
void blowbox::CommandContext::CopyCounter ( GpuResource dest_resource,
UINT  dest_offset,
StructuredBuffer source_resource 
)

Copies a Counter buffer from a StructuredBuffer into another resource.

Parameters
[in]dest_resourceThe resource into which the counter buffer should be copied.
[in]dest_offsetThe offset in the dest_resource into which will be copied.
[in]source_resourceThe StructuredBuffer from which the Counter buffer should be copied.
void blowbox::CommandContext::CopySubresource ( GpuResource dest_resource,
UINT  dest_subresource_index,
GpuResource source_resource,
UINT  source_subresource_index 
)

Copies a subresource from one resource into another.

Parameters
[in]dest_resourceThe resource into which the source_resource should be copied.
[in]dest_subresource_indexThe index into which the source subresource should be copied.
[in]source_resourceThe resource that contains the data to be copied over into the dest_resource.
[in]source_subresource_indexThe index from where the source subresource should be copied.
uint64_t blowbox::CommandContext::Finish ( bool  wait_for_completion = false)

This finishes the CommandContext. That means that it will submit everything to the correct CommandQueue, while also releasing its resources.

Parameters
[in]wait_for_completionWhether the function should be blocking until all the work has been completed by the GPU.
uint64_t blowbox::CommandContext::Flush ( bool  wait_for_completion = false)

This flushes the CommandContext. That means that it will submit everything to the correct CommandQueue, without releasing its resources.

Parameters
[in]wait_for_completionWhether the function should be blocking until all the work has been completed by the GPU.
void blowbox::CommandContext::FlushResourceBarriers ( )

Flushes all queued up resource barriers by submitting them to the command list.

ID3D12GraphicsCommandList * blowbox::CommandContext::Get ( )
Returns
The underlying command list.
ComputeContext & blowbox::CommandContext::GetComputeContext ( )

Converts this CommandContext into a ComputeContext.

GraphicsContext & blowbox::CommandContext::GetGraphicsContext ( )

Converts this CommandContext into a GraphicsContext.

void blowbox::CommandContext::Initialize ( )

Initializes the CommandContext, by creating all the resources that it needs.

void blowbox::CommandContext::InitializeBuffer ( GpuResource dest_resource,
const void *  data,
UINT  num_bytes,
bool  use_offset = false,
UINT  offset = 0 
)
static

Initialize a Buffer resource with supplied data.

Parameters
[in]dest_resourceThe resource which has to be initialized with the data.
[in]dataThe data that should be put into the dest_resource.
[in]num_bytesThe number of bytes in data.
[in]use_offsetWhether or not to use a certain offset when copying the data into the dest_resource.
[in]offsetThe offset that should be used when copying the data into the dest_resource.
void blowbox::CommandContext::InitializeTexture ( GpuResource dest_resource,
UINT  num_subresources,
D3D12_SUBRESOURCE_DATA  subresource_data[] 
)
static

Initialize a Texture resource with supplied data.

Parameters
[in]dest_resourceThe resource which has to be initialized with the data.
[in]num_subresourcesThe number of subresources that have to be set in the dest_resource.
[in]subresource_dataThe actual data that you want the dest_resource to be initialized with.
void blowbox::CommandContext::InsertAliasBuffer ( GpuResource before,
GpuResource after,
bool  flush_immediate = false 
)

Inserts an alias barrier.

Parameters
[in]beforefuck if i know
[in]afterfuck if i know
[in]flush_immediateWhether the transition should be pushed through immediately to the command list.
void blowbox::CommandContext::InsertTimeStamp ( ID3D12QueryHeap *  query_heap,
UINT  query_idx 
)

Inserts a timestamp. Fuck if I know what that means.

Parameters
[in]query_heapno clue
[in]query_idxno clue
void blowbox::CommandContext::InsertUAVBarrier ( GpuResource resource,
bool  flush_immediate = false 
)

Inserts a UAV barrier.

Parameters
[in]resourceThe resource that gets transitioned to a UAV state.
[in]flush_immediateWhether the transition should be pushed through immediately to the command list.
void blowbox::CommandContext::Reset ( )
private

Resets the CommandContext.

Remarks
This essentially frees all the resources this CommandContext was using, and requests new ones, so that the CommandContext can be re-used.
void blowbox::CommandContext::ResolveTimeStamps ( ID3D12Resource *  read_back_heap,
ID3D12QueryHeap *  query_heap,
UINT  num_queries 
)

Resolves the timestamps. No clue man.

Parameters
[in]read_back_heapNo clue.
[in]query_heapNo clue.
[in]num_queriesNo clue.
void blowbox::CommandContext::SetDescriptorHeap ( D3D12_DESCRIPTOR_HEAP_TYPE  type,
ID3D12DescriptorHeap *  heap 
)

Set a descriptor heap that is bound to the pipeline.

Parameters
[in]typeThe type that you want bound to the pipeline.
[in]heapThe descriptor heap that should be bound to the pipeline.
void blowbox::CommandContext::SetDescriptorHeaps ( UINT  heap_count,
D3D12_DESCRIPTOR_HEAP_TYPE  heap_types[],
ID3D12DescriptorHeap *  heaps[] 
)

Sets the descriptor heaps that should be bound to the pipeline.

Parameters
[in]heap_countThe number of heaps that need to be bound.
[in]heap_typesThe types of heaps you want bound to the pipeline.
[in]heapsThe actual descriptor heaps that you want to bind to the pipeline.
void blowbox::CommandContext::SetName ( const WString name)
inlineprotected

Sets the name of the CommandContext.

Parameters
[in]nameThe name of the CommandContext.
void blowbox::CommandContext::SetPredication ( ID3D12Resource *  buffer,
UINT64  buffer_offset,
D3D12_PREDICATION_OP  op 
)

Sets a predication.

Parameters
[in]bufferYo i dunno man
[in]buffer_offsetStill dont know
[in]opDefinitely don't know now
void blowbox::CommandContext::TransitionResource ( GpuResource resource,
const D3D12_RESOURCE_STATES &  new_state,
bool  flush_immediate = false 
)

Transitions a GpuResource into another state.

Parameters
[in]resourceThe resource that should be transitioned.
[in]new_stateThe new state that the resource should be in.
[in]flush_immediateWhether the transition should be pushed through immediately to the command list.

Member Data Documentation

ID3D12CommandAllocator* blowbox::CommandContext::allocator_
protected

The allocator used to allocate the commands.

ID3D12PipelineState* blowbox::CommandContext::compute_pipeline_state_
protected

The ComputePSO that is currently bound.

ID3D12RootSignature* blowbox::CommandContext::compute_root_signature_
protected

The compute root signature that is currently bound.

ID3D12DescriptorHeap* blowbox::CommandContext::descriptor_heaps_[4]
protected

All DescriptorHeaps that are currently bound.

ID3D12PipelineState* blowbox::CommandContext::graphics_pipeline_state_
protected

The GraphicsPSO that is currently bound.

ID3D12RootSignature* blowbox::CommandContext::graphics_root_signature_
protected

The graphics root signature that is currently bound.

ID3D12GraphicsCommandList* blowbox::CommandContext::list_
protected

The actual underlying command list.

WString blowbox::CommandContext::name_
protected

The name of the CommandContext.

UINT blowbox::CommandContext::num_flushable_barriers_
protected

The number of resource barriers that are queued up.

D3D12_RESOURCE_BARRIER blowbox::CommandContext::resource_barrier_buffer_[COMMAND_CONTEXT_BARRIER_BUFFER_SIZE]
protected

The actual queued up resource barriers.

D3D12_COMMAND_LIST_TYPE blowbox::CommandContext::type_
protected

The type of CommandContext this is.


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