Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_dualbuffer.hpp
Go to the documentation of this file.
1#pragma once
2#include "../core/foray_managedbuffer.hpp"
3#include "../foray_basics.hpp"
4
5namespace foray::util {
6
18 {
19 public:
22 void Create(core::Context* context, const core::ManagedBuffer::CreateInfo& devicebufferCreateInfo, uint32_t stageBufferCount = INFLIGHT_FRAME_COUNT);
23
25 virtual void StageFullBuffer(uint32_t frameIndex, const void* data);
26
28 virtual void StageSection(uint32_t frameIndex, const void* data, size_t destOffset, size_t size);
29
32 virtual void CmdCopyToDevice(uint32_t frameIndex, VkCommandBuffer cmdBuffer);
33
35 virtual void CmdPrepareForRead(VkCommandBuffer cmdBuffer, VkPipelineStageFlags2 dstStageMask, VkAccessFlags2 dstAccessMask) const;
36
38 virtual VkBufferMemoryBarrier2 MakeBarrierPrepareForRead(VkPipelineStageFlags2 dstStageMask, VkAccessFlags2 dstAccessMask) const;
39
40 inline bool Exists() const { return mDeviceBuffer.Exists(); }
41
42 inline std::string GetName() const { return mDeviceBuffer.GetName(); }
43 DualBuffer& SetName(std::string_view name);
44
45 inline VkDescriptorBufferInfo GetVkDescriptorInfo() const { return VkDescriptorBufferInfo{.buffer = mDeviceBuffer.GetBuffer(), .offset = 0U, .range = VK_WHOLE_SIZE}; }
46 inline VkBuffer GetDeviceVkBuffer() const { return mDeviceBuffer.GetBuffer(); }
47
48 void Destroy();
49
50 inline virtual ~DualBuffer() { Destroy(); }
51
52 FORAY_GETTER_CR(DeviceBuffer)
53
54 protected:
56 std::vector<void*> mStagingBufferMaps;
58 std::vector<std::unique_ptr<core::ManagedBuffer>> mStagingBuffers;
60 std::vector<std::vector<VkBufferCopy>> mBufferCopies;
63 };
64} // namespace foray::util
Simple types for supressing automatic definition of duplicating move constructors & operator.
Definition foray_basics.hpp:19
Wraps allocation and lifetime functionality of a VkBuffer.
Definition foray_managedbuffer.hpp:12
virtual bool Exists() const override
Return true, if the managed resource is allocated.
Definition foray_managedbuffer.hpp:47
std::string_view GetName() const
Return a custom name for the object.
Definition foray_managedresource.hpp:40
Helper class for organizing CPU -> GPU data synchronisation. In flight data is stored on host side,...
Definition foray_dualbuffer.hpp:18
VkBuffer GetDeviceVkBuffer() const
Definition foray_dualbuffer.hpp:46
virtual void StageFullBuffer(uint32_t frameIndex, const void *data)
Updates the entire staging buffer.
std::vector< std::unique_ptr< core::ManagedBuffer > > mStagingBuffers
Permanently mapped host-local staging buffers (one per frame in flight)
Definition foray_dualbuffer.hpp:58
virtual void CmdPrepareForRead(VkCommandBuffer cmdBuffer, VkPipelineStageFlags2 dstStageMask, VkAccessFlags2 dstAccessMask) const
Prepares the device buffer for read access with a pipeline barrier (must be called before read access...
std::vector< void * > mStagingBufferMaps
Memory locations the permanently mapped staging buffers are mapped to.
Definition foray_dualbuffer.hpp:56
DualBuffer & SetName(std::string_view name)
core::ManagedBuffer mDeviceBuffer
The buffer used by the device.
Definition foray_dualbuffer.hpp:62
virtual void StageSection(uint32_t frameIndex, const void *data, size_t destOffset, size_t size)
Updates a section of a staging buffer.
VkDescriptorBufferInfo GetVkDescriptorInfo() const
Definition foray_dualbuffer.hpp:45
virtual VkBufferMemoryBarrier2 MakeBarrierPrepareForRead(VkPipelineStageFlags2 dstStageMask, VkAccessFlags2 dstAccessMask) const
Returns a barrier which prepares the device buffer for read access.
virtual ~DualBuffer()
Definition foray_dualbuffer.hpp:50
bool Exists() const
Definition foray_dualbuffer.hpp:40
std::string GetName() const
Definition foray_dualbuffer.hpp:42
std::vector< std::vector< VkBufferCopy > > mBufferCopies
Record of all buffer copies submitted. Added to when writing to staging buffers, cleared when buildin...
Definition foray_dualbuffer.hpp:60
void Create(core::Context *context, const core::ManagedBuffer::CreateInfo &devicebufferCreateInfo, uint32_t stageBufferCount=INFLIGHT_FRAME_COUNT)
Creates the dualbuffer setup.
virtual void CmdCopyToDevice(uint32_t frameIndex, VkCommandBuffer cmdBuffer)
Writes commands required to copy the changes recorded in the indexed staging buffer to the device buf...
#define FORAY_GETTER_CR(member)
Return constant reference.
Definition foray_basics.hpp:60
Definition foray_dualbuffer.hpp:5
constexpr uint32_t INFLIGHT_FRAME_COUNT
Inflight frame count is the amount of frames 'in flight' aka frames recorded on the host before waiti...
Definition foray_basics.hpp:35
Non owning context object.
Definition foray_context.hpp:16
Combines all structs used for initialization.
Definition foray_managedbuffer.hpp:16