Cogs.Core
ContextD3D11.h
1#pragma once
2
3#include <d3d11_1.h>
4
5#include "../Base/ContextCommon.h"
6
7#include "EffectsD3D11.h"
8
9namespace Cogs
10{
11 struct BufferD3D11;
12 struct BuffersD3D11;
13 struct EffectsD3D11;
14 struct GraphicsDeviceD3D11;
15 struct RenderTargetsD3D11;
16 struct SyncObjectsD3D11;
17 struct TexturesD3D11;
18
20 {
21 ID3D11Buffer * currentVertexBuffers[kMaxVertexInputSlots] = {};
22 BufferD3D11 * currentIndexBuffer = nullptr;
23 };
24
26 {
29
30 void initialize(GraphicsDeviceD3D11 * graphicsDevice, BuffersD3D11 * buffers, TexturesD3D11 * textures, EffectsD3D11 * effects, RenderTargetsD3D11 * renderTargets, SyncObjectsD3D11* sync);
31
32 void setDefaults();
33
34 void pushCommandGroupAnnotation(const StringView & name) override;
35 void popCommandGroupAnnotation() override;
36 void setAnnotationMarker(const StringView & name) override;
37
38 void setEffect(EffectHandle handle);
39
40 void signal(FenceHandle fenceHandle) override;
41
42 void beginRenderPass(const RenderPassInfo &info) override;
43 void endRenderPass() override;
44
45 void setRenderTarget(const RenderTargetHandle handle, const DepthStencilHandle depthStencilHandle) override;
46 void setViewport(const float x, const float y, const float width, const float height);
47 void setScissor(const int x, const int y, const int width, const int height);
48
49 void clearRenderTarget(const float * value);
50 void clearRenderTarget(const float ** values, const int numValue);
51 void clearDepth(const float depth = 1.0f);
52
55 void setBlendState(const BlendStateHandle handle, const float* constant) override;
56
57 void resolveResource(TextureHandle sourceTexture, TextureHandle destination);
58
59 void setInputLayout(const InputLayoutHandle inputLayoutHandle);
60 void setVertexBuffers(const VertexBufferHandle * vertexBufferHandles, const size_t count, const uint32_t * strides, const uint32_t * offsets);
61 void setVertexBuffers(const VertexBufferHandle * vertexBufferHandles, const size_t count);
62 void setIndexBuffer(IndexBufferHandle indexBufferHandle, uint32_t stride, uint32_t offset);
63 void setConstantBuffer(const ConstantBufferBindingHandle bufferBinding, const BufferHandle bufferHandle, const uint32_t offset, const uint32_t size);
64
65 void setupConstantBuffers();
66 void endFrame();
67
68 void draw(PrimitiveType::EPrimitiveType primitiveType, const size_t startVertex, const size_t numVertexes);
69 void drawIndexed(PrimitiveType::EPrimitiveType primitiveType, const size_t startIndex, const size_t numIndexes, const size_t startVertex = 0);
70
71 void drawInstanced(PrimitiveType::EPrimitiveType primitiveType, const size_t startVertex, const size_t numVertexes, const size_t startInstance, const size_t numInstances);
72 void drawInstancedIndexed(PrimitiveType::EPrimitiveType primitiveType, const size_t startInstance, const size_t numInstances, const size_t startIndex, const size_t numIndexes);
73
74 void dispatchCompute(const unsigned int threadGroupsX, const unsigned int threadGroupsY, const unsigned int threadGroupsZ);
75
76 void readDepthBuffer(BufferHandle bufferHandle, int x, int y, int width, int height, Framebuffer::EFrameBuffer framebuffer);
77 void readColorBuffer(BufferHandle bufferHandle, int x, int y, int width, int height, Framebuffer::EFrameBuffer framebuffer);
78
79 void * map(BufferHandle bufferHandle, MapMode::EMapMode accessMode, uint32_t * stride);
80 void unmap(BufferHandle bufferHandle);
81
82 void * map(TextureHandle textureHandle, MapMode::EMapMode accessMode, uint32_t * rowPitch, uint32_t * depthPitch) override;
83 void unmap(TextureHandle textureHandle) override;
84
85 void updateSubTexture(TextureHandle textureHandle, const size_t level, const void * data);
86 void updateSubBuffer(BufferHandle bufferHandle, const size_t offset, const size_t size, const void * data) override;
87
88 void copyResource(BufferHandle destinationHandle, BufferHandle sourceHandle);
89 void copyResource(TextureHandle destinationHandle, TextureHandle sourceHandle);
90
91 void copyTexture(TextureHandle dstHandle, unsigned dstSub, unsigned dstX, unsigned dstY, unsigned dstZ, TextureHandle sourceHandle, unsigned srcSub) override;
92
93 void clearResource(BufferHandle destinationHandle, uint32_t *Values);
94 void clearResource(BufferHandle destinationHandle, float *Values);
95
96 void setTexture(const TextureBindingHandle textureBindingHandle, const TextureHandle textureHandle);
97 void setTexture(const TextureBindingHandle textureBindingHandle, TextureViewHandle textureViewHandle) override;
98 void setSamplerState(const SamplerStateBindingHandle samplerStateBindingHandle, const SamplerStateHandle samplerStateHandle);
99
100 void setBuffer(const BufferBindingHandle bufferBindingHandle, BufferHandle bufferHandle);
101
102 void setBufferCounter(BufferHandle bufferHandle, uint32_t value);
103 void setBufferCounter(BufferHandle bufferHandle, BufferHandle sourceBufferHandle);
104 void getBufferCounter(BufferHandle bufferHandle, BufferHandle destinationBufferHandle);
105
106 void setShaderResources(uint32_t * slots, ID3D11ShaderResourceView *const *ppShaderResourceViews);
107
108 uint32_t getBufferCounter(BufferHandle bufferHandle);
109
110 void setDevice(ResourcePointer<ID3D11Device>& device, ResourcePointer<ID3D11Device1>& device1);
111
112 void resetSRVBindings();
113
114 void updateRenderTargets();
115
116 EffectHandle currentEffect;
117 bool isCompute;
118
124
126
127 InputAssemblerStateCommon * getIAState() override { return &iaState; }
128 EffectHandle getCurrentEffect() override { return currentEffect; }
129 IEffects * getEffects() override { return effects; }
130
132
133 ID3D11UnorderedAccessView * uavs[D3D11_PS_CS_UAV_REGISTER_COUNT] = {};
134 uint32_t uavCounts[16] = {};
135 uint32_t minUavSlot = ~0u;
136 uint32_t maxUavSlot = 0;
137 bool uavDirty = false;
138
139 GraphicsDeviceD3D11 * graphicsDevice = nullptr;
140 BuffersD3D11 * buffers = nullptr;
141 TexturesD3D11 * textures = nullptr;
142 EffectsD3D11 * effects = nullptr;
143 RenderTargetsD3D11 * renderTargets = nullptr;
144 SyncObjectsD3D11* syncObjects = nullptr;
145
146 DepthStencilStateHandle defaultDepthStencilState;
147 RasterizerStateHandle defaultRasterizerState;
148 BlendStateHandle defaultBlendState;
149 SamplerStateHandle defaultSamplerState;
150
151 bool inRenderPass = false;
152 RenderPassInfo renderPassInfo = {};
153
154 RenderTargetHandle currentRenderTarget;
155 DepthStencilHandle currentDepthStencil;
156
157 InputLayoutHandle currentInputLayout;
158 };
159}
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
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 pushCommandGroupAnnotation(const StringView &name) override
Begin to tag a sequence of commands as a group in graphics debugger.
void resolveResource(TextureHandle sourceTexture, TextureHandle destination)
Resolves the given source resource target into the given destination texture.
void setBufferCounter(BufferHandle bufferHandle, uint32_t value)
Set the associated counter of a buffer.
void draw(PrimitiveType::EPrimitiveType primitiveType, const size_t startVertex, const size_t numVertexes)
Draws non-indexed, non-instanced primitives.
void setRenderTarget(const RenderTargetHandle handle, const DepthStencilHandle depthStencilHandle) override
Sets the current render target and an associated depth stencil target.
void setSamplerState(const SamplerStateBindingHandle samplerStateBindingHandle, const SamplerStateHandle samplerStateHandle)
Sets the sampler state binding given to the given sampler state.
void setBuffer(const BufferBindingHandle bufferBindingHandle, BufferHandle bufferHandle)
Sets a buffer to bind to the given binding.
void setBlendState(const BlendStateHandle handle, const float *constant) override
Set the current blend state.
void readDepthBuffer(BufferHandle bufferHandle, int x, int y, int width, int height, Framebuffer::EFrameBuffer framebuffer)
Reads data from the current depth target into the given bufferHandle.
void setTexture(const TextureBindingHandle textureBindingHandle, const TextureHandle textureHandle)
Sets the texture given to the binding given by textureBindingHandle.
void drawInstancedIndexed(PrimitiveType::EPrimitiveType primitiveType, const size_t startInstance, const size_t numInstances, const size_t startIndex, const size_t numIndexes)
Draws indexed, instanced primitives.
void setRasterizerState(const RasterizerStateHandle handle)
Set the current rasterizer state.
void updateSubTexture(TextureHandle textureHandle, const size_t level, const void *data)
Update the data of a level in the given texture.
void setEffect(EffectHandle handle)
Set the current effect.
void popCommandGroupAnnotation() override
End to tag a sequence of commands as a group in graphics debugger.
void setDepthStencilState(const DepthStencilStateHandle handle)
Set the current depth stencil state.
void endRenderPass() override
End a render pass.
void setInputLayout(const InputLayoutHandle inputLayoutHandle)
Sets the current input layout.
void getBufferCounter(BufferHandle bufferHandle, BufferHandle destinationBufferHandle)
Get the associated counter of a buffer.
void unmap(BufferHandle bufferHandle)
Unmaps the given buffer, applying any synchronization necessary to reflect changes in the mapped memo...
void drawIndexed(PrimitiveType::EPrimitiveType primitiveType, const size_t startIndex, const size_t numIndexes, const size_t startVertex=0)
Draws indexed, non-instanced primitives.
void * map(BufferHandle bufferHandle, MapMode::EMapMode accessMode, uint32_t *stride)
Maps the given buffer so it can be accessed.
void signal(FenceHandle fenceHandle) override
Insert a fence in the command stream that will signal when all commands before the fence are complete...
void setVertexBuffers(const VertexBufferHandle *vertexBufferHandles, const size_t count, const uint32_t *strides, const uint32_t *offsets)
Sets the current vertex buffers.
void setScissor(const int x, const int y, const int width, const int height)
Sets the current scissor rectangle.
void dispatchCompute(const unsigned int threadGroupsX, const unsigned int threadGroupsY, const unsigned int threadGroupsZ)
Dispatch computing work on the graphics device using the desired thread group count.
void clearDepth(const float depth=1.0f)
Clear the currently set depth/stencil target to the given depth.
void beginRenderPass(const RenderPassInfo &info) override
Begin a render pass.
void setViewport(const float x, const float y, const float width, const float height)
Sets the current viewport to the given location and dimensions.
void setIndexBuffer(IndexBufferHandle indexBufferHandle, uint32_t stride, uint32_t offset)
Sets the current index buffer.
void drawInstanced(PrimitiveType::EPrimitiveType primitiveType, const size_t startVertex, const size_t numVertexes, const size_t startInstance, const size_t numInstances)
Draws non-indexed, instanced primitives.
void clearRenderTarget(const float *value)
Clear the currently set render target to the given value (4 component floating point RGBA).
void readColorBuffer(BufferHandle bufferHandle, int x, int y, int width, int height, Framebuffer::EFrameBuffer framebuffer)
Reads data from the current render target into the given bufferHandle.
void setAnnotationMarker(const StringView &name) override
Add a tag in the sequence of commands in graphics debugger.
void setConstantBuffer(const ConstantBufferBindingHandle bufferBinding, const BufferHandle bufferHandle, const uint32_t offset, const uint32_t size)
Sets a constant buffer to the given constant buffer binding.
Provides effects and shader management functionality.
Definition: IEffects.h:148
EMapMode
Mapping mode enumeration.
Definition: Flags.h:93
EPrimitiveType
Primitive type enumeration.
Definition: Common.h:114