LiteFX 0.4.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:
32 explicit DirectX12VertexBufferLayout(size_t vertexSize, UInt32 binding = 0);
33
40 explicit DirectX12VertexBufferLayout(size_t vertexSize, const Enumerable<BufferAttribute>& attributes, UInt32 binding = 0);
41
42 private:
45
48
50 DirectX12VertexBufferLayout& operator=(DirectX12VertexBufferLayout&&) noexcept = delete;
51
54
55 public:
57 ~DirectX12VertexBufferLayout() noexcept override;
58
59 public:
66 static inline auto create(size_t vertexSize, UInt32 binding = 0) {
67 return SharedObject::create<DirectX12VertexBufferLayout>(vertexSize, binding);
68 }
69
77 static inline auto create(size_t vertexSize, const Enumerable<BufferAttribute>& attributes, UInt32 binding = 0) {
78 return SharedObject::create<DirectX12VertexBufferLayout>(vertexSize, attributes, binding);
79 }
80
86 static inline auto create(const DirectX12VertexBufferLayout& other) {
88 }
89
90 // IVertexBufferLayout interface.
91 public:
93 const Array<BufferAttribute>& attributes() const override;
94
95 // IBufferLayout interface.
96 public:
98 size_t elementSize() const noexcept override;
99
101 UInt32 binding() const noexcept override;
102
104 BufferType type() const noexcept override;
105 };
106
112 class LITEFX_DIRECTX12_API DirectX12IndexBufferLayout final : public IIndexBufferLayout {
113 LITEFX_IMPLEMENTATION(DirectX12IndexBufferLayoutImpl);
115
116 private:
122
123 private:
126
129
131 DirectX12IndexBufferLayout& operator=(DirectX12IndexBufferLayout&&) noexcept = delete;
132
134 DirectX12IndexBufferLayout& operator=(const DirectX12IndexBufferLayout&) = delete;
135
136 public:
138 ~DirectX12IndexBufferLayout() noexcept override;
139
140 public:
146 static inline auto create(IndexType type) {
148 }
149
155 static inline auto create(const DirectX12IndexBufferLayout& other) {
157 }
158
159 // IIndexBufferLayout interface.
160 public:
162 IndexType indexType() const noexcept override;
163
164 // IBufferLayout interface.
165 public:
167 size_t elementSize() const noexcept override;
168
170 UInt32 binding() const noexcept override;
171
173 BufferType type() const noexcept override;
174 };
175
183 class LITEFX_DIRECTX12_API IDirectX12Buffer : public virtual IBuffer, public virtual IResource<ComPtr<ID3D12Resource>> {
184 protected:
185 IDirectX12Buffer() noexcept = default;
186 IDirectX12Buffer(IDirectX12Buffer&&) noexcept = default;
188 IDirectX12Buffer& operator=(IDirectX12Buffer&&) noexcept = default;
189 IDirectX12Buffer& operator=(const IDirectX12Buffer&) = delete;
190
191 public:
192 ~IDirectX12Buffer() noexcept override = default;
193 };
194
200 class LITEFX_DIRECTX12_API IDirectX12VertexBuffer : public virtual VertexBuffer<DirectX12VertexBufferLayout>, public virtual IDirectX12Buffer {
201 protected:
202 IDirectX12VertexBuffer() noexcept = default;
205 IDirectX12VertexBuffer& operator=(IDirectX12VertexBuffer&&) noexcept = default;
207
208 public:
209 ~IDirectX12VertexBuffer() noexcept override = default;
210
211 public:
212 virtual const D3D12_VERTEX_BUFFER_VIEW& view() const noexcept = 0;
213 };
214
220 class LITEFX_DIRECTX12_API IDirectX12IndexBuffer : public virtual IndexBuffer<DirectX12IndexBufferLayout>, public virtual IDirectX12Buffer {
221 protected:
222 IDirectX12IndexBuffer() noexcept = default;
225 IDirectX12IndexBuffer& operator=(IDirectX12IndexBuffer&&) noexcept = default;
226 IDirectX12IndexBuffer& operator=(const IDirectX12IndexBuffer&) = delete;
227
228 public:
229 ~IDirectX12IndexBuffer() noexcept override = default;
230
231 public:
232 virtual const D3D12_INDEX_BUFFER_VIEW& view() const noexcept = 0;
233 };
234
242 class LITEFX_DIRECTX12_API IDirectX12Image : public virtual IImage, public virtual IResource<ComPtr<ID3D12Resource>> {
243 protected:
244 IDirectX12Image() noexcept = default;
245 IDirectX12Image(IDirectX12Image&&) noexcept = default;
247 IDirectX12Image& operator=(IDirectX12Image&&) noexcept = default;
248 IDirectX12Image& operator=(const IDirectX12Image&) = delete;
249
250 public:
251 ~IDirectX12Image() noexcept override = default;
252 };
253
261 class LITEFX_DIRECTX12_API IDirectX12Sampler : public virtual ISampler {
262 protected:
263 IDirectX12Sampler() noexcept = default;
266 IDirectX12Sampler& operator=(IDirectX12Sampler&&) noexcept = default;
267 IDirectX12Sampler& operator=(const IDirectX12Sampler&) = delete;
268
269 public:
270 ~IDirectX12Sampler() noexcept override = default;
271 };
272
290
297 friend class DirectX12Device;
299
303
304 public:
312 explicit DirectX12BottomLevelAccelerationStructure(AccelerationStructureFlags flags = AccelerationStructureFlags::None, StringView name = "");
313
316
319
322
325
328
329 // IAccelerationStructure interface.
330 public:
332 AccelerationStructureFlags flags() const noexcept override;
333
335 SharedPtr<const IDirectX12Buffer> buffer() const noexcept;
336
338 void build(const DirectX12CommandBuffer& commandBuffer, const SharedPtr<const IDirectX12Buffer>& scratchBuffer = nullptr, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
339
341 void update(const DirectX12CommandBuffer& commandBuffer, const SharedPtr<const IDirectX12Buffer>& scratchBuffer = nullptr, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
342
344 void copy(const DirectX12CommandBuffer& commandBuffer, DirectX12BottomLevelAccelerationStructure& destination, bool compress = false, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, bool copyBuildInfo = true) const;
345
347 UInt64 offset() const noexcept override;
348
350 UInt64 size() const noexcept override;
351
352 // IBottomLevelAccelerationStructure interface.
353 public:
355 const Array<TriangleMesh>& triangleMeshes() const noexcept override;
356
358 void addTriangleMesh(const TriangleMesh& mesh) override;
359
361 const Array<BoundingBoxes>& boundingBoxes() const noexcept override;
362
364 void addBoundingBox(const BoundingBoxes& aabb) override;
365
367 void clear() noexcept override;
368
370 bool remove(const TriangleMesh& mesh) noexcept override;
371
373 bool remove(const BoundingBoxes& aabb) noexcept override;
374
375 private:
376 Array<D3D12_RAYTRACING_GEOMETRY_DESC> buildInfo() const;
377
378 private:
379 SharedPtr<const IBuffer> getBuffer() const noexcept override;
380 void doBuild(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
381 void doUpdate(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
382 void doCopy(const ICommandBuffer& commandBuffer, IBottomLevelAccelerationStructure& destination, bool compress, const SharedPtr<const IBuffer>& buffer, UInt64 offset, bool copyBuildInfo) const override;
383 };
384
389 class LITEFX_DIRECTX12_API DirectX12TopLevelAccelerationStructure final : public ITopLevelAccelerationStructure, public virtual StateResource, public virtual IDirectX12AccelerationStructure {
390 LITEFX_IMPLEMENTATION(DirectX12TopLevelAccelerationStructureImpl);
391 friend class DirectX12Device;
393
397
398 public:
406 explicit DirectX12TopLevelAccelerationStructure(AccelerationStructureFlags flags = AccelerationStructureFlags::None, StringView name = "");
407
410
413
416
419
422
423 // IAccelerationStructure interface.
424 public:
426 AccelerationStructureFlags flags() const noexcept override;
427
429 SharedPtr<const IDirectX12Buffer> buffer() const noexcept;
430
432 void build(const DirectX12CommandBuffer& commandBuffer, const SharedPtr<const IDirectX12Buffer>& scratchBuffer = nullptr, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
433
435 void update(const DirectX12CommandBuffer& commandBuffer, const SharedPtr<const IDirectX12Buffer>& scratchBuffer = nullptr, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, UInt64 maxSize = 0);
436
438 void copy(const DirectX12CommandBuffer& commandBuffer, DirectX12TopLevelAccelerationStructure& destination, bool compress = false, const SharedPtr<const IDirectX12Buffer>& buffer = nullptr, UInt64 offset = 0, bool copyBuildInfo = true) const;
439
441 UInt64 offset() const noexcept override;
442
444 UInt64 size() const noexcept override;
445
446 // ITopLevelAccelerationStructure interface.
447 public:
449 const Array<Instance>& instances() const noexcept override;
450
452 void addInstance(const Instance& instance) override;
453
455 void clear() noexcept override;
456
458 bool remove(const Instance& instance) noexcept override;
459
460 private:
461 Array<D3D12_RAYTRACING_INSTANCE_DESC> buildInfo() const;
462
463 private:
464 SharedPtr<const IBuffer> getBuffer() const noexcept override;
465 void doBuild(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
466 void doUpdate(const ICommandBuffer& commandBuffer, const SharedPtr<const IBuffer>& scratchBuffer, const SharedPtr<const IBuffer>& buffer, UInt64 offset, UInt64 maxSize) override;
467 void doCopy(const ICommandBuffer& commandBuffer, ITopLevelAccelerationStructure& destination, bool compress, const SharedPtr<const IBuffer>& buffer, UInt64 offset, bool copyBuildInfo) const override;
468 };
469
477 class LITEFX_DIRECTX12_API DirectX12Barrier final : public Barrier<IDirectX12Buffer, IDirectX12Image> {
478 LITEFX_IMPLEMENTATION(DirectX12BarrierImpl);
479 LITEFX_BUILDER(DirectX12BarrierBuilder);
480
481 public:
483 using base_type::transition;
484
485 public:
491 explicit DirectX12Barrier(PipelineStage syncBefore, PipelineStage syncAfter) noexcept;
492
495
498
500 DirectX12Barrier& operator=(DirectX12Barrier&&) noexcept;
501
504
506 ~DirectX12Barrier() noexcept override;
507
508 private:
509 explicit DirectX12Barrier() noexcept;
510 PipelineStage& syncBefore() noexcept;
511 PipelineStage& syncAfter() noexcept;
512
513 // Barrier interface.
514 public:
516 PipelineStage syncBefore() const noexcept override;
517
519 PipelineStage syncAfter() const noexcept override;
520
522 void wait(ResourceAccess accessBefore, ResourceAccess accessAfter) override;
523
525 void transition(const IDirectX12Buffer& buffer, ResourceAccess accessBefore, ResourceAccess accessAfter) override;
526
528 void transition(const IDirectX12Buffer& buffer, UInt32 element, ResourceAccess accessBefore, ResourceAccess accessAfter) override;
529
531 void transition(const IDirectX12Image& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) override;
532
534 void transition(const IDirectX12Image& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) override;
535
537 void transition(const IDirectX12Image& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) override;
538
540 void transition(const IDirectX12Image& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) override;
541
542 public:
548 void execute(const DirectX12CommandBuffer& commandBuffer) const;
549 };
550
556 class LITEFX_DIRECTX12_API DirectX12ShaderModule final : public IShaderModule, public ComResource<IDxcBlob> {
557 LITEFX_IMPLEMENTATION(DirectX12ShaderModuleImpl);
558
559 public:
568 explicit DirectX12ShaderModule(const DirectX12Device& device, ShaderStage type, const String& fileName, const String& entryPoint = "main", const Optional<DescriptorBindingPoint>& shaderLocalDescriptor = std::nullopt);
569
579 explicit DirectX12ShaderModule(const DirectX12Device& device, ShaderStage type, std::istream& stream, const String& name, const String& entryPoint = "main", const Optional<DescriptorBindingPoint>& shaderLocalDescriptor = std::nullopt);
580
583
586
589
591 DirectX12ShaderModule& operator=(const DirectX12ShaderModule&) = delete;
592
594 ~DirectX12ShaderModule() noexcept override;
595
596 // IShaderModule interface.
597 public:
599 const String& fileName() const noexcept override;
600
602 const String& entryPoint() const noexcept override;
603
605 ShaderStage type() const noexcept override;
606
608 const Optional<DescriptorBindingPoint>& shaderLocalDescriptor() const noexcept override;
609 };
610
616 class LITEFX_DIRECTX12_API DirectX12ShaderProgram final : public ShaderProgram<DirectX12ShaderModule> {
617 LITEFX_IMPLEMENTATION(DirectX12ShaderProgramImpl);
618 LITEFX_BUILDER(DirectX12ShaderProgramBuilder);
620
621 private:
628
633 explicit DirectX12ShaderProgram(const DirectX12Device& device) noexcept;
634
635 private:
638
641
643 DirectX12ShaderProgram& operator=(DirectX12ShaderProgram&&) noexcept = delete;
644
646 DirectX12ShaderProgram& operator=(const DirectX12ShaderProgram&) = delete;
647
648 public:
650 ~DirectX12ShaderProgram() noexcept override;
651
652 // Factory method.
653 public:
660 static inline auto create(const DirectX12Device& device, Enumerable<UniquePtr<DirectX12ShaderModule>>&& modules) -> SharedPtr<DirectX12ShaderProgram> {
661 return SharedObject::create<DirectX12ShaderProgram>(device, std::move(modules));
662 }
663
664 private:
669 static inline auto create(const DirectX12Device& device) {
671 }
672
673 public:
675 const Array<UniquePtr<const DirectX12ShaderModule>>& modules() const noexcept override;
676
678 virtual SharedPtr<DirectX12PipelineLayout> reflectPipelineLayout() const;
679
680 private:
681 SharedPtr<IPipelineLayout> parsePipelineLayout() const override {
682 return std::static_pointer_cast<IPipelineLayout>(this->reflectPipelineLayout());
683 }
684
685 public:
698 static void suppressMissingRootSignatureWarning(bool disableWarning = true) noexcept;
699 };
700
706 LITEFX_IMPLEMENTATION(DirectX12DescriptorSetImpl);
707
708 public:
710 using base_type::update;
711
712 public:
719 explicit DirectX12DescriptorSet(const DirectX12DescriptorSetLayout& layout, ComPtr<ID3D12DescriptorHeap>&& bufferHeap, ComPtr<ID3D12DescriptorHeap>&& samplerHeap);
720
723
726
728 DirectX12DescriptorSet& operator=(DirectX12DescriptorSet&&) noexcept = delete;
729
732
734 ~DirectX12DescriptorSet() noexcept override;
735
736 public:
741 virtual const DirectX12DescriptorSetLayout& layout() const noexcept;
742
743 public:
745 void update(UInt32 binding, const IDirectX12Buffer& buffer, UInt32 bufferElement = 0, UInt32 elements = 0, UInt32 firstDescriptor = 0) const override;
746
748 void update(UInt32 binding, const IDirectX12Image& texture, UInt32 descriptor = 0, UInt32 firstLevel = 0, UInt32 levels = 0, UInt32 firstLayer = 0, UInt32 layers = 0) const override;
749
751 void update(UInt32 binding, const IDirectX12Sampler& sampler, UInt32 descriptor = 0) const override;
752
754 void update(UInt32 binding, const IDirectX12AccelerationStructure& accelerationStructure, UInt32 descriptor = 0) const override;
755
756 public:
761 virtual const ComPtr<ID3D12DescriptorHeap>& bufferHeap() const noexcept;
762
767 virtual UInt32 bufferOffset() const noexcept;
768
773 virtual const ComPtr<ID3D12DescriptorHeap>& samplerHeap() const noexcept;
774
779 virtual UInt32 samplerOffset() const noexcept;
780 };
781
790 class LITEFX_DIRECTX12_API DirectX12DescriptorLayout final : public IDescriptorLayout {
791 LITEFX_IMPLEMENTATION(DirectX12DescriptorLayoutImpl);
792
793 public:
802 DirectX12DescriptorLayout(DescriptorType type, UInt32 binding, size_t elementSize, UInt32 descriptors = 1, bool local = false);
803
810 DirectX12DescriptorLayout(const IDirectX12Sampler& staticSampler, UInt32 binding, bool local = false);
811
814
817
820
823
825 ~DirectX12DescriptorLayout() noexcept override;
826
827 // DirectX 12 descriptor layout.
828 public:
836 bool local() const noexcept;
837
838 // IDescriptorLayout interface.
839 public:
841 DescriptorType descriptorType() const noexcept override;
842
844 UInt32 descriptors() const noexcept override;
845
847 const IDirectX12Sampler* staticSampler() const noexcept override;
848
849 // IBufferLayout interface.
850 public:
852 size_t elementSize() const noexcept override;
853
855 UInt32 binding() const noexcept override;
856
858 BufferType type() const noexcept override;
859 };
860
867 LITEFX_IMPLEMENTATION(DirectX12DescriptorSetLayoutImpl);
868 LITEFX_BUILDER(DirectX12DescriptorSetLayoutBuilder);
871
872 public:
874 using base_type::free;
875 using base_type::allocate;
876
877 private:
885 explicit DirectX12DescriptorSetLayout(const DirectX12Device& device, const Enumerable<DirectX12DescriptorLayout>& descriptorLayouts, UInt32 space, ShaderStage stages);
886
891 explicit DirectX12DescriptorSetLayout(const DirectX12Device& device);
892
893 private:
896
899
901 DirectX12DescriptorSetLayout& operator=(DirectX12DescriptorSetLayout&&) noexcept = delete;
902
905
906 public:
908 ~DirectX12DescriptorSetLayout() noexcept override;
909
910 public:
919 static inline auto create(const DirectX12Device& device, const Enumerable<DirectX12DescriptorLayout>& descriptorLayouts, UInt32 space, ShaderStage stages) {
920 return SharedObject::create<DirectX12DescriptorSetLayout>(device, descriptorLayouts, space, stages);
921 }
922
928 static inline auto create(const DirectX12DescriptorSetLayout& other) {
930 }
931
932 private:
938 static inline auto create(const DirectX12Device& device) {
940 }
941
942 public:
950 virtual UInt32 descriptorOffsetForBinding(UInt32 binding) const;
951
956 virtual SharedPtr<const DirectX12Device> device() const noexcept;
957
958 protected:
966 virtual bool isRuntimeArray() const noexcept;
967
968 public:
970 const Array<DirectX12DescriptorLayout>& descriptors() const noexcept override;
971
973 const DirectX12DescriptorLayout& descriptor(UInt32 binding) const override;
974
976 UInt32 space() const noexcept override;
977
979 ShaderStage shaderStages() const noexcept override;
980
982 UInt32 uniforms() const noexcept override;
983
985 UInt32 storages() const noexcept override;
986
988 UInt32 images() const noexcept override;
989
991 UInt32 buffers() const noexcept override;
992
994 UInt32 samplers() const noexcept override;
995
997 UInt32 staticSamplers() const noexcept override;
998
1000 UInt32 inputAttachments() const noexcept override;
1001
1002 public:
1004 UniquePtr<DirectX12DescriptorSet> allocate(UInt32 descriptors, std::initializer_list<DescriptorBinding> bindings) const override;
1005
1007 UniquePtr<DirectX12DescriptorSet> allocate(UInt32 descriptors, Span<DescriptorBinding> bindings) const override;
1008
1010 UniquePtr<DirectX12DescriptorSet> allocate(UInt32 descriptors, Generator<DescriptorBinding> bindings) const override;
1011
1013 Generator<UniquePtr<DirectX12DescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::initializer_list<std::initializer_list<DescriptorBinding>> bindings = { }) const override;
1014
1015#ifdef __cpp_lib_mdspan
1017 Generator<UniquePtr<DirectX12DescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::mdspan<DescriptorBinding, std::dextents<size_t, 2>> bindings) const override;
1018#endif
1019
1021 Generator<UniquePtr<DirectX12DescriptorSet>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::function<Generator<DescriptorBinding>(UInt32)> bindingFactory) const override;
1022
1024 void free(const DirectX12DescriptorSet& descriptorSet) const override;
1025 };
1026
1031 class LITEFX_DIRECTX12_API DirectX12PushConstantsRange final : public IPushConstantsRange {
1032 LITEFX_IMPLEMENTATION(DirectX12PushConstantsRangeImpl);
1034
1035 public:
1044 explicit DirectX12PushConstantsRange(ShaderStage shaderStages, UInt32 offset, UInt32 size, UInt32 space, UInt32 binding);
1045
1048
1051
1054
1057
1059 ~DirectX12PushConstantsRange() noexcept override;
1060
1061 public:
1063 UInt32 space() const noexcept override;
1064
1066 UInt32 binding() const noexcept override;
1067
1069 UInt32 offset() const noexcept override;
1070
1072 UInt32 size() const noexcept override;
1073
1075 ShaderStage stage() const noexcept override;
1076 };
1077
1090 LITEFX_IMPLEMENTATION(DirectX12PushConstantsLayoutImpl);
1091 LITEFX_BUILDER(DirectX12PushConstantsLayoutBuilder);
1093
1094 public:
1101
1104
1107
1110
1113
1115 ~DirectX12PushConstantsLayout() noexcept override;
1116
1117 private:
1122 explicit DirectX12PushConstantsLayout(UInt32 size);
1123
1124 public:
1126 UInt32 size() const noexcept override;
1127
1129 const DirectX12PushConstantsRange& range(ShaderStage stage) const override;
1130
1132 const Array<UniquePtr<DirectX12PushConstantsRange>>& ranges() const override;
1133
1134 protected:
1140 };
1141
1146 class LITEFX_DIRECTX12_API DirectX12PipelineLayout final : public PipelineLayout<DirectX12DescriptorSetLayout, DirectX12PushConstantsLayout>, public ComResource<ID3D12RootSignature> {
1147 LITEFX_IMPLEMENTATION(DirectX12PipelineLayoutImpl);
1148 LITEFX_BUILDER(DirectX12PipelineLayoutBuilder);
1150
1151 private:
1158 explicit DirectX12PipelineLayout(const DirectX12Device& device, const Enumerable<SharedPtr<DirectX12DescriptorSetLayout>>& descriptorSetLayouts, UniquePtr<DirectX12PushConstantsLayout>&& pushConstantsLayout);
1159
1164 explicit DirectX12PipelineLayout(const DirectX12Device& device);
1165
1166 private:
1169
1172
1174 DirectX12PipelineLayout& operator=(DirectX12PipelineLayout&&) noexcept = delete;
1175
1177 DirectX12PipelineLayout& operator=(const DirectX12PipelineLayout&) = delete;
1178
1179 public:
1181 ~DirectX12PipelineLayout() noexcept override;
1182
1183 public:
1191 static inline auto create(const DirectX12Device& device, const Enumerable<SharedPtr<DirectX12DescriptorSetLayout>>& descriptorSetLayouts, UniquePtr<DirectX12PushConstantsLayout>&& pushConstantsLayout) {
1192 return SharedObject::create<DirectX12PipelineLayout>(device, descriptorSetLayouts, std::move(pushConstantsLayout));
1193 }
1194
1195 private:
1201 static inline auto create(const DirectX12Device& device) {
1203 }
1204
1205 // PipelineLayout interface.
1206 public:
1208 const DirectX12Device& device() const noexcept /*override*/;
1209
1211 const DirectX12DescriptorSetLayout& descriptorSet(UInt32 space) const override;
1212
1214 const Array<SharedPtr<const DirectX12DescriptorSetLayout>>& descriptorSets() const override;
1215
1217 const DirectX12PushConstantsLayout* pushConstants() const noexcept override;
1218
1219 public:
1232 Optional<UInt32> rootParameterIndex(const DirectX12DescriptorSetLayout& layout) const noexcept;
1233
1243 Optional<UInt32> rootParameterIndex(const DirectX12PushConstantsRange& range) const noexcept;
1244 };
1245
1251 LITEFX_IMPLEMENTATION(DirectX12InputAssemblerImpl);
1252 LITEFX_BUILDER(DirectX12InputAssemblerBuilder);
1254
1255 private:
1262 explicit DirectX12InputAssembler(Enumerable<SharedPtr<DirectX12VertexBufferLayout>>&& vertexBufferLayouts, SharedPtr<DirectX12IndexBufferLayout>&& indexBufferLayout, PrimitiveTopology primitiveTopology = PrimitiveTopology::TriangleList);
1263
1267 explicit DirectX12InputAssembler();
1268
1269 private:
1272
1275
1277 DirectX12InputAssembler& operator=(DirectX12InputAssembler&&) noexcept;
1278
1280 DirectX12InputAssembler& operator=(const DirectX12InputAssembler&) = delete;
1281
1282 public:
1284 ~DirectX12InputAssembler() noexcept override;
1285
1286 public:
1294 static inline auto create(Enumerable<SharedPtr<DirectX12VertexBufferLayout>>&& vertexBufferLayouts, SharedPtr<DirectX12IndexBufferLayout>&& indexBufferLayout, PrimitiveTopology primitiveTopology = PrimitiveTopology::TriangleList) {
1295 return SharedObject::create<DirectX12InputAssembler>(std::move(vertexBufferLayouts), std::move(indexBufferLayout), primitiveTopology);
1296 }
1297
1303 static inline auto create(const DirectX12InputAssembler& other) {
1305 }
1306
1307 private:
1312 static inline auto create() {
1314 }
1315
1316 public:
1318 Enumerable<const DirectX12VertexBufferLayout&> vertexBufferLayouts() const override;
1319
1321 const DirectX12VertexBufferLayout& vertexBufferLayout(UInt32 binding) const override;
1322
1324 const DirectX12IndexBufferLayout* indexBufferLayout() const noexcept override;
1325
1327 PrimitiveTopology topology() const noexcept override;
1328 };
1329
1334 class LITEFX_DIRECTX12_API DirectX12Rasterizer final : public Rasterizer {
1335 LITEFX_BUILDER(DirectX12RasterizerBuilder);
1337
1338 private:
1347 explicit DirectX12Rasterizer(PolygonMode polygonMode, CullMode cullMode, CullOrder cullOrder, Float lineWidth = 1.f, const DepthStencilState& depthStencilState = {}) 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:
1381 static inline auto create(PolygonMode polygonMode, CullMode cullMode, CullOrder cullOrder, Float lineWidth = 1.f, const DepthStencilState& depthStencilState = {}) {
1382 return SharedObject::create<DirectX12Rasterizer>(polygonMode, cullMode, cullOrder, lineWidth, depthStencilState);
1383 }
1384
1390 static inline auto create(const DirectX12Rasterizer& other) {
1392 }
1393
1394 private:
1399 static inline auto create() {
1401 }
1402 };
1403
1409 class LITEFX_DIRECTX12_API DirectX12PipelineState : public virtual Pipeline<DirectX12PipelineLayout, DirectX12ShaderProgram>, public ComResource<ID3D12PipelineState> {
1410 protected:
1411 using ComResource<ID3D12PipelineState>::ComResource;
1412
1415 DirectX12PipelineState& operator=(DirectX12PipelineState&&) noexcept = default;
1417
1418 public:
1419 ~DirectX12PipelineState() noexcept override = default;
1420
1421 public:
1426 virtual void use(const DirectX12CommandBuffer& commandBuffer) const = 0;
1427 };
1428
1434 LITEFX_IMPLEMENTATION(DirectX12CommandBufferImpl);
1436
1437 public:
1439 using base_type::dispatch;
1440 using base_type::dispatchIndirect;
1441 using base_type::dispatchMesh;
1442 using base_type::draw;
1443 using base_type::drawIndirect;
1444 using base_type::drawIndexed;
1445 using base_type::drawIndexedIndirect;
1446 using base_type::barrier;
1447 using base_type::transfer;
1448 using base_type::bind;
1449 using base_type::use;
1450 using base_type::pushConstants;
1451 using base_type::buildAccelerationStructure;
1452 using base_type::updateAccelerationStructure;
1453 using base_type::copyAccelerationStructure;
1454
1455 private:
1462 explicit DirectX12CommandBuffer(const DirectX12Queue& queue, bool begin = false, bool primary = true);
1463
1464 private:
1467
1470
1472 DirectX12CommandBuffer& operator=(DirectX12CommandBuffer&&) noexcept = delete;
1473
1475 DirectX12CommandBuffer& operator=(const DirectX12CommandBuffer&) = delete;
1476
1477 public:
1479 ~DirectX12CommandBuffer() noexcept override;
1480
1481 public:
1488 static inline SharedPtr<DirectX12CommandBuffer> create(const DirectX12Queue& queue, bool begin = false, bool primary = true) {
1489 return SharedObject::create<DirectX12CommandBuffer>(queue, begin, primary);
1490 }
1491
1492 // CommandBuffer interface.
1493 public:
1495 SharedPtr<const DirectX12Queue> queue() const noexcept;
1496
1498 void begin() const override;
1499
1501 void end() const override;
1502
1504 void track(SharedPtr<const IBuffer> buffer) const override;
1505
1507 void track(SharedPtr<const IImage> image) const override;
1508
1510 void track(SharedPtr<const ISampler> sampler) const override;
1511
1513 bool isSecondary() const noexcept override;
1514
1516 void setViewports(Span<const IViewport*> viewports) const override;
1517
1519 void setViewports(const IViewport* viewport) const override;
1520
1522 void setScissors(Span<const IScissor*> scissors) const override;
1523
1525 void setScissors(const IScissor* scissor) const override;
1526
1528 void setBlendFactors(const Vector4f& blendFactors) const noexcept override;
1529
1531 void setStencilRef(UInt32 stencilRef) const noexcept override;
1532
1534 UInt64 submit() const override;
1535
1537 [[nodiscard]] UniquePtr<DirectX12Barrier> makeBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const override;
1538
1540 void barrier(const DirectX12Barrier& barrier) const noexcept override;
1541
1543 void transfer(const IDirectX12Buffer& source, const IDirectX12Buffer& target, UInt32 sourceElement = 0, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1544
1546 void transfer(const void* const data, size_t size, const IDirectX12Buffer& target, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1547
1549 void transfer(Span<const void* const> data, size_t elementSize, const IDirectX12Buffer& target, UInt32 firstElement = 0) const override;
1550
1552 void transfer(const IDirectX12Buffer& source, const IDirectX12Image& target, UInt32 sourceElement = 0, UInt32 firstSubresource = 0, UInt32 elements = 1) const override;
1553
1555 void transfer(const void* const data, size_t size, const IDirectX12Image& target, UInt32 subresource = 0) const override;
1556
1558 void transfer(Span<const void* const> data, size_t elementSize, const IDirectX12Image& target, UInt32 firstSubresource = 0, UInt32 subresources = 1) const override;
1559
1561 void transfer(const IDirectX12Image& source, const IDirectX12Image& target, UInt32 sourceSubresource = 0, UInt32 targetSubresource = 0, UInt32 subresources = 1) const override;
1562
1564 void transfer(const IDirectX12Image& source, const IDirectX12Buffer& target, UInt32 firstSubresource = 0, UInt32 targetElement = 0, UInt32 subresources = 1) const override;
1565
1567 void transfer(const SharedPtr<const IDirectX12Buffer>& source, const IDirectX12Buffer& target, UInt32 sourceElement = 0, UInt32 targetElement = 0, UInt32 elements = 1) const override;
1568
1570 void transfer(const SharedPtr<const IDirectX12Buffer>& source, const IDirectX12Image& target, UInt32 sourceElement = 0, UInt32 firstSubresource = 0, UInt32 elements = 1) const override;
1571
1573 void transfer(const SharedPtr<const IDirectX12Image>& source, const IDirectX12Image& target, UInt32 sourceSubresource = 0, UInt32 targetSubresource = 0, UInt32 subresources = 1) const override;
1574
1576 void transfer(const SharedPtr<const IDirectX12Image>& source, const IDirectX12Buffer& target, UInt32 firstSubresource = 0, UInt32 targetElement = 0, UInt32 subresources = 1) const override;
1577
1579 void use(const DirectX12PipelineState& pipeline) const noexcept override;
1580
1582 void bind(const DirectX12DescriptorSet& descriptorSet) const override;
1583
1585 void bind(Span<const DirectX12DescriptorSet*> descriptorSets) const override;
1586
1588 void bind(const DirectX12DescriptorSet& descriptorSet, const DirectX12PipelineState& pipeline) const override;
1589
1591 void bind(Span<const DirectX12DescriptorSet*> descriptorSets, const DirectX12PipelineState& pipeline) const override;
1592
1594 void bind(const IDirectX12VertexBuffer& buffer) const noexcept override;
1595
1597 void bind(const IDirectX12IndexBuffer& buffer) const noexcept override;
1598
1600 void dispatch(const Vector3u& threadCount) const noexcept override;
1601
1603 void dispatchIndirect(const IDirectX12Buffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1604
1606 void dispatchIndirect(const IDirectX12Buffer& batchBuffer, const IDirectX12Buffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept;
1607
1609 void dispatchMesh(const Vector3u& threadCount) const noexcept override;
1610
1612 void dispatchMeshIndirect(const IDirectX12Buffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1613
1615 void dispatchMeshIndirect(const IDirectX12Buffer& batchBuffer, const IDirectX12Buffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1616
1618 void draw(UInt32 vertices, UInt32 instances = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) const noexcept override;
1619
1621 void drawIndirect(const IDirectX12Buffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1622
1624 void drawIndirect(const IDirectX12Buffer& batchBuffer, const IDirectX12Buffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1625
1627 void drawIndexed(UInt32 indices, UInt32 instances = 1, UInt32 firstIndex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0) const noexcept override;
1628
1630 void drawIndexedIndirect(const IDirectX12Buffer& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept override;
1631
1633 void drawIndexedIndirect(const IDirectX12Buffer& batchBuffer, const IDirectX12Buffer& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept override;
1634
1636 void pushConstants(const DirectX12PushConstantsLayout& layout, const void* const memory) const override;
1637
1639 void writeTimingEvent(const SharedPtr<const TimingEvent>& timingEvent) const override;
1640
1642 void execute(const SharedPtr<const DirectX12CommandBuffer>& commandBuffer) const override;
1643
1645 void execute(Enumerable<SharedPtr<const DirectX12CommandBuffer>> commandBuffers) const override;
1646
1648 void buildAccelerationStructure(DirectX12BottomLevelAccelerationStructure& blas, const SharedPtr<const IDirectX12Buffer>& scratchBuffer, const IDirectX12Buffer& buffer, UInt64 offset = 0) const override;
1649
1651 void buildAccelerationStructure(DirectX12TopLevelAccelerationStructure& tlas, const SharedPtr<const IDirectX12Buffer>& scratchBuffer, const IDirectX12Buffer& buffer, UInt64 offset = 0) const override;
1652
1654 void updateAccelerationStructure(DirectX12BottomLevelAccelerationStructure& blas, const SharedPtr<const IDirectX12Buffer>& scratchBuffer, const IDirectX12Buffer& buffer, UInt64 offset = 0) const override;
1655
1657 void updateAccelerationStructure(DirectX12TopLevelAccelerationStructure& tlas, const SharedPtr<const IDirectX12Buffer>& scratchBuffer, const IDirectX12Buffer& buffer, UInt64 offset = 0) const override;
1658
1660 void copyAccelerationStructure(const DirectX12BottomLevelAccelerationStructure& from, const DirectX12BottomLevelAccelerationStructure& to, bool compress = false) const noexcept override;
1661
1663 void copyAccelerationStructure(const DirectX12TopLevelAccelerationStructure& from, const DirectX12TopLevelAccelerationStructure& to, bool compress = false) const noexcept override;
1664
1666 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;
1667
1668 private:
1669 inline SharedPtr<const ICommandQueue> getQueue() const noexcept override {
1670 return std::static_pointer_cast<const ICommandQueue>(this->queue());
1671 }
1672
1673 void releaseSharedState() const override;
1674 };
1675
1680 class LITEFX_DIRECTX12_API DirectX12Queue final : public CommandQueue<DirectX12CommandBuffer>, public ComResource<ID3D12CommandQueue> {
1681 LITEFX_IMPLEMENTATION(DirectX12QueueImpl);
1683
1684 public:
1686 using base_type::submit;
1687
1688 private:
1695 explicit DirectX12Queue(const DirectX12Device& device, QueueType type, QueuePriority priority);
1696
1697 private:
1699 DirectX12Queue(DirectX12Queue&&) noexcept = delete;
1700
1702 DirectX12Queue(const DirectX12Queue&) = delete;
1703
1705 DirectX12Queue& operator=(DirectX12Queue&&) noexcept = delete;
1706
1708 DirectX12Queue& operator=(const DirectX12Queue&) = delete;
1709
1710 public:
1712 ~DirectX12Queue() noexcept override;
1713
1714 public:
1722 static inline SharedPtr<DirectX12Queue> create(const DirectX12Device& device, QueueType type, QueuePriority priority) {
1723 return SharedObject::create<DirectX12Queue>(device, type, priority);
1724 }
1725
1726 // DirectX12Queue interface.
1727 public:
1732 virtual SharedPtr<const DirectX12Device> device() const noexcept;
1733
1734 // CommandQueue interface.
1735 public:
1737 QueuePriority priority() const noexcept override;
1738
1740 QueueType type() const noexcept override;
1741
1742#if defined(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS) && defined(LITEFX_BUILD_WITH_PIX_RUNTIME)
1743 public:
1745 void beginDebugRegion(const String& label, const Vectors::ByteVector3& color = DEFAULT_DEBUG_COLOR) const noexcept override;
1746
1748 void endDebugRegion() const noexcept override;
1749
1751 void setDebugMarker(const String& label, const Vectors::ByteVector3& color = DEFAULT_DEBUG_COLOR) const noexcept override;
1752#endif // defined(LITEFX_BUILD_SUPPORT_DEBUG_MARKERS) && defined(LITEFX_BUILD_WITH_PIX_RUNTIME)
1753
1754 public:
1756 SharedPtr<DirectX12CommandBuffer> createCommandBuffer(bool beginRecording = false, bool secondary = false) const override;
1757
1759 UInt64 submit(const SharedPtr<const DirectX12CommandBuffer>& commandBuffer) const override;
1760
1762 UInt64 submit(Enumerable<SharedPtr<const DirectX12CommandBuffer>> commandBuffers) const override;
1763
1765 void waitFor(UInt64 fence) const override;
1766
1768 void waitFor(const DirectX12Queue& queue, UInt64 fence) const noexcept;
1769
1771 UInt64 currentFence() const noexcept override;
1772
1773 private:
1774 inline void waitForQueue(const ICommandQueue& queue, UInt64 fence) const override {
1775 auto d3dQueue = dynamic_cast<const DirectX12Queue*>(&queue);
1776
1777 if (d3dQueue == nullptr) [[unlikely]]
1778 throw InvalidArgumentException("queue", "Cannot wait for queues from other backends.");
1779
1780 this->waitFor(*d3dQueue, fence);
1781 }
1782 };
1783
1789 class LITEFX_DIRECTX12_API DirectX12RenderPipeline final : public virtual DirectX12PipelineState, public RenderPipeline<DirectX12PipelineLayout, DirectX12ShaderProgram, DirectX12InputAssembler, DirectX12Rasterizer> {
1790 LITEFX_IMPLEMENTATION(DirectX12RenderPipelineImpl);
1791 LITEFX_BUILDER(DirectX12RenderPipelineBuilder);
1792
1793 public:
1805 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 = "");
1806
1809
1812
1814 DirectX12RenderPipeline& operator=(DirectX12RenderPipeline&&) noexcept = delete;
1815
1818
1820 ~DirectX12RenderPipeline() noexcept override;
1821
1822 private:
1828 DirectX12RenderPipeline(const DirectX12RenderPass& renderPass, const String& name = "");
1829
1830 // Pipeline interface.
1831 public:
1833 SharedPtr<const DirectX12ShaderProgram> program() const noexcept override;
1834
1836 SharedPtr<const DirectX12PipelineLayout> layout() const noexcept override;
1837
1838 // RenderPipeline interface.
1839 public:
1841 SharedPtr<DirectX12InputAssembler> inputAssembler() const noexcept override;
1842
1844 SharedPtr<DirectX12Rasterizer> rasterizer() const noexcept override;
1845
1847 bool alphaToCoverage() const noexcept override;
1848
1850 MultiSamplingLevel samples() const noexcept override;
1851
1853 void updateSamples(MultiSamplingLevel samples) override;
1854
1855 // DirectX12PipelineState interface.
1856 public:
1858 void use(const DirectX12CommandBuffer& commandBuffer) const override;
1859 };
1860
1867 LITEFX_IMPLEMENTATION(DirectX12ComputePipelineImpl);
1868 LITEFX_BUILDER(DirectX12ComputePipelineBuilder);
1869
1870 public:
1878 explicit DirectX12ComputePipeline(const DirectX12Device& device, const SharedPtr<DirectX12PipelineLayout>& layout, const SharedPtr<DirectX12ShaderProgram>& shaderProgram, const String& name = "");
1879
1882
1885
1888
1891
1893 ~DirectX12ComputePipeline() noexcept override;
1894
1895 private:
1900 DirectX12ComputePipeline(const DirectX12Device& device) noexcept;
1901
1902 // Pipeline interface.
1903 public:
1905 SharedPtr<const DirectX12ShaderProgram> program() const noexcept override;
1906
1908 SharedPtr<const DirectX12PipelineLayout> layout() const noexcept override;
1909
1910 // DirectX12PipelineState interface.
1911 public:
1912 void use(const DirectX12CommandBuffer& commandBuffer) const noexcept override;
1913 };
1914
1928 LITEFX_IMPLEMENTATION(DirectX12RayTracingPipelineImpl);
1929 LITEFX_BUILDER(DirectX12RayTracingPipelineBuilder);
1930
1931 public:
1943 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)
1944
1947
1950
1953
1956
1958 ~DirectX12RayTracingPipeline() noexcept override;
1959
1960 private:
1966 DirectX12RayTracingPipeline(const DirectX12Device& device, ShaderRecordCollection&& shaderRecords) noexcept;
1967
1968 // Pipeline interface.
1969 public:
1971 SharedPtr<const DirectX12ShaderProgram> program() const noexcept override;
1972
1974 SharedPtr<const DirectX12PipelineLayout> layout() const noexcept override;
1975
1976 // RayTracingPipeline interface.
1977 public:
1979 const ShaderRecordCollection& shaderRecords() const noexcept override;
1980
1982 UInt32 maxRecursionDepth() const noexcept override;
1983
1985 UInt32 maxPayloadSize() const noexcept override;
1986
1988 UInt32 maxAttributeSize() const noexcept override;
1989
1991 SharedPtr<IDirectX12Buffer> allocateShaderBindingTable(ShaderBindingTableOffsets& offsets, ShaderBindingGroup groups = ShaderBindingGroup::All) const override;
1992
1993 // DirectX12PipelineState interface.
1994 public:
1996 void use(const DirectX12CommandBuffer& commandBuffer) const noexcept override;
1997
2002 ComPtr<ID3D12StateObject> stateObject() const noexcept;
2003 };
2004
2009 class LITEFX_DIRECTX12_API DirectX12FrameBuffer final : public FrameBuffer<IDirectX12Image> {
2010 LITEFX_IMPLEMENTATION(DirectX12FrameBufferImpl);
2012
2013 public:
2014 using FrameBuffer::addImage;
2015 using FrameBuffer::mapRenderTarget;
2016 using FrameBuffer::mapRenderTargets;
2017
2018 private:
2025 DirectX12FrameBuffer(const DirectX12Device& device, const Size2d& renderArea, StringView name = "");
2026
2027 private:
2029 DirectX12FrameBuffer(DirectX12FrameBuffer&&) noexcept = delete;
2030
2033
2035 DirectX12FrameBuffer& operator=(DirectX12FrameBuffer&&) noexcept = delete;
2036
2038 DirectX12FrameBuffer& operator=(const DirectX12FrameBuffer&) = delete;
2039
2040 public:
2042 ~DirectX12FrameBuffer() noexcept override;
2043
2044 public:
2052 static inline SharedPtr<DirectX12FrameBuffer> create(const DirectX12Device& device, const Size2d& renderArea, StringView name = "") {
2053 return SharedObject::create<DirectX12FrameBuffer>(device, renderArea, name);
2054 }
2055
2056 // DirectX 12 FrameBuffer
2057 public:
2064 D3D12_CPU_DESCRIPTOR_HANDLE descriptorHandle(UInt32 imageIndex) const;
2065
2072 D3D12_CPU_DESCRIPTOR_HANDLE descriptorHandle(StringView imageName) const;
2073
2080 D3D12_CPU_DESCRIPTOR_HANDLE descriptorHandle(const RenderTarget& renderTarget) const;
2081
2082 // FrameBuffer interface.
2083 public:
2085 const Size2d& size() const noexcept override;
2086
2088 size_t getWidth() const noexcept override;
2089
2091 size_t getHeight() const noexcept override;
2092
2094 void mapRenderTarget(const RenderTarget& renderTarget, UInt32 index) override;
2095
2097 void mapRenderTarget(const RenderTarget& renderTarget, StringView name) override;
2098
2100 void unmapRenderTarget(const RenderTarget& renderTarget) noexcept override;
2101
2103 const Array<SharedPtr<const IDirectX12Image>>& images() const override;
2104
2106 inline const IDirectX12Image& operator[](UInt32 index) const override {
2107 return this->image(index);
2108 }
2109
2111 const IDirectX12Image& image(UInt32 index) const override;
2112
2114 inline const IDirectX12Image& operator[](const RenderTarget& renderTarget) const override {
2115 return this->image(renderTarget);
2116 }
2117
2119 const IDirectX12Image& image(const RenderTarget& renderTarget) const override;
2120
2122 inline const IDirectX12Image& operator[](StringView renderTargetName) const override {
2123 return this->resolveImage(hash(renderTargetName));
2124 }
2125
2127 inline const IDirectX12Image& image(StringView renderTargetName) const override {
2128 return this->resolveImage(hash(renderTargetName));
2129 }
2130
2132 const IDirectX12Image& resolveImage(UInt64 hash) const override;
2133
2135 void addImage(const String& name, Format format, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::FrameBufferImage) override;
2136
2138 void addImage(const String& name, const RenderTarget& renderTarget, MultiSamplingLevel samples = MultiSamplingLevel::x1, ResourceUsage usage = ResourceUsage::FrameBufferImage) override;
2139
2141 void resize(const Size2d& renderArea) override;
2142 };
2143
2148 class LITEFX_DIRECTX12_API DirectX12RenderPass final : public RenderPass<DirectX12Queue, DirectX12FrameBuffer> {
2149 LITEFX_IMPLEMENTATION(DirectX12RenderPassImpl);
2150 LITEFX_BUILDER(DirectX12RenderPassBuilder);
2152
2153 public:
2155
2156 private:
2166 explicit DirectX12RenderPass(const DirectX12Device& device, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u);
2167
2178 explicit DirectX12RenderPass(const DirectX12Device& device, const String& name, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u);
2179
2190 explicit DirectX12RenderPass(const DirectX12Device& device, const DirectX12Queue& queue, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u);
2191
2203 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);
2204
2205 private:
2207 DirectX12RenderPass(DirectX12RenderPass&&) noexcept = delete;
2208
2210 DirectX12RenderPass(const DirectX12RenderPass&) = delete;
2211
2213 DirectX12RenderPass& operator=(DirectX12RenderPass&&) noexcept = delete;
2214
2216 DirectX12RenderPass& operator=(const DirectX12RenderPass&) = delete;
2217
2218 public:
2220 ~DirectX12RenderPass() noexcept override;
2221
2222 public:
2233 static inline SharedPtr<DirectX12RenderPass> create(const DirectX12Device& device, Span<RenderTarget> renderTargets, Span<RenderPassDependency> inputAttachments = { }, Optional<DescriptorBindingPoint> inputAttachmentSamplerBinding = std::nullopt, UInt32 secondaryCommandBuffers = 1u) {
2234 return SharedObject::create<DirectX12RenderPass>(device, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers);
2235 }
2236
2248 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) {
2249 return SharedObject::create<DirectX12RenderPass>(device, name, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers);
2250 }
2251
2263 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) {
2264 return SharedObject::create<DirectX12RenderPass>(device, queue, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers);
2265 }
2266
2279 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) {
2280 return SharedObject::create<DirectX12RenderPass>(device, name, queue, renderTargets, inputAttachments, inputAttachmentSamplerBinding, secondaryCommandBuffers);
2281 }
2282
2283 private:
2289 explicit DirectX12RenderPass(const DirectX12Device& device, const String& name = "");
2290
2301 static inline SharedPtr<DirectX12RenderPass> create(const DirectX12Device& device, const String& name = "") {
2302 return SharedObject::create<DirectX12RenderPass>(device, name);
2303 }
2304
2305 // RenderPass interface.
2306 public:
2311 const DirectX12Device& device() const noexcept /*override*/;
2312
2314 SharedPtr<const DirectX12FrameBuffer> activeFrameBuffer() const noexcept override;
2315
2317 const DirectX12Queue& commandQueue() const noexcept override;
2318
2320 Enumerable<SharedPtr<const DirectX12CommandBuffer>> commandBuffers() const override;
2321
2323 SharedPtr<const DirectX12CommandBuffer> commandBuffer(UInt32 index) const override;
2324
2326 UInt32 secondaryCommandBuffers() const noexcept override;
2327
2329 const Array<RenderTarget>& renderTargets() const noexcept override;
2330
2332 const RenderTarget& renderTarget(UInt32 location) const override;
2333
2335 bool hasPresentTarget() const noexcept override;
2336
2338 const Array<RenderPassDependency>& inputAttachments() const noexcept override;
2339
2341 const RenderPassDependency& inputAttachment(UInt32 location) const override;
2342
2344 const Optional<DescriptorBindingPoint>& inputAttachmentSamplerBinding() const noexcept override;
2345
2347 void begin(const DirectX12FrameBuffer& frameBuffer) const override;
2348
2350 UInt64 end() const override;
2351 };
2352
2356 class LITEFX_DIRECTX12_API DirectX12SwapChain final : public SwapChain<IDirectX12Image>, public ComResource<IDXGISwapChain4> {
2357 LITEFX_IMPLEMENTATION(DirectX12SwapChainImpl);
2359 friend class DirectX12Image;
2360 friend class DirectX12Device;
2361
2362 public:
2364
2365 private:
2375 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)
2376
2377 public:
2380
2383
2385 DirectX12SwapChain& operator=(DirectX12SwapChain&&) noexcept = delete;
2386
2388 DirectX12SwapChain& operator=(const DirectX12SwapChain&) = delete;
2389
2391 ~DirectX12SwapChain() noexcept override;
2392
2393 // DirectX 12 swap chain.
2394 public:
2399 virtual bool supportsVariableRefreshRate() const noexcept;
2400
2405 virtual ID3D12QueryHeap* timestampQueryHeap() const noexcept;
2406
2407 // SwapChain interface.
2408 public:
2410 const Array<SharedPtr<const TimingEvent>>& timingEvents() const override;
2411
2413 SharedPtr<const TimingEvent> timingEvent(UInt32 queryId) const override;
2414
2416 UInt64 readTimingEvent(SharedPtr<const TimingEvent> timingEvent) const override;
2417
2419 UInt32 resolveQueryId(SharedPtr<const TimingEvent> timingEvent) const override;
2420
2422 const IGraphicsDevice& device() const override;
2423
2425 Format surfaceFormat() const noexcept override;
2426
2428 UInt32 buffers() const noexcept override;
2429
2431 const Size2d& renderArea() const noexcept override;
2432
2434 bool verticalSynchronization() const noexcept override;
2435
2437 IDirectX12Image* image(UInt32 backBuffer) const override;
2438
2440 const IDirectX12Image& image() const noexcept override;
2441
2443 const Array<SharedPtr<IDirectX12Image>>& images() const noexcept override;
2444
2446 void present(UInt64 fence) const override;
2447
2448 public:
2450 Enumerable<Format> getSurfaceFormats() const override;
2451
2453 void addTimingEvent(SharedPtr<const TimingEvent> timingEvent) override;
2454
2456 void reset(Format surfaceFormat, const Size2d& renderArea, UInt32 buffers, bool enableVsync = false) override;
2457
2459 [[nodiscard]] UInt32 swapBackBuffer() const override;
2460
2461 private:
2462 void resolveQueryHeaps(const DirectX12CommandBuffer& commandBuffer) const noexcept;
2463 };
2464
2472 LITEFX_IMPLEMENTATION(DirectX12GraphicsFactoryImpl);
2473 friend class DirectX12Device;
2475
2476 public:
2478 using base_type::createBuffer;
2479 using base_type::createVertexBuffer;
2480 using base_type::createIndexBuffer;
2481 using base_type::createTexture;
2482 using base_type::createTextures;
2483 using base_type::createSampler;
2484 using base_type::createSamplers;
2485
2486 private:
2491 explicit DirectX12GraphicsFactory(const DirectX12Device& device);
2492
2493 private:
2496
2499
2501 DirectX12GraphicsFactory& operator=(DirectX12GraphicsFactory&&) noexcept = delete;
2502
2504 DirectX12GraphicsFactory& operator=(const DirectX12GraphicsFactory&) = delete;
2505
2506 public:
2508 ~DirectX12GraphicsFactory() noexcept override;
2509
2510 private:
2515 static inline SharedPtr<DirectX12GraphicsFactory> create(const DirectX12Device& device) {
2517 }
2518
2519 public:
2521 SharedPtr<IDirectX12Buffer> createBuffer(BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default) const override;
2522
2524 SharedPtr<IDirectX12Buffer> createBuffer(const String& name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default) const override;
2525
2527 SharedPtr<IDirectX12VertexBuffer> createVertexBuffer(const DirectX12VertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default) const override;
2528
2530 SharedPtr<IDirectX12VertexBuffer> createVertexBuffer(const String& name, const DirectX12VertexBufferLayout& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default) const override;
2531
2533 SharedPtr<IDirectX12IndexBuffer> createIndexBuffer(const DirectX12IndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default) const override;
2534
2536 SharedPtr<IDirectX12IndexBuffer> createIndexBuffer(const String& name, const DirectX12IndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default) const override;
2537
2539 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) const override;
2540
2542 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) const override;
2543
2545 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) const override;
2546
2548 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;
2549
2551 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;
2552
2554 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;
2555
2557 UniquePtr<DirectX12BottomLevelAccelerationStructure> createBottomLevelAccelerationStructure(StringView name, AccelerationStructureFlags flags = AccelerationStructureFlags::None) const override;
2558
2560 UniquePtr<DirectX12TopLevelAccelerationStructure> createTopLevelAccelerationStructure(StringView name, AccelerationStructureFlags flags = AccelerationStructureFlags::None) const override;
2561 };
2562
2566 class LITEFX_DIRECTX12_API DirectX12Device final : public GraphicsDevice<DirectX12GraphicsFactory, DirectX12Surface, DirectX12GraphicsAdapter, DirectX12SwapChain, DirectX12Queue, DirectX12RenderPass, DirectX12RenderPipeline, DirectX12ComputePipeline, DirectX12RayTracingPipeline, DirectX12Barrier>, public ComResource<ID3D12Device10> {
2567 LITEFX_IMPLEMENTATION(DirectX12DeviceImpl);
2569 friend class DirectX12Backend;
2570
2571 private:
2579 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);
2580
2581 private:
2583 DirectX12Device(DirectX12Device&&) noexcept = delete;
2584
2586 DirectX12Device(const DirectX12Device&) = delete;
2587
2589 DirectX12Device& operator=(DirectX12Device&&) noexcept = delete;
2590
2592 DirectX12Device& operator=(const DirectX12Device&) = delete;
2593
2594 public:
2596 ~DirectX12Device() noexcept override;
2597
2598 // Factory methods.
2599 public:
2609 static inline SharedPtr<DirectX12Device> create(const DirectX12Backend& backend, const DirectX12GraphicsAdapter& adapter, UniquePtr<DirectX12Surface>&& surface, GraphicsDeviceFeatures features = {}) {
2610 return SharedObject::create<DirectX12Device>(adapter, std::move(surface))->initialize(backend, Format::B8G8R8A8_SRGB, { 800, 600 }, 3, false, features); // NOLINT(cppcoreguidelines-avoid-magic-numbers)
2611 }
2612
2627 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) {
2628 return SharedObject::create<DirectX12Device>(adapter, std::move(surface), globalBufferHeapSize, globalSamplerHeapSize)->initialize(backend, format, renderArea, backBuffers, enableVsync, features);
2629 }
2630
2631 private:
2642 SharedPtr<DirectX12Device> initialize(const DirectX12Backend& backend, Format format, const Size2d& renderArea, UInt32 backBuffers, bool enableVsync, GraphicsDeviceFeatures features);
2643
2647 void release() noexcept;
2648
2649 // DirectX 12 Device interface.
2650 public:
2658 const ID3D12DescriptorHeap* globalBufferHeap() const noexcept;
2659
2665 const ID3D12DescriptorHeap* globalSamplerHeap() const noexcept;
2666
2673 void allocateGlobalDescriptors(const DirectX12DescriptorSet& descriptorSet, UInt32& bufferOffset, UInt32& samplerOffset) const;
2674
2684 void releaseGlobalDescriptors(const DirectX12DescriptorSet& descriptorSet) const;
2685
2692 void updateBufferDescriptors(const DirectX12DescriptorSet& descriptorSet, UInt32 firstDescriptor, UInt32 descriptors) const noexcept;
2693
2700 void updateSamplerDescriptors(const DirectX12DescriptorSet& descriptorSet, UInt32 firstDescriptor, UInt32 descriptors) const noexcept;
2701
2712 void bindDescriptorSet(const DirectX12CommandBuffer& commandBuffer, const DirectX12DescriptorSet& descriptorSet, const DirectX12PipelineState& pipeline) const noexcept;
2713
2718 void bindGlobalDescriptorHeaps(const DirectX12CommandBuffer& commandBuffer) const noexcept;
2719
2727 void indirectDrawSignatures(ComPtr<ID3D12CommandSignature>& dispatchSignature, ComPtr<ID3D12CommandSignature>& dispatchMeshSignature, ComPtr<ID3D12CommandSignature>& drawSignature, ComPtr<ID3D12CommandSignature>& drawIndexedSignature) const noexcept;
2728
2729 // GraphicsDevice interface.
2730 public:
2732 DeviceState& state() const noexcept override;
2733
2735 const DirectX12SwapChain& swapChain() const noexcept override;
2736
2738 DirectX12SwapChain& swapChain() noexcept override;
2739
2741 const DirectX12Surface& surface() const noexcept override;
2742
2744 const DirectX12GraphicsAdapter& adapter() const noexcept override;
2745
2747 const DirectX12GraphicsFactory& factory() const noexcept override;
2748
2750 const DirectX12Queue& defaultQueue(QueueType type) const override;
2751
2753 SharedPtr<const DirectX12Queue> createQueue(QueueType type, QueuePriority priority) override;
2754
2756 [[nodiscard]] UniquePtr<DirectX12Barrier> makeBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const override;
2757
2759 [[nodiscard]] SharedPtr<DirectX12FrameBuffer> makeFrameBuffer(StringView name, const Size2d& renderArea) const override;
2760
2763 MultiSamplingLevel maximumMultiSamplingLevel(Format format) const noexcept override;
2764
2766 double ticksPerMillisecond() const noexcept override;
2767
2769 void wait() const override;
2770
2772 void computeAccelerationStructureSizes(const DirectX12BottomLevelAccelerationStructure& blas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate = false) const override;
2773
2775 void computeAccelerationStructureSizes(const DirectX12TopLevelAccelerationStructure& tlas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate = false) const override;
2776
2777#if defined(LITEFX_BUILD_DEFINE_BUILDERS)
2778 public:
2780 [[nodiscard]] DirectX12RenderPassBuilder buildRenderPass(UInt32 commandBuffers = 1) const override;
2781
2783 [[nodiscard]] DirectX12RenderPassBuilder buildRenderPass(const String& name, UInt32 commandBuffers = 1) const override;
2784
2786 //[[nodiscard]] DirectX12RenderPipelineBuilder buildRenderPipeline(const String& name) const override;
2787
2789 [[nodiscard]] DirectX12RenderPipelineBuilder buildRenderPipeline(const DirectX12RenderPass& renderPass, const String& name) const override;
2790
2792 [[nodiscard]] DirectX12ComputePipelineBuilder buildComputePipeline(const String& name) const override;
2793
2795 [[nodiscard]] DirectX12RayTracingPipelineBuilder buildRayTracingPipeline(ShaderRecordCollection&& shaderRecords) const override;
2796
2798 [[nodiscard]] DirectX12RayTracingPipelineBuilder buildRayTracingPipeline(const String& name, ShaderRecordCollection&& shaderRecords) const override;
2799
2801 [[nodiscard]] DirectX12PipelineLayoutBuilder buildPipelineLayout() const override;
2802
2804 [[nodiscard]] DirectX12InputAssemblerBuilder buildInputAssembler() const override;
2805
2807 [[nodiscard]] DirectX12RasterizerBuilder buildRasterizer() const override;
2808
2810 [[nodiscard]] DirectX12ShaderProgramBuilder buildShaderProgram() const override;
2811
2813 [[nodiscard]] DirectX12BarrierBuilder buildBarrier() const override;
2814#endif // defined(LITEFX_BUILD_DEFINE_BUILDERS)
2815 };
2816
2820 class LITEFX_DIRECTX12_API DirectX12Backend final : public RenderBackend<DirectX12Device>, public ComResource<IDXGIFactory7> {
2821 LITEFX_IMPLEMENTATION(DirectX12BackendImpl);
2822
2823 public:
2824 explicit DirectX12Backend(const App& app, bool advancedSoftwareRasterizer = false);
2825
2828
2831
2833 DirectX12Backend& operator=(DirectX12Backend&&) noexcept;
2834
2836 DirectX12Backend& operator=(const DirectX12Backend&) = delete;
2837
2839 ~DirectX12Backend() noexcept override;
2840
2841 // IBackend interface.
2842 public:
2844 BackendType type() const noexcept override;
2845
2847 StringView name() const noexcept override;
2848
2849 protected:
2851 void activate() override;
2852
2854 void deactivate() override;
2855
2856 // RenderBackend interface.
2857 public:
2859 const Array<SharedPtr<const DirectX12GraphicsAdapter>>& adapters() const override;
2860
2862 const DirectX12GraphicsAdapter* findAdapter(const Optional<UInt64>& adapterId = std::nullopt) const noexcept override;
2863
2865 void registerDevice(const String& name, SharedPtr<DirectX12Device>&& device) override;
2866
2868 void releaseDevice(const String& name) override;
2869
2871 DirectX12Device* device(const String& name) noexcept override;
2872
2874 const DirectX12Device* device(const String& name) const noexcept override;
2875
2876 public:
2882 UniquePtr<DirectX12Surface> createSurface(const HWND& hwnd) const;
2883
2892 virtual void enableAdvancedSoftwareRasterizer(bool enable = false);
2893 };
2894
2895}
2896
2897#pragma warning(pop)
The base class for an application.
Definition app.hpp:402
Provides access to a resource managed by the class.
Definition containers.hpp:792
An exception that is thrown, if a provided argument is not valid.
Definition exceptions.hpp:60
Definition math.hpp:850
Definition math.hpp:819
Definition math.hpp:490
Definition math.hpp:534
Implements the DirectX 12 RenderBackend.
Definition dx12.hpp:2820
DirectX12Backend(DirectX12Backend &&) noexcept
Implements a DirectX 12 resource barrier.
Definition dx12.hpp:477
DirectX12Barrier(DirectX12Barrier &&) noexcept
Implements a DirectX 12 bottom-level acceleration structure (BLAS).
Definition dx12.hpp:295
DirectX12BottomLevelAccelerationStructure(DirectX12BottomLevelAccelerationStructure &&) noexcept
Records commands for a DirectX12Queue
Definition dx12.hpp:1433
Implements a DirectX 12 ComputePipeline.
Definition dx12.hpp:1866
DirectX12ComputePipeline(DirectX12ComputePipeline &&) noexcept
Implements a DirectX 12 IDescriptorLayout
Definition dx12.hpp:790
DirectX12DescriptorLayout(DirectX12DescriptorLayout &&) noexcept
Implements a DirectX 12 DescriptorSet.
Definition dx12.hpp:705
DirectX12DescriptorSet(DirectX12DescriptorSet &&) noexcept=delete
Implements a DirectX 12 DescriptorSetLayout.
Definition dx12.hpp:866
static auto create(const DirectX12DescriptorSetLayout &other)
Creates a copy of a DirectX 12 descriptor set layout.
Definition dx12.hpp:928
Implements a DirectX 12 graphics device.
Definition dx12.hpp:2566
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:2627
Implements a DirectX 12 frame buffer.
Definition dx12.hpp:2009
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:2127
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:2114
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:2122
Implements a DirectX12 IGraphicsAdapter.
Definition dx12_api.hpp:224
A graphics factory that produces objects for a DirectX12Device.
Definition dx12.hpp:2471
Implements a DirectX12 IImage.
Definition image.h:16
Implements a DirectX 12 index buffer layout.
Definition dx12.hpp:112
static auto create(const DirectX12IndexBufferLayout &other)
Creates a copy of an index buffer layout.
Definition dx12.hpp:155
Implements the DirectX 12 input assembler state.
Definition dx12.hpp:1250
static auto create(const DirectX12InputAssembler &other)
Creates a new DirectX 12 input assembler state as a copy from another one.
Definition dx12.hpp:1303
Implements a DirectX 12 PipelineLayout.
Definition dx12.hpp:1146
Defines the base class for DirectX 12 pipeline state objects.
Definition dx12.hpp:1409
DirectX12PipelineState(DirectX12PipelineState &&) noexcept=default
Implements the DirectX 12 PushConstantsLayout.
Definition dx12.hpp:1089
DirectX12PushConstantsLayout(DirectX12PushConstantsLayout &&) noexcept
Implements the DirectX 12 IPushConstantsRange.
Definition dx12.hpp:1031
DirectX12PushConstantsRange(DirectX12PushConstantsRange &&) noexcept
Implements a DirectX 12 command queue.
Definition dx12.hpp:1680
Implements a DirectX 12 IRasterizer.
Definition dx12.hpp:1334
static auto create(const DirectX12Rasterizer &other)
Creates a new DirectX 12 rasterizer state by copying an existing one.
Definition dx12.hpp:1390
Implements a DirectX 12 RayTracingPipeline.
Definition dx12.hpp:1927
DirectX12RayTracingPipeline(DirectX12RayTracingPipeline &&) noexcept
Implements a DirectX 12 render pass.
Definition dx12.hpp:2148
static SharedPtr< DirectX12RenderPass > create(const DirectX12Device &device, const String &name, Span< RenderTarget > renderTargets, Span< RenderPassDependency > inputAttachments={ }, Optional< DescriptorBindingPoint > inputAttachmentSamplerBinding=std::nullopt, UInt32 secondaryCommandBuffers=1u)
Creates and initializes a new DirectX 12 render pass instance that executes on the default graphics q...
Definition dx12.hpp:2248
static SharedPtr< DirectX12RenderPass > create(const DirectX12Device &device, const DirectX12Queue &queue, Span< RenderTarget > renderTargets, Span< RenderPassDependency > inputAttachments={ }, Optional< DescriptorBindingPoint > inputAttachmentSamplerBinding=std::nullopt, UInt32 secondaryCommandBuffers=1u)
Creates and initializes a new DirectX 12 render pass instance.
Definition dx12.hpp:2263
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)
Creates and initializes a new DirectX 12 render pass instance.
Definition dx12.hpp:2279
Implements a DirectX 12 RenderPipeline.
Definition dx12.hpp:1789
DirectX12RenderPipeline(DirectX12RenderPipeline &&) noexcept=delete
Implements a DirectX 12 IShaderModule.
Definition dx12.hpp:556
DirectX12ShaderModule(DirectX12ShaderModule &&) noexcept
Implements a DirectX 12 ShaderProgram.
Definition dx12.hpp:616
Implements a DirectX12 ISurface.
Definition dx12_api.hpp:290
Implements a DirectX 12 swap chain.
Definition dx12.hpp:2356
DirectX12SwapChain(DirectX12SwapChain &&) noexcept=delete
Implements a DirectX 12 top-level acceleration structure (TLAS).
Definition dx12.hpp:389
DirectX12TopLevelAccelerationStructure(DirectX12TopLevelAccelerationStructure &&) noexcept
Implements a DirectX 12 vertex buffer layout.
Definition dx12.hpp:21
static auto create(const DirectX12VertexBufferLayout &other)
Creates a copy of a vertex buffer layout.
Definition dx12.hpp:86
static auto create(size_t vertexSize, const Enumerable< BufferAttribute > &attributes, UInt32 binding=0)
Creates a new vertex buffer layout.
Definition dx12.hpp:77
Represents the base interface for a DirectX 12 acceleration structure implementation.
Definition dx12.hpp:279
Represents the base interface for a DirectX 12 buffer implementation.
Definition dx12.hpp:183
Represents a DirectX 12 sampled image or the base interface for a texture.
Definition dx12.hpp:242
Represents a DirectX 12 index buffer.
Definition dx12.hpp:220
Represents a DirectX 12 sampler.
Definition dx12.hpp:261
Represents a DirectX 12 vertex buffer.
Definition dx12.hpp:200
A barrier used for GPU resource synchronization.
Definition rendering.hpp:17
Represents a command buffer, that buffers commands that should be submitted to a CommandQueue.
Definition rendering.hpp:597
Represents a command queue.
Definition rendering.hpp:1090
Represents a compute Pipeline.
Definition rendering.hpp:1001
Stores the depth/stencil state of a see IRasterizer.
Definition rendering_api.hpp:3143
Defines a set of descriptors.
Definition rendering.hpp:150
Describes the layout of a descriptor set.
Definition rendering.hpp:215
A class that can be used to manage the state of a IGraphicsDevice.
Definition rendering_api.hpp:2312
Stores the images used by a RenderPass to either read from using input attachments or write to using ...
Definition rendering.hpp:1057
Represents the graphics device that a rendering back-end is doing work on.
Definition rendering.hpp:1431
Describes a factory that creates objects for a GraphicsDevice.
Definition rendering.hpp:1254
Base interface for a ray tracing acceleration structure.
Definition rendering_api.hpp:4449
void update(const ICommandBuffer &commandBuffer, const SharedPtr< const IBuffer > &scratchBuffer=nullptr, const SharedPtr< const IBuffer > &buffer=nullptr, UInt64 offset=0, UInt64 maxSize=0)
Performs an update on the acceleration structure.
Definition rendering_api.hpp:4530
void build(const ICommandBuffer &commandBuffer, const SharedPtr< const IBuffer > &scratchBuffer=nullptr, const SharedPtr< const IBuffer > &buffer=nullptr, UInt64 offset=0, UInt64 maxSize=0)
Performs a complete build of the acceleration structure.
Definition rendering_api.hpp:4494
A structure that holds a singular entity of geometry for hardware ray-tracing.
Definition rendering_api.hpp:4588
void copy(const ICommandBuffer &commandBuffer, IBottomLevelAccelerationStructure &destination, bool compress=false, const SharedPtr< const IBuffer > &buffer=nullptr, UInt64 offset=0, bool copyBuildInfo=true) const
Copies the acceleration structure into the acceleration structure provided by destination .
Definition rendering_api.hpp:4807
Base interface for buffer objects.
Definition rendering_api.hpp:4186
The interface for a command buffer.
Definition rendering_api.hpp:6517
The interface for a command queue.
Definition rendering_api.hpp:8481
Describes a the layout of a single descriptor within a DescriptorSet.
Definition rendering_api.hpp:3993
The interface for a graphics device that.
Definition rendering_api.hpp:9164
Describes a generic image.
Definition rendering_api.hpp:4208
Describes a index buffer layout.
Definition rendering_api.hpp:3952
The interface for a pipeline layout.
Definition rendering_api.hpp:6385
Describes a range within a IPushConstantsLayout.
Definition rendering_api.hpp:5645
Describes a texture sampler.
Definition rendering_api.hpp:4324
The interface of a scissor.
Definition rendering_api.hpp:3562
Represents a single shader module, i.e. a part of a IShaderProgram.
Definition rendering_api.hpp:2755
A structure that stores the instance data for a IBottomLevelAccelerationStructure.
Definition rendering_api.hpp:4870
void copy(const ICommandBuffer &commandBuffer, ITopLevelAccelerationStructure &destination, bool compress=false, const SharedPtr< const IBuffer > &buffer=nullptr, UInt64 offset=0, bool copyBuildInfo=true) const
Copies the acceleration structure into the acceleration structure provided by destination .
Definition rendering_api.hpp:5016
Describes a vertex buffer layout.
Definition rendering_api.hpp:3929
Interface for a viewport.
Definition rendering_api.hpp:3444
Describes an index buffer.
Definition rendering.hpp:479
Represents a the input assembler state of a RenderPipeline.
Definition rendering.hpp:506
Represents a pipeline state.
Definition rendering.hpp:547
Represents a the layout of a RenderPipeline, ComputePipeline or RayTracingPipeline.
Definition rendering.hpp:418
Describes the layout of the pipelines push constant ranges.
Definition rendering.hpp:355
Implements a IRasterizer.
Definition rendering_api.hpp:3371
Represents a ray-tracing Pipeline.
Definition rendering.hpp:1020
Defines a back-end, that provides a device instance for a certain surface and graphics adapter.
Definition rendering.hpp:1642
Represents a mapping between a set of RenderTarget instances and the input attachments of a IRenderPa...
Definition rendering_api.hpp:3076
Represents a render pass.
Definition rendering.hpp:1150
Represents a graphics Pipeline.
Definition rendering.hpp:962
Implements a render target.
Definition rendering_api.hpp:2976
Represents a shader program, consisting of multiple IShaderModules.
Definition rendering.hpp:386
Stores a set of IShaderRecords in that later form a shader binding table used for ray-tracing.
Definition rendering_api.hpp:6007
Base class for a resource that can be identified by a name string within a DeviceState.
Definition rendering_api.hpp:2265
Represents a swap chain, i.e. a chain of multiple IImage instances, that can be presented to a ISurfa...
Definition rendering.hpp:1210
An event that is used to measure timestamps in a command queue.
Definition rendering_api.hpp:3726
Describes a vertex buffer.
Definition rendering.hpp:455
Implements the IResource interface.
Definition containers.hpp:823
static auto create(TArgs &&... args) -> SharedPtr< T >
Generic factory method used to create instances of the shared object.
Definition containers.hpp:1114
Concept that can be used to refer to backend implementations.
Definition app.hpp:80
Definition math.hpp:30
uint64_t UInt64
A type for an unsigned 64 bit integer.
Definition math.hpp:66
float_t Float
A type for a floating point value with single precision.
Definition math.hpp:71
uint32_t UInt32
A type for an unsigned 32 bit integer.
Definition math.hpp:56
int32_t Int32
A type for a signed 32 bit integer.
Definition math.hpp:51
Definition dx12.hpp:11
Definition dx12.hpp:11
BorderMode
Describes how to treat texture coordinates that are outside the domain [0..1].
Definition rendering_api.hpp:1184
CullOrder
Describes the order or vertex winding, that is used to determine, whether a polygon is facing towards...
Definition rendering_api.hpp:1018
ImageLayout
Specifies the layout of an IImage resource.
Definition rendering_api.hpp:1686
MipMapMode
Describes the filter operation between two mip-map levels.
Definition rendering_api.hpp:1169
CullMode
Describes which faces are culled by the Rasterizer stage.
Definition rendering_api.hpp:991
ShaderStage
Describes the valid shader stages of a graphics pipeline.
Definition rendering_api.hpp:799
IndexType
Describes the element type of an index buffer.
Definition rendering_api.hpp:750
PrimitiveTopology
Describes the topology of a mesh primitive.
Definition rendering_api.hpp:765
@ TriangleList
A list of triangles, where each triplet of vertices refers to a whole triangle.
ShaderBindingGroup
Describes a group or combination of groups of a shader binding table.
Definition rendering_api.hpp:939
@ All
Refers to a combination of all possible groups that can be stored in a shader binding table.
PolygonMode
Describes the draw mode for polygons.
Definition rendering_api.hpp:970
BufferType
Describes the type of a IBuffer.
Definition rendering_api.hpp:540
ResourceUsage
Describes the intended usage for a resource.
Definition rendering_api.hpp:690
ImageDimensions
Describes the dimensions of a image resource, i.e. the dimensions that are required to access a texel...
Definition rendering_api.hpp:1086
DescriptorType
Describes the type of a IDescriptor.
Definition rendering_api.hpp:436
QueuePriority
Specifies the priority with which a queue is scheduled on the GPU.
Definition rendering_api.hpp:159
QueueType
Represents the type of a CommandQueue.
Definition rendering_api.hpp:113
ResourceHeap
Defines where a resource (buffer or image) memory is located and from where it can be accessed.
Definition rendering_api.hpp:649
AccelerationStructureFlags
Controls how an acceleration structure should be built.
Definition rendering_api.hpp:1816
FilterMode
Describes the filter operation when accessing a pixel from a texture coordinate.
Definition rendering_api.hpp:1152
PipelineStage
Defines pipeline stages as points where synchronization may occur.
Definition rendering_api.hpp:1373
ResourceAccess
Defines how a IBuffer or IImage resource is accessed.
Definition rendering_api.hpp:1537
Format
Describes a texel format.
Definition rendering_api.hpp:182
MultiSamplingLevel
Describes the number of samples with which a IImage is sampled.
Definition rendering_api.hpp:1111
std::generator< T, TVal > Generator
Describes an intermediate container for elements of type T .
Definition containers.hpp:206
std::vector< T > Array
Represents a dynamic array.
Definition containers.hpp:73
std::optional< T > Optional
Represents an optional value.
Definition containers.hpp:94
std::shared_ptr< T > SharedPtr
Represents a shared pointer, that expresses non-exclusive ownership.
Definition containers.hpp:109
std::unique_ptr< T, TDeleter > UniquePtr
Represents a unique pointer, that expresses exclusive ownership.
Definition containers.hpp:102
std::string String
Definition string.hpp:24
std::string_view StringView
Definition string.hpp:26
BackendType
Definition app_api.hpp:35
std::span< T > Span
Represents a view of an array.
Definition containers.hpp:87
An input range over another range, where the returned values of type T are covariants of the values ...
Definition containers.hpp:529
An algebraic vector type.
Definition vector.hpp:23
Describes a resource binding to a descriptor or descriptor set.
Definition rendering_api.hpp:5334
Describes a single descriptor binding point within a IShaderModule.
Definition rendering_api.hpp:2735
Describes optional features that can be supported by a device.
Definition rendering_api.hpp:9138
Stores a buffer that contains axis-aligned bounding boxes.
Definition rendering_api.hpp:4670
Represents a triangle mesh.
Definition rendering_api.hpp:4593
Represents an instance of an IBottomLevelAccelerationStructure.
Definition rendering_api.hpp:4877
Describes the offsets and sizes of a shader group within a shader binding table buffer.
Definition rendering_api.hpp:3646
An allocator used to allocate the shared object.
Definition containers.hpp:1098