Skip to content

[Draft] Rewrite output parameters - #5249

Draft
Chris B (llvm-beanz) wants to merge 3 commits into
microsoft:mainfrom
llvm-beanz:cbieneman/out-param-draft
Draft

Chris B (llvm-beanz) wants to merge 3 commits into
microsoft:mainfrom
llvm-beanz:cbieneman/out-param-draft

Conversation

@llvm-beanz

@llvm-beanz Chris B (llvm-beanz) commented May 30, 2023 •

Copy link
Copy Markdown
Collaborator

This change is a huge swath of changes rewriting how HLSL represents pointers, references and arrays as well as the handling of output parameters in function signatures.

The main changes included in this PR are:

  • Restoring Array->Pointer Decay in the HLSL ASTs.
  • Representing all output parameters using reference types in the AST.
  • Adding a new HLSLOutParamExpr AST node for output parameters. *Adding a new HLSLArrayTemporaryExpr to represent temporary array values.

There are also a large number of associated fixes and patches to make the code generation and optimization code resilient to the new AST and IR structures that are generated.

Disclaimer: This is a massive PR with no good way to break it up. In the current state there are still some test failures that I need to resolve, but I want to get this in front of people to review before it gets any bigger.

Fixes #5377

This change is a huge swath of changes rewriting how HLSL represents
pointers, references and arrays as well as the handling of output
parameters in function signatures.

The main changes included in this PR are:
* Restoring Array->Pointer Decay in the HLSL ASTs.
* Representing all output parameters using reference types in the AST.
* Adding a new HLSLOutParamExpr AST node for output parameters.
*Adding a new HLSLArrayTemporaryExpr to represent temporary array
values.

There are also a large number of associated fixes and patches to make
the code generation and optimization code resilient to the new AST and
IR structures that are generated.
@llvm-beanz

Copy link
Copy Markdown
Collaborator Author

For more information on the changes contained here see: Revising HLSL out Parameters.pdf

@AppVeyorBot

Copy link
Copy Markdown

@s-perron Steven Perron (s-perron) left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look at the SPIR-V changes, and nothing looks like it should be a problem.

@s-perron

Copy link
Copy Markdown
Collaborator

I'll take a look at the failing spir-v test to make sure the newly generated spir-v makes sense.

@s-perron

Copy link
Copy Markdown
Collaborator

Some of the failing tests are real problems that need to be fixed:

  • FileTest.BinaryOpAssignOpaqueArray - Some optimizations are not happening. They are probably unaware of OpCopyMemory. Spirv-opt will have to be improved. This has to be fixed before merging.
  • FileTest.FunctionInOutParamLocalResource - The is an error related to the counter variables. I don't know if this is intended, but I expect it is not. I'm not sure what needs to be done in this case.
  • FileTest.FunctionInOutParamIsomorphism - The optimization is not as good as it could be. Not necessary to fix, but would be nice.

I still have to look at ~30 more failing test cases.

@s-perron

Copy link
Copy Markdown
Collaborator
  • FileTest.TextureGetDimensions - I cannot tell from the test if this is a problem or not. In some cases where the output variable is not used, the temp does not get copied out to the original variable. This is one example of many. We should check what happens when the value it used to make sure the code is okay.
  • FileTest.ByteAddressBufferTemplatedLoadMatrix - The spirv is incorrect. The OpCopyMemory is trying to copy a value that has already been loaded. Affects other test cases as well.
  • FileTest.SpirvInterpolationVS - I think the test case is invalid, and needs to be updated. This is more than just updating the expected outputs.
  • FileTest.MeshShadingEXTAmplification - There is a new error message, but the error message seems wrong. It says that expected groupshared object as argument to DispatchMesh(), but the argument that it points to is groupshared.
  • FileTest.ReduceLoadSize - OpCopyMemory is trying to copy between the objects of different type. The types are different because of their decorations. Before spir-v 1.4 you have to do what the old code does: extract individual part, and reconstruct them. In spir-v 1.4, we can load, OpCopyLogical, and store.

@llvm-beanz

Copy link
Copy Markdown
Collaborator Author

Related to #2419

@dnovillo

Copy link
Copy Markdown
Collaborator

Chris B (@llvm-beanz) are you still interested in this? It's quite old and still marked as draft.

@llvm-beanz

Copy link
Copy Markdown
Collaborator Author

Chris B (Chris B (@llvm-beanz)) are you still interested in this? It's quite old and still marked as draft.

I have very mixed feelings about this. The branch was useful in that it proved out the design we ultimately used in Clang for implementing parameter passing. I don't really know how to gain enough confidence in the correctness of a change this large to actually land it.

I don't feel like the HLSL testing we have available to us is sufficient to give confidence.

The change would be a big win though. It fixes warning diagnostics, codegen bugs, and removes a ton of code that never needed to exist.

I may try to get creative about how we could test this and see what I can come up with.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spirv Work related to SPIR-V

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

out and inout should always be references

4 participants