Bug 51328

Summary: _mesa_unpack_uint_z_row and _mesa_unpack_depth_span are slow
Product: Mesa Reporter: Javantea <jvoss>
Component: Mesa coreAssignee: mesa-dev
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium CC: stereotype441
Version: git   
Hardware: All   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: Patch for low performance in Psychonauts

Description Javantea 2012-06-22 02:45:01 UTC
Created attachment 63337 [details]
Patch for low performance in Psychonauts

Psychonauts, part of the Humble Indie Bundle 5, uses 100% cpu and runs at approximately 1 frame per second on Sandy Bridge and Ivy Bridge. sysprof and gdb showed that two functions caused the slowdown.

The stack trace for what is calling these functions are:
#0 0xf5ae1bf9 in unpack_uint_z_X8_Z24 () from /opt/xorg/lib32/dri/libdricore.so
#1 0xf5ae1eeb in _mesa_unpack_uint_z_row () from /opt/xorg/lib32/dri/libdricore.so
#2 0xf5b2a1a1 in fast_read_depth_pixels () from /opt/xorg/lib32/dri/libdricore.so
#3 0xf5b2a274 in read_depth_pixels () from /opt/xorg/lib32/dri/libdricore.so
#4 0xf5b2b70a in _mesa_readpixels () from /opt/xorg/lib32/dri/libdricore.so
#5 0xf5d5ff70 in intelReadPixels () from /opt/xorg/lib32/dri//i965_dri.so
#6 0xf5b2bbc9 in _mesa_ReadnPixelsARB () from /opt/xorg/lib32/dri/libdricore.so
#7 0xf5b2bc22 in _mesa_ReadPixels () from /opt/xorg/lib32/dri/libdricore.so
#8 0xf5c6d307 in _mesa_meta_BlitFramebuffer () from /opt/xorg/lib32/dri/libdricore.so
#9 0xf5d579a4 in intel_blit_framebuffer () from /opt/xorg/lib32/dri//i965_dri.so
#10 0xf5ac78fb in _mesa_BlitFramebufferEXT () from /opt/xorg/lib32/dri/libdricore.so
#11 0x08187c6e in EOpenGLRenderer::glBlitFramebufferEXT(int, int, int, int, int, int, int, int, unsigned int, unsigned int) const ()
#12 0x0818aa66 in ERenderer::RestoreRenderTarget() ()
#13 0x082f543a in GameApp::CreateDownsampledZBuffer() ()
#14 0x082f395d in GameApp::RenderSceneGeometry() ()
#15 0x082d898e in GameApp::RenderFrame() ()
#16 0x08522ad8 in main ()

and

#0 0xf5adf65d in _mesa_unpack_depth_span () from /opt/xorg/lib32/dri/libdricore.so
#1 0xf5b1aa05 in _mesa_texstore_x8_z24 () from /opt/xorg/lib32/dri/libdricore.so
#2 0xf5b2198d in _mesa_texstore () from /opt/xorg/lib32/dri/libdricore.so
#3 0xf5b21cd6 in store_texsubimage () from /opt/xorg/lib32/dri/libdricore.so
#4 0xf5b21e59 in _mesa_store_teximage () from /opt/xorg/lib32/dri/libdricore.so
#5 0xf5d20b85 in intelTexImage () from /opt/xorg/lib32/dri//i965_dri.so
#6 0xf5b0dd2d in teximage () from /opt/xorg/lib32/dri/libdricore.so
#7 0xf5b0def5 in _mesa_TexImage2D () from /opt/xorg/lib32/dri/libdricore.so
#8 0xf5c2bc56 in setup_drawpix_texture () from /opt/xorg/lib32/dri/libdricore.so
#9 0xf5c2c9b2 in _mesa_meta_BlitFramebuffer () from /opt/xorg/lib32/dri/libdricore.so
#10 0xf5d167fe in intel_blit_framebuffer () from /opt/xorg/lib32/dri//i965_dri.so
#11 0xf5a877bf in _mesa_BlitFramebufferEXT () from /opt/xorg/lib32/dri/libdricore.so
#12 0x08187c6e in EOpenGLRenderer::glBlitFramebufferEXT(int, int, int, int, int, int, int, int, unsigned int, unsigned int) const ()
#13 0x0818aa66 in ERenderer::RestoreRenderTarget() ()
#14 0x0818a364 in ERenderer::SetRenderTarget(unsigned int, unsigned int, CUBEMAPFACE) ()
#15 0x082f4554 in GameApp::BlitTextureFiltered(unsigned int, unsigned int, BLENDMODE, FILTERTYPE, EVec2 const*, EVec2 const*, EVec4 const*, ERect*) ()
#16 0x082ef784 in GameApp::renderGlareToTexture() ()
#17 0x082f3b66 in GameApp::RenderSceneGeometry() ()
#18 0x082d898e in GameApp::RenderFrame() ()
#19 0x08522ad8 in main ()

These stack traces are from Psychonauts 0.2, but since there are symbols it should be possible to use these. It's also very easy to reproduce with Intel drivers (possibly Radeon open source or Nouveau as well).

I patched the source code of src/mesa/main/readpix.c and src/mesa/main/texstore.c to remove these calls. However, I am not confident that this is the correct solution. There are many possible side-effects that could occur if you were to use my patch, so I leave the solution to you. The patch fixes the performance problem and I am able to play Psychonauts with reasonable fps at 1680x1050 at the highest quality.

I would be happy to work on an open source repro if that is necessary, but I suspect that just looking at the code will be sufficient. If you need any other data, let me know. I have been using git master successfully for months. I can also test this with closed source nvidia or open source r600 drivers.
Comment 1 Paul Berry 2012-06-22 07:52:51 UTC
This sounds like a problem I fixed on Friday June 15 (see commit 75f409d75cacf90df2d6f1d718251a5d5cd92f7f).  Which revision of Mesa are you using?
Comment 2 Javantea 2012-06-22 11:21:00 UTC
Paul Berry fixed the bug in commit 75f409d75cacf90df2d6f1d718251a5d5cd92f7f.

Many thanks. I'm glad you solved this correctly.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.