From: Gert Wollny Date: Sat, 28 Dec 2019 14:34:43 +0000 (+0100) Subject: r600: enable NIR backend DEBUG flag for supported architectures X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c5d9456d841c54b50616b293a532d106323658ce;p=mesa.git r600: enable NIR backend DEBUG flag for supported architectures When NIR is enabled, a few features that are not yet supported will be explicitely disabled. Signed-off-by: Gert Wollny Part-of: --- diff --git a/src/gallium/drivers/r600/r600_pipe.c b/src/gallium/drivers/r600/r600_pipe.c index f26da31d2ae..97f20355d59 100644 --- a/src/gallium/drivers/r600/r600_pipe.c +++ b/src/gallium/drivers/r600/r600_pipe.c @@ -249,6 +249,12 @@ fail: return NULL; } +static bool is_nir_enabled(struct r600_common_screen *screen) { + return (screen->debug_flags & DBG_NIR && + screen->family >= CHIP_CEDAR && + screen->family < CHIP_CAYMAN); +} + /* * pipe_screen */ @@ -333,7 +339,7 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param) return rscreen->b.chip_class > R700; case PIPE_CAP_TGSI_TEXCOORD: - return 0; + return is_nir_enabled(&rscreen->b); case PIPE_CAP_FAKE_SW_MSAA: return 0; @@ -414,7 +420,7 @@ static int r600_get_param(struct pipe_screen* pscreen, enum pipe_cap param) return 1; case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT: - if (family >= CHIP_CEDAR) + if (family >= CHIP_CEDAR && !is_nir_enabled(&rscreen->b)) return 256; return 0; @@ -542,7 +548,6 @@ static int r600_get_shader_param(struct pipe_screen* pscreen, { case PIPE_SHADER_FRAGMENT: case PIPE_SHADER_VERTEX: - case PIPE_SHADER_COMPUTE: break; case PIPE_SHADER_GEOMETRY: if (rscreen->b.family >= CHIP_CEDAR) @@ -551,9 +556,14 @@ static int r600_get_shader_param(struct pipe_screen* pscreen, if (rscreen->b.info.drm_minor >= 37) break; return 0; + /* With NIR we currently disable TES, TCS and COMP shaders */ case PIPE_SHADER_TESS_CTRL: case PIPE_SHADER_TESS_EVAL: - if (rscreen->b.family >= CHIP_CEDAR) + if (rscreen->b.family >= CHIP_CEDAR && + !is_nir_enabled(&rscreen->b)) + break; + case PIPE_SHADER_COMPUTE: + if (!is_nir_enabled(&rscreen->b)) break; default: return 0; @@ -576,9 +586,11 @@ static int r600_get_shader_param(struct pipe_screen* pscreen, case PIPE_SHADER_CAP_MAX_CONST_BUFFER_SIZE: if (shader == PIPE_SHADER_COMPUTE) { uint64_t max_const_buffer_size; - pscreen->get_compute_param(pscreen, PIPE_SHADER_IR_TGSI, - PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE, - &max_const_buffer_size); + enum pipe_shader_ir ir_type = is_nir_enabled(&rscreen->b) ? + PIPE_SHADER_IR_NIR: PIPE_SHADER_IR_TGSI; + pscreen->get_compute_param(pscreen, ir_type, + PIPE_COMPUTE_CAP_MAX_MEM_ALLOC_SIZE, + &max_const_buffer_size); return MIN2(max_const_buffer_size, INT_MAX); } else { @@ -605,14 +617,19 @@ static int r600_get_shader_param(struct pipe_screen* pscreen, case PIPE_SHADER_CAP_MAX_TEXTURE_SAMPLERS: case PIPE_SHADER_CAP_MAX_SAMPLER_VIEWS: return 16; - case PIPE_SHADER_CAP_PREFERRED_IR: + case PIPE_SHADER_CAP_PREFERRED_IR: + if (is_nir_enabled(&rscreen->b)) + return PIPE_SHADER_IR_NIR; return PIPE_SHADER_IR_TGSI; case PIPE_SHADER_CAP_SUPPORTED_IRS: { int ir = 0; if (shader == PIPE_SHADER_COMPUTE) ir = 1 << PIPE_SHADER_IR_NATIVE; - if (rscreen->b.family >= CHIP_CEDAR) + if (rscreen->b.family >= CHIP_CEDAR) { ir |= 1 << PIPE_SHADER_IR_TGSI; + if (is_nir_enabled(&rscreen->b)) + ir |= 1 << PIPE_SHADER_IR_NIR; + } return ir; } case PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED: diff --git a/src/gallium/drivers/r600/r600_shader.c b/src/gallium/drivers/r600/r600_shader.c index 85e584baff5..734565baa22 100644 --- a/src/gallium/drivers/r600/r600_shader.c +++ b/src/gallium/drivers/r600/r600_shader.c @@ -24,7 +24,9 @@ #include "r600_formats.h" #include "r600_opcodes.h" #include "r600_shader.h" +#include "r600_dump.h" #include "r600d.h" +#include "sfn/sfn_nir.h" #include "sb/sb_public.h" @@ -33,6 +35,10 @@ #include "tgsi/tgsi_parse.h" #include "tgsi/tgsi_scan.h" #include "tgsi/tgsi_dump.h" +#include "tgsi/tgsi_from_mesa.h" +#include "nir/tgsi_to_nir.h" +#include "nir/nir_to_tgsi_info.h" +#include "compiler/nir/nir.h" #include "util/u_bitcast.h" #include "util/u_memory.h" #include "util/u_math.h" @@ -157,6 +163,8 @@ static int store_shader(struct pipe_context *ctx, return 0; } +extern const struct nir_shader_compiler_options r600_nir_options; +static int nshader = 0; int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_pipe_shader *shader, union r600_shader_key key) @@ -164,27 +172,61 @@ int r600_pipe_shader_create(struct pipe_context *ctx, struct r600_context *rctx = (struct r600_context *)ctx; struct r600_pipe_shader_selector *sel = shader->selector; int r; - bool dump = r600_can_dump_shader(&rctx->screen->b, - tgsi_get_processor_type(sel->tokens)); - unsigned use_sb = !(rctx->screen->b.debug_flags & DBG_NO_SB); + struct r600_screen *rscreen = (struct r600_screen *)ctx->screen; + + int processor = sel->ir_type == PIPE_SHADER_IR_TGSI ? + tgsi_get_processor_type(sel->tokens): + pipe_shader_type_from_mesa(sel->nir->info.stage); + + bool dump = r600_can_dump_shader(&rctx->screen->b, processor); + unsigned use_sb = !(rctx->screen->b.debug_flags & DBG_NO_SB) && + !(rscreen->b.debug_flags & DBG_NIR); unsigned sb_disasm; unsigned export_shader; - + shader->shader.bc.isa = rctx->isa; - + + if (!(rscreen->b.debug_flags & DBG_NIR)) { + assert(sel->ir_type == PIPE_SHADER_IR_TGSI); + r = r600_shader_from_tgsi(rctx, shader, key); + if (r) { + R600_ERR("translation from TGSI failed !\n"); + goto error; + } + } else { + if (sel->ir_type == PIPE_SHADER_IR_TGSI) + sel->nir = tgsi_to_nir_noscreen(sel->tokens, &r600_nir_options); + nir_tgsi_scan_shader(sel->nir, &sel->info, true); + r = r600_shader_from_nir(rctx, shader, &key); + if (r) { + fprintf(stderr, "--Failed shader--------------------------------------------------\n"); + + if (sel->ir_type == PIPE_SHADER_IR_TGSI) { + fprintf(stderr, "--TGSI--------------------------------------------------------\n"); + tgsi_dump(sel->tokens, 0); + } + + if (rscreen->b.debug_flags & DBG_NIR) { + fprintf(stderr, "--NIR --------------------------------------------------------\n"); + nir_print_shader(sel->nir, stderr); + } + + R600_ERR("translation from NIR failed !\n"); + goto error; + } + } + if (dump) { - fprintf(stderr, "--------------------------------------------------------------\n"); - tgsi_dump(sel->tokens, 0); - + if (sel->ir_type == PIPE_SHADER_IR_TGSI) { + fprintf(stderr, "--TGSI--------------------------------------------------------\n"); + tgsi_dump(sel->tokens, 0); + } + if (sel->so.num_outputs) { r600_dump_streamout(&sel->so); } } - r = r600_shader_from_tgsi(rctx, shader, key); - if (r) { - R600_ERR("translation from TGSI failed !\n"); - goto error; - } + if (shader->shader.processor_type == PIPE_SHADER_VERTEX) { /* only disable for vertex shaders in tess paths */ if (key.vs.as_ls) @@ -216,7 +258,7 @@ int r600_pipe_shader_create(struct pipe_context *ctx, r600_bytecode_disasm(&shader->shader.bc); fprintf(stderr, "______________________________________________________________\n"); } else if ((dump && sb_disasm) || use_sb) { - r = r600_sb_bytecode_process(rctx, &shader->shader.bc, &shader->shader, + r = r600_sb_bytecode_process(rctx, &shader->shader.bc, &shader->shader, dump, use_sb); if (r) { R600_ERR("r600_sb_bytecode_process failed !\n"); @@ -224,6 +266,30 @@ int r600_pipe_shader_create(struct pipe_context *ctx, } } + if (dump) { + FILE *f; + char fname[1024]; + snprintf(fname, 1024, "shader_from_%s_%d.cpp", + (sel->ir_type == PIPE_SHADER_IR_TGSI ? + (rscreen->b.debug_flags & DBG_NIR ? "tgsi-nir" : "tgsi") + : "nir"), nshader); + f = fopen(fname, "w"); + print_shader_info(f, nshader++, &shader->shader); + print_shader_info(stderr, nshader++, &shader->shader); + print_pipe_info(stderr, &sel->info); + if (sel->ir_type == PIPE_SHADER_IR_TGSI) { + fprintf(f, "/****TGSI**********************************\n"); + tgsi_dump_to_file(sel->tokens, 0, f); + } + + if (rscreen->b.debug_flags & DBG_NIR){ + fprintf(f, "/****NIR **********************************\n"); + nir_print_shader(sel->nir, f); + } + fprintf(f, "******************************************/\n"); + fclose(f); + } + if (shader->gs_copy_shader) { if (dump) { // dump copy shader @@ -301,7 +367,8 @@ error: void r600_pipe_shader_destroy(struct pipe_context *ctx UNUSED, struct r600_pipe_shader *shader) { r600_resource_reference(&shader->bo, NULL); - r600_bytecode_clear(&shader->shader.bc); + if (shader->shader.bc.cf.next) + r600_bytecode_clear(&shader->shader.bc); r600_release_command_buffer(&shader->command_buffer); } @@ -2469,9 +2536,9 @@ static void convert_edgeflag_to_int(struct r600_shader_ctx *ctx) r600_bytecode_add_alu(ctx->bc, &alu); } -static int generate_gs_copy_shader(struct r600_context *rctx, - struct r600_pipe_shader *gs, - struct pipe_stream_output_info *so) +int generate_gs_copy_shader(struct r600_context *rctx, + struct r600_pipe_shader *gs, + struct pipe_stream_output_info *so) { struct r600_shader_ctx ctx = {}; struct r600_shader *gs_shader = &gs->shader; diff --git a/src/gallium/drivers/r600/r600_shader.h b/src/gallium/drivers/r600/r600_shader.h index fd7dac75266..1e00a9527b5 100644 --- a/src/gallium/drivers/r600/r600_shader.h +++ b/src/gallium/drivers/r600/r600_shader.h @@ -191,6 +191,10 @@ int eg_get_interpolator_index(unsigned interpolate, unsigned location); int r600_get_lds_unique_index(unsigned semantic_name, unsigned index); +int generate_gs_copy_shader(struct r600_context *rctx, + struct r600_pipe_shader *gs, + struct pipe_stream_output_info *so); + #ifdef __cplusplus } // extern "C" #endif