Foundation
Loading...
Searching...
No Matches
Command.hpp
Go to the documentation of this file.
1#pragma once
2#include "Common.hpp"
3#include "Resource.hpp"
4#include <RHICore/Command.hpp>
6namespace Foundation::RHI {
7 class VulkanDevice;
8 class VulkanCommandList;
10 protected:
13 vk::raii::CommandPool mCommandPool{ nullptr };
15 public:
17
18 auto const& GetDevice() const { return mDevice; }
19 auto const& GetVkCommandPool() const { return mCommandPool; }
20
22 RHICommandList* GetCommandList(Handle handle) const override;
23 void DestroyCommandList(Handle handle) override;
24
25 void ResetAllCommandLists(bool freeResources) override;
26
27 void DebugSetObjectName(const char* name) override;
28 };
29 constexpr size_t kCommandBarrierReserveSize = 256;
31 protected:
33 vk::raii::CommandBuffer mCommandBuffer{ nullptr };
34
36 // Stack allocator for temporary allocations during command list execution
37 // Only valid within Begin(), End() clause
39 constexpr static size_t kArenaSize = 2LL * (1LL << 20); // 2 MB
40
50 // !! XXX: Resources allocated with m_allocator must be destroyed before
51 // the allocator goes down.
52 // VTable can in-fact get corrupted otherwise - we need a better solution
53 // to safeguard this type of issue.
55 public:
57
58 [[nodiscard]] auto const& GetVkCommandBuffer() const { return mCommandBuffer; }
59
60 RHICommandList& Begin() override;
61
63 RHICommandList& SetBufferTransition(RHIBuffer* image, TransitionDesc const& desc) override;
64 RHICommandList& SetImageTransition(RHITexture* image, TransitionDesc const& desc) override;
65 RHICommandList& EndTransition() override;
66
67 RHICommandList& SetPipeline(PipelineDesc const& desc) override;
70 RHIPipelineState* pipeline,
72 size_t first) override;
73 RHICommandList& SetViewport(float x, float y, float width, float height, float depth_min = 0.0, float depth_max = 1.0) override;
74 RHICommandList& SetScissor(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override;
79 RHICommandList& DrawMeshTasksIndirect(RHIBuffer* cmd_buffer, size_t cmd_offset, size_t draw_count, size_t stride) override;
80
82 RHICommandList& FillBuffer(RHIBuffer* buffer, uint32_t value, size_t offset = 0, size_t size = kFullSize) override;
86
87 RHICommandList& BeginGraphics(GraphicsDesc const& desc) override;
89 RHICommandList& BindIndexBuffer(RHIBuffer* buffer, size_t offset, RHIResourceFormat format) override;
90 RHICommandList& EndGraphics() override;
91
93
94 RHICommandList& DebugBegin(const char* message) override;
95 RHICommandList& DebugInsertMarker(const char* message) override;
96 RHICommandList& DebugEnd() override;
97
98 void End() override;
99 void Reset() override;
100
101 void DebugSetObjectName(const char* name) override;
102 };
103}
General Purpose Allocator (GPA) interface.
Definition Allocator.hpp:24
Implements an atomic stack-based bump allocator.
Definition StackAllocator.hpp:9
Definition Resource.hpp:30
Definition Command.hpp:34
Definition Command.hpp:13
Definition PipelineState.hpp:7
Definition Resource.hpp:146
Definition Command.hpp:30
auto const & GetVkCommandBuffer() const
Definition Command.hpp:58
RHICommandList & Dispatch(uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z) override
Definition Command.cpp:432
RHICommandList & DrawMeshTasksIndirect(RHIBuffer *cmd_buffer, size_t cmd_offset, size_t draw_count, size_t stride) override
Definition Command.cpp:189
void End() override
Definition Command.cpp:440
RHICommandList & DrawMeshTasks(uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z) override
Definition Command.cpp:181
RHICommandList & DebugBegin(const char *message) override
Definition Command.cpp:452
RHICommandList & CopyBufferToImage(RHIBuffer *src_buffer, RHITexture *dst_image, RHITextureLayout dst_layout, Core::Span< const CopyImageRegion > regions) override
Definition Command.cpp:283
UniquePtr< Barriers > mBarriers
Definition Command.hpp:54
RHICommandList & EndTransition() override
Definition Command.cpp:115
RHICommandList & Begin() override
Definition Command.cpp:61
StackAllocator mAllocator
Definition Command.hpp:38
RHICommandList & DebugInsertMarker(const char *message) override
Definition Command.cpp:460
void DebugSetObjectName(const char *name) override
Definition Command.cpp:474
RHICommandList & DebugEnd() override
Definition Command.cpp:468
RHICommandList & Draw(uint32_t vertex_count, uint32_t instance_count=1, uint32_t first_vertex=0, uint32_t first_instance=0) override
Definition Command.cpp:155
RHICommandList & BindIndexBuffer(RHIBuffer *buffer, size_t offset, RHIResourceFormat format) override
Definition Command.cpp:384
RHICommandList & SetViewport(float x, float y, float width, float height, float depth_min=0.0, float depth_max=1.0) override
Definition Command.cpp:141
RHICommandList & BeginGraphics(GraphicsDesc const &desc) override
Definition Command.cpp:319
RHICommandList & SetImageTransition(RHITexture *image, TransitionDesc const &desc) override
Definition Command.cpp:91
RHICommandList & EndGraphics() override
Definition Command.cpp:426
RHICommandList & SetBufferTransition(RHIBuffer *image, TransitionDesc const &desc) override
Definition Command.cpp:75
RHICommandList & SetPipeline(PipelineDesc const &desc) override
Definition Command.cpp:131
RHICommandList & PushConstant(RHIPipelineState *pipeline, RHIShaderStage stage, uint32_t offset, Core::Span< const char > data) override
Definition Command.cpp:201
static constexpr size_t kArenaSize
Definition Command.hpp:39
RHICommandList & DrawIndexed(uint32_t index_count, uint32_t instance_count=1, uint32_t first_index=0, int32_t vertex_offset=0, uint32_t first_instance=0) override
Definition Command.cpp:161
const VulkanCommandPool & mCommandPool
Definition Command.hpp:32
RHICommandList & FillBuffer(RHIBuffer *buffer, uint32_t value, size_t offset=0, size_t size=kFullSize) override
Definition Command.cpp:210
RHICommandList & SetScissor(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override
Definition Command.cpp:148
ScopedArena mArena
Definition Command.hpp:35
RHICommandList & CopyImage(RHITexture *src_image, RHITextureLayout src_layout, RHITexture *dst_image, RHITextureLayout dst_layout, Core::Span< const CopyImageRegion > regions) override
Definition Command.cpp:244
vk::raii::CommandBuffer mCommandBuffer
Definition Command.hpp:33
void Reset() override
Definition Command.cpp:446
RHICommandList & BindVertexBuffer(uint32_t index, Core::Span< RHIBuffer *const > buffers, Core::Span< const size_t > offsets) override
Definition Command.cpp:369
RHICommandList & DrawIndexedIndirectCount(RHIBuffer *buffer, size_t offset, RHIBuffer *count_buffer, size_t count_offset, uint32_t max_draw_count, uint32_t stride) override
Definition Command.cpp:167
RHICommandList & BindDescriptorSet(RHIDevicePipelineType bindpoint, RHIPipelineState *pipeline, Span< RHIDeviceDescriptorSet *const > sets, size_t first) override
Definition Command.cpp:403
RHICommandList & CopyBuffer(RHIBuffer *src_buffer, RHIBuffer *dst_buffer, Core::Span< const CopyBufferRegion > regions) override
Definition Command.cpp:218
RHICommandList & BeginTransition() override
Definition Command.cpp:69
Definition Command.hpp:9
vk::raii::CommandPool mCommandPool
Definition Command.hpp:13
auto const & GetDevice() const
Definition Command.hpp:18
void DestroyCommandList(Handle handle) override
Definition Command.cpp:43
Allocator * mAllocator
Definition Command.hpp:11
auto const & GetVkCommandPool() const
Definition Command.hpp:19
void ResetAllCommandLists(bool freeResources) override
Definition Command.cpp:46
const VulkanDevice & mDevice
Definition Command.hpp:12
RHICommandPoolScopedHandle< RHICommandList > CreateCommandList() override
Definition Command.cpp:37
RHICommandList * GetCommandList(Handle handle) const override
Definition Command.cpp:40
void DebugSetObjectName(const char *name) override
Definition Command.cpp:28
RHIObjectPool mStorage
Definition Command.hpp:14
Definition Device.hpp:80
std::unique_ptr< T, StlDeleter< T > > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:161
Low-level Rendering Hardware Interface (RHI) abstractions.
Definition Application.hpp:5
RHIDevicePipelineType
Definition Common.hpp:84
RHITextureLayout
Definition Common.hpp:99
uint64_t Handle
Definition Details.hpp:9
constexpr size_t kCommandBarrierReserveSize
Definition Command.hpp:29
RHIResourceFormat
Definition Common.hpp:20
static constexpr size_t kFullSize
Definition Common.hpp:8
RAII wrapper for an arena allocated from an Allocator.
Definition Allocator.hpp:43
Vector< vk::ImageMemoryBarrier2 > image
Definition Command.hpp:42
Barriers(Allocator *allocator)
Definition Command.hpp:44
Vector< vk::BufferMemoryBarrier2 > buffer
Definition Command.hpp:43