Skip to content

Commit ee4a2c4

Browse files
committed
Added OutputGraph to output control flow as a graphvis text file
1 parent 744c9a2 commit ee4a2c4

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

renderdoc/driver/shaders/dxil/dxil_controlflow.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,38 @@ already computed
7171

7272
namespace DXIL
7373
{
74+
void OutputGraph(const char *const name, const ControlFlow *graph)
75+
{
76+
ControlFlow::BlockArray divergentBlocks = graph->GetDivergentBlocks();
77+
rdcarray<ConvergentBlockData> convergentBlocks = graph->GetConvergentBlocks();
78+
79+
rdcstr fname = StringFormat::Fmt("%s.txt", name);
80+
FILE *f = FileIO::fopen(fname.c_str(), FileIO::WriteText);
81+
rdcstr line = StringFormat::Fmt("digraph %s {\n", name);
82+
fprintf(f, line.c_str());
83+
for(uint32_t from : graph->m_Blocks)
84+
{
85+
line = StringFormat::Fmt("%u", from);
86+
if(divergentBlocks.contains(from))
87+
line += StringFormat::Fmt(" [shape=diamond color=red]");
88+
line += ";\n";
89+
90+
for(uint32_t to : graph->m_BlockOutLinks[from])
91+
line += StringFormat::Fmt("%u -> %u [weight=1];\n", from, to);
92+
93+
fprintf(f, line.c_str());
94+
}
95+
for(ConvergentBlockData data : convergentBlocks)
96+
{
97+
line = StringFormat::Fmt("%u -> %u [weight=0 style=dashed color=blue constraint=false];\n",
98+
data.first, data.second, data.first, data.second);
99+
100+
fprintf(f, line.c_str());
101+
}
102+
fprintf(f, "}\n");
103+
FileIO::fclose(f);
104+
}
105+
74106
bool ControlFlow::IsBlockConnected(const size_t pathsType, uint32_t from, uint32_t to) const
75107
{
76108
const rdcarray<BlockPath> &paths = m_PathSets[pathsType];
@@ -627,6 +659,7 @@ void ControlFlow::Construct(const rdcarray<rdcpair<uint32_t, uint32_t>> &links)
627659
}
628660
RDCLOG("Convergent Blocks: %s", output.c_str());
629661
}
662+
// OutputGraph("dxil_cfg", this);
630663

631664
// Clear temporary data
632665
m_TracedBlocks.clear();
@@ -1813,6 +1846,8 @@ TEST_CASE("DXIL Control Flow", "[dxil][controlflow]")
18131846
REQUIRE(expectedCountDivergentBlocks == convergentBlocks.count());
18141847
CheckDivergentBlocks(expectedConvergentBlocks, divergentBlocks);
18151848
CheckConvergentBlocks(expectedConvergentBlocks, convergentBlocks);
1849+
1850+
// OutputGraph("complex_case", &controlFlow);
18161851
}
18171852
};
18181853
};

renderdoc/driver/shaders/dxil/dxil_controlflow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,7 @@ struct ControlFlow
8787
rdcarray<uint32_t> m_DivergentBlocks;
8888
rdcarray<ConvergentBlockData> m_ConvergentBlocks;
8989
mutable rdcarray<rdcarray<ConnectionState>> m_Connections;
90+
91+
friend void OutputGraph(const char *const name, const ControlFlow *graph);
9092
};
9193
}; // namespace DXIL

0 commit comments

Comments
 (0)