Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import os
- config = {}
- config['py_lib_dir'] = 'C:\\Program Files\\Anaconda2\\Lib\\'
- config['save_dir'] = 'D:/gtav_playing_for_data/'
- config['dir_prefix'] = lambda logFilename : ''
- config['file_prefix'] = lambda logFilename : basename(logFilename)[:-4] + '_'
- config['gbufferpass_colortargets'] = 4
- config['gbufferpass_hasdepth'] = True
- config['gbuffer_names'] = ['gbuffer1', 'gbuffer2', 'gbuffer3', 'gbuffer4']
- config['hudpass_colortargets'] = 4 # number of color targets that identify the HUD pass
- config['hudpass_hasdepth'] = True # whether HUD pass has a depth target
- config['hudpass_drawcallname'] = '' # name of drawcall event #What should I use for this?
- sys.path.append(config['py_lib_dir'])
- frameInfo = pyrenderdoc.FrameInfo
- print(dir(frameInfo))
- print(dir(frameInfo.stats))
- #print(dir(frameInfo.stats.shaders[0].calls.imag))
- #print(frameInfo.debugMessages)
- #assert(len(frameInfo) == 1, 'expected only one frame.')
- #frameId = pyrenderdoc.CurFrame
- #print 'Extracting from frame %d' % frameId
- from os import mkdir
- from os.path import dirname, basename, exists
- dirPrefix = config['dir_prefix'](pyrenderdoc.LogFileName)
- filePrefix = config['file_prefix'](pyrenderdoc.LogFileName)
- saveDir = '%s/%s/' % (config['save_dir'], dirPrefix)
- if not exists(saveDir):
- mkdir(saveDir)
- pass
- print 'Output directory is %s' % saveDir
- print 'File prefix is %s' % filePrefix
- # Get drawcalls
- drawcalls = pyrenderdoc.GetDrawcalls()
- print 'Found %d drawcalls.' % len(drawcalls)
- def containsTargets(drawcallName, numColorTargets, hasDepthTarget):
- """ Determines if drawcall has multiple render targets by checking its name.
- The name is defined by renderdoc and contains information about render targets."""
- if hasDepthTarget:
- return drawcallName.find('(%d Targets + Depth)' % numColorTargets) >= 0
- else:
- return drawcallName.find('(%d Targets)' % numColorTargets) >= 0
- pass
- def findGbufferPass(numColorTargets, hasDepthTarget):
- """ Identifies the G-buffer pass. """
- gbufferEnd = 0
- gbufferIds = [i for i,call in enumerate(drawcalls) if containsTargets(call.name, numColorTargets, hasDepthTarget)]
- if len(gbufferIds) == 1:
- gbufferId = gbufferIds[0]
- gbufferCalls = drawcalls[gbufferId].children
- print 'G-buffer pass has %d drawcalls.' % len(gbufferCalls)
- gbufferEnd = drawcalls[gbufferId].children[-1].eventID # last drawcall of the G-buffer pass
- pass
- assert(gbufferEnd > 0, 'Did not find any drawcall with the specified G-buffer settings.')
- return gbufferId, gbufferEnd
- def findFinalPass(numColorTargets, hasDepthTarget, drawCallName):
- """ Returns the EventID of the pass that draws the final image (before HUD). """
- # Find last drawcall before HUD
- potentialHudIds = [i for i,call in enumerate(drawcalls) if containsTargets(call.name, numColorTargets, hasDepthTarget)]
- print 'Found %d potential HUD passes.' % len(potentialHudIds)
- colorpassIds = [i for i,call in enumerate(drawcalls) if containsTargets(call.name, 1, False)]
- a = colorpassIds[:]
- a.extend(potentialHudIds[:-3])
- assert(len(a) > 0, 'Found not enough potential final passes.')
- firstPotentialFinalId = max(a)
- finalPassId = 0
- return [call.eventID for call in drawcalls[-1:0:-1] if call.name.find(drawCallName) >= 0][1]
- #def getColorBuffers(frameId, eventId):
- def getColorBuffers(eventId):
- """ Sets the pipeline to eventId and returns the ids of bound render targets. """
- renderdoc.SetEventID(None, frameId, eventId)
- commonState = renderdoc.CurPipelineState
- outputTargets = commonState.GetOutputTargets()
- return [t for t in outputTargets if str(t) <> '0']
- #def initIDRendering(frameId, gbufferId, gbufferEnd):
- def initIDRendering(gbufferId, gbufferEnd):
- gbufferStart = drawcalls[gbufferId].children[0].eventID
- renderdoc.SetEventID(None, frameId, gbufferStart)
- renderdoc.SetIDRenderingEvents(frameId, gbufferStart, gbufferEnd)
- renderdoc.SetIDRendering(True)
- pass
- gbufferId, gbufferEnd = findGbufferPass(config['gbufferpass_colortargets'], config['gbufferpass_hasdepth'])
- print 'G-buffer pass is done at EID %d.' % gbufferEnd
- #bufferIds = getColorBuffers(frameId, gbufferEnd)
- bufferIds = getColorBuffers(gbufferEnd)
- # Save color targets
- for i,bid in enumerate(bufferIds):
- renderdoc.SaveTexture(bid, '{0}/{1}_{2}.png'.format(saveDir, filePrefix, config['gbuffer_names'][i]))
- # Save depth target
- depthTarget = renderdoc.CurPipelineState.GetDepthTarget()
- renderdoc.SaveTexture(depthTarget, '{0}/{1}_depth.exr'.format(saveDir, filePrefix))
- finalPassId = findFinalPass(config['hudpass_colortargets'], config['hudpass_hasdepth'], config['hudpass_drawcallname'])
- assert(finalPassId == 0, 'Found not enough potential final passes.')
- bufferIds = getColorBuffers(frameId, finalPassId)
- assert(len(bufferIds) == 1, 'Found %d potential final render targets.' % len(bufferIds))
- renderdoc.SaveTexture(bufferIds[0], '{0}/{1}_final.png'.format(saveDir, filePrefix))
- # now do the id rendering
- print 'Rendering ids...',
- initIDRendering(gbufferId, gbufferEnd)
- bufferIds = getColorBuffers(frameId, gbufferEnd)
- bufferNames = ['texture', 'mesh', 'shader', 'overflow']
- for i,bid in enumerate(bufferIds):
- renderdoc.SaveTexture(bid, '{0}/{1}_{2}.png'.format(saveDir, filePrefix, bufferNames[i]))
- renderdoc.HashTextures('{0}/{1}_tex.txt'.format(saveDir, filePrefix))
- renderdoc.HashBuffers('{0}/{1}_mesh.txt'.format(saveDir, filePrefix))
- renderdoc.HashShaders('{0}/{1}_shader.txt'.format(saveDir, filePrefix))
- print 'done.'
- #renderdoc.AppWindow.Close()
- ---------------------------------------------------------------------
- error:
- ['Equals', 'GetHashCode', 'GetType', 'MemberwiseClone', 'ReferenceEquals', 'ToString', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'captureTime', 'compressedFileSize', 'debugMessages', 'fileOffset', 'firstEvent', 'frameNumber', 'initDataSize', 'persistentSize', 'stats', 'uncompressedFileSize']
- ['Equals', 'GetHashCode', 'GetType', 'MemberwiseClone', 'ReferenceEquals', 'ToString', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'blends', 'constants', 'depths', 'dispatches', 'draws', 'indices', 'layouts', 'outputs', 'rasters', 'recorded', 'resources', 'samplers', 'shaders', 'updates', 'vertices']
- Output directory is D:/gtav_playing_for_data///
- File prefix is GTAVLauncher_2017.03.21_13.21.43_frame12060_
- Found 121 drawcalls.
- Traceback (most recent call last):
- File "<string>", line 103, in <module>
- File "<string>", line 66, in findGbufferPass
- UnboundLocalError: Local variable 'gbufferId' referenced before assignment.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement