https://github.com/Alexander-Johnston updated
https://github.com/llvm/llvm-project/pull/168887
>From 9eeb0f70545165f05235bd117f1867c5fc43132b Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Thu, 20 Nov 2025 14:58:13 +
Subject: [PATCH 1/2] [HLSL] Implement ddx and ddy HLSL intrinsics
https://github.com/Alexander-Johnston created
https://github.com/llvm/llvm-project/pull/168887
Implements the ddx and ddy HLSL intrinsics. The DXIL intrinsics call the
ddx_coarse and ddy_builtins as they lower to the coarse variants.
The SPIRV intrinsics lower to their own opcodes OpDPdx and Op
https://github.com/Alexander-Johnston updated
https://github.com/llvm/llvm-project/pull/168874
>From 7d4660218d94def086a798852fc856851261bf02 Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Wed, 19 Nov 2025 00:21:25 +
Subject: [PATCH] [HLSL] Implement ddx/ddy_fine intrinsics
Implem
https://github.com/Alexander-Johnston created
https://github.com/llvm/llvm-project/pull/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.co
Alexander-Johnston wrote:
I don't have permissions to merge this. If you're happy with the nit fixes and
test changes can you merge it @farzonl ? Thanks!
https://github.com/llvm/llvm-project/pull/161378
___
cfe-commits mailing list
[email protected]
Alexander-Johnston wrote:
I believe that's the nits fixed. I updated the `ddx_coarse-errors.ll` and
ddy_coarse-errors.ll` tests to include a run with a compute triple and check
for the appropriate error.
https://github.com/llvm/llvm-project/pull/161378
_
https://github.com/Alexander-Johnston edited
https://github.com/llvm/llvm-project/pull/161378
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
https://github.com/Alexander-Johnston updated
https://github.com/llvm/llvm-project/pull/161378
>From 5af43f878799ca037a963ba2bd331a7b641d295c Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Mon, 29 Sep 2025 19:54:02 +0100
Subject: [PATCH 1/3] [HLSL] Implement the `fwidth` intrinsic
Clo
@@ -2615,6 +2618,15 @@ bool SPIRVInstructionSelector::selectDiscard(Register
ResVReg,
.constrainAllUses(TII, TRI, RBI);
}
+bool SPIRVInstructionSelector::selectFwidth(Register ResVReg,
+const SPIRVType *ResType,
+
@@ -2615,6 +2618,15 @@ bool SPIRVInstructionSelector::selectDiscard(Register
ResVReg,
.constrainAllUses(TII, TRI, RBI);
}
+bool SPIRVInstructionSelector::selectFwidth(Register ResVReg,
+const SPIRVType *ResType,
+
@@ -605,5 +605,30 @@ smoothstep(__detail::HLSL_FIXED_VECTOR Min,
return __detail::smoothstep_vec_impl(Min, Max, X);
}
+//===--===//
+// fwidth builtin
+//===--
@@ -21,3 +21,4 @@ def subgroup_local_invocation_id : SPIRVBuiltin<"uint32_t()",
[NoThrow, Const]>;
def distance : SPIRVBuiltin<"void(...)", [NoThrow, Const]>;
def length : SPIRVBuiltin<"void(...)", [NoThrow, Const]>;
def smoothstep : SPIRVBuiltin<"void(...)", [NoThrow, Const,
@@ -148,6 +148,31 @@ template constexpr T ldexp_impl(T X, T Exp) {
return exp2(Exp) * X;
}
+template constexpr T fwidth_impl(T input) {
+#if (__has_builtin(__builtin_spirv_fwidth))
+ return __builtin_spirv_fwidth(input);
+#else
+ T derivCoarseX = __builtin_hlsl_elementwi
@@ -148,6 +148,31 @@ template constexpr T ldexp_impl(T X, T Exp) {
return exp2(Exp) * X;
}
+template constexpr T fwidth_impl(T input) {
+#if (__has_builtin(__builtin_spirv_fwidth))
+ return __builtin_spirv_fwidth(input);
+#else
+ T derivCoarseX = __builtin_hlsl_elementwi
Alexander-Johnston wrote:
I don't have permissions to merge this. Can one of you @Keenuts @farzonl ?
Thanks!
https://github.com/llvm/llvm-project/pull/164831
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailma
https://github.com/Alexander-Johnston updated
https://github.com/llvm/llvm-project/pull/164831
>From 658a18417d52b6ba5739dabfd9acac9808cac1c1 Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Thu, 23 Oct 2025 15:12:23 +0100
Subject: [PATCH 01/12] [HLSL] Implement ddx/ddy_coarse intrinsics
@@ -3099,6 +3101,66 @@ bool SPIRVInstructionSelector::wrapIntoSpecConstantOp(
return Result;
}
+bool SPIRVInstructionSelector::selectDpdCoarse(Register ResVReg,
+ const SPIRVType *ResType,
+
Alexander-Johnston wrote:
I think that should be all the nits fixed now. I appreciate the time you've
spent on this!
https://github.com/llvm/llvm-project/pull/164831
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bi
@@ -0,0 +1,47 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-vulkan %s -o - |
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan %s -o -
-filetype=obj | spirv-val %}
+
+; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
+; CHECK-DAG: %[[#fl
https://github.com/Alexander-Johnston updated
https://github.com/llvm/llvm-project/pull/164831
>From 120e88999b8f11971fc7848121eebef1b3c15fee Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Thu, 23 Oct 2025 15:12:23 +0100
Subject: [PATCH 1/7] [HLSL] Implement ddx/ddy_coarse intrinsics
Alexander-Johnston wrote:
@farzonl I've updated this and should have fixed the test failures. I'd place
emphasis on the SPIRV instruction selection changes I've made. SPIRV only
allows float as an input to the `OpDPd*` while HLSL takes half or float, so
I've wrapped it in `OpFConvert` to switc
https://github.com/Alexander-Johnston updated
https://github.com/llvm/llvm-project/pull/164831
>From 120e88999b8f11971fc7848121eebef1b3c15fee Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Thu, 23 Oct 2025 15:12:23 +0100
Subject: [PATCH 1/6] [HLSL] Implement ddx/ddy_coarse intrinsics
@@ -0,0 +1,43 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-vulkan %s -o - |
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan %s -o -
-filetype=obj | spirv-val %}
Alexander-Johnston wrote:
I only see the --target-e
@@ -0,0 +1,43 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-vulkan %s -o - |
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan %s -o -
-filetype=obj | spirv-val %}
+
+; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
+; CHECK-DAG: %[[#fl
@@ -0,0 +1,43 @@
+; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-unknown-vulkan %s -o - |
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan %s -o -
-filetype=obj | spirv-val %}
+
+; CHECK-DAG: %[[#float_32:]] = OpTypeFloat 32
+; CHECK-DAG: %[[#fl
@@ -0,0 +1,41 @@
+; RUN: opt -S -scalarizer -dxil-op-lower
-mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
+
+; Make sure dxil operation function calls for fwidth are generated for
half/float and matching vectors
Alexander-Johnston wrote:
Fixed
http
@@ -0,0 +1,15 @@
+; RUN: not opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s
2>&1 | FileCheck %s
+
+; DXIL operation ddy.coarse does not support double overload type
+; CHECK: in function ddy.coarse
+; CHECK-SAME: Cannot create DerivCoarseY operation: Invalid ove
@@ -0,0 +1,41 @@
+; RUN: opt -S -scalarizer -dxil-op-lower
-mtriple=dxil-pc-shadermodel6.3-library %s | FileCheck %s
+
+; Make sure dxil operation function calls for fwidth are generated for
half/float and matching vectors
Alexander-Johnston wrote:
Fixed
http
@@ -0,0 +1,15 @@
+; RUN: not opt -S -dxil-op-lower -mtriple=dxil-pc-shadermodel6.3-library %s
2>&1 | FileCheck %s
+
+; DXIL operation ddx.coarse does not support double overload type
+; CHECK: in function ddx.coarse
+; CHECK-SAME: Cannot create DerivCoarseX operation: Invalid ove
@@ -0,0 +1,29 @@
+/// RUN: %clang_cc1 %s -triple spirv-pc-vulkan-compute -verify
+
Alexander-Johnston wrote:
Removed
https://github.com/llvm/llvm-project/pull/164831
___
cfe-commits mailing list
[email protected].
@@ -0,0 +1,29 @@
+/// RUN: %clang_cc1 %s -triple spirv-pc-vulkan-compute -verify
+
+typedef _Float16 half;
Alexander-Johnston wrote:
Removed
https://github.com/llvm/llvm-project/pull/164831
___
cfe-commits mailing list
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library %s
-fnative-half-type -verify
+
+float no_arg() {
+ return __builtin_hlsl_elementwise_ddy_coarse();
+ // expected-error@-1 {{too few arguments to function call, expected 1, have
0}}
+}
+
+float too_man
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library %s
-fnative-half-type -verify
+
+typedef float float2 __attribute__((ext_vector_type(2)));
+
+float no_arg() {
+ return __builtin_hlsl_elementwise_ddx_coarse();
+ // expected-error@-1 {{too few argument
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
dxil-pc-shadermodel6.3-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-half-type -o - | \
+// RUN: FileCheck %s --check-prefixes=CHECK
Alexander-Johnston wrote:
Done
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
dxil-pc-shadermodel6.3-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-half-type -o - | \
+// RUN: FileCheck %s --check-prefixes=CHECK
+
+using hlsl::ddx_coarse;
+
+// CHECK: define l
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
dxil-pc-shadermodel6.3-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-half-type -o - | \
+// RUN: FileCheck %s --check-prefixes=CHECK
+
+using hlsl::ddx_coarse;
+
+// CHECK: define l
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
dxil-pc-shadermodel6.3-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-half-type -o - | \
Alexander-Johnston wrote:
Added a second run line with spirv target to each
@@ -0,0 +1,61 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
dxil-pc-shadermodel6.3-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-half-type -o - | \
+// RUN: FileCheck %s --check-prefixes=CHECK
+
+using hlsl::ddx_coarse;
Alex
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
dxil-pc-shadermodel6.3-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-half-type -o - | \
+// RUN: FileCheck %s --check-prefixes=CHECK
+
+// CHECK: define hidden noundef nofpclass(nan
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple
dxil-pc-shadermodel6.3-library %s \
+// RUN: -emit-llvm -disable-llvm-passes -fnative-half-type -o - | \
+// RUN: FileCheck %s --check-prefixes=CHECK
+
+// CHECK: define hidden noundef nofpclass(nan
@@ -360,6 +373,19 @@ bool SemaSPIRV::CheckSPIRVBuiltinFunctionCall(const
TargetInfo &TI,
case SPIRV::BI__builtin_spirv_generic_cast_to_ptr_explicit: {
return checkGenericCastToPtr(SemaRef, TheCall);
}
+ case SPIRV::BI__builtin_spirv_ddx_coarse:
+ case SPIRV::BI__buil
@@ -46,6 +46,19 @@ static bool CheckAllArgsHaveSameType(Sema *S, CallExpr
*TheCall) {
return false;
}
+static bool CheckAllArgTypesAreCorrect(
+Sema *S, CallExpr *TheCall,
+llvm::function_ref
+Check) {
+ for (unsigned I = 0; I < TheCall->getNumArgs(); ++I)
@@ -605,5 +605,81 @@ smoothstep(__detail::HLSL_FIXED_VECTOR Min,
return __detail::smoothstep_vec_impl(Min, Max, X);
}
+//===--===//
+// ddx_coarse builtin
+//===--
@@ -12,3 +12,5 @@ include "clang/Basic/BuiltinsSPIRVBase.td"
def reflect : SPIRVBuiltin<"void(...)", [NoThrow, Const]>;
def faceforward : SPIRVBuiltin<"void(...)", [NoThrow, Const,
CustomTypeChecking]>;
def refract : SPIRVBuiltin<"void(...)", [NoThrow, Const, CustomTypeCheckin
@@ -151,6 +151,18 @@ Value *CodeGenFunction::EmitSPIRVBuiltinExpr(unsigned
BuiltinID,
Intrinsic::spv_global_offset,
ArrayRef{EmitScalarExpr(E->getArg(0))}, nullptr,
"spv.global.offset");
+ case SPIRV::BI__builtin_spirv_ddx_coarse:
+return Builder.C
@@ -148,6 +148,22 @@ template constexpr T ldexp_impl(T X, T Exp) {
return exp2(Exp) * X;
}
+template constexpr T ddx_coarse_impl(T value) {
+#if (__has_builtin(__builtin_spirv_ddx_coarse))
+ return __builtin_spirv_ddx_coarse(value);
+#else
+ return __builtin_hlsl_element
https://github.com/Alexander-Johnston updated
https://github.com/llvm/llvm-project/pull/164831
>From 120e88999b8f11971fc7848121eebef1b3c15fee Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Thu, 23 Oct 2025 15:12:23 +0100
Subject: [PATCH 1/4] [HLSL] Implement ddx/ddy_coarse intrinsics
@@ -162,6 +162,8 @@ def int_dx_splitdouble :
DefaultAttrsIntrinsic<[llvm_anyint_ty, LLVMMatchType<0>
[LLVMScalarOrSameVectorWidth<0, llvm_double_ty>], [IntrNoMem]>;
def int_dx_radians : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
[LLVMMatchType<0>], [IntrNoMem]>;
def int_dx
https://github.com/Alexander-Johnston created
https://github.com/llvm/llvm-project/pull/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
@@ -162,6 +162,8 @@ def int_dx_splitdouble :
DefaultAttrsIntrinsic<[llvm_anyint_ty, LLVMMatchType<0>
[LLVMScalarOrSameVectorWidth<0, llvm_double_ty>], [IntrNoMem]>;
def int_dx_radians : DefaultAttrsIntrinsic<[llvm_anyfloat_ty],
[LLVMMatchType<0>], [IntrNoMem]>;
def int_dx
https://github.com/Alexander-Johnston updated
https://github.com/llvm/llvm-project/pull/161378
>From a1419718a44fa4c65324477443f218e5382ed384 Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Mon, 29 Sep 2025 19:54:02 +0100
Subject: [PATCH] [HLSL] Implement the `fwidth` intrinsic
Closes
https://github.com/Alexander-Johnston updated
https://github.com/llvm/llvm-project/pull/161378
>From 445fcb1bb4a074c3e78c019e36d7ecfbb1da0430 Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Mon, 29 Sep 2025 19:54:02 +0100
Subject: [PATCH] [HLSL] Implement the `fwidth` intrinsic
Closes
https://github.com/Alexander-Johnston created
https://github.com/llvm/llvm-project/pull/161378
Closes #99120
>From 69ecd6eee47cb93349b3b965fb1b54680408b619 Mon Sep 17 00:00:00 2001
From: Alexander Johnston
Date: Mon, 29 Sep 2025 19:54:02 +0100
Subject: [PATCH] [HLSL] Implement the `fwidth` int
53 matches
Mail list logo