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
4
5#include <glm/vec4.hpp>
6#include <optional>
7#include <string>
8#include <vector>
9#include <vulkan/vulkan.h>
10
11class ComputeShader;
12namespace EngineCore {
13
14
15 class Context;
16
17 // [tdbe] uniform properties to bind to a material's shader.
18 // properties need to be copied to DynamicVertexUniformData
20 glm::vec4 colorMultiplier = glm::vec4(1.0f);
21 };
22
23 // [tdbe] pipeline configurations for this pipeline / "material"
25 VkBlendFactor srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
26 VkBlendFactor dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
27 VkBlendOp colorBlendOp = VK_BLEND_OP_ADD;
28 VkBlendFactor srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE;
29 VkBlendFactor dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
30 VkBlendOp alphaBlendOp = VK_BLEND_OP_ADD;
31 VkCullModeFlagBits cullMode = VkCullModeFlagBits::VK_CULL_MODE_NONE;
32 bool operator==(const PipelineMaterialPayload& other) const
33 {
34 return
36 &&
38 &&
39 (colorBlendOp == other.colorBlendOp)
40 &&
42 &&
44 &&
45 (alphaBlendOp == other.alphaBlendOp)
46 &&
47 (cullMode == other.cullMode);
48 }
49 };
50
56 public:
57 virtual ~PipelineSpecializationData() = default;
58
63 virtual std::vector<VkSpecializationMapEntry> getMapEntries() const = 0;
68 virtual const void* getData() const = 0;
73 virtual size_t getDataSize() const = 0;
74 };
75
81 struct Data {
82 uint32_t localSizeX;
84 public:
86 ComputePipelineSpecializationData(uint32_t threadCount) : data{threadCount} {};
87
93 std::vector<VkSpecializationMapEntry> getMapEntries() const override;
94
99 const void * getData() const override { return &data; }
100
105 size_t getDataSize() const override { return sizeof(data); }
106
111 [[nodiscard]] virtual uint32_t getThreadCount() const { return data.localSizeX; }
112 };
113
115 struct Data {
116 uint32_t localSizeX;
119 public:
120 DispatcherComputePipelineSpecializationData(uint32_t threadCount, uint32_t nextStageThreadCount) : data{threadCount, nextStageThreadCount} {};
121
122 std::vector<VkSpecializationMapEntry> getMapEntries() const override;
123 const void * getData() const override { return &data; }
124 size_t getDataSize() const override { return sizeof(data); }
125
126 [[nodiscard]] uint32_t getThreadCount() const { return data.localSizeX; }
127 [[nodiscard]] uint32_t getNextStageThreadCount() const { return data.nextStageThreadCount; }
128 };
129
138 public:
139 MeshShaderSpecializationData(float screenWidth, float screenHeight)
140 : data{screenWidth, screenHeight} {}
141
142 std::vector<VkSpecializationMapEntry> getMapEntries() const override;
143 const void* getData() const override { return &data; }
144 size_t getDataSize() const override { return sizeof(data); }
145
146 [[nodiscard]] float getScreenWidth() const { return data.screenWidth; }
147 [[nodiscard]] float getScreenHeight() const { return data.screenHeight; }
148 };
149
150 /*
151 * The pipeline class wraps a Vulkan pipeline for convenience. It describes the rendering technique to use, including
152 * shaders, culling, scissoring (renderable area, similar to viewport (but changing the scissor rect won't affect coordinates),
153 * and other aspects.
154 */
156 {
157 public:
158#if !defined(HEADLESS) && !defined(COMPUTE_DEBUG)
159 GraphicsPipeline(VkDevice device,
160 VkSampleCountFlagBits multisampling,
161 VkPipelineLayout pipelineLayout,
162 VkRenderPass renderPass,
163 const std::string& meshShaderFilename,
164 const std::string& fragmentShaderFilename,
165 const std::vector<VkVertexInputBindingDescription>& vertexInputBindingDescriptions,
166 const std::vector<VkVertexInputAttributeDescription>& vertexInputAttributeDescriptions,
168 std::optional<const MeshShaderSpecializationData*> meshShaderSpecialization = std::nullopt,
169 bool depthOnly = false // When true, creates pipeline with no color attachments for Z-prepass
170 );
171#else
173 VkDevice device,
174 VkSampleCountFlagBits multisampling,
175 VkPipelineLayout pipelineLayout,
176 VkRenderPass renderPass,
177 const std::string& vertexShaderName,
178 const std::string& fragmentShaderName
179 );
180#endif
182
183 void bind(VkCommandBuffer commandBuffer) const;
184
189 bool isValid() const;
190
191 const std::string getMeshShaderName() const;
192 const std::string getFragShaderName() const;
194
195 bool operator==(const GraphicsPipeline& other) const;
196
197 private:
198 VkDevice device;
199 VkSampleCountFlagBits multisampling;
200
201 std::string meshShaderName;
202 std::string fragShaderName;
203 bool valid = false;
204
205 const Context* context = nullptr;
206 VkPipeline pipeline = nullptr;
207
209 };
210
218 {
219 public:
221 VkDevice device,
222 VkPipelineLayout layout,
223 std::string shaderFilename,
224 std::optional<const PipelineSpecializationData *> pSpecializationData
225 );
227
235 void bind(VkCommandBuffer commandBuffer);
236
244 VkPipeline get() const { return pipeline; }
245
252 void cleanup();
253 private:
254 VkDevice device = VK_NULL_HANDLE;
255 VkPipeline pipeline = VK_NULL_HANDLE;
257 VkPipelineLayout layout = VK_NULL_HANDLE;
258 };
259
260}
std::vector< VkSpecializationMapEntry > getMapEntries() const override
Gets the specialization data which will be uploaded to a shader.
size_t getDataSize() const override
Gets the size of the data stored in the result of getData()
const void * getData() const override
Gets a pointer for the data for the specialization data.
struct EngineCore::ComputePipelineSpecializationData::Data data
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.
void bind(VkCommandBuffer commandBuffer)
Binds this pipeline to an arbitrary command buffer.
void cleanup()
Cleans up all the resource handles of this object.
ComputePipeline(VkDevice device, VkPipelineLayout layout, std::string shaderFilename, std::optional< const PipelineSpecializationData * > pSpecializationData)
VkPipeline get() const
Getter for the raw vulkan pipeline.
DispatcherComputePipelineSpecializationData(uint32_t threadCount, uint32_t nextStageThreadCount)
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.
struct EngineCore::DispatcherComputePipelineSpecializationData::Data data
size_t getDataSize() const override
Getter for the size at the data pointer.
bool operator==(const GraphicsPipeline &other) const
void bind(VkCommandBuffer commandBuffer) const
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, bool depthOnly=false)
const std::string getFragShaderName() const
const std::string getMeshShaderName() const
bool isValid() const
Checks if the object is fully constructed.
const void * getData() const override
Getter for data pointer.
MeshShaderSpecializationData(float screenWidth, float screenHeight)
struct EngineCore::MeshShaderSpecializationData::Data data
std::vector< VkSpecializationMapEntry > getMapEntries() const override
Creates the list of specialization map entries which are applied to a shader.
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 std::vector< VkSpecializationMapEntry > getMapEntries() const =0
Creates the list of specialization map entries which are applied to a shader.
virtual const void * getData() const =0
Getter for data pointer.
virtual ~PipelineSpecializationData()=default
Log category system implementation.
bool operator==(const PipelineMaterialPayload &other) const