11#ifdef CORRELATION_USE_VULKAN
12#include <vulkan/vulkan.h>
23#ifdef CORRELATION_USE_VULKAN
30class VulkanOffscreenTarget {
32 static constexpr std::size_t STAGING_BUFFER_COUNT = 2;
34 VulkanOffscreenTarget() noexcept = default;
35 ~VulkanOffscreenTarget() noexcept { destroy(); }
37 VulkanOffscreenTarget(
const VulkanOffscreenTarget &) =
delete;
38 VulkanOffscreenTarget &operator=(
const VulkanOffscreenTarget &) =
delete;
40 VulkanOffscreenTarget(VulkanOffscreenTarget &&other)
noexcept { moveFrom(other); }
41 VulkanOffscreenTarget &operator=(VulkanOffscreenTarget &&other)
noexcept {
56 void create(VkDevice device, VkPhysicalDevice physical_device, uint32_t width, uint32_t height);
63 void resize(uint32_t width, uint32_t height);
68 void destroy() noexcept;
75 void beginRenderPass(VkCommandBuffer cmd,
76 VkClearColorValue clear_color = {{0.1F, 0.1F, 0.12F, 1.0F}});
82 static void endRenderPass(VkCommandBuffer cmd);
90 void copyToStaging(VkCommandBuffer cmd, uint32_t staging_index,
bool copy_depth =
false);
97 [[nodiscard]] std::span<const uint8_t> readoutStagingSpan(uint32_t staging_index)
const noexcept;
102 [[nodiscard]] std::span<uint8_t> readoutStagingMutableSpan(uint32_t staging_index)
noexcept;
107 [[nodiscard]] std::span<const float>
108 readoutDepthStagingSpan(uint32_t staging_index)
const noexcept;
110 [[nodiscard]]
bool hasDepthReadout() const noexcept {
111 return depth_format_ == VK_FORMAT_D32_SFLOAT;
114 [[nodiscard]] VkRenderPass renderPass() const noexcept {
return render_pass_; }
115 [[nodiscard]] VkFramebuffer framebuffer() const noexcept {
return framebuffer_; }
116 [[nodiscard]] VkExtent2D extent() const noexcept {
return extent_; }
117 [[nodiscard]] uint32_t width() const noexcept {
return extent_.width; }
118 [[nodiscard]] uint32_t height() const noexcept {
return extent_.height; }
119 [[nodiscard]] VkFormat colorFormat() const noexcept {
return color_format_; }
120 [[nodiscard]] VkFormat depthFormat() const noexcept {
return depth_format_; }
121 [[nodiscard]] VkImage colorImage() const noexcept {
return color_image_; }
122 [[nodiscard]] VkImage depthImage() const noexcept {
return depth_image_; }
123 [[nodiscard]]
bool isValid() const noexcept {
return framebuffer_ != VK_NULL_HANDLE; }
126 void moveFrom(VulkanOffscreenTarget &other)
noexcept;
127 void createRenderPass();
128 void createColorResources();
129 void createDepthResources();
130 void createFramebuffer();
131 void createStagingBuffers();
132 void destroyFrameResources() noexcept;
134 [[nodiscard]] VkFormat findDepthFormat() const;
135 void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling,
136 VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage &image,
137 VkDeviceMemory &memory);
138 [[nodiscard]] VkImageView createImageView(VkImage image, VkFormat format,
139 VkImageAspectFlags aspect_flags) const;
141 VkDevice device_{VK_NULL_HANDLE};
142 VkPhysicalDevice physical_device_{VK_NULL_HANDLE};
143 VkExtent2D extent_{.width = 0, .height = 0};
145 VkFormat color_format_{VK_FORMAT_R8G8B8A8_UNORM};
146 VkFormat depth_format_{VK_FORMAT_UNDEFINED};
148 VkRenderPass render_pass_{VK_NULL_HANDLE};
149 VkImage color_image_{VK_NULL_HANDLE};
150 VkDeviceMemory color_memory_{VK_NULL_HANDLE};
151 VkImageView color_image_view_{VK_NULL_HANDLE};
153 VkImage depth_image_{VK_NULL_HANDLE};
154 VkDeviceMemory depth_memory_{VK_NULL_HANDLE};
155 VkImageView depth_image_view_{VK_NULL_HANDLE};
157 VkFramebuffer framebuffer_{VK_NULL_HANDLE};
159 std::array<VulkanBuffer, STAGING_BUFFER_COUNT> staging_buffers_{};
160 std::array<VulkanBuffer, STAGING_BUFFER_COUNT> depth_staging_buffers_{};
RAII encapsulation of a Vulkan buffer and its associated device memory.
Definition VulkanComputeService.hpp:24