2323#include " clang/AST/ExternalASTSource.h"
2424#include " clang/AST/HlslBuiltinTypeDeclBuilder.h"
2525#include " clang/AST/TypeLoc.h"
26+ #include " clang/Basic/Specifiers.h"
2627#include " clang/Sema/Overload.h"
2728#include " clang/Sema/Sema.h"
2829#include " clang/Sema/SemaDiagnostic.h"
@@ -1070,7 +1071,7 @@ static void CreateConstructorDeclaration(
10701071static void CreateObjectFunctionDeclaration (
10711072 ASTContext &context, CXXRecordDecl *recordDecl, QualType resultType,
10721073 ArrayRef<QualType> args, DeclarationName declarationName, bool isConst,
1073- CXXMethodDecl **functionDecl, TypeSourceInfo **tinfo) {
1074+ StorageClass SC, CXXMethodDecl **functionDecl, TypeSourceInfo **tinfo) {
10741075 DXASSERT_NOMSG (recordDecl != nullptr );
10751076 DXASSERT_NOMSG (functionDecl != nullptr );
10761077
@@ -1082,8 +1083,8 @@ static void CreateObjectFunctionDeclaration(
10821083 *tinfo = context.getTrivialTypeSourceInfo (functionQT, NoLoc);
10831084 DXASSERT_NOMSG (*tinfo != nullptr );
10841085 *functionDecl = CXXMethodDecl::Create (
1085- context, recordDecl, NoLoc, declNameInfo, functionQT, *tinfo,
1086- StorageClass::SC_None, InlineSpecifiedFalse, IsConstexprFalse, NoLoc);
1086+ context, recordDecl, NoLoc, declNameInfo, functionQT, *tinfo, SC,
1087+ InlineSpecifiedFalse, IsConstexprFalse, NoLoc);
10871088 DXASSERT_NOMSG (*functionDecl != nullptr );
10881089 (*functionDecl)->setLexicalDeclContext (recordDecl);
10891090 (*functionDecl)->setAccess (AccessSpecifier::AS_public);
@@ -1092,15 +1093,16 @@ static void CreateObjectFunctionDeclaration(
10921093CXXMethodDecl *hlsl::CreateObjectFunctionDeclarationWithParams (
10931094 ASTContext &context, CXXRecordDecl *recordDecl, QualType resultType,
10941095 ArrayRef<QualType> paramTypes, ArrayRef<StringRef> paramNames,
1095- DeclarationName declarationName, bool isConst, bool isTemplateFunction) {
1096+ DeclarationName declarationName, bool isConst, StorageClass SC,
1097+ bool isTemplateFunction) {
10961098 DXASSERT_NOMSG (recordDecl != nullptr );
10971099 DXASSERT_NOMSG (!resultType.isNull ());
10981100 DXASSERT_NOMSG (paramTypes.size () == paramNames.size ());
10991101
11001102 TypeSourceInfo *tinfo;
11011103 CXXMethodDecl *functionDecl;
11021104 CreateObjectFunctionDeclaration (context, recordDecl, resultType, paramTypes,
1103- declarationName, isConst, &functionDecl,
1105+ declarationName, isConst, SC, &functionDecl,
11041106 &tinfo);
11051107
11061108 // Create and associate parameters to method.
@@ -1215,6 +1217,46 @@ CXXRecordDecl *hlsl::DeclareRayQueryType(ASTContext &context) {
12151217 return typeDeclBuilder.getRecordDecl ();
12161218}
12171219
1220+ CXXRecordDecl *hlsl::DeclareHitObjectType (NamespaceDecl &NSDecl) {
1221+ ASTContext &Context = NSDecl.getASTContext ();
1222+ // HitObject { ... }
1223+ BuiltinTypeDeclBuilder TypeDeclBuilder (&NSDecl, " HitObject" );
1224+ TypeDeclBuilder.startDefinition ();
1225+
1226+ // Add handle to mark as HLSL object.
1227+ TypeDeclBuilder.addField (" h" , GetHLSLObjectHandleType (Context));
1228+ CXXRecordDecl *RecordDecl = TypeDeclBuilder.getRecordDecl ();
1229+
1230+ CanQualType canQualType = Context.getCanonicalType (
1231+ Context.getRecordType (TypeDeclBuilder.getRecordDecl ()));
1232+
1233+ // Add constructor that will be lowered to MOP_HitObject_MakeNop.
1234+ CXXConstructorDecl *pConstructorDecl = nullptr ;
1235+ TypeSourceInfo *pTypeSourceInfo = nullptr ;
1236+ CreateConstructorDeclaration (
1237+ Context, RecordDecl, Context.VoidTy , {},
1238+ Context.DeclarationNames .getCXXConstructorName (canQualType), false ,
1239+ &pConstructorDecl, &pTypeSourceInfo);
1240+ RecordDecl->addDecl (pConstructorDecl);
1241+ pConstructorDecl->addAttr (HLSLIntrinsicAttr::CreateImplicit (
1242+ Context, " op" , " " ,
1243+ static_cast <int >(hlsl::IntrinsicOp::MOP_DxHitObject_MakeNop)));
1244+ pConstructorDecl->addAttr (HLSLCXXOverloadAttr::CreateImplicit (Context));
1245+
1246+ // Add AvailabilityAttribute for SM6.9+
1247+ VersionTuple VT69 = VersionTuple (6 , 9 );
1248+ RecordDecl->addAttr (ConstructAvailabilityAttribute (Context, VT69));
1249+
1250+ // Add the implicit HLSLHitObjectAttr attribute to unambiguously recognize the
1251+ // builtin HitObject type.
1252+ RecordDecl->addAttr (HLSLHitObjectAttr::CreateImplicit (Context));
1253+ RecordDecl->setImplicit (true );
1254+
1255+ // Add to namespace
1256+ RecordDecl->setDeclContext (&NSDecl);
1257+ return RecordDecl;
1258+ }
1259+
12181260CXXRecordDecl *hlsl::DeclareResourceType (ASTContext &context, bool bSampler) {
12191261 // struct ResourceDescriptor { uint8 desc; }
12201262 StringRef Name = bSampler ? " .Sampler" : " .Resource" ;
0 commit comments