gallium/util: replace pipe_mutex_init() with mtx_init()
[mesa.git] / src / gallium / drivers / nouveau / nv50 / nv50_state_validate.c
index e7631bb1fcffeb05328147e53e46d7240d762d30..c6f0363075a190e84450a0201864b37f6376fc70 100644 (file)
@@ -1,5 +1,5 @@
 
-#include "util/u_format.h"
+#include "util/u_viewport.h"
 
 #include "nv50/nv50_context.h"
 
@@ -265,8 +265,12 @@ nv50_validate_viewport(struct nv50_context *nv50)
       PUSH_DATAf(push, vpt->scale[1]);
       PUSH_DATAf(push, vpt->scale[2]);
 
-      zmin = vpt->translate[2] - fabsf(vpt->scale[2]);
-      zmax = vpt->translate[2] + fabsf(vpt->scale[2]);
+      /* If the halfz setting ever changes, the viewports will also get
+       * updated. The rast will get updated before the validate function has a
+       * chance to hit, so we can just use it directly without an atom
+       * dependency.
+       */
+      util_viewport_zmin_zmax(vpt, nv50->rast->pipe.clip_halfz, &zmin, &zmax);
 
 #ifdef NV50_SCISSORS_CLIPPING
       BEGIN_NV04(push, NV50_3D(DEPTH_RANGE_NEAR(i)), 2);
@@ -278,6 +282,32 @@ nv50_validate_viewport(struct nv50_context *nv50)
    nv50->viewports_dirty = 0;
 }
 
+static void
+nv50_validate_window_rects(struct nv50_context *nv50)
+{
+   struct nouveau_pushbuf *push = nv50->base.pushbuf;
+   bool enable = nv50->window_rect.rects > 0 || nv50->window_rect.inclusive;
+   int i;
+
+   BEGIN_NV04(push, NV50_3D(CLIP_RECTS_EN), 1);
+   PUSH_DATA (push, enable);
+   if (!enable)
+      return;
+
+   BEGIN_NV04(push, NV50_3D(CLIP_RECTS_MODE), 1);
+   PUSH_DATA (push, !nv50->window_rect.inclusive);
+   BEGIN_NV04(push, NV50_3D(CLIP_RECT_HORIZ(0)), NV50_MAX_WINDOW_RECTANGLES * 2);
+   for (i = 0; i < nv50->window_rect.rects; i++) {
+      struct pipe_scissor_state *s = &nv50->window_rect.rect[i];
+      PUSH_DATA(push, (s->maxx << 16) | s->minx);
+      PUSH_DATA(push, (s->maxy << 16) | s->miny);
+   }
+   for (; i < NV50_MAX_WINDOW_RECTANGLES; i++) {
+      PUSH_DATA(push, 0);
+      PUSH_DATA(push, 0);
+   }
+}
+
 static inline void
 nv50_check_program_ucps(struct nv50_context *nv50,
                         struct nv50_program *vp, uint8_t mask)
@@ -316,31 +346,12 @@ nv50_validate_derived_2(struct nv50_context *nv50)
    }
 }
 
-static void
-nv50_validate_derived_3(struct nv50_context *nv50)
-{
-   struct nouveau_pushbuf *push = nv50->base.pushbuf;
-   struct pipe_framebuffer_state *fb = &nv50->framebuffer;
-   uint32_t ms = 0;
-
-   if ((!fb->nr_cbufs || !fb->cbufs[0] ||
-        !util_format_is_pure_integer(fb->cbufs[0]->format)) && nv50->blend) {
-      if (nv50->blend->pipe.alpha_to_coverage)
-         ms |= NV50_3D_MULTISAMPLE_CTRL_ALPHA_TO_COVERAGE;
-      if (nv50->blend->pipe.alpha_to_one)
-         ms |= NV50_3D_MULTISAMPLE_CTRL_ALPHA_TO_ONE;
-   }
-
-   BEGIN_NV04(push, NV50_3D(MULTISAMPLE_CTRL), 1);
-   PUSH_DATA (push, ms);
-}
-
 static void
 nv50_validate_clip(struct nv50_context *nv50)
 {
    struct nouveau_pushbuf *push = nv50->base.pushbuf;
    struct nv50_program *vp;
-   uint8_t clip_enable;
+   uint8_t clip_enable = nv50->rast->pipe.clip_plane_enable;
 
    if (nv50->dirty_3d & NV50_NEW_3D_CLIP) {
       BEGIN_NV04(push, NV50_3D(CB_ADDR), 1);
@@ -353,13 +364,20 @@ nv50_validate_clip(struct nv50_context *nv50)
    if (likely(!vp))
       vp = nv50->vertprog;
 
-   clip_enable = nv50->rast->pipe.clip_plane_enable;
+   if (clip_enable)
+      nv50_check_program_ucps(nv50, vp, clip_enable);
+
+   clip_enable &= vp->vp.clip_enable;
+   clip_enable |= vp->vp.cull_enable;
 
    BEGIN_NV04(push, NV50_3D(CLIP_DISTANCE_ENABLE), 1);
    PUSH_DATA (push, clip_enable);
 
-   if (clip_enable)
-      nv50_check_program_ucps(nv50, vp, clip_enable);
+   if (nv50->state.clip_mode != vp->vp.clip_mode) {
+      nv50->state.clip_mode = vp->vp.clip_mode;
+      BEGIN_NV04(push, NV50_3D(CLIP_DISTANCE_MODE), 1);
+      PUSH_DATA (push, vp->vp.clip_mode);
+   }
 }
 
 static void
@@ -437,6 +455,7 @@ nv50_switch_pipe_context(struct nv50_context *ctx_to)
       ctx_to->state = ctx_to->screen->save_state;
 
    ctx_to->dirty_3d = ~0;
+   ctx_to->dirty_cp = ~0;
    ctx_to->viewports_dirty = ~0;
    ctx_to->scissors_dirty = ~0;
 
@@ -484,17 +503,18 @@ validate_list_3d[] = {
     { nv50_validate_scissor,       NV50_NEW_3D_SCISSOR },
 #endif
     { nv50_validate_viewport,      NV50_NEW_3D_VIEWPORT },
+    { nv50_validate_window_rects,  NV50_NEW_3D_WINDOW_RECTS },
     { nv50_vertprog_validate,      NV50_NEW_3D_VERTPROG },
     { nv50_gmtyprog_validate,      NV50_NEW_3D_GMTYPROG },
     { nv50_fragprog_validate,      NV50_NEW_3D_FRAGPROG | NV50_NEW_3D_RASTERIZER |
-                                   NV50_NEW_3D_MIN_SAMPLES },
+                                   NV50_NEW_3D_MIN_SAMPLES | NV50_NEW_3D_ZSA |
+                                   NV50_NEW_3D_FRAMEBUFFER},
     { nv50_fp_linkage_validate,    NV50_NEW_3D_FRAGPROG | NV50_NEW_3D_VERTPROG |
                                    NV50_NEW_3D_GMTYPROG | NV50_NEW_3D_RASTERIZER },
     { nv50_gp_linkage_validate,    NV50_NEW_3D_GMTYPROG | NV50_NEW_3D_VERTPROG },
     { nv50_validate_derived_rs,    NV50_NEW_3D_FRAGPROG | NV50_NEW_3D_RASTERIZER |
                                    NV50_NEW_3D_VERTPROG | NV50_NEW_3D_GMTYPROG },
     { nv50_validate_derived_2,     NV50_NEW_3D_ZSA | NV50_NEW_3D_FRAMEBUFFER },
-    { nv50_validate_derived_3,     NV50_NEW_3D_BLEND | NV50_NEW_3D_FRAMEBUFFER },
     { nv50_validate_clip,          NV50_NEW_3D_CLIP | NV50_NEW_3D_RASTERIZER |
                                    NV50_NEW_3D_VERTPROG | NV50_NEW_3D_GMTYPROG },
     { nv50_constbufs_validate,     NV50_NEW_3D_CONSTBUF },