-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[HLSL] add IsTypedResourceElementCompatible type trait #114864
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
Changes from 7 commits
a311992
7f24d4c
5403988
76243df
300f8e3
65b3141
010785c
6e218c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -2163,6 +2163,50 @@ static void BuildFlattenedTypeList(QualType BaseTy, | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| bool SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) { | ||||||
| if (QT.isNull()) | ||||||
| return false; | ||||||
|
|
||||||
| // check if the outer type was an array type | ||||||
| if (QT->isArrayType()) | ||||||
| return false; | ||||||
|
|
||||||
| llvm::SmallVector<QualType, 4> QTTypes; | ||||||
| BuildFlattenedTypeList(QT, QTTypes); | ||||||
|
|
||||||
| assert(QTTypes.size() > 0 && | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this assert fire if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When QT is an empty struct (like
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's an incomplete type, not an empty struct. What about something like: struct EmptyStruct {};
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyStruct), "");
struct EmptyDerived : EmptyStruct {};
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EmptyDerived), "");
struct EmptyBase : EmptyStruct {
int4 V;
};
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(EmptyBase), "");We frequently find bugs in DXC with cases of empty structs, empty base classes, etc.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #115045 |
||||||
| "expected at least one constituent type from non-null type"); | ||||||
| QualType FirstQT = QTTypes[0]; | ||||||
|
||||||
| QualType FirstQT = QTTypes[0]; | |
| QualType FirstQT = SemaRef.Context.getCanonicalType(QTTypes[0]); |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be a call to hasSameUnqualifiedType not a direct comparison.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than doing this in the loop for each type, you could do this after the loop on FirstQT, since all types need to be the same.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -fnative-half-type -verify %s | ||
| // expected-no-diagnostics | ||
|
|
||
| struct oneInt { | ||
| int i; | ||
| }; | ||
|
|
||
| struct twoInt { | ||
| int aa; | ||
| int ab; | ||
| }; | ||
|
|
||
| struct threeInts { | ||
| oneInt o; | ||
| twoInt t; | ||
| }; | ||
|
|
||
| struct oneFloat { | ||
| float f; | ||
| }; | ||
| struct depthDiff { | ||
| int i; | ||
| oneInt o; | ||
| oneFloat f; | ||
| }; | ||
|
|
||
| struct notHomogenous{ | ||
| int i; | ||
| float f; | ||
| }; | ||
|
|
||
| struct EightElements { | ||
| twoInt x[2]; | ||
| twoInt y[2]; | ||
| }; | ||
|
|
||
| struct EightHalves { | ||
| half x[8]; | ||
| }; | ||
|
|
||
| struct intVec { | ||
| int2 i; | ||
| }; | ||
|
|
||
| struct oneIntWithVec { | ||
| int i; | ||
| oneInt i2; | ||
| int2 i3; | ||
| }; | ||
|
|
||
| struct weirdStruct { | ||
| int i; | ||
| intVec iv; | ||
| }; | ||
|
|
||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(int), ""); | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(float), ""); | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(float4), ""); | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(double2), ""); | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(oneInt), ""); | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(oneFloat), ""); | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(twoInt), ""); | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(threeInts), ""); | ||
| _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(notHomogenous), ""); | ||
| _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(depthDiff), ""); | ||
| _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EightElements), ""); | ||
| _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EightHalves), ""); | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(oneIntWithVec), ""); | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(weirdStruct), ""); | ||
| _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(RWBuffer<int>), ""); | ||
|
|
||
|
|
||
| // arrays not allowed | ||
| _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(half[4]), ""); | ||
|
|
||
| template<typename T> struct TemplatedBuffer { | ||
| T a; | ||
| __hlsl_resource_t h; | ||
| }; | ||
| _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(TemplatedBuffer<int>), ""); | ||
|
|
||
| struct MyStruct1 : TemplatedBuffer<float> { | ||
| float x; | ||
| }; | ||
| _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(MyStruct1), ""); | ||
|
|
||
| struct MyStruct2 { | ||
| const TemplatedBuffer<float> TB[10]; | ||
| }; | ||
| _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(MyStruct2), ""); | ||
|
|
||
| template<typename T> struct SimpleTemplate { | ||
| T a; | ||
| }; | ||
|
|
||
| // though the element type is incomplete, the type trait should still technically return true | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(SimpleTemplate<__hlsl_resource_t>), ""); | ||
|
|
||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(SimpleTemplate<float>), ""); | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -fnative-half-type -verify %s | ||
|
|
||
| // types must be complete | ||
| _Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(__hlsl_resource_t), ""); | ||
|
|
||
| // expected-note@+1{{forward declaration of 'notComplete'}} | ||
| struct notComplete; | ||
| // expected-error@+1{{incomplete type 'notComplete' where a complete type is required}} | ||
| _Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(notComplete), ""); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.