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);
24 friend struct SharedObject::Allocator<DirectX12VertexBufferLayout>;
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:
46 DirectX12VertexBufferLayout(DirectX12VertexBufferLayout&&) noexcept = delete;
47
49 DirectX12VertexBufferLayout(const DirectX12VertexBufferLayout&);
50
52 DirectX12VertexBufferLayout& operator=(DirectX12VertexBufferLayout&&) noexcept = delete;
53
55 DirectX12VertexBufferLayout& operator=(const DirectX12VertexBufferLayout&) = delete;
56
57 public:
59 ~DirectX12VertexBufferLayout() noexcept override;
60
61 public:
72
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);
121 friend struct SharedObject::Allocator<DirectX12IndexBufferLayout>;
122
123 private:
128 explicit DirectX12IndexBufferLayout(IndexType type);
129
130 private:
132 DirectX12IndexBufferLayout(DirectX12IndexBufferLayout&&) noexcept = delete;
133
135 DirectX12IndexBufferLayout(const DirectX12IndexBufferLayout&);
136
138 DirectX12IndexBufferLayout& operator=(DirectX12IndexBufferLayout&&) noexcept = delete;
139
141 DirectX12IndexBufferLayout& operator=(const DirectX12IndexBufferLayout&) = delete;
142
143 public:
145 ~DirectX12IndexBufferLayout() noexcept override;
146
147 public:
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:
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:
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:
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:
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);
626 friend struct SharedObject::Allocator<DirectX12ShaderProgram>;
627
628 private:
634 explicit DirectX12ShaderProgram(const DirectX12Device& device, Enumerable<UniquePtr<DirectX12ShaderModule>>&& modules);
635
640 explicit DirectX12ShaderProgram(const DirectX12Device& device) noexcept;
641
642 private:
644 DirectX12ShaderProgram(DirectX12ShaderProgram&&) noexcept = delete;
645
647 DirectX12ShaderProgram(const DirectX12ShaderProgram&) = delete;
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:
791
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
857 class LITEFX_DIRECTX12_API DirectX12DescriptorSetLayout final : public DescriptorSetLayout<DirectX12DescriptorLayout, DirectX12DescriptorSet> {
858 LITEFX_IMPLEMENTATION(DirectX12DescriptorSetLayoutImpl);
859 LITEFX_BUILDER(DirectX12DescriptorSetLayoutBuilder);
861 friend struct SharedObject::Allocator<DirectX12DescriptorSetLayout>;
862
863 public:
865 using base_type::free;
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:
886 DirectX12DescriptorSetLayout(DirectX12DescriptorSetLayout&&) noexcept = delete;
887
889 DirectX12DescriptorSetLayout(const DirectX12DescriptorSetLayout& other);
890
892 DirectX12DescriptorSetLayout& operator=(DirectX12DescriptorSetLayout&&) noexcept = delete;
893
895 DirectX12DescriptorSetLayout& operator=(const DirectX12DescriptorSetLayout&) = delete;
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:
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:
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);
1133 friend struct SharedObject::Allocator<DirectX12PipelineLayout>;
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:
1152 DirectX12PipelineLayout(DirectX12PipelineLayout&&) noexcept = delete;
1153
1155 DirectX12PipelineLayout(const DirectX12PipelineLayout&) = delete;
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
1248 class LITEFX_DIRECTX12_API DirectX12InputAssembler final : public InputAssembler<DirectX12VertexBufferLayout, DirectX12IndexBufferLayout> {
1249 LITEFX_IMPLEMENTATION(DirectX12InputAssemblerImpl);
1250 LITEFX_BUILDER(DirectX12InputAssemblerBuilder);
1251 friend struct SharedObject::Allocator<DirectX12InputAssembler>;
1252
1253 private:
1261
1265 explicit DirectX12InputAssembler();
1266
1267 private:
1269 DirectX12InputAssembler(DirectX12InputAssembler&&) noexcept;
1270
1272 DirectX12InputAssembler(const DirectX12InputAssembler&);
1273
1275 DirectX12InputAssembler& operator=(DirectX12InputAssembler&&) noexcept;
1276
1278 DirectX12InputAssembler& operator=(const DirectX12InputAssembler&) = delete;
1279
1280 public:
1282 ~DirectX12InputAssembler() noexcept override;
1283
1284 public:
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);
1334 friend struct SharedObject::Allocator<DirectX12Rasterizer>;
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
1435 class LITEFX_DIRECTX12_API DirectX12CommandBuffer final : public CommandBuffer<DirectX12CommandBuffer, IDirectX12Buffer, IDirectX12VertexBuffer, IDirectX12IndexBuffer, IDirectX12Image, DirectX12Barrier, DirectX12PipelineState, DirectX12BottomLevelAccelerationStructure, DirectX12TopLevelAccelerationStructure>, public ComResource<ID3D12GraphicsCommandList7> {
1436 LITEFX_IMPLEMENTATION(DirectX12CommandBufferImpl);
1437 friend struct SharedObject::Allocator<DirectX12CommandBuffer>;
1438
1439 public:
1440 using base_type = CommandBuffer<DirectX12CommandBuffer, IDirectX12Buffer, IDirectX12VertexBuffer, IDirectX12IndexBuffer, IDirectX12Image, DirectX12Barrier, DirectX12PipelineState, DirectX12BottomLevelAccelerationStructure, DirectX12TopLevelAccelerationStructure>;
1441 using base_type::dispatch;
1444 using base_type::draw;
1448 using base_type::barrier;
1449 using base_type::transfer;
1450 using base_type::bind;
1451 using base_type::use;
1456
1457 private:
1464 explicit DirectX12CommandBuffer(const DirectX12Queue& queue, bool begin = false, bool primary = true);
1465
1466 private:
1468 DirectX12CommandBuffer(DirectX12CommandBuffer&&) noexcept = delete;
1469
1471 DirectX12CommandBuffer(const DirectX12CommandBuffer&) = delete;
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) {
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);
1690 friend struct SharedObject::Allocator<DirectX12Queue>;
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:
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:
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
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:
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:
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
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);
2022 friend struct SharedObject::Allocator<DirectX12FrameBuffer>;
2023
2024 public:
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
2054 DirectX12FrameBuffer(const DirectX12FrameBuffer&) = delete;
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);
2185 friend struct SharedObject::Allocator<DirectX12RenderPass>;
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:
2424 DirectX12SwapChain(DirectX12SwapChain&&) noexcept = delete;
2425
2427 DirectX12SwapChain(const DirectX12SwapChain&) = delete;
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
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;
2519 friend struct SharedObject::Allocator<DirectX12GraphicsFactory>;
2520
2521 public:
2534 using base_type::allocate;
2535
2536 private:
2541 explicit DirectX12GraphicsFactory(const DirectX12Device& device);
2542
2543 private:
2545 DirectX12GraphicsFactory(DirectX12GraphicsFactory&&) noexcept = delete;
2546
2548 DirectX12GraphicsFactory(const DirectX12GraphicsFactory&) = delete;
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
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
2596
2599
2602
2605
2608
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
2620
2623
2626
2629
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
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
2659
2662 };
2663
2668 LITEFX_IMPLEMENTATION(DirectX12DeviceImpl);
2669 friend struct SharedObject::Allocator<DirectX12Device>;
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:
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
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
UniquePtr< DirectX12Surface > createSurface(const HWND &hwnd) const
Creates a surface on a window handle.
Definition backend.cpp:156
BackendType type() const noexcept override
Gets the type of the backend.The type of the backend.BackendType
Definition backend.cpp:83
void registerDevice(const String &name, SharedPtr< DirectX12Device > &&device) override
Definition backend.cpp:116
void activate() override
Called by the parent App, if the backend is started.
Definition backend.cpp:93
StringView name() const noexcept override
Gets the name of the backend.The name of the backend.
Definition backend.cpp:88
virtual void enableAdvancedSoftwareRasterizer(bool enable=false)
Enables Windows Advanced Software Rasterization (WARP).
Definition backend.cpp:161
const DirectX12GraphicsAdapter * findAdapter(const Optional< UInt64 > &adapterId=std::nullopt) const noexcept override
Finds an adapter using its unique ID.Note that the adapter ID is optional, which allows the back-end ...
Definition backend.cpp:108
const Array< SharedPtr< const DirectX12GraphicsAdapter > > & adapters() const override
Definition backend.cpp:103
DirectX12Device * device(const String &name) noexcept override
Looks up a device and returns a pointer to it, or nullptr, if no device with the provided name could...
Definition backend.cpp:140
DirectX12Backend(const App &app, bool advancedSoftwareRasterizer=false)
Definition backend.cpp:72
void deactivate() override
Called by the parent App, if the backend is stopped.
Definition backend.cpp:98
DirectX12Backend(DirectX12Backend &&) noexcept
void releaseDevice(const String &name) override
Destroys and removes a device from the backend.
Definition backend.cpp:128
Implements a DirectX 12 resource barrier.
Definition dx12.hpp:484
DirectX12Barrier(DirectX12Barrier &&) noexcept
Barrier< IDirectX12Buffer, IDirectX12Image > base_type
Definition dx12.hpp:489
void transition(const IDirectX12Buffer &buffer, ResourceAccess accessBefore, ResourceAccess accessAfter) override
Definition barrier.cpp:76
DirectX12Barrier(PipelineStage syncBefore, PipelineStage syncAfter) noexcept
Initializes a new DirectX 12 barrier.
Definition barrier.cpp:35
void execute(const DirectX12CommandBuffer &commandBuffer) const
Adds the barrier to a command buffer and updates the resource target states.
Definition barrier.cpp:106
void wait(ResourceAccess accessBefore, ResourceAccess accessAfter) override
Inserts a global barrier that waits for previous commands to finish accesses described by accessBefor...
Definition barrier.cpp:71
Implements a DirectX 12 bottom-level acceleration structure (BLAS).
Definition dx12.hpp:302
SharedPtr< const IDirectX12Buffer > buffer() const noexcept
Definition blas.cpp:160
void clear() noexcept override
Clears all bounding boxes and triangle meshes from the acceleration structure.
Definition blas.cpp:330
void update(const DirectX12CommandBuffer &commandBuffer, const SharedPtr< const IDirectX12Buffer > &scratchBuffer=nullptr, const SharedPtr< const IDirectX12Buffer > &buffer=nullptr, UInt64 offset=0, UInt64 maxSize=0)
Definition blas.cpp:216
const Array< TriangleMesh > & triangleMeshes() const noexcept override
Returns an array of triangle meshes contained by the BLAS.The array of triangle meshes contained by t...
Definition blas.cpp:304
void build(const DirectX12CommandBuffer &commandBuffer, const SharedPtr< const IDirectX12Buffer > &scratchBuffer=nullptr, const SharedPtr< const IDirectX12Buffer > &buffer=nullptr, UInt64 offset=0, UInt64 maxSize=0)
Definition blas.cpp:178
void addTriangleMesh(const TriangleMesh &mesh) override
Adds a triangle mesh to the BLAS.
Definition blas.cpp:309
UInt64 size() const noexcept override
Returns the amount of memory in bytes inside buffer that store the acceleration structure....
Definition blas.cpp:170
void addBoundingBox(const BoundingBoxes &aabb) override
Adds a buffer containing axis-aligned bounding boxes to the BLAS.
Definition blas.cpp:322
UInt64 offset() const noexcept override
Returns the offset into buffer at which the acceleration structure is stored.The offset into buffer a...
Definition blas.cpp:165
bool remove(const TriangleMesh &mesh) noexcept override
Removes a triangle mesh from the acceleration structure.true, if the triangle mesh was removed,...
Definition blas.cpp:336
void copy(const DirectX12CommandBuffer &commandBuffer, DirectX12BottomLevelAccelerationStructure &destination, bool compress=false, const SharedPtr< const IDirectX12Buffer > &buffer=nullptr, UInt64 offset=0, bool copyBuildInfo=true) const
Definition blas.cpp:261
AccelerationStructureFlags flags() const noexcept override
Returns the flags that control how the acceleration structure should be built.The flags that control ...
Definition blas.cpp:155
const Array< BoundingBoxes > & boundingBoxes() const noexcept override
Returns an array of buffers, each containing axis-aligned bounding boxes stored in the BLAS....
Definition blas.cpp:317
DirectX12BottomLevelAccelerationStructure(AccelerationStructureFlags flags=AccelerationStructureFlags::None, StringView name="")
Initializes a new DirectX 12 bottom-level acceleration structure (BLAS).
Definition blas.cpp:146
DirectX12BottomLevelAccelerationStructure(DirectX12BottomLevelAccelerationStructure &&) noexcept
Records commands for a DirectX12Queue.
Definition dx12.hpp:1435
void begin() const override
Sets the command buffer into recording state, so that it can receive command that should be submitted...
Definition command_buffer.cpp:192
static SharedPtr< DirectX12CommandBuffer > create(const DirectX12Queue &queue, bool begin=false, bool primary=true)
Initializes the command buffer from a command queue.
Definition dx12.hpp:1490
SharedPtr< const DirectX12Queue > queue() const noexcept
Definition command_buffer.cpp:187
CommandBuffer< DirectX12CommandBuffer, IDirectX12Buffer, IDirectX12VertexBuffer, IDirectX12IndexBuffer, IDirectX12Image, DirectX12Barrier, DirectX12PipelineState, DirectX12BottomLevelAccelerationStructure, DirectX12TopLevelAccelerationStructure > base_type
Definition dx12.hpp:1440
Implements a DirectX 12 ComputePipeline.
Definition dx12.hpp:1877
void use(const DirectX12CommandBuffer &commandBuffer) const noexcept override
Sets the current pipeline state on the commandBuffer .
Definition compute_pipeline.cpp:108
DirectX12ComputePipeline(DirectX12ComputePipeline &&) noexcept
SharedPtr< const DirectX12ShaderProgram > program() const noexcept override
Definition compute_pipeline.cpp:98
DirectX12ComputePipeline(const DirectX12Device &device, const SharedPtr< DirectX12PipelineLayout > &layout, const SharedPtr< DirectX12ShaderProgram > &shaderProgram, const String &name="")
Initializes a new DirectX 12 compute pipeline.
Definition compute_pipeline.cpp:80
SharedPtr< const DirectX12PipelineLayout > layout() const noexcept override
Definition compute_pipeline.cpp:103
Implements a DirectX 12 IDescriptorLayout.
Definition dx12.hpp:777
bool unbounded() const noexcept override
Returns true, if the descriptor defines an unbounded descriptor array.true, if the descriptor defines...
Definition descriptor_layout.cpp:93
DirectX12DescriptorLayout(DirectX12DescriptorLayout &&) noexcept
UInt32 binding() const noexcept override
Returns the binding point, the buffer will be bound to.In GLSL, the binding point is identified by th...
Definition descriptor_layout.cpp:98
bool local() const noexcept
Returns true, if the descriptor belongs to the local root signature of a ray-tracing pipeline or fals...
Definition descriptor_layout.cpp:78
UInt32 descriptors() const noexcept override
Returns the number of descriptors in the descriptor array.If unbounded is set to true,...
Definition descriptor_layout.cpp:88
size_t elementSize() const noexcept override
Returns the size of a single element within the buffer.The size of a single element within the buffer...
Definition descriptor_layout.cpp:83
DescriptorType descriptorType() const noexcept override
Returns the type of the descriptor.The type of the descriptor.
Definition descriptor_layout.cpp:108
const IDirectX12Sampler * staticSampler() const noexcept override
If the descriptor describes a static sampler, this method returns the state of the sampler....
Definition descriptor_layout.cpp:113
BufferType type() const noexcept override
Returns the buffer type of the buffer.The buffer type of the buffer.
Definition descriptor_layout.cpp:103
DirectX12DescriptorLayout(DescriptorType type, UInt32 binding, size_t elementSize, UInt32 descriptors=1, bool unbounded=false, bool local=false)
Initializes a new DirectX 12 descriptor layout.
Definition descriptor_layout.cpp:62
Implements a DirectX 12 DescriptorSet.
Definition dx12.hpp:697
virtual const DirectX12DescriptorSetLayout & layout() const noexcept
Returns the parent descriptor set layout.
Definition descriptor_set.cpp:460
DirectX12DescriptorSet(DirectX12DescriptorSet &&) noexcept=delete
virtual const ComPtr< ID3D12DescriptorHeap > localHeap(DescriptorHeapType heapType) const noexcept
Returns the local (CPU-visible) heap that contains the set's descriptors.
Definition descriptor_set.cpp:611
DirectX12DescriptorSet(const DirectX12DescriptorSetLayout &layout, ComPtr< ID3D12DescriptorHeap > &&resourceHeap=nullptr, ComPtr< ID3D12DescriptorHeap > &&samplerHeap=nullptr)
Initializes a new descriptor set.
Definition descriptor_set.cpp:444
void update(UInt32 binding, const IDirectX12Buffer &buffer, UInt32 bufferElement=0, UInt32 elements=0, UInt32 firstDescriptor=0, Format texelFormat=Format::None) const override
Definition descriptor_set.cpp:509
DescriptorSet< IDirectX12Buffer, IDirectX12Image, IDirectX12Sampler, IDirectX12AccelerationStructure > base_type
Definition dx12.hpp:701
UInt32 bindToHeap(DescriptorType bindingType, UInt32 descriptor, const IDirectX12Buffer &buffer, UInt32 bufferElement=0, UInt32 elements=0, Format texelFormat=Format::None) const override
Definition descriptor_set.cpp:470
VirtualAllocator::Allocation globalHeapAllocation(DescriptorHeapType heapType) const noexcept override
Returns the allocation information for the descriptor set in the global descriptor heap indicated by ...
Definition descriptor_set.cpp:465
Implements a DirectX 12 DescriptorSetLayout.
Definition dx12.hpp:857
friend class DirectX12PipelineLayout
Definition dx12.hpp:860
static auto create(const DirectX12Device &device, const Enumerable< DirectX12DescriptorLayout > &descriptorLayouts, UInt32 space, ShaderStage stages)
Creates a DirectX 12 descriptor set layout.
Definition dx12.hpp:910
static auto create(const DirectX12DescriptorSetLayout &other)
Creates a copy of a DirectX 12 descriptor set layout.
Definition dx12.hpp:919
DescriptorSetLayout< DirectX12DescriptorLayout, DirectX12DescriptorSet > base_type
Definition dx12.hpp:864
virtual SharedPtr< const DirectX12Device > device() const noexcept
Returns the parent device or nullptr, if it has been released.
Definition descriptor_set_layout.cpp:245
UInt32 space() const noexcept override
Returns the space index of the descriptor set.The descriptor set space maps to the space index in HLS...
Definition descriptor_set_layout.cpp:263
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
static SharedPtr< DirectX12Device > create(const DirectX12Backend &backend, const DirectX12GraphicsAdapter &adapter, UniquePtr< DirectX12Surface > &&surface, GraphicsDeviceFeatures features={})
Initializes the device instance.
Definition dx12.hpp:2710
friend class DirectX12Backend
Definition dx12.hpp:2670
const DirectX12Surface & surface() const noexcept override
Returns the surface, the device draws to.A reference of the surface, the device draws to.
Definition device.cpp:534
const DirectX12GraphicsAdapter & adapter() const noexcept override
Returns the graphics adapter, the device uses for drawing.A reference of the graphics adapter,...
Definition device.cpp:539
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
IFrameBuffer::allocation_callback_type< image_type > allocation_callback_type
Definition rendering.hpp:1082
static SharedPtr< DirectX12FrameBuffer > create(const DirectX12Device &device, const Size2d &renderArea, StringView name="")
Initializes a DirectX 12 frame buffer.
Definition dx12.hpp:2074
const IDirectX12Image & resolveImage(UInt64 hash) const override
Resolves a render target name hash and returns the image mapped to it.The image mapped to the render ...
Definition frame_buffer.cpp:251
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...
friend class DirectX12Device
Definition dx12.hpp:2518
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
GraphicsFactory< DirectX12DescriptorLayout, IDirectX12Buffer, IDirectX12VertexBuffer, IDirectX12IndexBuffer, IDirectX12Image, IDirectX12Sampler, DirectX12BottomLevelAccelerationStructure, DirectX12TopLevelAccelerationStructure > base_type
Definition dx12.hpp:2522
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
Array< MemoryHeapStatistics > memoryStatistics() const override
Returns an array of objects, that contain information about the current memory usage and available me...
DetailedMemoryStatistics detailedMemoryStatistics() const override
Returns detailed memory statistics.Only call this method for debugging purposes, as it is significant...
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 DirectX 12 index buffer layout.
Definition dx12.hpp:119
static auto create(IndexType type)
Creates a new index buffer layout.
Definition dx12.hpp:153
static auto create(const DirectX12IndexBufferLayout &other)
Creates a copy of an index buffer layout.
Definition dx12.hpp:162
BufferType type() const noexcept override
Returns the buffer type of the buffer.The buffer type of the buffer.
Definition index_buffer_layout.cpp:45
Implements the DirectX 12 input assembler state.
Definition dx12.hpp:1248
const DirectX12IndexBufferLayout * indexBufferLayout() const noexcept override
Returns a pointer to the index buffer layout, or nullptr if the input assembler does not handle indic...
Definition input_assembler.cpp:69
static auto create(const DirectX12InputAssembler &other)
Creates a new DirectX 12 input assembler state as a copy from another one.
Definition dx12.hpp:1301
static auto create(Enumerable< SharedPtr< DirectX12VertexBufferLayout > > &&vertexBufferLayouts, SharedPtr< DirectX12IndexBufferLayout > &&indexBufferLayout, PrimitiveTopology primitiveTopology=PrimitiveTopology::TriangleList)
Creates a new DirectX 12 input assembler state.
Definition dx12.hpp:1292
Enumerable< const DirectX12VertexBufferLayout & > vertexBufferLayouts() const override
Definition input_assembler.cpp:56
Implements a DirectX 12 PipelineLayout.
Definition dx12.hpp:1130
static auto create(const DirectX12Device &device, const Enumerable< SharedPtr< DirectX12DescriptorSetLayout > > &descriptorSetLayouts, UniquePtr< DirectX12PushConstantsLayout > &&pushConstantsLayout)
Creates a new DirectX 12 render pipeline layout.
Definition dx12.hpp:1175
const DirectX12Device & device() const noexcept
Definition pipeline_layout.cpp:328
Defines the base class for DirectX 12 pipeline state objects.
Definition dx12.hpp:1411
DirectX12PipelineState(DirectX12PipelineState &&) noexcept=default
virtual void use(const DirectX12CommandBuffer &commandBuffer) const =0
Sets the current pipeline state on the commandBuffer .
Implements the DirectX 12 PushConstantsLayout.
Definition dx12.hpp:1073
DirectX12PushConstantsLayout(DirectX12PushConstantsLayout &&) noexcept
friend class DirectX12PipelineLayout
Definition dx12.hpp:1076
const Array< UniquePtr< DirectX12PushConstantsRange > > & ranges() const override
Definition push_constants_layout.cpp:82
DirectX12PushConstantsLayout(Enumerable< UniquePtr< DirectX12PushConstantsRange > > &&ranges, UInt32 size)
Initializes a new push constants layout.
Definition push_constants_layout.cpp:49
const DirectX12PushConstantsRange & range(ShaderStage stage) const override
Returns the push constant range associated with the shader stage provided in stage ....
Definition push_constants_layout.cpp:69
UInt32 size() const noexcept override
Returns the size (in bytes) of the push constants backing memory.The size (in bytes) of the push cons...
Definition push_constants_layout.cpp:64
Implements the DirectX 12 IPushConstantsRange.
Definition dx12.hpp:1015
friend class DirectX12PipelineLayout
Definition dx12.hpp:1017
UInt32 size() const noexcept override
Returns the size (in bytes) of the range.The size (in bytes) of the range.offset
Definition push_constants_range.cpp:62
UInt32 space() const noexcept override
Returns the shader space the push constants can be accessed from.The shader space the push constants ...
Definition push_constants_range.cpp:47
UInt32 binding() const noexcept override
Returns the binding point or register, the push constants are made available at.The binding point or ...
Definition push_constants_range.cpp:52
DirectX12PushConstantsRange(DirectX12PushConstantsRange &&) noexcept
UInt32 offset() const noexcept override
Returns the offset from the push constants backing memory block, the range starts at....
Definition push_constants_range.cpp:57
ShaderStage stage() const noexcept override
Returns the shader stage(s), the range is accessible from.The shader stage(s), the range is accessibl...
Definition push_constants_range.cpp:67
DirectX12PushConstantsRange(ShaderStage shaderStages, UInt32 offset, UInt32 size, UInt32 space, UInt32 binding)
Initializes a new push constants range.
Definition push_constants_range.cpp:36
Implements a DirectX 12 command queue.
Definition dx12.hpp:1688
QueueType type() const noexcept override
Returns the type of the queue.The type of the queue.
Definition queue.cpp:119
static SharedPtr< DirectX12Queue > create(const DirectX12Device &device, QueueType type, QueuePriority priority)
Creates the DirectX 12 command queue.
Definition dx12.hpp:1730
CommandQueue< DirectX12CommandBuffer > base_type
Definition dx12.hpp:1693
QueuePriority priority() const noexcept override
Returns the priority of the queue.The priority of the queue.
Definition queue.cpp:141
virtual SharedPtr< const DirectX12Device > device() const noexcept
Returns a pointer to the device that provides this queue or nullptr, if the device has already been r...
Definition queue.cpp:114
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
static auto create(PolygonMode polygonMode, CullMode cullMode, CullOrder cullOrder, Float lineWidth=1.f, bool depthClip=true, const DepthStencilState &depthStencilState={}, bool conservativeRasterization=false)
Creates a new DirectX 12 rasterizer state.
Definition dx12.hpp:1383
Implements a DirectX 12 RayTracingPipeline.
Definition dx12.hpp:1938
UInt32 maxRecursionDepth() const noexcept override
Returns the maximum number of ray bounces.The shader record collection of the ray tracing pipeline.
Definition ray_tracing_pipeline.cpp:542
void use(const DirectX12CommandBuffer &commandBuffer) const noexcept override
Sets the current pipeline state on the commandBuffer .
Definition ray_tracing_pipeline.cpp:567
UInt32 maxPayloadSize() const noexcept override
Returns the maximum size of a single ray payload.A ray payload is the data that is passed down the Tr...
Definition ray_tracing_pipeline.cpp:547
DirectX12RayTracingPipeline(DirectX12RayTracingPipeline &&) noexcept
SharedPtr< const DirectX12PipelineLayout > layout() const noexcept override
Definition ray_tracing_pipeline.cpp:532
SharedPtr< const DirectX12ShaderProgram > program() const noexcept override
Definition ray_tracing_pipeline.cpp:527
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="")
Initializes a new DirectX 12 ray-tracing pipeline.
Definition ray_tracing_pipeline.cpp:509
SharedPtr< IDirectX12Buffer > allocateShaderBindingTable(ShaderBindingTableOffsets &offsets, ShaderBindingGroup groups=ShaderBindingGroup::All) const override
Definition ray_tracing_pipeline.cpp:562
ComPtr< ID3D12StateObject > stateObject() const noexcept
Returns the handle of the ray tracing pipeline state object.
Definition ray_tracing_pipeline.cpp:557
UInt32 maxAttributeSize() const noexcept override
Returns the maximum size of a single ray attribute.A ray attribute is the data that is passed to a hi...
Definition ray_tracing_pipeline.cpp:552
const ShaderRecordCollection & shaderRecords() const noexcept override
Returns the shader record collection of the ray tracing pipeline.The shader record collection of the ...
Definition ray_tracing_pipeline.cpp:537
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
RenderPass< DirectX12Queue, DirectX12FrameBuffer > base_type
Definition dx12.hpp:2188
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
const Array< RenderPassDependency > & inputAttachments() const noexcept override
Returns the input attachment the render pass is consuming.An array of input attachment mappings,...
Definition render_pass.cpp:324
static SharedPtr< DirectX12RenderPass > create(const DirectX12Device &device, 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:2272
const DirectX12Device & device() const noexcept
Returns a reference of the device that provides this queue.
Definition render_pass.cpp:262
const Array< RenderTarget > & renderTargets() const noexcept override
Returns the list of render targets, the render pass renders into.Note that the actual render target i...
Definition render_pass.cpp:306
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
SharedPtr< const DirectX12ShaderProgram > program() const noexcept override
Definition render_pipeline.cpp:561
void updateSamples(MultiSamplingLevel samples) override
Changes the multi-sampling level of the pipeline.Changing the multi-sampling level of a pipeline caus...
Definition render_pipeline.cpp:591
DirectX12RenderPipeline(DirectX12RenderPipeline &&) noexcept=delete
SharedPtr< DirectX12InputAssembler > inputAssembler() const noexcept override
Definition render_pipeline.cpp:571
bool alphaToCoverage() const noexcept override
Returns true, if the pipeline uses Alpha-to-Coverage multi-sampling.Alpha-to-Coverage is a multi-samp...
Definition render_pipeline.cpp:581
void use(const DirectX12CommandBuffer &commandBuffer) const override
Sets the current pipeline state on the commandBuffer .
Definition render_pipeline.cpp:603
SharedPtr< DirectX12Rasterizer > rasterizer() const noexcept override
Definition render_pipeline.cpp:576
MultiSamplingLevel samples() const noexcept override
Returns the multi-sampling level of the pipeline.When using the pipeline, the multi-sampling level mu...
Definition render_pipeline.cpp:586
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="")
Initializes a new DirectX 12 render pipeline.
Definition render_pipeline.cpp:541
SharedPtr< const DirectX12PipelineLayout > layout() const noexcept override
Definition render_pipeline.cpp:566
Implements a DirectX 12 IShaderModule.
Definition dx12.hpp:563
DirectX12ShaderModule(DirectX12ShaderModule &&) noexcept
const Optional< DescriptorBindingPoint > & shaderLocalDescriptor() const noexcept override
For ray-tracing shader modules returns the binding point for the descriptor that receives shader-loca...
Definition shader_module.cpp:88
const String & fileName() const noexcept override
Returns the file name of the shader module.The file name of the shader module.
Definition shader_module.cpp:78
ShaderStage type() const noexcept override
Returns the type of the shader module.The type of the shader module.
Definition shader_module.cpp:73
const String & entryPoint() const noexcept override
Returns the name of the shader module entry point.The name of the shader module entry point.
Definition shader_module.cpp:83
DirectX12ShaderModule(const DirectX12Device &device, ShaderStage type, const String &fileName, const String &entryPoint="main", const Optional< DescriptorBindingPoint > &shaderLocalDescriptor=std::nullopt)
Initializes a new DirectX 12 shader module.
Definition shader_module.cpp:57
Implements a DirectX 12 ShaderProgram.
Definition dx12.hpp:623
static auto create(const DirectX12Device &device, Enumerable< UniquePtr< DirectX12ShaderModule > > &&modules) -> SharedPtr< DirectX12ShaderProgram >
Creates a new shader program instance.
Definition dx12.hpp:667
const Array< UniquePtr< const DirectX12ShaderModule > > & modules() const noexcept override
Definition shader_program.cpp:680
Implements a DirectX12 ISurface.
Definition dx12_api.hpp:290
Implements a DirectX 12 swap chain.
Definition dx12.hpp:2401
const Array< SharedPtr< const TimingEvent > > & timingEvents() const override
Returns all registered timing events.An array, containing all registered timing events.
Definition swapchain.cpp:240
UInt32 resolveQueryId(SharedPtr< const TimingEvent > timingEvent) const override
Returns the query ID for the timing event.The query ID for the timingEvent .TimingEvent::queryId
Definition swapchain.cpp:264
virtual bool supportsVariableRefreshRate() const noexcept
Returns true, if the adapter supports variable refresh rates (i.e. tearing is allowed).
Definition swapchain.cpp:230
friend class DirectX12RenderPass
Definition dx12.hpp:2403
const Size2d & renderArea() const noexcept override
Returns the size of the render area.The size of the render area.
Definition swapchain.cpp:295
friend class DirectX12Image
Definition dx12.hpp:2404
SwapChain< IDirectX12Image > base_type
Definition dx12.hpp:2408
Enumerable< Format > getSurfaceFormats() const override
Returns an array of supported formats, that can be drawn to the surface.An array of supported formats...
Definition swapchain.cpp:335
UInt64 readTimingEvent(SharedPtr< const TimingEvent > timingEvent) const override
Reads the current time stamp value (in ticks) of a timing event.In order to convert the number of tic...
Definition swapchain.cpp:253
DirectX12SwapChain(DirectX12SwapChain &&) noexcept=delete
UInt32 swapBackBuffer() const override
Swaps the front buffer with the next back buffer in order.A reference of the front buffer after the b...
Definition swapchain.cpp:368
friend class DirectX12Device
Definition dx12.hpp:2405
void addTimingEvent(SharedPtr< const TimingEvent > timingEvent) override
Definition swapchain.cpp:350
void present(UInt64 fence) const override
Queues a present that gets executed after fence has been signaled on the default graphics queue....
Definition swapchain.cpp:323
IDirectX12Image * image(UInt32 backBuffer) const override
Returns the swap chain present image for backBuffer .A pointer to the back buffers swap chain present...
Definition swapchain.cpp:305
Format surfaceFormat() const noexcept override
Returns the swap chain image format.The swap chain image format.
Definition swapchain.cpp:285
void reset(Format surfaceFormat, const Size2d &renderArea, UInt32 buffers, bool enableVsync=false) override
Causes the swap chain to be re-created. All frame and command buffers will be invalidated and rebuilt...
Definition swapchain.cpp:362
UInt32 buffers() const noexcept override
Returns the number of images in the swap chain.The number of images in the swap chain.
Definition swapchain.cpp:290
SharedPtr< const TimingEvent > timingEvent(UInt32 queryId) const override
Returns the timing event registered for queryId .The timing event registered for queryId .
Definition swapchain.cpp:245
const Array< SharedPtr< IDirectX12Image > > & images() const noexcept override
Definition swapchain.cpp:318
const IGraphicsDevice & device() const override
Returns the swap chain's parent device instance.A reference of the swap chain's parent device instanc...
Definition swapchain.cpp:275
bool verticalSynchronization() const noexcept override
Returns true, if vertical synchronization should be used, otherwise false.true, if vertical synchroni...
Definition swapchain.cpp:300
virtual ID3D12QueryHeap * timestampQueryHeap() const noexcept
Returns the query heap for the current frame.
Definition swapchain.cpp:235
Implements a DirectX 12 top-level acceleration structure (TLAS).
Definition dx12.hpp:396
DirectX12TopLevelAccelerationStructure(AccelerationStructureFlags flags=AccelerationStructureFlags::None, StringView name="")
Initializes a new DirectX 12 top-level acceleration structure (BLAS).
Definition tlas.cpp:96
DirectX12TopLevelAccelerationStructure(DirectX12TopLevelAccelerationStructure &&) noexcept
void copy(const DirectX12CommandBuffer &commandBuffer, DirectX12TopLevelAccelerationStructure &destination, bool compress=false, const SharedPtr< const IDirectX12Buffer > &buffer=nullptr, UInt64 offset=0, bool copyBuildInfo=true) const
Definition tlas.cpp:213
AccelerationStructureFlags flags() const noexcept override
Returns the flags that control how the acceleration structure should be built.The flags that control ...
Definition tlas.cpp:105
void build(const DirectX12CommandBuffer &commandBuffer, const SharedPtr< const IDirectX12Buffer > &scratchBuffer=nullptr, const SharedPtr< const IDirectX12Buffer > &buffer=nullptr, UInt64 offset=0, UInt64 maxSize=0)
Definition tlas.cpp:130
UInt64 offset() const noexcept override
Returns the offset into buffer at which the acceleration structure is stored.The offset into buffer a...
Definition tlas.cpp:115
const Array< Instance > & instances() const noexcept override
Returns an array of instances in the TLAS.The array of instances in the TLAS.
Definition tlas.cpp:253
SharedPtr< const IDirectX12Buffer > buffer() const noexcept
Definition tlas.cpp:110
void clear() noexcept override
Clears all instances from the acceleration structure.
Definition tlas.cpp:266
void update(const DirectX12CommandBuffer &commandBuffer, const SharedPtr< const IDirectX12Buffer > &scratchBuffer=nullptr, const SharedPtr< const IDirectX12Buffer > &buffer=nullptr, UInt64 offset=0, UInt64 maxSize=0)
Definition tlas.cpp:168
bool remove(const Instance &instance) noexcept override
Removes an instance from the acceleration structure.true, if the instance has been removed,...
Definition tlas.cpp:271
UInt64 size() const noexcept override
Returns the amount of memory in bytes inside buffer that store the acceleration structure....
Definition tlas.cpp:120
void addInstance(const Instance &instance) override
Adds an instance to the TLAS.
Definition tlas.cpp:258
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
UInt32 binding() const noexcept override
Returns the binding point, the buffer will be bound to.In GLSL, the binding point is identified by th...
Definition vertex_buffer_layout.cpp:56
static auto create(size_t vertexSize, UInt32 binding=0, VertexBufferInputRate inputRate=VertexBufferInputRate::Vertex)
Creates a new vertex buffer layout.
Definition dx12.hpp:69
const Array< BufferAttribute > & attributes() const override
Returns the vertex buffer attributes.The vertex buffer attributes.
Definition vertex_buffer_layout.cpp:66
VertexBufferInputRate inputRate() const noexcept override
Returns the vertex buffer input rate that describes how the data is made available to the vertex shad...
Definition vertex_buffer_layout.cpp:71
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
virtual const D3D12_INDEX_BUFFER_VIEW & view() const noexcept=0
Represents a DirectX 12 sampler.
Definition dx12.hpp:268
Represents a DirectX 12 vertex buffer.
Definition dx12.hpp:207
virtual const D3D12_VERTEX_BUFFER_VIEW & view() const noexcept=0
virtual constexpr void transition(const buffer_type &buffer, ResourceAccess accessBefore, ResourceAccess accessAfter)=0
virtual UInt64 submit(const SharedPtr< command_buffer_type > &commandBuffer) const
Definition rendering.hpp:1134
Stores the depth/stencil state of a see IRasterizer.
Definition rendering_api.hpp:3751
virtual void update(UInt32 binding, const buffer_type &buffer, UInt32 bufferElement=0, UInt32 elements=0, UInt32 firstDescriptor=0, Format texelFormat=Format::None) const=0
virtual void free(const descriptor_set_type &descriptorSet) const=0
virtual UniquePtr< descriptor_set_type > allocate(std::initializer_list< DescriptorBinding > bindings={ }) const
Definition rendering.hpp:262
A class that can be used to manage the state of a IGraphicsDevice.
Definition rendering_api.hpp:2697
IFrameBuffer::allocation_callback_type< image_type > allocation_callback_type
Definition rendering.hpp:1082
auto addImage(this TSelf &&self, Format format, MultiSamplingLevel samples=MultiSamplingLevel::x1, ResourceUsage usage=ResourceUsage::FrameBufferImage) -> TSelf &&
Adds an image to the frame buffer.
Definition rendering_api.hpp:9180
virtual SharedPtr< IDirectX12Buffer > createBuffer(BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const=0
virtual 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=0
virtual bool tryCreateIndexBuffer(SharedPtr< IDirectX12IndexBuffer > &buffer, const index_buffer_layout_type &layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const=0
virtual 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=0
virtual SharedPtr< IDirectX12IndexBuffer > createIndexBuffer(const index_buffer_layout_type &layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const=0
virtual SharedPtr< IDirectX12VertexBuffer > createVertexBuffer(const vertex_buffer_layout_type &layout, ResourceHeap heap, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const=0
virtual Generator< SharedPtr< IDirectX12Image > > createTextures(Format format, const Size3d &size, ImageDimensions dimension=ImageDimensions::DIM_2, UInt32 layers=1, UInt32 levels=1, MultiSamplingLevel samples=MultiSamplingLevel::x1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const=0
virtual bool tryCreateBuffer(SharedPtr< IDirectX12Buffer > &buffer, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const=0
virtual bool tryCreateVertexBuffer(SharedPtr< IDirectX12VertexBuffer > &buffer, const vertex_buffer_layout_type &layout, ResourceHeap heap, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const=0
virtual 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=0
virtual 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=0
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
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
IBuffer() noexcept=default
The interface for a command buffer.
Definition rendering_api.hpp:7682
The interface for a command queue.
Definition rendering_api.hpp:9742
The interface for a descriptor set.
Definition rendering_api.hpp:6064
void mapRenderTargets(Span< const RenderTarget > renderTargets)
Maps a set of render targets to the frame buffer images, using the names of the render targets to loo...
Definition rendering_api.hpp:9094
virtual void mapRenderTarget(const RenderTarget &renderTarget, UInt32 index)=0
Maps a render target to a frame buffer image.
The interface for a graphics device that.
Definition rendering_api.hpp:11050
virtual ResourceAllocationResult allocate(const ResourceAllocationInfo &allocationInfo, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const
Allocates a single resource as described by allocationInfo .
Definition rendering_api.hpp:10211
Describes a generic image.
Definition rendering_api.hpp:5019
IImage() noexcept=default
Describes a texture sampler.
Definition rendering_api.hpp:5135
ISampler() noexcept=default
The interface of a scissor.
Definition rendering_api.hpp:4207
IShaderModule() noexcept=default
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
Interface for a viewport.
Definition rendering_api.hpp:4089
Float lineWidth() const noexcept override
Returns the line width of the rasterizer state.Note that line width is not supported in DirectX and i...
Definition rasterizer.cpp:58
CullMode cullMode() const noexcept override
Returns the cull mode of the rasterizer state.The cull mode of the rasterizer state.
Definition rasterizer.cpp:48
const DepthStencilState & depthStencilState() const noexcept override
Returns the depth/stencil state of the rasterizer.The depth/stencil state of the rasterizer.
Definition rasterizer.cpp:63
CullOrder cullOrder() const noexcept override
Returns the cull mode of the rasterizer state.The cull mode of the rasterizer state.
Definition rasterizer.cpp:53
PolygonMode polygonMode() const noexcept override
Returns the polygon mode of the rasterizer state.The polygon mode of the rasterizer state.
Definition rasterizer.cpp:43
bool depthClip() const noexcept override
Returns true, if z-clipping should be used during distance clipping.true, if z-clipping should be use...
Definition rasterizer.cpp:68
Rasterizer(PolygonMode polygonMode, CullMode cullMode, CullOrder cullOrder, Float lineWidth=1.f, bool depthClip=true, const DepthStencilState &depthStencilState={}, bool conservativeRasterization=false) noexcept
Initializes a new rasterizer instance.
Definition rasterizer.cpp:32
Represents a mapping between a set of RenderTarget instances and the input attachments of a IRenderPa...
Definition rendering_api.hpp:3684
Implements a render target.
Definition rendering_api.hpp:3584
Stores a set of IShaderRecords in that later form a shader binding table used for ray-tracing.
Definition rendering_api.hpp:6923
StateResource()
Initializes a new state resource instance with a default name.
Definition state_resource.cpp:27
String & name() noexcept
Definition state_resource.cpp:41
An event that is used to measure timestamps in a command queue.
Definition rendering_api.hpp:4371
Represents a virtual allocator that manages memory distribution from a piece of raw memory.
Definition rendering_api.hpp:3032
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
Contains additional exported vector types.
Definition math.hpp:617
TVector3< UInt8 > ByteVector3
A vector that contains three bytes.
Definition math.hpp:631
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
Resource< ComPtr< THandle > > ComResource
A resource that is hold by a ComPtr.
Definition dx12_api.hpp:105
Definition dx12.hpp:11
BorderMode
Describes how to treat texture coordinates that are outside the domain [0..1].
Definition rendering_api.hpp:1356
@ Repeat
Repeat the texture.
Definition rendering_api.hpp:1360
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
@ Nearest
Take the texel from the mip-map level that is closest to the actual depth.
Definition rendering_api.hpp:1345
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.
Definition rendering_api.hpp:953
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.
Definition rendering_api.hpp:1135
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
@ Balanced
Provides a balance between fragment computation time and packing efficiency.
Definition rendering_api.hpp:895
ResourceUsage
Describes the intended usage for a resource.
Definition rendering_api.hpp:761
@ FrameBufferImage
Default usage for frame buffer images.
Definition rendering_api.hpp:815
@ Default
Shortcut for commonly used TransferSource | TransferDestination combination.
Definition rendering_api.hpp:809
ImageDimensions
Describes the dimensions of a image resource, i.e. the dimensions that are required to access a texel...
Definition rendering_api.hpp:1258
@ DIM_2
Represents a 2D image.
Definition rendering_api.hpp:1267
AllocationAlgorithm
The allocation algorithm used by VirtualAllocators.
Definition rendering_api.hpp:852
@ Default
The default algorithm without any constraints on the memory layout.
Definition rendering_api.hpp:856
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
@ None
Use default options for building the acceleration structure.
Definition rendering_api.hpp:1992
FilterMode
Describes the filter operation when accessing a pixel from a texture coordinate.
Definition rendering_api.hpp:1324
@ Nearest
Take the nearest texel with respect to the texture coordinate.
Definition rendering_api.hpp:1328
AllocationBehavior
Controls the allocation behavior of IGraphicsFactory.
Definition rendering_api.hpp:830
@ Default
Represents the default behavior, which might fall back to slower memory types, if required.
Definition rendering_api.hpp:834
VertexBufferInputRate
The rate at which a vertex buffer of a certain IVertexBufferLayout is made available for vertex shade...
Definition rendering_api.hpp:922
@ Vertex
The vertex buffer layout describes data that is made available per individual vertex.
Definition rendering_api.hpp:926
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
@ B8G8R8A8_SRGB
Definition rendering_api.hpp:234
MultiSamplingLevel
Describes the number of samples with which a IImage is sampled.
Definition rendering_api.hpp:1283
@ x1
The default number of samples. Multi-sampling will be deactivated, if this sampling level is used.
Definition rendering_api.hpp:1287
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
@ None
Definition app_api.hpp:30
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
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