Skip to content

[HLSL] Array by-value parameter passing #70123

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 #67692
llvm-beanz opened this issue Oct 24, 2023 · 2 comments · Fixed by #79382
Closed
Tracked by #67692

[HLSL] Array by-value parameter passing #70123

llvm-beanz opened this issue Oct 24, 2023 · 2 comments · Fixed by #79382
Assignees
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support

Comments

@llvm-beanz
Copy link
Collaborator

llvm-beanz commented Oct 24, 2023

In HLSL arrays when passed as parameters to functions are passed by-value. This is implemented in DXIL by creating a temporary of the array then passing the pointer-decayed temporary in place of the parameter.

https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-function-parameters

AC:

  • non-decaying array type is implemented
  • This is able to be disabled in later SMs easily
    • This helps us better align with C
@llvm-beanz llvm-beanz converted this from a draft issue Oct 24, 2023
@llvm-beanz llvm-beanz self-assigned this Oct 24, 2023
@llvm-beanz llvm-beanz added the HLSL HLSL Language Support label Oct 24, 2023
@llvm-beanz llvm-beanz moved this to In Progress in HLSL Support Nov 30, 2023
@llvm-beanz
Copy link
Collaborator Author

Some of the documentation for this is available here:
https://clang.llvm.org/docs/HLSL/FunctionCalls.html

The initial PR is: #79382

llvm-beanz added a commit that referenced this issue Apr 1, 2024
HLSL constant sized array function parameters do not decay to pointers.
Instead constant sized array types are preserved as unique types for
overload resolution, template instantiation and name mangling.

This implements the change by adding a new `ArrayParameterType` which
represents a non-decaying `ConstantArrayType`. The new type behaves the
same as `ConstantArrayType` except that it does not decay to a pointer.

Values of `ConstantArrayType` in HLSL decay during overload resolution
via a new `HLSLArrayRValue` cast to `ArrayParameterType`.

`ArrayParamterType` values are passed indirectly by-value to functions
in IR generation resulting in callee generated memcpy instructions.

The behavior of HLSL function calls is documented in the [draft language
specification](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf)
under the Expr.Post.Call heading.

Additionally the design of this implementation approach is documented in
[Clang's
documentation](https://clang.llvm.org/docs/HLSL/FunctionCalls.html)

Resolves #70123
@github-project-automation github-project-automation bot moved this from Active to Done in HLSL Support Apr 1, 2024
@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Apr 1, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 1, 2024

@llvm/issue-subscribers-clang-frontend

Author: Chris B (llvm-beanz)

In HLSL arrays when passed as parameters to functions are passed by-value. This is implemented in DXIL by creating a temporary of the array then passing the pointer-decayed temporary in place of the parameter.

https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-function-parameters

AC:

  • non-decaying array type is implemented
  • This is able to be disabled in later SMs easily
    • This helps us better align with C

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants