Skip to content

Commit

Permalink
Merge pull request #2425 from KhronosGroup/fix-2420
Browse files Browse the repository at this point in the history
Track invariance dependencies separate from expression deps.
  • Loading branch information
HansKristian-Work authored Dec 10, 2024
2 parents 6eac38b + a75ad07 commit 022aad4
Show file tree
Hide file tree
Showing 3 changed files with 15 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
11 changes: 10 additions & 1 deletion spirv_cross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,15 @@ 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))
{
auto &deps = ptr_e->invariance_dependencies;
if (std::find(deps.begin(), deps.end(), source_expression) == deps.end())
deps.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 +2586,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 022aad4

Please sign in to comment.