LiteFX 0.5.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
dx12.hpp
1#pragma once
2
3#include <litefx/rendering.hpp>
4
5#include "dx12_api.hpp"
6#include "dx12_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_DIRECTX12_API DirectX12VertexBufferLayout final : public IVertexBufferLayout {
22 LITEFX_IMPLEMENTATION(DirectX12VertexBufferLayoutImpl);
23 LITEFX_BUILDER(DirectX12VertexBufferLayoutBuilder);
25
26 private:
33 explicit DirectX12VertexBufferLayout(size_t vertexSize, UInt32 binding = 0, VertexBufferInputRate inputRate = VertexBufferInputRate::Vertex);
34
42 explicit DirectX12VertexBufferLayout(size_t vertexSize, const Enumerable<BufferAttribute>& attributes, UInt32 binding = 0, VertexBufferInputRate inputRate = VertexBufferInputRate::Vertex);
43
44 private:
47
50
52 DirectX12VertexBufferLayout& operator=(DirectX12VertexBufferLayout&&) noexcept = delete;
53
56
57 public:
59 ~DirectX12VertexBufferLayout() noexcept override;
60
61 public:
69 static inline auto create(size_t vertexSize, UInt32 binding = 0, VertexBufferInputRate inputRate = VertexBufferInputRate::Vertex) {
70 return SharedObject::create<DirectX12VertexBufferLayout>(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<DirectX12VertexBufferLayout>(vertexSize, attributes, binding, inputRate);
83 }
84
90 static inline auto create(const DirectX12VertexBufferLayout& 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_DIRECTX12_API DirectX12IndexBufferLayout final : public IIndexBufferLayout {
120 LITEFX_IMPLEMENTATION(DirectX12IndexBufferLayoutImpl);
122
123 private:
129
130 private:
133
136
138 DirectX12IndexBufferLayout& operator=(DirectX12IndexBufferLayout&&) noexcept = delete;
139
141 DirectX12IndexBufferLayout& operator=(const DirectX12IndexBufferLayout&) = delete;
142
143 public:
145 ~DirectX12IndexBufferLayout() noexcept override;
146
147 public:
153 static inline auto create(IndexType type) {
155 }
156
162 static inline auto create(const DirectX12IndexBufferLayout& 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_DIRECTX12_API IDirectX12Buffer : public virtual IBuffer, public virtual IResource<ComPtr<ID3D12Resource>> {
191 protected:
192 IDirectX12Buffer() noexcept = default;
193 IDirectX12Buffer(IDirectX12Buffer&&) noexcept = default;
195 IDirectX12Buffer& operator=(IDirectX12Buffer&&) noexcept = default;
196 IDirectX12Buffer& operator=(const IDirectX12Buffer&) = delete;
197
198 public:
199 ~IDirectX12Buffer() noexcept override = default;
200 };
201
207 class LITEFX_DIRECTX12_API IDirectX12VertexBuffer : public virtual VertexBuffer<DirectX12VertexBufferLayout>, public virtual IDirectX12Buffer {
208 protected:
209 IDirectX12VertexBuffer() noexcept = default;
212 IDirectX12VertexBuffer& operator=(IDirectX12VertexBuffer&&) noexcept = default;
214
215 public:
216 ~IDirectX12VertexBuffer() noexcept override = default;
217
218 public:
219 virtual const D3D12_VERTEX_BUFFER_VIEW& view() const noexcept = 0;
220 };
221
227 class LITEFX_DIRECTX12_API IDirectX12IndexBuffer : public virtual IndexBuffer<DirectX12IndexBufferLayout>, public virtual IDirectX12Buffer {
228 protected:
229 IDirectX12IndexBuffer() noexcept = default;
232 IDirectX12IndexBuffer& operator=(IDirectX12IndexBuffer&&) noexcept = default;
233 IDirectX12IndexBuffer& operator=(const IDirectX12IndexBuffer&) = delete;
234
235 public:
236 ~IDirectX12IndexBuffer() noexcept override = default;
237
238 public:
239 virtual const D3D12_INDEX_BUFFER_VIEW& view() const noexcept = 0;
240 };
241
249 class LITEFX_DIRECTX12_API IDirectX12Image : public virtual IImage, public virtual IResource<ComPtr<ID3D12Resource>> {
250 protected:
251 IDirectX12Image() noexcept = default;
252 IDirectX12Image(IDirectX12Image&&) noexcept = default;
254 IDirectX12Image& operator=(IDirectX12Image&&) noexcept = default;
255 IDirectX12Image& operator=(const IDirectX12Image&) = delete;
256
257 public:
258 ~IDirectX12Image() noexcept override = default;
259 };
260
268 class LITEFX_DIRECTX12_API IDirectX12Sampler : public virtual ISampler {
269 protected:
270 IDirectX12Sampler() noexcept = default;
273 IDirectX12Sampler& operator=(IDirectX12Sampler&&) noexcept = default;
274 IDirectX12Sampler& operator=(const IDirectX12Sampler&) = delete;
275
276 public:
277 ~IDirectX12Sampler() noexcept override = default;
278 };
279
297
304 friend class DirectX12Device;
306
310
311 public:
319 explicit DirectX12BottomLevelAccelerationStructure(AccelerationStructureFlags flags = AccelerationStructureFlags::None, StringView name = "");
320
323
326
329
332
335
336 // IAccelerationStructure interface.
337 public:
339 AccelerationStructureFlags flags() const noexcept override;
340
342 SharedPtr<const IDirectX12Buffer> buffer() const noexcept;
343
345 void build(const DirectX12CommandBuffer& commandBuffer, const SharedPtr<const IDirectX12Buffer>& scratchBuffer = nullptr, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
346
348 void update(const DirectX12CommandBuffer& commandBuffer, const SharedPtr<const IDirectX12Buffer>& scratchBuffer = nullptr, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
349
351 void copy(const DirectX12CommandBuffer& commandBuffer, DirectX12BottomLevelAccelerationStructure& destination, bool compress = false, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, bool copyBuildInfo = true) const;
352
354 UInt64 offset() const noexcept override;
355
357 UInt64 size() const noexcept override;
358
359 // IBottomLevelAccelerationStructure interface.
360 public:
362 const Array<TriangleMesh>& triangleMeshes() const noexcept override;
363
365 void addTriangleMesh(const TriangleMesh& mesh) override;
366
368 const Array<BoundingBoxes>& boundingBoxes() const noexcept override;
369
371 void addBoundingBox(const BoundingBoxes& aabb) override;
372
374 void clear() noexcept override;
375
377 bool remove(const TriangleMesh& mesh) noexcept override;
378
380 bool remove(const BoundingBoxes& aabb) noexcept override;
381
382 private:
383 Array<D3D12_RAYTRACING_GEOMETRY_DESC> buildInfo() const;
384
385 private:
386 SharedPtr<const IBuffer> getBuffer() const noexcept override;
387 void doBuild(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
388 void doUpdate(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
389 void doCopy(const ICommandBuffer& commandBuffer, IBottomLevelAccelerationStructure& destination, bool compress, const SharedPtr<const IBuffer>& buffer, UInt64 offset, bool copyBuildInfo) const override;
390 };
391
396 class LITEFX_DIRECTX12_API DirectX12TopLevelAccelerationStructure final : public ITopLevelAccelerationStructure, public virtual StateResource, public virtual IDirectX12AccelerationStructure {
397 LITEFX_IMPLEMENTATION(DirectX12TopLevelAccelerationStructureImpl);
398 friend class DirectX12Device;
400
404
405 public:
413 explicit DirectX12TopLevelAccelerationStructure(AccelerationStructureFlags flags = AccelerationStructureFlags::None, StringView name = "");
414
417
420
423
426
429
430 // IAccelerationStructure interface.
431 public:
433 AccelerationStructureFlags flags() const noexcept override;
434
436 SharedPtr<const IDirectX12Buffer> buffer() const noexcept;
437
439 void build(const DirectX12CommandBuffer& commandBuffer, const SharedPtr<const IDirectX12Buffer>& scratchBuffer = nullptr, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
440
442 void update(const DirectX12CommandBuffer& commandBuffer, const SharedPtr<const IDirectX12Buffer>& scratchBuffer = nullptr, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
443
445 void copy(const DirectX12CommandBuffer& commandBuffer, DirectX12TopLevelAccelerationStructure& destination, bool compress = false, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, bool copyBuildInfo = true) const;
446
448 UInt64 offset() const noexcept override;
449
451 UInt64 size() const noexcept override;
452
453 // ITopLevelAccelerationStructure interface.
454 public:
456 const Array<Instance>& instances() const noexcept override;
457
459 void addInstance(const Instance& instance) override;
460
462 void clear() noexcept override;
463
465 bool remove(const Instance& instance) noexcept override;
466
467 private:
468 Array<D3D12_RAYTRACING_INSTANCE_DESC> buildInfo() const;
469
470 private:
471 SharedPtr<const IBuffer> getBuffer() const noexcept override;
472 void doBuild(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
473 void doUpdate(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
474 void doCopy(const ICommandBuffer& commandBuffer, ITopLevelAccelerationStructure& destination, bool compress, const SharedPtr<const IBuffer>& buffer, UInt64 offset, bool copyBuildInfo) const override;
475 };
476
484 class LITEFX_DIRECTX12_API DirectX12Barrier final : public Barrier<IDirectX12Buffer, IDirectX12Image> {
485 LITEFX_IMPLEMENTATION(DirectX12BarrierImpl);
486 LITEFX_BUILDER(DirectX12BarrierBuilder);
487
488 public:
490 using base_type::transition;
491
492 public:
498 explicit DirectX12Barrier(PipelineStage syncBefore, PipelineStage syncAfter) noexcept;
499
502
505
507 DirectX12Barrier& operator=(DirectX12Barrier&&) noexcept;
508
511
513 ~DirectX12Barrier() noexcept override;
514
515 private:
516 explicit DirectX12Barrier() noexcept;
517 PipelineStage& syncBefore() noexcept;
518 PipelineStage& syncAfter() noexcept;
519
520 // Barrier interface.
521 public:
523 PipelineStage syncBefore() const noexcept override;
524
526 PipelineStage syncAfter() const noexcept override;
527
529 void wait(ResourceAccess accessBefore, ResourceAccess accessAfter) override;
530
532 void transition(const IDirectX12Buffer& buffer, ResourceAccess accessBefore, ResourceAccess accessAfter) override;
533
535 void transition(const IDirectX12Buffer& buffer, UInt32 element, ResourceAccess accessBefore, ResourceAccess accessAfter) override;
536
538 void transition(const IDirectX12Image& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) override;
539
541 void transition(const IDirectX12Image& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) override;
542
544 void transition(const IDirectX12Image& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) override;
545
547 void transition(const IDirectX12Image& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) override;
548
549 public:
555 void execute(const DirectX12CommandBuffer& commandBuffer) const;
556 };
557
563 class LITEFX_DIRECTX12_API DirectX12ShaderModule final : public IShaderModule, public ComResource<IDxcBlob> {
564 LITEFX_IMPLEMENTATION(DirectX12ShaderModuleImpl);
565
566 public:
575 explicit DirectX12ShaderModule(const DirectX12Device& device, ShaderStage type, const String& fileName, const String& entryPoint = "main", const Optional<DescriptorBindingPoint>& shaderLocalDescriptor = std::nullopt);
576
586 explicit DirectX12ShaderModule(const DirectX12Device& device, ShaderStage type, std::istream& stream, const String& name, const String& entryPoint = "main", const Optional<DescriptorBindingPoint>& shaderLocalDescriptor = std::nullopt);
587
590
593
596
598 DirectX12ShaderModule& operator=(const DirectX12ShaderModule&) = delete;
599
601 ~DirectX12ShaderModule() noexcept override;
602
603 // IShaderModule interface.
604 public:
606 const String& fileName() const noexcept override;
607
609 const String& entryPoint() const noexcept override;
610
612 ShaderStage type() const noexcept override;
613
615 const Optional<DescriptorBindingPoint>& shaderLocalDescriptor() const noexcept override;
616 };
617
623 class LITEFX_DIRECTX12_API DirectX12ShaderProgram final : public ShaderProgram<DirectX12ShaderModule> {
624 LITEFX_IMPLEMENTATION(DirectX12ShaderProgramImpl);
625 LITEFX_BUILDER(DirectX12ShaderProgramBuilder);
627
628 private:
635
640 explicit DirectX12ShaderProgram(const DirectX12Device& device) noexcept;
641
642 private:
645
648
650 DirectX12ShaderProgram& operator=(DirectX12ShaderProgram&&) noexcept = delete;
651
653 DirectX12ShaderProgram& operator=(const DirectX12ShaderProgram&) = delete;
654
655 public:
657 ~DirectX12ShaderProgram() noexcept override;
658
659 // Factory method.
660 public:
667 static inline auto create(const DirectX12Device& device, Enumerable<UniquePtr<DirectX12ShaderModule>>&& modules) -> SharedPtr<DirectX12ShaderProgram> {
668 return SharedObject::create<DirectX12ShaderProgram>(device, std::move(modules));
669 }
670
671 private:
676 static inline auto create(const DirectX12Device& device) {
678 }
679
680 public:
682 const Array<UniquePtr<const DirectX12ShaderModule>>& modules() const noexcept override;
683
685 virtual SharedPtr<DirectX12PipelineLayout> reflectPipelineLayout(Enumerable<PipelineBindingHint> hints = {}) const;
686
687 private:
688 SharedPtr<IPipelineLayout> parsePipelineLayout(Enumerable<PipelineBindingHint> hints) const override {
689 return std::static_pointer_cast<IPipelineLayout>(this->reflectPipelineLayout(hints));
690 }
691 };
692
697 class LITEFX_DIRECTX12_API DirectX12DescriptorSet final : public DescriptorSet<IDirectX12Buffer, IDirectX12Image, IDirectX12Sampler, IDirectX12AccelerationStructure> {
698 LITEFX_IMPLEMENTATION(DirectX12DescriptorSetImpl);
699
700 public:
702 using base_type::update;
703
704 public:
711 explicit DirectX12DescriptorSet(const DirectX12DescriptorSetLayout& layout, ComPtr<ID3D12DescriptorHeap>&& resourceHeap = nullptr, ComPtr<ID3D12DescriptorHeap>&& samplerHeap = nullptr);
712
715
718
720 DirectX12DescriptorSet& operator=(DirectX12DescriptorSet&&) noexcept = delete;
721
724
726 ~DirectX12DescriptorSet() noexcept override;
727
728 public:
733 virtual const DirectX12DescriptorSetLayout& layout() const noexcept;
734
735 public:
737 VirtualAllocator::Allocation globalHeapAllocation(DescriptorHeapType heapType) const noexcept override;
738
740 UInt32 bindToHeap(DescriptorType bindingType, UInt32 descriptor, const IDirectX12Buffer& buffer, UInt32 bufferElement = 0, UInt32 elements = 0, Format texelFormat = Format::None) const override;
741
743 UInt32 bindToHeap(DescriptorType bindingType, UInt32 descriptor, const IDirectX12Image& image, UInt32 firstLevel = 0, UInt32 levels = 0, UInt32 firstLayer = 0, UInt32 layers = 0) const override;
744
746 UInt32 bindToHeap(UInt32 descriptor, const IDirectX12Sampler& sampler) const override;
747
749 void update(UInt32 binding, const IDirectX12Buffer& buffer, UInt32 bufferElement = 0, UInt32 elements = 0, UInt32 firstDescriptor = 0, Format texelFormat = Format::None) const override;
750
752 void update(UInt32 binding, const IDirectX12Image& texture, UInt32 descriptor = 0, UInt32 firstLevel = 0, UInt32 levels = 0, UInt32 firstLayer = 0, UInt32 layers = 0) const override;
753
755 void update(UInt32 binding, const IDirectX12Sampler& sampler, UInt32 descriptor = 0) const override;
756
758 void update(UInt32 binding, const IDirectX12AccelerationStructure& accelerationStructure, UInt32 descriptor = 0) const override;
759
760 public:
766 virtual const ComPtr<ID3D12DescriptorHeap> localHeap(DescriptorHeapType heapType) const noexcept;
767 };
768
777 class LITEFX_DIRECTX12_API DirectX12DescriptorLayout final : public IDescriptorLayout {
778 LITEFX_IMPLEMENTATION(DirectX12DescriptorLayoutImpl);
779
780 public:
790 DirectX12DescriptorLayout(DescriptorType type, UInt32 binding, size_t elementSize, UInt32 descriptors = 1, bool unbounded = false, bool local = false);
791
798 DirectX12DescriptorLayout(const IDirectX12Sampler& staticSampler, UInt32 binding, bool local = false);
799
802
805
808
811
813 ~DirectX12DescriptorLayout() noexcept override;
814
815 // DirectX 12 descriptor layout.
816 public:
824 bool local() const noexcept;
825
826 // IDescriptorLayout interface.
827 public:
829 DescriptorType descriptorType() const noexcept override;
830
832 UInt32 descriptors() const noexcept override;
833
835 bool unbounded() const noexcept override;
836
838 const IDirectX12Sampler* staticSampler() const noexcept override;
839
840 // IBufferLayout interface.
841 public:
843 size_t elementSize() const noexcept override;
844
846 UInt32 binding() const noexcept override;
847
849 BufferType type() const noexcept override;
850 };
851
858 LITEFX_IMPLEMENTATION(DirectX12DescriptorSetLayoutImpl);
859 LITEFX_BUILDER(DirectX12DescriptorSetLayoutBuilder);
862
863 public:
865 using base_type::free;
866 using base_type::allocate;
867
868 private:
876 explicit DirectX12DescriptorSetLayout(const DirectX12Device& device, const Enumerable<DirectX12DescriptorLayout>& descriptorLayouts, UInt32 space, ShaderStage stages);
877
882 explicit DirectX12DescriptorSetLayout(const DirectX12Device& device);
883
884 private:
887
890
892 DirectX12DescriptorSetLayout& operator=(DirectX12DescriptorSetLayout&&) noexcept = delete;
893
896
897 public:
899 ~DirectX12DescriptorSetLayout() noexcept override;
900
901 public:
910 static inline auto create(const DirectX12Device& device, const Enumerable<DirectX12DescriptorLayout>& descriptorLayouts, UInt32 space, ShaderStage stages) {
911 return SharedObject::create<DirectX12DescriptorSetLayout>(device, descriptorLayouts, space, stages);
912 }
913
919 static inline auto create(const DirectX12DescriptorSetLayout& other) {
921 }
922
923 private:
929 static inline auto create(const DirectX12Device& device) {
931 }
932
933 public:
938 virtual SharedPtr<const DirectX12Device> device() const noexcept;
939
940 public:
942 const Array<DirectX12DescriptorLayout>& descriptors() const noexcept override;
943
945 const DirectX12DescriptorLayout& descriptor(UInt32 binding) const override;
946
948 UInt32 space() const noexcept override;
949
951 ShaderStage shaderStages() const noexcept override;
952
954 UInt32 uniforms() const noexcept override;
955
957 UInt32 storages() const noexcept override;
958
960 UInt32 images() const noexcept override;
961
963 UInt32 buffers() const noexcept override;
964
966 UInt32 samplers() const noexcept override;
967
969 UInt32 staticSamplers() const noexcept override;
970
972 UInt32 inputAttachments() const noexcept override;
973
975 bool containsUnboundedArray() const noexcept override;
976
978 UInt32 getDescriptorOffset(UInt32 binding, UInt32 element = 0) const override;
979
981 bool bindsResources() const noexcept override;
982
984 bool bindsSamplers() const noexcept override;
985
986 public:
988 UniquePtr<DirectX12DescriptorSet> allocate(UInt32 descriptors, std::initializer_list<DescriptorBinding> bindings) const override;
989
991 UniquePtr<DirectX12DescriptorSet> allocate(UInt32 descriptors, Span<DescriptorBinding> bindings) const override;
992
994 UniquePtr<DirectX12DescriptorSet> allocate(UInt32 descriptors, Generator<DescriptorBinding> bindings) const override;
995
997 Generator<UniquePtr<DirectX12DescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::initializer_list<std::initializer_list<DescriptorBinding>> bindings = { }) const override;
998
999#ifdef __cpp_lib_mdspan
1001 Generator<UniquePtr<DirectX12DescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::mdspan<DescriptorBinding, std::dextents<size_t, 2>> bindings) const override;
1002#endif
1003
1005 Generator<UniquePtr<DirectX12DescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::function<Generator<DescriptorBinding>(UInt32)> bindingFactory) const override;
1006
1008 void free(const DirectX12DescriptorSet& descriptorSet) const override;
1009 };
1010
1015 class LITEFX_DIRECTX12_API DirectX12PushConstantsRange final : public IPushConstantsRange {
1016 LITEFX_IMPLEMENTATION(DirectX12PushConstantsRangeImpl);
1018
1019 public:
1028 explicit DirectX12PushConstantsRange(ShaderStage shaderStages, UInt32 offset, UInt32 size, UInt32 space, UInt32 binding);
1029
1032
1035
1038
1041
1043 ~DirectX12PushConstantsRange() noexcept override;
1044
1045 public:
1047 UInt32 space() const noexcept override;
1048
1050 UInt32 binding() const noexcept override;
1051
1053 UInt32 offset() const noexcept override;
1054
1056 UInt32 size() const noexcept override;
1057
1059 ShaderStage stage() const noexcept override;
1060 };
1061
1074 LITEFX_IMPLEMENTATION(DirectX12PushConstantsLayoutImpl);
1075 LITEFX_BUILDER(DirectX12PushConstantsLayoutBuilder);
1077
1078 public:
1085
1088
1091
1094
1097
1099 ~DirectX12PushConstantsLayout() noexcept override;
1100
1101 private:
1106 explicit DirectX12PushConstantsLayout(UInt32 size);
1107
1108 public:
1110 UInt32 size() const noexcept override;
1111
1113 const DirectX12PushConstantsRange& range(ShaderStage stage) const override;
1114
1116 const Array<UniquePtr<DirectX12PushConstantsRange>>& ranges() const override;
1117
1118 protected:
1124 };
1125
1130 class LITEFX_DIRECTX12_API DirectX12PipelineLayout final : public PipelineLayout<DirectX12DescriptorSetLayout, DirectX12PushConstantsLayout>, public ComResource<ID3D12RootSignature> {
1131 LITEFX_IMPLEMENTATION(DirectX12PipelineLayoutImpl);
1132 LITEFX_BUILDER(DirectX12PipelineLayoutBuilder);
1134
1135 private:
1142 explicit DirectX12PipelineLayout(const DirectX12Device& device, const Enumerable<SharedPtr<DirectX12DescriptorSetLayout>>& descriptorSetLayouts, UniquePtr<DirectX12PushConstantsLayout>&& pushConstantsLayout);
1143
1148 explicit DirectX12PipelineLayout(const DirectX12Device& device);
1149
1150 private:
1153
1156
1158 DirectX12PipelineLayout& operator=(DirectX12PipelineLayout&&) noexcept = delete;
1159
1161 DirectX12PipelineLayout& operator=(const DirectX12PipelineLayout&) = delete;
1162
1163 public:
1165 ~DirectX12PipelineLayout() noexcept override;
1166
1167 public:
1175 static inline auto create(const DirectX12Device& device, const Enumerable<SharedPtr<DirectX12DescriptorSetLayout>>& descriptorSetLayouts, UniquePtr<DirectX12PushConstantsLayout>&& pushConstantsLayout) {
1176 return SharedObject::create<DirectX12PipelineLayout>(device, descriptorSetLayouts, std::move(pushConstantsLayout));
1177 }
1178
1179 private:
1185 static inline auto create(const DirectX12Device& device) {
1187 }
1188
1189 // PipelineLayout interface.
1190 public:
1192 const DirectX12Device& device() const noexcept /*override*/;
1193
1195 const DirectX12DescriptorSetLayout& descriptorSet(UInt32 space) const override;
1196
1198 const Array<SharedPtr<const DirectX12DescriptorSetLayout>>& descriptorSets() const override;
1199
1201 const DirectX12PushConstantsLayout* pushConstants() const noexcept override;
1202
1204 bool dynamicResourceHeapAccess() const override;
1205
1207 bool dynamicSamplerHeapAccess() const override;
1208
1209 public:
1230 Optional<UInt32> rootParameterIndex(const DirectX12DescriptorSetLayout& layout, DescriptorHeapType heapType) const noexcept;
1231
1241 Optional<UInt32> rootParameterIndex(const DirectX12PushConstantsRange& range) const noexcept;
1242 };
1243
1249 LITEFX_IMPLEMENTATION(DirectX12InputAssemblerImpl);
1250 LITEFX_BUILDER(DirectX12InputAssemblerBuilder);
1252
1253 private:
1260 explicit DirectX12InputAssembler(Enumerable<SharedPtr<DirectX12VertexBufferLayout>>&& vertexBufferLayouts, SharedPtr<DirectX12IndexBufferLayout>&& indexBufferLayout, PrimitiveTopology primitiveTopology = PrimitiveTopology::TriangleList);
1261
1265 explicit DirectX12InputAssembler();
1266
1267 private:
1270
1273
1275 DirectX12InputAssembler& operator=(DirectX12InputAssembler&&) noexcept;
1276
1278 DirectX12InputAssembler& operator=(const DirectX12InputAssembler&) = delete;
1279
1280 public:
1282 ~DirectX12InputAssembler() noexcept override;
1283
1284 public:
1292 static inline auto create(Enumerable<SharedPtr<DirectX12VertexBufferLayout>>&& vertexBufferLayouts, SharedPtr<DirectX12IndexBufferLayout>&& indexBufferLayout, PrimitiveTopology primitiveTopology = PrimitiveTopology::TriangleList) {
1293 return SharedObject::create<DirectX12InputAssembler>(std::move(vertexBufferLayouts), std::move(indexBufferLayout), primitiveTopology);
1294 }
1295
1301 static inline auto create(const DirectX12InputAssembler& other) {
1303 }
1304
1305 private:
1310 static inline auto create() {
1312 }
1313
1314 public:
1316 Enumerable<const DirectX12VertexBufferLayout&> vertexBufferLayouts() const override;
1317
1319 const DirectX12VertexBufferLayout& vertexBufferLayout(UInt32 binding) const override;
1320
1322 const DirectX12IndexBufferLayout* indexBufferLayout() const noexcept override;
1323
1325 PrimitiveTopology topology() const noexcept override;
1326 };
1327
1332 class LITEFX_DIRECTX12_API DirectX12Rasterizer final : public Rasterizer {
1333 LITEFX_BUILDER(DirectX12RasterizerBuilder);
1335
1336 private:
1347 explicit DirectX12Rasterizer(PolygonMode polygonMode, CullMode cullMode, CullOrder cullOrder, Float lineWidth = 1.f, bool depthClip = true, const DepthStencilState& depthStencilState = {}, bool conservativeRasterization = false) noexcept;
1348
1352 explicit DirectX12Rasterizer() noexcept;
1353
1354 private:
1356 DirectX12Rasterizer(DirectX12Rasterizer&&) noexcept = delete;
1357
1359 DirectX12Rasterizer(const DirectX12Rasterizer&) = default;
1360
1362 DirectX12Rasterizer& operator=(DirectX12Rasterizer&&) noexcept = delete;
1363
1365 DirectX12Rasterizer& operator=(const DirectX12Rasterizer&) = delete;
1366
1367 public:
1369 ~DirectX12Rasterizer() noexcept override = default;
1370
1371 public:
1383 static inline auto create(PolygonMode polygonMode, CullMode cullMode, CullOrder cullOrder, Float lineWidth = 1.f, bool depthClip = true, const DepthStencilState& depthStencilState = {}, bool conservativeRasterization = false) {
1384 return SharedObject::create<DirectX12Rasterizer>(polygonMode, cullMode, cullOrder, lineWidth, depthClip, depthStencilState, conservativeRasterization);
1385 }
1386
1392 static inline auto create(const DirectX12Rasterizer& other) {
1394 }
1395
1396 private:
1401 static inline auto create() {
1403 }
1404 };
1405
1411 class LITEFX_DIRECTX12_API DirectX12PipelineState : public virtual Pipeline<DirectX12PipelineLayout, DirectX12ShaderProgram>, public ComResource<ID3D12PipelineState> {
1412 protected:
1413 using ComResource<ID3D12PipelineState>::ComResource;
1414
1417 DirectX12PipelineState& operator=(DirectX12PipelineState&&) noexcept = default;
1419
1420 public:
1421 ~DirectX12PipelineState() noexcept override = default;
1422
1423 public:
1428 virtual void use(const DirectX12CommandBuffer& commandBuffer) const = 0;
1429 };
1430
1436 LITEFX_IMPLEMENTATION(DirectX12CommandBufferImpl);
1438
1439 public:
1441 using base_type::dispatch;
1442 using base_type::dispatchIndirect;
1443 using base_type::dispatchMesh;
1444 using base_type::draw;
1445 using base_type::drawIndirect;
1446 using base_type::drawIndexed;
1447 using base_type::drawIndexedIndirect;
1448 using base_type::barrier;
1449 using base_type::transfer;
1450 using base_type::bind;
1451 using base_type::use;
1452 using base_type::pushConstants;
1453 using base_type::buildAccelerationStructure;
1454 using base_type::updateAccelerationStructure;
1455 using base_type::copyAccelerationStructure;
1456
1457 private:
1464 explicit DirectX12CommandBuffer(const DirectX12Queue& queue, bool begin = false, bool primary = true);
1465
1466 private:
1469
1472
1474 DirectX12CommandBuffer& operator=(DirectX12CommandBuffer&&) noexcept = delete;
1475
1477 DirectX12CommandBuffer& operator=(const DirectX12CommandBuffer&) = delete;
1478
1479 public:
1481 ~DirectX12CommandBuffer() noexcept override;
1482
1483 public:
1490 static inline SharedPtr<DirectX12CommandBuffer> create(const DirectX12Queue& queue, bool begin = false, bool primary = true) {
1491 return SharedObject::create<DirectX12CommandBuffer>(queue, begin, primary);
1492 }
1493
1494 // CommandBuffer interface.
1495 public:
1497 SharedPtr<const DirectX12Queue> queue() const noexcept;
1498
1500 void begin() const override;
1501
1503 void end() const override;
1504
1506 void track(SharedPtr<const IBuffer> buffer) const override;
1507
1509 void track(SharedPtr<const IImage> image) const override;
1510
1512 void track(SharedPtr<const ISampler> sampler) const override;
1513
1515 void track(UniquePtr<const IDescriptorSet>&& descriptorSet) const override;
1516
1518 bool isSecondary() const noexcept override;
1519
1521 void setViewports(Span<const IViewport*> viewports) const override;
1522
1524 void setViewports(const IViewport* viewport) const override;
1525
1527 void setScissors(Span<const IScissor*> scissors) const override;
1528
1530 void setScissors(const IScissor* scissor) const override;
1531
1533 void setBlendFactors(const Vector4f& blendFactors) const noexcept override;
1534
1536 void setStencilRef(UInt32 stencilRef) const noexcept override;
1537
1539 void setDepthBounds(Float minBounds, Float maxBounds) const noexcept override;
1540
1542 UInt64 submit() const override;
1543
1545 [[nodiscard]] UniquePtr<DirectX12Barrier> makeBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const override;
1546
1548 void barrier(const DirectX12Barrier& barrier) const noexcept override;
1549
1551 void transfer(const IDirectX12Buffer& source, const IDirectX12Buffer& target, UInt32 sourceElement = 0, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1552
1554 void transfer(const void* const data, size_t size, const IDirectX12Buffer& target, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1555
1557 void transfer(Span<const void* const> data, size_t elementSize, const IDirectX12Buffer& target, UInt32 firstElement = 0) const override;
1558
1560 void transfer(const IDirectX12Buffer& source, const IDirectX12Image& target, UInt32 sourceElement = 0, UInt32 firstSubresource = 0, UInt32 elements = 1) const override;
1561
1563 void transfer(const void* const data, size_t size, const IDirectX12Image& target, UInt32 subresource = 0) const override;
1564
1566 void transfer(Span<const void* const> data, size_t elementSize, const IDirectX12Image& target, UInt32 firstSubresource = 0, UInt32 subresources = 1) const override;
1567
1569 void transfer(const IDirectX12Image& source, const IDirectX12Image& target, UInt32 sourceSubresource = 0, UInt32 targetSubresource = 0, UInt32 subresources = 1) const override;
1570
1572 void transfer(const IDirectX12Image& source, const IDirectX12Buffer& target, UInt32 firstSubresource = 0, UInt32 targetElement = 0, UInt32 subresources = 1) const override;
1573
1575 void transfer(const SharedPtr<const IDirectX12Buffer>& source, const IDirectX12Buffer& target, UInt32 sourceElement = 0, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1576
1578 void transfer(const SharedPtr<const IDirectX12Buffer>& source, const IDirectX12Image& target, UInt32 sourceElement = 0, UInt32 firstSubresource = 0, UInt32 elements = 1) const override;
1579
1581 void transfer(const SharedPtr<const IDirectX12Image>& source, const IDirectX12Image& target, UInt32 sourceSubresource = 0, UInt32 targetSubresource = 0, UInt32 subresources = 1) const override;
1582
1584 void transfer(const SharedPtr<const IDirectX12Image>& source, const IDirectX12Buffer& target, UInt32 firstSubresource = 0, UInt32 targetElement = 0, UInt32 subresources = 1) const override;
1585
1587 void use(const DirectX12PipelineState& pipeline) const noexcept override;
1588
1590 void bind(const DirectX12DescriptorSet& descriptorSet) const override;
1591
1593 void bind(Span<const DirectX12DescriptorSet*> descriptorSets) const override;
1594
1596 void bind(const DirectX12DescriptorSet& descriptorSet, const DirectX12PipelineState& pipeline) const override;
1597
1599 void bind(Span<const DirectX12DescriptorSet*> descriptorSets, const DirectX12PipelineState& pipeline) const override;
1600
1602 void bind(const IDirectX12VertexBuffer& buffer) const noexcept override;
1603
1605 void bind(const IDirectX12IndexBuffer& buffer) const noexcept override;
1606
1608 void dispatch(const Vector3u& threadCount) const noexcept override;
1609
1611 void dispatchIndirect(const IDirectX12Buffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1612
1614 void dispatchIndirect(const IDirectX12Buffer& batchBuffer, const IDirectX12Buffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept;
1615
1617 void dispatchMesh(const Vector3u& threadCount) const noexcept override;
1618
1620 void dispatchMeshIndirect(const IDirectX12Buffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1621
1623 void dispatchMeshIndirect(const IDirectX12Buffer& batchBuffer, const IDirectX12Buffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1624
1626 void draw(UInt32 vertices, UInt32 instances = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) const noexcept override;
1627
1629 void drawIndirect(const IDirectX12Buffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1630
1632 void drawIndirect(const IDirectX12Buffer& batchBuffer, const IDirectX12Buffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1633
1635 void drawIndexed(UInt32 indices, UInt32 instances = 1, UInt32 firstIndex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0) const noexcept override;
1636
1638 void drawIndexedIndirect(const IDirectX12Buffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1639
1641 void drawIndexedIndirect(const IDirectX12Buffer& batchBuffer, const IDirectX12Buffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1642
1644 void pushConstants(const DirectX12PushConstantsLayout& layout, const void* const memory) const override;
1645
1647 void writeTimingEvent(const SharedPtr<const TimingEvent>& timingEvent) const override;
1648
1650 void execute(const SharedPtr<const DirectX12CommandBuffer>& commandBuffer) const override;
1651
1653 void execute(Enumerable<SharedPtr<const DirectX12CommandBuffer>> commandBuffers) const override;
1654
1656 void buildAccelerationStructure(DirectX12BottomLevelAccelerationStructure& blas, const SharedPtr<const IDirectX12Buffer>& scratchBuffer, const IDirectX12Buffer& buffer, UInt64 offset = 0) const override;
1657
1659 void buildAccelerationStructure(DirectX12TopLevelAccelerationStructure& tlas, const SharedPtr<const IDirectX12Buffer>& scratchBuffer, const IDirectX12Buffer& buffer, UInt64 offset = 0) const override;
1660
1662 void updateAccelerationStructure(DirectX12BottomLevelAccelerationStructure& blas, const SharedPtr<const IDirectX12Buffer>& scratchBuffer, const IDirectX12Buffer& buffer, UInt64 offset = 0) const override;
1663
1665 void updateAccelerationStructure(DirectX12TopLevelAccelerationStructure& tlas, const SharedPtr<const IDirectX12Buffer>& scratchBuffer, const IDirectX12Buffer& buffer, UInt64 offset = 0) const override;
1666
1668 void copyAccelerationStructure(const DirectX12BottomLevelAccelerationStructure& from, const DirectX12BottomLevelAccelerationStructure& to, bool compress = false) const noexcept override;
1669
1671 void copyAccelerationStructure(const DirectX12TopLevelAccelerationStructure& from, const DirectX12TopLevelAccelerationStructure& to, bool compress = false) const noexcept override;
1672
1674 void traceRays(UInt32 width, UInt32 height, UInt32 depth, const ShaderBindingTableOffsets& offsets, const IDirectX12Buffer& rayGenerationShaderBindingTable, const IDirectX12Buffer* missShaderBindingTable, const IDirectX12Buffer* hitShaderBindingTable, const IDirectX12Buffer* callableShaderBindingTable) const noexcept override;
1675
1676 private:
1677 inline SharedPtr<const ICommandQueue> getQueue() const noexcept override {
1678 return std::static_pointer_cast<const ICommandQueue>(this->queue());
1679 }
1680
1681 void releaseSharedState() const override;
1682 };
1683
1688 class LITEFX_DIRECTX12_API DirectX12Queue final : public CommandQueue<DirectX12CommandBuffer>, public ComResource<ID3D12CommandQueue> {
1689 LITEFX_IMPLEMENTATION(DirectX12QueueImpl);
1691
1692 public:
1694 using base_type::submit;
1695
1696 private:
1703 explicit DirectX12Queue(const DirectX12Device& device, QueueType type, QueuePriority priority);
1704
1705 private:
1707 DirectX12Queue(DirectX12Queue&&) noexcept = delete;
1708
1710 DirectX12Queue(const DirectX12Queue&) = delete;
1711
1713 DirectX12Queue& operator=(DirectX12Queue&&) noexcept = delete;
1714
1716 DirectX12Queue& operator=(const DirectX12Queue&) = delete;
1717
1718 public:
1720 ~DirectX12Queue() noexcept override;
1721
1722 public:
1730 static inline SharedPtr<DirectX12Queue> create(const DirectX12Device& device, QueueType type, QueuePriority priority) {
1731 return SharedObject::create<DirectX12Queue>(device, type, priority);
1732 }
1733
1734 // DirectX12Queue interface.
1735 public:
1740 virtual SharedPtr<const DirectX12Device> device() const noexcept;
1741
1742 // CommandQueue interface.
1743 public:
1745 QueuePriority priority() const noexcept override;
1746
1748 QueueType type() const noexcept override;
1749
1750#if defined(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS) && defined(LITEFX_BUILD_WITH_PIX_RUNTIME)
1751 public:
1753 void beginDebugRegion(const String& label, const Vectors::ByteVector3& color = DEFAULT_DEBUG_COLOR) const noexcept override;
1754
1756 void endDebugRegion() const noexcept override;
1757
1759 void setDebugMarker(const String& label, const Vectors::ByteVector3& color = DEFAULT_DEBUG_COLOR) const noexcept override;
1760#endif // defined(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS) && defined(LITEFX_BUILD_WITH_PIX_RUNTIME)
1761
1762 public:
1764 SharedPtr<DirectX12CommandBuffer> createCommandBuffer(bool beginRecording = false, bool secondary = false) const override;
1765
1767 UInt64 submit(const SharedPtr<const DirectX12CommandBuffer>& commandBuffer) const override;
1768
1770 UInt64 submit(Enumerable<SharedPtr<const DirectX12CommandBuffer>> commandBuffers) const override;
1771
1773 void waitFor(UInt64 fence) const override;
1774
1776 void waitFor(const DirectX12Queue& queue, UInt64 fence) const noexcept;
1777
1779 UInt64 currentFence() const noexcept override;
1780
1782 UInt64 lastCompletedFence() const noexcept override;
1783
1784 private:
1785 inline void waitForQueue(const ICommandQueue& queue, UInt64 fence) const override {
1786 auto d3dQueue = dynamic_cast<const DirectX12Queue*>(&queue);
1787
1788 if (d3dQueue == nullptr) [[unlikely]]
1789 throw InvalidArgumentException("queue", "Cannot wait for queues from other backends.");
1790
1791 this->waitFor(*d3dQueue, fence);
1792 }
1793 };
1794
1800 class LITEFX_DIRECTX12_API DirectX12RenderPipeline final : public virtual DirectX12PipelineState, public RenderPipeline<DirectX12PipelineLayout, DirectX12ShaderProgram, DirectX12InputAssembler, DirectX12Rasterizer> {
1801 LITEFX_IMPLEMENTATION(DirectX12RenderPipelineImpl);
1802 LITEFX_BUILDER(DirectX12RenderPipelineBuilder);
1803
1804 public:
1816 explicit DirectX12RenderPipeline(const DirectX12RenderPass& renderPass, const SharedPtr<DirectX12PipelineLayout>& layout, const SharedPtr<DirectX12ShaderProgram>& shaderProgram, const SharedPtr<DirectX12InputAssembler>& inputAssembler, const SharedPtr<DirectX12Rasterizer>& rasterizer, MultiSamplingLevel samples = MultiSamplingLevel::x1, bool enableAlphaToCoverage = false, const String& name = "");
1817
1820
1823
1825 DirectX12RenderPipeline& operator=(DirectX12RenderPipeline&&) noexcept = delete;
1826
1829
1831 ~DirectX12RenderPipeline() noexcept override;
1832
1833 private:
1839 DirectX12RenderPipeline(const DirectX12RenderPass& renderPass, const String& name = "");
1840
1841 // Pipeline interface.
1842 public:
1844 SharedPtr<const DirectX12ShaderProgram> program() const noexcept override;
1845
1847 SharedPtr<const DirectX12PipelineLayout> layout() const noexcept override;
1848
1849 // RenderPipeline interface.
1850 public:
1852 SharedPtr<DirectX12InputAssembler> inputAssembler() const noexcept override;
1853
1855 SharedPtr<DirectX12Rasterizer> rasterizer() const noexcept override;
1856
1858 bool alphaToCoverage() const noexcept override;
1859
1861 MultiSamplingLevel samples() const noexcept override;
1862
1864 void updateSamples(MultiSamplingLevel samples) override;
1865
1866 // DirectX12PipelineState interface.
1867 public:
1869 void use(const DirectX12CommandBuffer& commandBuffer) const override;
1870 };
1871
1878 LITEFX_IMPLEMENTATION(DirectX12ComputePipelineImpl);
1879 LITEFX_BUILDER(DirectX12ComputePipelineBuilder);
1880
1881 public:
1889 explicit DirectX12ComputePipeline(const DirectX12Device& device, const SharedPtr<DirectX12PipelineLayout>& layout, const SharedPtr<DirectX12ShaderProgram>& shaderProgram, const String& name = "");
1890
1893
1896
1899
1902
1904 ~DirectX12ComputePipeline() noexcept override;
1905
1906 private:
1911 DirectX12ComputePipeline(const DirectX12Device& device) noexcept;
1912
1913 // Pipeline interface.
1914 public:
1916 SharedPtr<const DirectX12ShaderProgram> program() const noexcept override;
1917
1919 SharedPtr<const DirectX12PipelineLayout> layout() const noexcept override;
1920
1921 // DirectX12PipelineState interface.
1922 public:
1923 void use(const DirectX12CommandBuffer& commandBuffer) const noexcept override;
1924 };
1925
1939 LITEFX_IMPLEMENTATION(DirectX12RayTracingPipelineImpl);
1940 LITEFX_BUILDER(DirectX12RayTracingPipelineBuilder);
1941
1942 public:
1954 explicit DirectX12RayTracingPipeline(const DirectX12Device& device, const SharedPtr<DirectX12PipelineLayout>& layout, const SharedPtr<DirectX12ShaderProgram>& shaderProgram, ShaderRecordCollection&& shaderRecords, UInt32 maxRecursionDepth = 10, UInt32 maxPayloadSize = 0, UInt32 maxAttributeSize = 32, const String& name = ""); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
1955
1958
1961
1964
1967
1969 ~DirectX12RayTracingPipeline() noexcept override;
1970
1971 private:
1977 DirectX12RayTracingPipeline(const DirectX12Device& device, ShaderRecordCollection&& shaderRecords) noexcept;
1978
1979 // Pipeline interface.
1980 public:
1982 SharedPtr<const DirectX12ShaderProgram> program() const noexcept override;
1983
1985 SharedPtr<const DirectX12PipelineLayout> layout() const noexcept override;
1986
1987 // RayTracingPipeline interface.
1988 public:
1990 const ShaderRecordCollection& shaderRecords() const noexcept override;
1991
1993 UInt32 maxRecursionDepth() const noexcept override;
1994
1996 UInt32 maxPayloadSize() const noexcept override;
1997
1999 UInt32 maxAttributeSize() const noexcept override;
2000
2002 SharedPtr<IDirectX12Buffer> allocateShaderBindingTable(ShaderBindingTableOffsets& offsets, ShaderBindingGroup groups = ShaderBindingGroup::All) const override;
2003
2004 // DirectX12PipelineState interface.
2005 public:
2007 void use(const DirectX12CommandBuffer& commandBuffer) const noexcept override;
2008
2013 ComPtr<ID3D12StateObject> stateObject() const noexcept;
2014 };
2015
2020 class LITEFX_DIRECTX12_API DirectX12FrameBuffer final : public FrameBuffer<IDirectX12Image> {
2021 LITEFX_IMPLEMENTATION(DirectX12FrameBufferImpl);
2023
2024 public:
2026 using FrameBuffer::addImage;
2027 using FrameBuffer::mapRenderTarget;
2028 using FrameBuffer::mapRenderTargets;
2029
2030 private:
2037 DirectX12FrameBuffer(const DirectX12Device& device, const Size2d& renderArea, StringView name = "");
2038
2047 DirectX12FrameBuffer(const DirectX12Device& device, const Size2d& renderArea, allocation_callback_type allocationCallback, StringView name = "");
2048
2049 private:
2051 DirectX12FrameBuffer(DirectX12FrameBuffer&&) noexcept = delete;
2052
2055
2057 DirectX12FrameBuffer& operator=(DirectX12FrameBuffer&&) noexcept = delete;
2058
2060 DirectX12FrameBuffer& operator=(const DirectX12FrameBuffer&) = delete;
2061
2062 public:
2064 ~DirectX12FrameBuffer() noexcept override;
2065
2066 public:
2074 static inline SharedPtr<DirectX12FrameBuffer> create(const DirectX12Device& device, const Size2d& renderArea, StringView name = "") {
2075 return SharedObject::create<DirectX12FrameBuffer>(device, renderArea, name);
2076 }
2077
2086 static inline SharedPtr<DirectX12FrameBuffer> create(const DirectX12Device& device, const Size2d& renderArea, allocation_callback_type allocationCallback, StringView name = "") {
2087 return SharedObject::create<DirectX12FrameBuffer>(device, renderArea, std::move(allocationCallback), name);
2088 }
2089
2090 // DirectX 12 FrameBuffer
2091 public:
2098 D3D12_CPU_DESCRIPTOR_HANDLE descriptorHandle(UInt32 imageIndex) const;
2099
2106 D3D12_CPU_DESCRIPTOR_HANDLE descriptorHandle(StringView imageName) const;
2107
2114 D3D12_CPU_DESCRIPTOR_HANDLE descriptorHandle(const RenderTarget& renderTarget) const;
2115
2116 // FrameBuffer interface.
2117 public:
2119 const Size2d& size() const noexcept override;
2120
2122 size_t getWidth() const noexcept override;
2123
2125 size_t getHeight() const noexcept override;
2126
2128 void mapRenderTarget(const RenderTarget& renderTarget, UInt32 index) override;
2129
2131 void mapRenderTarget(const RenderTarget& renderTarget, StringView name) override;
2132
2134 void unmapRenderTarget(const RenderTarget& renderTarget) noexcept override;
2135
2137 const Array<SharedPtr<const IDirectX12Image>>& images() const override;
2138
2140 inline const IDirectX12Image& operator[](UInt32 index) const override {
2141 return this->image(index);
2142 }
2143
2145 const IDirectX12Image& image(UInt32 index) const override;
2146
2148 inline const IDirectX12Image& operator[](const RenderTarget& renderTarget) const override {
2149 return this->image(renderTarget);
2150 }
2151
2153 const IDirectX12Image& image(const RenderTarget& renderTarget) const override;
2154
2156 inline const IDirectX12Image& operator[](StringView renderTargetName) const override {
2157 return this->resolveImage(hash(renderTargetName));
2158 }
2159
2161 inline const IDirectX12Image& image(StringView renderTargetName) const override {
2162 return this->resolveImage(hash(renderTargetName));
2163 }
2164
2166 const IDirectX12Image& resolveImage(UInt64 hash) const override;
2167
2169 void addImage(const String& name, Format format, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::FrameBufferImage) override;
2170
2172 void addImage(const String& name, const RenderTarget& renderTarget, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::FrameBufferImage) override;
2173
2175 void resize(const Size2d& renderArea) override;
2176 };
2177
2182 class LITEFX_DIRECTX12_API DirectX12RenderPass final : public RenderPass<DirectX12Queue, DirectX12FrameBuffer> {
2183 LITEFX_IMPLEMENTATION(DirectX12RenderPassImpl);
2184 LITEFX_BUILDER(DirectX12RenderPassBuilder);
2186
2187 public:
2189
2190 private:
2201 explicit DirectX12RenderPass(const DirectX12Device& device, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000);
2202
2214 explicit DirectX12RenderPass(const DirectX12Device& device, const String& name, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000);
2215
2227 explicit DirectX12RenderPass(const DirectX12Device& device, const DirectX12Queue& queue, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000);
2228
2241 explicit DirectX12RenderPass(const DirectX12Device& device, const String& name, const DirectX12Queue& queue, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000);
2242
2243 private:
2245 DirectX12RenderPass(DirectX12RenderPass&&) noexcept = delete;
2246
2248 DirectX12RenderPass(const DirectX12RenderPass&) = delete;
2249
2251 DirectX12RenderPass& operator=(DirectX12RenderPass&&) noexcept = delete;
2252
2254 DirectX12RenderPass& operator=(const DirectX12RenderPass&) = delete;
2255
2256 public:
2258 ~DirectX12RenderPass() noexcept override;
2259
2260 public:
2272 static inline SharedPtr<DirectX12RenderPass> create(const DirectX12Device& device, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000) {
2273 return SharedObject::create<DirectX12RenderPass>(device, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers, viewMask);
2274 }
2275
2288 static inline SharedPtr<DirectX12RenderPass> create(const DirectX12Device& device, const String& name, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000) {
2289 return SharedObject::create<DirectX12RenderPass>(device, name, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers, viewMask);
2290 }
2291
2304 static inline SharedPtr<DirectX12RenderPass> create(const DirectX12Device& device, const DirectX12Queue& queue, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000) {
2305 return SharedObject::create<DirectX12RenderPass>(device, queue, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers, viewMask);
2306 }
2307
2321 static inline SharedPtr<DirectX12RenderPass> create(const DirectX12Device& device, const String& name, const DirectX12Queue& queue, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u, UInt32 viewMask = 0b0000) {
2322 return SharedObject::create<DirectX12RenderPass>(device, name, queue, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers, viewMask);
2323 }
2324
2325 private:
2331 explicit DirectX12RenderPass(const DirectX12Device& device, const String& name = "");
2332
2343 static inline SharedPtr<DirectX12RenderPass> create(const DirectX12Device& device, const String& name = "") {
2344 return SharedObject::create<DirectX12RenderPass>(device, name);
2345 }
2346
2347 // RenderPass interface.
2348 public:
2353 const DirectX12Device& device() const noexcept /*override*/;
2354
2356 SharedPtr<const DirectX12FrameBuffer> activeFrameBuffer() const noexcept override;
2357
2359 const DirectX12Queue& commandQueue() const noexcept override;
2360
2362 Enumerable<SharedPtr<const DirectX12CommandBuffer>> commandBuffers() const override;
2363
2365 SharedPtr<const DirectX12CommandBuffer> commandBuffer(UInt32 index) const override;
2366
2368 UInt32 secondaryCommandBuffers() const noexcept override;
2369
2371 const Array<RenderTarget>& renderTargets() const noexcept override;
2372
2374 const RenderTarget& renderTarget(UInt32 location) const override;
2375
2377 bool hasPresentTarget() const noexcept override;
2378
2380 const Array<RenderPassDependency>& inputAttachments() const noexcept override;
2381
2383 const RenderPassDependency& inputAttachment(UInt32 location) const override;
2384
2386 const Optional<DescriptorBindingPoint>& inputAttachmentSamplerBinding() const noexcept override;
2387
2389 void begin(const DirectX12FrameBuffer& frameBuffer) const override;
2390
2392 UInt64 end() const override;
2393
2395 UInt32 viewMask() const noexcept override;
2396 };
2397
2401 class LITEFX_DIRECTX12_API DirectX12SwapChain final : public SwapChain<IDirectX12Image>, public ComResource<IDXGISwapChain4> {
2402 LITEFX_IMPLEMENTATION(DirectX12SwapChainImpl);
2404 friend class DirectX12Image;
2405 friend class DirectX12Device;
2406
2407 public:
2409
2410 private:
2420 explicit DirectX12SwapChain(const DirectX12Device& device, const DirectX12Backend& backend, Format surfaceFormat = Format::B8G8R8A8_SRGB, const Size2d& renderArea = { 800, 600 }, UInt32 buffers = 3, bool enableVsync = false); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
2421
2422 public:
2425
2428
2430 DirectX12SwapChain& operator=(DirectX12SwapChain&&) noexcept = delete;
2431
2433 DirectX12SwapChain& operator=(const DirectX12SwapChain&) = delete;
2434
2436 ~DirectX12SwapChain() noexcept override;
2437
2438 // DirectX 12 swap chain.
2439 public:
2444 virtual bool supportsVariableRefreshRate() const noexcept;
2445
2450 virtual ID3D12QueryHeap* timestampQueryHeap() const noexcept;
2451
2452 // SwapChain interface.
2453 public:
2455 const Array<SharedPtr<const TimingEvent>>& timingEvents() const override;
2456
2458 SharedPtr<const TimingEvent> timingEvent(UInt32 queryId) const override;
2459
2461 UInt64 readTimingEvent(SharedPtr<const TimingEvent> timingEvent) const override;
2462
2464 UInt32 resolveQueryId(SharedPtr<const TimingEvent> timingEvent) const override;
2465
2467 const IGraphicsDevice& device() const override;
2468
2470 Format surfaceFormat() const noexcept override;
2471
2473 UInt32 buffers() const noexcept override;
2474
2476 const Size2d& renderArea() const noexcept override;
2477
2479 bool verticalSynchronization() const noexcept override;
2480
2482 IDirectX12Image* image(UInt32 backBuffer) const override;
2483
2485 const IDirectX12Image& image() const noexcept override;
2486
2488 const Array<SharedPtr<IDirectX12Image>>& images() const noexcept override;
2489
2491 void present(UInt64 fence) const override;
2492
2493 public:
2495 Enumerable<Format> getSurfaceFormats() const override;
2496
2498 void addTimingEvent(SharedPtr<const TimingEvent> timingEvent) override;
2499
2501 void reset(Format surfaceFormat, const Size2d& renderArea, UInt32 buffers, bool enableVsync = false) override;
2502
2504 [[nodiscard]] UInt32 swapBackBuffer() const override;
2505
2506 private:
2507 void resolveQueryHeaps(const DirectX12CommandBuffer& commandBuffer) const noexcept;
2508 };
2509
2517 LITEFX_IMPLEMENTATION(DirectX12GraphicsFactoryImpl);
2518 friend class DirectX12Device;
2520
2521 public:
2523 using base_type::createBuffer;
2524 using base_type::tryCreateBuffer;
2525 using base_type::createVertexBuffer;
2526 using base_type::tryCreateVertexBuffer;
2527 using base_type::createIndexBuffer;
2528 using base_type::tryCreateIndexBuffer;
2529 using base_type::createTexture;
2530 using base_type::tryCreateTexture;
2531 using base_type::createTextures;
2532 using base_type::createSampler;
2533 using base_type::createSamplers;
2534 using base_type::allocate;
2535
2536 private:
2541 explicit DirectX12GraphicsFactory(const DirectX12Device& device);
2542
2543 private:
2546
2549
2551 DirectX12GraphicsFactory& operator=(DirectX12GraphicsFactory&&) noexcept = delete;
2552
2554 DirectX12GraphicsFactory& operator=(const DirectX12GraphicsFactory&) = delete;
2555
2556 public:
2558 ~DirectX12GraphicsFactory() noexcept override;
2559
2560 private:
2565 static inline SharedPtr<DirectX12GraphicsFactory> create(const DirectX12Device& device) {
2567 }
2568
2569 public:
2571 [[nodiscard]] VirtualAllocator createAllocator(UInt64 overallMemory, AllocationAlgorithm algorithm = AllocationAlgorithm::Default) const override;
2572
2574 void beginDefragmentation(const ICommandQueue& queue, DefragmentationStrategy strategy = DefragmentationStrategy::Balanced, UInt64 maxBytesToMove = 0u, UInt32 maxAllocationsToMove = 0u) const override;
2575
2578
2580 bool endDefragmentationPass() const override;
2581
2583 Generator<ResourceAllocationResult> allocate(Enumerable<const ResourceAllocationInfo&> allocationInfos, AllocationBehavior allocationBehavior = AllocationBehavior::Default, bool alias = false) const override;
2584
2586 bool canAlias(Enumerable<const ResourceAllocationInfo&> allocationInfos) const override;
2587
2589 SharedPtr<IDirectX12Buffer> createBuffer(BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2590
2592 SharedPtr<IDirectX12Buffer> createBuffer(const String& name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2593
2595 SharedPtr<IDirectX12VertexBuffer> createVertexBuffer(const DirectX12VertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2596
2598 SharedPtr<IDirectX12VertexBuffer> createVertexBuffer(const String& name, const DirectX12VertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2599
2601 SharedPtr<IDirectX12IndexBuffer> createIndexBuffer(const DirectX12IndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2602
2604 SharedPtr<IDirectX12IndexBuffer> createIndexBuffer(const String& name, const DirectX12IndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2605
2607 SharedPtr<IDirectX12Image> 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;
2608
2610 SharedPtr<IDirectX12Image> 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;
2611
2613 bool tryCreateBuffer(SharedPtr<IDirectX12Buffer>& buffer, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2614
2616 bool tryCreateBuffer(SharedPtr<IDirectX12Buffer>& buffer, const String& name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2617
2619 bool tryCreateVertexBuffer(SharedPtr<IDirectX12VertexBuffer>& buffer, const DirectX12VertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2620
2622 bool tryCreateVertexBuffer(SharedPtr<IDirectX12VertexBuffer>& buffer, const String& name, const DirectX12VertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2623
2625 bool tryCreateIndexBuffer(SharedPtr<IDirectX12IndexBuffer>& buffer, const DirectX12IndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2626
2628 bool tryCreateIndexBuffer(SharedPtr<IDirectX12IndexBuffer>& buffer, const String& name, const DirectX12IndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const override;
2629
2631 bool tryCreateTexture(SharedPtr<IDirectX12Image>& 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;
2632
2634 bool tryCreateTexture(SharedPtr<IDirectX12Image>& 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;
2635
2637 Generator<SharedPtr<IDirectX12Image>> 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;
2638
2640 SharedPtr<IDirectX12Sampler> 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;
2641
2643 SharedPtr<IDirectX12Sampler> 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;
2644
2646 Generator<SharedPtr<IDirectX12Sampler>> 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;
2647
2650
2653
2655 bool supportsResizableBaseAddressRegister() const noexcept override;
2656
2658 Array<MemoryHeapStatistics> memoryStatistics() const override;
2659
2661 DetailedMemoryStatistics detailedMemoryStatistics() const override;
2662 };
2663
2668 LITEFX_IMPLEMENTATION(DirectX12DeviceImpl);
2670 friend class DirectX12Backend;
2671
2672 private:
2680 explicit DirectX12Device(const DirectX12GraphicsAdapter& adapter, UniquePtr<DirectX12Surface>&& surface, UInt32 globalBufferHeapSize = D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1, UInt32 globalSamplerHeapSize = D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE);
2681
2682 private:
2684 DirectX12Device(DirectX12Device&&) noexcept = delete;
2685
2687 DirectX12Device(const DirectX12Device&) = delete;
2688
2690 DirectX12Device& operator=(DirectX12Device&&) noexcept = delete;
2691
2693 DirectX12Device& operator=(const DirectX12Device&) = delete;
2694
2695 public:
2697 ~DirectX12Device() noexcept override;
2698
2699 // Factory methods.
2700 public:
2710 static inline SharedPtr<DirectX12Device> create(const DirectX12Backend& backend, const DirectX12GraphicsAdapter& adapter, UniquePtr<DirectX12Surface>&& surface, GraphicsDeviceFeatures features = {}) {
2711 return SharedObject::create<DirectX12Device>(adapter, std::move(surface))->initialize(backend, Format::B8G8R8A8_SRGB, { 800, 600 }, 3, false, features); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
2712 }
2713
2728 static inline SharedPtr<DirectX12Device> create(const DirectX12Backend& backend, const DirectX12GraphicsAdapter& adapter, UniquePtr<DirectX12Surface>&& surface, Format format, const Size2d& renderArea, UInt32 backBuffers, bool enableVsync = false, GraphicsDeviceFeatures features = {}, UInt32 globalBufferHeapSize = D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1, UInt32 globalSamplerHeapSize = D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE) {
2729 return SharedObject::create<DirectX12Device>(adapter, std::move(surface), globalBufferHeapSize, globalSamplerHeapSize)->initialize(backend, format, renderArea, backBuffers, enableVsync, features);
2730 }
2731
2732 private:
2743 SharedPtr<DirectX12Device> initialize(const DirectX12Backend& backend, Format format, const Size2d& renderArea, UInt32 backBuffers, bool enableVsync, GraphicsDeviceFeatures features);
2744
2748 void release() noexcept;
2749
2750 // DirectX 12 Device interface.
2751 public:
2759 ID3D12DescriptorHeap* globalBufferHeap() const noexcept;
2760
2766 ID3D12DescriptorHeap* globalSamplerHeap() const noexcept;
2767
2775 void indirectDrawSignatures(ComPtr<ID3D12CommandSignature>& dispatchSignature, ComPtr<ID3D12CommandSignature>& dispatchMeshSignature, ComPtr<ID3D12CommandSignature>& drawSignature, ComPtr<ID3D12CommandSignature>& drawIndexedSignature) const noexcept;
2776
2793 [[nodiscard]] VirtualAllocator::Allocation allocateGlobalDescriptors(UInt32 descriptors, DescriptorHeapType heapType) const;
2794
2804 void releaseGlobalDescriptors(DescriptorHeapType heapType, VirtualAllocator::Allocation&& allocation) const;
2805
2806 // GraphicsDevice interface.
2807 public:
2809 DeviceState& state() const noexcept override;
2810
2812 const DirectX12SwapChain& swapChain() const noexcept override;
2813
2815 DirectX12SwapChain& swapChain() noexcept override;
2816
2818 const DirectX12Surface& surface() const noexcept override;
2819
2821 const DirectX12GraphicsAdapter& adapter() const noexcept override;
2822
2824 const DirectX12GraphicsFactory& factory() const noexcept override;
2825
2827 const DirectX12Queue& defaultQueue(QueueType type) const override;
2828
2830 SharedPtr<const DirectX12Queue> createQueue(QueueType type, QueuePriority priority) override;
2831
2833 [[nodiscard]] UniquePtr<DirectX12Barrier> makeBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const override;
2834
2836 [[nodiscard]] SharedPtr<DirectX12FrameBuffer> makeFrameBuffer(StringView name, const Size2d& renderArea) const override;
2837
2839 [[nodiscard]] SharedPtr<DirectX12FrameBuffer> makeFrameBuffer(StringView name, const Size2d& renderArea, DirectX12FrameBuffer::allocation_callback_type allocationCallback) const override;
2840
2843 MultiSamplingLevel maximumMultiSamplingLevel(Format format) const noexcept override;
2844
2846 double ticksPerMillisecond() const noexcept override;
2847
2849 void wait() const override;
2850
2852 void computeAccelerationStructureSizes(const DirectX12BottomLevelAccelerationStructure& blas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate = false) const override;
2853
2855 void computeAccelerationStructureSizes(const DirectX12TopLevelAccelerationStructure& tlas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate = false) const override;
2856
2858 [[nodiscard]] VirtualAllocator::Allocation allocateGlobalDescriptors(const DirectX12DescriptorSet& descriptorSet, DescriptorHeapType heapType) const override;
2859
2861 void releaseGlobalDescriptors(const DirectX12DescriptorSet& descriptorSet) const override;
2862
2864 void updateGlobalDescriptors(const DirectX12DescriptorSet& descriptorSet, UInt32 binding, UInt32 offset, UInt32 descriptors) const override;
2865
2867 void bindDescriptorSet(const DirectX12CommandBuffer& commandBuffer, const DirectX12DescriptorSet& descriptorSet, const DirectX12PipelineState& pipeline) const noexcept override;
2868
2870 void bindGlobalDescriptorHeaps(const DirectX12CommandBuffer& commandBuffer) const noexcept override;
2871
2872#if defined(LITEFX_BUILD_DEFINE_BUILDERS)
2873 public:
2875 [[nodiscard]] DirectX12RenderPassBuilder buildRenderPass(UInt32 commandBuffers = 1) const override;
2876
2878 [[nodiscard]] DirectX12RenderPassBuilder buildRenderPass(const String& name, UInt32 commandBuffers = 1) const override;
2879
2881 //[[nodiscard]] DirectX12RenderPipelineBuilder buildRenderPipeline(const String& name) const override;
2882
2884 [[nodiscard]] DirectX12RenderPipelineBuilder buildRenderPipeline(const DirectX12RenderPass& renderPass, const String& name) const override;
2885
2887 [[nodiscard]] DirectX12ComputePipelineBuilder buildComputePipeline(const String& name) const override;
2888
2890 [[nodiscard]] DirectX12RayTracingPipelineBuilder buildRayTracingPipeline(ShaderRecordCollection&& shaderRecords) const override;
2891
2893 [[nodiscard]] DirectX12RayTracingPipelineBuilder buildRayTracingPipeline(const String& name, ShaderRecordCollection&& shaderRecords) const override;
2894
2896 [[nodiscard]] DirectX12PipelineLayoutBuilder buildPipelineLayout() const override;
2897
2899 [[nodiscard]] DirectX12InputAssemblerBuilder buildInputAssembler() const override;
2900
2902 [[nodiscard]] DirectX12RasterizerBuilder buildRasterizer() const override;
2903
2905 [[nodiscard]] DirectX12ShaderProgramBuilder buildShaderProgram() const override;
2906
2908 [[nodiscard]] DirectX12BarrierBuilder buildBarrier() const override;
2909#endif // defined(LITEFX_BUILD_DEFINE_BUILDERS)
2910 };
2911
2915 class LITEFX_DIRECTX12_API DirectX12Backend final : public RenderBackend<DirectX12Device>, public ComResource<IDXGIFactory7> {
2916 LITEFX_IMPLEMENTATION(DirectX12BackendImpl);
2917
2918 public:
2919 explicit DirectX12Backend(const App& app, bool advancedSoftwareRasterizer = false);
2920
2923
2926
2928 DirectX12Backend& operator=(DirectX12Backend&&) noexcept;
2929
2931 DirectX12Backend& operator=(const DirectX12Backend&) = delete;
2932
2934 ~DirectX12Backend() noexcept override;
2935
2936 // IBackend interface.
2937 public:
2939 BackendType type() const noexcept override;
2940
2942 StringView name() const noexcept override;
2943
2944 protected:
2946 void activate() override;
2947
2949 void deactivate() override;
2950
2951 // RenderBackend interface.
2952 public:
2954 const Array<SharedPtr<const DirectX12GraphicsAdapter>>& adapters() const override;
2955
2957 const DirectX12GraphicsAdapter* findAdapter(const Optional<UInt64>& adapterId = std::nullopt) const noexcept override;
2958
2960 void registerDevice(const String& name, SharedPtr<DirectX12Device>&& device) override;
2961
2963 void releaseDevice(const String& name) override;
2964
2966 DirectX12Device* device(const String& name) noexcept override;
2967
2969 const DirectX12Device* device(const String& name) const noexcept override;
2970
2971 public:
2977 UniquePtr<DirectX12Surface> createSurface(const HWND& hwnd) const;
2978
2987 virtual void enableAdvancedSoftwareRasterizer(bool enable = false);
2988 };
2989
2990}
2991
2992#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
Implements the DirectX 12 RenderBackend.
Definition dx12.hpp:2915
DirectX12Backend(DirectX12Backend &&) noexcept
Implements a DirectX 12 resource barrier.
Definition dx12.hpp:484
DirectX12Barrier(DirectX12Barrier &&) noexcept
Implements a DirectX 12 bottom-level acceleration structure (BLAS).
Definition dx12.hpp:302
DirectX12BottomLevelAccelerationStructure(DirectX12BottomLevelAccelerationStructure &&) noexcept
Records commands for a DirectX12Queue
Definition dx12.hpp:1435
Implements a DirectX 12 ComputePipeline.
Definition dx12.hpp:1877
DirectX12ComputePipeline(DirectX12ComputePipeline &&) noexcept
Implements a DirectX 12 IDescriptorLayout
Definition dx12.hpp:777
DirectX12DescriptorLayout(DirectX12DescriptorLayout &&) noexcept
Implements a DirectX 12 DescriptorSet.
Definition dx12.hpp:697
DirectX12DescriptorSet(DirectX12DescriptorSet &&) noexcept=delete
Implements a DirectX 12 DescriptorSetLayout.
Definition dx12.hpp:857
static auto create(const DirectX12DescriptorSetLayout &other)
Creates a copy of a DirectX 12 descriptor set layout.
Definition dx12.hpp:919
Implements a DirectX 12 graphics device.
Definition dx12.hpp:2667
static SharedPtr< DirectX12Device > create(const DirectX12Backend &backend, const DirectX12GraphicsAdapter &adapter, UniquePtr< DirectX12Surface > &&surface, Format format, const Size2d &renderArea, UInt32 backBuffers, bool enableVsync=false, GraphicsDeviceFeatures features={}, UInt32 globalBufferHeapSize=D3D12_MAX_SHADER_VISIBLE_DESCRIPTOR_HEAP_SIZE_TIER_1, UInt32 globalSamplerHeapSize=D3D12_MAX_SHADER_VISIBLE_SAMPLER_HEAP_SIZE)
Initializes the device instance.
Definition dx12.hpp:2728
Implements a DirectX 12 frame buffer.
Definition dx12.hpp:2020
const IDirectX12Image & 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 dx12.hpp:2161
static SharedPtr< DirectX12FrameBuffer > create(const DirectX12Device &device, const Size2d &renderArea, allocation_callback_type allocationCallback, StringView name="")
Initializes a DirectX 12 frame buffer.
Definition dx12.hpp:2086
const IDirectX12Image & 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 dx12.hpp:2148
const IDirectX12Image & 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 dx12.hpp:2156
Implements a DirectX12 IGraphicsAdapter.
Definition dx12_api.hpp:224
A graphics factory that produces objects for a DirectX12Device.
Definition dx12.hpp:2516
SharedPtr< IDirectX12Sampler > 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
bool tryCreateTexture(SharedPtr< IDirectX12Image > &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
SharedPtr< IDirectX12Sampler > 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
SharedPtr< IDirectX12IndexBuffer > createIndexBuffer(const DirectX12IndexBufferLayout &layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
bool endDefragmentationPass() const override
Ends a defragmentation pass.Before calling this method, make sure you have started a defragmentation ...
Generator< ResourceAllocationResult > allocate(Enumerable< const ResourceAllocationInfo & > allocationInfos, AllocationBehavior allocationBehavior=AllocationBehavior::Default, bool alias=false) const override
Allocates a set of resources as described by allocationInfos .If the alias parameter is set to true,...
Generator< SharedPtr< IDirectX12Sampler > > 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
UniquePtr< DirectX12TopLevelAccelerationStructure > createTopLevelAccelerationStructure(StringView name, AccelerationStructureFlags flags=AccelerationStructureFlags::None) const override
bool tryCreateIndexBuffer(SharedPtr< IDirectX12IndexBuffer > &buffer, const String &name, const DirectX12IndexBufferLayout &layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
SharedPtr< IDirectX12Image > 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
UInt64 beginDefragmentationPass() const override
Starts a new defragmentation pass.Before calling this method, make sure you have started a defragment...
UniquePtr< DirectX12BottomLevelAccelerationStructure > createBottomLevelAccelerationStructure(StringView name, AccelerationStructureFlags flags=AccelerationStructureFlags::None) const override
bool tryCreateVertexBuffer(SharedPtr< IDirectX12VertexBuffer > &buffer, const DirectX12VertexBufferLayout &layout, ResourceHeap heap, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
VirtualAllocator createAllocator(UInt64 overallMemory, AllocationAlgorithm algorithm=AllocationAlgorithm::Default) const override
Creates a virtual allocator that can be used to manage allocation from a custom block of memory....
SharedPtr< IDirectX12Buffer > createBuffer(const String &name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
bool tryCreateBuffer(SharedPtr< IDirectX12Buffer > &buffer, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
SharedPtr< IDirectX12VertexBuffer > createVertexBuffer(const DirectX12VertexBufferLayout &layout, ResourceHeap heap, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
SharedPtr< IDirectX12IndexBuffer > createIndexBuffer(const String &name, const DirectX12IndexBufferLayout &layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
SharedPtr< IDirectX12Buffer > createBuffer(BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
bool tryCreateTexture(SharedPtr< IDirectX12Image > &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
SharedPtr< IDirectX12VertexBuffer > createVertexBuffer(const String &name, const DirectX12VertexBufferLayout &layout, ResourceHeap heap, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
bool canAlias(Enumerable< const ResourceAllocationInfo & > allocationInfos) const override
Checks if the resources described by allocationInfos can be overlapped.true, if the resources descri...
bool tryCreateIndexBuffer(SharedPtr< IDirectX12IndexBuffer > &buffer, const DirectX12IndexBufferLayout &layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
bool tryCreateVertexBuffer(SharedPtr< IDirectX12VertexBuffer > &buffer, const String &name, const DirectX12VertexBufferLayout &layout, ResourceHeap heap, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
void beginDefragmentation(const ICommandQueue &queue, DefragmentationStrategy strategy=DefragmentationStrategy::Balanced, UInt64 maxBytesToMove=0u, UInt32 maxAllocationsToMove=0u) const override
Starts a defragmentation process for the resources allocated from the factory.Defragmentation is an i...
bool tryCreateBuffer(SharedPtr< IDirectX12Buffer > &buffer, const String &name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const override
SharedPtr< IDirectX12Image > 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
Generator< SharedPtr< IDirectX12Image > > 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
bool supportsResizableBaseAddressRegister() const noexcept override
Returns true, if the GPU supports resizable base address register (ReBAR) and false otherwise....
Implements a DirectX12 IImage.
Definition image.h:16
Implements a DirectX 12 index buffer layout.
Definition dx12.hpp:119
static auto create(const DirectX12IndexBufferLayout &other)
Creates a copy of an index buffer layout.
Definition dx12.hpp:162
Implements the DirectX 12 input assembler state.
Definition dx12.hpp:1248
static auto create(const DirectX12InputAssembler &other)
Creates a new DirectX 12 input assembler state as a copy from another one.
Definition dx12.hpp:1301
Implements a DirectX 12 PipelineLayout.
Definition dx12.hpp:1130
Defines the base class for DirectX 12 pipeline state objects.
Definition dx12.hpp:1411
DirectX12PipelineState(DirectX12PipelineState &&) noexcept=default
Implements the DirectX 12 PushConstantsLayout.
Definition dx12.hpp:1073
DirectX12PushConstantsLayout(DirectX12PushConstantsLayout &&) noexcept
Implements the DirectX 12 IPushConstantsRange.
Definition dx12.hpp:1015
DirectX12PushConstantsRange(DirectX12PushConstantsRange &&) noexcept
Implements a DirectX 12 command queue.
Definition dx12.hpp:1688
Implements a DirectX 12 IRasterizer.
Definition dx12.hpp:1332
static auto create(const DirectX12Rasterizer &other)
Creates a new DirectX 12 rasterizer state by copying an existing one.
Definition dx12.hpp:1392
Implements a DirectX 12 RayTracingPipeline.
Definition dx12.hpp:1938
DirectX12RayTracingPipeline(DirectX12RayTracingPipeline &&) noexcept
Implements a DirectX 12 render pass.
Definition dx12.hpp:2182
static SharedPtr< DirectX12RenderPass > create(const DirectX12Device &device, const String &name, const DirectX12Queue &queue, Span< RenderTarget > renderTargets, Span< RenderPassDependency > inputAttachments={ }, Optional< DescriptorBindingPoint > inputAttachmentSamplerBinding=std::nullopt, UInt32 secondaryCommandBuffers=1u, UInt32 viewMask=0b0000)
Creates and initializes a new DirectX 12 render pass instance.
Definition dx12.hpp:2321
static SharedPtr< DirectX12RenderPass > create(const DirectX12Device &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 DirectX 12 render pass instance that executes on the default graphics q...
Definition dx12.hpp:2288
static SharedPtr< DirectX12RenderPass > create(const DirectX12Device &device, const DirectX12Queue &queue, Span< RenderTarget > renderTargets, Span< RenderPassDependency > inputAttachments={ }, Optional< DescriptorBindingPoint > inputAttachmentSamplerBinding=std::nullopt, UInt32 secondaryCommandBuffers=1u, UInt32 viewMask=0b0000)
Creates and initializes a new DirectX 12 render pass instance.
Definition dx12.hpp:2304
Implements a DirectX 12 RenderPipeline.
Definition dx12.hpp:1800
DirectX12RenderPipeline(DirectX12RenderPipeline &&) noexcept=delete
Implements a DirectX 12 IShaderModule.
Definition dx12.hpp:563
DirectX12ShaderModule(DirectX12ShaderModule &&) noexcept
Implements a DirectX 12 ShaderProgram.
Definition dx12.hpp:623
Implements a DirectX12 ISurface.
Definition dx12_api.hpp:290
Implements a DirectX 12 swap chain.
Definition dx12.hpp:2401
DirectX12SwapChain(DirectX12SwapChain &&) noexcept=delete
Implements a DirectX 12 top-level acceleration structure (TLAS).
Definition dx12.hpp:396
DirectX12TopLevelAccelerationStructure(DirectX12TopLevelAccelerationStructure &&) noexcept
Implements a DirectX 12 vertex buffer layout.
Definition dx12.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 dx12.hpp:81
static auto create(const DirectX12VertexBufferLayout &other)
Creates a copy of a vertex buffer layout.
Definition dx12.hpp:90
Represents the base interface for a DirectX 12 acceleration structure implementation.
Definition dx12.hpp:286
Represents the base interface for a DirectX 12 buffer implementation.
Definition dx12.hpp:190
Represents a DirectX 12 sampled image or the base interface for a texture.
Definition dx12.hpp:249
Represents a DirectX 12 index buffer.
Definition dx12.hpp:227
Represents a DirectX 12 sampler.
Definition dx12.hpp:268
Represents a DirectX 12 vertex buffer.
Definition dx12.hpp:207
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
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
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
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