Module: Mesa Branch: main Commit: 5f1dbd80b3cef05e3d1fe87823ab3df2529c7aa8 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=5f1dbd80b3cef05e3d1fe87823ab3df2529c7aa8
Author: Jason Ekstrand <[email protected]> Date: Fri Sep 2 22:50:03 2022 -0500 hasvk: Rip out primitive replication Reviewed-by: Lionel Landwerlin <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19852> --- src/intel/vulkan_hasvk/anv_nir.h | 8 +-- src/intel/vulkan_hasvk/anv_nir_lower_multiview.c | 65 +----------------------- src/intel/vulkan_hasvk/anv_pipeline.c | 41 ++------------- 3 files changed, 7 insertions(+), 107 deletions(-) diff --git a/src/intel/vulkan_hasvk/anv_nir.h b/src/intel/vulkan_hasvk/anv_nir.h index 86705dfd4f6..a9502cd706e 100644 --- a/src/intel/vulkan_hasvk/anv_nir.h +++ b/src/intel/vulkan_hasvk/anv_nir.h @@ -31,13 +31,7 @@ extern "C" { #endif -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, uint32_t view_mask, - bool use_primitive_replication); +bool anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask); bool anv_nir_lower_ycbcr_textures(nir_shader *shader, const struct anv_pipeline_layout *layout); diff --git a/src/intel/vulkan_hasvk/anv_nir_lower_multiview.c b/src/intel/vulkan_hasvk/anv_nir_lower_multiview.c index 4fb66cf48f6..2699c6f121c 100644 --- a/src/intel/vulkan_hasvk/anv_nir_lower_multiview.c +++ b/src/intel/vulkan_hasvk/anv_nir_lower_multiview.c @@ -176,8 +176,7 @@ replace_load_view_index_with_layer_id(struct nir_builder *b, } bool -anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask, - bool use_primitive_replication) +anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask) { assert(shader->info.stage != MESA_SHADER_COMPUTE); @@ -195,32 +194,6 @@ anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask, /* This pass assumes a single entrypoint */ nir_function_impl *entrypoint = nir_shader_get_entrypoint(shader); - /* Primitive Replication allows a shader to write different positions for - * each view in the same execution. If only the position depends on the - * view, then it is possible to use the feature instead of instancing to - * implement multiview. - */ - if (use_primitive_replication) { - bool progress = nir_lower_multiview(shader, view_mask); - - if (progress) { - nir_builder b; - nir_builder_init(&b, entrypoint); - b.cursor = nir_before_cf_list(&entrypoint->body); - - /* Fill Layer ID with zero. Replication will use that as base to - * apply the RTAI offsets. - */ - nir_variable *layer_id_out = - nir_variable_create(shader, nir_var_shader_out, - glsl_int_type(), "layer ID"); - layer_id_out->data.location = VARYING_SLOT_LAYER; - nir_store_var(&b, layer_id_out, nir_imm_zero(&b, 1, 32), 0x1); - } - - return progress; - } - struct lower_multiview_state state = { .view_mask = view_mask, }; @@ -286,39 +259,3 @@ anv_nir_lower_multiview(nir_shader *shader, uint32_t view_mask, return true; } - -bool -anv_check_for_primitive_replication(struct anv_device *device, - VkShaderStageFlags stages, - nir_shader **shaders, - uint32_t view_mask) -{ - assert(device->info->ver >= 12); - - static int primitive_replication_max_views = -1; - if (primitive_replication_max_views < 0) { - /* TODO: Figure out why we are not getting same benefits for larger than - * 2 views. For now use Primitive Replication just for the 2-view case - * by default. - */ - const unsigned default_max_views = 2; - - primitive_replication_max_views = - MIN2(MAX_VIEWS_FOR_PRIMITIVE_REPLICATION, - debug_get_num_option("ANV_PRIMITIVE_REPLICATION_MAX_VIEWS", - default_max_views)); - } - - /* TODO: We should be able to support replication at 'geometry' stages - * later than Vertex. In that case only the last stage can refer to - * gl_ViewIndex. - */ - if (stages & ~(VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT)) - return false; - - int view_count = util_bitcount(view_mask); - if (view_count == 1 || view_count > primitive_replication_max_views) - return false; - - return nir_can_lower_multiview(shaders[MESA_SHADER_VERTEX]); -} diff --git a/src/intel/vulkan_hasvk/anv_pipeline.c b/src/intel/vulkan_hasvk/anv_pipeline.c index 328263099d4..e986b9aab2e 100644 --- a/src/intel/vulkan_hasvk/anv_pipeline.c +++ b/src/intel/vulkan_hasvk/anv_pipeline.c @@ -552,8 +552,7 @@ static void anv_pipeline_lower_nir(struct anv_pipeline *pipeline, void *mem_ctx, struct anv_pipeline_stage *stage, - struct anv_pipeline_layout *layout, - bool use_primitive_replication) + struct anv_pipeline_layout *layout) { const struct anv_physical_device *pdevice = pipeline->device->physical; const struct brw_compiler *compiler = pdevice->compiler; @@ -575,8 +574,7 @@ anv_pipeline_lower_nir(struct anv_pipeline *pipeline, if (pipeline->type == ANV_PIPELINE_GRAPHICS) { struct anv_graphics_pipeline *gfx_pipeline = anv_pipeline_to_graphics(pipeline); - NIR_PASS(_, nir, anv_nir_lower_multiview, gfx_pipeline->view_mask, - use_primitive_replication); + NIR_PASS(_, nir, anv_nir_lower_multiview, gfx_pipeline->view_mask); } nir_shader_gather_info(nir, nir_shader_get_entrypoint(nir)); @@ -1354,24 +1352,6 @@ anv_graphics_pipeline_compile(struct anv_graphics_pipeline *pipeline, next_stage = &stages[s]; } - bool use_primitive_replication = false; - if (pipeline->base.device->info->ver >= 12 && - pipeline->view_mask != 0) { - /* For some pipelines HW Primitive Replication can be used instead of - * instancing to implement Multiview. This depend on how viewIndex is - * used in all the active shaders, so this check can't be done per - * individual shaders. - */ - nir_shader *shaders[ANV_GRAPHICS_SHADER_STAGE_COUNT] = {}; - for (unsigned s = 0; s < ARRAY_SIZE(shaders); s++) - shaders[s] = stages[s].nir; - - use_primitive_replication = - anv_check_for_primitive_replication(pipeline->base.device, - pipeline->active_stages, - shaders, pipeline->view_mask); - } - struct anv_pipeline_stage *prev_stage = NULL; for (unsigned i = 0; i < ARRAY_SIZE(graphics_shader_order); i++) { gl_shader_stage s = graphics_shader_order[i]; @@ -1382,8 +1362,7 @@ anv_graphics_pipeline_compile(struct anv_graphics_pipeline *pipeline, void *stage_ctx = ralloc_context(NULL); - anv_pipeline_lower_nir(&pipeline->base, stage_ctx, &stages[s], layout, - use_primitive_replication); + anv_pipeline_lower_nir(&pipeline->base, stage_ctx, &stages[s], layout); if (prev_stage && compiler->nir_options[s]->unify_interfaces) { prev_stage->nir->info.outputs_written |= stages[s].nir->info.inputs_read & @@ -1574,8 +1553,7 @@ anv_pipeline_compile_cs(struct anv_compute_pipeline *pipeline, return vk_error(pipeline, VK_ERROR_UNKNOWN); } - anv_pipeline_lower_nir(&pipeline->base, mem_ctx, &stage, layout, - false /* use_primitive_replication */); + anv_pipeline_lower_nir(&pipeline->base, mem_ctx, &stage, layout); unsigned local_size = stage.nir->info.workgroup_size[0] * stage.nir->info.workgroup_size[1] * @@ -1825,17 +1803,8 @@ anv_graphics_pipeline_init(struct anv_graphics_pipeline *pipeline, pipeline->vb[b].instance_divisor = state->vi->bindings[b].divisor; } - /* Our implementation of VK_KHR_multiview uses instancing to draw the - * different views when primitive replication cannot be used. If the client - * asks for instancing, we need to multiply by the client's instance count - * at draw time and instance divisor in the vertex bindings by the number - * of views ensure that we repeat the client's per-instance data once for - * each view. - */ - const bool uses_primitive_replication = - anv_pipeline_get_last_vue_prog_data(pipeline)->vue_map.num_pos_slots > 1; pipeline->instance_multiplier = 1; - if (pipeline->view_mask && !uses_primitive_replication) + if (pipeline->view_mask) pipeline->instance_multiplier = util_bitcount(pipeline->view_mask); pipeline->negative_one_to_one =
