23
23
#include " clang/AST/ExternalASTSource.h"
24
24
#include " clang/AST/HlslBuiltinTypeDeclBuilder.h"
25
25
#include " clang/AST/TypeLoc.h"
26
+ #include " clang/Basic/Specifiers.h"
26
27
#include " clang/Sema/Overload.h"
27
28
#include " clang/Sema/Sema.h"
28
29
#include " clang/Sema/SemaDiagnostic.h"
@@ -1070,7 +1071,7 @@ static void CreateConstructorDeclaration(
1070
1071
static void CreateObjectFunctionDeclaration (
1071
1072
ASTContext &context, CXXRecordDecl *recordDecl, QualType resultType,
1072
1073
ArrayRef<QualType> args, DeclarationName declarationName, bool isConst,
1073
- CXXMethodDecl **functionDecl, TypeSourceInfo **tinfo) {
1074
+ StorageClass SC, CXXMethodDecl **functionDecl, TypeSourceInfo **tinfo) {
1074
1075
DXASSERT_NOMSG (recordDecl != nullptr );
1075
1076
DXASSERT_NOMSG (functionDecl != nullptr );
1076
1077
@@ -1082,8 +1083,8 @@ static void CreateObjectFunctionDeclaration(
1082
1083
*tinfo = context.getTrivialTypeSourceInfo (functionQT, NoLoc);
1083
1084
DXASSERT_NOMSG (*tinfo != nullptr );
1084
1085
*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);
1087
1088
DXASSERT_NOMSG (*functionDecl != nullptr );
1088
1089
(*functionDecl)->setLexicalDeclContext (recordDecl);
1089
1090
(*functionDecl)->setAccess (AccessSpecifier::AS_public);
@@ -1092,15 +1093,16 @@ static void CreateObjectFunctionDeclaration(
1092
1093
CXXMethodDecl *hlsl::CreateObjectFunctionDeclarationWithParams (
1093
1094
ASTContext &context, CXXRecordDecl *recordDecl, QualType resultType,
1094
1095
ArrayRef<QualType> paramTypes, ArrayRef<StringRef> paramNames,
1095
- DeclarationName declarationName, bool isConst, bool isTemplateFunction) {
1096
+ DeclarationName declarationName, bool isConst, StorageClass SC,
1097
+ bool isTemplateFunction) {
1096
1098
DXASSERT_NOMSG (recordDecl != nullptr );
1097
1099
DXASSERT_NOMSG (!resultType.isNull ());
1098
1100
DXASSERT_NOMSG (paramTypes.size () == paramNames.size ());
1099
1101
1100
1102
TypeSourceInfo *tinfo;
1101
1103
CXXMethodDecl *functionDecl;
1102
1104
CreateObjectFunctionDeclaration (context, recordDecl, resultType, paramTypes,
1103
- declarationName, isConst, &functionDecl,
1105
+ declarationName, isConst, SC, &functionDecl,
1104
1106
&tinfo);
1105
1107
1106
1108
// Create and associate parameters to method.
@@ -1215,6 +1217,46 @@ CXXRecordDecl *hlsl::DeclareRayQueryType(ASTContext &context) {
1215
1217
return typeDeclBuilder.getRecordDecl ();
1216
1218
}
1217
1219
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
+
1218
1260
CXXRecordDecl *hlsl::DeclareResourceType (ASTContext &context, bool bSampler) {
1219
1261
// struct ResourceDescriptor { uint8 desc; }
1220
1262
StringRef Name = bSampler ? " .Sampler" : " .Resource" ;
0 commit comments