Extended SwapchainSupportDetails API to force it to requery values, use darray's rather than initializer lists and extended the get_framebuffer_extent function to allow disabling the final clamping step at the end of the function. This is used by the swapchain to avoid repeatedly requerying when minimised.

This commit is contained in:
2025-07-10 21:50:26 +10:00
parent 8ccafddb64
commit aa752bc208
2 changed files with 36 additions and 8 deletions

View File

@@ -19,9 +19,11 @@ namespace basalt
SwapchainSupportDetails(VkPhysicalDevice phy, VkSurfaceKHR surface);
~SwapchainSupportDetails();
VkSurfaceFormatKHR get_surface_format(const std::initializer_list<VkSurfaceFormatKHR>& allowed_formats);
VkPresentModeKHR get_present_mode(const std::initializer_list<VkPresentModeKHR>& allowed_present_modes);
VkExtent2D get_framebuffer_extent(basalt::Window& window);
void requery(basalt::Window& window, VkPhysicalDevice phy, const basalt::darray<VkSurfaceFormatKHR>& allowed_formats, const basalt::darray<VkPresentModeKHR>& allowed_present_modes);
VkSurfaceFormatKHR get_surface_format(const basalt::darray<VkSurfaceFormatKHR>& allowed_formats);
VkPresentModeKHR get_present_mode(const basalt::darray<VkPresentModeKHR>& allowed_present_modes);
VkExtent2D get_framebuffer_extent(basalt::Window& window, bool clamp=true);
VkSurfaceCapabilitiesKHR surface_capabilities;
basalt::darray<VkSurfaceFormatKHR> surface_formats;
@@ -37,6 +39,7 @@ namespace basalt
operator VkPhysicalDevice() noexcept;
VkPhysicalDeviceMemoryProperties memory_props;
basalt::darray<const char*> enabled_extensions;
DeviceQueueFamilyIndicies indicies;
VkSurfaceKHR surface;

View File

@@ -333,7 +333,9 @@ basalt::DeviceQueueFamilyIndicies::DeviceQueueFamilyIndicies(u32 graphics, u32 p
basalt::PhysicalDevice::PhysicalDevice(VkPhysicalDevice dev, const DeviceQueueFamilyIndicies& indicies, basalt::darray<const char*>&& enabled_extensions, VkSurfaceKHR surface) :
phys(dev), indicies(indicies), enabled_extensions(std::move(enabled_extensions)), surface(surface)
{ }
{
vkGetPhysicalDeviceMemoryProperties(dev, &memory_props);
}
basalt::PhysicalDevice::operator VkPhysicalDevice() noexcept
{ return this->phys; }
@@ -364,7 +366,27 @@ basalt::SwapchainSupportDetails::~SwapchainSupportDetails()
BTRACE("Destroyed %s (%p) with present modes at %p, and surface formats at %p\n", typeid(SwapchainSupportDetails).name(), this, this->present_modes.m_pdata, this->surface_formats.m_pdata);
}
VkSurfaceFormatKHR basalt::SwapchainSupportDetails::get_surface_format(const std::initializer_list<VkSurfaceFormatKHR>& allowed_formats)
void basalt::SwapchainSupportDetails::requery(basalt::Window& window, VkPhysicalDevice phy, const basalt::darray<VkSurfaceFormatKHR>& allowed_formats, const basalt::darray<VkPresentModeKHR>& allowed_present_modes)
{
vkGetPhysicalDeviceSurfaceCapabilitiesKHR(phy, window, &this->surface_capabilities);
u32 tmp = 0;
vkGetPhysicalDeviceSurfaceFormatsKHR(phy, window, &tmp, VK_NULL_HANDLE);
this->surface_formats.resize(tmp);
vkGetPhysicalDeviceSurfaceFormatsKHR(phy, window, &tmp, this->surface_formats.begin());
vkGetPhysicalDeviceSurfacePresentModesKHR(phy, window, &tmp, VK_NULL_HANDLE);
this->present_modes.resize(tmp);
vkGetPhysicalDeviceSurfacePresentModesKHR(phy, window, &tmp, this->present_modes.begin());
this->cached_format.format = VK_FORMAT_MAX_ENUM;
this->cached_format.colorSpace = VK_COLOR_SPACE_MAX_ENUM_KHR;
get_surface_format(allowed_formats);
this->cached_present_mode = VK_PRESENT_MODE_MAX_ENUM_KHR;
get_present_mode(allowed_present_modes);
get_framebuffer_extent(window);
}
VkSurfaceFormatKHR basalt::SwapchainSupportDetails::get_surface_format(const basalt::darray<VkSurfaceFormatKHR>& allowed_formats)
{
if (this->cached_format.colorSpace != VK_COLOR_SPACE_MAX_ENUM_KHR && this->cached_format.format != VK_FORMAT_MAX_ENUM)
return this->cached_format;
@@ -383,7 +405,7 @@ VkSurfaceFormatKHR basalt::SwapchainSupportDetails::get_surface_format(const std
return surface_formats[0];
}
VkPresentModeKHR basalt::SwapchainSupportDetails::get_present_mode(const std::initializer_list<VkPresentModeKHR>& allowed_present_modes)
VkPresentModeKHR basalt::SwapchainSupportDetails::get_present_mode(const basalt::darray<VkPresentModeKHR>& allowed_present_modes)
{
if (this->cached_present_mode != VK_PRESENT_MODE_MAX_ENUM_KHR)
return this->cached_present_mode;
@@ -402,7 +424,7 @@ VkPresentModeKHR basalt::SwapchainSupportDetails::get_present_mode(const std::in
return VK_PRESENT_MODE_FIFO_KHR;
}
VkExtent2D basalt::SwapchainSupportDetails::get_framebuffer_extent(basalt::Window& window)
VkExtent2D basalt::SwapchainSupportDetails::get_framebuffer_extent(basalt::Window& window, bool clamp)
{
i32 width, height;
glfwGetFramebufferSize(window, &width, &height);
@@ -410,7 +432,10 @@ VkExtent2D basalt::SwapchainSupportDetails::get_framebuffer_extent(basalt::Windo
.width = (u32)width,
.height = (u32)height
};
BCLAMP_EXTENT(ext, this->surface_capabilities.minImageExtent, this->surface_capabilities.maxImageExtent);
if (clamp)
{
BCLAMP_EXTENT(ext, this->surface_capabilities.minImageExtent, this->surface_capabilities.maxImageExtent);
}
return ext;
}