svga: Fix surface view error handling
authorThomas Hellstrom <thellstrom@vmware.com>
Fri, 4 Sep 2015 10:26:05 +0000 (03:26 -0700)
committerThomas Hellstrom <thellstrom@vmware.com>
Mon, 7 Sep 2015 08:25:08 +0000 (01:25 -0700)
Make sure errors are correcly propagated.
Also don't flush during state emission if emission fails.

Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Charmaine Lee <charmainel@vmware.com>
Reviewed-by: Brian Paul <brianp@vmware.com>
src/gallium/drivers/svga/svga_surface.c

index 477a938ccdd879408db24bbae00462fbe2955789..aca5abcdfce8768d8a6ca95504c2f1e40de43daf 100644 (file)
@@ -296,6 +296,11 @@ svga_create_surface_view(struct pipe_context *pipe,
       s->handle = svga_texture_view_surface(svga, tex, bind, flags, tex->key.format,
                                             surf_tmpl->u.tex.level, 1,
                                             layer, nlayers, zslice, &s->key);
+      if (!s->handle) {
+         FREE(s);
+         return NULL;
+      }
+
       s->key.format = format;
       s->real_layer = 0;
       s->real_level = 0;
@@ -358,6 +363,8 @@ create_backed_surface_view(struct svga_context *svga, struct svga_surface *s)
                                              &tex->b.b,
                                              &s->base,
                                              TRUE);
+      if (!backed_view)
+         return NULL;
 
       bs = svga_surface(backed_view);
       s->backed = bs;
@@ -376,7 +383,6 @@ struct pipe_surface *
 svga_validate_surface_view(struct svga_context *svga, struct svga_surface *s)
 {
    enum pipe_error ret = PIPE_OK;
-   int try;
    unsigned shader;
 
    assert(svga_have_vgpu10(svga));
@@ -395,6 +401,9 @@ svga_validate_surface_view(struct svga_context *svga, struct svga_surface *s)
                   "same resource used in shaderResource and renderTarget 0x%x\n",
                   s->handle);
          s = create_backed_surface_view(svga, s);
+         if (!s)
+            return NULL;
+
          break;
       }
    }
@@ -430,32 +439,27 @@ svga_validate_surface_view(struct svga_context *svga, struct svga_surface *s)
          resType = SVGA3D_RESOURCE_TEXTURE2D;
       }
 
-      for (try = 0; try < 2; try++) {
-         if (util_format_is_depth_or_stencil(s->base.format)) {
-            ret = SVGA3D_vgpu10_DefineDepthStencilView(svga->swc,
-                                                       s->view_id,
-                                                       s->handle,
-                                                       s->key.format,
-                                                       resType,
-                                                       &desc);
-         }
-         else {
-            ret = SVGA3D_vgpu10_DefineRenderTargetView(svga->swc,
-                                                       s->view_id,
-                                                       s->handle,
-                                                       s->key.format,
-                                                       resType,
-                                                       &desc);
-         }
-         if (ret == PIPE_OK)
-            break;
-         svga_context_flush(svga, NULL);
+      if (util_format_is_depth_or_stencil(s->base.format)) {
+         ret = SVGA3D_vgpu10_DefineDepthStencilView(svga->swc,
+                                                    s->view_id,
+                                                    s->handle,
+                                                    s->key.format,
+                                                    resType,
+                                                    &desc);
+      }
+      else {
+         ret = SVGA3D_vgpu10_DefineRenderTargetView(svga->swc,
+                                                    s->view_id,
+                                                    s->handle,
+                                                    s->key.format,
+                                                    resType,
+                                                    &desc);
       }
 
-      assert(ret == PIPE_OK);
       if (ret != PIPE_OK) {
          util_bitmask_clear(svga->surface_view_id_bm, s->view_id);
          s->view_id = SVGA3D_INVALID_ID;
+         return NULL;
       }
    }
    return &s->base;