11#include <vulkan/vulkan_raii.hpp>
13namespace renderer::sync {
32 compute_storage_write,
37 fragment_storage_read,
62 vk::PipelineStageFlags2 stages;
63 vk::AccessFlags2 access;
64 vk::ImageLayout layout = vk::ImageLayout::eUndefined;
71TOAST_API
auto writes(
Usage usage) -> bool;
75 vk::Image image = VK_NULL_HANDLE;
76 vk::ImageSubresourceRange range {vk::ImageAspectFlagBits::eColor, 0, 1, 0, 1};
80 void reset(vk::Image new_image,
const vk::ImageSubresourceRange& new_range) {
87 explicit operator bool()
const {
88 return image != VK_NULL_HANDLE;
93 uint32_t from = VK_QUEUE_FAMILY_IGNORED;
94 uint32_t to = VK_QUEUE_FAMILY_IGNORED;
99 auto crossesQueues() const noexcept ->
bool {
110 void image(vk::Image
image,
const vk::ImageSubresourceRange& range,
Usage previous,
Usage next);
112 void buffer(vk::Buffer buffer,
Usage previous,
Usage next, vk::DeviceSize offset = 0, vk::DeviceSize size = VK_WHOLE_SIZE);
126 vk::DeviceSize size = VK_WHOLE_SIZE
130 vk::Buffer buffer,
Usage next,
const QueueHandoff& handoff, vk::DeviceSize offset = 0, vk::DeviceSize size = VK_WHOLE_SIZE
133 void flush(vk::CommandBuffer cmd);
136 auto empty()
const ->
bool {
137 return m_images.empty() && m_buffers.empty() && m_memory.empty();
141 auto pendingImages()
const -> std::span<const vk::ImageMemoryBarrier2> {
146 auto pendingBuffers()
const -> std::span<const vk::BufferMemoryBarrier2> {
151 auto pendingMemory()
const -> std::span<const vk::MemoryBarrier2> {
156 std::vector<vk::ImageMemoryBarrier2> m_images;
157 std::vector<vk::BufferMemoryBarrier2> m_buffers;
158 std::vector<vk::MemoryBarrier2> m_memory;
162 transition(vk::CommandBuffer cmd, vk::Image image,
const vk::ImageSubresourceRange& range,
Usage previous,
Usage next);
164TOAST_API
void transition(vk::CommandBuffer cmd,
ImageState& state,
Usage next);
167 vk::Semaphore semaphore;
168 vk::PipelineStageFlags2 stages;
174 vk::Semaphore semaphore;
180 std::span<const vk::CommandBuffer> commands;
181 std::span<const SemaphoreWait> waits;
182 std::span<const SemaphoreSignal> signals;
Skips a barrier only when neither side writes and the layout and next read stages are already covered...
Definition gpu_sync.hpp:105
void release(vk::Image image, const vk::ImageSubresourceRange &range, Usage previous, Usage next, const QueueHandoff &handoff)
Definition gpu_sync.cpp:189
void acquire(vk::Image image, const vk::ImageSubresourceRange &range, Usage previous, Usage next, const QueueHandoff &handoff)
Definition gpu_sync.cpp:210
void image(ImageState &state, Usage next)
No op for an image that does not exist. The widest usage until the next write avoids read to read bar...
Definition gpu_sync.cpp:139
void submit(vk::Queue queue, const SubmitDesc &desc)
The caller holds any lock the queue needs.
Definition gpu_sync.cpp:307
Usage
Definition gpu_sync.hpp:15
@ depth_attachment
eDepthAttachmentOptimal including load and store ops
Definition gpu_sync.hpp:22
@ shader_sampled
Vertex fragment and compute.
Definition gpu_sync.hpp:29
@ none
Contents discarded and the layout undefined.
Definition gpu_sync.hpp:17
@ vertex_input
Vertex and index buffers.
Definition gpu_sync.hpp:41
@ present
Colour attachment output stage so the next use chains onto the acquire semaphore wait.
Definition gpu_sync.hpp:50
@ depth_sampled
eDepthReadOnlyOptimal sampled by fragment and compute shaders
Definition gpu_sync.hpp:24
@ color_attachment
Includes load and store ops.
Definition gpu_sync.hpp:20
@ vertex_storage_read
Vertex pulling.
Definition gpu_sync.hpp:34
@ acceleration_trace_fragment
Fragment shader ray queries.
Definition gpu_sync.hpp:55
@ general
Every stage and access in eGeneral so correct anywhere and slow everywhere.
Definition gpu_sync.hpp:58
@ acceleration_build
Build input output and scratch.
Definition gpu_sync.hpp:53
@ uniform_read
Any shader stage.
Definition gpu_sync.hpp:39
@ mesh_storage_read
Task and mesh shaders on devices with VK_EXT_mesh_shader only.
Definition gpu_sync.hpp:36
Owned next to the image it describes.
Definition gpu_sync.hpp:74
void reset(vk::Image new_image, const vk::ImageSubresourceRange &new_range)
On every image creation since its contents start undefined.
Definition gpu_sync.hpp:80
Definition gpu_sync.hpp:92
bool exclusive
False for eConcurrent resources which need visibility on the consumer but no ownership transfer.
Definition gpu_sync.hpp:96
Definition gpu_sync.hpp:173
uint64_t value
Timeline value and ignored for binary semaphores.
Definition gpu_sync.hpp:176
Definition gpu_sync.hpp:166
uint64_t value
Timeline value and ignored for binary semaphores.
Definition gpu_sync.hpp:170
Definition gpu_sync.hpp:179
const void * next
Chained to SubmitInfo2 such as a FrameBoundaryEXT.
Definition gpu_sync.hpp:185
Definition gpu_sync.hpp:61