llvmpipe: use dummy tile when out of memory
authorBrian Paul <brianp@vmware.com>
Wed, 30 Jun 2010 17:57:14 +0000 (11:57 -0600)
committerBrian Paul <brianp@vmware.com>
Wed, 30 Jun 2010 20:05:45 +0000 (14:05 -0600)
src/gallium/drivers/llvmpipe/lp_rast.c
src/gallium/drivers/llvmpipe/lp_rast_priv.h
src/gallium/drivers/llvmpipe/lp_setup.c

index 1fadb9cca1e8c275aac245593148e7a260f7b310..1a82dd5694e36b399164b2185f753e97642e45a6 100644 (file)
@@ -81,7 +81,6 @@ lp_rast_begin( struct lp_rasterizer *rast,
                                              zsbuf->zslice,
                                              LP_TEX_USAGE_READ_WRITE,
                                              LP_TEX_LAYOUT_NONE);
-      assert(rast->zsbuf.map);
    }
 
    lp_scene_bin_iter_begin( scene );
@@ -188,7 +187,7 @@ lp_rast_tile_begin(struct lp_rasterizer_task *task,
          /* Get actual pointer to the tile data.  Note that depth/stencil
           * data is tiled differently than color data.
           */
-         task->depth_tile = lp_rast_get_depth_block_pointer(rast, x, y);
+         task->depth_tile = lp_rast_get_depth_block_pointer(task, x, y);
 
          assert(task->depth_tile);
       }
@@ -286,7 +285,10 @@ lp_rast_clear_zstencil(struct lp_rasterizer_task *task,
 
    dst = task->depth_tile;
 
-   assert(dst == lp_rast_get_depth_block_pointer(rast, task->x, task->y));
+   if (lp_is_dummy_tile(dst))
+      return;
+
+   assert(dst == lp_rast_get_depth_block_pointer(task, task->x, task->y));
 
    switch (block_size) {
    case 1:
@@ -442,7 +444,7 @@ lp_rast_shade_tile(struct lp_rasterizer_task *task,
                                                        tile_x + x, tile_y + y);
 
          /* depth buffer */
-         depth = lp_rast_get_depth_block_pointer(rast, tile_x + x, tile_y + y);
+         depth = lp_rast_get_depth_block_pointer(task, tile_x + x, tile_y + y);
 
          /* run shader on 4x4 block */
          variant->jit_function[RAST_WHOLE]( &state->jit_context,
@@ -494,7 +496,7 @@ void lp_rast_shade_quads( struct lp_rasterizer_task *task,
    }
 
    /* depth buffer */
-   depth = lp_rast_get_depth_block_pointer(rast, x, y);
+   depth = lp_rast_get_depth_block_pointer(task, x, y);
 
 
    assert(lp_check_alignment(state->jit_context.blend_color, 16));
index 9bded086efcfb48805b9f29ba91aad323262a34f..eb4175dfa67801fe1f5c111ef031e289c97e79fd 100644 (file)
@@ -31,6 +31,7 @@
 #include "os/os_thread.h"
 #include "util/u_format.h"
 #include "gallivm/lp_bld_debug.h"
+#include "lp_memory.h"
 #include "lp_rast.h"
 #include "lp_scene.h"
 #include "lp_state.h"
@@ -132,18 +133,20 @@ void lp_rast_shade_quads( struct lp_rasterizer_task *task,
  * \param x, y location of 4x4 block in window coords
  */
 static INLINE void *
-lp_rast_get_depth_block_pointer(const struct lp_rasterizer *rast,
+lp_rast_get_depth_block_pointer(struct lp_rasterizer_task *task,
                                 unsigned x, unsigned y)
 {
+   const struct lp_rasterizer *rast = task->rast;
    void *depth;
 
    assert((x % TILE_VECTOR_WIDTH) == 0);
    assert((y % TILE_VECTOR_HEIGHT) == 0);
 
-   assert(rast->zsbuf.map || !rast->curr_scene->fb.zsbuf);
-
-   if (!rast->zsbuf.map)
-      return NULL;
+   if (!rast->zsbuf.map && (task->current_state->variant->key.depth.enabled ||
+                            task->current_state->variant->key.stencil[0].enabled)) {
+      /* out of memory - use dummy tile memory */
+      return lp_get_dummy_tile();
+   }
 
    depth = (rast->zsbuf.map +
             rast->zsbuf.stride * y +
@@ -172,8 +175,10 @@ lp_rast_get_color_block_pointer(struct lp_rasterizer_task *task,
    assert((y % TILE_VECTOR_HEIGHT) == 0);
 
    color = task->color_tiles[buf];
-   if (!color)
-      return NULL;
+   if (!color) {
+      /* out of memory - use dummy tile memory */
+      return lp_get_dummy_tile();
+   }
 
    px = x % TILE_SIZE;
    py = y % TILE_SIZE;
@@ -197,7 +202,7 @@ lp_rast_shade_quads_all( struct lp_rasterizer_task *task,
                          const struct lp_rast_shader_inputs *inputs,
                          unsigned x, unsigned y )
 {
-   struct lp_rasterizer *rast = task->rast;
+   const struct lp_rasterizer *rast = task->rast;
    const struct lp_rast_state *state = task->current_state;
    struct lp_fragment_shader_variant *variant = state->variant;
    uint8_t *color[PIPE_MAX_COLOR_BUFS];
@@ -208,7 +213,7 @@ lp_rast_shade_quads_all( struct lp_rasterizer_task *task,
    for (i = 0; i < rast->state.nr_cbufs; i++)
       color[i] = lp_rast_get_color_block_pointer(task, i, x, y);
 
-   depth = lp_rast_get_depth_block_pointer(rast, x, y);
+   depth = lp_rast_get_depth_block_pointer(task, x, y);
 
    /* run shader on 4x4 block */
    variant->jit_function[RAST_WHOLE]( &state->jit_context,
index 158f9e88ccf0618c22c3d9da25c87f08936a9287..2597fa8f71b09f8081bf7c63a353022fa729b4d0 100644 (file)
@@ -40,6 +40,7 @@
 #include "util/u_memory.h"
 #include "util/u_pack_color.h"
 #include "lp_context.h"
+#include "lp_memory.h"
 #include "lp_scene.h"
 #include "lp_scene_queue.h"
 #include "lp_texture.h"
@@ -622,6 +623,17 @@ lp_setup_set_fragment_sampler_views(struct lp_setup_context *setup,
                                                  LP_TEX_LAYOUT_LINEAR);
                jit_tex->row_stride[j] = lp_tex->row_stride[j];
                jit_tex->img_stride[j] = lp_tex->img_stride[j];
+
+               if (!jit_tex->data[j]) {
+                  /* out of memory - use dummy tile memory */
+                  jit_tex->data[j] = lp_get_dummy_tile();
+                  jit_tex->width = TILE_SIZE;
+                  jit_tex->height = TILE_SIZE;
+                  jit_tex->depth = 1;
+                  jit_tex->last_level = 0;
+                  jit_tex->row_stride[j] = 0;
+                  jit_tex->img_stride[j] = 0;
+               }
             }
          }
          else {