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