radv: convert all COMPUTE operations to the RADV_META_SAVE_XXX flags
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 3 Oct 2017 13:11:21 +0000 (15:11 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 6 Oct 2017 07:49:06 +0000 (09:49 +0200)
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 a35e23167a99953c76daaa9832da193182bc9874..3f57618ad285165ab003f65f2a54d353b202fc78 100644 (file)
@@ -149,37 +149,6 @@ radv_meta_restore(const struct radv_meta_saved_state *state,
        }
 }
 
-void
-radv_meta_save_compute(struct radv_meta_saved_compute_state *state,
-                       const struct radv_cmd_buffer *cmd_buffer,
-                       unsigned push_constant_size)
-{
-       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 (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)
-{
-       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 (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;
-       }
-}
-
 VkImageViewType
 radv_meta_get_view_type(const struct radv_image *image)
 {
index 358df7059912c1eadd01fa9c38322fbec9a8809d..d10ec994137701040eae1394aa26b496ca9aca42 100644 (file)
@@ -58,14 +58,6 @@ struct radv_meta_saved_state {
        VkRect2D render_area;
 };
 
-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];
-};
-
 VkResult radv_device_init_meta_clear_state(struct radv_device *device);
 void radv_device_finish_meta_clear_state(struct radv_device *device);
 
@@ -102,13 +94,6 @@ void radv_meta_save(struct radv_meta_saved_state *saved_state,
 void radv_meta_restore(const struct radv_meta_saved_state *state,
                       struct radv_cmd_buffer *cmd_buffer);
 
-void radv_meta_save_compute(struct radv_meta_saved_compute_state *state,
-                           const struct radv_cmd_buffer *cmd_buffer,
-                           unsigned push_constant_size);
-
-void radv_meta_restore_compute(const struct radv_meta_saved_compute_state *state,
-                              struct radv_cmd_buffer *cmd_buffer);
-
 VkImageViewType radv_meta_get_view_type(const struct radv_image *image);
 
 uint32_t radv_meta_get_iview_layer(const struct radv_image *dest_image,
index ea11ed18c4ff443bdd7b1675ae744afd606ac9c1..e009234f045cf390a8c9577bd80b281df06ff768 100644 (file)
@@ -285,9 +285,12 @@ static void fill_buffer_shader(struct radv_cmd_buffer *cmd_buffer,
 {
        struct radv_device *device = cmd_buffer->device;
        uint64_t block_count = round_up_u64(size, 1024);
-       struct radv_meta_saved_compute_state saved_state;
+       struct radv_meta_saved_state saved_state;
 
-       radv_meta_save_compute(&saved_state, cmd_buffer, 4);
+       radv_meta_save(&saved_state, cmd_buffer,
+                      RADV_META_SAVE_COMPUTE_PIPELINE |
+                      RADV_META_SAVE_CONSTANTS |
+                      RADV_META_SAVE_DESCRIPTORS);
 
        struct radv_buffer dst_buffer = {
                .bo = bo,
@@ -325,7 +328,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);
+       radv_meta_restore(&saved_state, cmd_buffer);
 }
 
 static void copy_buffer_shader(struct radv_cmd_buffer *cmd_buffer,
@@ -336,9 +339,11 @@ static void copy_buffer_shader(struct radv_cmd_buffer *cmd_buffer,
 {
        struct radv_device *device = cmd_buffer->device;
        uint64_t block_count = round_up_u64(size, 1024);
-       struct radv_meta_saved_compute_state saved_state;
+       struct radv_meta_saved_state saved_state;
 
-       radv_meta_save_compute(&saved_state, cmd_buffer, 0);
+       radv_meta_save(&saved_state, cmd_buffer,
+                      RADV_META_SAVE_COMPUTE_PIPELINE |
+                      RADV_META_SAVE_DESCRIPTORS);
 
        struct radv_buffer dst_buffer = {
                .bo = dst_bo,
@@ -389,7 +394,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);
+       radv_meta_restore(&saved_state, cmd_buffer);
 }
 
 
index d4a95b8bddabf5fd44e070782c0d248954d2a0a1..0f895f8c50f5bd64981207fcf8920960eff734a8 100644 (file)
@@ -1368,11 +1368,6 @@ radv_cmd_clear_image(struct radv_cmd_buffer *cmd_buffer,
        }
 }
 
-union meta_saved_state {
-       struct radv_meta_saved_state gfx;
-       struct radv_meta_saved_compute_state compute;
-};
-
 void radv_CmdClearColorImage(
        VkCommandBuffer                             commandBuffer,
        VkImage                                     image_h,
@@ -1383,24 +1378,25 @@ void radv_CmdClearColorImage(
 {
        RADV_FROM_HANDLE(radv_cmd_buffer, cmd_buffer, commandBuffer);
        RADV_FROM_HANDLE(radv_image, image, image_h);
-       union meta_saved_state saved_state;
+       struct radv_meta_saved_state saved_state;
        bool cs = cmd_buffer->queue_family_index == RADV_QUEUE_COMPUTE;
 
-       if (cs)
-               radv_meta_save_compute(&saved_state.compute, cmd_buffer, 16);
-       else
-               radv_meta_save(&saved_state.gfx, cmd_buffer,
+       if (cs) {
+               radv_meta_save(&saved_state, cmd_buffer,
+                              RADV_META_SAVE_COMPUTE_PIPELINE |
+                              RADV_META_SAVE_CONSTANTS |
+                              RADV_META_SAVE_DESCRIPTORS);
+       } else {
+               radv_meta_save(&saved_state, cmd_buffer,
                               RADV_META_SAVE_GRAPHICS_PIPELINE |
                               RADV_META_SAVE_CONSTANTS);
+       }
 
        radv_cmd_clear_image(cmd_buffer, image, imageLayout,
                             (const VkClearValue *) pColor,
                             rangeCount, pRanges, cs);
 
-       if (cs)
-               radv_meta_restore_compute(&saved_state.compute, cmd_buffer);
-       else
-               radv_meta_restore(&saved_state.gfx, cmd_buffer);
+       radv_meta_restore(&saved_state, cmd_buffer);
 }
 
 void radv_CmdClearDepthStencilImage(
index 09bd3ec608af0ca8bf2b271634814a8353b53fb5..a42b15a01afa5a6649af169558955fbd6e4f9603 100644 (file)
@@ -100,11 +100,6 @@ blit_surf_for_image_level_layer(struct radv_image *image,
        };
 }
 
-union meta_saved_state {
-       struct radv_meta_saved_state gfx;
-       struct radv_meta_saved_compute_state compute;
-};
-
 static void
 meta_copy_buffer_to_image(struct radv_cmd_buffer *cmd_buffer,
                           struct radv_buffer* buffer,
@@ -113,20 +108,18 @@ meta_copy_buffer_to_image(struct radv_cmd_buffer *cmd_buffer,
                           const VkBufferImageCopy* pRegions)
 {
        bool cs = cmd_buffer->queue_family_index == RADV_QUEUE_COMPUTE;
-       union meta_saved_state saved_state;
+       struct radv_meta_saved_state saved_state;
 
        /* The Vulkan 1.0 spec says "dstImage must have a sample count equal to
         * VK_SAMPLE_COUNT_1_BIT."
         */
        assert(image->info.samples == 1);
 
-       if (cs)
-               radv_meta_save_compute(&saved_state.compute, cmd_buffer, 12);
-       else
-               radv_meta_save(&saved_state.gfx, cmd_buffer,
-                              RADV_META_SAVE_GRAPHICS_PIPELINE |
-                              RADV_META_SAVE_CONSTANTS |
-                              RADV_META_SAVE_DESCRIPTORS);
+       radv_meta_save(&saved_state, cmd_buffer,
+                      (cs ? RADV_META_SAVE_COMPUTE_PIPELINE :
+                       RADV_META_SAVE_GRAPHICS_PIPELINE) |
+                      RADV_META_SAVE_CONSTANTS |
+                      RADV_META_SAVE_DESCRIPTORS);
 
        for (unsigned r = 0; r < regionCount; r++) {
 
@@ -205,10 +198,8 @@ meta_copy_buffer_to_image(struct radv_cmd_buffer *cmd_buffer,
                                slice_array++;
                }
        }
-       if (cs)
-               radv_meta_restore_compute(&saved_state.compute, cmd_buffer);
-       else
-               radv_meta_restore(&saved_state.gfx, cmd_buffer);
+
+       radv_meta_restore(&saved_state, cmd_buffer);
 }
 
 void radv_CmdCopyBufferToImage(
@@ -234,9 +225,12 @@ meta_copy_image_to_buffer(struct radv_cmd_buffer *cmd_buffer,
                           uint32_t regionCount,
                           const VkBufferImageCopy* pRegions)
 {
-       struct radv_meta_saved_compute_state saved_state;
+       struct radv_meta_saved_state saved_state;
 
-       radv_meta_save_compute(&saved_state, cmd_buffer, 12);
+       radv_meta_save(&saved_state, cmd_buffer,
+                      RADV_META_SAVE_COMPUTE_PIPELINE |
+                      RADV_META_SAVE_CONSTANTS |
+                      RADV_META_SAVE_DESCRIPTORS);
 
        for (unsigned r = 0; r < regionCount; r++) {
 
@@ -307,7 +301,8 @@ meta_copy_image_to_buffer(struct radv_cmd_buffer *cmd_buffer,
                                slice_array++;
                }
        }
-       radv_meta_restore_compute(&saved_state, cmd_buffer);
+
+       radv_meta_restore(&saved_state, cmd_buffer);
 }
 
 void radv_CmdCopyImageToBuffer(
@@ -334,7 +329,7 @@ meta_copy_image(struct radv_cmd_buffer *cmd_buffer,
                const VkImageCopy *pRegions)
 {
        bool cs = cmd_buffer->queue_family_index == RADV_QUEUE_COMPUTE;
-       union meta_saved_state saved_state;
+       struct radv_meta_saved_state saved_state;
 
        /* From the Vulkan 1.0 spec:
         *
@@ -342,13 +337,12 @@ meta_copy_image(struct radv_cmd_buffer *cmd_buffer,
         *    images, but both images must have the same number of samples.
         */
        assert(src_image->info.samples == dest_image->info.samples);
-       if (cs)
-               radv_meta_save_compute(&saved_state.compute, cmd_buffer, 16);
-       else
-               radv_meta_save(&saved_state.gfx, cmd_buffer,
-                              RADV_META_SAVE_GRAPHICS_PIPELINE |
-                              RADV_META_SAVE_CONSTANTS |
-                              RADV_META_SAVE_DESCRIPTORS);
+
+       radv_meta_save(&saved_state, cmd_buffer,
+                      (cs ? RADV_META_SAVE_COMPUTE_PIPELINE :
+                       RADV_META_SAVE_GRAPHICS_PIPELINE) |
+                      RADV_META_SAVE_CONSTANTS |
+                      RADV_META_SAVE_DESCRIPTORS);
 
        for (unsigned r = 0; r < regionCount; r++) {
                assert(pRegions[r].srcSubresource.aspectMask ==
@@ -419,10 +413,7 @@ meta_copy_image(struct radv_cmd_buffer *cmd_buffer,
                }
        }
 
-       if (cs)
-               radv_meta_restore_compute(&saved_state.compute, cmd_buffer);
-       else
-               radv_meta_restore(&saved_state.gfx, cmd_buffer);
+       radv_meta_restore(&saved_state, cmd_buffer);
 }
 
 void radv_CmdCopyImage(
index 7104ccd35f5f0dfa31919eaa6d3fa7dc8f709f94..3833faa1247b47a985d68daeba0008bc8d7a990f 100644 (file)
@@ -377,7 +377,7 @@ void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
                                     uint32_t region_count,
                                     const VkImageResolve *regions)
 {
-       struct radv_meta_saved_compute_state saved_state;
+       struct radv_meta_saved_state saved_state;
 
        for (uint32_t r = 0; r < region_count; ++r) {
                const VkImageResolve *region = &regions[r];
@@ -393,7 +393,10 @@ void radv_meta_resolve_compute_image(struct radv_cmd_buffer *cmd_buffer,
                radv_fast_clear_flush_image_inplace(cmd_buffer, src_image, &range);
        }
 
-       radv_meta_save_compute(&saved_state, cmd_buffer, 16);
+       radv_meta_save(&saved_state, cmd_buffer,
+                      RADV_META_SAVE_COMPUTE_PIPELINE |
+                      RADV_META_SAVE_CONSTANTS |
+                      RADV_META_SAVE_DESCRIPTORS);
 
        for (uint32_t r = 0; r < region_count; ++r) {
                const VkImageResolve *region = &regions[r];
@@ -460,7 +463,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);
+       radv_meta_restore(&saved_state, cmd_buffer);
 }
 
 /**
@@ -471,7 +474,7 @@ radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer)
 {
        struct radv_framebuffer *fb = cmd_buffer->state.framebuffer;
        const struct radv_subpass *subpass = cmd_buffer->state.subpass;
-       struct radv_meta_saved_compute_state saved_state;
+       struct radv_meta_saved_state saved_state;
        /* FINISHME(perf): Skip clears for resolve attachments.
         *
         * From the Vulkan 1.0 spec:
@@ -509,7 +512,10 @@ radv_cmd_buffer_resolve_subpass_cs(struct radv_cmd_buffer *cmd_buffer)
                radv_fast_clear_flush_image_inplace(cmd_buffer, src_iview->image, &range);
        }
 
-       radv_meta_save_compute(&saved_state, cmd_buffer, 16);
+       radv_meta_save(&saved_state, cmd_buffer,
+                      RADV_META_SAVE_COMPUTE_PIPELINE |
+                      RADV_META_SAVE_CONSTANTS |
+                      RADV_META_SAVE_DESCRIPTORS);
 
        for (uint32_t i = 0; i < subpass->color_count; ++i) {
                VkAttachmentReference src_att = subpass->color_attachments[i];
@@ -527,7 +533,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);
+       radv_meta_restore(&saved_state, cmd_buffer);
 
        for (uint32_t i = 0; i < subpass->color_count; ++i) {
                VkAttachmentReference dest_att = subpass->resolve_attachments[i];
index 40faf22b082be103e19890c53514c980a258d4f3..b2ef8055f481ffb48d6489bbae0e81303c69b87a 100644 (file)
@@ -649,9 +649,12 @@ static void radv_query_shader(struct radv_cmd_buffer *cmd_buffer,
                               uint32_t pipeline_stats_mask, uint32_t avail_offset)
 {
        struct radv_device *device = cmd_buffer->device;
-       struct radv_meta_saved_compute_state saved_state;
+       struct radv_meta_saved_state saved_state;
 
-       radv_meta_save_compute(&saved_state, cmd_buffer, 16);
+       radv_meta_save(&saved_state, cmd_buffer,
+                      RADV_META_SAVE_COMPUTE_PIPELINE |
+                      RADV_META_SAVE_CONSTANTS |
+                      RADV_META_SAVE_DESCRIPTORS);
 
        struct radv_buffer dst_buffer = {
                .bo = dst_bo,
@@ -735,7 +738,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);
+       radv_meta_restore(&saved_state, cmd_buffer);
 }
 
 VkResult radv_CreateQueryPool(