r300: further cleanup
[mesa.git] / src / mesa / drivers / dri / r300 / r300_emit.c
index dc08b642c52828f5bc7fa75e32cea119e51c6634..20b77bc9aea0a95d2b91bac21861599d220065db 100644 (file)
@@ -33,12 +33,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  * \author Keith Whitwell <keith@tungstengraphics.com>
  */
 
-#include "glheader.h"
-#include "mtypes.h"
-#include "colormac.h"
-#include "imports.h"
-#include "macros.h"
-#include "image.h"
+#include "main/glheader.h"
+#include "main/mtypes.h"
+#include "main/colormac.h"
+#include "main/imports.h"
+#include "main/macros.h"
+#include "main/image.h"
 
 #include "swrast_setup/swrast_setup.h"
 #include "math/m_translate.h"
@@ -46,14 +46,10 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "tnl/t_context.h"
 
 #include "r300_context.h"
-#include "radeon_ioctl.h"
 #include "r300_state.h"
 #include "r300_emit.h"
 #include "r300_ioctl.h"
 
-#ifdef USER_BUFFERS
-#include "r300_mem.h"
-#endif
 
 #if SWIZZLE_X != R300_INPUT_ROUTE_SELECT_X || \
     SWIZZLE_Y != R300_INPUT_ROUTE_SELECT_Y || \
@@ -66,147 +62,6 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #define DEBUG_ALL DEBUG_VERTS
 
-#if defined(USE_X86_ASM)
-#define COPY_DWORDS( dst, src, nr )                                    \
-do {                                                                   \
-       int __tmp;                                                      \
-       __asm__ __volatile__( "rep ; movsl"                             \
-                             : "=%c" (__tmp), "=D" (dst), "=S" (__tmp) \
-                             : "0" (nr),                               \
-                               "D" ((long)dst),                        \
-                               "S" ((long)src) );                      \
-} while (0)
-#else
-#define COPY_DWORDS( dst, src, nr )            \
-do {                                           \
-   int j;                                      \
-   for ( j = 0 ; j < nr ; j++ )                        \
-      dst[j] = ((int *)src)[j];                        \
-   dst += nr;                                  \
-} while (0)
-#endif
-
-static void r300EmitVec4(GLcontext * ctx, struct r300_dma_region *rvb,
-                        GLvoid * data, int stride, int count)
-{
-       int i;
-       int *out = (int *)(rvb->address + rvb->start);
-
-       if (RADEON_DEBUG & DEBUG_VERTS)
-               fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-                       __FUNCTION__, count, stride, (void *)out, (void *)data);
-
-       if (stride == 4)
-               COPY_DWORDS(out, data, count);
-       else
-               for (i = 0; i < count; i++) {
-                       out[0] = *(int *)data;
-                       out++;
-                       data += stride;
-               }
-}
-
-static void r300EmitVec8(GLcontext * ctx, struct r300_dma_region *rvb,
-                        GLvoid * data, int stride, int count)
-{
-       int i;
-       int *out = (int *)(rvb->address + rvb->start);
-
-       if (RADEON_DEBUG & DEBUG_VERTS)
-               fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-                       __FUNCTION__, count, stride, (void *)out, (void *)data);
-
-       if (stride == 8)
-               COPY_DWORDS(out, data, count * 2);
-       else
-               for (i = 0; i < count; i++) {
-                       out[0] = *(int *)data;
-                       out[1] = *(int *)(data + 4);
-                       out += 2;
-                       data += stride;
-               }
-}
-
-static void r300EmitVec12(GLcontext * ctx, struct r300_dma_region *rvb,
-                         GLvoid * data, int stride, int count)
-{
-       int i;
-       int *out = (int *)(rvb->address + rvb->start);
-
-       if (RADEON_DEBUG & DEBUG_VERTS)
-               fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-                       __FUNCTION__, count, stride, (void *)out, (void *)data);
-
-       if (stride == 12)
-               COPY_DWORDS(out, data, count * 3);
-       else
-               for (i = 0; i < count; i++) {
-                       out[0] = *(int *)data;
-                       out[1] = *(int *)(data + 4);
-                       out[2] = *(int *)(data + 8);
-                       out += 3;
-                       data += stride;
-               }
-}
-
-static void r300EmitVec16(GLcontext * ctx, struct r300_dma_region *rvb,
-                         GLvoid * data, int stride, int count)
-{
-       int i;
-       int *out = (int *)(rvb->address + rvb->start);
-
-       if (RADEON_DEBUG & DEBUG_VERTS)
-               fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-                       __FUNCTION__, count, stride, (void *)out, (void *)data);
-
-       if (stride == 16)
-               COPY_DWORDS(out, data, count * 4);
-       else
-               for (i = 0; i < count; i++) {
-                       out[0] = *(int *)data;
-                       out[1] = *(int *)(data + 4);
-                       out[2] = *(int *)(data + 8);
-                       out[3] = *(int *)(data + 12);
-                       out += 4;
-                       data += stride;
-               }
-}
-
-static void r300EmitVec(GLcontext * ctx, struct r300_dma_region *rvb,
-                       GLvoid * data, int size, int stride, int count)
-{
-       r300ContextPtr rmesa = R300_CONTEXT(ctx);
-
-       if (stride == 0) {
-               r300AllocDmaRegion(rmesa, rvb, size * 4, 4);
-               count = 1;
-               rvb->aos_offset = GET_START(rvb);
-               rvb->aos_stride = 0;
-       } else {
-               r300AllocDmaRegion(rmesa, rvb, size * count * 4, 4);
-               rvb->aos_offset = GET_START(rvb);
-               rvb->aos_stride = size;
-       }
-
-       switch (size) {
-       case 1:
-               r300EmitVec4(ctx, rvb, data, stride, count);
-               break;
-       case 2:
-               r300EmitVec8(ctx, rvb, data, stride, count);
-               break;
-       case 3:
-               r300EmitVec12(ctx, rvb, data, stride, count);
-               break;
-       case 4:
-               r300EmitVec16(ctx, rvb, data, stride, count);
-               break;
-       default:
-               assert(0);
-               break;
-       }
-}
-
 #define DW_SIZE(x) ((inputs[tab[(x)]] << R300_DST_VEC_LOC_SHIFT) |     \
                    (attribptr[tab[(x)]]->size - 1) << R300_DATA_TYPE_0_SHIFT)
 
@@ -272,7 +127,6 @@ GLuint r300VAPInputCntl0(GLcontext * ctx, GLuint InputsRead)
 
 GLuint r300VAPInputCntl1(GLcontext * ctx, GLuint InputsRead)
 {
-       r300ContextPtr rmesa = R300_CONTEXT(ctx);
        GLuint i, vic_1 = 0;
 
        if (InputsRead & (1 << VERT_ATTRIB_POS))
@@ -284,10 +138,8 @@ GLuint r300VAPInputCntl1(GLcontext * ctx, GLuint InputsRead)
        if (InputsRead & (1 << VERT_ATTRIB_COLOR0))
                vic_1 |= R300_INPUT_CNTL_COLOR;
 
-       rmesa->state.texture.tc_count = 0;
        for (i = 0; i < ctx->Const.MaxTextureUnits; i++)
                if (InputsRead & (1 << (VERT_ATTRIB_TEX0 + i))) {
-                       rmesa->state.texture.tc_count++;
                        vic_1 |= R300_INPUT_CNTL_TC0 << i;
                }
 
@@ -314,10 +166,6 @@ GLuint r300VAPOutputCntl0(GLcontext * ctx, GLuint OutputsWritten)
                    R300_VAP_OUTPUT_VTX_FMT_0__COLOR_2_PRESENT |
                    R300_VAP_OUTPUT_VTX_FMT_0__COLOR_3_PRESENT;
 
-#if 0
-       if (OutputsWritten & (1 << VERT_RESULT_FOGC)) ;
-#endif
-
        if (OutputsWritten & (1 << VERT_RESULT_PSIZ))
                ret |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT;
 
@@ -326,12 +174,21 @@ GLuint r300VAPOutputCntl0(GLcontext * ctx, GLuint OutputsWritten)
 
 GLuint r300VAPOutputCntl1(GLcontext * ctx, GLuint OutputsWritten)
 {
-       GLuint i, ret = 0;
+       GLuint i, ret = 0, first_free_texcoord = 0;
 
        for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
                if (OutputsWritten & (1 << (VERT_RESULT_TEX0 + i))) {
                        ret |= (4 << (3 * i));
+                       ++first_free_texcoord;
+               }
+       }
+
+       if (OutputsWritten & (1 << VERT_RESULT_FOGC)) {
+               if (first_free_texcoord > 8) {
+                       fprintf(stderr, "\tout of free texcoords to write fog coord\n");
+                       _mesa_exit(-1);
                }
+               ret |= 1 << (3 * first_free_texcoord);
        }
 
        return ret;
@@ -357,12 +214,12 @@ int r300EmitArrays(GLcontext * ctx)
        struct r300_vertex_program *prog =
            (struct r300_vertex_program *)CURRENT_VERTEX_SHADER(ctx);
 
-       if (hw_tcl_on) {
+       if (rmesa->options.hw_tcl_enabled) {
                inputs = prog->inputs;
                InputsRead = prog->key.InputsRead;
                OutputsWritten = prog->key.OutputsWritten;
        } else {
-               inputs = rmesa->state.sw_tcl_inputs;
+               inputs = rmesa->swtcl.sw_tcl_inputs;
 
                DECLARE_RENDERINPUTS(render_inputs_bitset);
                RENDERINPUTS_COPY(render_inputs_bitset, tnl->render_inputs_bitset);
@@ -371,7 +228,6 @@ int r300EmitArrays(GLcontext * ctx)
 
                assert(RENDERINPUTS_TEST(render_inputs_bitset, _TNL_ATTRIB_POS));
                assert(RENDERINPUTS_TEST(render_inputs_bitset, _TNL_ATTRIB_NORMAL) == 0);
-               //assert(RENDERINPUTS_TEST(render_inputs_bitset, _TNL_ATTRIB_COLOR0));
 
                if (RENDERINPUTS_TEST(render_inputs_bitset, _TNL_ATTRIB_POS)) {
                        InputsRead |= 1 << VERT_ATTRIB_POS;
@@ -416,7 +272,7 @@ int r300EmitArrays(GLcontext * ctx)
                        if (InputsRead & (1 << i))
                                inputs[i] = 6 + (i - VERT_ATTRIB_TEX0);
 
-               RENDERINPUTS_COPY(rmesa->state.render_inputs_bitset, render_inputs_bitset);
+               RENDERINPUTS_COPY(rmesa->render_inputs_bitset, render_inputs_bitset);
        }
 
        assert(InputsRead);
@@ -433,7 +289,7 @@ int r300EmitArrays(GLcontext * ctx)
        }
 
        for (i = 0; i < nr; i++) {
-               int ci, fix, found = 0;
+               int ci;
 
                swizzle[i][0] = SWIZZLE_ZERO;
                swizzle[i][1] = SWIZZLE_ZERO;
@@ -443,60 +299,34 @@ int r300EmitArrays(GLcontext * ctx)
                for (ci = 0; ci < vb->AttribPtr[tab[i]]->size; ci++) {
                        swizzle[i][ci] = ci;
                }
-
-               if (r300IsGartMemory(rmesa, vb->AttribPtr[tab[i]]->data, 4)) {
-                       if (vb->AttribPtr[tab[i]]->stride % 4) {
-                               return R300_FALLBACK_TCL;
-                       }
-                       rmesa->state.aos[i].address = (void *)(vb->AttribPtr[tab[i]]->data);
-                       rmesa->state.aos[i].start = 0;
-                       rmesa->state.aos[i].aos_offset = r300GartOffsetFromVirtual(rmesa, vb->AttribPtr[tab[i]]->data);
-                       rmesa->state.aos[i].aos_stride = vb->AttribPtr[tab[i]]->stride / 4;
-                       rmesa->state.aos[i].aos_size = vb->AttribPtr[tab[i]]->size;
-               } else {
-                       r300EmitVec(ctx, &rmesa->state.aos[i],
+               rcommon_emit_vector(ctx, &rmesa->radeon.tcl.aos[i],
                                    vb->AttribPtr[tab[i]]->data,
                                    vb->AttribPtr[tab[i]]->size,
                                    vb->AttribPtr[tab[i]]->stride, count);
-               }
-
-               rmesa->state.aos[i].aos_size = vb->AttribPtr[tab[i]]->size;
-
-               for (fix = 0; fix <= 4 - vb->AttribPtr[tab[i]]->size; fix++) {
-                       if ((rmesa->state.aos[i].aos_offset - _mesa_sizeof_type(GL_FLOAT) * fix) % 4) {
-                               continue;
-                       }
-                       found = 1;
-                       break;
-               }
-
-               if (found) {
-                       if (fix > 0) {
-                               WARN_ONCE("Feeling lucky?\n");
-                       }
-                       rmesa->state.aos[i].aos_offset -= _mesa_sizeof_type(GL_FLOAT) * fix;
-                       for (ci = 0; ci < vb->AttribPtr[tab[i]]->size; ci++) {
-                               swizzle[i][ci] += fix;
-                       }
-               } else {
-                       WARN_ONCE
-                           ("Cannot handle offset %x with stride %d, comp %d\n",
-                            rmesa->state.aos[i].aos_offset,
-                            rmesa->state.aos[i].aos_stride,
-                            vb->AttribPtr[tab[i]]->size);
-                       return R300_FALLBACK_TCL;
-               }
        }
 
        /* Setup INPUT_ROUTE. */
-       R300_STATECHANGE(rmesa, vir[0]);
-       ((drm_r300_cmd_header_t *) rmesa->hw.vir[0].cmd)->packet0.count =
-           r300VAPInputRoute0(&rmesa->hw.vir[0].cmd[R300_VIR_CNTL_0],
-                              vb->AttribPtr, inputs, tab, nr);
-       R300_STATECHANGE(rmesa, vir[1]);
-       ((drm_r300_cmd_header_t *) rmesa->hw.vir[1].cmd)->packet0.count =
-           r300VAPInputRoute1(&rmesa->hw.vir[1].cmd[R300_VIR_CNTL_0], swizzle,
-                              nr);
+       if (rmesa->radeon.radeonScreen->kernel_mm) {
+               R300_STATECHANGE(rmesa, vir[0]);
+               rmesa->hw.vir[0].cmd[0] &= 0xC000FFFF;
+               rmesa->hw.vir[1].cmd[0] &= 0xC000FFFF;
+               rmesa->hw.vir[0].cmd[0] |=
+                       (r300VAPInputRoute0(&rmesa->hw.vir[0].cmd[R300_VIR_CNTL_0],
+                                           vb->AttribPtr, inputs, tab, nr) & 0x3FFF) << 16;
+               R300_STATECHANGE(rmesa, vir[1]);
+               rmesa->hw.vir[1].cmd[0] |=
+                       (r300VAPInputRoute1(&rmesa->hw.vir[1].cmd[R300_VIR_CNTL_0], swizzle,
+                                           nr) & 0x3FFF) << 16;
+       } else {
+               R300_STATECHANGE(rmesa, vir[0]);
+               ((drm_r300_cmd_header_t *) rmesa->hw.vir[0].cmd)->packet0.count =
+                       r300VAPInputRoute0(&rmesa->hw.vir[0].cmd[R300_VIR_CNTL_0],
+                                          vb->AttribPtr, inputs, tab, nr);
+               R300_STATECHANGE(rmesa, vir[1]);
+               ((drm_r300_cmd_header_t *) rmesa->hw.vir[1].cmd)->packet0.count =
+                       r300VAPInputRoute1(&rmesa->hw.vir[1].cmd[R300_VIR_CNTL_0], swizzle,
+                                          nr);
+       }
 
        /* Setup INPUT_CNTL. */
        R300_STATECHANGE(rmesa, vic);
@@ -510,50 +340,22 @@ int r300EmitArrays(GLcontext * ctx)
        rmesa->hw.vof.cmd[R300_VOF_CNTL_1] =
            r300VAPOutputCntl1(ctx, OutputsWritten);
 
-       rmesa->state.aos_count = nr;
+       rmesa->radeon.tcl.aos_count = nr;
 
        return R300_FALLBACK_NONE;
 }
 
-#ifdef USER_BUFFERS
-void r300UseArrays(GLcontext * ctx)
-{
-       r300ContextPtr rmesa = R300_CONTEXT(ctx);
-       int i;
-
-       if (rmesa->state.elt_dma.buf)
-               r300_mem_use(rmesa, rmesa->state.elt_dma.buf->id);
-
-       for (i = 0; i < rmesa->state.aos_count; i++) {
-               if (rmesa->state.aos[i].buf)
-                       r300_mem_use(rmesa, rmesa->state.aos[i].buf->id);
-       }
-}
-#endif
-
-void r300ReleaseArrays(GLcontext * ctx)
-{
-       r300ContextPtr rmesa = R300_CONTEXT(ctx);
-       int i;
-
-       r300ReleaseDmaRegion(rmesa, &rmesa->state.elt_dma, __FUNCTION__);
-       for (i = 0; i < rmesa->state.aos_count; i++) {
-               r300ReleaseDmaRegion(rmesa, &rmesa->state.aos[i], __FUNCTION__);
-       }
-}
-
 void r300EmitCacheFlush(r300ContextPtr rmesa)
 {
-       int cmd_reserved = 0;
-       int cmd_written = 0;
-
-       drm_radeon_cmd_header_t *cmd = NULL;
-
-       reg_start(R300_RB3D_DSTCACHE_CTLSTAT, 0);
-       e32(RB3D_DSTCACHE_CTLSTAT_DC_FREE_FREE_3D_TAGS |
-           RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_FLUSH_DIRTY_3D);
-
-       reg_start(ZB_ZCACHE_CTLSTAT, 0);
-       e32(ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE |
-           ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE);
+       BATCH_LOCALS(&rmesa->radeon);
+
+       BEGIN_BATCH_NO_AUTOSTATE(4);
+       OUT_BATCH_REGVAL(R300_RB3D_DSTCACHE_CTLSTAT,
+               R300_RB3D_DSTCACHE_CTLSTAT_DC_FREE_FREE_3D_TAGS |
+               R300_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_FLUSH_DIRTY_3D);
+       OUT_BATCH_REGVAL(R300_ZB_ZCACHE_CTLSTAT,
+               R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE |
+               R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE);
+       END_BATCH();
+       COMMIT_BATCH();
 }