Skip to content

Commit

Permalink
vulkan: rework swapchain creation code
Browse files Browse the repository at this point in the history
Save windows WIP hdr test as REAPER_WINDOWS_HDR_TEST.
Make use of newer functions for swapchain properties queries.
Renamed most fields as well.
  • Loading branch information
Ryp committed Aug 10, 2023
1 parent 15ecf9d commit 64c7669
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 139 deletions.
2 changes: 1 addition & 1 deletion src/GameLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
23 changes: 22 additions & 1 deletion src/renderer/ExecuteFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/renderer/vulkan/Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ void create_vulkan_renderer_backend(ReaperRoot& root, VulkanBackend& backend)

std::vector<const char*> 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");
Expand Down
14 changes: 7 additions & 7 deletions src/renderer/vulkan/Backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
221 changes: 124 additions & 97 deletions src/renderer/vulkan/Swapchain.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/renderer/vulkan/renderpass/SwapchainPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
30 changes: 5 additions & 25 deletions src/renderer/vulkan/renderpass/TestGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/vulkan_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/vulkan_loader/SymbolHelper.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 64c7669

Please sign in to comment.