r300g: various other cleanups
[mesa.git] / src / gallium / drivers / r300 / r300_context.c
index 55850e09c3b9d20520d530ac8b13e8a158a20a4a..503af3e78a25647a581e8941d2dcd51648150295 100644 (file)
@@ -35,7 +35,6 @@
 #include "r300_screen.h"
 #include "r300_screen_buffer.h"
 #include "r300_state_invariant.h"
-#include "r300_transfer.h"
 #include "r300_winsys.h"
 
 static void r300_destroy_context(struct pipe_context* context)
@@ -47,7 +46,7 @@ static void r300_destroy_context(struct pipe_context* context)
     draw_destroy(r300->draw);
 
     /* Free the OQ BO. */
-    context->screen->buffer_destroy(r300->oqbo);
+    context->screen->resource_destroy(context->screen, r300->oqbo);
 
     /* If there are any queries pending or not destroyed, remove them now. */
     foreach_s(query, temp, &r300->query_list) {
@@ -67,29 +66,11 @@ static void r300_destroy_context(struct pipe_context* context)
     FREE(r300->vap_output_state.state);
     FREE(r300->viewport_state.state);
     FREE(r300->ztop_state.state);
+    FREE(r300->fs_constants.state);
+    FREE(r300->vs_constants.state);
     FREE(r300);
 }
 
-static unsigned int
-r300_is_texture_referenced(struct pipe_context *context,
-                           struct pipe_texture *texture,
-                           unsigned face, unsigned level)
-{
-    struct r300_context* r300 = r300_context(context);
-    struct r300_texture* tex = r300_texture(texture);
-
-    return r300->rws->is_buffer_referenced(r300->rws, tex->buffer);
-}
-
-static unsigned int
-r300_is_buffer_referenced(struct pipe_context *context,
-                          struct pipe_buffer *buf)
-{
-    struct r300_context* r300 = r300_context(context);
-
-    return r300_buffer_is_referenced(r300, buf);
-}
-
 static void r300_flush_cb(void *data)
 {
     struct r300_context* const cs_context_copy = data;
@@ -119,6 +100,7 @@ static void r300_setup_atoms(struct r300_context* r300)
      * the size of 0 here. */
     make_empty_list(&r300->atom_list);
     R300_INIT_ATOM(invariant_state, 71);
+    R300_INIT_ATOM(query_start, 4);
     R300_INIT_ATOM(ztop_state, 2);
     R300_INIT_ATOM(blend_state, 8);
     R300_INIT_ATOM(blend_color_state, is_r500 ? 3 : 2);
@@ -133,8 +115,19 @@ static void r300_setup_atoms(struct r300_context* r300)
     R300_INIT_ATOM(vap_output_state, 6);
     R300_INIT_ATOM(pvs_flush, 2);
     R300_INIT_ATOM(vs_state, 0);
+    R300_INIT_ATOM(vs_constants, 0);
     R300_INIT_ATOM(texture_cache_inval, 2);
     R300_INIT_ATOM(textures_state, 0);
+    R300_INIT_ATOM(fs, 0);
+    R300_INIT_ATOM(fs_rc_constant_state, 0);
+    R300_INIT_ATOM(fs_constants, 0);
+
+    /* Replace emission functions for r500. */
+    if (r300->screen->caps.is_r500) {
+        r300->fs.emit = r500_emit_fs;
+        r300->fs_rc_constant_state.emit = r500_emit_fs_rc_constant_state;
+        r300->fs_constants.emit = r500_emit_fs_constants;
+    }
 
     /* Some non-CSO atoms need explicit space to store the state locally. */
     r300->blend_color_state.state = CALLOC_STRUCT(r300_blend_color_state);
@@ -146,6 +139,8 @@ static void r300_setup_atoms(struct r300_context* r300)
     r300->vap_output_state.state = CALLOC_STRUCT(r300_vap_output_state);
     r300->viewport_state.state = CALLOC_STRUCT(r300_viewport_state);
     r300->ztop_state.state = CALLOC_STRUCT(r300_ztop_state);
+    r300->fs_constants.state = CALLOC_STRUCT(r300_constant_buffer);
+    r300->vs_constants.state = CALLOC_STRUCT(r300_constant_buffer);
 }
 
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
@@ -201,23 +196,17 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
         draw_set_viewport_state(r300->draw, &r300_viewport_identity);
     }
 
-    r300->context.is_texture_referenced = r300_is_texture_referenced;
-    r300->context.is_buffer_referenced = r300_is_buffer_referenced;
-
     r300_setup_atoms(r300);
 
     /* Open up the OQ BO. */
-    r300->oqbo = screen->buffer_create(screen, 4096,
-            PIPE_BUFFER_USAGE_PIXEL, 4096);
+    r300->oqbo = pipe_buffer_create(screen,
+                                   R300_BIND_OQBO, 4096);
     make_empty_list(&r300->query_list);
 
     r300_init_flush_functions(r300);
-
     r300_init_query_functions(r300);
-
-    r300_init_transfer_functions(r300);
-
     r300_init_state_functions(r300);
+    r300_init_resource_functions(r300);
 
     r300->invariant_state.dirty = TRUE;
 
@@ -226,16 +215,16 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
 
     r300->blitter = util_blitter_create(&r300->context);
 
-    r300->upload_ib = u_upload_create(screen,
+    r300->upload_ib = u_upload_create(&r300->context,
                                      32 * 1024, 16,
-                                     PIPE_BUFFER_USAGE_INDEX);
+                                     PIPE_BIND_INDEX_BUFFER);
 
     if (r300->upload_ib == NULL)
         goto no_upload_ib;
 
-    r300->upload_vb = u_upload_create(screen,
+    r300->upload_vb = u_upload_create(&r300->context,
                                      128 * 1024, 16,
-                                     PIPE_BUFFER_USAGE_VERTEX);
+                                     PIPE_BIND_VERTEX_BUFFER);
     if (r300->upload_vb == NULL)
         goto no_upload_vb;