anv: Stop looking at the pipeline in multiview lowering
authorJason Ekstrand <jason.ekstrand@collabora.com>
Mon, 18 Jul 2022 16:06:41 +0000 (11:06 -0500)
committerMarge Bot <emma+marge@anholt.net>
Wed, 31 Aug 2022 02:00:18 +0000 (02:00 +0000)
Passing all the data we need in directly avoids issues where we might
forget what is and isn't set on the pipeline object at the time the
shader call happens.  This will be especially important once we start
splitting things up for pipeline libraries.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Caio Oliveira <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17602>

src/intel/vulkan/anv_nir.h
src/intel/vulkan/anv_nir_lower_multiview.c
src/intel/vulkan/anv_pipeline.c

index 5751f74..86705df 100644 (file)
 extern "C" {
 #endif
 
-bool anv_check_for_primitive_replication(nir_shader **shaders,
-                                         struct anv_graphics_pipeline *pipeline);
+bool anv_check_for_primitive_replication(struct anv_device *device,
+                                         VkShaderStageFlags stages,
+                                         nir_shader **shaders,
+                                         uint32_t view_mask);
 
-bool anv_nir_lower_multiview(nir_shader *shader,
-                             struct anv_graphics_pipeline *pipeline);
+bool anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask,
+                             bool use_primitive_replication);
 
 bool anv_nir_lower_ycbcr_textures(nir_shader *shader,
                                   const struct anv_pipeline_layout *layout);
index 3272b2f..dd59197 100644 (file)
@@ -176,11 +176,10 @@ replace_load_view_index_with_layer_id(struct nir_builder *b,
 }
 
 bool
-anv_nir_lower_multiview(nir_shader *shader,
-                        struct anv_graphics_pipeline *pipeline)
+anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask,
+                        bool use_primitive_replication)
 {
    assert(shader->info.stage != MESA_SHADER_COMPUTE);
-   uint32_t view_mask = pipeline->view_mask;
 
    /* If multiview isn't enabled, just lower the ViewIndex builtin to zero. */
    if (view_mask == 0) {
@@ -201,8 +200,8 @@ anv_nir_lower_multiview(nir_shader *shader,
     * view, then it is possible to use the feature instead of instancing to
     * implement multiview.
     */
-   if (pipeline->use_primitive_replication) {
-      bool progress = nir_lower_multiview(shader, pipeline->view_mask);
+   if (use_primitive_replication) {
+      bool progress = nir_lower_multiview(shader, view_mask);
 
       if (progress) {
          nir_builder b;
@@ -289,10 +288,12 @@ anv_nir_lower_multiview(nir_shader *shader,
 }
 
 bool
-anv_check_for_primitive_replication(nir_shader **shaders,
-                                    struct anv_graphics_pipeline *pipeline)
+anv_check_for_primitive_replication(struct anv_device *device,
+                                    VkShaderStageFlags stages,
+                                    nir_shader **shaders,
+                                    uint32_t view_mask)
 {
-   assert(pipeline->base.device->info->ver >= 12);
+   assert(device->info->ver >= 12);
 
    static int primitive_replication_max_views = -1;
    if (primitive_replication_max_views < 0) {
@@ -312,11 +313,9 @@ anv_check_for_primitive_replication(nir_shader **shaders,
     * later than Vertex.  In that case only the last stage can refer to
     * gl_ViewIndex.
     */
-   if (pipeline->active_stages & ~(VK_SHADER_STAGE_VERTEX_BIT |
-                                   VK_SHADER_STAGE_FRAGMENT_BIT))
+   if (stages & ~(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT))
       return false;
 
-   uint32_t view_mask = pipeline->view_mask;
    int view_count = util_bitcount(view_mask);
    if (view_count == 1 || view_count > primitive_replication_max_views)
       return false;
index e50ccbe..cb40ab5 100644 (file)
@@ -711,8 +711,10 @@ anv_pipeline_lower_nir(struct anv_pipeline *pipeline,
    NIR_PASS(_, nir, anv_nir_lower_ycbcr_textures, layout);
 
    if (pipeline->type == ANV_PIPELINE_GRAPHICS) {
-      NIR_PASS(_, nir, anv_nir_lower_multiview,
-               anv_pipeline_to_graphics(pipeline));
+      struct anv_graphics_pipeline *gfx_pipeline =
+         anv_pipeline_to_graphics(pipeline);
+      NIR_PASS(_, nir, anv_nir_lower_multiview, gfx_pipeline->view_mask,
+               gfx_pipeline->use_primitive_replication);
    }
 
    nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir));
@@ -1612,7 +1614,9 @@ anv_graphics_pipeline_compile(struct anv_graphics_pipeline *pipeline,
          shaders[s] = stages[s].nir;
 
       pipeline->use_primitive_replication =
-         anv_check_for_primitive_replication(shaders, pipeline);
+         anv_check_for_primitive_replication(pipeline->base.device,
+                                             pipeline->active_stages,
+                                             shaders, pipeline->view_mask);
    } else {
       pipeline->use_primitive_replication = false;
    }