radv: rework dynamic viewports/scissors support
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 30 Jun 2020 08:38:11 +0000 (10:38 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 13 Jul 2020 08:31:54 +0000 (08:31 +0000)
The number of viewports/scissors is currently static because it can
only be specified at pipeline creation, but it doesn't hurt to
assume it's dynamic. Will help for supporting setting the number
of viewports/scissors dynamically.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5718>

src/amd/vulkan/radv_cmd_buffer.c
src/amd/vulkan/radv_meta.c

index fd8400e9b7e0b224a73d103a5038bdc8c20ff8c6..723a94c8192955c3cae41ff08548814b7123bc96 100644 (file)
@@ -106,15 +106,11 @@ radv_bind_dynamic_state(struct radv_cmd_buffer *cmd_buffer,
        uint32_t copy_mask = src->mask;
        uint32_t dest_mask = 0;
 
-       /* Make sure to copy the number of viewports/scissors because they can
-        * only be specified at pipeline creation time.
-        */
-       dest->viewport.count = src->viewport.count;
-       dest->scissor.count = src->scissor.count;
        dest->discard_rectangle.count = src->discard_rectangle.count;
        dest->sample_location.count = src->sample_location.count;
 
        if (copy_mask & RADV_DYNAMIC_VIEWPORT) {
+               dest->viewport.count = src->viewport.count;
                if (memcmp(&dest->viewport.viewports, &src->viewport.viewports,
                           src->viewport.count * sizeof(VkViewport))) {
                        typed_memcpy(dest->viewport.viewports,
@@ -125,6 +121,7 @@ radv_bind_dynamic_state(struct radv_cmd_buffer *cmd_buffer,
        }
 
        if (copy_mask & RADV_DYNAMIC_SCISSOR) {
+               dest->scissor.count = src->scissor.count;
                if (memcmp(&dest->scissor.scissors, &src->scissor.scissors,
                           src->scissor.count * sizeof(VkRect2D))) {
                        typed_memcpy(dest->scissor.scissors,
@@ -3956,11 +3953,15 @@ void radv_CmdSetViewport(
        assert(firstViewport < MAX_VIEWPORTS);
        assert(total_count >= 1 && total_count <= MAX_VIEWPORTS);
 
-       if (!memcmp(state->dynamic.viewport.viewports + firstViewport,
+       if (total_count <= state->dynamic.viewport.count &&
+           !memcmp(state->dynamic.viewport.viewports + firstViewport,
                    pViewports, viewportCount * sizeof(*pViewports))) {
                return;
        }
 
+       if (state->dynamic.viewport.count < total_count)
+               state->dynamic.viewport.count = total_count;
+
        memcpy(state->dynamic.viewport.viewports + firstViewport, pViewports,
               viewportCount * sizeof(*pViewports));
 
@@ -3980,11 +3981,15 @@ void radv_CmdSetScissor(
        assert(firstScissor < MAX_SCISSORS);
        assert(total_count >= 1 && total_count <= MAX_SCISSORS);
 
-       if (!memcmp(state->dynamic.scissor.scissors + firstScissor, pScissors,
+       if (total_count <= state->dynamic.scissor.count &&
+           !memcmp(state->dynamic.scissor.scissors + firstScissor, pScissors,
                    scissorCount * sizeof(*pScissors))) {
                return;
        }
 
+       if (state->dynamic.scissor.count < total_count)
+               state->dynamic.scissor.count = total_count;
+
        memcpy(state->dynamic.scissor.scissors + firstScissor, pScissors,
               scissorCount * sizeof(*pScissors));
 
index f0156829526589e333b90d6bdc1f755de7d271a9..1fb32f94621d5ebc0280b54fb5f4c21cb21e5ba8 100644 (file)
@@ -62,15 +62,6 @@ radv_meta_save(struct radv_meta_saved_state *state,
                typed_memcpy(state->scissor.scissors,
                             cmd_buffer->state.dynamic.scissor.scissors,
                             MAX_SCISSORS);
-
-               /* The most common meta operations all want to have the
-                * viewport reset and any scissors disabled. The rest of the
-                * dynamic state should have no effect.
-                */
-               cmd_buffer->state.dynamic.viewport.count = 0;
-               cmd_buffer->state.dynamic.scissor.count = 0;
-               cmd_buffer->state.dirty |= 1 << VK_DYNAMIC_STATE_VIEWPORT |
-                                          1 << VK_DYNAMIC_STATE_SCISSOR;
        }
 
        if (state->flags & RADV_META_SAVE_SAMPLE_LOCATIONS) {