anv/meta: Remove unneeded resolve pipeline
[mesa.git] / src / vulkan / anv_meta_resolve.c
index 1be87c4c1982fe41b35cf77071a92e5d242c55f5..9969a0e5d883556a2ad1dab2b7c460f9254d3095 100644 (file)
@@ -56,6 +56,17 @@ meta_resolve_restore(struct anv_meta_saved_state *saved_state,
    anv_meta_restore(saved_state, cmd_buffer);
 }
 
+static VkPipeline *                                                                                          
+get_pipeline_h(struct anv_device *device, uint32_t samples)
+{                                                                                                            
+   uint32_t i = ffs(samples) - 2; /* log2(samples) - 1 */                                                        
+
+   assert(samples >= 2);
+   assert(i < ARRAY_SIZE(device->meta_state.resolve.pipelines));                                             
+
+   return &device->meta_state.resolve.pipelines[i];
+}                                                                                                            
+
 static nir_shader *
 build_nir_vs(void)
 {
@@ -164,7 +175,7 @@ build_nir_fs(uint32_t num_samples)
 }
 
 static VkResult
-create_pass(struct anv_device *device, VkRenderPass *pass_h)
+create_pass(struct anv_device *device)
 {
    VkResult result;
    VkDevice device_h = anv_device_to_handle(device);
@@ -201,7 +212,7 @@ create_pass(struct anv_device *device, VkRenderPass *pass_h)
          .dependencyCount = 0,
       },
       alloc,
-      pass_h);
+      &device->meta_state.resolve.pass);
 
    return result;
 }
@@ -209,9 +220,7 @@ create_pass(struct anv_device *device, VkRenderPass *pass_h)
 static VkResult
 create_pipeline(struct anv_device *device,
                 uint32_t num_samples,
-                VkShaderModule vs_module_h,
-                VkRenderPass pass_h,
-                VkPipeline *pipeline_h)
+                VkShaderModule vs_module_h)
 {
    VkResult result;
    VkDevice device_h = anv_device_to_handle(device);
@@ -223,7 +232,7 @@ create_pipeline(struct anv_device *device,
    if (!fs_module.nir) {
       /* XXX: Need more accurate error */
       result = VK_ERROR_OUT_OF_HOST_MEMORY;
-      goto fail;
+      goto cleanup;
    }
 
    result = anv_graphics_pipeline_create(device_h,
@@ -328,7 +337,7 @@ create_pipeline(struct anv_device *device,
             },
          },
          .layout = device->meta_state.resolve.pipeline_layout,
-         .renderPass = pass_h,
+         .renderPass = device->meta_state.resolve.pass,
          .subpass = 0,
       },
       &(struct anv_graphics_pipeline_create_info) {
@@ -340,15 +349,12 @@ create_pipeline(struct anv_device *device,
          .use_rectlist = true
       },
       &device->meta_state.alloc,
-      pipeline_h);
+      get_pipeline_h(device, num_samples));
    if (result != VK_SUCCESS)
-      goto fail;
+      goto cleanup;
 
    goto cleanup;
 
-fail:
-   *pipeline_h = VK_NULL_HANDLE;
-
 cleanup:
    ralloc_free(fs_module.nir);
    return result;
@@ -435,22 +441,18 @@ anv_device_init_meta_resolve_state(struct anv_device *device)
    if (res != VK_SUCCESS)
       goto fail;
 
-
-   res = create_pass(device, &device->meta_state.resolve.pass);
+   res = create_pass(device);
    if (res != VK_SUCCESS)
       goto fail;
 
-
    for (uint32_t i = 0;
         i < ARRAY_SIZE(device->meta_state.resolve.pipelines); ++i) {
-      uint32_t sample_count = 1 << i;
 
+      uint32_t sample_count = 1 << (1 + i);
       if (!(sample_count_mask & sample_count))
          continue;
 
-      res = create_pipeline(device, sample_count, vs_module_h,
-                            device->meta_state.resolve.pass,
-                            &device->meta_state.resolve.pipelines[i]);
+      res = create_pipeline(device, sample_count, vs_module_h);
       if (res != VK_SUCCESS)
          goto fail;
    }
@@ -480,7 +482,6 @@ emit_resolve(struct anv_cmd_buffer *cmd_buffer,
    const struct anv_framebuffer *fb = cmd_buffer->state.framebuffer;
    const struct anv_image *src_image = src_iview->image;
    VkDescriptorPool dummy_desc_pool_h = (VkDescriptorPool) 1;
-   uint32_t samples_log2 = ffs(src_image->samples) - 1;
 
    const struct vertex_attrs vertex_data[3] = {
       {
@@ -617,7 +618,7 @@ emit_resolve(struct anv_cmd_buffer *cmd_buffer,
          },
       });
 
-   VkPipeline pipeline_h = device->meta_state.resolve.pipelines[samples_log2];
+   VkPipeline pipeline_h = *get_pipeline_h(device, src_image->samples);
    ANV_FROM_HANDLE(anv_pipeline, pipeline, pipeline_h);
 
    if (cmd_buffer->state.pipeline != pipeline) {