radv: save/restore all viewports/scissors for meta operations
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 25 Sep 2017 12:02:49 +0000 (14:02 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 25 Sep 2017 18:31:55 +0000 (20:31 +0200)
This is needed since we don't update the number of viewports/scissors
when they are set dynamically (according to the spec). In the following
scenario:

* vkCmdSetViewport()
* vkCmdClearColorImage() (or any other meta operations)

The viewports/scissors weren't saved correctly because no pipeline
was bound before, and thus the number of viewports/scissors were 0.

This fixes a regression with:

dEQP-VK.draw.negative_viewport_height.front_ccw_cull_back

Fixes: 60878dd00c ("radv: do not update the number of viewports in vkCmdSetViewport()")
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_meta.c
src/amd/vulkan/radv_meta.h
src/amd/vulkan/radv_private.h

index b17076703aef59fd78081eedf98f7effa000a26b..2e16c9b9f462dd56fc8cb1f48abf6db07f39f514 100644 (file)
 
 static void
 radv_meta_save_novertex(struct radv_meta_saved_state *state,
-              const struct radv_cmd_buffer *cmd_buffer,
-              uint32_t dynamic_mask)
+                       const struct radv_cmd_buffer *cmd_buffer)
 {
        state->old_pipeline = cmd_buffer->state.pipeline;
        state->old_descriptor_set0 = cmd_buffer->state.descriptors[0];
 
-       state->dynamic_mask = dynamic_mask;
-       radv_dynamic_state_copy(&state->dynamic, &cmd_buffer->state.dynamic,
-                               dynamic_mask);
+       /* Save all viewports. */
+       state->viewport.count = cmd_buffer->state.dynamic.viewport.count;
+       typed_memcpy(state->viewport.viewports,
+                    cmd_buffer->state.dynamic.viewport.viewports,
+                    MAX_VIEWPORTS);
+
+       /* Save all scissors. */
+       state->scissor.count = cmd_buffer->state.dynamic.scissor.count;
+       typed_memcpy(state->scissor.scissors,
+                    cmd_buffer->state.dynamic.scissor.scissors,
+                    MAX_SCISSORS);
 
        memcpy(state->push_constants, cmd_buffer->push_constants, MAX_PUSH_CONSTANTS_SIZE);
 }
@@ -55,9 +62,20 @@ radv_meta_restore(const struct radv_meta_saved_state *state,
 
        cmd_buffer->state.dirty |= RADV_CMD_DIRTY_PIPELINE;
 
-       radv_dynamic_state_copy(&cmd_buffer->state.dynamic, &state->dynamic,
-                               state->dynamic_mask);
-       cmd_buffer->state.dirty |= state->dynamic_mask;
+       /* Restore all viewports. */
+       cmd_buffer->state.dynamic.viewport.count = state->viewport.count;
+       typed_memcpy(cmd_buffer->state.dynamic.viewport.viewports,
+                    state->viewport.viewports,
+                    MAX_VIEWPORTS);
+
+       /* Restore all scissors. */
+       cmd_buffer->state.dynamic.scissor.count = state->scissor.count;
+       typed_memcpy(cmd_buffer->state.dynamic.scissor.scissors,
+                    state->scissor.scissors,
+                    MAX_SCISSORS);
+
+       cmd_buffer->state.dirty |= 1 << VK_DYNAMIC_STATE_VIEWPORT |
+                                  1 << VK_DYNAMIC_STATE_SCISSOR;
 
        memcpy(cmd_buffer->push_constants, state->push_constants, MAX_PUSH_CONSTANTS_SIZE);
        cmd_buffer->push_constant_stages |= VK_SHADER_STAGE_ALL_GRAPHICS | VK_SHADER_STAGE_COMPUTE_BIT;
@@ -391,11 +409,11 @@ void
 radv_meta_save_graphics_reset_vport_scissor_novertex(struct radv_meta_saved_state *saved_state,
                                                     struct radv_cmd_buffer *cmd_buffer)
 {
-       uint32_t dirty_state = (1 << VK_DYNAMIC_STATE_VIEWPORT) | (1 << VK_DYNAMIC_STATE_SCISSOR);
-       radv_meta_save_novertex(saved_state, cmd_buffer, dirty_state);
+       radv_meta_save_novertex(saved_state, cmd_buffer);
        cmd_buffer->state.dynamic.viewport.count = 0;
        cmd_buffer->state.dynamic.scissor.count = 0;
-       cmd_buffer->state.dirty |= dirty_state;
+       cmd_buffer->state.dirty |= 1 << VK_DYNAMIC_STATE_VIEWPORT |
+                                  1 << VK_DYNAMIC_STATE_SCISSOR;
 }
 
 nir_ssa_def *radv_meta_gen_rect_vertices_comp2(nir_builder *vs_b, nir_ssa_def *comp2)
index 5d28cc5f0f9f493ec8b2cd48b24c2f588d7b4b8f..c7c9a6bd5e19f70c22fda075924d049d3694071c 100644 (file)
@@ -36,14 +36,10 @@ extern "C" {
 #define RADV_META_VERTEX_BINDING_COUNT 2
 
 struct radv_meta_saved_state {
-       /**
-        * Bitmask of (1 << VK_DYNAMIC_STATE_*). Defines the set of saved dynamic
-        * state.
-        */
-       uint32_t dynamic_mask;
-       struct radv_dynamic_state dynamic;
        struct radv_descriptor_set *old_descriptor_set0;
        struct radv_pipeline *old_pipeline;
+       struct radv_viewport_state viewport;
+       struct radv_scissor_state scissor;
 
        char push_constants[128];
 };
index 79ac295a0fd2cde76594f6482a8694ccc5442d28..c23e8cf4995950c8c429f41358e1682522d4f638 100644 (file)
@@ -700,16 +700,20 @@ struct radv_vertex_binding {
        VkDeviceSize                                 offset;
 };
 
+struct radv_viewport_state {
+       uint32_t                                          count;
+       VkViewport                                        viewports[MAX_VIEWPORTS];
+};
+
+struct radv_scissor_state {
+       uint32_t                                          count;
+       VkRect2D                                          scissors[MAX_SCISSORS];
+};
+
 struct radv_dynamic_state {
-       struct {
-               uint32_t                                  count;
-               VkViewport                                viewports[MAX_VIEWPORTS];
-       } viewport;
+       struct radv_viewport_state                        viewport;
 
-       struct {
-               uint32_t                                  count;
-               VkRect2D                                  scissors[MAX_SCISSORS];
-       } scissor;
+       struct radv_scissor_state                         scissor;
 
        float                                        line_width;