Skip to content

[DirectX backend] flatten multi-dimensional array into a one-dimensional array. #89646

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

Closed
Tracked by #92422
python3kgae opened this issue Apr 22, 2024 · 0 comments · Fixed by #114332
Closed
Tracked by #92422

[DirectX backend] flatten multi-dimensional array into a one-dimensional array. #89646

python3kgae opened this issue Apr 22, 2024 · 0 comments · Fixed by #114332
Assignees

Comments

@python3kgae
Copy link
Contributor

python3kgae commented Apr 22, 2024

DXIL requires array to be 1D only in https://github.com/Microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#arrays

Need a pass in DirectX backend to flatten multi-dimensional array into a one-dimensional array.

Not limited to group shared. static global variable or local variable need to be flattened as well.

groupshared float a[10][16];
static float b[16][4];

Buffer<float> B;
float foo(int x, int y) {
  float l[16][4];
  for (int i=0;i<16;++i)
     for (int j=0;j<4;++j)
        l[i][j] = B[i] + B[j];
  return l[x][y];
}

The groupshared variable ‘a’, static global variable ‘b’, and local variable ‘l’ all need to be flattened into a one-dimensional array.

AC:

  • A new IR path is created that transforms arrays into 1D arrays
    • Collect all multi-dimensional array variable as candidates.
    • Create one-dimensional array to replace the original array.
    • Update debug info.
  • Tests are created and are passing
@python3kgae python3kgae self-assigned this May 13, 2024
@python3kgae python3kgae removed their assignment Jul 9, 2024
farzonl added a commit to llvm/wg-hlsl that referenced this issue Sep 20, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
This proposal covers:
- all the cases mentioned in:
llvm/llvm-project#107920
- The results of our design discussion
- the global multi-d to 1d array flattening cases mentioned in:
llvm/llvm-project#89646
- intro, background, and motivation for this work.
@farzonl farzonl self-assigned this Sep 23, 2024
@damyanp damyanp moved this to Active in HLSL Support Oct 7, 2024
farzonl added a commit that referenced this issue Nov 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
-  Relevant piece is `DXILFlattenArrays.cpp`
- Loads and Store Instruction visits are just for finding
GetElementPtrConstantExpr and splitting them.
-  Allocas needed to be replaced with flattened allocas.
- Global arrays were similar to allocas. Only interesting piece here is
around initializers.
- Most of the work went into building correct GEP chains. The approach
here was a recursive strategy via `recursivelyCollectGEPs`.
- All intermediary GEPs get marked for deletion and only the leaf GEPs
get updated with the new index.

fixes [89646](#89646)
@github-project-automation github-project-automation bot moved this from Active to Closed in HLSL Support Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants