nv30, nv40: partially non-trivially unify nv[34]0_fragtex.c
authorLuca Barbieri <luca@luca-barbieri.com>
Sun, 21 Feb 2010 14:07:17 +0000 (15:07 +0100)
committerYounes Manton <younes.m@gmail.com>
Mon, 15 Mar 2010 04:03:03 +0000 (00:03 -0400)
The bulk files cannot be unified, but the frontend can and allows to
share some code and simplify state_emit.c

src/gallium/drivers/nv30/nv30_fragtex.c
src/gallium/drivers/nv40/nv40_fragtex.c
src/gallium/drivers/nvfx/Makefile
src/gallium/drivers/nvfx/nvfx_context.h
src/gallium/drivers/nvfx/nvfx_fragtex.c [new file with mode: 0644]
src/gallium/drivers/nvfx/nvfx_state_emit.c

index ab39ded..52f7c52 100644 (file)
@@ -57,7 +57,7 @@ nv30_fragtex_format(uint pipe_format)
 }
 
 
-static struct nouveau_stateobj *
+struct nouveau_stateobj *
 nv30_fragtex_build(struct nvfx_context *nvfx, int unit)
 {
        struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit];
@@ -116,46 +116,3 @@ nv30_fragtex_build(struct nvfx_context *nvfx, int unit)
        return so;
 }
 
-static boolean
-nv30_fragtex_validate(struct nvfx_context *nvfx)
-{
-       struct nvfx_fragment_program *fp = nvfx->fragprog;
-       struct nvfx_state *state = &nvfx->state;
-       struct nouveau_stateobj *so;
-       unsigned samplers, unit;
-
-       samplers = state->fp_samplers & ~fp->samplers;
-       while (samplers) {
-               unit = ffs(samplers) - 1;
-               samplers &= ~(1 << unit);
-
-               so = so_new(1, 1, 0);
-               so_method(so, nvfx->screen->eng3d, NV34TCL_TX_ENABLE(unit), 1);
-               so_data  (so, 0);
-               so_ref(so, &nvfx->state.hw[NVFX_STATE_FRAGTEX0 + unit]);
-               so_ref(NULL, &so);
-               state->dirty |= (1ULL << (NVFX_STATE_FRAGTEX0 + unit));
-       }
-
-       samplers = nvfx->dirty_samplers & fp->samplers;
-       while (samplers) {
-               unit = ffs(samplers) - 1;
-               samplers &= ~(1 << unit);
-
-               so = nv30_fragtex_build(nvfx, unit);
-               so_ref(so, &nvfx->state.hw[NVFX_STATE_FRAGTEX0 + unit]);
-               so_ref(NULL, &so);
-               state->dirty |= (1ULL << (NVFX_STATE_FRAGTEX0 + unit));
-       }
-
-       nvfx->state.fp_samplers = fp->samplers;
-       return FALSE;
-}
-
-struct nvfx_state_entry nv30_state_fragtex = {
-       .validate = nv30_fragtex_validate,
-       .dirty = {
-               .pipe = NVFX_NEW_SAMPLER | NVFX_NEW_FRAGPROG,
-               .hw = 0
-       }
-};
index 2925717..7615095 100644 (file)
@@ -59,7 +59,7 @@ nv40_fragtex_format(uint pipe_format)
 }
 
 
-static struct nouveau_stateobj *
+struct nouveau_stateobj *
 nv40_fragtex_build(struct nvfx_context *nvfx, int unit)
 {
        struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit];
@@ -126,47 +126,3 @@ nv40_fragtex_build(struct nvfx_context *nvfx, int unit)
 
        return so;
 }
-
-static boolean
-nv40_fragtex_validate(struct nvfx_context *nvfx)
-{
-       struct nvfx_fragment_program *fp = nvfx->fragprog;
-       struct nvfx_state *state = &nvfx->state;
-       struct nouveau_stateobj *so;
-       unsigned samplers, unit;
-
-       samplers = state->fp_samplers & ~fp->samplers;
-       while (samplers) {
-               unit = ffs(samplers) - 1;
-               samplers &= ~(1 << unit);
-
-               so = so_new(1, 1, 0);
-               so_method(so, nvfx->screen->eng3d, NV34TCL_TX_ENABLE(unit), 1);
-               so_data  (so, 0);
-               so_ref(so, &nvfx->state.hw[NVFX_STATE_FRAGTEX0 + unit]);
-               state->dirty |= (1ULL << (NVFX_STATE_FRAGTEX0 + unit));
-       }
-
-       samplers = nvfx->dirty_samplers & fp->samplers;
-       while (samplers) {
-               unit = ffs(samplers) - 1;
-               samplers &= ~(1 << unit);
-
-               so = nv40_fragtex_build(nvfx, unit);
-               so_ref(so, &nvfx->state.hw[NVFX_STATE_FRAGTEX0 + unit]);
-               so_ref(NULL, &so);
-               state->dirty |= (1ULL << (NVFX_STATE_FRAGTEX0 + unit));
-       }
-
-       nvfx->state.fp_samplers = fp->samplers;
-       return FALSE;
-}
-
-struct nvfx_state_entry nv40_state_fragtex = {
-       .validate = nv40_fragtex_validate,
-       .dirty = {
-               .pipe = NVFX_NEW_SAMPLER | NVFX_NEW_FRAGPROG,
-               .hw = 0
-       }
-};
-
index aa03a15..51fa34c 100644 (file)
@@ -8,6 +8,7 @@ C_SOURCES = \
        nvfx_clear.c \
        nvfx_draw.c \
        nvfx_fragprog.c \
+       nvfx_fragtex.c \
        nvfx_miptree.c \
        nvfx_query.c \
        nvfx_screen.c \
index 0bd37a7..e538904 100644 (file)
@@ -184,6 +184,7 @@ struct nvfx_state_entry {
 extern struct nvfx_state_entry nvfx_state_blend;
 extern struct nvfx_state_entry nvfx_state_blend_colour;
 extern struct nvfx_state_entry nvfx_state_fragprog;
+extern struct nvfx_state_entry nvfx_state_fragtex;
 extern struct nvfx_state_entry nvfx_state_framebuffer;
 extern struct nvfx_state_entry nvfx_state_rasterizer;
 extern struct nvfx_state_entry nvfx_state_scissor;
@@ -220,12 +221,14 @@ extern void nvfx_fragprog_destroy(struct nvfx_context *,
 /* nv30_fragtex.c */
 extern void nv30_init_sampler_functions(struct nvfx_context *nvfx);
 extern void nv30_fragtex_bind(struct nvfx_context *);
-extern struct nvfx_state_entry nv30_state_fragtex;
+extern struct nouveau_stateobj *
+nv30_fragtex_build(struct nvfx_context *nvfx, int unit);
 
 /* nv40_fragtex.c */
 extern void nv40_init_sampler_functions(struct nvfx_context *nvfx);
 extern void nv40_fragtex_bind(struct nvfx_context *);
-extern struct nvfx_state_entry nv40_state_fragtex;
+extern struct nouveau_stateobj *
+nv40_fragtex_build(struct nvfx_context *nvfx, int unit);
 
 /* nvfx_state.c */
 extern void nvfx_init_state_functions(struct nvfx_context *nvfx);
diff --git a/src/gallium/drivers/nvfx/nvfx_fragtex.c b/src/gallium/drivers/nvfx/nvfx_fragtex.c
new file mode 100644 (file)
index 0000000..84e4eb1
--- /dev/null
@@ -0,0 +1,49 @@
+#include "nvfx_context.h"
+
+static boolean
+nvfx_fragtex_validate(struct nvfx_context *nvfx)
+{
+       struct nvfx_fragment_program *fp = nvfx->fragprog;
+       struct nvfx_state *state = &nvfx->state;
+       struct nouveau_stateobj *so;
+       unsigned samplers, unit;
+
+       samplers = state->fp_samplers & ~fp->samplers;
+       while (samplers) {
+               unit = ffs(samplers) - 1;
+               samplers &= ~(1 << unit);
+
+               so = so_new(1, 1, 0);
+               so_method(so, nvfx->screen->eng3d, NV34TCL_TX_ENABLE(unit), 1);
+               so_data  (so, 0);
+               so_ref(so, &nvfx->state.hw[NVFX_STATE_FRAGTEX0 + unit]);
+               so_ref(NULL, &so);
+               state->dirty |= (1ULL << (NVFX_STATE_FRAGTEX0 + unit));
+       }
+
+       samplers = nvfx->dirty_samplers & fp->samplers;
+       while (samplers) {
+               unit = ffs(samplers) - 1;
+               samplers &= ~(1 << unit);
+
+               if(!nvfx->is_nv4x)
+                       so = nv30_fragtex_build(nvfx, unit);
+               else
+                       so = nv40_fragtex_build(nvfx, unit);
+
+               so_ref(so, &nvfx->state.hw[NVFX_STATE_FRAGTEX0 + unit]);
+               so_ref(NULL, &so);
+               state->dirty |= (1ULL << (NVFX_STATE_FRAGTEX0 + unit));
+       }
+
+       nvfx->state.fp_samplers = fp->samplers;
+       return FALSE;
+}
+
+struct nvfx_state_entry nvfx_state_fragtex = {
+       .validate = nvfx_fragtex_validate,
+       .dirty = {
+               .pipe = NVFX_NEW_SAMPLER | NVFX_NEW_FRAGPROG,
+               .hw = 0
+       }
+};
index 9d28b59..7253738 100644 (file)
@@ -2,14 +2,14 @@
 #include "nvfx_state.h"
 #include "draw/draw_context.h"
 
-#define RENDER_STATES(name, nvxx, vbo) \
-static struct nvfx_state_entry *name##_render_states[] = { \
+#define RENDER_STATES(name, vbo) \
+static struct nvfx_state_entry *name##render_states[] = { \
        &nvfx_state_framebuffer, \
        &nvfx_state_rasterizer, \
        &nvfx_state_scissor, \
        &nvfx_state_stipple, \
        &nvfx_state_fragprog, \
-       &nvxx##_state_fragtex, \
+       &nvfx_state_fragtex, \
        &nvfx_state_vertprog, \
        &nvfx_state_blend, \
        &nvfx_state_blend_colour, \
@@ -20,10 +20,8 @@ static struct nvfx_state_entry *name##_render_states[] = { \
        NULL \
 }
 
-RENDER_STATES(nv30, nv30, vbo);
-RENDER_STATES(nv30_swtnl, nv30, vtxfmt);
-RENDER_STATES(nv40, nv40, vbo);
-RENDER_STATES(nv40_swtnl, nv40, vtxfmt);
+RENDER_STATES(, vbo);
+RENDER_STATES(swtnl_, vtxfmt);
 
 static void
 nvfx_state_do_validate(struct nvfx_context *nvfx,
@@ -126,10 +124,7 @@ nvfx_state_validate(struct nvfx_context *nvfx)
                nvfx->render_mode = HW;
        }
 
-       if(!nvfx->is_nv4x)
-               nvfx_state_do_validate(nvfx, nv30_render_states);
-       else
-               nvfx_state_do_validate(nvfx, nv40_render_states);
+       nvfx_state_do_validate(nvfx, render_states);
 
        if (nvfx->fallback_swtnl || nvfx->fallback_swrast)
                return FALSE;
@@ -172,10 +167,7 @@ nvfx_state_validate_swtnl(struct nvfx_context *nvfx)
                draw_set_vertex_elements(draw, nvfx->vtxelt->num_elements, nvfx->vtxelt->pipe);
        }
 
-       if(!nvfx->is_nv4x)
-               nvfx_state_do_validate(nvfx, nv30_swtnl_render_states);
-       else
-               nvfx_state_do_validate(nvfx, nv40_swtnl_render_states);
+       nvfx_state_do_validate(nvfx, swtnl_render_states);
 
        if (nvfx->fallback_swrast) {
                NOUVEAU_ERR("swtnl->swrast 0x%08x\n", nvfx->fallback_swrast);