st/mesa: check for incomplete texture in st_finalize_texture()
authorBrian Paul <brianp@vmware.com>
Tue, 27 Jun 2017 15:29:18 +0000 (09:29 -0600)
committerBrian Paul <brianp@vmware.com>
Fri, 30 Jun 2017 19:37:10 +0000 (13:37 -0600)
Return early from st_finalize_texture() if we have an incomplete
texture.  This avoids trying to create a texture resource with invalid
parameters (too many mipmap levels given the base dimension).

Specifically, the Piglit fbo-incomplete-texture-03 test winds up
calling pipe_screen::resource_create() with width0=32, height0=32 and
last_level=6 because the first five cube faces are 32x32 but the sixth
face is 64x64.  Some drivers handle this, but others (like VMware svga)
do not (generates device errors).

Note that this code is on the path that's usually not taken (we normally
build consistent textures).

No Piglit regressions.

v2: only need to check for base-level completeness since that's what has to
be consistent in order to specify the dimensions for a new gallium texture.
Per Roland.

Reviewed-by: Roland Scheidegger <sroland@vmware.com>
src/mesa/state_tracker/st_cb_texture.c

index 9798321d4bc4d848765ab4f1797da2e18f9b50b2..1847cc30df9e752ae60b00b4fe806ba90c1cc9da 100644 (file)
@@ -2543,6 +2543,18 @@ st_finalize_texture(struct gl_context *ctx,
                 stObj->base.Target == GL_TEXTURE_CUBE_MAP_ARRAY)
                ptHeight = ptWidth;
          }
+
+         /* At this point, the texture may be incomplete (mismatched cube
+          * face sizes, for example).  If that's the case, give up, but
+          * don't return GL_FALSE as that would raise an incorrect
+          * GL_OUT_OF_MEMORY error.  See Piglit fbo-incomplete-texture-03 test.
+          */
+         if (!stObj->base._BaseComplete) {
+            _mesa_test_texobj_completeness(ctx, &stObj->base);
+            if (!stObj->base._BaseComplete) {
+               return TRUE;
+            }
+         }
       }
 
       ptNumSamples = firstImage->base.NumSamples;