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

spirv-opt: A pass repairs interfaces of OpEntryPoint instructions. #4275

Merged
merged 9 commits into from
Jun 29, 2021

Conversation

thatname
Copy link
Contributor

Hi !
Working with SPIR-V with multiple OpEntryPoint instructions is painful.
Some tools often generate incorrect or suboptimal interfaces for OpEntryPoint instructions.
If the interface of an entry point instruction lists an unused global variable that used by another entry point, currently DCE passs can not remove it from the list, because it can only remove dead variables.
If an used global variable is not listed, there is no tool to fix currently.

This PR adds spvtools::opt::InterfaceRepairPass which is an optmizer pass fixs the problem. It iterates the entry points, traverses the functions called, remembers the used variables, and rewrites the interfaces. Just add "--interface-repair" in command line to invoke it.

@CLAassistant
Copy link

CLAassistant commented May 10, 2021

CLA assistant check
All committers have signed the CLA.

@thatname thatname changed the title Added a optimizer pass which can repair interfaces of OpEntryPoint instructions. spirv-opt: A pass repairs interfaces of OpEntryPoint instructions. May 10, 2021
@alan-baker alan-baker requested a review from s-perron May 12, 2021 15:05
Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

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

I can see that this will be useful. Thanks for adding it. I do have a few suggested changes. We have a number of utility function to try to reduce the boiler plate code that is needed. I would suggest using those unless there is a good reason not to. I may have missed something.

You should also add tests for the pass. You can look at

TEST_F(WrapOpKillTest, SingleOpKill) {
for an example to follow.

source/opt/interface_repair_pass.cpp Outdated Show resolved Hide resolved
source/opt/interface_repair_pass.h Outdated Show resolved Hide resolved
source/opt/interface_repair_pass.cpp Outdated Show resolved Hide resolved
source/opt/interface_repair_pass.cpp Outdated Show resolved Hide resolved
source/opt/interface_repair_pass.cpp Outdated Show resolved Hide resolved
source/opt/interface_repair_pass.cpp Outdated Show resolved Hide resolved
source/opt/interface_repair_pass.cpp Outdated Show resolved Hide resolved
source/opt/interface_repair_pass.cpp Outdated Show resolved Hide resolved
source/opt/interface_repair_pass.cpp Outdated Show resolved Hide resolved
@jaebaek
Copy link
Contributor

jaebaek commented May 20, 2021

microsoft/DirectXShaderCompiler#3789 handles the DXC issue. If the PR works correct, we do not need this change.

jaebaek added a commit to microsoft/DirectXShaderCompiler that referenced this pull request May 25, 2021
…ns (#3789)

As mentioned in #3759 and KhronosGroup/SPIRV-Tools#4275,
DXC does not generate correct operands of `OpEntryPoint` when the shader has
multiple entry functions. The main reason is that the existing SPIR-V backend does
not separate interfaces between entry functions. This commit lets `DeclResultIdMapper`
keep the information of the entry point of each stage variable in `StageVar` and
lets `SpirvEmitter` correctly emit interfaces for each `OpEntryPoint`.
@jaebaek
Copy link
Contributor

jaebaek commented May 26, 2021

I submitted the change. I think we can close this issue. @thatname please let us know if it is ok or not.

@jaebaek
Copy link
Contributor

jaebaek commented Jun 1, 2021

Let me close it now. If you have any further questions or issues, please let us know.

@s-perron
Copy link
Collaborator

s-perron commented Jun 3, 2021

Many tests failed. It might be because you need to rebase, and you might need to run clang-format on the new header file. Sorry for the extra work.

@thatname
Copy link
Contributor Author

thatname commented Jun 4, 2021

@s-perron Thanks, I've formatted the files, now CI seems OK, still need to rebase?

@s-perron
Copy link
Collaborator

s-perron commented Jun 4, 2021

The format is good, but the tests still fail. We run the tests with the latest from all of our dependencies. If you update spirv-headers you will see the failure locally. The problem as already been fixed, but you need to rebase you change to pick up that fix.

FYI: A maintainer has to trigger the kokoro tests for security reasons.

…structions by listing the global variables exactly referenced.
Copyright should be owned by author,
ID operands should be iterated by ForEachInId.
And a BUG introduced by my last commit is fixed.
Following the style of the code base, changed methods to begin with capital letters.
@s-perron
Copy link
Collaborator

Ignoring the smoke test failure. It looked like a network issue, and this change will not affect it.

@s-perron s-perron merged commit f9893c4 into KhronosGroup:master Jun 29, 2021
sliu-UIUC pushed a commit to sliu-UIUC/SPIRV-Tools that referenced this pull request Jul 14, 2021
…s. (KhronosGroup#4275)

The new pass will removed interface variable on the OpEntryPoint instruction when they are not statically referenced in the call tree of the entry point.

It can be enabled on the command line using the options `remove-unused-interface-variables`.
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.

5 participants