-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Merged
bob80905
merged 8 commits into
llvm:main
from
bob80905:add_builtin_line_vector_compatible
Nov 5, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a311992
add type trait
bob80905 7f24d4c
fix bug
bob80905 5403988
address Finn
bob80905 76243df
remove unused bits / unused functions
bob80905 300f8e3
remove unused function
bob80905 65b3141
remove whitespace change
bob80905 010785c
remove comparison of diff types
bob80905 6e218c5
address Chris
bob80905 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// 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>), ""); | ||
|
||
|
||
typedef int myInt; | ||
|
||
struct TypeDefTest { | ||
int x; | ||
myInt y; | ||
}; | ||
|
||
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest), ""); |
10 changes: 10 additions & 0 deletions
10
clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatibleErrors.hlsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), ""); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this assert fire if
QT
is an empty struct?Uh oh!
There was an error while loading. Please reload this page.
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.
When QT is an empty struct (like
struct notComplete;
inclang\test\SemaHLSL\Types\Traits\IsTypedResourceElementCompatibleErrors.hlsl
)the assert is never hit, the function is never entered.
clang\lib\Sema\SemaExprCXX.cpp::EvaluateUnaryTypeTrait
won't callIsTypedResourceElementCompatible
because there's an early return, that is executed whenRequireCompleteType
returns false.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.
That's an incomplete type, not an empty struct. What about something like:
We frequently find bugs in DXC with cases of empty structs, empty base classes, etc.
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.
See #115045