3#include "../Base/ContextCommon.h"
5#include "BuffersD3D12.h"
6#include "TexturesD3D12.h"
7#include "EffectsD3D12.h"
8#include "RenderTargetsD3D12.h"
10#include <unordered_map>
14#include "FrameResourcesD3D12.h"
15#include "ContextStateD3D12.h"
28 void updateFrameResources();
32 void executeCommandList();
45 void setViewport(
const float x,
const float y,
const float width,
const float height)
override;
46 void setScissor(
const int x,
const int y,
const int width,
const int height)
override;
50 void clearDepth(
const float depth = 1.0f)
override;
65 void setupConstantBuffers();
66 void setupDrawBuffers();
74 void dispatchCompute(
const unsigned int threadGroupsX,
const unsigned int threadGroupsY,
const unsigned int threadGroupsZ)
override;
91 void copyTexture(
TextureHandle dstHandle,
unsigned dstSub,
unsigned dstX,
unsigned dstY,
unsigned dstZ,
TextureHandle sourceHandle,
unsigned srcSub)
override {}
93 void clearResource(BufferHandle destinationHandle, uint32_t *Values)
override {}
94 void clearResource(BufferHandle destinationHandle,
float *Values)
override {}
96 void setTexture(
const TextureBindingHandle textureBindingHandle,
const TextureHandle textureHandle)
override;
97 void setTexture(
const TextureBindingHandle textureBindingHandle, TextureViewHandle textureViewHandle)
override;
99 void setSamplerState(
const SamplerStateBindingHandle samplerStateBindingHandle,
const SamplerStateHandle samplerStateHandle)
override;
101 void setBuffer(
const BufferBindingHandle bufferBindingHandle, BufferHandle bufferHandle)
override;
104 void setBufferCounter(BufferHandle bufferHandle, BufferHandle sourceBufferHandle);
106 void getBufferCounter(BufferHandle bufferHandle, BufferHandle destinationBufferHandle);
108 struct GraphicsDeviceD3D12 * graphicsDevice;
115 InputAssemblerStateCommon * getIAState()
override {
return &iaState; }
116 EffectHandle getCurrentEffect()
override {
return currentEffect; }
118 void checkTextureState(TextureD3D12 & texture);
120 ResourcePointer<ID3D12DescriptorHeap> descriptorHeapCPU;
121 ResourcePointer<ID3D12DescriptorHeap> descriptorHeap;
122 CD3DX12_CPU_DESCRIPTOR_HANDLE cbvCurrentCpuHandle;
123 CD3DX12_GPU_DESCRIPTOR_HANDLE cbvCurrentGpuHandle;
125 CD3DX12_CPU_DESCRIPTOR_HANDLE cbvCurrentCpuHandleCPU;
127 CD3DX12_CPU_DESCRIPTOR_HANDLE srvCurrentCpuHandle;
128 CD3DX12_GPU_DESCRIPTOR_HANDLE srvCurrentGpuHandle;
130 CD3DX12_CPU_DESCRIPTOR_HANDLE uavCurrentCpuHandle;
131 CD3DX12_GPU_DESCRIPTOR_HANDLE uavCurrentGpuHandle;
134 ResourcePointer<ID3D12DescriptorHeap> samplerDescriptorHeap;
135 CD3DX12_CPU_DESCRIPTOR_HANDLE samplerCurrentCpuHandle;
136 CD3DX12_GPU_DESCRIPTOR_HANDLE samplerCurrentGpuHandle;
137 UINT samplerHandleIncrement;
139 ResourcePointer<ID3D12Fence> fence;
142 std::array<FrameResources, 3> frameResources;
143 size_t frameResourceIndex = 0;
144 FrameResources * currentFrameResources =
nullptr;
146 uint64_t currentFenceValue = 0;
148 ID3D12CommandAllocator * commandAllocator;
149 ID3D12GraphicsCommandList * commandList;
151 std::unordered_map<size_t, ResourcePointer<ID3D12PipelineState>> PSOs;
153 bool constantBuffersUpdated;
155 Direct3D12::InputAssemblerState iaState;
156 Direct3D12::PipelineState state;
157 Direct3D12::ShaderState shaderState;
159 EffectHandle currentEffect;
161 ResourcePointer<ID3D12Device> device;
163 BuffersD3D12 * buffers;
164 TexturesD3D12 * textures;
165 EffectsD3D12 * effects;
166 RenderTargetsD3D12 * renderTargets;
168 DepthStencilStateHandle defaultDepthStencilState;
169 RasterizerStateHandle defaultRasterizerState;
170 BlendStateHandle defaultBlendState;
171 SamplerStateHandle defaultSamplerState;
173 RenderTargetHandle defaultRenderTarget;
174 DepthStencilHandle defaultDepthStencil;
Contains all Cogs related functionality.
void setRasterizerState(const RasterizerStateHandle handle) override
Set the current rasterizer state.
void dispatchCompute(const unsigned int threadGroupsX, const unsigned int threadGroupsY, const unsigned int threadGroupsZ) override
Dispatch computing work on the graphics device using the desired thread group count.
void updateSubBuffer(BufferHandle bufferHandle, const size_t offset, const size_t size, const void *data) override
Update a region of data in a buffer.
void clearDepth(const float depth=1.0f) override
Clear the currently set depth/stencil target to the given depth.
void clearRenderTarget(const float *color) override
Clear the currently set render target to the given value (4 component floating point RGBA).
void setBufferCounter(BufferHandle bufferHandle, uint32_t value)
Set the associated counter of a buffer.
void endRenderPass() override
End a render pass.
void draw(PrimitiveType::EPrimitiveType primitiveType, const size_t startVertex, const size_t numVertexes) override
Draws non-indexed, non-instanced primitives.
void resolveResource(TextureHandle source, TextureHandle destination) override
Resolves the given source resource target into the given destination texture.
void setSamplerState(const SamplerStateBindingHandle samplerStateBindingHandle, const SamplerStateHandle samplerStateHandle) override
Sets the sampler state binding given to the given sampler state.
void setDepthStencilState(const DepthStencilStateHandle handle) override
Set the current depth stencil state.
void drawInstanced(PrimitiveType::EPrimitiveType primitiveType, const size_t startVertex, const size_t numVertexes, const size_t startInstance, const size_t numInstances) override
Draws non-indexed, instanced primitives.
void readColorBuffer(BufferHandle bufferHandle, int x, int y, int width, int height, Framebuffer::EFrameBuffer framebuffer) override
Reads data from the current render target into the given bufferHandle.
void setEffect(EffectHandle handle) override
Set the current effect.
void drawInstancedIndexed(PrimitiveType::EPrimitiveType primitiveType, const size_t startInstance, const size_t numInstances, const size_t startIndex, const size_t numIndexes) override
Draws indexed, instanced primitives.
void setBlendState(const BlendStateHandle handle, const float *constant) override
Set the current blend state.
void setConstantBuffer(const ConstantBufferBindingHandle bufferBinding, const BufferHandle bufferHandle, const uint32_t offset, const uint32_t size) override
Sets a constant buffer to the given constant buffer binding.
void setTexture(const TextureBindingHandle textureBindingHandle, const TextureHandle textureHandle) override
Sets the texture given to the binding given by textureBindingHandle.
uint32_t getBufferCounter(BufferHandle bufferHandle)
Get the associated counter of a buffer.
void signal(FenceHandle fenceHandle) override
Insert a fence in the command stream that will signal when all commands before the fence are complete...
void drawIndexed(PrimitiveType::EPrimitiveType primitiveType, const size_t startIndex, const size_t numIndexes, const size_t startVertex) override
Draws indexed, non-instanced primitives.
void * map(TextureHandle textureHandle, MapMode::EMapMode accessMode, uint32_t *rowPitch, uint32_t *depthPitch) override
Create host mapping of a staging texture.
void setVertexBuffers(const VertexBufferHandle *vertexBufferHandles, const size_t count) override
Overload provided to support transitioning.
void setRenderTarget(const RenderTargetHandle handle, const DepthStencilHandle depthStencilHandle) override
Sets the current render target and an associated depth stencil target.
void unmap(BufferHandle bufferHandle) override
Unmaps the given buffer, applying any synchronization necessary to reflect changes in the mapped memo...
void setIndexBuffer(IndexBufferHandle indexBufferHandle, uint32_t stride, uint32_t offset) override
Sets the current index buffer.
void unmap(TextureHandle textureHandle)
Release a host mapping of a staging texture.
void beginRenderPass(const RenderPassInfo &info) override
Begin a render pass.
void setScissor(const int x, const int y, const int width, const int height) override
Sets the current scissor rectangle.
void setViewport(const float x, const float y, const float width, const float height) override
Sets the current viewport to the given location and dimensions.
void readDepthBuffer(BufferHandle bufferHandle, int x, int y, int width, int height, Framebuffer::EFrameBuffer framebuffer) override
Reads data from the current depth target into the given bufferHandle.
void setInputLayout(const InputLayoutHandle inputLayoutHandle) override
Sets the current input layout.
void setBuffer(const BufferBindingHandle bufferBindingHandle, BufferHandle bufferHandle) override
Sets a buffer to bind to the given binding.
void updateSubTexture(TextureHandle textureHandle, const size_t level, const void *data) override
Update the data of a level in the given texture.
Provides effects and shader management functionality.
EMapMode
Mapping mode enumeration.
EPrimitiveType
Primitive type enumeration.