LiteFX 0.5.1.2025
Computer Graphics Engine
Loading...
Searching...
No Matches
rendering.hpp
1#pragma once
2
3#include <litefx/rendering_api.hpp>
4#include <litefx/rendering_formatters.hpp>
5
6namespace LiteFX::Rendering {
7 using namespace LiteFX;
8 using namespace LiteFX::Math;
9
14 template <typename TBuffer, typename TImage> requires
15 std::derived_from<TBuffer, IBuffer> &&
16 std::derived_from<TImage, IImage>
17 class Barrier : public IBarrier {
18 public:
20
21 using buffer_type = TBuffer;
22 using image_type = TImage;
23
24 protected:
25 Barrier() noexcept = default;
26 Barrier(const Barrier&) = default;
27 Barrier(Barrier&&) noexcept = default;
28 Barrier& operator=(const Barrier&) = default;
29 Barrier& operator=(Barrier&&) noexcept = default;
30
31 public:
32 constexpr ~Barrier() noexcept override = default;
33
34 public:
36 constexpr virtual void transition(const buffer_type& buffer, ResourceAccess accessBefore, ResourceAccess accessAfter) = 0;
37
39 constexpr virtual void transition(const buffer_type& buffer, UInt32 element, ResourceAccess accessBefore, ResourceAccess accessAfter) = 0;
40
42 constexpr virtual void transition(const image_type& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) = 0;
43
45 constexpr virtual void transition(const image_type& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) = 0;
46
48 constexpr virtual void transition(const image_type& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) = 0;
49
51 constexpr virtual void transition(const image_type& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) = 0;
52
53 private:
54 constexpr void doTransition(const IBuffer& buffer, ResourceAccess accessBefore, ResourceAccess accessAfter) override {
55 this->transition(dynamic_cast<const buffer_type&>(buffer), accessBefore, accessAfter);
56 }
57
58 constexpr void doTransition(const IBuffer& buffer, UInt32 element, ResourceAccess accessBefore, ResourceAccess accessAfter) override {
59 this->transition(dynamic_cast<const buffer_type&>(buffer), element, accessBefore, accessAfter);
60 }
61
62 constexpr void doTransition(const IImage& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) override {
63 this->transition(dynamic_cast<const image_type&>(image), accessBefore, accessAfter, layout);
64 }
65
66 constexpr void doTransition(const IImage& image, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) override {
67 this->transition(dynamic_cast<const image_type&>(image), accessBefore, accessAfter, fromLayout, toLayout);
68 }
69
70 constexpr void doTransition(const IImage& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout layout) override {
71 this->transition(dynamic_cast<const image_type&>(image), level, levels, layer, layers, plane, accessBefore, accessAfter, layout);
72 }
73
74 constexpr void doTransition(const IImage& image, UInt32 level, UInt32 levels, UInt32 layer, UInt32 layers, UInt32 plane, ResourceAccess accessBefore, ResourceAccess accessAfter, ImageLayout fromLayout, ImageLayout toLayout) override {
75 this->transition(dynamic_cast<const image_type&>(image), level, levels, layer, layers, plane, accessBefore, accessAfter, fromLayout, toLayout);
76 }
77 };
78
145 template <typename TBuffer, typename TImage, typename TSampler, typename TAccelerationStructure> requires
146 std::derived_from<TBuffer, IBuffer> &&
147 std::derived_from<TSampler, ISampler> &&
148 std::derived_from<TImage, IImage> &&
149 std::derived_from<TAccelerationStructure, IAccelerationStructure>
151 public:
154
155 using buffer_type = TBuffer;
156 using sampler_type = TSampler;
157 using image_type = TImage;
158 using acceleration_structure_type = TAccelerationStructure;
159
160 protected:
161 DescriptorSet() noexcept = default;
162 DescriptorSet(const DescriptorSet&) = default;
163 DescriptorSet(DescriptorSet&&) noexcept = default;
164 DescriptorSet& operator=(const DescriptorSet&) = default;
165 DescriptorSet& operator=(DescriptorSet&&) noexcept = default;
166
167 public:
168 ~DescriptorSet() noexcept override = default;
169
170 public:
172 virtual UInt32 bindToHeap(DescriptorType bindingType, UInt32 descriptor, const buffer_type& buffer, UInt32 bufferElement = 0, UInt32 elements = 0, Format texelFormat = Format::None) const = 0;
173
175 virtual UInt32 bindToHeap(DescriptorType bindingType, UInt32 descriptor, const image_type& image, UInt32 firstLevel = 0, UInt32 levels = 0, UInt32 firstLayer = 0, UInt32 layers = 0) const = 0;
176
178 virtual UInt32 bindToHeap(UInt32 descriptor, const sampler_type& sampler) const = 0;
179
181 virtual void update(UInt32 binding, const buffer_type& buffer, UInt32 bufferElement = 0, UInt32 elements = 0, UInt32 firstDescriptor = 0, Format texelFormat = Format::None) const = 0;
182
184 virtual void update(UInt32 binding, const image_type& texture, UInt32 descriptor = 0, UInt32 firstLevel = 0, UInt32 levels = 0, UInt32 firstLayer = 0, UInt32 layers = 0) const = 0;
185
187 virtual void update(UInt32 binding, const sampler_type& sampler, UInt32 descriptor = 0) const = 0;
188
190 virtual void update(UInt32 binding, const acceleration_structure_type& accelerationStructure, UInt32 descriptor = 0) const = 0;
191
192 private:
193 UInt32 doBind(DescriptorType bindingType, UInt32 descriptor, const IBuffer& buffer, UInt32 bufferElement, UInt32 elements, Format texelFormat) const override {
194 return this->bindToHeap(bindingType, descriptor, dynamic_cast<const buffer_type&>(buffer), bufferElement, elements, texelFormat);
195 }
196
197 UInt32 doBind(DescriptorType bindingType, UInt32 descriptor, const IImage& image, UInt32 firstLevel, UInt32 levels, UInt32 firstLayer, UInt32 layers) const override {
198 return this->bindToHeap(bindingType, descriptor, dynamic_cast<const image_type&>(image), firstLevel, levels, firstLayer, layers);
199 }
200
201 UInt32 doBind(UInt32 descriptor, const ISampler& sampler) const override {
202 return this->bindToHeap(descriptor, dynamic_cast<const sampler_type&>(sampler));
203 }
204
205 void doUpdate(UInt32 binding, const IBuffer& buffer, UInt32 bufferElement, UInt32 elements, UInt32 firstDescriptor, Format texelFormat) const override {
206 this->update(binding, dynamic_cast<const buffer_type&>(buffer), bufferElement, elements, firstDescriptor, texelFormat);
207 }
208
209 void doUpdate(UInt32 binding, const IImage& texture, UInt32 descriptor, UInt32 firstLevel, UInt32 levels, UInt32 firstLayer, UInt32 layers) const override {
210 this->update(binding, dynamic_cast<const image_type&>(texture), descriptor, firstLevel, levels, firstLayer, layers);
211 }
212
213 void doUpdate(UInt32 binding, const ISampler& sampler, UInt32 descriptor) const override {
214 this->update(binding, dynamic_cast<const sampler_type&>(sampler), descriptor);
215 }
216
217 void doUpdate(UInt32 binding, const IAccelerationStructure& accelerationStructure, UInt32 descriptor) const override {
218 this->update(binding, dynamic_cast<const acceleration_structure_type&>(accelerationStructure), descriptor);
219 }
220 };
221
234 template <typename TDescriptorLayout, typename TDescriptorSet> requires
235 meta::implements<TDescriptorLayout, IDescriptorLayout> &&
236 meta::implements<TDescriptorSet, DescriptorSet<typename TDescriptorSet::buffer_type, typename TDescriptorSet::image_type, typename TDescriptorSet::sampler_type, typename TDescriptorSet::acceleration_structure_type>>
238 public:
240
241 using descriptor_layout_type = TDescriptorLayout;
242 using descriptor_set_type = TDescriptorSet;
243
244 protected:
245 DescriptorSetLayout() noexcept = default;
248 DescriptorSetLayout& operator=(const DescriptorSetLayout&) = default;
249 DescriptorSetLayout& operator=(DescriptorSetLayout&&) noexcept = default;
250
251 public:
252 ~DescriptorSetLayout() noexcept override = default;
253
254 public:
256 virtual const Array<descriptor_layout_type>& descriptors() const noexcept = 0;
257
259 const descriptor_layout_type& descriptor(UInt32 binding) const override = 0;
260
262 virtual inline UniquePtr<descriptor_set_type> allocate(std::initializer_list<DescriptorBinding> bindings = { }) const {
263 return this->allocate(0, bindings);
264 }
265
268 return this->allocate(0, bindings);
269 }
270
273 return this->allocate(0, std::move(bindings));
274 }
275
277 virtual UniquePtr<descriptor_set_type> allocate(UInt32 descriptors, std::initializer_list<DescriptorBinding> bindings) const = 0;
278
281
284
286 virtual inline Generator<UniquePtr<descriptor_set_type>> allocate(UInt32 descriptorSets, std::initializer_list<std::initializer_list<DescriptorBinding>> bindings = { }) const {
287 return this->allocate(descriptorSets, 0, bindings);
288 }
289
290#ifdef __cpp_lib_mdspan
292 virtual inline Generator<UniquePtr<descriptor_set_type>> allocate(UInt32 descriptorSets, std::mdspan<DescriptorBinding, std::dextents<size_t, 2>> bindings) const {
293 return this->allocate(descriptorSets, 0, bindings);
294 }
295#endif
296
298 virtual inline Generator<UniquePtr<descriptor_set_type>> allocate(UInt32 descriptorSets, std::function<Generator<DescriptorBinding>(UInt32)> bindings) const {
299 return this->allocate(descriptorSets, 0, std::move(bindings));
300 }
301
303 virtual Generator<UniquePtr<descriptor_set_type>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::initializer_list<std::initializer_list<DescriptorBinding>> bindings = { }) const = 0;
304
305#ifdef __cpp_lib_mdspan
307 virtual Generator<UniquePtr<descriptor_set_type>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::mdspan<DescriptorBinding, std::dextents<size_t, 2>> bindings) const = 0;
308#endif
309
311 virtual Generator<UniquePtr<descriptor_set_type>> allocate(UInt32 descriptorSets, UInt32 descriptors, std::function<Generator<DescriptorBinding>(UInt32)> bindingFactory) const = 0;
312
314 virtual void free(const descriptor_set_type& descriptorSet) const = 0;
315
316 private:
317 inline Enumerable<const IDescriptorLayout&> getDescriptors() const noexcept override {
318 return this->descriptors();
319 }
320
321 inline UniquePtr<IDescriptorSet> getDescriptorSet(UInt32 descriptors, std::initializer_list<DescriptorBinding> bindings) const override {
322 return this->allocate(descriptors, bindings);
323 }
324
325 inline UniquePtr<IDescriptorSet> getDescriptorSet(UInt32 descriptors, Span<DescriptorBinding> bindings) const override {
326 return this->allocate(descriptors, bindings);
327 }
328
329 inline UniquePtr<IDescriptorSet> getDescriptorSet(UInt32 descriptors, Generator<DescriptorBinding> bindings) const override {
330 return this->allocate(descriptors, std::move(bindings));
331 }
332
333 inline Generator<UniquePtr<IDescriptorSet>> getDescriptorSets(UInt32 descriptorSets, UInt32 descriptors, std::initializer_list<std::initializer_list<DescriptorBinding>> bindings) const override {
334 co_yield std::ranges::elements_of(this->allocate(descriptorSets, descriptors, bindings) | std::views::transform([](auto set) -> UniquePtr<IDescriptorSet> { return set; }));
335 }
336
337#ifdef __cpp_lib_mdspan
338 inline Generator<UniquePtr<IDescriptorSet>> getDescriptorSets(UInt32 descriptorSets, UInt32 descriptors, std::mdspan<DescriptorBinding, std::dextents<size_t, 2>> bindings) const override {
339 co_yield std::ranges::elements_of(this->allocate(descriptorSets, descriptors, bindings) | std::views::transform([](auto set) -> UniquePtr<IDescriptorSet> { return set; }));
340 }
341#endif
342
343 inline Generator<UniquePtr<IDescriptorSet>> getDescriptorSets(UInt32 descriptorSets, UInt32 descriptors, std::function<Generator<DescriptorBinding>(UInt32)> bindingFactory) const override {
344 co_yield std::ranges::elements_of(this->allocate(descriptorSets, descriptors, std::move(bindingFactory)) | std::views::transform([](auto set) -> UniquePtr<IDescriptorSet> { return set; }));
345 }
346
347 inline void releaseDescriptorSet(const IDescriptorSet& descriptorSet) const override {
348 this->free(dynamic_cast<const descriptor_set_type&>(descriptorSet));
349 }
350 };
351
375 template <typename TPushConstantsRange> requires
376 meta::implements<TPushConstantsRange, IPushConstantsRange>
378 public:
379 using push_constants_range_type = TPushConstantsRange;
380
381 protected:
382 PushConstantsLayout() noexcept = default;
385 PushConstantsLayout& operator=(const PushConstantsLayout&) = default;
386 PushConstantsLayout& operator=(PushConstantsLayout&&) noexcept = default;
387
388 public:
389 ~PushConstantsLayout() noexcept override = default;
390
391 public:
393 virtual const Array<UniquePtr<push_constants_range_type>>& ranges() const = 0;
394
395 private:
396 inline Enumerable<const IPushConstantsRange&> getRanges() const override {
397 return this->ranges() | std::views::transform([](auto& ptr) -> const IPushConstantsRange& { return *ptr; });
398 }
399 };
400
406 template <typename TShaderModule> requires
409 public:
410 using shader_module_type = TShaderModule;
411
412 protected:
413 ShaderProgram() noexcept = default;
414 ShaderProgram(const ShaderProgram&) = default;
415 ShaderProgram(ShaderProgram&&) noexcept = default;
416 ShaderProgram& operator=(const ShaderProgram&) = default;
417 ShaderProgram& operator=(ShaderProgram&&) noexcept = default;
418
419 public:
420 ~ShaderProgram() noexcept override = default;
421
422 public:
424 virtual const Array<UniquePtr<const shader_module_type>>& modules() const noexcept = 0;
425
426 private:
427 inline Enumerable<const IShaderModule&> getModules() const override {
428 return this->modules() | std::views::transform([](const auto& m) -> const IShaderModule& { return *m; });
429 }
430 };
431
437 template <typename TDescriptorSetLayout, typename TPushConstantsLayout> requires
441 public:
442 using descriptor_set_layout_type = TDescriptorSetLayout;
443 using push_constants_layout_type = TPushConstantsLayout;
444
445 protected:
446 PipelineLayout() noexcept = default;
448 PipelineLayout(PipelineLayout&&) noexcept = default;
449 PipelineLayout& operator=(const PipelineLayout&) = default;
450 PipelineLayout& operator=(PipelineLayout&&) noexcept = default;
451
452 public:
453 ~PipelineLayout() noexcept override = default;
454
455 public:
457 const descriptor_set_layout_type& descriptorSet(UInt32 space) const override = 0;
458
460 virtual const Array<SharedPtr<const descriptor_set_layout_type>>& descriptorSets() const = 0;
461
463 const push_constants_layout_type* pushConstants() const noexcept override = 0;
464
465 private:
466 inline Enumerable<SharedPtr<const IDescriptorSetLayout>> getDescriptorSets() const override {
467 return this->descriptorSets();
468 }
469 };
470
475 template <typename TVertexBufferLayout> requires
477 class VertexBuffer : public virtual IVertexBuffer {
478 public:
479 using vertex_buffer_layout_type = TVertexBufferLayout;
480 protected:
481 VertexBuffer() noexcept = default;
482 VertexBuffer(const VertexBuffer&) = default;
483 VertexBuffer(VertexBuffer&&) noexcept = default;
484 VertexBuffer& operator=(const VertexBuffer&) = default;
485 VertexBuffer& operator=(VertexBuffer&&) noexcept = default;
486
487 public:
488 ~VertexBuffer() noexcept override = default;
489
490 public:
492 const vertex_buffer_layout_type& layout() const noexcept override = 0;
493 };
494
499 template <typename TIndexBufferLayout> requires
500 meta::implements<TIndexBufferLayout, IIndexBufferLayout>
501 class IndexBuffer : public virtual IIndexBuffer {
502 public:
503 using index_buffer_layout_type = TIndexBufferLayout;
504
505 protected:
506 IndexBuffer() noexcept = default;
507 IndexBuffer(const IndexBuffer&) = default;
508 IndexBuffer(IndexBuffer&&) noexcept = default;
509 IndexBuffer& operator=(const IndexBuffer&) = default;
510 IndexBuffer& operator=(IndexBuffer&&) noexcept = default;
511
512 public:
513 ~IndexBuffer() noexcept override = default;
514
515 public:
517 const index_buffer_layout_type& layout() const noexcept override = 0;
518 };
519
525 template <typename TVertexBufferLayout, typename TIndexBufferLayout> requires
526 meta::implements<TVertexBufferLayout, IVertexBufferLayout> &&
527 meta::implements<TIndexBufferLayout, IIndexBufferLayout>
529 public:
530 using vertex_buffer_layout_type = TVertexBufferLayout;
531 using index_buffer_layout_type = TIndexBufferLayout;
532
533 protected:
534 InputAssembler() noexcept = default;
536 InputAssembler(InputAssembler&&) noexcept = default;
537 InputAssembler& operator=(const InputAssembler&) = default;
538 InputAssembler& operator=(InputAssembler&&) noexcept = default;
539
540 public:
541 ~InputAssembler() noexcept override = default;
542
543 public:
545 virtual Enumerable<const vertex_buffer_layout_type&> vertexBufferLayouts() const = 0;
546
548 const vertex_buffer_layout_type& vertexBufferLayout(UInt32 binding) const override = 0;
549
551 const index_buffer_layout_type* indexBufferLayout() const noexcept override = 0;
552
553 private:
554 inline Enumerable<const IVertexBufferLayout&> getVertexBufferLayouts() const override {
555 return this->vertexBufferLayouts();
556 }
557 };
558
566 template <typename TPipelineLayout, typename TShaderProgram> requires
569 class Pipeline : public virtual IPipeline, public virtual StateResource {
570 public:
571 using shader_program_type = TShaderProgram;
572 using pipeline_layout_type = TPipelineLayout;
573
574 protected:
575 Pipeline() noexcept = default;
576 Pipeline(const Pipeline&) = default;
577 Pipeline(Pipeline&&) noexcept = default;
578 Pipeline& operator=(const Pipeline&) = default;
579 Pipeline& operator=(Pipeline&&) noexcept = default;
580
581 public:
582 ~Pipeline() noexcept override = default;
583
584 public:
586 virtual SharedPtr<const shader_program_type> program() const noexcept = 0;
587
589 virtual SharedPtr<const pipeline_layout_type> layout() const noexcept = 0;
590
591 private:
592 inline SharedPtr<const IShaderProgram> getProgram() const noexcept override {
593 return std::static_pointer_cast<const IShaderProgram>(this->program());
594 }
595
596 inline SharedPtr<const IPipelineLayout> getLayout() const noexcept override {
597 return std::static_pointer_cast<const IPipelineLayout>(this->layout());
598 }
599 };
600
613 template <typename TCommandBuffer, typename TBuffer, typename TVertexBuffer, typename TIndexBuffer, typename TImage, typename TBarrier, typename TPipeline, typename TBLAS, typename TTLAS> requires
614 meta::implements<TBarrier, Barrier<TBuffer, TImage>> &&
615 //std::derived_from<TCommandBuffer, ICommandBuffer> &&
616 std::derived_from<TPipeline, Pipeline<typename TPipeline::pipeline_layout_type, typename TPipeline::shader_program_type>> &&
617 std::derived_from<TBLAS, IBottomLevelAccelerationStructure> &&
618 std::derived_from<TTLAS, ITopLevelAccelerationStructure>
620 public:
624
638
640
641 public:
642 using command_buffer_type = TCommandBuffer;
643 using buffer_type = TBuffer;
644 using vertex_buffer_type = TVertexBuffer;
645 using index_buffer_type = TIndexBuffer;
646 using image_type = TImage;
647 using barrier_type = TBarrier;
648 using pipeline_type = TPipeline;
649 using pipeline_layout_type = pipeline_type::pipeline_layout_type;
650 using descriptor_set_layout_type = pipeline_layout_type::descriptor_set_layout_type;
651 using push_constants_layout_type = pipeline_layout_type::push_constants_layout_type;
652 using descriptor_set_type = descriptor_set_layout_type::descriptor_set_type;
655
656 private:
657 CommandBuffer() noexcept = default;
658 CommandBuffer(CommandBuffer&&) noexcept = default;
659 CommandBuffer(const CommandBuffer&) = default;
660 CommandBuffer& operator=(const CommandBuffer&) = default;
661 CommandBuffer& operator=(CommandBuffer&&) noexcept = default;
662
663 public:
664 ~CommandBuffer() noexcept override = default;
665
666 public:
668 virtual UniquePtr<barrier_type> makeBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const = 0;
669
671 virtual void barrier(const barrier_type& barrier) const noexcept = 0;
672
674 virtual void transfer(const buffer_type& source, const buffer_type& target, UInt32 sourceElement = 0, UInt32 targetElement = 0, UInt32 elements = 1) const = 0;
675
677 virtual void transfer(const void* const data, size_t size, const buffer_type& target, UInt32 targetElement = 0, UInt32 elements = 1) const = 0;
678
680 virtual void transfer(Span<const void* const> data, size_t elementSize, const buffer_type& target, UInt32 firstElement = 0) const = 0;
681
683 virtual void transfer(const buffer_type& source, const image_type& target, UInt32 sourceElement = 0, UInt32 firstSubresource = 0, UInt32 elements = 1) const = 0;
684
686 virtual void transfer(const void* const data, size_t size, const image_type& target, UInt32 subresource = 0) const = 0;
687
689 virtual void transfer(Span<const void* const> data, size_t elementSize, const image_type& target, UInt32 firstSubresource = 0, UInt32 subresources = 1) const = 0;
690
692 virtual void transfer(const image_type& source, const image_type& target, UInt32 sourceSubresource = 0, UInt32 targetSubresource = 0, UInt32 subresources = 1) const = 0;
693
695 virtual void transfer(const image_type& source, const buffer_type& target, UInt32 firstSubresource = 0, UInt32 targetElement = 0, UInt32 subresources = 1) const = 0;
696
698 virtual void transfer(const SharedPtr<const buffer_type>& source, const buffer_type& target, UInt32 sourceElement = 0, UInt32 targetElement = 0, UInt32 elements = 1) const = 0;
699
701 virtual void transfer(const SharedPtr<const buffer_type>& source, const image_type& target, UInt32 sourceElement = 0, UInt32 firstSubresource = 0, UInt32 elements = 1) const = 0;
702
704 virtual void transfer(const SharedPtr<const image_type>& source, const image_type& target, UInt32 sourceSubresource = 0, UInt32 targetSubresource = 0, UInt32 subresources = 1) const = 0;
705
707 virtual void transfer(const SharedPtr<const image_type>& source, const buffer_type& target, UInt32 firstSubresource = 0, UInt32 targetElement = 0, UInt32 subresources = 1) const = 0;
708
710 virtual void use(const pipeline_type& pipeline) const noexcept = 0;
711
713 virtual void bind(const descriptor_set_type& descriptorSet) const = 0;
714
716 virtual void bind(Span<const descriptor_set_type*> descriptorSets) const = 0;
717
719 virtual void bind(const descriptor_set_type& descriptorSet, const pipeline_type& pipeline) const = 0;
720
722 virtual void bind(Span<const descriptor_set_type*> descriptorSets, const pipeline_type& pipeline) const = 0;
723
725 virtual void bind(const vertex_buffer_type& buffer) const noexcept = 0;
726
728 virtual void bind(const index_buffer_type& buffer) const noexcept = 0;
729
731 virtual void pushConstants(const push_constants_layout_type& layout, const void* const memory) const = 0;
732
734 virtual void dispatchIndirect(const buffer_type& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept = 0;
735
737 virtual void dispatchMeshIndirect(const buffer_type& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept = 0;
738
740 virtual void dispatchMeshIndirect(const buffer_type& batchBuffer, const buffer_type& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept = 0;
741
743 virtual void drawIndirect(const buffer_type& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept = 0;
744
746 virtual void drawIndirect(const buffer_type& batchBuffer, const buffer_type& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept = 0;
747
749 virtual void drawIndexedIndirect(const buffer_type& batchBuffer, UInt32 batchCount, UInt64 offset = 0) const noexcept = 0;
750
752 virtual void drawIndexedIndirect(const buffer_type& batchBuffer, const buffer_type& countBuffer, UInt64 offset = 0, UInt64 countOffset = 0, UInt32 maxBatches = std::numeric_limits<UInt32>::max()) const noexcept = 0;
753
755 virtual inline void draw(const vertex_buffer_type& vertexBuffer, UInt32 instances = 1, UInt32 firstVertex = 0, UInt32 firstInstance = 0) const {
756 this->bind(vertexBuffer);
757 this->draw(vertexBuffer.elements(), instances, firstVertex, firstInstance);
758 }
759
761 virtual inline void drawIndexed(const index_buffer_type& indexBuffer, UInt32 instances = 1, UInt32 firstIndex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0) const {
762 this->bind(indexBuffer);
763 this->drawIndexed(indexBuffer.elements(), instances, firstIndex, vertexOffset, firstInstance);
764 }
765
767 virtual inline void drawIndexed(const vertex_buffer_type& vertexBuffer, const index_buffer_type& indexBuffer, UInt32 instances = 1, UInt32 firstIndex = 0, Int32 vertexOffset = 0, UInt32 firstInstance = 0) const {
768 this->bind(vertexBuffer);
769 this->bind(indexBuffer);
770 this->drawIndexed(indexBuffer.elements(), instances, firstIndex, vertexOffset, firstInstance);
771 }
772
774 virtual void execute(const SharedPtr<const command_buffer_type>& commandBuffer) const = 0;
775
777 virtual void execute(Enumerable<SharedPtr<const command_buffer_type>> commandBuffers) const = 0;
778
780 virtual void buildAccelerationStructure(bottom_level_acceleration_structure_type& blas, const SharedPtr<const buffer_type>& scratchBuffer, const buffer_type& buffer, UInt64 offset = 0) const = 0;
781
783 virtual void buildAccelerationStructure(top_level_acceleration_structure_type& tlas, const SharedPtr<const buffer_type>& scratchBuffer, const buffer_type& buffer, UInt64 offset = 0) const = 0;
784
786 virtual void updateAccelerationStructure(bottom_level_acceleration_structure_type& blas, const SharedPtr<const buffer_type>& scratchBuffer, const buffer_type& buffer, UInt64 offset = 0) const = 0;
787
789 virtual void updateAccelerationStructure(top_level_acceleration_structure_type& tlas, const SharedPtr<const buffer_type>& scratchBuffer, const buffer_type& buffer, UInt64 offset = 0) const = 0;
790
792 virtual void copyAccelerationStructure(const bottom_level_acceleration_structure_type& from, const bottom_level_acceleration_structure_type& to, bool compress = false) const noexcept = 0;
793
795 virtual void copyAccelerationStructure(const top_level_acceleration_structure_type& from, const top_level_acceleration_structure_type& to, bool compress = false) const noexcept = 0;
796
798 virtual void traceRays(UInt32 width, UInt32 height, UInt32 depth, const ShaderBindingTableOffsets& offsets, const buffer_type& rayGenerationShaderBindingTable, const buffer_type* missShaderBindingTable, const buffer_type* hitShaderBindingTable, const buffer_type* callableShaderBindingTable) const noexcept = 0;
799
801 inline void traceRays(const Vector3u& dimensions, const ShaderBindingTableOffsets& offsets, const buffer_type& rayGenerationShaderBindingTable, const buffer_type* missShaderBindingTable, const buffer_type* hitShaderBindingTable, const buffer_type* callableShaderBindingTable) const noexcept {
802 this->traceRays(dimensions.x(), dimensions.y(), dimensions.z(), offsets, rayGenerationShaderBindingTable, missShaderBindingTable, hitShaderBindingTable, callableShaderBindingTable);
803 }
804
805 private:
806 inline UniquePtr<IBarrier> getBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const override {
807 return this->makeBarrier(syncBefore, syncAfter);
808 }
809
810 inline void cmdBarrier(const IBarrier& barrier) const noexcept override {
811 this->barrier(dynamic_cast<const barrier_type&>(barrier));
812 }
813
814 inline void cmdTransfer(const IBuffer& source, const IBuffer& target, UInt32 sourceElement, UInt32 targetElement, UInt32 elements) const override {
815 this->transfer(dynamic_cast<const buffer_type&>(source), dynamic_cast<const buffer_type&>(target), sourceElement, targetElement, elements);
816 }
817
818 inline void cmdTransfer(const IBuffer& source, const IImage& target, UInt32 sourceElement, UInt32 firstSubresource, UInt32 elements) const override {
819 this->transfer(dynamic_cast<const buffer_type&>(source), dynamic_cast<const image_type&>(target), sourceElement, firstSubresource, elements);
820 }
821
822 inline void cmdTransfer(const IImage& source, const IImage& target, UInt32 sourceSubresource, UInt32 targetSubresource, UInt32 subresources) const override {
823 this->transfer(dynamic_cast<const image_type&>(source), dynamic_cast<const image_type&>(target), sourceSubresource, targetSubresource, subresources);
824 }
825
826 inline void cmdTransfer(const IImage& source, const IBuffer& target, UInt32 firstSubresource, UInt32 targetElement, UInt32 subresources) const override {
827 this->transfer(dynamic_cast<const image_type&>(source), dynamic_cast<const buffer_type&>(target), firstSubresource, targetElement, subresources);
828 }
829
830 inline void cmdTransfer(const SharedPtr<const IBuffer>& source, const IBuffer& target, UInt32 sourceElement, UInt32 targetElement, UInt32 elements) const override {
831 this->transfer(std::dynamic_pointer_cast<const buffer_type>(source), dynamic_cast<const buffer_type&>(target), sourceElement, targetElement, elements);
832 }
833
834 inline void cmdTransfer(const SharedPtr<const IBuffer>& source, const IImage& target, UInt32 sourceElement, UInt32 firstSubresource, UInt32 elements) const override {
835 this->transfer(std::dynamic_pointer_cast<const buffer_type>(source), dynamic_cast<const image_type&>(target), sourceElement, firstSubresource, elements);
836 }
837
838 inline void cmdTransfer(const SharedPtr<const IImage>& source, const IImage& target, UInt32 sourceSubresource, UInt32 targetSubresource, UInt32 subresources) const override {
839 this->transfer(std::dynamic_pointer_cast<const image_type>(source), dynamic_cast<const image_type&>(target), sourceSubresource, targetSubresource, subresources);
840 }
841
842 inline void cmdTransfer(const SharedPtr<const IImage>& source, const IBuffer& target, UInt32 firstSubresource, UInt32 targetElement, UInt32 subresources) const override {
843 this->transfer(std::dynamic_pointer_cast<const image_type>(source), dynamic_cast<const buffer_type&>(target), firstSubresource, targetElement, subresources);
844 }
845
846 inline void cmdTransfer(const void* const data, size_t size, const IBuffer& target, UInt32 targetElement, UInt32 elements) const override {
847 this->transfer(data, size, dynamic_cast<const buffer_type&>(target), targetElement, elements);
848 }
849
850 inline void cmdTransfer(Span<const void* const> data, size_t elementSize, const IBuffer& target, UInt32 targetElement) const override {
851 this->transfer(data, elementSize, dynamic_cast<const buffer_type&>(target), targetElement);
852 }
853
854 inline void cmdTransfer(const void* const data, size_t size, const IImage& target, UInt32 subresource) const override {
855 this->transfer(data, size, dynamic_cast<const image_type&>(target), subresource);
856 }
857
858 inline void cmdTransfer(Span<const void* const> data, size_t elementSize, const IImage& target, UInt32 firstSubresource, UInt32 elements) const override {
859 this->transfer(data, elementSize, dynamic_cast<const image_type&>(target), firstSubresource, elements);
860 }
861
862 inline void cmdUse(const IPipeline& pipeline) const noexcept override {
863 this->use(dynamic_cast<const pipeline_type&>(pipeline));
864 }
865
866 inline void cmdBind(const IDescriptorSet& descriptorSet) const override {
867 this->bind(dynamic_cast<const descriptor_set_type&>(descriptorSet));
868 }
869
870 inline void cmdBind(Span<const IDescriptorSet*> descriptorSets) const override {
871 auto sets = descriptorSets | std::views::transform([](auto set) { return dynamic_cast<const descriptor_set_type*>(set); }) | std::ranges::to<Array<const descriptor_set_type*>>();
872 this->bind(Span<const descriptor_set_type*>(sets));
873 }
874
875 inline void cmdBind(const IDescriptorSet& descriptorSet, const IPipeline& pipeline) const override {
876 this->bind(dynamic_cast<const descriptor_set_type&>(descriptorSet), dynamic_cast<const pipeline_type&>(pipeline));
877 }
878
879 inline void cmdBind(Span<const IDescriptorSet*> descriptorSets, const IPipeline& pipeline) const override {
880 auto sets = descriptorSets | std::views::transform([](auto set) { return dynamic_cast<const descriptor_set_type*>(set); }) | std::ranges::to<Array<const descriptor_set_type*>>();
881 this->bind(Span<const descriptor_set_type*>(sets), dynamic_cast<const pipeline_type&>(pipeline));
882 }
883
884 inline void cmdBind(const IVertexBuffer& buffer) const override {
885 this->bind(dynamic_cast<const vertex_buffer_type&>(buffer));
886 }
887
888 inline void cmdBind(const IIndexBuffer& buffer) const override {
889 this->bind(dynamic_cast<const index_buffer_type&>(buffer));
890 }
891
892 inline void cmdPushConstants(const IPushConstantsLayout& layout, const void* const memory) const override {
893 this->pushConstants(dynamic_cast<const push_constants_layout_type&>(layout), memory);
894 }
895
896 inline void cmdDispatchIndirect(const IBuffer& batchBuffer, UInt32 batchCount, UInt64 offset) const noexcept override {
897 this->dispatchIndirect(dynamic_cast<const buffer_type&>(batchBuffer), batchCount, offset);
898 }
899
900 inline void cmdDispatchMeshIndirect(const IBuffer& batchBuffer, UInt32 batchCount, UInt64 offset) const noexcept override {
901 this->dispatchMeshIndirect(dynamic_cast<const buffer_type&>(batchBuffer), batchCount, offset);
902 }
903
904 inline void cmdDispatchMeshIndirect(const IBuffer& batchBuffer, const IBuffer& countBuffer, UInt64 offset, UInt64 countOffset, UInt32 maxBatches) const noexcept override {
905 this->dispatchMeshIndirect(dynamic_cast<const buffer_type&>(batchBuffer), dynamic_cast<const buffer_type&>(countBuffer), offset, countOffset, maxBatches);
906 }
907
908 inline void cmdDraw(const IVertexBuffer& vertexBuffer, UInt32 instances, UInt32 firstVertex, UInt32 firstInstance) const override {
909 this->draw(dynamic_cast<const vertex_buffer_type&>(vertexBuffer), instances, firstVertex, firstInstance);
910 }
911
912 inline void cmdDrawIndirect(const IBuffer& batchBuffer, UInt32 batchCount, UInt64 offset) const noexcept override {
913 this->drawIndirect(dynamic_cast<const buffer_type&>(batchBuffer), batchCount, offset);
914 }
915
916 inline void cmdDrawIndirect(const IBuffer& batchBuffer, const IBuffer& countBuffer, UInt64 offset, UInt64 countOffset, UInt32 maxBatches) const noexcept override {
917 this->drawIndirect(dynamic_cast<const buffer_type&>(batchBuffer), dynamic_cast<const buffer_type&>(countBuffer), offset, countOffset, maxBatches);
918 }
919
920 inline void cmdDrawIndexed(const IIndexBuffer& indexBuffer, UInt32 instances, UInt32 firstIndex, Int32 vertexOffset, UInt32 firstInstance) const override {
921 this->drawIndexed(dynamic_cast<const index_buffer_type&>(indexBuffer), instances, firstIndex, vertexOffset, firstInstance);
922 }
923
924 inline void cmdDrawIndexed(const IVertexBuffer& vertexBuffer, const IIndexBuffer& indexBuffer, UInt32 instances, UInt32 firstIndex, Int32 vertexOffset, UInt32 firstInstance) const override {
925 this->drawIndexed(dynamic_cast<const vertex_buffer_type&>(vertexBuffer), dynamic_cast<const index_buffer_type&>(indexBuffer), instances, firstIndex, vertexOffset, firstInstance);
926 }
927
928 inline void cmdDrawIndexedIndirect(const IBuffer& batchBuffer, UInt32 batchCount, UInt64 offset) const noexcept override {
929 this->drawIndexedIndirect(dynamic_cast<const buffer_type&>(batchBuffer), batchCount, offset);
930 }
931
932 inline void cmdDrawIndexedIndirect(const IBuffer& batchBuffer, const IBuffer& countBuffer, UInt64 offset, UInt64 countOffset, UInt32 maxBatches) const noexcept override {
933 this->drawIndexedIndirect(dynamic_cast<const buffer_type&>(batchBuffer), dynamic_cast<const buffer_type&>(countBuffer), offset, countOffset, maxBatches);
934 }
935
936 inline void cmdExecute(const SharedPtr<const ICommandBuffer>& commandBuffer) const override {
937 this->execute(std::dynamic_pointer_cast<const command_buffer_type>(commandBuffer));
938 }
939
940 inline void cmdExecute(Enumerable<SharedPtr<const ICommandBuffer>> commandBuffers) const override {
941 return this->execute(commandBuffers | std::views::transform([](const SharedPtr<const ICommandBuffer>& buffer) { return std::dynamic_pointer_cast<const command_buffer_type>(buffer); }));
942 }
943
944 void cmdBuildAccelerationStructure(IBottomLevelAccelerationStructure& blas, const SharedPtr<const IBuffer>& scratchBuffer, const IBuffer& buffer, UInt64 offset) const override {
945 this->buildAccelerationStructure(dynamic_cast<bottom_level_acceleration_structure_type&>(blas), std::dynamic_pointer_cast<const buffer_type>(scratchBuffer), dynamic_cast<const buffer_type&>(buffer), offset);
946 }
947
948 void cmdBuildAccelerationStructure(ITopLevelAccelerationStructure& tlas, const SharedPtr<const IBuffer>& scratchBuffer, const IBuffer& buffer, UInt64 offset) const override {
949 this->buildAccelerationStructure(dynamic_cast<top_level_acceleration_structure_type&>(tlas), std::dynamic_pointer_cast<const buffer_type>(scratchBuffer), dynamic_cast<const buffer_type&>(buffer), offset);
950 }
951
952 void cmdUpdateAccelerationStructure(IBottomLevelAccelerationStructure& blas, const SharedPtr<const IBuffer>& scratchBuffer, const IBuffer& buffer, UInt64 offset) const override {
953 this->updateAccelerationStructure(dynamic_cast<bottom_level_acceleration_structure_type&>(blas), std::dynamic_pointer_cast<const buffer_type>(scratchBuffer), dynamic_cast<const buffer_type&>(buffer), offset);
954 }
955
956 void cmdUpdateAccelerationStructure(ITopLevelAccelerationStructure& tlas, const SharedPtr<const IBuffer>& scratchBuffer, const IBuffer& buffer, UInt64 offset) const override {
957 this->updateAccelerationStructure(dynamic_cast<top_level_acceleration_structure_type&>(tlas), std::dynamic_pointer_cast<const buffer_type>(scratchBuffer), dynamic_cast<const buffer_type&>(buffer), offset);
958 }
959
960 void cmdCopyAccelerationStructure(const IBottomLevelAccelerationStructure& from, const IBottomLevelAccelerationStructure& to, bool compress) const noexcept override {
961 this->copyAccelerationStructure(dynamic_cast<const bottom_level_acceleration_structure_type&>(from), dynamic_cast<const bottom_level_acceleration_structure_type&>(to), compress);
962 }
963
964 void cmdCopyAccelerationStructure(const ITopLevelAccelerationStructure& from, const ITopLevelAccelerationStructure& to, bool compress) const noexcept override {
965 this->copyAccelerationStructure(dynamic_cast<const top_level_acceleration_structure_type&>(from), dynamic_cast<const top_level_acceleration_structure_type&>(to), compress);
966 }
967
968 void cmdTraceRays(UInt32 width, UInt32 height, UInt32 depth, const ShaderBindingTableOffsets& offsets, const IBuffer& rayGenerationShaderBindingTable, const IBuffer* missShaderBindingTable, const IBuffer* hitShaderBindingTable, const IBuffer* callableShaderBindingTable) const noexcept override {
969 this->traceRays(width, height, depth, offsets, dynamic_cast<const buffer_type&>(rayGenerationShaderBindingTable), dynamic_cast<const buffer_type*>(missShaderBindingTable), dynamic_cast<const buffer_type*>(hitShaderBindingTable), dynamic_cast<const buffer_type*>(callableShaderBindingTable));
970 }
971 };
972
981 template <typename TPipelineLayout, typename TShaderProgram, typename TInputAssembler, typename TRasterizer> requires
982 meta::implements<TInputAssembler, InputAssembler<typename TInputAssembler::vertex_buffer_layout_type, typename TInputAssembler::index_buffer_layout_type>> &&
983 meta::implements<TRasterizer, Rasterizer>
984 class RenderPipeline : public IRenderPipeline, public virtual Pipeline<TPipelineLayout, TShaderProgram> {
985 public:
986 using input_assembler_type = TInputAssembler;
987 using rasterizer_type = TRasterizer;
988
989 protected:
990 RenderPipeline() noexcept = default;
991 RenderPipeline(RenderPipeline&&) noexcept = default;
993 RenderPipeline& operator=(RenderPipeline&&) noexcept = default;
994 RenderPipeline& operator=(const RenderPipeline&) = default;
995
996 public:
997 ~RenderPipeline() noexcept override = default;
998
999 public:
1001 virtual SharedPtr<input_assembler_type> inputAssembler() const noexcept = 0;
1002
1004 virtual SharedPtr<rasterizer_type> rasterizer() const noexcept = 0;
1005
1006 private:
1007 inline SharedPtr<IInputAssembler> getInputAssembler() const noexcept override {
1008 return this->inputAssembler();
1009 }
1010
1011 inline SharedPtr<IRasterizer> getRasterizer() const noexcept override {
1012 return this->rasterizer();
1013 }
1014 };
1015
1022 template <typename TPipelineLayout, typename TShaderProgram>
1023 class ComputePipeline : public IComputePipeline, public virtual Pipeline<TPipelineLayout, TShaderProgram> {
1024 protected:
1025 ComputePipeline() noexcept = default;
1026 ComputePipeline(ComputePipeline&&) noexcept = default;
1028 ComputePipeline& operator=(ComputePipeline&&) noexcept = default;
1029 ComputePipeline& operator=(const ComputePipeline&) = default;
1030
1031 public:
1032 ~ComputePipeline() noexcept override = default;
1033 };
1034
1041 template <typename TPipelineLayout, typename TShaderProgram>
1042 class RayTracingPipeline : public IRayTracingPipeline, public virtual Pipeline<TPipelineLayout, TShaderProgram> {
1043 public:
1045 using descriptor_set_layout_type = base_type::pipeline_layout_type::descriptor_set_layout_type;
1046 using descriptor_set_type = descriptor_set_layout_type::descriptor_set_type;
1047 using descriptor_layout_type = descriptor_set_layout_type::descriptor_layout_type;
1048 using buffer_type = descriptor_set_type::buffer_type;
1049 using image_type = descriptor_set_type::image_type;
1050 using sampler_type = descriptor_set_type::sampler_type;
1051
1052 protected:
1053 RayTracingPipeline() noexcept = default;
1056 RayTracingPipeline& operator=(RayTracingPipeline&&) noexcept = default;
1057 RayTracingPipeline& operator=(const RayTracingPipeline&) = default;
1058
1059 public:
1060 ~RayTracingPipeline() noexcept override = default;
1061
1062 public:
1064 virtual SharedPtr<buffer_type> allocateShaderBindingTable(ShaderBindingTableOffsets& offsets, ShaderBindingGroup groups = ShaderBindingGroup::All) const = 0;
1065
1066 private:
1067 inline SharedPtr<IBuffer> getShaderBindingTable(ShaderBindingTableOffsets& offsets, ShaderBindingGroup groups) const override {
1068 return this->allocateShaderBindingTable(offsets, groups);
1069 }
1070 };
1071
1077 template <typename TImage> requires
1078 std::derived_from<TImage, IImage>
1079 class FrameBuffer : public virtual StateResource, public IFrameBuffer {
1080 public:
1081 using image_type = TImage;
1083
1084 public:
1086
1087 protected:
1088 FrameBuffer() noexcept = default;
1089 FrameBuffer(FrameBuffer&&) noexcept = default;
1090 FrameBuffer(const FrameBuffer&) = default;
1091 FrameBuffer& operator=(FrameBuffer&&) noexcept = default;
1092 FrameBuffer& operator=(const FrameBuffer&) = default;
1093
1094 public:
1095 ~FrameBuffer() noexcept override = default;
1096
1097 public:
1099 virtual const Array<SharedPtr<const image_type>>& images() const = 0;
1100
1101 private:
1102 inline Enumerable<const IImage&> getImages() const override {
1103 return this->images() | std::views::transform([](auto& image) -> const IImage& { return *image; });
1104 }
1105 };
1106
1111 template <typename TCommandBuffer> requires
1114 public:
1116
1117 using command_buffer_type = TCommandBuffer;
1118
1119 protected:
1120 CommandQueue() noexcept = default;
1121 CommandQueue(CommandQueue&&) noexcept = default;
1122 CommandQueue(const CommandQueue&) = default;
1123 CommandQueue& operator=(CommandQueue&&) noexcept = default;
1124 CommandQueue& operator=(const CommandQueue&) = default;
1125
1126 public:
1127 ~CommandQueue() noexcept override = default;
1128
1129 public:
1131 virtual SharedPtr<command_buffer_type> createCommandBuffer(bool beginRecording = false, bool secondary = false) const = 0;
1132
1134 virtual inline UInt64 submit(const SharedPtr<command_buffer_type>& commandBuffer) const {
1135 return this->submit(std::static_pointer_cast<const command_buffer_type>(commandBuffer));
1136 }
1137
1139 virtual UInt64 submit(const SharedPtr<const command_buffer_type>& commandBuffer) const = 0;
1140
1143
1144 private:
1145 inline SharedPtr<ICommandBuffer> getCommandBuffer(bool beginRecording, bool secondary) const override {
1146 return this->createCommandBuffer(beginRecording, secondary);
1147 }
1148
1149 inline UInt64 submitCommandBuffer(const SharedPtr<const ICommandBuffer>& commandBuffer) const override {
1150 return this->submit(std::dynamic_pointer_cast<const command_buffer_type>(commandBuffer));
1151 }
1152
1153 inline UInt64 submitCommandBuffers(Enumerable<SharedPtr<const ICommandBuffer>> commandBuffers) const override {
1154 return this->submit(Enumerable<SharedPtr<const command_buffer_type>> {
1155 commandBuffers | std::views::transform([](const SharedPtr<const ICommandBuffer>& buffer) { return std::dynamic_pointer_cast<const command_buffer_type>(buffer); })
1156 });
1157 }
1158 };
1159
1170 template <typename TCommandQueue, typename TFrameBuffer> requires
1171 meta::implements<TCommandQueue, CommandQueue<typename TCommandQueue::command_buffer_type>> &&
1172 meta::implements<TFrameBuffer, FrameBuffer<typename TFrameBuffer::image_type>>
1173 class RenderPass : public virtual StateResource, public IRenderPass {
1174 public:
1175 using command_queue_type = TCommandQueue;
1176 using command_buffer_type = TCommandQueue::command_buffer_type;
1177 using frame_buffer_type = TFrameBuffer;
1178
1179 protected:
1180 RenderPass() noexcept = default;
1181 RenderPass(RenderPass&&) noexcept = default;
1182 RenderPass(const RenderPass&) = default;
1183 RenderPass& operator=(RenderPass&&) noexcept = default;
1184 RenderPass& operator=(const RenderPass&) = default;
1185
1186 public:
1187 ~RenderPass() noexcept override = default;
1188
1189 public:
1191 virtual SharedPtr<const frame_buffer_type> activeFrameBuffer() const noexcept = 0;
1192
1194 virtual Enumerable<SharedPtr<const command_buffer_type>> commandBuffers() const = 0;
1195
1197 virtual const command_queue_type& commandQueue() const noexcept = 0;
1198
1200 virtual SharedPtr<const command_buffer_type> commandBuffer(UInt32 index) const = 0;
1201
1203 virtual void begin(const frame_buffer_type& frameBuffer) const = 0;
1204
1205 private:
1206 inline SharedPtr<const IFrameBuffer> getActiveFrameBuffer() const noexcept override {
1207 return this->activeFrameBuffer();
1208 }
1209
1210 inline SharedPtr<const ICommandBuffer> getCommandBuffer(UInt32 index) const noexcept override {
1211 return this->commandBuffer(index);
1212 }
1213
1214 inline const ICommandQueue& getCommandQueue() const noexcept override {
1215 return this->commandQueue();
1216 }
1217
1218 inline Enumerable<SharedPtr<const ICommandBuffer>> getCommandBuffers() const override {
1219 return this->commandBuffers();
1220 }
1221
1222 inline void beginRenderPass(const IFrameBuffer& frameBuffer) const override {
1223 this->begin(dynamic_cast<const frame_buffer_type&>(frameBuffer));
1224 }
1225 };
1226
1231 template <typename TImageInterface> requires
1232 std::derived_from<TImageInterface, IImage>
1233 class SwapChain : public ISwapChain {
1234 public:
1235 using image_interface_type = TImageInterface;
1236
1237 protected:
1238 SwapChain() noexcept = default;
1239 SwapChain(SwapChain&&) noexcept = default;
1240 SwapChain(const SwapChain&) = default;
1241 SwapChain& operator=(SwapChain&&) noexcept = default;
1242 SwapChain& operator=(const SwapChain&) = default;
1243
1244 public:
1245 ~SwapChain() noexcept override = default;
1246
1247 public:
1249 virtual const Array<SharedPtr<image_interface_type>>& images() const noexcept = 0;
1250
1251 private:
1252 inline Enumerable<IImage&> getImages() const override {
1253 return this->images() | std::views::transform([](auto& image) -> IImage& { return *image; });
1254 }
1255 };
1256
1268 template <typename TDescriptorLayout, typename TBuffer, typename TVertexBuffer, typename TIndexBuffer, typename TImage, typename TSampler, typename TBLAS, typename TTLAS> requires
1270 std::derived_from<TVertexBuffer, VertexBuffer<typename TVertexBuffer::vertex_buffer_layout_type>> &&
1271 std::derived_from<TIndexBuffer, IndexBuffer<typename TIndexBuffer::index_buffer_layout_type>> &&
1272 std::derived_from<TImage, IImage> &&
1273 std::derived_from<TBuffer, IBuffer> &&
1274 std::derived_from<TSampler, ISampler> &&
1275 std::derived_from<TBLAS, IBottomLevelAccelerationStructure> &&
1276 std::derived_from<TTLAS, ITopLevelAccelerationStructure>
1278 public:
1290
1291 using descriptor_layout_type = TDescriptorLayout;
1292 using vertex_buffer_type = TVertexBuffer;
1293 using vertex_buffer_layout_type = vertex_buffer_type::vertex_buffer_layout_type;
1294 using index_buffer_type = TIndexBuffer;
1295 using index_buffer_layout_type = index_buffer_type::index_buffer_layout_type;
1296 using buffer_type = TBuffer;
1297 using image_type = TImage;
1298 using sampler_type = TSampler;
1301
1302 protected:
1303 GraphicsFactory() noexcept = default;
1304 GraphicsFactory(GraphicsFactory&&) noexcept = default;
1306 GraphicsFactory& operator=(GraphicsFactory&&) noexcept = default;
1307 GraphicsFactory& operator=(const GraphicsFactory&) = default;
1308
1309 public:
1310 ~GraphicsFactory() noexcept override = default;
1311
1312 public:
1314 virtual SharedPtr<TBuffer> createBuffer(BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1315
1317 virtual SharedPtr<TBuffer> createBuffer(const String& name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1318
1320 virtual SharedPtr<TVertexBuffer> createVertexBuffer(const vertex_buffer_layout_type& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1321
1323 virtual SharedPtr<TVertexBuffer> createVertexBuffer(const String& name, const vertex_buffer_layout_type& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1324
1326 virtual SharedPtr<TIndexBuffer> createIndexBuffer(const index_buffer_layout_type& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1327
1329 virtual SharedPtr<TIndexBuffer> createIndexBuffer(const String& name, const index_buffer_layout_type& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1330
1332 virtual SharedPtr<TImage> 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;
1333
1335 virtual SharedPtr<TImage> 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 = 0;
1336
1338 virtual bool tryCreateBuffer(SharedPtr<TBuffer>& buffer, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1339
1341 virtual bool tryCreateBuffer(SharedPtr<TBuffer>& buffer, const String& name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1342
1344 virtual bool tryCreateVertexBuffer(SharedPtr<TVertexBuffer>& buffer, const vertex_buffer_layout_type& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1345
1347 virtual bool tryCreateVertexBuffer(SharedPtr<TVertexBuffer>& buffer, const String& name, const vertex_buffer_layout_type& layout, ResourceHeap heap, UInt32 elements = 1, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1348
1350 virtual bool tryCreateIndexBuffer(SharedPtr<TIndexBuffer>& buffer, const index_buffer_layout_type& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1351
1353 virtual bool tryCreateIndexBuffer(SharedPtr<TIndexBuffer>& buffer, const String& name, const index_buffer_layout_type& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage = ResourceUsage::Default, AllocationBehavior allocationBehavior = AllocationBehavior::Default) const = 0;
1354
1356 virtual bool tryCreateTexture(SharedPtr<TImage>& 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;
1357
1359 virtual bool tryCreateTexture(SharedPtr<TImage>& 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 = 0;
1360
1362 virtual Generator<SharedPtr<TImage>> 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;
1363
1365 virtual SharedPtr<TSampler> 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;
1366
1368 virtual SharedPtr<TSampler> 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 = 0;
1369
1371 virtual Generator<SharedPtr<TSampler>> 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;
1372
1374 inline UniquePtr<TBLAS> createBottomLevelAccelerationStructure(AccelerationStructureFlags flags) const {
1375 return this->createBottomLevelAccelerationStructure("", flags);
1376 }
1377
1380
1383 return this->createTopLevelAccelerationStructure("", flags);
1384 }
1385
1388
1389 private:
1390 inline SharedPtr<IBuffer> getBuffer(BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1391 return this->createBuffer(type, heap, elementSize, elements, usage, allocationBehavior);
1392 }
1393
1394 inline SharedPtr<IBuffer> getBuffer(const String& name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1395 return this->createBuffer(name, type, heap, elementSize, elements, usage, allocationBehavior);
1396 }
1397
1398 inline SharedPtr<IVertexBuffer> getVertexBuffer(const IVertexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1399 return this->createVertexBuffer(dynamic_cast<const vertex_buffer_layout_type&>(layout), heap, elements, usage, allocationBehavior);
1400 }
1401
1402 inline SharedPtr<IVertexBuffer> getVertexBuffer(const String& name, const IVertexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1403 return this->createVertexBuffer(name, dynamic_cast<const vertex_buffer_layout_type&>(layout), heap, elements, usage, allocationBehavior);
1404 }
1405
1406 inline SharedPtr<IIndexBuffer> getIndexBuffer(const IIndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1407 return this->createIndexBuffer(dynamic_cast<const index_buffer_layout_type&>(layout), heap, elements, usage, allocationBehavior);
1408 }
1409
1410 inline SharedPtr<IIndexBuffer> getIndexBuffer(const String& name, const IIndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1411 return this->createIndexBuffer(name, dynamic_cast<const index_buffer_layout_type&>(layout), heap, elements, usage, allocationBehavior);
1412 }
1413
1414 inline SharedPtr<IImage> getTexture(Format format, const Size3d& size, ImageDimensions dimension, UInt32 levels, UInt32 layers, MultiSamplingLevel samples, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1415 return this->createTexture(format, size, dimension, levels, layers, samples, usage, allocationBehavior);
1416 }
1417
1418 inline SharedPtr<IImage> getTexture(const String& name, Format format, const Size3d& size, ImageDimensions dimension, UInt32 levels, UInt32 layers, MultiSamplingLevel samples, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1419 return this->createTexture(name, format, size, dimension, levels, layers, samples, usage, allocationBehavior);
1420 }
1421
1422 inline bool tryGetBuffer(SharedPtr<IBuffer>& buffer, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1423 SharedPtr<buffer_type> actualBuffer;
1424 auto result = this->tryCreateBuffer(actualBuffer, type, heap, elementSize, elements, usage, allocationBehavior);
1425 buffer = actualBuffer;
1426 return result;
1427 }
1428
1429 inline bool tryGetBuffer(SharedPtr<IBuffer>& buffer, const String& name, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1430 SharedPtr<buffer_type> actualBuffer;
1431 auto result = this->tryCreateBuffer(actualBuffer, name, type, heap, elementSize, elements, usage, allocationBehavior);
1432 buffer = actualBuffer;
1433 return result;
1434 }
1435
1436 inline bool tryGetVertexBuffer(SharedPtr<IVertexBuffer>& buffer, const IVertexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1437 SharedPtr<vertex_buffer_type> actualBuffer;
1438 auto result = this->tryCreateVertexBuffer(actualBuffer, dynamic_cast<const vertex_buffer_layout_type&>(layout), heap, elements, usage, allocationBehavior);
1439 buffer = actualBuffer;
1440 return result;
1441 }
1442
1443 inline bool tryGetVertexBuffer(SharedPtr<IVertexBuffer>& buffer, const String& name, const IVertexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1444 SharedPtr<vertex_buffer_type> actualBuffer;
1445 auto result = this->tryCreateVertexBuffer(actualBuffer, name, dynamic_cast<const vertex_buffer_layout_type&>(layout), heap, elements, usage, allocationBehavior);
1446 buffer = actualBuffer;
1447 return result;
1448 }
1449
1450 inline bool tryGetIndexBuffer(SharedPtr<IIndexBuffer>& buffer, const IIndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1451 SharedPtr<index_buffer_type> actualBuffer;
1452 auto result = this->tryCreateIndexBuffer(actualBuffer, dynamic_cast<const index_buffer_layout_type&>(layout), heap, elements, usage, allocationBehavior);
1453 buffer = actualBuffer;
1454 return result;
1455 }
1456
1457 inline bool tryGetIndexBuffer(SharedPtr<IIndexBuffer>& buffer, const String& name, const IIndexBufferLayout& layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1458 SharedPtr<index_buffer_type> actualBuffer;
1459 auto result = this->tryCreateIndexBuffer(actualBuffer, name, dynamic_cast<const index_buffer_layout_type&>(layout), heap, elements, usage, allocationBehavior);
1460 buffer = actualBuffer;
1461 return result;
1462 }
1463
1464 inline bool tryGetTexture(SharedPtr<IImage>& image, Format format, const Size3d& size, ImageDimensions dimension, UInt32 levels, UInt32 layers, MultiSamplingLevel samples, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1465 SharedPtr<image_type> actualImage;
1466 auto result = this->tryCreateTexture(actualImage, format, size, dimension, levels, layers, samples, usage, allocationBehavior);
1467 image = actualImage;
1468 return result;
1469 }
1470
1471 inline bool tryGetTexture(SharedPtr<IImage>& image, const String& name, Format format, const Size3d& size, ImageDimensions dimension, UInt32 levels, UInt32 layers, MultiSamplingLevel samples, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1472 SharedPtr<image_type> actualImage;
1473 auto result = this->tryCreateTexture(actualImage, name, format, size, dimension, levels, layers, samples, usage, allocationBehavior);
1474 image = actualImage;
1475 return result;
1476 }
1477
1478 inline Generator<SharedPtr<IImage>> getTextures(Format format, const Size3d& size, ImageDimensions dimension, UInt32 layers, UInt32 levels, MultiSamplingLevel samples, ResourceUsage usage, AllocationBehavior allocationBehavior) const override {
1480 for (auto texture : gen)
1481 co_yield std::move(texture);
1482 }(this->createTextures(format, size, dimension, layers, levels, samples, usage, allocationBehavior));
1483 }
1484
1485 inline SharedPtr<ISampler> getSampler(FilterMode magFilter, FilterMode minFilter, BorderMode borderU, BorderMode borderV, BorderMode borderW, MipMapMode mipMapMode, Float mipMapBias, Float maxLod, Float minLod, Float anisotropy) const override {
1486 return this->createSampler(magFilter, minFilter, borderU, borderV, borderW, mipMapMode, mipMapBias, maxLod, minLod, anisotropy);
1487 }
1488
1489 inline SharedPtr<ISampler> getSampler(const String& name, FilterMode magFilter, FilterMode minFilter, BorderMode borderU, BorderMode borderV, BorderMode borderW, MipMapMode mipMapMode, Float mipMapBias, Float maxLod, Float minLod, Float anisotropy) const override {
1490 return this->createSampler(name, magFilter, minFilter, borderU, borderV, borderW, mipMapMode, mipMapBias, maxLod, minLod, anisotropy);
1491 }
1492
1493 inline Generator<SharedPtr<ISampler>> getSamplers(FilterMode magFilter, FilterMode minFilter, BorderMode borderU, BorderMode borderV, BorderMode borderW, MipMapMode mipMapMode, Float mipMapBias, Float maxLod, Float minLod, Float anisotropy) const override {
1495 for (auto sampler : gen)
1496 co_yield std::move(sampler);
1497 }(this->createSamplers(magFilter, minFilter, borderU, borderV, borderW, mipMapMode, mipMapBias, maxLod, minLod, anisotropy));
1498 }
1499
1501 return this->createBottomLevelAccelerationStructure(name, flags);
1502 }
1503
1504 inline UniquePtr<ITopLevelAccelerationStructure> getTlas(StringView name, AccelerationStructureFlags flags) const override {
1505 return this->createTopLevelAccelerationStructure(name, flags);
1506 }
1507 };
1508
1527 template <typename TFactory, typename TSurface, typename TGraphicsAdapter, typename TSwapChain, typename TCommandQueue, typename TRenderPass, typename TRenderPipeline, typename TComputePipeline, typename TRayTracingPipeline, typename TBarrier> requires
1528 meta::implements<TSurface, ISurface> &&
1529 meta::implements<TGraphicsAdapter, IGraphicsAdapter> &&
1530 meta::implements<TSwapChain, SwapChain<typename TFactory::image_type>> &&
1531 meta::implements<TCommandQueue, CommandQueue<typename TCommandQueue::command_buffer_type>> &&
1532 meta::implements<TFactory, GraphicsFactory<typename TFactory::descriptor_layout_type, typename TFactory::buffer_type, typename TFactory::vertex_buffer_type, typename TFactory::index_buffer_type, typename TFactory::image_type, typename TFactory::sampler_type, typename TFactory::bottom_level_acceleration_structure_type, typename TFactory::top_level_acceleration_structure_type>> &&
1533 meta::implements<TRenderPass, RenderPass<TCommandQueue, typename TRenderPass::frame_buffer_type>> &&
1534 meta::implements<TRenderPipeline, RenderPipeline<typename TRenderPipeline::pipeline_layout_type, typename TRenderPipeline::shader_program_type, typename TRenderPipeline::input_assembler_type, typename TRenderPipeline::rasterizer_type>> &&
1535 meta::implements<TComputePipeline, ComputePipeline<typename TComputePipeline::pipeline_layout_type, typename TComputePipeline::shader_program_type>> &&
1536 meta::implements<TRayTracingPipeline, RayTracingPipeline<typename TRayTracingPipeline::pipeline_layout_type, typename TRayTracingPipeline::shader_program_type>> &&
1537 meta::implements<TBarrier, Barrier<typename TFactory::buffer_type, typename TFactory::image_type>>
1539 public:
1540 using surface_type = TSurface;
1541 using adapter_type = TGraphicsAdapter;
1542 using swap_chain_type = TSwapChain;
1543 using command_queue_type = TCommandQueue;
1544 using command_buffer_type = command_queue_type::command_buffer_type;
1545 using descriptor_set_type = command_buffer_type::descriptor_set_type;
1546 using pipeline_type = command_buffer_type::pipeline_type;
1547 using factory_type = TFactory;
1548 using barrier_type = TBarrier;
1549 using descriptor_layout_type = factory_type::descriptor_layout_type;
1550 using vertex_buffer_type = factory_type::vertex_buffer_type;
1551 using index_buffer_type = factory_type::index_buffer_type;
1552 using buffer_type = factory_type::buffer_type;
1553 using image_type = factory_type::image_type;
1554 using sampler_type = factory_type::sampler_type;
1555 using bottom_level_acceleration_structure_type = factory_type::bottom_level_acceleration_structure_type;
1556 using top_level_acceleration_structure_type = factory_type::top_level_acceleration_structure_type;
1557 using render_pass_type = TRenderPass;
1558 using frame_buffer_type = render_pass_type::frame_buffer_type;
1559 using render_pipeline_type = TRenderPipeline;
1560 using compute_pipeline_type = TComputePipeline;
1561 using ray_tracing_pipeline_type = TRayTracingPipeline;
1562 using pipeline_layout_type = render_pipeline_type::pipeline_layout_type;
1563 using shader_program_type = render_pipeline_type::shader_program_type;
1564 using input_assembler_type = render_pipeline_type::input_assembler_type;
1565 using rasterizer_type = render_pipeline_type::rasterizer_type;
1566
1567 protected:
1568 GraphicsDevice() noexcept = default;
1569 GraphicsDevice(GraphicsDevice&&) noexcept = default;
1571 GraphicsDevice& operator=(GraphicsDevice&&) noexcept = default;
1572 GraphicsDevice& operator=(const GraphicsDevice&) = default;
1573
1574 public:
1575 ~GraphicsDevice() noexcept override = default;
1576
1577 public:
1579 const surface_type& surface() const noexcept override = 0;
1580
1582 const adapter_type& adapter() const noexcept override = 0;
1583
1585 const swap_chain_type& swapChain() const noexcept override = 0;
1586
1588 swap_chain_type& swapChain() noexcept override = 0;
1589
1591 const factory_type& factory() const noexcept override = 0;
1592
1594 virtual const command_queue_type& defaultQueue(QueueType type) const = 0;
1595
1597 virtual SharedPtr<const command_queue_type> createQueue(QueueType type, QueuePriority priority = QueuePriority::Normal) = 0;
1598
1600 [[nodiscard]] virtual UniquePtr<barrier_type> makeBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const = 0;
1601
1603 [[nodiscard]] inline SharedPtr<frame_buffer_type> makeFrameBuffer(const Size2d& renderArea) const {
1604 return this->makeFrameBuffer("", renderArea);
1605 }
1606
1609 [[nodiscard]] inline SharedPtr<frame_buffer_type> makeFrameBuffer(const Size2d& renderArea, frame_buffer_type::allocation_callback_type allocationCallback) const {
1610 return this->makeFrameBuffer("", renderArea, std::move(allocationCallback));
1611 }
1612
1614 [[nodiscard]] virtual SharedPtr<frame_buffer_type> makeFrameBuffer(StringView name, const Size2d& renderArea) const = 0;
1615
1618 [[nodiscard]] virtual SharedPtr<frame_buffer_type> makeFrameBuffer(StringView name, const Size2d& renderArea, frame_buffer_type::allocation_callback_type allocationCallback) const = 0;
1619
1620 private:
1621 inline UniquePtr<IBarrier> getNewBarrier(PipelineStage syncBefore, PipelineStage syncAfter) const override {
1622 return this->makeBarrier(syncBefore, syncAfter);
1623 }
1624
1625 inline SharedPtr<IFrameBuffer> getNewFrameBuffer(StringView name, const Size2d& renderArea) const override {
1626 return this->makeFrameBuffer(name, renderArea);
1627 }
1628
1629 inline const ICommandQueue& getDefaultQueue(QueueType type) const override {
1630 return this->defaultQueue(type);
1631 }
1632
1633 inline SharedPtr<const ICommandQueue> getNewQueue(QueueType type, QueuePriority priority) override {
1634 return std::static_pointer_cast<const ICommandQueue>(this->createQueue(type, priority));
1635 }
1636
1637 public:
1639 virtual void computeAccelerationStructureSizes(const bottom_level_acceleration_structure_type& blas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate = false) const = 0;
1640
1642 virtual void computeAccelerationStructureSizes(const top_level_acceleration_structure_type& tlas, UInt64 & bufferSize, UInt64 & scratchSize, bool forUpdate = false) const = 0;
1643
1645 [[nodiscard]] virtual VirtualAllocator::Allocation allocateGlobalDescriptors(const descriptor_set_type& descriptorSet, DescriptorHeapType heapType) const = 0;
1646
1648 virtual void releaseGlobalDescriptors(const descriptor_set_type& descriptorSet) const = 0;
1649
1651 virtual void updateGlobalDescriptors(const descriptor_set_type& descriptorSet, UInt32 binding, UInt32 offset, UInt32 descriptors) const = 0;
1652
1654 virtual void bindDescriptorSet(const command_buffer_type& commandBuffer, const descriptor_set_type& descriptorSet, const pipeline_type& pipeline) const noexcept = 0;
1655
1657 virtual void bindGlobalDescriptorHeaps(const command_buffer_type& commandBuffer) const noexcept = 0;
1658
1659 private:
1660 inline void getAccelerationStructureSizes(const IBottomLevelAccelerationStructure& blas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate) const override {
1661 this->computeAccelerationStructureSizes(dynamic_cast<const bottom_level_acceleration_structure_type&>(blas), bufferSize, scratchSize, forUpdate);
1662 }
1663
1664 inline void getAccelerationStructureSizes(const ITopLevelAccelerationStructure& tlas, UInt64& bufferSize, UInt64& scratchSize, bool forUpdate) const override {
1665 this->computeAccelerationStructureSizes(dynamic_cast<const top_level_acceleration_structure_type&>(tlas), bufferSize, scratchSize, forUpdate);
1666 }
1667
1668 inline VirtualAllocator::Allocation doAllocateGlobalDescriptors(const IDescriptorSet& descriptorSet, DescriptorHeapType heapType) const override {
1669 return this->allocateGlobalDescriptors(dynamic_cast<const descriptor_set_type&>(descriptorSet), heapType);
1670 }
1671
1672 inline void doReleaseGlobalDescriptors(const IDescriptorSet& descriptorSet) const override {
1673 this->releaseGlobalDescriptors(dynamic_cast<const descriptor_set_type&>(descriptorSet));
1674 }
1675
1676 inline void doUpdateGlobalDescriptors(const IDescriptorSet& descriptorSet, UInt32 binding, UInt32 offset, UInt32 descriptors) const override {
1677 this->updateGlobalDescriptors(dynamic_cast<const descriptor_set_type&>(descriptorSet), binding, offset, descriptors);
1678 }
1679
1680 inline void doBindDescriptorSet(const ICommandBuffer& commandBuffer, const IDescriptorSet& descriptorSet, const IPipeline& pipeline) const noexcept override {
1681 this->bindDescriptorSet(dynamic_cast<const command_buffer_type&>(commandBuffer), dynamic_cast<const descriptor_set_type&>(descriptorSet), dynamic_cast<const pipeline_type&>(pipeline));
1682 }
1683
1684 inline void doBindGlobalDescriptorHeaps(const ICommandBuffer& commandBuffer) const noexcept override {
1685 this->bindGlobalDescriptorHeaps(dynamic_cast<const command_buffer_type&>(commandBuffer));
1686 }
1687
1688#if defined(LITEFX_BUILD_DEFINE_BUILDERS)
1689 public:
1690 using render_pass_builder_type = render_pass_type::builder_type;
1691 using render_pipeline_builder_type = render_pipeline_type::builder_type;
1692 using compute_pipeline_builder_type = compute_pipeline_type::builder_type;
1693 using ray_tracing_pipeline_builder_type = ray_tracing_pipeline_type::builder_type;
1694 using pipeline_layout_builder_type = pipeline_layout_type::builder_type;
1695 using input_assembler_builder_type = input_assembler_type::builder_type;
1696 using rasterizer_builder_type = rasterizer_type::builder_type;
1697 using shader_program_builder_type = shader_program_type::builder_type;
1698 using barrier_builder_Type = barrier_type::builder_type;
1699
1705 [[nodiscard]] virtual render_pass_builder_type buildRenderPass(UInt32 commandBuffers = 1) const = 0;
1706
1713 [[nodiscard]] virtual render_pass_builder_type buildRenderPass(const String& name, UInt32 commandBuffers = 1) const = 0;
1714
1720 [[nodiscard]] virtual compute_pipeline_builder_type buildComputePipeline(const String& name) const = 0;
1721
1727 //[[nodiscard]] virtual render_pipeline_builder_type buildRenderPipeline(const String& name) const = 0;
1728
1735 [[nodiscard]] virtual render_pipeline_builder_type buildRenderPipeline(const render_pass_type& renderPass, const String& name) const = 0;
1736
1745 [[nodiscard]] virtual ray_tracing_pipeline_builder_type buildRayTracingPipeline(ShaderRecordCollection&& shaderRecords) const = 0;
1746
1756 [[nodiscard]] virtual ray_tracing_pipeline_builder_type buildRayTracingPipeline(const String& name, ShaderRecordCollection&& shaderRecords) const = 0;
1757
1762 [[nodiscard]] virtual pipeline_layout_builder_type buildPipelineLayout() const = 0;
1763
1768 [[nodiscard]] virtual input_assembler_builder_type buildInputAssembler() const = 0;
1769
1774 [[nodiscard]] virtual rasterizer_builder_type buildRasterizer() const = 0;
1775
1780 [[nodiscard]] virtual shader_program_builder_type buildShaderProgram() const = 0;
1781
1786 [[nodiscard]] virtual barrier_builder_Type buildBarrier() const = 0;
1787#endif // defined(LITEFX_BUILD_DEFINE_BUILDERS)
1788 };
1789
1794 template <typename TGraphicsDevice> requires
1795 meta::implements<TGraphicsDevice, GraphicsDevice<typename TGraphicsDevice::factory_type, typename TGraphicsDevice::surface_type, typename TGraphicsDevice::adapter_type, typename TGraphicsDevice::swap_chain_type, typename TGraphicsDevice::command_queue_type, typename TGraphicsDevice::render_pass_type, typename TGraphicsDevice::render_pipeline_type, typename TGraphicsDevice::compute_pipeline_type, typename TGraphicsDevice::ray_tracing_pipeline_type, typename TGraphicsDevice::barrier_type>>
1797 public:
1798 using device_type = TGraphicsDevice;
1799 using surface_type = device_type::surface_type;
1800 using adapter_type = device_type::adapter_type;
1801 using swap_chain_type = device_type::swap_chain_type;
1802 using command_queue_type = device_type::command_queue_type;
1803 using command_buffer_type = device_type::command_buffer_type;
1804 using factory_type = device_type::factory_type;
1805 using barrier_type = device_type::barrier_type;
1806 using descriptor_layout_type = factory_type::descriptor_layout_type;
1807 using vertex_buffer_type = factory_type::vertex_buffer_type;
1808 using index_buffer_type = factory_type::index_buffer_type;
1809 using buffer_type = factory_type::buffer_type;
1810 using image_type = factory_type::image_type;
1811 using sampler_type = factory_type::sampler_type;
1812 using frame_buffer_type = device_type::frame_buffer_type;
1813 using render_pass_type = device_type::render_pass_type;
1814 using pipeline_layout_type = device_type::pipeline_layout_type;
1815 using render_pipeline_type = device_type::render_pipeline_type;
1816 using compute_pipeline_type = device_type::compute_pipeline_type;
1817 using ray_tracing_pipeline_type = device_type::ray_tracing_pipeline_type;
1818 using shader_program_type = device_type::shader_program_type;
1819 using input_assembler_type = device_type::input_assembler_type;
1820 using rasterizer_type = device_type::rasterizer_type;
1821
1822 protected:
1823 RenderBackend() noexcept = default;
1824 RenderBackend(RenderBackend&&) noexcept = default;
1825 RenderBackend(const RenderBackend&) = default;
1826 RenderBackend& operator=(RenderBackend&&) noexcept = default;
1827 RenderBackend& operator=(const RenderBackend&) = default;
1828
1829 public:
1830 ~RenderBackend() noexcept override = default;
1831
1832 public:
1834 virtual const Array<SharedPtr<const adapter_type>>& adapters() const = 0;
1835
1837 const adapter_type* findAdapter(const Optional<UInt64>& adapterId = std::nullopt) const noexcept override = 0;
1838
1840 virtual void registerDevice(const String& name, SharedPtr<device_type>&& device) = 0;
1841
1847 template <typename TSelf, typename ...TArgs>
1848 inline device_type& createDevice(this TSelf& self, const String& name, const adapter_type& adapter, UniquePtr<surface_type>&& surface, TArgs&&... _args) {
1849 auto devicePtr = device_type::create(self, adapter, std::move(surface), std::forward<TArgs>(_args)...);
1850 auto& device = *devicePtr;
1851 self.registerDevice(name, std::move(devicePtr));
1852 return device;
1853 }
1854
1859 virtual void releaseDevice(const String& name) = 0;
1860
1862 device_type* device(const String& name) noexcept override = 0;
1863
1865 const device_type* device(const String& name) const noexcept override = 0;
1866
1868 inline const device_type* operator[](const String& name) const noexcept override {
1869 return this->device(name);
1870 };
1871
1873 inline device_type* operator[](const String& name) noexcept override {
1874 return this->device(name);
1875 };
1876
1877 // IRenderBackend interface
1878 private:
1879 inline Enumerable<SharedPtr<const IGraphicsAdapter>> getAdapters() const override {
1880 return this->adapters();
1881 }
1882 };
1883}
Definition math.hpp:864
Definition math.hpp:833
Definition math.hpp:504
A barrier used for GPU resource synchronization.
Definition rendering.hpp:17
TImage image_type
Definition rendering.hpp:22
virtual constexpr void transition(const buffer_type &buffer, ResourceAccess accessBefore, ResourceAccess accessAfter)=0
TBuffer buffer_type
Definition rendering.hpp:21
Barrier() noexcept=default
Represents a command buffer, that buffers commands that should be submitted to a CommandQueue.
Definition rendering.hpp:619
virtual void execute(const SharedPtr< const command_buffer_type > &commandBuffer) const =0
pipeline_type::pipeline_layout_type pipeline_layout_type
Definition rendering.hpp:649
virtual void buildAccelerationStructure(bottom_level_acceleration_structure_type &blas, const SharedPtr< const buffer_type > &scratchBuffer, const buffer_type &buffer, UInt64 offset=0) const =0
TBuffer buffer_type
Definition rendering.hpp:643
virtual void updateAccelerationStructure(bottom_level_acceleration_structure_type &blas, const SharedPtr< const buffer_type > &scratchBuffer, const buffer_type &buffer, UInt64 offset=0) const =0
TBLAS bottom_level_acceleration_structure_type
Definition rendering.hpp:653
pipeline_layout_type::push_constants_layout_type push_constants_layout_type
Definition rendering.hpp:651
TBarrier barrier_type
Definition rendering.hpp:647
virtual void drawIndexed(const vertex_buffer_type &vertexBuffer, const index_buffer_type &indexBuffer, UInt32 instances=1, UInt32 firstIndex=0, Int32 vertexOffset=0, UInt32 firstInstance=0) const
Definition rendering.hpp:767
virtual void execute(Enumerable< SharedPtr< const command_buffer_type > > commandBuffers) const =0
TVertexBuffer vertex_buffer_type
Definition rendering.hpp:644
TIndexBuffer index_buffer_type
Definition rendering.hpp:645
descriptor_set_layout_type::descriptor_set_type descriptor_set_type
Definition rendering.hpp:652
pipeline_layout_type::descriptor_set_layout_type descriptor_set_layout_type
Definition rendering.hpp:650
virtual void copyAccelerationStructure(const bottom_level_acceleration_structure_type &from, const bottom_level_acceleration_structure_type &to, bool compress=false) const noexcept=0
virtual void buildAccelerationStructure(top_level_acceleration_structure_type &tlas, const SharedPtr< const buffer_type > &scratchBuffer, const buffer_type &buffer, UInt64 offset=0) const =0
TCommandBuffer command_buffer_type
Definition rendering.hpp:642
TImage image_type
Definition rendering.hpp:646
TPipeline pipeline_type
Definition rendering.hpp:648
virtual void updateAccelerationStructure(top_level_acceleration_structure_type &tlas, const SharedPtr< const buffer_type > &scratchBuffer, const buffer_type &buffer, UInt64 offset=0) const =0
virtual void drawIndexed(const index_buffer_type &indexBuffer, UInt32 instances=1, UInt32 firstIndex=0, Int32 vertexOffset=0, UInt32 firstInstance=0) const
Definition rendering.hpp:761
TTLAS top_level_acceleration_structure_type
Definition rendering.hpp:654
friend TCommandBuffer
Definition rendering.hpp:639
Represents a command queue.
Definition rendering.hpp:1113
TCommandBuffer command_buffer_type
Definition rendering.hpp:1117
virtual UInt64 submit(const SharedPtr< const command_buffer_type > &commandBuffer) const =0
virtual UInt64 submit(Enumerable< SharedPtr< const command_buffer_type > > commandBuffers) const =0
CommandQueue() noexcept=default
Represents a compute Pipeline.
Definition rendering.hpp:1023
ComputePipeline() noexcept=default
Defines a set of descriptors.
Definition rendering.hpp:150
virtual void update(UInt32 binding, const buffer_type &buffer, UInt32 bufferElement=0, UInt32 elements=0, UInt32 firstDescriptor=0, Format texelFormat=Format::None) const =0
TSampler sampler_type
Definition rendering.hpp:156
virtual UInt32 bindToHeap(DescriptorType bindingType, UInt32 descriptor, const buffer_type &buffer, UInt32 bufferElement=0, UInt32 elements=0, Format texelFormat=Format::None) const =0
TAccelerationStructure acceleration_structure_type
Definition rendering.hpp:158
TImage image_type
Definition rendering.hpp:157
DescriptorSet() noexcept=default
TBuffer buffer_type
Definition rendering.hpp:155
Describes the layout of a descriptor set.
Definition rendering.hpp:237
virtual const Array< descriptor_layout_type > & descriptors() const noexcept=0
virtual UniquePtr< descriptor_set_type > allocate(UInt32 descriptors, Generator< DescriptorBinding > bindings) const =0
virtual UniquePtr< descriptor_set_type > allocate(Generator< DescriptorBinding > bindings) const
Definition rendering.hpp:272
virtual UniquePtr< descriptor_set_type > allocate(UInt32 descriptors, Span< DescriptorBinding > bindings) const =0
virtual Generator< UniquePtr< descriptor_set_type > > allocate(UInt32 descriptorSets, UInt32 descriptors, std::function< Generator< DescriptorBinding >(UInt32)> bindingFactory) const =0
virtual Generator< UniquePtr< descriptor_set_type > > allocate(UInt32 descriptorSets, std::function< Generator< DescriptorBinding >(UInt32)> bindings) const
Definition rendering.hpp:298
virtual Generator< UniquePtr< descriptor_set_type > > allocate(UInt32 descriptorSets, UInt32 descriptors, std::initializer_list< std::initializer_list< DescriptorBinding > > bindings={ }) const =0
virtual UniquePtr< descriptor_set_type > allocate(UInt32 descriptors, std::initializer_list< DescriptorBinding > bindings) const =0
const descriptor_layout_type & descriptor(UInt32 binding) const override=0
Returns the descriptor layout for the descriptor bound to the binding point provided with binding ....
virtual Generator< UniquePtr< descriptor_set_type > > allocate(UInt32 descriptorSets, std::initializer_list< std::initializer_list< DescriptorBinding > > bindings={ }) const
Definition rendering.hpp:286
TDescriptorSet descriptor_set_type
Definition rendering.hpp:242
virtual void free(const descriptor_set_type &descriptorSet) const =0
virtual UniquePtr< descriptor_set_type > allocate(Span< DescriptorBinding > bindings) const
Definition rendering.hpp:267
TDescriptorLayout descriptor_layout_type
Definition rendering.hpp:241
virtual UniquePtr< descriptor_set_type > allocate(std::initializer_list< DescriptorBinding > bindings={ }) const
Definition rendering.hpp:262
Stores the images used by a RenderPass to either read from using input attachments or write to using ...
Definition rendering.hpp:1079
TImage image_type
Definition rendering.hpp:1081
IFrameBuffer::allocation_callback_type< image_type > allocation_callback_type
Definition rendering.hpp:1082
FrameBuffer() noexcept=default
Represents the graphics device that a rendering back-end is doing work on.
Definition rendering.hpp:1538
command_buffer_type::pipeline_type pipeline_type
Definition rendering.hpp:1546
TFactory factory_type
Definition rendering.hpp:1547
factory_type::top_level_acceleration_structure_type top_level_acceleration_structure_type
Definition rendering.hpp:1556
TRayTracingPipeline ray_tracing_pipeline_type
Definition rendering.hpp:1561
factory_type::vertex_buffer_type vertex_buffer_type
Definition rendering.hpp:1550
virtual void computeAccelerationStructureSizes(const bottom_level_acceleration_structure_type &blas, UInt64 &bufferSize, UInt64 &scratchSize, bool forUpdate=false) const =0
render_pipeline_type::pipeline_layout_type pipeline_layout_type
Definition rendering.hpp:1562
TGraphicsAdapter adapter_type
Definition rendering.hpp:1541
SharedPtr< frame_buffer_type > makeFrameBuffer(const Size2d &renderArea, frame_buffer_type::allocation_callback_type allocationCallback) const
Definition rendering.hpp:1609
render_pipeline_type::shader_program_type shader_program_type
Definition rendering.hpp:1563
TComputePipeline compute_pipeline_type
Definition rendering.hpp:1560
virtual void updateGlobalDescriptors(const descriptor_set_type &descriptorSet, UInt32 binding, UInt32 offset, UInt32 descriptors) const =0
render_pipeline_type::input_assembler_type input_assembler_type
Definition rendering.hpp:1564
factory_type::bottom_level_acceleration_structure_type bottom_level_acceleration_structure_type
Definition rendering.hpp:1555
TBarrier barrier_type
Definition rendering.hpp:1548
TSwapChain swap_chain_type
Definition rendering.hpp:1542
virtual void releaseGlobalDescriptors(const descriptor_set_type &descriptorSet) const =0
virtual SharedPtr< frame_buffer_type > makeFrameBuffer(StringView name, const Size2d &renderArea) const =0
factory_type::buffer_type buffer_type
Definition rendering.hpp:1552
command_queue_type::command_buffer_type command_buffer_type
Definition rendering.hpp:1544
TRenderPass render_pass_type
Definition rendering.hpp:1557
TRenderPipeline render_pipeline_type
Definition rendering.hpp:1559
virtual void computeAccelerationStructureSizes(const top_level_acceleration_structure_type &tlas, UInt64 &bufferSize, UInt64 &scratchSize, bool forUpdate=false) const =0
factory_type::descriptor_layout_type descriptor_layout_type
Definition rendering.hpp:1549
render_pass_type::frame_buffer_type frame_buffer_type
Definition rendering.hpp:1558
GraphicsDevice() noexcept=default
factory_type::image_type image_type
Definition rendering.hpp:1553
TSurface surface_type
Definition rendering.hpp:1540
render_pipeline_type::rasterizer_type rasterizer_type
Definition rendering.hpp:1565
virtual void bindGlobalDescriptorHeaps(const command_buffer_type &commandBuffer) const noexcept=0
factory_type::sampler_type sampler_type
Definition rendering.hpp:1554
virtual VirtualAllocator::Allocation allocateGlobalDescriptors(const descriptor_set_type &descriptorSet, DescriptorHeapType heapType) const =0
virtual SharedPtr< frame_buffer_type > makeFrameBuffer(StringView name, const Size2d &renderArea, frame_buffer_type::allocation_callback_type allocationCallback) const =0
virtual void bindDescriptorSet(const command_buffer_type &commandBuffer, const descriptor_set_type &descriptorSet, const pipeline_type &pipeline) const noexcept=0
command_buffer_type::descriptor_set_type descriptor_set_type
Definition rendering.hpp:1545
TCommandQueue command_queue_type
Definition rendering.hpp:1543
factory_type::index_buffer_type index_buffer_type
Definition rendering.hpp:1551
Describes a factory that creates objects for a GraphicsDevice.
Definition rendering.hpp:1277
TVertexBuffer vertex_buffer_type
Definition rendering.hpp:1292
vertex_buffer_type::vertex_buffer_layout_type vertex_buffer_layout_type
Definition rendering.hpp:1293
virtual UniquePtr< TBLAS > createBottomLevelAccelerationStructure(StringView name, AccelerationStructureFlags flags) const =0
TTLAS top_level_acceleration_structure_type
Definition rendering.hpp:1300
GraphicsFactory() noexcept=default
virtual UniquePtr< TTLAS > createTopLevelAccelerationStructure(StringView name, AccelerationStructureFlags flags) const =0
TIndexBuffer index_buffer_type
Definition rendering.hpp:1294
TImage image_type
Definition rendering.hpp:1297
TSampler sampler_type
Definition rendering.hpp:1298
index_buffer_type::index_buffer_layout_type index_buffer_layout_type
Definition rendering.hpp:1295
TDescriptorLayout descriptor_layout_type
Definition rendering.hpp:1291
TBLAS bottom_level_acceleration_structure_type
Definition rendering.hpp:1299
TBuffer buffer_type
Definition rendering.hpp:1296
UniquePtr< TTLAS > createTopLevelAccelerationStructure(AccelerationStructureFlags flags) const
Definition rendering.hpp:1382
Base interface for a ray tracing acceleration structure.
Definition rendering_api.hpp:5260
The interface for a barrier.
Definition rendering_api.hpp:5921
constexpr void transition(const IBuffer &buffer, ResourceAccess accessBefore, ResourceAccess accessAfter)
Inserts a buffer barrier that blocks access to buffer of types contained in accessAfter for subsequ...
Definition rendering_api.hpp:5960
A structure that holds a singular entity of geometry for hardware ray-tracing.
Definition rendering_api.hpp:5399
Base interface for buffer objects.
Definition rendering_api.hpp:4997
The interface for a command buffer.
Definition rendering_api.hpp:7682
void barrier(const IBarrier &barrier) const noexcept
Executes the transitions that have been added to barrier .
Definition rendering_api.hpp:7791
void bind(const IDescriptorSet &descriptorSet) const
Binds the provided descriptor to the last pipeline that was used by the command buffer.
Definition rendering_api.hpp:8128
void pushConstants(const IPushConstantsLayout &layout, const void *const memory) const
Pushes a block of memory into the push constants backing memory.
Definition rendering_api.hpp:8488
void transfer(const IBuffer &source, const IBuffer &target, UInt32 sourceElement=0, UInt32 targetElement=0, UInt32 elements=1) const
Performs a buffer-to-buffer transfer from source to target .
Definition rendering_api.hpp:7809
virtual void drawIndexed(UInt32 indices, UInt32 instances=1, UInt32 firstIndex=0, Int32 vertexOffset=0, UInt32 firstInstance=0) const noexcept=0
Draws the currently bound vertex buffer with a set of indices from the currently bound index buffer.
virtual void dispatchMesh(const Vector3u &threadGroupCount) const noexcept=0
Executes a mesh shader pipeline.
void updateAccelerationStructure(IBottomLevelAccelerationStructure &blas, const SharedPtr< const IBuffer > &scratchBuffer, const IBuffer &buffer, UInt64 offset=0) const
Updates a bottom-level acceleration structure.
Definition rendering_api.hpp:8617
void use(const IPipeline &pipeline) const noexcept
Sets the active pipeline state.
Definition rendering_api.hpp:8118
SharedPtr< const ICommandQueue > queue() const noexcept
Gets a pointer to the command queue that this command buffer was allocated from or nullptr,...
Definition rendering_api.hpp:7768
void copyAccelerationStructure(const IBottomLevelAccelerationStructure &from, const IBottomLevelAccelerationStructure &to, bool compress=false) const noexcept
Copies the acceleration structure from into the acceleration structure to .
Definition rendering_api.hpp:8650
virtual void dispatch(const Vector3u &threadGroupCount) const noexcept=0
Executes a compute shader.
void drawIndexedIndirect(const IBuffer &batchBuffer, UInt32 batchCount, UInt64 offset=0) const noexcept
Executes a set of indirect indexed draw calls.
Definition rendering_api.hpp:8466
void dispatchIndirect(const IBuffer &batchBuffer, UInt32 batchCount, UInt64 offset=0) const noexcept
Executes a set of indirect dispatches.
Definition rendering_api.hpp:8285
void drawIndirect(const IBuffer &batchBuffer, UInt32 batchCount, UInt64 offset=0) const noexcept
Executes a set of indirect non-indexed draw calls.
Definition rendering_api.hpp:8400
void buildAccelerationStructure(IBottomLevelAccelerationStructure &blas, const SharedPtr< const IBuffer > &scratchBuffer, const IBuffer &buffer, UInt64 offset=0) const
Builds a bottom-level acceleration structure.
Definition rendering_api.hpp:8585
virtual void draw(UInt32 vertices, UInt32 instances=1, UInt32 firstVertex=0, UInt32 firstInstance=0) const noexcept=0
Draws a number of vertices from the currently bound vertex buffer.
The interface for a command queue.
Definition rendering_api.hpp:9742
UInt64 submit(const SharedPtr< const ICommandBuffer > &commandBuffer) const
Submits a single command buffer with shared ownership and inserts a fence to wait for it.
Definition rendering_api.hpp:9896
The interface for a compute pipeline.
Definition rendering_api.hpp:8795
The interface for a descriptor set.
Definition rendering_api.hpp:6064
UInt32 bindToHeap(DescriptorType bindingType, UInt32 descriptor, const IBuffer &buffer, UInt32 bufferElement=0, UInt32 elements=0, Format texelFormat=Format::None) const
Binds a resource directly to a descriptor heap and returns the index that can be used to access it.
Definition rendering_api.hpp:6101
void update(UInt32 binding, const IBuffer &buffer, UInt32 bufferElement=0, UInt32 elements=0, UInt32 firstDescriptor=0, Format texelFormat=Format::None) const
Updates one or more buffer descriptors within the current descriptor set.
Definition rendering_api.hpp:6154
The interface for a descriptor set layout.
Definition rendering_api.hpp:6290
void free(const IDescriptorSet &descriptorSet) const
Marks a descriptor set as unused, so that it can be handed out again instead of allocating a new one.
Definition rendering_api.hpp:6541
The interface for a frame buffer.
Definition rendering_api.hpp:8903
std::function< SharedPtr< const TImage >(Optional< UInt64 >, Size2d, ResourceUsage, Format, MultiSamplingLevel, const String &)> allocation_callback_type
A function that gets invoked as a callback, if the frame buffer needs to allocate an image.
Definition rendering_api.hpp:8925
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
The interface for a graphics device that.
Definition rendering_api.hpp:11050
The interface for a graphics factory.
Definition rendering_api.hpp:10120
bool tryCreateBuffer(SharedPtr< IBuffer > &buffer, BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const
Tries to create a buffer of type type .
Definition rendering_api.hpp:10289
SharedPtr< IIndexBuffer > createIndexBuffer(const IIndexBufferLayout &layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const
Creates an index buffer, based on the layout .
Definition rendering_api.hpp:10664
SharedPtr< IVertexBuffer > createVertexBuffer(const IVertexBufferLayout &layout, ResourceHeap heap, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const
Creates a vertex buffer, based on the layout .
Definition rendering_api.hpp:10598
SharedPtr< IBuffer > createBuffer(BufferType type, ResourceHeap heap, size_t elementSize, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const
Creates a buffer of type type .
Definition rendering_api.hpp:10274
bool tryCreateTexture(SharedPtr< IImage > &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
Tries to create a texture.
Definition rendering_api.hpp:10750
SharedPtr< IImage > 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
Creates a texture.
Definition rendering_api.hpp:10733
Generator< SharedPtr< ISampler > > 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
Creates a series of texture samplers.
Definition rendering_api.hpp:10864
SharedPtr< ISampler > 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
Creates a texture sampler.
Definition rendering_api.hpp:10825
bool tryCreateVertexBuffer(SharedPtr< IVertexBuffer > &buffer, const IVertexBufferLayout &layout, ResourceHeap heap, UInt32 elements=1, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const
Tries to create a vertex buffer, based on the layout .
Definition rendering_api.hpp:10612
Generator< SharedPtr< IImage > > 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
Creates a series of textures.
Definition rendering_api.hpp:10806
bool tryCreateIndexBuffer(SharedPtr< IIndexBuffer > &buffer, const IIndexBufferLayout &layout, ResourceHeap heap, UInt32 elements, ResourceUsage usage=ResourceUsage::Default, AllocationBehavior allocationBehavior=AllocationBehavior::Default) const
Tries to create an index buffer, based on the layout .
Definition rendering_api.hpp:10678
Describes a generic image.
Definition rendering_api.hpp:5019
The interface for an index buffer.
Definition rendering_api.hpp:5236
Describes a index buffer layout.
Definition rendering_api.hpp:4603
The interface for an input assembler state.
Definition rendering_api.hpp:7596
The interface for a pipeline.
Definition rendering_api.hpp:7646
The interface for a pipeline layout.
Definition rendering_api.hpp:7538
The interface for a push constants layout.
Definition rendering_api.hpp:6609
Describes a range within a IPushConstantsLayout.
Definition rendering_api.hpp:6561
The interface for a ray tracing pipeline.
Definition rendering_api.hpp:8810
The interface to access a render backend.
Definition rendering_api.hpp:11305
The interface for a render pass.
Definition rendering_api.hpp:9292
The interface for a render pipeline.
Definition rendering_api.hpp:8725
Describes a texture sampler.
Definition rendering_api.hpp:5135
Represents a single shader module, i.e. a part of a IShaderProgram.
Definition rendering_api.hpp:3363
The interface for a shader program.
Definition rendering_api.hpp:7437
Interface for a swap chain.
Definition rendering_api.hpp:9484
A structure that stores the instance data for a IBottomLevelAccelerationStructure.
Definition rendering_api.hpp:5681
The interface for a vertex buffer.
Definition rendering_api.hpp:5214
Describes a vertex buffer layout.
Definition rendering_api.hpp:4574
Describes an index buffer.
Definition rendering.hpp:501
IndexBuffer() noexcept=default
TIndexBufferLayout index_buffer_layout_type
Definition rendering.hpp:503
Represents a the input assembler state of a RenderPipeline.
Definition rendering.hpp:528
TIndexBufferLayout index_buffer_layout_type
Definition rendering.hpp:531
InputAssembler() noexcept=default
TVertexBufferLayout vertex_buffer_layout_type
Definition rendering.hpp:530
Represents a pipeline state.
Definition rendering.hpp:569
Pipeline() noexcept=default
TShaderProgram shader_program_type
Definition rendering.hpp:571
TPipelineLayout pipeline_layout_type
Definition rendering.hpp:572
Represents a the layout of a RenderPipeline, ComputePipeline or RayTracingPipeline.
Definition rendering.hpp:440
PipelineLayout() noexcept=default
TPushConstantsLayout push_constants_layout_type
Definition rendering.hpp:443
const push_constants_layout_type * pushConstants() const noexcept override=0
Returns the push constants layout, or nullptr, if the pipeline does not use any push constants....
virtual const Array< SharedPtr< const descriptor_set_layout_type > > & descriptorSets() const =0
const descriptor_set_layout_type & descriptorSet(UInt32 space) const override=0
Returns the descriptor set layout for the descriptor set that is bound to the space provided by space...
TDescriptorSetLayout descriptor_set_layout_type
Definition rendering.hpp:442
Describes the layout of the pipelines push constant ranges.
Definition rendering.hpp:377
virtual const Array< UniquePtr< push_constants_range_type > > & ranges() const =0
TPushConstantsRange push_constants_range_type
Definition rendering.hpp:379
Represents a ray-tracing Pipeline.
Definition rendering.hpp:1042
descriptor_set_layout_type::descriptor_layout_type descriptor_layout_type
Definition rendering.hpp:1047
base_type::pipeline_layout_type::descriptor_set_layout_type descriptor_set_layout_type
Definition rendering.hpp:1045
descriptor_set_type::image_type image_type
Definition rendering.hpp:1049
descriptor_set_type::sampler_type sampler_type
Definition rendering.hpp:1050
descriptor_set_layout_type::descriptor_set_type descriptor_set_type
Definition rendering.hpp:1046
descriptor_set_type::buffer_type buffer_type
Definition rendering.hpp:1048
Defines a back-end, that provides a device instance for a certain surface and graphics adapter.
Definition rendering.hpp:1796
device_type::render_pipeline_type render_pipeline_type
Definition rendering.hpp:1815
factory_type::sampler_type sampler_type
Definition rendering.hpp:1811
const device_type * operator[](const String &name) const noexcept override
Looks up a device and returns a pointer to it, or nullptr, if no device with the provided name could...
Definition rendering.hpp:1868
device_type::surface_type surface_type
Definition rendering.hpp:1799
factory_type::index_buffer_type index_buffer_type
Definition rendering.hpp:1808
device_type::barrier_type barrier_type
Definition rendering.hpp:1805
const device_type * device(const String &name) const noexcept override=0
Looks up a device and returns a pointer to it, or nullptr, if no device with the provided name could...
TGraphicsDevice device_type
Definition rendering.hpp:1798
device_type::input_assembler_type input_assembler_type
Definition rendering.hpp:1819
device_type::command_queue_type command_queue_type
Definition rendering.hpp:1802
device_type::factory_type factory_type
Definition rendering.hpp:1804
device_type * device(const String &name) noexcept override=0
Looks up a device and returns a pointer to it, or nullptr, if no device with the provided name could...
factory_type::buffer_type buffer_type
Definition rendering.hpp:1809
device_type::compute_pipeline_type compute_pipeline_type
Definition rendering.hpp:1816
device_type::frame_buffer_type frame_buffer_type
Definition rendering.hpp:1812
virtual void releaseDevice(const String &name)=0
Destroys and removes a device from the backend.
factory_type::image_type image_type
Definition rendering.hpp:1810
device_type * operator[](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 rendering.hpp:1873
device_type::render_pass_type render_pass_type
Definition rendering.hpp:1813
device_type::pipeline_layout_type pipeline_layout_type
Definition rendering.hpp:1814
device_type::swap_chain_type swap_chain_type
Definition rendering.hpp:1801
device_type::rasterizer_type rasterizer_type
Definition rendering.hpp:1820
RenderBackend() noexcept=default
device_type::shader_program_type shader_program_type
Definition rendering.hpp:1818
device_type::adapter_type adapter_type
Definition rendering.hpp:1800
factory_type::vertex_buffer_type vertex_buffer_type
Definition rendering.hpp:1807
factory_type::descriptor_layout_type descriptor_layout_type
Definition rendering.hpp:1806
device_type::command_buffer_type command_buffer_type
Definition rendering.hpp:1803
device_type::ray_tracing_pipeline_type ray_tracing_pipeline_type
Definition rendering.hpp:1817
Represents a render pass.
Definition rendering.hpp:1173
TCommandQueue command_queue_type
Definition rendering.hpp:1175
TCommandQueue::command_buffer_type command_buffer_type
Definition rendering.hpp:1176
RenderPass() noexcept=default
TFrameBuffer frame_buffer_type
Definition rendering.hpp:1177
Represents a graphics Pipeline.
Definition rendering.hpp:984
TInputAssembler input_assembler_type
Definition rendering.hpp:986
RenderPipeline() noexcept=default
TRasterizer rasterizer_type
Definition rendering.hpp:987
Represents a shader program, consisting of multiple IShaderModules.
Definition rendering.hpp:408
ShaderProgram() noexcept=default
TShaderModule shader_module_type
Definition rendering.hpp:410
virtual const Array< UniquePtr< const shader_module_type > > & modules() const noexcept=0
Stores a set of IShaderRecords in that later form a shader binding table used for ray-tracing.
Definition rendering_api.hpp:6923
Base class for a resource that can be identified by a name string within a DeviceState.
Definition rendering_api.hpp:2650
Represents a swap chain, i.e. a chain of multiple IImage instances, that can be presented to a ISurfa...
Definition rendering.hpp:1233
SwapChain() noexcept=default
TImageInterface image_interface_type
Definition rendering.hpp:1235
Describes a vertex buffer.
Definition rendering.hpp:477
const vertex_buffer_layout_type & layout() const noexcept override=0
Gets the layout of the vertex buffer.The layout of the vertex buffer.
VertexBuffer() noexcept=default
TVertexBufferLayout vertex_buffer_layout_type
Definition rendering.hpp:479
Checks if a type TDerived is derived from another type TBase and is non-abstract.
Definition traits.hpp:118
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
BorderMode
Describes how to treat texture coordinates that are outside the domain [0..1].
Definition rendering_api.hpp:1356
@ Repeat
Repeat the texture.
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
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.
BufferType
Describes the type of a IBuffer.
Definition rendering_api.hpp:601
ResourceUsage
Describes the intended usage for a resource.
Definition rendering_api.hpp:761
@ Default
Shortcut for commonly used TransferSource | TransferDestination combination.
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.
DescriptorType
Describes the type of a IDescriptor.
Definition rendering_api.hpp:442
QueuePriority
Specifies the priority with which a queue is scheduled on the GPU.
Definition rendering_api.hpp:160
@ Normal
The default queue priority.
QueueType
Represents the type of a CommandQueue.
Definition rendering_api.hpp:114
ResourceHeap
Defines where a resource (buffer or image) memory is located and from where it can be accessed.
Definition rendering_api.hpp:710
AccelerationStructureFlags
Controls how an acceleration structure should be built.
Definition rendering_api.hpp:1988
FilterMode
Describes the filter operation when accessing a pixel from a texture coordinate.
Definition rendering_api.hpp:1324
@ Nearest
Take the nearest texel with respect to the texture coordinate.
AllocationBehavior
Controls the allocation behavior of IGraphicsFactory.
Definition rendering_api.hpp:830
PipelineStage
Defines pipeline stages as points where synchronization may occur.
Definition rendering_api.hpp:1545
ResourceAccess
Defines how a IBuffer or IImage resource is accessed.
Definition rendering_api.hpp:1709
Format
Describes a texel format.
Definition rendering_api.hpp:183
MultiSamplingLevel
Describes the number of samples with which a IImage is sampled.
Definition rendering_api.hpp:1283
@ x1
The default number of samples. Multi-sampling will be deactivated, if this sampling level is used.
Definition app.hpp:6
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
std::span< T > Span
Represents a view of an array.
Definition containers.hpp:87
An input range over another range, where the returned values of type T are covariants of the values ...
Definition containers.hpp:529
Describes a resource binding to a descriptor or descriptor set.
Definition rendering_api.hpp:6218
Describes the offsets and sizes of a shader group within a shader binding table buffer.
Definition rendering_api.hpp:4291
Represents an allocation within the memory managed by the virtual allocator.
Definition rendering_api.hpp:3037