failover: Fix after sampler view changes.
authorMichal Krol <michal@vmware.com>
Tue, 23 Feb 2010 15:09:10 +0000 (16:09 +0100)
committerMichal Krol <michal@vmware.com>
Tue, 23 Feb 2010 15:09:10 +0000 (16:09 +0100)
src/gallium/drivers/failover/fo_context.h
src/gallium/drivers/failover/fo_state.c
src/gallium/drivers/failover/fo_state_emit.c

index ae3b0b0c189deab489c533d5c813c2d03f7ef0a1..53e1a02bcba1f38fea25f909d719902d0724a686 100644 (file)
@@ -47,7 +47,7 @@
 #define FO_NEW_ALPHA_TEST      0x100
 #define FO_NEW_DEPTH_STENCIL   0x200
 #define FO_NEW_SAMPLER         0x400
-#define FO_NEW_TEXTURE         0x800
+#define FO_NEW_SAMPLER_VIEW    0x800
 #define FO_NEW_VERTEX          0x2000
 #define FO_NEW_VERTEX_SHADER   0x4000
 #define FO_NEW_BLEND_COLOR     0x8000
@@ -65,6 +65,13 @@ struct fo_state {
    void *sw_state;
    void *hw_state;
 };
+
+struct fo_sampler_view {
+   struct pipe_sampler_view base;
+   struct pipe_sampler_view *sw;
+   struct pipe_sampler_view *hw;
+};
+
 struct failover_context {
    struct pipe_context pipe;  /**< base class */
 
@@ -85,8 +92,6 @@ struct failover_context {
    struct pipe_framebuffer_state framebuffer;
    struct pipe_poly_stipple poly_stipple;
    struct pipe_scissor_state scissor;
-   struct pipe_sampler_view *sampler_views[PIPE_MAX_SAMPLERS];
-   struct pipe_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
    struct pipe_viewport_state viewport;
    struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS];
    struct pipe_vertex_element vertex_elements[PIPE_MAX_ATTRIBS];
@@ -99,12 +104,15 @@ struct failover_context {
    void *sw_vertex_sampler_state[PIPE_MAX_VERTEX_SAMPLERS];
    void *hw_vertex_sampler_state[PIPE_MAX_VERTEX_SAMPLERS];
 
+   struct fo_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
+   struct fo_sampler_view *vertex_sampler_views[PIPE_MAX_VERTEX_SAMPLERS];
+   unsigned num_fragment_sampler_views;
+   unsigned num_vertex_sampler_views;
+
    unsigned dirty;
 
    unsigned num_samplers;
    unsigned num_vertex_samplers;
-   unsigned num_sampler_views;
-   unsigned num_vertex_sampler_views;
 
    unsigned mode;
    struct pipe_context *hw;
index b16f2197f11d4ee55f0cdf7a5cd0a752389ef074..d0c2f1474aecf01640761413023ee9272179af5b 100644 (file)
@@ -404,30 +404,66 @@ failover_delete_sampler_state(struct pipe_context *pipe, void *sampler)
 }
 
 
+static struct pipe_sampler_view *
+failover_create_sampler_view(struct pipe_context *pipe,
+                             struct pipe_texture *texture,
+                             const struct pipe_sampler_view *templ)
+{
+   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);
+   view->hw = failover->hw->create_sampler_view(failover->hw, texture, templ);
+
+   view->base = *templ;
+   view->base.reference.count = 1;
+   view->base.texture = NULL;
+   pipe_texture_reference(&view->base.texture, texture);
+   view->base.context = pipe;
+
+   return &view->base;
+}
+
+static void
+failover_sampler_view_destroy(struct pipe_context *pipe,
+                              struct pipe_sampler_view *view)
+{
+   struct fo_sampler_view *fo_view = (struct fo_sampler_view *)view;
+   struct failover_context *failover = failover_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);
+}
+
 static void
 failover_set_fragment_sampler_views(struct pipe_context *pipe,
                                     unsigned num,
                                     struct pipe_sampler_view **views)
 {
    struct failover_context *failover = failover_context(pipe);
+   struct pipe_sampler_view *hw_views[PIPE_MAX_SAMPLERS];
    uint i;
 
    assert(num <= PIPE_MAX_SAMPLERS);
 
    /* Check for no-op */
-   if (num == failover->num_sampler_views &&
-       !memcmp(failover->sampler_views, views, num * sizeof(struct pipe_sampler_view *)))
+   if (num == failover->num_fragment_sampler_views &&
+       !memcmp(failover->fragment_sampler_views, views, num * sizeof(struct pipe_sampler_view *)))
       return;
-   for (i = 0; i < num; i++)
-      pipe_sampler_view_reference((struct pipe_sampler_view **) &failover->sampler_views[i],
-                                  views[i]);
-   for (i = num; i < failover->num_sampler_views; i++)
-      pipe_sampler_view_reference((struct pipe_sampler_view **) &failover->sampler_views[i],
-                                  NULL);
-   failover->dirty |= FO_NEW_TEXTURE;
-   failover->num_sampler_views = num;
-   failover->sw->set_fragment_sampler_views( failover->sw, num, views );
-   failover->hw->set_fragment_sampler_views( failover->hw, num, views );
+   for (i = 0; i < num; i++) {
+      struct fo_sampler_view *fo_view = (struct fo_sampler_view *)views[i];
+
+      pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->fragment_sampler_views[i], views[i]);
+      hw_views[i] = fo_view->hw;
+   }
+   for (i = num; i < failover->num_fragment_sampler_views; i++)
+      pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->fragment_sampler_views[i], NULL);
+   failover->dirty |= FO_NEW_SAMPLER_VIEW;
+   failover->num_fragment_sampler_views = num;
+   failover->hw->set_fragment_sampler_views(failover->hw, num, hw_views);
 }
 
 
@@ -437,6 +473,7 @@ failover_set_vertex_sampler_views(struct pipe_context *pipe,
                                   struct pipe_sampler_view **views)
 {
    struct failover_context *failover = failover_context(pipe);
+   struct pipe_sampler_view *hw_views[PIPE_MAX_VERTEX_SAMPLERS];
    uint i;
 
    assert(num <= PIPE_MAX_VERTEX_SAMPLERS);
@@ -447,17 +484,16 @@ failover_set_vertex_sampler_views(struct pipe_context *pipe,
       return;
    }
    for (i = 0; i < num; i++) {
-      pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i],
-                                  views[i]);
-   }
-   for (i = num; i < failover->num_vertex_sampler_views; i++) {
-      pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i],
-                                  NULL);
+      struct fo_sampler_view *fo_view = (struct fo_sampler_view *)views[i];
+
+      pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], views[i]);
+      hw_views[i] = fo_view->hw;
    }
-   failover->dirty |= FO_NEW_TEXTURE;
+   for (i = num; i < failover->num_vertex_sampler_views; i++)
+      pipe_sampler_view_reference((struct pipe_sampler_view **)&failover->vertex_sampler_views[i], NULL);
+   failover->dirty |= FO_NEW_SAMPLER_VIEW;
    failover->num_vertex_sampler_views = num;
-   failover->sw->set_vertex_sampler_views(failover->sw, num, views);
-   failover->hw->set_vertex_sampler_views(failover->hw, num, views);
+   failover->hw->set_vertex_sampler_views(failover->hw, num, hw_views);
 }
 
 
@@ -556,4 +592,6 @@ failover_init_state_functions( struct failover_context *failover )
    failover->pipe.set_vertex_buffers = failover_set_vertex_buffers;
    failover->pipe.set_vertex_elements = failover_set_vertex_elements;
    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;
 }
index 1c37668027fdbe5162188f47856b471fccd56f00..171151e1ee2230e4e6a22f6db9071dc5bf621e58 100644 (file)
@@ -102,12 +102,24 @@ failover_state_emit( struct failover_context *failover )
                                                failover->sw_vertex_sampler_state);
    }
 
-   if (failover->dirty & FO_NEW_TEXTURE) {
-      failover->sw->set_fragment_sampler_views( failover->sw, failover->num_sampler_views, 
-                                                failover->sampler_views );
+   if (failover->dirty & FO_NEW_SAMPLER_VIEW) {
+      struct pipe_sampler_view *fragment_views[PIPE_MAX_SAMPLERS];
+      struct pipe_sampler_view *vertex_views[PIPE_MAX_VERTEX_SAMPLERS];
+      uint i;
+
+      for (i = 0; i < failover->num_fragment_sampler_views; i++) {
+         fragment_views[i] = failover->fragment_sampler_views[i]->sw;
+      }
+      failover->sw->set_fragment_sampler_views(failover->sw,
+                                               failover->num_fragment_sampler_views,
+                                               fragment_views);
+
+      for (i = 0; i < failover->num_vertex_sampler_views; i++) {
+         vertex_views[i] = failover->vertex_sampler_views[i]->sw;
+      }
       failover->sw->set_vertex_sampler_views(failover->sw,
-                                             failover->num_vertex_sampler_views, 
-                                             failover->vertex_sampler_views);
+                                             failover->num_vertex_sampler_views,
+                                             vertex_views);
    }
 
    if (failover->dirty & FO_NEW_VERTEX_BUFFER) {