diff options
author | Kenneth Graunke <[email protected]> | 2017-05-21 01:36:14 -0700 |
---|---|---|
committer | Jason Ekstrand <[email protected]> | 2019-07-24 18:00:13 +0000 |
commit | 517005b4cf376b292f61d786d419e2a611e4a02a (patch) | |
tree | a3fa98353d391aa1ea680d0baccc846010836f70 /src/mesa | |
parent | d10de2530976ed3aba9c5d077e2edb141f71e7dd (diff) |
i965: Use NIR to lower legacy userclipping.
This allows us to drop legacy userclip plane handling in both the vec4
and FS backends, and simplifies a few interfaces.
v2 (Jason Ekstrand):
- Move brw_nir_lower_legacy_clipping to brw_nir_uniforms.cpp because
it's i965-specific.
- Handle adding the params in brw_nir_lower_legacy_clipping
- Call brw_nir_lower_legacy_clipping from brw_codegen_vs_prog
Co-authored-by: Jason Ekstrand <[email protected]>
Reviewed-by: Jason Ekstrand <[email protected]>
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp | 56 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_vs.c | 5 |
2 files changed, 61 insertions, 0 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp b/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp index e5f97b647af..2ea316e7420 100644 --- a/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp +++ b/src/mesa/drivers/dri/i965/brw_nir_uniforms.cpp @@ -395,3 +395,59 @@ brw_nir_lower_gl_images(nir_shader *shader, } } } + +void +brw_nir_lower_legacy_clipping(nir_shader *nir, int nr_userclip_plane_consts, + struct brw_stage_prog_data *prog_data) +{ + if (nr_userclip_plane_consts == 0) + return; + + nir_function_impl *impl = nir_shader_get_entrypoint(nir); + + nir_lower_clip_vs(nir, (1 << nr_userclip_plane_consts) - 1, true); + nir_lower_io_to_temporaries(nir, impl, true, false); + nir_lower_global_vars_to_local(nir); + nir_lower_vars_to_ssa(nir); + + const unsigned clip_plane_base = nir->num_uniforms; + + assert(nir->num_uniforms == prog_data->nr_params * 4); + const unsigned num_clip_floats = 4 * nr_userclip_plane_consts; + uint32_t *clip_param = + brw_stage_prog_data_add_params(prog_data, num_clip_floats); + nir->num_uniforms += num_clip_floats * sizeof(float); + assert(nir->num_uniforms == prog_data->nr_params * 4); + + for (unsigned i = 0; i < num_clip_floats; i++) + clip_param[i] = BRW_PARAM_BUILTIN_CLIP_PLANE(i / 4, i % 4); + + nir_builder b; + nir_builder_init(&b, impl); + nir_foreach_block(block, impl) { + nir_foreach_instr_safe(instr, block) { + if (instr->type != nir_instr_type_intrinsic) + continue; + + nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr); + if (intrin->intrinsic != nir_intrinsic_load_user_clip_plane) + continue; + + b.cursor = nir_before_instr(instr); + + nir_intrinsic_instr *load = + nir_intrinsic_instr_create(nir, nir_intrinsic_load_uniform); + load->num_components = 4; + load->src[0] = nir_src_for_ssa(nir_imm_int(&b, 0)); + nir_ssa_dest_init(&load->instr, &load->dest, 4, 32, NULL); + nir_intrinsic_set_base(load, clip_plane_base + 4 * sizeof(float) * + nir_intrinsic_ucp_id(intrin)); + nir_intrinsic_set_range(load, 4 * sizeof(float)); + nir_builder_instr_insert(&b, &load->instr); + + nir_ssa_def_rewrite_uses(&intrin->dest.ssa, + nir_src_for_ssa(&load->dest.ssa)); + nir_instr_remove(instr); + } + } +} diff --git a/src/mesa/drivers/dri/i965/brw_vs.c b/src/mesa/drivers/dri/i965/brw_vs.c index d15cd33ed3e..32b3953d537 100644 --- a/src/mesa/drivers/dri/i965/brw_vs.c +++ b/src/mesa/drivers/dri/i965/brw_vs.c @@ -149,6 +149,11 @@ brw_codegen_vs_prog(struct brw_context *brw, &prog_data.base.base); } + if (key->nr_userclip_plane_consts > 0) { + brw_nir_lower_legacy_clipping(nir, key->nr_userclip_plane_consts, + &prog_data.base.base); + } + uint64_t outputs_written = brw_vs_outputs_written(brw, key, nir->info.outputs_written); |