Skip to content

[SER] Transform RayDesc in ScalarReplHLSL for robust lowering #7435

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
wants to merge 2 commits into from

Conversation

simoll
Copy link
Contributor

@simoll simoll commented May 7, 2025

ScalarReplHLSL will refuse to faltten RayDesc if some users are incompatible. This is at odds with HLOperationLower, which always expects a specific flattened form.
This implements explicit RayDesc flattening in ScalarReplHLSL to make this more reliable. One issue with RayDesc-from-cbuffer in RayQuery remains and is documented with a test.

Implement ScalarReplHLSL handling for RayDesc param in HL ops:

  • HitObject::MakeMiss [RewriteCallArg]
  • HitObject::TraceRay [RewriteCallArg]
  • TraceRay [RewriteCallArg]
  • RayQuery::TraceRayInline [unchanged - flatten to RayDesc elements]

In the process:

  • Fix copyout code in RewriteCallArg (ScalarReplHLSL)
  • Remove obsolete tests that expected a RayDesc alloca (where RayDesc is now SROA'd entirely)
  • Document RayQuery lowering bug when RayDesc is taken directly from cbuffer.

Closes #7434 Unflattened RayDesc breaking HL->DXIL lowering #7434

ScalarReplHLSL will refuse to faltten RayDesc if some users are
incompatible. This is at odds with HLOperationLower, which always
expects a specific flattened form.
This implements explicit RayDesc flattening in ScalarReplHLSL to make this more reliable. One issue with RayDesc-from-cbuffer in RayQuery remains and is documented with a test.

Implement ScalarReplHLSL handling for RayDesc param in HL ops:
- HitObject::MakeMiss [RewriteCallArg]
- HitObject::TraceRay [RewriteCallArg]
- TraceRay            [RewriteCallArg]
- RayQuery::TraceRayInline [unchanged - flatten to RayDesc elements]

In the process:
- Fix copyout code in RewriteCallArg (ScalarReplHLSL)
- Remove obsolete tests that expected a RayDesc alloca (where RayDesc is
  now SROA'd entirely)
- Document RayQuery lowering bug when RayDesc is taken directly from
  cbuffer.

Closes microsoft#7434  Unflattened RayDesc breaking HL->DXIL lowering microsoft#7434
@simoll
Copy link
Contributor Author

simoll commented May 8, 2025

Pipelines failing because the RaygenAllocaStructAlignment pixtest has to be updated. Will do that once we settle for a solution.

Copy link
Member

@pow2clk pow2clk left a comment

Choose a reason for hiding this comment

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

I just have one question.

I think we've decided to move forward with this change for the time being. I think @tex3d had a conversation with Jeff Noyle and confirmed that the pix test changes are fine. Since the alternatives would, at least, require significantly more testing, it's preferrable to take this solution while those get completed.

@@ -2687,7 +2685,7 @@ void SROA_Helper::RewriteCallArg(CallInst *CI, unsigned ArgIdx, bool bIn,
Builder.SetInsertPoint(CI->getNextNode());
MemCpyInst *cpy = cast<MemCpyInst>(Builder.CreateMemCpy(
userTyV, Alloca, DL.getTypeAllocSize(userTyElt), false));
RewriteMemIntrin(cpy, cpy->getRawSource());
RewriteMemIntrin(cpy, cpy->getRawDest());
Copy link
Member

Choose a reason for hiding this comment

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

This change has fewer than expected, but nevertheless extant, though potentially subtle effects. What prompted it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was erroneously triggering the memcpy-undef-to-undef-optimization inRewriteMemIntrin for the out-copy. This change makes the in and out RewriteMemIntrin calls symmetric and resolves the mis-optimization.

@damyanp
Copy link
Member

damyanp commented May 15, 2025

We're closing this one in favor of #7440.

@damyanp damyanp closed this May 15, 2025
@github-project-automation github-project-automation bot moved this from New to Done in HLSL Roadmap May 15, 2025
@github-project-automation github-project-automation bot moved this from Active to Closed in HLSL Support May 15, 2025
@simoll simoll deleted the scalarrepl_raydesc branch May 16, 2025 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Unflattened RayDesc breaking HL->DXIL lowering
4 participants