Skip to content

[HLSL] Implement IncrementCounter/DecrementCounter on structured buffers #113513

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 #124
hekota opened this issue Oct 24, 2024 · 2 comments · Fixed by #114148 or #117608
Closed
Tracked by #124

[HLSL] Implement IncrementCounter/DecrementCounter on structured buffers #113513

hekota opened this issue Oct 24, 2024 · 2 comments · Fixed by #114148 or #117608
Assignees
Labels
backend:DirectX clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support

Comments

@hekota
Copy link
Member

hekota commented Oct 24, 2024

Introduce a clang builtin that will be used to implement the implement IncrementCounter and DecrementCounter methods on structured buffers. The builtin could be something like this:

`void __builtin_hlsl_resource_update_counter(resource_t x, int value);`

Allowed values for value are 1 or -1.

The builtin would be lowered to LLVM DirectX intrinsic llvm.dx.bufferUpdateCounter during clang codegen. Related to task #92147.

Applies to:

  • RWStructuredBuffer
  • RasterizerOrderedStructuredBuffer

Docs:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-rwstructuredbuffer

Example:
https://godbolt.org/z/1aWf4Pec7

AC:

  • The builtin is available and lowers to appropriate LLVM DirectX intrinsics during clang codegen
  • IncrementCounter and DecrementCounter method can be implemented using this builtin
@hekota hekota transferred this issue from llvm/wg-hlsl Oct 24, 2024
@EugeneZelenko EugeneZelenko added HLSL HLSL Language Support and removed new issue labels Oct 24, 2024
@hekota hekota changed the title [HLSL] Implement IncrementCounter/DecrementCounter on structured buffers [HLSL] Implement IncrementCounter/DecrementCounter on RWStructuredBuffer Oct 24, 2024
@hekota hekota changed the title [HLSL] Implement IncrementCounter/DecrementCounter on RWStructuredBuffer [HLSL] Implement IncrementCounter/DecrementCounter on structured buffers Oct 24, 2024
@hekota hekota moved this to Planning in HLSL Support Oct 24, 2024
@hekota hekota self-assigned this Oct 25, 2024
@davidcook-msft davidcook-msft moved this from Planning to Ready in HLSL Support Oct 29, 2024
@hekota hekota moved this from Ready to Active in HLSL Support Oct 29, 2024
hekota added a commit to hekota/llvm-project that referenced this issue Oct 29, 2024
Introduces `__builtin_hlsl_buffer_update_counter` clang buildin that is used to implement IncrementCounter and DecrementCounter methods on RWStructuredBuffer and RasterizerOrderedStructuredBuffer. The builtin is translated to LLVM intrisics llvm.dx.bufferUpdateCounter/llvm.spv.bufferUpdateCounter.

Introduces `BuiltinTypeMethodBuilder` helper in `HLSLExternalSemaSource` that allows adding methods to builtin types
using the builder pattern like this:

   BuiltinTypeMethodBuilder(Sema, RecordBuilder, "MethodName", ReturnType)
       .addParam("param_name", Type, InOutModifier)
       .callBuiltin("buildin_name", { BuiltinParams })
       .finalizeMethod();

Fixes llvm#113513
@hekota hekota moved this from Active to Needs Review in HLSL Support Oct 31, 2024
@hekota hekota closed this as completed in 94bde8c Nov 23, 2024
@github-project-automation github-project-automation bot moved this from Needs Review to Closed in HLSL Support Nov 23, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:codegen IR generation bugs: mangling, exceptions, etc. labels Nov 24, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 24, 2024

@llvm/issue-subscribers-clang-codegen

Author: Helena Kotas (hekota)

Introduce a clang builtin that will be used to implement the implement `IncrementCounter` and `DecrementCounter` methods on structured buffers. The builtin could be something like this:
`void __builtin_hlsl_resource_update_counter(resource_t x, int value);`

Allowed values for value are 1 or -1.

The builtin would be lowered to LLVM DirectX intrinsic llvm.dx.bufferUpdateCounter during clang codegen. Related to task llvm/llvm-project#92147.

Applies to:

  • RWStructuredBuffer
  • RasterizerOrderedStructuredBuffer

Docs:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-rwstructuredbuffer

Example:
https://godbolt.org/z/1aWf4Pec7

AC:

  • The builtin is available and lowers to appropriate LLVM DirectX intrinsics during clang codegen
  • IncrementCounter and DecrementCounter method can be implemented using this builtin

@llvmbot
Copy link
Member

llvmbot commented Nov 24, 2024

@llvm/issue-subscribers-clang-frontend

Author: Helena Kotas (hekota)

Introduce a clang builtin that will be used to implement the implement `IncrementCounter` and `DecrementCounter` methods on structured buffers. The builtin could be something like this:
`void __builtin_hlsl_resource_update_counter(resource_t x, int value);`

Allowed values for value are 1 or -1.

The builtin would be lowered to LLVM DirectX intrinsic llvm.dx.bufferUpdateCounter during clang codegen. Related to task llvm/llvm-project#92147.

Applies to:

  • RWStructuredBuffer
  • RasterizerOrderedStructuredBuffer

Docs:
https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-rwstructuredbuffer

Example:
https://godbolt.org/z/1aWf4Pec7

AC:

  • The builtin is available and lowers to appropriate LLVM DirectX intrinsics during clang codegen
  • IncrementCounter and DecrementCounter method can be implemented using this builtin

hekota added a commit that referenced this issue Nov 26, 2024
…rs (#117608)

Introduces `__builtin_hlsl_buffer_update_counter` clang buildin that is
used to implement the `IncrementCounter` and `DecrementCounter` methods
on `RWStructuredBuffer` and `RasterizerOrderedStructuredBuffer` (see
Note).

The builtin is translated to LLVM intrisic `llvm.dx.bufferUpdateCounter`
or `llvm.spv.bufferUpdateCounter`.

Introduces `BuiltinTypeMethodBuilder` helper in `HLSLExternalSemaSource`
that enables adding methods to builtin types using builder pattern like
this:
```
   BuiltinTypeMethodBuilder(Sema, RecordBuilder, "MethodName", ReturnType)
       .addParam("param_name", Type, InOutModifier)
       .callBuiltin("buildin_name", { BuiltinParams })
       .finalizeMethod();
```

Fixes #113513

[First version](#114148) of this PR was reverted
because of build break.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:DirectX clang:codegen IR generation bugs: mangling, exceptions, etc. clang:frontend Language frontend issues, e.g. anything involving "Sema" HLSL HLSL Language Support
Projects
Status: Closed
3 participants