Skip to content

Commit

Permalink
PIX: Shader debug: don't instrument ray query handles (microsoft#3434)
Browse files Browse the repository at this point in the history
* checkpoint

* Move helper to new file

Co-authored-by: Jeff Noyle <[email protected]>
  • Loading branch information
jeffnn and Jeff Noyle authored Feb 10, 2021
1 parent 694e565 commit ade0e24
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/DxilPIXPasses/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ add_llvm_library(LLVMDxilPIXPasses
DxilShaderAccessTracking.cpp
DxilPIXPasses.cpp
DxilPIXVirtualRegisters.cpp

PixPassHelpers.cpp

ADDITIONAL_HEADER_DIRS
${LLVM_MAIN_INCLUDE_DIR}/llvm/IR
Expand Down
6 changes: 6 additions & 0 deletions lib/DxilPIXPasses/DxilDbgValueToDbgDeclare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "llvm/IR/Module.h"
#include "llvm/Pass.h"

#include "PixPassHelpers.h"

#define DEBUG_TYPE "dxil-dbg-value-to-dbg-declare"

namespace {
Expand Down Expand Up @@ -364,6 +366,10 @@ bool DxilDbgValueToDbgDeclare::runOnModule(

if (auto *DbgValue = llvm::dyn_cast<llvm::DbgValueInst>(User))
{
llvm::Value *V = DbgValue->getValue();
if (PIXPassHelpers::IsAllocateRayQueryInstruction(V)) {
continue;
}
Changed = true;
handleDbgValue(M, DbgValue);
DbgValue->eraseFromParent();
Expand Down
54 changes: 25 additions & 29 deletions lib/DxilPIXPasses/DxilDebugInstrumentation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "llvm/IR/InstIterator.h"
#include "llvm/IR/Module.h"

#include "PixPassHelpers.h"

using namespace llvm;
using namespace hlsl;

Expand Down Expand Up @@ -263,7 +265,7 @@ class DxilDebugInstrumentation : public ModulePass {
void addInvocationStartMarker(BuilderContext &BC);
void reserveDebugEntrySpace(BuilderContext &BC, uint32_t SpaceInDwords);
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,
Value *V, std::uint32_t ValueOrdinal,
Value *ValueOrdinalIndex);
Expand Down Expand Up @@ -807,42 +809,37 @@ 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,
Instruction *Inst) {
if (Inst->getOpcode() == Instruction::OtherOps::PHI) {
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)) {
Expand Down Expand Up @@ -980,7 +977,6 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
};

std::map<BasicBlock *, std::vector<ValueAndPhi>> InsertableEdges;

auto &Is = CurrentBlock.getInstList();
for (auto &Inst : Is) {
if (Inst.getOpcode() != Instruction::OtherOps::PHI) {
Expand Down
22 changes: 22 additions & 0 deletions lib/DxilPIXPasses/PixPassHelpers.cpp
Original file line number Diff line number Diff line change
@@ -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 changes: 15 additions & 0 deletions lib/DxilPIXPasses/PixPassHelpers.h
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit ade0e24

Please sign in to comment.