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,15 +1078,12 @@ 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
// The following conducts analysis on resource ranges to detect and report
1087
1088
// any overlaps in resource ranges.
1088
1089
//
@@ -1107,9 +1108,15 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1107
1108
using ResourceRange = llvm::hlsl::rootsig::ResourceRange;
1108
1109
using GroupT = std::pair<ResourceClass, /* Space*/ uint32_t >;
1109
1110
1111
+ // Introduce a mapping from the collected RangeInfos back to the
1112
+ // RootSignatureElement that will retain its diagnostics info
1113
+ llvm::DenseMap<size_t , const hlsl::RootSignatureElement *> InfoIndexMap;
1114
+ size_t InfoIndex = 0 ;
1115
+
1110
1116
// 1. Collect RangeInfos
1111
1117
llvm::SmallVector<RangeInfo> Infos;
1112
- for (const llvm::hlsl::rootsig::RootElement &Elem : D->getRootElements ()) {
1118
+ for (const hlsl::RootSignatureElement &RootSigElem : Elements) {
1119
+ const llvm::hlsl::rootsig::RootElement &Elem = RootSigElem.getElement ();
1113
1120
if (const auto *Descriptor =
1114
1121
std::get_if<llvm::hlsl::rootsig::RootDescriptor>(&Elem)) {
1115
1122
RangeInfo Info;
@@ -1120,6 +1127,9 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1120
1127
llvm::dxil::ResourceClass (llvm::to_underlying (Descriptor->Type ));
1121
1128
Info.Space = Descriptor->Space ;
1122
1129
Info.Visibility = Descriptor->Visibility ;
1130
+
1131
+ Info.Index = InfoIndex++;
1132
+ InfoIndexMap[Info.Index ] = &RootSigElem;
1123
1133
Infos.push_back (Info);
1124
1134
} else if (const auto *Constants =
1125
1135
std::get_if<llvm::hlsl::rootsig::RootConstants>(&Elem)) {
@@ -1130,6 +1140,9 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1130
1140
Info.Class = llvm::dxil::ResourceClass::CBuffer;
1131
1141
Info.Space = Constants->Space ;
1132
1142
Info.Visibility = Constants->Visibility ;
1143
+
1144
+ Info.Index = InfoIndex++;
1145
+ InfoIndexMap[Info.Index ] = &RootSigElem;
1133
1146
Infos.push_back (Info);
1134
1147
} else if (const auto *Sampler =
1135
1148
std::get_if<llvm::hlsl::rootsig::StaticSampler>(&Elem)) {
@@ -1140,6 +1153,9 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1140
1153
Info.Class = llvm::dxil::ResourceClass::Sampler;
1141
1154
Info.Space = Sampler->Space ;
1142
1155
Info.Visibility = Sampler->Visibility ;
1156
+
1157
+ Info.Index = InfoIndex++;
1158
+ InfoIndexMap[Info.Index ] = &RootSigElem;
1143
1159
Infos.push_back (Info);
1144
1160
} else if (const auto *Clause =
1145
1161
std::get_if<llvm::hlsl::rootsig::DescriptorTableClause>(
@@ -1154,7 +1170,10 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1154
1170
1155
1171
Info.Class = Clause->Type ;
1156
1172
Info.Space = Clause->Space ;
1173
+
1157
1174
// Note: Clause does not hold the visibility this will need to
1175
+ Info.Index = InfoIndex++;
1176
+ InfoIndexMap[Info.Index ] = &RootSigElem;
1158
1177
Infos.push_back (Info);
1159
1178
} else if (const auto *Table =
1160
1179
std::get_if<llvm::hlsl::rootsig::DescriptorTable>(&Elem)) {
@@ -1201,13 +1220,15 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
1201
1220
};
1202
1221
1203
1222
// Helper to report diagnostics
1204
- auto ReportOverlap = [this , Loc , &HadOverlap](const RangeInfo *Info,
1223
+ auto ReportOverlap = [this , InfoIndexMap , &HadOverlap](const RangeInfo *Info,
1205
1224
const RangeInfo *OInfo) {
1206
1225
HadOverlap = true ;
1207
1226
auto CommonVis = Info->Visibility == llvm::dxbc::ShaderVisibility::All
1208
1227
? OInfo->Visibility
1209
1228
: Info->Visibility ;
1210
- this ->Diag (Loc, diag::err_hlsl_resource_range_overlap)
1229
+ const hlsl::RootSignatureElement *Elem = InfoIndexMap.at (Info->Index );
1230
+ SourceLocation InfoLoc = Elem->getLocation ();
1231
+ this ->Diag (InfoLoc, diag::err_hlsl_resource_range_overlap)
1211
1232
<< llvm::to_underlying (Info->Class ) << Info->LowerBound
1212
1233
<< /* unbounded=*/ (Info->UpperBound == RangeInfo::Unbounded)
1213
1234
<< Info->UpperBound << llvm::to_underlying (OInfo->Class )
0 commit comments