LiteFX 0.5.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:
33 explicit VulkanVertexBufferLayout(size_t vertexSize, UInt32 binding = 0, VertexBufferInputRate inputRate = VertexBufferInputRate::Vertex);
34
42 explicit VulkanVertexBufferLayout(size_t vertexSize, const Enumerable<BufferAttribute>& attributes, UInt32 binding = 0, VertexBufferInputRate inputRate = VertexBufferInputRate::Vertex);
43
44 private:
47
50
52 VulkanVertexBufferLayout& operator=(VulkanVertexBufferLayout&&) noexcept = delete;
53
55 VulkanVertexBufferLayout& operator=(const VulkanVertexBufferLayout&) = delete;
56
57 public:
59 ~VulkanVertexBufferLayout() noexcept override;
60
61 public:
69 static inline auto create(size_t vertexSize, UInt32 binding = 0, VertexBufferInputRate inputRate = VertexBufferInputRate::Vertex) {
70 return SharedObject::create<VulkanVertexBufferLayout>(vertexSize, binding, inputRate);
71 }
72
81 static inline auto create(size_t vertexSize, const Enumerable<BufferAttribute>& attributes, UInt32 binding = 0, VertexBufferInputRate inputRate = VertexBufferInputRate::Vertex) {
82 return SharedObject::create<VulkanVertexBufferLayout>(vertexSize, attributes, binding, inputRate);
83 }
84
90 static inline auto create(const VulkanVertexBufferLayout& other) {
92 }
93
94 // IVertexBufferLayout interface.
95 public:
97 const Array<BufferAttribute>& attributes() const override;
98
100 VertexBufferInputRate inputRate() const noexcept override;
101
102 // IBufferLayout interface.
103 public:
105 size_t elementSize() const noexcept override;
106
108 UInt32 binding() const noexcept override;
109
111 BufferType type() const noexcept override;
112 };
113
119 class LITEFX_VULKAN_API VulkanIndexBufferLayout final : public IIndexBufferLayout {
120 LITEFX_IMPLEMENTATION(VulkanIndexBufferLayoutImpl);
122
123 private:
128 explicit VulkanIndexBufferLayout(IndexType type);
129
130 private:
133
136
138 VulkanIndexBufferLayout& operator=(VulkanIndexBufferLayout&&) noexcept = delete;
139
141 VulkanIndexBufferLayout& operator=(const VulkanIndexBufferLayout&) = delete;
142
143 public:
145 ~VulkanIndexBufferLayout() noexcept override;
146
147 public:
153 static inline auto create(IndexType type) {
155 }
156
162 static inline auto create(const VulkanIndexBufferLayout& other) {
164 }
165
166 // IIndexBufferLayout interface.
167 public:
169 IndexType indexType() const noexcept override;
170
171 // IBufferLayout interface.
172 public:
174 size_t elementSize() const noexcept override;
175
177 UInt32 binding() const noexcept override;
178
180 BufferType type() const noexcept override;
181 };
182
190 class LITEFX_VULKAN_API IVulkanBuffer : public virtual IBuffer, public virtual IResource<VkBuffer> {
191 protected:
192 IVulkanBuffer() noexcept = default;
193 IVulkanBuffer(IVulkanBuffer&&) noexcept = default;
194 IVulkanBuffer(const IVulkanBuffer&) = delete;
195 IVulkanBuffer& operator=(IVulkanBuffer&&) noexcept = default;
196 IVulkanBuffer& operator=(const IVulkanBuffer&) = delete;
197
198 public:
199 ~IVulkanBuffer() noexcept override = default;
200 };
201
207 class LITEFX_VULKAN_API IVulkanVertexBuffer : public virtual VertexBuffer<VulkanVertexBufferLayout>, public virtual IVulkanBuffer {
208 protected:
209 IVulkanVertexBuffer() noexcept = default;
212 IVulkanVertexBuffer& operator=(IVulkanVertexBuffer&&) noexcept = default;
213 IVulkanVertexBuffer& operator=(const IVulkanVertexBuffer&) = delete;
214
215 public:
216 ~IVulkanVertexBuffer() noexcept override = default;
217 };
218
224 class LITEFX_VULKAN_API IVulkanIndexBuffer : public virtual IndexBuffer<VulkanIndexBufferLayout>, public virtual IVulkanBuffer {
225 protected:
226 IVulkanIndexBuffer() noexcept = default;
229 IVulkanIndexBuffer& operator=(IVulkanIndexBuffer&&) noexcept = default;
230 IVulkanIndexBuffer& operator=(const IVulkanIndexBuffer&) = delete;
231
232 public:
233 ~IVulkanIndexBuffer() noexcept override = default;
234 };
235
244 class LITEFX_VULKAN_API IVulkanImage : public virtual IImage, public virtual IResource<VkImage> {
245 protected:
246 IVulkanImage() noexcept = default;
247 IVulkanImage(IVulkanImage&&) noexcept = default;
248 IVulkanImage(const IVulkanImage&) = delete;
249 IVulkanImage& operator=(IVulkanImage&&) noexcept = default;
250 IVulkanImage& operator=(const IVulkanImage&) = delete;
251
252 public:
253 ~IVulkanImage() noexcept override = default;
254
255 public:
260 virtual VkImageAspectFlags aspectMask() const noexcept = 0;
261
267 virtual VkImageAspectFlags aspectMask(UInt32 plane) const = 0;
268 };
269
277 class LITEFX_VULKAN_API IVulkanSampler : public virtual ISampler, public virtual IResource<VkSampler> {
278 protected:
279 IVulkanSampler() noexcept = default;
280 IVulkanSampler(IVulkanSampler&&) noexcept = default;
282 IVulkanSampler& operator=(IVulkanSampler&&) noexcept = default;
283 IVulkanSampler& operator=(const IVulkanSampler&) = delete;
284
285 public:
286 ~IVulkanSampler() noexcept override = default;
287 };
288
295 class LITEFX_VULKAN_API IVulkanAccelerationStructure : public virtual IAccelerationStructure, public virtual IResource<VkAccelerationStructureKHR> {
296 protected:
297 IVulkanAccelerationStructure() noexcept = default;
302
303 public:
304 ~IVulkanAccelerationStructure() noexcept override = default;
305 };
306
311 class LITEFX_VULKAN_API VulkanBottomLevelAccelerationStructure final : public IBottomLevelAccelerationStructure, public virtual IVulkanAccelerationStructure, public virtual StateResource, public virtual Resource<VkAccelerationStructureKHR> {
312 LITEFX_IMPLEMENTATION(VulkanBottomLevelAccelerationStructureImpl);
313 friend class VulkanDevice;
315
319
320 public:
328 explicit VulkanBottomLevelAccelerationStructure(AccelerationStructureFlags flags = AccelerationStructureFlags::None, StringView name = "");
329
332
335
338
341
343 ~VulkanBottomLevelAccelerationStructure() noexcept override;
344
345 // IAccelerationStructure interface.
346 public:
348 AccelerationStructureFlags flags() const noexcept override;
349
351 SharedPtr<const IVulkanBuffer> buffer() const noexcept;
352
354 void build(const VulkanCommandBuffer& commandBuffer, const SharedPtr<const IVulkanBuffer>& scratchBuffer = nullptr, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
355
357 void update(const VulkanCommandBuffer& commandBuffer, const SharedPtr<const IVulkanBuffer>& scratchBuffer = nullptr, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
358
360 void copy(const VulkanCommandBuffer& commandBuffer, VulkanBottomLevelAccelerationStructure& destination, bool compress = false, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, bool copyBuildInfo = true) const;
361
363 UInt64 offset() const noexcept override;
364
366 UInt64 size() const noexcept override;
367
368 // IBottomLevelAccelerationStructure interface.
369 public:
371 const Array<TriangleMesh>& triangleMeshes() const noexcept override;
372
374 void addTriangleMesh(const TriangleMesh& mesh) override;
375
377 const Array<BoundingBoxes>& boundingBoxes() const noexcept override;
378
380 void addBoundingBox(const BoundingBoxes& aabb) override;
381
383 void clear() noexcept override;
384
386 bool remove(const TriangleMesh& mesh) noexcept override;
387
389 bool remove(const BoundingBoxes& aabb) noexcept override;
390
391 private:
392 Array<std::pair<UInt32, VkAccelerationStructureGeometryKHR>> buildInfo() const;
393 void updateState(const VulkanDevice* device, VkAccelerationStructureKHR handle) noexcept;
394
395 private:
396 SharedPtr<const IBuffer> getBuffer() const noexcept override;
397 void doBuild(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
398 void doUpdate(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
399 void doCopy(const ICommandBuffer& commandBuffer, IBottomLevelAccelerationStructure& destination, bool compress, const SharedPtr<const IBuffer>& buffer, UInt64 offset, bool copyBuildInfo) const override;
400 };
401
406 class LITEFX_VULKAN_API VulkanTopLevelAccelerationStructure final : public ITopLevelAccelerationStructure, public virtual IVulkanAccelerationStructure, public virtual StateResource, public virtual Resource<VkAccelerationStructureKHR> {
407 LITEFX_IMPLEMENTATION(VulkanTopLevelAccelerationStructureImpl);
408 friend class VulkanDevice;
410
414
415 public:
423 explicit VulkanTopLevelAccelerationStructure(AccelerationStructureFlags flags = AccelerationStructureFlags::None, StringView name = "");
424
427
430
433
436
438 ~VulkanTopLevelAccelerationStructure() noexcept override;
439
440 // IAccelerationStructure interface.
441 public:
443 AccelerationStructureFlags flags() const noexcept override;
444
446 SharedPtr<const IVulkanBuffer> buffer() const noexcept;
447
449 void build(const VulkanCommandBuffer& commandBuffer, const SharedPtr<const IVulkanBuffer>& scratchBuffer = nullptr, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
450
452 void update(const VulkanCommandBuffer& commandBuffer, const SharedPtr<const IVulkanBuffer>& scratchBuffer = nullptr, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
453
455 void copy(const VulkanCommandBuffer& commandBuffer, VulkanTopLevelAccelerationStructure& destination, bool compress = false, const SharedPtr<const IVulkanBuffer>& buffer = nullptr, UInt64 offset = 0, bool copyBuildInfo = true) const;
456
458 UInt64 offset() const noexcept override;
459
461 UInt64 size() const noexcept override;
462
463 // ITopLevelAccelerationStructure interface.
464 public:
466 const Array<Instance>& instances() const noexcept override;
467
469 void addInstance(const Instance& instance) override;
470
472 void clear() noexcept override;
473
475 bool remove(const Instance& mesh) noexcept override;
476
477 private:
478 Array<VkAccelerationStructureInstanceKHR> buildInfo() const;
479 void updateState(const VulkanDevice* device, VkAccelerationStructureKHR handle) noexcept;
480
481 private:
482 SharedPtr<const IBuffer> getBuffer() const noexcept override;
483 void doBuild(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
484 void doUpdate(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
485 void doCopy(const ICommandBuffer& commandBuffer, ITopLevelAccelerationStructure& destination, bool compress, const SharedPtr<const IBuffer>& buffer, UInt64 offset, bool copyBuildInfo) const override;
486 };
487
495 class LITEFX_VULKAN_API VulkanBarrier final : public Barrier<IVulkanBuffer, IVulkanImage> {
496 LITEFX_IMPLEMENTATION(VulkanBarrierImpl);
497 LITEFX_BUILDER(VulkanBarrierBuilder);
498
499 public:
501 using base_type::transition;
502
503 public:
509 explicit VulkanBarrier(PipelineStage syncBefore, PipelineStage syncAfter) noexcept;
510
513
516
518 VulkanBarrier& operator=(VulkanBarrier&&) noexcept;
519
521 VulkanBarrier& operator=(const VulkanBarrier&);
522
524 ~VulkanBarrier() noexcept override;
525
526 private:
527 explicit VulkanBarrier() noexcept;
528 PipelineStage& syncBefore() noexcept;
529 PipelineStage& syncAfter() noexcept;
530
531 // Barrier interface.
532 public:
534 PipelineStage syncBefore() const noexcept override;
535
537 PipelineStage syncAfter() const noexcept override;
538
540 void wait(ResourceAccess accessBefore, ResourceAccess accessAfter) override;
541
543 void transition(const IVulkanBuffer& buffer, ResourceAccess accessBefore, ResourceAccess accessAfter) override;
544
546 void transition(const IVulkanBuffer& buffer, UInt32 element, ResourceAccess accessBefore, ResourceAccess accessAfter) override;
547
549 void transition(const IVulkanImage& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) override;
550
552 void transition(const IVulkanImage& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) override;
553
555 void transition(const IVulkanImage& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) override;
556
558 void transition(const IVulkanImage& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) override;
559
560 public:
566 void execute(const VulkanCommandBuffer& commandBuffer) const;
567 };
568
575 class LITEFX_VULKAN_API VulkanShaderModule final : public IShaderModule, public Resource<VkShaderModule> {
576 LITEFX_IMPLEMENTATION(VulkanShaderModuleImpl);
577
578 public:
587 explicit VulkanShaderModule(const VulkanDevice& device, ShaderStage type, const String& fileName, const String& entryPoint = "main", const Optional<DescriptorBindingPoint>& shaderLocalDescriptor = std::nullopt);
588
598 explicit VulkanShaderModule(const VulkanDevice& device, ShaderStage type, std::istream& stream, const String& name, const String& entryPoint = "main", const Optional<DescriptorBindingPoint>& shaderLocalDescriptor = std::nullopt);
599
602
605
608
610 VulkanShaderModule& operator=(const VulkanShaderModule&) = delete;
611
613 ~VulkanShaderModule() noexcept override;
614
615 // ShaderModule interface.
616 public:
618 const String& fileName() const noexcept override;
619
621 const String& entryPoint() const noexcept override;
622
624 ShaderStage type() const noexcept override;
625
627 const Optional<DescriptorBindingPoint>& shaderLocalDescriptor() const noexcept override;
628
629 public:
634 virtual const String& bytecode() const noexcept;
635
640 virtual VkPipelineShaderStageCreateInfo shaderStageDefinition() const;
641 };
642
649 class LITEFX_VULKAN_API VulkanShaderProgram final : public ShaderProgram<VulkanShaderModule> {
650 LITEFX_IMPLEMENTATION(VulkanShaderProgramImpl);
651 LITEFX_BUILDER(VulkanShaderProgramBuilder);
653
654 private:
661
666 explicit VulkanShaderProgram(const VulkanDevice& device);
667
668 public:
671
674
676 VulkanShaderProgram& operator=(VulkanShaderProgram&&) noexcept = delete;
677
679 VulkanShaderProgram& operator=(const VulkanShaderProgram&) = delete;
680
681 public:
683 ~VulkanShaderProgram() noexcept override;
684
685 // Factory method.
686 public:
693 static inline auto create(const VulkanDevice& device, Enumerable<UniquePtr<VulkanShaderModule>>&& modules) {
694 return SharedObject::create<VulkanShaderProgram>(device, std::move(modules));
695 }
696
697 private:
702 static inline auto create(const VulkanDevice& device) {
704 }
705
706 public:
708 const Array<UniquePtr<const VulkanShaderModule>>& modules() const noexcept override;
709
711 virtual SharedPtr<VulkanPipelineLayout> reflectPipelineLayout(Enumerable<PipelineBindingHint> hints = {}) const;
712
713 private:
714 SharedPtr<IPipelineLayout> parsePipelineLayout(Enumerable<PipelineBindingHint> hints) const override {
715 return std::static_pointer_cast<IPipelineLayout>(this->reflectPipelineLayout(hints));
716 }
717 };
718
723 class LITEFX_VULKAN_API VulkanDescriptorSet final : public DescriptorSet<IVulkanBuffer, IVulkanImage, IVulkanSampler, IVulkanAccelerationStructure> {
724 LITEFX_IMPLEMENTATION(VulkanDescriptorSetImpl);
726
727 public:
729 using base_type::update;
730
731 private:
737 explicit VulkanDescriptorSet(const VulkanDescriptorSetLayout& layout, Array<Byte>&& buffer);
738
739 public:
745 explicit VulkanDescriptorSet(const VulkanDescriptorSetLayout& layout, UInt32 unboundedArraySize = std::numeric_limits<UInt32>::max());
746
749
752
754 VulkanDescriptorSet& operator=(VulkanDescriptorSet&&) noexcept = delete;
755
757 VulkanDescriptorSet& operator=(const VulkanDescriptorSet&) = delete;
758
760 ~VulkanDescriptorSet() noexcept override;
761
762 public:
767 virtual const VulkanDescriptorSetLayout& layout() const noexcept;
768
769 private:
774 Array<Byte>&& releaseBuffer() const noexcept;
775
776 public:
781 Span<const Byte> descriptorBuffer() const noexcept;
782
783 public:
785 VirtualAllocator::Allocation globalHeapAllocation(DescriptorHeapType heapType) const noexcept override;
786
788 UInt32 bindToHeap(DescriptorType bindingType, UInt32 descriptor, const IVulkanBuffer& buffer, UInt32 bufferElement = 0, UInt32 elements = 0, Format texelFormat = Format::None) const override;
789
791 UInt32 bindToHeap(DescriptorType bindingType, UInt32 descriptor, const IVulkanImage& image, UInt32 firstLevel = 0, UInt32 levels = 0, UInt32 firstLayer = 0, UInt32 layers = 0) const override;
792
794 UInt32 bindToHeap(UInt32 descriptor, const IVulkanSampler& sampler) const override;
795
797 void update(UInt32 binding, const IVulkanBuffer& buffer, UInt32 bufferElement = 0, UInt32 elements = 0, UInt32 firstDescriptor = 0, Format texelFormat = Format::None) const override;
798
800 void update(UInt32 binding, const IVulkanImage& texture, UInt32 descriptor = 0, UInt32 firstLevel = 0, UInt32 levels = 0, UInt32 firstLayer = 0, UInt32 layers = 0) const override;
801
803 void update(UInt32 binding, const IVulkanSampler& sampler, UInt32 descriptor = 0) const override;
804
806 void update(UInt32 binding, const IVulkanAccelerationStructure& accelerationStructure, UInt32 descriptor = 0) const override;
807 };
808
817 class LITEFX_VULKAN_API VulkanDescriptorLayout final : public IDescriptorLayout {
818 LITEFX_IMPLEMENTATION(VulkanDescriptorLayoutImpl);
819
820 public:
830 VulkanDescriptorLayout(DescriptorType type, UInt32 binding, size_t elementSize, UInt32 descriptors = 1, bool unbounded = false);
831
837 VulkanDescriptorLayout(const IVulkanSampler& staticSampler, UInt32 binding);
838
844 VulkanDescriptorLayout(UInt32 binding, UInt32 inputAttachmentIndex);
845
848
851
854
857
859 ~VulkanDescriptorLayout() noexcept override;
860
861 // IDescriptorLayout interface.
862 public:
864 DescriptorType descriptorType() const noexcept override;
865
867 UInt32 descriptors() const noexcept override;
868
870 bool unbounded() const noexcept override;
871
873 const IVulkanSampler* staticSampler() const noexcept override;
874
875 // IBufferLayout interface.
876 public:
878 size_t elementSize() const noexcept override;
879
881 UInt32 binding() const noexcept override;
882
884 BufferType type() const noexcept override;
885
886 // VulkanDescriptorLayout
887 public:
896 UInt32 inputAttachmentIndex() const noexcept;
897 };
898
904 class LITEFX_VULKAN_API VulkanDescriptorSetLayout final : public DescriptorSetLayout<VulkanDescriptorLayout, VulkanDescriptorSet>, public Resource<VkDescriptorSetLayout> {
905 LITEFX_IMPLEMENTATION(VulkanDescriptorSetLayoutImpl);
906 LITEFX_BUILDER(VulkanDescriptorSetLayoutBuilder);
908
909 public:
911 using base_type::free;
912 using base_type::allocate;
913
914 private:
922 explicit VulkanDescriptorSetLayout(const VulkanDevice& device, const Enumerable<VulkanDescriptorLayout>& descriptorLayouts, UInt32 space, ShaderStage stages);
923
928 explicit VulkanDescriptorSetLayout(const VulkanDevice& device);
929
930 private:
933
936
938 VulkanDescriptorSetLayout& operator=(VulkanDescriptorSetLayout&&) noexcept = delete;
939
941 VulkanDescriptorSetLayout& operator=(const VulkanDescriptorSetLayout&) = delete;
942
943 public:
945 ~VulkanDescriptorSetLayout() noexcept override;
946
947 public:
956 static inline auto create(const VulkanDevice& device, const Enumerable<VulkanDescriptorLayout>& descriptorLayouts, UInt32 space, ShaderStage stages) {
957 return SharedObject::create<VulkanDescriptorSetLayout>(device, descriptorLayouts, space, stages);
958 }
959
965 static inline auto create(const VulkanDescriptorSetLayout& other) {
967 }
968
969 private:
975 static inline auto create(const VulkanDevice& device) {
977 }
978
979 public:
984 const VulkanDevice& device() const noexcept;
985
990 UInt32 maxUnboundedArraySize() const noexcept;
991
992 public:
994 const Array<VulkanDescriptorLayout>& descriptors() const noexcept override;
995
997 const VulkanDescriptorLayout& descriptor(UInt32 binding) const override;
998
1000 UInt32 space() const noexcept override;
1001
1003 ShaderStage shaderStages() const noexcept override;
1004
1006 UInt32 uniforms() const noexcept override;
1007
1009 UInt32 storages() const noexcept override;
1010
1012 UInt32 images() const noexcept override;
1013
1015 UInt32 buffers() const noexcept override;
1016
1018 UInt32 samplers() const noexcept override;
1019
1021 UInt32 staticSamplers() const noexcept override;
1022
1024 UInt32 inputAttachments() const noexcept override;
1025
1027 bool containsUnboundedArray() const noexcept override;
1028
1030 UInt32 getDescriptorOffset(UInt32 binding, UInt32 element = 0) const override;
1031
1033 bool bindsResources() const noexcept override;
1034
1036 bool bindsSamplers() const noexcept override;
1037
1038 public:
1040 UniquePtr<VulkanDescriptorSet> allocate(UInt32 descriptors, std::initializer_list<DescriptorBinding> bindings) const override;
1041
1043 UniquePtr<VulkanDescriptorSet> allocate(UInt32 descriptors, Span<DescriptorBinding> bindings) const override;
1044
1046 UniquePtr<VulkanDescriptorSet> allocate(UInt32 descriptors, Generator<DescriptorBinding> bindings) const override;
1047
1049 Generator<UniquePtr<VulkanDescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::initializer_list<std::initializer_list<DescriptorBinding>> bindings = { }) const override;
1050
1051#ifdef __cpp_lib_mdspan
1053 Generator<UniquePtr<VulkanDescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::mdspan<DescriptorBinding, std::dextents<size_t, 2>> bindings) const override;
1054#endif
1055
1057 Generator<UniquePtr<VulkanDescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::function<Generator<DescriptorBinding>(UInt32)> bindingFactory) const override;
1058
1060 void free(const VulkanDescriptorSet& descriptorSet) const override;
1061 };
1062
1067 class LITEFX_VULKAN_API VulkanPushConstantsRange final : public IPushConstantsRange {
1068 LITEFX_IMPLEMENTATION(VulkanPushConstantsRangeImpl);
1069
1070 public:
1079 explicit VulkanPushConstantsRange(ShaderStage shaderStage, UInt32 offset, UInt32 size, UInt32 space, UInt32 binding);
1080
1083
1086
1089
1092
1094 ~VulkanPushConstantsRange() noexcept override;
1095
1096 public:
1098 UInt32 space() const noexcept override;
1099
1101 UInt32 binding() const noexcept override;
1102
1104 UInt32 offset() const noexcept override;
1105
1107 UInt32 size() const noexcept override;
1108
1110 ShaderStage stage() const noexcept override;
1111 };
1112
1120 LITEFX_IMPLEMENTATION(VulkanPushConstantsLayoutImpl);
1121 LITEFX_BUILDER(VulkanPushConstantsLayoutBuilder);
1123
1124 public:
1131
1134
1137
1140
1143
1145 ~VulkanPushConstantsLayout() noexcept override;
1146
1147 private:
1152 explicit VulkanPushConstantsLayout(UInt32 size);
1153
1154 public:
1156 UInt32 size() const noexcept override;
1157
1159 const VulkanPushConstantsRange& range(ShaderStage stage) const override;
1160
1162 const Array<UniquePtr<VulkanPushConstantsRange>>& ranges() const override;
1163 };
1164
1169 class LITEFX_VULKAN_API VulkanPipelineLayout final : public PipelineLayout<VulkanDescriptorSetLayout, VulkanPushConstantsLayout>, public Resource<VkPipelineLayout> {
1170 LITEFX_IMPLEMENTATION(VulkanPipelineLayoutImpl);
1171 LITEFX_BUILDER(VulkanPipelineLayoutBuilder);
1173
1174 private:
1181 explicit VulkanPipelineLayout(const VulkanDevice& device, const Enumerable<SharedPtr<VulkanDescriptorSetLayout>>& descriptorSetLayouts, UniquePtr<VulkanPushConstantsLayout>&& pushConstantsLayout);
1182
1187 explicit VulkanPipelineLayout(const VulkanDevice& device) noexcept;
1188
1189 private:
1191 VulkanPipelineLayout(VulkanPipelineLayout&&) noexcept = delete;
1192
1195
1197 VulkanPipelineLayout& operator=(VulkanPipelineLayout&&) noexcept = delete;
1198
1200 VulkanPipelineLayout& operator=(const VulkanPipelineLayout&) = delete;
1201
1202 public:
1204 ~VulkanPipelineLayout() noexcept override;
1205
1206 public:
1214 static inline auto create(const VulkanDevice& device, const Enumerable<SharedPtr<VulkanDescriptorSetLayout>>& descriptorSetLayouts, UniquePtr<VulkanPushConstantsLayout>&& pushConstantsLayout) {
1215 return SharedObject::create<VulkanPipelineLayout>(device, descriptorSetLayouts, std::move(pushConstantsLayout));
1216 }
1217
1218 private:
1224 static inline auto create(const VulkanDevice& device) {
1226 }
1227
1228 // PipelineLayout interface.
1229 public:
1231 const VulkanDevice& device() const noexcept /*override*/;
1232
1234 const VulkanDescriptorSetLayout& descriptorSet(UInt32 space) const override;
1235
1237 const Array<SharedPtr<const VulkanDescriptorSetLayout>>& descriptorSets() const override;
1238
1240 const VulkanPushConstantsLayout* pushConstants() const noexcept override;
1241
1243 bool dynamicResourceHeapAccess() const override;
1244
1246 bool dynamicSamplerHeapAccess() const override;
1247 };
1248
1254 LITEFX_IMPLEMENTATION(VulkanInputAssemblerImpl);
1255 LITEFX_BUILDER(VulkanInputAssemblerBuilder);
1257
1258 private:
1265 explicit VulkanInputAssembler(Enumerable<SharedPtr<VulkanVertexBufferLayout>>&& vertexBufferLayouts, SharedPtr<VulkanIndexBufferLayout>&& indexBufferLayout = nullptr, PrimitiveTopology primitiveTopology = PrimitiveTopology::TriangleList);
1266
1270 explicit VulkanInputAssembler();
1271
1272 private:
1274 VulkanInputAssembler(VulkanInputAssembler&&) noexcept = delete;
1275
1278
1280 VulkanInputAssembler& operator=(VulkanInputAssembler&&) noexcept = delete;
1281
1283 VulkanInputAssembler& operator=(const VulkanInputAssembler&) = delete;
1284
1285 public:
1287 ~VulkanInputAssembler() noexcept override;
1288
1289 public:
1297 static inline auto create(Enumerable<SharedPtr<VulkanVertexBufferLayout>>&& vertexBufferLayouts, SharedPtr<VulkanIndexBufferLayout>&& indexBufferLayout = nullptr, PrimitiveTopology primitiveTopology = PrimitiveTopology::TriangleList) {
1298 return SharedObject::create<VulkanInputAssembler>(std::move(vertexBufferLayouts), std::move(indexBufferLayout), primitiveTopology);
1299 }
1300
1306 static inline auto create(const VulkanInputAssembler& other) {
1308 }
1309
1310 private:
1315 static inline auto create() {
1317 }
1318
1319 public:
1321 Enumerable<const VulkanVertexBufferLayout&> vertexBufferLayouts() const override;
1322
1324 const VulkanVertexBufferLayout& vertexBufferLayout(UInt32 binding) const override;
1325
1327 const VulkanIndexBufferLayout* indexBufferLayout() const noexcept override;
1328
1330 PrimitiveTopology topology() const noexcept override;
1331 };
1332
1337 class LITEFX_VULKAN_API VulkanRasterizer final : public Rasterizer {
1338 LITEFX_BUILDER(VulkanRasterizerBuilder);
1340
1341 private:
1352 explicit VulkanRasterizer(PolygonMode polygonMode, CullMode cullMode, CullOrder cullOrder, Float lineWidth = 1.f, bool depthClip = true, const DepthStencilState& depthStencilState = {}, bool conservativeRasterization = false) noexcept;
1353
1357 explicit VulkanRasterizer() noexcept;
1358
1359 private:
1361 VulkanRasterizer(VulkanRasterizer&&) noexcept = delete;
1362
1364 VulkanRasterizer(const VulkanRasterizer&) = default;
1365
1367 VulkanRasterizer& operator=(VulkanRasterizer&&) noexcept = delete;
1368
1370 VulkanRasterizer& operator=(const VulkanRasterizer&) = delete;
1371
1372 public:
1374 ~VulkanRasterizer() noexcept override;
1375
1376 public:
1388 static inline auto create(PolygonMode polygonMode, CullMode cullMode, CullOrder cullOrder, Float lineWidth = 1.f, bool depthClip = true, const DepthStencilState& depthStencilState = {}, bool conservativeRasterization = false) {
1389 return SharedObject::create<VulkanRasterizer>(polygonMode, cullMode, cullOrder, lineWidth, depthClip, depthStencilState, conservativeRasterization);
1390 }
1391
1397 static inline auto create(const VulkanRasterizer& other) {
1399 }
1400
1401 private:
1406 static inline auto create() {
1408 }
1409
1410 public:
1423 virtual void updateLineWidth(Float lineWidth) noexcept;
1424 };
1425
1431 class LITEFX_VULKAN_API VulkanPipelineState : public virtual Pipeline<VulkanPipelineLayout, VulkanShaderProgram>, public Resource<VkPipeline> {
1432 protected:
1433 using Resource<VkPipeline>::Resource;
1434
1437 VulkanPipelineState& operator=(VulkanPipelineState&&) noexcept = default;
1438 VulkanPipelineState& operator=(const VulkanPipelineState&) = delete;
1439
1440 public:
1441 ~VulkanPipelineState() noexcept override = default;
1442
1443 public:
1448 virtual VkPipelineBindPoint pipelineType() const noexcept = 0;
1449
1454 virtual void use(const VulkanCommandBuffer& commandBuffer) const = 0;
1455 };
1456
1462 LITEFX_IMPLEMENTATION(VulkanCommandBufferImpl);
1464
1465 public:
1467 using base_type::dispatch;
1468 using base_type::dispatchIndirect;
1469 using base_type::dispatchMesh;
1470 using base_type::draw;
1471 using base_type::drawIndirect;
1472 using base_type::drawIndexed;
1473 using base_type::drawIndexedIndirect;
1474 using base_type::barrier;
1475 using base_type::transfer;
1476 using base_type::bind;
1477 using base_type::use;
1478 using base_type::pushConstants;
1479 using base_type::buildAccelerationStructure;
1480 using base_type::updateAccelerationStructure;
1481 using base_type::copyAccelerationStructure;
1482
1483 private:
1490 explicit VulkanCommandBuffer(const VulkanQueue& queue, bool begin = false, bool primary = true);
1491
1492 private:
1494 VulkanCommandBuffer(VulkanCommandBuffer&&) noexcept = delete;
1495
1498
1500 VulkanCommandBuffer& operator=(VulkanCommandBuffer&&) noexcept = delete;
1501
1503 VulkanCommandBuffer& operator=(const VulkanCommandBuffer&) = delete;
1504
1505 public:
1507 ~VulkanCommandBuffer() noexcept override;
1508
1509 // Factory method.
1510 public:
1517 static inline SharedPtr<VulkanCommandBuffer> create(const VulkanQueue& queue, bool begin = false, bool primary = true) {
1518 return SharedObject::create<VulkanCommandBuffer>(queue, begin, primary);
1519 }
1520
1521 // Vulkan Command Buffer interface.
1522 public:
1527 virtual void begin(const VulkanRenderPass& renderPass) const;
1528
1529 // CommandBuffer interface.
1530 public:
1532 SharedPtr<const VulkanQueue> queue() const noexcept;
1533
1535 void begin() const override;
1536
1538 void end() const override;
1539
1541 void track(SharedPtr<const IBuffer> buffer) const override;
1542
1544 void track(SharedPtr<const IImage> image) const override;
1545
1547 void track(SharedPtr<const ISampler> sampler) const override;
1548
1550 void track(UniquePtr<const IDescriptorSet>&& descriptorSet) const override;
1551
1553 bool isSecondary() const noexcept override;
1554
1556 void setViewports(Span<const IViewport*> viewports) const override;
1557
1559 void setViewports(const IViewport* viewport) const override;
1560
1562 void setScissors(Span<const IScissor*> scissors) const override;
1563
1565 void setScissors(const IScissor* scissor) const override;
1566
1568 void setBlendFactors(const Vector4f& blendFactors) const noexcept override;
1569
1571 void setStencilRef(UInt32 stencilRef) const noexcept override;
1572
1574 void setDepthBounds(Float minBounds, Float maxBounds) const noexcept override;
1575
1577 UInt64 submit() const override;
1578
1580 [[nodiscard]] UniquePtr<VulkanBarrier> makeBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const override;
1581
1583 void barrier(const VulkanBarrier& barrier) const noexcept override;
1584
1586 void transfer(const IVulkanBuffer& source, const IVulkanBuffer& target, UInt32 sourceElement = 0, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1587
1589 void transfer(const void* const data, size_t size, const IVulkanBuffer& target, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1590
1592 void transfer(Span<const void* const> data, size_t elementSize, const IVulkanBuffer& target, UInt32 firstElement = 0) const override;
1593
1595 void transfer(const IVulkanBuffer& source, const IVulkanImage& target, UInt32 sourceElement = 0, UInt32 firstSubresource = 0, UInt32 subresources = 1) const override;
1596
1598 void transfer(const void* const data, size_t size, const IVulkanImage& target, UInt32 subresource = 0) const override;
1599
1601 void transfer(Span<const void* const> data, size_t elementSize, const IVulkanImage& target, UInt32 firstSubresource = 0, UInt32 subresources = 1) const override;
1602
1604 void transfer(const IVulkanImage& source, const IVulkanImage& target, UInt32 sourceSubresource = 0, UInt32 targetSubresource = 0, UInt32 subresources = 1) const override;
1605
1607 void transfer(const IVulkanImage& source, const IVulkanBuffer& target, UInt32 firstSubresource = 0, UInt32 targetElement = 0, UInt32 subresources = 1) const override;
1608
1610 void transfer(const SharedPtr<const IVulkanBuffer>& source, const IVulkanBuffer& target, UInt32 sourceElement = 0, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1611
1613 void transfer(const SharedPtr<const IVulkanBuffer>& source, const IVulkanImage& target, UInt32 sourceElement = 0, UInt32 firstSubresource = 0, UInt32 elements = 1) const override;
1614
1616 void transfer(const SharedPtr<const IVulkanImage>& source, const IVulkanImage& target, UInt32 sourceSubresource = 0, UInt32 targetSubresource = 0, UInt32 subresources = 1) const override;
1617
1619 void transfer(const SharedPtr<const IVulkanImage>& source, const IVulkanBuffer& target, UInt32 firstSubresource = 0, UInt32 targetElement = 0, UInt32 subresources = 1) const override;
1620
1622 void use(const VulkanPipelineState& pipeline) const noexcept override;
1623
1625 void bind(const VulkanDescriptorSet& descriptorSet) const override;
1626
1628 void bind(Span<const VulkanDescriptorSet*> descriptorSets) const override;
1629
1631 void bind(const VulkanDescriptorSet& descriptorSet, const VulkanPipelineState& pipeline) const override;
1632
1634 void bind(Span<const VulkanDescriptorSet*> descriptorSets, const VulkanPipelineState& pipeline) const override;
1635
1637 void bind(const IVulkanVertexBuffer& buffer) const noexcept override;
1638
1640 void bind(const IVulkanIndexBuffer& buffer) const noexcept override;
1641
1643 void dispatch(const Vector3u& threadCount) const noexcept override;
1644
1646 void dispatchIndirect(const IVulkanBuffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1647
1649 void dispatchMesh(const Vector3u& threadCount) const noexcept override;
1650
1652 void dispatchMeshIndirect(const IVulkanBuffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1653
1655 void dispatchMeshIndirect(const IVulkanBuffer& batchBuffer, const IVulkanBuffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1656
1658 void draw(UInt32 vertices, UInt32 instances = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) const noexcept override;
1659
1661 void drawIndirect(const IVulkanBuffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1662
1664 void drawIndirect(const IVulkanBuffer& batchBuffer, const IVulkanBuffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1665
1667 void drawIndexed(UInt32 indices, UInt32 instances = 1, UInt32 firstIndex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0) const noexcept override;
1668
1670 void drawIndexedIndirect(const IVulkanBuffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1671
1673 void drawIndexedIndirect(const IVulkanBuffer& batchBuffer, const IVulkanBuffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1674
1676 void pushConstants(const VulkanPushConstantsLayout& layout, const void* const memory) const override;
1677
1679 void writeTimingEvent(const SharedPtr<const TimingEvent>& timingEvent) const override;
1680
1682 void execute(const SharedPtr<const VulkanCommandBuffer>& commandBuffer) const override;
1683
1685 void execute(Enumerable<SharedPtr<const VulkanCommandBuffer>> commandBuffers) const override;
1686
1688 void buildAccelerationStructure(VulkanBottomLevelAccelerationStructure& blas, const SharedPtr<const IVulkanBuffer>& scratchBuffer, const IVulkanBuffer& buffer, UInt64 offset) const override;
1689
1691 void buildAccelerationStructure(VulkanTopLevelAccelerationStructure& tlas, const SharedPtr<const IVulkanBuffer>& scratchBuffer, const IVulkanBuffer& buffer, UInt64 offset) const override;
1692
1694 void updateAccelerationStructure(VulkanBottomLevelAccelerationStructure& blas, const SharedPtr<const IVulkanBuffer>& scratchBuffer, const IVulkanBuffer& buffer, UInt64 offset) const override;
1695
1697 void updateAccelerationStructure(VulkanTopLevelAccelerationStructure& tlas, const SharedPtr<const IVulkanBuffer>& scratchBuffer, const IVulkanBuffer& buffer, UInt64 offset) const override;
1698
1700 void copyAccelerationStructure(const VulkanBottomLevelAccelerationStructure& from, const VulkanBottomLevelAccelerationStructure& to, bool compress = false) const noexcept override;
1701
1703 void copyAccelerationStructure(const VulkanTopLevelAccelerationStructure& from, const VulkanTopLevelAccelerationStructure& to, bool compress = false) const noexcept override;
1704
1706 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;
1707
1708 private:
1709 inline SharedPtr<const ICommandQueue> getQueue() const noexcept override {
1710 return std::static_pointer_cast<const ICommandQueue>(this->queue());
1711 }
1712
1713 void releaseSharedState() const override;
1714 };
1715
1720 class LITEFX_VULKAN_API VulkanQueue final : public CommandQueue<VulkanCommandBuffer>, public Resource<VkQueue> {
1721 LITEFX_IMPLEMENTATION(VulkanQueueImpl);
1722 friend struct SharedObject::Allocator<VulkanQueue>;
1723
1724 public:
1726 using base_type::submit;
1727
1728 private:
1737 explicit VulkanQueue(const VulkanDevice& device, QueueType type, QueuePriority priority, UInt32 familyId, UInt32 queueId);
1738
1739 private:
1741 VulkanQueue(VulkanQueue&&) noexcept = delete;
1742
1744 VulkanQueue(const VulkanQueue&) = delete;
1745
1747 VulkanQueue& operator=(VulkanQueue&&) noexcept = delete;
1748
1750 VulkanQueue& operator=(const VulkanQueue&) = delete;
1751
1752 public:
1754 ~VulkanQueue() noexcept override;
1755
1756 public:
1766 static inline SharedPtr<VulkanQueue> create(const VulkanDevice& device, QueueType type, QueuePriority priority, UInt32 familyId, UInt32 queueId) {
1767 return SharedObject::create<VulkanQueue>(device, type, priority, familyId, queueId);
1768 }
1769
1770 // VulkanQueue interface.
1771 public:
1776 SharedPtr<const VulkanDevice> device() const noexcept;
1777
1782 UInt32 familyId() const noexcept;
1783
1788 UInt32 queueId() const noexcept;
1789
1794 const VkSemaphore& timelineSemaphore() const noexcept;
1795
1796 // CommandQueue interface.
1797 public:
1799 QueuePriority priority() const noexcept override;
1800
1802 QueueType type() const noexcept override;
1803
1804#ifdef LITEFX_BUILD_SUPPORT_DEBUG_MARKERS
1805 public:
1807 void beginDebugRegion(const String& label, const Vectors::ByteVector3& color = DEFAULT_DEBUG_COLOR) const noexcept override;
1808
1810 void endDebugRegion() const noexcept override;
1811
1813 void setDebugMarker(const String& label, const Vectors::ByteVector3& color = DEFAULT_DEBUG_COLOR) const noexcept override;
1814#endif // LITEFX_BUILD_SUPPORT_DEBUG_MARKERS
1815
1816 public:
1818 SharedPtr<VulkanCommandBuffer> createCommandBuffer(bool beginRecording = false, bool secondary = false) const override;
1819
1821 UInt64 submit(const SharedPtr<const VulkanCommandBuffer>& commandBuffer) const override;
1822
1824 UInt64 submit(Enumerable<SharedPtr<const VulkanCommandBuffer>> commandBuffers) const override;
1825
1827 void waitFor(UInt64 fence) const override;
1828
1830 void waitFor(const VulkanQueue& queue, UInt64 fence) const noexcept;
1831
1833 UInt64 currentFence() const noexcept override;
1834
1836 UInt64 lastCompletedFence() const noexcept override;
1837
1838 private:
1839 inline void waitForQueue(const ICommandQueue& queue, UInt64 fence) const override {
1840 auto vkQueue = dynamic_cast<const VulkanQueue*>(&queue);
1841
1842 if (vkQueue == nullptr) [[unlikely]]
1843 throw InvalidArgumentException("queue", "Cannot wait for queues from other backends.");
1844
1845 this->waitFor(*vkQueue, fence);
1846 }
1847 };
1848
1854 class LITEFX_VULKAN_API VulkanRenderPipeline final : public virtual VulkanPipelineState, public RenderPipeline<VulkanPipelineLayout, VulkanShaderProgram, VulkanInputAssembler, VulkanRasterizer> {
1855 LITEFX_IMPLEMENTATION(VulkanRenderPipelineImpl);
1856 LITEFX_BUILDER(VulkanRenderPipelineBuilder);
1857
1858 public:
1870 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 = "");
1871
1874
1877
1879 VulkanRenderPipeline& operator=(VulkanRenderPipeline&&) noexcept = delete;
1880
1882 VulkanRenderPipeline& operator=(const VulkanRenderPipeline&) = delete;
1883
1885 ~VulkanRenderPipeline() noexcept override;
1886
1887 private:
1893 VulkanRenderPipeline(const VulkanRenderPass& renderPass, const String& name = "");
1894
1895 // Pipeline interface.
1896 public:
1898 SharedPtr<const VulkanShaderProgram> program() const noexcept override;
1899
1901 SharedPtr<const VulkanPipelineLayout> layout() const noexcept override;
1902
1903 // RenderPipeline interface.
1904 public:
1906 SharedPtr<VulkanInputAssembler> inputAssembler() const noexcept override;
1907
1909 SharedPtr<VulkanRasterizer> rasterizer() const noexcept override;
1910
1912 bool alphaToCoverage() const noexcept override;
1913
1915 MultiSamplingLevel samples() const noexcept override;
1916
1918 void updateSamples(MultiSamplingLevel samples) override;
1919
1920 // VulkanPipelineState interface.
1921 public:
1923 VkPipelineBindPoint pipelineType() const noexcept override;
1924
1926 void use(const VulkanCommandBuffer& commandBuffer) const override;
1927 };
1928
1935 LITEFX_IMPLEMENTATION(VulkanComputePipelineImpl);
1936 LITEFX_BUILDER(VulkanComputePipelineBuilder);
1937
1938 public:
1946 explicit VulkanComputePipeline(const VulkanDevice& device, const SharedPtr<VulkanPipelineLayout>& layout, const SharedPtr<VulkanShaderProgram>& shaderProgram, const String& name = "");
1947
1950
1953
1956
1959
1961 ~VulkanComputePipeline() noexcept override;
1962
1963 private:
1968 VulkanComputePipeline(const VulkanDevice& device) noexcept;
1969
1970 // Pipeline interface.
1971 public:
1973 SharedPtr<const VulkanShaderProgram> program() const noexcept override;
1974
1976 SharedPtr<const VulkanPipelineLayout> layout() const noexcept override;
1977
1978 // VulkanPipelineState interface.
1979 public:
1981 VkPipelineBindPoint pipelineType() const noexcept override;
1982
1984 void use(const VulkanCommandBuffer& commandBuffer) const override;
1985 };
1986
1993 LITEFX_IMPLEMENTATION(VulkanRayTracingPipelineImpl);
1994 LITEFX_BUILDER(VulkanRayTracingPipelineBuilder);
1995
1996 public:
2008 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)
2009
2012
2015
2018
2021
2023 ~VulkanRayTracingPipeline() noexcept override;
2024
2025 private:
2031 VulkanRayTracingPipeline(const VulkanDevice& device, ShaderRecordCollection&& shaderRecords) noexcept;
2032
2033 // Pipeline interface.
2034 public:
2036 SharedPtr<const VulkanShaderProgram> program() const noexcept override;
2037
2039 SharedPtr<const VulkanPipelineLayout> layout() const noexcept override;
2040
2041 // RayTracingPipeline interface.
2042 public:
2044 const ShaderRecordCollection& shaderRecords() const noexcept override;
2045
2047 UInt32 maxRecursionDepth() const noexcept override;
2048
2050 UInt32 maxPayloadSize() const noexcept override;
2051
2053 UInt32 maxAttributeSize() const noexcept override;
2054
2056 SharedPtr<IVulkanBuffer> allocateShaderBindingTable(ShaderBindingTableOffsets& offsets, ShaderBindingGroup groups = ShaderBindingGroup::All) const override;
2057
2058 // VulkanPipelineState interface.
2059 public:
2061 VkPipelineBindPoint pipelineType() const noexcept override;
2062
2064 void use(const VulkanCommandBuffer& commandBuffer) const override;
2065 };
2066
2071 class LITEFX_VULKAN_API VulkanFrameBuffer final : public FrameBuffer<IVulkanImage> {
2072 LITEFX_IMPLEMENTATION(VulkanFrameBufferImpl);
2074
2075 public:
2077 using FrameBuffer::addImage;
2078 using FrameBuffer::mapRenderTarget;
2079 using FrameBuffer::mapRenderTargets;
2080
2081 private:
2088 VulkanFrameBuffer(const VulkanDevice& device, const Size2d& renderArea, StringView name = "");
2089
2098 VulkanFrameBuffer(const VulkanDevice& device, const Size2d& renderArea, allocation_callback_type allocationCallback, StringView name = "");
2099
2100 private:
2102 VulkanFrameBuffer(VulkanFrameBuffer&&) noexcept = delete;
2103
2105 VulkanFrameBuffer(const VulkanFrameBuffer&) = delete;
2106
2108 VulkanFrameBuffer& operator=(VulkanFrameBuffer&&) noexcept = delete;
2109
2111 VulkanFrameBuffer& operator=(const VulkanFrameBuffer&) = delete;
2112
2113 public:
2115 ~VulkanFrameBuffer() noexcept override;
2116
2117 public:
2125 static inline SharedPtr<VulkanFrameBuffer> create(const VulkanDevice& device, const Size2d& renderArea, StringView name = "") {
2126 return SharedObject::create<VulkanFrameBuffer>(device, renderArea, name);
2127 }
2128
2137 static inline SharedPtr<VulkanFrameBuffer> create(const VulkanDevice& device, const Size2d& renderArea, allocation_callback_type allocationCallback, StringView name = "") {
2138 return SharedObject::create<VulkanFrameBuffer>(device, renderArea, std::move(allocationCallback), name);
2139 }
2140
2141 // Vulkan frame buffer interface.
2142 public:
2149 VkImageView imageView(UInt32 imageIndex) const;
2150
2157 VkImageView imageView(StringView imageName) const;
2158
2165 VkImageView imageView(const RenderTarget& renderTarget) const;
2166
2167 // FrameBuffer interface.
2168 public:
2170 const Size2d& size() const noexcept override;
2171
2173 size_t getWidth() const noexcept override;
2174
2176 size_t getHeight() const noexcept override;
2177
2179 void mapRenderTarget(const RenderTarget& renderTarget, UInt32 index) override;
2180
2182 void mapRenderTarget(const RenderTarget& renderTarget, StringView name) override;
2183
2185 void unmapRenderTarget(const RenderTarget& renderTarget) noexcept override;
2186
2188 const Array<SharedPtr<const IVulkanImage>>& images() const override;
2189
2191 inline const IVulkanImage& operator[](UInt32 index) const override {
2192 return this->image(index);
2193 }
2194
2196 const IVulkanImage& image(UInt32 index) const override;
2197
2199 inline const IVulkanImage& operator[](const RenderTarget& renderTarget) const override {
2200 return this->image(renderTarget);
2201 }
2202
2204 const IVulkanImage& image(const RenderTarget& renderTarget) const override;
2205
2207 inline const IVulkanImage& operator[](StringView renderTargetName) const override {
2208 return this->resolveImage(hash(renderTargetName));
2209 }
2210
2212 inline const IVulkanImage& image(StringView renderTargetName) const override {
2213 return this->resolveImage(hash(renderTargetName));
2214 }
2215
2217 const IVulkanImage& resolveImage(UInt64 hash) const override;
2218
2220 void addImage(const String& name, Format format, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::FrameBufferImage) override;
2221
2223 void addImage(const String& name, const RenderTarget& renderTarget, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::FrameBufferImage) override;
2224
2226 void resize(const Size2d& renderArea) override;
2227 };
2228
2233 class LITEFX_VULKAN_API VulkanRenderPass final : public RenderPass<VulkanQueue, VulkanFrameBuffer> {
2234 LITEFX_IMPLEMENTATION(VulkanRenderPassImpl);
2235 LITEFX_BUILDER(VulkanRenderPassBuilder);
2237
2238 public:
2240
2241 private:
2251 explicit VulkanRenderPass(const VulkanDevice& device, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000);
2252
2263 explicit VulkanRenderPass(const VulkanDevice& device, const String& name, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000);
2264
2275 explicit VulkanRenderPass(const VulkanDevice& device, const VulkanQueue& queue, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000);
2276
2288 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, UInt32 viewMask = 0b0000);
2289
2290 private:
2292 VulkanRenderPass(VulkanRenderPass&&) noexcept = delete;
2293
2295 VulkanRenderPass(const VulkanRenderPass&) = delete;
2296
2298 VulkanRenderPass& operator=(VulkanRenderPass&&) noexcept = delete;
2299
2301 VulkanRenderPass& operator=(const VulkanRenderPass&) = delete;
2302
2303 public:
2305 ~VulkanRenderPass() noexcept override;
2306
2307 public:
2318 static inline SharedPtr<VulkanRenderPass> create(const VulkanDevice& device, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000) {
2319 return SharedObject::create<VulkanRenderPass>(device, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers, viewMask);
2320 }
2321
2333 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, UInt32 viewMask = 0b0000) {
2334 return SharedObject::create<VulkanRenderPass>(device, name, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers, viewMask);
2335 }
2336
2348 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, UInt32 viewMask = 0b0000) {
2349 return SharedObject::create<VulkanRenderPass>(device, queue, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers, viewMask);
2350 }
2351
2364 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, UInt32 viewMask = 0b0000) {
2365 return SharedObject::create<VulkanRenderPass>(device, name, queue, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers, viewMask);
2366 }
2367
2368 private:
2374 explicit VulkanRenderPass(const VulkanDevice& device, const String& name = "");
2375
2386 static inline SharedPtr<VulkanRenderPass> create(const VulkanDevice& device, const String& name = "") {
2387 return SharedObject::create<VulkanRenderPass>(device, name);
2388 }
2389
2390 // RenderPass interface.
2391 public:
2396 const VulkanDevice& device() const noexcept /*override*/;
2397
2399 SharedPtr<const VulkanFrameBuffer> activeFrameBuffer() const noexcept override;
2400
2402 const VulkanQueue& commandQueue() const noexcept override;
2403
2405 Enumerable<SharedPtr<const VulkanCommandBuffer>> commandBuffers() const override;
2406
2408 SharedPtr<const VulkanCommandBuffer> commandBuffer(UInt32 index) const override;
2409
2411 UInt32 secondaryCommandBuffers() const noexcept override;
2412
2414 const Array<RenderTarget>& renderTargets() const noexcept override;
2415
2417 const RenderTarget& renderTarget(UInt32 location) const override;
2418
2420 bool hasPresentTarget() const noexcept override;
2421
2423 const Array<RenderPassDependency>& inputAttachments() const noexcept override;
2424
2426 const RenderPassDependency& inputAttachment(UInt32 location) const override;
2427
2429 const Optional<DescriptorBindingPoint>& inputAttachmentSamplerBinding() const noexcept override;
2430
2432 void begin(const VulkanFrameBuffer& frameBuffer) const override;
2433
2435 UInt64 end() const override;
2436
2438 UInt32 viewMask() const noexcept override;
2439 };
2440
2444 class LITEFX_VULKAN_API VulkanSwapChain final : public SwapChain<IVulkanImage> {
2445 LITEFX_IMPLEMENTATION(VulkanSwapChainImpl);
2446 friend class VulkanImage;
2447 friend class VulkanDevice;
2448
2449 public:
2451
2452 private:
2461 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)
2462
2463 public:
2465 VulkanSwapChain(VulkanSwapChain&&) noexcept = delete;
2466
2469
2471 VulkanSwapChain& operator=(VulkanSwapChain&&) noexcept = delete;
2472
2474 VulkanSwapChain& operator=(const VulkanSwapChain&) = delete;
2475
2477 ~VulkanSwapChain() noexcept override;
2478
2479 // Vulkan Swap Chain interface.
2480 public:
2485 virtual const VkQueryPool& timestampQueryPool() const noexcept;
2486
2487 // SwapChain interface.
2488 public:
2490 const Array<SharedPtr<const TimingEvent>>& timingEvents() const override;
2491
2493 SharedPtr<const TimingEvent> timingEvent(UInt32 queryId) const override;
2494
2496 UInt64 readTimingEvent(SharedPtr<const TimingEvent> timingEvent) const override;
2497
2499 UInt32 resolveQueryId(SharedPtr<const TimingEvent> timingEvent) const override;
2500
2502 const IGraphicsDevice& device() const override;
2503
2505 Format surfaceFormat() const noexcept override;
2506
2508 UInt32 buffers() const noexcept override;
2509
2511 const Size2d& renderArea() const noexcept override;
2512
2514 bool verticalSynchronization() const noexcept override;
2515
2517 IVulkanImage* image(UInt32 backBuffer) const override;
2518
2520 const IVulkanImage& image() const noexcept override;
2521
2523 const Array<SharedPtr<IVulkanImage>>& images() const noexcept override;
2524
2526 void present(UInt64 fence) const override;
2527
2528 public:
2530 Enumerable<Format> getSurfaceFormats() const override;
2531
2533 void addTimingEvent(SharedPtr<const TimingEvent> timingEvent) override;
2534
2536 void reset(Format surfaceFormat, const Size2d& renderArea, UInt32 buffers, bool enableVsync = false) override;
2537
2539 [[nodiscard]] UInt32 swapBackBuffer() const override;
2540 };
2541
2549 LITEFX_IMPLEMENTATION(VulkanGraphicsFactoryImpl);
2550 friend class VulkanDevice;
2552
2553 public:
2555 using base_type::createBuffer;
2556 using base_type::tryCreateBuffer;
2557 using base_type::createVertexBuffer;
2558 using base_type::tryCreateVertexBuffer;
2559 using base_type::createIndexBuffer;
2560 using base_type::tryCreateIndexBuffer;
2561 using base_type::createTexture;
2562 using base_type::tryCreateTexture;
2563 using base_type::createTextures;
2564 using base_type::createSampler;
2565 using base_type::createSamplers;
2566 using base_type::allocate;
2567
2568 private:
2573 explicit VulkanGraphicsFactory(const VulkanDevice& device);
2574
2575 private:
2577 VulkanGraphicsFactory(VulkanGraphicsFactory&&) noexcept = delete;
2578
2581
2583 VulkanGraphicsFactory& operator=(VulkanGraphicsFactory&&) noexcept = delete;
2584
2586 VulkanGraphicsFactory& operator=(const VulkanGraphicsFactory&) = delete;
2587
2588 public:
2590 ~VulkanGraphicsFactory() noexcept override;
2591
2592 private:
2597 static inline SharedPtr<VulkanGraphicsFactory> create(const VulkanDevice& device) {
2599 }
2600
2606 SharedPtr<IVulkanBuffer> createDescriptorHeap(size_t heapSize) const;
2607
2614 SharedPtr<IVulkanBuffer> createDescriptorHeap(const String& name, size_t heapSize) const;
2615
2616 public:
2618 [[nodiscard]] VirtualAllocator createAllocator(UInt64 overallMemory, AllocationAlgorithm algorithm = AllocationAlgorithm::Default) const override;
2619
2621 void beginDefragmentation(const ICommandQueue& queue, DefragmentationStrategy strategy = DefragmentationStrategy::Balanced, UInt64 maxBytesToMove = 0u, UInt32 maxAllocationsToMove = 0u) const override;
2622
2624 UInt64 beginDefragmentationPass() const override;
2625
2627 bool endDefragmentationPass() const override;
2628
2630 Generator<ResourceAllocationResult> allocate(Enumerable<const ResourceAllocationInfo&> allocationInfos, AllocationBehavior allocationBehavior = AllocationBehavior::Default, bool alias = false) const override;
2631
2633 bool canAlias(Enumerable<const ResourceAllocationInfo&> allocationInfos) const override;
2634
2636 SharedPtr<IVulkanBuffer> createBuffer(BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2637
2639 SharedPtr<IVulkanBuffer> createBuffer(const String& name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2640
2642 SharedPtr<IVulkanVertexBuffer> createVertexBuffer(const VulkanVertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2643
2645 SharedPtr<IVulkanVertexBuffer> createVertexBuffer(const String& name, const VulkanVertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2646
2648 SharedPtr<IVulkanIndexBuffer> createIndexBuffer(const VulkanIndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2649
2651 SharedPtr<IVulkanIndexBuffer> createIndexBuffer(const String& name, const VulkanIndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2652
2654 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, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2655
2657 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, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2658
2660 bool tryCreateBuffer(SharedPtr<IVulkanBuffer>& buffer, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2661
2663 bool tryCreateBuffer(SharedPtr<IVulkanBuffer>& buffer, const String& name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2664
2666 bool tryCreateVertexBuffer(SharedPtr<IVulkanVertexBuffer>& buffer, const VulkanVertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2667
2669 bool tryCreateVertexBuffer(SharedPtr<IVulkanVertexBuffer>& buffer, const String& name, const VulkanVertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2670
2672 bool tryCreateIndexBuffer(SharedPtr<IVulkanIndexBuffer>& buffer, const VulkanIndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2673
2675 bool tryCreateIndexBuffer(SharedPtr<IVulkanIndexBuffer>& buffer, const String& name, const VulkanIndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2676
2678 bool tryCreateTexture(SharedPtr<IVulkanImage>& image, Format format, const Size3d& size, ImageDimensions dimension = ImageDimensions::DIM_2, UInt32 levels = 1, UInt32 layers = 1, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2679
2681 bool tryCreateTexture(SharedPtr<IVulkanImage>& image, 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, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2682
2684 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, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2685
2687 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;
2688
2690 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;
2691
2693 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;
2694
2696 UniquePtr<VulkanBottomLevelAccelerationStructure> createBottomLevelAccelerationStructure(StringView name, AccelerationStructureFlags flags = AccelerationStructureFlags::None) const override;
2697
2699 UniquePtr<VulkanTopLevelAccelerationStructure> createTopLevelAccelerationStructure(StringView name, AccelerationStructureFlags flags = AccelerationStructureFlags::None) const override;
2700
2702 bool supportsResizableBaseAddressRegister() const noexcept override;
2703
2705 Array<MemoryHeapStatistics> memoryStatistics() const override;
2706
2708 DetailedMemoryStatistics detailedMemoryStatistics() const override;
2709 };
2710
2715 LITEFX_IMPLEMENTATION(VulkanDeviceImpl);
2717 friend class VulkanBackend;
2718
2719 public:
2727 static const size_t DEFAULT_DESCRIPTOR_HEAP_SIZE = 134'217'728; // equals 128 Mb
2728
2729 private:
2739 explicit VulkanDevice(const VulkanBackend& backend, const VulkanGraphicsAdapter& adapter, UniquePtr<VulkanSurface>&& surface, GraphicsDeviceFeatures features = { }, Span<String> extensions = { }, size_t globalDescriptorHeapSize = DEFAULT_DESCRIPTOR_HEAP_SIZE);
2740
2741 private:
2743 VulkanDevice(VulkanDevice&&) noexcept = delete;
2744
2746 VulkanDevice(const VulkanDevice&) = delete;
2747
2749 VulkanDevice& operator=(VulkanDevice&&) noexcept = delete;
2750
2752 VulkanDevice& operator=(const VulkanDevice&) = delete;
2753
2754 public:
2756 ~VulkanDevice() noexcept override;
2757
2758 // Factory methods.
2759 public:
2770 static inline SharedPtr<VulkanDevice> create(const VulkanBackend& backend, const VulkanGraphicsAdapter& adapter, UniquePtr<VulkanSurface>&& surface, GraphicsDeviceFeatures features = { }, Span<String> extensions = { }, size_t globalDescriptorHeapSize = DEFAULT_DESCRIPTOR_HEAP_SIZE) {
2771 return SharedObject::create<VulkanDevice>(backend, adapter, std::move(surface), features, extensions, globalDescriptorHeapSize)->initialize(Format::B8G8R8A8_SRGB, { 800, 600 }, 3, false, features); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
2772 }
2773
2788 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 = { }, size_t globalDescriptorHeapSize = DEFAULT_DESCRIPTOR_HEAP_SIZE) {
2789 return SharedObject::create<VulkanDevice>(backend, adapter, std::move(surface), features, extensions, globalDescriptorHeapSize)->initialize(format, renderArea, backBuffers, enableVsync, features);
2790 }
2791
2792 private:
2802 SharedPtr<VulkanDevice> initialize(Format format, const Size2d& renderArea, UInt32 backBuffers, bool enableVsync = false, GraphicsDeviceFeatures features = { });
2803
2807 void release() noexcept;
2808
2809 // Vulkan Device interface.
2810 private:
2821 void setDebugName(VkDebugReportObjectTypeEXT objectType, UInt64 objectHandle, StringView name) const noexcept;
2822
2823 public:
2828 Span<const String> enabledExtensions() const noexcept;
2829
2841 template <typename THandle>
2842 inline void setDebugName(THandle objectHandle, VkDebugReportObjectTypeEXT objectType, StringView name) const noexcept {
2843 this->setDebugName(objectType, Vk::handleAddress(objectHandle), name); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
2844 }
2845
2851 Enumerable<UInt32> queueFamilyIndices(QueueType type = QueueType::None) const;
2852
2858 UInt32 descriptorSize(DescriptorType type) const;
2859
2860 // GraphicsDevice interface.
2861 public:
2863 DeviceState& state() const noexcept override;
2864
2866 const VulkanSwapChain& swapChain() const noexcept override;
2867
2869 VulkanSwapChain& swapChain() noexcept override;
2870
2872 const VulkanSurface& surface() const noexcept override;
2873
2875 const VulkanGraphicsAdapter& adapter() const noexcept override;
2876
2878 const VulkanGraphicsFactory& factory() const noexcept override;
2879
2881 const VulkanQueue& defaultQueue(QueueType type) const override;
2882
2884 SharedPtr<const VulkanQueue> createQueue(QueueType type, QueuePriority priority = QueuePriority::Normal) override;
2885
2887 [[nodiscard]] UniquePtr<VulkanBarrier> makeBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const override;
2888
2890 [[nodiscard]] SharedPtr<VulkanFrameBuffer> makeFrameBuffer(StringView name, const Size2d& renderArea) const override;
2891
2893 [[nodiscard]] SharedPtr<VulkanFrameBuffer> makeFrameBuffer(StringView name, const Size2d& renderArea, VulkanFrameBuffer::allocation_callback_type allocationCallback) const override;
2894
2896 MultiSamplingLevel maximumMultiSamplingLevel(Format format) const noexcept override;
2897
2899 double ticksPerMillisecond() const noexcept override;
2900
2902 void wait() const override;
2903
2905 void computeAccelerationStructureSizes(const VulkanBottomLevelAccelerationStructure& blas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate = false) const override;
2906
2908 void computeAccelerationStructureSizes(const VulkanTopLevelAccelerationStructure& tlas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate = false) const override;
2909
2911 [[nodiscard]] VirtualAllocator::Allocation allocateGlobalDescriptors(const VulkanDescriptorSet& descriptorSet, DescriptorHeapType heapType) const override;
2912
2914 void releaseGlobalDescriptors(const VulkanDescriptorSet& descriptorSet) const override;
2915
2917 void updateGlobalDescriptors(const VulkanDescriptorSet& descriptorSet, UInt32 binding, UInt32 offset, UInt32 descriptors) const override;
2918
2920 void bindDescriptorSet(const VulkanCommandBuffer& commandBuffer, const VulkanDescriptorSet& descriptorSet, const VulkanPipelineState& pipeline) const noexcept override;
2921
2923 void bindGlobalDescriptorHeaps(const VulkanCommandBuffer& commandBuffer) const noexcept override;
2924
2925#if defined(LITEFX_BUILD_DEFINE_BUILDERS)
2926 public:
2928 [[nodiscard]] VulkanRenderPassBuilder buildRenderPass(UInt32 commandBuffers = 1) const override;
2929
2931 [[nodiscard]] VulkanRenderPassBuilder buildRenderPass(const String& name, UInt32 commandBuffers = 1) const override;
2932
2934 //[[nodiscard]] VulkanRenderPipelineBuilder buildRenderPipeline(const String& name) const override;
2935
2937 [[nodiscard]] VulkanRenderPipelineBuilder buildRenderPipeline(const VulkanRenderPass& renderPass, const String& name) const override;
2938
2940 [[nodiscard]] VulkanComputePipelineBuilder buildComputePipeline(const String& name) const override;
2941
2943 [[nodiscard]] VulkanRayTracingPipelineBuilder buildRayTracingPipeline(ShaderRecordCollection&& shaderRecords) const override;
2944
2946 [[nodiscard]] VulkanRayTracingPipelineBuilder buildRayTracingPipeline(const String& name, ShaderRecordCollection&& shaderRecords) const override;
2947
2949 [[nodiscard]] VulkanPipelineLayoutBuilder buildPipelineLayout() const override;
2950
2952 [[nodiscard]] VulkanInputAssemblerBuilder buildInputAssembler() const override;
2953
2955 [[nodiscard]] VulkanRasterizerBuilder buildRasterizer() const override;
2956
2958 [[nodiscard]] VulkanShaderProgramBuilder buildShaderProgram() const override;
2959
2961 [[nodiscard]] VulkanBarrierBuilder buildBarrier() const override;
2962#endif // defined(LITEFX_BUILD_DEFINE_BUILDERS)
2963 };
2964
2968 class LITEFX_VULKAN_API VulkanBackend final : public RenderBackend<VulkanDevice>, public Resource<VkInstance> {
2969 LITEFX_IMPLEMENTATION(VulkanBackendImpl);
2970
2971 public:
2978 explicit VulkanBackend(const App& app, const Span<String> extensions = { }, const Span<String> validationLayers = { });
2979
2982
2985
2987 VulkanBackend& operator=(VulkanBackend&&) noexcept;
2988
2990 VulkanBackend& operator=(const VulkanBackend&) = delete;
2991
2993 ~VulkanBackend() noexcept override;
2994
2995 public:
3000 virtual Span<const String> getEnabledValidationLayers() const noexcept;
3001
3002#ifdef VK_USE_PLATFORM_WIN32_KHR
3008 UniquePtr<VulkanSurface> createSurface(const HWND& hwnd) const;
3009#else
3013 typedef std::function<VkSurfaceKHR(const VkInstance&)> surface_callback;
3014
3021 UniquePtr<VulkanSurface> createSurface(surface_callback predicate) const;
3022#endif // VK_USE_PLATFORM_WIN32_KHR
3023
3024 public:
3030 static bool validateInstanceExtensions(Span<const String> extensions);
3031
3037 static Enumerable<String> getAvailableInstanceExtensions();
3038
3044 static bool validateInstanceLayers(const Span<const String> validationLayers);
3045
3051 static Enumerable<String> getInstanceValidationLayers();
3052
3053 // IBackend interface.
3054 public:
3056 BackendType type() const noexcept override;
3057
3059 StringView name() const noexcept override;
3060
3061 protected:
3063 void activate() override;
3064
3066 void deactivate() override;
3067
3068 // RenderBackend interface.
3069 public:
3071 const Array<SharedPtr<const VulkanGraphicsAdapter>>& adapters() const override;
3072
3074 const VulkanGraphicsAdapter* findAdapter(const Optional<UInt64>& adapterId = std::nullopt) const noexcept override;
3075
3077 void registerDevice(const String& name, SharedPtr<VulkanDevice>&& device) override;
3078
3080 void releaseDevice(const String& name) override;
3081
3083 VulkanDevice* device(const String& name) noexcept override;
3084
3086 const VulkanDevice* device(const String& name) const noexcept override;
3087 };
3088
3089}
3090
3091#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:864
Definition math.hpp:833
Definition math.hpp:504
Definition math.hpp:548
Represents the base interface for a Vulkan acceleration structure implementation.
Definition vulkan.hpp:295
Represents the base interface for a Vulkan buffer implementation.
Definition vulkan.hpp:190
Represents a Vulkan sampled image or the base interface for a texture.
Definition vulkan.hpp:244
Represents a Vulkan index buffer.
Definition vulkan.hpp:224
Represents a Vulkan sampler.
Definition vulkan.hpp:277
Represents a Vulkan vertex buffer.
Definition vulkan.hpp:207
Defines a rendering backend that creates a Vulkan device.
Definition vulkan.hpp:2968
std::function< VkSurfaceKHR(const VkInstance &)> surface_callback
A callback that creates a surface from a Vulkan instance.
Definition vulkan.hpp:3013
VulkanBackend(VulkanBackend &&) noexcept
Implements a Vulkan resource barrier.
Definition vulkan.hpp:495
VulkanBarrier(VulkanBarrier &&) noexcept
Implements a Vulkan bottom-level acceleration structure (BLAS).
Definition vulkan.hpp:311
VulkanBottomLevelAccelerationStructure(VulkanBottomLevelAccelerationStructure &&) noexcept
Records commands for a VulkanQueue
Definition vulkan.hpp:1461
Implements a Vulkan ComputePipeline.
Definition vulkan.hpp:1934
VulkanComputePipeline(VulkanComputePipeline &&) noexcept
Implements a Vulkan IDescriptorLayout
Definition vulkan.hpp:817
VulkanDescriptorLayout(VulkanDescriptorLayout &&) noexcept
Implements a Vulkan DescriptorSet.
Definition vulkan.hpp:723
VulkanDescriptorSet(VulkanDescriptorSet &&) noexcept=delete
Implements a Vulkan DescriptorSetLayout.
Definition vulkan.hpp:904
static auto create(const VulkanDescriptorSetLayout &other)
Creates a copy of a Vulkan descriptor set layout.
Definition vulkan.hpp:965
Implements a Vulkan graphics device.
Definition vulkan.hpp:2714
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={ }, size_t globalDescriptorHeapSize=DEFAULT_DESCRIPTOR_HEAP_SIZE)
Initializes the device instance.
Definition vulkan.hpp:2788
Implements a Vulkan frame buffer.
Definition vulkan.hpp:2071
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:2207
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:2199
static SharedPtr< VulkanFrameBuffer > create(const VulkanDevice &device, const Size2d &renderArea, allocation_callback_type allocationCallback, StringView name="")
Initializes a Vulkan frame buffer.
Definition vulkan.hpp:2137
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:2212
Represents a Vulkan IGraphicsAdapter.
Definition vulkan_api.hpp:232
A graphics factory that produces objects for a VulkanDevice.
Definition vulkan.hpp:2548
Implements a Vulkan IImage.
Definition image.h:16
Implements a Vulkan index buffer layout.
Definition vulkan.hpp:119
static auto create(const VulkanIndexBufferLayout &other)
Creates a copy of an index buffer layout.
Definition vulkan.hpp:162
Implements the Vulkan input assembler state.
Definition vulkan.hpp:1253
static auto create(const VulkanInputAssembler &other)
Creates a new Vulkan input assembler state as a copy from another one.
Definition vulkan.hpp:1306
Implements a Vulkan PipelineLayout.
Definition vulkan.hpp:1169
Defines the base class for Vulkan pipeline state objects.
Definition vulkan.hpp:1431
VulkanPipelineState(VulkanPipelineState &&) noexcept=default
Implements the Vulkan PushConstantsLayout.
Definition vulkan.hpp:1119
VulkanPushConstantsLayout(VulkanPushConstantsLayout &&) noexcept
Implements the Vulkan IPushConstantsRange.
Definition vulkan.hpp:1067
VulkanPushConstantsRange(VulkanPushConstantsRange &&) noexcept
Implements a Vulkan command queue.
Definition vulkan.hpp:1720
Implements a Vulkan IRasterizer.
Definition vulkan.hpp:1337
static auto create(const VulkanRasterizer &other)
Creates a new Vulkan rasterizer state by copying an existing one.
Definition vulkan.hpp:1397
Implements a Vulkan RayTracingPipeline.
Definition vulkan.hpp:1992
VulkanRayTracingPipeline(VulkanRayTracingPipeline &&) noexcept
Implements a Vulkan render pass.
Definition vulkan.hpp:2233
static SharedPtr< VulkanRenderPass > create(const VulkanDevice &device, const String &name, Span< RenderTarget > renderTargets, Span< RenderPassDependency > inputAttachments={ }, Optional< DescriptorBindingPoint > inputAttachmentSamplerBinding=std::nullopt, UInt32 secondaryCommandBuffers=1u, UInt32 viewMask=0b0000)
Creates and initializes a new Vulkan render pass instance that executes on the default graphics queue...
Definition vulkan.hpp:2333
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, UInt32 viewMask=0b0000)
Creates and initializes a new Vulkan render pass instance.
Definition vulkan.hpp:2364
static SharedPtr< VulkanRenderPass > create(const VulkanDevice &device, const VulkanQueue &queue, Span< RenderTarget > renderTargets, Span< RenderPassDependency > inputAttachments={ }, Optional< DescriptorBindingPoint > inputAttachmentSamplerBinding=std::nullopt, UInt32 secondaryCommandBuffers=1u, UInt32 viewMask=0b0000)
Creates and initializes a new Vulkan render pass instance.
Definition vulkan.hpp:2348
Implements a Vulkan RenderPipeline.
Definition vulkan.hpp:1854
VulkanRenderPipeline(VulkanRenderPipeline &&) noexcept=delete
Implements a Vulkan IShaderModule.
Definition vulkan.hpp:575
VulkanShaderModule(VulkanShaderModule &&) noexcept
Implements a Vulkan ShaderProgram.
Definition vulkan.hpp:649
VulkanShaderProgram(VulkanShaderProgram &&) noexcept=delete
Represents a Vulkan ISurface.
Definition vulkan_api.hpp:334
Implements a Vulkan swap chain.
Definition vulkan.hpp:2444
VulkanSwapChain(VulkanSwapChain &&) noexcept=delete
Implements a Vulkan top-level acceleration structure (TLAS).
Definition vulkan.hpp:406
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, VertexBufferInputRate inputRate=VertexBufferInputRate::Vertex)
Creates a new vertex buffer layout.
Definition vulkan.hpp:81
static auto create(const VulkanVertexBufferLayout &other)
Creates a copy of a vertex buffer layout.
Definition vulkan.hpp:90
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:619
Represents a command queue.
Definition rendering.hpp:1113
Represents a compute Pipeline.
Definition rendering.hpp:1023
Stores the depth/stencil state of a see IRasterizer.
Definition rendering_api.hpp:3751
Defines a set of descriptors.
Definition rendering.hpp:150
Describes the layout of a descriptor set.
Definition rendering.hpp:237
A class that can be used to manage the state of a IGraphicsDevice.
Definition rendering_api.hpp:2697
Stores the images used by a RenderPass to either read from using input attachments or write to using ...
Definition rendering.hpp:1079
IFrameBuffer::allocation_callback_type< image_type > allocation_callback_type
Definition rendering.hpp:1082
Represents the graphics device that a rendering back-end is doing work on.
Definition rendering.hpp:1538
Describes a factory that creates objects for a GraphicsDevice.
Definition rendering.hpp:1277
Base interface for a ray tracing acceleration structure.
Definition rendering_api.hpp:5260
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:5341
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:5305
A structure that holds a singular entity of geometry for hardware ray-tracing.
Definition rendering_api.hpp:5399
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:5618
Base interface for buffer objects.
Definition rendering_api.hpp:4997
The interface for a command buffer.
Definition rendering_api.hpp:7682
The interface for a command queue.
Definition rendering_api.hpp:9742
Describes a the layout of a single descriptor within a DescriptorSet.
Definition rendering_api.hpp:4641
The interface for a descriptor set.
Definition rendering_api.hpp:6064
std::function< SharedPtr< const TImage >(Optional< UInt64 >, Size2d, ResourceUsage, Format, MultiSamplingLevel, const String &)> allocation_callback_type
A function that gets invoked as a callback, if the frame buffer needs to allocate an image.
Definition rendering_api.hpp:8925
The interface for a graphics device that.
Definition rendering_api.hpp:11050
Describes a generic image.
Definition rendering_api.hpp:5019
Describes a index buffer layout.
Definition rendering_api.hpp:4603
Describes a range within a IPushConstantsLayout.
Definition rendering_api.hpp:6561
Describes a texture sampler.
Definition rendering_api.hpp:5135
The interface of a scissor.
Definition rendering_api.hpp:4207
Represents a single shader module, i.e. a part of a IShaderProgram.
Definition rendering_api.hpp:3363
A structure that stores the instance data for a IBottomLevelAccelerationStructure.
Definition rendering_api.hpp:5681
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:5827
Describes a vertex buffer layout.
Definition rendering_api.hpp:4574
Interface for a viewport.
Definition rendering_api.hpp:4089
Describes an index buffer.
Definition rendering.hpp:501
Represents a the input assembler state of a RenderPipeline.
Definition rendering.hpp:528
Represents a pipeline state.
Definition rendering.hpp:569
Represents a the layout of a RenderPipeline, ComputePipeline or RayTracingPipeline.
Definition rendering.hpp:440
Describes the layout of the pipelines push constant ranges.
Definition rendering.hpp:377
Implements a IRasterizer.
Definition rendering_api.hpp:4006
Represents a ray-tracing Pipeline.
Definition rendering.hpp:1042
Defines a back-end, that provides a device instance for a certain surface and graphics adapter.
Definition rendering.hpp:1796
Represents a mapping between a set of RenderTarget instances and the input attachments of a IRenderPa...
Definition rendering_api.hpp:3684
Represents a render pass.
Definition rendering.hpp:1173
Represents a graphics Pipeline.
Definition rendering.hpp:984
Implements a render target.
Definition rendering_api.hpp:3584
Represents a shader program, consisting of multiple IShaderModules.
Definition rendering.hpp:408
Stores a set of IShaderRecords in that later form a shader binding table used for ray-tracing.
Definition rendering_api.hpp:6923
Base class for a resource that can be identified by a name string within a DeviceState.
Definition rendering_api.hpp:2650
Represents a swap chain, i.e. a chain of multiple IImage instances, that can be presented to a ISurfa...
Definition rendering.hpp:1233
An event that is used to measure timestamps in a command queue.
Definition rendering_api.hpp:4371
Describes a vertex buffer.
Definition rendering.hpp:477
Represents a virtual allocator that manages memory distribution from a piece of raw memory.
Definition rendering_api.hpp:3032
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:71
float_t Float
A type for a floating point value with single precision.
Definition math.hpp:76
uint32_t UInt32
A type for an unsigned 32 bit integer.
Definition math.hpp:61
int32_t Int32
A type for a signed 32 bit integer.
Definition math.hpp:56
std::byte Byte
A type for a single byte of raw memory.
Definition math.hpp:36
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:1356
CullOrder
Describes the order or vertex winding, that is used to determine, whether a polygon is facing towards...
Definition rendering_api.hpp:1190
DescriptorHeapType
The target heap type for a descriptor.
Definition rendering_api.hpp:580
@ Resource
Binds all non-sampler resource views.
ImageLayout
Specifies the layout of an IImage resource.
Definition rendering_api.hpp:1858
MipMapMode
Describes the filter operation between two mip-map levels.
Definition rendering_api.hpp:1341
CullMode
Describes which faces are culled by the Rasterizer stage.
Definition rendering_api.hpp:1163
ShaderStage
Describes the valid shader stages of a graphics pipeline.
Definition rendering_api.hpp:971
IndexType
Describes the element type of an index buffer.
Definition rendering_api.hpp:906
PrimitiveTopology
Describes the topology of a mesh primitive.
Definition rendering_api.hpp:937
@ 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:1111
@ 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:1142
BufferType
Describes the type of a IBuffer.
Definition rendering_api.hpp:601
DefragmentationStrategy
The strategy to apply to a defragmentation pass.
Definition rendering_api.hpp:886
ResourceUsage
Describes the intended usage for a resource.
Definition rendering_api.hpp:761
ImageDimensions
Describes the dimensions of a image resource, i.e. the dimensions that are required to access a texel...
Definition rendering_api.hpp:1258
AllocationAlgorithm
The allocation algorithm used by VirtualAllocators.
Definition rendering_api.hpp:852
DescriptorType
Describes the type of a IDescriptor.
Definition rendering_api.hpp:442
QueuePriority
Specifies the priority with which a queue is scheduled on the GPU.
Definition rendering_api.hpp:160
@ Normal
The default queue priority.
QueueType
Represents the type of a CommandQueue.
Definition rendering_api.hpp:114
ResourceHeap
Defines where a resource (buffer or image) memory is located and from where it can be accessed.
Definition rendering_api.hpp:710
AccelerationStructureFlags
Controls how an acceleration structure should be built.
Definition rendering_api.hpp:1988
FilterMode
Describes the filter operation when accessing a pixel from a texture coordinate.
Definition rendering_api.hpp:1324
AllocationBehavior
Controls the allocation behavior of IGraphicsFactory.
Definition rendering_api.hpp:830
VertexBufferInputRate
The rate at which a vertex buffer of a certain IVertexBufferLayout is made available for vertex shade...
Definition rendering_api.hpp:922
PipelineStage
Defines pipeline stages as points where synchronization may occur.
Definition rendering_api.hpp:1545
ResourceAccess
Defines how a IBuffer or IImage resource is accessed.
Definition rendering_api.hpp:1709
Format
Describes a texel format.
Definition rendering_api.hpp:183
MultiSamplingLevel
Describes the number of samples with which a IImage is sampled.
Definition rendering_api.hpp:1283
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
Definition sample.cpp:21
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:6218
Describes a single descriptor binding point within a IShaderModule.
Definition rendering_api.hpp:3309
Stores extended memory statistics, that can be queried by calling IGraphicsFactory::detailedMemorySta...
Definition rendering_api.hpp:10040
Describes optional features that can be supported by a device.
Definition rendering_api.hpp:10983
Stores a buffer that contains axis-aligned bounding boxes.
Definition rendering_api.hpp:5481
Represents a triangle mesh.
Definition rendering_api.hpp:5404
Represents an instance of an IBottomLevelAccelerationStructure.
Definition rendering_api.hpp:5688
Stores simple memory heap statistics, that can be quickly queried by calling IGraphicsFactory::memory...
Definition rendering_api.hpp:9985
A hint used during shader reflection to control the pipeline layout.
Definition rendering_api.hpp:7174
Describes the offsets and sizes of a shader group within a shader binding table buffer.
Definition rendering_api.hpp:4291
An allocator used to allocate the shared object.
Definition containers.hpp:1098
Definition alloc_buffer.cpp:13