diff options
author | Nicolai Hähnle <[email protected]> | 2019-05-03 21:18:51 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2019-06-12 20:28:23 -0400 |
commit | f8315ae04b304bbdb47680654238edd107c5a129 (patch) | |
tree | f6b0c284ea97df378392b5b48811397ce32c88d6 /src/gallium | |
parent | dc99a8cd9bf743746926c062a7c921f272e1648f (diff) |
amd/rtld: layout and relocate LDS symbols
Upcoming changes to LLVM will emit LDS objects as symbols in the ELF
symbol table, with relocations that will be resolved with this change.
Callers will also be able to define LDS symbols that are shared between
shader parts. This will be used by radeonsi for the ESGS ring in gfx9+
merged shaders.
Reviewed-by: Marek Olšák <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/drivers/radeonsi/si_compute.c | 9 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_debug.c | 22 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_shader.c | 61 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_shader.h | 5 | ||||
-rw-r--r-- | src/gallium/drivers/radeonsi/si_state_shaders.c | 2 |
5 files changed, 66 insertions, 33 deletions
diff --git a/src/gallium/drivers/radeonsi/si_compute.c b/src/gallium/drivers/radeonsi/si_compute.c index 7eadbcdd960..7e5259b70a0 100644 --- a/src/gallium/drivers/radeonsi/si_compute.c +++ b/src/gallium/drivers/radeonsi/si_compute.c @@ -64,8 +64,11 @@ static const amd_kernel_code_t *si_compute_get_code_object( } struct ac_rtld_binary rtld; - if (!ac_rtld_open(&rtld, 1, &program->shader.binary.elf_buffer, - &program->shader.binary.elf_size)) + if (!ac_rtld_open(&rtld, (struct ac_rtld_open_info){ + .info = &program->screen->info, + .num_parts = 1, + .elf_ptrs = &program->shader.binary.elf_buffer, + .elf_sizes = &program->shader.binary.elf_size })) return NULL; const amd_kernel_code_t *result = NULL; @@ -160,7 +163,7 @@ static void si_create_compute_state_async(void *job, int thread_index) si_shader_cache_load_shader(sscreen, ir_binary, shader)) { mtx_unlock(&sscreen->shader_cache_mutex); - si_shader_dump_stats_for_shader_db(shader, debug); + si_shader_dump_stats_for_shader_db(sscreen, shader, debug); si_shader_dump(sscreen, shader, debug, PIPE_SHADER_COMPUTE, stderr, true); diff --git a/src/gallium/drivers/radeonsi/si_debug.c b/src/gallium/drivers/radeonsi/si_debug.c index b11f7cc6e4f..0f2e81dd600 100644 --- a/src/gallium/drivers/radeonsi/si_debug.c +++ b/src/gallium/drivers/radeonsi/si_debug.c @@ -99,7 +99,7 @@ void si_destroy_saved_cs(struct si_saved_cs *scs) static void si_dump_shader(struct si_screen *sscreen, enum pipe_shader_type processor, - const struct si_shader *shader, FILE *f) + struct si_shader *shader, FILE *f) { if (shader->shader_log) fwrite(shader->shader_log, shader->shader_log_size, 1, f); @@ -935,13 +935,18 @@ struct si_shader_inst { * The caller must keep \p rtld_binary alive as long as \p instructions are * used and then close it afterwards. */ -static void si_add_split_disasm(struct ac_rtld_binary *rtld_binary, +static void si_add_split_disasm(struct si_screen *screen, + struct ac_rtld_binary *rtld_binary, struct si_shader_binary *binary, uint64_t *addr, unsigned *num, struct si_shader_inst *instructions) { - if (!ac_rtld_open(rtld_binary, 1, &binary->elf_buffer, &binary->elf_size)) + if (!ac_rtld_open(rtld_binary, (struct ac_rtld_open_info){ + .info = &screen->info, + .num_parts = 1, + .elf_ptrs = &binary->elf_buffer, + .elf_sizes = &binary->elf_size })) return; const char *disasm; @@ -987,6 +992,7 @@ static void si_print_annotated_shader(struct si_shader *shader, if (!shader) return; + struct si_screen *screen = shader->selector->screen; uint64_t start_addr = shader->bo->gpu_address; uint64_t end_addr = start_addr + shader->bo->b.b.width0; unsigned i; @@ -1013,21 +1019,21 @@ static void si_print_annotated_shader(struct si_shader *shader, calloc(shader->bo->b.b.width0 / 4, sizeof(struct si_shader_inst)); if (shader->prolog) { - si_add_split_disasm(&rtld_binaries[0], &shader->prolog->binary, + si_add_split_disasm(screen, &rtld_binaries[0], &shader->prolog->binary, &inst_addr, &num_inst, instructions); } if (shader->previous_stage) { - si_add_split_disasm(&rtld_binaries[1], &shader->previous_stage->binary, + si_add_split_disasm(screen, &rtld_binaries[1], &shader->previous_stage->binary, &inst_addr, &num_inst, instructions); } if (shader->prolog2) { - si_add_split_disasm(&rtld_binaries[2], &shader->prolog2->binary, + si_add_split_disasm(screen, &rtld_binaries[2], &shader->prolog2->binary, &inst_addr, &num_inst, instructions); } - si_add_split_disasm(&rtld_binaries[3], &shader->binary, + si_add_split_disasm(screen, &rtld_binaries[3], &shader->binary, &inst_addr, &num_inst, instructions); if (shader->epilog) { - si_add_split_disasm(&rtld_binaries[4], &shader->epilog->binary, + si_add_split_disasm(screen, &rtld_binaries[4], &shader->epilog->binary, &inst_addr, &num_inst, instructions); } diff --git a/src/gallium/drivers/radeonsi/si_shader.c b/src/gallium/drivers/radeonsi/si_shader.c index 2beb3f9f2ef..ab97cd87273 100644 --- a/src/gallium/drivers/radeonsi/si_shader.c +++ b/src/gallium/drivers/radeonsi/si_shader.c @@ -5051,7 +5051,8 @@ static void si_llvm_emit_polygon_stipple(struct si_shader_context *ctx, #define DEBUGGER_END_OF_CODE_MARKER 0xbf9f0000 /* invalid instruction */ #define DEBUGGER_NUM_MARKERS 5 -static bool si_shader_binary_open(const struct si_shader *shader, +static bool si_shader_binary_open(struct si_screen *screen, + struct si_shader *shader, struct ac_rtld_binary *rtld) { const char *part_elfs[5]; @@ -5073,13 +5074,25 @@ static bool si_shader_binary_open(const struct si_shader *shader, #undef add_part - return ac_rtld_open(rtld, num_parts, part_elfs, part_sizes); + bool ok = ac_rtld_open(rtld, (struct ac_rtld_open_info){ + .info = &screen->info, + .num_parts = num_parts, + .elf_ptrs = part_elfs, + .elf_sizes = part_sizes }); + + if (rtld->lds_size > 0) { + unsigned alloc_granularity = screen->info.chip_class >= GFX7 ? 512 : 256; + shader->config.lds_size = + align(rtld->lds_size, alloc_granularity) / alloc_granularity; + } + + return ok; } -static unsigned si_get_shader_binary_size(const struct si_shader *shader) +static unsigned si_get_shader_binary_size(struct si_screen *screen, struct si_shader *shader) { struct ac_rtld_binary rtld; - si_shader_binary_open(shader, &rtld); + si_shader_binary_open(screen, shader, &rtld); return rtld.rx_size; } @@ -5111,7 +5124,7 @@ bool si_shader_binary_upload(struct si_screen *sscreen, struct si_shader *shader uint64_t scratch_va) { struct ac_rtld_binary binary; - if (!si_shader_binary_open(shader, &binary)) + if (!si_shader_binary_open(sscreen, shader, &binary)) return false; si_resource_reference(&shader->bo, NULL); @@ -5145,13 +5158,18 @@ bool si_shader_binary_upload(struct si_screen *sscreen, struct si_shader *shader return ok; } -static void si_shader_dump_disassembly(const struct si_shader_binary *binary, +static void si_shader_dump_disassembly(struct si_screen *screen, + const struct si_shader_binary *binary, struct pipe_debug_callback *debug, const char *name, FILE *file) { struct ac_rtld_binary rtld_binary; - if (!ac_rtld_open(&rtld_binary, 1, &binary->elf_buffer, &binary->elf_size)) + if (!ac_rtld_open(&rtld_binary, (struct ac_rtld_open_info){ + .info = &screen->info, + .num_parts = 1, + .elf_ptrs = &binary->elf_buffer, + .elf_sizes = &binary->elf_size })) return; const char *disasm; @@ -5255,7 +5273,8 @@ static void si_calculate_max_simd_waves(struct si_shader *shader) shader->info.max_simd_waves = max_simd_waves; } -void si_shader_dump_stats_for_shader_db(const struct si_shader *shader, +void si_shader_dump_stats_for_shader_db(struct si_screen *screen, + struct si_shader *shader, struct pipe_debug_callback *debug) { const struct ac_shader_config *conf = &shader->config; @@ -5265,14 +5284,14 @@ void si_shader_dump_stats_for_shader_db(const struct si_shader *shader, "LDS: %d Scratch: %d Max Waves: %d Spilled SGPRs: %d " "Spilled VGPRs: %d PrivMem VGPRs: %d", conf->num_sgprs, conf->num_vgprs, - si_get_shader_binary_size(shader), + si_get_shader_binary_size(screen, shader), conf->lds_size, conf->scratch_bytes_per_wave, shader->info.max_simd_waves, conf->spilled_sgprs, conf->spilled_vgprs, shader->info.private_mem_vgprs); } static void si_shader_dump_stats(struct si_screen *sscreen, - const struct si_shader *shader, + struct si_shader *shader, unsigned processor, FILE *file, bool check_debug_option) @@ -5302,7 +5321,7 @@ static void si_shader_dump_stats(struct si_screen *sscreen, conf->num_sgprs, conf->num_vgprs, conf->spilled_sgprs, conf->spilled_vgprs, shader->info.private_mem_vgprs, - si_get_shader_binary_size(shader), + si_get_shader_binary_size(sscreen, shader), conf->lds_size, conf->scratch_bytes_per_wave, shader->info.max_simd_waves); } @@ -5341,7 +5360,7 @@ const char *si_get_shader_name(const struct si_shader *shader, unsigned processo } } -void si_shader_dump(struct si_screen *sscreen, const struct si_shader *shader, +void si_shader_dump(struct si_screen *sscreen, struct si_shader *shader, struct pipe_debug_callback *debug, unsigned processor, FILE *file, bool check_debug_option) { @@ -5368,19 +5387,19 @@ void si_shader_dump(struct si_screen *sscreen, const struct si_shader *shader, fprintf(file, "\n%s:\n", si_get_shader_name(shader, processor)); if (shader->prolog) - si_shader_dump_disassembly(&shader->prolog->binary, + si_shader_dump_disassembly(sscreen, &shader->prolog->binary, debug, "prolog", file); if (shader->previous_stage) - si_shader_dump_disassembly(&shader->previous_stage->binary, + si_shader_dump_disassembly(sscreen, &shader->previous_stage->binary, debug, "previous stage", file); if (shader->prolog2) - si_shader_dump_disassembly(&shader->prolog2->binary, + si_shader_dump_disassembly(sscreen, &shader->prolog2->binary, debug, "prolog2", file); - si_shader_dump_disassembly(&shader->binary, debug, "main", file); + si_shader_dump_disassembly(sscreen, &shader->binary, debug, "main", file); if (shader->epilog) - si_shader_dump_disassembly(&shader->epilog->binary, + si_shader_dump_disassembly(sscreen, &shader->epilog->binary, debug, "epilog", file); fprintf(file, "\n"); } @@ -5425,7 +5444,11 @@ static int si_compile_llvm(struct si_screen *sscreen, } struct ac_rtld_binary rtld; - if (!ac_rtld_open(&rtld, 1, &binary->elf_buffer, &binary->elf_size)) + if (!ac_rtld_open(&rtld, (struct ac_rtld_open_info){ + .info = &sscreen->info, + .num_parts = 1, + .elf_ptrs = &binary->elf_buffer, + .elf_sizes = &binary->elf_size })) return -1; bool ok = ac_rtld_read_config(&rtld, conf); @@ -6892,7 +6915,7 @@ int si_compile_tgsi_shader(struct si_screen *sscreen, } si_calculate_max_simd_waves(shader); - si_shader_dump_stats_for_shader_db(shader, debug); + si_shader_dump_stats_for_shader_db(sscreen, shader, debug); return 0; } diff --git a/src/gallium/drivers/radeonsi/si_shader.h b/src/gallium/drivers/radeonsi/si_shader.h index e8c769da69f..beda82beb05 100644 --- a/src/gallium/drivers/radeonsi/si_shader.h +++ b/src/gallium/drivers/radeonsi/si_shader.h @@ -699,10 +699,11 @@ unsigned si_shader_io_get_unique_index(unsigned semantic_name, unsigned index, unsigned is_varying); 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, const struct si_shader *shader, +void si_shader_dump(struct si_screen *sscreen, struct si_shader *shader, struct pipe_debug_callback *debug, unsigned processor, FILE *f, bool check_debug_option); -void si_shader_dump_stats_for_shader_db(const struct si_shader *shader, +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); diff --git a/src/gallium/drivers/radeonsi/si_state_shaders.c b/src/gallium/drivers/radeonsi/si_state_shaders.c index 6e47f7f55ba..e90884c898a 100644 --- a/src/gallium/drivers/radeonsi/si_state_shaders.c +++ b/src/gallium/drivers/radeonsi/si_state_shaders.c @@ -2116,7 +2116,7 @@ static void si_init_shader_selector_async(void *job, int thread_index) if (ir_binary && si_shader_cache_load_shader(sscreen, ir_binary, shader)) { mtx_unlock(&sscreen->shader_cache_mutex); - si_shader_dump_stats_for_shader_db(shader, debug); + si_shader_dump_stats_for_shader_db(sscreen, shader, debug); } else { mtx_unlock(&sscreen->shader_cache_mutex); |