Mesa (master): nv50,nvc0: implement colour clamping controls

Christoph Bumiller chrisbmr at kemper.freedesktop.org
Tue Mar 29 21:10:43 UTC 2011


Module: Mesa
Branch: master
Commit: 8f060df60d1f5ad63a341e39f2ec5a0c3c452cf5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8f060df60d1f5ad63a341e39f2ec5a0c3c452cf5

Author: Christoph Bumiller <e0425955 at student.tuwien.ac.at>
Date:   Tue Mar 29 23:09:02 2011 +0200

nv50,nvc0: implement colour clamping controls

---

 src/gallium/drivers/nv50/nv50_3d.xml.h         |    2 +-
 src/gallium/drivers/nv50/nv50_context.h        |    4 ++-
 src/gallium/drivers/nv50/nv50_program.c        |    2 +-
 src/gallium/drivers/nv50/nv50_screen.c         |    2 +
 src/gallium/drivers/nv50/nv50_shader_state.c   |   41 +++++++++++++++++++++++-
 src/gallium/drivers/nv50/nv50_state.c          |    3 ++
 src/gallium/drivers/nv50/nv50_state_validate.c |    2 +-
 src/gallium/drivers/nv50/nv50_stateobj.h       |    2 +-
 src/gallium/drivers/nvc0/nvc0_screen.c         |    4 +-
 src/gallium/drivers/nvc0/nvc0_shader_state.c   |    2 -
 src/gallium/drivers/nvc0/nvc0_state.c          |    4 ++
 src/gallium/drivers/nvc0/nvc0_stateobj.h       |    2 +-
 12 files changed, 59 insertions(+), 11 deletions(-)

diff --git a/src/gallium/drivers/nv50/nv50_3d.xml.h b/src/gallium/drivers/nv50/nv50_3d.xml.h
index 9bb3211..92b97dd 100644
--- a/src/gallium/drivers/nv50/nv50_3d.xml.h
+++ b/src/gallium/drivers/nv50/nv50_3d.xml.h
@@ -1673,7 +1673,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define NV50_3D_MAP_SEMANTIC_0_BFC0_ID__SHIFT			8
 #define NV50_3D_MAP_SEMANTIC_0_COLR_NR__MASK			0x00ff0000
 #define NV50_3D_MAP_SEMANTIC_0_COLR_NR__SHIFT			16
-#define NV50_3D_MAP_SEMANTIC_0_CLMP_EN				0xff000000
+#define NV50_3D_MAP_SEMANTIC_0_CLMP_EN				0x01000000
 
 #define NV50_3D_MAP_SEMANTIC_1					0x00001908
 #define NV50_3D_MAP_SEMANTIC_1_CLIP_START__MASK			0x000000ff
diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h
index 46e6c22..f480f04 100644
--- a/src/gallium/drivers/nv50/nv50_context.h
+++ b/src/gallium/drivers/nv50/nv50_context.h
@@ -80,6 +80,8 @@ struct nv50_context {
       uint32_t instance_elts; /* bitmask of per-instance elements */
       uint32_t instance_base;
       uint32_t interpolant_ctrl;
+      uint32_t semantic_color;
+      uint32_t semantic_psize;
       int32_t index_bias;
       boolean prim_restart;
       boolean point_sprite;
@@ -183,7 +185,7 @@ void nv50_fragprog_validate(struct nv50_context *);
 void nv50_fp_linkage_validate(struct nv50_context *);
 void nv50_gp_linkage_validate(struct nv50_context *);
 void nv50_constbufs_validate(struct nv50_context *);
-void nv50_sprite_coords_validate(struct nv50_context *);
+void nv50_validate_derived_rs(struct nv50_context *);
 
 /* nv50_state.c */
 extern void nv50_init_state_functions(struct nv50_context *);
diff --git a/src/gallium/drivers/nv50/nv50_program.c b/src/gallium/drivers/nv50/nv50_program.c
index a63f9d8..37025a6 100644
--- a/src/gallium/drivers/nv50/nv50_program.c
+++ b/src/gallium/drivers/nv50/nv50_program.c
@@ -486,7 +486,7 @@ nv50_fragprog_prepare(struct nv50_translation_info *ti)
       ++nintp;
    }
 
-   p->fp.colors = (1 << 24) | 4; /* CLAMP, FFC0_ID = 4 */
+   p->fp.colors = 4 << NV50_3D_MAP_SEMANTIC_0_FFC0_ID__SHIFT; /* after HPOS */
 
    for (i = 0; i < p->in_nr; ++i) {
       int j = p->in[i].id;
diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c
index 7690c80..9978d1e 100644
--- a/src/gallium/drivers/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nv50/nv50_screen.c
@@ -108,6 +108,8 @@ nv50_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
       return 1;
    case PIPE_CAP_MAX_RENDER_TARGETS:
       return 8;
+   case PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL:
+      return 1;
    case PIPE_CAP_TIMER_QUERY:
    case PIPE_CAP_OCCLUSION_QUERY:
       return 1;
diff --git a/src/gallium/drivers/nv50/nv50_shader_state.c b/src/gallium/drivers/nv50/nv50_shader_state.c
index bea9c09..82c346c 100644
--- a/src/gallium/drivers/nv50/nv50_shader_state.c
+++ b/src/gallium/drivers/nv50/nv50_shader_state.c
@@ -226,7 +226,7 @@ nv50_gmtyprog_validate(struct nv50_context *nv50)
    OUT_RING  (chan, gp->code_base);
 }
 
-void
+static void
 nv50_sprite_coords_validate(struct nv50_context *nv50)
 {
    struct nouveau_channel *chan = nv50->screen->base.channel;
@@ -282,6 +282,39 @@ nv50_sprite_coords_validate(struct nv50_context *nv50)
    OUT_RINGp (chan, pntc, 8);
 }
 
+/* Validate state derived from shaders and the rasterizer cso. */
+void
+nv50_validate_derived_rs(struct nv50_context *nv50)
+{
+   struct nouveau_channel *chan = nv50->screen->base.channel;
+   uint32_t color, psize;
+
+   nv50_sprite_coords_validate(nv50);
+
+   if (nv50->dirty & NV50_NEW_FRAGPROG)
+      return;
+   psize = nv50->state.semantic_psize & ~NV50_3D_MAP_SEMANTIC_3_PTSZ_EN__MASK;
+   color = nv50->state.semantic_color & ~NV50_3D_MAP_SEMANTIC_0_CLMP_EN;
+
+   if (nv50->rast->pipe.clamp_vertex_color)
+      color |= NV50_3D_MAP_SEMANTIC_0_CLMP_EN;
+
+   if (color != nv50->state.semantic_color) {
+      nv50->state.semantic_color = color;
+      BEGIN_RING(chan, RING_3D(MAP_SEMANTIC_0), 1);
+      OUT_RING  (chan, color);
+   }
+
+   if (nv50->rast->pipe.point_size_per_vertex)
+      psize |= NV50_3D_MAP_SEMANTIC_3_PTSZ_EN__MASK;
+
+   if (psize != nv50->state.semantic_psize) {
+      nv50->state.semantic_psize = psize;
+      BEGIN_RING(chan, RING_3D(MAP_SEMANTIC_3), 1);
+      OUT_RING  (chan, psize);
+   }
+}
+
 static int
 nv50_vec4_map(uint8_t *map, int mid, uint32_t lin[4],
               struct nv50_varying *in, struct nv50_varying *out)
@@ -372,6 +405,9 @@ nv50_fp_linkage_validate(struct nv50_context *nv50)
       map[m++] = vp->vp.psiz;
    }
 
+   if (nv50->rast->pipe.clamp_vertex_color)
+      colors |= NV50_3D_MAP_SEMANTIC_0_CLMP_EN;
+
    n = (m + 3) / 4;
    assert(m <= 64);
 
@@ -404,6 +440,9 @@ nv50_fp_linkage_validate(struct nv50_context *nv50)
 
    nv50->state.interpolant_ctrl = interp;
 
+   nv50->state.semantic_color = colors;
+   nv50->state.semantic_psize = psiz;
+
    BEGIN_RING(chan, RING_3D(NOPERSPECTIVE_BITMAP(0)), 4);
    OUT_RINGp (chan, lin, 4);
 
diff --git a/src/gallium/drivers/nv50/nv50_state.c b/src/gallium/drivers/nv50/nv50_state.c
index db25715..4c96db8 100644
--- a/src/gallium/drivers/nv50/nv50_state.c
+++ b/src/gallium/drivers/nv50/nv50_state.c
@@ -198,6 +198,9 @@ nv50_rasterizer_state_create(struct pipe_context *pipe,
    SB_BEGIN_3D(so, VERTEX_TWO_SIDE_ENABLE, 1);
    SB_DATA    (so, cso->light_twoside);
 
+   SB_BEGIN_3D(so, FRAG_COLOR_CLAMP_EN, 1);
+   SB_DATA    (so, cso->clamp_fragment_color ? 0x11111111 : 0x00000000);
+
    SB_BEGIN_3D(so, LINE_WIDTH, 1);
    SB_DATA    (so, fui(cso->line_width));
    SB_BEGIN_3D(so, LINE_SMOOTH_ENABLE, 1);
diff --git a/src/gallium/drivers/nv50/nv50_state_validate.c b/src/gallium/drivers/nv50/nv50_state_validate.c
index f3d45eb..cdf1a98 100644
--- a/src/gallium/drivers/nv50/nv50_state_validate.c
+++ b/src/gallium/drivers/nv50/nv50_state_validate.c
@@ -309,7 +309,7 @@ static struct state_validate {
     { nv50_fp_linkage_validate,    NV50_NEW_FRAGPROG | NV50_NEW_VERTPROG |
                                    NV50_NEW_GMTYPROG },
     { nv50_gp_linkage_validate,    NV50_NEW_GMTYPROG | NV50_NEW_VERTPROG },
-    { nv50_sprite_coords_validate, NV50_NEW_FRAGPROG | NV50_NEW_RASTERIZER |
+    { nv50_validate_derived_rs,    NV50_NEW_FRAGPROG | NV50_NEW_RASTERIZER |
                                    NV50_NEW_VERTPROG | NV50_NEW_GMTYPROG },
     { nv50_constbufs_validate,     NV50_NEW_CONSTBUF },
     { nv50_validate_textures,      NV50_NEW_TEXTURES },
diff --git a/src/gallium/drivers/nv50/nv50_stateobj.h b/src/gallium/drivers/nv50/nv50_stateobj.h
index 515e3e7..cd55ad8 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[40];
+   uint32_t state[42];
 };
 
 struct nv50_zsa_stateobj {
diff --git a/src/gallium/drivers/nvc0/nvc0_screen.c b/src/gallium/drivers/nvc0/nvc0_screen.c
index 1047ba3..f0f5237 100644
--- a/src/gallium/drivers/nvc0/nvc0_screen.c
+++ b/src/gallium/drivers/nvc0/nvc0_screen.c
@@ -93,6 +93,8 @@ nvc0_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
       return 1;
    case PIPE_CAP_MAX_RENDER_TARGETS:
       return 8;
+   case PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL:
+      return 1;
    case PIPE_CAP_TIMER_QUERY:
    case PIPE_CAP_OCCLUSION_QUERY:
       return 1;
@@ -599,8 +601,6 @@ nvc0_screen_create(struct pipe_winsys *ws, struct nouveau_device *dev)
    BEGIN_RING(chan, RING_3D(POINT_RASTER_RULES), 1);
    OUT_RING  (chan, NVC0_3D_POINT_RASTER_RULES_OGL);
 
-   BEGIN_RING(chan, RING_3D(FRAG_COLOR_CLAMP_EN), 1);
-   OUT_RING  (chan, 0x11111111);
    BEGIN_RING(chan, RING_3D(EDGEFLAG_ENABLE), 1);
    OUT_RING  (chan, 1);
 
diff --git a/src/gallium/drivers/nvc0/nvc0_shader_state.c b/src/gallium/drivers/nvc0/nvc0_shader_state.c
index 7294eaa..287160e 100644
--- a/src/gallium/drivers/nvc0/nvc0_shader_state.c
+++ b/src/gallium/drivers/nvc0/nvc0_shader_state.c
@@ -97,8 +97,6 @@ nvc0_vertprog_validate(struct nvc0_context *nvc0)
 
    // BEGIN_RING(chan, RING_3D_(0x163c), 1);
    // OUT_RING  (chan, 0);
-   BEGIN_RING(chan, RING_3D(VERT_COLOR_CLAMP_EN), 1);
-   OUT_RING  (chan, 1);
 }
 
 void
diff --git a/src/gallium/drivers/nvc0/nvc0_state.c b/src/gallium/drivers/nvc0/nvc0_state.c
index ab68abc..c482b25 100644
--- a/src/gallium/drivers/nvc0/nvc0_state.c
+++ b/src/gallium/drivers/nvc0/nvc0_state.c
@@ -183,6 +183,10 @@ nvc0_rasterizer_state_create(struct pipe_context *pipe,
     SB_IMMED_3D(so, PROVOKING_VERTEX_LAST, !cso->flatshade_first);
     SB_IMMED_3D(so, VERTEX_TWO_SIDE_ENABLE, cso->light_twoside);
 
+    SB_IMMED_3D(so, VERT_COLOR_CLAMP_EN, cso->clamp_vertex_color);
+    SB_BEGIN_3D(so, FRAG_COLOR_CLAMP_EN, 1);
+    SB_DATA    (so, cso->clamp_fragment_color ? 0x11111111 : 0x00000000);
+
     SB_BEGIN_3D(so, LINE_WIDTH, 1);
     SB_DATA    (so, fui(cso->line_width));
     SB_IMMED_3D(so, LINE_SMOOTH_ENABLE, cso->line_smooth);
diff --git a/src/gallium/drivers/nvc0/nvc0_stateobj.h b/src/gallium/drivers/nvc0/nvc0_stateobj.h
index 8222f93..cc6b04d 100644
--- a/src/gallium/drivers/nvc0/nvc0_stateobj.h
+++ b/src/gallium/drivers/nvc0/nvc0_stateobj.h
@@ -25,7 +25,7 @@ struct nvc0_blend_stateobj {
 struct nvc0_rasterizer_stateobj {
    struct pipe_rasterizer_state pipe;
    int size;
-   uint32_t state[36];
+   uint32_t state[39];
 };
 
 struct nvc0_zsa_stateobj {




More information about the mesa-commit mailing list