LiteFX 0.3.1.2022
Computer Graphics Engine
vulkan_builders.hpp
1#pragma once
2
3#include <litefx/rendering_builders.hpp>
4#include "vulkan_api.hpp"
5#include "vulkan.hpp"
6
7#if defined(BUILD_DEFINE_BUILDERS)
9 using namespace LiteFX::Math;
10 using namespace LiteFX::Rendering;
11
16 class LITEFX_VULKAN_API VulkanShaderProgramBuilder : public ShaderProgramBuilder<VulkanShaderProgramBuilder, VulkanShaderProgram> {
17 LITEFX_IMPLEMENTATION(VulkanShaderProgramBuilderImpl);
18
19 public:
24 explicit VulkanShaderProgramBuilder(const VulkanDevice& device);
25 VulkanShaderProgramBuilder(const VulkanShaderProgramBuilder&) = delete;
26 VulkanShaderProgramBuilder(VulkanShaderProgramBuilder&&) = delete;
27 virtual ~VulkanShaderProgramBuilder() noexcept;
28
29 // Builder interface.
30 protected:
32 virtual void build() override;
33
34 // ShaderProgramBuilder interface.
35 public:
37 virtual VulkanShaderProgramBuilder& withShaderModule(const ShaderStage& type, const String& fileName, const String& entryPoint = "main") override;
38
40 virtual VulkanShaderProgramBuilder& withShaderModule(const ShaderStage& type, std::istream& stream, const String& name, const String& entryPoint = "main") override;
41
43 virtual VulkanShaderProgramBuilder& withVertexShaderModule(const String& fileName, const String& entryPoint = "main") override;
44
46 virtual VulkanShaderProgramBuilder& withVertexShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
47
49 virtual VulkanShaderProgramBuilder& withTessellationControlShaderModule(const String& fileName, const String& entryPoint = "main") override;
50
52 virtual VulkanShaderProgramBuilder& withTessellationControlShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
53
55 virtual VulkanShaderProgramBuilder& withTessellationEvaluationShaderModule(const String& fileName, const String& entryPoint = "main") override;
56
58 virtual VulkanShaderProgramBuilder& withTessellationEvaluationShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
59
61 virtual VulkanShaderProgramBuilder& withGeometryShaderModule(const String& fileName, const String& entryPoint = "main") override;
62
64 virtual VulkanShaderProgramBuilder& withGeometryShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
65
67 virtual VulkanShaderProgramBuilder& withFragmentShaderModule(const String& fileName, const String& entryPoint = "main") override;
68
70 virtual VulkanShaderProgramBuilder& withFragmentShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
71
73 virtual VulkanShaderProgramBuilder& withComputeShaderModule(const String& fileName, const String& entryPoint = "main") override;
74
76 virtual VulkanShaderProgramBuilder& withComputeShaderModule(std::istream& stream, const String& name, const String& entryPoint = "main") override;
77 };
78
83 class LITEFX_VULKAN_API VulkanRasterizerBuilder : public RasterizerBuilder<VulkanRasterizerBuilder, VulkanRasterizer> {
84 LITEFX_IMPLEMENTATION(VulkanRasterizerBuilderImpl);
85
86 public:
90 explicit VulkanRasterizerBuilder() noexcept;
91 VulkanRasterizerBuilder(const VulkanRasterizerBuilder&) noexcept = delete;
92 VulkanRasterizerBuilder(VulkanRasterizerBuilder&&) noexcept = delete;
93 virtual ~VulkanRasterizerBuilder() noexcept;
94
95 // Builder interface.
96 public:
98 virtual void build() override;
99
100 // RasterizerBuilder interface.
101 public:
103 virtual VulkanRasterizerBuilder& polygonMode(const PolygonMode& mode = PolygonMode::Solid) noexcept override;
104
106 virtual VulkanRasterizerBuilder& cullMode(const CullMode& cullMode = CullMode::BackFaces) noexcept override;
107
109 virtual VulkanRasterizerBuilder& cullOrder(const CullOrder& cullOrder = CullOrder::CounterClockWise) noexcept override;
110
112 virtual VulkanRasterizerBuilder& lineWidth(const Float& lineWidth = 1.f) noexcept override;
113
115 virtual VulkanRasterizerBuilder& depthBias(const DepthStencilState::DepthBias& depthBias) noexcept override;
116
118 virtual VulkanRasterizerBuilder& depthState(const DepthStencilState::DepthState& depthState) noexcept override;
119
121 virtual VulkanRasterizerBuilder& stencilState(const DepthStencilState::StencilState& stencilState) noexcept override;
122 };
123
129 class LITEFX_VULKAN_API VulkanVertexBufferLayoutBuilder : public VertexBufferLayoutBuilder<VulkanVertexBufferLayoutBuilder, VulkanVertexBufferLayout, VulkanInputAssemblerBuilder> {
130 public:
131 using VertexBufferLayoutBuilder<VulkanVertexBufferLayoutBuilder, VulkanVertexBufferLayout, VulkanInputAssemblerBuilder>::VertexBufferLayoutBuilder;
132
133 public:
135 virtual VulkanVertexBufferLayoutBuilder& withAttribute(UniquePtr<BufferAttribute>&& attribute) override;
136
137 public:
148 virtual VulkanVertexBufferLayoutBuilder& withAttribute(const BufferFormat& format, const UInt32& offset, const AttributeSemantic& semantic = AttributeSemantic::Unknown, const UInt32& semanticIndex = 0);
149
158 virtual VulkanVertexBufferLayoutBuilder& withAttribute(const UInt32& location, const BufferFormat& format, const UInt32& offset, const AttributeSemantic& semantic = AttributeSemantic::Unknown, const UInt32& semanticIndex = 0);
159 };
160
165 class LITEFX_VULKAN_API VulkanInputAssemblerBuilder : public InputAssemblerBuilder<VulkanInputAssemblerBuilder, VulkanInputAssembler> {
166 LITEFX_IMPLEMENTATION(VulkanInputAssemblerBuilderImpl);
167
168 public:
172 explicit VulkanInputAssemblerBuilder() noexcept;
173 VulkanInputAssemblerBuilder(const VulkanInputAssemblerBuilder&) noexcept = delete;
174 VulkanInputAssemblerBuilder(VulkanInputAssemblerBuilder&&) noexcept = delete;
175 virtual ~VulkanInputAssemblerBuilder() noexcept;
176
177 // Builder interface.
178 public:
180 virtual void build() override;
181
182 // InputAssemblerBuilder interface.
183 public:
185 virtual VulkanInputAssemblerBuilder& topology(const PrimitiveTopology& topology) override;
186
188 virtual void use(UniquePtr<VulkanVertexBufferLayout>&& layout) override;
189
191 virtual void use(UniquePtr<VulkanIndexBufferLayout>&& layout) override;
192
193 // VulkanInputAssemblerBuilder interface.
194 public:
200 virtual VulkanVertexBufferLayoutBuilder vertexBuffer(const size_t& elementSize, const UInt32& binding = 0);
201
206 virtual VulkanInputAssemblerBuilder& indexType(const IndexType& type);
207 };
208
215 class LITEFX_VULKAN_API VulkanDescriptorSetLayoutBuilder : public DescriptorSetLayoutBuilder<VulkanDescriptorSetLayoutBuilder, VulkanDescriptorSetLayout, VulkanPipelineLayoutBuilder> {
216 LITEFX_IMPLEMENTATION(VulkanDescriptorSetLayoutBuilderImpl);
217
218 public:
228 explicit VulkanDescriptorSetLayoutBuilder(VulkanPipelineLayoutBuilder& parent, const UInt32& space = 0, const ShaderStage& stages = ShaderStage::Compute | ShaderStage::Fragment | ShaderStage::Geometry | ShaderStage::TessellationControl | ShaderStage::TessellationEvaluation | ShaderStage::Vertex, const UInt32& poolSize = 1024, const UInt32& maxUnboundedArraySize = 104857);
229 VulkanDescriptorSetLayoutBuilder(const VulkanDescriptorSetLayoutBuilder&) = delete;
230 VulkanDescriptorSetLayoutBuilder(VulkanDescriptorSetLayoutBuilder&&) = delete;
231 virtual ~VulkanDescriptorSetLayoutBuilder() noexcept;
232
233 // Builder interface.
234 public:
236 virtual void build() override;
237
238 // DescriptorSetLayoutBuilder interface.
239 public:
241 virtual VulkanDescriptorSetLayoutBuilder& withDescriptor(UniquePtr<VulkanDescriptorLayout>&& layout) override;
242
244 virtual VulkanDescriptorSetLayoutBuilder& withDescriptor(const DescriptorType& type, const UInt32& binding, const UInt32& descriptorSize, const UInt32& descriptors = 1) override;
245
247 virtual VulkanDescriptorSetLayoutBuilder& withStaticSampler(const UInt32& binding, const FilterMode& magFilter = FilterMode::Nearest, const FilterMode& minFilter = FilterMode::Nearest, const BorderMode& borderU = BorderMode::Repeat, const BorderMode& borderV = BorderMode::Repeat, const BorderMode& borderW = BorderMode::Repeat, const MipMapMode& mipMapMode = MipMapMode::Nearest, const Float& mipMapBias = 0.f, const Float& minLod = 0.f, const Float& maxLod = std::numeric_limits<Float>::max(), const Float& anisotropy = 0.f) override;
248
249 // VulkanDescriptorSetLayoutBuilder.
250 public:
255 virtual VulkanDescriptorSetLayoutBuilder& space(const UInt32& space) noexcept;
256
261 virtual VulkanDescriptorSetLayoutBuilder& shaderStages(const ShaderStage& stages) noexcept;
262
267 virtual VulkanDescriptorSetLayoutBuilder& poolSize(const UInt32& poolSize) noexcept;
268 };
269
274 class LITEFX_VULKAN_API VulkanPushConstantsLayoutBuilder : public PushConstantsLayoutBuilder<VulkanPushConstantsLayoutBuilder, VulkanPushConstantsLayout, VulkanPipelineLayoutBuilder> {
275 LITEFX_IMPLEMENTATION(VulkanPushConstantsLayoutBuilderImpl);
276
277 public:
283 explicit VulkanPushConstantsLayoutBuilder(VulkanPipelineLayoutBuilder& parent, const UInt32& size);
284 VulkanPushConstantsLayoutBuilder(const VulkanPushConstantsLayoutBuilder&) = delete;
285 VulkanPushConstantsLayoutBuilder(VulkanPushConstantsLayoutBuilder&&) = delete;
286 virtual ~VulkanPushConstantsLayoutBuilder() noexcept;
287
288 // IBuilder interface.
289 public:
291 virtual void build() override;
292
293 // PushConstantsLayoutBuilder interface.
294 public:
296 virtual VulkanPushConstantsLayoutBuilder& withRange(const ShaderStage& shaderStages, const UInt32& offset, const UInt32& size, const UInt32& space, const UInt32& binding) override;
297 };
298
305 class LITEFX_VULKAN_API VulkanPipelineLayoutBuilder : public PipelineLayoutBuilder<VulkanPipelineLayoutBuilder, VulkanPipelineLayout> {
306 LITEFX_IMPLEMENTATION(VulkanPipelineLayoutBuilderImpl);
307 friend class VulkanDescriptorSetLayoutBuilder;
308
309 public:
314 explicit VulkanPipelineLayoutBuilder(const VulkanDevice& device);
315 VulkanPipelineLayoutBuilder(VulkanPipelineLayoutBuilder&&) = delete;
316 VulkanPipelineLayoutBuilder(const VulkanPipelineLayoutBuilder&) = delete;
317 virtual ~VulkanPipelineLayoutBuilder() noexcept;
318
319 // Builder interface.
320 public:
322 virtual void build() override;
323
324 // PipelineLayoutBuilder interface.
325 public:
327 virtual void use(UniquePtr<VulkanDescriptorSetLayout>&& layout) override;
328
330 virtual void use(UniquePtr<VulkanPushConstantsLayout>&& layout) override;
331
332 // VulkanPipelineLayoutBuilder.
333 public:
340 virtual VulkanDescriptorSetLayoutBuilder descriptorSet(const UInt32& space = 0, const ShaderStage& stages = ShaderStage::Fragment | ShaderStage::Geometry | ShaderStage::TessellationControl | ShaderStage::TessellationEvaluation | ShaderStage::Vertex, const UInt32& poolSize = 1024);
341
346 virtual VulkanPushConstantsLayoutBuilder pushConstants(const UInt32& size);
347
348 private:
353 virtual const VulkanDevice& device() const noexcept;
354 };
355
360 class LITEFX_VULKAN_API VulkanRenderPipelineBuilder : public RenderPipelineBuilder<VulkanRenderPipelineBuilder, VulkanRenderPipeline> {
361 LITEFX_IMPLEMENTATION(VulkanRenderPipelineBuilderImpl);
362
363 public:
369 explicit VulkanRenderPipelineBuilder(const VulkanRenderPass& renderPass, const String& name = "");
370 VulkanRenderPipelineBuilder(VulkanRenderPipelineBuilder&&) = delete;
371 VulkanRenderPipelineBuilder(const VulkanRenderPipelineBuilder&) = delete;
372 virtual ~VulkanRenderPipelineBuilder() noexcept;
373
374 // Builder interface.
375 public:
377 virtual void build() override;
378
379 // RenderPipelineBuilder interface.
380 public:
382 virtual VulkanRenderPipelineBuilder& shaderProgram(SharedPtr<VulkanShaderProgram> shaderProgram) override;
383
385 virtual VulkanRenderPipelineBuilder& layout(SharedPtr<VulkanPipelineLayout> layout) override;
386
388 virtual VulkanRenderPipelineBuilder& rasterizer(SharedPtr<VulkanRasterizer> rasterizer) override;
389
391 virtual VulkanRenderPipelineBuilder& inputAssembler(SharedPtr<VulkanInputAssembler> inputAssembler) override;
392
394 virtual VulkanRenderPipelineBuilder& viewport(SharedPtr<IViewport> viewport) override;
395
397 virtual VulkanRenderPipelineBuilder& scissor(SharedPtr<IScissor> scissor) override;
398
400 virtual VulkanRenderPipelineBuilder& enableAlphaToCoverage(const bool& enable = true) override;
401 };
402
407 class LITEFX_VULKAN_API VulkanComputePipelineBuilder : public ComputePipelineBuilder<VulkanComputePipelineBuilder, VulkanComputePipeline> {
408 LITEFX_IMPLEMENTATION(VulkanComputePipelineBuilderImpl);
409
410 public:
416 explicit VulkanComputePipelineBuilder(const VulkanDevice& device, const String& name = "");
417 VulkanComputePipelineBuilder(VulkanComputePipelineBuilder&&) = delete;
418 VulkanComputePipelineBuilder(const VulkanComputePipelineBuilder&) = delete;
419 virtual ~VulkanComputePipelineBuilder() noexcept;
420
421 // Builder interface.
422 public:
424 virtual void build() override;
425
426 // ComputePipelineBuilder interface.
427 public:
429 virtual VulkanComputePipelineBuilder& shaderProgram(SharedPtr<VulkanShaderProgram> program) override;
430
432 virtual VulkanComputePipelineBuilder& layout(SharedPtr<VulkanPipelineLayout> layout) override;
433 };
434
439 class LITEFX_VULKAN_API VulkanRenderPassBuilder : public RenderPassBuilder<VulkanRenderPassBuilder, VulkanRenderPass> {
440 LITEFX_IMPLEMENTATION(VulkanRenderPassBuilderImpl)
441
442 public:
448 explicit VulkanRenderPassBuilder(const VulkanDevice& device, const String& name = "") noexcept;
449
456 explicit VulkanRenderPassBuilder(const VulkanDevice& device, const MultiSamplingLevel& samples = MultiSamplingLevel::x1, const String& name = "") noexcept;
457
464 explicit VulkanRenderPassBuilder(const VulkanDevice& device, const UInt32& commandBuffers, const String& name = "") noexcept;
465
473 explicit VulkanRenderPassBuilder(const VulkanDevice& device, const UInt32& commandBuffers, const MultiSamplingLevel& multiSamplingLevel, const String& name = "") noexcept;
474 VulkanRenderPassBuilder(const VulkanRenderPassBuilder&) noexcept = delete;
475 VulkanRenderPassBuilder(VulkanRenderPassBuilder&&) noexcept = delete;
476 virtual ~VulkanRenderPassBuilder() noexcept;
477
478 // Builder interface.
479 public:
481 virtual void build() override;
482
483 // RenderPassBuilder interface.
484 public:
486 virtual VulkanRenderPassBuilder& commandBuffers(const UInt32& count) override;
487
489 virtual VulkanRenderPassBuilder& multiSamplingLevel(const MultiSamplingLevel& samples) override;
490
492 virtual VulkanRenderPassBuilder& renderTarget(const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
493
495 virtual VulkanRenderPassBuilder& renderTarget(const String& name, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
496
498 virtual VulkanRenderPassBuilder& renderTarget(const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
499
501 virtual VulkanRenderPassBuilder& renderTarget(const String& name, const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
502
504 virtual VulkanRenderPassBuilder& renderTarget(VulkanInputAttachmentMapping& output, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
505
507 virtual VulkanRenderPassBuilder& renderTarget(const String& name, VulkanInputAttachmentMapping& output, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
508
510 virtual VulkanRenderPassBuilder& renderTarget(VulkanInputAttachmentMapping& output, const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
511
513 virtual VulkanRenderPassBuilder& renderTarget(const String& name, VulkanInputAttachmentMapping& output, const UInt32& location, const RenderTargetType& type, const Format& format, const Vector4f& clearValues = { 0.0f, 0.0f, 0.0f, 0.0f }, bool clearColor = true, bool clearStencil = true, bool isVolatile = false) override;
514
516 virtual VulkanRenderPassBuilder& inputAttachment(const VulkanInputAttachmentMapping& inputAttachment) override;
517
519 virtual VulkanRenderPassBuilder& inputAttachment(const UInt32& inputLocation, const VulkanRenderPass& renderPass, const UInt32& outputLocation) override;
520
522 virtual VulkanRenderPassBuilder& inputAttachment(const UInt32& inputLocation, const VulkanRenderPass& renderPass, const RenderTarget& renderTarget) override;
523 };
524}
525#endif // defined(BUILD_DEFINE_BUILDERS)
Definition: math.hpp:349
Stores the depth/stencil state of a see IRasterizer.
Definition: rendering_api.hpp:2066
The interface of a scissor.
Definition: rendering_api.hpp:2415
Interface for a viewport.
Definition: rendering_api.hpp:2331
Implements a render target.
Definition: rendering_api.hpp:1994
Definition: math.hpp:30
uint32_t UInt32
Definition: math.hpp:37
float_t Float
Definition: math.hpp:40
Definition: dx12.hpp:8
Definition: dx12.hpp:8
std::string String
Definition: string.hpp:19
std::shared_ptr< T > SharedPtr
Represents a shared pointer, that expresses non-exclusive ownership.
Definition: containers.hpp:94
std::unique_ptr< T, TDeleter > UniquePtr
Represents a unique pointer, that expresses exclusive ownership.
Definition: containers.hpp:87
Definition: graphics.hpp:11