From a2f9f68565e52eb1cfd5722fd413de478cfb7cf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 7 Dec 2021 21:46:10 +0100 Subject: [PATCH] Vulkan: More scissor dimension checks. See #15207 --- Common/GPU/Vulkan/VulkanQueueRunner.cpp | 2 ++ Common/GPU/Vulkan/VulkanRenderManager.h | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanQueueRunner.cpp b/Common/GPU/Vulkan/VulkanQueueRunner.cpp index a44d02167ac2..d6575c4cc69b 100644 --- a/Common/GPU/Vulkan/VulkanQueueRunner.cpp +++ b/Common/GPU/Vulkan/VulkanQueueRunner.cpp @@ -1337,6 +1337,8 @@ void VulkanQueueRunner::PerformRenderPass(const VKRStep &step, VkCommandBuffer c } else { // Rendering to backbuffer. Might need to rotate. const VkRect2D &rc = c.scissor.scissor; + _dbg_assert_(rc.offset.x >= 0); + _dbg_assert_(rc.offset.y >= 0); DisplayRect rotated_rc{ rc.offset.x, rc.offset.y, (int)rc.extent.width, (int)rc.extent.height }; RotateRectToDisplay(rotated_rc, vulkan_->GetBackbufferWidth(), vulkan_->GetBackbufferHeight()); _dbg_assert_(rotated_rc.x >= 0); diff --git a/Common/GPU/Vulkan/VulkanRenderManager.h b/Common/GPU/Vulkan/VulkanRenderManager.h index ec4f701d8dd6..d707c5479b79 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.h +++ b/Common/GPU/Vulkan/VulkanRenderManager.h @@ -291,6 +291,8 @@ class VulkanRenderManager { void SetScissor(VkRect2D rc) { _dbg_assert_(curRenderStep_ && curRenderStep_->stepType == VKRStepType::RENDER); + _dbg_assert_((int)rc.offset.x >= 0); + _dbg_assert_((int)rc.offset.y >= 0); _dbg_assert_((int)rc.extent.width >= 0); _dbg_assert_((int)rc.extent.height >= 0); @@ -300,7 +302,7 @@ class VulkanRenderManager { rc.extent.width = std::max(1, newWidth); if (rc.offset.x >= curWidth_) { // Fallback. - rc.offset.x = curWidth_ - rc.extent.width; + rc.offset.x = std::max(0, curWidth_ - (int)rc.extent.width); } } @@ -309,9 +311,12 @@ class VulkanRenderManager { rc.extent.height = std::max(1, newHeight); if (rc.offset.y >= curHeight_) { // Fallback. - rc.offset.y = curHeight_ - rc.extent.height; + rc.offset.y = std::max(0, curHeight_ - (int)rc.extent.height); } } + + // TODO: If any of the dimensions are now zero, we should flip a flag and not do draws, probably. + curRenderArea_.Apply(rc); VkRenderData data{ VKRRenderCommand::SCISSOR };