Advertisement
lamiastella

removing bufferId

Mar 28th, 2017
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.83 KB | None | 0 0
  1. import sys
  2. import os
  3.  
  4. config = {}
  5. config['py_lib_dir']  = 'C:\\Program Files\\Anaconda2\\Lib\\'
  6. config['save_dir']    = 'D:/gtav_playing_for_data/'
  7. config['dir_prefix']  = lambda logFilename : ''      
  8. config['file_prefix'] = lambda logFilename : basename(logFilename)[:-4] + '_'
  9.  
  10. config['gbufferpass_colortargets'] = 4  
  11. config['gbufferpass_hasdepth']     = True
  12.  
  13. config['gbuffer_names'] = ['gbuffer1', 'gbuffer2', 'gbuffer3', 'gbuffer4']
  14. config['hudpass_colortargets'] = 4 # number of color targets that identify the HUD pass
  15. config['hudpass_hasdepth']     = True # whether HUD pass has a depth target
  16. config['hudpass_drawcallname'] = '' # name of drawcall event #What should I use for this?
  17.  
  18. sys.path.append(config['py_lib_dir'])
  19.  
  20. frameInfo = pyrenderdoc.FrameInfo
  21. print(dir(frameInfo))
  22. print(dir(frameInfo.stats))
  23. #print(dir(frameInfo.stats.shaders[0].calls.imag))
  24. #print(frameInfo.debugMessages)
  25. #assert(len(frameInfo) == 1, 'expected only one frame.')
  26. #frameId   = pyrenderdoc.CurFrame
  27. #print 'Extracting from frame %d' % frameId
  28.  
  29. from os import mkdir
  30. from os.path import dirname, basename, exists
  31. dirPrefix  = config['dir_prefix'](pyrenderdoc.LogFileName)
  32. filePrefix = config['file_prefix'](pyrenderdoc.LogFileName)
  33. saveDir    = '%s/%s/' % (config['save_dir'], dirPrefix)
  34. if not exists(saveDir):
  35.     mkdir(saveDir)
  36.     pass
  37. print 'Output directory is %s' % saveDir
  38. print 'File prefix is %s' % filePrefix
  39.  
  40. # Get drawcalls
  41. drawcalls = pyrenderdoc.GetDrawcalls()
  42. print 'Found %d drawcalls.' % len(drawcalls)
  43.  
  44. def containsTargets(drawcallName, numColorTargets, hasDepthTarget):
  45.     """ Determines if drawcall has multiple render targets by checking its name.
  46.         The name is defined by renderdoc and contains information about render targets.""" 
  47.     if hasDepthTarget:
  48.         return drawcallName.find('(%d Targets + Depth)' % numColorTargets) >= 0    
  49.     else:      
  50.         return drawcallName.find('(%d Targets)' % numColorTargets) >= 0    
  51.     pass
  52.  
  53.  
  54. def findGbufferPass(numColorTargets, hasDepthTarget):
  55.     """ Identifies the G-buffer pass. """
  56.     gbufferEnd = 0
  57.     gbufferIds = [i for i,call in enumerate(drawcalls) if containsTargets(call.name, numColorTargets, hasDepthTarget)]
  58.     if len(gbufferIds) == 1:
  59.         gbufferId    = gbufferIds[0]
  60.         gbufferCalls = drawcalls[gbufferId].children
  61.         print 'G-buffer pass has %d drawcalls.' % len(gbufferCalls)
  62.         gbufferEnd   = drawcalls[gbufferId].children[-1].eventID # last drawcall of the G-buffer pass
  63.         pass
  64.    
  65.     assert(gbufferEnd > 0, 'Did not find any drawcall with the specified G-buffer settings.')
  66.     return gbufferId, gbufferEnd
  67.    
  68. def findFinalPass(numColorTargets, hasDepthTarget, drawCallName):
  69.     """ Returns the EventID of the pass that draws the final image (before HUD). """
  70.  
  71.     # Find last drawcall before HUD
  72.     potentialHudIds = [i for i,call in enumerate(drawcalls) if containsTargets(call.name, numColorTargets, hasDepthTarget)]
  73.     print 'Found %d potential HUD passes.' % len(potentialHudIds)
  74.  
  75.     colorpassIds = [i for i,call in enumerate(drawcalls) if containsTargets(call.name, 1, False)]
  76.  
  77.     a = colorpassIds[:]
  78.     a.extend(potentialHudIds[:-3])
  79.     assert(len(a) > 0, 'Found not enough potential final passes.')
  80.     firstPotentialFinalId = max(a)
  81.  
  82.     finalPassId = 0
  83.     return [call.eventID for call in drawcalls[-1:0:-1] if call.name.find(drawCallName) >= 0][1]
  84.    
  85. #def getColorBuffers(frameId, eventId):
  86. def getColorBuffers(eventId):
  87.  
  88.     """ Sets the pipeline to eventId and returns the ids of bound render targets. """
  89.     renderdoc.SetEventID(None, frameId, eventId)
  90.     commonState   = renderdoc.CurPipelineState
  91.     outputTargets = commonState.GetOutputTargets()
  92.     return [t for t in outputTargets if str(t) <> '0']
  93.  
  94. #def initIDRendering(frameId, gbufferId, gbufferEnd):
  95. def initIDRendering(gbufferId, gbufferEnd):
  96.     gbufferStart = drawcalls[gbufferId].children[0].eventID
  97.     renderdoc.SetEventID(None, frameId, gbufferStart)
  98.     renderdoc.SetIDRenderingEvents(frameId, gbufferStart, gbufferEnd)
  99.     renderdoc.SetIDRendering(True)
  100.     pass
  101.  
  102.    
  103. gbufferId, gbufferEnd = findGbufferPass(config['gbufferpass_colortargets'], config['gbufferpass_hasdepth'])
  104. print 'G-buffer pass is done at EID %d.' % gbufferEnd
  105. #bufferIds = getColorBuffers(frameId, gbufferEnd)
  106. bufferIds = getColorBuffers(gbufferEnd)
  107.  
  108. # Save color targets
  109. for i,bid in enumerate(bufferIds):
  110.     renderdoc.SaveTexture(bid, '{0}/{1}_{2}.png'.format(saveDir, filePrefix, config['gbuffer_names'][i]))
  111.  
  112. # Save depth target
  113. depthTarget = renderdoc.CurPipelineState.GetDepthTarget()
  114. renderdoc.SaveTexture(depthTarget, '{0}/{1}_depth.exr'.format(saveDir, filePrefix))
  115.  
  116. finalPassId = findFinalPass(config['hudpass_colortargets'], config['hudpass_hasdepth'], config['hudpass_drawcallname'])
  117. assert(finalPassId == 0, 'Found not enough potential final passes.')
  118.  
  119. bufferIds = getColorBuffers(frameId, finalPassId)
  120. assert(len(bufferIds) == 1, 'Found %d potential final render targets.' % len(bufferIds))
  121. renderdoc.SaveTexture(bufferIds[0], '{0}/{1}_final.png'.format(saveDir, filePrefix))
  122.  
  123. # now do the id rendering
  124. print 'Rendering ids...',
  125. initIDRendering(gbufferId, gbufferEnd)
  126. bufferIds   = getColorBuffers(frameId, gbufferEnd)
  127. bufferNames = ['texture', 'mesh', 'shader', 'overflow']
  128.  
  129. for i,bid in enumerate(bufferIds):
  130.     renderdoc.SaveTexture(bid, '{0}/{1}_{2}.png'.format(saveDir, filePrefix, bufferNames[i]))
  131.  
  132. renderdoc.HashTextures('{0}/{1}_tex.txt'.format(saveDir, filePrefix))
  133. renderdoc.HashBuffers('{0}/{1}_mesh.txt'.format(saveDir, filePrefix))
  134. renderdoc.HashShaders('{0}/{1}_shader.txt'.format(saveDir, filePrefix))
  135.  
  136. print 'done.'
  137. #renderdoc.AppWindow.Close()
  138.  
  139. ---------------------------------------------------------------------
  140. error:
  141. ['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']
  142. ['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']
  143. Output directory is D:/gtav_playing_for_data///
  144. File prefix is GTAVLauncher_2017.03.21_13.21.43_frame12060_
  145. Found 121 drawcalls.
  146. Traceback (most recent call last):
  147.   File "<string>", line 103, in <module>
  148.   File "<string>", line 66, in findGbufferPass
  149. UnboundLocalError: Local variable 'gbufferId' referenced before assignment.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement