Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
DeviceCommandContext.h
Go to the documentation of this file.
1/* Copyright (C) 2024 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_RENDERER_BACKEND_DUMMY_DEVICECOMMANDCONTEXT
19#define INCLUDED_RENDERER_BACKEND_DUMMY_DEVICECOMMANDCONTEXT
20
24
25#include <memory>
26
27namespace Renderer
28{
29
30namespace Backend
31{
32
33namespace Dummy
34{
35
36class CDevice;
37class CBuffer;
38class CFramebuffer;
39class CShaderProgram;
40class CTexture;
41
43{
44public:
46
47 IDevice* GetDevice() override;
48
49 void SetGraphicsPipelineState(IGraphicsPipelineState* pipelineState) override;
50 void SetComputePipelineState(IComputePipelineState* pipelineState) override;
51
52 void BlitFramebuffer(
53 IFramebuffer* sourceFramebuffer, IFramebuffer* destinationFramebuffer,
54 const Rect& sourceRegion, const Rect& destinationRegion,
55 const Sampler::Filter filter) override;
57 IFramebuffer* sourceFramebuffer, IFramebuffer* destinationFramebuffer) override;
58
59 void ClearFramebuffer(const bool color, const bool depth, const bool stencil) override;
60 void BeginFramebufferPass(IFramebuffer* framebuffer) override;
61 void EndFramebufferPass() override;
63 const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height,
64 void* data) override;
65
66 void UploadTexture(ITexture* texture, const Format dataFormat,
67 const void* data, const size_t dataSize,
68 const uint32_t level = 0, const uint32_t layer = 0) override;
69 void UploadTextureRegion(ITexture* texture, const Format dataFormat,
70 const void* data, const size_t dataSize,
71 const uint32_t xOffset, const uint32_t yOffset,
72 const uint32_t width, const uint32_t height,
73 const uint32_t level = 0, const uint32_t layer = 0) override;
74
75 using UploadBufferFunction = std::function<void(u8*)>;
76 void UploadBuffer(IBuffer* buffer, const void* data, const uint32_t dataSize) override;
77 void UploadBuffer(IBuffer* buffer, const UploadBufferFunction& uploadFunction) override;
79 IBuffer* buffer, const void* data, const uint32_t dataOffset, const uint32_t dataSize) override;
81 IBuffer* buffer, const uint32_t dataOffset, const uint32_t dataSize,
82 const UploadBufferFunction& uploadFunction) override;
83
84 void SetScissors(const uint32_t scissorCount, const Rect* scissors) override;
85 void SetViewports(const uint32_t viewportCount, const Rect* viewports) override;
86
88 IVertexInputLayout* vertexInputLayout) override;
89
90 void SetVertexBuffer(
91 const uint32_t bindingSlot, IBuffer* buffer, const uint32_t offset) override;
93 const uint32_t bindingSlot, const void* data, const uint32_t dataSize) override;
94
95 void SetIndexBuffer(IBuffer* buffer) override;
96 void SetIndexBufferData(const void* data, const uint32_t dataSize) override;
97
98 void BeginPass() override;
99 void EndPass() override;
100
101 void Draw(const uint32_t firstVertex, const uint32_t vertexCount) override;
102 void DrawIndexed(
103 const uint32_t firstIndex, const uint32_t indexCount, const int32_t vertexOffset) override;
104 void DrawInstanced(
105 const uint32_t firstVertex, const uint32_t vertexCount,
106 const uint32_t firstInstance, const uint32_t instanceCount) override;
108 const uint32_t firstIndex, const uint32_t indexCount,
109 const uint32_t firstInstance, const uint32_t instanceCount,
110 const int32_t vertexOffset) override;
112 const uint32_t firstIndex, const uint32_t indexCount,
113 const uint32_t start, const uint32_t end) override;
114
115 void BeginComputePass() override;
116 void EndComputePass() override;
117
118 void Dispatch(
119 const uint32_t groupCountX,
120 const uint32_t groupCountY,
121 const uint32_t groupCountZ) override;
122
123 void SetTexture(const int32_t bindingSlot, ITexture* texture) override;
124
125 void SetStorageTexture(const int32_t bindingSlot, ITexture* texture) override;
126
127 void SetUniform(
128 const int32_t bindingSlot,
129 const float value) override;
130 void SetUniform(
131 const int32_t bindingSlot,
132 const float valueX, const float valueY) override;
133 void SetUniform(
134 const int32_t bindingSlot,
135 const float valueX, const float valueY,
136 const float valueZ) override;
137 void SetUniform(
138 const int32_t bindingSlot,
139 const float valueX, const float valueY,
140 const float valueZ, const float valueW) override;
141 void SetUniform(
142 const int32_t bindingSlot, PS::span<const float> values) override;
143
144 void BeginScopedLabel(const char* name) override;
145 void EndScopedLabel() override;
146
147 void Flush() override;
148
149private:
150 friend class CDevice;
151
152 static std::unique_ptr<CDeviceCommandContext> Create(CDevice* device);
153
155
156 CDevice* m_Device = nullptr;
157};
158
159} // namespace Dummy
160
161} // namespace Backend
162
163} // namespace Renderer
164
165#endif // INCLUDED_RENDERER_BACKEND_DUMMY_DEVICECOMMANDCONTEXT
A wrapper for backend shader program to handle high-level operations like file reloading and handling...
Definition: ShaderProgram.h:34
Represents a texture object.
Definition: TextureManager.h:262
Simplifed version of std::span (C++20) as we don't support the original one yet.
Definition: Span.h:37
Definition: DeviceCommandContext.h:43
void UploadBufferRegion(IBuffer *buffer, const void *data, const uint32_t dataOffset, const uint32_t dataSize) override
Definition: DeviceCommandContext.cpp:85
void SetGraphicsPipelineState(IGraphicsPipelineState *pipelineState) override
Binds the graphics pipeline state.
Definition: DeviceCommandContext.cpp:54
void Flush() override
Definition: DeviceCommandContext.cpp:103
void DrawIndexedInstanced(const uint32_t firstIndex, const uint32_t indexCount, const uint32_t firstInstance, const uint32_t instanceCount, const int32_t vertexOffset) override
Definition: DeviceCommandContext.cpp:183
void EndComputePass() override
Finishes a compute pass.
Definition: DeviceCommandContext.cpp:197
void ResolveFramebuffer(IFramebuffer *sourceFramebuffer, IFramebuffer *destinationFramebuffer) override
Resolves multisample source framebuffer attachments to destination attachments.
Definition: DeviceCommandContext.cpp:112
void SetViewports(const uint32_t viewportCount, const Rect *viewports) override
Definition: DeviceCommandContext.cpp:137
void ReadbackFramebufferSync(const uint32_t x, const uint32_t y, const uint32_t width, const uint32_t height, void *data) override
Readbacks the current backbuffer to data in R8G8B8_UNORM format somewhen between the function call an...
Definition: DeviceCommandContext.cpp:128
void SetUniform(const int32_t bindingSlot, const float value) override
Definition: DeviceCommandContext.cpp:213
void SetStorageTexture(const int32_t bindingSlot, ITexture *texture) override
Sets a read & write resource to the binding slot.
Definition: DeviceCommandContext.cpp:209
void Draw(const uint32_t firstVertex, const uint32_t vertexCount) override
Definition: DeviceCommandContext.cpp:170
void SetScissors(const uint32_t scissorCount, const Rect *scissors) override
Definition: DeviceCommandContext.cpp:133
void UploadTextureRegion(ITexture *texture, const Format dataFormat, const void *data, const size_t dataSize, const uint32_t xOffset, const uint32_t yOffset, const uint32_t width, const uint32_t height, const uint32_t level=0, const uint32_t layer=0) override
Definition: DeviceCommandContext.cpp:70
void SetIndexBufferData(const void *data, const uint32_t dataSize) override
Definition: DeviceCommandContext.cpp:158
void SetVertexBuffer(const uint32_t bindingSlot, IBuffer *buffer, const uint32_t offset) override
Definition: DeviceCommandContext.cpp:145
void SetTexture(const int32_t bindingSlot, ITexture *texture) override
Sets a read-only texture to the binding slot.
Definition: DeviceCommandContext.cpp:205
void SetComputePipelineState(IComputePipelineState *pipelineState) override
Binds the graphics pipeline state.
Definition: DeviceCommandContext.cpp:59
void BlitFramebuffer(IFramebuffer *sourceFramebuffer, IFramebuffer *destinationFramebuffer, const Rect &sourceRegion, const Rect &destinationRegion, const Sampler::Filter filter) override
Copies source region into destination region automatically applying compatible format conversion and ...
Definition: DeviceCommandContext.cpp:107
void BeginScopedLabel(const char *name) override
Definition: DeviceCommandContext.cpp:95
IDevice * GetDevice() override
Definition: DeviceCommandContext.cpp:49
void SetIndexBuffer(IBuffer *buffer) override
Definition: DeviceCommandContext.cpp:154
void BeginComputePass() override
Starts a compute pass, can't be called inside a framebuffer pass.
Definition: DeviceCommandContext.cpp:193
void DrawInstanced(const uint32_t firstVertex, const uint32_t vertexCount, const uint32_t firstInstance, const uint32_t instanceCount) override
Definition: DeviceCommandContext.cpp:178
void Dispatch(const uint32_t groupCountX, const uint32_t groupCountY, const uint32_t groupCountZ) override
Dispatches groupCountX * groupCountY * groupCountZ compute groups.
Definition: DeviceCommandContext.cpp:201
void SetVertexInputLayout(IVertexInputLayout *vertexInputLayout) override
Binds the vertex input layout.
Definition: DeviceCommandContext.cpp:141
std::function< void(u8 *)> UploadBufferFunction
Definition: DeviceCommandContext.h:75
void BeginFramebufferPass(IFramebuffer *framebuffer) override
Starts a framebuffer pass, performs attachment load operations.
Definition: DeviceCommandContext.cpp:120
void UploadTexture(ITexture *texture, const Format dataFormat, const void *data, const size_t dataSize, const uint32_t level=0, const uint32_t layer=0) override
Definition: DeviceCommandContext.cpp:64
void EndFramebufferPass() override
Finishes a framebuffer pass, performs attachment store operations.
Definition: DeviceCommandContext.cpp:124
void ClearFramebuffer(const bool color, const bool depth, const bool stencil) override
Clears all mentioned attachments.
Definition: DeviceCommandContext.cpp:116
void BeginPass() override
Definition: DeviceCommandContext.cpp:162
void DrawIndexed(const uint32_t firstIndex, const uint32_t indexCount, const int32_t vertexOffset) override
Definition: DeviceCommandContext.cpp:174
void SetVertexBufferData(const uint32_t bindingSlot, const void *data, const uint32_t dataSize) override
Definition: DeviceCommandContext.cpp:149
void EndPass() override
Definition: DeviceCommandContext.cpp:166
void EndScopedLabel() override
Definition: DeviceCommandContext.cpp:99
static std::unique_ptr< CDeviceCommandContext > Create(CDevice *device)
Definition: DeviceCommandContext.cpp:38
CDevice * m_Device
Definition: DeviceCommandContext.h:156
void DrawIndexedInRange(const uint32_t firstIndex, const uint32_t indexCount, const uint32_t start, const uint32_t end) override
Definition: DeviceCommandContext.cpp:188
void UploadBuffer(IBuffer *buffer, const void *data, const uint32_t dataSize) override
Definition: DeviceCommandContext.cpp:77
Definition: Device.h:42
Definition: IBuffer.h:32
A holder for precompiled compute pipeline description.
Definition: PipelineState.h:207
Definition: IDeviceCommandContext.h:42
Definition: IDevice.h:48
IFramebuffer stores attachments which should be used by backend as rendering destinations.
Definition: IFramebuffer.h:85
A holder for precompiled graphics pipeline description.
Definition: PipelineState.h:198
Definition: ITexture.h:34
IVertexInputLayout stores precompiled list of vertex attributes.
Definition: IShaderProgram.h:74
Filter
Definition: Sampler.h:36
Format
Definition: Format.h:28
Backend
Definition: Backend.h:28
Definition: VideoMode.h:29
Definition: IDeviceCommandContext.h:58
uint8_t u8
Definition: types.h:37
unsigned int uint32_t
Definition: wposix_types.h:53