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
120 struct Data {
124 uint32_t localSizeX;
125
131 public:
132 DispatcherComputePipelineSpecializationData(uint32_t threadCount, uint32_t nextStageThreadCount) : data{threadCount, nextStageThreadCount} {};
133
134 std::vector<VkSpecializationMapEntry> getMapEntries() const override;
135 const void * getData() const override { return &data; }
136 size_t getDataSize() const override { return sizeof(data); }
137
138 [[nodiscard]] uint32_t getThreadCount() const { return data.localSizeX; }
139 [[nodiscard]] uint32_t getNextStageThreadCount() const { return data.nextStageThreadCount; }
140 };
141
150 public:
151 MeshShaderSpecializationData(float screenWidth, float screenHeight)
152 : data{screenWidth, screenHeight} {}
153
154 std::vector<VkSpecializationMapEntry> getMapEntries() const override;
155 const void* getData() const override { return &data; }
156 size_t getDataSize() const override { return sizeof(data); }
157
158 [[nodiscard]] float getScreenWidth() const { return data.screenWidth; }
159 [[nodiscard]] float getScreenHeight() const { return data.screenHeight; }
160 };
161
162 /*
163 * The pipeline class wraps a Vulkan pipeline for convenience. It describes the rendering technique to use, including
164 * shaders, culling, scissoring (renderable area, similar to viewport (but changing the scissor rect won't affect coordinates),
165 * and other aspects.
166 */
168 {
169 public:
170#if !defined(HEADLESS) && !defined(COMPUTE_DEBUG)
172 VkSampleCountFlagBits multisampling,
173 VkPipelineLayout pipelineLayout,
174 VkRenderPass renderPass,
175 const std::string& meshShaderFilename,
176 const std::string& fragmentShaderFilename,
177 const std::vector<VkVertexInputBindingDescription>& vertexInputBindingDescriptions,
178 const std::vector<VkVertexInputAttributeDescription>& vertexInputAttributeDescriptions,
180 std::optional<const MeshShaderSpecializationData*> meshShaderSpecialization = std::nullopt,
181 VkFormat colorFormat = VK_FORMAT_R8G8B8A8_UNORM
182 );
183#else
185 VkDevice device,
186 VkSampleCountFlagBits multisampling,
187 VkPipelineLayout pipelineLayout,
188 VkRenderPass renderPass,
189 const std::string& vertexShaderName,
190 const std::string& fragmentShaderName
191 );
192#endif
194
195 void bind(VkCommandBuffer commandBuffer) const;
196
201 bool isValid() const;
202
203 const std::string getMeshShaderName() const;
204 const std::string getFragShaderName() const;
206
207 bool operator==(const GraphicsPipeline& other) const;
208
209 private:
210 VkDevice device;
211 VkSampleCountFlagBits multisampling;
212
213 std::string meshShaderName;
214 std::string fragShaderName;
215 bool valid = false;
216
218 VkPipeline pipeline = nullptr;
219
221 };
222
227 {
228 public:
230 VkDevice device,
231 VkPipelineLayout layout,
232 std::string shaderFilename,
233 std::optional<const PipelineSpecializationData *> pSpecializationData
234 );
236
241 void bind(VkCommandBuffer commandBuffer);
242
247 VkPipeline get() const { return pipeline; }
248
252 void cleanup();
253 private:
254 VkDevice device = VK_NULL_HANDLE;
255 VkPipeline pipeline = VK_NULL_HANDLE;
256 Core::ComputeShader * computeShader = nullptr;
257 VkPipelineLayout layout = VK_NULL_HANDLE;
258 };
259
260}
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.
Manages IBL (Image-Based Lighting) resources for specular reflections.
uint32_t localSizeX
Workgroup local size for the current dispatch stage.
uint32_t nextStageThreadCount
Thread count consumed by the next dispatch stage.
bool operator==(const PipelineMaterialPayload &other) const