Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
PipelineMaterialPayload.h
Go to the documentation of this file.
1#pragma once
2
3#include <glm/vec4.hpp>
4#include <optional>
5#include <string>
6#include <vector>
7#include <vulkan/vulkan.h>
8
9namespace Engine::Core
10{
11 class ComputeShader;
13} // namespace Engine::Core
14
15namespace Engine::Rendering {
16 // [tdbe] uniform properties to bind to a material's shader.
17 // properties need to be copied to DynamicVertexUniformData
19 glm::vec4 colorMultiplier = glm::vec4(1.0f);
20 };
21
22 // [tdbe] pipeline configurations for this pipeline / "material"
24 VkBlendFactor srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
25 VkBlendFactor dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
26 VkBlendOp colorBlendOp = VK_BLEND_OP_ADD;
27 VkBlendFactor srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
28 VkBlendFactor dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
29 VkBlendOp alphaBlendOp = VK_BLEND_OP_ADD;
30 VkCullModeFlagBits cullMode = VkCullModeFlagBits::VK_CULL_MODE_NONE;
31 bool operator==(const PipelineMaterialPayload& other) const
32 {
33 return
35 &&
37 &&
38 (colorBlendOp == other.colorBlendOp)
39 &&
41 &&
43 &&
44 (alphaBlendOp == other.alphaBlendOp)
45 &&
46 (cullMode == other.cullMode);
47 }
48 };
49
55 public:
56 virtual ~PipelineSpecializationData() = default;
57
62 virtual std::vector<VkSpecializationMapEntry> getMapEntries() const = 0;
67 virtual const void* getData() const = 0;
72 virtual size_t getDataSize() const = 0;
73 };
74
80 struct Data {
81 uint32_t localSizeX;
83 public:
85 ComputePipelineSpecializationData(uint32_t threadCount) : data{threadCount} {};
86
92 std::vector<VkSpecializationMapEntry> getMapEntries() const override;
93
98 const void * getData() const override { return &data; }
99
104 size_t getDataSize() const override { return sizeof(data); }
105
110 [[nodiscard]] virtual uint32_t getThreadCount() const { return data.localSizeX; }
111 };
112
114 struct Data {
115 uint32_t localSizeX;
118 public:
119 DispatcherComputePipelineSpecializationData(uint32_t threadCount, uint32_t nextStageThreadCount) : data{threadCount, nextStageThreadCount} {};
120
121 std::vector<VkSpecializationMapEntry> getMapEntries() const override;
122 const void * getData() const override { return &data; }
123 size_t getDataSize() const override { return sizeof(data); }
124
125 [[nodiscard]] uint32_t getThreadCount() const { return data.localSizeX; }
126 [[nodiscard]] uint32_t getNextStageThreadCount() const { return data.nextStageThreadCount; }
127 };
128
137 public:
138 MeshShaderSpecializationData(float screenWidth, float screenHeight)
139 : data{screenWidth, screenHeight} {}
140
141 std::vector<VkSpecializationMapEntry> getMapEntries() const override;
142 const void* getData() const override { return &data; }
143 size_t getDataSize() const override { return sizeof(data); }
144
145 [[nodiscard]] float getScreenWidth() const { return data.screenWidth; }
146 [[nodiscard]] float getScreenHeight() const { return data.screenHeight; }
147 };
148
149 /*
150 * The pipeline class wraps a Vulkan pipeline for convenience. It describes the rendering technique to use, including
151 * shaders, culling, scissoring (renderable area, similar to viewport (but changing the scissor rect won't affect coordinates),
152 * and other aspects.
153 */
155 {
156 public:
157#if !defined(HEADLESS) && !defined(COMPUTE_DEBUG)
159 VkSampleCountFlagBits multisampling,
160 VkPipelineLayout pipelineLayout,
161 VkRenderPass renderPass,
162 const std::string& meshShaderFilename,
163 const std::string& fragmentShaderFilename,
164 const std::vector<VkVertexInputBindingDescription>& vertexInputBindingDescriptions,
165 const std::vector<VkVertexInputAttributeDescription>& vertexInputAttributeDescriptions,
167 std::optional<const MeshShaderSpecializationData*> meshShaderSpecialization = std::nullopt,
168 VkFormat colorFormat = VK_FORMAT_R8G8B8A8_UNORM
169 );
170#else
172 VkDevice device,
173 VkSampleCountFlagBits multisampling,
174 VkPipelineLayout pipelineLayout,
175 VkRenderPass renderPass,
176 const std::string& vertexShaderName,
177 const std::string& fragmentShaderName
178 );
179#endif
181
182 void bind(VkCommandBuffer commandBuffer) const;
183
188 bool isValid() const;
189
190 const std::string getMeshShaderName() const;
191 const std::string getFragShaderName() const;
193
194 bool operator==(const GraphicsPipeline& other) const;
195
196 private:
197 VkDevice device;
198 VkSampleCountFlagBits multisampling;
199
200 std::string meshShaderName;
201 std::string fragShaderName;
202 bool valid = false;
203
205 VkPipeline pipeline = nullptr;
206
208 };
209
214 {
215 public:
217 VkDevice device,
218 VkPipelineLayout layout,
219 std::string shaderFilename,
220 std::optional<const PipelineSpecializationData *> pSpecializationData
221 );
223
228 void bind(VkCommandBuffer commandBuffer);
229
234 VkPipeline get() const { return pipeline; }
235
239 void cleanup();
240 private:
241 VkDevice device = VK_NULL_HANDLE;
242 VkPipeline pipeline = VK_NULL_HANDLE;
243 Core::ComputeShader * computeShader = nullptr;
244 VkPipelineLayout layout = VK_NULL_HANDLE;
245 };
246
247}
The application context is the core class which stores the basic openxr and vulkan objects.
const void * getData() const override
Gets a pointer for the data for the specialization data.
struct Engine::Rendering::ComputePipelineSpecializationData::Data data
std::vector< VkSpecializationMapEntry > getMapEntries() const override
Gets the specialization data which will be uploaded to a shader.
virtual uint32_t getThreadCount() const
Getter for how man threads the compute shader this specialization is applied to should have.
ComputePipelineSpecializationData(uint32_t threadCount)
Constructor.
size_t getDataSize() const override
Gets the size of the data stored in the result of getData()
VkPipeline get() const
Getter for the raw vulkan pipeline.
void bind(VkCommandBuffer commandBuffer)
Binds this pipeline to an arbitrary command buffer.
ComputePipeline(VkDevice device, VkPipelineLayout layout, std::string shaderFilename, std::optional< const PipelineSpecializationData * > pSpecializationData)
void cleanup()
Cleans up all the resource handles of this object.
struct Engine::Rendering::DispatcherComputePipelineSpecializationData::Data data
const void * getData() const override
Getter for data pointer.
std::vector< VkSpecializationMapEntry > getMapEntries() const override
Creates the list of specialization map entries which are applied to a shader.
DispatcherComputePipelineSpecializationData(uint32_t threadCount, uint32_t nextStageThreadCount)
size_t getDataSize() const override
Getter for the size at the data pointer.
const PipelineMaterialPayload & getPipelineMaterialData() const
GraphicsPipeline(VkDevice device, VkSampleCountFlagBits multisampling, VkPipelineLayout pipelineLayout, VkRenderPass renderPass, const std::string &meshShaderFilename, const std::string &fragmentShaderFilename, const std::vector< VkVertexInputBindingDescription > &vertexInputBindingDescriptions, const std::vector< VkVertexInputAttributeDescription > &vertexInputAttributeDescriptions, PipelineMaterialPayload pipelineData, std::optional< const MeshShaderSpecializationData * > meshShaderSpecialization=std::nullopt, VkFormat colorFormat=VK_FORMAT_R8G8B8A8_UNORM)
const Core::ApplicationContext * context
bool isValid() const
Checks if the object is fully constructed.
const std::string getFragShaderName() const
const std::string getMeshShaderName() const
void bind(VkCommandBuffer commandBuffer) const
bool operator==(const GraphicsPipeline &other) const
struct Engine::Rendering::MeshShaderSpecializationData::Data data
const void * getData() const override
Getter for data pointer.
std::vector< VkSpecializationMapEntry > getMapEntries() const override
Creates the list of specialization map entries which are applied to a shader.
MeshShaderSpecializationData(float screenWidth, float screenHeight)
size_t getDataSize() const override
Getter for the size at the data pointer.
Base class which defines the interface for pipeline specialization data. This can be thread count....
virtual size_t getDataSize() const =0
Getter for the size at the data pointer.
virtual const void * getData() const =0
Getter for data pointer.
virtual std::vector< VkSpecializationMapEntry > getMapEntries() const =0
Creates the list of specialization map entries which are applied to a shader.
Core audio subsystem owning the miniaudio engine and managing playback.
Definition AudioConfig.h:9
bool operator==(const PipelineMaterialPayload &other) const