Merge branch 'mesa_7_5_branch'
[mesa.git] / src / gallium / drivers / nv30 / nv30_fragtex.c
index 4242f86f76ffcb40c184b4524c2845661c7cfe01..822e1d8defe7c42b0f1dcdceb6737d306cf62131 100644 (file)
@@ -1,30 +1,5 @@
 #include "nv30_context.h"
-
-static INLINE int log2i(int i)
-{
-       int r = 0;
-
-       if (i & 0xffff0000) {
-               i >>= 16;
-               r += 16;
-       }
-       if (i & 0x0000ff00) {
-               i >>= 8;
-               r += 8;
-       }
-       if (i & 0x000000f0) {
-               i >>= 4;
-               r += 4;
-       }
-       if (i & 0x0000000c) {
-               i >>= 2;
-               r += 2;
-       }
-       if (i & 0x00000002) {
-               r += 1;
-       }
-       return r;
-}
+#include "nouveau/nouveau_util.h"
 
 #define _(m,tf,ts0x,ts0y,ts0z,ts0w,ts1x,ts1y,ts1z,ts1w)                        \
 {                                                                              \
@@ -34,7 +9,7 @@ static INLINE int log2i(int i)
   (NV34TCL_TX_SWIZZLE_S0_X_##ts0x | NV34TCL_TX_SWIZZLE_S0_Y_##ts0y |           \
    NV34TCL_TX_SWIZZLE_S0_Z_##ts0z | NV34TCL_TX_SWIZZLE_S0_W_##ts0w |           \
    NV34TCL_TX_SWIZZLE_S1_X_##ts1x | NV34TCL_TX_SWIZZLE_S1_Y_##ts1y |           \
-   NV34TCL_TX_SWIZZLE_S1_Z_##ts1z | NV34TCL_TX_SWIZZLE_S1_W_##ts1w),           \
+   NV34TCL_TX_SWIZZLE_S1_Z_##ts1z | NV34TCL_TX_SWIZZLE_S1_W_##ts1w)            \
 }
 
 struct nv30_texture_format {
@@ -75,8 +50,7 @@ nv30_fragtex_format(uint pipe_format)
                tf++;
        }
 
-       pf_sprint_name(fs, pipe_format);
-       NOUVEAU_ERR("unknown texture format %s\n", fs);
+       NOUVEAU_ERR("unknown texture format %s\n", pf_name(pipe_format));
        return NULL;
 }
 
@@ -87,10 +61,10 @@ nv30_fragtex_build(struct nv30_context *nv30, int unit)
        struct nv30_sampler_state *ps = nv30->tex_sampler[unit];
        struct nv30_miptree *nv30mt = nv30->tex_miptree[unit];
        struct pipe_texture *pt = &nv30mt->base;
+       struct nouveau_bo *bo = nouveau_bo(nv30mt->buffer);
        struct nv30_texture_format *tf;
        struct nouveau_stateobj *so;
-       uint32_t txf, txs /*, txp*/;
-       /*int swizzled = 0;*/ /*XXX: implement in region code? */
+       uint32_t txf, txs , txp;
        unsigned tex_flags = NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD;
 
        tf = nv30_fragtex_format(pt->format);
@@ -122,13 +96,20 @@ nv30_fragtex_build(struct nv30_context *nv30, int unit)
                return NULL;
        }
 
+       if (!(pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR)) {
+               txp = 0;
+       } else {
+               txp  = nv30mt->level[0].pitch;
+               txf |= (1<<13) /*FIXME: NV34TCL_TX_FORMAT_LINEAR ? */;
+       }
+
        txs = tf->swizzle;
 
        so = so_new(16, 2);
        so_method(so, nv30->screen->rankine, NV34TCL_TX_OFFSET(unit), 8);
-       so_reloc (so, nv30mt->buffer, 0, tex_flags | NOUVEAU_BO_LOW, 0, 0);
-       so_reloc (so, nv30mt->buffer, txf, tex_flags | NOUVEAU_BO_OR,
-                 NV34TCL_TX_FORMAT_DMA0, NV34TCL_TX_FORMAT_DMA1);
+       so_reloc (so, bo, 0, tex_flags | NOUVEAU_BO_LOW, 0, 0);
+       so_reloc (so, bo, txf, tex_flags | NOUVEAU_BO_OR,
+                     NV34TCL_TX_FORMAT_DMA0, NV34TCL_TX_FORMAT_DMA1);
        so_data  (so, ps->wrap);
        so_data  (so, NV34TCL_TX_ENABLE_ENABLE | ps->en);
        so_data  (so, txs);
@@ -157,6 +138,7 @@ nv30_fragtex_validate(struct nv30_context *nv30)
                so_method(so, nv30->screen->rankine, NV34TCL_TX_ENABLE(unit), 1);
                so_data  (so, 0);
                so_ref(so, &nv30->state.hw[NV30_STATE_FRAGTEX0 + unit]);
+               so_ref(NULL, &so);
                state->dirty |= (1ULL << (NV30_STATE_FRAGTEX0 + unit));
        }
 
@@ -167,6 +149,7 @@ nv30_fragtex_validate(struct nv30_context *nv30)
 
                so = nv30_fragtex_build(nv30, unit);
                so_ref(so, &nv30->state.hw[NV30_STATE_FRAGTEX0 + unit]);
+               so_ref(NULL, &so);
                state->dirty |= (1ULL << (NV30_STATE_FRAGTEX0 + unit));
        }