anv/pipeline: Handle output lowering in anv_pipeline instead of spirv_to_nir
[mesa.git] / src / vulkan / anv_meta_clear.c
index 24ff1ea75e49c9be417d9da47d29648492e08c7b..1a4300c07e329440b9359a75f830d0fa1171c721 100644 (file)
@@ -23,8 +23,8 @@
 
 #include "anv_meta.h"
 #include "anv_meta_clear.h"
-#include "anv_nir_builder.h"
 #include "anv_private.h"
+#include "glsl/nir/nir_builder.h"
 
 /** Vertex attributes for color clears.  */
 struct color_clear_vattrs {
@@ -66,8 +66,8 @@ build_color_shaders(struct nir_shader **out_vs,
    nir_builder vs_b;
    nir_builder fs_b;
 
-   nir_builder_init_simple_shader(&vs_b, MESA_SHADER_VERTEX);
-   nir_builder_init_simple_shader(&fs_b, MESA_SHADER_FRAGMENT);
+   nir_builder_init_simple_shader(&vs_b, NULL, MESA_SHADER_VERTEX, NULL);
+   nir_builder_init_simple_shader(&fs_b, NULL, MESA_SHADER_FRAGMENT, NULL);
 
    const struct glsl_type *position_type = glsl_vec4_type();
    const struct glsl_type *color_type = glsl_vec4_type();
@@ -112,22 +112,25 @@ build_color_shaders(struct nir_shader **out_vs,
    *out_fs = fs_b.shader;
 }
 
-static struct anv_pipeline *
+static VkResult
 create_pipeline(struct anv_device *device,
                 struct nir_shader *vs_nir,
                 struct nir_shader *fs_nir,
                 const VkPipelineVertexInputStateCreateInfo *vi_state,
                 const VkPipelineDepthStencilStateCreateInfo *ds_state,
                 const VkPipelineColorBlendStateCreateInfo *cb_state,
-                const VkAllocationCallbacks *alloc)
+                const VkAllocationCallbacks *alloc,
+                struct anv_pipeline **pipeline)
 {
    VkDevice device_h = anv_device_to_handle(device);
+   VkResult result;
 
    struct anv_shader_module vs_m = { .nir = vs_nir };
    struct anv_shader_module fs_m = { .nir = fs_nir };
 
    VkPipeline pipeline_h;
-   anv_graphics_pipeline_create(device_h,
+   result = anv_graphics_pipeline_create(device_h,
+      VK_NULL_HANDLE,
       &(VkGraphicsPipelineCreateInfo) {
          .sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO,
          .stageCount = 2,
@@ -212,10 +215,12 @@ create_pipeline(struct anv_device *device,
    ralloc_free(vs_nir);
    ralloc_free(fs_nir);
 
-   return anv_pipeline_from_handle(pipeline_h);
+   *pipeline = anv_pipeline_from_handle(pipeline_h);
+
+   return result;
 }
 
-static void
+static VkResult
 init_color_pipeline(struct anv_device *device)
 {
    struct nir_shader *vs_nir;
@@ -281,9 +286,10 @@ init_color_pipeline(struct anv_device *device)
       },
    };
 
-   device->meta_state.clear.color_pipeline =
+   return
       create_pipeline(device, vs_nir, fs_nir, &vi_state, &ds_state,
-                      &cb_state, NULL);
+                      &cb_state, NULL,
+                      &device->meta_state.clear.color_pipeline);
 }
 
 static void
@@ -316,8 +322,7 @@ emit_load_color_clear(struct anv_cmd_buffer *cmd_buffer,
    };
 
    struct anv_state state =
-      anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, sizeof(vertex_data), 16);
-   memcpy(state.map, vertex_data, sizeof(vertex_data));
+      anv_cmd_buffer_emit_dynamic(cmd_buffer, vertex_data, sizeof(vertex_data), 16);
 
    struct anv_buffer vertex_buffer = {
       .device = device,
@@ -373,8 +378,8 @@ build_depthstencil_shaders(struct nir_shader **out_vs,
    nir_builder vs_b;
    nir_builder fs_b;
 
-   nir_builder_init_simple_shader(&vs_b, MESA_SHADER_VERTEX);
-   nir_builder_init_simple_shader(&fs_b, MESA_SHADER_FRAGMENT);
+   nir_builder_init_simple_shader(&vs_b, NULL, MESA_SHADER_VERTEX, NULL);
+   nir_builder_init_simple_shader(&fs_b, NULL, MESA_SHADER_FRAGMENT, NULL);
 
    const struct glsl_type *position_type = glsl_vec4_type();
 
@@ -394,9 +399,10 @@ build_depthstencil_shaders(struct nir_shader **out_vs,
    *out_fs = fs_b.shader;
 }
 
-static struct anv_pipeline *
+static VkResult
 create_depthstencil_pipeline(struct anv_device *device,
-                             VkImageAspectFlags aspects)
+                             VkImageAspectFlags aspects,
+                             struct anv_pipeline **pipeline)
 {
    struct nir_shader *vs_nir;
    struct nir_shader *fs_nir;
@@ -456,7 +462,7 @@ create_depthstencil_pipeline(struct anv_device *device,
    };
 
    return create_pipeline(device, vs_nir, fs_nir, &vi_state, &ds_state,
-                          &cb_state, NULL);
+                          &cb_state, NULL, pipeline);
 }
 
 static void
@@ -485,8 +491,7 @@ emit_load_depthstencil_clear(struct anv_cmd_buffer *cmd_buffer,
    };
 
    struct anv_state state =
-      anv_cmd_buffer_alloc_dynamic_state(cmd_buffer, sizeof(vertex_data), 16);
-   memcpy(state.map, vertex_data, sizeof(vertex_data));
+      anv_cmd_buffer_emit_dynamic(cmd_buffer, vertex_data, sizeof(vertex_data), 16);
 
    struct anv_buffer vertex_buffer = {
       .device = device,
@@ -555,25 +560,67 @@ emit_load_depthstencil_clear(struct anv_cmd_buffer *cmd_buffer,
    ANV_CALL(CmdDraw)(cmd_buffer_h, 3, 1, 0, 0);
 }
 
-static void
+static VkResult
 init_depthstencil_pipelines(struct anv_device *device)
 {
-   device->meta_state.clear.depth_only_pipeline =
-      create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_DEPTH_BIT);
-
-   device->meta_state.clear.stencil_only_pipeline =
-      create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_STENCIL_BIT);
-
-   device->meta_state.clear.depthstencil_pipeline =
-      create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_DEPTH_BIT |
-                                           VK_IMAGE_ASPECT_STENCIL_BIT);
+   VkResult result;
+   struct anv_meta_state *state = &device->meta_state;
+
+   result =
+      create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_DEPTH_BIT,
+                                   &state->clear.depth_only_pipeline);
+   if (result != VK_SUCCESS)
+      goto fail;
+
+   result =
+      create_depthstencil_pipeline(device, VK_IMAGE_ASPECT_STENCIL_BIT,
+                                   &state->clear.stencil_only_pipeline);
+   if (result != VK_SUCCESS)
+      goto fail_depth_only;
+
+   result =
+      create_depthstencil_pipeline(device,
+                                   VK_IMAGE_ASPECT_DEPTH_BIT |
+                                   VK_IMAGE_ASPECT_STENCIL_BIT,
+                                   &state->clear.depthstencil_pipeline);
+   if (result != VK_SUCCESS)
+      goto fail_stencil_only;
+
+   return result;
+
+ fail_stencil_only:
+   anv_DestroyPipeline(anv_device_to_handle(device),
+                       anv_pipeline_to_handle(state->clear.stencil_only_pipeline),
+                       NULL);
+ fail_depth_only:
+   anv_DestroyPipeline(anv_device_to_handle(device),
+                       anv_pipeline_to_handle(state->clear.depth_only_pipeline),
+                       NULL);
+ fail:
+   return result;
 }
 
-void
+VkResult
 anv_device_init_meta_clear_state(struct anv_device *device)
 {
-   init_color_pipeline(device);
-   init_depthstencil_pipelines(device);
+   VkResult result;
+
+   result = init_color_pipeline(device);
+   if (result != VK_SUCCESS)
+      goto fail;
+
+   result = init_depthstencil_pipelines(device);
+   if (result != VK_SUCCESS)
+      goto fail_color_pipeline;
+
+   return VK_SUCCESS;
+
+ fail_color_pipeline:
+   anv_DestroyPipeline(anv_device_to_handle(device),
+                       anv_pipeline_to_handle(device->meta_state.clear.color_pipeline),
+                       NULL);
+ fail:
+    return result;
 }
 
 void
@@ -682,8 +729,8 @@ void anv_CmdClearColorImage(
                &(VkImageViewCreateInfo) {
                   .sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
                   .image = _image,
-                  .viewType = VK_IMAGE_VIEW_TYPE_2D,
-                  .format = image->format->vk_format,
+                  .viewType = anv_meta_get_view_type(image),
+                  .format = image->vk_format,
                   .subresourceRange = {
                      .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
                      .baseMipLevel = pRanges[r].baseMipLevel + l,
@@ -713,7 +760,7 @@ void anv_CmdClearColorImage(
                   .sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO,
                   .attachmentCount = 1,
                   .pAttachments = &(VkAttachmentDescription) {
-                     .format = iview.format->vk_format,
+                     .format = iview.vk_format,
                      .loadOp = VK_ATTACHMENT_LOAD_OP_LOAD,
                      .storeOp = VK_ATTACHMENT_STORE_OP_STORE,
                      .initialLayout = VK_IMAGE_LAYOUT_GENERAL,