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

WIP: spirv-opt: Demote r/w output variables to private #5672

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jeremy-lunarg
Copy link
Contributor

@jeremy-lunarg jeremy-lunarg commented May 16, 2024

Fix #5516

Pass: eliminate dead output stores

Stores to write-only output variables are safe to eliminate; however, stores to read-write output variables may be required for functional correctness. If a read-write output variable is detected, then it will be demoted to a private variable and any associated stores will not be eliminated.

@jeremy-lunarg jeremy-lunarg requested a review from greg-lunarg May 16, 2024 20:50
@jeremy-lunarg jeremy-lunarg self-assigned this May 16, 2024
Fix KhronosGroup#5516

Pass: eliminate dead output stores

Stores to write-only output variables are safe to eliminate; however,
stores to read-write output variables may be required for functional
correctness. If a read-write output variable is detected, then it will
be demoted to a private variable and any associated stores will not be
eliminated.
@s-perron
Copy link
Collaborator

This look reasonable to me, but I did not look at it in detail. I'll let a code owner (someone from lunarg) do a detailed review.

@jeremy-lunarg jeremy-lunarg changed the title spirv-opt: Demote r/w output variables to private WIP: spirv-opt: Demote r/w output variables to private May 21, 2024
@jeremy-lunarg
Copy link
Contributor Author

Thanks @s-perron. There's one more thing I'd like to address before pushing this.

analysis::DefUseManager* def_use_mgr = context()->get_def_use_mgr();

bool is_read = false;
def_use_mgr->ForEachUser(variable, [&is_read](Instruction* user) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to iterate over every user? If not, should WhileEachUser be used instead?

@greg-lunarg
Copy link
Contributor

This code does not address reads and writes of Output variables through OpAccessChains. So this pass is still broken for these cases.

I suggest the following approach: if the Output OpVariable has an OpLoad either directly through the OpVariable or through an OpAccessChain, 1) create a Private OpVariable with the same type as the Output OpVariable and replace all uses of the Output OpVariable with the Private OpVariable; then 2) for each OpStore of the Private OpVariable, either directly through the OpVariable or through an OpAccessChain, insert a duplicate OpStore (and OpAccessChain if needed) using the original Output OpVariable.

Then allow the original logic to process the Output variable and it's OpStores.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with EliminateDeadOutputStores when reading from out variable
4 participants