3#include "CommonWebGPU.h"
4#include "../IBindGroups.h"
5#include "../IContext.h"
6#include "../Statistics.h"
12 class GraphicsDeviceWebGPU;
14 struct BindGroupsWebGPU;
27 virtual const FrameStatistics& getLastFrameStatistics()
override {
return prevStats; }
28 virtual const UploadStatistics& getLastUploadStatistics()
override {
return prevUploadStats; }
30 virtual void frameStatisticsConfigure(
bool enable)
override { frameStatisticsEnabled = enable; }
36 virtual void clearDepth(
const float = 1.0f)
override;
46 virtual void setViewport(
const float ,
const float ,
const float ,
const float )
override;
47 virtual void setScissor(
const int ,
const int ,
const int ,
const int )
override;
71 virtual void setBindGroup(
BindGroupHandle bindGroupHandle, uint32_t groupIdx)
override;
87 virtual void dispatchCompute(
const unsigned int ,
const unsigned int ,
const unsigned int )
override;
106 virtual void clearResource(
BufferHandle , uint32_t* )
override;
107 virtual void clearResource(
BufferHandle ,
float* )
override;
111 FrameStatistics currStats{};
113 UploadStatistics prevUploadStats{};
114 UploadStatistics currUploadStats{};
117 bool frameStatisticsEnabled =
false;
118 bool uploadStatisticsEnabled =
true;
121 void frameStatisticsAccountDrawCall(
size_t count,
bool indexed);
124 void uploadStatisticsBufferUpload(
size_t size);
125 void uploadStatisticsTextureUpload(
size_t size);
127 bool createOwnedBindGroup(uint32_t group);
129 EffectHandle getCurrentEffect();
130 EffectsWebGPU *getEffects();
131 BindGroupsWebGPU *getBindGroups();
135 void beginRenderPassInt();
136 void endRenderPassInt();
137 void updateRenderPass();
140 void beginComputePass();
141 void endComputePass();
142 void updateComputePass();
143 bool updateComputePipeline();
145 void ClearBindGroups();
147 GraphicsDeviceWebGPU *graphicsDevice =
nullptr;
149 WGPURenderPassEncoder renderPassEncoder = 0;
150 WGPUComputePassEncoder computePassEncoder = 0;
152 EffectHandle effect = {};
153 InputLayoutHandle inputLayoutHandle = {};
154 RasterizerStateHandle rasterizeStateHandle = {};
155 DepthStencilStateHandle depthStencilStateHandle = {};
156 BlendStateHandle blendStateHandle = {};
158 RenderPipelineHandle currentRenderPipeline = {};
159 ComputePipelineHandle currentComputePipeline = {};
160 WGPUIndexFormat currentIndexFormat = WGPUIndexFormat_Uint32;
162 bool inRenderPass =
false;
163 RenderTargetHandle renderTargetHandle = {};
164 DepthStencilHandle depthStencilHandle = {};
165 WGPUColor clearColor[8] = {};
166 float clearDepthVal = 1.0f;
167 bool do_clear_render_target =
false;
168 bool do_clear_depth =
false;
169 bool update_render_target =
true;
171 static constexpr uint32_t MAX_BIND_GROUPS =
static_cast<uint32_t
>(MaxBindGroups);
173 bool bind_group_owned_by_context[MAX_BIND_GROUPS]{
false };
virtual void setSamplerState(const StringView &, unsigned int, SamplerStateHandle) override
Sets the sampler slot given by unit with the given name to contain the given sampler state.
virtual void pushCommandGroupAnnotation(const StringView &name) override
Begin to tag a sequence of commands as a group in graphics debugger.
virtual void getBufferCounter(BufferHandle, BufferHandle) override
Get the associated counter of a buffer.
virtual void setAnnotationMarker(const StringView &name) override
Add a tag in the sequence of commands in graphics debugger.
virtual void setEffect(EffectHandle) override
Set the current effect.
virtual void draw(PrimitiveType, const size_t, const size_t) override
Draws non-indexed, non-instanced primitives.
virtual void readColorBuffer(BufferHandle, int, int, int, int, Framebuffer) override
Reads data from the current render target into the given bufferHandle.
virtual void resolveResource(TextureHandle, TextureHandle) override
Resolves the given source resource target into the given destination texture.
virtual void clearDepth(const float=1.0f) override
Clear the currently set depth/stencil target to the given depth.
virtual void setBlendState(const BlendStateHandle, const float *) override
Set the current blend state.
virtual void updateSubBuffer(BufferHandle, const size_t, const size_t, const void *) override
Update a region of data in a buffer.
virtual void setVertexBuffers(const VertexBufferHandle *, const size_t, const uint32_t *, const uint32_t *) override
Sets the current vertex buffers.
virtual void readDepthBuffer(BufferHandle, int, int, int, int, Framebuffer) override
Reads data from the current depth target into the given bufferHandle.
virtual void drawInstanced(PrimitiveType, const size_t, const size_t, const size_t, const size_t) override
Draws non-indexed, instanced primitives.
virtual void setBuffer(const StringView &, BufferHandle) override
Sets the given buffer to the buffer binding slot with the given name.
virtual void popCommandGroupAnnotation() override
End to tag a sequence of commands as a group in graphics debugger.
virtual uint32_t getBufferCounter(BufferHandle) override
Get the associated counter of a buffer.
virtual void dispatchCompute(const unsigned int, const unsigned int, const unsigned int) override
Dispatch computing work on the graphics device using the desired thread group count.
virtual void setConstantBuffer(const StringView &, const BufferHandle, const uint32_t=0, const uint32_t=~0u) override
Sets a constant buffer to be bound to the given name and slot.
virtual void setBufferCounter(BufferHandle, uint32_t) override
Set the associated counter of a buffer.
virtual void unmap(BufferHandle) override
Unmaps the given buffer, applying any synchronization necessary to reflect changes in the mapped memo...
virtual void drawIndexed(PrimitiveType, const size_t, const size_t, const size_t=0) override
Draws indexed, non-instanced primitives.
virtual void setDepthStencilState(const DepthStencilStateHandle) override
Set the current depth stencil state.
virtual void setScissor(const int, const int, const int, const int) override
Sets the current scissor rectangle.
virtual void setRasterizerState(const RasterizerStateHandle) override
Set the current rasterizer state.
virtual void endRenderPass() override
End a render pass.
virtual void drawInstancedIndexed(PrimitiveType, const size_t, const size_t, const size_t, const size_t) override
Draws indexed, instanced primitives.
virtual void updateSubTexture(TextureHandle, const size_t, const void *) override
Update the data of a level in the given texture.
virtual void beginRenderPass(const RenderPassInfo &info) override
Begin a render pass.
virtual void setVertexArrayObject(VertexArrayObjectHandle) override
Sets vertexBuffers and index buffers using a prevalidated vertex array object.
virtual void signal(FenceHandle) override
Insert a fence in the command stream that will signal when all commands before the fence are complete...
virtual void setIndexBuffer(IndexBufferHandle, uint32_t=4, uint32_t=0) override
Sets the current index buffer.
virtual void clearRenderTarget(const float *) override
Clear the currently set render target to the given value (4 component floating point RGBA).
virtual void setTexture(const StringView &, unsigned int, TextureHandle) override
Sets the texture slot given by unit with the given name to contain the given texture.
virtual void setInputLayout(const InputLayoutHandle) override
Sets the current input layout.
virtual void setRenderTarget(const RenderTargetHandle handle, const DepthStencilHandle depthStencilHandle) override
Sets the current render target and an associated depth stencil target.
virtual void setViewport(const float, const float, const float, const float) override
Sets the current viewport to the given location and dimensions.
virtual void updateBuffer(BufferHandle, const void *, const size_t) override
Replace contents of buffer with new data.
Provides a weakly referenced view over the contents of a string.
Contains all Cogs related functionality.
Framebuffer
Framebuffers to select from when doing framebuffer operations.
PrimitiveType
Primitive types for interpreting vertex data sent to the graphics pipeline.
Handle template class used to provide opaque, non-converting handles.
static const Handle_t NoHandle
Represents a handle to nothing.
Represents a graphics device context which can receive rendering commands.
EMapMode
Mapping mode enumeration.