nv50: update to handle new sampler view state
[mesa.git] / src / gallium / drivers / nv50 / nv50_state_validate.c
index c8bdf9dc2761944d35c086166df6420124ca0fbb..741f8e8f59d719578b5ba72e60817265a1a5d018 100644 (file)
@@ -20,6 +20,8 @@
  * SOFTWARE.
  */
 
+#include "util/u_format.h"
+
 #include "nv50_context.h"
 #include "nouveau/nouveau_stateobj.h"
 
@@ -33,7 +35,7 @@ static void
 nv50_state_validate_fb(struct nv50_context *nv50)
 {
        struct nouveau_grobj *tesla = nv50->screen->tesla;
-       struct nouveau_stateobj *so = so_new(128, 18);
+       struct nouveau_stateobj *so = so_new(32, 79, 18);
        struct pipe_framebuffer_state *fb = &nv50->framebuffer;
        unsigned i, w, h, gw = 0;
 
@@ -79,7 +81,7 @@ nv50_state_validate_fb(struct nv50_context *nv50)
                NV50_CBUF_FORMAT_CASE(R16G16_UNORM);
                default:
                        NOUVEAU_ERR("AIIII unknown format %s\n",
-                                   pf_name(fb->cbufs[i]->format));
+                                   util_format_name(fb->cbufs[i]->format));
                        so_data(so, NV50TCL_RT_FORMAT_X8R8G8B8_UNORM);
                        break;
                }
@@ -116,7 +118,7 @@ nv50_state_validate_fb(struct nv50_context *nv50)
                NV50_ZETA_FORMAT_CASE(Z32_FLOAT);
                default:
                        NOUVEAU_ERR("AIIII unknown format %s\n",
-                                   pf_name(fb->zsbuf->format));
+                                   util_format_name(fb->zsbuf->format));
                        so_data(so, NV50TCL_ZETA_FORMAT_S8Z24_UNORM);
                        break;
                }
@@ -185,7 +187,10 @@ nv50_state_emit(struct nv50_context *nv50)
        struct nv50_screen *screen = nv50->screen;
        struct nouveau_channel *chan = screen->base.channel;
 
-       if (nv50->pctx_id != screen->cur_pctx) {
+       /* XXX: this is racy for multiple contexts active on separate
+        * threads.
+        */
+       if (screen->cur_ctx != nv50) {
                if (nv50->state.fb)
                        nv50->state.dirty |= NV50_NEW_FRAMEBUFFER;
                if (nv50->state.blend)
@@ -196,10 +201,14 @@ nv50_state_emit(struct nv50_context *nv50)
                        nv50->state.dirty |= NV50_NEW_VERTPROG;
                if (nv50->state.fragprog)
                        nv50->state.dirty |= NV50_NEW_FRAGPROG;
+               if (nv50->state.geomprog)
+                       nv50->state.dirty |= NV50_NEW_GEOMPROG;
                if (nv50->state.rast)
                        nv50->state.dirty |= NV50_NEW_RASTERIZER;
                if (nv50->state.blend_colour)
                        nv50->state.dirty |= NV50_NEW_BLEND_COLOUR;
+               if (nv50->state.stencil_ref)
+                       nv50->state.dirty |= NV50_NEW_STENCIL_REF;
                if (nv50->state.stipple)
                        nv50->state.dirty |= NV50_NEW_STIPPLE;
                if (nv50->state.scissor)
@@ -212,7 +221,7 @@ nv50_state_emit(struct nv50_context *nv50)
                        nv50->state.dirty |= NV50_NEW_TEXTURE;
                if (nv50->state.vtxfmt && nv50->state.vtxbuf)
                        nv50->state.dirty |= NV50_NEW_ARRAYS;
-               screen->cur_pctx = nv50->pctx_id;
+               screen->cur_ctx = nv50;
        }
 
        if (nv50->state.dirty & NV50_NEW_FRAMEBUFFER)
@@ -225,13 +234,20 @@ nv50_state_emit(struct nv50_context *nv50)
                so_emit(chan, nv50->state.vertprog);
        if (nv50->state.dirty & NV50_NEW_FRAGPROG)
                so_emit(chan, nv50->state.fragprog);
+       if (nv50->state.dirty & NV50_NEW_GEOMPROG && nv50->state.geomprog)
+               so_emit(chan, nv50->state.geomprog);
        if (nv50->state.dirty & (NV50_NEW_FRAGPROG | NV50_NEW_VERTPROG |
-                                NV50_NEW_RASTERIZER))
-               so_emit(chan, nv50->state.programs);
+                                NV50_NEW_GEOMPROG | NV50_NEW_RASTERIZER))
+               so_emit(chan, nv50->state.fp_linkage);
+       if ((nv50->state.dirty & (NV50_NEW_VERTPROG | NV50_NEW_GEOMPROG))
+           && nv50->state.gp_linkage)
+               so_emit(chan, nv50->state.gp_linkage);
        if (nv50->state.dirty & NV50_NEW_RASTERIZER)
                so_emit(chan, nv50->state.rast);
        if (nv50->state.dirty & NV50_NEW_BLEND_COLOUR)
                so_emit(chan, nv50->state.blend_colour);
+       if (nv50->state.dirty & NV50_NEW_STENCIL_REF)
+               so_emit(chan, nv50->state.stencil_ref);
        if (nv50->state.dirty & NV50_NEW_STIPPLE)
                so_emit(chan, nv50->state.stipple);
        if (nv50->state.dirty & NV50_NEW_SCISSOR)
@@ -264,6 +280,9 @@ nv50_state_flush_notify(struct nouveau_channel *chan)
        so_emit_reloc_markers(chan, nv50->state.fragprog);
        so_emit_reloc_markers(chan, nv50->state.vtxbuf);
        so_emit_reloc_markers(chan, nv50->screen->static_init);
+
+       if (nv50->state.instbuf)
+               so_emit_reloc_markers(chan, nv50->state.instbuf);
 }
 
 boolean
@@ -288,15 +307,21 @@ nv50_state_validate(struct nv50_context *nv50)
        if (nv50->dirty & (NV50_NEW_FRAGPROG | NV50_NEW_FRAGPROG_CB))
                nv50_fragprog_validate(nv50);
 
+       if (nv50->dirty & (NV50_NEW_GEOMPROG | NV50_NEW_GEOMPROG_CB))
+               nv50_geomprog_validate(nv50);
+
        if (nv50->dirty & (NV50_NEW_FRAGPROG | NV50_NEW_VERTPROG |
-                          NV50_NEW_RASTERIZER))
-               nv50_linkage_validate(nv50);
+                          NV50_NEW_GEOMPROG | NV50_NEW_RASTERIZER))
+               nv50_fp_linkage_validate(nv50);
+
+       if (nv50->dirty & (NV50_NEW_GEOMPROG | NV50_NEW_VERTPROG))
+               nv50_gp_linkage_validate(nv50);
 
        if (nv50->dirty & NV50_NEW_RASTERIZER)
                so_ref(nv50->rasterizer->so, &nv50->state.rast);
 
        if (nv50->dirty & NV50_NEW_BLEND_COLOUR) {
-               so = so_new(5, 0);
+               so = so_new(1, 4, 0);
                so_method(so, tesla, NV50TCL_BLEND_COLOR(0), 4);
                so_data  (so, fui(nv50->blend_colour.color[0]));
                so_data  (so, fui(nv50->blend_colour.color[1]));
@@ -306,8 +331,18 @@ nv50_state_validate(struct nv50_context *nv50)
                so_ref(NULL, &so);
        }
 
+       if (nv50->dirty & NV50_NEW_STENCIL_REF) {
+               so = so_new(2, 2, 0);
+               so_method(so, tesla, NV50TCL_STENCIL_FRONT_FUNC_REF, 1);
+               so_data  (so, nv50->stencil_ref.ref_value[0]);
+               so_method(so, tesla, NV50TCL_STENCIL_BACK_FUNC_REF, 1);
+               so_data  (so, nv50->stencil_ref.ref_value[1]);
+               so_ref(so, &nv50->state.stencil_ref);
+               so_ref(NULL, &so);
+       }
+
        if (nv50->dirty & NV50_NEW_STIPPLE) {
-               so = so_new(33, 0);
+               so = so_new(1, 32, 0);
                so_method(so, tesla, NV50TCL_POLYGON_STIPPLE_PATTERN(0), 32);
                for (i = 0; i < 32; i++)
                        so_data(so, util_bswap32(nv50->stipple.stipple[i]));
@@ -324,7 +359,7 @@ nv50_state_validate(struct nv50_context *nv50)
                        goto scissor_uptodate;
                nv50->state.scissor_enabled = rast->scissor;
 
-               so = so_new(3, 0);
+               so = so_new(1, 2, 0);
                so_method(so, tesla, NV50TCL_SCISSOR_HORIZ(0), 2);
                if (nv50->state.scissor_enabled) {
                        so_data(so, (s->maxx << 16) | s->minx);
@@ -353,7 +388,7 @@ scissor_uptodate:
                        goto viewport_uptodate;
                nv50->state.viewport_bypass = bypass;
 
-               so = so_new(14, 0);
+               so = so_new(5, 9, 0);
                if (!bypass) {
                        so_method(so, tesla, NV50TCL_VIEWPORT_TRANSLATE_X(0), 3);
                        so_data  (so, fui(nv50->viewport.translate[0]));
@@ -397,10 +432,12 @@ viewport_uptodate:
                for (i = 0; i < PIPE_SHADER_TYPES; ++i)
                        nr += nv50->sampler_nr[i];
 
-               so = so_new(nr * 8 + 24 * PIPE_SHADER_TYPES + 2, 4);
+               so = so_new(1 + 5 * PIPE_SHADER_TYPES,
+                           1 + 19 * PIPE_SHADER_TYPES + nr * 8,
+                           PIPE_SHADER_TYPES * 2);
 
-               nv50_validate_samplers(nv50, so, PIPE_SHADER_VERTEX);
-               nv50_validate_samplers(nv50, so, PIPE_SHADER_FRAGMENT);
+               nv50_validate_samplers(nv50, so, 0); /* VP samplers */
+               nv50_validate_samplers(nv50, so, 2); /* FP samplers */
 
                so_method(so, tesla, 0x1334, 1); /* flush TSC */
                so_data  (so, 0);