Mesa (master): st/mesa: Allocate full miplevels if MaxLevel is explicitly set

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jan 16 08:41:54 UTC 2020


Module: Mesa
Branch: master
Commit: e3405f177bdff591423e1fe154defba10d326d55
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=e3405f177bdff591423e1fe154defba10d326d55

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue Jan 14 16:25:11 2020 -0800

st/mesa: Allocate full miplevels if MaxLevel is explicitly set

Some applications explicitly call glTex[ture]Parameteri[v] to set
GL_TEXTURE_MAX_LEVEL and GL_TEXTURE_BASE_LEVEL before uploading any
texture data.  Core Mesa initializes MaxLevel to 1000, so if it isn't
that, we know they've set it.  (We check for < TEXTURE_MAX_LEVELS to
avoid hardcoding that value, however.)

If MaxLevel - BaseLevel > 0, then the app is trying to tell us that
this texture is going to have multiple miplevels.  In that case, go
ahead and allocate the space for it.

Avoids many resource_copy_region calls at texture finalization time
in the Civilization VI benchmark.

Reviewed-by: Michel Dänzer <mdaenzer at redhat.com>
Reviewed-by: Eric Anholt <eric at anholt.net>
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3401>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3401>

---

 src/mesa/state_tracker/st_cb_texture.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 21f67659c0d..ff0f1a2efa6 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -525,6 +525,17 @@ allocate_full_mipmap(const struct st_texture_object *stObj,
    if (stImage->base.Level > 0 || stObj->base.GenerateMipmap)
       return TRUE;
 
+   /* If the application has explicitly called glTextureParameter to set
+    * GL_TEXTURE_MAX_LEVEL, such that (max - base) > 0, then they're trying
+    * to communicate that they will have multiple miplevels.
+    *
+    * Core Mesa will initialize MaxLevel to value much larger than
+    * MAX_TEXTURE_LEVELS, so we check that to see if it's been set at all.
+    */
+   if (stObj->base.MaxLevel < MAX_TEXTURE_LEVELS &&
+       stObj->base.MaxLevel - stObj->base.BaseLevel > 0)
+      return TRUE;
+
    if (stImage->base._BaseFormat == GL_DEPTH_COMPONENT ||
        stImage->base._BaseFormat == GL_DEPTH_STENCIL_EXT)
       /* depth/stencil textures are seldom mipmapped */



More information about the mesa-commit mailing list