radv: add radv_get_depth_pipeline() helper
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 2 Jul 2019 12:50:24 +0000 (14:50 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 3 Jul 2019 06:51:42 +0000 (08:51 +0200)
Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
src/amd/vulkan/radv_meta_decompress.c

index 578a287d07b689ceb954ab13e7f99f2a3c07d7a4..fa5de24314a9ab086566d3602da2b75cd62f925c 100644 (file)
@@ -320,6 +320,43 @@ enum radv_depth_op {
        DEPTH_RESUMMARIZE,
 };
 
+static VkPipeline *
+radv_get_depth_pipeline(struct radv_cmd_buffer *cmd_buffer,
+                       struct radv_image *image, enum radv_depth_op op)
+{
+       struct radv_meta_state *state = &cmd_buffer->device->meta_state;
+       uint32_t samples = image->info.samples;
+       uint32_t samples_log2 = ffs(samples) - 1;
+       VkPipeline *pipeline;
+
+       if (!state->depth_decomp[samples_log2].decompress_pipeline) {
+               VkResult ret;
+
+               ret = create_pipeline(cmd_buffer->device, VK_NULL_HANDLE, samples,
+                                     state->depth_decomp[samples_log2].pass,
+                                     state->depth_decomp[samples_log2].p_layout,
+                                     &state->depth_decomp[samples_log2].decompress_pipeline,
+                                     &state->depth_decomp[samples_log2].resummarize_pipeline);
+               if (ret != VK_SUCCESS) {
+                       cmd_buffer->record_result = ret;
+                       return NULL;
+               }
+       }
+
+       switch (op) {
+       case DEPTH_DECOMPRESS:
+               pipeline = &state->depth_decomp[samples_log2].decompress_pipeline;
+               break;
+       case DEPTH_RESUMMARIZE:
+               pipeline = &state->depth_decomp[samples_log2].resummarize_pipeline;
+               break;
+       default:
+               unreachable("unknown operation");
+       }
+
+       return pipeline;
+}
+
 static void radv_process_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer,
                                             struct radv_image *image,
                                             VkImageSubresourceRange *subresourceRange,
@@ -336,41 +373,20 @@ static void radv_process_depth_image_inplace(struct radv_cmd_buffer *cmd_buffer,
        uint32_t samples = image->info.samples;
        uint32_t samples_log2 = ffs(samples) - 1;
        struct radv_meta_state *meta_state = &cmd_buffer->device->meta_state;
-       VkPipeline pipeline_h;
+       VkPipeline *pipeline;
 
        if (!radv_image_has_htile(image))
                return;
 
-       if (!meta_state->depth_decomp[samples_log2].decompress_pipeline) {
-               VkResult ret = create_pipeline(cmd_buffer->device, VK_NULL_HANDLE, samples,
-                                              meta_state->depth_decomp[samples_log2].pass,
-                                              meta_state->depth_decomp[samples_log2].p_layout,
-                                              &meta_state->depth_decomp[samples_log2].decompress_pipeline,
-                                              &meta_state->depth_decomp[samples_log2].resummarize_pipeline);
-               if (ret != VK_SUCCESS) {
-                       cmd_buffer->record_result = ret;
-                       return;
-               }
-       }
-
        radv_meta_save(&saved_state, cmd_buffer,
                       RADV_META_SAVE_GRAPHICS_PIPELINE |
                       RADV_META_SAVE_SAMPLE_LOCATIONS |
                       RADV_META_SAVE_PASS);
 
-       switch (op) {
-       case DEPTH_DECOMPRESS:
-               pipeline_h = meta_state->depth_decomp[samples_log2].decompress_pipeline;
-               break;
-       case DEPTH_RESUMMARIZE:
-               pipeline_h = meta_state->depth_decomp[samples_log2].resummarize_pipeline;
-               break;
-       default:
-               unreachable("unknown operation");
-       }
+       pipeline = radv_get_depth_pipeline(cmd_buffer, image, op);
 
-       radv_CmdBindPipeline(cmd_buffer_h, VK_PIPELINE_BIND_POINT_GRAPHICS,
-                            pipeline_h);
+       radv_CmdBindPipeline(radv_cmd_buffer_to_handle(cmd_buffer),
+                            VK_PIPELINE_BIND_POINT_GRAPHICS, *pipeline);
 
        radv_CmdSetViewport(cmd_buffer_h, 0, 1, &(VkViewport) {
                .x = 0,