339 Commits

Author SHA1 Message Date
Helena Kotas
e04fedadba
[HLSL] Tests for local resource arrays (#153257)
Add tests for local arrays of resources.

Closes #145425
2025-08-19 09:22:27 -07:00
Helena Kotas
eb3d88423d
[HLSL] Global resource arrays element access (#152454)
Adds support for accessing individual resources from fixed-size global resource arrays.

Design proposal:
https://github.com/llvm/wg-hlsl/blob/main/proposals/0028-resource-arrays.md

Enables indexing into globally scoped, fixed-size resource arrays to retrieve individual resources. The initialization logic is primarily handled during codegen. When a global resource array is indexed, the
codegen translates the `ArraySubscriptExpr` AST node into a constructor call for the corresponding resource record type and binding.

To support this behavior, Sema needs to ensure that:
- The constructor for the specific resource type is instantiated.
- An implicit binding attribute is added to resource arrays that lack explicit bindings (#152452).

Closes #145424
2025-08-18 18:20:46 -07:00
Kaitlin Peng
cbc8f650ea
[HLSL][DirectX] Fix dot2add DXIL operation to use float overload (#152781)
Fixes #152585.

The `dot2add` DXILOpFunction should be `dx.op.dot2AddHalf.f32` (i.e. it
has [a single overload that's a
float](https://github.com/microsoft/DirectXShaderCompiler/blob/main/utils/hct/hctdb.py#L3960),
rather than no overloads). It was also being defined for too low of a
DXIL version - [dxc says
SM6.4](https://github.com/microsoft/DirectXShaderCompiler/blob/main/utils/hct/hctdb.py#L740).
2025-08-11 13:03:24 -07:00
Steven Perron
fe0948c9a5
[HLSL][SPIRV] Add vk::binding attribute (#150957)
The vk::binding attribute allows users to explicitly set the set and
binding for a resource in SPIR-V without chaning the "register"
attribute, which will be used when targeting DXIL.

Fixes https://github.com/llvm/llvm-project/issues/136894
2025-08-05 21:00:06 -04:00
Helena Kotas
3b2a1a5d9b
[HLSL][NFC] Move all resource tests under CodeGenHLSL\resources (#152035)
Also removes an outdated test buffer-array-operator.hlsl. Array operator on resources is tested in StructuredBuffers-subscripts.hlsl and RWBuffer-subscript.hlsl.
2025-08-05 10:05:05 -07:00
Farzon Lotfi
b59cb281c1
[HLSL] fix D3DCOLORtoUBYTE4 return type to be int (#151353)
fixes #150673
fixes #150678

The issue was we were using the wrong return type.
2025-07-31 12:34:02 -04:00
Deric C.
ed9a1027a4
[HLSL] Avoid putting the byval attribute on out and inout parameters (#150495)
Fixes #148063 by preventing the ByVal attribute from being placed on out
and inout function parameters which causes them to be eliminated by the
Dead Store Elimination (DSE) pass.
2025-07-24 13:54:00 -07:00
raoanag
056f0a10b3
[HLSL][DXIL] Implement refract intrinsic (#147342)
- [x] Implement refract using HLSL source in hlsl_intrinsics.h
- [x] Implement the refract SPIR-V target built-in in
clang/include/clang/Basic/BuiltinsSPIRV.td
- [x] Add sema checks for refract to CheckSPIRVBuiltinFunctionCall in
clang/lib/Sema/SemaSPIRV.cpp
- [x] Add codegen for spv refract to EmitSPIRVBuiltinExpr in
CGBuiltin.cpp
- [x] Add codegen tests to clang/test/CodeGenHLSL/builtins/refract.hlsl
- [x] Add spv codegen test to clang/test/CodeGenSPIRV/Builtins/refract.c
- [x] Add sema tests to clang/test/SemaHLSL/BuiltIns/refract-errors.hlsl
- [x] Add spv sema tests to
clang/test/SemaSPIRV/BuiltIns/refract-errors.c
- [x] Create the int_spv_refract intrinsic in IntrinsicsSPIRV.td
- [x] In SPIRVInstructionSelector.cpp create the refract lowering and
map it to int_spv_refract in SPIRVInstructionSelector::selectIntrinsic.
- [x] Create SPIR-V backend test case in
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/refract.ll
- [x] Check for what OpenCL support is needed.

Resolves https://github.com/llvm/llvm-project/issues/99153
2025-07-16 11:28:55 -07:00
Finn Plummer
7ccdc595f8
[HLSL][RootSignature] Add basic parameter validations of Root Elements (#145795)
In this pr we go through and enforce the various bounded parameter
values for non-flag values and the valid flag combinations for
`RootDescriptor` and `DescriptorRange` flags.

For reference of the required checks, please see here:
https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-in-sema.

- Updates `SemaHLSL` to iterate through `RootElement`s and verify that
all non-flag parameters are within their bounds
- Updates `SemaHLSL` to iterate through `RootElement`s and verify that
all flag parameters are a valid combination
- Extends `RootSignature-err.hlsl` with testcases for all invalid
specifications
- Adds `RootSignature-flags-err.hlsl` with testcase for invalid flag
specifications

Resolves: https://github.com/llvm/llvm-project/issues/129940
2025-07-13 10:23:38 -07:00
Victor Lomuller
27c9b55659
[SPIRV] Add more id and range builtIns (#143909)
The patch adds intrinsics and lowering logic for GlobalSize,
GlobalOffset, SubgroupMaxSize, NumWorkgroups, WorkgroupSize,
WorkgroupId, LocalInvocationId, GlobalInvocationId, SubgroupSize,
NumSubgroups, SubgroupId and SubgroupLocalInvocationId SPIR-V builtins.

The patch also extend spv_thread_id, spv_group_id and
spv_thread_id_in_group to return anyint rather than i32. This allows the
intrinsics to support the opencl environment.

For each of the intrinsics, new clang builtins were added as well as a
binding for the SPIR-V "friendly" format. The original format doesn't
define such binding (uses global variables) but it is not possible to
express the Input SC which is normally required by the environement
specs, and using builtin functions is the most usual approach for other
backend and programming models.
2025-07-09 13:52:06 +01:00
Steven Perron
68173c8091
[HLSL][SPRIV] Handle signed RWBuffer correctly (#144774)
In Vulkan, the signedness of the accesses to images has to match the
signedness of the backing image.
    
See

https://docs.vulkan.org/spec/latest/chapters/textures.html#textures-input,
where it says the behaviour is undefined if
    
> the signedness of any read or sample operation does not match the
signedness of the image’s format.
    
Users who define say an `RWBuffer<int>` will create a Vulkan image with
a signed integer format. So the HLSL that is generated must match that
expecation.
    
The solution we use is to generate a `spirv.SignedImage` target type for
signed integer instead of `spirv.Image`. The two types are otherwise the
same.
    
The backend will add the `signExtend` image operand to access to the
image to ensure the image is access as a signed image.
    
Fixes #144580
2025-07-02 12:09:47 -04:00
Sarah Spall
23be14b222
[HLSL][SPIRV] Boolean in a RawBuffer should be i32 and Boolean vector in a RawBuffer should be <N x i32> (#144929)
Instead of converting the type in a RawBuffer to its HLSL type using
'ConvertType', use 'ConvertTypeForMem'.
ConvertTypeForMem handles booleans being i32 and boolean vectors being <
N x i32 >.
Add tests to show booleans and boolean vectors in RawBuffers now have
the correct type of i32, and respectively.
Closes #141089
2025-06-27 13:43:03 -07:00
Steven Perron
08964d69b0
[HLSL][SPIRV] Handle uint type for spec constant (#145577)
The testing only tried `unsigned int` and not `uint`. We want to
correctly handle these surgared types as specialization constants.
2025-06-26 11:19:02 -04:00
Nikita Popov
1128a4fd2c
[HLSL] Don't use CreateRuntimeFunction for intrinsics (#145334)
HLSL uses CreateRuntimeFunction for three intrinsics. This is pretty
unusual thing to do, and doesn't match what the rest of the file does.

I suspect this might be because these are convergent calls, but the
intrinsics themselves are already marked convergent, so it's not
necessary for clang to manually add the attribute.

This does lose the spir_func CC on the intrinsic declaration, but again,
CC should not be relevant to intrinsics at all.
2025-06-23 17:37:33 +02:00
Justin Bogner
6b9fe9e0bc
[HLSL] Emit a version in the dx.rootsignatures metadata (#145113)
In #144957 the backend was updated to expect a version in the metadata,
but since the frontend wasn't updated this breaks compilation. This is a
somewhat temporary fix to that until #144813 lands.
2025-06-20 16:21:47 -07:00
Steven Perron
01d648a429
[HLSL][SPIRV] Reapply "[HLSL][SPIRV] Add vk::constant_id attribute." (#144902)
- **Reapply "[HLSL][SPIRV] Add vk::constant_id attribute." (#144812)**
- **Fix memory leak.**
2025-06-19 11:52:55 -04:00
Steven Perron
5f69d680e2
Revert "[HLSL][SPIRV] Add vk::constant_id attribute." (#144812)
Reverts llvm/llvm-project#143544
2025-06-18 19:30:43 -04:00
Nathan Gauër
3af4d4e810
[HLSL][SPIR-V] Fix LinkageAttribute emission for BuiltIn (#144701)
BuiltIn variables were missing the visibility attribute, which caused
the Linkage capability to be emitted by the backend.
2025-06-18 17:26:40 +02:00
Steven Perron
acde20b560
[HLSL][SPIRV] Add vk::constant_id attribute. (#143544)
The vk::constant_id attribute is used to indicate that a global const
variable
represents a specialization constant in SPIR-V. This PR adds this
attribute to clang.

The documentation for the attribute is
[here](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/SPIR-V.rst#specialization-constants).

The strategy is to to modify the initializer to get the value of a
specialize constant for a builtin defined in the SPIR-V backend.

Implements https://github.com/llvm/wg-hlsl/pull/287

Fixes https://github.com/llvm/llvm-project/issues/142448

---------

Co-authored-by: Nathan Gauër <github@keenuts.net>
2025-06-18 06:39:52 -04:00
Ashley Coleman
73f307a5ca
[HLSL] Use ExtVector for firstbit intrinsics (#142679)
Fixes https://github.com/llvm/llvm-project/issues/142430

firstbit intrinsics were using the wrong vector type which causes some
conversions to fail. This PR switches them to ExtVector which resolves
the issue
2025-06-17 14:32:11 -06:00
Steven Perron
a027eb4472
[HLSL] Use hidden visibility for external linkage. (#140292)
Implements

https://github.com/llvm/wg-hlsl/blob/main/proposals/0026-symbol-visibility.md.

The change is to stop using the `hlsl.export` attribute. Instead,
symbols with "program linkage" in HLSL will have export linkage with
default visibility, and symbols with "external linkage" in HLSL will
have export linkage with hidden visibility.
2025-06-16 16:44:55 -04:00
Nathan Gauër
50f534e21c
[HLSL][SPIR-V] Handle SV_Position builtin in PS (#141759)
This commit is using the same mechanism as vk::ext_builtin_input to
implement the SV_Position semantic input.
The HLSL signature is not yet ready for DXIL, hence this commit only
implements the SPIR-V side.

This is incomplete as it doesn't allow the semantic on hull/domain and
other shaders, but it's a first step to validate the overall
input/output
semantic logic.

Fixes https://github.com/llvm/llvm-project/issues/136969
2025-06-11 14:22:54 +02:00
Nathan Gauër
33fee56499
[HLSL][SPIR-V] Change SPV AS map for groupshared (#143519)
The previous mapping we setting the hlsl_groupshared AS to 0, which
translated to either Generic or Function.
Changing this to 3, which translated to Workgroup.

Related to #142804
2025-06-11 14:22:45 +02:00
Nathan Gauër
6582d7d348
[HLSL] Add WaveGetLaneCount() intrinsic to FE (#143127)
This commit adds code to lower WaveGetLaneCount() into the SPV or DXIL
intrinsic. The backends will then need to lower the intrinsic into
proper SPIR-V/DXIL.

Related to #99159
2025-06-10 14:25:09 +02:00
Finn Plummer
b3ed4288bd
[HLSL][RootSignature] Metadata generation of StaticSampler (#142642)
Implements metadata generation of a Root Signature from its in-memory
representation. It follows the same style as:
https://github.com/llvm/llvm-project/pull/139633.

This pr handles `StaticSamplers`. It also handles converting the else-if
chain into a `std::visit` to allow for future compiler warnings when
adding additional `RootElement` variants.

The metadata follows the format described
[here](https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#metadata-schema).

- Implement `BuildStaticSampler` into HLSLRootSignature.h
- Add sample testcases demonstrating functionality

Note: there is no validation of metadata nodes as the
`llvm::hlsl::rootsig::RootElement` that generates it will have already
been validated.

Resolves https://github.com/llvm/llvm-project/issues/126586
2025-06-05 10:18:49 -07:00
Nathan Gauër
20d70196c9
[HLSL][SPIR-V] Implement vk::ext_builtin_input attribute (#138530)
This variable attribute is used in HLSL to add Vulkan specific builtins
in a shader.
The attribute is documented here:

17727e88fd/proposals/0011-inline-spirv.md

Those variable, even if marked as `static` are externally initialized by
the pipeline/driver/GPU. This is handled by moving them to a specific
address space `hlsl_input`, also added by this commit.

The design for input variables in Clang can be found here:
355771361e/proposals/0019-spirv-input-builtin.md


Co-authored-by: Justin Bogner <mail@justinbogner.com>
2025-06-04 13:22:37 +02:00
Finn Plummer
9cdd33db16
[HLSL][RootSignature] Metadata generation of RootFlags, RootConstants, RootDescriptors (#142010)
Implements metadata generation of a Root Signature from its in-memory
representation. It follows the same style as:
https://github.com/llvm/llvm-project/pull/139633.

This pr handles RootFlags, RootConstants and RootDescriptors.

The metadata follows the format described
[here](https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#metadata-schema).

- Implement `BuildRoot[Flags|Constants|Descriptors]` into
`HLSLRootSignature.h`
- Add sample testcases demonstrating functionality

Note: there is no validation of metadata nodes as the
`llvm::hlsl::rootsig::RootElement` that generates it will have already
been validated.

First part of https://github.com/llvm/llvm-project/issues/126586.
2025-05-30 16:52:19 -07:00
Helena Kotas
2a22e79b17
[HLSL] Make implicit binding warning off by default (#141879)
Make implicit binding warning off by default and remove `-Wno-hlsl-implicit-binding` from tests.

Closes #135907
2025-05-29 12:27:00 -07:00
Steven Perron
5584020d8a
[HLSL][SPIRV] Implement the SPIR-V target type for cbuffers. (#140061)
This change implement the type used to represent cbuffer for SPIR-V.

Fixes https://github.com/llvm/llvm-project/issues/138274.
2025-05-28 07:51:03 -04:00
Helena Kotas
27675ccdd6
[DirectX] Add resource name argument to llvm.dx.handlefrom[implicit]binding intrinsics (#139991)
Adds resource name argument to `llvm.dx.handlefrombinding` and `llvm.dx.handlefromimplicitbinding` intrinsics.
SPIR-V currently does not seem to need the resource names so this change only affects DirectX binding intrinsics.

Part 2/4 of https://github.com/llvm/llvm-project/issues/105059
2025-05-27 22:57:01 -07:00
Helena Kotas
20f1e351c7
[HLSL] Add resource name argument to resource class constructors (#139985)
Adds resource name argument to resource class constructors and to builtin functions that initialize resource handles
`__builtin_hlsl_resource_handlefrombinding` and `__builtin_hlsl_resource_handlefromimplicitbinding`.

Part 1/4 of https://github.com/llvm/llvm-project/issues/105059
2025-05-27 10:41:04 -07:00
Cassandra Beckley
5a4571133a
[HLSL] Implement SpirvType and SpirvOpaqueType (#134034)
This implements the design proposed by [Representing SpirvType in
Clang's Type System](https://github.com/llvm/wg-hlsl/pull/181). It
creates `HLSLInlineSpirvType` as a new `Type` subclass, and
`__hlsl_spirv_type` as a new builtin type template to create such a
type.

This new type is lowered to the `spirv.Type` target extension type, as
described in [Target Extension Types for Inline SPIR-V and Decorated
Types](https://github.com/llvm/wg-hlsl/blob/main/proposals/0017-inline-spirv-and-decorated-types.md).
2025-05-27 11:40:54 -04:00
Sarah Spall
5999988af8
[HLSL] Move where ZExt happens in 'EmitStoreThroughExtVectorComponentLValue' to handle bug with hlsl boolean vector swizzles (#140627)
In 'EmitStoreThroughExtVectorComponentLValue', move the code which ZExts
in the case the Destination Scalar Type is larger than the Source Scalar
Type, to the top of the function, to ensure each condition is handled.

The previous code missed this case:
```
bool4 b = true.xxxx;
b.xyz = false.xxx;
```
Leading to a bad shuffle vector. 

Closes #140564
2025-05-20 10:27:34 -07:00
Justin Bogner
f695c8d529
[DirectX][SPIRV] Fix the lowering of dot4add (#140315)
There were some issues with these ops:
- The overload wasn't being specified (`dx.op.dot4AddPacked` vs
`dx.op.dot4AddPacked.i32`)
- The versioning wasn't correct (These ops were added in SM 6.4)
- The argument order was off - while the HLSL function has the
accumulator as the last argument, the DXIL op lists it first.

This fixes the DXIL.td definition and adjusts the LLVM DX and SPIRV
intrinsics to match the argument order in DXIL rather than the argument
order in HLSL.

Fixes #139018
2025-05-17 10:38:24 -07:00
Helena Kotas
f95f3030e5
[HLSL] Implicit resource binding for cbuffers (#139022)
Constant buffers defined with the `cbuffer` keyword do not have a
constructor. Instead, the call to initialize the resource handle based
on its binding is generated in codegen. This change adds initialization
of `cbuffer` handles that have implicit binding.

Closes  #139617
2025-05-15 19:49:29 -07:00
Finn Plummer
a4eb0db062
[HLSL][RootSignature] Add metadata generation for descriptor tables (#139633)
- prereq: Modify `RootSignatureAttr` to hold a reference to the owned
declaration
- Define and implement `MetadataBuilder` in `HLSLRootSignature`
- Integrate and invoke the builder in `CGHLSLRuntime.cpp` to generate
the Root Signature for any associated entry functions
- Add tests to demonstrate functionality in `RootSignature.hlsl`

Resolves https://github.com/llvm/llvm-project/issues/126584

Note: this is essentially just
https://github.com/llvm/llvm-project/pull/125131 rebased onto the new
approach of constructing a root signature decl, instead of holding the
elements in `AdditionalMembers`.
2025-05-15 14:54:00 -07:00
Steven Perron
2e6433b829
[clang] Emit convergence tokens for loop in global array init (#140120)
When initializing a global array, a loop is generated, but no
convergence is emitted for the loop. This fixes that up.
2025-05-15 17:44:34 -04:00
Helena Kotas
520773b47e
[HLSL] Add resource constructor with implicit binding for global resources (#138976)
Adds constructor for resources with implicit binding and applies it to
all resources without binding at the global scope.
Adds Clang builtin function
`__builtin_hlsl_resource_handlefromimplicitbinding` that gets translated
to `llvm.dx|spv.resource.handlefromimplicitbinding` intrinsic calls.
Specific bindings are assigned in DXILResourceImplicitBinding pass.

Design proposals:

https://github.com/llvm/wg-hlsl/blob/main/proposals/0024-implicit-resource-binding.md

https://github.com/llvm/wg-hlsl/blob/main/proposals/0025-resource-constructors.md

One change from the proposals is that the `orderId` parameter is added
onto the constructor. Originally it was supposed to be generated in
codegen when the `llvm.dx|spv.resource.handlefromimplicitbinding` call
is emitted, but that is not possible because the call is inside a
constructor, and the constructor body is generated once per resource
type and not resource instance. So the only way to inject instance-based
data like `orderId` into the
`llvm.dx|spv.resource.handlefromimplicitbinding` call is that it must
come in via the constructor argument.

Closes #136784
2025-05-14 18:41:17 -07:00
Helena Kotas
a3ba00a3db
[HLSL][NFC] Simplify resource constructors codegen tests (#139842)
Verification of the local allocas and load/store is not that useful and
it makes the test fragile.
2025-05-14 10:08:24 -07:00
Helena Kotas
df053d68ca
[HLSL][NFC] Test cleanup - remove function attributes (#139302)
The function attribute numbers are not stable. They are not part of the
test and can be removed.
2025-05-09 14:14:52 -07:00
Ashley Coleman
0beb2f56f6
[HLSL][NFC] Stricter Overload Tests (clamp,max,min,pow) (#138993)
Partial implementation of #138016 to unblock other ongoing work. NFC
2025-05-08 11:20:17 -06:00
Sarah Spall
02e0a954a0
[HLSL] Handle init list with OpaqueValueExprs in CGExprScalar (#138541)
When an HLSL Init list is producing a Scalar, handle OpaqueValueExprs in
the Init List with 'emitInitListOpaqueValues'
Copied from 'AggExprEmitter::VisitCXXParenListOrInitListExpr'
Closes #136408

---------

Co-authored-by: Chris B <beanz@abolishcrlf.org>
2025-05-05 13:04:41 -07:00
Kaitlin Peng
d11df05841
[HLSL] Implement the ldexp intrinsic (#138182)
Closes #99133.

Implemented `ldexp` entirely in `hlsl_intrinsics.h` and
`hlsl_intrinsic_helpers.h`, added coresponding tests in
`clang/test/CodeGenHLSL/builtins/ldexp.hlsl` and
`clang/test/SemaHLSL/BuiltIns/ldexp-errors.hlsl`.
2025-05-02 22:07:37 -07:00
Justin Bogner
ae6b4b23ea
[HLSL] Overloads for lerp with a scalar weight (#137877)
This adds overloads for the `lerp` function that accept a scalar for the
weight parameter by splatting it into the appropriate vector.

Fixes #137827
2025-04-30 12:30:06 -07:00
Justin Bogner
d851490c29
[HLSL] Make lerp overload tests stricter. NFC (#137898)
These tests had checks across multiple functions, because none of the
hlsl header implementation functions were inlined. Switch the run lines
to use -O1 instead of -disable-llvm-passes and rewrite the tests to
actually look at the whole function.

Note - this would be simpler with update_cc_test_checks, but the
differences between DX and SPIRV are difficult to account for with those
scripts.
2025-04-30 12:26:52 -07:00
Helena Kotas
f1750300aa
[HLSL] Resource initialization by constructors (#135120)
- Adds resource constructor that takes explicit binding for all resource
classes.
- Updates implementation of default resource constructor to initialize
resource handle to `poison`.
- Removes initialization of resource classes from Codegen.
- Initialization of `cbuffer` still needs to happen in `CGHLSLRuntime`
because it does not have a corresponding resource class type.
- Adds `ImplicitCastExpr` for builtin function calls. Sema adds these
automatically when a method of a template class is instantiated, but
some resource classes like `ByteAddressBuffer` are not templates so they
need to have this added explicitly.

Design proposal: llvm/wg-hlsl#197

Closes #134154
2025-04-29 18:42:22 -07:00
Justin Bogner
f9855917f6
[HLSL] Treat classes and structs as packed by default (#137391)
Fixes #121010.
2025-04-28 13:44:46 -07:00
Sarah Spall
561a21f18c
[HLSL] Put tests for compatibility overloads for 'clamp', 'isinf', 'min', and 'max' in own files (#137004)
Put tests for compatibility overloads for 'clamp', 'isinf', 'min', and
'max' in own files which guarantee hlsl version 202x.
Closes #133277
2025-04-28 11:02:11 -07:00
Kaitlin Peng
67cbfb9d8c
[HLSL] Implement the faceforward intrinsic (#135878)
Resolves #99114.

Tasks completed:
- Implement `faceforward` in
`hlsl_intrinsics.h`/`hlsl_intrinsic_helpers.h`
- Implement `faceforward` SPIR-V target builtin in
`clang/include/clang/Basic/BuiltinsSPIRV.td`
- Add a SPIR-V fast path in `hlsl_intrinsic_helpers.h`
- Add sema checks for `faceforward` to `CheckSPIRVBuiltinFunctionCall`
in `clang/lib/Sema/SemaSPIRV.cpp`
- Add codegen for SPIR-V `faceforward` builtin to `EmitSPIRVBuiltinExpr`
in `SPIR.cpp`
- Add HLSL codegen tests to
`clang/test/CodeGenHLSL/builtins/faceforward.hlsl`
- Add SPIRV builtin codegen tests to
`clang/test/CodeGenSPIRV/Builtins/faceforward.c`
- Add sema tests to
`clang/test/SemaHLSL/BuiltIns/faceforward-errors.hlsl`
- Add spirv sema tests to
`clang/test/SemaSPIRV/BuiltIns/faceforward-errors.c`
- Create the `int_spv_faceforward` intrinsic in `IntrinsicsSPIRV.td`
- In `SPIRVInstructionSelector.cpp` create the `faceforward` lowering
and map it to `int_spv_faceforward` in
`SPIRVInstructionSelector::selectIntrinsic`
- Create SPIR-V backend test case in
`llvm/test/CodeGen/SPIRV/hlsl-intrinsics/faceforward.ll`

Incomplete tasks:
- Create SPIR-V backend test case in
`llvm/test/CodeGen/SPIRV/opencl/faceforward.ll`
- Not applicable because the OpenCL SPIR-V extended instruction set does
not include a `faceforward` function

Follow-up tasks:
- Implement pattern matching for `faceforward` in `SPIRVCombine.td` and
`SPIRVPreLegalizerCombiner.cpp`
- In `faceforward.ll`, change `--target-env spv1.4` to `vulkan1.3` and
update the test accordingly once
[#136344](https://github.com/llvm/llvm-project/issues/136344) has been
resolved
2025-04-24 14:45:05 -07:00
Steven Perron
c073c22865
[HLSL] Use hlsl_device address space for getpointer. (#127675)
We add the hlsl_device address space to represent the device memory
space as defined in section 1.7.1.3 of the [HLSL
spec](https://microsoft.github.io/hlsl-specs/specs/hlsl.pdf).

Fixes https://github.com/llvm/llvm-project/issues/127075
2025-04-22 13:26:32 -04:00