Skip to content

Commit 65c6e1a

Browse files
committed
address chris
1 parent 0ed4809 commit 65c6e1a

File tree

2 files changed

+19
-108
lines changed

2 files changed

+19
-108
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2200,17 +2200,20 @@ static void BuildFlattenedTypeList(QualType BaseTy,
22002200
}
22012201

22022202
bool SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) {
2203-
if (QT.isNull())
2203+
// null and array types are not allowed.
2204+
if (QT.isNull() || QT->isArrayType())
22042205
return false;
22052206

2206-
// check if the outer type was an array type
2207-
if (QT->isArrayType())
2207+
// UDT types are not allowed
2208+
clang::QualType CanonicalType = QT.getCanonicalType();
2209+
if (CanonicalType->getAs<clang::RecordType>()) {
22082210
return false;
2211+
}
22092212

22102213
llvm::SmallVector<QualType, 4> QTTypes;
22112214
BuildFlattenedTypeList(QT, QTTypes);
22122215

2213-
// empty structs are not typed resource element compatible
2216+
// empty element type is not typed resource element compatible
22142217
if (QTTypes.size() == 0)
22152218
return false;
22162219

Lines changed: 12 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,120 +1,28 @@
11
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -fnative-half-type -verify %s
22
// expected-no-diagnostics
33

4-
struct oneInt {
5-
int i;
6-
};
7-
8-
struct twoInt {
9-
int aa;
10-
int ab;
11-
};
12-
13-
struct threeInts {
14-
oneInt o;
15-
twoInt t;
16-
};
17-
18-
struct oneFloat {
19-
float f;
20-
};
21-
struct depthDiff {
22-
int i;
23-
oneInt o;
24-
oneFloat f;
25-
};
26-
27-
struct notHomogenous{
28-
int i;
29-
float f;
30-
};
31-
32-
struct EightElements {
33-
twoInt x[2];
34-
twoInt y[2];
35-
};
36-
37-
struct EightHalves {
38-
half x[8];
39-
};
40-
41-
struct intVec {
42-
int2 i;
43-
};
44-
45-
struct oneIntWithVec {
46-
int i;
47-
oneInt i2;
48-
int2 i3;
49-
};
50-
51-
struct weirdStruct {
52-
int i;
53-
intVec iv;
54-
};
554

565
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(int), "");
576
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(float), "");
587
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(float4), "");
598
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(double2), "");
60-
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(oneInt), "");
61-
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(oneFloat), "");
62-
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(twoInt), "");
63-
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(threeInts), "");
64-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(notHomogenous), "");
65-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(depthDiff), "");
66-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EightElements), "");
67-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EightHalves), "");
68-
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(oneIntWithVec), "");
69-
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(weirdStruct), "");
70-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(RWBuffer<int>), "");
719

10+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(RWBuffer<int>), "");
7211

73-
// arrays not allowed
74-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(half[4]), "");
75-
76-
template<typename T> struct TemplatedBuffer {
77-
T a;
78-
__hlsl_resource_t h;
79-
};
80-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(TemplatedBuffer<int>), "");
81-
82-
struct MyStruct1 : TemplatedBuffer<float> {
83-
float x;
84-
};
85-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(MyStruct1), "");
86-
87-
struct MyStruct2 {
88-
const TemplatedBuffer<float> TB[10];
89-
};
90-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(MyStruct2), "");
91-
92-
template<typename T> struct SimpleTemplate {
93-
T a;
94-
};
95-
96-
// though the element type is incomplete, the type trait should still technically return true
97-
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(SimpleTemplate<__hlsl_resource_t>), "");
98-
99-
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(SimpleTemplate<float>), "");
100-
101-
102-
typedef int myInt;
103-
104-
struct TypeDefTest {
12+
struct s {
10513
int x;
106-
myInt y;
10714
};
10815

109-
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest), "");
16+
// structs not allowed
17+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(s), "");
11018

111-
struct EmptyStruct {};
112-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyStruct), "");
19+
// arrays not allowed
20+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(half[4]), "");
11321

114-
struct EmptyDerived : EmptyStruct {};
115-
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyDerived), "");
22+
typedef vector<int, 8> int8;
23+
// too many elements
24+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(int8), "");
25+
26+
// size exceeds 16 bytes, and exceeds element count limit after splitting 64 bit types into 32 bit types
27+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(double3), "");
11628

117-
struct EmptyBase : EmptyStruct {
118-
int4 V;
119-
};
120-
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(EmptyBase), "");

0 commit comments

Comments
 (0)