nir/lower_non_uniform: improve code with the same texture, sampler indices

NIR can't CSE the read_first_invocation intrinsics, so we can end up
creating iand(read_first_invocation(a) == a, read_first_invocation(a) == a)

Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3813>
This commit is contained in:
Rhys Perry 2020-02-13 15:09:53 +00:00 committed by Marge Bot
parent 5d55ca9c30
commit efba865c4c

View file

@ -73,9 +73,10 @@ lower_non_uniform_tex_access(nir_builder *b, nir_tex_instr *tex)
assert(handle_count < 2);
assert(tex->src[i].src.is_ssa);
nir_ssa_def *handle = tex->src[i].src.ssa;
nir_deref_instr *parent = NULL;
if (handle->parent_instr->type == nir_instr_type_deref) {
nir_deref_instr *deref = nir_instr_as_deref(handle->parent_instr);
nir_deref_instr *parent = nir_deref_instr_parent(deref);
parent = nir_deref_instr_parent(deref);
if (deref->deref_type == nir_deref_type_var)
continue;
@ -87,16 +88,19 @@ lower_non_uniform_tex_access(nir_builder *b, nir_tex_instr *tex)
continue;
handle = deref->arr.index.ssa;
parent_derefs[handle_count] = parent;
}
unsigned handle_index = (!handle_count || handle != handles[0]) ? handle_count : 0;
if (parent) {
parent_derefs[handle_index] = parent;
if (tex->src[i].src_type == nir_tex_src_texture_deref)
texture_deref_handle = handle_count;
texture_deref_handle = handle_index;
else
sampler_deref_handle = handle_count;
sampler_deref_handle = handle_index;
}
assert(handle->num_components == 1);
handles[handle_count++] = handle;
if (handle_index == handle_count)
handles[handle_count++] = handle;
}
if (handle_count == 0)