Module: Mesa Branch: main Commit: dcfffdcad189ba856705d5569b79a94622c07919 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=dcfffdcad189ba856705d5569b79a94622c07919
Author: Jason Ekstrand <[email protected]> Date: Tue May 3 09:28:01 2022 -0500 nir/lower_blend: Be more explicit about deref assumptions Because we pull the RT from the variable location and use that to look up formats, we need a constant RT index. To deal with arrays (possibly of arrays), we would either need to handle array derefs (we don't today) or we need to require the variables to be split into one variable per RT. Given that we have to lower indirect derefs anyway (to get constant indices), we may as well require the client to split output variables by calling nir_lower_io_arrays_to_elements_no_indirect(). Reviewed-by: Alyssa Rosenzweig <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16309> --- src/compiler/nir/nir_lower_blend.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/compiler/nir/nir_lower_blend.c b/src/compiler/nir/nir_lower_blend.c index ecf14e01a07..8f61346d35d 100644 --- a/src/compiler/nir/nir_lower_blend.c +++ b/src/compiler/nir/nir_lower_blend.c @@ -350,10 +350,17 @@ nir_lower_blend_instr(nir_builder *b, nir_instr *instr, void *data) if (intr->intrinsic != nir_intrinsic_store_deref) return false; - nir_variable *var = nir_intrinsic_get_var(intr, 0); - if (var->data.mode != nir_var_shader_out || - (var->data.location != FRAG_RESULT_COLOR && - var->data.location < FRAG_RESULT_DATA0)) + nir_deref_instr *deref = nir_src_as_deref(intr->src[0]); + if (!nir_deref_mode_is(deref, nir_var_shader_out)) + return false; + + /* Indirects must be already lowered and output variables split */ + assert(deref && deref->deref_type == nir_deref_type_var); + nir_variable *var = deref->var; + assert(glsl_type_is_vector_or_scalar(var->type)); + + if (var->data.location != FRAG_RESULT_COLOR && + var->data.location < FRAG_RESULT_DATA0) return false; /* Determine render target for per-RT blending */ @@ -399,6 +406,15 @@ nir_lower_blend_instr(nir_builder *b, nir_instr *instr, void *data) return true; } +/** Lower blending to framebuffer fetch and some math + * + * This pass requires that indirects are lowered and output variables split + * so that we have a single output variable for each RT. We could go to the + * effort of handling arrays (possibly of arrays) but, given that we need + * indirects lowered anyway (we need constant indices to look up blend + * functions and formats), we may as well require variables to be split. + * This can be done by calling nir_lower_io_arrays_to_elements_no_indirect(). + */ void nir_lower_blend(nir_shader *shader, nir_lower_blend_options options) {
