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

Marek Olšák maraeo at gmail.com
Fri Feb 8 05:54:41 PST 2013


On Fri, Feb 8, 2013 at 1:57 AM, Brian Paul <brianp at vmware.com> wrote:
> 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.

Yeah, it's doesn't look very efficient, but it's really nothing
compared to a non-memcpy GetTexImage path.

>
> 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.

Yeah. glTex(Sub)Image is another place where it could be used, though
to a much lesser extent, however blit-based glTex(Sub)Image is not a
bad idea either if we ever find out it's a bottleneck (texture
streaming comes to mind).

Marek


More information about the mesa-dev mailing list