Foray Library
rapid prototyping framework for crossplatform development of vulkan hardware ray tracing applications
Loading...
Searching...
No Matches
foray_commandbuffer.hpp
Go to the documentation of this file.
1#pragma once
2#include "foray_context.hpp"
4#include <vulkan/vulkan.h>
5
6namespace foray::core {
7
9 class CommandBuffer : public VulkanResource<VkObjectType::VK_OBJECT_TYPE_COMMAND_BUFFER>
10 {
11 public:
12 CommandBuffer() = default;
13 inline virtual ~CommandBuffer() { Destroy(); }
14
16 virtual VkCommandBuffer Create(Context* context, VkCommandBufferLevel cmdBufferLvl = VK_COMMAND_BUFFER_LEVEL_PRIMARY, bool begin = false);
18 virtual void Begin();
20 virtual void End();
22 virtual void Reset(VkCommandBufferResetFlags flags = 0);
23
25 virtual void Destroy() override;
26 virtual bool Exists() const override { return mCommandBuffer; }
27 virtual void SetName(std::string_view name) override;
28
29 inline operator VkCommandBuffer() const { return mCommandBuffer; }
30
32 protected:
34
35 VkCommandBuffer mCommandBuffer{};
36 bool mIsRecording = false;
37 };
38
41 {
42 public:
44 virtual VkCommandBuffer Create(Context* context, VkCommandBufferLevel cmdBufferLvl = VK_COMMAND_BUFFER_LEVEL_PRIMARY, bool begin = false) override;
45
47 void Submit();
54
55 virtual void Destroy() override;
56
57 inline virtual ~HostSyncCommandBuffer() { Destroy(); }
58
59 protected:
60 VkFence mFence = nullptr;
61 };
62
65 {
67 VkSemaphoreType SemaphoreType = VkSemaphoreType::VK_SEMAPHORE_TYPE_BINARY;
69 uint64_t TimelineValue = 0;
71 VkSemaphore Semaphore = nullptr;
73 VkPipelineStageFlags2 WaitStage = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;
74
78 static SemaphoreReference Binary(VkSemaphore semaphore, VkPipelineStageFlags2 waitStage = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT);
83 static SemaphoreReference Timeline(VkSemaphore semaphore, uint64_t value, VkPipelineStageFlags2 waitStage = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT);
84
85 operator VkSemaphoreSubmitInfo() const;
86 };
87
90 {
91 public:
96
97 FORAY_PROPERTY_R(WaitSemaphores)
98 FORAY_PROPERTY_R(SignalSemaphores)
99 FORAY_PROPERTY_V(Fence)
100
101
102 virtual void Submit();
103
105 virtual void WriteToSubmitInfo(std::vector<VkSubmitInfo2>& submitInfos);
106
107 protected:
110 VkFence mFence = nullptr;
111 };
112
113} // namespace foray::core
VkCommandBuffer wrapper.
Definition foray_commandbuffer.hpp:10
core::Context * mContext
Definition foray_commandbuffer.hpp:33
virtual void SetName(std::string_view name) override
Set a custom name for the object.
virtual void End()
vkEndCommandBuffer()
virtual bool Exists() const override
Return true, if the managed resource is allocated.
Definition foray_commandbuffer.hpp:26
virtual ~CommandBuffer()
Definition foray_commandbuffer.hpp:13
virtual void Begin()
vkBeginCommandBuffer();
bool mIsRecording
Definition foray_commandbuffer.hpp:36
VkCommandBuffer mCommandBuffer
Definition foray_commandbuffer.hpp:35
virtual void Reset(VkCommandBufferResetFlags flags=0)
vkResetCommandBuffer()
virtual void Destroy() override
Destroys the associated resources.
virtual VkCommandBuffer Create(Context *context, VkCommandBufferLevel cmdBufferLvl=VK_COMMAND_BUFFER_LEVEL_PRIMARY, bool begin=false)
Create based on the contexts device, command pool and queue.
Extension of the commandbuffer wrapper for device and/or host synchronized command buffer execution.
Definition foray_commandbuffer.hpp:90
std::vector< SemaphoreReference > mSignalSemaphores
Definition foray_commandbuffer.hpp:109
VkFence mFence
Definition foray_commandbuffer.hpp:110
std::vector< SemaphoreReference > mWaitSemaphores
Definition foray_commandbuffer.hpp:108
virtual DeviceSyncCommandBuffer & AddWaitSemaphore(const SemaphoreReference &semaphore)
Adds a semaphore to wait for before execution of the commandbuffer.
virtual void WriteToSubmitInfo(std::vector< VkSubmitInfo2 > &submitInfos)
Appends a suitable submitinfo to the vector.
virtual DeviceSyncCommandBuffer & AddSignalSemaphore(const SemaphoreReference &semaphore)
Adds a semaphore to signal after execution of commandbuffer has finished.
virtual void Submit()
Submits the commandbuffer.
Extension of the commandbuffer wrapper for temporary host synchronized command buffer execution.
Definition foray_commandbuffer.hpp:41
void WaitForCompletion()
Blocks CPU thread until commandbuffer has completed.
virtual VkCommandBuffer Create(Context *context, VkCommandBufferLevel cmdBufferLvl=VK_COMMAND_BUFFER_LEVEL_PRIMARY, bool begin=false) override
Create based on the contexts device, command pool and queue.
void SubmitAndWait()
Submits and waits for the commandbuffer to be completed.
void Submit()
Submits but doesn't synchronize. Use HasCompleted() and/or WaitForCompletion() to synchronize.
virtual ~HostSyncCommandBuffer()
Definition foray_commandbuffer.hpp:57
VkFence mFence
Definition foray_commandbuffer.hpp:60
bool HasCompleted()
Checks the fence for completion (non-blocking)
virtual void Destroy() override
Destroys the associated resources.
ManagedResource variant which automates GetTypeName() overloading by returning a stringified version ...
Definition foray_managedresource.hpp:59
#define FORAY_GETTER_V(member)
Return value.
Definition foray_basics.hpp:39
#define FORAY_PROPERTY_V(member)
Getter+Setter shorthand for value types.
Definition foray_basics.hpp:81
#define FORAY_PROPERTY_R(member)
Getter+Setter shorthand for reference types.
Definition foray_basics.hpp:86
Definition foray_commandbuffer.hpp:6
Definition foray_env.hpp:92
Non owning context object.
Definition foray_context.hpp:16
Wraps a wait or signal semaphore action.
Definition foray_commandbuffer.hpp:65
VkSemaphoreType SemaphoreType
Type of semaphore.
Definition foray_commandbuffer.hpp:67
VkSemaphore Semaphore
Semaphore.
Definition foray_commandbuffer.hpp:71
static SemaphoreReference Timeline(VkSemaphore semaphore, uint64_t value, VkPipelineStageFlags2 waitStage=VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT)
Shorthand for initializing a SemaphoreReference struct for a timeline semaphore.
static SemaphoreReference Binary(VkSemaphore semaphore, VkPipelineStageFlags2 waitStage=VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT)
Shorthand for initializing a SemaphoreReference struct for a binary semaphore.
VkPipelineStageFlags2 WaitStage
Stage masks.
Definition foray_commandbuffer.hpp:73
uint64_t TimelineValue
Timeline value to signal/wait (ignored if binary semaphore)
Definition foray_commandbuffer.hpp:69