From 4fbdfdce9c63537225ea10dafa9e23a34e351684 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Wed, 20 Mar 2024 10:52:52 +0200 Subject: [PATCH] anv: allocate pipeline bindings tables dynamically on the heap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lionel Landwerlin Reviewed-by: José Roberto de Souza Reviewed-by: Paulo Zanoni Part-of: --- src/intel/vulkan/anv_pipeline.c | 50 ++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index 56fbbb61687..65aca90f1ce 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -411,9 +411,6 @@ struct anv_pipeline_stage { enum brw_robustness_flags robust_flags; - struct anv_pipeline_binding surface_to_descriptor[256]; - struct anv_pipeline_binding sampler_to_descriptor[256]; - struct anv_pipeline_embedded_sampler_binding embedded_sampler_to_binding[2048]; struct anv_pipeline_bind_map bind_map; bool uses_bt_for_push_descs; @@ -434,6 +431,29 @@ struct anv_pipeline_stage { struct anv_shader_bin *bin; }; +static void +anv_stage_allocate_bind_map_tables(struct anv_pipeline *pipeline, + struct anv_pipeline_stage *stage, + void *mem_ctx) +{ + struct anv_pipeline_binding *surface_bindings = + brw_shader_stage_requires_bindless_resources(stage->stage) ? NULL : + rzalloc_array(mem_ctx, struct anv_pipeline_binding, 256); + struct anv_pipeline_binding *sampler_bindings = + brw_shader_stage_requires_bindless_resources(stage->stage) ? NULL : + rzalloc_array(mem_ctx, struct anv_pipeline_binding, 256); + struct anv_pipeline_embedded_sampler_binding *embedded_sampler_bindings = + rzalloc_array(mem_ctx, struct anv_pipeline_embedded_sampler_binding, + anv_pipeline_sets_layout_embedded_sampler_count( + &pipeline->layout)); + + stage->bind_map = (struct anv_pipeline_bind_map) { + .surface_to_descriptor = surface_bindings, + .sampler_to_descriptor = sampler_bindings, + .embedded_sampler_to_binding = embedded_sampler_bindings, + }; +} + static enum brw_robustness_flags anv_get_robust_flags(const struct vk_pipeline_robustness_state *rstate) { @@ -2004,12 +2024,6 @@ anv_graphics_pipeline_load_nir(struct anv_graphics_base_pipeline *pipeline, assert(stages[s].stage == s); - stages[s].bind_map = (struct anv_pipeline_bind_map) { - .surface_to_descriptor = stages[s].surface_to_descriptor, - .sampler_to_descriptor = stages[s].sampler_to_descriptor, - .embedded_sampler_to_binding = stages[s].embedded_sampler_to_binding, - }; - /* Only use the create NIR from the pStages[] element if we don't have * an imported library for the same stage. */ @@ -2273,6 +2287,8 @@ anv_graphics_pipeline_compile(struct anv_graphics_base_pipeline *pipeline, link_optimize, s)) continue; + anv_stage_allocate_bind_map_tables(&pipeline->base, &stages[s], tmp_ctx); + anv_pipeline_nir_preprocess(&pipeline->base, &stages[s]); } @@ -2614,11 +2630,7 @@ anv_pipeline_compile_cs(struct anv_compute_pipeline *pipeline, if (stage.bin == NULL) { int64_t stage_start = os_time_get_nano(); - stage.bind_map = (struct anv_pipeline_bind_map) { - .surface_to_descriptor = stage.surface_to_descriptor, - .sampler_to_descriptor = stage.sampler_to_descriptor, - .embedded_sampler_to_binding = stage.embedded_sampler_to_binding, - }; + anv_stage_allocate_bind_map_tables(&pipeline->base, &stage, mem_ctx); /* Set up a binding for the gl_NumWorkGroups */ stage.bind_map.surface_count = 1; @@ -3018,12 +3030,6 @@ anv_graphics_pipeline_import_lib(struct anv_graphics_base_pipeline *pipeline, stages[s].subgroup_size_type = lib->retained_shaders[s].subgroup_size_type; stages[s].imported.nir = lib->retained_shaders[s].nir; stages[s].imported.bin = lib->base.shaders[s]; - - stages[s].bind_map = (struct anv_pipeline_bind_map) { - .surface_to_descriptor = stages[s].surface_to_descriptor, - .sampler_to_descriptor = stages[s].sampler_to_descriptor, - .embedded_sampler_to_binding = stages[s].embedded_sampler_to_binding, - }; } /* When not link optimizing, import the executables (shader descriptions @@ -3551,8 +3557,8 @@ anv_pipeline_init_ray_tracing_stages(struct anv_ray_tracing_pipeline *pipeline, }, }; - stages[i].bind_map.embedded_sampler_to_binding = - stages[i].embedded_sampler_to_binding; + anv_stage_allocate_bind_map_tables(&pipeline->base, &stages[i], + tmp_pipeline_ctx); pipeline->base.active_stages |= sinfo->stage;