Browse Source

PIX: Shader debug: don't instrument ray query handles (#3434)

* checkpoint

* Move helper to new file

Co-authored-by: Jeff Noyle <[email protected]>
Jeff Noyle 4 years ago
parent
commit
ade0e24792

+ 1 - 1
lib/DxilPIXPasses/CMakeLists.txt

@@ -13,7 +13,7 @@ add_llvm_library(LLVMDxilPIXPasses
   DxilShaderAccessTracking.cpp
   DxilShaderAccessTracking.cpp
   DxilPIXPasses.cpp
   DxilPIXPasses.cpp
   DxilPIXVirtualRegisters.cpp
   DxilPIXVirtualRegisters.cpp
-
+  PixPassHelpers.cpp
 
 
   ADDITIONAL_HEADER_DIRS
   ADDITIONAL_HEADER_DIRS
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/IR
   ${LLVM_MAIN_INCLUDE_DIR}/llvm/IR

+ 6 - 0
lib/DxilPIXPasses/DxilDbgValueToDbgDeclare.cpp

@@ -28,6 +28,8 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/Pass.h"
 
 
+#include "PixPassHelpers.h"
+
 #define DEBUG_TYPE "dxil-dbg-value-to-dbg-declare"
 #define DEBUG_TYPE "dxil-dbg-value-to-dbg-declare"
 
 
 namespace {
 namespace {
@@ -364,6 +366,10 @@ bool DxilDbgValueToDbgDeclare::runOnModule(
 
 
     if (auto *DbgValue = llvm::dyn_cast<llvm::DbgValueInst>(User))
     if (auto *DbgValue = llvm::dyn_cast<llvm::DbgValueInst>(User))
     {
     {
+      llvm::Value *V = DbgValue->getValue();
+      if (PIXPassHelpers::IsAllocateRayQueryInstruction(V)) {
+          continue;
+      }
       Changed = true;
       Changed = true;
       handleDbgValue(M, DbgValue);
       handleDbgValue(M, DbgValue);
       DbgValue->eraseFromParent();
       DbgValue->eraseFromParent();

+ 25 - 29
lib/DxilPIXPasses/DxilDebugInstrumentation.cpp

@@ -22,6 +22,8 @@
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/InstIterator.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Module.h"
 
 
+#include "PixPassHelpers.h"
+
 using namespace llvm;
 using namespace llvm;
 using namespace hlsl;
 using namespace hlsl;
 
 
@@ -263,7 +265,7 @@ private:
   void addInvocationStartMarker(BuilderContext &BC);
   void addInvocationStartMarker(BuilderContext &BC);
   void reserveDebugEntrySpace(BuilderContext &BC, uint32_t SpaceInDwords);
   void reserveDebugEntrySpace(BuilderContext &BC, uint32_t SpaceInDwords);
   void addStoreStepDebugEntry(BuilderContext &BC, StoreInst *Inst);
   void addStoreStepDebugEntry(BuilderContext &BC, StoreInst *Inst);
-  void addStepDebugEntry(BuilderContext &BC, Instruction *Inst);
+  void addStepDebugEntry(BuilderContext& BC, Instruction* Inst);
   void addStepDebugEntryValue(BuilderContext &BC, std::uint32_t InstNum,
   void addStepDebugEntryValue(BuilderContext &BC, std::uint32_t InstNum,
                               Value *V, std::uint32_t ValueOrdinal,
                               Value *V, std::uint32_t ValueOrdinal,
                               Value *ValueOrdinalIndex);
                               Value *ValueOrdinalIndex);
@@ -807,24 +809,28 @@ void DxilDebugInstrumentation::addStepEntryForType(
   }
   }
 }
 }
 
 
-void DxilDebugInstrumentation::addStoreStepDebugEntry(BuilderContext &BC,
-                                                      StoreInst *Inst) {
-  std::uint32_t ValueOrdinalBase;
-  std::uint32_t UnusedValueOrdinalSize;
-  llvm::Value *ValueOrdinalIndex;
-  if (!pix_dxil::PixAllocaRegWrite::FromInst(Inst, &ValueOrdinalBase,
-                                             &UnusedValueOrdinalSize,
-                                             &ValueOrdinalIndex)) {
-    return;
-  }
+void DxilDebugInstrumentation::addStoreStepDebugEntry(BuilderContext& BC,
+    StoreInst* Inst) {
+    std::uint32_t ValueOrdinalBase;
+    std::uint32_t UnusedValueOrdinalSize;
+    llvm::Value* ValueOrdinalIndex;
+    if (!pix_dxil::PixAllocaRegWrite::FromInst(Inst, &ValueOrdinalBase,
+        &UnusedValueOrdinalSize,
+        &ValueOrdinalIndex)) {
+        return;
+    }
 
 
-  std::uint32_t InstNum;
-  if (!pix_dxil::PixDxilInstNum::FromInst(Inst, &InstNum)) {
-    return;
-  }
+    std::uint32_t InstNum;
+    if (!pix_dxil::PixDxilInstNum::FromInst(Inst, &InstNum)) {
+        return;
+    }
+
+    if (PIXPassHelpers::IsAllocateRayQueryInstruction(Inst->getValueOperand())) {
+        return;
+    }
 
 
-  addStepDebugEntryValue(BC, InstNum, Inst->getValueOperand(), ValueOrdinalBase,
-                         ValueOrdinalIndex);
+    addStepDebugEntryValue(BC, InstNum, Inst->getValueOperand(), ValueOrdinalBase,
+        ValueOrdinalIndex);
 }
 }
 
 
 void DxilDebugInstrumentation::addStepDebugEntry(BuilderContext &BC,
 void DxilDebugInstrumentation::addStepDebugEntry(BuilderContext &BC,
@@ -832,17 +838,8 @@ void DxilDebugInstrumentation::addStepDebugEntry(BuilderContext &BC,
   if (Inst->getOpcode() == Instruction::OtherOps::PHI) {
   if (Inst->getOpcode() == Instruction::OtherOps::PHI) {
     return;
     return;
   }
   }
-
-  if (Inst->getOpcode() == Instruction::OtherOps::Call) {
-    if (Inst->getNumOperands() > 0) {
-      if (auto *asInt =
-              llvm::cast_or_null<llvm::ConstantInt>(Inst->getOperand(0))) {
-        if (asInt->getZExtValue() == (uint64_t)DXIL::OpCode::AllocateRayQuery) {
-          // Ray query handles should not be stored in the debug trace UAV
-          return;
-        }
-      }
-    }
+  if (PIXPassHelpers::IsAllocateRayQueryInstruction(Inst)) {
+      return;
   }
   }
 
 
   if (auto *St = llvm::dyn_cast<llvm::StoreInst>(Inst)) {
   if (auto *St = llvm::dyn_cast<llvm::StoreInst>(Inst)) {
@@ -980,7 +977,6 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
     };
     };
 
 
     std::map<BasicBlock *, std::vector<ValueAndPhi>> InsertableEdges;
     std::map<BasicBlock *, std::vector<ValueAndPhi>> InsertableEdges;
-
     auto &Is = CurrentBlock.getInstList();
     auto &Is = CurrentBlock.getInstList();
     for (auto &Inst : Is) {
     for (auto &Inst : Is) {
       if (Inst.getOpcode() != Instruction::OtherOps::PHI) {
       if (Inst.getOpcode() != Instruction::OtherOps::PHI) {

+ 22 - 0
lib/DxilPIXPasses/PixPassHelpers.cpp

@@ -0,0 +1,22 @@
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// PixPassHelpers.cpp														 //
+// Copyright (C) Microsoft Corporation. All rights reserved.                 //
+// This file is distributed under the University of Illinois Open Source     //
+// License. See LICENSE.TXT for details.                                     //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#include "dxc/DXIL/DxilOperations.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+
+namespace PIXPassHelpers
+{
+    bool IsAllocateRayQueryInstruction(llvm::Value* Val) {
+        if (llvm::Instruction* Inst = llvm::dyn_cast<llvm::Instruction>(Val)) {
+            return hlsl::OP::IsDxilOpFuncCallInst(Inst, hlsl::OP::OpCode::AllocateRayQuery);
+        }
+        return false;
+    }
+}

+ 15 - 0
lib/DxilPIXPasses/PixPassHelpers.h

@@ -0,0 +1,15 @@
+///////////////////////////////////////////////////////////////////////////////
+//                                                                           //
+// PixPassHelpers.h  														 //
+// Copyright (C) Microsoft Corporation. All rights reserved.                 //
+// This file is distributed under the University of Illinois Open Source     //
+// License. See LICENSE.TXT for details.                                     //
+//                                                                           //
+///////////////////////////////////////////////////////////////////////////////
+
+#pragma once
+
+namespace PIXPassHelpers
+{
+	bool IsAllocateRayQueryInstruction(llvm::Value* Val);
+}