gallium: notify drivers about possible changes in user buffer contents
[mesa.git] / src / gallium / drivers / failover / fo_state.c
index 25c6273570520ee98e434be680e51efb7de38e0e..b4da1b8b9016c00087a2f3265f6482522ec30516 100644 (file)
@@ -29,6 +29,8 @@
  */
 
 #include "util/u_inlines.h"
+#include "util/u_memory.h"
+#include "util/u_transfer.h"
 
 #include "fo_context.h"
 
@@ -53,7 +55,7 @@ static void *
 failover_create_blend_state( struct pipe_context *pipe,
                              const struct pipe_blend_state *blend )
 {
-   struct fo_state *state = malloc(sizeof(struct fo_state));
+   struct fo_state *state = MALLOC(sizeof(struct fo_state));
    struct failover_context *failover = failover_context(pipe);
 
    state->sw_state = failover->sw->create_blend_state(failover->sw, blend);
@@ -85,7 +87,7 @@ failover_delete_blend_state( struct pipe_context *pipe,
    failover->hw->delete_blend_state(failover->hw, state->hw_state);
    state->sw_state = 0;
    state->hw_state = 0;
-   free(state);
+   FREE(state);
 }
 
 static void
@@ -124,12 +126,25 @@ failover_set_clip_state( struct pipe_context *pipe,
    failover->hw->set_clip_state( failover->hw, clip );
 }
 
+static void
+failover_set_sample_mask(struct pipe_context *pipe,
+                         unsigned sample_mask)
+{
+   struct failover_context *failover = failover_context(pipe);
+
+   failover->sample_mask = sample_mask;
+   failover->dirty |= FO_NEW_SAMPLE_MASK;
+   failover->sw->set_sample_mask( failover->sw, sample_mask );
+   failover->hw->set_sample_mask( failover->hw, sample_mask );
+
+}
+
 
 static void *
 failover_create_depth_stencil_state(struct pipe_context *pipe,
                               const struct pipe_depth_stencil_alpha_state *templ)
 {
-   struct fo_state *state = malloc(sizeof(struct fo_state));
+   struct fo_state *state = MALLOC(sizeof(struct fo_state));
    struct failover_context *failover = failover_context(pipe);
 
    state->sw_state = failover->sw->create_depth_stencil_alpha_state(failover->sw, templ);
@@ -161,7 +176,7 @@ failover_delete_depth_stencil_state(struct pipe_context *pipe,
    failover->hw->delete_depth_stencil_alpha_state(failover->hw, state->hw_state);
    state->sw_state = 0;
    state->hw_state = 0;
-   free(state);
+   FREE(state);
 }
 
 static void
@@ -181,7 +196,7 @@ static void *
 failover_create_fs_state(struct pipe_context *pipe,
                          const struct pipe_shader_state *templ)
 {
-   struct fo_state *state = malloc(sizeof(struct fo_state));
+   struct fo_state *state = MALLOC(sizeof(struct fo_state));
    struct failover_context *failover = failover_context(pipe);
 
    state->sw_state = failover->sw->create_fs_state(failover->sw, templ);
@@ -212,14 +227,14 @@ failover_delete_fs_state(struct pipe_context *pipe,
    failover->hw->delete_fs_state(failover->hw, state->hw_state);
    state->sw_state = 0;
    state->hw_state = 0;
-   free(state);
+   FREE(state);
 }
 
 static void *
 failover_create_vs_state(struct pipe_context *pipe,
                          const struct pipe_shader_state *templ)
 {
-   struct fo_state *state = malloc(sizeof(struct fo_state));
+   struct fo_state *state = MALLOC(sizeof(struct fo_state));
    struct failover_context *failover = failover_context(pipe);
 
    state->sw_state = failover->sw->create_vs_state(failover->sw, templ);
@@ -252,7 +267,7 @@ failover_delete_vs_state(struct pipe_context *pipe,
    failover->hw->delete_vs_state(failover->hw, state->hw_state);
    state->sw_state = 0;
    state->hw_state = 0;
-   free(state);
+   FREE(state);
 }
 
 
@@ -262,7 +277,7 @@ failover_create_vertex_elements_state( struct pipe_context *pipe,
                                        unsigned count,
                                        const struct pipe_vertex_element *velems )
 {
-   struct fo_state *state = malloc(sizeof(struct fo_state));
+   struct fo_state *state = MALLOC(sizeof(struct fo_state));
    struct failover_context *failover = failover_context(pipe);
 
    state->sw_state = failover->sw->create_vertex_elements_state(failover->sw, count, velems);
@@ -295,7 +310,7 @@ failover_delete_vertex_elements_state( struct pipe_context *pipe,
    failover->hw->delete_vertex_elements_state(failover->hw, state->hw_state);
    state->sw_state = 0;
    state->hw_state = 0;
-   free(state);
+   FREE(state);
 }
 
 static void 
@@ -315,7 +330,7 @@ static void *
 failover_create_rasterizer_state(struct pipe_context *pipe,
                                  const struct pipe_rasterizer_state *templ)
 {
-   struct fo_state *state = malloc(sizeof(struct fo_state));
+   struct fo_state *state = MALLOC(sizeof(struct fo_state));
    struct failover_context *failover = failover_context(pipe);
 
    state->sw_state = failover->sw->create_rasterizer_state(failover->sw, templ);
@@ -348,7 +363,7 @@ failover_delete_rasterizer_state(struct pipe_context *pipe,
    failover->hw->delete_rasterizer_state(failover->hw, state->hw_state);
    state->sw_state = 0;
    state->hw_state = 0;
-   free(state);
+   FREE(state);
 }
 
 
@@ -369,7 +384,7 @@ static void *
 failover_create_sampler_state(struct pipe_context *pipe,
                               const struct pipe_sampler_state *templ)
 {
-   struct fo_state *state = malloc(sizeof(struct fo_state));
+   struct fo_state *state = MALLOC(sizeof(struct fo_state));
    struct failover_context *failover = failover_context(pipe);
 
    state->sw_state = failover->sw->create_sampler_state(failover->sw, templ);
@@ -443,16 +458,16 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler)
    failover->hw->delete_sampler_state(failover->hw, state->hw_state);
    state->sw_state = 0;
    state->hw_state = 0;
-   free(state);
+   FREE(state);
 }
 
 
 static struct pipe_sampler_view *
 failover_create_sampler_view(struct pipe_context *pipe,
-                             struct pipe_texture *texture,
+                             struct pipe_resource *texture,
                              const struct pipe_sampler_view *templ)
 {
-   struct fo_sampler_view *view = malloc(sizeof(struct fo_sampler_view));
+   struct fo_sampler_view *view = MALLOC(sizeof(struct fo_sampler_view));
    struct failover_context *failover = failover_context(pipe);
 
    view->sw = failover->sw->create_sampler_view(failover->sw, texture, templ);
@@ -461,7 +476,7 @@ failover_create_sampler_view(struct pipe_context *pipe,
    view->base = *templ;
    view->base.reference.count = 1;
    view->base.texture = NULL;
-   pipe_texture_reference(&view->base.texture, texture);
+   pipe_resource_reference(&view->base.texture, texture);
    view->base.context = pipe;
 
    return &view->base;
@@ -477,8 +492,8 @@ failover_sampler_view_destroy(struct pipe_context *pipe,
    failover->sw->sampler_view_destroy(failover->sw, fo_view->sw);
    failover->hw->sampler_view_destroy(failover->hw, fo_view->hw);
 
-   pipe_texture_reference(&fo_view->base.texture, NULL);
-   free(fo_view);
+   pipe_resource_reference(&fo_view->base.texture, NULL);
+   FREE(fo_view);
 }
 
 static void
@@ -560,27 +575,44 @@ failover_set_vertex_buffers(struct pipe_context *pipe,
 {
    struct failover_context *failover = failover_context(pipe);
 
-   memcpy(failover->vertex_buffers, vertex_buffers,
-          count * sizeof(vertex_buffers[0]));
+   util_copy_vertex_buffers(failover->vertex_buffers,
+                            &failover->num_vertex_buffers,
+                            vertex_buffers, count);
    failover->dirty |= FO_NEW_VERTEX_BUFFER;
-   failover->num_vertex_buffers = count;
    failover->sw->set_vertex_buffers( failover->sw, count, vertex_buffers );
    failover->hw->set_vertex_buffers( failover->hw, count, vertex_buffers );
 }
 
 
+static void
+failover_set_index_buffer(struct pipe_context *pipe,
+                          const struct pipe_index_buffer *ib)
+{
+   struct failover_context *failover = failover_context(pipe);
+
+   if (ib)
+      memcpy(&failover->index_buffer, ib, sizeof(failover->index_buffer));
+   else
+      memset(&failover->index_buffer, 0, sizeof(failover->index_buffer));
+
+   failover->dirty |= FO_NEW_INDEX_BUFFER;
+   failover->sw->set_index_buffer( failover->sw, ib );
+   failover->hw->set_index_buffer( failover->hw, ib );
+}
+
+
 void
 failover_set_constant_buffer(struct pipe_context *pipe,
                              uint shader, uint index,
-                             struct pipe_buffer *buf)
+                             struct pipe_resource *res)
 {
    struct failover_context *failover = failover_context(pipe);
 
    assert(shader < PIPE_SHADER_TYPES);
    assert(index == 0);
 
-   failover->sw->set_constant_buffer(failover->sw, shader, index, buf);
-   failover->hw->set_constant_buffer(failover->hw, shader, index, buf);
+   failover->sw->set_constant_buffer(failover->sw, shader, index, res);
+   failover->hw->set_constant_buffer(failover->hw, shader, index, res);
 }
 
 
@@ -613,6 +645,7 @@ failover_init_state_functions( struct failover_context *failover )
    failover->pipe.set_blend_color = failover_set_blend_color;
    failover->pipe.set_stencil_ref = failover_set_stencil_ref;
    failover->pipe.set_clip_state = failover_set_clip_state;
+   failover->pipe.set_sample_mask = failover_set_sample_mask;
    failover->pipe.set_framebuffer_state = failover_set_framebuffer_state;
    failover->pipe.set_polygon_stipple = failover_set_polygon_stipple;
    failover->pipe.set_scissor_state = failover_set_scissor_state;
@@ -620,7 +653,9 @@ failover_init_state_functions( struct failover_context *failover )
    failover->pipe.set_vertex_sampler_views = failover_set_vertex_sampler_views;
    failover->pipe.set_viewport_state = failover_set_viewport_state;
    failover->pipe.set_vertex_buffers = failover_set_vertex_buffers;
+   failover->pipe.set_index_buffer = failover_set_index_buffer;
    failover->pipe.set_constant_buffer = failover_set_constant_buffer;
    failover->pipe.create_sampler_view = failover_create_sampler_view;
    failover->pipe.sampler_view_destroy = failover_sampler_view_destroy;
+   failover->pipe.redefine_user_buffer = u_default_redefine_user_buffer;
 }