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

Structured control flow #9

Closed
Jasper-Bekkers opened this issue Aug 18, 2020 · 7 comments
Closed

Structured control flow #9

Jasper-Bekkers opened this issue Aug 18, 2020 · 7 comments
Labels
t: enhancement A new feature or improvement to an existing one.

Comments

@Jasper-Bekkers
Copy link
Contributor

Jasper-Bekkers commented Aug 18, 2020

MIR internally is pretty much completely unstructured which leads to some problems since in the flavour of SPIR-V that we're trying to support the control flow needs to be fully structured. The only flavor that supports unstructured controlflow is for OpenCL.

This requires potentially quite a bit of engineering to solve since the algorithms involved are relatively complex.

One avenue of exploration could be to see if we can shoehorn the Mesa3d controlflow restructurizer back into our compile chain:

Another option would be to implement either Stackifier or Relooper as part of spirv-opt that we run after the fact. We may already need to run spirv-opt to run mem2reg since we'll mostly be emitting OpLoad and OpStore instead of sticking to SSA proper.

Another option is one that @MaikKlein proposed:

There is I think another option that I haven't explored yet, and that is to remove some mir passes. Basically I think if you would remove most of the mir passes between HIR and MIR then the resulting cfg should be fairly easy to work with. I think most of the information will be lost during some of the optimization passes. Recomputing the control flow is fairly easy.

This option would leave the high-level controlflow constructs in tact without ever lowering them to branches/jumps which is a lot more robust then trying to reconstruct the structured controlflow from the jumps.

Some other projects have also run into similar issues:

@Jasper-Bekkers
Copy link
Contributor Author

My intuition is the pragmatic fast way to make progress on a few architectures is to drop structured control flow, but the long-term formal way to be portable across a diversity of architectures is to have a robust execution model, which at the moment wants structured control flow

It may be worthwhile to experiment and see if the desktop gpus already support unstructured controlflow in their Vulkan drivers so we can potentially push this problem a little bit ahead of us while we work towards a minimally viable product.

@Jasper-Bekkers
Copy link
Contributor Author

Our hardware actually has IF, ELSE, ENDIF, and DO, BREAK, and CONT instructions.

From Intel.

waveops make absolutely no sense without structured control flow

Another contribution.

@VZout
Copy link
Member

VZout commented Aug 28, 2020

Taking the Relooper approach seems like a good option for now. While not the most efficient, it would be a good start for me to get started with this kind of work and performance is likely not that important for the first prototype.
Here is a tracking issue on my progress:

#24

@XAMPPRocky XAMPPRocky added the t: enhancement A new feature or improvement to an existing one. label Oct 21, 2020
@XAMPPRocky XAMPPRocky mentioned this issue Oct 21, 2020
18 tasks
@repi
Copy link
Contributor

repi commented Oct 21, 2020

This old issue is partially resolved now right @VZout ?

@VZout
Copy link
Member

VZout commented Oct 22, 2020

There is a solution for the problem but not fully implemented yet. Currently only simple conditional branch's work.
We can probably replace it with a tracking issue?

@repi
Copy link
Contributor

repi commented Oct 22, 2020

Ok np, could either create new one that tracks the progress support around this, or keep this one. up to you

@VZout
Copy link
Member

VZout commented Oct 22, 2020

Closing in favor of #97

@VZout VZout closed this as completed Oct 22, 2020
Firestar99 pushed a commit to Firestar99/rust-gpu that referenced this issue Sep 19, 2024
…tudios#1157) (EmbarkStudios#9)

* bump glam to 0.29

* fix cargo deny

* upgrade wgpu

* fix cfg-check lints

Co-authored-by: Gray Olson <gray@grayolson.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
t: enhancement A new feature or improvement to an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants