From 18fb9d7d39dcf9ebeb38a2f933c2a278d0e6aeef Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Sun, 29 Oct 2023 18:20:08 -0400 Subject: [PATCH 1/3] [Vulkan] Better logging of rateDeviceSuitability failures --- lib/ivis_opengl/gfx_api_vk.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/ivis_opengl/gfx_api_vk.cpp b/lib/ivis_opengl/gfx_api_vk.cpp index a50f9a4719d..34eff8ff562 100644 --- a/lib/ivis_opengl/gfx_api_vk.cpp +++ b/lib/ivis_opengl/gfx_api_vk.cpp @@ -3430,42 +3430,49 @@ int rateDeviceSuitability(const vk::PhysicalDevice &device, const vk::SurfaceKHR // Requires: deviceProperties.apiVersion >= minSupportedVulkanVersion if (!VK_VERSION_GREATER_THAN_OR_EQUAL(deviceProperties.apiVersion, minSupportedVulkanVersion)) { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: Insufficient apiVersion (%s)", deviceProperties.deviceID, deviceProperties.deviceName.data(), VkhInfo::vulkan_apiversion_to_string(deviceProperties.apiVersion).c_str()); return 0; } // Requires: limits.maxDescriptorSetUniformBuffers >= minRequired_DescriptorSetUniformBuffers if (deviceProperties.limits.maxDescriptorSetUniformBuffers < minRequired_DescriptorSetUniformBuffers) { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: Insufficient maxDescriptorSetUniformBuffers (%" PRIu32 ")", deviceProperties.deviceID, deviceProperties.deviceName.data(), deviceProperties.limits.maxDescriptorSetUniformBuffers); return 0; } // Requires: limits.maxDescriptorSetUniformBuffersDynamic >= minRequired_DescriptorSetUniformBuffersDynamic if (deviceProperties.limits.maxDescriptorSetUniformBuffersDynamic < minRequired_DescriptorSetUniformBuffersDynamic) { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: Insufficient maxDescriptorSetUniformBuffersDynamic (%" PRIu32 ")", deviceProperties.deviceID, deviceProperties.deviceName.data(), deviceProperties.limits.maxDescriptorSetUniformBuffersDynamic); return 0; } // Requires: limits.maxBoundDescriptorSets >= minRequired_BoundDescriptorSets if (deviceProperties.limits.maxBoundDescriptorSets < minRequired_BoundDescriptorSets) { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: Insufficient maxBoundDescriptorSets (%" PRIu32 ")", deviceProperties.deviceID, deviceProperties.deviceName.data(), deviceProperties.limits.maxBoundDescriptorSets); return 0; } // Requires: limits.maxViewports >= minRequired_Viewports if (deviceProperties.limits.maxViewports < minRequired_Viewports) { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: Insufficient maxViewports (%" PRIu32 ")", deviceProperties.deviceID, deviceProperties.deviceName.data(), deviceProperties.limits.maxViewports); return 0; } // Requires: limits.maxColorAttachments >= minRequired_ColorAttachments if (deviceProperties.limits.maxColorAttachments < minRequired_ColorAttachments) { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: Insufficient maxColorAttachments (%" PRIu32 ")", deviceProperties.deviceID, deviceProperties.deviceName.data(), deviceProperties.limits.maxColorAttachments); return 0; } // Requires: samplerAnisotropy if (!deviceFeatures.samplerAnisotropy) { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: No samplerAnisotropy support", deviceProperties.deviceID, deviceProperties.deviceName.data()); return 0; } @@ -3479,6 +3486,7 @@ int rateDeviceSuitability(const vk::PhysicalDevice &device, const vk::SurfaceKHR QueueFamilyIndices indices = findQueueFamilies(device, surface, vkDynLoader); if (!indices.isComplete()) { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: Unable to find graphics + present queue families", deviceProperties.deviceID, deviceProperties.deviceName.data()); return 0; } if (indices.graphicsFamily.value() == indices.presentFamily.value()) @@ -3490,6 +3498,7 @@ int rateDeviceSuitability(const vk::PhysicalDevice &device, const vk::SurfaceKHR // Check that device supports `deviceExtensions` if (!checkDeviceExtensionSupport(device, deviceExtensions, vkDynLoader)) { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: Missing required device extension(s)", deviceProperties.deviceID, deviceProperties.deviceName.data()); return 0; } @@ -3498,11 +3507,20 @@ int rateDeviceSuitability(const vk::PhysicalDevice &device, const vk::SurfaceKHR SwapChainSupportDetails swapChainSupportDetails = querySwapChainSupport(device, surface, vkDynLoader); if (swapChainSupportDetails.formats.empty() || swapChainSupportDetails.presentModes.empty()) { + if (swapChainSupportDetails.formats.empty()) + { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: Empty swapchain formats?", deviceProperties.deviceID, deviceProperties.deviceName.data()); + } + if (swapChainSupportDetails.presentModes.empty()) + { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: Empty swapchain presentModes?", deviceProperties.deviceID, deviceProperties.deviceName.data()); + } return 0; } } - catch (const vk::SystemError&) + catch (const vk::SystemError& e) { + debug(LOG_3D, "Excluding deviceID [%" PRIu32 "] (%s) because: querySwapChainSupport failed with error: %s", deviceProperties.deviceID, deviceProperties.deviceName.data(), e.what()); return 0; } From e90fa52d3b4603c6eba4e97d9cd0fa0ffa9d4dc3 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Mon, 30 Oct 2023 18:13:47 -0400 Subject: [PATCH 2/3] debug: Prevent FATAL error from being overwritten in popup --- lib/framework/debug.cpp | 2 +- lib/framework/wzapp.h | 2 +- lib/sdl/main_sdl.cpp | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/framework/debug.cpp b/lib/framework/debug.cpp index b9444143d1e..d8b22ce8d2a 100644 --- a/lib/framework/debug.cpp +++ b/lib/framework/debug.cpp @@ -580,7 +580,7 @@ void _debug(int line, code_part part, const char *function, const char *str, ... { if (wzIsFullscreen()) { - wzChangeWindowMode(WINDOW_MODE::windowed); + wzChangeWindowMode(WINDOW_MODE::windowed, true); } #if defined(WZ_OS_WIN) char wbuf[MAX_LEN_LOG_LINE+512]; diff --git a/lib/framework/wzapp.h b/lib/framework/wzapp.h index a91f39dc2f7..a45a20516ba 100644 --- a/lib/framework/wzapp.h +++ b/lib/framework/wzapp.h @@ -86,7 +86,7 @@ WINDOW_MODE wzGetNextWindowMode(WINDOW_MODE currentMode); WINDOW_MODE wzAltEnterToggleFullscreen(); bool wzSetToggleFullscreenMode(WINDOW_MODE fullscreenMode); WINDOW_MODE wzGetToggleFullscreenMode(); -bool wzChangeWindowMode(WINDOW_MODE mode); +bool wzChangeWindowMode(WINDOW_MODE mode, bool silent = false); WINDOW_MODE wzGetCurrentWindowMode(); bool wzIsFullscreen(); void wzSetWindowIsResizable(bool resizable); diff --git a/lib/sdl/main_sdl.cpp b/lib/sdl/main_sdl.cpp index b5fb3f2a7c8..4a7ac1bd383 100644 --- a/lib/sdl/main_sdl.cpp +++ b/lib/sdl/main_sdl.cpp @@ -676,7 +676,7 @@ WINDOW_MODE wzGetToggleFullscreenMode() return altEnterToggleFullscreenMode; } -bool wzChangeWindowMode(WINDOW_MODE mode) +bool wzChangeWindowMode(WINDOW_MODE mode, bool silent) { auto currMode = wzGetCurrentWindowMode(); if (currMode == mode) @@ -691,7 +691,10 @@ bool wzChangeWindowMode(WINDOW_MODE mode) return false; } - debug(LOG_INFO, "Changing window mode: %s -> %s", to_display_string(currMode).c_str(), to_display_string(mode).c_str()); + if (!silent) + { + debug(LOG_INFO, "Changing window mode: %s -> %s", to_display_string(currMode).c_str(), to_display_string(mode).c_str()); + } int sdl_result = -1; switch (mode) From 11399ee6845dd19e478d0ec64c385c3d60d2a755 Mon Sep 17 00:00:00 2001 From: past-due <30942300+past-due@users.noreply.github.com> Date: Mon, 30 Oct 2023 18:23:22 -0400 Subject: [PATCH 3/3] [Vulkan] Fix: Apply MSAA only to the scene framebuffer --- lib/ivis_opengl/gfx_api_vk.cpp | 12 ++++++------ lib/ivis_opengl/gfx_api_vk.h | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ivis_opengl/gfx_api_vk.cpp b/lib/ivis_opengl/gfx_api_vk.cpp index 34eff8ff562..51d29ccaa52 100644 --- a/lib/ivis_opengl/gfx_api_vk.cpp +++ b/lib/ivis_opengl/gfx_api_vk.cpp @@ -2707,13 +2707,13 @@ static bool createDepthStencilImage(const vk::PhysicalDevice& physicalDevice, co void VkRoot::createDefaultRenderpass(vk::Format swapchainFormat, vk::Format depthFormat) { - bool msaaEnabled = false; // default render pass doesn't get MSAA + bool msaaEnabled = (msaaSamplesSwapchain != vk::SampleCountFlagBits::e1); auto attachments = std::vector{ vk::AttachmentDescription() // colorAttachment .setFormat(swapchainFormat) - .setSamples(msaaSamples) + .setSamples(msaaSamplesSwapchain) .setInitialLayout(vk::ImageLayout::eUndefined) .setFinalLayout((msaaEnabled) ? vk::ImageLayout::eColorAttachmentOptimal : vk::ImageLayout::ePresentSrcKHR) .setLoadOp(vk::AttachmentLoadOp::eClear) @@ -2722,7 +2722,7 @@ void VkRoot::createDefaultRenderpass(vk::Format swapchainFormat, vk::Format dept .setStencilStoreOp(vk::AttachmentStoreOp::eStore), vk::AttachmentDescription() // depthAttachment .setFormat(depthFormat) - .setSamples(msaaSamples) + .setSamples(msaaSamplesSwapchain) .setInitialLayout(vk::ImageLayout::eDepthStencilAttachmentOptimal) .setFinalLayout(vk::ImageLayout::eDepthStencilAttachmentOptimal) .setLoadOp(vk::AttachmentLoadOp::eClear) @@ -2790,7 +2790,7 @@ void VkRoot::createDefaultRenderpass(vk::Format swapchainFormat, vk::Format dept renderPasses[DEFAULT_RENDER_PASS_ID].rp_compat_info = std::make_shared(createInfo); renderPasses[DEFAULT_RENDER_PASS_ID].rp = dev.createRenderPass(createInfo, nullptr, vkDynLoader); - renderPasses[DEFAULT_RENDER_PASS_ID].msaaSamples = (msaaEnabled) ? msaaSamples : vk::SampleCountFlagBits::e1; + renderPasses[DEFAULT_RENDER_PASS_ID].msaaSamples = msaaSamplesSwapchain; // createFramebuffers for default render pass ASSERT(!swapchainImageView.empty(), "No swapchain image views?"); @@ -4231,7 +4231,7 @@ bool VkRoot::createSwapchain() // createColorResources vk::Format colorFormat = surfaceFormat.format; - if (!createColorAttachmentImage(physicalDevice, memprops, dev, swapchainSize, msaaSamples, colorFormat, + if (!createColorAttachmentImage(physicalDevice, memprops, dev, swapchainSize, msaaSamplesSwapchain, colorFormat, colorImage, colorImageMemory, colorImageView, vkDynLoader)) { debug(LOG_ERROR, "Failed to create MSAA color attachment image"); @@ -4241,7 +4241,7 @@ bool VkRoot::createSwapchain() // createDepthStencilImage vk::Format depthFormat = findDepthStencilFormat(physicalDevice, vkDynLoader); debug(LOG_3D, "Using depth buffer format: %s", to_string(depthFormat).c_str()); - if (!createDepthStencilImage(physicalDevice, memprops, dev, swapchainSize, msaaSamples, depthFormat, + if (!createDepthStencilImage(physicalDevice, memprops, dev, swapchainSize, msaaSamplesSwapchain, depthFormat, depthStencilImage, depthStencilMemory, depthStencilView, vkDynLoader)) { debug(LOG_ERROR, "Failed to create depth stencil image"); diff --git a/lib/ivis_opengl/gfx_api_vk.h b/lib/ivis_opengl/gfx_api_vk.h index 5f2d19d81d8..e740a241a34 100644 --- a/lib/ivis_opengl/gfx_api_vk.h +++ b/lib/ivis_opengl/gfx_api_vk.h @@ -649,7 +649,8 @@ struct VkRoot final : gfx_api::context uint32_t currentSwapchainIndex = 0; std::vector swapchainImageView; - vk::SampleCountFlagBits msaaSamples = vk::SampleCountFlagBits::e1; + vk::SampleCountFlagBits msaaSamples = vk::SampleCountFlagBits::e1; // msaaSamples used for scene + vk::SampleCountFlagBits msaaSamplesSwapchain = vk::SampleCountFlagBits::e1; // msaaSamples used for swapchain assets (should generally be 1) vk::Image colorImage; vk::DeviceMemory colorImageMemory; vk::ImageView colorImageView;