glsl: don't tree graft globals
As per this optimisations description:
"Takes assignments to variables that are dereferenced only
once and pastes the RHS expression into where the variables
dereferenced."
However the optimisation is run at compile time before multiple
shaders from the same stage could have been pasted together.
So this optimisation can incorrectly assume a global is only
referenced once since it cannot see the other pieces of the
shader stage until link time.
Here we skip the optimisation if the variable is a global. We
could change it to only run at link time however this
optimisation is only run at link time if we are being forced
to use GLSL IR to inline a function that glsl to nir cannot
handle and this will also be removed in a future patchset.
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/10482
Fixes: d75a36a9ee ("glsl: remove do_copy_propagation_elements() optimisation pass")
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27351>
(cherry picked from commit bc0178af57fe5e328580190806354982e1c41e16)
This commit is contained in:
parent
4ce8d2d8b3
commit
f45c9a38db
4 changed files with 16 additions and 3 deletions
|
|
@ -1624,7 +1624,7 @@
|
|||
"description": "glsl: don't tree graft globals",
|
||||
"nominated": true,
|
||||
"nomination_type": 1,
|
||||
"resolution": 0,
|
||||
"resolution": 1,
|
||||
"main_sha": null,
|
||||
"because_sha": "d75a36a9eeb1606fab19362746f9b5d94b98bd3a",
|
||||
"notes": null
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ ir_variable_refcount_visitor::ir_variable_refcount_visitor()
|
|||
{
|
||||
this->mem_ctx = ralloc_context(NULL);
|
||||
this->ht = _mesa_pointer_hash_table_create(NULL);
|
||||
this->global = true;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -94,8 +95,10 @@ ir_visitor_status
|
|||
ir_variable_refcount_visitor::visit(ir_variable *ir)
|
||||
{
|
||||
ir_variable_refcount_entry *entry = this->get_variable_entry(ir);
|
||||
if (entry)
|
||||
if (entry) {
|
||||
entry->declaration = true;
|
||||
entry->is_global = this->global;
|
||||
}
|
||||
|
||||
return visit_continue;
|
||||
}
|
||||
|
|
@ -117,10 +120,14 @@ ir_variable_refcount_visitor::visit(ir_dereference_variable *ir)
|
|||
ir_visitor_status
|
||||
ir_variable_refcount_visitor::visit_enter(ir_function_signature *ir)
|
||||
{
|
||||
global = false;
|
||||
|
||||
/* We don't want to descend into the function parameters and
|
||||
* dead-code eliminate them, so just accept the body here.
|
||||
*/
|
||||
visit_list_elements(this, &ir->body);
|
||||
|
||||
global = true;
|
||||
return visit_continue_with_parent;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,6 +62,9 @@ public:
|
|||
unsigned assigned_count;
|
||||
|
||||
bool declaration; /* If the variable had a decl in the instruction stream */
|
||||
|
||||
/** Is the variable a global */
|
||||
bool is_global;
|
||||
};
|
||||
|
||||
class ir_variable_refcount_visitor : public ir_hierarchical_visitor {
|
||||
|
|
@ -86,6 +89,8 @@ public:
|
|||
struct hash_table *ht;
|
||||
|
||||
void *mem_ctx;
|
||||
|
||||
bool global;
|
||||
};
|
||||
|
||||
#endif /* GLSL_IR_VARIABLE_REFCOUNT_H */
|
||||
|
|
|
|||
|
|
@ -386,7 +386,8 @@ tree_grafting_basic_block(ir_instruction *bb_first,
|
|||
|
||||
if (!entry->declaration ||
|
||||
entry->assigned_count != 1 ||
|
||||
entry->referenced_count != 2)
|
||||
entry->referenced_count != 2 ||
|
||||
entry->is_global)
|
||||
continue;
|
||||
|
||||
/* Found a possibly graftable assignment. Now, walk through the
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue