Skip to content

Commit ad4a3ea

Browse files
authored
PIX: Entry point can be null for DXBC->DXIL hull shader (#3805)
This is a bit of a corner-case, but PIX tripped up on it while capturing an app under d3d11on12. PIX is probably the only client who cares about this case, since it's only relevant when DXBC->DXIL has been run (e.g. 11on12), and then examined via reflection and/or the PIX-specific passes. Here's the entry-point metadata provided by DXBC->DXIL for a representative case. It has a null entry point, but a non-null patch-constant function: !dx.entryPoints = !{!7} !7 = !{null, !"", !8, !2, !24} !24 = !{i32 0, i64 256, i32 3, !25} !25 = !{void ()* @pc_main, i32 3, i32 3, i32 2, i32 3, i32 3, float 0.000000e+00} (Documentation of DXBC->DXIL's operation in this case is here: https://github.com/Microsoft/DirectXShaderCompiler/blob/master/docs/DXIL.rst#hull-shader-representation) (PIX bug #32030124)
1 parent 12b8140 commit ad4a3ea

9 files changed

Lines changed: 25 additions & 14 deletions

lib/DxilPIXPasses/DxilAddPixelHitInstrumentation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ bool DxilAddPixelHitInstrumentation::runOnModule(Module &M) {
9595
SV_Position_ID = SV_Position->get()->GetID();
9696
}
9797

98-
auto EntryPointFunction = DM.GetEntryFunction();
98+
auto EntryPointFunction = PIXPassHelpers::GetEntryFunction(DM);
9999

100100
auto &EntryBlock = EntryPointFunction->getEntryBlock();
101101

102102
CallInst *HandleForUAV;
103103
{
104104
IRBuilder<> Builder(
105-
dxilutil::FirstNonAllocaInsertionPt(DM.GetEntryFunction()));
105+
dxilutil::FirstNonAllocaInsertionPt(PIXPassHelpers::GetEntryFunction(DM)));
106106

107107
HandleForUAV = PIXPassHelpers::CreateUAV(DM, Builder, 0, "PIX_CountUAV_Handle");
108108

lib/DxilPIXPasses/DxilAnnotateWithVirtualRegister.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
#include "llvm/Support/Casting.h"
3636
#include "llvm/Support/raw_ostream.h"
3737

38+
#include "PixPassHelpers.h"
39+
3840
#define DEBUG_TYPE "dxil-annotate-with-virtual-regs"
3941

4042
uint32_t CountStructMembers(llvm::Type const *pType) {
@@ -87,7 +89,7 @@ class DxilAnnotateWithVirtualRegister : public llvm::ModulePass {
8789
m_DM = &M.GetOrCreateDxilModule();
8890
m_uVReg = 0;
8991
m_MST.reset(new llvm::ModuleSlotTracker(&M));
90-
m_MST->incorporateFunction(*m_DM->GetEntryFunction());
92+
m_MST->incorporateFunction(*PIXPassHelpers::GetEntryFunction(*m_DM));
9193
}
9294
};
9395

@@ -106,7 +108,7 @@ bool DxilAnnotateWithVirtualRegister::runOnModule(llvm::Module &M) {
106108
}
107109

108110
std::uint32_t InstNum = 0;
109-
for (llvm::Instruction &I : llvm::inst_range(m_DM->GetEntryFunction())) {
111+
for (llvm::Instruction &I : llvm::inst_range(PIXPassHelpers::GetEntryFunction(*m_DM))) {
110112
if (!llvm::isa<llvm::DbgDeclareInst>(&I)) {
111113
pix_dxil::PixDxilInstNum::AddMD(M.getContext(), &I, InstNum++);
112114
}
@@ -124,11 +126,11 @@ bool DxilAnnotateWithVirtualRegister::runOnModule(llvm::Module &M) {
124126
*OSOverride << "\nBegin - dxil values to virtual register mapping\n";
125127
}
126128

127-
for (llvm::Instruction &I : llvm::inst_range(m_DM->GetEntryFunction())) {
129+
for (llvm::Instruction &I : llvm::inst_range(PIXPassHelpers::GetEntryFunction(*m_DM))) {
128130
AnnotateValues(&I);
129131
}
130132

131-
for (llvm::Instruction &I : llvm::inst_range(m_DM->GetEntryFunction())) {
133+
for (llvm::Instruction &I : llvm::inst_range(PIXPassHelpers::GetEntryFunction(*m_DM))) {
132134
AnnotateStore(&I);
133135
}
134136

lib/DxilPIXPasses/DxilDbgValueToDbgDeclare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ VariableRegisters::VariableRegisters(
793793
llvm::Module *M)
794794
: m_dbgLoc(dbgLoc)
795795
,m_Variable(Variable)
796-
, m_B(M->GetOrCreateDxilModule().GetEntryFunction()->getEntryBlock().begin())
796+
, m_B(PIXPassHelpers::GetEntryFunction(M->GetOrCreateDxilModule())->getEntryBlock().begin())
797797
, m_DbgDeclareFn(llvm::Intrinsic::getDeclaration(
798798
M, llvm::Intrinsic::dbg_declare))
799799
{

lib/DxilPIXPasses/DxilDebugInstrumentation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,8 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
887887

888888
// First record pointers to all instructions in the function:
889889
std::vector<Instruction *> AllInstructions;
890-
for (inst_iterator I = inst_begin(DM.GetEntryFunction()),
891-
E = inst_end(DM.GetEntryFunction());
890+
for (inst_iterator I = inst_begin(PIXPassHelpers::GetEntryFunction(DM)),
891+
E = inst_end(PIXPassHelpers::GetEntryFunction(DM));
892892
I != E; ++I) {
893893
AllInstructions.push_back(&*I);
894894
}
@@ -907,7 +907,7 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
907907
//
908908

909909
Instruction *firstInsertionPt =
910-
dxilutil::FirstNonAllocaInsertionPt(DM.GetEntryFunction());
910+
dxilutil::FirstNonAllocaInsertionPt(PIXPassHelpers::GetEntryFunction(DM));
911911
IRBuilder<> Builder(firstInsertionPt);
912912

913913
BuilderContext BC{M, DM, Ctx, HlslOP, Builder};
@@ -921,7 +921,7 @@ bool DxilDebugInstrumentation::runOnModule(Module &M) {
921921
// Explicitly name new blocks in order to provide stable names for testing purposes
922922
int NewBlockCounter = 0;
923923

924-
auto Fn = DM.GetEntryFunction();
924+
auto Fn = PIXPassHelpers::GetEntryFunction(DM);
925925
auto &Blocks = Fn->getBasicBlockList();
926926
for (auto &CurrentBlock : Blocks) {
927927
struct ValueAndPhi {

lib/DxilPIXPasses/DxilOutputColorBecomesConstant.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ bool DxilOutputColorBecomesConstant::runOnModule(Module &M) {
169169
pCBuf->SetSize(4);
170170

171171
Instruction *entryPointInstruction =
172-
&*(DM.GetEntryFunction()->begin()->begin());
172+
&*(PIXPassHelpers::GetEntryFunction(DM)->begin()->begin());
173173
IRBuilder<> Builder(entryPointInstruction);
174174

175175
// Create handle for the newly-added constant buffer (which is achieved via

lib/DxilPIXPasses/DxilPIXMeshShaderOutputInstrumentation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ bool DxilPIXMeshShaderOutputInstrumentation::runOnModule(Module &M)
222222
OP *HlslOP = DM.GetOP();
223223

224224
Instruction *firstInsertionPt =
225-
dxilutil::FirstNonAllocaInsertionPt(DM.GetEntryFunction());
225+
dxilutil::FirstNonAllocaInsertionPt(PIXPassHelpers::GetEntryFunction(DM));
226226
IRBuilder<> Builder(firstInsertionPt);
227227

228228
BuilderContext BC{M, DM, Ctx, HlslOP, Builder};

lib/DxilPIXPasses/PixPassHelpers.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ llvm::CallInst *CreateUAV(DxilModule &DM, IRBuilder<> &Builder,
166166
return handle;
167167
}
168168

169+
llvm::Function* GetEntryFunction(hlsl::DxilModule& DM) {
170+
if (DM.GetEntryFunction() != nullptr) {
171+
return DM.GetEntryFunction();
172+
}
173+
return DM.GetPatchConstantFunction();
174+
}
169175

170176
#ifdef PIX_DEBUG_DUMP_HELPER
171177

lib/DxilPIXPasses/PixPassHelpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace PIXPassHelpers
2323
llvm::CallInst* CreateHandleForResource(hlsl::DxilModule& DM, llvm::IRBuilder<>& Builder,
2424
hlsl::DxilResourceBase * resource,
2525
const char* name);
26-
26+
llvm::Function* GetEntryFunction(hlsl::DxilModule& DM);
2727
#ifdef PIX_DEBUG_DUMP_HELPER
2828
void Log(const char* format, ...);
2929
void LogPartialLine(const char* format, ...);

lib/HLSL/DxilContainerReflection.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,6 +2137,9 @@ static bool GetUnsignedVal(Value *V, uint32_t *pValue) {
21372137

21382138
void DxilShaderReflection::MarkUsedSignatureElements() {
21392139
Function *F = m_pDxilModule->GetEntryFunction();
2140+
if (F == nullptr) {
2141+
F = m_pDxilModule->GetPatchConstantFunction();
2142+
}
21402143
DXASSERT(F != nullptr, "else module load should have failed");
21412144
// For every loadInput/storeOutput, update the corresponding ReadWriteMask.
21422145
// F is a pointer to a Function instance

0 commit comments

Comments
 (0)