diff options
author | Timothy Arceri <[email protected]> | 2017-11-09 17:32:08 +1100 |
---|---|---|
committer | Timothy Arceri <[email protected]> | 2017-12-04 09:10:30 +1100 |
commit | da953b641d806cdb8031ff8fe7ce458963a3fe4f (patch) | |
tree | 6f611c7be2409c582841759a9fb77fde6f419796 /src/mesa/state_tracker | |
parent | 2a35021bc61632562e34448249c80887a0d7ac3c (diff) |
st/glsl: move nir linking loop to new function st_link_nir()
This will allow us to refactor linking and include some nir link
time optimisations.
Reviewed-by: Nicolai Hähnle <[email protected]>
Diffstat (limited to 'src/mesa/state_tracker')
-rw-r--r-- | src/mesa/state_tracker/st_glsl_to_nir.cpp | 25 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 26 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_nir.h | 7 |
3 files changed, 41 insertions, 17 deletions
diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index d0375dd3aa7..8b66f8277a8 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -508,4 +508,29 @@ st_nir_get_mesa_program(struct gl_context *ctx, return prog; } +bool +st_link_nir(struct gl_context *ctx, + struct gl_shader_program *shader_program) +{ + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { + struct gl_linked_shader *shader = shader_program->_LinkedShaders[i]; + if (shader == NULL) + continue; + + struct gl_program *linked_prog = + st_nir_get_mesa_program(ctx, shader_program, shader); + + if (linked_prog) { + if (!ctx->Driver.ProgramStringNotify(ctx, + _mesa_shader_stage_to_program(i), + linked_prog)) { + _mesa_reference_program(ctx, &shader->Program, NULL); + return false; + } + } + } + + return true; +} + } /* extern "C" */ diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp index fa51fef343b..8eeae86dabb 100644 --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp @@ -6901,6 +6901,7 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) struct pipe_screen *pscreen = ctx->st->pipe->screen; assert(prog->data->LinkStatus); + bool use_nir = false; for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { if (prog->_LinkedShaders[i] == NULL) continue; @@ -6920,6 +6921,12 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) unsigned if_threshold = pscreen->get_shader_param(pscreen, ptarget, PIPE_SHADER_CAP_LOWER_IF_THRESHOLD); + enum pipe_shader_ir preferred_ir = (enum pipe_shader_ir) + pscreen->get_shader_param(pscreen, ptarget, + PIPE_SHADER_CAP_PREFERRED_IR); + if (preferred_ir == PIPE_SHADER_IR_NIR) + use_nir = true; + /* If there are forms of indirect addressing that the driver * cannot handle, perform the lowering pass. */ @@ -7023,24 +7030,17 @@ st_link_shader(struct gl_context *ctx, struct gl_shader_program *prog) build_program_resource_list(ctx, prog); + if (use_nir) + return st_link_nir(ctx, prog); + for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) { struct gl_linked_shader *shader = prog->_LinkedShaders[i]; if (shader == NULL) continue; - enum pipe_shader_type ptarget = - pipe_shader_type_from_mesa(shader->Stage); - enum pipe_shader_ir preferred_ir = (enum pipe_shader_ir) - pscreen->get_shader_param(pscreen, ptarget, - PIPE_SHADER_CAP_PREFERRED_IR); - - struct gl_program *linked_prog = NULL; - if (preferred_ir == PIPE_SHADER_IR_NIR) { - linked_prog = st_nir_get_mesa_program(ctx, prog, shader); - } else { - linked_prog = get_mesa_program_tgsi(ctx, prog, shader); - st_set_prog_affected_state_flags(linked_prog); - } + struct gl_program *linked_prog = + get_mesa_program_tgsi(ctx, prog, shader); + st_set_prog_affected_state_flags(linked_prog); if (linked_prog) { if (!ctx->Driver.ProgramStringNotify(ctx, diff --git a/src/mesa/state_tracker/st_nir.h b/src/mesa/state_tracker/st_nir.h index 9302a7c786b..c65e753f9b4 100644 --- a/src/mesa/state_tracker/st_nir.h +++ b/src/mesa/state_tracker/st_nir.h @@ -45,10 +45,9 @@ void st_finalize_nir(struct st_context *st, struct gl_program *prog, struct gl_shader_program *shader_program, struct nir_shader *nir); -struct gl_program * -st_nir_get_mesa_program(struct gl_context *ctx, - struct gl_shader_program *shader_program, - struct gl_linked_shader *shader); +bool +st_link_nir(struct gl_context *ctx, + struct gl_shader_program *shader_program); #ifdef __cplusplus } |