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

#include <graphics_context.h>

Public Member Functions

void ClearUAV (GpuBuffer &target)
 
void ClearUAV (ColorBuffer &target)
 
void ClearColor (ColorBuffer &target)
 
void ClearDepth (DepthBuffer &target)
 
void ClearStencil (DepthBuffer &target)
 
void ClearDepthAndStencil (DepthBuffer &target)
 
void BeginQuery (ID3D12QueryHeap *query_heap, D3D12_QUERY_TYPE type, UINT heap_index)
 
void EndQuery (ID3D12QueryHeap *query_heap, D3D12_QUERY_TYPE type, UINT heap_index)
 
void ResolveQueryData (ID3D12QueryHeap *query_heap, D3D12_QUERY_TYPE type, UINT start_index, UINT num_queries, ID3D12Resource *dest_buffer, UINT64 dest_buffer_offset)
 
void SetRootSignature (const RootSignature &root_signature)
 
void SetRenderTargets (UINT num_rtvs, const UINT rtvs[])
 
void SetRenderTargets (UINT num_rtvs, const UINT rtvs[], UINT dsv)
 
void SetRenderTarget (UINT rtv)
 
void SetRenderTarget (UINT rtv, UINT dsv)
 
void SetDepthStencilTarget (UINT dsv)
 
void SetViewport (const D3D12_VIEWPORT &vp)
 
void SetViewport (FLOAT x, FLOAT y, FLOAT w, FLOAT h, FLOAT min_depth=0.0f, FLOAT max_depth=1.0f)
 
void SetScissor (const D3D12_RECT &rect)
 
void SetScissor (UINT left, UINT top, UINT right, UINT bottom)
 
void SetViewportAndScissor (const D3D12_VIEWPORT &vp, const D3D12_RECT &rect)
 
void SetViewportAndScissor (UINT x, UINT y, UINT w, UINT h)
 
void SetStencilRef (UINT stencil_ref)
 
void SetBlendFactor (float colorRGBA[])
 
void SetPrimitiveTopology (D3D12_PRIMITIVE_TOPOLOGY topology)
 
void SetPipelineState (const GraphicsPSO &pso)
 
void SetConstants (UINT root_index, UINT num_constants, const void *constants)
 
void SetConstants (UINT root_index, Param32Bit x)
 
void SetConstants (UINT root_index, Param32Bit x, Param32Bit y)
 
void SetConstants (UINT root_index, Param32Bit x, Param32Bit y, Param32Bit z)
 
void SetConstants (UINT root_index, Param32Bit x, Param32Bit y, Param32Bit z, Param32Bit w)
 
void SetConstantBuffer (UINT root_index, D3D12_GPU_VIRTUAL_ADDRESS cbv)
 
void SetBufferSRV (UINT root_index, GpuBuffer &srv, UINT offset=0)
 
void SetBufferUAV (UINT root_index, GpuBuffer &uav, UINT offset=0)
 
void SetDescriptorTable (UINT root_index, D3D12_GPU_DESCRIPTOR_HANDLE first_handle)
 
void SetIndexBuffer (const D3D12_INDEX_BUFFER_VIEW &ibv)
 
void SetVertexBuffer (UINT slot, const D3D12_VERTEX_BUFFER_VIEW &vbv)
 
void SetVertexBuffers (UINT start_slot, UINT count, const D3D12_VERTEX_BUFFER_VIEW vbvs[])
 
void Draw (UINT vertex_count, UINT vertex_start_offset=0)
 
void DrawIndexed (UINT index_count, UINT start_index_location=0, INT base_vertex_location=0)
 
void DrawInstanced (UINT vertex_count_per_instance, UINT instance_count, UINT start_vertex_location=0, UINT start_instance_location=0)
 
void DrawIndexedInstanced (UINT index_count_per_instance, UINT instance_count, UINT start_index_location, INT start_vertex_location, UINT start_instance_location)
 
void DrawIndirect (GpuBuffer &argument_buffer, UINT argument_buffer_offset=0)
 
- Public Member Functions inherited from blowbox::CommandContext
 ~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 GraphicsContextBegin (const eastl::wstring &name=L"")
 
- Static Public Member Functions inherited from blowbox::CommandContext
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)
 

Additional Inherited Members

- Protected Member Functions inherited from blowbox::CommandContext
void BindDescriptorHeaps ()
 
void SetName (const WString &name)
 
- Protected Attributes inherited from blowbox::CommandContext
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_
 

Detailed Description

Wraps functionality for submitting graphics related command lists.

Inherting from the CommandContext, this GraphicsContext allows you to create, record and submit graphics command lists to the GPU. Use GraphicsContext::Begin() to start a new context and submit it by either calling GraphicsContext::Finish() or GraphicsContext::Flush() on it.

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

Member Function Documentation

GraphicsContext & blowbox::GraphicsContext::Begin ( const eastl::wstring &  name = L"")
static

Begins a new GraphicsContext.

Parameters
[in]nameThe name of the newly created GraphicsContext.
Returns
A new GraphicsContext that can immediately be used to record commands.
void blowbox::GraphicsContext::BeginQuery ( ID3D12QueryHeap *  query_heap,
D3D12_QUERY_TYPE  type,
UINT  heap_index 
)

Begins a query.

Parameters
[in]query_heapThe query heap.
[in]typeThe query type.
[in]heap_indexThe heap index.
void blowbox::GraphicsContext::ClearColor ( ColorBuffer target)

Clears a RTV resource.

Parameters
[in]targetThe resource that should be cleared.
void blowbox::GraphicsContext::ClearDepth ( DepthBuffer target)

Clears a DSV resource.

Parameters
[in]targetThe resource that should be cleared.
void blowbox::GraphicsContext::ClearDepthAndStencil ( DepthBuffer target)

Clears a DSV resource.

Parameters
[in]targetThe resource that should be cleared.
void blowbox::GraphicsContext::ClearStencil ( DepthBuffer target)

Clears a DSV resource.

Parameters
[in]targetThe resource that should be cleared.
void blowbox::GraphicsContext::ClearUAV ( GpuBuffer target)

Clears a UAV resource.

Parameters
[in]targetThe resource that should be cleared.
void blowbox::GraphicsContext::ClearUAV ( ColorBuffer target)

Clears a UAV resource.

Parameters
[in]targetThe resource that should be cleared.
void blowbox::GraphicsContext::Draw ( UINT  vertex_count,
UINT  vertex_start_offset = 0 
)

Issues a non-instanced non-indexed draw call.

Parameters
[in]vertex_countNumber of vertices that should be drawn.
[in]vertex_start_offsetThe offset into the vertex buffer from which the vertices should start counting, usually 0.
void blowbox::GraphicsContext::DrawIndexed ( UINT  index_count,
UINT  start_index_location = 0,
INT  base_vertex_location = 0 
)

Issues an non-instanced indexed draw call.

Parameters
[in]index_countNumber of indices that should be drawn.
[in]start_index_locationThe offset into the index buffer from which the indices should start counting, usually 0.
[in]base_vertex_locationThe offset into the vertex buffer from which the vertices should start counting, usually 0.
void blowbox::GraphicsContext::DrawIndexedInstanced ( UINT  index_count_per_instance,
UINT  instance_count,
UINT  start_index_location,
INT  start_vertex_location,
UINT  start_instance_location 
)

Issues an instanced indexed draw call.

Parameters
[in]index_count_per_instanceNumber of vertices per instance.
[in]instance_countNumber of instances that should be drawn.
[in]start_index_locationThe offset into the index buffer from which the indices should start counting, usually 0.
[in]start_vertex_locationThe offset into the vertex buffer from which the vertices should start counting, usually 0.
[in]start_instance_locationThe offset into the vertex buffer from which the per instance vertex buffer should start counting, usually 0.
void blowbox::GraphicsContext::DrawIndirect ( GpuBuffer argument_buffer,
UINT  argument_buffer_offset = 0 
)

Issues an indirect draw buffer.

Parameters
[in]argument_bufferArgument buffer.
[in]argument_buffer_offsetArgument buffer offset.
void blowbox::GraphicsContext::DrawInstanced ( UINT  vertex_count_per_instance,
UINT  instance_count,
UINT  start_vertex_location = 0,
UINT  start_instance_location = 0 
)

Issues an instanced non-indexed draw call.

Parameters
[in]vertex_count_per_instanceNumber of vertices per instance.
[in]instance_countNumber of instances that should be drawn.
[in]start_vertex_locationThe offset into the vertex buffer from which the vertices should start counting, usually 0.
[in]start_instance_locationThe offset into the vertex buffer from which the per instance vertex buffer should start counting, usually 0.
void blowbox::GraphicsContext::EndQuery ( ID3D12QueryHeap *  query_heap,
D3D12_QUERY_TYPE  type,
UINT  heap_index 
)

Ends a query.

Parameters
[in]query_heapThe query heap.
[in]typeThe query type.
[in]heap_indexThe heap index.
void blowbox::GraphicsContext::ResolveQueryData ( ID3D12QueryHeap *  query_heap,
D3D12_QUERY_TYPE  type,
UINT  start_index,
UINT  num_queries,
ID3D12Resource *  dest_buffer,
UINT64  dest_buffer_offset 
)

Resolves a query.

Parameters
[in]query_heapThe query heap.
[in]typeThe query type.
[in]start_indexThe start heap index.
[in]num_queriesThe number of queries.
[in]dest_bufferThe destination buffer.
[in]dest_buffer_offsetThe offset into the destination buffer.
void blowbox::GraphicsContext::SetBlendFactor ( float  colorRGBA[])

Sets the blend factor.

Parameters
[in]colorRGBAThe blend factor.
void blowbox::GraphicsContext::SetBufferSRV ( UINT  root_index,
GpuBuffer srv,
UINT  offset = 0 
)

Binds a root SRV buffer to the pipeline.

Parameters
[in]root_indexThe index in the root signature that the buffer should be put at.
[in]srvThe descriptor ID of the SRV that should be bound to the pipeline.
[in]offsetIf an offset into the SRV buffer should be used, this is the place to do it.
void blowbox::GraphicsContext::SetBufferUAV ( UINT  root_index,
GpuBuffer uav,
UINT  offset = 0 
)

Binds a root UAV buffer to the pipeline.

Parameters
[in]root_indexThe index in the root signature that the buffer should be put at.
[in]uavThe descriptor ID of the UAV that should be bound to the pipeline.
[in]offsetIf an offset into the UAV buffer should be used, this is the place to do it.
void blowbox::GraphicsContext::SetConstantBuffer ( UINT  root_index,
D3D12_GPU_VIRTUAL_ADDRESS  cbv 
)

Sets a root constant buffer.

Parameters
[in]root_indexThe index in the root signature that the buffer should be put at.
[in]cbvThe GPU address where the buffer exists.
void blowbox::GraphicsContext::SetConstants ( UINT  root_index,
UINT  num_constants,
const void *  constants 
)

Sets a number of root constants.

Parameters
[in]root_indexThe index in the root signature that the constants should be put at.
[in]num_constantsThe number of constants to be set.
[in]constantsThe constants that should be set.
void blowbox::GraphicsContext::SetConstants ( UINT  root_index,
Param32Bit  x 
)

Sets a root constant.

Parameters
[in]root_indexThe index in the root signature that the constants should be put at.
[in]xThe first constant data.
void blowbox::GraphicsContext::SetConstants ( UINT  root_index,
Param32Bit  x,
Param32Bit  y 
)

Sets a root constant.

Parameters
[in]root_indexThe index in the root signature that the constants should be put at.
[in]xThe first constant data.
[in]yThe second constant data.
void blowbox::GraphicsContext::SetConstants ( UINT  root_index,
Param32Bit  x,
Param32Bit  y,
Param32Bit  z 
)

Sets a root constant.

Parameters
[in]root_indexThe index in the root signature that the constants should be put at.
[in]xThe first constant data.
[in]yThe second constant data.
[in]zThe third constant data.
void blowbox::GraphicsContext::SetConstants ( UINT  root_index,
Param32Bit  x,
Param32Bit  y,
Param32Bit  z,
Param32Bit  w 
)

Sets a root constant.

Parameters
[in]root_indexThe index in the root signature that the constants should be put at.
[in]xThe first constant data.
[in]yThe second constant data.
[in]zThe third constant data.
[in]wThe fourth constant data.
void blowbox::GraphicsContext::SetDepthStencilTarget ( UINT  dsv)
inline

Sets a depth stencil.

Parameters
[in]dsvThe descriptor id of the DSV that should be bound.
Remarks
This also unbinds the current RTV, if any.
void blowbox::GraphicsContext::SetDescriptorTable ( UINT  root_index,
D3D12_GPU_DESCRIPTOR_HANDLE  first_handle 
)

Bind a descriptortable to the pipeline.

Parameters
[in]root_indexThe index in the root signature that the buffer should be put at.
[in]first_handleThe first handle to a descriptor in a descriptor heap from where the descriptor table should start.
void blowbox::GraphicsContext::SetIndexBuffer ( const D3D12_INDEX_BUFFER_VIEW &  ibv)

Binds an index buffer to the pipeline.

Parameters
[in]ibvThe index buffer view that should be bound.
void blowbox::GraphicsContext::SetPipelineState ( const GraphicsPSO pso)

Sets the pipeline state.

Parameters
[in]psoThe PSO that should be bound to the pipeline.
void blowbox::GraphicsContext::SetPrimitiveTopology ( D3D12_PRIMITIVE_TOPOLOGY  topology)

Sets the primitive topology.

Parameters
[in]topologyThe primitive topology.
void blowbox::GraphicsContext::SetRenderTarget ( UINT  rtv)
inline

Sets a render target.

Parameters
[in]rtvThe descriptor id of the RTV that should be bound.
void blowbox::GraphicsContext::SetRenderTarget ( UINT  rtv,
UINT  dsv 
)
inline

Sets a render target and depth stencil.

Parameters
[in]rtvThe descriptor id of the RTV that should be bound.
[in]dsvThe descriptor id of the DSV that should be bound.
void blowbox::GraphicsContext::SetRenderTargets ( UINT  num_rtvs,
const UINT  rtvs[] 
)

Sets a number of render targets.

Parameters
[in]num_rtvsThe number of render targets that you want to set.
[in]rtvsThe descriptor ids of the render targets that should be bound to the pipeline.
void blowbox::GraphicsContext::SetRenderTargets ( UINT  num_rtvs,
const UINT  rtvs[],
UINT  dsv 
)

Sets a number of render targets, and a depth stencil.

Parameters
[in]num_rtvsThe number of render targets that you want to set.
[in]rtvsThe descriptor ids of the render targets that should be bound to the pipeline.
[in]dsvThe descriptor id of the depth stencil buffer you want to bind.
void blowbox::GraphicsContext::SetRootSignature ( const RootSignature root_signature)

Sets the pipeline's root signature.

Parameters
[in]root_signatureThe root signature that you want to set.
void blowbox::GraphicsContext::SetScissor ( const D3D12_RECT &  rect)

Sets the current scissor rect.

Parameters
[in]rectThe scissor rect you want to set.
void blowbox::GraphicsContext::SetScissor ( UINT  left,
UINT  top,
UINT  right,
UINT  bottom 
)

Sets the current scissor rect.

Parameters
[in]leftThe left most coordinate of the rect.
[in]topThe top most coordinate of the rect.
[in]rightThe right most coordinate of the rect.
[in]bottomThe bottom most coordinate of the rect.
void blowbox::GraphicsContext::SetStencilRef ( UINT  stencil_ref)

Sets the stencil reference value.

Parameters
[in]stencil_refThe stencil reference value.
void blowbox::GraphicsContext::SetVertexBuffer ( UINT  slot,
const D3D12_VERTEX_BUFFER_VIEW &  vbv 
)

Binds a vertex buffer to the pipeline.

Parameters
[in]slotThe slot at which the buffer should be bound, usually 0.
[in]vbvThe vertex buffer view that should be bound.
void blowbox::GraphicsContext::SetVertexBuffers ( UINT  start_slot,
UINT  count,
const D3D12_VERTEX_BUFFER_VIEW  vbvs[] 
)

Binds a number of vertex buffers to the pipeline.

Parameters
[in]start_slotThe slot at which the buffers should be bound, usually 0.
[in]countThe number of vertex buffers to bind.
[in]vbvsThe vertex buffer views that should be bound.
void blowbox::GraphicsContext::SetViewport ( const D3D12_VIEWPORT &  vp)

Sets the current viewport.

Parameters
[in]vpThe viewport that should be set.
void blowbox::GraphicsContext::SetViewport ( FLOAT  x,
FLOAT  y,
FLOAT  w,
FLOAT  h,
FLOAT  min_depth = 0.0f,
FLOAT  max_depth = 1.0f 
)

Sets the current viewport.

Parameters
[in]xThe top left X coordinate.
[in]yThe top left Y coordinate.
[in]wThe width of the viewport.
[in]hThe height of the viewport.
[in]min_depthThe minimum depth value (closest).
[in]max_depthThe maximum depth value (furthest).
void blowbox::GraphicsContext::SetViewportAndScissor ( const D3D12_VIEWPORT &  vp,
const D3D12_RECT &  rect 
)

Sets the current viewport and scissor rect.

Parameters
[in]vpThe viewport to be set.
[in]rectThe scissor rect to be set.
void blowbox::GraphicsContext::SetViewportAndScissor ( UINT  x,
UINT  y,
UINT  w,
UINT  h 
)

Sets the current viewport and scissor rect - identically. (!)

Parameters
[in]xThe top left X coordinate.
[in]yThe top left Y coordinate.
[in]wThe width of the rect to be set.
[in]hThe height of the rect to be set.

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