Skip to content

Instantly share code, notes, and snippets.

@el3ment
Created July 20, 2017 18:41
Show Gist options
  • Save el3ment/c34f8b958c28d946afea7578a1b984d5 to your computer and use it in GitHub Desktop.
Save el3ment/c34f8b958c28d946afea7578a1b984d5 to your computer and use it in GitHub Desktop.
# RenderDoc Python scripts, powered by IronPython 2.7.4.1000
# The 'pyrenderdoc' object is the Core class instance.
# The 'renderdoc' module is available, as the matching namespace in C#
from collections import defaultdict
lastDraw = pyrenderdoc.CurDrawcalls[len(pyrenderdoc.CurDrawcalls) - 1]
draws = []
for eventID in range(0, lastDraw.eventID): # lastDraw.eventID
curdraw = pyrenderdoc.GetDrawcall(eventID)
if curdraw == None:
continue
draws.append(curdraw)
_width = 1536
_height = 864
last_frame_sources = set()
last_frame_targets = set()
unique_nodes = set()
ordered_nodes = []
main_draw_path = []
textures = {}
depths = []
numdraws = defaultdict(int)
dot_file = open("C:/Users/rpottorff/game.dot", 'w')
dot_file.write("digraph G { graph[splines=ortho];\n")
prev_node = "start"
last_node_name = prev_node
for i, curdraw in enumerate(draws):
pyrenderdoc.SetEventID(None, curdraw.eventID)
this_frame_sources = set()
this_frame_targets = set()
node_name = curdraw.eventID
pyrenderdoc.CurPipelineState.GetOutputTargets()
out_edges = []
out_edges = [o.Id for o in pyrenderdoc.CurPipelineState.GetOutputTargets() if str(o.Id) != "0"]
#out_edges += [pyrenderdoc.CurPipelineState.GetDepthTarget().Id] if str(pyrenderdoc.CurPipelineState.GetDepthTarget().Id) != "0" else []
if str(pyrenderdoc.CurPipelineState.GetDepthTarget().Id) != "0":
depths.append(str(pyrenderdoc.GetTexture(pyrenderdoc.CurPipelineState.GetDepthTarget().Id).name))
in_edges =[]
for x in [x for x in pyrenderdoc.CurPipelineState.GetReadOnlyResources(renderdoc.ShaderStageType.Pixel) if str(x.Value[0].Id) != "0"]:
if str(x.Value[0].Id) != "0" and pyrenderdoc.GetTexture(x.Value[0].Id) is not None:
if str(pyrenderdoc.GetTexture(x.Value[0].Id).name) not in depths:
in_edges += [x.Value[0].Id]
has_targets = False
for n in out_edges:
tex = pyrenderdoc.GetTexture(n)
if tex and tex.width == _width and tex.height == _height:
textures[str(tex.name)] = tex
this_frame_targets.add(str(tex.name))
for n in in_edges:
tex = pyrenderdoc.GetTexture(n)
if tex and tex.width == _width and tex.height == _height:
textures[str(tex.name)] = tex
this_frame_sources.add(str(tex.name))
if this_frame_targets == last_frame_targets and this_frame_sources == last_frame_sources:
numdraws[str(last_node_name)] += 1
continue;
last_node_name = str(node_name)
for n in this_frame_targets:
unique_nodes.add(n)
dot_file.write("\"%s\" -> \"%s\" [color=blue]; \n" % (node_name, n))
last_frame_sources = this_frame_sources
last_frame_targets = this_frame_targets
for n in this_frame_sources:
unique_nodes.add(n)
dot_file.write("\"%s\" -> \"%s\" [color=green]; \n" % (n, node_name))
unique_nodes.add(str(node_name))
ordered_nodes.append(str(node_name))
unique_nodes.add(str(node_name))
main_draw_path.append((prev_node, node_name))
prev_node = node_name
for i, n in enumerate(unique_nodes):
style = "" if n != "Serialised Swap Chain Buffer" else "[color=lightgreen,style=filled]"
style = "[color=lightblue,style=filled]" if n == ordered_nodes[0] else style
if n in textures.keys():
texsave = renderdoc.TextureSave()
texsave.destType = renderdoc.FileType.PNG
texsave.id = textures[n].ID
texsave.sample.mapToArray = False
texsave.sample.sampleIndex = 0
texsave.slice.sliceIndex = 0
texsave.slice.slicesAsGrid = False
texsave.slice.sliceGridWidth = 1
texsave.slice.cubeCruciform = False
texsave.mip = 0
texsave.comp.blackPoint = 0.0
texsave.comp.whitePoint = 1.0
texsave.alpha = renderdoc.AlphaMapping.Discard
if n in depths:
texsave.comp.whitePoint = 0.15
texsave.channelExtract = 0
pyrenderdoc.Renderer.Invoke(lambda x: x.SaveTexture(texsave, "C:\\Users\\rpottorff\\" + n + ".png"))
style = '[width=2,height=2,fixedsize=true,image="C:\\\\Users\\\\rpottorff\\\\' + n + '.png",labelloc=b]'
if n in numdraws.keys():
style = '[label="' + n + '(' + str(numdraws[n]) + ')"]'
dot_file.write("\"%s\" %s;\n" % (n, style))
dot_file.write("subgraph cluster_0 { graph[style=invis];\n");
for node_name, next_node_name in main_draw_path:
dot_file.write("\"%s\" -> \"%s\" [style=invis]; \n" % (node_name, next_node_name))
dot_file.write("}\n")
dot_file.write("}")
dot_file.close()
print("done")
@el3ment
Copy link
Author

el3ment commented Jul 20, 2017

this was quick-and-dirty research code, so it is far from even remotely reasonable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment