Skip to content

Commit 2bed922

Browse files
committed
[HLSL][SPIRV] Handle uint type for spec constant
The testing only tried `unsigned int` and not `uint`. We want to correctly handle these surgared types as specialization constants.
1 parent fb20992 commit 2bed922

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static ResourceClass getResourceClass(RegisterType RT) {
120120
llvm_unreachable("unexpected RegisterType value");
121121
}
122122

123-
static Builtin::ID getSpecConstBuiltinId(QualType Type) {
123+
static Builtin::ID getSpecConstBuiltinId(const Type *Type) {
124124
const auto *BT = dyn_cast<BuiltinType>(Type);
125125
if (!BT) {
126126
if (!Type->isEnumeralType())
@@ -654,7 +654,8 @@ SemaHLSL::mergeVkConstantIdAttr(Decl *D, const AttributeCommonInfo &AL,
654654

655655
auto *VD = cast<VarDecl>(D);
656656

657-
if (getSpecConstBuiltinId(VD->getType()) == Builtin::NotBuiltin) {
657+
if (getSpecConstBuiltinId(VD->getType()->getUnqualifiedDesugaredType()) ==
658+
Builtin::NotBuiltin) {
658659
Diag(VD->getLocation(), diag::err_specialization_const);
659660
return nullptr;
660661
}
@@ -3920,7 +3921,8 @@ bool SemaHLSL::handleInitialization(VarDecl *VDecl, Expr *&Init) {
39203921
return false;
39213922
}
39223923

3923-
Builtin::ID BID = getSpecConstBuiltinId(VDecl->getType());
3924+
Builtin::ID BID =
3925+
getSpecConstBuiltinId(VDecl->getType()->getUnqualifiedDesugaredType());
39243926

39253927
// Argument 1: The ID from the attribute
39263928
int ConstantID = ConstIdAttr->getId();

clang/test/AST/HLSL/vk.spec-constant.usage.hlsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ const unsigned short ushort_const = 10;
6464
[[vk::constant_id(6)]]
6565
const unsigned int uint_const = 12;
6666

67+
// CHECK: VarDecl {{.*}} uint_const_2 'const hlsl_private uint':'const hlsl_private unsigned int' static cinit
68+
// CHECK-NEXT: CallExpr {{.*}} 'unsigned int'
69+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int (*)(unsigned int, unsigned int) noexcept' <FunctionToPointerDecay>
70+
// 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'
71+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <IntegralCast>
72+
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 6
73+
// CHECK-NEXT: ImplicitCastExpr {{.*}} 'unsigned int' <IntegralCast>
74+
// CHECK-NEXT: IntegerLiteral {{.*}} 'int' 12
75+
[[vk::constant_id(6)]]
76+
const uint uint_const_2 = 12;
77+
6778

6879
// CHECK: VarDecl {{.*}} ulong_const 'const hlsl_private unsigned long long' static cinit
6980
// CHECK-NEXT: CallExpr {{.*}} 'unsigned long long'

0 commit comments

Comments
 (0)