Skip to content

Instantly share code, notes, and snippets.

@thatcosmonaut
Created October 1, 2020 03:04
Show Gist options
  • Save thatcosmonaut/4eb4b8d274ba3c8529fc4205c568eb96 to your computer and use it in GitHub Desktop.
Save thatcosmonaut/4eb4b8d274ba3c8529fc4205c568eb96 to your computer and use it in GitHub Desktop.
# RenderDoc Python console, powered by python 3.8.5.
# The 'pyrenderdoc' object is the current CaptureContext instance.
# The 'renderdoc' and 'qrenderdoc' modules are available.
# Documentation is available: https://renderdoc.org/docs/python_api/index.html
# Alias renderdoc for legibility
rd = renderdoc
def saveColorBuffer(controller, drawCall, drawCallCounter):
controller.SetFrameEvent(drawCall.eventId, True)
texsave = rd.TextureSave()
texsave.resourceId = drawCall.outputs[0]
if texsave.resourceId == rd.ResourceId.Null():
return
filename = "drawcall_" + str(int(drawCallCounter)).rjust(5, '0')
print("Saving images of %s at %d: %s" % (filename, drawCall.eventId, drawCall.name))
texsave.alpha = rd.AlphaMapping.BlendToCheckerboard
texsave.mip = 0
texsave.slice.sliceIndex = 0
texsave.destType = rd.FileType.PNG
controller.SaveTexture(texsave, filename + ".png")
def saveAllDrawCalls(controller):
drawCallCounter = 0
for d in controller.GetDrawcalls():
for child in d.children:
saveColorBuffer(controller, child, drawCallCounter)
drawCallCounter += 1
def loadCapture(filename):
# Open a capture file handle
cap = rd.OpenCaptureFile()
# Open a particular file - see also OpenBuffer to load from memory
status = cap.OpenFile(filename, '', None)
# Make sure the file opened successfully
if status != rd.ReplayStatus.Succeeded:
raise RuntimeError("Couldn't open file: " + str(status))
# Make sure we can replay
if not cap.LocalReplaySupport():
raise RuntimeError("Capture cannot be replayed")
# Initialise the replay
status,controller = cap.OpenCapture(rd.ReplayOptions(), None)
if status != rd.ReplayStatus.Succeeded:
raise RuntimeError("Couldn't initialise replay: " + str(status))
return (cap, controller)
if 'pyrenderdoc' in globals():
pyrenderdoc.Replay().BlockInvoke(saveAllDrawCalls)
else:
rd.InitialiseReplay(rd.GlobalEnvironment(), [])
if len(sys.argv) <= 1:
print('Usage: python3 {} filename.rdc'.format(sys.argv[0]))
sys.exit(0)
cap,controller = loadCapture(sys.argv[1])
saveAllDrawCalls(controller)
controller.Shutdown()
cap.Shutdown()
rd.ShutdownReplay()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment