28
28
#include " clang/Basic/SourceLocation.h"
29
29
#include " clang/Basic/Specifiers.h"
30
30
#include " clang/Basic/TargetInfo.h"
31
+ #include " clang/Parse/ParseHLSLRootSignature.h"
31
32
#include " clang/Sema/Initialization.h"
32
33
#include " clang/Sema/Lookup.h"
33
34
#include " clang/Sema/ParsedAttr.h"
@@ -1066,6 +1067,9 @@ void SemaHLSL::ActOnFinishRootSignatureDecl(
1066
1067
SourceLocation Loc, IdentifierInfo *DeclIdent,
1067
1068
ArrayRef<hlsl::RootSignatureElement> RootElements) {
1068
1069
1070
+ if (handleRootSignatureElements (RootElements, Loc))
1071
+ return ;
1072
+
1069
1073
SmallVector<llvm::hlsl::rootsig::RootElement> Elements;
1070
1074
for (auto &RootSigElement : RootElements)
1071
1075
Elements.push_back (RootSigElement.getElement ());
@@ -1074,21 +1078,24 @@ void SemaHLSL::ActOnFinishRootSignatureDecl(
1074
1078
SemaRef.getASTContext (), /* DeclContext=*/ SemaRef.CurContext , Loc,
1075
1079
DeclIdent, SemaRef.getLangOpts ().HLSLRootSigVer , Elements);
1076
1080
1077
- if (handleRootSignatureDecl (SignatureDecl, Loc))
1078
- return ;
1079
-
1080
1081
SignatureDecl->setImplicit ();
1081
1082
SemaRef.PushOnScopeChains (SignatureDecl, SemaRef.getCurScope ());
1082
1083
}
1083
1084
1084
- bool SemaHLSL::handleRootSignatureDecl (HLSLRootSignatureDecl *D,
1085
- SourceLocation Loc) {
1085
+ bool SemaHLSL::handleRootSignatureElements (
1086
+ ArrayRef<hlsl::RootSignatureElement> Elements, SourceLocation Loc) {
1086
1087
using RangeInfo = llvm::hlsl::rootsig::RangeInfo;
1087
1088
using OverlappingRanges = llvm::hlsl::rootsig::OverlappingRanges;
1088
1089
1090
+ // Introduce a mapping from the collected RangeInfos back to the
1091
+ // RootSignatureElement that will retain its diagnostics info
1092
+ llvm::DenseMap<size_t , const hlsl::RootSignatureElement *> InfoIndexMap;
1093
+ size_t InfoIndex = 0 ;
1094
+
1089
1095
// 1. Collect RangeInfos
1090
1096
llvm::SmallVector<RangeInfo> Infos;
1091
- for (const llvm::hlsl::rootsig::RootElement &Elem : D->getRootElements ()) {
1097
+ for (const hlsl::RootSignatureElement &RootSigElem : Elements) {
1098
+ const llvm::hlsl::rootsig::RootElement &Elem = RootSigElem.getElement ();
1092
1099
if (const auto *Descriptor =
1093
1100
std::get_if<llvm::hlsl::rootsig::RootDescriptor>(&Elem)) {
1094
1101
RangeInfo Info;
@@ -1099,6 +1106,9 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1099
1106
llvm::dxil::ResourceClass (llvm::to_underlying (Descriptor->Type ));
1100
1107
Info.Space = Descriptor->Space ;
1101
1108
Info.Visibility = Descriptor->Visibility ;
1109
+
1110
+ Info.Index = InfoIndex++;
1111
+ InfoIndexMap[Info.Index ] = &RootSigElem;
1102
1112
Infos.push_back (Info);
1103
1113
} else if (const auto *Constants =
1104
1114
std::get_if<llvm::hlsl::rootsig::RootConstants>(&Elem)) {
@@ -1109,6 +1119,9 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1109
1119
Info.Class = llvm::dxil::ResourceClass::CBuffer;
1110
1120
Info.Space = Constants->Space ;
1111
1121
Info.Visibility = Constants->Visibility ;
1122
+
1123
+ Info.Index = InfoIndex++;
1124
+ InfoIndexMap[Info.Index ] = &RootSigElem;
1112
1125
Infos.push_back (Info);
1113
1126
} else if (const auto *Sampler =
1114
1127
std::get_if<llvm::hlsl::rootsig::StaticSampler>(&Elem)) {
@@ -1119,6 +1132,9 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1119
1132
Info.Class = llvm::dxil::ResourceClass::Sampler;
1120
1133
Info.Space = Sampler->Space ;
1121
1134
Info.Visibility = Sampler->Visibility ;
1135
+
1136
+ Info.Index = InfoIndex++;
1137
+ InfoIndexMap[Info.Index ] = &RootSigElem;
1122
1138
Infos.push_back (Info);
1123
1139
} else if (const auto *Clause =
1124
1140
std::get_if<llvm::hlsl::rootsig::DescriptorTableClause>(
@@ -1133,7 +1149,10 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1133
1149
1134
1150
Info.Class = Clause->Type ;
1135
1151
Info.Space = Clause->Space ;
1152
+
1136
1153
// Note: Clause does not hold the visibility this will need to
1154
+ Info.Index = InfoIndex++;
1155
+ InfoIndexMap[Info.Index ] = &RootSigElem;
1137
1156
Infos.push_back (Info);
1138
1157
} else if (const auto *Table =
1139
1158
std::get_if<llvm::hlsl::rootsig::DescriptorTable>(&Elem)) {
@@ -1150,13 +1169,15 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1150
1169
}
1151
1170
1152
1171
// Helper to report diagnostics
1153
- auto ReportOverlap = [this , Loc ](OverlappingRanges Overlap) {
1172
+ auto ReportOverlap = [this , &InfoIndexMap ](OverlappingRanges Overlap) {
1154
1173
const RangeInfo *Info = Overlap.A ;
1155
1174
const RangeInfo *OInfo = Overlap.B ;
1156
1175
auto CommonVis = Info->Visibility == llvm::dxbc::ShaderVisibility::All
1157
1176
? OInfo->Visibility
1158
1177
: Info->Visibility ;
1159
- this ->Diag (Loc, diag::err_hlsl_resource_range_overlap)
1178
+ const hlsl::RootSignatureElement *Elem = InfoIndexMap.at (Info->Index );
1179
+ SourceLocation InfoLoc = Elem->getLocation ();
1180
+ this ->Diag (InfoLoc, diag::err_hlsl_resource_range_overlap)
1160
1181
<< llvm::to_underlying (Info->Class ) << Info->LowerBound
1161
1182
<< /* unbounded=*/ (Info->UpperBound == RangeInfo::Unbounded)
1162
1183
<< Info->UpperBound << llvm::to_underlying (OInfo->Class )
0 commit comments