-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[HLSL][SPIRV] Handle uint
type for spec constant
#145577
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
Conversation
@llvm/pr-subscribers-hlsl Author: Steven Perron (s-perron) ChangesThe testing only tried Full diff: https://github.com/llvm/llvm-project/pull/145577.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index d003967a522a1..e36db2ee10c20 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -120,7 +120,7 @@ static ResourceClass getResourceClass(RegisterType RT) {
llvm_unreachable("unexpected RegisterType value");
}
-static Builtin::ID getSpecConstBuiltinId(QualType Type) {
+static Builtin::ID getSpecConstBuiltinId(const Type *Type) {
const auto *BT = dyn_cast<BuiltinType>(Type);
if (!BT) {
if (!Type->isEnumeralType())
@@ -654,7 +654,8 @@ SemaHLSL::mergeVkConstantIdAttr(Decl *D, const AttributeCommonInfo &AL,
auto *VD = cast<VarDecl>(D);
- if (getSpecConstBuiltinId(VD->getType()) == Builtin::NotBuiltin) {
+ if (getSpecConstBuiltinId(VD->getType()->getUnqualifiedDesugaredType()) ==
+ Builtin::NotBuiltin) {
Diag(VD->getLocation(), diag::err_specialization_const);
return nullptr;
}
@@ -3920,7 +3921,8 @@ bool SemaHLSL::handleInitialization(VarDecl *VDecl, Expr *&Init) {
return false;
}
- Builtin::ID BID = getSpecConstBuiltinId(VDecl->getType());
+ Builtin::ID BID =
+ getSpecConstBuiltinId(VDecl->getType()->getUnqualifiedDesugaredType());
// Argument 1: The ID from the attribute
int ConstantID = ConstIdAttr->getId();
diff --git a/clang/test/AST/HLSL/vk.spec-constant.usage.hlsl b/clang/test/AST/HLSL/vk.spec-constant.usage.hlsl
index c0955c1ea7b43..733c4e2ee5a36 100644
--- a/clang/test/AST/HLSL/vk.spec-constant.usage.hlsl
+++ b/clang/test/AST/HLSL/vk.spec-constant.usage.hlsl
@@ -64,6 +64,17 @@ const unsigned short ushort_const = 10;
[[vk::constant_id(6)]]
const unsigned int uint_const = 12;
+// CHECK: VarDecl {{.*}} uint_const_2 'const hlsl_private uint':'const hlsl_private unsigned int' static cinit
+// CHECK-NEXT: CallExpr {{.*}} 'unsigned int'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int (*)(unsigned int, unsigned int) noexcept' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int (unsigned int, unsigned int) noexcept' lvalue Function {{.*}} '__builtin_get_spirv_spec_constant_uint' 'unsigned int (unsigned int, unsigned int) noexcept'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <IntegralCast>
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <IntegralCast>
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 12
+[[vk::constant_id(6)]]
+const uint uint_const_2 = 12;
+
// CHECK: VarDecl {{.*}} ulong_const 'const hlsl_private unsigned long long' static cinit
// CHECK-NEXT: CallExpr {{.*}} 'unsigned long long'
|
@llvm/pr-subscribers-clang Author: Steven Perron (s-perron) ChangesThe testing only tried Full diff: https://github.com/llvm/llvm-project/pull/145577.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index d003967a522a1..e36db2ee10c20 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -120,7 +120,7 @@ static ResourceClass getResourceClass(RegisterType RT) {
llvm_unreachable("unexpected RegisterType value");
}
-static Builtin::ID getSpecConstBuiltinId(QualType Type) {
+static Builtin::ID getSpecConstBuiltinId(const Type *Type) {
const auto *BT = dyn_cast<BuiltinType>(Type);
if (!BT) {
if (!Type->isEnumeralType())
@@ -654,7 +654,8 @@ SemaHLSL::mergeVkConstantIdAttr(Decl *D, const AttributeCommonInfo &AL,
auto *VD = cast<VarDecl>(D);
- if (getSpecConstBuiltinId(VD->getType()) == Builtin::NotBuiltin) {
+ if (getSpecConstBuiltinId(VD->getType()->getUnqualifiedDesugaredType()) ==
+ Builtin::NotBuiltin) {
Diag(VD->getLocation(), diag::err_specialization_const);
return nullptr;
}
@@ -3920,7 +3921,8 @@ bool SemaHLSL::handleInitialization(VarDecl *VDecl, Expr *&Init) {
return false;
}
- Builtin::ID BID = getSpecConstBuiltinId(VDecl->getType());
+ Builtin::ID BID =
+ getSpecConstBuiltinId(VDecl->getType()->getUnqualifiedDesugaredType());
// Argument 1: The ID from the attribute
int ConstantID = ConstIdAttr->getId();
diff --git a/clang/test/AST/HLSL/vk.spec-constant.usage.hlsl b/clang/test/AST/HLSL/vk.spec-constant.usage.hlsl
index c0955c1ea7b43..733c4e2ee5a36 100644
--- a/clang/test/AST/HLSL/vk.spec-constant.usage.hlsl
+++ b/clang/test/AST/HLSL/vk.spec-constant.usage.hlsl
@@ -64,6 +64,17 @@ const unsigned short ushort_const = 10;
[[vk::constant_id(6)]]
const unsigned int uint_const = 12;
+// CHECK: VarDecl {{.*}} uint_const_2 'const hlsl_private uint':'const hlsl_private unsigned int' static cinit
+// CHECK-NEXT: CallExpr {{.*}} 'unsigned int'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int (*)(unsigned int, unsigned int) noexcept' <FunctionToPointerDecay>
+// CHECK-NEXT: DeclRefExpr {{.*}} 'unsigned int (unsigned int, unsigned int) noexcept' lvalue Function {{.*}} '__builtin_get_spirv_spec_constant_uint' 'unsigned int (unsigned int, unsigned int) noexcept'
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <IntegralCast>
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
+// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <IntegralCast>
+// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 12
+[[vk::constant_id(6)]]
+const uint uint_const_2 = 12;
+
// CHECK: VarDecl {{.*}} ulong_const 'const hlsl_private unsigned long long' static cinit
// CHECK-NEXT: CallExpr {{.*}} 'unsigned long long'
|
The testing only tried `unsigned int` and not `uint`. We want to correctly handle these surgared types as specialization constants.
2bed922
to
44cb96a
Compare
The testing only tried `unsigned int` and not `uint`. We want to correctly handle these surgared types as specialization constants.
The testing only tried `unsigned int` and not `uint`. We want to correctly handle these surgared types as specialization constants.
The testing only tried
unsigned int
and notuint
. We want tocorrectly handle these surgared types as specialization constants.