radv: store the amount of saved constants in the compute state
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 26 Sep 2017 21:26:20 +0000 (23:26 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 27 Sep 2017 07:26:44 +0000 (09:26 +0200)
It's safer and more elegant.

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_meta_buffer.c
src/amd/vulkan/radv_meta_clear.c
src/amd/vulkan/radv_meta_copy.c
src/amd/vulkan/radv_meta_resolve_cs.c
src/amd/vulkan/radv_query.c

index 2e16c9b9f462dd56fc8cb1f48abf6db07f39f514..3ddbc2e9af4a82a0657bc405f008f22574931135 100644 (file)
@@ -112,23 +112,26 @@ radv_meta_save_compute(struct radv_meta_saved_compute_state *state,
 {
        state->old_pipeline = cmd_buffer->state.compute_pipeline;
        state->old_descriptor_set0 = cmd_buffer->state.descriptors[0];
+       state->push_constant_size = push_constant_size;
 
-       if (push_constant_size)
-               memcpy(state->push_constants, cmd_buffer->push_constants, push_constant_size);
+       if (state->push_constant_size) {
+               memcpy(state->push_constants, cmd_buffer->push_constants,
+                      state->push_constant_size);
+       }
 }
 
 void
 radv_meta_restore_compute(const struct radv_meta_saved_compute_state *state,
-                          struct radv_cmd_buffer *cmd_buffer,
-                          unsigned push_constant_size)
+                          struct radv_cmd_buffer *cmd_buffer)
 {
        radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer), VK_PIPELINE_BIND_POINT_COMPUTE,
                             radv_pipeline_to_handle(state->old_pipeline));
 
        cmd_buffer->state.descriptors[0] = state->old_descriptor_set0;
 
-       if (push_constant_size) {
-               memcpy(cmd_buffer->push_constants, state->push_constants, push_constant_size);
+       if (state->push_constant_size) {
+               memcpy(cmd_buffer->push_constants, state->push_constants,
+                      state->push_constant_size);
                cmd_buffer->push_constant_stages |= VK_SHADER_STAGE_COMPUTE_BIT;
        }
 }
index 8a443fa1b176a0d184c717a9c243705bec471ce3..20b4498ab3afe879b1dff7e138eda1e41b507652 100644 (file)
@@ -56,6 +56,7 @@ struct radv_meta_saved_compute_state {
        struct radv_descriptor_set *old_descriptor_set0;
        struct radv_pipeline *old_pipeline;
 
+       unsigned push_constant_size;
        char push_constants[128];
 };
 
@@ -103,8 +104,7 @@ void radv_meta_save_compute(struct radv_meta_saved_compute_state *state,
                            unsigned push_constant_size);
 
 void radv_meta_restore_compute(const struct radv_meta_saved_compute_state *state,
-                              struct radv_cmd_buffer *cmd_buffer,
-                              unsigned push_constant_size);
+                              struct radv_cmd_buffer *cmd_buffer);
 
 VkImageViewType radv_meta_get_view_type(const struct radv_image *image);
 
index a16c65aab8130d6c9fecaf3831312e9a4c35d2ea..14f848664c2c9f47f15f17c87ca3e31266ab53b4 100644 (file)
@@ -340,7 +340,7 @@ static void fill_buffer_shader(struct radv_cmd_buffer *cmd_buffer,
 
        radv_CmdDispatch(radv_cmd_buffer_to_handle(cmd_buffer), block_count, 1, 1);
 
-       radv_meta_restore_compute(&saved_state, cmd_buffer, 4);
+       radv_meta_restore_compute(&saved_state, cmd_buffer);
 }
 
 static void copy_buffer_shader(struct radv_cmd_buffer *cmd_buffer,
@@ -404,7 +404,7 @@ static void copy_buffer_shader(struct radv_cmd_buffer *cmd_buffer,
 
        radv_CmdDispatch(radv_cmd_buffer_to_handle(cmd_buffer), block_count, 1, 1);
 
-       radv_meta_restore_compute(&saved_state, cmd_buffer, 0);
+       radv_meta_restore_compute(&saved_state, cmd_buffer);
 }
 
 
index b1cbb505ad08089d49e9eb43b13173abedc22c80..62c920e869ff5cdd591724a64fc28e07b138f29b 100644 (file)
@@ -1401,7 +1401,7 @@ void radv_CmdClearColorImage(
                             rangeCount, pRanges, cs);
 
        if (cs)
-               radv_meta_restore_compute(&saved_state.compute, cmd_buffer, 16);
+               radv_meta_restore_compute(&saved_state.compute, cmd_buffer);
        else
                radv_meta_restore(&saved_state.gfx, cmd_buffer);
 }
index fdef37f39f0fafc6d7433d965b91e046fb87df4f..f3e41ff05692feeaa06881d1bdcd8a0dc4fcad7e 100644 (file)
@@ -203,7 +203,7 @@ meta_copy_buffer_to_image(struct radv_cmd_buffer *cmd_buffer,
                }
        }
        if (cs)
-               radv_meta_restore_compute(&saved_state.compute, cmd_buffer, 12);
+               radv_meta_restore_compute(&saved_state.compute, cmd_buffer);
        else
                radv_meta_restore(&saved_state.gfx, cmd_buffer);
 }
@@ -304,7 +304,7 @@ meta_copy_image_to_buffer(struct radv_cmd_buffer *cmd_buffer,
                                slice_array++;
                }
        }
-       radv_meta_restore_compute(&saved_state, cmd_buffer, 12);
+       radv_meta_restore_compute(&saved_state, cmd_buffer);
 }
 
 void radv_CmdCopyImageToBuffer(
@@ -414,7 +414,7 @@ meta_copy_image(struct radv_cmd_buffer *cmd_buffer,
        }
 
        if (cs)
-               radv_meta_restore_compute(&saved_state.compute, cmd_buffer, 16);
+               radv_meta_restore_compute(&saved_state.compute, cmd_buffer);
        else
                radv_meta_restore(&saved_state.gfx, cmd_buffer);
 }
index ce02884d2d6b6906ee39776756789c3aaaf23685..05a212b6d93e0d77586bd4fd4e26d52ea0f9ab5c 100644 (file)
@@ -462,7 +462,7 @@ void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
                                     &(VkExtent2D) {extent.width, extent.height });
                }
        }
-       radv_meta_restore_compute(&saved_state, cmd_buffer, 16);
+       radv_meta_restore_compute(&saved_state, cmd_buffer);
 }
 
 /**
@@ -529,7 +529,7 @@ radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer)
                             &(VkExtent2D) { fb->width, fb->height });
        }
 
-       radv_meta_restore_compute(&saved_state, cmd_buffer, 16);
+       radv_meta_restore_compute(&saved_state, cmd_buffer);
 
        for (uint32_t i = 0; i < subpass->color_count; ++i) {
                VkAttachmentReference dest_att = subpass->resolve_attachments[i];
index 1dbc493e1b74d431cbac37b5de7ad3c9448692b8..f63497a4457d64535f2e9968790aa9c70c4aa2f2 100644 (file)
@@ -737,7 +737,7 @@ static void radv_query_shader(struct radv_cmd_buffer *cmd_buffer,
                                        RADV_CMD_FLAG_INV_VMEM_L1 |
                                        RADV_CMD_FLAG_CS_PARTIAL_FLUSH;
 
-       radv_meta_restore_compute(&saved_state, cmd_buffer, 16);
+       radv_meta_restore_compute(&saved_state, cmd_buffer);
 }
 
 VkResult radv_CreateQueryPool(