From e1b12b49e6af928ca86f35dd5c3cc4007e85080a Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 30 Jan 2023 20:11:53 -0600 Subject: [PATCH] vulkan: Allow scissors or viewports to be set without counts This is unlikely but can happen if you have the following sequence: 1. vkCmdSetScissors() 2. No pipeline bind 3. vkCmdClearImage() which causes a meta save 4. Meta restore with vk_cmd_set_dynamic_graphics_state() In that case, we don't have scissor counts but need to restore the scissors set with `vkCmdSetScissors()` before the meta save. We can safely copy all of them, it's just more memory traffic than maybe we'd like. Fortunately, this can only happen at the start of a command buffer and only with a fairly silly sequence of commands. Part-of: --- src/vulkan/runtime/vk_graphics_state.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/vulkan/runtime/vk_graphics_state.c b/src/vulkan/runtime/vk_graphics_state.c index 04114fe3362..1074fce2f79 100644 --- a/src/vulkan/runtime/vk_graphics_state.c +++ b/src/vulkan/runtime/vk_graphics_state.c @@ -1882,14 +1882,18 @@ vk_dynamic_graphics_state_copy(struct vk_dynamic_graphics_state *dst, COPY_IF_SET(VP_VIEWPORT_COUNT, vp.viewport_count); if (IS_SET_IN_SRC(VP_VIEWPORTS)) { - assert(IS_SET_IN_SRC(VP_VIEWPORT_COUNT)); - COPY_ARRAY(VP_VIEWPORTS, vp.viewports, src->vp.viewport_count); + if (likely(IS_SET_IN_SRC(VP_VIEWPORT_COUNT))) + COPY_ARRAY(VP_VIEWPORTS, vp.viewports, src->vp.viewport_count); + else + COPY_ARRAY(VP_VIEWPORTS, vp.viewports, MESA_VK_MAX_VIEWPORTS); } COPY_IF_SET(VP_SCISSOR_COUNT, vp.scissor_count); if (IS_SET_IN_SRC(VP_SCISSORS)) { - assert(IS_SET_IN_SRC(VP_SCISSOR_COUNT)); - COPY_ARRAY(VP_SCISSORS, vp.scissors, src->vp.scissor_count); + if (likely(IS_SET_IN_SRC(VP_SCISSOR_COUNT))) + COPY_ARRAY(VP_SCISSORS, vp.scissors, src->vp.scissor_count); + else + COPY_ARRAY(VP_SCISSORS, vp.scissors, MESA_VK_MAX_SCISSORS); } COPY_IF_SET(VP_DEPTH_CLIP_NEGATIVE_ONE_TO_ONE,