@@ -868,8 +868,34 @@ static Expr *constructTypedBufferConstraintExpr(Sema &S, SourceLocation NameLoc,
868868 return TypedResExpr;
869869}
870870
871- static ConceptDecl *constructTypedBufferConceptDecl (Sema &S,
872- NamespaceDecl *NSD) {
871+ static Expr *constructRawBufferConstraintExpr (Sema &S, SourceLocation NameLoc,
872+ TemplateTypeParmDecl *T) {
873+ ASTContext &Context = S.getASTContext ();
874+
875+ // Obtain the QualType for 'bool'
876+ QualType BoolTy = Context.BoolTy ;
877+
878+ // Create a QualType that points to this TemplateTypeParmDecl
879+ QualType TType = Context.getTypeDeclType (T);
880+
881+ // Create a TypeSourceInfo for the template type parameter 'T'
882+ TypeSourceInfo *TTypeSourceInfo =
883+ Context.getTrivialTypeSourceInfo (TType, NameLoc);
884+
885+ TypeTraitExpr *IsIntangibleExpr =
886+ TypeTraitExpr::Create (Context, BoolTy, NameLoc, UTT_IsIntangibleType,
887+ {TTypeSourceInfo}, NameLoc, true );
888+
889+ // negate IsIntangibleExpr
890+ UnaryOperator *NotIntangibleExpr = UnaryOperator::Create (
891+ Context, IsIntangibleExpr, UO_Not, BoolTy, VK_LValue, OK_Ordinary,
892+ NameLoc, false , FPOptionsOverride ());
893+
894+ return NotIntangibleExpr;
895+ }
896+
897+ static ConceptDecl *constructTypedBufferConceptDecl (Sema &S, NamespaceDecl *NSD,
898+ bool isTypedBuffer) {
873899 ASTContext &Context = S.getASTContext ();
874900 DeclContext *DC = NSD->getDeclContext ();
875901 SourceLocation DeclLoc = SourceLocation ();
@@ -890,9 +916,18 @@ static ConceptDecl *constructTypedBufferConceptDecl(Sema &S,
890916 TemplateParameterList *ConceptParams = TemplateParameterList::Create (
891917 Context, DeclLoc, DeclLoc, {T}, DeclLoc, nullptr );
892918
893- DeclarationName DeclName = DeclarationName (
894- &Context.Idents .get (" __is_typed_resource_element_compatible" ));
895- Expr *ConstraintExpr = constructTypedBufferConstraintExpr (S, DeclLoc, T);
919+ DeclarationName DeclName;
920+ Expr *ConstraintExpr = nullptr ;
921+
922+ if (isTypedBuffer) {
923+ DeclName = DeclarationName (
924+ &Context.Idents .get (" __is_typed_resource_element_compatible" ));
925+ ConstraintExpr = constructTypedBufferConstraintExpr (S, DeclLoc, T);
926+ } else {
927+ DeclName = DeclarationName (
928+ &Context.Idents .get (" __is_raw_resource_element_compatible" ));
929+ ConstraintExpr = constructRawBufferConstraintExpr (S, DeclLoc, T);
930+ }
896931
897932 // Create a ConceptDecl
898933 ConceptDecl *CD =
@@ -910,8 +945,10 @@ static ConceptDecl *constructTypedBufferConceptDecl(Sema &S,
910945
911946void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations () {
912947 CXXRecordDecl *Decl;
913- ConceptDecl *TypedBufferConcept =
914- constructTypedBufferConceptDecl (*SemaPtr, HLSLNamespace);
948+ ConceptDecl *TypedBufferConcept = constructTypedBufferConceptDecl (
949+ *SemaPtr, HLSLNamespace, /* isTypedBuffer*/ true );
950+ ConceptDecl *RawBufferConcept = constructTypedBufferConceptDecl (
951+ *SemaPtr, HLSLNamespace, /* isTypedBuffer*/ false );
915952 Decl = BuiltinTypeDeclBuilder (*SemaPtr, HLSLNamespace, " RWBuffer" )
916953 .addSimpleTemplateParams ({" element_type" }, TypedBufferConcept)
917954 .finalizeForwardDeclaration ();
@@ -926,7 +963,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
926963
927964 Decl =
928965 BuiltinTypeDeclBuilder (*SemaPtr, HLSLNamespace, " RasterizerOrderedBuffer" )
929- .addSimpleTemplateParams ({" element_type" })
966+ .addSimpleTemplateParams ({" element_type" }, RawBufferConcept )
930967 .finalizeForwardDeclaration ();
931968 onCompletion (Decl, [this ](CXXRecordDecl *Decl) {
932969 setupBufferType (Decl, *SemaPtr, ResourceClass::UAV,
@@ -937,7 +974,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
937974 });
938975
939976 Decl = BuiltinTypeDeclBuilder (*SemaPtr, HLSLNamespace, " StructuredBuffer" )
940- .addSimpleTemplateParams ({" element_type" })
977+ .addSimpleTemplateParams ({" element_type" }, RawBufferConcept )
941978 .finalizeForwardDeclaration ();
942979 onCompletion (Decl, [this ](CXXRecordDecl *Decl) {
943980 setupBufferType (Decl, *SemaPtr, ResourceClass::SRV, ResourceKind::RawBuffer,
@@ -947,7 +984,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
947984 });
948985
949986 Decl = BuiltinTypeDeclBuilder (*SemaPtr, HLSLNamespace, " RWStructuredBuffer" )
950- .addSimpleTemplateParams ({" element_type" })
987+ .addSimpleTemplateParams ({" element_type" }, RawBufferConcept )
951988 .finalizeForwardDeclaration ();
952989 onCompletion (Decl, [this ](CXXRecordDecl *Decl) {
953990 setupBufferType (Decl, *SemaPtr, ResourceClass::UAV, ResourceKind::RawBuffer,
@@ -960,7 +997,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
960997
961998 Decl =
962999 BuiltinTypeDeclBuilder (*SemaPtr, HLSLNamespace, " AppendStructuredBuffer" )
963- .addSimpleTemplateParams ({" element_type" })
1000+ .addSimpleTemplateParams ({" element_type" }, RawBufferConcept )
9641001 .finalizeForwardDeclaration ();
9651002 onCompletion (Decl, [this ](CXXRecordDecl *Decl) {
9661003 setupBufferType (Decl, *SemaPtr, ResourceClass::UAV, ResourceKind::RawBuffer,
@@ -971,7 +1008,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
9711008
9721009 Decl =
9731010 BuiltinTypeDeclBuilder (*SemaPtr, HLSLNamespace, " ConsumeStructuredBuffer" )
974- .addSimpleTemplateParams ({" element_type" })
1011+ .addSimpleTemplateParams ({" element_type" }, RawBufferConcept )
9751012 .finalizeForwardDeclaration ();
9761013 onCompletion (Decl, [this ](CXXRecordDecl *Decl) {
9771014 setupBufferType (Decl, *SemaPtr, ResourceClass::UAV, ResourceKind::RawBuffer,
@@ -982,7 +1019,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
9821019
9831020 Decl = BuiltinTypeDeclBuilder (*SemaPtr, HLSLNamespace,
9841021 " RasterizerOrderedStructuredBuffer" )
985- .addSimpleTemplateParams ({" element_type" })
1022+ .addSimpleTemplateParams ({" element_type" }, RawBufferConcept )
9861023 .finalizeForwardDeclaration ();
9871024 onCompletion (Decl, [this ](CXXRecordDecl *Decl) {
9881025 setupBufferType (Decl, *SemaPtr, ResourceClass::UAV, ResourceKind::RawBuffer,
0 commit comments