diff options
author | Kenneth Graunke <[email protected]> | 2018-07-18 16:42:03 -0700 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2018-07-26 21:51:36 -0700 |
commit | 488972222c6454551ab1559f753c13a493dc513f (patch) | |
tree | 8a82f16349438be19eb29e611c961654b0010ff6 /src/mesa/drivers/dri | |
parent | 29dd5dda9d189eebb2d14de71e3fe30722e72743 (diff) |
i965: Combine both gl_PatchVerticesIn lowering passes.
Until now, we had separate passes for lowering gl_PatchVerticesIn to
a statically known constant (for TES inputs when linked against a TCS),
and a uniform in the other cases. Annoyingly, one had to be run before
nir_lower_system_values, and the other afterward. This simplified the
passes, but made life painful for the callers.
This patch combines both into a single pass. If you give it a non-zero
static count, it uses that. If you give it Mesa state slots, it turns
it back into a built-in uniform. Otherwise, it does nothing.
This also moves the i965 uniform lowering out to shared code.
v2: Make token arrays const.
Reviewed-by: Eric Anholt <[email protected]>
Diffstat (limited to 'src/mesa/drivers/dri')
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp | 28 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_program.c | 41 |
2 files changed, 18 insertions, 51 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp b/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp index 28a60691926..54f9f9b1a6b 100644 --- a/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp +++ b/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp @@ -267,31 +267,3 @@ brw_nir_setup_arb_uniforms(void *mem_ctx, nir_shader *shader, stage_prog_data->param[4 * p + i] = BRW_PARAM_BUILTIN_ZERO; } } - -void -brw_nir_lower_patch_vertices_in_to_uniform(nir_shader *nir) -{ - nir_foreach_variable_safe(var, &nir->system_values) { - if (var->data.location != SYSTEM_VALUE_VERTICES_IN) - continue; - - gl_state_index16 tokens[STATE_LENGTH] = { - STATE_INTERNAL, - nir->info.stage == MESA_SHADER_TESS_CTRL ? - (gl_state_index16)STATE_TCS_PATCH_VERTICES_IN : - (gl_state_index16)STATE_TES_PATCH_VERTICES_IN, - }; - var->num_state_slots = 1; - var->state_slots = - ralloc_array(var, nir_state_slot, var->num_state_slots); - memcpy(var->state_slots[0].tokens, tokens, sizeof(tokens)); - var->state_slots[0].swizzle = SWIZZLE_XXXX; - - var->data.mode = nir_var_uniform; - var->data.location = -1; - exec_node_remove(&var->node); - exec_list_push_tail(&nir->uniforms, &var->node); - } - - nir_fixup_deref_modes(nir); -} diff --git a/src/mesa/drivers/dri/i965/brw_program.c b/src/mesa/drivers/dri/i965/brw_program.c index 9fa1b4b9bb7..7adb75d0eaa 100644 --- a/src/mesa/drivers/dri/i965/brw_program.c +++ b/src/mesa/drivers/dri/i965/brw_program.c @@ -74,6 +74,7 @@ brw_create_nir(struct brw_context *brw, gl_shader_stage stage, bool is_scalar) { + const struct gen_device_info *devinfo = &brw->screen->devinfo; struct gl_context *ctx = &brw->ctx; const nir_shader_compiler_options *options = ctx->Const.ShaderCompilerOptions[stage].NirOptions; @@ -99,32 +100,26 @@ brw_create_nir(struct brw_context *brw, } nir_validate_shader(nir); - /* Lower PatchVerticesIn from system value to uniform. This needs to - * happen before brw_preprocess_nir, since that will lower system values - * to intrinsics. - * - * We only do this for TES if no TCS is present, since otherwise we know - * the number of vertices in the patch at link time and we can lower it - * directly to a constant. We do this in nir_lower_patch_vertices, which - * needs to run after brw_nir_preprocess has turned the system values - * into intrinsics. - */ - const bool lower_patch_vertices_in_to_uniform = - (stage == MESA_SHADER_TESS_CTRL && brw->screen->devinfo.gen >= 8) || - (stage == MESA_SHADER_TESS_EVAL && - !shader_prog->_LinkedShaders[MESA_SHADER_TESS_CTRL]); - - if (lower_patch_vertices_in_to_uniform) - brw_nir_lower_patch_vertices_in_to_uniform(nir); - nir = brw_preprocess_nir(brw->screen->compiler, nir); - if (stage == MESA_SHADER_TESS_EVAL && !lower_patch_vertices_in_to_uniform) { - assert(shader_prog->_LinkedShaders[MESA_SHADER_TESS_CTRL]); - struct gl_linked_shader *linked_tcs = + if (stage == MESA_SHADER_TESS_CTRL) { + /* Lower gl_PatchVerticesIn from a sys. value to a uniform on Gen8+. */ + static const gl_state_index16 tokens[STATE_LENGTH] = + { STATE_INTERNAL, STATE_TCS_PATCH_VERTICES_IN }; + nir_lower_patch_vertices(nir, 0, devinfo->gen >= 8 ? tokens : NULL); + } + + if (stage == MESA_SHADER_TESS_EVAL) { + /* Lower gl_PatchVerticesIn to a constant if we have a TCS, or + * a uniform if we don't. + */ + struct gl_linked_shader *tcs = shader_prog->_LinkedShaders[MESA_SHADER_TESS_CTRL]; - uint32_t patch_vertices = linked_tcs->Program->info.tess.tcs_vertices_out; - nir_lower_tes_patch_vertices(nir, patch_vertices); + uint32_t static_patch_vertices = + tcs ? tcs->Program->info.tess.tcs_vertices_out : 0; + static const gl_state_index16 tokens[STATE_LENGTH] = + { STATE_INTERNAL, STATE_TES_PATCH_VERTICES_IN }; + nir_lower_patch_vertices(nir, static_patch_vertices, tokens); } if (stage == MESA_SHADER_FRAGMENT) { |