[Mesa-dev] [PATCH 2/2] st/mesa: accelerate glGetTexImage for all formats using a blit

Brian Paul brianp at vmware.com
Thu Feb 7 16:57:26 PST 2013


On 02/07/2013 01:13 PM, Marek Olšák wrote:
> This commit allows using glGetTexImage during rendering and still
> maintain interactive framerates.
>
> This improves performance of WarCraft 3 under Wine. The framerate is improved
> from 25 fps to 39 fps in the main menu, and from 0.5 fps to 32 fps in the game.
> ---
>   src/mesa/state_tracker/st_cb_texture.c |  201 ++++++++++++++++++++++++--------
>   src/mesa/state_tracker/st_format.c     |    1 -
>   2 files changed, 153 insertions(+), 49 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
> index ab5ff27..3b6a9bb 100644
> --- a/src/mesa/state_tracker/st_cb_texture.c
> +++ b/src/mesa/state_tracker/st_cb_texture.c
> @@ -560,15 +560,52 @@ st_CompressedTexImage(struct gl_context *ctx, GLuint dims,
>   }
>
>
> +static enum pipe_format
> +choose_matching_format(struct pipe_screen *screen, unsigned bind,
> +                       GLenum format, GLenum type, GLboolean swapBytes)
> +{
> +   gl_format mesa_format;
> +
> +   for (mesa_format = 1; mesa_format<  MESA_FORMAT_COUNT; mesa_format++) {
> +      if (_mesa_get_format_color_encoding(mesa_format) == GL_SRGB) {
> +         continue;
> +      }
> +
> +      if (_mesa_format_matches_format_and_type(mesa_format, format, type,
> +                                               swapBytes)) {
> +         enum pipe_format format = st_mesa_format_to_pipe_format(mesa_format);
> +
> +         if (format&&
> +             screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, 0,
> +                                         bind)) {
> +            return format;
> +         }
> +         /* It's unlikely to find 2 matching Mesa formats. */
> +         break;
> +      }
> +   }
> +   return PIPE_FORMAT_NONE;
> +}

This seems like kind of an inefficient function.  If we find that the 
app is calling glGetTexImage() over and over with the same 
format/type, perhaps we could cache the result of this function to 
avoid calling it the next time.  Maybe that's not a big deal though.

The st_cb_drawpixels.c file has some similar code that tries to find a 
pipe_format that matches a GL format/type combo.  Your new code is 
more sophisticated.  Maybe it could be used for glDrawPixels too.

[...]

Otherwise, this all looks good to me.

Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the mesa-dev mailing list