Mesa (gallium-clip-state): nv50: adapt to new clip state

Christoph Bumiller chrisbmr at kemper.freedesktop.org
Tue Jan 3 22:56:23 UTC 2012


Module: Mesa
Branch: gallium-clip-state
Commit: c86ad730aa1c017788ae88a55f54071bf222be12
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c86ad730aa1c017788ae88a55f54071bf222be12

Author: Christoph Bumiller <e0425955 at student.tuwien.ac.at>
Date:   Tue Jan  3 23:51:30 2012 +0100

nv50: adapt to new clip state

---

 src/gallium/drivers/nv50/nv50_shader_state.c   |    6 --
 src/gallium/drivers/nv50/nv50_state.c          |   23 +++++++--
 src/gallium/drivers/nv50/nv50_state_validate.c |   59 +++++++++++++----------
 src/gallium/drivers/nv50/nv50_stateobj.h       |    2 +-
 src/gallium/drivers/nv50/nv50_surface.c        |    7 ---
 5 files changed, 52 insertions(+), 45 deletions(-)

diff --git a/src/gallium/drivers/nv50/nv50_shader_state.c b/src/gallium/drivers/nv50/nv50_shader_state.c
index d73f7c7..d3cdb69 100644
--- a/src/gallium/drivers/nv50/nv50_shader_state.c
+++ b/src/gallium/drivers/nv50/nv50_shader_state.c
@@ -171,12 +171,6 @@ nv50_vertprog_validate(struct nv50_context *nv50)
    struct nouveau_channel *chan = nv50->screen->base.channel;
    struct nv50_program *vp = nv50->vertprog;
 
-   if (nv50->clip.nr > vp->vp.clpd_nr) {
-      if (vp->translated)
-         nv50_program_destroy(nv50, vp);
-      vp->vp.clpd_nr = nv50->clip.nr;
-   }
-
    if (!nv50_program_validate(nv50, vp))
          return;
 
diff --git a/src/gallium/drivers/nv50/nv50_state.c b/src/gallium/drivers/nv50/nv50_state.c
index ede8713..0f46afb 100644
--- a/src/gallium/drivers/nv50/nv50_state.c
+++ b/src/gallium/drivers/nv50/nv50_state.c
@@ -225,6 +225,7 @@ nv50_rasterizer_state_create(struct pipe_context *pipe,
                              const struct pipe_rasterizer_state *cso)
 {
    struct nv50_rasterizer_stateobj *so;
+   uint32_t reg;
 
    so = CALLOC_STRUCT(nv50_rasterizer_stateobj);
    if (!so)
@@ -312,6 +313,22 @@ nv50_rasterizer_state_create(struct pipe_context *pipe,
       SB_DATA    (so, fui(cso->offset_clamp));
    }
 
+   if (cso->depth_clip) {
+      reg = 0;
+   } else {
+      reg =
+         NV50_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_CLAMP_NEAR |
+         NV50_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_CLAMP_FAR |
+         NV50_3D_VIEW_VOLUME_CLIP_CTRL_UNK12_UNK1;
+   }
+#ifndef NV50_SCISSORS_CLIPPING
+   reg |=
+      NV50_3D_VIEW_VOLUME_CLIP_CTRL_UNK7 |
+      NV50_3D_VIEW_VOLUME_CLIP_CTRL_UNK12_UNK1;
+#endif
+   SB_BEGIN_3D(so, VIEW_VOLUME_CLIP_CTRL, 1);
+   SB_DATA    (so, reg);
+
    assert(so->size <= (sizeof(so->state) / sizeof(so->state[0])));
    return (void *)so;
 }
@@ -763,12 +780,8 @@ nv50_set_clip_state(struct pipe_context *pipe,
                     const struct pipe_clip_state *clip)
 {
    struct nv50_context *nv50 = nv50_context(pipe);
-   const unsigned size = clip->nr * sizeof(clip->ucp[0]);
-
-   memcpy(&nv50->clip.ucp[0][0], &clip->ucp[0][0], size);
-   nv50->clip.nr = clip->nr;
 
-   nv50->clip.depth_clamp = clip->depth_clamp;
+   memcpy(nv50->clip.ucp, clip->ucp, sizeof(clip->ucp));
 
    nv50->dirty |= NV50_NEW_CLIP;
 }
diff --git a/src/gallium/drivers/nv50/nv50_state_validate.c b/src/gallium/drivers/nv50/nv50_state_validate.c
index 05f32ea..65ef4fc 100644
--- a/src/gallium/drivers/nv50/nv50_state_validate.c
+++ b/src/gallium/drivers/nv50/nv50_state_validate.c
@@ -213,42 +213,48 @@ nv50_validate_viewport(struct nv50_context *nv50)
 #endif
 }
 
+static INLINE void
+nv50_check_program_ucps(struct nv50_context *nv50,
+                        struct nv50_program *vp, uint8_t mask)
+{
+   const unsigned n = util_logbase2(mask) + 1;
+
+   if (vp->vp.clpd_nr >= n)
+      return;
+   nv50_program_destroy(nv50, vp);
+
+   vp->vp.clpd_nr = n;
+   if (likely(vp == nv50->vertprog))
+      nv50_vertprog_validate(nv50);
+   else
+      nv50_gmtyprog_validate(nv50);
+   nv50_fp_linkage_validate(nv50);
+}
+
 static void
 nv50_validate_clip(struct nv50_context *nv50)
 {
    struct nouveau_channel *chan = nv50->screen->base.channel;
-   uint32_t clip;
-
-   if (nv50->clip.depth_clamp) {
-      clip =
-         NV50_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_CLAMP_NEAR |
-         NV50_3D_VIEW_VOLUME_CLIP_CTRL_DEPTH_CLAMP_FAR |
-         NV50_3D_VIEW_VOLUME_CLIP_CTRL_UNK12_UNK1;
-   } else {
-      clip = 0;
-   }
-
-#ifndef NV50_SCISSORS_CLIPPING
-   clip |=
-      NV50_3D_VIEW_VOLUME_CLIP_CTRL_UNK7 |
-      NV50_3D_VIEW_VOLUME_CLIP_CTRL_UNK12_UNK1;
-#endif
-
-   BEGIN_RING(chan, RING_3D(VIEW_VOLUME_CLIP_CTRL), 1);
-   OUT_RING  (chan, clip);
+   struct nv50_program *vp;
+   uint8_t clip_enable;
 
-   if (nv50->clip.nr) {
+   if (nv50->dirty & NV50_NEW_CLIP) {
       BEGIN_RING(chan, RING_3D(CB_ADDR), 1);
       OUT_RING  (chan, (0 << 8) | NV50_CB_AUX);
-      BEGIN_RING_NI(chan, RING_3D(CB_DATA(0)), nv50->clip.nr * 4);
-      OUT_RINGp (chan, &nv50->clip.ucp[0][0], nv50->clip.nr * 4);
+      BEGIN_RING_NI(chan, RING_3D(CB_DATA(0)), PIPE_MAX_CLIP_PLANES * 4);
+      OUT_RINGp (chan, &nv50->clip.ucp[0][0], PIPE_MAX_CLIP_PLANES * 4);
    }
 
+   vp = nv50->gmtyprog;
+   if (likely(!vp))
+      vp = nv50->vertprog;
+
+   clip_enable = nv50->rast->pipe.user_clip_plane_enable;
+
    BEGIN_RING(chan, RING_3D(VP_CLIP_DISTANCE_ENABLE), 1);
-   OUT_RING  (chan, (1 << nv50->clip.nr) - 1);
+   OUT_RING  (chan, clip_enable);
 
-   if (nv50->vertprog && nv50->clip.nr > nv50->vertprog->vp.clpd_nr)
-      nv50->dirty |= NV50_NEW_VERTPROG;
+   nv50_check_program_ucps(nv50, vp, clip_enable);
 }
 
 static void
@@ -350,7 +356,8 @@ static struct state_validate {
     { nv50_validate_scissor,       NV50_NEW_SCISSOR },
 #endif
     { nv50_validate_viewport,      NV50_NEW_VIEWPORT },
-    { nv50_validate_clip,          NV50_NEW_CLIP },
+    { nv50_validate_clip,          NV50_NEW_CLIP | NV50_NEW_RASTERIZER |
+                                   NV50_NEW_VERTPROG | NV50_NEW_GMTYPROG },
     { nv50_vertprog_validate,      NV50_NEW_VERTPROG },
     { nv50_gmtyprog_validate,      NV50_NEW_GMTYPROG },
     { nv50_fragprog_validate,      NV50_NEW_FRAGPROG },
diff --git a/src/gallium/drivers/nv50/nv50_stateobj.h b/src/gallium/drivers/nv50/nv50_stateobj.h
index 83a08b0..c443dfb 100644
--- a/src/gallium/drivers/nv50/nv50_stateobj.h
+++ b/src/gallium/drivers/nv50/nv50_stateobj.h
@@ -27,7 +27,7 @@ struct nv50_blend_stateobj {
 struct nv50_rasterizer_stateobj {
    struct pipe_rasterizer_state pipe;
    int size;
-   uint32_t state[46];
+   uint32_t state[48];
 };
 
 struct nv50_zsa_stateobj {
diff --git a/src/gallium/drivers/nv50/nv50_surface.c b/src/gallium/drivers/nv50/nv50_surface.c
index 910e18f..28e34bd 100644
--- a/src/gallium/drivers/nv50/nv50_surface.c
+++ b/src/gallium/drivers/nv50/nv50_surface.c
@@ -433,7 +433,6 @@ struct nv50_blitctx
       struct pipe_sampler_view *texture;
       struct nv50_tsc_entry *sampler;
       unsigned dirty;
-      unsigned clip_nr;
    } saved;
    struct nv50_program vp;
    struct nv50_program fp;
@@ -775,10 +774,6 @@ nv50_blitctx_pre_blit(struct nv50_blitctx *blit, struct nv50_context *nv50)
    nv50->gmtyprog = NULL;
    nv50->fragprog = &blit->fp;
 
-   blit->saved.clip_nr = nv50->clip.nr;
-
-   nv50->clip.nr = 0;
-
    for (s = 0; s < 3; ++s) {
       blit->saved.num_textures[s] = nv50->num_textures[s];
       blit->saved.num_samplers[s] = nv50->num_samplers[s];
@@ -816,8 +811,6 @@ nv50_blitctx_post_blit(struct nv50_context *nv50, struct nv50_blitctx *blit)
    nv50->gmtyprog = blit->saved.gp;
    nv50->fragprog = blit->saved.fp;
 
-   nv50->clip.nr = blit->saved.clip_nr;
-
    pipe_sampler_view_reference(&nv50->textures[2][0], NULL);
 
    for (s = 0; s < 3; ++s) {




More information about the mesa-commit mailing list