@@ -10770,6 +10770,22 @@ HLSLExternalSource::ApplyTypeSpecSignToParsedType(clang::QualType &type,
1077010770 }
1077110771}
1077210772
10773+ bool DiagnoseIntersectionAttributes(Sema &S, SourceLocation Loc, QualType Ty) {
10774+ // Must be a UDT
10775+ if (Ty.isNull() || !hlsl::IsHLSLCopyableAnnotatableRecord(Ty)) {
10776+ S.Diag(Loc, diag::err_payload_attrs_must_be_udt)
10777+ << /*payload|attributes|callable*/ 1 << /*parameter %2|type*/ 1;
10778+ return false;
10779+ }
10780+
10781+ if (ContainsLongVector(Ty)) {
10782+ const unsigned AttributesIdx = 11;
10783+ S.Diag(Loc, diag::err_hlsl_unsupported_long_vector) << AttributesIdx;
10784+ return false;
10785+ }
10786+ return true;
10787+ }
10788+
1077310789Sema::TemplateDeductionResult
1077410790HLSLExternalSource::DeduceTemplateArgumentsForHLSL(
1077510791 FunctionTemplateDecl *FunctionTemplate,
@@ -10878,6 +10894,7 @@ HLSLExternalSource::DeduceTemplateArgumentsForHLSL(
1087810894 LPCSTR tableName = cursor.GetTableName();
1087910895 // Currently only intrinsic we allow for explicit template arguments are
1088010896 // for Load/Store for ByteAddressBuffer/RWByteAddressBuffer
10897+ // and HitObject::GetAttributes with user-defined intersection attributes.
1088110898
1088210899 // Check Explicit template arguments
1088310900 UINT intrinsicOp = (*cursor)->Op;
@@ -10892,28 +10909,38 @@ HLSLExternalSource::DeduceTemplateArgumentsForHLSL(
1089210909 IsBABLoad = intrinsicOp == (UINT)IntrinsicOp::MOP_Load;
1089310910 IsBABStore = intrinsicOp == (UINT)IntrinsicOp::MOP_Store;
1089410911 }
10895- if (ExplicitTemplateArgs && ExplicitTemplateArgs->size() > 0) {
10896- bool isLegalTemplate = false;
10912+ bool IsHitObjectGetAttributes =
10913+ intrinsicOp == (UINT)IntrinsicOp::MOP_DxHitObject_GetAttributes;
10914+ if (ExplicitTemplateArgs && ExplicitTemplateArgs->size() >= 1) {
1089710915 SourceLocation Loc = ExplicitTemplateArgs->getLAngleLoc();
10898- auto TemplateDiag = diag::err_hlsl_intrinsic_template_arg_unsupported;
10899- if (ExplicitTemplateArgs->size() >= 1 && (IsBABLoad || IsBABStore)) {
10900- TemplateDiag = diag::err_hlsl_intrinsic_template_arg_requires_2018;
10901- Loc = (*ExplicitTemplateArgs)[0].getLocation();
10902- if (Is2018) {
10903- TemplateDiag = diag::err_hlsl_intrinsic_template_arg_numeric;
10904- if (ExplicitTemplateArgs->size() == 1 &&
10905- !functionTemplateTypeArg.isNull() &&
10906- hlsl::IsHLSLNumericOrAggregateOfNumericType(
10907- functionTemplateTypeArg)) {
10908- isLegalTemplate = true;
10909- }
10910- }
10916+ if (!IsBABLoad && !IsBABStore && !IsHitObjectGetAttributes) {
10917+ getSema()->Diag(Loc, diag::err_hlsl_intrinsic_template_arg_unsupported)
10918+ << intrinsicName;
10919+ return Sema::TemplateDeductionResult::TDK_Invalid;
1091110920 }
10912-
10913- if (!isLegalTemplate) {
10914- getSema()->Diag(Loc, TemplateDiag) << intrinsicName;
10921+ Loc = (*ExplicitTemplateArgs)[0].getLocation();
10922+ if (!Is2018) {
10923+ getSema()->Diag(Loc,
10924+ diag::err_hlsl_intrinsic_template_arg_requires_2018)
10925+ << intrinsicName;
1091510926 return Sema::TemplateDeductionResult::TDK_Invalid;
1091610927 }
10928+
10929+ if (IsBABLoad || IsBABStore) {
10930+ const bool IsLegalTemplate =
10931+ !functionTemplateTypeArg.isNull() &&
10932+ hlsl::IsHLSLNumericOrAggregateOfNumericType(
10933+ functionTemplateTypeArg);
10934+ if (!IsLegalTemplate) {
10935+ getSema()->Diag(Loc, diag::err_hlsl_intrinsic_template_arg_numeric)
10936+ << intrinsicName;
10937+ return Sema::TemplateDeductionResult::TDK_Invalid;
10938+ }
10939+ }
10940+ if (IsHitObjectGetAttributes &&
10941+ !DiagnoseIntersectionAttributes(*getSema(), Loc,
10942+ functionTemplateTypeArg))
10943+ return Sema::TemplateDeductionResult::TDK_Invalid;
1091710944 } else if (IsBABStore) {
1091810945 // Prior to HLSL 2018, Store operation only stored scalar uint.
1091910946 if (!Is2018) {
0 commit comments