231 Commits

Author SHA1 Message Date
Vlad Serebrennikov
9dd5542a34
[clang][NFC] Replace includes of "Attrs.inc" with "Attr.h" (#180356)
"clang/AST/Attrs.inc" is not a self-contained header and is not intended
to be included directly. Instead, "clang/AST/Attr.h" is the header that
users need.
2026-02-07 17:32:56 +00:00
Farzon Lotfi
5f4543fbaf
[HLSL][Matrix] introduce MatrixElementExpr as accessor and swizzle operator (#171225)
fixes #159438

This patch adds `MatrixElementExpr`, a new AST node for HLSL matrix
element and swizzle access (e.g. M._m00, M._11_22_33).

It introduces a shared `ElementAccessExprBase` used by both matrix and
vector swizzle expressions, updates Sema to parse and validate
zero-based and one-based accessors, detects duplicates for l-value
checks, and emits improved diagnostics. CodeGen is updated to lower
scalar and multi-element accesses consistently, and full AST
serialization, dumping, and tooling support is included. This
implementation reflects the updated
[RFC](https://github.com/llvm/wg-hlsl/pull/357/files) for HLSL matrix
accessor semantics.
2026-02-06 13:16:49 -05:00
Kaitlin Peng
7798a8907e
Implement ByteAddressBuffer Load/Store methods (#176058)
Closes #108058.

This PR:
- Adds the `uint` `Load` and `Store` methods (`Load/Store`,
`Load2/Store2`, `Load3/Store3`, `Load4/Store4`) to the existing
`ByteAddressBuffer` objects
- Adds the new templated `Load` and `Store` methods to
`ByteAddressBuffer` objects, which allow types other than `uint` (e.g.
aggregate types) to be used with them directly
- One exception to this is array types, which are rejected by the
methods (as array returns will be disallowed in 202x)
- Adds the relevant `AST`, `CodeGenHLSL`, and `SemaHLSL` tests for these
methods

*Note: the `HLSL Tests` check is failing because this implementation
makes the `ByteAddressBuffer` tests XPASS. Will remove the XFAILs from
these tests in a follow-up.*
2026-02-03 10:02:44 -08:00
Kai
751a546fa9
[HLSL][DXIL][SPIRV] WavePrefixSum intrinsic support (#167946)
Issue: https://github.com/llvm/llvm-project/issues/99172
- [x] Implement `WavePrefixSum` clang builtin
- [x] Link `WavePrefixSum` clang builtin with `hlsl_intrinsics.h`
- [x] Add sema checks for `WavePrefixSum` to
`CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [x] Add codegen for `WavePrefixSum` to `EmitHLSLBuiltinExpr` in
`CGBuiltin.cpp`
- [x] Add codegen tests to
`clang/test/CodeGenHLSL/builtins/WavePrefixSum.hlsl`
- [x] Add sema tests to
`clang/test/SemaHLSL/BuiltIns/WavePrefixSum-errors.hlsl`
- [x] Create the `int_dx_WavePrefixSum` intrinsic in
`IntrinsicsDirectX.td`
- [x] Create the `DXILOpMapping` of `int_dx_WavePrefixSum` to `121` in
`DXIL.td`
- [x] Create the `WavePrefixSum.ll` and `WavePrefixSum_errors.ll` tests
in `llvm/test/CodeGen/DirectX/`
- [x] Create the `int_spv_WavePrefixSum` intrinsic in
`IntrinsicsSPIRV.td`
- [x] In SPIRVInstructionSelector.cpp create the `WavePrefixSum`
lowering and map it to `int_spv_WavePrefixSum` in
`SPIRVInstructionSelector::selectIntrinsic`.
- [x] Create SPIR-V backend test case in
`llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WavePrefixSum.ll`

I also added a new macro
`GENERATE_HLSL_INTRINSIC_FUNCTION_SELECT_UNSIGNED` in conjunction with
the new function `getUnsignedIntrinsicVariant` to make selecting
unsigned variants of the intrinsic easier. As a result, I was able to
replace `getWaveActiveSumIntrinsic`, `getWaveActiveMaxIntrinsic`, and
`getWaveActiveMinIntrinsic` using the new macro.
2026-02-03 03:00:45 -05:00
Steven Perron
60556a2ec2
[HLSL] Implement Texture2D type and Sample method in Clang (#177240)
This patch implements the `Texture2D` resource type and its `Sample`
member
function in Clang. It includes the necessary AST and Sema changes to
support
the new type and its built-in methods, as well as CodeGen support for
both
DirectX and SPIR-V targets.

Key changes:
- Added `ResourceDimension` to `HLSLAttributedResourceType` and
`HLSLResourceDimension` attribute.
- Implemented `Texture2D` and `SamplerState` in
`HLSLExternalSemaSource`.
- Added `__builtin_hlsl_resource_sample` and associated Sema checking.
- Updated `DirectXTargetCodeGenInfo` and `CommonSPIRTargetCodeGenInfo`
to handle texture types.
- Added AST, Sema, and CodeGen tests for `Texture2D`.

Part 2 of https://github.com/llvm/llvm-project/issues/175630
2026-01-30 21:44:01 -05:00
Farzon Lotfi
8065a03083
[HLSL] Make Matrix types in buildInitializerListImpl index in row major order for initializer lists. (#178931)
fixes #178930

- changes the loop indexing order
- updates the associated tests
2026-01-30 21:13:54 -05:00
Joshua Batista
293a668329
[HLSL] Add wave prefix count bits function (#178059)
This PR adds the WavePrefixCountBits function to HLSL, including spirv
and DXIL code generation.
Fixes https://github.com/llvm/llvm-project/issues/99171
2026-01-29 12:09:27 -08:00
Tim Corringham
d5f405558d
[HLSL] Implement f32tof16() intrinsic (#172469)
Implement the f32tof16() intrinsic, DXIL and SPIRV codegen, and related
tests.

Fixes #99113

---------

Co-authored-by: Tim Corringham <tcorring@amd.com>
2026-01-26 15:06:48 +00:00
Joshua Batista
6fdccdbe91
[Sema][HLSL] Reject empty initializer lists for LHS containing an incomplete array. (#176075)
This PR rejects empty initializer lists when the LHS is or contains an
incomplete array type.
Without this early validation, an assumption would be made that there
was an argument in the initializer list.
This would cause an assertion failure.

Fixes https://github.com/llvm/llvm-project/issues/173076
2026-01-20 10:11:15 -08:00
Helena Kotas
d52c7da086
[HLSL] Simplify register value conversion and fix a few clang-tidy issues (#175697)
Moves `SlotNumStr` conversion back outside of the `ValidateRegisterNumber` function.
Also fixes couple of few clang-tidy issues and adds `llvm_unreachable` to catch unexpected declarations.

Related to #136809
2026-01-13 10:40:11 -08:00
Joshua Batista
719006a195
[HLSL][Sema] Validate that occupied register numbers never exceed UINT32_MAX (#174028)
This PR adds validation for register numbers.
Register numbers ought never to exceed UINT32_MAX, or 4294967295
Additionally, resource arrays will have each resource element bound
sequentially, and those resource's register numbers should not exceed
UINT32_MAX, or 4294967295. Even though not explicitly given a register
number, their effective register number is also validated.
This accounts for nested resource declarations and resource arrays too.

Fixes https://github.com/llvm/llvm-project/issues/136809
2026-01-09 13:37:49 -08:00
Nathan Gauër
0258aa62b7
[HLSL] Prevent uninitialized on 2 int arguments (#173352)
Unparsed HLSL semantics have 2 int/bool arguments with default values.
Those values are loaded using checkUInt32Argument, and thus this should
never fail.

But if something is wrong in the code above (or the def changed), this
code wouldn't catch it and we'd read uninitialized integers. This
commits checks both return values and assert if one fails. On release
builds, this would early return, causing a bad codegen, but such change
will be caught by tests.
2025-12-29 13:12:15 +01:00
Akira Hatanaka
634eb7ee40
[NFC] Constify IdentifierInfo (#173266)
This change updates several APIs and local uses to take pointers to
const IdentifierInfo where mutation is not required.
2025-12-23 09:26:26 -08:00
Farzon Lotfi
cb56a910f8
[HLSL][Matrix] Add OR and AND logical operator support for matrix (#172384)
fixes #172341

This change adds the `or` and `and` HLSL builtins with overloads for the
matrix types.

It also disables the logical operators from being used for HLSL 2021. To
keep this code from getting too complicated HLSL 2018 and lower logical
operator support was not added.
2025-12-20 17:20:32 -05:00
Helena Kotas
91f14c1f4a
[HLSL] Improve packoffset error message (#173077)
Aggregate types cannot have a component specified on a `packoffset` annotation (i.e. `packoffset(c1.y)`). If the component is preset and it is not 'x', the reported error is `register or packoffset bind is not valid`.

For non-aggregate types with a component that does not fit the constant buffer row size of 128 bits minus the component offset, the error message is `packoffset cannot cross register boundary`.

Also fixes grammar in a related error message.

Fixes #128109
2025-12-20 10:34:37 -08:00
Sarah Spall
ac387cee97
[HLSL][NFC] Add assert ensuring divide by zero can't happen (#173072)
Add assert ensuring divide by zero can't happen in the case we are
initializing an incomplete array type object.
2025-12-19 11:16:01 -08:00
Nathan Gauër
8cfda79105
[HLSL][SPIR-V] Implement vk::push_constant (#166793)
Implements initial support for vk::push_constant.
As is, this allows handling simple push constants, but has one
main issue: layout can be incorrect (See #168401). The layout
issue being not only push-constant related, it's ignored for this PR.

The frontend part of the implementation is straightforward:
 - adding a new attribute
 - when targeting vulkan/spirv, we process it
 - global variables with this attribute gets a new AS:
   hlsl_push_constant

The IR has nothing specific, only some RO globals in this new AS.

On the SPIR-V side, we not convert this AS into a PushConstant storage
class. But this creates some issues: the variables in this storage class
must have a specific set of decoration to define their layout.

Current infra to create the SPIR-V types lacks the context required to
make this decision: no indication on the AS or context around the type
being created. Refactoring this would be a heavy task as it would
require getting this information in every place using the GR for type
creation.

Instead, we do something similar to CBuffers:
 - find all globals with this address space, and change their type to
   a target-specific type.
 - insert a new intrinsic in place of every reference to this global
   variable.

This allow the backend to handle both layout variables loads and type
lowering independently.

Type lowering has nothing specific: when we encounter a target extension
type with spirv.PushConstant, we lower this to the correct SPIR-V type
with the proper offset & block decorations.

As for the intrinsic, it's mostly a no-op, but required since we have
this target-specific type.

Note: this implementation prevents the static declaration of multiple
push constants in a single shader module. The actual specification is
more relaxed: there can be only one **used** push constant block per
entrypoint. To correctly implement this, we'd require to keep some
additional state to determine the list of statically used resources per
entrypoint. This shall be addressed as a follow-up (see #170310)
2025-12-18 11:01:11 +01:00
Alexander Johnston
4ca2caeab6
[HLSL] Implement ddx/ddy_fine intrinsics (#168874)
Implements the HLSL ddx_fine and ddy_fine intrinsics.
For the SPIRV backend the intrinsics are ensured to be unavailable in
opencl (as they require fragment execution stage).

Closes https://github.com/llvm/llvm-project/issues/99098
Closes https://github.com/llvm/llvm-project/issues/99101
2025-12-12 09:34:41 -08:00
Farzon Lotfi
dd1b4abfb7
[HLSL][Matrix] Add support for Matrix element and trunc Casts (#168915)
fixes #168737
fixes #168755

This change fixes adds support for Matrix truncations via the
ICK_HLSL_Matrix_Truncation enum. That ends up being most of the files
changed.

It also allows Matrix as an HLSL Elementwise cast as long as the cast
does not perform a shape transformation ie 3x2 to 2x3.

Tests for the new elementwise and truncation behavior were added. As
well as sema tests to make sure we error n the shape transformation
cast.

I am punting right now on the ConstExpr Matrix support. That will need
to be addressed later. Will file a seperate issue for that if reviewers
agree it can wait.
2025-12-02 19:02:25 -05:00
Helena Kotas
434127b0c1
[HLSL] Static resources (#166880)
This change fixes couple of issues with static resources:
- Enables assignment to static resource or resource array variables (fixes #166458)
- Initializes static resources and resource arrays with default constructor that sets the handle to poison
2025-12-02 22:25:17 +00:00
Nathan Gauër
8a40d08b83
[HLSL][SPIR-V] Implement vk::location for inputs (#169479)
This commit adds the support for vk::location attribute which can be
applied to input and output variables.

As in/inout parameters are not supported yet, vk::location on such
parameters is not tested.

As implemented in DXC, vk::location has the following rules:
- input and outputs are handled independently.
- input/output lowered to a SPIR-V builtins are not using the assigned
vk::location and thus ignored.
- input/output lowered to a Location decoration must either all have
explicit locations, or none. Mixing is not allowed (except with
builtins).
2025-12-02 14:08:31 +00:00
Nathan Gauër
e74b425ddc
[HLSL][SPIR-V] Add support for SV_Target semantic (#168743)
This PR adds the support for the SV_Target semantic and improved the
diagnostics when the stage is correct, but the direction is disallowed.

This PR will require #168735 to be merged first.
2025-12-02 13:19:00 +00:00
Nathan Gauër
74f5548bbc
[HLSL][SPIR-V] Implements SV_Position for VS/PS I/O (#168735)
Current implementation for SV_Position was very basic to allow
implementing/testing some semantics. Now that semantic support is more
robust, I can move forward and implement the whole semantic logic.

DX part is still a bit placeholder.
2025-11-24 12:42:20 +00:00
Joshua Batista
fea070b610
[HLSL] Add Load overload with status (#166449)
This PR adds a Load method for resources, which takes an additional
parameter by reference, status. It fills the status parameter with a 1
or 0, depending on whether or not the resource access was mapped.
CheckAccessFullyMapped is also added as an intrinsic, and called in the
production of this status bit.
Only addresses DXIL for the below issue:
https://github.com/llvm/llvm-project/issues/138910
Also only addresses the DXIL variant for the below issue:
https://github.com/llvm/llvm-project/issues/99204
2025-11-21 10:11:38 -08:00
Helena Kotas
19fe9b477b
[HLSL][TableGen] Add __hlsl_resource_t to known built-in function types (#163465)
This change adds resource handle type `__hlsl_resource_t` to the list of types recognized in the Clang's built-in functions prototype string.

HLSL has built-in resource classes and some of them have many methods, such as
[Texture2D](https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-object-texture2d).
Most of these methods will be implemented by built-in functions that will take resource handle as an argument. This change enables us to move from generic `void(...)` prototype string for these methods and explicit argument checking in `SemaHLSL.cpp` to a prototype string with explicit argument types. Argument checking in `SemaHLSL.cpp` can be reduced to handle just the rules that cannot be expressed in the prototype string (for example verifying that the offset value in `__builtin_hlsl_buffer_update_counter` is `1` or `-1`).

In order to make this work, we now allow conversions from attributed resource handle type such as `__hlsl_resource_t [[hlsl::resource_class(UAV)]] [[hlsl::contained_type(float)]]` to a plain non-attributed `__hlsl_resource_t` type.
2025-11-19 14:56:49 -08:00
Nathan Gauër
2fc42c7163
[HLSL] Add initial support for output semantics (#168095)
This commits adds the first part of the output semantics. It only
considers return values (and sret), but does not handle `inout` or `out`
parameters yet.
Those missing bits will reuse the same code, but will require additional
testing & some fixups, so planning on adding them separately.
2025-11-19 14:51:46 +01:00
Alexander Johnston
ed60cd2563
[HLSL] Implement ddx/ddy_coarse intrinsics (#164831)
Closes https://github.com/llvm/llvm-project/issues/99097
Closes https://github.com/llvm/llvm-project/issues/99100

As ddx and ddy are near identical implementations I've combined them in
this PR. This aims to unblock
https://github.com/llvm/llvm-project/pull/161378

---------

Co-authored-by: Alexander Johnston <alexander.johnston@amd.com>
2025-11-18 16:41:07 +01:00
Nathan Gauër
78554d9e84
Reapply "[HLSL] Rework semantic handling as attributes" (#167862)
Last PR had asan failures due to bad use of a Twine instead of an
std::string.
2025-11-13 14:09:15 +01:00
Nathan Gauër
1d2429b5ac
Revert "[HLSL] Rework semantic handling as attributes #166796" (#167759)
Reverting 2 commits from the mainline. The origin of the issue, and the
tentative fix-forward.
2025-11-12 21:19:34 +00:00
Michael Liao
cc54ee854f [clang][HLSL] Fix crash issue due to Twine usage
- Dangling pointer (from std::string) is created and trigger crash on
  some Linux distributions under different build types.
2025-11-12 14:55:15 -05:00
Nathan Gauër
dba85079c7
[HLSL] Rework semantic handling as attributes (#166796)
Previously, we had 2 level of attributes:
 - HLSLUnparsedSemantic
 - N attributes, one for each known system semantic.

The first was assigned during parsing, and carried no other meaning than
"there is a semantic token". It was then converted to one of the N
attributes later during Sema.
Those attributes also carried informations like "is indexable" or "is
index explicit".

This had a few issues:
- there was no difference between a semantic attribute applied to a
decl, and the effective semantic in the entrypoint use context.
 - having the indexable bit was not useful.
 - semantic constraints checks were split between .td files and sema.

Also, existing implementation had effective attributes attached to the
type decl or parameters, meaning struct decl reuse across entrypoints of
in a nested type was not supported, even if legal in HLSL.

This PR tried to simplifies semantic attribute by having 3 attributes:

 - HLSLUnpasedSemantic
 - HLSLParsedSemantic
 - HLSLAppliedSemantic

Initial parsing emits an `HLSLUnparsedSemantic`. We simply say "here is
an HLSL semantic token", but we don't do any semantic check.

Then, Sema does initial validation and transforms an UnparseSemantic
into a ParsedSemantic. This validates a system semantic is known, or
that the associated type is valid (like uint3 for a ThreadIndex).

Then, once we parse an actual shader entrypoint, we can know how
semantics are used in a real context. This step emits a list of
AppliedSemantic. Those are the actual semantic in use for this specific
entrypoint.
Those attributes are attached to each entrypoint parameter, as a flat
list matching the semantic structure flattening HLSL defines. At this
stage of sema, index collision or other stage compabitility checkes are
carried.

This allows codegen to simply iterate over this list and emit the proper
DXIL or SPIR-V codegen.
2025-11-12 18:54:38 +01:00
Helena Kotas
6d1831361f
[HLSL] Add internal linkage attribute to resources (#166844)
HLSL resources should not be externally visible from the module. We made sure of this by marking them `static` as soon as they were declared. However, this prevents us fixing issue #166458 because there is no way to know if a resource has been explicitly marked `static` by the user, and can therefore be assigned to.

This change moves from making all resources `static` to adding Clang internal linkage attribute to all non-static resource declarations as a global scope.

No explicit test added this change. There is a number of existing HLSL codegen tests that already verify that the resource globals are emitted as `internal global`.
2025-11-10 10:25:59 -08:00
Nathan Gauër
b8a814e4fc
[HLSL] Add support for user semantics (#153424)
This commit adds support for HLSL input semantics. User semantics are
all semantics not starting with `SV_`.
Those semantics ends up with a Location assignment in SPIR-V.

Note: user semantics means Location, but the opposite is not true.
Depending on the stage, some system semantics can rely on a Location
index. This is not implemented in this PR.
2025-11-06 15:36:17 +01:00
Tim Corringham
89ec96b8b4
[HLSL] Implement the f16tof32() intrinsic (#165860)
Implement the f16tof32() intrinsic, including DXILand SPIRV codegen, and
associated tests.

Fixes #99112

---------

Co-authored-by: Tim Corringham <tcorring@amd.com>
2025-11-04 17:04:39 +00:00
Sietze Riemersma
bfd4935fa3
[HLSL][DXIL][SPRIV] Added WaveActiveMin intrinsic (#164385)
Adds the WaveActiveMin intrinsic from #99169. I think I did all of the
required things on the checklist:
- [x]  Implement `WaveActiveMin` clang builtin,
- [x]  Link `WaveActiveMin` clang builtin with `hlsl_intrinsics.h`
- [x] Add sema checks for `WaveActiveMin` to
`CheckHLSLBuiltinFunctionCall` in `SemaChecking.cpp`
- [x] Add codegen for `WaveActiveMin` to `EmitHLSLBuiltinExpr` in
`CGBuiltin.cpp`
- [x] Add codegen tests to
`clang/test/CodeGenHLSL/builtins/WaveActiveMin.hlsl`
- [x] Add sema tests to
`clang/test/SemaHLSL/BuiltIns/WaveActiveMin-errors.hlsl`
- [x] Create the `int_dx_WaveActiveMin` intrinsic in
`IntrinsicsDirectX.td`
- [x] Create the `DXILOpMapping` of `int_dx_WaveActiveMin` to `119` in
`DXIL.td`
- [x] Create the `WaveActiveMin.ll` and `WaveActiveMin_errors.ll` tests
in `llvm/test/CodeGen/DirectX/`
- [x] Create the `int_spv_WaveActiveMin` intrinsic in
`IntrinsicsSPIRV.td`
- [x] In SPIRVInstructionSelector.cpp create the `WaveActiveMin`
lowering and map it to `int_spv_WaveActiveMin` in
`SPIRVInstructionSelector::selectIntrinsic`.
- [x] Create SPIR-V backend test case in
`llvm/test/CodeGen/SPIRV/hlsl-intrinsics/WaveActiveMin.ll

But as some of the code has changed and was moved around (E.G.
`CGBuiltin.cpp` -> `CGHLSLBuiltins.cpp`) I mostly followed how
`WaveActiveMax()` is implemented.

I have not been able to run the tests myself as I am unsure which
project runs the correct test. Any guidance on how I can test myself
would be helpful.

Also added some tests to the offload-test-suite
https://github.com/llvm/offload-test-suite/pull/478
2025-10-28 11:01:13 -07:00
Farzon Lotfi
251edd1228
[HLSL] Add matrix constructors using initalizer lists (#162743)
fixes #159434

In HLSL matrices are matrix_type in all respects except that they
support a constructor style syntax for initializing matrices.

This change adds a translation of vector constructor arguments into
initializer lists.

This supports the following HLSL syntax:
(1) HLSL matrices support constructor syntax
(2) HLSL matrices are expanded to constituate components in constructor

using the same initalizer list behavior defined in transformInitList
allows us to support struct element initalization via
HLSLElementwiseCast
2025-10-24 15:40:41 -04:00
Nathan Gauër
865cd8ea02
[HLSL] Allow input semantics on structs (#159047)
This PR is an incremental improvement regarding semantics I/O in HLSL.
This PR allows
system semantics to be used on struct type in addition to parameters
(state today).
This PR doesn't consider implicit indexing increment that happens when
placing a semantic on an aggregate/array as implemented system semantics
don't allow such use yet.

The next step will be to enable user semantics, which will bring the
need to properly determine semantic indices depending on context.
This PR diverge from the initial wg-hlsl proposal as all diagnostics are
done in Sema (initial proposal suggested running diags in codegen).

This is not yet a solid semantic implementation, but increases the test
coverage and improves the status from where we are now.
2025-10-23 15:49:35 +02:00
Helena Kotas
024dd56922
[HLSL] GetDimensions methods for buffer resources (#161929)
Adds `GetDimensions` methods to all supported buffer resource classes (`{RW}Buffer`, `*StructuredBuffer`, `{RW}ByteAddressBuffer`). The method is implemented by calling one of both built-in functions `__builtin_hlsl_resource_getdimensions_x` and `__builtin_hlsl_resource_getstride` as described in proposal https://github.com/llvm/wg-hlsl/pull/350.

The `__builtin_hlsl_resource_getstride` is implemented directly by Clang codegen by setting the buffer stride to the output variable.

The `__building_hlsl_buffer_getdimensions` built-in function gets translated to LLVM intrinsic `@llvm.dx.resource.getdimensions.x`.

Closes #112984
2025-10-17 12:09:34 -07:00
Matheus Izvekov
b516dcc998
[clang] NFC: rename TagType::getOriginalDecl back to getDecl (#163271)
This rename was made as part of
https://github.com/llvm/llvm-project/pull/147835 in order to ease
rebasing the PR, and give a nice window for other patches to get rebased
as well.

It has been a while already, so lets go ahead and rename it back.
2025-10-15 16:11:17 -03:00
Sarah Spall
9bf88d09b3
[NFC][HLSL] Remove unused function 'ContainsBitField' (#163230)
Remove unused function, 'ContainsBitField', which was meant to be
removed when bitfield support was added to HLSLAggregateSplatCast and
HLSLElementwiseCast.
2025-10-13 11:53:53 -07:00
Steven Perron
ec15cdfb32
[SPIRV][HLSL] Add Sema and CodeGen for implicit typed buffer counters (#162291)
This commit implements the Sema and CodeGen portions of the typed buffer
counter proposal described in the HLSL WG proposal 0023.

This change introduces the necessary Sema and CodeGen logic to handle
implicit counter variables for typed buffers. This includes:

- Extending `HLSLResourceBindingAttr` to store the implicit counter
  binding order ID.
- Introducing the
`__builtin_hlsl_resource_counterhandlefromimplicitbinding`
  builtin.
- Updating `SemaHLSL` to correctly initialize global resource
declarations
  and resource arrays with implicit counter buffers.
- Adding CodeGen support for the new builtin, which generates a
  `llvm.spv.resource.counterhandlefromimplicitbinding` intrinsic for the
SPIR-V target and aliases the main resource handle for the DXIL target.
- Adding and updating tests to verify the new functionality.

Fixes #137032
2025-10-09 12:30:58 -04:00
Helena Kotas
2a2324a6ea
[HLSL] Do not remove HLSLVkBindingAttr if the target is not SPIR-V (#161752)
The attribute needs to be preserved for rewriter scenarios. Two places were updated to use the `ResourceBindingAttrs` helper struct to make sure the `HLSLVkBindingAttr` is ignored when the target is DirectX.
2025-10-07 14:48:29 -07:00
joaosaffran
58ce3e20e5
[DirectX] Fix Flags validation to prevent casting into enum (#161587)
This PR changes the validation logic for Root Descriptor and Descriptor
Range flags to properly check if the `uint32_t` values are within range
before casting into the enums.
2025-10-06 17:21:28 -04:00
Sarah Spall
35c57a778b
[HLSL] Add support for elementwise and aggregate splat casting struct types with bitfields (#161263)
Adds support for elementwise and aggregate splat casting struct types
with bitfields. Replacing existing Flattening function which used to
produce a list of GEPs representing a flattened object with one that
produces a list of LValues representing a flattened object. The LValues
can be used by EmitStoreThroughLValue and EmitLoadOfLValue, ensuring
bitfields are properly loaded and stored. This also simplifies the code
in the elementwise and aggregate splat casting functions.
Closes #125986
2025-10-06 08:26:23 -07:00
Steven Perron
67c000efb7
[HLSL] [SPIR-V] Add counter member for typed buffer (#161414)
This is part 1 of implementing the typed buffer counters proposal:

https://github.com/llvm/wg-hlsl/blob/main/proposals/0023-typed-buffer-counters.md

This patch adds the initial plumbing for supporting counter variables
associated with structured buffers for the SPIR-V backend. It introduces
an `IsCounter` attribute to `HLSLAttributedResourceType` and threads it
through the AST, type printing, and mangling. It also adds a
`__counter_handle` member to the relevant buffer types in
`HLSLBuiltinTypeDeclBuilder`.

Contributes to https://github.com/llvm/llvm-project/issues/137032
2025-10-02 17:47:28 +00:00
Helena Kotas
b6dfa3d47d
[HLSL][NFC] Add helper struct to simplify dealing with resource binding attributes (#161254)
Add new `ResourceBindingAttrs` struct that holds resource binding attributes `HLSLResourceBindingAttr` and `HLSLVkBindingAttr` and provides helper methods to simplify dealing with resource bindings. This code is placed in the AST library to be shared between Sema and CodeGen.

This change has been done in preparation of a third binding attribute coming soon to represent `[[vk::counter_binding()]]`. This new attribute and more helper member functions will be added to `ResourceBindingAttrs` and will be used in both Sema and in CodeGen to implement resource counter initialization.
2025-09-30 14:24:55 -07:00
Dan Brown
df420ee2ba
Implements isnan() HLSL intrinsic for DXIL and SPIR-V targets. (#157733)
Addresses #99132.
2025-09-25 12:34:47 -04:00
Sarah Spall
f8bb4f9311
[HLSL] Enable InitList code to handle zero sized structs (#160355)
Enable InitList code to handle zero sized structs; this includes structs
with no fields and those with only unnamed bitfields.
Closes #157920
2025-09-23 14:05:42 -07:00
Farzon Lotfi
6ac40aaaf6
[HLSL] Add support for the HLSL matrix type (#159446)
fixes #109839

This change is really simple. It creates a matrix alias that will let
HLSL use the existing clang `matrix_type` infra.

The only additional change was to add explict alias for the typed
dimensions of 1-4 inclusive matricies available in HLSL.

Testing therefore is limited to exercising the alias, sema errors, and
basic codegen.
future work will add things like constructors and accessors.

The main difference in this attempt is the type printer and less of an
emphasis on tests where things overlap with existing `matrix_type`
testing like cast behavior.
2025-09-23 13:02:17 -04:00
Sarah Spall
fc438d30d9
[HLSL] avoid unnamed bit fields when dealing with InitLists in HLSL (#159212)
In HLSL Init List code avoid initializing unnamed bitfields and avoid
initializing using unnamed bit fields.
Add tests.
Closes #157922
2025-09-23 09:35:45 -07:00