Skip to content

Commit

Permalink
Vulkan: More scissor dimension checks. See #15207
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Dec 7, 2021
1 parent 05429fc commit a2f9f68
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Common/GPU/Vulkan/VulkanQueueRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> 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);
Expand Down
9 changes: 7 additions & 2 deletions Common/GPU/Vulkan/VulkanRenderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
}

Expand All @@ -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 };
Expand Down

0 comments on commit a2f9f68

Please sign in to comment.