From 1eb4f1f1722a0382e84b809f07be6a2e19690ec8 Mon Sep 17 00:00:00 2001 From: slime Date: Sun, 25 Sep 2022 17:41:47 -0300 Subject: [PATCH] vulkan: flush batched draws before clear(). minor code cleanup. --- src/modules/graphics/vulkan/Graphics.cpp | 28 ++++++++++++++++-------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index d9474b2da..873d97f8a 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -115,6 +115,11 @@ love::graphics::Buffer *Graphics::newBuffer(const love::graphics::Buffer::Settin void Graphics::clear(OptionalColorD color, OptionalInt stencil, OptionalDouble depth) { + if (!color.hasValue && !stencil.hasValue && !depth.hasValue) + return; + + flushBatchedDraws(); + if (!renderPassState.active) startRenderPass(); @@ -163,6 +168,11 @@ void Graphics::clear(OptionalColorD color, OptionalInt stencil, OptionalDouble d void Graphics::clear(const std::vector &colors, OptionalInt stencil, OptionalDouble depth) { + if (colors.empty() && !stencil.hasValue && !depth.hasValue) + return; + + flushBatchedDraws(); + if (!renderPassState.active) startRenderPass(); @@ -188,12 +198,12 @@ void Graphics::clear(const std::vector &colors, OptionalInt sten if (stencil.hasValue) { - depthStencilAttachment.aspectMask = VK_IMAGE_ASPECT_STENCIL_BIT; + depthStencilAttachment.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT; depthStencilAttachment.clearValue.depthStencil.stencil = static_cast(stencil.value); } if (depth.hasValue) { - depthStencilAttachment.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + depthStencilAttachment.aspectMask |= VK_IMAGE_ASPECT_DEPTH_BIT; depthStencilAttachment.clearValue.depthStencil.depth = static_cast(depth.value); } @@ -1500,7 +1510,7 @@ QueueFamilyIndices Graphics::findQueueFamilies(VkPhysicalDevice device) int i = 0; for (const auto &queueFamily : queueFamilies) { - if (queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT && queueFamily.queueFlags & VK_QUEUE_COMPUTE_BIT) + if ((queueFamily.queueFlags & VK_QUEUE_GRAPHICS_BIT) && (queueFamily.queueFlags & VK_QUEUE_COMPUTE_BIT)) indices.graphicsFamily = i; VkBool32 presentSupport = false; @@ -1772,8 +1782,8 @@ void Graphics::createSwapChain() VkPresentModeKHR presentMode = chooseSwapPresentMode(swapChainSupport.presentModes); VkExtent2D extent = chooseSwapExtent(swapChainSupport.capabilities); - if (swapChainSupport.capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR || - swapChainSupport.capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) + if ((swapChainSupport.capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR) || + (swapChainSupport.capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR)) { uint32_t width, height; width = extent.width; @@ -1795,10 +1805,10 @@ void Graphics::createSwapChain() angle = -3.0f * PI / 2.0f; float data[] = { - cosf(angle), -sinf(angle), 0.0f, 0.0f, - sinf(angle), cosf(angle), 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f, + cosf(angle), -sinf(angle), 0.0f, 0.0f, + sinf(angle), cosf(angle), 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f, }; displayRotation = Matrix4(data);