r300g: don't return NULL in resource_from_handle if the resource is too small
authorMarek Olšák <maraeo@gmail.com>
Thu, 20 Oct 2011 21:14:36 +0000 (23:14 +0200)
committerMarek Olšák <maraeo@gmail.com>
Thu, 20 Oct 2011 21:37:22 +0000 (23:37 +0200)
The DDX may allocate a buffer with a too small size.
Instead of failing, let's pretend everything's alright.

Such bugs should be fixed in the DDX, of course.

NOTE: This is a candidate for the stable branches.

src/gallium/drivers/r300/r300_texture.c
src/gallium/drivers/r300/r300_texture.h
src/gallium/drivers/r300/r300_texture_desc.c
src/gallium/drivers/r300/r300_texture_desc.h

index 34860c9d72b5c509b378c3650931d6d1ca2bb239..fa09410c6a530c1c1c552d74ccb2c974fb95c135 100644 (file)
@@ -812,9 +812,9 @@ static void r300_texture_setup_fb_state(struct r300_surface *surf)
     }
 }
 
-boolean r300_resource_set_properties(struct pipe_screen *screen,
-                                     struct pipe_resource *tex,
-                                     const struct pipe_resource *new_properties)
+void r300_resource_set_properties(struct pipe_screen *screen,
+                                  struct pipe_resource *tex,
+                                  const struct pipe_resource *new_properties)
 {
     struct r300_screen *rscreen = r300_screen(screen);
     struct r300_resource *res = r300_resource(tex);
@@ -824,13 +824,8 @@ boolean r300_resource_set_properties(struct pipe_screen *screen,
         util_format_short_name(tex->format),
         util_format_short_name(new_properties->format));
 
-    if (!r300_texture_desc_init(rscreen, res, new_properties)) {
-        fprintf(stderr, "r300: ERROR: Cannot set texture properties.\n");
-        return FALSE;
-    }
+    r300_texture_desc_init(rscreen, res, new_properties);
     r300_texture_setup_format_state(rscreen, res, 0, &res->tx_format);
-
-    return TRUE;
 }
 
 static void r300_texture_destroy(struct pipe_screen *screen,
@@ -897,12 +892,7 @@ r300_texture_create_object(struct r300_screen *rscreen,
     tex->tex.stride_in_bytes_override = stride_in_bytes_override;
     tex->buf = buffer;
 
-    if (!r300_resource_set_properties(&rscreen->screen, &tex->b.b.b, base)) {
-        if (buffer)
-            pb_reference(&buffer, NULL);
-        FREE(tex);
-        return NULL;
-    }
+    r300_resource_set_properties(&rscreen->screen, &tex->b.b.b, base);
 
     /* Create the backing buffer if needed. */
     if (!tex->buf) {
index 0da07235a69f122bd1a60176cf2306b405a2d986..f87d2842a8bfb27cc64891032c21d3071ec6f87d 100644 (file)
@@ -46,9 +46,9 @@ uint32_t r300_translate_texformat(enum pipe_format format,
 
 uint32_t r500_tx_format_msb_bit(enum pipe_format format);
 
-boolean r300_resource_set_properties(struct pipe_screen *screen,
-                                     struct pipe_resource *tex,
-                                     const struct pipe_resource *new_properties);
+void r300_resource_set_properties(struct pipe_screen *screen,
+                                  struct pipe_resource *tex,
+                                  const struct pipe_resource *new_properties);
 
 boolean r300_is_colorbuffer_format_supported(enum pipe_format format);
 
index 55e363b892c849027c5105271a4d8d79e8a4bbc7..926bb0b10de95bbba5ec46b7e9df0a188cfa8f10 100644 (file)
@@ -473,9 +473,9 @@ static void r300_tex_print_info(struct r300_resource *tex,
             util_format_short_name(tex->b.b.b.format));
 }
 
-boolean r300_texture_desc_init(struct r300_screen *rscreen,
-                               struct r300_resource *tex,
-                               const struct pipe_resource *base)
+void r300_texture_desc_init(struct r300_screen *rscreen,
+                            struct r300_resource *tex,
+                            const struct pipe_resource *base)
 {
     tex->b.b.b.target = base->target;
     tex->b.b.b.format = base->format;
@@ -514,11 +514,15 @@ boolean r300_texture_desc_init(struct r300_screen *rscreen,
 
         /* Make sure the buffer we got is large enough. */
         if (tex->tex.size_in_bytes > tex->buf->size) {
-            fprintf(stderr, "r300: texture_desc_init: The buffer is not "
-                            "large enough. Got: %i, Need: %i, Info:\n",
-                            tex->buf->size, tex->tex.size_in_bytes);
+            fprintf(stderr,
+                "r300: I got a pre-allocated buffer to use it as a texture "
+                "storage, but the buffer is too small. I'll use the buffer "
+                "anyway, because I can't crash here, but it's dangerous. "
+                "This can be a DDX bug. Got: %iB, Need: %iB, Info:\n",
+                tex->buf->size, tex->tex.size_in_bytes);
             r300_tex_print_info(tex, "texture_desc_init");
-            return FALSE;
+            /* Ooops, what now. Apps will break if we fail this,
+             * so just pretend everything's okay. */
         }
     }
 
@@ -526,8 +530,6 @@ boolean r300_texture_desc_init(struct r300_screen *rscreen,
 
     if (SCREEN_DBG_ON(rscreen, DBG_TEX))
         r300_tex_print_info(tex, "texture_desc_init");
-
-    return TRUE;
 }
 
 unsigned r300_texture_get_offset(struct r300_resource *tex,
index a84d6fae0ea75b310a35f1c0cea5ad3819f0bc28..591592dfb041fbc69f091d8dbd5978d2905f976f 100644 (file)
@@ -43,9 +43,9 @@ unsigned r300_get_pixel_alignment(enum pipe_format format,
                                   enum radeon_bo_layout macrotile,
                                   enum r300_dim dim, boolean is_rs690);
 
-boolean r300_texture_desc_init(struct r300_screen *rscreen,
-                               struct r300_resource *tex,
-                               const struct pipe_resource *base);
+void r300_texture_desc_init(struct r300_screen *rscreen,
+                            struct r300_resource *tex,
+                            const struct pipe_resource *base);
 
 unsigned r300_texture_get_offset(struct r300_resource *tex,
                                  unsigned level, unsigned layer);