From 3e116e6e43e0d9296bb96e3783eabbeacfb3e497 Mon Sep 17 00:00:00 2001 From: catbot Date: Thu, 18 Jun 2026 19:35:54 +0000 Subject: [PATCH] feat(window): env-gated uncapped present mode for benchmarking CRAFTER_PRESENT_IMMEDIATE selects IMMEDIATE (then MAILBOX) when the surface offers it, instead of the default FIFO. Needed to measure steady-state frame throughput without the compositor's vblank cap; FIFO remains the default when the variable is unset. Co-Authored-By: Claude Opus 4.8 --- implementations/Crafter.Graphics-Window.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/implementations/Crafter.Graphics-Window.cpp b/implementations/Crafter.Graphics-Window.cpp index bee7f82..3af8c7b 100644 --- a/implementations/Crafter.Graphics-Window.cpp +++ b/implementations/Crafter.Graphics-Window.cpp @@ -1072,8 +1072,24 @@ void Window::CreateSwapchain() swapchainCI.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE; swapchainCI.queueFamilyIndexCount = 0; // VK_PRESENT_MODE_FIFO_KHR ("v-sync") is guaranteed available per spec, so - // it is used unconditionally — no present-mode enumeration is needed. + // it is the default. For benchmarking we want frame pacing uncapped from + // the display refresh, so when CRAFTER_PRESENT_IMMEDIATE is set in the + // environment we enumerate the surface's present modes and prefer + // IMMEDIATE (then MAILBOX) when offered, falling back to FIFO otherwise. swapchainCI.presentMode = VK_PRESENT_MODE_FIFO_KHR; + if (std::getenv("CRAFTER_PRESENT_IMMEDIATE")) { + std::uint32_t presentModeCount = 0; + vkGetPhysicalDeviceSurfacePresentModesKHR(Device::physDevice, vulkanSurface, &presentModeCount, nullptr); + std::vector presentModes(presentModeCount); + vkGetPhysicalDeviceSurfacePresentModesKHR(Device::physDevice, vulkanSurface, &presentModeCount, presentModes.data()); + bool haveImmediate = false, haveMailbox = false; + for (VkPresentModeKHR m : presentModes) { + if (m == VK_PRESENT_MODE_IMMEDIATE_KHR) haveImmediate = true; + if (m == VK_PRESENT_MODE_MAILBOX_KHR) haveMailbox = true; + } + if (haveImmediate) swapchainCI.presentMode = VK_PRESENT_MODE_IMMEDIATE_KHR; + else if (haveMailbox) swapchainCI.presentMode = VK_PRESENT_MODE_MAILBOX_KHR; + } // Setting oldSwapChain to the saved handle of the previous swapchain aids in resource reuse and makes sure that we can still present already acquired images swapchainCI.oldSwapchain = oldSwapchain; // Setting clipped to VK_TRUE allows the implementation to discard rendering outside of the surface area