Mesa (gallium-no-rhw-position): cso: Track clip state with cso context.

Michał Król michal at kemper.freedesktop.org
Wed Feb 24 15:41:32 UTC 2010


Module: Mesa
Branch: gallium-no-rhw-position
Commit: 227ae7b968c1351921babdbf6f052239766ffce4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=227ae7b968c1351921babdbf6f052239766ffce4

Author: Michal Krol <michal at vmware.com>
Date:   Wed Feb 24 15:16:54 2010 +0100

cso: Track clip state with cso context.

---

 src/gallium/auxiliary/cso_cache/cso_context.c |   54 +++++++++++++++++++++++++
 src/gallium/auxiliary/cso_cache/cso_context.h |   13 ++++++
 2 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/src/gallium/auxiliary/cso_cache/cso_context.c b/src/gallium/auxiliary/cso_cache/cso_context.c
index b5241fa..a7335c3 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.c
+++ b/src/gallium/auxiliary/cso_cache/cso_context.c
@@ -90,6 +90,9 @@ struct cso_context {
    void *fragment_shader, *fragment_shader_saved, *geometry_shader;
    void *vertex_shader, *vertex_shader_saved, *geometry_shader_saved;
 
+   struct pipe_clip_state clip;
+   struct pipe_clip_state clip_saved;
+
    struct pipe_framebuffer_state fb, fb_saved;
    struct pipe_viewport_state vp, vp_saved;
    struct pipe_blend_color blend_color;
@@ -1126,3 +1129,54 @@ void cso_restore_geometry_shader(struct cso_context *ctx)
    }
    ctx->geometry_shader_saved = NULL;
 }
+
+
+/* clip state */
+
+static INLINE void
+clip_state_cpy(struct pipe_clip_state *dst,
+               const struct pipe_clip_state *src)
+{
+   dst->nr = src->nr;
+   if (src->nr) {
+      memcpy(dst->ucp, src->ucp, src->nr * sizeof(src->ucp[0]));
+   }
+}
+
+static INLINE int
+clip_state_cmp(const struct pipe_clip_state *a,
+               const struct pipe_clip_state *b)
+{
+   if (a->nr != b->nr) {
+      return 1;
+   }
+   if (a->nr) {
+      return memcmp(a->ucp, b->ucp, a->nr * sizeof(a->ucp[0]));
+   }
+   return 0;
+}
+
+void
+cso_set_clip(struct cso_context *ctx,
+             const struct pipe_clip_state *clip)
+{
+   if (clip_state_cmp(&ctx->clip, clip)) {
+      clip_state_cpy(&ctx->clip, clip);
+      ctx->pipe->set_clip_state(ctx->pipe, clip);
+   }
+}
+
+void
+cso_save_clip(struct cso_context *ctx)
+{
+   clip_state_cpy(&ctx->clip_saved, &ctx->clip);
+}
+
+void
+cso_restore_clip(struct cso_context *ctx)
+{
+   if (clip_state_cmp(&ctx->clip, &ctx->clip_saved)) {
+      clip_state_cpy(&ctx->clip, &ctx->clip_saved);
+      ctx->pipe->set_clip_state(ctx->pipe, &ctx->clip_saved);
+   }
+}
diff --git a/src/gallium/auxiliary/cso_cache/cso_context.h b/src/gallium/auxiliary/cso_cache/cso_context.h
index 707b3c2..251a9a6 100644
--- a/src/gallium/auxiliary/cso_cache/cso_context.h
+++ b/src/gallium/auxiliary/cso_cache/cso_context.h
@@ -180,6 +180,19 @@ void cso_save_stencil_ref(struct cso_context *cso);
 void cso_restore_stencil_ref(struct cso_context *cso);
 
 
+/* clip state */
+
+void
+cso_set_clip(struct cso_context *cso,
+             const struct pipe_clip_state *clip);
+
+void
+cso_save_clip(struct cso_context *cso);
+
+void
+cso_restore_clip(struct cso_context *cso);
+
+
 #ifdef	__cplusplus
 }
 #endif




More information about the mesa-commit mailing list