From faeca1c4bcb010797cd30191f0f132471b1a9b2e Mon Sep 17 00:00:00 2001 From: niki Date: Mon, 12 Sep 2022 13:46:03 +0200 Subject: [PATCH] vulkan: fix wrong image layout validation warnings --- src/modules/graphics/vulkan/Graphics.cpp | 52 +++++++++++++++--------- src/modules/graphics/vulkan/Graphics.h | 1 + src/modules/window/sdl/Window.cpp | 1 - 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index 3523567d4..c2e30c63c 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -1,14 +1,14 @@ -#include "Graphics.h" -#include "Buffer.h" -#include "GraphicsReadback.h" -#include "SDL_vulkan.h" -#include "window/Window.h" #include "common/Exception.h" -#include "Shader.h" -#include "graphics/Texture.h" -#include "Vulkan.h" -#include "common/version.h" #include "common/pixelformat.h" +#include "common/version.h" +#include "window/Window.h" +#include "Buffer.h" +#include "Graphics.h" +#include "GraphicsReadback.h" +#include "Shader.h" +#include "Vulkan.h" + +#include "SDL_vulkan.h" #include #include @@ -16,7 +16,6 @@ #include #include #include -#include #include @@ -356,6 +355,7 @@ bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int createSyncObjects(); createColorResources(); createDepthResources(); + transitionColorDepthLayouts = true; createDefaultRenderPass(); createDefaultFramebuffers(); createCommandPool(); @@ -402,12 +402,6 @@ bool Graphics::setMode(void *context, int width, int height, int pixelwidth, int drawCalls = 0; drawCallsBatched = 0; - Vulkan::cmdTransitionImageLayout( - commandBuffers.at(currentFrame), - depthImage, - VK_IMAGE_LAYOUT_UNDEFINED, - VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); - return true; } @@ -891,6 +885,24 @@ void Graphics::beginFrame() VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + if (transitionColorDepthLayouts) + { + Vulkan::cmdTransitionImageLayout( + commandBuffers.at(currentFrame), + depthImage, + VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL); + + if (colorImage) + Vulkan::cmdTransitionImageLayout( + commandBuffers.at(currentFrame), + colorImage, + VK_IMAGE_LAYOUT_UNDEFINED, + VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); + + transitionColorDepthLayouts = false; + } + Vulkan::resetShaderSwitches(); usedShadersInFrame.clear(); @@ -1302,6 +1314,8 @@ void Graphics::createLogicalDevice() optionalDeviceFeatures.memoryBudget = false; if (optionalDeviceFeatures.spirv14 && !optionalDeviceFeatures.shaderFloatControls) optionalDeviceFeatures.spirv14 = false; + if (optionalDeviceFeatures.spirv14 && VK_API_VERSION_1_1 > vulkanApiVersion) + optionalDeviceFeatures.spirv14 = false; VkPhysicalDeviceFeatures deviceFeatures{}; deviceFeatures.samplerAnisotropy = VK_TRUE; @@ -2248,10 +2262,6 @@ VkPipeline Graphics::createGraphicsPipeline(GraphicsPipelineConfiguration &confi multisampling.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO; multisampling.sampleShadingEnable = VK_FALSE; multisampling.rasterizationSamples = configuration.msaaSamples; - multisampling.minSampleShading = 1.0f; // Optional - multisampling.pSampleMask = nullptr; // Optional - multisampling.alphaToCoverageEnable = VK_FALSE; // Optional - multisampling.alphaToOneEnable = VK_FALSE; // Optional VkPipelineRasterizationStateCreateInfo rasterizer{}; rasterizer.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO; @@ -2660,6 +2670,8 @@ void Graphics::recreateSwapChain() createDepthResources(); createDefaultRenderPass(); createDefaultFramebuffers(); + + transitionColorDepthLayouts = true; } love::graphics::Graphics *createInstance() diff --git a/src/modules/graphics/vulkan/Graphics.h b/src/modules/graphics/vulkan/Graphics.h index c87798122..497781d50 100644 --- a/src/modules/graphics/vulkan/Graphics.h +++ b/src/modules/graphics/vulkan/Graphics.h @@ -437,6 +437,7 @@ private: size_t currentFrame = 0; uint32_t imageIndex = 0; bool framebufferResized = false; + bool transitionColorDepthLayouts = false; VmaAllocator vmaAllocator = VK_NULL_HANDLE; std::unique_ptr standardTexture = nullptr; // we need an array of draw buffers, since the frames are being rendered asynchronously diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index db3e575ae..aca41006a 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -1118,7 +1118,6 @@ void Window::setVSync(int vsync) SDL_GL_SetSwapInterval(1); } - // fixme: doesn't work for vulkan yet. #ifdef LOVE_GRAPHICS_VULKAN love::graphics::vulkan::Vulkan::setVsync(vsync); #endif