Skip to content

[SPIR-V] Structurize SPIR-V for graphics #75801

@Keenuts

Description

@Keenuts

The current backend mostly supports OpenCL's SPIR-V.
For graphical SPIR-V, one crucial step needs to be added: the structurizer.

The spec defining what a structured control-flow means for SPIR-V is here:
https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_structured_control_flow

The current method we'd like to pursue would be relying on convergent intrinsics in the LLVM IR.
The frontend (only HLSL so far) will have to generate the correct convergent instructions around loops, and wave operations.

Once we have those operations, we believe the IR can be structured in 7 steps:

  • adding pre-headers to all the loops
  • split basic-blocks with different convergent operations. (Each basic block shall be linked to at most 1 convergent token)
  • merge back-edges for loops with multiple back edges.
  • identify convergence regions (regions sharing the same convergence token).
  • merge exit blocks for convergence region with multiple exits.

At this point, we shall have a hierarchy of SESE regions, each associated with a convergence token.
This should ensure we don't yoyo across convergence regions.

Once those initial 5 steps done, we can add the SPIR-V instructions to determine merge/continue nodes.

  • Adding OpLoopMerge instructions to loop constructs.
  • Adding OpSelectionMerge to selection constructs

The last 2 steps will be slightly more complex, as we shall make sure no header share multiple OpSelectionMerge/OpLoopMerge, and no branch breaks out of multiple selection/loop constructs. But those are merely fixup steps once we have the initial 5 steps implemented.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions