Skip to content

Commit 022aad4

Browse files
Merge pull request #2425 from KhronosGroup/fix-2420
Track invariance dependencies separate from expression deps.
2 parents 6eac38b + a75ad07 commit 022aad4

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

spirv_common.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ struct SPIRExpression : IVariant
748748
// A list of expressions which this expression depends on.
749749
SmallVector<ID> expression_dependencies;
750750

751+
// Similar as expression dependencies, but does not stop the tracking for force-temporary variables.
752+
// We need to know the full chain from store back to any SSA variable.
753+
SmallVector<ID> invariance_dependencies;
754+
751755
// By reading this expression, we implicitly read these expressions as well.
752756
// Used by access chain Store and Load since we read multiple expressions in this case.
753757
SmallVector<ID> implied_read_expressions;

spirv_cross.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,15 @@ void Compiler::add_active_interface_variable(uint32_t var_id)
25692569

25702570
void Compiler::inherit_expression_dependencies(uint32_t dst, uint32_t source_expression)
25712571
{
2572+
auto *ptr_e = maybe_get<SPIRExpression>(dst);
2573+
2574+
if (is_position_invariant() && ptr_e && maybe_get<SPIRExpression>(source_expression))
2575+
{
2576+
auto &deps = ptr_e->invariance_dependencies;
2577+
if (std::find(deps.begin(), deps.end(), source_expression) == deps.end())
2578+
deps.push_back(source_expression);
2579+
}
2580+
25722581
// Don't inherit any expression dependencies if the expression in dst
25732582
// is not a forwarded temporary.
25742583
if (forwarded_temporaries.find(dst) == end(forwarded_temporaries) ||
@@ -2577,7 +2586,7 @@ void Compiler::inherit_expression_dependencies(uint32_t dst, uint32_t source_exp
25772586
return;
25782587
}
25792588

2580-
auto &e = get<SPIRExpression>(dst);
2589+
auto &e = *ptr_e;
25812590
auto *phi = maybe_get<SPIRVariable>(source_expression);
25822591
if (phi && phi->phi_variable)
25832592
{

spirv_glsl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11772,7 +11772,7 @@ void CompilerGLSL::disallow_forwarding_in_expression_chain(const SPIRExpression
1177211772
force_temporary_and_recompile(expr.self);
1177311773
forced_invariant_temporaries.insert(expr.self);
1177411774

11775-
for (auto &dependent : expr.expression_dependencies)
11775+
for (auto &dependent : expr.invariance_dependencies)
1177611776
disallow_forwarding_in_expression_chain(get<SPIRExpression>(dependent));
1177711777
}
1177811778
}

0 commit comments

Comments
 (0)