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 WebGPUConstantBufferType { UniformBuffer, Texture, Sampler };
11
13 size_t group;
14 size_t nameHash;
15 WGPUBindGroupLayoutEntry bg_ent;
16 std::string name;
17 };
18
20 uint8_t semantic;
21 uint8_t slot;
22 uint8_t binding;
23 WGPUVertexFormat format;
24 size_t nameHash;
25 };
26
27 struct EffectWebGPU : public Effect
28 {
29 static const size_t maxTexUnits = 128;
30 static const size_t maxConstantBuffers = 128;
31 static const size_t maxVertexAttribs = 32;
32 WGPUShaderModule vs_module;
33 WGPUShaderModule fs_module;
34 WGPUShaderModule cs_module;
35 std::string vs_entry;
36 std::string fs_entry;
37 std::string cs_entry;
38 std::string name;
39 size_t num_bindings;
40 size_t num_attribs;
41 WebGPUConstantBufferBinding constantBufferBindings[maxConstantBuffers];
42 SemanticSlotBinding semanticSlotBindings[maxVertexAttribs];
43
44 size_t hash(size_t base)
45 {
46 base = Cogs::hash((size_t)vs_module, base);
47 base = Cogs::hash((size_t)fs_module, base);
48 base = Cogs::hash((size_t)cs_module, base);
49 base = Cogs::hash(vs_entry.c_str(), base);
50 base = Cogs::hash(fs_entry.c_str(), base);
51 base = Cogs::hash(cs_entry.c_str(), base);
52 return base;
53 }
54 };
55
57 {
58 public:
59 void initialize(GraphicsDeviceWebGPU *device, IBuffers * buffers);
60
61 virtual void releaseEffect(EffectHandle effectHandle) override;
62 virtual void releaseResources() override;
63
64 virtual void annotate(EffectHandle /*handle*/, const StringView& /*name*/) override {}
65 virtual void annotateVS(EffectHandle /*handle*/, const StringView& /*name*/) override {}
66 virtual void annotateGS(EffectHandle /*handle*/, const StringView& /*name*/) override {}
67 virtual void annotatePS(EffectHandle /*handle*/, const StringView& /*name*/) override {}
68 virtual void annotateCS(EffectHandle /*handle*/, const StringView& /*name*/) override {}
69
70 virtual EffectHandle loadComputeEffect(const StringView& /*fileName*/, EffectFlags::EEffectFlags /*effectFlags*/) override;
71 virtual EffectHandle loadComputeEffect(const StringView& /*fileName*/, const PreprocessorDefinitions& /*defines*/, EffectFlags::EEffectFlags /*effectFlags*/) override;
72
73 virtual EffectHandle load(const ProcessedContent& /*vsSource*/,
74 const ProcessedContent& /*hsSource*/,
75 const ProcessedContent& /*dsSource*/,
76 const ProcessedContent& /*gsSource*/,
77 const ProcessedContent& /*psSource*/,
78 const StringView& /*vsEntryPoint*/,
79 const StringView& /*hsEntryPoint*/,
80 const StringView& /*dsEntryPoint*/,
81 const StringView& /*gsEntryPoint*/,
82 const StringView& /*psEntryPoint*/,
83 const EffectDescription& /*desc*/) override;
84
85 // TODO fix this
87 BufferBindingHandle getBufferBinding(EffectHandle effectHandle, const StringView& name) override;
88 void releaseBufferBinding(BufferBindingHandle /*bufferBindingHandle*/) override
89 {
90 }
91 TextureBindingHandle getTextureBinding(EffectHandle effectHandle, const StringView& name, const unsigned int slot) override;
92 SamplerStateBindingHandle getSamplerStateBinding(EffectHandle effectHandle, const StringView& /*name*/, const unsigned int slot) override;
93
94 bool addConstantBufferBindings(EffectWebGPU& effect, const std::vector<Cogs::WebGPUConstantBufferBinding>& bindings);
95 const WebGPUConstantBufferBinding* getConstantBufferBindings(EffectHandle effectHandle, size_t& num_bindings);
96
97 GraphicsDeviceWebGPU *graphicsDevice = nullptr;
98
100 };
101}
virtual void annotate(EffectHandle, const StringView &) override
Associate a name with an object for use in graphics debugging.
Definition: EffectsWebGPU.h:64
virtual void annotateVS(EffectHandle, const StringView &) override
Associate a name with an object for use in graphics debugging.
Definition: EffectsWebGPU.h:65
void releaseBufferBinding(BufferBindingHandle) override
Release a handle to a buffer binding.
Definition: EffectsWebGPU.h:88
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:66
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:68
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:67
Provides a weakly referenced view over the contents of a string.
Definition: StringView.h:50
Contains all Cogs related functionality.
Definition: FieldSetter.h:23
constexpr size_t hash() noexcept
Simple getter function that returns the initial value for fnv1a hashing.
Definition: HashFunctions.h:62
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