diff options
author | Marek Olšák <[email protected]> | 2019-07-02 18:43:40 -0400 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2019-07-09 17:24:16 -0400 |
commit | 3be4ed2fe1ee8629a486156a764b451513d34aac (patch) | |
tree | 8a4b395a6da52384ee7a5f9749ab5ccebb082528 | |
parent | 37b26671a75d8d6e9fa293b1bdb8df78763f3c03 (diff) |
radeonsi: fix and clean up shader_type passing
- don't pass it via a parameter if it can be derived from other parameters
- set shader_type for ac_rtld_open
- use enum pipe_shader_type instead of unsigned
Acked-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Acked-by: Dave Airlie <[email protected]>
-rw-r--r-- | src/gallium/drivers/radeonsi/si_compute.c | 7 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_debug.c | 27 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_pipe.c | 2 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_shader.c | 83 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_shader.h | 6 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c | 2 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_state_shaders.c | 4 |
7 files changed, 71 insertions, 60 deletions
diff --git a/src/gallium/drivers/radeonsi/si_compute.c b/src/gallium/drivers/radeonsi/si_compute.c index 54f35cfcfd9..f4fabca8635 100644 --- a/src/gallium/drivers/radeonsi/si_compute.c +++ b/src/gallium/drivers/radeonsi/si_compute.c @@ -66,6 +66,7 @@ static const amd_kernel_code_t *si_compute_get_code_object( struct ac_rtld_binary rtld; if (!ac_rtld_open(&rtld, (struct ac_rtld_open_info){ .info = &program->screen->info, + .shader_type = MESA_SHADER_COMPUTE, .num_parts = 1, .elf_ptrs = &program->shader.binary.elf_buffer, .elf_sizes = &program->shader.binary.elf_size })) @@ -164,8 +165,7 @@ static void si_create_compute_state_async(void *job, int thread_index) mtx_unlock(&sscreen->shader_cache_mutex); si_shader_dump_stats_for_shader_db(sscreen, shader, debug); - si_shader_dump(sscreen, shader, debug, PIPE_SHADER_COMPUTE, - stderr, true); + si_shader_dump(sscreen, shader, debug, stderr, true); if (!si_shader_binary_upload(sscreen, shader, 0)) program->shader.compilation_failed = true; @@ -276,8 +276,7 @@ static void *si_create_compute_state( si_compute_get_code_object(program, 0); code_object_to_config(code_object, &program->shader.config); - si_shader_dump(sctx->screen, &program->shader, &sctx->debug, - PIPE_SHADER_COMPUTE, stderr, true); + si_shader_dump(sctx->screen, &program->shader, &sctx->debug, stderr, true); if (!si_shader_binary_upload(sctx->screen, &program->shader, 0)) { fprintf(stderr, "LLVM failed to upload shader\n"); free((void *)program->shader.binary.elf_buffer); diff --git a/src/gallium/drivers/radeonsi/si_debug.c b/src/gallium/drivers/radeonsi/si_debug.c index 8265159c0d0..7d2f492fcc8 100644 --- a/src/gallium/drivers/radeonsi/si_debug.c +++ b/src/gallium/drivers/radeonsi/si_debug.c @@ -26,6 +26,7 @@ #include "si_compute.h" #include "sid.h" #include "sid_tables.h" +#include "tgsi/tgsi_from_mesa.h" #include "driver_ddebug/dd_util.h" #include "util/u_dump.h" #include "util/u_log.h" @@ -98,13 +99,12 @@ void si_destroy_saved_cs(struct si_saved_cs *scs) } static void si_dump_shader(struct si_screen *sscreen, - enum pipe_shader_type processor, struct si_shader *shader, FILE *f) { if (shader->shader_log) fwrite(shader->shader_log, shader->shader_log_size, 1, f); else - si_shader_dump(sscreen, shader, NULL, processor, f, false); + si_shader_dump(sscreen, shader, NULL, f, false); if (shader->bo && sscreen->options.dump_shader_binary) { unsigned size = shader->bo->b.b.width0; @@ -136,7 +136,6 @@ struct si_log_chunk_shader { */ struct si_context *ctx; struct si_shader *shader; - enum pipe_shader_type processor; /* For keep-alive reference counts */ struct si_shader_selector *sel; @@ -157,8 +156,7 @@ si_log_chunk_shader_print(void *data, FILE *f) { struct si_log_chunk_shader *chunk = data; struct si_screen *sscreen = chunk->ctx->screen; - si_dump_shader(sscreen, chunk->processor, - chunk->shader, f); + si_dump_shader(sscreen, chunk->shader, f); } static struct u_log_chunk_type si_log_chunk_type_shader = { @@ -177,7 +175,6 @@ static void si_dump_gfx_shader(struct si_context *ctx, struct si_log_chunk_shader *chunk = CALLOC_STRUCT(si_log_chunk_shader); chunk->ctx = ctx; - chunk->processor = state->cso->info.processor; chunk->shader = current; si_shader_selector_reference(ctx, &chunk->sel, current->selector); u_log_chunk(log, &si_log_chunk_type_shader, chunk); @@ -193,7 +190,6 @@ static void si_dump_compute_shader(struct si_context *ctx, struct si_log_chunk_shader *chunk = CALLOC_STRUCT(si_log_chunk_shader); chunk->ctx = ctx; - chunk->processor = PIPE_SHADER_COMPUTE; chunk->shader = &state->program->shader; si_compute_reference(&chunk->program, state->program); u_log_chunk(log, &si_log_chunk_type_shader, chunk); @@ -942,10 +938,12 @@ static void si_add_split_disasm(struct si_screen *screen, struct si_shader_binary *binary, uint64_t *addr, unsigned *num, - struct si_shader_inst *instructions) + struct si_shader_inst *instructions, + enum pipe_shader_type shader_type) { if (!ac_rtld_open(rtld_binary, (struct ac_rtld_open_info){ .info = &screen->info, + .shader_type = tgsi_processor_to_shader_stage(shader_type), .num_parts = 1, .elf_ptrs = &binary->elf_buffer, .elf_sizes = &binary->elf_size })) @@ -995,6 +993,7 @@ static void si_print_annotated_shader(struct si_shader *shader, return; struct si_screen *screen = shader->selector->screen; + enum pipe_shader_type shader_type = shader->selector->type; uint64_t start_addr = shader->bo->gpu_address; uint64_t end_addr = start_addr + shader->bo->b.b.width0; unsigned i; @@ -1022,25 +1021,25 @@ static void si_print_annotated_shader(struct si_shader *shader, if (shader->prolog) { si_add_split_disasm(screen, &rtld_binaries[0], &shader->prolog->binary, - &inst_addr, &num_inst, instructions); + &inst_addr, &num_inst, instructions, shader_type); } if (shader->previous_stage) { si_add_split_disasm(screen, &rtld_binaries[1], &shader->previous_stage->binary, - &inst_addr, &num_inst, instructions); + &inst_addr, &num_inst, instructions, shader_type); } if (shader->prolog2) { si_add_split_disasm(screen, &rtld_binaries[2], &shader->prolog2->binary, - &inst_addr, &num_inst, instructions); + &inst_addr, &num_inst, instructions, shader_type); } si_add_split_disasm(screen, &rtld_binaries[3], &shader->binary, - &inst_addr, &num_inst, instructions); + &inst_addr, &num_inst, instructions, shader_type); if (shader->epilog) { si_add_split_disasm(screen, &rtld_binaries[4], &shader->epilog->binary, - &inst_addr, &num_inst, instructions); + &inst_addr, &num_inst, instructions, shader_type); } fprintf(f, COLOR_YELLOW "%s - annotated disassembly:" COLOR_RESET "\n", - si_get_shader_name(shader, shader->selector->type)); + si_get_shader_name(shader)); /* Print instructions with annotations. */ for (i = 0; i < num_inst; i++) { diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c index 85e9fe8f7bc..07b483a7668 100644 --- a/src/gallium/drivers/radeonsi/si_pipe.c +++ b/src/gallium/drivers/radeonsi/si_pipe.c @@ -884,7 +884,7 @@ static void si_set_max_shader_compiler_threads(struct pipe_screen *screen, static bool si_is_parallel_shader_compilation_finished(struct pipe_screen *screen, void *shader, - unsigned shader_type) + enum pipe_shader_type shader_type) { if (shader_type == PIPE_SHADER_COMPUTE) { struct si_compute *cs = (struct si_compute*)shader; diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index 756199a3496..610edcb9a78 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -55,8 +55,7 @@ static void si_llvm_emit_barrier(const struct lp_build_tgsi_action *action, struct lp_build_tgsi_context *bld_base, struct lp_build_emit_data *emit_data); -static void si_dump_shader_key(unsigned processor, const struct si_shader *shader, - FILE *f); +static void si_dump_shader_key(const struct si_shader *shader, FILE *f); static void si_build_vs_prolog_function(struct si_shader_context *ctx, union si_shader_part_key *key); @@ -5362,6 +5361,7 @@ bool si_shader_binary_upload(struct si_screen *sscreen, struct si_shader *shader static void si_shader_dump_disassembly(struct si_screen *screen, const struct si_shader_binary *binary, + enum pipe_shader_type shader_type, struct pipe_debug_callback *debug, const char *name, FILE *file) { @@ -5369,6 +5369,7 @@ static void si_shader_dump_disassembly(struct si_screen *screen, if (!ac_rtld_open(&rtld_binary, (struct ac_rtld_open_info){ .info = &screen->info, + .shader_type = tgsi_processor_to_shader_stage(shader_type), .num_parts = 1, .elf_ptrs = &binary->elf_buffer, .elf_sizes = &binary->elf_size })) @@ -5455,6 +5456,7 @@ static void si_calculate_max_simd_waves(struct si_shader *shader) DIV_ROUND_UP(max_workgroup_size, 64); } break; + default:; } /* Compute the per-SIMD wave counts. */ @@ -5482,7 +5484,9 @@ void si_shader_dump_stats_for_shader_db(struct si_screen *screen, const struct ac_shader_config *conf = &shader->config; if (screen->options.debug_disassembly) - si_shader_dump_disassembly(screen, &shader->binary, debug, "main", NULL); + si_shader_dump_disassembly(screen, &shader->binary, + shader->selector->type, + debug, "main", NULL); pipe_debug_message(debug, SHADER_INFO, "Shader Stats: SGPRS: %d VGPRS: %d Code Size: %d " @@ -5497,15 +5501,16 @@ void si_shader_dump_stats_for_shader_db(struct si_screen *screen, static void si_shader_dump_stats(struct si_screen *sscreen, struct si_shader *shader, - unsigned processor, FILE *file, bool check_debug_option) { const struct ac_shader_config *conf = &shader->config; + enum pipe_shader_type shader_type = + shader->selector ? shader->selector->type : PIPE_SHADER_COMPUTE; if (!check_debug_option || - si_can_dump_shader(sscreen, processor)) { - if (processor == PIPE_SHADER_FRAGMENT) { + si_can_dump_shader(sscreen, shader_type)) { + if (shader_type == PIPE_SHADER_FRAGMENT) { fprintf(file, "*** SHADER CONFIG ***\n" "SPI_PS_INPUT_ADDR = 0x%04x\n" "SPI_PS_INPUT_ENA = 0x%04x\n", @@ -5532,9 +5537,12 @@ static void si_shader_dump_stats(struct si_screen *sscreen, } } -const char *si_get_shader_name(const struct si_shader *shader, unsigned processor) +const char *si_get_shader_name(const struct si_shader *shader) { - switch (processor) { + enum pipe_shader_type shader_type = + shader->selector ? shader->selector->type : PIPE_SHADER_COMPUTE; + + switch (shader_type) { case PIPE_SHADER_VERTEX: if (shader->key.as_es) return "Vertex Shader as ES"; @@ -5570,51 +5578,53 @@ const char *si_get_shader_name(const struct si_shader *shader, unsigned processo } void si_shader_dump(struct si_screen *sscreen, struct si_shader *shader, - struct pipe_debug_callback *debug, unsigned processor, + struct pipe_debug_callback *debug, FILE *file, bool check_debug_option) { + enum pipe_shader_type shader_type = + shader->selector ? shader->selector->type : PIPE_SHADER_COMPUTE; + if (!check_debug_option || - si_can_dump_shader(sscreen, processor)) - si_dump_shader_key(processor, shader, file); + si_can_dump_shader(sscreen, shader_type)) + si_dump_shader_key(shader, file); if (!check_debug_option && shader->binary.llvm_ir_string) { if (shader->previous_stage && shader->previous_stage->binary.llvm_ir_string) { fprintf(file, "\n%s - previous stage - LLVM IR:\n\n", - si_get_shader_name(shader, processor)); + si_get_shader_name(shader)); fprintf(file, "%s\n", shader->previous_stage->binary.llvm_ir_string); } fprintf(file, "\n%s - main shader part - LLVM IR:\n\n", - si_get_shader_name(shader, processor)); + si_get_shader_name(shader)); fprintf(file, "%s\n", shader->binary.llvm_ir_string); } if (!check_debug_option || - (si_can_dump_shader(sscreen, processor) && + (si_can_dump_shader(sscreen, shader_type) && !(sscreen->debug_flags & DBG(NO_ASM)))) { - fprintf(file, "\n%s:\n", si_get_shader_name(shader, processor)); + fprintf(file, "\n%s:\n", si_get_shader_name(shader)); if (shader->prolog) si_shader_dump_disassembly(sscreen, &shader->prolog->binary, - debug, "prolog", file); + shader_type, debug, "prolog", file); if (shader->previous_stage) si_shader_dump_disassembly(sscreen, &shader->previous_stage->binary, - debug, "previous stage", file); + shader_type, debug, "previous stage", file); if (shader->prolog2) si_shader_dump_disassembly(sscreen, &shader->prolog2->binary, - debug, "prolog2", file); + shader_type, debug, "prolog2", file); - si_shader_dump_disassembly(sscreen, &shader->binary, debug, "main", file); + si_shader_dump_disassembly(sscreen, &shader->binary, shader_type, debug, "main", file); if (shader->epilog) si_shader_dump_disassembly(sscreen, &shader->epilog->binary, - debug, "epilog", file); + shader_type, debug, "epilog", file); fprintf(file, "\n"); } - si_shader_dump_stats(sscreen, shader, processor, file, - check_debug_option); + si_shader_dump_stats(sscreen, shader, file, check_debug_option); } static int si_compile_llvm(struct si_screen *sscreen, @@ -5623,13 +5633,13 @@ static int si_compile_llvm(struct si_screen *sscreen, struct ac_llvm_compiler *compiler, LLVMModuleRef mod, struct pipe_debug_callback *debug, - unsigned processor, + enum pipe_shader_type shader_type, const char *name, bool less_optimized) { unsigned count = p_atomic_inc_return(&sscreen->num_compilations); - if (si_can_dump_shader(sscreen, processor)) { + if (si_can_dump_shader(sscreen, shader_type)) { fprintf(stderr, "radeonsi: Compiling shader %d\n", count); if (!(sscreen->debug_flags & (DBG(NO_IR) | DBG(PREOPT_IR)))) { @@ -5655,6 +5665,7 @@ static int si_compile_llvm(struct si_screen *sscreen, struct ac_rtld_binary rtld; if (!ac_rtld_open(&rtld, (struct ac_rtld_open_info){ .info = &sscreen->info, + .shader_type = tgsi_processor_to_shader_stage(shader_type), .num_parts = 1, .elf_ptrs = &binary->elf_buffer, .elf_sizes = &binary->elf_size })) @@ -5819,8 +5830,7 @@ si_generate_gs_copy_shader(struct si_screen *sscreen, "GS Copy Shader", false) == 0) { if (si_can_dump_shader(sscreen, PIPE_SHADER_GEOMETRY)) fprintf(stderr, "GS Copy Shader:\n"); - si_shader_dump(sscreen, ctx.shader, debug, - PIPE_SHADER_GEOMETRY, stderr, true); + si_shader_dump(sscreen, ctx.shader, debug, stderr, true); if (!ctx.shader->config.scratch_bytes_per_wave) ok = si_shader_binary_upload(sscreen, ctx.shader, 0); @@ -5867,14 +5877,15 @@ static void si_dump_shader_key_vs(const struct si_shader_key *key, fprintf(f, "}\n"); } -static void si_dump_shader_key(unsigned processor, const struct si_shader *shader, - FILE *f) +static void si_dump_shader_key(const struct si_shader *shader, FILE *f) { const struct si_shader_key *key = &shader->key; + enum pipe_shader_type shader_type = + shader->selector ? shader->selector->type : PIPE_SHADER_COMPUTE; fprintf(f, "SHADER KEY\n"); - switch (processor) { + switch (shader_type) { case PIPE_SHADER_VERTEX: si_dump_shader_key_vs(key, &key->part.vs.prolog, "part.vs.prolog", f); @@ -5960,9 +5971,9 @@ static void si_dump_shader_key(unsigned processor, const struct si_shader *shade assert(0); } - if ((processor == PIPE_SHADER_GEOMETRY || - processor == PIPE_SHADER_TESS_EVAL || - processor == PIPE_SHADER_VERTEX) && + if ((shader_type == PIPE_SHADER_GEOMETRY || + shader_type == PIPE_SHADER_TESS_EVAL || + shader_type == PIPE_SHADER_VERTEX) && !key->as_es && !key->as_ls) { fprintf(f, " opt.kill_outputs = 0x%"PRIx64"\n", key->opt.kill_outputs); fprintf(f, " opt.clip_disable = %u\n", key->opt.clip_disable); @@ -6907,7 +6918,7 @@ int si_compile_tgsi_shader(struct si_screen *sscreen, /* Dump TGSI code before doing TGSI->LLVM conversion in case the * conversion fails. */ - if (si_can_dump_shader(sscreen, sel->info.processor) && + if (si_can_dump_shader(sscreen, sel->type) && !(sscreen->debug_flags & DBG(NO_TGSI))) { if (sel->tokens) tgsi_dump(sel->tokens, 0); @@ -7132,7 +7143,7 @@ int si_compile_tgsi_shader(struct si_screen *sscreen, /* Compile to bytecode. */ r = si_compile_llvm(sscreen, &shader->binary, &shader->config, compiler, ctx.ac.module, debug, ctx.type, - si_get_shader_name(shader, ctx.type), + si_get_shader_name(shader), si_should_optimize_less(compiler, shader->selector)); si_llvm_dispose(&ctx); if (r) { @@ -8310,6 +8321,7 @@ bool si_shader_create(struct si_screen *sscreen, struct ac_llvm_compiler *compil shader->config.num_vgprs = MAX2(shader->config.num_vgprs, shader->info.num_input_vgprs); break; + default:; } /* Update SGPR and VGPR counts. */ @@ -8362,8 +8374,7 @@ bool si_shader_create(struct si_screen *sscreen, struct ac_llvm_compiler *compil } si_fix_resource_usage(sscreen, shader); - si_shader_dump(sscreen, shader, debug, sel->info.processor, - stderr, true); + si_shader_dump(sscreen, shader, debug, stderr, true); /* Upload. */ if (!si_shader_binary_upload(sscreen, shader, 0)) { diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h index 86d91f29b3c..8fb4b563b78 100644 --- a/src/gallium/drivers/radeonsi/si_shader.h +++ b/src/gallium/drivers/radeonsi/si_shader.h @@ -347,7 +347,7 @@ struct si_shader_selector { struct tgsi_tessctrl_info tcs_info; /* PIPE_SHADER_[VERTEX|FRAGMENT|...] */ - unsigned type; + enum pipe_shader_type type; bool vs_needs_prolog; bool force_correct_derivs_after_kill; bool prim_discard_cs_allowed; @@ -753,14 +753,14 @@ unsigned si_shader_io_get_unique_index(unsigned semantic_name, unsigned index, bool si_shader_binary_upload(struct si_screen *sscreen, struct si_shader *shader, uint64_t scratch_va); void si_shader_dump(struct si_screen *sscreen, struct si_shader *shader, - struct pipe_debug_callback *debug, unsigned processor, + struct pipe_debug_callback *debug, FILE *f, bool check_debug_option); void si_shader_dump_stats_for_shader_db(struct si_screen *screen, struct si_shader *shader, struct pipe_debug_callback *debug); void si_multiwave_lds_size_workaround(struct si_screen *sscreen, unsigned *lds_size); -const char *si_get_shader_name(const struct si_shader *shader, unsigned processor); +const char *si_get_shader_name(const struct si_shader *shader); void si_shader_binary_clean(struct si_shader_binary *binary); /* si_shader_nir.c */ diff --git a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c index a9946d99185..1690c3cb8a8 100644 --- a/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c +++ b/src/gallium/drivers/radeonsi/si_shader_tgsi_setup.c @@ -1105,7 +1105,7 @@ void si_llvm_create_func(struct si_shader_context *ctx, LLVMTypeRef main_fn_type, ret_type; LLVMBasicBlockRef main_fn_body; enum si_llvm_calling_convention call_conv; - unsigned real_shader_type; + enum pipe_shader_type real_shader_type; if (num_return_elems) ret_type = LLVMStructTypeInContext(ctx->ac.context, diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c index 44abc186d16..6e77ca9fc59 100644 --- a/src/gallium/drivers/radeonsi/si_state_shaders.c +++ b/src/gallium/drivers/radeonsi/si_state_shaders.c @@ -2049,7 +2049,7 @@ static void si_build_shader_variant(struct si_shader *shader, FILE *f = open_memstream(&shader->shader_log, &shader->shader_log_size); if (f) { - si_shader_dump(sscreen, shader, NULL, sel->type, f, false); + si_shader_dump(sscreen, shader, NULL, f, false); fclose(f); } } @@ -2785,6 +2785,7 @@ static void *si_create_shader_selector(struct pipe_context *ctx, } } break; + default:; } /* PA_CL_VS_OUT_CNTL */ @@ -3135,6 +3136,7 @@ static void si_delete_shader(struct si_context *sctx, struct si_shader *shader) case PIPE_SHADER_FRAGMENT: si_pm4_delete_state(sctx, ps, shader->pm4); break; + default:; } } |