nv30: add state viewport, based on nv40 one
authorPatrice Mandin <pmandin@caramail.com>
Mon, 23 Jun 2008 19:37:41 +0000 (21:37 +0200)
committerPatrice Mandin <pmandin@caramail.com>
Mon, 23 Jun 2008 19:37:41 +0000 (21:37 +0200)
src/gallium/drivers/nv30/Makefile
src/gallium/drivers/nv30/nv30_context.h
src/gallium/drivers/nv30/nv30_state_viewport.c [new file with mode: 0644]

index 91601087a347177c65f36370224c0f6d08d73183..a6a8cf1df9c9b067341f72608a924d9e597d5153 100644 (file)
@@ -19,6 +19,7 @@ DRIVER_SOURCES = \
        nv30_state_rasterizer.c \
        nv30_state_scissor.c \
        nv30_state_stipple.c \
+       nv30_state_viewport.c \
        nv30_surface.c \
        nv30_vbo.c \
        nv30_vertprog.c
index 446e43a726d3e29f2859a7207e3ed937344c3fa4..eb7e5a8b124cf9a99bafde44fa2f61b94dbc51b2 100644 (file)
@@ -92,6 +92,7 @@ struct nv30_blend_state_new {
 struct nv30_state {
        unsigned scissor_enabled;
        unsigned stipple_enabled;
+       unsigned viewport_bypass;
 
        struct nouveau_stateobj *hw[NV30_STATE_MAX];
 };
@@ -120,6 +121,7 @@ struct nv30_context {
        /* Context state */
        struct nv30_blend_state_new *blend;
        struct pipe_blend_color blend_colour;
+       struct pipe_viewport_state viewport;
        struct pipe_framebuffer_state framebuffer;
        struct nv30_rasterizer_state_new *rasterizer;
        unsigned stipple[32];
diff --git a/src/gallium/drivers/nv30/nv30_state_viewport.c b/src/gallium/drivers/nv30/nv30_state_viewport.c
new file mode 100644 (file)
index 0000000..951d40e
--- /dev/null
@@ -0,0 +1,70 @@
+#include "nv30_context.h"
+
+static boolean
+nv30_state_viewport_validate(struct nv30_context *nv30)
+{
+       struct pipe_viewport_state *vpt = &nv30->viewport;
+       struct nouveau_stateobj *so;
+       unsigned bypass;
+
+       if (/*nv30->render_mode == HW &&*/ !nv30->rasterizer->pipe.bypass_clipping)
+               bypass = 0;
+       else
+               bypass = 1;
+
+       if (nv30->state.hw[NV30_STATE_VIEWPORT] &&
+           (bypass || !(nv30->dirty & NV30_NEW_VIEWPORT)) &&
+           nv30->state.viewport_bypass == bypass)
+               return FALSE;
+       nv30->state.viewport_bypass = bypass;
+
+       so = so_new(11, 0);
+       if (!bypass) {
+               so_method(so, nv30->screen->rankine,
+                         NV34TCL_VIEWPORT_TRANSLATE_X, 8);
+               so_data  (so, fui(vpt->translate[0]));
+               so_data  (so, fui(vpt->translate[1]));
+               so_data  (so, fui(vpt->translate[2]));
+               so_data  (so, fui(vpt->translate[3]));
+               so_data  (so, fui(vpt->scale[0]));
+               so_data  (so, fui(vpt->scale[1]));
+               so_data  (so, fui(vpt->scale[2]));
+               so_data  (so, fui(vpt->scale[3]));
+/*             so_method(so, nv30->screen->rankine, 0x1d78, 1);
+               so_data  (so, 1);
+*/     } else {
+               so_method(so, nv30->screen->rankine,
+                         NV34TCL_VIEWPORT_TRANSLATE_X, 8);
+               so_data  (so, fui(0.0));
+               so_data  (so, fui(0.0));
+               so_data  (so, fui(0.0));
+               so_data  (so, fui(0.0));
+               so_data  (so, fui(1.0));
+               so_data  (so, fui(1.0));
+               so_data  (so, fui(1.0));
+               so_data  (so, fui(0.0));
+               /* Not entirely certain what this is yet.  The DDX uses this
+                * value also as it fixes rendering when you pass
+                * pre-transformed vertices to the GPU.  My best gusss is that
+                * this bypasses some culling/clipping stage.  Might be worth
+                * noting that points/lines are uneffected by whatever this
+                * value fixes, only filled polygons are effected.
+                */
+/*             so_method(so, nv30->screen->rankine, 0x1d78, 1);
+               so_data  (so, 0x110);
+*/     }
+       /* TODO/FIXME: never saw value 0x0110 in renouveau dumps, only 0x0001 */
+       so_method(so, nv30->screen->rankine, 0x1d78, 1);
+       so_data  (so, 1);
+
+       so_ref(so, &nv30->state.hw[NV30_STATE_VIEWPORT]);
+       return TRUE;
+}
+
+struct nv30_state_entry nv30_state_viewport = {
+       .validate = nv30_state_viewport_validate,
+       .dirty = {
+               .pipe = NV30_NEW_VIEWPORT | NV30_NEW_RAST,
+               .hw = NV30_STATE_VIEWPORT
+       }
+};