Skip to content
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

[HLSL] Validate that updateCounter is only either incremented or decremented and not both #114130

Open
Tracked by #88
hekota opened this issue Oct 29, 2024 · 2 comments
Open
Tracked by #88
Assignees
Labels
HLSL HLSL Language Support

Comments

@hekota
Copy link
Member

hekota commented Oct 29, 2024

RWStructuredBuffer has IncrementCounter and DecrementCounter. Only one of these methods can ever be called on any given RWStructuredBuffer instance - the buffer counter can only be incremented or decremented but not both.

DXC validation rule: Instr.OnlyOneAllocConsume

AC:

  • Test case rejects IR that calls updateCounter with both a positive and negative number

Design:

  • Add a new late stage DXIL only pass to llvm/lib/Target/DirectX/DirectXIRPasses that errors when updateCounter is incremented and decremented on the same resource, this pass should be small/focused in order to avoid becoming a kitchen sync
  • Register the pass in Target/DirectX/DirectXTargetMachine.cpp before DXILOpLowering
  • Walk the module searching for updateCounter calls. For each updateCounter call
    • extract the resource handle, and the current inc/dec value
    • resolve the handle into binding info
    • check if the key is in a pass global map
      • if yes: error if map value != current inc/dec value
      • if no: insert key into map with current inc/dev value

Notes:

  • SPIR-V doesn't have this restriction so the validation isn't added there
@hekota hekota changed the title Validate that updateCounter is only either incremented or decremented and not both [HLSL] Validate that updateCounter is only either incremented or decremented and not both Oct 29, 2024
@hekota hekota changed the title [HLSL] Validate that updateCounter is only either incremented or decremented and not both [HLSL] Validate that updateCounter is only either incremented or decremented and not both Oct 29, 2024
@hekota hekota transferred this issue from llvm/wg-hlsl Oct 29, 2024
@hekota hekota moved this to Designing in HLSL Support Oct 29, 2024
@EugeneZelenko EugeneZelenko added HLSL HLSL Language Support and removed new issue labels Oct 29, 2024
@V-FEXrt
Copy link
Contributor

V-FEXrt commented Jan 21, 2025

Qs:

  • Can this be done at LLVM IR or does the work need to be duplicated for DXIL and SPRIV
    • A: This validation is only needed for DXIL, nothing is needed for SPRIV
  • Is there a "Passes" template or should I just work from something like MachinePostDominatorTreeAnalysis
  • Should this be a fully new pass or can it be stuffed into something existing like DXILResourceTypeAnalysis

@V-FEXrt
Copy link
Contributor

V-FEXrt commented Jan 21, 2025

Expected error: https://godbolt.org/z/ofWfTGG4P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
HLSL HLSL Language Support
Projects
Status: Designing
Development

No branches or pull requests

3 participants