LiteFX 0.3.1.2022
Computer Graphics Engine
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
16 template <typename TBuffer, typename TImage> requires
17 std::derived_from<TBuffer, IBuffer> &&
18 std::derived_from<TImage, IImage>
19 class Barrier : public IBarrier {
20 public:
21 using buffer_type = TBuffer;
22 using image_type = TImage;
23
24 public:
25 virtual ~Barrier() noexcept = default;
26
27 public:
29 virtual void transition(buffer_type& buffer, const ResourceState& targetState) = 0;
30
32 virtual void transition(buffer_type& buffer, const UInt32& element, const ResourceState& targetState) = 0;
33
35 virtual void transition(buffer_type& buffer, const ResourceState& sourceState, const ResourceState& targetState) = 0;
36
38 virtual void transition(buffer_type& buffer, const ResourceState& sourceState, const UInt32& element, const ResourceState& targetState) = 0;
39
41 virtual void transition(image_type& image, const ResourceState& targetState) = 0;
42
44 virtual void transition(image_type& image, const UInt32& level, const UInt32& layer, const UInt32& plane, const ResourceState& targetState) = 0;
45
47 virtual void transition(image_type& image, const ResourceState& sourceState, const ResourceState& targetState) = 0;
48
50 virtual void transition(image_type& image, const ResourceState& sourceState, const UInt32& level, const UInt32& layer, const UInt32& plane, const ResourceState& targetState) = 0;
51
53 virtual void waitFor(const buffer_type& buffer) = 0;
54
56 virtual void waitFor(const image_type& image) = 0;
57
58 private:
59 virtual void doTransition(IBuffer& buffer, const ResourceState& targetState) override {
60 this->transition(dynamic_cast<buffer_type&>(buffer), targetState);
61 }
62
63 virtual void doTransition(IBuffer& buffer, const UInt32& element, const ResourceState& targetState) override {
64 this->transition(dynamic_cast<buffer_type&>(buffer), element, targetState);
65 }
66
67 virtual void doTransition(IBuffer& buffer, const ResourceState& sourceState, const ResourceState& targetState) override {
68 this->transition(dynamic_cast<buffer_type&>(buffer), sourceState, targetState);
69 }
70
71 virtual void doTransition(IBuffer& buffer, const ResourceState& sourceState, const UInt32& element, const ResourceState& targetState) override {
72 this->transition(dynamic_cast<buffer_type&>(buffer), sourceState, element, targetState);
73 }
74
75 virtual void doTransition(IImage& image, const ResourceState& targetState) override {
76 this->transition(dynamic_cast<image_type&>(image), targetState);
77 }
78
79 virtual void doTransition(IImage& image, const UInt32& level, const UInt32& layer, const UInt32& plane, const ResourceState& targetState) override {
80 this->transition(dynamic_cast<image_type&>(image), level, layer, plane, targetState);
81 }
82
83 virtual void doTransition(IImage& image, const ResourceState& sourceState, const ResourceState& targetState) override {
84 this->transition(dynamic_cast<image_type&>(image), sourceState, targetState);
85 }
86
87 virtual void doTransition(IImage& image, const ResourceState& sourceState, const UInt32& level, const UInt32& layer, const UInt32& plane, const ResourceState& targetState) override {
88 this->transition(dynamic_cast<image_type&>(image), sourceState, level, layer, plane, targetState);
89 }
90
91 virtual void doWaitFor(const IBuffer& buffer) override {
92 this->waitFor(dynamic_cast<const buffer_type&>(buffer));
93 }
94
95 virtual void doWaitFor(const IImage& image) override {
96 this->waitFor(dynamic_cast<const image_type&>(image));
97 }
98 };
99
165 template <typename TBuffer, typename TImage, typename TSampler> requires
166 std::derived_from<TBuffer, IBuffer> &&
167 std::derived_from<TSampler, ISampler> &&
168 std::derived_from<TImage, IImage>
170 public:
171 using buffer_type = TBuffer;
172 using sampler_type = TSampler;
173 using image_type = TImage;
174
175 public:
176 virtual ~DescriptorSet() noexcept = default;
177
178 public:
180 virtual void update(const UInt32& binding, const buffer_type& buffer, const UInt32& bufferElement = 0, const UInt32& elements = 1, const UInt32& firstDescriptor = 0) const = 0;
181
183 virtual void update(const UInt32& binding, const image_type& texture, const UInt32& descriptor = 0, const UInt32& firstLevel = 0, const UInt32& levels = 0, const UInt32& firstLayer = 0, const UInt32& layers = 0) const = 0;
184
186 virtual void update(const UInt32& binding, const sampler_type& sampler, const UInt32& descriptor = 0) const = 0;
187
189 virtual void attach(const UInt32& binding, const image_type& image) const = 0;
190
191 private:
192 virtual void doUpdate(const UInt32& binding, const IBuffer& buffer, const UInt32& bufferElement, const UInt32& elements, const UInt32& firstDescriptor) const override {
193 this->update(binding, dynamic_cast<const buffer_type&>(buffer), bufferElement, elements, firstDescriptor);
194 }
195
196 virtual void doUpdate(const UInt32& binding, const IImage& texture, const UInt32& descriptor, const UInt32& firstLevel, const UInt32& levels, const UInt32& firstLayer, const UInt32& layers) const override {
197 this->update(binding, dynamic_cast<const image_type&>(texture), descriptor, firstLevel, levels, firstLayer, layers);
198 }
199
200 virtual void doUpdate(const UInt32& binding, const ISampler& sampler, const UInt32& descriptor) const override {
201 this->update(binding, dynamic_cast<const sampler_type&>(sampler), descriptor);
202 }
203
204 virtual void doAttach(const UInt32& binding, const IImage& image) const override {
205 this->attach(binding, dynamic_cast<const image_type&>(image));
206 }
207 };
208
221 template <typename TDescriptorLayout, typename TDescriptorSet> requires
222 rtti::implements<TDescriptorLayout, IDescriptorLayout> &&
223 rtti::implements<TDescriptorSet, DescriptorSet<typename TDescriptorSet::buffer_type, typename TDescriptorSet::image_type, typename TDescriptorSet::sampler_type>>
225 public:
226 using descriptor_layout_type = TDescriptorLayout;
227 using descriptor_set_type = TDescriptorSet;
228
229 public:
230 virtual ~DescriptorSetLayout() noexcept = default;
231
232 public:
234 virtual Array<const descriptor_layout_type*> descriptors() const noexcept = 0;
235
237 virtual const descriptor_layout_type& descriptor(const UInt32& binding) const = 0;
238
241
243 virtual Array<UniquePtr<descriptor_set_type>> allocateMultiple(const UInt32& descriptorSets, const UInt32& descriptors = 0) const = 0;
244
246 virtual void free(const descriptor_set_type& descriptorSet) const noexcept = 0;
247
248 private:
249 virtual Array<const IDescriptorLayout*> getDescriptors() const noexcept override {
250 auto descriptors = this->descriptors();
252 }
253
254 virtual UniquePtr<IDescriptorSet> getDescriptorSet(const UInt32& descriptors) const override {
255 return this->allocate(descriptors);
256 }
257
258 virtual Array<UniquePtr<IDescriptorSet>> getDescriptorSets(const UInt32& descriptorSets, const UInt32& descriptors) const override {
259 auto sets = this->allocateMultiple(descriptorSets, descriptors);
261 results.reserve(sets.size());
262 std::move(sets.begin(), sets.end(), std::inserter(results, results.end()));
263 return results;
264 }
265
266 virtual void releaseDescriptorSet(const IDescriptorSet& descriptorSet) const noexcept override {
267 this->releaseDescriptorSet(dynamic_cast<const descriptor_set_type&>(descriptorSet));
268 }
269 };
270
294 template <typename TPushConstantsRange> requires
295 rtti::implements<TPushConstantsRange, IPushConstantsRange>
297 public:
298 using push_constants_range_type = TPushConstantsRange;
299
300 public:
301 virtual ~PushConstantsLayout() noexcept = default;
302
303 public:
305 virtual Array<const push_constants_range_type*> ranges() const noexcept = 0;
306
307 private:
308 virtual Array<const IPushConstantsRange*> getRanges() const noexcept override {
309 auto ranges = this->ranges();
310 return Array<const IPushConstantsRange*>(ranges.begin(), ranges.end());
311 }
312 };
313
319 template <typename TShaderModule> requires
322 public:
323 using shader_module_type = TShaderModule;
324
325 public:
326 virtual ~ShaderProgram() noexcept = default;
327
328 public:
330 virtual Array<const shader_module_type*> modules() const noexcept = 0;
331
332 private:
333 virtual Array<const IShaderModule*> getModules() const noexcept {
334 auto modules = this->modules();
335 return Array<const IShaderModule*>(modules.begin(), modules.end());
336 }
337 };
338
344 template <typename TDescriptorSetLayout, typename TPushConstantsLayout> requires
348 public:
349 using descriptor_set_layout_type = TDescriptorSetLayout;
350 using push_constants_layout_type = TPushConstantsLayout;
351
352 public:
353 virtual ~PipelineLayout() noexcept = default;
354
355 public:
357 virtual const descriptor_set_layout_type& descriptorSet(const UInt32& space) const = 0;
358
360 virtual Array<const descriptor_set_layout_type*> descriptorSets() const noexcept = 0;
361
363 virtual const push_constants_layout_type* pushConstants() const noexcept = 0;
364
365 private:
366 virtual Array<const IDescriptorSetLayout*> getDescriptorSets() const noexcept override {
367 auto layouts = this->descriptorSets();
368 return Array<const IDescriptorSetLayout*>(layouts.begin(), layouts.end());
369 }
370 };
371
376 template <typename TVertexBufferLayout> requires
378 class VertexBuffer : public virtual IVertexBuffer {
379 public:
380 using vertex_buffer_layout_type = TVertexBufferLayout;
381
382 public:
383 virtual ~VertexBuffer() noexcept = default;
384
385 public:
387 virtual const vertex_buffer_layout_type& layout() const noexcept = 0;
388 };
389
394 template <typename TIndexBufferLayout> requires
395 rtti::implements<TIndexBufferLayout, IIndexBufferLayout>
396 class IndexBuffer : public virtual IIndexBuffer {
397 public:
398 using index_buffer_layout_type = TIndexBufferLayout;
399
400 public:
401 virtual ~IndexBuffer() noexcept = default;
402
403 public:
405 virtual const index_buffer_layout_type& layout() const noexcept = 0;
406 };
407
413 template <typename TVertexBufferLayout, typename TIndexBufferLayout> requires
414 rtti::implements<TVertexBufferLayout, IVertexBufferLayout> &&
415 rtti::implements<TIndexBufferLayout, IIndexBufferLayout>
417 public:
418 using vertex_buffer_layout_type = TVertexBufferLayout;
419 using index_buffer_layout_type = TIndexBufferLayout;
420
421 public:
422 virtual ~InputAssembler() noexcept = default;
423
424 public:
426 virtual Array<const vertex_buffer_layout_type*> vertexBufferLayouts() const noexcept = 0;
427
429 virtual const vertex_buffer_layout_type& vertexBufferLayout(const UInt32& binding) const = 0;
430
432 virtual const index_buffer_layout_type& indexBufferLayout() const = 0;
433
434 private:
435 virtual Array<const IVertexBufferLayout*> getVertexBufferLayouts() const noexcept override {
436 auto layouts = this->vertexBufferLayouts();
437 return Array<const IVertexBufferLayout*>(layouts.begin(), layouts.end());
438 }
439 };
440
448 template <typename TPipelineLayout, typename TShaderProgram> requires
451 class Pipeline : public virtual IPipeline, public virtual StateResource {
452 public:
453 using shader_program_type = TShaderProgram;
454 using pipeline_layout_type = TPipelineLayout;
455
456 public:
457 virtual ~Pipeline() noexcept = default;
458
459 public:
461 virtual SharedPtr<const shader_program_type> program() const noexcept = 0;
462
464 virtual SharedPtr<const pipeline_layout_type> layout() const noexcept = 0;
465
466 private:
467 virtual SharedPtr<const IShaderProgram> getProgram() const noexcept override {
468 return std::static_pointer_cast<const IShaderProgram>(this->program());
469 }
470
471 virtual SharedPtr<const IPipelineLayout> getLayout() const noexcept override {
472 return std::static_pointer_cast<const IPipelineLayout>(this->layout());
473 }
474 };
475
485 template <typename TBuffer, typename TVertexBuffer, typename TIndexBuffer, typename TImage, typename TBarrier, typename TPipeline> requires
486 rtti::implements<TBarrier, Barrier<TBuffer, TImage>> &&
487 std::derived_from<TPipeline, Pipeline<typename TPipeline::pipeline_layout_type, typename TPipeline::shader_program_type>>
494
495 public:
496 using buffer_type = TBuffer;
497 using vertex_buffer_type = TVertexBuffer;
498 using index_buffer_type = TIndexBuffer;
499 using image_type = TImage;
500 using barrier_type = TBarrier;
501 using pipeline_type = TPipeline;
502 using pipeline_layout_type = pipeline_type::pipeline_layout_type;
503 using descriptor_set_layout_type = pipeline_layout_type::descriptor_set_layout_type;
504 using push_constants_layout_type = pipeline_layout_type::push_constants_layout_type;
505 using descriptor_set_type = descriptor_set_layout_type::descriptor_set_type;
506
507 public:
508 virtual ~CommandBuffer() noexcept = default;
509
510 public:
512 virtual void barrier(const barrier_type& barrier, const bool& invert = false) const noexcept = 0;
513
515 virtual void generateMipMaps(image_type& image) noexcept = 0;
516
518 virtual void transfer(const buffer_type& source, const buffer_type& target, const UInt32& sourceElement = 0, const UInt32& targetElement = 0, const UInt32& elements = 1) const = 0;
519
521 virtual void transfer(const buffer_type& source, const image_type& target, const UInt32& sourceElement = 0, const UInt32& firstSubresource = 0, const UInt32& elements = 1) const = 0;
522
524 virtual void transfer(const image_type& source, const image_type& target, const UInt32& sourceSubresource = 0, const UInt32& targetSubresource = 0, const UInt32& subresources = 1) const = 0;
525
527 virtual void transfer(const image_type& source, const buffer_type& target, const UInt32& firstSubresource = 0, const UInt32& targetElement = 0, const UInt32& subresources = 1) const = 0;
528
530 virtual void use(const pipeline_type& pipeline) const noexcept = 0;
531
533 virtual void bind(const descriptor_set_type& descriptorSet, const pipeline_type& pipeline) const noexcept = 0;
534
536 virtual void bind(const vertex_buffer_type& buffer) const noexcept = 0;
537
539 virtual void bind(const index_buffer_type& buffer) const noexcept = 0;
540
542 virtual void pushConstants(const push_constants_layout_type& layout, const void* const memory) const noexcept = 0;
543
545 virtual void draw(const vertex_buffer_type& vertexBuffer, const UInt32& instances = 1, const UInt32& firstVertex = 0, const UInt32& firstInstance = 0) const {
546 this->bind(vertexBuffer);
547 this->draw(vertexBuffer.elements(), instances, firstVertex, firstInstance);
548 }
549
551 virtual void drawIndexed(const index_buffer_type& indexBuffer, const UInt32& instances = 1, const UInt32& firstIndex = 0, const Int32& vertexOffset = 0, const UInt32& firstInstance = 0) const {
552 this->bind(indexBuffer);
553 this->drawIndexed(indexBuffer.elements(), instances, firstIndex, vertexOffset, firstInstance);
554 }
555
557 virtual void drawIndexed(const vertex_buffer_type& vertexBuffer, const index_buffer_type& indexBuffer, const UInt32& instances = 1, const UInt32& firstIndex = 0, const Int32& vertexOffset = 0, const UInt32& firstInstance = 0) const {
558 this->bind(vertexBuffer);
559 this->bind(indexBuffer);
560 this->drawIndexed(indexBuffer.elements(), instances, firstIndex, vertexOffset, firstInstance);
561 }
562
563 private:
564 virtual void cmdBarrier(const IBarrier& barrier, const bool& invert) const noexcept override {
565 this->barrier(dynamic_cast<const barrier_type&>(barrier), invert);
566 }
567
568 virtual void cmdGenerateMipMaps(IImage& image) noexcept override {
569 this->generateMipMaps(dynamic_cast<image_type&>(image));
570 }
571
572 virtual void cmdTransfer(const IBuffer& source, const IBuffer& target, const UInt32& sourceElement, const UInt32& targetElement, const UInt32& elements) const override {
573 this->transfer(dynamic_cast<const buffer_type&>(source), dynamic_cast<const buffer_type&>(target), sourceElement, targetElement, elements);
574 }
575
576 virtual void cmdTransfer(const IBuffer& source, const IImage& target, const UInt32& sourceElement, const UInt32& firstSubresource, const UInt32& elements) const override {
577 this->transfer(dynamic_cast<const buffer_type&>(source), dynamic_cast<const image_type&>(target), sourceElement, firstSubresource, elements);
578 }
579
580 virtual void cmdTransfer(const IImage& source, const IImage& target, const UInt32& sourceSubresource, const UInt32& targetSubresource, const UInt32& subresources) const override {
581 this->transfer(dynamic_cast<const image_type&>(source), dynamic_cast<const image_type&>(target), sourceSubresource, targetSubresource, subresources);
582 }
583
584 virtual void cmdTransfer(const IImage& source, const IBuffer& target, const UInt32& firstSubresource, const UInt32& targetElement, const UInt32& subresources) const override {
585 this->transfer(dynamic_cast<const image_type&>(source), dynamic_cast<const buffer_type&>(target), firstSubresource, targetElement, subresources);
586 }
587
588 virtual void cmdUse(const IPipeline& pipeline) const noexcept override {
589 this->use(dynamic_cast<const pipeline_type&>(pipeline));
590 }
591
592 virtual void cmdBind(const IDescriptorSet& descriptorSet, const IPipeline& pipeline) const noexcept override {
593 this->bind(dynamic_cast<const descriptor_set_type&>(descriptorSet), dynamic_cast<const pipeline_type&>(pipeline));
594 }
595
596 virtual void cmdBind(const IVertexBuffer& buffer) const noexcept override {
597 this->bind(dynamic_cast<const vertex_buffer_type&>(buffer));
598 }
599
600 virtual void cmdBind(const IIndexBuffer& buffer) const noexcept override {
601 this->bind(dynamic_cast<const index_buffer_type&>(buffer));
602 }
603
604 virtual void cmdPushConstants(const IPushConstantsLayout& layout, const void* const memory) const noexcept override {
605 this->pushConstants(dynamic_cast<const push_constants_layout_type&>(layout), memory);
606 }
607
608 virtual void cmdDraw(const IVertexBuffer& vertexBuffer, const UInt32& instances, const UInt32& firstVertex, const UInt32& firstInstance) const override {
609 this->draw(dynamic_cast<const vertex_buffer_type&>(vertexBuffer), instances, firstVertex, firstInstance);
610 }
611
612 virtual void cmdDrawIndexed(const IIndexBuffer& indexBuffer, const UInt32& instances, const UInt32& firstIndex, const Int32& vertexOffset, const UInt32& firstInstance) const override {
613 this->drawIndexed(dynamic_cast<const index_buffer_type&>(indexBuffer), instances, firstIndex, vertexOffset, firstInstance);
614 }
615
616 virtual void cmdDrawIndexed(const IVertexBuffer& vertexBuffer, const IIndexBuffer& indexBuffer, const UInt32& instances, const UInt32& firstIndex, const Int32& vertexOffset, const UInt32& firstInstance) const override {
617 this->drawIndexed(dynamic_cast<const vertex_buffer_type&>(vertexBuffer), dynamic_cast<const index_buffer_type&>(indexBuffer), instances, firstIndex, vertexOffset, firstInstance);
618 }
619 };
620
629 template <typename TPipelineLayout, typename TShaderProgram, typename TInputAssembler, typename TRasterizer> requires
630 rtti::implements<TInputAssembler, InputAssembler<typename TInputAssembler::vertex_buffer_layout_type, typename TInputAssembler::index_buffer_layout_type>> &&
631 rtti::implements<TRasterizer, Rasterizer>
632 class RenderPipeline : public IRenderPipeline, public Pipeline<TPipelineLayout, TShaderProgram> {
633 public:
634 using input_assembler_type = TInputAssembler;
635 using rasterizer_type = TRasterizer;
636
637 public:
638 virtual ~RenderPipeline() noexcept = default;
639
640 public:
642 virtual SharedPtr<input_assembler_type> inputAssembler() const noexcept = 0;
643
645 virtual SharedPtr<rasterizer_type> rasterizer() const noexcept = 0;
646
647 private:
648 virtual SharedPtr<IInputAssembler> getInputAssembler() const noexcept override {
649 return this->inputAssembler();
650 }
651
652 virtual SharedPtr<IRasterizer> getRasterizer() const noexcept override {
653 return this->rasterizer();
654 }
655 };
656
663 template <typename TPipelineLayout, typename TShaderProgram>
664 class ComputePipeline : public IComputePipeline, public Pipeline<TPipelineLayout, TShaderProgram> {
665 public:
666 virtual ~ComputePipeline() noexcept = default;
667 };
668
674 template <typename TCommandBuffer> requires
675 rtti::implements<TCommandBuffer, CommandBuffer<typename TCommandBuffer::buffer_type, typename TCommandBuffer::vertex_buffer_type, typename TCommandBuffer::index_buffer_type, typename TCommandBuffer::image_type, typename TCommandBuffer::barrier_type, typename TCommandBuffer::pipeline_type>>
676 class FrameBuffer : public IFrameBuffer {
677 public:
678 using command_buffer_type = TCommandBuffer;
679 using image_type = command_buffer_type::image_type;
680
681 public:
682 virtual ~FrameBuffer() noexcept = default;
683
684 public:
686 virtual Array<const command_buffer_type*> commandBuffers() const noexcept = 0;
687
689 virtual const command_buffer_type& commandBuffer(const UInt32& index) const = 0;
690
692 virtual Array<const image_type*> images() const noexcept = 0;
693
695 virtual const image_type& image(const UInt32& location) const = 0;
696
697 private:
698 virtual Array<const ICommandBuffer*> getCommandBuffers() const noexcept override {
699 auto commandBuffers = this->commandBuffers();
700 return Array<const ICommandBuffer*>(commandBuffers.begin(), commandBuffers.end());
701 }
702
703 virtual Array<const IImage*> getImages() const noexcept override {
704 auto images = this->images();
705 return Array<const IImage*>(images.begin(), images.end());
706 }
707 };
708
717 template <typename TFrameBuffer> requires
718 rtti::implements<TFrameBuffer, FrameBuffer<typename TFrameBuffer::command_buffer_type>>
720 public:
721 using frame_buffer_type = TFrameBuffer;
722
723 public:
724 virtual ~IInputAttachmentMappingSource() noexcept = default;
725
726 public:
733 virtual const frame_buffer_type& frameBuffer(const UInt32& buffer) const = 0;
734 };
735
740 template <typename TInputAttachmentMappingSource> requires
741 rtti::implements<TInputAttachmentMappingSource, IInputAttachmentMappingSource<typename TInputAttachmentMappingSource::frame_buffer_type>>
743 public:
744 using input_attachment_mapping_source_type = TInputAttachmentMappingSource;
745
746 public:
747 virtual ~IInputAttachmentMapping() noexcept = default;
748
749 public:
754 virtual const input_attachment_mapping_source_type* inputAttachmentSource() const noexcept = 0;
755
760 virtual const RenderTarget& renderTarget() const noexcept = 0;
761
770 virtual const UInt32& location() const noexcept = 0;
771 };
772
783 template <typename TRenderPipeline, typename TFrameBuffer, typename TInputAttachmentMapping> requires
784 rtti::implements<TFrameBuffer, FrameBuffer<typename TFrameBuffer::command_buffer_type>> &&
785 rtti::implements<TRenderPipeline, RenderPipeline<typename TRenderPipeline::pipeline_layout_type, typename TRenderPipeline::shader_program_type, typename TRenderPipeline::input_assembler_type, typename TRenderPipeline::rasterizer_type>> /*&&
786 rtti::implements<TInputAttachmentMapping, IInputAttachmentMapping<TDerived>>*/
787 class RenderPass : public virtual StateResource, public IRenderPass, public IInputAttachmentMappingSource<TFrameBuffer> {
788 public:
789 using frame_buffer_type = TFrameBuffer;
790 using render_pipeline_type = TRenderPipeline;
791 using input_attachment_mapping_type = TInputAttachmentMapping;
792 using pipeline_layout_type = render_pipeline_type::pipeline_layout_type;
793 using descriptor_set_layout_type = pipeline_layout_type::descriptor_set_layout_type;
794 using descriptor_set_type = descriptor_set_layout_type::descriptor_set_type;
795
796 public:
797 virtual ~RenderPass() noexcept = default;
798
799 public:
801 virtual const frame_buffer_type& activeFrameBuffer() const = 0;
802
804 virtual Array<const frame_buffer_type*> frameBuffers() const noexcept = 0;
805
807 virtual Array<const render_pipeline_type*> pipelines() const noexcept = 0;
808
810 virtual Span<const input_attachment_mapping_type> inputAttachments() const noexcept = 0;
811
813 virtual void updateAttachments(const descriptor_set_type& descriptorSet) const = 0;
814
815 private:
816 virtual Array<const IFrameBuffer*> getFrameBuffers() const noexcept override {
817 auto frameBuffers = this->frameBuffers();
818 return Array<const IFrameBuffer*>(frameBuffers.begin(), frameBuffers.end());
819 }
820
821 virtual Array<const IRenderPipeline*> getPipelines() const noexcept override {
822 auto pipelines = this->pipelines();
823 return Array<const IRenderPipeline*>(pipelines.begin(), pipelines.end());
824 }
825
826 virtual void setAttachments(const IDescriptorSet& descriptorSet) const override {
827 this->updateAttachments(dynamic_cast<const descriptor_set_type&>(descriptorSet));
828 }
829 };
830
835 template <typename TImageInterface, typename TFrameBuffer> requires
836 rtti::implements<TFrameBuffer, FrameBuffer<typename TFrameBuffer::command_buffer_type>> &&
837 std::derived_from<TImageInterface, IImage>
838 class SwapChain : public ISwapChain {
839 public:
840 using image_interface_type = TImageInterface;
841 using frame_buffer_type = TFrameBuffer;
842
843 public:
844 virtual ~SwapChain() noexcept = default;
845
846 public:
848 virtual Array<const image_interface_type*> images() const noexcept = 0;
849
854 virtual void present(const frame_buffer_type& frameBuffer) const = 0;
855
857 virtual void present(const IFrameBuffer& frameBuffer) const override {
858 this->present(dynamic_cast<const frame_buffer_type&>(frameBuffer));
859 }
860
861 private:
862 virtual Array<const IImage*> getImages() const noexcept override {
863 auto images = this->images();
864 return Array<const IImage*>(images.begin(), images.end());
865 }
866 };
867
872 template <typename TCommandBuffer> requires
873 rtti::implements<TCommandBuffer, CommandBuffer<typename TCommandBuffer::buffer_type, typename TCommandBuffer::vertex_buffer_type, typename TCommandBuffer::index_buffer_type, typename TCommandBuffer::image_type, typename TCommandBuffer::barrier_type, typename TCommandBuffer::pipeline_type>>
875 public:
876 using command_buffer_type = TCommandBuffer;
877
878 public:
879 virtual ~CommandQueue() noexcept = default;
880
881 public:
883 virtual UniquePtr<command_buffer_type> createCommandBuffer(const bool& beginRecording = false) const = 0;
884
886 virtual UInt64 submit(const command_buffer_type& commandBuffer) const = 0;
887
889 virtual UInt64 submit(const Array<const command_buffer_type*>& commandBuffers) const = 0;
890
891 private:
892 virtual UniquePtr<ICommandBuffer> getCommandBuffer(const bool& beginRecording) const override {
893 return this->createCommandBuffer(beginRecording);
894 }
895
896 virtual UInt64 submitCommandBuffer(const ICommandBuffer& commandBuffer) const override {
897 return this->submit(dynamic_cast<const command_buffer_type&>(commandBuffer));
898 }
899
900 virtual UInt64 submitCommandBuffers(const Array<const ICommandBuffer*>& commandBuffers) const override {
902 buffers.reserve(commandBuffers.size());
903 std::transform(commandBuffers.begin(), commandBuffers.end(), buffers.begin(), [](auto buffer) { return dynamic_cast<const command_buffer_type*>(buffer); });
904 return this->submit(buffers);
905 }
906 };
907
923 template <typename TDescriptorLayout, typename TBuffer, typename TVertexBuffer, typename TIndexBuffer, typename TImage, typename TSampler> requires
924 rtti::implements<TDescriptorLayout, IDescriptorLayout> &&
925 std::derived_from<TVertexBuffer, VertexBuffer<typename TVertexBuffer::vertex_buffer_layout_type>> &&
926 std::derived_from<TIndexBuffer, IndexBuffer<typename TIndexBuffer::index_buffer_layout_type>> &&
927 std::derived_from<TImage, IImage> &&
928 std::derived_from<TBuffer, IBuffer> &&
929 std::derived_from<TSampler, ISampler>
931 public:
932 using descriptor_layout_type = TDescriptorLayout;
933 using vertex_buffer_type = TVertexBuffer;
934 using vertex_buffer_layout_type = vertex_buffer_type::vertex_buffer_layout_type;
935 using index_buffer_type = TIndexBuffer;
936 using index_buffer_layout_type = index_buffer_type::index_buffer_layout_type;
937 using buffer_type = TBuffer;
938 using image_type = TImage;
939 using sampler_type = TSampler;
940
941 public:
942 virtual ~GraphicsFactory() noexcept = default;
943
944 public:
946 virtual UniquePtr<TBuffer> createBuffer(const BufferType& type, const BufferUsage& usage, const size_t& elementSize, const UInt32& elements = 1, const bool& allowWrite = false) const = 0;
947
949 virtual UniquePtr<TBuffer> createBuffer(const String& name, const BufferType& type, const BufferUsage& usage, const size_t& elementSize, const UInt32& elements = 1, const bool& allowWrite = false) const = 0;
950
952 virtual UniquePtr<TVertexBuffer> createVertexBuffer(const vertex_buffer_layout_type& layout, const BufferUsage& usage, const UInt32& elements = 1) const = 0;
953
955 virtual UniquePtr<TVertexBuffer> createVertexBuffer(const String& name, const vertex_buffer_layout_type& layout, const BufferUsage& usage, const UInt32& elements = 1) const = 0;
956
958 virtual UniquePtr<TIndexBuffer> createIndexBuffer(const index_buffer_layout_type& layout, const BufferUsage& usage, const UInt32& elements) const = 0;
959
961 virtual UniquePtr<TIndexBuffer> createIndexBuffer(const String& name, const index_buffer_layout_type& layout, const BufferUsage& usage, const UInt32& elements) const = 0;
962
964 virtual UniquePtr<TImage> createAttachment(const Format& format, const Size2d& size, const MultiSamplingLevel& samples = MultiSamplingLevel::x1) const = 0;
965
967 virtual UniquePtr<TImage> createAttachment(const String& name, const Format& format, const Size2d& size, const MultiSamplingLevel& samples = MultiSamplingLevel::x1) const = 0;
968
970 virtual UniquePtr<TImage> createTexture(const Format& format, const Size3d& size, const ImageDimensions& dimension = ImageDimensions::DIM_2, const UInt32& levels = 1, const UInt32& layers = 1, const MultiSamplingLevel& samples = MultiSamplingLevel::x1, const bool& allowWrite = false) const = 0;
971
973 virtual UniquePtr<TImage> createTexture(const String& name, const Format& format, const Size3d& size, const ImageDimensions& dimension = ImageDimensions::DIM_2, const UInt32& levels = 1, const UInt32& layers = 1, const MultiSamplingLevel& samples = MultiSamplingLevel::x1, const bool& allowWrite = false) const = 0;
974
976 virtual Array<UniquePtr<TImage>> createTextures(const UInt32& elements, const Format& format, const Size3d& size, const ImageDimensions& dimension = ImageDimensions::DIM_2, const UInt32 & layers = 1, const UInt32& levels = 1, const MultiSamplingLevel& samples = MultiSamplingLevel::x1, const bool& allowWrite = false) const = 0;
977
979 virtual UniquePtr<TSampler> createSampler(const FilterMode& magFilter = FilterMode::Nearest, const FilterMode& minFilter = FilterMode::Nearest, const BorderMode& borderU = BorderMode::Repeat, const BorderMode& borderV = BorderMode::Repeat, const BorderMode& borderW = BorderMode::Repeat, const MipMapMode& mipMapMode = MipMapMode::Nearest, const Float& mipMapBias = 0.f, const Float& maxLod = std::numeric_limits<Float>::max(), const Float& minLod = 0.f, const Float& anisotropy = 0.f) const = 0;
980
982 virtual UniquePtr<TSampler> createSampler(const String& name, const FilterMode& magFilter = FilterMode::Nearest, const FilterMode& minFilter = FilterMode::Nearest, const BorderMode& borderU = BorderMode::Repeat, const BorderMode& borderV = BorderMode::Repeat, const BorderMode& borderW = BorderMode::Repeat, const MipMapMode& mipMapMode = MipMapMode::Nearest, const Float& mipMapBias = 0.f, const Float& maxLod = std::numeric_limits<Float>::max(), const Float& minLod = 0.f, const Float& anisotropy = 0.f) const = 0;
983
985 virtual Array<UniquePtr<TSampler>> createSamplers(const UInt32& elements, const FilterMode& magFilter = FilterMode::Nearest, const FilterMode& minFilter = FilterMode::Nearest, const BorderMode& borderU = BorderMode::Repeat, const BorderMode& borderV = BorderMode::Repeat, const BorderMode& borderW = BorderMode::Repeat, const MipMapMode& mipMapMode = MipMapMode::Nearest, const Float& mipMapBias = 0.f, const Float& maxLod = std::numeric_limits<Float>::max(), const Float& minLod = 0.f, const Float& anisotropy = 0.f) const = 0;
986
987 private:
988 virtual UniquePtr<IBuffer> getBuffer(const BufferType& type, const BufferUsage& usage, const size_t& elementSize, const UInt32& elements, const bool& allowWrite) const override {
989 return this->createBuffer(type, usage, elementSize, elements, allowWrite);
990 }
991
992 virtual UniquePtr<IBuffer> getBuffer(const String& name, const BufferType& type, const BufferUsage& usage, const size_t& elementSize, const UInt32& elements, const bool& allowWrite) const override {
993 return this->createBuffer(name, type, usage, elementSize, elements, allowWrite);
994 }
995
996 virtual UniquePtr<IVertexBuffer> getVertexBuffer(const IVertexBufferLayout& layout, const BufferUsage& usage, const UInt32& elements) const override {
997 return this->createVertexBuffer(dynamic_cast<const vertex_buffer_layout_type&>(layout), usage, elements);
998 }
999
1000 virtual UniquePtr<IVertexBuffer> getVertexBuffer(const String& name, const IVertexBufferLayout& layout, const BufferUsage& usage, const UInt32& elements) const override {
1001 return this->createVertexBuffer(name, dynamic_cast<const vertex_buffer_layout_type&>(layout), usage, elements);
1002 }
1003
1004 virtual UniquePtr<IIndexBuffer> getIndexBuffer(const IIndexBufferLayout& layout, const BufferUsage& usage, const UInt32& elements) const override {
1005 return this->createIndexBuffer(dynamic_cast<const index_buffer_layout_type&>(layout), usage, elements);
1006 }
1007
1008 virtual UniquePtr<IIndexBuffer> getIndexBuffer(const String& name, const IIndexBufferLayout& layout, const BufferUsage& usage, const UInt32& elements) const override {
1009 return this->createIndexBuffer(name, dynamic_cast<const index_buffer_layout_type&>(layout), usage, elements);
1010 }
1011
1012 virtual UniquePtr<IImage> getAttachment(const Format& format, const Size2d& size, const MultiSamplingLevel& samples) const override {
1013 return this->createAttachment(format, size, samples);
1014 }
1015
1016 virtual UniquePtr<IImage> getAttachment(const String& name, const Format& format, const Size2d& size, const MultiSamplingLevel& samples) const override {
1017 return this->createAttachment(name, format, size, samples);
1018 }
1019
1020 virtual UniquePtr<IImage> getTexture(const Format& format, const Size3d& size, const ImageDimensions& dimension, const UInt32& levels, const UInt32& layers, const MultiSamplingLevel& samples, const bool& allowWrite) const override {
1021 return this->createTexture(format, size, dimension, levels, layers, samples, allowWrite);
1022 }
1023
1024 virtual UniquePtr<IImage> getTexture(const String& name, const Format& format, const Size3d& size, const ImageDimensions& dimension, const UInt32& levels, const UInt32& layers, const MultiSamplingLevel& samples, const bool& allowWrite) const override {
1025 return this->createTexture(name, format, size, dimension, levels, layers, samples, allowWrite);
1026 }
1027
1028 virtual Array<UniquePtr<IImage>> getTextures(const UInt32& elements, const Format& format, const Size3d& size, const ImageDimensions& dimension, const UInt32& layers, const UInt32& levels, const MultiSamplingLevel& samples, const bool& allowWrite) const override {
1029 auto textures = this->getTextures(elements, format, size, dimension, layers, levels, samples, allowWrite);
1030 Array<UniquePtr<IImage>> results;
1031 results.reserve(textures.size());
1032 std::move(std::begin(textures), std::end(textures), std::inserter(results, std::end(results)));
1033 return results;
1034 }
1035
1036 virtual UniquePtr<ISampler> getSampler(const FilterMode& magFilter, const FilterMode& minFilter, const BorderMode& borderU, const BorderMode& borderV, const BorderMode& borderW, const MipMapMode& mipMapMode, const Float& mipMapBias, const Float& maxLod, const Float& minLod, const Float& anisotropy) const override {
1037 return this->createSampler(magFilter, minFilter, borderU, borderV, borderW, mipMapMode, mipMapBias, maxLod, minLod, anisotropy);
1038 }
1039
1040 virtual UniquePtr<ISampler> getSampler(const String& name, const FilterMode& magFilter, const FilterMode& minFilter, const BorderMode& borderU, const BorderMode& borderV, const BorderMode& borderW, const MipMapMode& mipMapMode, const Float& mipMapBias, const Float& maxLod, const Float& minLod, const Float& anisotropy) const override {
1041 return this->createSampler(name, magFilter, minFilter, borderU, borderV, borderW, mipMapMode, mipMapBias, maxLod, minLod, anisotropy);
1042 }
1043
1044 virtual Array<UniquePtr<ISampler>> getSamplers(const UInt32& elements, const FilterMode& magFilter, const FilterMode& minFilter, const BorderMode& borderU, const BorderMode& borderV, const BorderMode& borderW, const MipMapMode& mipMapMode, const Float& mipMapBias, const Float& maxLod, const Float& minLod, const Float& anisotropy) const override {
1045 auto samplers = this->createSamplers(elements, magFilter, minFilter, borderU, borderV, borderW, mipMapMode, mipMapBias, maxLod, minLod, anisotropy);
1047 results.reserve(samplers.size());
1048 std::move(std::begin(samplers), std::end(samplers), std::inserter(results, std::end(results)));
1049 return results;
1050 }
1051 };
1052
1069 template <typename TFactory, typename TSurface, typename TGraphicsAdapter, typename TSwapChain, typename TCommandQueue, typename TRenderPass, typename TComputePipeline, typename TBarrier> requires
1070 rtti::implements<TSurface, ISurface> &&
1071 rtti::implements<TGraphicsAdapter, IGraphicsAdapter> &&
1072 rtti::implements<TSwapChain, SwapChain<typename TFactory::image_type, typename TRenderPass::frame_buffer_type>> &&
1073 rtti::implements<TCommandQueue, CommandQueue<typename TCommandQueue::command_buffer_type>> &&
1074 rtti::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>> &&
1075 rtti::implements<TRenderPass, RenderPass<typename TRenderPass::render_pipeline_type, typename TRenderPass::frame_buffer_type, typename TRenderPass::input_attachment_mapping_type>> &&
1076 rtti::implements<TComputePipeline, ComputePipeline<typename TComputePipeline::pipeline_layout_type, typename TComputePipeline::shader_program_type>> &&
1077 rtti::implements<TBarrier, Barrier<typename TFactory::buffer_type, typename TFactory::image_type>>
1079 public:
1080 using surface_type = TSurface;
1081 using adapter_type = TGraphicsAdapter;
1082 using swap_chain_type = TSwapChain;
1083 using command_queue_type = TCommandQueue;
1084 using command_buffer_type = command_queue_type::command_buffer_type;
1085 using factory_type = TFactory;
1086 using barrier_type = TBarrier;
1087 using descriptor_layout_type = factory_type::descriptor_layout_type;
1088 using vertex_buffer_type = factory_type::vertex_buffer_type;
1089 using index_buffer_type = factory_type::index_buffer_type;
1090 using buffer_type = factory_type::buffer_type;
1091 using image_type = factory_type::image_type;
1092 using sampler_type = factory_type::sampler_type;
1093 using render_pass_type = TRenderPass;
1094 using frame_buffer_type = render_pass_type::frame_buffer_type;
1095 using render_pipeline_type = render_pass_type::render_pipeline_type;
1096 using compute_pipeline_type = TComputePipeline;
1097 using pipeline_layout_type = render_pipeline_type::pipeline_layout_type;
1098 using shader_program_type = render_pipeline_type::shader_program_type;
1099 using input_assembler_type = render_pipeline_type::input_assembler_type;
1100 using rasterizer_type = render_pipeline_type::rasterizer_type;
1101 using shader_program_type = render_pipeline_type::shader_program_type;
1102
1103 public:
1104 virtual ~GraphicsDevice() noexcept = default;
1105
1106 public:
1108 virtual const surface_type& surface() const noexcept = 0;
1109
1111 virtual const adapter_type& adapter() const noexcept = 0;
1112
1114 virtual const swap_chain_type& swapChain() const noexcept = 0;
1115
1117 virtual swap_chain_type& swapChain() noexcept = 0;
1118
1120 virtual const factory_type& factory() const noexcept = 0;
1121
1123 virtual const command_queue_type& graphicsQueue() const noexcept = 0;
1124
1126 virtual const command_queue_type& transferQueue() const noexcept = 0;
1127
1129 virtual const command_queue_type& bufferQueue() const noexcept = 0;
1130
1132 virtual const command_queue_type& computeQueue() const noexcept = 0;
1133
1135 virtual UniquePtr<barrier_type> makeBarrier() const noexcept = 0;
1136
1137 private:
1138 virtual UniquePtr<IBarrier> getNewBarrier() const noexcept override {
1139 return this->makeBarrier();
1140 }
1141
1142#if defined(BUILD_DEFINE_BUILDERS)
1143 public:
1144 using render_pass_builder_type = render_pass_type::builder_type;
1145 using render_pipeline_builder_type = render_pipeline_type::builder_type;
1146 using compute_pipeline_builder_type = compute_pipeline_type::builder_type;
1147 using pipeline_layout_builder_type = pipeline_layout_type::builder_type;
1148 using input_assembler_builder_type = input_assembler_type::builder_type;
1149 using rasterizer_builder_type = rasterizer_type::builder_type;
1150 using shader_program_builder_type = shader_program_type::builder_type;
1151
1158 [[nodiscard]] virtual render_pass_builder_type buildRenderPass(const MultiSamplingLevel& samples = MultiSamplingLevel::x1, const UInt32& commandBuffers = 1) const = 0;
1159
1167 [[nodiscard]] virtual render_pass_builder_type buildRenderPass(const String& name, const MultiSamplingLevel& samples = MultiSamplingLevel::x1, const UInt32& commandBuffers = 1) const = 0;
1168
1174 [[nodiscard]] virtual compute_pipeline_builder_type buildComputePipeline(const String& name) const = 0;
1175
1181 //[[nodiscard]] virtual render_pipeline_builder_type buildRenderPipeline(const String& name) const = 0;
1182
1189 [[nodiscard]] virtual render_pipeline_builder_type buildRenderPipeline(const render_pass_type& renderPass, const String& name) const = 0;
1190
1195 [[nodiscard]] virtual pipeline_layout_builder_type buildPipelineLayout() const = 0;
1196
1201 [[nodiscard]] virtual input_assembler_builder_type buildInputAssembler() const = 0;
1202
1207 [[nodiscard]] virtual rasterizer_builder_type buildRasterizer() const = 0;
1208
1213 [[nodiscard]] virtual shader_program_builder_type buildShaderProgram() const = 0;
1214#endif // defined(BUILD_DEFINE_BUILDERS)
1215 };
1216
1222 template <typename TBackend, typename TGraphicsDevice> requires
1225 public:
1226 using device_type = TGraphicsDevice;
1227 using surface_type = device_type::surface_type;
1228 using adapter_type = device_type::adapter_type;
1229 using swap_chain_type = device_type::swap_chain_type;
1230 using command_queue_type = device_type::command_queue_type;
1231 using command_buffer_type = device_type::command_buffer_type;
1232 using factory_type = device_type::factory_type;
1233 using barrier_type = device_type::barrier_type;
1234 using descriptor_layout_type = factory_type::descriptor_layout_type;
1235 using vertex_buffer_type = factory_type::vertex_buffer_type;
1236 using index_buffer_type = factory_type::index_buffer_type;
1237 using buffer_type = factory_type::buffer_type;
1238 using image_type = factory_type::image_type;
1239 using sampler_type = factory_type::sampler_type;
1240 using frame_buffer_type = device_type::frame_buffer_type;
1241 using render_pass_type = device_type::render_pass_type;
1242 using pipeline_layout_type = device_type::pipeline_layout_type;
1243 using render_pipeline_type = device_type::render_pipeline_type;
1244 using compute_pipeline_type = device_type::compute_pipeline_type;
1245 using shader_program_type = device_type::shader_program_type;
1246 using input_assembler_type = device_type::input_assembler_type;
1247 using rasterizer_type = device_type::rasterizer_type;
1248
1249 public:
1250 virtual ~RenderBackend() noexcept = default;
1251
1252 public:
1254 virtual Array<const adapter_type*> listAdapters() const = 0;
1255
1257 virtual const adapter_type* findAdapter(const Optional<UInt64>& adapterId = std::nullopt) const = 0;
1258
1260 virtual void registerDevice(String name, UniquePtr<device_type>&& device) = 0;
1261
1267 template <typename ...TArgs>
1268 device_type* createDevice(String name, const adapter_type& adapter, UniquePtr<surface_type>&& surface, TArgs&&... _args) {
1269 auto device = makeUnique<device_type>(static_cast<const TBackend&>(*this), adapter, std::move(surface), std::forward<TArgs>(_args)...);
1270 auto devicePointer = device.get();
1271 this->registerDevice(name, std::move(device));
1272 return devicePointer;
1273 }
1274
1279 virtual void releaseDevice(const String& name) = 0;
1280
1282 virtual device_type* device(const String& name) noexcept = 0;
1283
1285 virtual const device_type* device(const String& name) const noexcept = 0;
1286
1288 virtual const device_type* operator[](const String& name) const noexcept {
1289 return this->device(name);
1290 };
1291
1293 virtual device_type* operator[](const String& name) noexcept {
1294 return this->device(name);
1295 };
1296
1297 // IRenderBackend interface
1298 private:
1299 virtual Array<const IGraphicsAdapter*> getAdapters() const override {
1300 auto adapters = this->listAdapters();
1301 return Array<const IGraphicsAdapter*>(adapters.begin(), adapters.end());
1302 }
1303 };
1304}
Definition: math.hpp:571
Definition: math.hpp:540
A barrier that transitions a set of resources backed by IDeviceMemory into different ResourceState.
Definition: rendering.hpp:19
virtual void waitFor(const buffer_type &buffer)=0
TImage image_type
Definition: rendering.hpp:22
virtual ~Barrier() noexcept=default
virtual void transition(buffer_type &buffer, const ResourceState &targetState)=0
TBuffer buffer_type
Definition: rendering.hpp:21
Represents a command buffer, that buffers commands that should be submitted to a CommandQueue.
Definition: rendering.hpp:488
virtual void drawIndexed(const vertex_buffer_type &vertexBuffer, const index_buffer_type &indexBuffer, const UInt32 &instances=1, const UInt32 &firstIndex=0, const Int32 &vertexOffset=0, const UInt32 &firstInstance=0) const
Definition: rendering.hpp:557
TBuffer buffer_type
Definition: rendering.hpp:496
virtual ~CommandBuffer() noexcept=default
pipeline_type::pipeline_layout_type pipeline_layout_type
Definition: rendering.hpp:502
TIndexBuffer index_buffer_type
Definition: rendering.hpp:498
virtual void drawIndexed(const index_buffer_type &indexBuffer, const UInt32 &instances=1, const UInt32 &firstIndex=0, const Int32 &vertexOffset=0, const UInt32 &firstInstance=0) const
Definition: rendering.hpp:551
descriptor_set_layout_type::descriptor_set_type descriptor_set_type
Definition: rendering.hpp:505
TVertexBuffer vertex_buffer_type
Definition: rendering.hpp:497
TImage image_type
Definition: rendering.hpp:499
TPipeline pipeline_type
Definition: rendering.hpp:501
pipeline_layout_type::push_constants_layout_type push_constants_layout_type
Definition: rendering.hpp:504
TBarrier barrier_type
Definition: rendering.hpp:500
pipeline_layout_type::descriptor_set_layout_type descriptor_set_layout_type
Definition: rendering.hpp:503
Represents a command queue.
Definition: rendering.hpp:874
TCommandBuffer command_buffer_type
Definition: rendering.hpp:876
virtual ~CommandQueue() noexcept=default
Represents a compute Pipeline.
Definition: rendering.hpp:664
virtual ~ComputePipeline() noexcept=default
Defines a set of descriptors.
Definition: rendering.hpp:169
virtual void update(const UInt32 &binding, const buffer_type &buffer, const UInt32 &bufferElement=0, const UInt32 &elements=1, const UInt32 &firstDescriptor=0) const =0
TBuffer buffer_type
Definition: rendering.hpp:171
virtual ~DescriptorSet() noexcept=default
TSampler sampler_type
Definition: rendering.hpp:172
virtual void attach(const UInt32 &binding, const image_type &image) const =0
TImage image_type
Definition: rendering.hpp:173
Describes the layout of a descriptor set.
Definition: rendering.hpp:224
virtual Array< const descriptor_layout_type * > descriptors() const noexcept=0
virtual Array< UniquePtr< descriptor_set_type > > allocateMultiple(const UInt32 &descriptorSets, const UInt32 &descriptors=0) const =0
virtual ~DescriptorSetLayout() noexcept=default
virtual const descriptor_layout_type & descriptor(const UInt32 &binding) const =0
Returns the descriptor layout for the descriptor bound to the binding point provided with binding .
TDescriptorSet descriptor_set_type
Definition: rendering.hpp:227
TDescriptorLayout descriptor_layout_type
Definition: rendering.hpp:226
virtual void free(const descriptor_set_type &descriptorSet) const noexcept=0
virtual UniquePtr< descriptor_set_type > allocate(const UInt32 &descriptors=0) const =0
Stores the images for the output attachments for a back buffer of a RenderPass, as well as a CommandB...
Definition: rendering.hpp:676
TCommandBuffer command_buffer_type
Definition: rendering.hpp:678
command_buffer_type::image_type image_type
Definition: rendering.hpp:679
virtual ~FrameBuffer() noexcept=default
Represents the graphics device that a rendering back-end is doing work on.
Definition: rendering.hpp:1078
render_pass_type::render_pipeline_type render_pipeline_type
Definition: rendering.hpp:1095
render_pipeline_type::pipeline_layout_type pipeline_layout_type
Definition: rendering.hpp:1097
render_pipeline_type::rasterizer_type rasterizer_type
Definition: rendering.hpp:1100
TComputePipeline compute_pipeline_type
Definition: rendering.hpp:1096
command_queue_type::command_buffer_type command_buffer_type
Definition: rendering.hpp:1084
TFactory factory_type
Definition: rendering.hpp:1085
TSwapChain swap_chain_type
Definition: rendering.hpp:1082
factory_type::buffer_type buffer_type
Definition: rendering.hpp:1090
factory_type::image_type image_type
Definition: rendering.hpp:1091
TCommandQueue command_queue_type
Definition: rendering.hpp:1083
factory_type::index_buffer_type index_buffer_type
Definition: rendering.hpp:1089
factory_type::sampler_type sampler_type
Definition: rendering.hpp:1092
factory_type::descriptor_layout_type descriptor_layout_type
Definition: rendering.hpp:1087
render_pipeline_type::input_assembler_type input_assembler_type
Definition: rendering.hpp:1099
factory_type::vertex_buffer_type vertex_buffer_type
Definition: rendering.hpp:1088
TSurface surface_type
Definition: rendering.hpp:1080
render_pass_type::frame_buffer_type frame_buffer_type
Definition: rendering.hpp:1094
TRenderPass render_pass_type
Definition: rendering.hpp:1093
render_pipeline_type::shader_program_type shader_program_type
Definition: rendering.hpp:1098
TBarrier barrier_type
Definition: rendering.hpp:1086
virtual ~GraphicsDevice() noexcept=default
TGraphicsAdapter adapter_type
Definition: rendering.hpp:1081
Describes a factory that creates objects for a GraphicsDevice.
Definition: rendering.hpp:930
TBuffer buffer_type
Definition: rendering.hpp:937
TIndexBuffer index_buffer_type
Definition: rendering.hpp:935
vertex_buffer_type::vertex_buffer_layout_type vertex_buffer_layout_type
Definition: rendering.hpp:934
TDescriptorLayout descriptor_layout_type
Definition: rendering.hpp:932
TVertexBuffer vertex_buffer_type
Definition: rendering.hpp:933
TImage image_type
Definition: rendering.hpp:938
TSampler sampler_type
Definition: rendering.hpp:939
index_buffer_type::index_buffer_layout_type index_buffer_layout_type
Definition: rendering.hpp:936
virtual ~GraphicsFactory() noexcept=default
The interface for a memory barrier.
Definition: rendering_api.hpp:2944
Base interface for buffer objects.
Definition: rendering_api.hpp:2774
virtual const BufferType & type() const noexcept=0
Returns the type of the buffer.
The interface for a command buffer.
Definition: rendering_api.hpp:3541
virtual void drawIndexed(const UInt32 &indices, const UInt32 &instances=1, const UInt32 &firstIndex=0, const Int32 &vertexOffset=0, const 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 end() const =0
Ends recording commands on the command buffer.
virtual void dispatch(const Vector3u &threadCount) const noexcept=0
Executes a compute shader.
virtual void draw(const UInt32 &vertices, const UInt32 &instances=1, const UInt32 &firstVertex=0, const UInt32 &firstInstance=0) const noexcept=0
Draws a number of vertices from the currently bound vertex buffer.
virtual void begin() const =0
Sets the command buffer into recording state, so that it can receive command that should be submitted...
The interface for a command queue.
Definition: rendering_api.hpp:4215
The interface for a compute pipeline.
Definition: rendering_api.hpp:3916
Describes a the layout of a single descriptor within a DescriptorSet.
Definition: rendering_api.hpp:2613
The interface for a descriptor set.
Definition: rendering_api.hpp:3072
The interface for a descriptor set layout.
Definition: rendering_api.hpp:3143
virtual size_t elementSize() const noexcept=0
Returns the size of a single element within the buffer. If there is only one element,...
virtual size_t size() const noexcept=0
Gets the size (in bytes) of the aligned memory chunk.
virtual const UInt32 & elements() const noexcept=0
Gets the number of sub-resources inside the memory chunk.
The interface for a frame buffer.
Definition: rendering_api.hpp:3924
The interface for a graphics device that.
Definition: rendering_api.hpp:4582
The interface for a graphics factory.
Definition: rendering_api.hpp:4324
Describes a generic image.
Definition: rendering_api.hpp:2789
The interface for an index buffer.
Definition: rendering_api.hpp:3458
Describes a index buffer layout.
Definition: rendering_api.hpp:2579
The interface for an input assembler state.
Definition: rendering_api.hpp:3473
Represents a mapping between a set of IRenderTarget instances and the input attachments of a RenderPa...
Definition: rendering.hpp:742
virtual ~IInputAttachmentMapping() noexcept=default
TInputAttachmentMappingSource input_attachment_mapping_source_type
Definition: rendering.hpp:744
Represents the source for an input attachment mapping.
Definition: rendering.hpp:719
virtual ~IInputAttachmentMappingSource() noexcept=default
TFrameBuffer frame_buffer_type
Definition: rendering.hpp:721
The interface for a pipeline.
Definition: rendering_api.hpp:3512
The interface for a pipeline layout.
Definition: rendering_api.hpp:3410
The interface for a push constants layout.
Definition: rendering_api.hpp:3323
Describes a range within a IPushConstantsLayout.
Definition: rendering_api.hpp:3282
The interface to access a render backend.
Definition: rendering_api.hpp:4692
The interface for a render pass.
Definition: rendering_api.hpp:4019
The interface for a render pipeline.
Definition: rendering_api.hpp:3840
Describes a texture sampler.
Definition: rendering_api.hpp:2872
Represents a single shader module, i.e. a part of a IShaderProgram.
Definition: rendering_api.hpp:1827
The interface for a shader program.
Definition: rendering_api.hpp:3361
virtual const String & name() const noexcept=0
Returns the name of the resource.
Interface for a swap chain.
Definition: rendering_api.hpp:4140
The interface for a vertex buffer.
Definition: rendering_api.hpp:3443
Describes a vertex buffer layout.
Definition: rendering_api.hpp:2563
Describes an index buffer.
Definition: rendering.hpp:396
TIndexBufferLayout index_buffer_layout_type
Definition: rendering.hpp:398
virtual ~IndexBuffer() noexcept=default
Represents a the input assembler state of a RenderPipeline.
Definition: rendering.hpp:416
TIndexBufferLayout index_buffer_layout_type
Definition: rendering.hpp:419
virtual ~InputAssembler() noexcept=default
TVertexBufferLayout vertex_buffer_layout_type
Definition: rendering.hpp:418
Represents a pipeline state.
Definition: rendering.hpp:451
virtual ~Pipeline() noexcept=default
TShaderProgram shader_program_type
Definition: rendering.hpp:453
TPipelineLayout pipeline_layout_type
Definition: rendering.hpp:454
Represents a the layout of a RenderPipeline or a ComputePipeline.
Definition: rendering.hpp:347
virtual const descriptor_set_layout_type & descriptorSet(const UInt32 &space) const =0
Returns the descriptor set layout for the descriptor set that is bound to the space provided by space...
virtual const push_constants_layout_type * pushConstants() const noexcept=0
Returns the push constants layout, or nullptr, if the pipeline does not use any push constants.
virtual ~PipelineLayout() noexcept=default
TPushConstantsLayout push_constants_layout_type
Definition: rendering.hpp:350
TDescriptorSetLayout descriptor_set_layout_type
Definition: rendering.hpp:349
virtual Array< const descriptor_set_layout_type * > descriptorSets() const noexcept=0
Describes the layout of the pipelines push constant ranges.
Definition: rendering.hpp:296
virtual ~PushConstantsLayout() noexcept=default
virtual Array< const push_constants_range_type * > ranges() const noexcept=0
TPushConstantsRange push_constants_range_type
Definition: rendering.hpp:298
Defines a back-end, that provides a device instance for a certain surface and graphics adapter.
Definition: rendering.hpp:1224
TGraphicsDevice device_type
Definition: rendering.hpp:1226
device_type::rasterizer_type rasterizer_type
Definition: rendering.hpp:1247
device_type::frame_buffer_type frame_buffer_type
Definition: rendering.hpp:1240
factory_type::vertex_buffer_type vertex_buffer_type
Definition: rendering.hpp:1235
virtual device_type * device(const String &name) noexcept=0
Looks up a device and returns a pointer to it, or nullptr, if no device with the provided name could...
virtual const device_type * operator[](const String &name) const noexcept
Looks up a device and returns a pointer to it, or nullptr, if no device with the provided name could...
Definition: rendering.hpp:1288
device_type::factory_type factory_type
Definition: rendering.hpp:1232
virtual void releaseDevice(const String &name)=0
Destroys and removes a device from the backend.
device_type::compute_pipeline_type compute_pipeline_type
Definition: rendering.hpp:1244
factory_type::descriptor_layout_type descriptor_layout_type
Definition: rendering.hpp:1234
device_type::swap_chain_type swap_chain_type
Definition: rendering.hpp:1229
virtual ~RenderBackend() noexcept=default
device_type::shader_program_type shader_program_type
Definition: rendering.hpp:1245
device_type::surface_type surface_type
Definition: rendering.hpp:1227
virtual const device_type * device(const String &name) const noexcept=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:1237
device_type::pipeline_layout_type pipeline_layout_type
Definition: rendering.hpp:1242
device_type::command_buffer_type command_buffer_type
Definition: rendering.hpp:1231
device_type::command_queue_type command_queue_type
Definition: rendering.hpp:1230
factory_type::sampler_type sampler_type
Definition: rendering.hpp:1239
device_type::render_pipeline_type render_pipeline_type
Definition: rendering.hpp:1243
virtual device_type * operator[](const String &name) noexcept
Looks up a device and returns a pointer to it, or nullptr, if no device with the provided name could...
Definition: rendering.hpp:1293
device_type::adapter_type adapter_type
Definition: rendering.hpp:1228
device_type::barrier_type barrier_type
Definition: rendering.hpp:1233
device_type::input_assembler_type input_assembler_type
Definition: rendering.hpp:1246
device_type::render_pass_type render_pass_type
Definition: rendering.hpp:1241
factory_type::image_type image_type
Definition: rendering.hpp:1238
factory_type::index_buffer_type index_buffer_type
Definition: rendering.hpp:1236
Represents a render pass.
Definition: rendering.hpp:787
render_pipeline_type::pipeline_layout_type pipeline_layout_type
Definition: rendering.hpp:792
virtual ~RenderPass() noexcept=default
TRenderPipeline render_pipeline_type
Definition: rendering.hpp:790
pipeline_layout_type::descriptor_set_layout_type descriptor_set_layout_type
Definition: rendering.hpp:793
TInputAttachmentMapping input_attachment_mapping_type
Definition: rendering.hpp:791
descriptor_set_layout_type::descriptor_set_type descriptor_set_type
Definition: rendering.hpp:794
Represents a graphics Pipeline.
Definition: rendering.hpp:632
TInputAssembler input_assembler_type
Definition: rendering.hpp:634
TRasterizer rasterizer_type
Definition: rendering.hpp:635
virtual ~RenderPipeline() noexcept=default
Implements a render target.
Definition: rendering_api.hpp:1994
Represents a shader program, consisting of multiple IShaderModules.
Definition: rendering.hpp:321
virtual Array< const shader_module_type * > modules() const noexcept=0
TShaderModule shader_module_type
Definition: rendering.hpp:323
virtual ~ShaderProgram() noexcept=default
Base class for a resource that can be identified by a name string within a DeviceState.
Definition: rendering_api.hpp:1453
Represents a swap chain, i.e. a chain of multiple IImage instances, that can be presented to a ISurfa...
Definition: rendering.hpp:838
virtual ~SwapChain() noexcept=default
TFrameBuffer frame_buffer_type
Definition: rendering.hpp:841
TImageInterface image_interface_type
Definition: rendering.hpp:840
Describes a vertex buffer.
Definition: rendering.hpp:378
virtual const vertex_buffer_layout_type & layout() const noexcept=0
Gets the layout of the vertex buffer.
virtual ~VertexBuffer() noexcept=default
TVertexBufferLayout vertex_buffer_layout_type
Definition: rendering.hpp:380
Definition: traits.hpp:95
Definition: math.hpp:30
uint32_t UInt32
Definition: math.hpp:37
float_t Float
Definition: math.hpp:40
uint64_t UInt64
Definition: math.hpp:39
int32_t Int32
Definition: math.hpp:36
Definition: dx12.hpp:8
Definition: app.hpp:6
std::string String
Definition: string.hpp:19
std::vector< T > Array
Represents a dynamic array.
Definition: containers.hpp:58
std::span< T > Span
Represents a view of an array.
Definition: containers.hpp:72
std::shared_ptr< T > SharedPtr
Represents a shared pointer, that expresses non-exclusive ownership.
Definition: containers.hpp:94
std::unique_ptr< T, TDeleter > UniquePtr
Represents a unique pointer, that expresses exclusive ownership.
Definition: containers.hpp:87
std::optional< T > Optional
Represents an optional value.
Definition: containers.hpp:79