Переглянути джерело

Add line number when report resource cannot map. (#892)

Xiang Li 7 роки тому
батько
коміт
9c459fedd8

+ 17 - 5
lib/HLSL/DxilGenerationPass.cpp

@@ -350,7 +350,16 @@ static Value *MergeImmResClass(Value *resClass) {
 }
 
 static const StringRef kResourceMapErrorMsg = "local resource not guaranteed to map to unique global resource.";
-
+static void EmitResMappingError(Instruction *Res) {
+  const DebugLoc &DL = Res->getDebugLoc();
+  if (DL.get()) {
+    Res->getContext().emitError("line:" + std::to_string(DL.getLine()) +
+        " col:" + std::to_string(DL.getCol()) + " " +
+        Twine(kResourceMapErrorMsg));
+  } else {
+    Res->getContext().emitError(Twine(kResourceMapErrorMsg) + " With /Zi to show more information.");
+  }
+}
 static Value *SelectOnOperand(Value *Cond, CallInst *CIT, CallInst *CIF,
                               unsigned idx, IRBuilder<> &Builder) {
   Value *OpT = CIT->getArgOperand(idx);
@@ -741,7 +750,7 @@ UpdateHandleOperands(Instruction *Res,
 
   for (unsigned i = startOpIdx; i < numOperands; i++) {
     if (!isa<Instruction>(Res->getOperand(i))) {
-      Res->getContext().emitError(Res, kResourceMapErrorMsg);
+      EmitResMappingError(Res);
       continue;
     }
     Instruction *ResOp = cast<Instruction>(Res->getOperand(i));
@@ -749,7 +758,7 @@ UpdateHandleOperands(Instruction *Res,
 
     if (!HandleOp) {
       if (handleMap.count(ResOp)) {
-        Res->getContext().emitError(Res, kResourceMapErrorMsg);
+        EmitResMappingError(Res);
         continue;
       }
       HandleOp = handleMap[ResOp];
@@ -877,7 +886,7 @@ void DxilGenerationPass::AddCreateHandleForPhiNodeAndSelect(OP *hlslOP) {
       if (!nonUniformOps.empty() && !bIsLib) {
         for (Instruction *I : nonUniformOps) {
           // Non uniform res class or res id.
-          FT->getContext().emitError(I, kResourceMapErrorMsg);
+          EmitResMappingError(I);
         }
         return;
       }
@@ -1543,7 +1552,10 @@ public:
       for (User *U : UndefHandle->users()) {
         // Report error if undef handle used for function call.
         if (isa<CallInst>(U)) {
-          M.getContext().emitError(kResourceMapErrorMsg);
+          if (Instruction *UI = dyn_cast<Instruction>(U))
+            EmitResMappingError(UI);
+          else
+            M.getContext().emitError(kResourceMapErrorMsg);
         }
       }
     }

+ 12 - 0
tools/clang/test/CodeGenHLSL/quick-test/local_res_fail_map_error_msg.hlsl

@@ -0,0 +1,12 @@
+// RUN: %dxc -E main -T ps_6_0 -Zi %s | FileCheck %s
+
+// Make sure line number is show for resource failed to map.
+
+// CHECK:line:11 col:10 local resource not guaranteed to map to unique global resource.
+
+SamplerState samp1 : register(s5);
+
+float4 main(float2 a : A) : SV_Target {
+  Texture2D text2;
+  return text2.Sample(samp1, a);
+}