@@ -53,44 +53,44 @@ ConvertHLSLVecMatTypeToExtVectorType(const clang::ASTContext &context,
53
53
return nullptr ;
54
54
}
55
55
56
+ template <typename AttrType> static AttrType *getAttr (clang::QualType type) {
57
+ type = type.getCanonicalType ();
58
+ if (const RecordType *RT = type->getAs <RecordType>()) {
59
+ if (const auto *Spec =
60
+ dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl ()))
61
+ if (const auto *Template =
62
+ dyn_cast<ClassTemplateDecl>(Spec->getSpecializedTemplate ()))
63
+ return Template->getTemplatedDecl ()->getAttr <AttrType>();
64
+ if (const auto *Decl = dyn_cast<CXXRecordDecl>(RT->getDecl ()))
65
+ return Decl->getAttr <AttrType>();
66
+ }
67
+ return nullptr ;
68
+ }
69
+
56
70
bool IsHLSLVecMatType (clang::QualType type) {
57
- const Type *Ty = type.getCanonicalType (). getTypePtr ();
58
- if (const RecordType *RT = dyn_cast <RecordType>(Ty )) {
59
- if (const ClassTemplateSpecializationDecl *templateDecl =
60
- dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl ())) {
61
- if (templateDecl-> getName () == " vector " ) {
62
- return true ;
63
- } else if (templateDecl-> getName () == " matrix " ) {
64
- return true ;
65
- }
66
- }
71
+ type = type.getCanonicalType ();
72
+ if (const RecordType *RT = type-> getAs <RecordType>()) {
73
+ if (const auto *Spec =
74
+ dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl ()))
75
+ if (const auto *Template =
76
+ dyn_cast<ClassTemplateDecl>(Spec-> getSpecializedTemplate ()))
77
+ return Template-> getTemplatedDecl ()-> getAttr <HLSLMatrixAttr> () ||
78
+ Template-> getTemplatedDecl ()-> getAttr <HLSLVectorAttr>() ;
79
+ if ( const auto *Decl = dyn_cast<CXXRecordDecl>(RT-> getDecl ()))
80
+ return Decl-> getAttr <HLSLMatrixAttr>() || Decl-> getAttr <HLSLVectorAttr>();
67
81
}
68
82
return false ;
69
83
}
70
84
71
85
bool IsHLSLMatType (clang::QualType type) {
72
- const clang::Type *Ty = type.getCanonicalType ().getTypePtr ();
73
- if (const RecordType *RT = dyn_cast<RecordType>(Ty)) {
74
- if (const ClassTemplateSpecializationDecl *templateDecl =
75
- dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl ())) {
76
- if (templateDecl->getName () == " matrix" ) {
77
- return true ;
78
- }
79
- }
80
- }
86
+ if (getAttr<HLSLMatrixAttr>(type))
87
+ return true ;
81
88
return false ;
82
89
}
83
90
84
91
bool IsHLSLVecType (clang::QualType type) {
85
- const clang::Type *Ty = type.getCanonicalType ().getTypePtr ();
86
- if (const RecordType *RT = dyn_cast<RecordType>(Ty)) {
87
- if (const ClassTemplateSpecializationDecl *templateDecl =
88
- dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl ())) {
89
- if (templateDecl->getName () == " vector" ) {
90
- return true ;
91
- }
92
- }
93
- }
92
+ if (getAttr<HLSLVectorAttr>(type))
93
+ return true ;
94
94
return false ;
95
95
}
96
96
@@ -475,20 +475,6 @@ clang::QualType GetHLSLMatElementType(clang::QualType type) {
475
475
return elemTy;
476
476
}
477
477
478
- template <typename AttrType> static AttrType *getAttr (clang::QualType type) {
479
- type = type.getCanonicalType ();
480
- if (const RecordType *RT = type->getAs <RecordType>()) {
481
- if (const auto *Spec =
482
- dyn_cast<ClassTemplateSpecializationDecl>(RT->getDecl ()))
483
- if (const auto *Template =
484
- dyn_cast<ClassTemplateDecl>(Spec->getSpecializedTemplate ()))
485
- return Template->getTemplatedDecl ()->getAttr <AttrType>();
486
- if (const auto *Decl = dyn_cast<CXXRecordDecl>(RT->getDecl ()))
487
- return Decl->getAttr <AttrType>();
488
- }
489
- return nullptr ;
490
- }
491
-
492
478
// TODO: Add type cache to ASTContext.
493
479
bool IsHLSLInputPatchType (QualType type) {
494
480
type = type.getCanonicalType ();
@@ -812,7 +798,11 @@ QualType GetHLSLResourceResultType(QualType type) {
812
798
if (const ClassTemplateSpecializationDecl *templateDecl =
813
799
dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
814
800
815
- if (RD->getName ().startswith (" FeedbackTexture" )) {
801
+ const HLSLResourceAttr *Attr = getAttr<HLSLResourceAttr>(type);
802
+ if (Attr && (Attr->getResKind () ==
803
+ (unsigned )DXIL::ResourceKind::FeedbackTexture2D ||
804
+ Attr->getResKind () ==
805
+ (unsigned )DXIL::ResourceKind::FeedbackTexture2DArray)) {
816
806
// Feedback textures are write-only and the data is opaque,
817
807
// so there is no result type per se.
818
808
return {};
0 commit comments