Squashed commit of the following:
[mesa.git] / src / gallium / drivers / i965 / brw_context.c
index e10b7d8bf55462f0eca4ecd7c7931419b5c11b58..227bc790debbc6166c35ac175161e7d5611464a8 100644 (file)
 
 
 #include "pipe/p_context.h"
+#include "util/u_inlines.h"
 #include "util/u_simple_list.h"
 
 #include "brw_context.h"
-#include "brw_defines.h"
 #include "brw_draw.h"
 #include "brw_state.h"
 #include "brw_batchbuffer.h"
 #include "brw_winsys.h"
+#include "brw_resource.h"
+#include "brw_screen.h"
 
 
 static void brw_destroy_context( struct pipe_context *pipe )
@@ -46,10 +48,27 @@ static void brw_destroy_context( struct pipe_context *pipe )
    struct brw_context *brw = brw_context(pipe);
    int i;
 
+   brw_context_flush( brw );
+   brw_batchbuffer_free( brw->batch );
    brw_destroy_state(brw);
 
    brw_draw_cleanup( brw );
 
+   brw_pipe_blend_cleanup( brw );
+   brw_pipe_depth_stencil_cleanup( brw );
+   brw_pipe_framebuffer_cleanup( brw );
+   brw_pipe_flush_cleanup( brw );
+   brw_pipe_misc_cleanup( brw );
+   brw_pipe_query_cleanup( brw );
+   brw_pipe_rast_cleanup( brw );
+   brw_pipe_sampler_cleanup( brw );
+   brw_pipe_shader_cleanup( brw );
+   brw_pipe_vertex_cleanup( brw );
+   brw_pipe_clear_cleanup( brw );
+
+   brw_hw_cc_cleanup( brw );
+
+
    FREE(brw->wm.compile_data);
 
    for (i = 0; i < brw->curr.fb.nr_cbufs; i++)
@@ -57,48 +76,64 @@ static void brw_destroy_context( struct pipe_context *pipe )
    brw->curr.fb.nr_cbufs = 0;
    pipe_surface_reference(&brw->curr.fb.zsbuf, NULL);
 
-   brw->sws->bo_unreference(brw->curbe.curbe_bo);
-   brw->sws->bo_unreference(brw->vs.prog_bo);
-   brw->sws->bo_unreference(brw->vs.state_bo);
-   brw->sws->bo_unreference(brw->vs.bind_bo);
-   brw->sws->bo_unreference(brw->gs.prog_bo);
-   brw->sws->bo_unreference(brw->gs.state_bo);
-   brw->sws->bo_unreference(brw->clip.prog_bo);
-   brw->sws->bo_unreference(brw->clip.state_bo);
-   brw->sws->bo_unreference(brw->clip.vp_bo);
-   brw->sws->bo_unreference(brw->sf.prog_bo);
-   brw->sws->bo_unreference(brw->sf.state_bo);
-   brw->sws->bo_unreference(brw->sf.vp_bo);
-   for (i = 0; i < BRW_MAX_TEX_UNIT; i++)
-      brw->sws->bo_unreference(brw->wm.sdc_bo[i]);
-   brw->sws->bo_unreference(brw->wm.bind_bo);
-   for (i = 0; i < BRW_WM_MAX_SURF; i++)
-      brw->sws->bo_unreference(brw->wm.surf_bo[i]);
-   brw->sws->bo_unreference(brw->wm.sampler_bo);
-   brw->sws->bo_unreference(brw->wm.prog_bo);
-   brw->sws->bo_unreference(brw->wm.state_bo);
-   brw->sws->bo_unreference(brw->cc.prog_bo);
-   brw->sws->bo_unreference(brw->cc.state_bo);
-   brw->sws->bo_unreference(brw->cc.vp_bo);
+   bo_reference(&brw->curbe.curbe_bo, NULL);
+   bo_reference(&brw->vs.prog_bo, NULL);
+   bo_reference(&brw->vs.state_bo, NULL);
+   bo_reference(&brw->vs.bind_bo, NULL);
+   bo_reference(&brw->gs.prog_bo, NULL);
+   bo_reference(&brw->gs.state_bo, NULL);
+   bo_reference(&brw->clip.prog_bo, NULL);
+   bo_reference(&brw->clip.state_bo, NULL);
+   bo_reference(&brw->clip.vp_bo, NULL);
+   bo_reference(&brw->sf.prog_bo, NULL);
+   bo_reference(&brw->sf.state_bo, NULL);
+   bo_reference(&brw->sf.vp_bo, NULL);
+
+   for (i = 0; i < Elements(brw->wm.sdc_bo); i++)
+      bo_reference(&brw->wm.sdc_bo[i], NULL);
+
+   bo_reference(&brw->wm.bind_bo, NULL);
+
+   for (i = 0; i < Elements(brw->wm.surf_bo); i++)
+      bo_reference(&brw->wm.surf_bo[i], NULL);
+
+   bo_reference(&brw->wm.sampler_bo, NULL);
+   bo_reference(&brw->wm.prog_bo, NULL);
+   bo_reference(&brw->wm.state_bo, NULL);
 }
 
 
-struct pipe_context *brw_create_context(struct pipe_screen *screen)
+struct pipe_context *brw_create_context(struct pipe_screen *screen,
+                                       void *priv)
 {
    struct brw_context *brw = (struct brw_context *) CALLOC_STRUCT(brw_context);
 
    if (!brw) {
       debug_printf("%s: failed to alloc context\n", __FUNCTION__);
-      return GL_FALSE;
+      return NULL;
    }
 
-   /* We want the GLSL compiler to emit code that uses condition codes */
-   //ctx->Shader.EmitCondCodes = GL_TRUE;
-   //ctx->Shader.EmitNVTempInitialization = GL_TRUE;
-
+   brw->base.screen = screen;
+   brw->base.priv = priv;
    brw->base.destroy = brw_destroy_context;
+   brw->sws = brw_screen(screen)->sws;
+   brw->chipset = brw_screen(screen)->chipset;
+
+   brw_init_resource_functions( brw );
+   brw_pipe_blend_init( brw );
+   brw_pipe_depth_stencil_init( brw );
+   brw_pipe_framebuffer_init( brw );
+   brw_pipe_flush_init( brw );
+   brw_pipe_misc_init( brw );
+   brw_pipe_query_init( brw );
+   brw_pipe_rast_init( brw );
+   brw_pipe_sampler_init( brw );
+   brw_pipe_shader_init( brw );
+   brw_pipe_vertex_init( brw );
+   brw_pipe_clear_init( brw );
+
+   brw_hw_cc_init( brw );
 
-   brw_init_query( brw );
    brw_init_state( brw );
    brw_draw_init( brw );
 
@@ -109,7 +144,15 @@ struct pipe_context *brw_create_context(struct pipe_screen *screen)
 
    make_empty_list(&brw->query.active_head);
 
+   brw->batch = brw_batchbuffer_alloc( brw->sws, brw->chipset );
+   if (brw->batch == NULL)
+      goto fail;
 
    return &brw->base;
+
+fail:
+   if (brw->batch)
+      brw_batchbuffer_free( brw->batch );
+   return NULL;
 }