Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track invariance dependencies separate from expression deps. #2425

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading