mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-22 17:50:12 +01:00
nir/opt_deref: Add a deref mode specialization optimization
Reviewed-by: Jesse Natalie <jenatali@microsoft.com> Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6332>
This commit is contained in:
parent
a8e53a772f
commit
df51518dc5
1 changed files with 28 additions and 0 deletions
|
|
@ -935,6 +935,30 @@ opt_remove_cast_cast(nir_deref_instr *cast)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Restrict variable modes in casts.
|
||||||
|
*
|
||||||
|
* If we know from something higher up the deref chain that the deref has a
|
||||||
|
* specific mode, we can cast to more general and back but we can never cast
|
||||||
|
* across modes. For non-cast derefs, we should only ever do anything here if
|
||||||
|
* the parent eventually comes from a cast that we restricted earlier.
|
||||||
|
*/
|
||||||
|
static bool
|
||||||
|
opt_restrict_deref_modes(nir_deref_instr *deref)
|
||||||
|
{
|
||||||
|
if (deref->type == nir_deref_type_var) {
|
||||||
|
assert(deref->modes == deref->var->data.mode);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
nir_deref_instr *parent = nir_src_as_deref(deref->parent);
|
||||||
|
if (parent == NULL || parent->modes == deref->modes)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
assert(parent->modes & deref->modes);
|
||||||
|
deref->modes &= parent->modes;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
opt_remove_sampler_cast(nir_deref_instr *cast)
|
opt_remove_sampler_cast(nir_deref_instr *cast)
|
||||||
{
|
{
|
||||||
|
|
@ -1259,6 +1283,10 @@ nir_opt_deref_impl(nir_function_impl *impl)
|
||||||
switch (instr->type) {
|
switch (instr->type) {
|
||||||
case nir_instr_type_deref: {
|
case nir_instr_type_deref: {
|
||||||
nir_deref_instr *deref = nir_instr_as_deref(instr);
|
nir_deref_instr *deref = nir_instr_as_deref(instr);
|
||||||
|
|
||||||
|
if (opt_restrict_deref_modes(deref))
|
||||||
|
progress = true;
|
||||||
|
|
||||||
switch (deref->deref_type) {
|
switch (deref->deref_type) {
|
||||||
case nir_deref_type_ptr_as_array:
|
case nir_deref_type_ptr_as_array:
|
||||||
if (opt_deref_ptr_as_array(&b, deref))
|
if (opt_deref_ptr_as_array(&b, deref))
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue