diff --git a/src/gallium/drivers/iris/iris_program.c b/src/gallium/drivers/iris/iris_program.c index 90c0719a99c..9a20cd1743d 100644 --- a/src/gallium/drivers/iris/iris_program.c +++ b/src/gallium/drivers/iris/iris_program.c @@ -2051,12 +2051,16 @@ iris_compile_cs(struct iris_screen *screen, struct brw_cs_prog_key brw_key = iris_to_brw_cs_key(devinfo, key); - char *error_str = NULL; - const unsigned *program = - brw_compile_cs(compiler, dbg, mem_ctx, &brw_key, cs_prog_data, - nir, -1, NULL, &error_str); + struct brw_compile_cs_params params = { + .nir = nir, + .key = &brw_key, + .prog_data = cs_prog_data, + .log_data = dbg, + }; + + const unsigned *program = brw_compile_cs(compiler, mem_ctx, ¶ms); if (program == NULL) { - dbg_printf("Failed to compile compute shader: %s\n", error_str); + dbg_printf("Failed to compile compute shader: %s\n", params.error_str); ralloc_free(mem_ctx); return false; } diff --git a/src/intel/compiler/brw_compiler.h b/src/intel/compiler/brw_compiler.h index ded2ccc4947..b93c7bb2ac3 100644 --- a/src/intel/compiler/brw_compiler.h +++ b/src/intel/compiler/brw_compiler.h @@ -1588,20 +1588,36 @@ brw_compile_fs(const struct brw_compiler *compiler, void *mem_ctx, struct brw_compile_fs_params *params); +/** + * Parameters for compiling a compute shader. + * + * Some of these will be modified during the shader compilation. + */ +struct brw_compile_cs_params { + nir_shader *nir; + + const struct brw_cs_prog_key *key; + struct brw_cs_prog_data *prog_data; + + bool shader_time; + int shader_time_index; + + struct brw_compile_stats *stats; + + void *log_data; + + char *error_str; +}; + /** * Compile a compute shader. * - * Returns the final assembly and the program's size. + * Returns the final assembly and updates the parameters structure. */ const unsigned * -brw_compile_cs(const struct brw_compiler *compiler, void *log_data, +brw_compile_cs(const struct brw_compiler *compiler, void *mem_ctx, - const struct brw_cs_prog_key *key, - struct brw_cs_prog_data *prog_data, - const nir_shader *nir, - int shader_time_index, - struct brw_compile_stats *stats, - char **error_str); + struct brw_compile_cs_params *params); /** * Compile a Ray Tracing shader. diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp index 457b781c182..551a3ab21d4 100644 --- a/src/intel/compiler/brw_fs.cpp +++ b/src/intel/compiler/brw_fs.cpp @@ -9430,15 +9430,15 @@ compile_cs_to_nir(const struct brw_compiler *compiler, } const unsigned * -brw_compile_cs(const struct brw_compiler *compiler, void *log_data, +brw_compile_cs(const struct brw_compiler *compiler, void *mem_ctx, - const struct brw_cs_prog_key *key, - struct brw_cs_prog_data *prog_data, - const nir_shader *nir, - int shader_time_index, - struct brw_compile_stats *stats, - char **error_str) + struct brw_compile_cs_params *params) { + const nir_shader *nir = params->nir; + const struct brw_cs_prog_key *key = params->key; + struct brw_cs_prog_data *prog_data = params->prog_data; + int shader_time_index = params->shader_time ? params->shader_time_index : -1; + const bool debug_enabled = INTEL_DEBUG & DEBUG_CS; prog_data->base.stage = MESA_SHADER_COMPUTE; @@ -9482,10 +9482,8 @@ brw_compile_cs(const struct brw_compiler *compiler, void *log_data, required_dispatch_width == 32); if (required_dispatch_width < min_dispatch_width || required_dispatch_width > max_dispatch_width) { - if (error_str) { - *error_str = ralloc_strdup(mem_ctx, - "Cannot satisfy explicit subgroup size"); - } + params->error_str = ralloc_strdup(mem_ctx, + "Cannot satisfy explicit subgroup size"); return NULL; } min_dispatch_width = max_dispatch_width = required_dispatch_width; @@ -9500,12 +9498,11 @@ brw_compile_cs(const struct brw_compiler *compiler, void *log_data, min_dispatch_width <= 8 && max_dispatch_width >= 8) { nir_shader *nir8 = compile_cs_to_nir(compiler, mem_ctx, key, nir, 8, debug_enabled); - v8 = new fs_visitor(compiler, log_data, mem_ctx, &key->base, + v8 = new fs_visitor(compiler, params->log_data, mem_ctx, &key->base, &prog_data->base, nir8, 8, shader_time_index, debug_enabled); if (!v8->run_cs(true /* allow_spilling */)) { - if (error_str) - *error_str = ralloc_strdup(mem_ctx, v8->fail_msg); + params->error_str = ralloc_strdup(mem_ctx, v8->fail_msg); delete v8; return NULL; } @@ -9526,7 +9523,7 @@ brw_compile_cs(const struct brw_compiler *compiler, void *log_data, /* Try a SIMD16 compile */ nir_shader *nir16 = compile_cs_to_nir(compiler, mem_ctx, key, nir, 16, debug_enabled); - v16 = new fs_visitor(compiler, log_data, mem_ctx, &key->base, + v16 = new fs_visitor(compiler, params->log_data, mem_ctx, &key->base, &prog_data->base, nir16, 16, shader_time_index, debug_enabled); if (v8) @@ -9534,16 +9531,14 @@ brw_compile_cs(const struct brw_compiler *compiler, void *log_data, const bool allow_spilling = generate_all || v == NULL; if (!v16->run_cs(allow_spilling)) { - compiler->shader_perf_log(log_data, + compiler->shader_perf_log(params->log_data, "SIMD16 shader failed to compile: %s", v16->fail_msg); if (!v) { assert(v8 == NULL); - if (error_str) { - *error_str = ralloc_asprintf( - mem_ctx, "Not enough threads for SIMD8 and " - "couldn't generate SIMD16: %s", v16->fail_msg); - } + params->error_str = ralloc_asprintf( + mem_ctx, "Not enough threads for SIMD8 and " + "couldn't generate SIMD16: %s", v16->fail_msg); delete v16; return NULL; } @@ -9574,7 +9569,7 @@ brw_compile_cs(const struct brw_compiler *compiler, void *log_data, /* Try a SIMD32 compile */ nir_shader *nir32 = compile_cs_to_nir(compiler, mem_ctx, key, nir, 32, debug_enabled); - v32 = new fs_visitor(compiler, log_data, mem_ctx, &key->base, + v32 = new fs_visitor(compiler, params->log_data, mem_ctx, &key->base, &prog_data->base, nir32, 32, shader_time_index, debug_enabled); if (v8) @@ -9584,17 +9579,15 @@ brw_compile_cs(const struct brw_compiler *compiler, void *log_data, const bool allow_spilling = generate_all || v == NULL; if (!v32->run_cs(allow_spilling)) { - compiler->shader_perf_log(log_data, + compiler->shader_perf_log(params->log_data, "SIMD32 shader failed to compile: %s", v32->fail_msg); if (!v) { assert(v8 == NULL); assert(v16 == NULL); - if (error_str) { - *error_str = ralloc_asprintf( - mem_ctx, "Not enough threads for SIMD16 and " - "couldn't generate SIMD32: %s", v32->fail_msg); - } + params->error_str = ralloc_asprintf( + mem_ctx, "Not enough threads for SIMD16 and " + "couldn't generate SIMD32: %s", v32->fail_msg); delete v32; return NULL; } @@ -9608,11 +9601,9 @@ brw_compile_cs(const struct brw_compiler *compiler, void *log_data, } if (unlikely(!v) && (INTEL_DEBUG & (DEBUG_NO8 | DEBUG_NO16 | DEBUG_NO32))) { - if (error_str) { - *error_str = - ralloc_strdup(mem_ctx, - "Cannot satisfy INTEL_DEBUG flags SIMD restrictions"); - } + params->error_str = + ralloc_strdup(mem_ctx, + "Cannot satisfy INTEL_DEBUG flags SIMD restrictions"); return NULL; } @@ -9620,7 +9611,7 @@ brw_compile_cs(const struct brw_compiler *compiler, void *log_data, const unsigned *ret = NULL; - fs_generator g(compiler, log_data, mem_ctx, &prog_data->base, + fs_generator g(compiler, params->log_data, mem_ctx, &prog_data->base, v->runtime_check_aads_emit, MESA_SHADER_COMPUTE); if (unlikely(debug_enabled)) { char *name = ralloc_asprintf(mem_ctx, "%s compute shader %s", @@ -9630,6 +9621,7 @@ brw_compile_cs(const struct brw_compiler *compiler, void *log_data, g.enable_debug(name); } + struct brw_compile_stats *stats = params->stats; if (generate_all) { if (prog_data->prog_mask & (1 << 0)) { assert(v8); diff --git a/src/intel/vulkan/anv_pipeline.c b/src/intel/vulkan/anv_pipeline.c index dbde4fa9970..a9e8c199761 100644 --- a/src/intel/vulkan/anv_pipeline.c +++ b/src/intel/vulkan/anv_pipeline.c @@ -1747,9 +1747,16 @@ anv_pipeline_compile_cs(struct anv_compute_pipeline *pipeline, NIR_PASS_V(stage.nir, brw_nir_lower_cs_intrinsics); stage.num_stats = 1; - stage.code = brw_compile_cs(compiler, pipeline->base.device, mem_ctx, - &stage.key.cs, &stage.prog_data.cs, - stage.nir, -1, stage.stats, NULL); + + struct brw_compile_cs_params params = { + .nir = stage.nir, + .key = &stage.key.cs, + .prog_data = &stage.prog_data.cs, + .stats = stage.stats, + .log_data = pipeline->base.device, + }; + + stage.code = brw_compile_cs(compiler, mem_ctx, ¶ms); if (stage.code == NULL) { ralloc_free(mem_ctx); return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY); diff --git a/src/mesa/drivers/dri/i965/brw_cs.c b/src/mesa/drivers/dri/i965/brw_cs.c index 6f93ea3c06c..6d9a418b0ec 100644 --- a/src/mesa/drivers/dri/i965/brw_cs.c +++ b/src/mesa/drivers/dri/i965/brw_cs.c @@ -114,19 +114,27 @@ brw_codegen_cs_prog(struct brw_context *brw, start_time = get_time(); } - int st_index = -1; - if (INTEL_DEBUG & DEBUG_SHADER_TIME) - st_index = brw_get_shader_time_index(brw, &cp->program, ST_CS, true); brw_nir_lower_cs_intrinsics(nir); - char *error_str; - program = brw_compile_cs(brw->screen->compiler, brw, mem_ctx, key, - &prog_data, nir, st_index, NULL, &error_str); + struct brw_compile_cs_params params = { + .nir = nir, + .key = key, + .prog_data = &prog_data, + .log_data = brw, + }; + + if (INTEL_DEBUG & DEBUG_SHADER_TIME) { + params.shader_time = true; + params.shader_time_index = + brw_get_shader_time_index(brw, &cp->program, ST_CS, true); + } + + program = brw_compile_cs(brw->screen->compiler, mem_ctx, ¶ms); if (program == NULL) { cp->program.sh.data->LinkStatus = LINKING_FAILURE; - ralloc_strcat(&cp->program.sh.data->InfoLog, error_str); - _mesa_problem(NULL, "Failed to compile compute shader: %s\n", error_str); + ralloc_strcat(&cp->program.sh.data->InfoLog, params.error_str); + _mesa_problem(NULL, "Failed to compile compute shader: %s\n", params.error_str); ralloc_free(mem_ctx); return false;