-
Notifications
You must be signed in to change notification settings - Fork 12k
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
[HLSL] Add empty struct test cases to __builtin_hlsl_is_typed_resource_element_compatible
test file
#115045
Conversation
@llvm/pr-subscribers-hlsl @llvm/pr-subscribers-clang Author: Joshua Batista (bob80905) ChangesThis PR adds empty struct cases to the test file for the builtin. Full diff: https://github.com/llvm/llvm-project/pull/115045.diff 1 Files Affected:
diff --git a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
index acc1f281daddfc..08d75a0c23b228 100644
--- a/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
+++ b/clang/test/SemaHLSL/Types/Traits/IsTypedResourceElementCompatible.hlsl
@@ -107,3 +107,5 @@ struct TypeDefTest {
};
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest), "");
+
+
|
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.
I think there is actually a bigger problem with your earlier PR that we need to address.
There is an inconsistency in the design document. Specifically in the beginning of the document it says:
Element types for typed buffer resources:
- Are not intangible (e.g., isn't a resource type)
- Must be vectors or scalars of arithmetic types, not bools nor enums nor arrays
- Should be a scalar or homogenous vector of a floating-point or integer type, with a maximum of 4 components after translating 64-bit components into pairs of uint32_t components
(edit: fixed formatting on quoted text, the formatting error is in the original document)
By this, elements should either be scalar or vectors, but not struct types.
The document later goes on to list test cases that are struct types.
I believe we had determined that DXC generates invalid code for some (most? all?) cases of structs in typed buffer elements, so we had determined to not support structs as element types in Clang.
Correct, I'll edit the spec to reflect this more clearly. I've removed most of the struct tests. |
|
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.
Looks good to me.
clang/lib/Sema/SemaHLSL.cpp
Outdated
if (CanonicalType->getAs<clang::RecordType>()) { | ||
return 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.
if (CanonicalType->getAs<clang::RecordType>()) { | |
return false; | |
} | |
if (CanonicalType->getAs<clang::RecordType>()) | |
return false; |
clang/lib/Sema/SemaHLSL.cpp
Outdated
llvm::SmallVector<QualType, 4> QTTypes; | ||
BuildFlattenedTypeList(QT, QTTypes); | ||
// the only other valid builtin types are scalars or vectors | ||
if (const BuiltinType *BT = CanonicalType->getAs<BuiltinType>()) { |
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.
Vectors aren't BuitinType
, so this can probably be simplified. Something like:
// All arithmetic and enumeration types are valid.
if (QT->isArithmeticType() || QT->isEnumeralType())
return true;
clang/lib/Sema/SemaHLSL.cpp
Outdated
QualType ElTy = VT->getElementType(); | ||
int TotalSizeInBytes = (SemaRef.Context.getTypeSize(ElTy) / 8) * ArraySize; | ||
|
||
if (TotalSizeInBytes > 16) |
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.
Can this be simplified to:
QualType ElTy = VT->getElementType(); | |
int TotalSizeInBytes = (SemaRef.Context.getTypeSize(ElTy) / 8) * ArraySize; | |
if (TotalSizeInBytes > 16) | |
if (SemaRef.Context.getTypeSize(QT) > 16) |
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.
With a division by 8, yes that is a good simplification
clang/lib/Sema/SemaHLSL.cpp
Outdated
// check if the outer type was an array type | ||
if (QT->isArrayType()) | ||
// UDT types are not allowed | ||
clang::QualType CanonicalType = QT.getCanonicalType(); |
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.
Most of the ways you're actually using this you likely don't need to query the canonical type. QT->isRecordType()
will query the type of the canonical type directly.
|
||
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(TypeDefTest), ""); |
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.
Do we need to remove all these tests, or just update them to expect false results?
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.
They could be left in and switched to false, but it doesn't seem valuable. All structs are disallowed, so I think just one struct test would suffice.
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(SimpleTemplate<__hlsl_resource_t>), ""); | ||
|
||
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(SimpleTemplate<float>), ""); | ||
// structs not allowed |
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 change may be a little too aggressive at removing test cases. All the struct cases should return false
, but we could maybe test a few different struct formations. Some key ones to cover: forward declaration (incomplete), empty structure, template struct, template struct containing a vector that would be valid.
|
||
typedef int myInt; | ||
typedef vector<int, 8> int8; |
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.
We should also have typedef tests that fail, the only one you have right now is a successful case.
What about arrays?
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(float[3]), "");
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.
The typedef test that I have right now does return false when evaluated by the builtin, it's a typedef of 8 ints in a vector. I also test for arrays with half[4]. Are these sufficient?
When you change what a PR does, please remember to update the title and description. This went in saying it's about adding some test cases but it actually changes much more than that. |
This PR adds empty struct cases to the test file for the builtin.