You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 31, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 31, 2025. It is now read-only.
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.
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.
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:
DirectXShaderCompiler's SPIR-V backend does work properly in this case, they've decided to emit SPIR-V more or less straight from the AST, which sits at a higher level then what we're currently doing (and are comfortable with). It's unlikely that the rustc team would accept such a change back into their mainline, or that they would support not breaking such a codepath.
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.
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:
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?
Activity
Jasper-Bekkers commentedon Aug 18, 2020
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 commentedon Aug 18, 2020
From Intel.
Another contribution.
VZout commentedon 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
repi commentedon Oct 21, 2020
This old issue is partially resolved now right @VZout ?
VZout commentedon 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 commentedon 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 commentedon Oct 22, 2020
Closing in favor of #97
Fix cfg-check lint errors, update glam to 0.29, wgpu to 22.1 (EmbarkS…