st/mesa: don't allocate mipmapped texture for NEAREST_MIPMAP_LINEAR

Submitted by Marek Olšák on Aug. 2, 2019, 11:13 p.m.

Details

Message ID 20190802231349.7757-1-maraeo@gmail.com
State New
Headers show
Series "st/mesa: don't allocate mipmapped texture for NEAREST_MIPMAP_LINEAR" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Marek Olšák Aug. 2, 2019, 11:13 p.m.
From: Marek Olšák <marek.olsak@amd.com>

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

Patch hide | download patch | download mbox

diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c
index 0edb3ea5c7e..1ace61863ff 100644
--- a/src/mesa/state_tracker/st_cb_texture.c
+++ b/src/mesa/state_tracker/st_cb_texture.c
@@ -516,20 +516,32 @@  allocate_full_mipmap(const struct st_texture_object *stObj,
       return FALSE;
 
    if (stObj->base.BaseLevel == 0 && stObj->base.MaxLevel == 0)
       return FALSE;
 
    if (stObj->base.Sampler.MinFilter == GL_NEAREST ||
        stObj->base.Sampler.MinFilter == GL_LINEAR)
       /* not a mipmap minification filter */
       return FALSE;
 
+   /* If the following sequence of GL calls is used:
+    *   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, ...
+    *   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+    *
+    * we would needlessly allocate a mipmapped texture, because the initial
+    * MinFilter is GL_NEAREST_MIPMAP_LINEAR. Catch this case and don't
+    * allocate a mipmapped texture by default. This may cause texture
+    * reallocation later, but GL_NEAREST_MIPMAP_LINEAR is pretty rare.
+    */
+   if (stObj->base.Sampler.MinFilter == GL_NEAREST_MIPMAP_LINEAR)
+      return FALSE;
+
    if (stObj->base.Target == GL_TEXTURE_3D)
       /* 3D textures are seldom mipmapped */
       return FALSE;
 
    return TRUE;
 }
 
 
 /**
  * Try to allocate a pipe_resource object for the given st_texture_object.

Comments


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


On 08/10/2019 10:14 AM, Marek Olšák wrote:
> Ping
> 
> On Fri., Aug. 2, 2019, 19:13 Marek Olšák, <maraeo@gmail.com 
> <mailto:maraeo@gmail.com>> wrote:
> 
>     From: Marek Olšák <marek.olsak@amd.com <mailto:marek.olsak@amd.com>>
> 
>     ---
>       src/mesa/state_tracker/st_cb_texture.c | 12 ++++++++++++
>       1 file changed, 12 insertions(+)
> 
>     diff --git a/src/mesa/state_tracker/st_cb_texture.c
>     b/src/mesa/state_tracker/st_cb_texture.c
>     index 0edb3ea5c7e..1ace61863ff 100644
>     --- a/src/mesa/state_tracker/st_cb_texture.c
>     +++ b/src/mesa/state_tracker/st_cb_texture.c
>     @@ -516,20 +516,32 @@ allocate_full_mipmap(const struct
>     st_texture_object *stObj,
>             return FALSE;
> 
>          if (stObj->base.BaseLevel == 0 && stObj->base.MaxLevel == 0)
>             return FALSE;
> 
>          if (stObj->base.Sampler.MinFilter == GL_NEAREST ||
>              stObj->base.Sampler.MinFilter == GL_LINEAR)
>             /* not a mipmap minification filter */
>             return FALSE;
> 
>     +   /* If the following sequence of GL calls is used:
>     +    *   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, ...
>     +    *   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
>     GL_LINEAR);
>     +    *
>     +    * we would needlessly allocate a mipmapped texture, because the
>     initial
>     +    * MinFilter is GL_NEAREST_MIPMAP_LINEAR. Catch this case and don't
>     +    * allocate a mipmapped texture by default. This may cause texture
>     +    * reallocation later, but GL_NEAREST_MIPMAP_LINEAR is pretty rare.
>     +    */
>     +   if (stObj->base.Sampler.MinFilter == GL_NEAREST_MIPMAP_LINEAR)
>     +      return FALSE;
>     +
>          if (stObj->base.Target == GL_TEXTURE_3D)
>             /* 3D textures are seldom mipmapped */
>             return FALSE;
> 
>          return TRUE;
>       }
> 
> 
>       /**
>        * Try to allocate a pipe_resource object for the given
>     st_texture_object.
>     -- 
>     2.17.1
> 
> 
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org