Skip to content

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

@hekota

Description

@hekota

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

This PR is step 3/4 of the changes proposed by https://github.com/llvm/wg-hlsl/blob/main/proposals/0022-resource-instance-analysis.md

Metadata

Metadata

Assignees

Labels

HLSLHLSL Language SupportobsoleteIssues with old (unsupported) versions of LLVM

Type

No type

Projects

Status

Closed

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions