Hymn to Beauty
C++ 3D Engine
WebGPUShaderProgram.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "../Interface/ShaderProgram.hpp"
4
5#include <initializer_list>
6#include <vector>
7#include "WebGPU.hpp"
8
9namespace Video {
10
11class Shader;
12class WebGPUShader;
13class WebGPURenderer;
14
17 public:
19
23 WebGPUShaderProgram(WGPUDevice device, std::initializer_list<const Shader*> shaders);
24
27
29
32 const std::vector<const WebGPUShader*>& GetShaders() const;
33
35
38 const WGPUBindGroupLayout* GetBindGroupLayouts() const;
39
41
47
49
52 bool HasUniformsBuffer() const;
53
55
58 uint32_t GetPushConstantSize() const;
59
60 private:
61 WebGPUShaderProgram(const WebGPUShaderProgram& other) = delete;
62
63 struct StorageBufferInfo {
64 WGPUShaderStageFlags shaderStages;
65 bool readWrite;
66 };
67
68 void AddMatrices(WGPUDevice device);
69 void AddStorageBuffers(WGPUDevice device, const std::vector<StorageBufferInfo>& storageBufferInfos);
70 void AddMaterial(WGPUDevice device, unsigned int count);
71 void AddPushConstants(WGPUDevice device, unsigned int pushConstantCount, ShaderSource::ReflectionInfo::PushConstant* pushConstants);
72 void AddUniforms(WGPUDevice device, bool hasUniformsBuffer);
73
74 std::vector<const WebGPUShader*> shaders;
75 // And extra bind group for emulated push constants.
76 WGPUBindGroupLayout bindGroupLayouts[ShaderProgram::BindingType::BINDING_TYPES];
77 bool bindGroupLayoutIsEmpty[ShaderProgram::BindingType::BINDING_TYPES];
78
79 bool hasUniformsBuffer = false;
80 uint32_t pushConstantSize = 0;
81};
82
83} // namespace Video
A shader program.
Definition: ShaderProgram.hpp:11
BindingType
A type of bound resource.
Definition: ShaderProgram.hpp:14
WebGPU implementation of ShaderProgram.
Definition: WebGPUShaderProgram.hpp:16
~WebGPUShaderProgram() final
Destructor.
Definition: WebGPUShaderProgram.cpp:62
WebGPUShaderProgram(WGPUDevice device, std::initializer_list< const Shader * > shaders)
Create new WebGPU shader program.
Definition: WebGPUShaderProgram.cpp:8
bool HasUniformsBuffer() const
Get whether the UNIFORMS bind group has a uniform buffer.
Definition: WebGPUShaderProgram.cpp:80
const WGPUBindGroupLayout * GetBindGroupLayouts() const
Get the bind group layouts.
Definition: WebGPUShaderProgram.cpp:72
bool IsBindGroupLayoutEmpty(ShaderProgram::BindingType bindingType) const
Get whether a bind group layout is empty.
Definition: WebGPUShaderProgram.cpp:76
const std::vector< const WebGPUShader * > & GetShaders() const
Get the shaders in the shader program.
Definition: WebGPUShaderProgram.cpp:68
uint32_t GetPushConstantSize() const
Get the size of the push constants.
Definition: WebGPUShaderProgram.cpp:84
Definition: Editor.hpp:18