Cogs.Core
EffectsWebGPU.h
1#pragma once
2
3#include "CommonWebGPU.h"
4
5#include "../Base/EffectsCommon.h"
6
7namespace Cogs {
8 class GraphicsDeviceWebGPU;
9
10 enum WebGPUConstantBufferUsage {
11 ShaderStage_None = 0x00000000,
12 ShaderStage_Vertex = 0x00000001,
13 ShaderStage_Fragment = 0x00000002,
14 ShaderStage_Compute = 0x00000004,
15 ShaderStage_Force32 = 0x7FFFFFFF
16 }; // Copied from webgpu.h
17
18 enum WebGPUConstantBufferType { UniformBuffer, Texture, Sampler };
19
21 size_t group;
22 size_t nameHash;
23 WGPUBindGroupLayoutEntry bg_ent;
24 };
25
27 uint8_t semantic;
28 uint8_t slot;
29 uint8_t binding;
30 WGPUVertexFormat format;
31 size_t nameHash;
32 };
33
34 struct EffectWebGPU : public Effect
35 {
36 static const size_t maxTexUnits = 128;
37 static const size_t maxConstantBuffers = 128;
38 static const size_t maxVertexAttribs = 32;
39 WGPUShaderModule vs_module;
40 WGPUShaderModule fs_module;
41 WGPUShaderModule cs_module;
42 std::string vs_entry;
43 std::string fs_entry;
44 std::string cs_entry;
45 std::string name;
46 size_t num_bindings;
47 size_t num_attribs;
48 WebGPUConstantBufferBinding constantBufferBindings[maxConstantBuffers];
49 SemanticSlotBinding semanticSlotBindings[maxVertexAttribs];
50 };
51
53 {
54 public:
55 void initialize(GraphicsDeviceWebGPU *device, IBuffers * buffers);
56
57 virtual void releaseEffect(EffectHandle effectHandle) override;
58 virtual void releaseResources() override;
59
60 virtual void annotate(EffectHandle /*handle*/, const StringView& /*name*/) override {}
61 virtual void annotateVS(EffectHandle /*handle*/, const StringView& /*name*/) override {}
62 virtual void annotateGS(EffectHandle /*handle*/, const StringView& /*name*/) override {}
63 virtual void annotatePS(EffectHandle /*handle*/, const StringView& /*name*/) override {}
64 virtual void annotateCS(EffectHandle /*handle*/, const StringView& /*name*/) override {}
65
66 virtual EffectHandle loadComputeEffect(const StringView& /*fileName*/, EffectFlags::EEffectFlags /*effectFlags*/) override;
67 virtual EffectHandle loadComputeEffect(const StringView& /*fileName*/, const PreprocessorDefinitions& /*defines*/, EffectFlags::EEffectFlags /*effectFlags*/) override;
68
69 virtual EffectHandle load(const ProcessedContent& /*vsSource*/,
70 const ProcessedContent& /*hsSource*/,
71 const ProcessedContent& /*dsSource*/,
72 const ProcessedContent& /*gsSource*/,
73 const ProcessedContent& /*psSource*/,
74 const StringView& /*vsEntryPoint*/,
75 const StringView& /*hsEntryPoint*/,
76 const StringView& /*dsEntryPoint*/,
77 const StringView& /*gsEntryPoint*/,
78 const StringView& /*psEntryPoint*/,
79 const EffectDescription& /*desc*/) override;
80
81 // TODO fix this
83 BufferBindingHandle getBufferBinding(EffectHandle effectHandle, const StringView& name) override;
84 void releaseBufferBinding(BufferBindingHandle /*bufferBindingHandle*/) override
85 {
86 }
87 TextureBindingHandle getTextureBinding(EffectHandle effectHandle, const StringView& name, const unsigned int slot) override;
88 SamplerStateBindingHandle getSamplerStateBinding(EffectHandle effectHandle, const StringView& /*name*/, const unsigned int slot) override;
89
90 bool addConstantBufferBindings(EffectWebGPU& effect, const std::vector<Cogs::WebGPUConstantBufferBinding>& bindings);
91 const WebGPUConstantBufferBinding* getConstantBufferBindings(EffectHandle effectHandle, size_t& num_bindings);
92
93 GraphicsDeviceWebGPU *graphicsDevice = nullptr;
94
96 };
97}
virtual void annotate(EffectHandle, const StringView &) override
Associate a name with an object for use in graphics debugging.
Definition: EffectsWebGPU.h:60
virtual void annotateVS(EffectHandle, const StringView &) override
Associate a name with an object for use in graphics debugging.
Definition: EffectsWebGPU.h:61
void releaseBufferBinding(BufferBindingHandle) override
Release a handle to a buffer binding.
Definition: EffectsWebGPU.h:84
TextureBindingHandle getTextureBinding(EffectHandle effectHandle, const StringView &name, const unsigned int slot) override
Get a handle to a texture object binding, mapping how to bind textures to the given effect.
virtual void annotateGS(EffectHandle, const StringView &) override
Associate a name with an object for use in graphics debugging.
Definition: EffectsWebGPU.h:62
virtual void releaseEffect(EffectHandle effectHandle) override
Release the effect with the given handle, freeing all resources generated during program loading.
BufferBindingHandle getBufferBinding(EffectHandle effectHandle, const StringView &name) override
Get a handle to a buffer binding.
virtual void annotateCS(EffectHandle, const StringView &) override
Associate a name with an object for use in graphics debugging.
Definition: EffectsWebGPU.h:64
virtual EffectHandle loadComputeEffect(const StringView &, EffectFlags::EEffectFlags) override
Load the compute shader with the given file name and create an effect.
ConstantBufferBindingHandle getConstantBufferBinding(EffectHandle effectHandle, const StringView &name) override
Get a handle to a constant buffer binding, mapping how to bind a constant buffer to the given effect.
virtual void releaseResources() override
Release all allocated effect resources.
SamplerStateBindingHandle getSamplerStateBinding(EffectHandle effectHandle, const StringView &, const unsigned int slot) override
Get a handle to a sampler state object binding, mapping how to bind the sampler state to the given ef...
virtual void annotatePS(EffectHandle, const StringView &) override
Associate a name with an object for use in graphics debugging.
Definition: EffectsWebGPU.h:63
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:24
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
std::vector< PreprocessorDefinition > PreprocessorDefinitions
A set of preprocessor definitions.
Definition: IEffects.h:13
Contains an effect description used to load a single effect.
Definition: IEffects.h:55
EEffectFlags
Effect source flags.
Definition: IEffects.h:20
Provides buffer management functionality.
Definition: IBuffers.h:13