Blowbox 2017
A 3D Game Engine by Riko Ophorst using DirectX 12
graphics_context.h
1 #pragma once
2 
3 #include "renderer/commands/command_context.h"
4 #include "renderer/pipeline_state.h"
5 
6 namespace blowbox
7 {
17  {
18  public:
24  static GraphicsContext& Begin(const eastl::wstring& name = L"");
25 
30  void ClearUAV(GpuBuffer& target);
31 
36  void ClearUAV(ColorBuffer& target);
37 
42  void ClearColor(ColorBuffer& target);
43 
48  void ClearDepth(DepthBuffer& target);
49 
54  void ClearStencil(DepthBuffer& target);
55 
60  void ClearDepthAndStencil(DepthBuffer& target);
61 
68  void BeginQuery(ID3D12QueryHeap* query_heap, D3D12_QUERY_TYPE type, UINT heap_index);
69 
76  void EndQuery(ID3D12QueryHeap* query_heap, D3D12_QUERY_TYPE type, UINT heap_index);
77 
87  void ResolveQueryData(ID3D12QueryHeap* query_heap, D3D12_QUERY_TYPE type, UINT start_index, UINT num_queries, ID3D12Resource* dest_buffer, UINT64 dest_buffer_offset);
88 
93  void SetRootSignature(const RootSignature& root_signature);
94 
100  void SetRenderTargets(UINT num_rtvs, const UINT rtvs[]);
101 
108  void SetRenderTargets(UINT num_rtvs, const UINT rtvs[], UINT dsv);
109 
114  void SetRenderTarget(UINT rtv) { SetRenderTargets(1, &rtv); }
115 
121  void SetRenderTarget(UINT rtv, UINT dsv) { SetRenderTargets(1, &rtv, dsv); }
122 
128  void SetDepthStencilTarget(UINT dsv) { SetRenderTargets(0, nullptr, dsv); }
129 
134  void SetViewport(const D3D12_VIEWPORT& vp);
135 
145  void SetViewport(FLOAT x, FLOAT y, FLOAT w, FLOAT h, FLOAT min_depth = 0.0f, FLOAT max_depth = 1.0f);
146 
151  void SetScissor(const D3D12_RECT& rect);
152 
160  void SetScissor(UINT left, UINT top, UINT right, UINT bottom);
161 
167  void SetViewportAndScissor(const D3D12_VIEWPORT& vp, const D3D12_RECT& rect);
168 
176  void SetViewportAndScissor(UINT x, UINT y, UINT w, UINT h);
177 
182  void SetStencilRef(UINT stencil_ref);
183 
188  void SetBlendFactor(float colorRGBA[]);
189 
194  void SetPrimitiveTopology(D3D12_PRIMITIVE_TOPOLOGY topology);
195 
200  void SetPipelineState(const GraphicsPSO& pso);
201 
208  void SetConstants(UINT root_index, UINT num_constants, const void* constants);
209 
215  void SetConstants(UINT root_index, Param32Bit x);
216 
223  void SetConstants(UINT root_index, Param32Bit x, Param32Bit y);
224 
232  void SetConstants(UINT root_index, Param32Bit x, Param32Bit y, Param32Bit z);
233 
242  void SetConstants(UINT root_index, Param32Bit x, Param32Bit y, Param32Bit z, Param32Bit w);
243 
249  void SetConstantBuffer(UINT root_index, D3D12_GPU_VIRTUAL_ADDRESS cbv);
250 
257  void SetBufferSRV(UINT root_index, GpuBuffer& srv, UINT offset = 0);
258 
265  void SetBufferUAV(UINT root_index, GpuBuffer& uav, UINT offset = 0);
266 
272  void SetDescriptorTable(UINT root_index, D3D12_GPU_DESCRIPTOR_HANDLE first_handle);
273 
278  void SetIndexBuffer(const D3D12_INDEX_BUFFER_VIEW& ibv);
279 
285  void SetVertexBuffer(UINT slot, const D3D12_VERTEX_BUFFER_VIEW& vbv);
286 
293  void SetVertexBuffers(UINT start_slot, UINT count, const D3D12_VERTEX_BUFFER_VIEW vbvs[]);
294 
300  void Draw(UINT vertex_count, UINT vertex_start_offset = 0);
301 
308  void DrawIndexed(UINT index_count, UINT start_index_location = 0, INT base_vertex_location = 0);
309 
317  void DrawInstanced(UINT vertex_count_per_instance, UINT instance_count, UINT start_vertex_location = 0, UINT start_instance_location = 0);
318 
327  void DrawIndexedInstanced(UINT index_count_per_instance, UINT instance_count, UINT start_index_location, INT start_vertex_location, UINT start_instance_location);
328 
334  void DrawIndirect(GpuBuffer& argument_buffer, UINT argument_buffer_offset = 0);
335  };
336 }
void BeginQuery(ID3D12QueryHeap *query_heap, D3D12_QUERY_TYPE type, UINT heap_index)
Begins a query.
Definition: graphics_context.cc:61
void ClearColor(ColorBuffer &target)
Clears a RTV resource.
Definition: graphics_context.cc:33
void SetPrimitiveTopology(D3D12_PRIMITIVE_TOPOLOGY topology)
Sets the primitive topology.
Definition: graphics_context.cc:181
void SetScissor(const D3D12_RECT &rect)
Sets the current scissor rect.
Definition: graphics_context.cc:137
Wrapper around D3D12 command lists.
Definition: command_context.h:77
void SetRootSignature(const RootSignature &root_signature)
Sets the pipeline's root signature.
Definition: graphics_context.cc:79
void SetDepthStencilTarget(UINT dsv)
Sets a depth stencil.
Definition: graphics_context.h:128
Wrapper for DepthBuffer-like resources.
Definition: depth_buffer.h:14
void SetBufferSRV(UINT root_index, GpuBuffer &srv, UINT offset=0)
Binds a root SRV buffer to the pipeline.
Definition: graphics_context.cc:241
void SetViewport(const D3D12_VIEWPORT &vp)
Sets the current viewport.
Definition: graphics_context.cc:117
void SetVertexBuffers(UINT start_slot, UINT count, const D3D12_VERTEX_BUFFER_VIEW vbvs[])
Binds a number of vertex buffers to the pipeline.
Definition: graphics_context.cc:271
void SetStencilRef(UINT stencil_ref)
Sets the stencil reference value.
Definition: graphics_context.cc:169
void ResolveQueryData(ID3D12QueryHeap *query_heap, D3D12_QUERY_TYPE type, UINT start_index, UINT num_queries, ID3D12Resource *dest_buffer, UINT64 dest_buffer_offset)
Resolves a query.
Definition: graphics_context.cc:73
Buffer-type for buffers with color data in them.
Definition: color_buffer.h:14
void DrawIndexed(UINT index_count, UINT start_index_location=0, INT base_vertex_location=0)
Issues an non-instanced indexed draw call.
Definition: graphics_context.cc:283
void 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.
Definition: graphics_context.cc:296
void SetVertexBuffer(UINT slot, const D3D12_VERTEX_BUFFER_VIEW &vbv)
Binds a vertex buffer to the pipeline.
Definition: graphics_context.cc:265
void SetRenderTarget(UINT rtv, UINT dsv)
Sets a render target and depth stencil.
Definition: graphics_context.h:121
void 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.
Definition: graphics_context.cc:289
Wraps the PipelineStateObject for graphics pipelines.
Definition: pipeline_state.h:61
void ClearUAV(GpuBuffer &target)
Clears a UAV resource.
Definition: graphics_context.cc:16
static GraphicsContext & Begin(const eastl::wstring &name=L"")
Begins a new GraphicsContext.
Definition: graphics_context.cc:10
void ClearDepthAndStencil(DepthBuffer &target)
Clears a DSV resource.
Definition: graphics_context.cc:54
Wraps the ID3D12RootSignature object.
Definition: root_signature.h:121
void SetViewportAndScissor(const D3D12_VIEWPORT &vp, const D3D12_RECT &rect)
Sets the current viewport and scissor rect.
Definition: graphics_context.cc:155
void SetConstantBuffer(UINT root_index, D3D12_GPU_VIRTUAL_ADDRESS cbv)
Sets a root constant buffer.
Definition: graphics_context.cc:235
Wraps buffer-type GpuResource's.
Definition: gpu_buffer.h:17
void SetPipelineState(const GraphicsPSO &pso)
Sets the pipeline state.
Definition: graphics_context.cc:187
void SetBufferUAV(UINT root_index, GpuBuffer &uav, UINT offset=0)
Binds a root UAV buffer to the pipeline.
Definition: graphics_context.cc:247
void SetRenderTargets(UINT num_rtvs, const UINT rtvs[])
Sets a number of render targets.
Definition: graphics_context.cc:89
void EndQuery(ID3D12QueryHeap *query_heap, D3D12_QUERY_TYPE type, UINT heap_index)
Ends a query.
Definition: graphics_context.cc:67
Wraps functionality for submitting graphics related command lists.
Definition: graphics_context.h:16
The main Blowbox namespace.
Definition: image.cc:8
void SetRenderTarget(UINT rtv)
Sets a render target.
Definition: graphics_context.h:114
void DrawIndirect(GpuBuffer &argument_buffer, UINT argument_buffer_offset=0)
Issues an indirect draw buffer.
Definition: graphics_context.cc:303
void SetBlendFactor(float colorRGBA[])
Sets the blend factor.
Definition: graphics_context.cc:175
Represents a 32 bit parameter, which can either be a float, uint or int.
Definition: command_context.h:20
void SetIndexBuffer(const D3D12_INDEX_BUFFER_VIEW &ibv)
Binds an index buffer to the pipeline.
Definition: graphics_context.cc:259
void ClearStencil(DepthBuffer &target)
Clears a DSV resource.
Definition: graphics_context.cc:47
void SetConstants(UINT root_index, UINT num_constants, const void *constants)
Sets a number of root constants.
Definition: graphics_context.cc:199
void Draw(UINT vertex_count, UINT vertex_start_offset=0)
Issues a non-instanced non-indexed draw call.
Definition: graphics_context.cc:277
void ClearDepth(DepthBuffer &target)
Clears a DSV resource.
Definition: graphics_context.cc:40
void SetDescriptorTable(UINT root_index, D3D12_GPU_DESCRIPTOR_HANDLE first_handle)
Bind a descriptortable to the pipeline.
Definition: graphics_context.cc:253