Squashed commit of the following:
[mesa.git] / src / gallium / drivers / i915 / i915_context.c
index 94c8aee30feeebcc9c2ebdfbfaab7cae45ca8a4e..4ae52911158190af66a0b89072f359696b70fa0d 100644 (file)
 #include "i915_context.h"
 #include "i915_state.h"
 #include "i915_screen.h"
+#include "i915_surface.h"
 #include "i915_batch.h"
-#include "i915_texture.h"
-#include "i915_reg.h"
+#include "i915_resource.h"
 
 #include "draw/draw_context.h"
 #include "pipe/p_defines.h"
-#include "pipe/internal/p_winsys_screen.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
 #include "util/u_memory.h"
 #include "pipe/p_screen.h"
 
@@ -45,9 +44,9 @@
  */
 
 
-static boolean
+static void
 i915_draw_range_elements(struct pipe_context *pipe,
-                         struct pipe_buffer *indexBuffer,
+                         struct pipe_resource *indexBuffer,
                          unsigned indexSize,
                          unsigned min_index,
                          unsigned max_index,
@@ -64,8 +63,7 @@ i915_draw_range_elements(struct pipe_context *pipe,
     * Map vertex buffers
     */
    for (i = 0; i < i915->num_vertex_buffers; i++) {
-      void *buf = pipe_buffer_map(pipe->screen, i915->vertex_buffer[i].buffer,
-                                  PIPE_BUFFER_USAGE_CPU_READ);
+      void *buf = i915_buffer(i915->vertex_buffer[i].buffer)->data;
       draw_set_mapped_vertex_buffer(draw, i, buf);
    }
 
@@ -73,8 +71,7 @@ i915_draw_range_elements(struct pipe_context *pipe,
     * Map index buffer, if present
     */
    if (indexBuffer) {
-      void *mapped_indexes = pipe_buffer_map(pipe->screen, indexBuffer,
-                                             PIPE_BUFFER_USAGE_CPU_READ);
+      void *mapped_indexes = i915_buffer(indexBuffer)->data;
       draw_set_mapped_element_buffer_range(draw, indexSize,
                                            min_index,
                                            max_index,
@@ -84,7 +81,7 @@ i915_draw_range_elements(struct pipe_context *pipe,
    }
 
 
-   draw_set_mapped_constant_buffer(draw,
+   draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0,
                                    i915->current.constants[PIPE_SHADER_VERTEX],
                                    (i915->current.num_user_constants[PIPE_SHADER_VERTEX] * 
                                       4 * sizeof(float)));
@@ -98,69 +95,34 @@ i915_draw_range_elements(struct pipe_context *pipe,
     * unmap vertex/index buffers
     */
    for (i = 0; i < i915->num_vertex_buffers; i++) {
-      pipe_buffer_unmap(pipe->screen, i915->vertex_buffer[i].buffer);
       draw_set_mapped_vertex_buffer(draw, i, NULL);
    }
 
    if (indexBuffer) {
-      pipe_buffer_unmap(pipe->screen, indexBuffer);
-      draw_set_mapped_element_buffer_range(draw, 0, start, start + count - 1, NULL);
+      draw_set_mapped_element_buffer(draw, 0, NULL);
    }
-
-   return TRUE;
 }
 
-static boolean
+static void
 i915_draw_elements(struct pipe_context *pipe,
-                   struct pipe_buffer *indexBuffer,
+                   struct pipe_resource *indexBuffer,
                    unsigned indexSize,
                    unsigned prim, unsigned start, unsigned count)
 {
-   return i915_draw_range_elements(pipe, indexBuffer,
-                                   indexSize,
-                                   0, 0xffffffff,
-                                   prim, start, count);
+   i915_draw_range_elements(pipe, indexBuffer,
+                            indexSize,
+                            0, 0xffffffff,
+                            prim, start, count);
 }
 
-static boolean
+static void
 i915_draw_arrays(struct pipe_context *pipe,
                  unsigned prim, unsigned start, unsigned count)
 {
-   return i915_draw_elements(pipe, NULL, 0, prim, start, count);
+   i915_draw_elements(pipe, NULL, 0, prim, start, count);
 }
 
 
-/*
- * Is referenced functions
- */
-
-
-static unsigned int
-i915_is_texture_referenced(struct pipe_context *pipe,
-                           struct pipe_texture *texture,
-                           unsigned face, unsigned level)
-{
-   /**
-    * FIXME: Return the corrent result. We can't alays return referenced
-    *        since it causes a double flush within the vbo module.
-    */
-#if 0
-   return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
-#else
-   return 0;
-#endif
-}
-
-static unsigned int
-i915_is_buffer_referenced(struct pipe_context *pipe,
-                          struct pipe_buffer *buf)
-{
-   /*
-    * Since we never expose hardware buffers to the state tracker
-    * they can never be referenced, so this isn't a lie
-    */
-   return 0;
-}
 
 
 /*
@@ -188,7 +150,7 @@ static void i915_destroy(struct pipe_context *pipe)
 }
 
 struct pipe_context *
-i915_create_context(struct pipe_screen *screen)
+i915_create_context(struct pipe_screen *screen, void *priv)
 {
    struct i915_context *i915;
 
@@ -199,6 +161,7 @@ i915_create_context(struct pipe_screen *screen)
    i915->iws = i915_screen(screen)->iws;
    i915->base.winsys = NULL;
    i915->base.screen = screen;
+   i915->base.priv = priv;
 
    i915->base.destroy = i915_destroy;
 
@@ -208,9 +171,6 @@ i915_create_context(struct pipe_screen *screen)
    i915->base.draw_elements = i915_draw_elements;
    i915->base.draw_range_elements = i915_draw_range_elements;
 
-   i915->base.is_texture_referenced = i915_is_texture_referenced;
-   i915->base.is_buffer_referenced = i915_is_buffer_referenced;
-
    /*
     * Create drawing context and plug our rendering stage into it.
     */
@@ -225,6 +185,7 @@ i915_create_context(struct pipe_screen *screen)
    i915_init_surface_functions(i915);
    i915_init_state_functions(i915);
    i915_init_flush_functions(i915);
+   i915_init_resource_functions(i915);
 
    draw_install_aaline_stage(i915->draw, &i915->base);
    draw_install_aapoint_stage(i915->draw, &i915->base);