r600g: Don't create a texture for the memory_pool during screen init
authorTom Stellard <thomas.stellard@amd.com>
Mon, 9 Jul 2012 15:42:25 +0000 (11:42 -0400)
committerTom Stellard <thomas.stellard@amd.com>
Mon, 9 Jul 2012 16:14:07 +0000 (12:14 -0400)
This fixes a segfault in r600_screen_create() introduced by
eb065f5d9d1159af3a88a64a7606c9b6d67dc3

Reported by tilman on irc.

src/gallium/drivers/r600/compute_memory_pool.c
src/gallium/drivers/r600/r600_pipe.c

index 648219b9eb93337335654c11cb9f49924f222832..0f8bee6e1cd53359e37131af5df7ee00334ce28f 100644 (file)
@@ -48,6 +48,9 @@ static struct r600_resource_texture * create_pool_texture(struct r600_screen * s
        struct pipe_resource templ;
        struct r600_resource_texture * tex;
 
+       if (size_in_dw == 0) {
+               return NULL;
+       }
        memset(&templ, 0, sizeof(templ));
        templ.target = PIPE_TEXTURE_1D;
        templ.format = PIPE_FORMAT_R32_UINT;
@@ -93,8 +96,10 @@ struct compute_memory_pool* compute_memory_pool_new(
 void compute_memory_pool_delete(struct compute_memory_pool* pool)
 {
        free(pool->shadow);
-       pool->screen->screen.resource_destroy((struct pipe_screen *)
+       if (pool->bo) {
+               pool->screen->screen.resource_destroy((struct pipe_screen *)
                        pool->screen, (struct pipe_resource *)pool->bo);
+       }
        free(pool);
 }
 
@@ -167,15 +172,24 @@ void compute_memory_grow_pool(struct compute_memory_pool* pool,
 
        new_size_in_dw += 1024 - (new_size_in_dw % 1024);
 
-       compute_memory_shadow(pool, pipe, 1);
+       if (pool->bo) {
+               compute_memory_shadow(pool, pipe, 1);
+       }
        pool->shadow = (uint32_t*)realloc(pool->shadow, new_size_in_dw*4);
        pool->size_in_dw = new_size_in_dw;
-       pool->screen->screen.resource_destroy(
-               (struct pipe_screen *)pool->screen,
-               (struct pipe_resource *)pool->bo);
-       pool->bo = (struct r600_resource*)create_pool_texture(pool->screen,
+       if (pool->bo) {
+               pool->screen->screen.resource_destroy(
+                       (struct pipe_screen *)pool->screen,
+                       (struct pipe_resource *)pool->bo);
+               pool->bo = (struct r600_resource*)create_pool_texture(
+                                                       pool->screen,
                                                        pool->size_in_dw);
-       compute_memory_shadow(pool, pipe, 0);
+               compute_memory_shadow(pool, pipe, 0);
+       } else {
+               pool->bo = (struct r600_resource*)create_pool_texture(
+                                                       pool->screen,
+                                                       pool->size_in_dw);
+       }
 }
 
 /**
@@ -383,6 +397,8 @@ void compute_memory_transfer(
        struct pipe_transfer *xfer;
        uint32_t *map;
 
+       assert(gart);
+
        if (device_to_host)
        {
                xfer = pipe->get_transfer(pipe, gart, 0, PIPE_TRANSFER_READ,
index 675834ed0488cee2c207cfda1f91f19c58d48a45..b354baecf65c38b6c9d8fe085b4d97645af974b7 100644 (file)
@@ -952,7 +952,7 @@ struct pipe_screen *r600_screen_create(struct radeon_winsys *ws)
        rscreen->use_surface_alloc = debug_get_bool_option("R600_SURF", TRUE);
        rscreen->glsl_feature_level = debug_get_bool_option("R600_GLSL130", TRUE) ? 130 : 120;
 
-       rscreen->global_pool = compute_memory_pool_new(1024*16, rscreen);
+       rscreen->global_pool = compute_memory_pool_new(0, rscreen);
 
        return &rscreen->screen;
 }