Merge branch 'mesa_7_6_branch'
[mesa.git] / src / gallium / drivers / r300 / r300_context.c
index 233a32b53c5b5c5e34cf6859154a3e1c9ee825e5..c34fbb11235ede8e29eeaceb2930d674d43d6fd9 100644 (file)
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
 
-#include "r300_context.h"
+#include "draw/draw_context.h"
 
-static boolean r300_draw_range_elements(struct pipe_context* pipe,
-                                        struct pipe_buffer* indexBuffer,
-                                        unsigned indexSize,
-                                        unsigned minIndex,
-                                        unsigned maxIndex,
-                                        unsigned mode,
-                                        unsigned start,
-                                        unsigned count)
-{
-    struct r300_context* r300 = r300_context(pipe);
-    int i;
-
-    for (i = 0; i < r300->vertex_buffer_count; i++) {
-        void* buf = pipe_buffer_map(pipe->screen,
-                                    r300->vertex_buffers[i].buffer,
-                                    PIPE_BUFFER_USAGE_CPU_READ);
-        draw_set_mapped_vertex_buffer(r300->draw, i, buf);
-    }
-
-    if (indexBuffer) {
-        void* indices = pipe_buffer_map(pipe->screen, indexBuffer,
-                                        PIPE_BUFFER_USAGE_CPU_READ);
-        draw_set_mapped_element_buffer_range(r300->draw, indexSize,
-                                             minIndex, maxIndex, indices);
-    } else {
-        draw_set_mapped_element_buffer(r300->draw, 0, NULL);
-    }
-
-    draw_set_mapped_constant_buffer(r300->draw,
-            r300->shader_constants[PIPE_SHADER_VERTEX].constants,
-            r300->shader_constants[PIPE_SHADER_VERTEX].user_count *
-                (sizeof(float) * 4));
-
-    draw_arrays(r300->draw, mode, start, count);
-
-    for (i = 0; i < r300->vertex_buffer_count; i++) {
-        pipe_buffer_unmap(pipe->screen, r300->vertex_buffers[i].buffer);
-        draw_set_mapped_vertex_buffer(r300->draw, i, NULL);
-    }
+#include "pipe/p_inlines.h"
 
-    if (indexBuffer) {
-        pipe_buffer_unmap(pipe->screen, indexBuffer);
-        draw_set_mapped_element_buffer_range(r300->draw, 0, start,
-                                             start + count - 1, NULL);
-    }
+#include "tgsi/tgsi_scan.h"
 
-    return TRUE;
-}
+#include "util/u_hash_table.h"
+#include "util/u_memory.h"
+#include "util/u_simple_list.h"
 
-static boolean r300_draw_elements(struct pipe_context* pipe,
-                                  struct pipe_buffer* indexBuffer,
-                                  unsigned indexSize, unsigned mode,
-                                  unsigned start, unsigned count)
+#include "r300_clear.h"
+#include "r300_context.h"
+#include "r300_flush.h"
+#include "r300_query.h"
+#include "r300_render.h"
+#include "r300_screen.h"
+#include "r300_state_derived.h"
+#include "r300_state_invariant.h"
+#include "r300_winsys.h"
+
+static enum pipe_error r300_clear_hash_table(void* key, void* value,
+                                             void* data)
 {
-    return r300_draw_range_elements(pipe, indexBuffer, indexSize, 0, ~0,
-                                    mode, start, count);
+    FREE(key);
+    FREE(value);
+    return PIPE_OK;
 }
 
-static boolean r300_draw_arrays(struct pipe_context* pipe, unsigned mode,
-                                unsigned start, unsigned count)
+static void r300_destroy_context(struct pipe_context* context)
 {
-    return r300_draw_elements(pipe, NULL, 0, mode, start, count);
-}
-
-static void r300_destroy_context(struct pipe_context* context) {
     struct r300_context* r300 = r300_context(context);
+    struct r300_query* query, * temp;
+
+    util_hash_table_foreach(r300->shader_hash_table, r300_clear_hash_table,
+        NULL);
+    util_hash_table_destroy(r300->shader_hash_table);
 
     draw_destroy(r300->draw);
 
+    /* Free the OQ BO. */
+    context->screen->buffer_destroy(r300->oqbo);
+
+    /* If there are any queries pending or not destroyed, remove them now. */
+    foreach_s(query, temp, &r300->query_list) {
+        remove_from_list(query);
+        FREE(query);
+    }
+
     FREE(r300->blend_color_state);
     FREE(r300->rs_block);
     FREE(r300->scissor_state);
@@ -121,6 +98,13 @@ r300_is_buffer_referenced( struct pipe_context *pipe,
    return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
 }
 
+static void r300_flush_cb(void *data)
+{
+    struct r300_context* const cs_context_copy = data;
+
+    cs_context_copy->context.flush(&cs_context_copy->context, 0, NULL);
+}
+
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
                                          struct r300_winsys* r300_winsys)
 {
@@ -132,7 +116,9 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
     r300->winsys = r300_winsys;
 
     r300->context.winsys = (struct pipe_winsys*)r300_winsys;
-    r300->context.screen = r300_screen(screen);
+    r300->context.screen = screen;
+
+    r300_init_debug(r300);
 
     r300->context.destroy = r300_destroy_context;
 
@@ -140,11 +126,19 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
 
     r300->context.draw_arrays = r300_draw_arrays;
     r300->context.draw_elements = r300_draw_elements;
-    r300->context.draw_range_elements = r300_draw_range_elements;
+    r300->context.draw_range_elements = r300_swtcl_draw_range_elements;
 
     r300->context.is_texture_referenced = r300_is_texture_referenced;
     r300->context.is_buffer_referenced = r300_is_buffer_referenced;
 
+    r300->shader_hash_table = util_hash_table_create(r300_shader_key_hash,
+        r300_shader_key_compare);
+
+    r300->blend_color_state = CALLOC_STRUCT(r300_blend_color_state);
+    r300->rs_block = CALLOC_STRUCT(r300_rs_block);
+    r300->scissor_state = CALLOC_STRUCT(r300_scissor_state);
+    r300->viewport_state = CALLOC_STRUCT(r300_viewport_state);
+
     /* Create a Draw. This is used for vert collation and SW TCL. */
     r300->draw = draw_create();
     /* Enable our renderer. */
@@ -155,22 +149,23 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
      * transform in hardware, always. */
     draw_set_viewport_state(r300->draw, &r300_viewport_identity);
 
-    r300->blend_color_state = CALLOC_STRUCT(r300_blend_color_state);
-    r300->rs_block = CALLOC_STRUCT(r300_rs_block);
-    r300->scissor_state = CALLOC_STRUCT(r300_scissor_state);
-    r300->viewport_state = CALLOC_STRUCT(r300_viewport_state);
+    /* Open up the OQ BO. */
+    r300->oqbo = screen->buffer_create(screen, 4096,
+            PIPE_BUFFER_USAGE_VERTEX, 4096);
 
     r300_init_flush_functions(r300);
 
     r300_init_query_functions(r300);
 
-    r300_init_surface_functions(r300);
+    /* r300_init_surface_functions(r300); */
 
     r300_init_state_functions(r300);
 
     r300_emit_invariant_state(r300);
+
+    r300->winsys->set_flush_cb(r300->winsys, r300_flush_cb, r300);
     r300->dirty_state = R300_NEW_KITCHEN_SINK;
     r300->dirty_hw++;
-
+    make_empty_list(&r300->query_list);
     return &r300->context;
 }