upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src/vulkan_present.h
diff options
context:
space:
mode:
authorMumogg <104529023+Mumogg@users.noreply.github.com>2026-11-23 16:11:49 -0600
committerMumogg <104529023+Mumogg@users.noreply.github.com>2026-11-23 16:11:49 -0600
commit0c7ec65c0e0d1890139eda86cc92fc4f0ed830e6 (patch)
treef27b75b09e1a4de109ce36b4b9aebb0bef353a97 /runtime/src/vulkan_present.h
parentc9ea50842077678228204a2be52314c4065f87d7 (diff)
local: apply #9419 (present dump) as a patch
Diffstat (limited to 'runtime/src/vulkan_present.h')
-rw-r--r--runtime/src/vulkan_present.h40
1 files changed, 29 insertions, 11 deletions
diff --git a/runtime/src/vulkan_present.h b/runtime/src/vulkan_present.h
index 8644346c5..2ce6f457b 100644
--- a/runtime/src/vulkan_present.h
+++ b/runtime/src/vulkan_present.h
@@ -27,6 +27,7 @@
27 27
28#include "vulkan_backend.h" 28#include "vulkan_backend.h"
29#include "vulkan_present_compose.h" 29#include "vulkan_present_compose.h"
30#include "present_dump.h"
30 31
31// Use the original EXT spellings. They are aliases of the promoted KHR types and are available in older headers. 32// Use the original EXT spellings. They are aliases of the promoted KHR types and are available in older headers.
32#if defined(VK_EXT_SWAPCHAIN_MAINTENANCE_1_EXTENSION_NAME) && defined(VK_EXT_SURFACE_MAINTENANCE_1_EXTENSION_NAME) 33#if defined(VK_EXT_SWAPCHAIN_MAINTENANCE_1_EXTENSION_NAME) && defined(VK_EXT_SURFACE_MAINTENANCE_1_EXTENSION_NAME)
@@ -583,7 +584,15 @@ private:
583 // Only a present the engine took counts (SUBOPTIMAL is shown too). OUT_OF_DATE was not shown: the swapchain 584 // Only a present the engine took counts (SUBOPTIMAL is shown too). OUT_OF_DATE was not shown: the swapchain
584 // is recreated next time, and the caller sees VK_SUCCESS, since its work was submitted. 585 // is recreated next time, and the caller sees VK_SUCCESS, since its work was submitted.
585 if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) { 586 if (result == VK_SUCCESS || result == VK_SUBOPTIMAL_KHR) {
586 ++presented_; 587 const auto shown = ++presented_;
588 if (dump_.due(shown - 1)) {
589 // Presentation is already queued and the queue/tracker locks are released. A sampled frame
590 // may stall here for its transfer fence and a private CPU copy. PNG and disk I/O run on a worker.
591 if (vkWaitForFences_(device, 1, &frame.done, VK_TRUE, UINT64_MAX) == VK_SUCCESS)
592 dump_.save(shown, extent_, format_, dump_pq_, capture_ptr_, size_t(capture_size_));
593 else
594 dump_.disable("present dump fence wait failed");
595 }
587 if (planes) ++composed_; 596 if (planes) ++composed_;
588 if (tearing) { 597 if (tearing) {
589 last_tore_ = true; 598 last_tore_ = true;
@@ -915,7 +924,7 @@ private:
915 const VkImageSubresourceRange range{VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1}; 924 const VkImageSubresourceRange range{VK_IMAGE_ASPECT_COLOR_BIT, 0, 1, 0, 1};
916 VkImageLayout layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; 925 VkImageLayout layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
917 VkAccessFlags access = VK_ACCESS_TRANSFER_WRITE_BIT; 926 VkAccessFlags access = VK_ACCESS_TRANSFER_WRITE_BIT;
918 if (capture_ && capture_buffer_) { 927 if (capture_buffer_ && (capture_ || dump_.due(presented_))) {
919 // Two frames may be in flight and share `capture_buffer_`: serialize the prior frame's capture copy 928 // Two frames may be in flight and share `capture_buffer_`: serialize the prior frame's capture copy
920 // before overwriting it, while moving this frame's swapchain image to TRANSFER_SRC. 929 // before overwriting it, while moving this frame's swapchain image to TRANSFER_SRC.
921 VkBufferMemoryBarrier capture_waw{VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER}; 930 VkBufferMemoryBarrier capture_waw{VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER};
@@ -942,6 +951,10 @@ private:
942 copy.imageExtent = {extent_.width, extent_.height, 1}; 951 copy.imageExtent = {extent_.width, extent_.height, 1};
943 fn.copy_image_to_buffer(commands, images_[image], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, capture_buffer_, 1, 952 fn.copy_image_to_buffer(commands, images_[image], VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, capture_buffer_, 1,
944 &copy); 953 &copy);
954 auto to_host = capture_waw;
955 to_host.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
956 fn.pipeline_barrier(commands, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0,
957 0, nullptr, 1, &to_host, 0, nullptr);
945 layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; 958 layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
946 access = VK_ACCESS_TRANSFER_READ_BIT; 959 access = VK_ACCESS_TRANSFER_READ_BIT;
947 } 960 }
@@ -954,7 +967,7 @@ private:
954 release_capture(); 967 release_capture();
955 auto& vk = context_.vk; 968 auto& vk = context_.vk;
956 const VkDevice device = context_.device(); 969 const VkDevice device = context_.device();
957 capture_size_ = VkDeviceSize(extent_.width) * extent_.height * 4; 970 capture_size_ = VkDeviceSize(extent_.width) * extent_.height * present_dump::texel_size(format_);
958 VkBufferCreateInfo info{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; 971 VkBufferCreateInfo info{VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
959 info.size = capture_size_; 972 info.size = capture_size_;
960 info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT; 973 info.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT;
@@ -1039,7 +1052,9 @@ private:
1039 return true; 1052 return true;
1040 } 1053 }
1041 VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT; 1054 VkImageUsageFlags usage = VK_IMAGE_USAGE_TRANSFER_DST_BIT;
1042 if (capture_) usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT; 1055 if (dump_.enabled() && !(caps.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT))
1056 dump_.disable("surface does not support swapchain readback");
1057 if (capture_ || dump_.enabled()) usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
1043 if ((caps.supportedUsageFlags & usage) != usage) return false; 1058 if ((caps.supportedUsageFlags & usage) != usage) return false;
1044 // Not used by the presenter itself (it blits or copies into the images), but overlays that hook the swapchain 1059 // Not used by the presenter itself (it blits or copies into the images), but overlays that hook the swapchain
1045 // draw their own frame into its images through a framebuffer, which needs COLOR_ATTACHMENT: without it 1060 // draw their own frame into its images through a framebuffer, which needs COLOR_ATTACHMENT: without it
@@ -1183,13 +1198,14 @@ private:
1183 extent_ = extent; 1198 extent_ = extent;
1184 extent_packed_ = (std::uint64_t(extent.width) << 32) | extent.height; 1199 extent_packed_ = (std::uint64_t(extent.width) << 32) | extent.height;
1185 hdr_active_ = chose_hdr; 1200 hdr_active_ = chose_hdr;
1186 if (capture_) { 1201 dump_pq_ = chosen.colorSpace == VK_COLOR_SPACE_HDR10_ST2084_EXT;
1187 // A capture that cannot be made fails the recreation with the swapchain in place and stale_ still set. 1202 if (capture_ || dump_.enabled()) {
1188 const bool four_bytes = format_ == VK_FORMAT_B8G8R8A8_UNORM || format_ == VK_FORMAT_R8G8B8A8_UNORM || 1203 const auto stride = present_dump::texel_size(format_);
1189 format_ == VK_FORMAT_B8G8R8A8_SRGB || format_ == VK_FORMAT_R8G8B8A8_SRGB || 1204 if (capture_ && stride != 4) return false; // read_back() promises four bytes per texel
1190 format_ == VK_FORMAT_A2B10G10R10_UNORM_PACK32 || 1205 if (!stride || !make_capture_buffer()) {
1191 format_ == VK_FORMAT_A2R10G10B10_UNORM_PACK32; 1206 dump_.disable("cannot read back this swapchain format or allocate its capture buffer");
1192 if (!four_bytes || !make_capture_buffer()) return false; 1207 if (capture_) return false;
1208 }
1193 } 1209 }
1194 vsync_ = vsync; 1210 vsync_ = vsync;
1195 swapchain_srgb_ = srgb; 1211 swapchain_srgb_ = srgb;
@@ -1300,6 +1316,8 @@ private:
1300 std::map<VkFormat, VkFormatFeatureFlags> features_; 1316 std::map<VkFormat, VkFormatFeatureFlags> features_;
1301 bool warned_srgb_ = false; 1317 bool warned_srgb_ = false;
1302 bool capture_ = false; 1318 bool capture_ = false;
1319 present_dump::PresentDump dump_;
1320 bool dump_pq_ = false;
1303 VkBuffer capture_buffer_ = VK_NULL_HANDLE; 1321 VkBuffer capture_buffer_ = VK_NULL_HANDLE;
1304 VkDeviceMemory capture_memory_ = VK_NULL_HANDLE; 1322 VkDeviceMemory capture_memory_ = VK_NULL_HANDLE;
1305 VkDeviceSize capture_size_ = 0; 1323 VkDeviceSize capture_size_ = 0;