Skip to content

Commit

Permalink
Track invariance dependencies separate from expression deps.
Browse files Browse the repository at this point in the history
We need to be able to punch through any non-forwarded temporaries as
well.

Any SSA variable that is a dependency of an invariant store must be
flushed to temporary.
  • Loading branch information
HansKristian-Work committed Dec 9, 2024
1 parent 6eac38b commit c2c8e43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions spirv_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ struct SPIRExpression : IVariant
// A list of expressions which this expression depends on.
SmallVector<ID> expression_dependencies;

// Similar as expression dependencies, but does not stop the tracking for force-temporary variables.
// We need to know the full chain from store back to any SSA variable.
SmallVector<ID> invariance_dependencies;

// By reading this expression, we implicitly read these expressions as well.
// Used by access chain Store and Load since we read multiple expressions in this case.
SmallVector<ID> implied_read_expressions;
Expand Down
7 changes: 6 additions & 1 deletion spirv_cross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,11 @@ void Compiler::add_active_interface_variable(uint32_t var_id)

void Compiler::inherit_expression_dependencies(uint32_t dst, uint32_t source_expression)
{
auto *ptr_e = maybe_get<SPIRExpression>(dst);

if (is_position_invariant() && ptr_e && maybe_get<SPIRExpression>(source_expression))
ptr_e->invariance_dependencies.push_back(source_expression);

// Don't inherit any expression dependencies if the expression in dst
// is not a forwarded temporary.
if (forwarded_temporaries.find(dst) == end(forwarded_temporaries) ||
Expand All @@ -2577,7 +2582,7 @@ void Compiler::inherit_expression_dependencies(uint32_t dst, uint32_t source_exp
return;
}

auto &e = get<SPIRExpression>(dst);
auto &e = *ptr_e;
auto *phi = maybe_get<SPIRVariable>(source_expression);
if (phi && phi->phi_variable)
{
Expand Down
2 changes: 1 addition & 1 deletion spirv_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11772,7 +11772,7 @@ void CompilerGLSL::disallow_forwarding_in_expression_chain(const SPIRExpression
force_temporary_and_recompile(expr.self);
forced_invariant_temporaries.insert(expr.self);

for (auto &dependent : expr.expression_dependencies)
for (auto &dependent : expr.invariance_dependencies)
disallow_forwarding_in_expression_chain(get<SPIRExpression>(dependent));
}
}
Expand Down

0 comments on commit c2c8e43

Please sign in to comment.