def GetRenderTarget(self, renderTargetFormat, width, height, locked = False): i = 0 hashKey = self.__Hash(renderTargetFormat, width, height, i) while self.lockedTargets.get(hashKey): i += 1 hashKey = self.__Hash(renderTargetFormat, width, height, i) rt = self.targets.get(hashKey) if rt and locked: self.lockedTargets[hashKey] = rt reapTasklet = None while not rt: try: rt = trinity.Tr2RenderTarget(width, height, 1, renderTargetFormat) self.targets[hashKey] = rt if locked: self.lockedTargets[hashKey] = rt reapTasklet = uthread.new(self.Reaper_t, hashKey).context = 'RenderTargetMananger::Reaper' except (trinity.E_OUTOFMEMORY, trinity.D3DERR_OUTOFVIDEOMEMORY): raise except trinity.DeviceLostError: rt = None blue.synchro.SleepWallclock(100) sleepCycles = self.targetsSleepCycles.get(hashKey, 0) self.targetsSleepCycles[hashKey] = sleepCycles + 1 if reapTasklet: uthread.schedule(reapTasklet) return rt
def GetRenderTarget(self, renderTargetFormat, width, height, locked=False): i = 0 hashKey = self.__Hash(renderTargetFormat, width, height, i) while self.lockedTargets.get(hashKey): i += 1 hashKey = self.__Hash(renderTargetFormat, width, height, i) rt = self.targets.get(hashKey) if rt and locked: self.lockedTargets[hashKey] = rt reapTasklet = None while not rt: try: rt = trinity.Tr2RenderTarget(width, height, 1, renderTargetFormat) self.targets[hashKey] = rt if locked: self.lockedTargets[hashKey] = rt reapTasklet = uthread.new( self.Reaper_t, hashKey).context = 'RenderTargetMananger::Reaper' except (trinity.E_OUTOFMEMORY, trinity.D3DERR_OUTOFVIDEOMEMORY): raise except trinity.DeviceLostError: rt = None blue.synchro.SleepWallclock(100) sleepCycles = self.targetsSleepCycles.get(hashKey, 0) self.targetsSleepCycles[hashKey] = sleepCycles + 1 if reapTasklet: uthread.schedule(reapTasklet) return rt
def Execute(self, callBack=None): """ Executs this test in a tasklet. Side-effect: Clears any previous test results """ self.results.clear() self.testTasklet = uthread.new(self.Execute_t, callBack) uthread.schedule(self.testTasklet)
def CreateTargetAvatarFromDoll(self, doll): self.doingAvatar = True self.__CreateNudeAvatar(doll) def PrepareAvatar_t(): try: self.SetShader_t(self.__avatar, [], BK_SHADERRES, False) finally: self.doingAvatar = False self.avatarShaderSettingTasklet = uthread.new(PrepareAvatar_t) uthread.schedule(self.avatarShaderSettingTasklet)
def ApplyShaders(self, doll, meshes): self.wrinkleFx = [] if not meshes: return skinSpotLightShadowsActive = PD.SkinSpotLightShadows.instance is not None skinLightmapRendererActive = doll.skinLightmapRenderer is not None tasklets = [] asyncMeshes = {} def DoClothMesh(mesh): isHair = False isHair = self.BindClothShaders(mesh, doll, isHair) if type(mesh.effect) == trinity.Tr2Effect: loadingResources = [] if mesh.effect and type(mesh.effect) == trinity.Tr2Effect: loadingResources.append(mesh.effect.effectResource) if mesh.effectReversed: loadingResources.append(mesh.effectReversed.effectResource) PD.WaitForAll(loadingResources, lambda x: x.isLoading) if mesh.effect: mesh.effect.PopulateParameters() if mesh.effectReversed: mesh.effectReversed.PopulateParameters() if PD.SkinSpotLightShadows.instance is not None: PD.SkinSpotLightShadows.instance.CreateEffectParamsForMesh(mesh, isClothMesh=True) if isHair and hasattr(mesh, 'useTransparentBatches'): mesh.useTransparentBatches = True for mesh in iter(meshes): if type(mesh) is trinity.Tr2ClothingActor: t = uthread.new(DoClothMesh, mesh) else: if skinSpotLightShadowsActive or skinLightmapRendererActive: asyncMeshes[mesh] = False if PD.DOLL_PARTS.HEAD in mesh.name: t = uthread.new(self.SetInteriorShader, *(asyncMeshes, mesh, self.wrinkleFx, doll)) else: t = uthread.new(self.SetInteriorShader, *(asyncMeshes, mesh, None, doll)) tasklets.append(t) uthread.schedule(t) PD.WaitForAll(tasklets, lambda x: x.alive) for mesh in asyncMeshes.iterkeys(): if skinSpotLightShadowsActive: PD.SkinSpotLightShadows.instance.CreateEffectParamsForMesh(mesh) if skinLightmapRendererActive and asyncMeshes[mesh]: doll.skinLightmapRenderer.BindLightmapShader(mesh)
def ApplyShaders(self, doll, meshes): self.wrinkleFx = [] if not meshes: return skinSpotLightShadowsActive = lambda : SkinSpotLightShadows.instance is not None skinLightmapRendererActive = lambda : doll.skinLightmapRenderer is not None tasklets = [] asyncMeshes = {} def DoClothMesh(mesh): isHair = False isHair = self.BindClothShaders(mesh, doll, isHair) if type(mesh.effect) == trinity.Tr2Effect: loadingResources = [] if mesh.effect and type(mesh.effect) == trinity.Tr2Effect: loadingResources.append(mesh.effect.effectResource) if mesh.effectReversed: loadingResources.append(mesh.effectReversed.effectResource) pdCf.WaitForAll(loadingResources, lambda x: x.isLoading) if mesh.effect: mesh.effect.PopulateParameters() if mesh.effectReversed: mesh.effectReversed.PopulateParameters() if SkinSpotLightShadows.instance is not None: SkinSpotLightShadows.instance.CreateEffectParamsForMesh(mesh, isClothMesh=True) if isHair and hasattr(mesh, 'useTransparentBatches'): mesh.useTransparentBatches = True for mesh in iter(meshes): if type(mesh) is trinity.Tr2ClothingActor: t = uthread.new(DoClothMesh, mesh) else: if skinSpotLightShadowsActive() or skinLightmapRendererActive(): asyncMeshes[mesh] = False if pdDef.DOLL_PARTS.HEAD in mesh.name: t = uthread.new(self.SetInteriorShader, *(asyncMeshes, mesh, self.wrinkleFx, doll)) else: t = uthread.new(self.SetInteriorShader, *(asyncMeshes, mesh, None, doll)) tasklets.append(t) uthread.schedule(t) pdCf.WaitForAll(tasklets, lambda x: x.alive) for mesh in asyncMeshes.iterkeys(): if skinSpotLightShadowsActive(): SkinSpotLightShadows.instance.CreateEffectParamsForMesh(mesh) if skinLightmapRendererActive() and asyncMeshes[mesh]: doll.skinLightmapRenderer.BindLightmapShader(mesh)
def RunSymmetricalSingleDollLODTest(coldCache=True, iterations=20, respaths=None, printStatistics=True): def fun(): results = PerformanceTestResults() key = 'Loading Factory' results.PunchIn(key) sTime = blue.os.GetWallclockTime() factory = PD.Factory() if respaths: factory.clothSimulationActive = True factory.WaitUntilLoaded() eTime = blue.os.GetWallclockTime() results.PunchOut(key) scene = SetupScene(usePrepass=True) onTestExecution = None if respaths: respathsIterator = itertools.cycle(respaths) def onTestExecution(x): x.resPath = respathsIterator.next() try: bm = Benchmarker(factory, scene, usePrepass=True) bm.clearCacheOnEachIteration = coldCache bm.iterations = iterations test0 = SingleDollTest(0, 2) bm.SetTest(test0) bm.ExecuteTest(onTestExecution) if printStatistics: import pprint pprint.pprint(bm.GetAnalyzedResults()) test1 = SingleDollTest(2, 0) bm.SetTest(test1) bm.ExecuteTest(onTestExecution) if printStatistics: pprint.pprint(bm.GetAnalyzedResults()) pprint.pprint(results) finally: trinity.renderJobs.UnscheduleByName(DEFAULT_PREPASS_RENDERJOB_NAME) testTasklet = uthread.new(fun) uthread.schedule(testTasklet) try: while testTasklet.alive: PD.Yield() except RuntimeError: PD.BeFrameNice()
def RunCrowdSpawnTest(coldCache=True, iterations=20, respaths=None, maxLodQueueActive=1, debugMode=False, nrPerLod=None): def fun(): results = PerformanceTestResults() key = 'Loading Factory' results.PunchIn(key) sTime = blue.os.GetWallclockTime() factory = PD.Factory() if respaths: factory.clothSimulationActive = True factory.WaitUntilLoaded() eTime = blue.os.GetWallclockTime() results.PunchOut(key) scene = SetupScene(usePrepass=True) onTestExecution = None try: import pprint bm = Benchmarker(factory, scene, usePrepass=True) bm.clearCacheOnEachIteration = coldCache bm.iterations = 1 if debugMode else iterations totalDolls = sum(nrPerLod) if nrPerLod else 32 lod0Dolls = nrPerLod[0] if nrPerLod else 8 lod1Dolls = nrPerLod[1] if nrPerLod else 8 test0 = MultiDollTest(totalDolls, lod0Dolls, lod1Dolls, maxLodQueueActive=1, resPaths=respaths, debugMode=debugMode) bm.SetTest(test0) bm.ExecuteTest(onTestExecution) pprint.pprint(bm.GetAnalyzedResults()) finally: if not debugMode: trinity.renderJobs.UnscheduleByName( DEFAULT_PREPASS_RENDERJOB_NAME) testTasklet = uthread.new(fun) uthread.schedule(testTasklet) try: while testTasklet.alive: PD.Yield() except RuntimeError: PD.BeFrameNice()
def RunSymmetricalSingleDollLODTest(coldCache = True, iterations = 20, respaths = None, printStatistics = True): def fun(): results = PerformanceTestResults() key = 'Loading Factory' results.PunchIn(key) sTime = blue.os.GetWallclockTime() factory = PD.Factory() if respaths: factory.clothSimulationActive = True factory.WaitUntilLoaded() eTime = blue.os.GetWallclockTime() results.PunchOut(key) scene = SetupScene(usePrepass=True) onTestExecution = None if respaths: respathsIterator = itertools.cycle(respaths) def onTestExecution(x): x.resPath = respathsIterator.next() try: bm = Benchmarker(factory, scene, usePrepass=True) bm.clearCacheOnEachIteration = coldCache bm.iterations = iterations test0 = SingleDollTest(0, 2) bm.SetTest(test0) bm.ExecuteTest(onTestExecution) if printStatistics: import pprint pprint.pprint(bm.GetAnalyzedResults()) test1 = SingleDollTest(2, 0) bm.SetTest(test1) bm.ExecuteTest(onTestExecution) if printStatistics: pprint.pprint(bm.GetAnalyzedResults()) pprint.pprint(results) finally: trinity.renderJobs.UnscheduleByName(DEFAULT_PREPASS_RENDERJOB_NAME) testTasklet = uthread.new(fun) uthread.schedule(testTasklet) try: while testTasklet.alive: PD.Yield() except RuntimeError: PD.BeFrameNice()
def RunIncarnaCrowdTest(coldCache=True, iterations=20, respaths=None, maxLodQueueActive=1, debugMode=False): def fun(): results = PerformanceTestResults() key = 'Loading Factory' results.PunchIn(key) sTime = blue.os.GetWallclockTime() factory = PD.Factory() if respaths: factory.clothSimulationActive = True factory.WaitUntilLoaded() eTime = blue.os.GetWallclockTime() results.PunchOut(key) scene = SetupScene( sceneFile= 'res:/Graphics/Character/Global/DataUsedForTests/referenceEstablishment.red', usePrepass=True) onTestExecution = None try: import pprint bm = Benchmarker(factory, scene, usePrepass=True) bm.clearCacheOnEachIteration = coldCache bm.iterations = 1 if debugMode else iterations test0 = MultiDollTest(32, 8, 16, maxLodQueueActive=1, resPaths=respaths, debugMode=debugMode) bm.SetTest(test0) bm.ExecuteTest(onTestExecution) pprint.pprint(bm.GetAnalyzedResults()) finally: if not debugMode: trinity.renderJobs.UnscheduleByName( DEFAULT_PREPASS_RENDERJOB_NAME) testTasklet = uthread.new(fun) uthread.schedule(testTasklet) try: while testTasklet.alive: PD.Yield() except RuntimeError: PD.BeFrameNice()
def CreateTargetAvatarFromDoll(self, doll): """ Creates the target avatar that is used for projecting the decal onto based on the doll instance. That avatar is completely nude, but matches the doll's blendshapes. The projection baking shader is then applied to this avatar. It is enough to set avatar once when baking out multiple decals that will project onto it. """ self.doingAvatar = True self.__CreateNudeAvatar(doll) def PrepareAvatar_t(): try: self.SetShader_t(self.__avatar, [], BK_SHADERRES, False) finally: self.doingAvatar = False self.avatarShaderSettingTasklet = uthread.new(PrepareAvatar_t) uthread.schedule(self.avatarShaderSettingTasklet)
def RunCrowdSpawnTest(coldCache = True, iterations = 20, respaths = None, maxLodQueueActive = 1, debugMode = False, nrPerLod = None): def fun(): results = PerformanceTestResults() key = 'Loading Factory' results.PunchIn(key) sTime = blue.os.GetWallclockTime() factory = PD.Factory() if respaths: factory.clothSimulationActive = True factory.WaitUntilLoaded() eTime = blue.os.GetWallclockTime() results.PunchOut(key) scene = SetupScene(usePrepass=True) onTestExecution = None try: import pprint bm = Benchmarker(factory, scene, usePrepass=True) bm.clearCacheOnEachIteration = coldCache bm.iterations = 1 if debugMode else iterations totalDolls = sum(nrPerLod) if nrPerLod else 32 lod0Dolls = nrPerLod[0] if nrPerLod else 8 lod1Dolls = nrPerLod[1] if nrPerLod else 8 test0 = MultiDollTest(totalDolls, lod0Dolls, lod1Dolls, maxLodQueueActive=1, resPaths=respaths, debugMode=debugMode) bm.SetTest(test0) bm.ExecuteTest(onTestExecution) pprint.pprint(bm.GetAnalyzedResults()) finally: if not debugMode: trinity.renderJobs.UnscheduleByName(DEFAULT_PREPASS_RENDERJOB_NAME) testTasklet = uthread.new(fun) uthread.schedule(testTasklet) try: while testTasklet.alive: PD.Yield() except RuntimeError: PD.BeFrameNice()
def RunIncarnaCrowdTest(coldCache = True, iterations = 20, respaths = None, maxLodQueueActive = 1, debugMode = False): def fun(): results = PerformanceTestResults() key = 'Loading Factory' results.PunchIn(key) sTime = blue.os.GetWallclockTime() factory = PD.Factory() if respaths: factory.clothSimulationActive = True factory.WaitUntilLoaded() eTime = blue.os.GetWallclockTime() results.PunchOut(key) scene = SetupScene(sceneFile='res:/Graphics/Character/Global/DataUsedForTests/referenceEstablishment.red', usePrepass=True) onTestExecution = None try: import pprint bm = Benchmarker(factory, scene, usePrepass=True) bm.clearCacheOnEachIteration = coldCache bm.iterations = 1 if debugMode else iterations test0 = MultiDollTest(32, 8, 16, maxLodQueueActive=1, resPaths=respaths, debugMode=debugMode) bm.SetTest(test0) bm.ExecuteTest(onTestExecution) pprint.pprint(bm.GetAnalyzedResults()) finally: if not debugMode: trinity.renderJobs.UnscheduleByName(DEFAULT_PREPASS_RENDERJOB_NAME) testTasklet = uthread.new(fun) uthread.schedule(testTasklet) try: while testTasklet.alive: PD.Yield() except RuntimeError: PD.BeFrameNice()
def Execute(self, callBack = None): self.results.clear() self.testTasklet = uthread.new(self.Execute_t, callBack) uthread.schedule(self.testTasklet)