From 64c76691bc33aa5d75ba3538a98ce234da37def5 Mon Sep 17 00:00:00 2001 From: Ryp Date: Thu, 10 Aug 2023 19:37:43 +0200 Subject: [PATCH] vulkan: rework swapchain creation code Save windows WIP hdr test as REAPER_WINDOWS_HDR_TEST. Make use of newer functions for swapchain properties queries. Renamed most fields as well. --- src/GameLoop.cpp | 2 +- src/renderer/ExecuteFrame.cpp | 23 +- src/renderer/vulkan/Backend.cpp | 9 +- src/renderer/vulkan/Backend.h | 14 +- src/renderer/vulkan/Swapchain.cpp | 221 ++++++++++-------- .../vulkan/renderpass/SwapchainPass.cpp | 4 +- .../vulkan/renderpass/TestGraphics.cpp | 30 +-- src/vulkan_loader/CMakeLists.txt | 4 +- src/vulkan_loader/SymbolHelper.inl | 3 +- 9 files changed, 171 insertions(+), 139 deletions(-) diff --git a/src/GameLoop.cpp b/src/GameLoop.cpp index 25b2596f..d0eb2302 100644 --- a/src/GameLoop.cpp +++ b/src/GameLoop.cpp @@ -443,7 +443,7 @@ void execute_game_loop(ReaperRoot& root) const MouseState mouse_state = window->get_mouse_state(); ImGuiIO& io = ImGui::GetIO(); io.DisplaySize = - ImVec2((float)backend.presentInfo.surfaceExtent.width, (float)backend.presentInfo.surfaceExtent.height); + ImVec2((float)backend.presentInfo.surface_extent.width, (float)backend.presentInfo.surface_extent.height); io.AddMousePosEvent((float)mouse_state.pos_x, (float)mouse_state.pos_y); ImGui_ImplVulkan_NewFrame(); diff --git a/src/renderer/ExecuteFrame.cpp b/src/renderer/ExecuteFrame.cpp index 11d1b82d..a7c791b6 100644 --- a/src/renderer/ExecuteFrame.cpp +++ b/src/renderer/ExecuteFrame.cpp @@ -73,9 +73,30 @@ void renderer_execute_frame(ReaperRoot& root, const SceneGraph& scene, std::vect { VulkanBackend& backend = *root.renderer->backend; +#if REAPER_WINDOWS_HDR_TEST + static bool fullscreen = false; + if (fullscreen == false) + { + VkResult acquireFullscreenResult = + vkAcquireFullScreenExclusiveModeEXT(backend.device, backend.presentInfo.swapchain); + + if (acquireFullscreenResult == VK_SUCCESS) + { + fullscreen = true; + // FIXME Trigger resize to check for new formats + backend.new_swapchain_extent = backend.presentInfo.surface_extent; + log_info(root, "vulkan: FULLSCREEN!"); + } + else + { + log_error(root, "vulkan: UNABLE TO SET FULLSCREEN!"); + } + } +#endif + resize_swapchain(root, backend); - const VkExtent2D backbufferExtent = backend.presentInfo.surfaceExtent; + const VkExtent2D backbufferExtent = backend.presentInfo.surface_extent; const glm::uvec2 backbuffer_viewport_extent(backbufferExtent.width, backbufferExtent.height); const float near_plane_distance = 0.1f; diff --git a/src/renderer/vulkan/Backend.cpp b/src/renderer/vulkan/Backend.cpp index 68a92e9d..bf0d3530 100644 --- a/src/renderer/vulkan/Backend.cpp +++ b/src/renderer/vulkan/Backend.cpp @@ -194,14 +194,15 @@ void create_vulkan_renderer_backend(ReaperRoot& root, VulkanBackend& backend) std::vector device_extensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME, +#if REAPER_WINDOWS_HDR_TEST + VK_EXT_HDR_METADATA_EXTENSION_NAME, + VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME, + VK_AMD_DISPLAY_NATIVE_HDR_EXTENSION_NAME, +#endif VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME, VK_EXT_CALIBRATED_TIMESTAMPS_EXTENSION_NAME, VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME, VK_EXT_PRIMITIVE_TOPOLOGY_LIST_RESTART_EXTENSION_NAME, -#if 0 - VK_EXT_HDR_METADATA_EXTENSION_NAME, - VK_EXT_FULL_SCREEN_EXCLUSIVE_EXTENSION_NAME, -#endif }; log_debug(root, "vulkan: choosing physical device"); diff --git a/src/renderer/vulkan/Backend.h b/src/renderer/vulkan/Backend.h index c12cf842..6b62ca7a 100644 --- a/src/renderer/vulkan/Backend.h +++ b/src/renderer/vulkan/Backend.h @@ -26,14 +26,14 @@ struct PresentationInfo bool queue_swapchain_transition = false; // Split this in another struct - VkSurfaceCapabilitiesKHR surfaceCaps; - VkSurfaceFormatKHR surfaceFormat; + VkSurfaceCapabilitiesKHR surface_caps; + VkSurfaceFormatKHR surface_format; VkFormat view_format; - u32 imageCount; - VkPresentModeKHR presentMode; - VkExtent2D surfaceExtent; - VkImageUsageFlags swapchainUsageFlags; - VkSurfaceTransformFlagBitsKHR transform; + u32 image_count; + VkPresentModeKHR present_mode; + VkExtent2D surface_extent; + VkImageUsageFlags swapchain_usage_flags; + VkSurfaceTransformFlagBitsKHR surface_transform; VkSwapchainKHR swapchain = VK_NULL_HANDLE; diff --git a/src/renderer/vulkan/Swapchain.cpp b/src/renderer/vulkan/Swapchain.cpp index 0244b9ff..e88bb961 100644 --- a/src/renderer/vulkan/Swapchain.cpp +++ b/src/renderer/vulkan/Swapchain.cpp @@ -17,23 +17,28 @@ #include "core/Assert.h" #include "profiling/Scope.h" +#if REAPER_WINDOWS_HDR_TEST +# include "renderer/window/Win32Window.h" // FIXME +#endif + namespace { -VkSurfaceFormatKHR vulkan_swapchain_choose_surface_format(std::vector& surface_formats, - VkSurfaceFormatKHR preferredFormat) +VkSurfaceFormatKHR vulkan_swapchain_choose_surface_format(std::vector& surface_formats, + VkSurfaceFormatKHR preferredFormat) { // If the list contains only one entry with undefined format // it means that there are no preferred surface formats and any can be chosen - if ((surface_formats.size() == 1) && (surface_formats[0].format == VK_FORMAT_UNDEFINED)) + if ((surface_formats.size() == 1) && (surface_formats[0].surfaceFormat.format == VK_FORMAT_UNDEFINED)) return preferredFormat; - for (const VkSurfaceFormatKHR& surface_format : surface_formats) + for (const VkSurfaceFormat2KHR& surface_format2 : surface_formats) { + const VkSurfaceFormatKHR& surface_format = surface_format2.surfaceFormat; if (surface_format.format == preferredFormat.format && surface_format.colorSpace == preferredFormat.colorSpace) return surface_format; } - return surface_formats[0]; // Return first available format + return surface_formats[0].surfaceFormat; // Return first available format } uint32_t clamp(uint32_t v, uint32_t min, uint32_t max) @@ -119,10 +124,6 @@ VkFormat vulkan_swapchain_view_format_override(VkSurfaceFormatKHR surface_format } } // namespace -#if 0 -# include "renderer/window/Win32Window.h" -#endif - namespace Reaper { void configure_vulkan_wm_swapchain(ReaperRoot& root, const VulkanBackend& backend, @@ -130,93 +131,107 @@ void configure_vulkan_wm_swapchain(ReaperRoot& root, const VulkanBackend& backen { log_debug(root, "vulkan: configuring wm swapchain"); - Assert( - vkGetPhysicalDeviceSurfaceCapabilitiesKHR(backend.physicalDevice, presentInfo.surface, &presentInfo.surfaceCaps) - == VK_SUCCESS); + VkPhysicalDeviceSurfaceInfo2KHR surface_info_2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR, + .pNext = nullptr, + .surface = presentInfo.surface}; - VkSurfaceCapabilitiesKHR& surfaceCaps = presentInfo.surfaceCaps; + VkSurfaceCapabilities2KHR surface_caps_2 = {}; + surface_caps_2.sType = VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR; -#if 0 - { - Win32Window* win32Window = dynamic_cast(root.renderer->window); - HMONITOR monitor = MonitorFromWindow(win32Window->m_handle, MONITOR_DEFAULTTOPRIMARY); - VkSurfaceFullScreenExclusiveWin32InfoEXT fullscreen_exclusive_info = { - VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_WIN32_INFO_EXT, - nullptr, - monitor, - }; - VkPhysicalDeviceSurfaceInfo2KHR hey = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR, - &fullscreen_exclusive_info, presentInfo.surface}; - VkSurfaceCapabilitiesFullScreenExclusiveEXT fullscreen_caps = { - VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_FULL_SCREEN_EXCLUSIVE_EXT, nullptr, {}}; - VkSurfaceCapabilities2KHR surfaceCaps2 = {VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR, &fullscreen_caps, {}}; - - Assert(vkGetPhysicalDeviceSurfaceCapabilities2KHR(backend.physicalDevice, &hey, &surfaceCaps2) == VK_SUCCESS); - Assert(fullscreen_caps.fullScreenExclusiveSupported == VK_TRUE); - } +#if REAPER_WINDOWS_HDR_TEST + Win32Window* win32Window = dynamic_cast(root.renderer->window); + + const VkSurfaceFullScreenExclusiveWin32InfoEXT fullscreen_exclusive_win32_info = { + .sType = VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_WIN32_INFO_EXT, + .pNext = nullptr, + .hmonitor = MonitorFromWindow(win32Window->m_handle, MONITOR_DEFAULTTOPRIMARY), + }; + + surface_info_2.pNext = &fullscreen_exclusive_win32_info, + + VkSurfaceCapabilitiesFullScreenExclusiveEXT fullscreen_exclusive_info = {}; + fullscreen_exclusive_info.sType = VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_FULL_SCREEN_EXCLUSIVE_EXT; + + VkDisplayNativeHdrSurfaceCapabilitiesAMD native_hdr_amd = {}; + native_hdr_amd.sType = VK_STRUCTURE_TYPE_DISPLAY_NATIVE_HDR_SURFACE_CAPABILITIES_AMD; + native_hdr_amd.pNext = &fullscreen_exclusive_info; + + surface_caps_2.pNext = &native_hdr_amd; +#endif + + Assert(vkGetPhysicalDeviceSurfaceCapabilities2KHR(backend.physicalDevice, &surface_info_2, &surface_caps_2) + == VK_SUCCESS); + +#if REAPER_WINDOWS_HDR_TEST + // Assert(native_hdr_amd.localDimmingSupport == VK_TRUE); + Assert(fullscreen_exclusive_info.fullScreenExclusiveSupported == VK_TRUE); #endif + presentInfo.surface_caps = surface_caps_2.surfaceCapabilities; + const VkSurfaceCapabilitiesKHR& surface_caps = surface_caps_2.surfaceCapabilities; + // Choose surface format - VkSurfaceFormatKHR& surfaceFormat = presentInfo.surfaceFormat; + VkSurfaceFormatKHR& surface_format = presentInfo.surface_format; { uint32_t formats_count; - Assert( - vkGetPhysicalDeviceSurfaceFormatsKHR(backend.physicalDevice, presentInfo.surface, &formats_count, nullptr) - == VK_SUCCESS); + Assert(vkGetPhysicalDeviceSurfaceFormats2KHR(backend.physicalDevice, &surface_info_2, &formats_count, nullptr) + == VK_SUCCESS); Assert(formats_count > 0); - std::vector surface_formats(formats_count); - Assert(vkGetPhysicalDeviceSurfaceFormatsKHR(backend.physicalDevice, presentInfo.surface, &formats_count, - &surface_formats[0]) + std::vector surface_formats( + formats_count, VkSurfaceFormat2KHR{ + .sType = VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR, .pNext = nullptr, .surfaceFormat = {}}); + Assert(vkGetPhysicalDeviceSurfaceFormats2KHR(backend.physicalDevice, &surface_info_2, &formats_count, + surface_formats.data()) == VK_SUCCESS); - log_debug(root, "vulkan: swapchain supports {} formats", formats_count); + log_info(root, "vulkan: swapchain supports {} formats", formats_count); for (auto& format : surface_formats) - log_debug(root, "- format = {}, colorspace = {}", GetFormatToString(format.format), - GetColorSpaceKHRToString(format.colorSpace)); + log_info(root, "- format = {}, colorspace = {}", GetFormatToString(format.surfaceFormat.format), + GetColorSpaceKHRToString(format.surfaceFormat.colorSpace)); - surfaceFormat = vulkan_swapchain_choose_surface_format(surface_formats, swapchainDesc.preferredFormat); + surface_format = vulkan_swapchain_choose_surface_format(surface_formats, swapchainDesc.preferredFormat); - if (surfaceFormat.format != swapchainDesc.preferredFormat.format - || surfaceFormat.colorSpace != swapchainDesc.preferredFormat.colorSpace) + if (surface_format.format != swapchainDesc.preferredFormat.format + || surface_format.colorSpace != swapchainDesc.preferredFormat.colorSpace) { log_warning(root, "vulkan: incompatible swapchain format: format = {}, colorspace = {}", GetFormatToString(swapchainDesc.preferredFormat.format), GetColorSpaceKHRToString(swapchainDesc.preferredFormat.colorSpace)); log_warning(root, "- falling back to: format = {}, colorspace = {}", - GetFormatToString(surfaceFormat.format), GetColorSpaceKHRToString(surfaceFormat.colorSpace)); + GetFormatToString(surface_format.format), GetColorSpaceKHRToString(surface_format.colorSpace)); } - presentInfo.view_format = vulkan_swapchain_view_format_override(surfaceFormat); + presentInfo.view_format = vulkan_swapchain_view_format_override(surface_format); log_debug(root, "vulkan: selecting swapchain format = {}, colorspace = {}", - GetFormatToString(surfaceFormat.format), GetColorSpaceKHRToString(surfaceFormat.colorSpace)); + GetFormatToString(surface_format.format), GetColorSpaceKHRToString(surface_format.colorSpace)); log_debug(root, "vulkan: selecting swapchain view format = {}", GetFormatToString(presentInfo.view_format)); } // Image count - uint32_t imageCount = swapchainDesc.preferredImageCount; + uint32_t image_count = swapchainDesc.preferredImageCount; { - log_debug(root, "vulkan: swapchain image count support: min = {}, max = {}", surfaceCaps.minImageCount, - surfaceCaps.maxImageCount); + log_debug(root, "vulkan: swapchain image count support: min = {}, max = {}", surface_caps.minImageCount, + surface_caps.maxImageCount); - if (imageCount < surfaceCaps.minImageCount) - imageCount = surfaceCaps.minImageCount; + if (image_count < surface_caps.minImageCount) + image_count = surface_caps.minImageCount; // Max count might be zero when uncapped - if (imageCount > surfaceCaps.maxImageCount && surfaceCaps.maxImageCount > 0) - imageCount = surfaceCaps.maxImageCount; + if (image_count > surface_caps.maxImageCount && surface_caps.maxImageCount > 0) + image_count = surface_caps.maxImageCount; - if (imageCount != swapchainDesc.preferredImageCount) + if (image_count != swapchainDesc.preferredImageCount) { log_warning(root, "vulkan: swapchain image count {} is unsupported. falling back to {}", - swapchainDesc.preferredImageCount, imageCount); + swapchainDesc.preferredImageCount, image_count); } - Assert(imageCount >= 2, "Swapchain should support at least double-buffering"); - Assert(imageCount <= 5, "Swapchain image count too large"); + Assert(image_count >= 2, "Swapchain should support at least double-buffering"); + Assert(image_count <= 5, "Swapchain image count too large"); - presentInfo.imageCount = imageCount; + presentInfo.image_count = image_count; } { @@ -235,11 +250,11 @@ void configure_vulkan_wm_swapchain(ReaperRoot& root, const VulkanBackend& backen for (auto& mode : availablePresentModes) log_debug(root, "- {}", GetPresentModeKHRToString(mode)); - presentInfo.presentMode = vulkan_swapchain_choose_present_mode(availablePresentModes); + presentInfo.present_mode = vulkan_swapchain_choose_present_mode(availablePresentModes); } { - VkExtent2D extent = vulkan_swapchain_choose_extent(surfaceCaps, swapchainDesc.preferredExtent); + VkExtent2D extent = vulkan_swapchain_choose_extent(surface_caps, swapchainDesc.preferredExtent); if (extent.width != swapchainDesc.preferredExtent.width || extent.height != swapchainDesc.preferredExtent.height) @@ -248,7 +263,7 @@ void configure_vulkan_wm_swapchain(ReaperRoot& root, const VulkanBackend& backen swapchainDesc.preferredExtent.height); log_warning(root, "- falling back to {}x{}", extent.width, extent.height); } - presentInfo.surfaceExtent = extent; + presentInfo.surface_extent = extent; } // Usage flags @@ -256,11 +271,11 @@ void configure_vulkan_wm_swapchain(ReaperRoot& root, const VulkanBackend& backen // and might trigger a validation warning down the line. // I suspect this is primarily done for frame capture purposes, like adding TRANSFER_SRC to allow copies. // It should be safe to ignore in this case. - presentInfo.swapchainUsageFlags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; - Assert((surfaceCaps.supportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) != 0, "Vulkan API error"); + presentInfo.swapchain_usage_flags = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT; + Assert((surface_caps.supportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) != 0, "Vulkan API error"); // Transform - presentInfo.transform = vulkan_swapchain_choose_transform(surfaceCaps); + presentInfo.surface_transform = vulkan_swapchain_choose_transform(surface_caps); } void create_vulkan_wm_swapchain(ReaperRoot& root, const VulkanBackend& backend, PresentationInfo& presentInfo) @@ -268,47 +283,59 @@ void create_vulkan_wm_swapchain(ReaperRoot& root, const VulkanBackend& backend, REAPER_PROFILE_SCOPE_FUNC(); log_debug(root, "vulkan: creating wm swapchain"); -#if 0 - VkSurfaceFullScreenExclusiveInfoEXT fullscreen_info = { - VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_INFO_EXT, - nullptr, - VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT, - }; -#endif - const std::vector view_formats = { - presentInfo.surfaceFormat.format, // Usual format if the swapchain was immutable - presentInfo.view_format, // Format to use the mutable feature with + presentInfo.surface_format.format, // Usual format if the swapchain was immutable + presentInfo.view_format, // Format to use the mutable feature with }; - const VkImageFormatListCreateInfo format_list = { + VkImageFormatListCreateInfo format_list = { .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO, -#if 0 - .pNext = &fullscreen_info, -#else .pNext = nullptr, -#endif .viewFormatCount = static_cast(view_formats.size()), .pViewFormats = view_formats.data(), }; +#if REAPER_WINDOWS_HDR_TEST + Win32Window* win32Window = dynamic_cast(root.renderer->window); + + const VkSurfaceFullScreenExclusiveWin32InfoEXT fullscreen_exclusive_win32_info = { + .sType = VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_WIN32_INFO_EXT, + .pNext = nullptr, + .hmonitor = MonitorFromWindow(win32Window->m_handle, MONITOR_DEFAULTTOPRIMARY), + }; + + const VkSurfaceFullScreenExclusiveInfoEXT fullscreen_exclusive_info = { + .sType = VK_STRUCTURE_TYPE_SURFACE_FULL_SCREEN_EXCLUSIVE_INFO_EXT, + .pNext = &fullscreen_exclusive_win32_info, + .fullScreenExclusive = VK_FULL_SCREEN_EXCLUSIVE_APPLICATION_CONTROLLED_EXT, + }; + + const VkSwapchainDisplayNativeHdrCreateInfoAMD display_native_hdr_amd_info = { + .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_DISPLAY_NATIVE_HDR_CREATE_INFO_AMD, + .pNext = &fullscreen_exclusive_info, + .localDimmingEnable = false, // FIXME + }; + + format_list.pNext = &display_native_hdr_amd_info, +#endif + VkSwapchainCreateInfoKHR swap_chain_create_info = { .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, .pNext = &format_list, .flags = VK_SWAPCHAIN_CREATE_MUTABLE_FORMAT_BIT_KHR, .surface = presentInfo.surface, - .minImageCount = presentInfo.imageCount, - .imageFormat = presentInfo.surfaceFormat.format, - .imageColorSpace = presentInfo.surfaceFormat.colorSpace, - .imageExtent = presentInfo.surfaceExtent, + .minImageCount = presentInfo.image_count, + .imageFormat = presentInfo.surface_format.format, + .imageColorSpace = presentInfo.surface_format.colorSpace, + .imageExtent = presentInfo.surface_extent, .imageArrayLayers = 1, - .imageUsage = presentInfo.swapchainUsageFlags, + .imageUsage = presentInfo.swapchain_usage_flags, .imageSharingMode = VK_SHARING_MODE_EXCLUSIVE, .queueFamilyIndexCount = 0, .pQueueFamilyIndices = nullptr, - .preTransform = presentInfo.transform, + .preTransform = presentInfo.surface_transform, .compositeAlpha = VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, - .presentMode = presentInfo.presentMode, + .presentMode = presentInfo.present_mode, .clipped = VK_TRUE, .oldSwapchain = presentInfo.swapchain, }; @@ -320,21 +347,21 @@ void create_vulkan_wm_swapchain(ReaperRoot& root, const VulkanBackend& backend, Assert(vkGetSwapchainImagesKHR(backend.device, presentInfo.swapchain, &actualImageCount, nullptr) == VK_SUCCESS); Assert(actualImageCount > 0); - Assert(actualImageCount >= presentInfo.imageCount, "Invalid swapchain image count returned"); + Assert(actualImageCount >= presentInfo.image_count, "Invalid swapchain image count returned"); presentInfo.images.resize(actualImageCount); Assert(vkGetSwapchainImagesKHR(backend.device, presentInfo.swapchain, &actualImageCount, &presentInfo.images[0]) == VK_SUCCESS); - if (actualImageCount != presentInfo.imageCount) + if (actualImageCount != presentInfo.image_count) { - log_warning(root, "vulkan: {} swapchain images were asked but we got {}", presentInfo.imageCount, + log_warning(root, "vulkan: {} swapchain images were asked but we got {}", presentInfo.image_count, actualImageCount); } // Since we don't control which swapchain image index we'll get when acquiring one, // we have to use the full amount of swapchain we get back. - presentInfo.imageCount = actualImageCount; + presentInfo.image_count = actualImageCount; VkSemaphoreCreateInfo semaphore_create_info = { VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, // VkStructureType sType @@ -389,8 +416,8 @@ void resize_vulkan_wm_swapchain(ReaperRoot& root, const VulkanBackend& backend, // Reconfigure even if we know most of what we expect/need SwapchainDescriptor swapchainDesc; - swapchainDesc.preferredImageCount = presentInfo.imageCount; - swapchainDesc.preferredFormat = presentInfo.surfaceFormat; + swapchainDesc.preferredImageCount = presentInfo.image_count; + swapchainDesc.preferredFormat = presentInfo.surface_format; swapchainDesc.preferredExtent = {extent.width, extent.height}; // New extent configure_vulkan_wm_swapchain(root, backend, swapchainDesc, presentInfo); @@ -409,13 +436,13 @@ void resize_vulkan_wm_swapchain(ReaperRoot& root, const VulkanBackend& backend, void create_swapchain_views(const VulkanBackend& backend, PresentationInfo& presentInfo) { - const size_t imgCount = presentInfo.imageCount; + const size_t image_count = presentInfo.image_count; - Assert(imgCount > 0); + Assert(image_count > 0); - presentInfo.imageViews.resize(imgCount); + presentInfo.imageViews.resize(image_count); - for (size_t i = 0; i < imgCount; ++i) + for (size_t i = 0; i < image_count; ++i) { VkImageViewCreateInfo image_view_create_info = { VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO, // VkStructureType sType diff --git a/src/renderer/vulkan/renderpass/SwapchainPass.cpp b/src/renderer/vulkan/renderpass/SwapchainPass.cpp index 65a58ae8..c72341be 100644 --- a/src/renderer/vulkan/renderpass/SwapchainPass.cpp +++ b/src/renderer/vulkan/renderpass/SwapchainPass.cpp @@ -121,8 +121,8 @@ namespace SpecConstants spec_constants; spec_constants.transfer_function_index = - get_transfer_function(backend.presentInfo.surfaceFormat, backend.presentInfo.view_format); - spec_constants.color_space_index = get_color_space(backend.presentInfo.surfaceFormat.colorSpace); + get_transfer_function(backend.presentInfo.surface_format, backend.presentInfo.view_format); + spec_constants.color_space_index = get_color_space(backend.presentInfo.surface_format.colorSpace); spec_constants.tonemap_function_index = TONEMAP_FUNC_NONE; VkSpecializationInfo specialization = { diff --git a/src/renderer/vulkan/renderpass/TestGraphics.cpp b/src/renderer/vulkan/renderpass/TestGraphics.cpp index bdd12958..84666219 100644 --- a/src/renderer/vulkan/renderpass/TestGraphics.cpp +++ b/src/renderer/vulkan/renderpass/TestGraphics.cpp @@ -90,15 +90,15 @@ void resize_swapchain(ReaperRoot& root, VulkanBackend& backend) REAPER_PROFILE_SCOPE_FUNC(); // Resize swapchain if necessary - if (backend.new_swapchain_extent.width != 0) + if (backend.new_swapchain_extent.width != 0 || backend.new_swapchain_extent.height != 0) { vkQueueWaitIdle(backend.deviceInfo.presentQueue); // FIXME Assert(backend.new_swapchain_extent.height > 0); resize_vulkan_wm_swapchain(root, backend, backend.presentInfo, backend.new_swapchain_extent); - const glm::uvec2 new_swapchain_extent(backend.presentInfo.surfaceExtent.width, - backend.presentInfo.surfaceExtent.height); + const glm::uvec2 new_swapchain_extent(backend.presentInfo.surface_extent.width, + backend.presentInfo.surface_extent.height); backend.new_swapchain_extent.width = 0; backend.new_swapchain_extent.height = 0; @@ -196,7 +196,7 @@ void backend_execute_frame(ReaperRoot& root, VulkanBackend& backend, CommandBuff Assert(vkResetFences(backend.device, 1, &drawFence) == VK_SUCCESS); } - const VkExtent2D backbufferExtent = backend.presentInfo.surfaceExtent; + const VkExtent2D backbufferExtent = backend.presentInfo.surface_extent; FrameData frame_data = {}; frame_data.backbufferExtent = backbufferExtent; @@ -214,26 +214,6 @@ void backend_execute_frame(ReaperRoot& root, VulkanBackend& backend, CommandBuff upload_audio_frame_resources(backend, prepared, resources.audio_resources); } -#if 0 - VkHdrMetadataEXT hdrMetaData = {}; - hdrMetaData.sType = VK_STRUCTURE_TYPE_HDR_METADATA_EXT, hdrMetaData.pNext = nullptr, - hdrMetaData.displayPrimaryRed.x = 0.708f; - hdrMetaData.displayPrimaryRed.y = 0.292f; - hdrMetaData.displayPrimaryGreen.x = 0.170f; - hdrMetaData.displayPrimaryGreen.y = 0.797f; - hdrMetaData.displayPrimaryBlue.x = 0.131f; - hdrMetaData.displayPrimaryBlue.y = 0.046f; - hdrMetaData.minLuminance = 0.0f; - hdrMetaData.maxLuminance = - 10000.0f; // This will cause tonemapping to happen on display end as long as it's greater than display's actual - // queried max luminance. The look will change and it will be display dependent! - hdrMetaData.maxContentLightLevel = 10000.0f; - hdrMetaData.maxFrameAverageLightLevel = - 400.0f; // max and average content light level data will be used to do tonemapping on display - - vkSetHdrMetadataEXT(backend.device, 1, &backend.presentInfo.swapchain, &hdrMetaData); -#endif - FrameGraph::FrameGraph framegraph; using namespace FrameGraph; @@ -1439,7 +1419,7 @@ void backend_execute_frame(ReaperRoot& root, VulkanBackend& backend, CommandBuff if (presentResult == VK_SUBOPTIMAL_KHR) { - backend.new_swapchain_extent = backend.presentInfo.surfaceExtent; + backend.new_swapchain_extent = backend.presentInfo.surface_extent; log_warning(root, "vulkan: present returned 'VK_SUBOPTIMAL_KHR' requesting swapchain re-creation"); } else if (presentResult == VK_ERROR_OUT_OF_DATE_KHR) diff --git a/src/vulkan_loader/CMakeLists.txt b/src/vulkan_loader/CMakeLists.txt index b1ba9031..4d0cedbb 100644 --- a/src/vulkan_loader/CMakeLists.txt +++ b/src/vulkan_loader/CMakeLists.txt @@ -34,7 +34,9 @@ find_package(Vulkan 1.3 REQUIRED) # Get the shared library name for each platform get_filename_component(REAPER_VK_LIB_NAME ${Vulkan_LIBRARY} NAME_WLE) -target_compile_definitions(${target} PUBLIC REAPER_VK_LIB_NAME="${REAPER_VK_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}") +target_compile_definitions(${target} PUBLIC + REAPER_VK_LIB_NAME="${REAPER_VK_LIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}" + REAPER_WINDOWS_HDR_TEST=0) target_link_libraries(${target} PUBLIC Vulkan::Headers diff --git a/src/vulkan_loader/SymbolHelper.inl b/src/vulkan_loader/SymbolHelper.inl index e1d012ea..c1ef06f1 100644 --- a/src/vulkan_loader/SymbolHelper.inl +++ b/src/vulkan_loader/SymbolHelper.inl @@ -190,7 +190,8 @@ REAPER_VK_DEVICE_LEVEL_FUNCTION(vkCmdSetViewportWithCount); # include "extension/VK_KHR_display.inl" #endif -#if 0 +#if REAPER_WINDOWS_HDR_TEST +# include "extension/VK_AMD_display_native_hdr.inl" # include "extension/VK_EXT_full_screen_exclusive.inl" # include "extension/VK_EXT_hdr_metadata.inl" #endif