From 7893eefa3b593da680121dbc069d25a8a014e0d7 Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Thu, 23 Apr 2026 12:26:33 -0700 Subject: [PATCH] brw: Use a single brw_compile entrypoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-by: Iván Briano Part-of: --- src/gallium/drivers/iris/iris_program.c | 12 +-- src/gallium/drivers/iris/iris_program_cache.c | 2 +- src/intel/blorp/blorp_brw.c | 6 +- src/intel/compiler/brw/brw_compiler.h | 86 ++++--------------- src/intel/compiler/brw/brw_private.h | 19 ++++ src/intel/compiler/brw/brw_shader.cpp | 38 ++++++++ src/intel/compiler/brw/brw_shader.h | 2 - src/intel/vulkan/anv_internal_kernels.c | 4 +- src/intel/vulkan/anv_shader.h | 2 +- src/intel/vulkan/anv_shader_compile.c | 18 ++-- src/intel/vulkan/anv_util.c | 6 +- 11 files changed, 98 insertions(+), 97 deletions(-) diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c index f39fa5d1868..2ef2a1e6c58 100644 --- a/src/gallium/drivers/iris/iris_program.c +++ b/src/gallium/drivers/iris/iris_program.c @@ -1934,7 +1934,7 @@ iris_compile_vs(struct iris_screen *screen, program = bin->kernel; } else { - program = brw_compile_vs(screen->brw, ¶ms); + program = brw_compile(screen->brw, ¶ms.base); } error = params.base.error_str; @@ -2204,7 +2204,7 @@ iris_compile_tcs(struct iris_screen *screen, .prog_data = brw_prog_data, }; - program = brw_compile_tcs(screen->brw, ¶ms); + program = brw_compile(screen->brw, ¶ms.base); error = params.base.error_str; if (program) { @@ -2415,7 +2415,7 @@ iris_compile_tes(struct iris_screen *screen, .input_vue_map = &input_vue_map, }; - program = brw_compile_tes(screen->brw, ¶ms); + program = brw_compile(screen->brw, ¶ms.base); error = params.base.error_str; if (program) { @@ -2609,7 +2609,7 @@ iris_compile_gs(struct iris_screen *screen, .prog_data = brw_prog_data, }; - program = brw_compile_gs(screen->brw, ¶ms); + program = brw_compile(screen->brw, ¶ms.base); error = params.base.error_str; if (program) { iris_debug_recompile(dbg, ish, key); @@ -2824,7 +2824,7 @@ iris_compile_fs(struct iris_screen *screen, program = bin->kernel; } else { - program = brw_compile_fs(screen->brw, ¶ms); + program = brw_compile(screen->brw, ¶ms.base); } error = params.base.error_str; @@ -3184,7 +3184,7 @@ iris_compile_cs(struct iris_screen *screen, program = bin->kernel; } else { - program = brw_compile_cs(screen->brw, ¶ms); + program = brw_compile(screen->brw, ¶ms.base); } error = params.base.error_str; diff --git a/src/gallium/drivers/iris/iris_program_cache.c b/src/gallium/drivers/iris/iris_program_cache.c index 92c56517a95..740c711f0c6 100644 --- a/src/gallium/drivers/iris/iris_program_cache.c +++ b/src/gallium/drivers/iris/iris_program_cache.c @@ -443,7 +443,7 @@ iris_ensure_indirect_generation_shader(struct iris_batch *batch) .key = &prog_key.fs, .prog_data = prog_data, }; - program = brw_compile_fs(screen->brw, ¶ms); + program = brw_compile(screen->brw, ¶ms.base); assert(program); iris_apply_brw_prog_data(shader, &prog_data->base, NULL); } else { diff --git a/src/intel/blorp/blorp_brw.c b/src/intel/blorp/blorp_brw.c index 53940e83622..6db91a9473c 100644 --- a/src/intel/blorp/blorp_brw.c +++ b/src/intel/blorp/blorp_brw.c @@ -91,7 +91,7 @@ blorp_compile_fs_brw(struct blorp_context *blorp, void *mem_ctx, .max_polygons = 1, }; - const unsigned *kernel = brw_compile_fs(compiler, ¶ms); + const unsigned *kernel = brw_compile(compiler, ¶ms.base); debug_archiver_close(archiver); @@ -140,7 +140,7 @@ blorp_compile_vs_brw(struct blorp_context *blorp, void *mem_ctx, .prog_data = vs_prog_data, }; - const unsigned *kernel = brw_compile_vs(compiler, ¶ms); + const unsigned *kernel = brw_compile(compiler, ¶ms.base); debug_archiver_close(archiver); @@ -247,7 +247,7 @@ blorp_compile_cs_brw(struct blorp_context *blorp, void *mem_ctx, .prog_data = cs_prog_data, }; - const unsigned *kernel = brw_compile_cs(compiler, ¶ms); + const unsigned *kernel = brw_compile(compiler, ¶ms.base); debug_archiver_close(archiver); diff --git a/src/intel/compiler/brw/brw_compiler.h b/src/intel/compiler/brw/brw_compiler.h index c9beecb204b..c1caa5226f3 100644 --- a/src/intel/compiler/brw/brw_compiler.h +++ b/src/intel/compiler/brw/brw_compiler.h @@ -1321,6 +1321,10 @@ struct brw_compile_params { debug_archiver *archiver; }; +const unsigned * +brw_compile(const struct brw_compiler *compiler, + struct brw_compile_params *params); + /** * Parameters for compiling a vertex shader. * @@ -1333,15 +1337,6 @@ struct brw_compile_vs_params { struct brw_vs_prog_data *prog_data; }; -/** - * Compile a vertex shader. - * - * Returns the final assembly and updates the parameters structure. - */ -const unsigned * -brw_compile_vs(const struct brw_compiler *compiler, - struct brw_compile_vs_params *params); - /** * Parameters for compiling a tessellation control shader. * @@ -1354,15 +1349,6 @@ struct brw_compile_tcs_params { struct brw_tcs_prog_data *prog_data; }; -/** - * Compile a tessellation control shader. - * - * Returns the final assembly and updates the parameters structure. - */ -const unsigned * -brw_compile_tcs(const struct brw_compiler *compiler, - struct brw_compile_tcs_params *params); - /** * Parameters for compiling a tessellation evaluation shader. * @@ -1376,15 +1362,6 @@ struct brw_compile_tes_params { const struct intel_vue_map *input_vue_map; }; -/** - * Compile a tessellation evaluation shader. - * - * Returns the final assembly and updates the parameters structure. - */ -const unsigned * -brw_compile_tes(const struct brw_compiler *compiler, - struct brw_compile_tes_params *params); - /** * Parameters for compiling a geometry shader. * @@ -1397,15 +1374,6 @@ struct brw_compile_gs_params { struct brw_gs_prog_data *prog_data; }; -/** - * Compile a geometry shader. - * - * Returns the final assembly and updates the parameters structure. - */ -const unsigned * -brw_compile_gs(const struct brw_compiler *compiler, - struct brw_compile_gs_params *params); - struct brw_compile_task_params { struct brw_compile_params base; @@ -1413,10 +1381,6 @@ struct brw_compile_task_params { struct brw_task_prog_data *prog_data; }; -const unsigned * -brw_compile_task(const struct brw_compiler *compiler, - struct brw_compile_task_params *params); - struct brw_compile_mesh_params { struct brw_compile_params base; @@ -1432,10 +1396,6 @@ struct brw_compile_mesh_params { nir_def *(*wa_18019110168_load_provoking_vertex)(nir_builder *b, void *data); }; -const unsigned * -brw_compile_mesh(const struct brw_compiler *compiler, - struct brw_compile_mesh_params *params); - /** * Parameters for compiling a fragment shader. * @@ -1463,15 +1423,6 @@ struct brw_compile_fs_params { nir_def *(*wa_18019110168_load_per_primitive_remap_table_offset)(nir_builder *b, void *data); }; -/** - * Compile a fragment shader. - * - * Returns the final assembly and updates the parameters structure. - */ -const unsigned * -brw_compile_fs(const struct brw_compiler *compiler, - struct brw_compile_fs_params *params); - /** * Parameters for compiling a compute shader. * @@ -1484,15 +1435,6 @@ struct brw_compile_cs_params { struct brw_cs_prog_data *prog_data; }; -/** - * Compile a compute shader. - * - * Returns the final assembly and updates the parameters structure. - */ -const unsigned * -brw_compile_cs(const struct brw_compiler *compiler, - struct brw_compile_cs_params *params); - /** * Parameters for compiling a Bindless shader. * @@ -1508,14 +1450,18 @@ struct brw_compile_bs_params { struct nir_shader **resume_shaders; }; -/** - * Compile a Bindless shader. - * - * Returns the final assembly and updates the parameters structure. - */ -const unsigned * -brw_compile_bs(const struct brw_compiler *compiler, - struct brw_compile_bs_params *params); +union brw_any_compile_params { + struct brw_compile_params base; + struct brw_compile_vs_params vs; + struct brw_compile_tcs_params tcs; + struct brw_compile_tes_params tes; + struct brw_compile_gs_params gs; + struct brw_compile_fs_params fs; + struct brw_compile_cs_params cs; + struct brw_compile_bs_params bs; + struct brw_compile_task_params task; + struct brw_compile_mesh_params mesh; +}; unsigned brw_cs_push_const_total_size(const struct brw_cs_prog_data *cs_prog_data, diff --git a/src/intel/compiler/brw/brw_private.h b/src/intel/compiler/brw/brw_private.h index aa060c39b24..42aaa6057d9 100644 --- a/src/intel/compiler/brw/brw_private.h +++ b/src/intel/compiler/brw/brw_private.h @@ -19,6 +19,25 @@ void brw_alloc_reg_sets(struct brw_compiler *compiler); extern const char *const conditional_modifier[16]; extern const char *const pred_ctrl_align16[16]; +const unsigned *brw_compile_vs(const struct brw_compiler *compiler, + struct brw_compile_vs_params *params); +const unsigned *brw_compile_tcs(const struct brw_compiler *compiler, + struct brw_compile_tcs_params *params); +const unsigned *brw_compile_tes(const struct brw_compiler *compiler, + struct brw_compile_tes_params *params); +const unsigned *brw_compile_gs(const struct brw_compiler *compiler, + struct brw_compile_gs_params *params); +const unsigned *brw_compile_task(const struct brw_compiler *compiler, + struct brw_compile_task_params *params); +const unsigned *brw_compile_mesh(const struct brw_compiler *compiler, + struct brw_compile_mesh_params *params); +const unsigned *brw_compile_fs(const struct brw_compiler *compiler, + struct brw_compile_fs_params *params); +const unsigned *brw_compile_cs(const struct brw_compiler *compiler, + struct brw_compile_cs_params *params); +const unsigned *brw_compile_bs(const struct brw_compiler *compiler, + struct brw_compile_bs_params *params); + typedef struct brw_pass_tracker { nir_shader *nir; unsigned dispatch_width; diff --git a/src/intel/compiler/brw/brw_shader.cpp b/src/intel/compiler/brw/brw_shader.cpp index 0a9ebd38958..1b169235b07 100644 --- a/src/intel/compiler/brw/brw_shader.cpp +++ b/src/intel/compiler/brw/brw_shader.cpp @@ -1050,6 +1050,44 @@ brw_allocate_vgrf_units(brw_shader &s, unsigned units_of_REGSIZE) return brw_vgrf(brw_allocate_vgrf_number(s, units_of_REGSIZE), BRW_TYPE_UD); } +const unsigned * +brw_compile(const struct brw_compiler *compiler, + struct brw_compile_params *params) +{ + assert(params); + assert(params->nir); + + switch (params->nir->info.stage) { + case MESA_SHADER_VERTEX: + return brw_compile_vs(compiler, (struct brw_compile_vs_params *)params); + case MESA_SHADER_TESS_CTRL: + return brw_compile_tcs(compiler, (struct brw_compile_tcs_params *)params); + case MESA_SHADER_TESS_EVAL: + return brw_compile_tes(compiler, (struct brw_compile_tes_params *)params); + case MESA_SHADER_GEOMETRY: + return brw_compile_gs(compiler, (struct brw_compile_gs_params *)params); + case MESA_SHADER_TASK: + return brw_compile_task(compiler, (struct brw_compile_task_params *)params); + case MESA_SHADER_MESH: + return brw_compile_mesh(compiler, (struct brw_compile_mesh_params *)params); + case MESA_SHADER_FRAGMENT: + return brw_compile_fs(compiler, (struct brw_compile_fs_params *)params); + case MESA_SHADER_COMPUTE: + case MESA_SHADER_KERNEL: + return brw_compile_cs(compiler, (struct brw_compile_cs_params *)params); + case MESA_SHADER_RAYGEN: + case MESA_SHADER_ANY_HIT: + case MESA_SHADER_CLOSEST_HIT: + case MESA_SHADER_MISS: + case MESA_SHADER_INTERSECTION: + case MESA_SHADER_CALLABLE: + return brw_compile_bs(compiler, (struct brw_compile_bs_params *)params); + default: + UNREACHABLE("Unsupported shader stage"); + return NULL; + } +} + void brw_prog_data_init(struct brw_stage_prog_data *prog_data, const struct brw_compile_params *params) { diff --git a/src/intel/compiler/brw/brw_shader.h b/src/intel/compiler/brw/brw_shader.h index 64eee6a9dcd..f91b56e3617 100644 --- a/src/intel/compiler/brw/brw_shader.h +++ b/src/intel/compiler/brw/brw_shader.h @@ -57,7 +57,6 @@ struct brw_shader_params const nir_shader *nir; const brw_base_prog_key *key; brw_stage_prog_data *prog_data; - unsigned dispatch_width; /* Fragment shader. */ @@ -125,7 +124,6 @@ public: const brw_base_prog_key *const key; struct brw_stage_prog_data *prog_data; - brw_analysis live_analysis; brw_analysis regpressure_analysis; brw_analysis performance_analysis; diff --git a/src/intel/vulkan/anv_internal_kernels.c b/src/intel/vulkan/anv_internal_kernels.c index 48d2fcd22b7..d3e0f11554a 100644 --- a/src/intel/vulkan/anv_internal_kernels.c +++ b/src/intel/vulkan/anv_internal_kernels.c @@ -180,7 +180,7 @@ compile_shader(struct anv_device *device, .prog_data = &prog_data.fs, }; prog_data.base.push_sizes[0] = align(prog_data.base.push_sizes[0], REG_SIZE); - program = brw_compile_fs(compiler, ¶ms); + program = brw_compile(compiler, ¶ms.base); if (!ANV_DEBUG(SHADER_PRINT)) { unsigned stat_idx = 0; @@ -216,7 +216,7 @@ compile_shader(struct anv_device *device, .key = &key.cs, .prog_data = &prog_data.cs, }; - program = brw_compile_cs(compiler, ¶ms); + program = brw_compile(compiler, ¶ms.base); if (!ANV_DEBUG(SHADER_PRINT)) { check_sends(&stats, sends_count_expectation); diff --git a/src/intel/vulkan/anv_shader.h b/src/intel/vulkan/anv_shader.h index cffe4286fce..c8dde75d4d4 100644 --- a/src/intel/vulkan/anv_shader.h +++ b/src/intel/vulkan/anv_shader.h @@ -112,7 +112,7 @@ struct anv_shader_data { bool uses_bt_for_push_descs; - unsigned *code; + const unsigned *code; debug_archiver *archiver; }; diff --git a/src/intel/vulkan/anv_shader_compile.c b/src/intel/vulkan/anv_shader_compile.c index 2739cee8600..7f74289f9bb 100644 --- a/src/intel/vulkan/anv_shader_compile.c +++ b/src/intel/vulkan/anv_shader_compile.c @@ -960,7 +960,7 @@ anv_shader_compile_vs(struct anv_device *device, shader_data->code = (void *) bin->kernel; } else { - shader_data->code = (void *) brw_compile_vs(compiler, ¶ms); + shader_data->code = (void *) brw_compile(compiler, ¶ms.base); } *error_str = params.base.error_str; @@ -993,7 +993,7 @@ anv_shader_compile_tcs(struct anv_device *device, .prog_data = &shader_data->prog_data.tcs, }; - shader_data->code = (void *)brw_compile_tcs(compiler, ¶ms); + shader_data->code = (void *)brw_compile(compiler, ¶ms.base); *error_str = params.base.error_str; } @@ -1031,7 +1031,7 @@ anv_shader_compile_tes(struct anv_device *device, &tcs_shader_data->prog_data.tcs.base.vue_map : NULL, }; - tes_shader_data->code = (void *)brw_compile_tes(compiler, ¶ms); + tes_shader_data->code = (void *)brw_compile(compiler, ¶ms.base); *error_str = params.base.error_str; } @@ -1059,7 +1059,7 @@ anv_shader_compile_gs(struct anv_device *device, .prog_data = &shader_data->prog_data.gs, }; - shader_data->code = (void *)brw_compile_gs(compiler, ¶ms); + shader_data->code = (void *)brw_compile(compiler, ¶ms.base); *error_str = params.base.error_str; } @@ -1087,7 +1087,7 @@ anv_shader_compile_task(struct anv_device *device, .prog_data = &shader_data->prog_data.task, }; - shader_data->code = (void *)brw_compile_task(compiler, ¶ms); + shader_data->code = (void *)brw_compile(compiler, ¶ms.base); *error_str = params.base.error_str; } @@ -1161,7 +1161,7 @@ anv_shader_compile_mesh(struct anv_device *device, .wa_18019110168_data = (void *)&mesh_shader_data->bind_map, }; - mesh_shader_data->code = (void *)brw_compile_mesh(compiler, ¶ms); + mesh_shader_data->code = (void *)brw_compile(compiler, ¶ms.base); *error_str = params.base.error_str; } @@ -1218,7 +1218,7 @@ anv_shader_compile_fs(struct anv_device *device, shader_data->code = (void *) bin->kernel; } else { - shader_data->code = (void *) brw_compile_fs(compiler, ¶ms); + shader_data->code = (void *) brw_compile(compiler, ¶ms.base); } *error_str = params.base.error_str; @@ -1279,7 +1279,7 @@ anv_shader_compile_cs(struct anv_device *device, params.prog_data->local_size[1] = nir->info.workgroup_size[1]; params.prog_data->local_size[2] = nir->info.workgroup_size[2]; } else { - shader_data->code = (void*)brw_compile_cs(compiler, ¶ms); + shader_data->code = (void*)brw_compile(compiler, ¶ms.base); } *error_str = params.base.error_str; @@ -1356,7 +1356,7 @@ anv_shader_compile_bs(struct anv_device *device, .resume_shaders = resume_shaders, }; - shader_data->code = (void *)brw_compile_bs(compiler, ¶ms); + shader_data->code = (void *)brw_compile(compiler, ¶ms.base); *error_str = params.base.error_str; } diff --git a/src/intel/vulkan/anv_util.c b/src/intel/vulkan/anv_util.c index 033578b1967..84844c7c6bf 100644 --- a/src/intel/vulkan/anv_util.c +++ b/src/intel/vulkan/anv_util.c @@ -422,7 +422,7 @@ anv_device_init_rt_shaders(struct anv_device *device) .prog_data = &trampoline_prog_data, }; const unsigned *tramp_data = - brw_compile_cs(device->physical->compiler, ¶ms); + brw_compile(device->physical->compiler, ¶ms.base); struct anv_shader_upload_params upload_params = { .stage = MESA_SHADER_COMPUTE, @@ -480,7 +480,7 @@ anv_device_init_rt_shaders(struct anv_device *device) .prog_data = &return_prog_data, }; const unsigned *return_data = - brw_compile_bs(device->physical->compiler, ¶ms); + brw_compile(device->physical->compiler, ¶ms.base); struct anv_shader_upload_params upload_params = { .stage = MESA_SHADER_CALLABLE, @@ -538,7 +538,7 @@ anv_device_init_rt_shaders(struct anv_device *device) .prog_data = &return_prog_data, }; const unsigned *return_data = - brw_compile_bs(device->physical->compiler, ¶ms); + brw_compile(device->physical->compiler, ¶ms.base); struct anv_shader_upload_params upload_params = { .stage = MESA_SHADER_CALLABLE,