LiteFX 0.4.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
vulkan.hpp
1#pragma once
2
3#include <litefx/rendering.hpp>
4
5#include "vulkan_api.hpp"
6#include "vulkan_formatters.hpp"
7
8#pragma warning(push)
9#pragma warning(disable:4250) // Base class members are inherited via dominance.
10
12 using namespace LiteFX::Math;
13 using namespace LiteFX::Rendering;
14
21 class LITEFX_VULKAN_API VulkanVertexBufferLayout final : public IVertexBufferLayout {
22 LITEFX_IMPLEMENTATION(VulkanVertexBufferLayoutImpl);
23 LITEFX_BUILDER(VulkanVertexBufferLayoutBuilder);
25
26 private:
32 explicit VulkanVertexBufferLayout(size_t vertexSize, UInt32 binding = 0);
33
40 explicit VulkanVertexBufferLayout(size_t vertexSize, const Enumerable<BufferAttribute>& attributes, UInt32 binding = 0);
41
42 private:
45
48
50 VulkanVertexBufferLayout& operator=(VulkanVertexBufferLayout&&) noexcept = delete;
51
53 VulkanVertexBufferLayout& operator=(const VulkanVertexBufferLayout&) = delete;
54
55 public:
57 ~VulkanVertexBufferLayout() noexcept override;
58
59 public:
66 static inline auto create(size_t vertexSize, UInt32 binding = 0) {
67 return SharedObject::create<VulkanVertexBufferLayout>(vertexSize, binding);
68 }
69
77 static inline auto create(size_t vertexSize, const Enumerable<BufferAttribute>& attributes, UInt32 binding = 0) {
78 return SharedObject::create<VulkanVertexBufferLayout>(vertexSize, attributes, binding);
79 }
80
86 static inline auto create(const VulkanVertexBufferLayout& other) {
88 }
89
90 // IVertexBufferLayout interface.
91 public:
93 const Array<BufferAttribute>& attributes() const override;
94
95 // IBufferLayout interface.
96 public:
98 size_t elementSize() const noexcept override;
99
101 UInt32 binding() const noexcept override;
102
104 BufferType type() const noexcept override;
105 };
106
112 class LITEFX_VULKAN_API VulkanIndexBufferLayout final : public IIndexBufferLayout {
113 LITEFX_IMPLEMENTATION(VulkanIndexBufferLayoutImpl);
115
116 private:
121 explicit VulkanIndexBufferLayout(IndexType type);
122
123 private:
126
129
131 VulkanIndexBufferLayout& operator=(VulkanIndexBufferLayout&&) noexcept = delete;
132
134 VulkanIndexBufferLayout& operator=(const VulkanIndexBufferLayout&) = delete;
135
136 public:
138 ~VulkanIndexBufferLayout() noexcept override;
139
140 public:
146 static inline auto create(IndexType type) {
148 }
149
155 static inline auto create(const VulkanIndexBufferLayout& other) {
157 }
158
159 // IIndexBufferLayout interface.
160 public:
162 IndexType indexType() const noexcept override;
163
164 // IBufferLayout interface.
165 public:
167 size_t elementSize() const noexcept override;
168
170 UInt32 binding() const noexcept override;
171
173 BufferType type() const noexcept override;
174 };
175
183 class LITEFX_VULKAN_API IVulkanBuffer : public virtual IBuffer, public virtual IResource<VkBuffer> {
184 protected:
185 IVulkanBuffer() noexcept = default;
186 IVulkanBuffer(IVulkanBuffer&&) noexcept = default;
187 IVulkanBuffer(const IVulkanBuffer&) = delete;
188 IVulkanBuffer& operator=(IVulkanBuffer&&) noexcept = default;
189 IVulkanBuffer& operator=(const IVulkanBuffer&) = delete;
190
191 public:
192 ~IVulkanBuffer() noexcept override = default;
193 };
194
200 class LITEFX_VULKAN_API IVulkanVertexBuffer : public virtual VertexBuffer<VulkanVertexBufferLayout>, public virtual IVulkanBuffer {
201 protected:
202 IVulkanVertexBuffer() noexcept = default;
205 IVulkanVertexBuffer& operator=(IVulkanVertexBuffer&&) noexcept = default;
206 IVulkanVertexBuffer& operator=(const IVulkanVertexBuffer&) = delete;
207
208 public:
209 ~IVulkanVertexBuffer() noexcept override = default;
210 };
211
217 class LITEFX_VULKAN_API IVulkanIndexBuffer : public virtual IndexBuffer<VulkanIndexBufferLayout>, public virtual IVulkanBuffer {
218 protected:
219 IVulkanIndexBuffer() noexcept = default;
222 IVulkanIndexBuffer& operator=(IVulkanIndexBuffer&&) noexcept = default;
223 IVulkanIndexBuffer& operator=(const IVulkanIndexBuffer&) = delete;
224
225 public:
226 ~IVulkanIndexBuffer() noexcept override = default;
227 };
228
237 class LITEFX_VULKAN_API IVulkanImage : public virtual IImage, public virtual IResource<VkImage> {
238 protected:
239 IVulkanImage() noexcept = default;
240 IVulkanImage(IVulkanImage&&) noexcept = default;
241 IVulkanImage(const IVulkanImage&) = delete;
242 IVulkanImage& operator=(IVulkanImage&&) noexcept = default;
243 IVulkanImage& operator=(const IVulkanImage&) = delete;
244
245 public:
246 ~IVulkanImage() noexcept override = default;
247
248 public:
253 virtual VkImageAspectFlags aspectMask() const noexcept = 0;
254
260 virtual VkImageAspectFlags aspectMask(UInt32 plane) const = 0;
261 };
262
270 class LITEFX_VULKAN_API IVulkanSampler : public virtual ISampler, public virtual IResource<VkSampler> {
271 protected:
272 IVulkanSampler() noexcept = default;
273 IVulkanSampler(IVulkanSampler&&) noexcept = default;
275 IVulkanSampler& operator=(IVulkanSampler&&) noexcept = default;
276 IVulkanSampler& operator=(const IVulkanSampler&) = delete;
277
278 public:
279 ~IVulkanSampler() noexcept override = default;
280 };
281
288 class LITEFX_VULKAN_API IVulkanAccelerationStructure : public virtual IAccelerationStructure, public virtual IResource<VkAccelerationStructureKHR> {
289 protected:
290 IVulkanAccelerationStructure() noexcept = default;
295
296 public:
297 ~IVulkanAccelerationStructure() noexcept override = default;
298 };
299
304 class LITEFX_VULKAN_API VulkanBottomLevelAccelerationStructure final : public IBottomLevelAccelerationStructure, public virtual IVulkanAccelerationStructure, public virtual StateResource, public virtual Resource<VkAccelerationStructureKHR> {
305 LITEFX_IMPLEMENTATION(VulkanBottomLevelAccelerationStructureImpl);
306 friend class VulkanDevice;
308
312
313 public:
321 explicit VulkanBottomLevelAccelerationStructure(AccelerationStructureFlags flags = AccelerationStructureFlags::None, StringView name = "");
322
325
328
331
334
336 ~VulkanBottomLevelAccelerationStructure() noexcept override;
337
338 // IAccelerationStructure interface.
339 public:
341 AccelerationStructureFlags flags() const noexcept override;
342
344 SharedPtr<const IVulkanBuffer> buffer() const noexcept;
345
347 void build(const VulkanCommandBuffer& commandBuffer, const SharedPtr<const IVulkanBuffer>& scratchBuffer = nullptr, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
348
350 void update(const VulkanCommandBuffer& commandBuffer, const SharedPtr<const IVulkanBuffer>& scratchBuffer = nullptr, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
351
353 void copy(const VulkanCommandBuffer& commandBuffer, VulkanBottomLevelAccelerationStructure& destination, bool compress = false, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, bool copyBuildInfo = true) const;
354
356 UInt64 offset() const noexcept override;
357
359 UInt64 size() const noexcept override;
360
361 // IBottomLevelAccelerationStructure interface.
362 public:
364 const Array<TriangleMesh>& triangleMeshes() const noexcept override;
365
367 void addTriangleMesh(const TriangleMesh& mesh) override;
368
370 const Array<BoundingBoxes>& boundingBoxes() const noexcept override;
371
373 void addBoundingBox(const BoundingBoxes& aabb) override;
374
376 void clear() noexcept override;
377
379 bool remove(const TriangleMesh& mesh) noexcept override;
380
382 bool remove(const BoundingBoxes& aabb) noexcept override;
383
384 private:
385 Array<std::pair<UInt32, VkAccelerationStructureGeometryKHR>> buildInfo() const;
386 void updateState(const VulkanDevice* device, VkAccelerationStructureKHR handle) noexcept;
387
388 private:
389 SharedPtr<const IBuffer> getBuffer() const noexcept override;
390 void doBuild(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
391 void doUpdate(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
392 void doCopy(const ICommandBuffer& commandBuffer, IBottomLevelAccelerationStructure& destination, bool compress, const SharedPtr<const IBuffer>& buffer, UInt64 offset, bool copyBuildInfo) const override;
393 };
394
399 class LITEFX_VULKAN_API VulkanTopLevelAccelerationStructure final : public ITopLevelAccelerationStructure, public virtual IVulkanAccelerationStructure, public virtual StateResource, public virtual Resource<VkAccelerationStructureKHR> {
400 LITEFX_IMPLEMENTATION(VulkanTopLevelAccelerationStructureImpl);
401 friend class VulkanDevice;
403
407
408 public:
416 explicit VulkanTopLevelAccelerationStructure(AccelerationStructureFlags flags = AccelerationStructureFlags::None, StringView name = "");
417
420
423
426
429
431 ~VulkanTopLevelAccelerationStructure() noexcept override;
432
433 // IAccelerationStructure interface.
434 public:
436 AccelerationStructureFlags flags() const noexcept override;
437
439 SharedPtr<const IVulkanBuffer> buffer() const noexcept;
440
442 void build(const VulkanCommandBuffer& commandBuffer, const SharedPtr<const IVulkanBuffer>& scratchBuffer = nullptr, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
443
445 void update(const VulkanCommandBuffer& commandBuffer, const SharedPtr<const IVulkanBuffer>& scratchBuffer = nullptr, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
446
448 void copy(const VulkanCommandBuffer& commandBuffer, VulkanTopLevelAccelerationStructure& destination, bool compress = false, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, bool copyBuildInfo = true) const;
449
451 UInt64 offset() const noexcept override;
452
454 UInt64 size() const noexcept override;
455
456 // ITopLevelAccelerationStructure interface.
457 public:
459 const Array<Instance>& instances() const noexcept override;
460
462 void addInstance(const Instance& instance) override;
463
465 void clear() noexcept override;
466
468 bool remove(const Instance& mesh) noexcept override;
469
470 private:
471 Array<VkAccelerationStructureInstanceKHR> buildInfo() const;
472 void updateState(const VulkanDevice* device, VkAccelerationStructureKHR handle) noexcept;
473
474 private:
475 SharedPtr<const IBuffer> getBuffer() const noexcept override;
476 void doBuild(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
477 void doUpdate(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
478 void doCopy(const ICommandBuffer& commandBuffer, ITopLevelAccelerationStructure& destination, bool compress, const SharedPtr<const IBuffer>& buffer, UInt64 offset, bool copyBuildInfo) const override;
479 };
480
488 class LITEFX_VULKAN_API VulkanBarrier final : public Barrier<IVulkanBuffer, IVulkanImage> {
489 LITEFX_IMPLEMENTATION(VulkanBarrierImpl);
490 LITEFX_BUILDER(VulkanBarrierBuilder);
491
492 public:
494 using base_type::transition;
495
496 public:
502 explicit VulkanBarrier(PipelineStage syncBefore, PipelineStage syncAfter) noexcept;
503
506
509
511 VulkanBarrier& operator=(VulkanBarrier&&) noexcept;
512
514 VulkanBarrier& operator=(const VulkanBarrier&);
515
517 ~VulkanBarrier() noexcept override;
518
519 private:
520 explicit VulkanBarrier() noexcept;
521 PipelineStage& syncBefore() noexcept;
522 PipelineStage& syncAfter() noexcept;
523
524 // Barrier interface.
525 public:
527 PipelineStage syncBefore() const noexcept override;
528
530 PipelineStage syncAfter() const noexcept override;
531
533 void wait(ResourceAccess accessBefore, ResourceAccess accessAfter) override;
534
536 void transition(const IVulkanBuffer& buffer, ResourceAccess accessBefore, ResourceAccess accessAfter) override;
537
539 void transition(const IVulkanBuffer& buffer, UInt32 element, ResourceAccess accessBefore, ResourceAccess accessAfter) override;
540
542 void transition(const IVulkanImage& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) override;
543
545 void transition(const IVulkanImage& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) override;
546
548 void transition(const IVulkanImage& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) override;
549
551 void transition(const IVulkanImage& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) override;
552
553 public:
559 void execute(const VulkanCommandBuffer& commandBuffer) const;
560 };
561
568 class LITEFX_VULKAN_API VulkanShaderModule final : public IShaderModule, public Resource<VkShaderModule> {
569 LITEFX_IMPLEMENTATION(VulkanShaderModuleImpl);
570
571 public:
580 explicit VulkanShaderModule(const VulkanDevice& device, ShaderStage type, const String& fileName, const String& entryPoint = "main", const Optional<DescriptorBindingPoint>& shaderLocalDescriptor = std::nullopt);
581
591 explicit VulkanShaderModule(const VulkanDevice& device, ShaderStage type, std::istream& stream, const String& name, const String& entryPoint = "main", const Optional<DescriptorBindingPoint>& shaderLocalDescriptor = std::nullopt);
592
595
598
601
603 VulkanShaderModule& operator=(const VulkanShaderModule&) = delete;
604
606 ~VulkanShaderModule() noexcept override;
607
608 // ShaderModule interface.
609 public:
611 const String& fileName() const noexcept override;
612
614 const String& entryPoint() const noexcept override;
615
617 ShaderStage type() const noexcept override;
618
620 const Optional<DescriptorBindingPoint>& shaderLocalDescriptor() const noexcept override;
621
622 public:
627 virtual const String& bytecode() const noexcept;
628
633 virtual VkPipelineShaderStageCreateInfo shaderStageDefinition() const;
634 };
635
642 class LITEFX_VULKAN_API VulkanShaderProgram final : public ShaderProgram<VulkanShaderModule> {
643 LITEFX_IMPLEMENTATION(VulkanShaderProgramImpl);
644 LITEFX_BUILDER(VulkanShaderProgramBuilder);
646
647 private:
654
659 explicit VulkanShaderProgram(const VulkanDevice& device);
660
661 public:
664
667
669 VulkanShaderProgram& operator=(VulkanShaderProgram&&) noexcept = delete;
670
672 VulkanShaderProgram& operator=(const VulkanShaderProgram&) = delete;
673
674 public:
676 ~VulkanShaderProgram() noexcept override;
677
678 // Factory method.
679 public:
686 static inline auto create(const VulkanDevice& device, Enumerable<UniquePtr<VulkanShaderModule>>&& modules) {
687 return SharedObject::create<VulkanShaderProgram>(device, std::move(modules));
688 }
689
690 private:
695 static inline auto create(const VulkanDevice& device) {
697 }
698
699 public:
701 const Array<UniquePtr<const VulkanShaderModule>>& modules() const noexcept override;
702
704 virtual SharedPtr<VulkanPipelineLayout> reflectPipelineLayout() const;
705
706 private:
707 SharedPtr<IPipelineLayout> parsePipelineLayout() const override {
708 return std::static_pointer_cast<IPipelineLayout>(this->reflectPipelineLayout());
709 }
710 };
711
716 class LITEFX_VULKAN_API VulkanDescriptorSet final : public DescriptorSet<IVulkanBuffer, IVulkanImage, IVulkanSampler, IVulkanAccelerationStructure>, public Resource<VkDescriptorSet> {
717 LITEFX_IMPLEMENTATION(VulkanDescriptorSetImpl);
718
719 public:
721 using base_type::update;
722
723 public:
729 explicit VulkanDescriptorSet(const VulkanDescriptorSetLayout& layout, VkDescriptorSet descriptorSet);
730
733
736
738 VulkanDescriptorSet& operator=(VulkanDescriptorSet&&) noexcept = delete;
739
741 VulkanDescriptorSet& operator=(const VulkanDescriptorSet&) = delete;
742
744 ~VulkanDescriptorSet() noexcept override;
745
746 public:
751 virtual const VulkanDescriptorSetLayout& layout() const noexcept;
752
753 public:
755 void update(UInt32 binding, const IVulkanBuffer& buffer, UInt32 bufferElement = 0, UInt32 elements = 0, UInt32 firstDescriptor = 0) const override;
756
758 void update(UInt32 binding, const IVulkanImage& texture, UInt32 descriptor = 0, UInt32 firstLevel = 0, UInt32 levels = 0, UInt32 firstLayer = 0, UInt32 layers = 0) const override;
759
761 void update(UInt32 binding, const IVulkanSampler& sampler, UInt32 descriptor = 0) const override;
762
764 void update(UInt32 binding, const IVulkanAccelerationStructure& accelerationStructure, UInt32 descriptor = 0) const override;
765 };
766
775 class LITEFX_VULKAN_API VulkanDescriptorLayout final : public IDescriptorLayout {
776 LITEFX_IMPLEMENTATION(VulkanDescriptorLayoutImpl);
777
778 public:
787 VulkanDescriptorLayout(DescriptorType type, UInt32 binding, size_t elementSize, UInt32 descriptors = 1);
788
794 VulkanDescriptorLayout(const IVulkanSampler& staticSampler, UInt32 binding);
795
801 VulkanDescriptorLayout(UInt32 binding, UInt32 inputAttachmentIndex);
802
805
808
811
814
816 ~VulkanDescriptorLayout() noexcept override;
817
818 // IDescriptorLayout interface.
819 public:
821 DescriptorType descriptorType() const noexcept override;
822
824 UInt32 descriptors() const noexcept override;
825
827 const IVulkanSampler* staticSampler() const noexcept override;
828
829 // IBufferLayout interface.
830 public:
832 size_t elementSize() const noexcept override;
833
835 UInt32 binding() const noexcept override;
836
838 BufferType type() const noexcept override;
839
840 // VulkanDescriptorLayout
841 public:
850 UInt32 inputAttachmentIndex() const noexcept;
851 };
852
858 class LITEFX_VULKAN_API VulkanDescriptorSetLayout final : public DescriptorSetLayout<VulkanDescriptorLayout, VulkanDescriptorSet>, public Resource<VkDescriptorSetLayout> {
859 LITEFX_IMPLEMENTATION(VulkanDescriptorSetLayoutImpl);
860 LITEFX_BUILDER(VulkanDescriptorSetLayoutBuilder);
862
863 public:
865 using base_type::free;
866 using base_type::allocate;
867
868 private:
876 explicit VulkanDescriptorSetLayout(const VulkanDevice& device, const Enumerable<VulkanDescriptorLayout>& descriptorLayouts, UInt32 space, ShaderStage stages);
877
882 explicit VulkanDescriptorSetLayout(const VulkanDevice& device);
883
884 private:
887
890
892 VulkanDescriptorSetLayout& operator=(VulkanDescriptorSetLayout&&) noexcept = delete;
893
895 VulkanDescriptorSetLayout& operator=(const VulkanDescriptorSetLayout&) = delete;
896
897 public:
899 ~VulkanDescriptorSetLayout() noexcept override;
900
901 public:
910 static inline auto create(const VulkanDevice& device, const Enumerable<VulkanDescriptorLayout>& descriptorLayouts, UInt32 space, ShaderStage stages) {
911 return SharedObject::create<VulkanDescriptorSetLayout>(device, descriptorLayouts, space, stages);
912 }
913
919 static inline auto create(const VulkanDescriptorSetLayout& other) {
921 }
922
923 private:
929 static inline auto create(const VulkanDevice& device) {
931 }
932
933 public:
938 const VulkanDevice& device() const noexcept;
939
940 public:
942 const Array<VulkanDescriptorLayout>& descriptors() const noexcept override;
943
945 const VulkanDescriptorLayout& descriptor(UInt32 binding) const override;
946
948 UInt32 space() const noexcept override;
949
951 ShaderStage shaderStages() const noexcept override;
952
954 UInt32 uniforms() const noexcept override;
955
957 UInt32 storages() const noexcept override;
958
960 UInt32 images() const noexcept override;
961
963 UInt32 buffers() const noexcept override;
964
966 UInt32 samplers() const noexcept override;
967
969 UInt32 staticSamplers() const noexcept override;
970
972 UInt32 inputAttachments() const noexcept override;
973
974 public:
976 UniquePtr<VulkanDescriptorSet> allocate(UInt32 descriptors, std::initializer_list<DescriptorBinding> bindings) const override;
977
979 UniquePtr<VulkanDescriptorSet> allocate(UInt32 descriptors, Span<DescriptorBinding> bindings) const override;
980
982 UniquePtr<VulkanDescriptorSet> allocate(UInt32 descriptors, Generator<DescriptorBinding> bindings) const override;
983
985 Generator<UniquePtr<VulkanDescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::initializer_list<std::initializer_list<DescriptorBinding>> bindings = { }) const override;
986
987#ifdef __cpp_lib_mdspan
989 Generator<UniquePtr<VulkanDescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::mdspan<DescriptorBinding, std::dextents<size_t, 2>> bindings) const override;
990#endif
991
993 Generator<UniquePtr<VulkanDescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::function<Generator<DescriptorBinding>(UInt32)> bindingFactory) const override;
994
996 void free(const VulkanDescriptorSet& descriptorSet) const override;
997
998 public:
1005 virtual size_t pools() const noexcept;
1006 };
1007
1012 class LITEFX_VULKAN_API VulkanPushConstantsRange final : public IPushConstantsRange {
1013 LITEFX_IMPLEMENTATION(VulkanPushConstantsRangeImpl);
1014
1015 public:
1024 explicit VulkanPushConstantsRange(ShaderStage shaderStage, UInt32 offset, UInt32 size, UInt32 space, UInt32 binding);
1025
1028
1031
1034
1037
1039 ~VulkanPushConstantsRange() noexcept override;
1040
1041 public:
1043 UInt32 space() const noexcept override;
1044
1046 UInt32 binding() const noexcept override;
1047
1049 UInt32 offset() const noexcept override;
1050
1052 UInt32 size() const noexcept override;
1053
1055 ShaderStage stage() const noexcept override;
1056 };
1057
1065 LITEFX_IMPLEMENTATION(VulkanPushConstantsLayoutImpl);
1066 LITEFX_BUILDER(VulkanPushConstantsLayoutBuilder);
1068
1069 public:
1076
1079
1082
1085
1088
1090 ~VulkanPushConstantsLayout() noexcept override;
1091
1092 private:
1097 explicit VulkanPushConstantsLayout(UInt32 size);
1098
1099 public:
1101 UInt32 size() const noexcept override;
1102
1104 const VulkanPushConstantsRange& range(ShaderStage stage) const override;
1105
1107 const Array<UniquePtr<VulkanPushConstantsRange>>& ranges() const override;
1108 };
1109
1114 class LITEFX_VULKAN_API VulkanPipelineLayout final : public PipelineLayout<VulkanDescriptorSetLayout, VulkanPushConstantsLayout>, public Resource<VkPipelineLayout> {
1115 LITEFX_IMPLEMENTATION(VulkanPipelineLayoutImpl);
1116 LITEFX_BUILDER(VulkanPipelineLayoutBuilder);
1118
1119 private:
1126 explicit VulkanPipelineLayout(const VulkanDevice& device, const Enumerable<SharedPtr<VulkanDescriptorSetLayout>>& descriptorSetLayouts, UniquePtr<VulkanPushConstantsLayout>&& pushConstantsLayout);
1127
1132 explicit VulkanPipelineLayout(const VulkanDevice& device) noexcept;
1133
1134 private:
1136 VulkanPipelineLayout(VulkanPipelineLayout&&) noexcept = delete;
1137
1140
1142 VulkanPipelineLayout& operator=(VulkanPipelineLayout&&) noexcept = delete;
1143
1145 VulkanPipelineLayout& operator=(const VulkanPipelineLayout&) = delete;
1146
1147 public:
1149 ~VulkanPipelineLayout() noexcept override;
1150
1151 public:
1159 static inline auto create(const VulkanDevice& device, const Enumerable<SharedPtr<VulkanDescriptorSetLayout>>& descriptorSetLayouts, UniquePtr<VulkanPushConstantsLayout>&& pushConstantsLayout) {
1160 return SharedObject::create<VulkanPipelineLayout>(device, descriptorSetLayouts, std::move(pushConstantsLayout));
1161 }
1162
1163 private:
1169 static inline auto create(const VulkanDevice& device) {
1171 }
1172
1173 // PipelineLayout interface.
1174 public:
1176 const VulkanDevice& device() const noexcept /*override*/;
1177
1179 const VulkanDescriptorSetLayout& descriptorSet(UInt32 space) const override;
1180
1182 const Array<SharedPtr<const VulkanDescriptorSetLayout>>& descriptorSets() const override;
1183
1185 const VulkanPushConstantsLayout* pushConstants() const noexcept override;
1186 };
1187
1193 LITEFX_IMPLEMENTATION(VulkanInputAssemblerImpl);
1194 LITEFX_BUILDER(VulkanInputAssemblerBuilder);
1196
1197 private:
1204 explicit VulkanInputAssembler(Enumerable<SharedPtr<VulkanVertexBufferLayout>>&& vertexBufferLayouts, SharedPtr<VulkanIndexBufferLayout>&& indexBufferLayout = nullptr, PrimitiveTopology primitiveTopology = PrimitiveTopology::TriangleList);
1205
1209 explicit VulkanInputAssembler();
1210
1211 private:
1213 VulkanInputAssembler(VulkanInputAssembler&&) noexcept = delete;
1214
1217
1219 VulkanInputAssembler& operator=(VulkanInputAssembler&&) noexcept = delete;
1220
1222 VulkanInputAssembler& operator=(const VulkanInputAssembler&) = delete;
1223
1224 public:
1226 ~VulkanInputAssembler() noexcept override;
1227
1228 public:
1236 static inline auto create(Enumerable<SharedPtr<VulkanVertexBufferLayout>>&& vertexBufferLayouts, SharedPtr<VulkanIndexBufferLayout>&& indexBufferLayout = nullptr, PrimitiveTopology primitiveTopology = PrimitiveTopology::TriangleList) {
1237 return SharedObject::create<VulkanInputAssembler>(std::move(vertexBufferLayouts), std::move(indexBufferLayout), primitiveTopology);
1238 }
1239
1245 static inline auto create(const VulkanInputAssembler& other) {
1247 }
1248
1249 private:
1254 static inline auto create() {
1256 }
1257
1258 public:
1260 Enumerable<const VulkanVertexBufferLayout&> vertexBufferLayouts() const override;
1261
1263 const VulkanVertexBufferLayout& vertexBufferLayout(UInt32 binding) const override;
1264
1266 const VulkanIndexBufferLayout* indexBufferLayout() const noexcept override;
1267
1269 PrimitiveTopology topology() const noexcept override;
1270 };
1271
1276 class LITEFX_VULKAN_API VulkanRasterizer final : public Rasterizer {
1277 LITEFX_BUILDER(VulkanRasterizerBuilder);
1279
1280 private:
1289 explicit VulkanRasterizer(PolygonMode polygonMode, CullMode cullMode, CullOrder cullOrder, Float lineWidth = 1.f, const DepthStencilState& depthStencilState = {}) noexcept;
1290
1294 explicit VulkanRasterizer() noexcept;
1295
1296 private:
1298 VulkanRasterizer(VulkanRasterizer&&) noexcept = delete;
1299
1301 VulkanRasterizer(const VulkanRasterizer&) = default;
1302
1304 VulkanRasterizer& operator=(VulkanRasterizer&&) noexcept = delete;
1305
1307 VulkanRasterizer& operator=(const VulkanRasterizer&) = delete;
1308
1309 public:
1311 ~VulkanRasterizer() noexcept override;
1312
1313 public:
1323 static inline auto create(PolygonMode polygonMode, CullMode cullMode, CullOrder cullOrder, Float lineWidth = 1.f, const DepthStencilState& depthStencilState = {}) {
1324 return SharedObject::create<VulkanRasterizer>(polygonMode, cullMode, cullOrder, lineWidth, depthStencilState);
1325 }
1326
1332 static inline auto create(const VulkanRasterizer& other) {
1334 }
1335
1336 private:
1341 static inline auto create() {
1343 }
1344
1345 public:
1358 virtual void updateLineWidth(Float lineWidth) noexcept;
1359 };
1360
1366 class LITEFX_VULKAN_API VulkanPipelineState : public virtual Pipeline<VulkanPipelineLayout, VulkanShaderProgram>, public Resource<VkPipeline> {
1367 protected:
1368 using Resource<VkPipeline>::Resource;
1369
1372 VulkanPipelineState& operator=(VulkanPipelineState&&) noexcept = default;
1373 VulkanPipelineState& operator=(const VulkanPipelineState&) = delete;
1374
1375 public:
1376 ~VulkanPipelineState() noexcept override = default;
1377
1378 public:
1383 virtual void use(const VulkanCommandBuffer& commandBuffer) const = 0;
1384
1390 virtual void bind(const VulkanCommandBuffer& commandBuffer, Span<const VulkanDescriptorSet*> descriptorSets) const = 0;
1391 };
1392
1398 LITEFX_IMPLEMENTATION(VulkanCommandBufferImpl);
1400
1401 public:
1403 using base_type::dispatch;
1404 using base_type::dispatchIndirect;
1405 using base_type::dispatchMesh;
1406 using base_type::draw;
1407 using base_type::drawIndirect;
1408 using base_type::drawIndexed;
1409 using base_type::drawIndexedIndirect;
1410 using base_type::barrier;
1411 using base_type::transfer;
1412 using base_type::bind;
1413 using base_type::use;
1414 using base_type::pushConstants;
1415 using base_type::buildAccelerationStructure;
1416 using base_type::updateAccelerationStructure;
1417 using base_type::copyAccelerationStructure;
1418
1419 private:
1426 explicit VulkanCommandBuffer(const VulkanQueue& queue, bool begin = false, bool primary = true);
1427
1428 private:
1430 VulkanCommandBuffer(VulkanCommandBuffer&&) noexcept = delete;
1431
1434
1436 VulkanCommandBuffer& operator=(VulkanCommandBuffer&&) noexcept = delete;
1437
1439 VulkanCommandBuffer& operator=(const VulkanCommandBuffer&) = delete;
1440
1441 public:
1443 ~VulkanCommandBuffer() noexcept override;
1444
1445 // Factory method.
1446 public:
1453 static inline SharedPtr<VulkanCommandBuffer> create(const VulkanQueue& queue, bool begin = false, bool primary = true) {
1454 return SharedObject::create<VulkanCommandBuffer>(queue, begin, primary);
1455 }
1456
1457 // Vulkan Command Buffer interface.
1458 public:
1463 virtual void begin(const VulkanRenderPass& renderPass) const;
1464
1465 // CommandBuffer interface.
1466 public:
1468 SharedPtr<const VulkanQueue> queue() const noexcept;
1469
1471 void begin() const override;
1472
1474 void end() const override;
1475
1477 void track(SharedPtr<const IBuffer> buffer) const override;
1478
1480 void track(SharedPtr<const IImage> image) const override;
1481
1483 void track(SharedPtr<const ISampler> sampler) const override;
1484
1486 bool isSecondary() const noexcept override;
1487
1489 void setViewports(Span<const IViewport*> viewports) const override;
1490
1492 void setViewports(const IViewport* viewport) const override;
1493
1495 void setScissors(Span<const IScissor*> scissors) const override;
1496
1498 void setScissors(const IScissor* scissor) const override;
1499
1501 void setBlendFactors(const Vector4f& blendFactors) const noexcept override;
1502
1504 void setStencilRef(UInt32 stencilRef) const noexcept override;
1505
1507 UInt64 submit() const override;
1508
1510 [[nodiscard]] UniquePtr<VulkanBarrier> makeBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const override;
1511
1513 void barrier(const VulkanBarrier& barrier) const noexcept override;
1514
1516 void transfer(const IVulkanBuffer& source, const IVulkanBuffer& target, UInt32 sourceElement = 0, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1517
1519 void transfer(const void* const data, size_t size, const IVulkanBuffer& target, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1520
1522 void transfer(Span<const void* const> data, size_t elementSize, const IVulkanBuffer& target, UInt32 firstElement = 0) const override;
1523
1525 void transfer(const IVulkanBuffer& source, const IVulkanImage& target, UInt32 sourceElement = 0, UInt32 firstSubresource = 0, UInt32 subresources = 1) const override;
1526
1528 void transfer(const void* const data, size_t size, const IVulkanImage& target, UInt32 subresource = 0) const override;
1529
1531 void transfer(Span<const void* const> data, size_t elementSize, const IVulkanImage& target, UInt32 firstSubresource = 0, UInt32 subresources = 1) const override;
1532
1534 void transfer(const IVulkanImage& source, const IVulkanImage& target, UInt32 sourceSubresource = 0, UInt32 targetSubresource = 0, UInt32 subresources = 1) const override;
1535
1537 void transfer(const IVulkanImage& source, const IVulkanBuffer& target, UInt32 firstSubresource = 0, UInt32 targetElement = 0, UInt32 subresources = 1) const override;
1538
1540 void transfer(const SharedPtr<const IVulkanBuffer>& source, const IVulkanBuffer& target, UInt32 sourceElement = 0, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1541
1543 void transfer(const SharedPtr<const IVulkanBuffer>& source, const IVulkanImage& target, UInt32 sourceElement = 0, UInt32 firstSubresource = 0, UInt32 elements = 1) const override;
1544
1546 void transfer(const SharedPtr<const IVulkanImage>& source, const IVulkanImage& target, UInt32 sourceSubresource = 0, UInt32 targetSubresource = 0, UInt32 subresources = 1) const override;
1547
1549 void transfer(const SharedPtr<const IVulkanImage>& source, const IVulkanBuffer& target, UInt32 firstSubresource = 0, UInt32 targetElement = 0, UInt32 subresources = 1) const override;
1550
1552 void use(const VulkanPipelineState& pipeline) const noexcept override;
1553
1555 void bind(const VulkanDescriptorSet& descriptorSet) const override;
1556
1558 void bind(Span<const VulkanDescriptorSet*> descriptorSets) const override;
1559
1561 void bind(const VulkanDescriptorSet& descriptorSet, const VulkanPipelineState& pipeline) const override;
1562
1564 void bind(Span<const VulkanDescriptorSet*> descriptorSets, const VulkanPipelineState& pipeline) const override;
1565
1567 void bind(const IVulkanVertexBuffer& buffer) const noexcept override;
1568
1570 void bind(const IVulkanIndexBuffer& buffer) const noexcept override;
1571
1573 void dispatch(const Vector3u& threadCount) const noexcept override;
1574
1576 void dispatchIndirect(const IVulkanBuffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1577
1579 void dispatchMesh(const Vector3u& threadCount) const noexcept override;
1580
1582 void dispatchMeshIndirect(const IVulkanBuffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1583
1585 void dispatchMeshIndirect(const IVulkanBuffer& batchBuffer, const IVulkanBuffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1586
1588 void draw(UInt32 vertices, UInt32 instances = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) const noexcept override;
1589
1591 void drawIndirect(const IVulkanBuffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1592
1594 void drawIndirect(const IVulkanBuffer& batchBuffer, const IVulkanBuffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1595
1597 void drawIndexed(UInt32 indices, UInt32 instances = 1, UInt32 firstIndex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0) const noexcept override;
1598
1600 void drawIndexedIndirect(const IVulkanBuffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1601
1603 void drawIndexedIndirect(const IVulkanBuffer& batchBuffer, const IVulkanBuffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1604
1606 void pushConstants(const VulkanPushConstantsLayout& layout, const void* const memory) const override;
1607
1609 void writeTimingEvent(const SharedPtr<const TimingEvent>& timingEvent) const override;
1610
1612 void execute(const SharedPtr<const VulkanCommandBuffer>& commandBuffer) const override;
1613
1615 void execute(Enumerable<SharedPtr<const VulkanCommandBuffer>> commandBuffers) const override;
1616
1618 void buildAccelerationStructure(VulkanBottomLevelAccelerationStructure& blas, const SharedPtr<const IVulkanBuffer>& scratchBuffer, const IVulkanBuffer& buffer, UInt64 offset) const override;
1619
1621 void buildAccelerationStructure(VulkanTopLevelAccelerationStructure& tlas, const SharedPtr<const IVulkanBuffer>& scratchBuffer, const IVulkanBuffer& buffer, UInt64 offset) const override;
1622
1624 void updateAccelerationStructure(VulkanBottomLevelAccelerationStructure& blas, const SharedPtr<const IVulkanBuffer>& scratchBuffer, const IVulkanBuffer& buffer, UInt64 offset) const override;
1625
1627 void updateAccelerationStructure(VulkanTopLevelAccelerationStructure& tlas, const SharedPtr<const IVulkanBuffer>& scratchBuffer, const IVulkanBuffer& buffer, UInt64 offset) const override;
1628
1630 void copyAccelerationStructure(const VulkanBottomLevelAccelerationStructure& from, const VulkanBottomLevelAccelerationStructure& to, bool compress = false) const noexcept override;
1631
1633 void copyAccelerationStructure(const VulkanTopLevelAccelerationStructure& from, const VulkanTopLevelAccelerationStructure& to, bool compress = false) const noexcept override;
1634
1636 void traceRays(UInt32 width, UInt32 height, UInt32 depth, const ShaderBindingTableOffsets& offsets, const IVulkanBuffer& rayGenerationShaderBindingTable, const IVulkanBuffer* missShaderBindingTable, const IVulkanBuffer* hitShaderBindingTable, const IVulkanBuffer* callableShaderBindingTable) const noexcept override;
1637
1638 private:
1639 inline SharedPtr<const ICommandQueue> getQueue() const noexcept override {
1640 return std::static_pointer_cast<const ICommandQueue>(this->queue());
1641 }
1642
1643 void releaseSharedState() const override;
1644 };
1645
1650 class LITEFX_VULKAN_API VulkanQueue final : public CommandQueue<VulkanCommandBuffer>, public Resource<VkQueue> {
1651 LITEFX_IMPLEMENTATION(VulkanQueueImpl);
1652 friend struct SharedObject::Allocator<VulkanQueue>;
1653
1654 public:
1656 using base_type::submit;
1657
1658 private:
1667 explicit VulkanQueue(const VulkanDevice& device, QueueType type, QueuePriority priority, UInt32 familyId, UInt32 queueId);
1668
1669 private:
1671 VulkanQueue(VulkanQueue&&) noexcept = delete;
1672
1674 VulkanQueue(const VulkanQueue&) = delete;
1675
1677 VulkanQueue& operator=(VulkanQueue&&) noexcept = delete;
1678
1680 VulkanQueue& operator=(const VulkanQueue&) = delete;
1681
1682 public:
1684 ~VulkanQueue() noexcept override;
1685
1686 public:
1696 static inline SharedPtr<VulkanQueue> create(const VulkanDevice& device, QueueType type, QueuePriority priority, UInt32 familyId, UInt32 queueId) {
1697 return SharedObject::create<VulkanQueue>(device, type, priority, familyId, queueId);
1698 }
1699
1700 // VulkanQueue interface.
1701 public:
1706 SharedPtr<const VulkanDevice> device() const noexcept;
1707
1712 UInt32 familyId() const noexcept;
1713
1718 UInt32 queueId() const noexcept;
1719
1724 const VkSemaphore& timelineSemaphore() const noexcept;
1725
1726 // CommandQueue interface.
1727 public:
1729 QueuePriority priority() const noexcept override;
1730
1732 QueueType type() const noexcept override;
1733
1734#ifdef LITEFX_BUILD_SUPPORT_DEBUG_MARKERS
1735 public:
1737 void beginDebugRegion(const String& label, const Vectors::ByteVector3& color = DEFAULT_DEBUG_COLOR) const noexcept override;
1738
1740 void endDebugRegion() const noexcept override;
1741
1743 void setDebugMarker(const String& label, const Vectors::ByteVector3& color = DEFAULT_DEBUG_COLOR) const noexcept override;
1744#endif // LITEFX_BUILD_SUPPORT_DEBUG_MARKERS
1745
1746 public:
1748 SharedPtr<VulkanCommandBuffer> createCommandBuffer(bool beginRecording = false, bool secondary = false) const override;
1749
1751 UInt64 submit(const SharedPtr<const VulkanCommandBuffer>& commandBuffer) const override;
1752
1754 UInt64 submit(Enumerable<SharedPtr<const VulkanCommandBuffer>> commandBuffers) const override;
1755
1757 void waitFor(UInt64 fence) const override;
1758
1760 void waitFor(const VulkanQueue& queue, UInt64 fence) const noexcept;
1761
1763 UInt64 currentFence() const noexcept override;
1764
1765 private:
1766 inline void waitForQueue(const ICommandQueue& queue, UInt64 fence) const override {
1767 auto vkQueue = dynamic_cast<const VulkanQueue*>(&queue);
1768
1769 if (vkQueue == nullptr) [[unlikely]]
1770 throw InvalidArgumentException("queue", "Cannot wait for queues from other backends.");
1771
1772 this->waitFor(*vkQueue, fence);
1773 }
1774 };
1775
1781 class LITEFX_VULKAN_API VulkanRenderPipeline final : public virtual VulkanPipelineState, public RenderPipeline<VulkanPipelineLayout, VulkanShaderProgram, VulkanInputAssembler, VulkanRasterizer> {
1782 LITEFX_IMPLEMENTATION(VulkanRenderPipelineImpl);
1783 LITEFX_BUILDER(VulkanRenderPipelineBuilder);
1784
1785 public:
1797 explicit VulkanRenderPipeline(const VulkanRenderPass& renderPass, const SharedPtr<VulkanShaderProgram>& shaderProgram, const SharedPtr<VulkanPipelineLayout>& layout, const SharedPtr<VulkanInputAssembler>& inputAssembler, const SharedPtr<VulkanRasterizer>& rasterizer, MultiSamplingLevel samples = MultiSamplingLevel::x1, bool enableAlphaToCoverage = false, const String& name = "");
1798
1801
1804
1806 VulkanRenderPipeline& operator=(VulkanRenderPipeline&&) noexcept = delete;
1807
1809 VulkanRenderPipeline& operator=(const VulkanRenderPipeline&) = delete;
1810
1812 ~VulkanRenderPipeline() noexcept override;
1813
1814 private:
1820 VulkanRenderPipeline(const VulkanRenderPass& renderPass, const String& name = "");
1821
1822 // Pipeline interface.
1823 public:
1825 SharedPtr<const VulkanShaderProgram> program() const noexcept override;
1826
1828 SharedPtr<const VulkanPipelineLayout> layout() const noexcept override;
1829
1830 // RenderPipeline interface.
1831 public:
1833 SharedPtr<VulkanInputAssembler> inputAssembler() const noexcept override;
1834
1836 SharedPtr<VulkanRasterizer> rasterizer() const noexcept override;
1837
1839 bool alphaToCoverage() const noexcept override;
1840
1842 MultiSamplingLevel samples() const noexcept override;
1843
1845 void updateSamples(MultiSamplingLevel samples) override;
1846
1847 // VulkanPipelineState interface.
1848 public:
1850 void use(const VulkanCommandBuffer& commandBuffer) const override;
1851
1853 void bind(const VulkanCommandBuffer& commandBuffer, Span<const VulkanDescriptorSet*> descriptorSets) const override;
1854 };
1855
1862 LITEFX_IMPLEMENTATION(VulkanComputePipelineImpl);
1863 LITEFX_BUILDER(VulkanComputePipelineBuilder);
1864
1865 public:
1873 explicit VulkanComputePipeline(const VulkanDevice& device, const SharedPtr<VulkanPipelineLayout>& layout, const SharedPtr<VulkanShaderProgram>& shaderProgram, const String& name = "");
1874
1877
1880
1883
1886
1888 ~VulkanComputePipeline() noexcept override;
1889
1890 private:
1895 VulkanComputePipeline(const VulkanDevice& device) noexcept;
1896
1897 // Pipeline interface.
1898 public:
1900 SharedPtr<const VulkanShaderProgram> program() const noexcept override;
1901
1903 SharedPtr<const VulkanPipelineLayout> layout() const noexcept override;
1904
1905 // VulkanPipelineState interface.
1906 public:
1908 void use(const VulkanCommandBuffer& commandBuffer) const override;
1909
1911 void bind(const VulkanCommandBuffer& commandBuffer, Span<const VulkanDescriptorSet*> descriptorSets) const override;
1912 };
1913
1920 LITEFX_IMPLEMENTATION(VulkanRayTracingPipelineImpl);
1921 LITEFX_BUILDER(VulkanRayTracingPipelineBuilder);
1922
1923 public:
1935 explicit VulkanRayTracingPipeline(const VulkanDevice& device, const SharedPtr<VulkanPipelineLayout>& layout, const SharedPtr<VulkanShaderProgram>& shaderProgram, ShaderRecordCollection&& shaderRecords, UInt32 maxRecursionDepth = 10, UInt32 maxPayloadSize = 0, UInt32 maxAttributeSize = 32, const String& name = ""); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
1936
1939
1942
1945
1948
1950 ~VulkanRayTracingPipeline() noexcept override;
1951
1952 private:
1958 VulkanRayTracingPipeline(const VulkanDevice& device, ShaderRecordCollection&& shaderRecords) noexcept;
1959
1960 // Pipeline interface.
1961 public:
1963 SharedPtr<const VulkanShaderProgram> program() const noexcept override;
1964
1966 SharedPtr<const VulkanPipelineLayout> layout() const noexcept override;
1967
1968 // RayTracingPipeline interface.
1969 public:
1971 const ShaderRecordCollection& shaderRecords() const noexcept override;
1972
1974 UInt32 maxRecursionDepth() const noexcept override;
1975
1977 UInt32 maxPayloadSize() const noexcept override;
1978
1980 UInt32 maxAttributeSize() const noexcept override;
1981
1983 SharedPtr<IVulkanBuffer> allocateShaderBindingTable(ShaderBindingTableOffsets& offsets, ShaderBindingGroup groups = ShaderBindingGroup::All) const override;
1984
1985 // VulkanPipelineState interface.
1986 public:
1988 void use(const VulkanCommandBuffer& commandBuffer) const override;
1989
1991 void bind(const VulkanCommandBuffer& commandBuffer, Span<const VulkanDescriptorSet*> descriptorSets) const override;
1992 };
1993
1998 class LITEFX_VULKAN_API VulkanFrameBuffer final : public FrameBuffer<IVulkanImage> {
1999 LITEFX_IMPLEMENTATION(VulkanFrameBufferImpl);
2001
2002 public:
2003 using FrameBuffer::addImage;
2004 using FrameBuffer::mapRenderTarget;
2005 using FrameBuffer::mapRenderTargets;
2006
2007 private:
2014 VulkanFrameBuffer(const VulkanDevice& device, const Size2d& renderArea, StringView name = "");
2015
2016 private:
2018 VulkanFrameBuffer(VulkanFrameBuffer&&) noexcept = delete;
2019
2021 VulkanFrameBuffer(const VulkanFrameBuffer&) = delete;
2022
2024 VulkanFrameBuffer& operator=(VulkanFrameBuffer&&) noexcept = delete;
2025
2027 VulkanFrameBuffer& operator=(const VulkanFrameBuffer&) = delete;
2028
2029 public:
2031 ~VulkanFrameBuffer() noexcept override;
2032
2033 public:
2041 static inline SharedPtr<VulkanFrameBuffer> create(const VulkanDevice& device, const Size2d& renderArea, StringView name = "") {
2042 return SharedObject::create<VulkanFrameBuffer>(device, renderArea, name);
2043 }
2044
2045 // Vulkan frame buffer interface.
2046 public:
2053 VkImageView imageView(UInt32 imageIndex) const;
2054
2061 VkImageView imageView(StringView imageName) const;
2062
2069 VkImageView imageView(const RenderTarget& renderTarget) const;
2070
2071 // FrameBuffer interface.
2072 public:
2074 const Size2d& size() const noexcept override;
2075
2077 size_t getWidth() const noexcept override;
2078
2080 size_t getHeight() const noexcept override;
2081
2083 void mapRenderTarget(const RenderTarget& renderTarget, UInt32 index) override;
2084
2086 void mapRenderTarget(const RenderTarget& renderTarget, StringView name) override;
2087
2089 void unmapRenderTarget(const RenderTarget& renderTarget) noexcept override;
2090
2092 const Array<SharedPtr<const IVulkanImage>>& images() const override;
2093
2095 inline const IVulkanImage& operator[](UInt32 index) const override {
2096 return this->image(index);
2097 }
2098
2100 const IVulkanImage& image(UInt32 index) const override;
2101
2103 inline const IVulkanImage& operator[](const RenderTarget& renderTarget) const override {
2104 return this->image(renderTarget);
2105 }
2106
2108 const IVulkanImage& image(const RenderTarget& renderTarget) const override;
2109
2111 inline const IVulkanImage& operator[](StringView renderTargetName) const override {
2112 return this->resolveImage(hash(renderTargetName));
2113 }
2114
2116 inline const IVulkanImage& image(StringView renderTargetName) const override {
2117 return this->resolveImage(hash(renderTargetName));
2118 }
2119
2121 const IVulkanImage& resolveImage(UInt64 hash) const override;
2122
2124 void addImage(const String& name, Format format, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::FrameBufferImage) override;
2125
2127 void addImage(const String& name, const RenderTarget& renderTarget, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::FrameBufferImage) override;
2128
2130 void resize(const Size2d& renderArea) override;
2131 };
2132
2137 class LITEFX_VULKAN_API VulkanRenderPass final : public RenderPass<VulkanQueue, VulkanFrameBuffer> {
2138 LITEFX_IMPLEMENTATION(VulkanRenderPassImpl);
2139 LITEFX_BUILDER(VulkanRenderPassBuilder);
2141
2142 public:
2144
2145 private:
2154 explicit VulkanRenderPass(const VulkanDevice& device, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u);
2155
2165 explicit VulkanRenderPass(const VulkanDevice& device, const String& name, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u);
2166
2176 explicit VulkanRenderPass(const VulkanDevice& device, const VulkanQueue& queue, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u);
2177
2188 explicit VulkanRenderPass(const VulkanDevice& device, const String& name, const VulkanQueue& queue, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u);
2189
2190 private:
2192 VulkanRenderPass(VulkanRenderPass&&) noexcept = delete;
2193
2195 VulkanRenderPass(const VulkanRenderPass&) = delete;
2196
2198 VulkanRenderPass& operator=(VulkanRenderPass&&) noexcept = delete;
2199
2201 VulkanRenderPass& operator=(const VulkanRenderPass&) = delete;
2202
2203 public:
2205 ~VulkanRenderPass() noexcept override;
2206
2207 public:
2217 static inline SharedPtr<VulkanRenderPass> create(const VulkanDevice& device, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u) {
2218 return SharedObject::create<VulkanRenderPass>(device, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers);
2219 }
2220
2231 static inline SharedPtr<VulkanRenderPass> create(const VulkanDevice& device, const String& name, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u) {
2232 return SharedObject::create<VulkanRenderPass>(device, name, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers);
2233 }
2234
2245 static inline SharedPtr<VulkanRenderPass> create(const VulkanDevice& device, const VulkanQueue& queue, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u) {
2246 return SharedObject::create<VulkanRenderPass>(device, queue, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers);
2247 }
2248
2260 static inline SharedPtr<VulkanRenderPass> create(const VulkanDevice& device, const String& name, const VulkanQueue& queue, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u) {
2261 return SharedObject::create<VulkanRenderPass>(device, name, queue, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers);
2262 }
2263
2264 private:
2270 explicit VulkanRenderPass(const VulkanDevice& device, const String& name = "");
2271
2282 static inline SharedPtr<VulkanRenderPass> create(const VulkanDevice& device, const String& name = "") {
2283 return SharedObject::create<VulkanRenderPass>(device, name);
2284 }
2285
2286 // RenderPass interface.
2287 public:
2292 const VulkanDevice& device() const noexcept /*override*/;
2293
2295 SharedPtr<const VulkanFrameBuffer> activeFrameBuffer() const noexcept override;
2296
2298 const VulkanQueue& commandQueue() const noexcept override;
2299
2301 Enumerable<SharedPtr<const VulkanCommandBuffer>> commandBuffers() const override;
2302
2304 SharedPtr<const VulkanCommandBuffer> commandBuffer(UInt32 index) const override;
2305
2307 UInt32 secondaryCommandBuffers() const noexcept override;
2308
2310 const Array<RenderTarget>& renderTargets() const noexcept override;
2311
2313 const RenderTarget& renderTarget(UInt32 location) const override;
2314
2316 bool hasPresentTarget() const noexcept override;
2317
2319 const Array<RenderPassDependency>& inputAttachments() const noexcept override;
2320
2322 const RenderPassDependency& inputAttachment(UInt32 location) const override;
2323
2325 const Optional<DescriptorBindingPoint>& inputAttachmentSamplerBinding() const noexcept override;
2326
2328 void begin(const VulkanFrameBuffer& frameBuffer) const override;
2329
2331 UInt64 end() const override;
2332 };
2333
2337 class LITEFX_VULKAN_API VulkanSwapChain final : public SwapChain<IVulkanImage> {
2338 LITEFX_IMPLEMENTATION(VulkanSwapChainImpl);
2339 friend class VulkanImage;
2340 friend class VulkanDevice;
2341
2342 public:
2344
2345 private:
2354 explicit VulkanSwapChain(const VulkanDevice& device, Format surfaceFormat = Format::B8G8R8A8_SRGB, const Size2d& renderArea = { 800, 600 }, UInt32 buffers = 3, bool enableVsync = false); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
2355
2356 public:
2358 VulkanSwapChain(VulkanSwapChain&&) noexcept = delete;
2359
2362
2364 VulkanSwapChain& operator=(VulkanSwapChain&&) noexcept = delete;
2365
2367 VulkanSwapChain& operator=(const VulkanSwapChain&) = delete;
2368
2370 ~VulkanSwapChain() noexcept override;
2371
2372 // Vulkan Swap Chain interface.
2373 public:
2378 virtual const VkQueryPool& timestampQueryPool() const noexcept;
2379
2380 // SwapChain interface.
2381 public:
2383 const Array<SharedPtr<const TimingEvent>>& timingEvents() const override;
2384
2386 SharedPtr<const TimingEvent> timingEvent(UInt32 queryId) const override;
2387
2389 UInt64 readTimingEvent(SharedPtr<const TimingEvent> timingEvent) const override;
2390
2392 UInt32 resolveQueryId(SharedPtr<const TimingEvent> timingEvent) const override;
2393
2395 const IGraphicsDevice& device() const override;
2396
2398 Format surfaceFormat() const noexcept override;
2399
2401 UInt32 buffers() const noexcept override;
2402
2404 const Size2d& renderArea() const noexcept override;
2405
2407 bool verticalSynchronization() const noexcept override;
2408
2410 IVulkanImage* image(UInt32 backBuffer) const override;
2411
2413 const IVulkanImage& image() const noexcept override;
2414
2416 const Array<SharedPtr<IVulkanImage>>& images() const noexcept override;
2417
2419 void present(UInt64 fence) const override;
2420
2421 public:
2423 Enumerable<Format> getSurfaceFormats() const override;
2424
2426 void addTimingEvent(SharedPtr<const TimingEvent> timingEvent) override;
2427
2429 void reset(Format surfaceFormat, const Size2d& renderArea, UInt32 buffers, bool enableVsync = false) override;
2430
2432 [[nodiscard]] UInt32 swapBackBuffer() const override;
2433 };
2434
2442 LITEFX_IMPLEMENTATION(VulkanGraphicsFactoryImpl);
2443 friend class VulkanDevice;
2445
2446 public:
2448 using base_type::createBuffer;
2449 using base_type::createVertexBuffer;
2450 using base_type::createIndexBuffer;
2451 using base_type::createTexture;
2452 using base_type::createTextures;
2453 using base_type::createSampler;
2454 using base_type::createSamplers;
2455
2456 private:
2461 explicit VulkanGraphicsFactory(const VulkanDevice& device);
2462
2463 private:
2465 VulkanGraphicsFactory(VulkanGraphicsFactory&&) noexcept = delete;
2466
2469
2471 VulkanGraphicsFactory& operator=(VulkanGraphicsFactory&&) noexcept = delete;
2472
2474 VulkanGraphicsFactory& operator=(const VulkanGraphicsFactory&) = delete;
2475
2476 public:
2478 ~VulkanGraphicsFactory() noexcept override;
2479
2480 private:
2485 static inline SharedPtr<VulkanGraphicsFactory> create(const VulkanDevice& device) {
2487 }
2488
2489 public:
2491 SharedPtr<IVulkanBuffer> createBuffer(BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default) const override;
2492
2494 SharedPtr<IVulkanBuffer> createBuffer(const String& name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default) const override;
2495
2497 SharedPtr<IVulkanVertexBuffer> createVertexBuffer(const VulkanVertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default) const override;
2498
2500 SharedPtr<IVulkanVertexBuffer> createVertexBuffer(const String& name, const VulkanVertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default) const override;
2501
2503 SharedPtr<IVulkanIndexBuffer> createIndexBuffer(const VulkanIndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default) const override;
2504
2506 SharedPtr<IVulkanIndexBuffer> createIndexBuffer(const String& name, const VulkanIndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default) const override;
2507
2509 SharedPtr<IVulkanImage> createTexture(Format format, const Size3d& size, ImageDimensions dimension = ImageDimensions::DIM_2, UInt32 levels = 1, UInt32 layers = 1, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::Default) const override;
2510
2512 SharedPtr<IVulkanImage> createTexture(const String& name, Format format, const Size3d& size, ImageDimensions dimension = ImageDimensions::DIM_2, UInt32 levels = 1, UInt32 layers = 1, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::Default) const override;
2513
2515 Generator<SharedPtr<IVulkanImage>> createTextures(Format format, const Size3d& size, ImageDimensions dimension = ImageDimensions::DIM_2, UInt32 levels = 1, UInt32 layers = 1, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::Default) const override;
2516
2518 SharedPtr<IVulkanSampler> createSampler(FilterMode magFilter = FilterMode::Nearest, FilterMode minFilter = FilterMode::Nearest, BorderMode borderU = BorderMode::Repeat, BorderMode borderV = BorderMode::Repeat, BorderMode borderW = BorderMode::Repeat, MipMapMode mipMapMode = MipMapMode::Nearest, Float mipMapBias = 0.f, Float maxLod = std::numeric_limits<Float>::max(), Float minLod = 0.f, Float anisotropy = 0.f) const override;
2519
2521 SharedPtr<IVulkanSampler> createSampler(const String& name, FilterMode magFilter = FilterMode::Nearest, FilterMode minFilter = FilterMode::Nearest, BorderMode borderU = BorderMode::Repeat, BorderMode borderV = BorderMode::Repeat, BorderMode borderW = BorderMode::Repeat, MipMapMode mipMapMode = MipMapMode::Nearest, Float mipMapBias = 0.f, Float maxLod = std::numeric_limits<Float>::max(), Float minLod = 0.f, Float anisotropy = 0.f) const override;
2522
2524 Generator<SharedPtr<IVulkanSampler>> createSamplers(FilterMode magFilter = FilterMode::Nearest, FilterMode minFilter = FilterMode::Nearest, BorderMode borderU = BorderMode::Repeat, BorderMode borderV = BorderMode::Repeat, BorderMode borderW = BorderMode::Repeat, MipMapMode mipMapMode = MipMapMode::Nearest, Float mipMapBias = 0.f, Float maxLod = std::numeric_limits<Float>::max(), Float minLod = 0.f, Float anisotropy = 0.f) const override;
2525
2527 UniquePtr<VulkanBottomLevelAccelerationStructure> createBottomLevelAccelerationStructure(StringView name, AccelerationStructureFlags flags = AccelerationStructureFlags::None) const override;
2528
2530 UniquePtr<VulkanTopLevelAccelerationStructure> createTopLevelAccelerationStructure(StringView name, AccelerationStructureFlags flags = AccelerationStructureFlags::None) const override;
2531 };
2532
2536 class LITEFX_VULKAN_API VulkanDevice final : public GraphicsDevice<VulkanGraphicsFactory, VulkanSurface, VulkanGraphicsAdapter, VulkanSwapChain, VulkanQueue, VulkanRenderPass, VulkanRenderPipeline, VulkanComputePipeline, VulkanRayTracingPipeline, VulkanBarrier>, public Resource<VkDevice> {
2537 LITEFX_IMPLEMENTATION(VulkanDeviceImpl);
2539 friend class VulkanBackend;
2540
2541 private:
2550 explicit VulkanDevice(const VulkanBackend& backend, const VulkanGraphicsAdapter& adapter, UniquePtr<VulkanSurface>&& surface, GraphicsDeviceFeatures features = { }, Span<String> extensions = { });
2551
2552 private:
2554 VulkanDevice(VulkanDevice&&) noexcept = delete;
2555
2557 VulkanDevice(const VulkanDevice&) = delete;
2558
2560 VulkanDevice& operator=(VulkanDevice&&) noexcept = delete;
2561
2563 VulkanDevice& operator=(const VulkanDevice&) = delete;
2564
2565 public:
2567 ~VulkanDevice() noexcept override;
2568
2569 // Factory methods.
2570 public:
2580 static inline SharedPtr<VulkanDevice> create(const VulkanBackend& backend, const VulkanGraphicsAdapter& adapter, UniquePtr<VulkanSurface>&& surface, GraphicsDeviceFeatures features = { }, Span<String> extensions = { }) {
2581 return SharedObject::create<VulkanDevice>(backend, adapter, std::move(surface), features, extensions)->initialize(Format::B8G8R8A8_SRGB, { 800, 600 }, 3, false, features); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
2582 }
2583
2597 static inline SharedPtr<VulkanDevice> create(const VulkanBackend& backend, const VulkanGraphicsAdapter& adapter, UniquePtr<VulkanSurface>&& surface, Format format, const Size2d& renderArea, UInt32 backBuffers, bool enableVsync = false, GraphicsDeviceFeatures features = { }, Span<String> extensions = { }) {
2598 return SharedObject::create<VulkanDevice>(backend, adapter, std::move(surface), features, extensions)->initialize(format, renderArea, backBuffers, enableVsync, features);
2599 }
2600
2601 private:
2611 SharedPtr<VulkanDevice> initialize(Format format, const Size2d& renderArea, UInt32 backBuffers, bool enableVsync = false, GraphicsDeviceFeatures features = { });
2612
2616 void release() noexcept;
2617
2618 // Vulkan Device interface.
2619 private:
2630 void setDebugName(VkDebugReportObjectTypeEXT objectType, UInt64 objectHandle, StringView name) const noexcept;
2631
2632 public:
2637 Span<const String> enabledExtensions() const noexcept;
2638
2650 template <typename THandle>
2651 inline void setDebugName(THandle objectHandle, VkDebugReportObjectTypeEXT objectType, StringView name) const noexcept {
2652 this->setDebugName(objectType, Vk::handleAddress(objectHandle), name); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
2653 }
2654
2660 Enumerable<UInt32> queueFamilyIndices(QueueType type = QueueType::None) const;
2661
2662 // GraphicsDevice interface.
2663 public:
2665 DeviceState& state() const noexcept override;
2666
2668 const VulkanSwapChain& swapChain() const noexcept override;
2669
2671 VulkanSwapChain& swapChain() noexcept override;
2672
2674 const VulkanSurface& surface() const noexcept override;
2675
2677 const VulkanGraphicsAdapter& adapter() const noexcept override;
2678
2680 const VulkanGraphicsFactory& factory() const noexcept override;
2681
2683 const VulkanQueue& defaultQueue(QueueType type) const override;
2684
2686 SharedPtr<const VulkanQueue> createQueue(QueueType type, QueuePriority priority = QueuePriority::Normal) override;
2687
2689 [[nodiscard]] UniquePtr<VulkanBarrier> makeBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const override;
2690
2692 [[nodiscard]] SharedPtr<VulkanFrameBuffer> makeFrameBuffer(StringView name, const Size2d& renderArea) const override;
2693
2695 MultiSamplingLevel maximumMultiSamplingLevel(Format format) const noexcept override;
2696
2698 double ticksPerMillisecond() const noexcept override;
2699
2701 void wait() const override;
2702
2704 void computeAccelerationStructureSizes(const VulkanBottomLevelAccelerationStructure& blas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate = false) const override;
2705
2707 void computeAccelerationStructureSizes(const VulkanTopLevelAccelerationStructure& tlas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate = false) const override;
2708
2709#if defined(LITEFX_BUILD_DEFINE_BUILDERS)
2710 public:
2712 [[nodiscard]] VulkanRenderPassBuilder buildRenderPass(UInt32 commandBuffers = 1) const override;
2713
2715 [[nodiscard]] VulkanRenderPassBuilder buildRenderPass(const String& name, UInt32 commandBuffers = 1) const override;
2716
2718 //[[nodiscard]] VulkanRenderPipelineBuilder buildRenderPipeline(const String& name) const override;
2719
2721 [[nodiscard]] VulkanRenderPipelineBuilder buildRenderPipeline(const VulkanRenderPass& renderPass, const String& name) const override;
2722
2724 [[nodiscard]] VulkanComputePipelineBuilder buildComputePipeline(const String& name) const override;
2725
2727 [[nodiscard]] VulkanRayTracingPipelineBuilder buildRayTracingPipeline(ShaderRecordCollection&& shaderRecords) const override;
2728
2730 [[nodiscard]] VulkanRayTracingPipelineBuilder buildRayTracingPipeline(const String& name, ShaderRecordCollection&& shaderRecords) const override;
2731
2733 [[nodiscard]] VulkanPipelineLayoutBuilder buildPipelineLayout() const override;
2734
2736 [[nodiscard]] VulkanInputAssemblerBuilder buildInputAssembler() const override;
2737
2739 [[nodiscard]] VulkanRasterizerBuilder buildRasterizer() const override;
2740
2742 [[nodiscard]] VulkanShaderProgramBuilder buildShaderProgram() const override;
2743
2745 [[nodiscard]] VulkanBarrierBuilder buildBarrier() const override;
2746#endif // defined(LITEFX_BUILD_DEFINE_BUILDERS)
2747 };
2748
2752 class LITEFX_VULKAN_API VulkanBackend final : public RenderBackend<VulkanDevice>, public Resource<VkInstance> {
2753 LITEFX_IMPLEMENTATION(VulkanBackendImpl);
2754
2755 public:
2762 explicit VulkanBackend(const App& app, const Span<String> extensions = { }, const Span<String> validationLayers = { });
2763
2766
2769
2771 VulkanBackend& operator=(VulkanBackend&&) noexcept;
2772
2774 VulkanBackend& operator=(const VulkanBackend&) = delete;
2775
2777 ~VulkanBackend() noexcept override;
2778
2779 public:
2784 virtual Span<const String> getEnabledValidationLayers() const noexcept;
2785
2786#ifdef VK_USE_PLATFORM_WIN32_KHR
2792 UniquePtr<VulkanSurface> createSurface(const HWND& hwnd) const;
2793#else
2797 typedef std::function<VkSurfaceKHR(const VkInstance&)> surface_callback;
2798
2805 UniquePtr<VulkanSurface> createSurface(surface_callback predicate) const;
2806#endif // VK_USE_PLATFORM_WIN32_KHR
2807
2808 public:
2814 static bool validateInstanceExtensions(Span<const String> extensions);
2815
2821 static Enumerable<String> getAvailableInstanceExtensions();
2822
2828 static bool validateInstanceLayers(const Span<const String> validationLayers);
2829
2835 static Enumerable<String> getInstanceValidationLayers();
2836
2837 // IBackend interface.
2838 public:
2840 BackendType type() const noexcept override;
2841
2843 StringView name() const noexcept override;
2844
2845 protected:
2847 void activate() override;
2848
2850 void deactivate() override;
2851
2852 // RenderBackend interface.
2853 public:
2855 const Array<SharedPtr<const VulkanGraphicsAdapter>>& adapters() const override;
2856
2858 const VulkanGraphicsAdapter* findAdapter(const Optional<UInt64>& adapterId = std::nullopt) const noexcept override;
2859
2861 void registerDevice(const String& name, SharedPtr<VulkanDevice>&& device) override;
2862
2864 void releaseDevice(const String& name) override;
2865
2867 VulkanDevice* device(const String& name) noexcept override;
2868
2870 const VulkanDevice* device(const String& name) const noexcept override;
2871 };
2872
2873}
2874
2875#pragma warning(pop)
The base class for an application.
Definition app.hpp:402
Provides access to a resource managed by the class.
Definition containers.hpp:792
An exception that is thrown, if a provided argument is not valid.
Definition exceptions.hpp:60
Definition math.hpp:850
Definition math.hpp:819
Definition math.hpp:490
Definition math.hpp:534
Represents the base interface for a Vulkan acceleration structure implementation.
Definition vulkan.hpp:288
Represents the base interface for a Vulkan buffer implementation.
Definition vulkan.hpp:183
Represents a Vulkan sampled image or the base interface for a texture.
Definition vulkan.hpp:237
Represents a Vulkan index buffer.
Definition vulkan.hpp:217
Represents a Vulkan sampler.
Definition vulkan.hpp:270
Represents a Vulkan vertex buffer.
Definition vulkan.hpp:200
Defines a rendering backend that creates a Vulkan device.
Definition vulkan.hpp:2752
std::function< VkSurfaceKHR(const VkInstance &)> surface_callback
A callback that creates a surface from a Vulkan instance.
Definition vulkan.hpp:2797
VulkanBackend(VulkanBackend &&) noexcept
Implements a Vulkan resource barrier.
Definition vulkan.hpp:488
VulkanBarrier(VulkanBarrier &&) noexcept
Implements a Vulkan bottom-level acceleration structure (BLAS).
Definition vulkan.hpp:304
VulkanBottomLevelAccelerationStructure(VulkanBottomLevelAccelerationStructure &&) noexcept
Records commands for a VulkanQueue
Definition vulkan.hpp:1397
Implements a Vulkan ComputePipeline.
Definition vulkan.hpp:1861
VulkanComputePipeline(VulkanComputePipeline &&) noexcept
Implements a Vulkan IDescriptorLayout
Definition vulkan.hpp:775
VulkanDescriptorLayout(VulkanDescriptorLayout &&) noexcept
Implements a Vulkan DescriptorSet.
Definition vulkan.hpp:716
VulkanDescriptorSet(VulkanDescriptorSet &&) noexcept=delete
Implements a Vulkan DescriptorSetLayout.
Definition vulkan.hpp:858
static auto create(const VulkanDescriptorSetLayout &other)
Creates a copy of a Vulkan descriptor set layout.
Definition vulkan.hpp:919
Implements a Vulkan graphics device.
Definition vulkan.hpp:2536
static SharedPtr< VulkanDevice > create(const VulkanBackend &backend, const VulkanGraphicsAdapter &adapter, UniquePtr< VulkanSurface > &&surface, Format format, const Size2d &renderArea, UInt32 backBuffers, bool enableVsync=false, GraphicsDeviceFeatures features={ }, Span< String > extensions={ })
Initializes the device instance.
Definition vulkan.hpp:2597
Implements a Vulkan frame buffer.
Definition vulkan.hpp:1998
const IVulkanImage & operator[](StringView renderTargetName) const override
Resolves a render target name and returns the image mapped to it.The image mapped to the render targe...
Definition vulkan.hpp:2111
const IVulkanImage & operator[](const RenderTarget &renderTarget) const override
Resolves a render target and returns the image mapped to it.The image mapped to the render target.
Definition vulkan.hpp:2103
const IVulkanImage & image(StringView renderTargetName) const override
Resolves a render target name and returns the image mapped to it.The image mapped to the render targe...
Definition vulkan.hpp:2116
Represents a Vulkan IGraphicsAdapter.
Definition vulkan_api.hpp:232
A graphics factory that produces objects for a VulkanDevice.
Definition vulkan.hpp:2441
Implements a Vulkan IImage.
Definition image.h:16
Implements a Vulkan index buffer layout.
Definition vulkan.hpp:112
static auto create(const VulkanIndexBufferLayout &other)
Creates a copy of an index buffer layout.
Definition vulkan.hpp:155
Implements the Vulkan input assembler state.
Definition vulkan.hpp:1192
static auto create(const VulkanInputAssembler &other)
Creates a new Vulkan input assembler state as a copy from another one.
Definition vulkan.hpp:1245
Implements a Vulkan PipelineLayout.
Definition vulkan.hpp:1114
Defines the base class for Vulkan pipeline state objects.
Definition vulkan.hpp:1366
VulkanPipelineState(VulkanPipelineState &&) noexcept=default
Implements the Vulkan PushConstantsLayout.
Definition vulkan.hpp:1064
VulkanPushConstantsLayout(VulkanPushConstantsLayout &&) noexcept
Implements the Vulkan IPushConstantsRange.
Definition vulkan.hpp:1012
VulkanPushConstantsRange(VulkanPushConstantsRange &&) noexcept
Implements a Vulkan command queue.
Definition vulkan.hpp:1650
Implements a Vulkan IRasterizer.
Definition vulkan.hpp:1276
static auto create(const VulkanRasterizer &other)
Creates a new Vulkan rasterizer state by copying an existing one.
Definition vulkan.hpp:1332
Implements a Vulkan RayTracingPipeline.
Definition vulkan.hpp:1919
VulkanRayTracingPipeline(VulkanRayTracingPipeline &&) noexcept
Implements a Vulkan render pass.
Definition vulkan.hpp:2137
static SharedPtr< VulkanRenderPass > create(const VulkanDevice &device, const String &name, Span< RenderTarget > renderTargets, Span< RenderPassDependency > inputAttachments={ }, Optional< DescriptorBindingPoint > inputAttachmentSamplerBinding=std::nullopt, UInt32 secondaryCommandBuffers=1u)
Creates and initializes a new Vulkan render pass instance that executes on the default graphics queue...
Definition vulkan.hpp:2231
static SharedPtr< VulkanRenderPass > create(const VulkanDevice &device, const String &name, const VulkanQueue &queue, Span< RenderTarget > renderTargets, Span< RenderPassDependency > inputAttachments={ }, Optional< DescriptorBindingPoint > inputAttachmentSamplerBinding=std::nullopt, UInt32 secondaryCommandBuffers=1u)
Creates and initializes a new Vulkan render pass instance.
Definition vulkan.hpp:2260
static SharedPtr< VulkanRenderPass > create(const VulkanDevice &device, const VulkanQueue &queue, Span< RenderTarget > renderTargets, Span< RenderPassDependency > inputAttachments={ }, Optional< DescriptorBindingPoint > inputAttachmentSamplerBinding=std::nullopt, UInt32 secondaryCommandBuffers=1u)
Creates and initializes a new Vulkan render pass instance.
Definition vulkan.hpp:2245
Implements a Vulkan RenderPipeline.
Definition vulkan.hpp:1781
VulkanRenderPipeline(VulkanRenderPipeline &&) noexcept=delete
Implements a Vulkan IShaderModule.
Definition vulkan.hpp:568
VulkanShaderModule(VulkanShaderModule &&) noexcept
Implements a Vulkan ShaderProgram.
Definition vulkan.hpp:642
VulkanShaderProgram(VulkanShaderProgram &&) noexcept=delete
Represents a Vulkan ISurface.
Definition vulkan_api.hpp:334
Implements a Vulkan swap chain.
Definition vulkan.hpp:2337
VulkanSwapChain(VulkanSwapChain &&) noexcept=delete
Implements a Vulkan top-level acceleration structure (TLAS).
Definition vulkan.hpp:399
VulkanTopLevelAccelerationStructure(VulkanTopLevelAccelerationStructure &&) noexcept
Implements a Vulkan vertex buffer layout.
Definition vulkan.hpp:21
static auto create(size_t vertexSize, const Enumerable< BufferAttribute > &attributes, UInt32 binding=0)
Creates a new vertex buffer layout.
Definition vulkan.hpp:77
static auto create(const VulkanVertexBufferLayout &other)
Creates a copy of a vertex buffer layout.
Definition vulkan.hpp:86
A barrier used for GPU resource synchronization.
Definition rendering.hpp:17
Represents a command buffer, that buffers commands that should be submitted to a CommandQueue.
Definition rendering.hpp:597
Represents a command queue.
Definition rendering.hpp:1090
Represents a compute Pipeline.
Definition rendering.hpp:1001
Stores the depth/stencil state of a see IRasterizer.
Definition rendering_api.hpp:3143
Defines a set of descriptors.
Definition rendering.hpp:150
Describes the layout of a descriptor set.
Definition rendering.hpp:215
A class that can be used to manage the state of a IGraphicsDevice.
Definition rendering_api.hpp:2312
Stores the images used by a RenderPass to either read from using input attachments or write to using ...
Definition rendering.hpp:1057
Represents the graphics device that a rendering back-end is doing work on.
Definition rendering.hpp:1431
Describes a factory that creates objects for a GraphicsDevice.
Definition rendering.hpp:1254
Base interface for a ray tracing acceleration structure.
Definition rendering_api.hpp:4449
void update(const ICommandBuffer &commandBuffer, const SharedPtr< const IBuffer > &scratchBuffer=nullptr, const SharedPtr< const IBuffer > &buffer=nullptr, UInt64 offset=0, UInt64 maxSize=0)
Performs an update on the acceleration structure.
Definition rendering_api.hpp:4530
void build(const ICommandBuffer &commandBuffer, const SharedPtr< const IBuffer > &scratchBuffer=nullptr, const SharedPtr< const IBuffer > &buffer=nullptr, UInt64 offset=0, UInt64 maxSize=0)
Performs a complete build of the acceleration structure.
Definition rendering_api.hpp:4494
A structure that holds a singular entity of geometry for hardware ray-tracing.
Definition rendering_api.hpp:4588
void copy(const ICommandBuffer &commandBuffer, IBottomLevelAccelerationStructure &destination, bool compress=false, const SharedPtr< const IBuffer > &buffer=nullptr, UInt64 offset=0, bool copyBuildInfo=true) const
Copies the acceleration structure into the acceleration structure provided by destination .
Definition rendering_api.hpp:4807
Base interface for buffer objects.
Definition rendering_api.hpp:4186
The interface for a command buffer.
Definition rendering_api.hpp:6517
The interface for a command queue.
Definition rendering_api.hpp:8481
Describes a the layout of a single descriptor within a DescriptorSet.
Definition rendering_api.hpp:3993
The interface for a graphics device that.
Definition rendering_api.hpp:9164
Describes a generic image.
Definition rendering_api.hpp:4208
Describes a index buffer layout.
Definition rendering_api.hpp:3952
The interface for a pipeline layout.
Definition rendering_api.hpp:6385
Describes a range within a IPushConstantsLayout.
Definition rendering_api.hpp:5645
Describes a texture sampler.
Definition rendering_api.hpp:4324
The interface of a scissor.
Definition rendering_api.hpp:3562
Represents a single shader module, i.e. a part of a IShaderProgram.
Definition rendering_api.hpp:2755
A structure that stores the instance data for a IBottomLevelAccelerationStructure.
Definition rendering_api.hpp:4870
void copy(const ICommandBuffer &commandBuffer, ITopLevelAccelerationStructure &destination, bool compress=false, const SharedPtr< const IBuffer > &buffer=nullptr, UInt64 offset=0, bool copyBuildInfo=true) const
Copies the acceleration structure into the acceleration structure provided by destination .
Definition rendering_api.hpp:5016
Describes a vertex buffer layout.
Definition rendering_api.hpp:3929
Interface for a viewport.
Definition rendering_api.hpp:3444
Describes an index buffer.
Definition rendering.hpp:479
Represents a the input assembler state of a RenderPipeline.
Definition rendering.hpp:506
Represents a pipeline state.
Definition rendering.hpp:547
Represents a the layout of a RenderPipeline, ComputePipeline or RayTracingPipeline.
Definition rendering.hpp:418
Describes the layout of the pipelines push constant ranges.
Definition rendering.hpp:355
Implements a IRasterizer.
Definition rendering_api.hpp:3371
Represents a ray-tracing Pipeline.
Definition rendering.hpp:1020
Defines a back-end, that provides a device instance for a certain surface and graphics adapter.
Definition rendering.hpp:1642
Represents a mapping between a set of RenderTarget instances and the input attachments of a IRenderPa...
Definition rendering_api.hpp:3076
Represents a render pass.
Definition rendering.hpp:1150
Represents a graphics Pipeline.
Definition rendering.hpp:962
Implements a render target.
Definition rendering_api.hpp:2976
Represents a shader program, consisting of multiple IShaderModules.
Definition rendering.hpp:386
Stores a set of IShaderRecords in that later form a shader binding table used for ray-tracing.
Definition rendering_api.hpp:6007
Base class for a resource that can be identified by a name string within a DeviceState.
Definition rendering_api.hpp:2265
Represents a swap chain, i.e. a chain of multiple IImage instances, that can be presented to a ISurfa...
Definition rendering.hpp:1210
An event that is used to measure timestamps in a command queue.
Definition rendering_api.hpp:3726
Describes a vertex buffer.
Definition rendering.hpp:455
Implements the IResource interface.
Definition containers.hpp:823
static auto create(TArgs &&... args) -> SharedPtr< T >
Generic factory method used to create instances of the shared object.
Definition containers.hpp:1114
Concept that can be used to refer to backend implementations.
Definition app.hpp:80
Definition math.hpp:30
uint64_t UInt64
A type for an unsigned 64 bit integer.
Definition math.hpp:66
float_t Float
A type for a floating point value with single precision.
Definition math.hpp:71
uint32_t UInt32
A type for an unsigned 32 bit integer.
Definition math.hpp:56
int32_t Int32
A type for a signed 32 bit integer.
Definition math.hpp:51
Definition dx12.hpp:11
Definition dx12.hpp:11
BorderMode
Describes how to treat texture coordinates that are outside the domain [0..1].
Definition rendering_api.hpp:1184
CullOrder
Describes the order or vertex winding, that is used to determine, whether a polygon is facing towards...
Definition rendering_api.hpp:1018
ImageLayout
Specifies the layout of an IImage resource.
Definition rendering_api.hpp:1686
MipMapMode
Describes the filter operation between two mip-map levels.
Definition rendering_api.hpp:1169
CullMode
Describes which faces are culled by the Rasterizer stage.
Definition rendering_api.hpp:991
ShaderStage
Describes the valid shader stages of a graphics pipeline.
Definition rendering_api.hpp:799
IndexType
Describes the element type of an index buffer.
Definition rendering_api.hpp:750
PrimitiveTopology
Describes the topology of a mesh primitive.
Definition rendering_api.hpp:765
@ TriangleList
A list of triangles, where each triplet of vertices refers to a whole triangle.
ShaderBindingGroup
Describes a group or combination of groups of a shader binding table.
Definition rendering_api.hpp:939
@ All
Refers to a combination of all possible groups that can be stored in a shader binding table.
PolygonMode
Describes the draw mode for polygons.
Definition rendering_api.hpp:970
BufferType
Describes the type of a IBuffer.
Definition rendering_api.hpp:540
ResourceUsage
Describes the intended usage for a resource.
Definition rendering_api.hpp:690
ImageDimensions
Describes the dimensions of a image resource, i.e. the dimensions that are required to access a texel...
Definition rendering_api.hpp:1086
DescriptorType
Describes the type of a IDescriptor.
Definition rendering_api.hpp:436
QueuePriority
Specifies the priority with which a queue is scheduled on the GPU.
Definition rendering_api.hpp:159
@ Normal
The default queue priority.
QueueType
Represents the type of a CommandQueue.
Definition rendering_api.hpp:113
ResourceHeap
Defines where a resource (buffer or image) memory is located and from where it can be accessed.
Definition rendering_api.hpp:649
@ Resource
Creates a resource that can be read by the GPU.
AccelerationStructureFlags
Controls how an acceleration structure should be built.
Definition rendering_api.hpp:1816
FilterMode
Describes the filter operation when accessing a pixel from a texture coordinate.
Definition rendering_api.hpp:1152
PipelineStage
Defines pipeline stages as points where synchronization may occur.
Definition rendering_api.hpp:1373
ResourceAccess
Defines how a IBuffer or IImage resource is accessed.
Definition rendering_api.hpp:1537
Format
Describes a texel format.
Definition rendering_api.hpp:182
MultiSamplingLevel
Describes the number of samples with which a IImage is sampled.
Definition rendering_api.hpp:1111
std::generator< T, TVal > Generator
Describes an intermediate container for elements of type T .
Definition containers.hpp:206
std::vector< T > Array
Represents a dynamic array.
Definition containers.hpp:73
std::optional< T > Optional
Represents an optional value.
Definition containers.hpp:94
std::shared_ptr< T > SharedPtr
Represents a shared pointer, that expresses non-exclusive ownership.
Definition containers.hpp:109
std::unique_ptr< T, TDeleter > UniquePtr
Represents a unique pointer, that expresses exclusive ownership.
Definition containers.hpp:102
std::string String
Definition string.hpp:24
std::string_view StringView
Definition string.hpp:26
BackendType
Definition app_api.hpp:35
std::span< T > Span
Represents a view of an array.
Definition containers.hpp:87
An input range over another range, where the returned values of type T are covariants of the values ...
Definition containers.hpp:529
An algebraic vector type.
Definition vector.hpp:23
Describes a resource binding to a descriptor or descriptor set.
Definition rendering_api.hpp:5334
Describes a single descriptor binding point within a IShaderModule.
Definition rendering_api.hpp:2735
Describes optional features that can be supported by a device.
Definition rendering_api.hpp:9138
Stores a buffer that contains axis-aligned bounding boxes.
Definition rendering_api.hpp:4670
Represents a triangle mesh.
Definition rendering_api.hpp:4593
Represents an instance of an IBottomLevelAccelerationStructure.
Definition rendering_api.hpp:4877
Describes the offsets and sizes of a shader group within a shader binding table buffer.
Definition rendering_api.hpp:3646
An allocator used to allocate the shared object.
Definition containers.hpp:1098