Foundation
Loading...
Searching...
No Matches
Command.hpp
Go to the documentation of this file.
1#pragma once
3#include <RHICore/Command.hpp>
4#include "Common.hpp"
5#include "Resource.hpp"
6
7namespace Foundation::RHI
8{
9 class VulkanDevice;
10 class VulkanCommandList;
11
13 {
14 protected:
17 vk::raii::CommandPool mCommandPool{nullptr};
19
20 public:
21 VulkanCommandPool(const VulkanDevice& device, PoolDesc const& desc, Allocator* allocator);
22
23 auto const& GetDevice() const { return mDevice; }
24 auto const& GetVkCommandPool() const { return mCommandPool; }
25
27 RHICommandList* GetCommandList(Handle handle) const override;
28 void DestroyCommandList(Handle handle) override;
29
30 void ResetAllCommandLists(bool freeResources) override;
31
32 void DebugSetObjectName(const char* name) override;
33 };
34
35 constexpr size_t kCommandBarrierReserveSize = 256;
36 constexpr size_t kDefaultCommandScratchSize = 64 * 1024;
37
39 {
40 protected:
42 vk::raii::CommandBuffer mCommandBuffer{nullptr};
46
59
60 // !! XXX: Resources allocated with m_allocator must be destroyed before
61 // the allocator goes down.
62 // VTable can in-fact get corrupted otherwise - we need a better solution
63 // to safeguard this type of issue.
65 bool mInTransition = false;
66
68 public:
69 VulkanCommandList(const VulkanCommandPool& commandPool);
70
71 [[nodiscard]] auto const& GetVkCommandBuffer() const { return mCommandBuffer; }
72
73 RHICommandList& Begin(Allocator* scratchAllocator = nullptr) override;
74
76 RHICommandList& SetBufferTransition(RHIBuffer* image, TransitionDesc const& desc) override;
77 RHICommandList& SetImageTransition(RHITexture* image, TransitionDesc const& desc) override;
79 TransitionDesc const& desc) override;
80 RHICommandList& EndTransition() override;
81
82 RHICommandList& SetPipeline(PipelineDesc const& desc) override;
84 RHIDevicePipelineType bindpoint,
85 RHIPipelineState* pipeline,
87 size_t first,
88 Span<const uint32_t> dynamicOffsets) override;
89 RHICommandList& SetViewport(float x, float y, float width, float height, float depth_min = 0.0,
90 float depth_max = 1.0, bool flipY = false) override;
91 RHICommandList& SetScissor(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override;
92 RHICommandList& Draw(uint32_t vertex_count, uint32_t instance_count = 1, uint32_t first_vertex = 0,
93 uint32_t first_instance = 0) override;
94 RHICommandList& DrawIndexed(uint32_t index_count, uint32_t instance_count = 1, uint32_t first_index = 0,
95 int32_t vertex_offset = 0, uint32_t first_instance = 0) override;
96 RHICommandList& DrawIndexedIndirectCount(RHIBuffer* buffer, size_t offset, RHIBuffer* count_buffer,
97 size_t count_offset, uint32_t max_draw_count,
98 uint32_t stride) override;
99 RHICommandList& DrawMeshTasks(uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z) override;
100 RHICommandList& DrawMeshTasksIndirect(RHIBuffer* cmd_buffer, size_t cmd_offset, size_t draw_count,
101 size_t stride) override;
102 RHICommandList& DrawMeshTasksIndirectCount(RHIBuffer* cmd_buffer, size_t cmd_offset, RHIBuffer* count_buffer,
103 size_t count_offset, uint32_t max_draw_count,
104 uint32_t cmd_stride) override;
105 RHICommandList& PushConstant(RHIPipelineState* pipeline, RHIShaderStage stage, uint32_t offset,
106 Span<const char> data) override;
107 RHICommandList& UpdateBuffer(RHIBuffer* buffer, size_t offset, Span<const char> data) override;
108 RHICommandList& FillBuffer(RHIBuffer* buffer, uint32_t value, size_t offset = 0,
109 size_t size = kFullSize) override;
110 RHICommandList& CopyBuffer(RHIBuffer* src_buffer, RHIBuffer* dst_buffer,
111 Span<const CopyBufferRegion> regions) override;
112 RHICommandList& CopyImage(RHITexture* src_image, RHITextureLayout src_layout, RHITexture* dst_image,
113 RHITextureLayout dst_layout, Span<const CopyImageRegion> regions) override;
114 RHICommandList& CopyBufferToImage(RHIBuffer* src_buffer, RHITexture* dst_image, RHITextureLayout dst_layout,
115 Span<const CopyImageRegion> regions) override;
117 RHIBuffer* dst_buffer, Span<const CopyImageRegion> regions) override;
119 bool compact) override;
120
121 RHICommandList& BeginGraphics(GraphicsDesc const& desc) override;
123 BindVertexBuffer(uint32_t index, Span<RHIBuffer* const> buffers, Span<const size_t> offsets) override;
124 RHICommandList& BindIndexBuffer(RHIBuffer* buffer, size_t offset, RHIResourceFormat format) override;
125 RHICommandList& EndGraphics() override;
126
127 RHICommandList& Dispatch(uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z) override;
128 RHICommandList& DispatchIndirect(RHIBuffer* cmd_buffer, size_t cmd_offset) override;
129
131 RHICommandList& TraceRays(uint32_t width, uint32_t height, uint32_t depth) override;
133 WriteTimestamp(RHIDeviceQueryPool* pool, RHIPipelineStageBits stage, uint32_t queryIndex) override;
135 RHIDeviceQueryPool* pool, size_t queryIndex) override;
136 RHICommandList& DebugBegin(const char* message) override;
137 RHICommandList& DebugInsertMarker(const char* message) override;
138 RHICommandList& DebugEnd() override;
139
140 void End() override;
141 void Reset() override;
142
143 void DebugSetObjectName(const char* name) override;
144 };
145}
Allocator interface (noexcept)
Definition Allocator.hpp:29
Definition Resource.hpp:57
Definition Command.hpp:42
Definition Command.hpp:18
Definition Device.hpp:165
Thread-safe type-erased handle dereference facility for RHI Objects.
Definition Details.hpp:147
Definition PipelineState.hpp:60
Scoped move-only RAII handle wrapper for RHI Objects.
Definition Details.hpp:85
Definition Resource.hpp:216
Definition Command.hpp:39
RHICommandList & Begin(Allocator *scratchAllocator=nullptr) override
Definition Command.cpp:68
RHICommandList & SetViewport(float x, float y, float width, float height, float depth_min=0.0, float depth_max=1.0, bool flipY=false) override
Definition Command.cpp:183
auto const & GetVkCommandBuffer() const
Definition Command.hpp:71
RHICommandList & BindVertexBuffer(uint32_t index, Span< RHIBuffer *const > buffers, Span< const size_t > offsets) override
Definition Command.cpp:479
RHICommandList & BindDescriptorSet(RHIDevicePipelineType bindpoint, RHIPipelineState *pipeline, Span< RHIDeviceDescriptorSet *const > sets, size_t first, Span< const uint32_t > dynamicOffsets) override
Definition Command.cpp:522
bool mInTransition
Definition Command.hpp:65
RHICommandList & CopyImage(RHITexture *src_image, RHITextureLayout src_layout, RHITexture *dst_image, RHITextureLayout dst_layout, Span< const CopyImageRegion > regions) override
Definition Command.cpp:311
RHICommandList & TraceRays(uint32_t width, uint32_t height, uint32_t depth) override
Definition Command.cpp:587
RHICommandList & SetAccelerationStructureTransition(RHIAccelerationStructure *as, TransitionDesc const &desc) override
Definition Command.cpp:132
RHICommandList & Dispatch(uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z) override
Definition Command.cpp:547
void End() override
Definition Command.cpp:622
RHICommandList & DrawMeshTasksIndirectCount(RHIBuffer *cmd_buffer, size_t cmd_offset, RHIBuffer *count_buffer, size_t count_offset, uint32_t max_draw_count, uint32_t cmd_stride) override
Definition Command.cpp:248
RHICommandList & DebugBegin(const char *message) override
Definition Command.cpp:639
UniquePtr< Barriers > mBarriers
Definition Command.hpp:64
RHICommandList & EndTransition() override
Definition Command.cpp:150
RHICommandList & DispatchIndirect(RHIBuffer *cmd_buffer, size_t cmd_offset) override
Definition Command.cpp:554
RHICommandList & DebugInsertMarker(const char *message) override
Definition Command.cpp:647
RHICommandList & WriteAccelerationStructureCompactedSize(Span< RHIAccelerationStructure *const > as, RHIDeviceQueryPool *pool, size_t queryIndex) override
Definition Command.cpp:608
void DebugSetObjectName(const char *name) override
Definition Command.cpp:662
RHICommandList & DebugEnd() override
Definition Command.cpp:655
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:205
RHICommandList & BindIndexBuffer(RHIBuffer *buffer, size_t offset, RHIResourceFormat format) override
Definition Command.cpp:497
UniquePtr< ScopedArena > mDefaultScratchArena
Definition Command.hpp:44
RHICommandList & BeginGraphics(GraphicsDesc const &desc) override
Definition Command.cpp:423
RHICommandList & SetImageTransition(RHITexture *image, TransitionDesc const &desc) override
Definition Command.cpp:109
RHICommandList & EndGraphics() override
Definition Command.cpp:540
RHIPipelineState * mLastPSO
Definition Command.hpp:67
RHICommandList & BuildAccelerationStructure(Span< const RHIAccelerationStructureBuildDesc > desc) override
Definition Command.cpp:562
RHICommandList & SetBufferTransition(RHIBuffer *image, TransitionDesc const &desc) override
Definition Command.cpp:92
RHICommandList & CopyBuffer(RHIBuffer *src_buffer, RHIBuffer *dst_buffer, Span< const CopyBufferRegion > regions) override
Definition Command.cpp:285
RHICommandList & SetPipeline(PipelineDesc const &desc) override
Definition Command.cpp:173
RHICommandList & CopyAccelerationStructure(RHIAccelerationStructure *src, RHIAccelerationStructure *dst, bool compact) override
Definition Command.cpp:408
RHICommandList & CopyBufferToImage(RHIBuffer *src_buffer, RHITexture *dst_image, RHITextureLayout dst_layout, Span< const CopyImageRegion > regions) override
Definition Command.cpp:345
RHICommandList & DrawMeshTasks(uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z) override
Definition Command.cpp:232
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:213
RHICommandList & DrawMeshTasksIndirect(RHIBuffer *cmd_buffer, size_t cmd_offset, size_t draw_count, size_t stride) override
Definition Command.cpp:239
const VulkanCommandPool & mCommandPool
Definition Command.hpp:41
RHICommandList & FillBuffer(RHIBuffer *buffer, uint32_t value, size_t offset=0, size_t size=kFullSize) override
Definition Command.cpp:277
RHICommandList & SetScissor(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override
Definition Command.cpp:197
RHICommandList & UpdateBuffer(RHIBuffer *buffer, size_t offset, Span< const char > data) override
Definition Command.cpp:269
vk::raii::CommandBuffer mCommandBuffer
Definition Command.hpp:42
void Reset() override
Definition Command.cpp:631
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:221
Allocator * mAllocator
Definition Command.hpp:43
RHICommandList & CopyImageToBuffer(RHITexture *src_image, RHITextureLayout src_layout, RHIBuffer *dst_buffer, Span< const CopyImageRegion > regions) override
Definition Command.cpp:376
RHICommandList & WriteTimestamp(RHIDeviceQueryPool *pool, RHIPipelineStageBits stage, uint32_t queryIndex) override
Definition Command.cpp:598
UniquePtr< AllocatorStack > mDefaultScratchAllocator
Definition Command.hpp:45
RHICommandList & BeginTransition() override
Definition Command.cpp:81
Definition Command.hpp:13
vk::raii::CommandPool mCommandPool
Definition Command.hpp:17
auto const & GetDevice() const
Definition Command.hpp:23
void DestroyCommandList(Handle handle) override
Definition Command.cpp:44
Allocator * mAllocator
Definition Command.hpp:15
auto const & GetVkCommandPool() const
Definition Command.hpp:24
void ResetAllCommandLists(bool freeResources) override
Definition Command.cpp:46
const VulkanDevice & mDevice
Definition Command.hpp:16
RHICommandPoolScopedHandle< RHICommandList > CreateCommandList() override
Definition Command.cpp:34
RHICommandList * GetCommandList(Handle handle) const override
Definition Command.cpp:39
void DebugSetObjectName(const char *name) override
Definition Command.cpp:26
RHIObjectPool mStorage
Definition Command.hpp:18
Definition Device.hpp:122
std::vector< T, StlAllocator< T > > Vector
std::vector with explicit Foundation::Core::StlAllocator constructor
Definition Container.hpp:149
std::unique_ptr< T, Deleter > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:180
std::span< T > Span
Alias for std::span
Definition Container.hpp:62
Low-level Rendering Hardware Interface (RHI) abstractions.
Definition Application.hpp:3
RHITextureLayout
Definition Common.hpp:218
uintptr_t Handle
Definition Details.hpp:9
constexpr size_t kCommandBarrierReserveSize
Definition Command.hpp:35
RHIResourceFormat
Definition Common.hpp:34
static constexpr size_t kFullSize
Definition Common.hpp:8
constexpr size_t kDefaultCommandScratchSize
Definition Command.hpp:36
Vector< vk::ImageMemoryBarrier2 > image
Definition Command.hpp:49
Barriers(Allocator *allocator)
Definition Command.hpp:52
Vector< vk::BufferMemoryBarrier2 > buffer
Definition Command.hpp:50
Definition BindlessSimple.cpp:9