Mesa (master): svga: add texture size/ levels sanity check code in svga_texture_create()

Brian Paul brianp at kemper.freedesktop.org
Fri Jun 30 20:03:10 UTC 2017


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

Author: Brian Paul <brianp at vmware.com>
Date:   Tue Jun 27 09:51:25 2017 -0600

svga: add texture size/levels sanity check code in svga_texture_create()

The state tracker should never ask us to create a texture with invalid
dimensions / mipmap levels.  Do some assertions to check that.

No Piglit regressions.

Reviewed-by: Charmaine Lee <charmainel at vmware.com>

---

 src/gallium/drivers/svga/svga_resource_texture.c | 33 ++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/src/gallium/drivers/svga/svga_resource_texture.c b/src/gallium/drivers/svga/svga_resource_texture.c
index 670100cb56..84441d116d 100644
--- a/src/gallium/drivers/svga/svga_resource_texture.c
+++ b/src/gallium/drivers/svga/svga_resource_texture.c
@@ -916,6 +916,39 @@ svga_texture_create(struct pipe_screen *screen,
       goto fail_notex;
    }
 
+   /* Verify the number of mipmap levels isn't impossibly large.  For example,
+    * if the base 2D image is 16x16, we can't have 8 mipmap levels.
+    * The state tracker should never ask us to create a resource with invalid
+    * parameters.
+    */
+   {
+      unsigned max_dim = template->width0;
+
+      switch (template->target) {
+      case PIPE_TEXTURE_1D:
+      case PIPE_TEXTURE_1D_ARRAY:
+         // nothing
+         break;
+      case PIPE_TEXTURE_2D:
+      case PIPE_TEXTURE_CUBE:
+      case PIPE_TEXTURE_CUBE_ARRAY:
+      case PIPE_TEXTURE_2D_ARRAY:
+         max_dim = MAX2(max_dim, template->height0);
+         break;
+      case PIPE_TEXTURE_3D:
+         max_dim = MAX3(max_dim, template->height0, template->depth0);
+         break;
+      case PIPE_TEXTURE_RECT:
+      case PIPE_BUFFER:
+         assert(template->last_level == 0);
+         /* the assertion below should always pass */
+         break;
+      default:
+         debug_printf("Unexpected texture target type\n");
+      }
+      assert(1 << template->last_level <= max_dim);
+   }
+
    tex = CALLOC_STRUCT(svga_texture);
    if (!tex) {
       goto fail_notex;




More information about the mesa-commit mailing list