37 Commits

Author SHA1 Message Date
Helena Kotas
ddf8cd3c6c
[HLSL][DirectX] Remove uniformity bit from resource initialization intrinsics (#155332)
Removes uniformity bit from resource initialization intrinsics `llvm.{dx|spv}.resource.handlefrombinding` and `llvm.{dx|spv}.resource.handlefromimplicitbinding`. The flag currently always set to `false`. It should be derived from resource analysis and not provided by codegen.

Closes #135452
2025-08-28 09:12:36 -07:00
joaosaffran
d56fa96524
[DirectX] Add Range Overlap validation (#152229)
As part of the Root Signature Spec, we need to validate if Root
Signatures are not defining overlapping ranges.
Closes: https://github.com/llvm/llvm-project/issues/126645

---------

Co-authored-by: joaosaffran <joao.saffran@microsoft.com>
Co-authored-by: Joao Saffran <{ID}+{username}@users.noreply.github.com>
Co-authored-by: Joao Saffran <jderezende@microsoft.com>
2025-08-14 18:40:11 -04:00
Helena Kotas
5165a6c197
[HLSL] Update DXIL resource metadata code to support resource arrays (#152254)
Closes #145422
2025-08-11 14:55:54 -07:00
Justin Bogner
3f066f5fcf
[HLSL][DirectX] Extract HLSLBinding out of DXILResource. NFC (#150633)
We extract the binding logic out of the DXILResource analysis passes into the
FrontendHLSL library. This will allow us to use this logic for resource and
root signature bindings in both the DirectX backend and the HLSL frontend.
2025-07-31 08:35:47 -07:00
Helena Kotas
f169af3ba7
[HLSL] Fix detection of overlapping binding with unbounded array (#150547)
Fixes #150534
2025-07-25 09:41:20 -07:00
Helena Kotas
945e7d33e8
[DirectX] Update resource type names in DXIL metadata to include element type (#140937)
Update resource type names for globals variables that we generate in `DXILTranslateMetadata` pass to include element type. This change prevents duplicate types for identical resources and brings the DXIL metadata names it closer to what DXC generates.
2025-05-29 11:44:34 -07:00
Helena Kotas
69c30f73a4
[DirectX] Use resource names when generating DXIL metadata (#140635)
Use resource names gathered during the DXIL resource analysis when creating DXIL resources metadata.

Part 4/4 of https://github.com/llvm/llvm-project/issues/105059

Closes #105059
2025-05-29 07:54:48 -07:00
Helena Kotas
f9ae8aaff2
[DirectX] Detect resources with identical overlapping binding (#140645)
This change uses resource name during DXIL resource binding analysis to detect when two (or more) resources have identical overlapping binding.

The DXIL resource analysis just detects that there is a problem with the binding and sets the `hasOverlappingBinding` flag. Full error reporting will happen later in DXILPostOptimizationValidation pass (llvm/llvm-project#110723).
2025-05-28 14:07:51 -07:00
Helena Kotas
219312c623
[DirectX] Gather resource names in DXIL resource analysis (#140633)
Gather resource names from `llvm.dx.resource.handlefrombinding` calls during DXIL resource analysis and add them to `DXILResourceMap`.

Part 3/4 of llvm/llvm-project#105059
2025-05-28 08:55:11 -07:00
Helena Kotas
03934d0a21
[DirectX] Implement DXILResourceImplicitBinding pass (#138043)
The `DXILResourceImplicitBinding` pass uses the results of
`DXILResourceBindingAnalysis` to assigns register slots to resources
that do not have explicit binding. It replaces all
`llvm.dx.resource.handlefromimplicitbinding` calls with
`llvm.dx.resource.handlefrombinding` using the newly assigned binding.

If a binding cannot be found for a resource, the pass will raise a
diagnostic error. Currently this diagnostic message does not include the
resource name, which will be addressed in a separate task (#137868).

Part 2/2 of #136786
Closes #136786
2025-05-12 23:00:00 -07:00
Kazu Hirata
4c9ffb7957
[Analysis] Use a range-based for loop (NFC) (#139488) 2025-05-11 21:29:07 -07:00
Ashley Coleman
793bee4f7b
[HLSL] Raise Diag for Invalid CounterDirection (#137697)
Fixes #135672

Raise a diagnostic in the post optimization validation pass as defined
in
https://github.com/llvm/wg-hlsl/blob/main/proposals/0022-resource-instance-analysis.md
2025-05-09 15:14:26 -06:00
Helena Kotas
c66f401e1e
[DirectX] Implement DXILResourceBindingAnalysis (#137258)
`DXILResourceBindingAnalysis` analyses explicit resource bindings in the
module and puts together lists of used virtual register spaces and
available virtual register slot ranges for each binding type. It also
stores additional information found during the analysis such as whether
the module uses implicit bindings or if any of the bindings overlap.

This information will be used in `DXILResourceImplicitBindings` pass
(coming soon) to assign register slots to resources with implicit
bindings, and in a post-optimization validation pass that will raise
diagnostic about overlapping bindings.

Part 1/2 of #136786
2025-05-09 10:42:31 -07:00
Helena Kotas
a1decfef3f
[HLSL][NFC] Rename getBindingMap to getResourceMap and update pass name (#137256)
The DXILResourceMap stores more information about resource instances
than just their binding.
2025-04-25 14:30:33 -07:00
Ashley Coleman
f12fb2ff74
[HLSL] Analyze updateCounter usage (#135669)
Fixes https://github.com/llvm/llvm-project/issues/135667

Analyze and annotate `ResourceInfo` with the derived direction of calls
to updateCounter (if any).

This change only sets the value. Any diagnostics that should be raised
must be done somewhere else.
2025-04-24 13:17:24 -06:00
Rahul Joshi
99e4b3927c
[LLVM] Cleanup pass initialization for Analysis passes (#135858)
- Do not call pass initialization from pass constructors.
- Instead, pass initialization should happen in the `initializeAnalysis`
function.
- https://github.com/llvm/llvm-project/issues/111767
2025-04-21 12:36:34 -07:00
Ashley Coleman
b07fc0fd5e
[HLSL] Move Resource Instance Properties from TypeInfo (#135259)
Fixes https://github.com/llvm/llvm-project/issues/134741

Moves Resource Instance properties from type info into resource info as
described in
https://github.com/llvm/wg-hlsl/blob/main/proposals/0022-resource-instance-analysis.md
2025-04-14 13:41:36 -06:00
Ashley Coleman
e3369a8dc9
[NFC][HLSL] Rename ResourceBinding Types (#134165)
Non-functional change as first step in
https://github.com/llvm/wg-hlsl/pull/207

Removes `Binding` from "Resource Instance" types
2025-04-04 16:51:35 -06:00
Justin Bogner
44ffeecde2
[DXIL][Analysis] Make sure resource accessors are contiguous (#128696)
When some resource types were present, but not all of them, we were
ending up in a situation where we would fail to initialize the `FirstX`
variables and get incorrect iterators.

Fixes #128560.
2025-02-25 13:52:17 -08:00
Justin Bogner
c79e867cd2
[DirectX] Update CBuffer to refer to a dx.Layout type (#128697)
This adds support cbuffers based on llvm/wg-hlsl#171 - the type argument
of the CBuffer TargetExtType is either a `dx.Layout` type which reports
its own size, or it's a normal type and we can simply refer to
DataLayout.
2025-02-25 12:36:29 -08:00
Ashley Coleman
02c9dae814
[HLSL] Add support to lookup a ResourceBindingInfo from its use (#126556)
Adds `findByUse` which takes a `llvm::Value` from a use and resolves it
(as best as possible) back to the creation of that resource.

It may return multiple ResourceBindingInfo if the use comes from
branched control flow.

Fixes #125746
2025-02-18 17:29:23 -07:00
Justin Bogner
aa07f92210
[DirectX][SPIRV] Consistent names for HLSL resource intrinsics (#120466)
Rename HLSL resource-related intrinsics to be consistent with the naming
conventions discussed in [wg-hlsl:0014].

This is an entirely mechanical change, consisting of the following
commands and automated formatting.

```sh
git grep -l handle.fromBinding | xargs perl -pi -e \
  's/(dx|spv)(.)handle.fromBinding/$1$2resource$2handlefrombinding/g'
git grep -l typedBufferLoad_checkbit | xargs perl -pi -e \
  's/(dx|spv)(.)typedBufferLoad_checkbit/$1$2resource$2loadchecked$2typedbuffer/g'
git grep -l typedBufferLoad | xargs perl -pi -e \
  's/(dx|spv)(.)typedBufferLoad/$1$2resource$2load$2typedbuffer/g'
git grep -l typedBufferStore | xargs perl -pi -e \
  's/(dx|spv)(.)typedBufferStore/$1$2resource$2store$2typedbuffer/g'
git grep -l bufferUpdateCounter | xargs perl -pi -e \
  's/(dx|spv)(.)bufferUpdateCounter/$1$2resource$2updatecounter/g'
git grep -l cast_handle | xargs perl -pi -e \
  's/(dx|spv)(.)cast.handle/$1$2resource$2casthandle/g'
```

[wg-hlsl:0014]: https://github.com/llvm/wg-hlsl/blob/main/proposals/0014-consistent-naming-for-dx-intrinsics.md
2024-12-19 12:17:21 -07:00
Justin Bogner
0e2466f624
[DirectX] Create symbols for resource handles (#119775)
We need to create symbols with "the original shape of resource and
element type" to put in the resource metadata in order to generate valid
DXIL.

Note that DXC generally doesn't emit an actual symbol outside of library
shaders (it emits an undef of a pointer to the type), but since we have
to deal with opaque pointers we would need a way to smuggle the type
through to match that. Instead, we simply emit symbols for now.

Fixed #116849
2024-12-18 10:47:12 -07:00
Justin Bogner
3eca15cbb9
[DirectX] Split resource info into type and binding info. NFC (#119773)
This splits the DXILResourceAnalysis pass into TypeAnalysis and
BindingAnalysis passes. The type analysis pass is made immutable and
populated lazily so that it can be used earlier in the pipeline without
needing to carefully maintain the invariants of the binding analysis.

Fixes #118400
2024-12-18 09:02:28 -07:00
Justin Bogner
482237e884
[DirectX] Get resource information via TargetExtType (#119772)
Instead of storing an auxilliary structure with the information from the
DXIL resource target extension types duplicated, access the information
that we can via the type itself.

This also means we need to handle some of the target extension types we
haven't fully defined yet, like Texture and CBuffer. For now we make an
educated guess to what those should look like based on llvm/wg-hlsl#76,
and we can update them fairly easily when we've defined them more
thoroughly.

First part of #118400
2024-12-16 16:04:25 -07:00
Justin Bogner
782bc4f669
[DXIL][Analysis] Uniquify duplicate resources in DXILResourceAnalysis
If a resources is used multiple times, we should only have one resource record
for it. This comes up most prominantly with arrays of resources like so:

```hlsl
RWBuffer<float4> BufferArray[10] : register(u0, space4);
RWBuffer<float4> B1 = BufferArray[0];
RWBuffer<float4> B2 = BufferArray[SomeIndex];
RWBuffer<float4> B3 = BufferArray[3];
```

In this case, there's only one resource, but we'll generate 3 different
`dx.handle.fromBinding` calls to access different slices.

Note that this adds some API that won't be used until #104447 later in the
stack. Trying to avoid that results in unnecessary churn.

Fixes #105143

Pull Request: https://github.com/llvm/llvm-project/pull/105602
2024-08-23 12:06:53 -07:00
Justin Bogner
51ede55ee2
Re-Apply "[DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers" (#104517)
Some build configs allow `llvm_unreachable` in a constexpr context, but
not all, so these functions that map a fully covered enum to a string
can't be constexpr. This version fixes that by dropping constexpr from
those functions.

This reverts commit fcc318ff7960d7de8cbac56eb4f32b44b5261677, reapplying
28d577ecefa1557f5dea5566bf33b885c563d14b.

Original message follows:

This implements the DXILResourceAnalysis pass for `dx.TypedBuffer` and
`dx.RawBuffer` types. This should be sufficient to lower
`dx.handle.fromBinding` for this set of types, but it leaves a number of
TODOs around for other resource types.

This also includes a straightforward `print` method in `ResourceInfo` to
make the analysis testable. This is deliberately different than the
printer in `lib/Target/DirectX/DXILResource.cpp`, which attempts to
print bindings in a format compatible with the comments `dxc` prints. We
will eventually want to make that functionality driven by this analysis
pass, but it isn't sufficient for testing so we need both.
2024-08-16 11:36:41 -07:00
Mehdi Amini
fcc318ff79
Revert "[DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers" (#104504)
Reverts llvm/llvm-project#100699

This broke a few bots unfortunately.
2024-08-15 22:48:43 +02:00
Justin Bogner
28d577ecef
[DXIL][Analysis] Implement enough of DXILResourceAnalysis for buffers
This implements the DXILResourceAnalysis pass for `dx.TypedBuffer` and
`dx.RawBuffer` types. This should be sufficient to lower
`dx.handle.fromBinding` for this set of types, but it leaves a number
of TODOs around for other resource types.

This also includes a straightforward `print` method in `ResourceInfo`
to make the analysis testable. This is deliberately different than the
printer in `lib/Target/DirectX/DXILResource.cpp`, which attempts to
print bindings in a format compatible with the comments `dxc` prints.
We will eventually want to make that functionality driven by this
analysis pass, but it isn't sufficient for testing so we need both.

Pull Request: https://github.com/llvm/llvm-project/pull/100699
2024-08-15 00:24:55 +03:00
Justin Bogner
372ddcd1ba
[DXIL][Analysis] Boilerplate for DXILResourceAnalysis pass
Broke this out into its own commit to make the next one easier to
review.

Pull Request: https://github.com/llvm/llvm-project/pull/100700
2024-08-15 00:11:45 +03:00
Justin Bogner
6992ebcb4b
Reapply "[DXIL][Analysis] Make alignment on StructuredBuffer optional" (#101113)
Unfortunately storing a `MaybeAlign` in ResourceInfo deletes our move
constructor in compilers that haven't implemented [P0602R4], like GCC 7.
Since we only ever use the alignment in ways where alignment 1 and unset
are ambiguous anyway, we'll just store the integer AlignLog2 value that
we'll eventually use directly.

[P0602R4]:
https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0602r4.html

This reverts commit c22171f12fa9f260e2525cf61b93c136889e17f2, reapplying
a94edb6b8e321a46fe429934236aaa4e2e9fb97f.
2024-07-30 10:38:34 -07:00
Justin Bogner
c22171f12f
Revert "[DXIL][Analysis] Make alignment on StructuredBuffer optional" (#101088)
Seeing build failures, reverting to investigate.

Reverts llvm/llvm-project#100697
2024-07-29 14:49:28 -07:00
Justin Bogner
a94edb6b8e
[DXIL][Analysis] Make alignment on StructuredBuffer optional
HLSL allows StructuredBuffer<> to be defined with scalar or
up-to-4-element vectors as well as with structs, but when doing so
`dxc` doesn't set the alignment. Emulate this.

Pull Request: https://github.com/llvm/llvm-project/pull/100697
2024-07-29 14:41:15 -07:00
Justin Bogner
38e671ab52
[DXIL][Analysis] Use setters for dxil::ResourceInfo initialization. NFC
This simplifies making sure we set all of the members of the unions
and adds asserts to help catch if we do something wrong.

Pull Request: https://github.com/llvm/llvm-project/pull/100696
2024-07-29 14:30:37 -07:00
Justin Bogner
59e91d4c50
[DXIL][Analysis] Make the DXILResource binding optional. NFC
This makes the binding structure in a DXILResource default to empty
and need a separate call to set up, and also moves the unique ID into
it since bindings are the only place where those are actually used.

This will put us in a better position when dealing with resource
handles in libraries.

Pull Request: https://github.com/llvm/llvm-project/pull/100623
2024-07-25 12:27:57 -07:00
Justin Bogner
82c21f085a
[DXIL][Analysis] Replace #include with forward declaration. NFC
Pull Request: https://github.com/llvm/llvm-project/pull/100622
2024-07-25 11:30:03 -07:00
Justin Bogner
b365dbbd8d
[DXIL][Analysis] Move dxil::ResourceInfo to the Analysis library. NFC
I had put this in Transforms/Utils, but that doesn't actually make
sense if we want to populate these structures via an analysis pass.

Pull Request: https://github.com/llvm/llvm-project/pull/100621
2024-07-25 11:22:04 -07:00