i965: Silence unused parameter warnings in intel_mipmap_tree.c
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_dma.c
index 386262b126e9086ea9c51305fc70b266595e7956..4c1c5d046fd7fd34e5eb5798c0d4142d7b9c8d81 100644 (file)
@@ -32,7 +32,8 @@ USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 #include <errno.h>
 #include "radeon_common.h"
-#include "main/simple_list.h"
+#include "radeon_fog.h"
+#include "util/simple_list.h"
 
 #if defined(USE_X86_ASM)
 #define COPY_DWORDS( dst, src, nr )                                    \
@@ -58,9 +59,9 @@ void radeonEmitVec4(uint32_t *out, const GLvoid * data, int stride, int count)
 {
        int i;
 
-       if (RADEON_DEBUG & DEBUG_VERTS)
+       if (RADEON_DEBUG & RADEON_VERTS)
                fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-                       __FUNCTION__, count, stride, (void *)out, (void *)data);
+                       __func__, count, stride, (void *)out, (void *)data);
 
        if (stride == 4)
                COPY_DWORDS(out, data, count);
@@ -76,9 +77,9 @@ void radeonEmitVec8(uint32_t *out, const GLvoid * data, int stride, int count)
 {
        int i;
 
-       if (RADEON_DEBUG & DEBUG_VERTS)
+       if (RADEON_DEBUG & RADEON_VERTS)
                fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-                       __FUNCTION__, count, stride, (void *)out, (void *)data);
+                       __func__, count, stride, (void *)out, (void *)data);
 
        if (stride == 8)
                COPY_DWORDS(out, data, count * 2);
@@ -95,9 +96,9 @@ void radeonEmitVec12(uint32_t *out, const GLvoid * data, int stride, int count)
 {
        int i;
 
-       if (RADEON_DEBUG & DEBUG_VERTS)
+       if (RADEON_DEBUG & RADEON_VERTS)
                fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-                       __FUNCTION__, count, stride, (void *)out, (void *)data);
+                       __func__, count, stride, (void *)out, (void *)data);
 
        if (stride == 12) {
                COPY_DWORDS(out, data, count * 3);
@@ -116,9 +117,9 @@ void radeonEmitVec16(uint32_t *out, const GLvoid * data, int stride, int count)
 {
        int i;
 
-       if (RADEON_DEBUG & DEBUG_VERTS)
+       if (RADEON_DEBUG & RADEON_VERTS)
                fprintf(stderr, "%s count %d stride %d out %p data %p\n",
-                       __FUNCTION__, count, stride, (void *)out, (void *)data);
+                       __func__, count, stride, (void *)out, (void *)data);
 
        if (stride == 16)
                COPY_DWORDS(out, data, count * 4);
@@ -133,7 +134,7 @@ void radeonEmitVec16(uint32_t *out, const GLvoid * data, int stride, int count)
                }
 }
 
-void rcommon_emit_vector(GLcontext * ctx, struct radeon_aos *aos,
+void rcommon_emit_vector(struct gl_context * ctx, struct radeon_aos *aos,
                         const GLvoid * data, int size, int stride, int count)
 {
        radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
@@ -151,6 +152,7 @@ void rcommon_emit_vector(GLcontext * ctx, struct radeon_aos *aos,
        aos->components = size;
        aos->count = count;
 
+       radeon_bo_map(aos->bo, 1);
        out = (uint32_t*)((char*)aos->bo->ptr + aos->offset);
        switch (size) {
        case 1: radeonEmitVec4(out, data, stride, count); break;
@@ -161,6 +163,42 @@ void rcommon_emit_vector(GLcontext * ctx, struct radeon_aos *aos,
                assert(0);
                break;
        }
+       radeon_bo_unmap(aos->bo);
+}
+
+void rcommon_emit_vecfog(struct gl_context *ctx, struct radeon_aos *aos,
+                        GLvoid *data, int stride, int count)
+{
+       int i;
+       float *out;
+       int size = 1;
+       radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
+
+       if (RADEON_DEBUG & RADEON_VERTS)
+               fprintf(stderr, "%s count %d stride %d\n",
+                       __func__, count, stride);
+
+       if (stride == 0) {
+               radeonAllocDmaRegion( rmesa, &aos->bo, &aos->offset, size * 4, 32 );
+               count = 1;
+               aos->stride = 0;
+       } else {
+               radeonAllocDmaRegion(rmesa, &aos->bo, &aos->offset, size * count * 4, 32);
+               aos->stride = size;
+       }
+
+       aos->components = size;
+       aos->count = count;
+
+       /* Emit the data */
+       radeon_bo_map(aos->bo, 1);
+       out = (float*)((char*)aos->bo->ptr + aos->offset);
+       for (i = 0; i < count; i++) {
+               out[0] = radeonComputeFogBlendFactor( ctx, *(GLfloat *)data );
+               out++;
+               data += stride;
+       }
+       radeon_bo_unmap(aos->bo);
 }
 
 void radeon_init_dma(radeonContextPtr rmesa)
@@ -179,13 +217,8 @@ void radeonRefillCurrentDmaRegion(radeonContextPtr rmesa, int size)
        if (size > rmesa->dma.minimum_size)
                rmesa->dma.minimum_size = (size + 15) & (~15);
 
-       if (RADEON_DEBUG & (DEBUG_IOCTL | DEBUG_DMA))
-               fprintf(stderr, "%s\n", __FUNCTION__);
-
-
-       /* unmap old reserved bo */
-       if (!is_empty_list(&rmesa->dma.reserved))
-               radeon_bo_unmap(first_elem(&rmesa->dma.reserved)->bo);
+       radeon_print(RADEON_DMA, RADEON_NORMAL, "%s size %d minimum_size %Zi\n",
+                       __func__, size, rmesa->dma.minimum_size);
 
        if (is_empty_list(&rmesa->dma.free)
              || last_elem(&rmesa->dma.free)->bo->size < size) {
@@ -198,7 +231,7 @@ again_alloc:
                                            RADEON_GEM_DOMAIN_GTT, 0);
 
                if (!dma_bo->bo) {
-                       rcommonFlushCmdBuf(rmesa, __FUNCTION__);
+                       rcommonFlushCmdBuf(rmesa, __func__);
                        goto again_alloc;
                }
                insert_at_head(&rmesa->dma.reserved, dma_bo);
@@ -207,14 +240,13 @@ again_alloc:
                   counter on unused buffers for later freeing them from
                   begin of list */
                dma_bo = last_elem(&rmesa->dma.free);
-               assert(dma_bo->bo->cref == 1);
                remove_from_list(dma_bo);
                insert_at_head(&rmesa->dma.reserved, dma_bo);
        }
 
        rmesa->dma.current_used = 0;
        rmesa->dma.current_vertexptr = 0;
-       
+
        if (radeon_cs_space_check_with_bo(rmesa->cmdbuf.cs,
                                          first_elem(&rmesa->dma.reserved)->bo,
                                          RADEON_GEM_DOMAIN_GTT, 0))
@@ -224,7 +256,6 @@ again_alloc:
         /* Cmd buff have been flushed in radeon_revalidate_bos */
                goto again_alloc;
        }
-
        radeon_bo_map(first_elem(&rmesa->dma.reserved)->bo, 1);
 }
 
@@ -235,11 +266,11 @@ void radeonAllocDmaRegion(radeonContextPtr rmesa,
                          struct radeon_bo **pbo, int *poffset,
                          int bytes, int alignment)
 {
-       if (RADEON_DEBUG & DEBUG_IOCTL)
-               fprintf(stderr, "%s %d\n", __FUNCTION__, bytes);
+       if (RADEON_DEBUG & RADEON_IOCTL)
+               fprintf(stderr, "%s %d\n", __func__, bytes);
 
        if (rmesa->dma.flush)
-               rmesa->dma.flush(rmesa->glCtx);
+               rmesa->dma.flush(&rmesa->glCtx);
 
        assert(rmesa->dma.current_used == rmesa->dma.current_vertexptr);
 
@@ -263,28 +294,27 @@ void radeonAllocDmaRegion(radeonContextPtr rmesa,
 
 void radeonFreeDmaRegions(radeonContextPtr rmesa)
 {
-       struct radeon_dma_bo *dma_bo = CALLOC_STRUCT(radeon_dma_bo);
+       struct radeon_dma_bo *dma_bo;
        struct radeon_dma_bo *temp;
-       if (RADEON_DEBUG & DEBUG_DMA)
-               fprintf(stderr, "%s\n", __FUNCTION__);
+       if (RADEON_DEBUG & RADEON_DMA)
+               fprintf(stderr, "%s\n", __func__);
 
        foreach_s(dma_bo, temp, &rmesa->dma.free) {
                remove_from_list(dma_bo);
                radeon_bo_unref(dma_bo->bo);
-               FREE(dma_bo);
+               free(dma_bo);
        }
 
        foreach_s(dma_bo, temp, &rmesa->dma.wait) {
                remove_from_list(dma_bo);
                radeon_bo_unref(dma_bo->bo);
-               FREE(dma_bo);
+               free(dma_bo);
        }
 
        foreach_s(dma_bo, temp, &rmesa->dma.reserved) {
                remove_from_list(dma_bo);
-               radeon_bo_unmap(dma_bo->bo);
                radeon_bo_unref(dma_bo->bo);
-               FREE(dma_bo);
+               free(dma_bo);
        }
 }
 
@@ -293,8 +323,8 @@ void radeonReturnDmaRegion(radeonContextPtr rmesa, int return_bytes)
        if (is_empty_list(&rmesa->dma.reserved))
                return;
 
-       if (RADEON_DEBUG & DEBUG_IOCTL)
-               fprintf(stderr, "%s %d\n", __FUNCTION__, return_bytes);
+       if (RADEON_DEBUG & RADEON_IOCTL)
+               fprintf(stderr, "%s %d\n", __func__, return_bytes);
        rmesa->dma.current_used -= return_bytes;
        rmesa->dma.current_vertexptr = rmesa->dma.current_used;
 }
@@ -317,7 +347,7 @@ void radeonReleaseDmaRegions(radeonContextPtr rmesa)
        const int expire_at = ++rmesa->dma.free.expire_counter + DMA_BO_FREE_TIME;
        const int time = rmesa->dma.free.expire_counter;
 
-       if (RADEON_DEBUG & DEBUG_DMA) {
+       if (RADEON_DEBUG & RADEON_DMA) {
                size_t free = 0,
                       wait = 0,
                       reserved = 0;
@@ -331,13 +361,9 @@ void radeonReleaseDmaRegions(radeonContextPtr rmesa)
                        ++reserved;
 
                fprintf(stderr, "%s: free %zu, wait %zu, reserved %zu, minimum_size: %zu\n",
-                     __FUNCTION__, free, wait, reserved, rmesa->dma.minimum_size);
+                     __func__, free, wait, reserved, rmesa->dma.minimum_size);
        }
 
-       if (!rmesa->radeonScreen->driScreen->dri2.enabled) {
-               /* request updated cs processing information from kernel */
-               legacy_track_pending(rmesa->radeonScreen->bom, 0);
-       }
        /* move waiting bos to free list.
           wait list provides gpu time to handle data before reuse */
        foreach_s(dma_bo, temp, &rmesa->dma.wait) {
@@ -345,33 +371,32 @@ void radeonReleaseDmaRegions(radeonContextPtr rmesa)
                        WARN_ONCE("Leaking dma buffer object!\n");
                        radeon_bo_unref(dma_bo->bo);
                        remove_from_list(dma_bo);
-                       FREE(dma_bo);
+                       free(dma_bo);
                        continue;
                }
                /* free objects that are too small to be used because of large request */
                if (dma_bo->bo->size < rmesa->dma.minimum_size) {
                   radeon_bo_unref(dma_bo->bo);
                   remove_from_list(dma_bo);
-                  FREE(dma_bo);
+                  free(dma_bo);
                   continue;
                }
-               if (!radeon_bo_is_idle(dma_bo->bo))
-                       continue;
+               if (!radeon_bo_is_idle(dma_bo->bo)) {
+                       break;
+               }
                remove_from_list(dma_bo);
                dma_bo->expire_counter = expire_at;
                insert_at_tail(&rmesa->dma.free, dma_bo);
        }
 
-       /* unmap the last dma region */
-       if (!is_empty_list(&rmesa->dma.reserved))
-               radeon_bo_unmap(first_elem(&rmesa->dma.reserved)->bo);
        /* move reserved to wait list */
        foreach_s(dma_bo, temp, &rmesa->dma.reserved) {
+               radeon_bo_unmap(dma_bo->bo);
                /* free objects that are too small to be used because of large request */
                if (dma_bo->bo->size < rmesa->dma.minimum_size) {
                   radeon_bo_unref(dma_bo->bo);
                   remove_from_list(dma_bo);
-                  FREE(dma_bo);
+                  free(dma_bo);
                   continue;
                }
                remove_from_list(dma_bo);
@@ -385,7 +410,7 @@ void radeonReleaseDmaRegions(radeonContextPtr rmesa)
                        break;
                remove_from_list(dma_bo);
                radeon_bo_unref(dma_bo->bo);
-               FREE(dma_bo);
+               free(dma_bo);
        }
 
 }
@@ -393,16 +418,17 @@ void radeonReleaseDmaRegions(radeonContextPtr rmesa)
 
 /* Flush vertices in the current dma region.
  */
-void rcommon_flush_last_swtcl_prim( GLcontext *ctx  )
+void rcommon_flush_last_swtcl_prim( struct gl_context *ctx  )
 {
        radeonContextPtr rmesa = RADEON_CONTEXT(ctx);
        struct radeon_dma *dma = &rmesa->dma;
-               
 
-       if (RADEON_DEBUG & DEBUG_IOCTL)
-               fprintf(stderr, "%s\n", __FUNCTION__);
+       if (RADEON_DEBUG & RADEON_IOCTL)
+               fprintf(stderr, "%s\n", __func__);
        dma->flush = NULL;
 
+       radeon_bo_unmap(rmesa->swtcl.bo);
+
        if (!is_empty_list(&dma->reserved)) {
            GLuint current_offset = dma->current_used;
 
@@ -417,6 +443,8 @@ void rcommon_flush_last_swtcl_prim( GLcontext *ctx  )
            }
            rmesa->swtcl.numverts = 0;
        }
+       radeon_bo_unref(rmesa->swtcl.bo);
+       rmesa->swtcl.bo = NULL;
 }
 /* Alloc space in the current dma region.
  */
@@ -425,12 +453,13 @@ rcommonAllocDmaLowVerts( radeonContextPtr rmesa, int nverts, int vsize )
 {
        GLuint bytes = vsize * nverts;
        void *head;
-       if (RADEON_DEBUG & DEBUG_IOCTL)
-               fprintf(stderr, "%s\n", __FUNCTION__);
+       if (RADEON_DEBUG & RADEON_IOCTL)
+               fprintf(stderr, "%s\n", __func__);
+
        if(is_empty_list(&rmesa->dma.reserved)
              ||rmesa->dma.current_vertexptr + bytes > first_elem(&rmesa->dma.reserved)->bo->size) {
                if (rmesa->dma.flush) {
-                       rmesa->dma.flush(rmesa->glCtx);
+                       rmesa->dma.flush(&rmesa->glCtx);
                }
 
                 radeonRefillCurrentDmaRegion(rmesa, bytes);
@@ -440,31 +469,37 @@ rcommonAllocDmaLowVerts( radeonContextPtr rmesa, int nverts, int vsize )
 
         if (!rmesa->dma.flush) {
                /* if cmdbuf flushed DMA restart */
-                rmesa->glCtx->Driver.NeedFlush |= FLUSH_STORED_VERTICES;
+                rmesa->glCtx.Driver.NeedFlush |= FLUSH_STORED_VERTICES;
                 rmesa->dma.flush = rcommon_flush_last_swtcl_prim;
         }
 
-       ASSERT( vsize == rmesa->swtcl.vertex_size * 4 );
-        ASSERT( rmesa->dma.flush == rcommon_flush_last_swtcl_prim );
-        ASSERT( rmesa->dma.current_used +
+       assert( vsize == rmesa->swtcl.vertex_size * 4 );
+        assert( rmesa->dma.flush == rcommon_flush_last_swtcl_prim );
+        assert( rmesa->dma.current_used +
                 rmesa->swtcl.numverts * rmesa->swtcl.vertex_size * 4 ==
                 rmesa->dma.current_vertexptr );
 
-       head = (first_elem(&rmesa->dma.reserved)->bo->ptr + rmesa->dma.current_vertexptr);
+       if (!rmesa->swtcl.bo) {
+               rmesa->swtcl.bo = first_elem(&rmesa->dma.reserved)->bo;
+               radeon_bo_ref(rmesa->swtcl.bo);
+               radeon_bo_map(rmesa->swtcl.bo, 1);
+       }
+
+       head = (rmesa->swtcl.bo->ptr + rmesa->dma.current_vertexptr);
        rmesa->dma.current_vertexptr += bytes;
        rmesa->swtcl.numverts += nverts;
        return head;
 }
 
-void radeonReleaseArrays( GLcontext *ctx, GLuint newinputs )
+void radeonReleaseArrays( struct gl_context *ctx, GLuint newinputs )
 {
    radeonContextPtr radeon = RADEON_CONTEXT( ctx );
    int i;
-       if (RADEON_DEBUG & DEBUG_IOCTL)
-               fprintf(stderr, "%s\n", __FUNCTION__);
+       if (RADEON_DEBUG & RADEON_IOCTL)
+               fprintf(stderr, "%s\n", __func__);
 
    if (radeon->dma.flush) {
-       radeon->dma.flush(radeon->glCtx);
+       radeon->dma.flush(&radeon->glCtx);
    }
    for (i = 0; i < radeon->tcl.aos_count; i++) {
       if (radeon->tcl.aos[i].bo) {