i965/miptree: Replace is_lossless_compressed with mt->aux_usage checks
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common.c
index d8839d1d4912de9520c629942c12c1697d4106f7..6e4b4c48808bcef5e36f083b058e6a836c3e9048 100644 (file)
@@ -164,10 +164,10 @@ uint32_t radeonGetAge(radeonContextPtr radeon)
 
        gp.param = RADEON_PARAM_LAST_CLEAR;
        gp.value = (int *)&age;
-       ret = drmCommandWriteRead(radeon->dri.fd, DRM_RADEON_GETPARAM,
+       ret = drmCommandWriteRead(radeon->radeonScreen->driScreen->fd, DRM_RADEON_GETPARAM,
                                  &gp, sizeof(gp));
        if (ret) {
-               fprintf(stderr, "%s: drmRadeonGetParam: %d\n", __FUNCTION__,
+               fprintf(stderr, "%s: drmRadeonGetParam: %d\n", __func__,
                        ret);
                exit(1);
        }
@@ -220,9 +220,9 @@ void radeon_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
         */
        if (ctx->NewState & (_NEW_BUFFERS | _NEW_COLOR | _NEW_PIXEL)) {
                /* this updates the DrawBuffer->_NumColorDrawBuffers fields, etc */
-               _mesa_update_framebuffer(ctx);
+               _mesa_update_framebuffer(ctx, ctx->ReadBuffer, ctx->DrawBuffer);
                /* this updates the DrawBuffer's Width/Height if it's a FBO */
-               _mesa_update_draw_buffer_bounds(ctx);
+               _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer);
        }
 
        if (fb->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
@@ -233,9 +233,9 @@ void radeon_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
                return;
        }
 
-       if (fb->Name)
+       if (fb->Name) {
                ;/* do something depthy/stencily TODO */
-
+        }
 
                /* none */
        if (fb->Name == 0) {
@@ -306,7 +306,6 @@ void radeon_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
        if (ctx->Driver.Enable) {
                ctx->Driver.Enable(ctx, GL_DEPTH_TEST,
                                   (ctx->Depth.Test && fb->Visual.depthBits > 0));
-               /* Need to update the derived ctx->Stencil._Enabled first */
                ctx->Driver.Enable(ctx, GL_STENCIL_TEST,
                                   (ctx->Stencil.Enabled && fb->Visual.stencilBits > 0));
        } else {
@@ -342,8 +341,8 @@ void radeon_draw_buffer(struct gl_context *ctx, struct gl_framebuffer *fb)
 void radeonDrawBuffer( struct gl_context *ctx, GLenum mode )
 {
        if (RADEON_DEBUG & RADEON_DRI)
-               fprintf(stderr, "%s %s\n", __FUNCTION__,
-                       _mesa_lookup_enum_by_nr( mode ));
+               fprintf(stderr, "%s %s\n", __func__,
+                       _mesa_enum_to_string( mode ));
 
        if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
                radeonContextPtr radeon = RADEON_CONTEXT(ctx);
@@ -358,8 +357,8 @@ void radeonDrawBuffer( struct gl_context *ctx, GLenum mode )
        * that the front-buffer has actually been allocated.
        */
                if (!was_front_buffer_rendering && radeon->is_front_buffer_rendering) {
-                       radeon_update_renderbuffers(radeon->dri.context,
-                               radeon->dri.context->driDrawablePriv, GL_FALSE);
+                       radeon_update_renderbuffers(radeon->driContext,
+                               radeon->driContext->driDrawablePriv, GL_FALSE);
       }
        }
 
@@ -375,8 +374,8 @@ void radeonReadBuffer( struct gl_context *ctx, GLenum mode )
                                        || (mode == GL_FRONT);
 
                if (!was_front_buffer_reading && rmesa->is_front_buffer_reading) {
-                       radeon_update_renderbuffers(rmesa->dri.context,
-                                                   rmesa->dri.context->driReadablePriv, GL_FALSE);
+                       radeon_update_renderbuffers(rmesa->driContext,
+                                                   rmesa->driContext->driReadablePriv, GL_FALSE);
                }
        }
        /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */
@@ -399,7 +398,7 @@ void radeon_window_moved(radeonContextPtr radeon)
 void radeon_viewport(struct gl_context *ctx)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
-       __DRIcontext *driContext = radeon->dri.context;
+       __DRIcontext *driContext = radeon->driContext;
        void (*old_viewport)(struct gl_context *ctx);
 
        if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
@@ -426,7 +425,7 @@ static void radeon_print_state_atom(radeonContextPtr radeon, struct radeon_state
        if (!radeon_is_debug_enabled(RADEON_STATE, RADEON_VERBOSE) )
                return;
 
-       dwords = (*state->check) (&radeon->glCtx, state);
+       dwords = state->check(&radeon->glCtx, state);
 
        fprintf(stderr, "  emit %s %d/%d\n", state->name, dwords, state->cmd_size);
 
@@ -486,20 +485,20 @@ out:
        return dwords;
 }
 
-static INLINE void radeon_emit_atom(radeonContextPtr radeon, struct radeon_state_atom *atom)
+static inline void radeon_emit_atom(radeonContextPtr radeon, struct radeon_state_atom *atom)
 {
        BATCH_LOCALS(radeon);
        int dwords;
 
-       dwords = (*atom->check) (&radeon->glCtx, atom);
+       dwords = atom->check(&radeon->glCtx, atom);
        if (dwords) {
 
                radeon_print_state_atom(radeon, atom);
 
                if (atom->emit) {
-                       (*atom->emit)(&radeon->glCtx, atom);
+                       atom->emit(&radeon->glCtx, atom);
                } else {
-                       BEGIN_BATCH_NO_AUTOSTATE(dwords);
+                       BEGIN_BATCH(dwords);
                        OUT_BATCH_TABLE(atom->cmd, dwords);
                        END_BATCH();
                }
@@ -511,13 +510,10 @@ static INLINE void radeon_emit_atom(radeonContextPtr radeon, struct radeon_state
 
 }
 
-static INLINE void radeonEmitAtoms(radeonContextPtr radeon, GLboolean emitAll)
+static inline void radeonEmitAtoms(radeonContextPtr radeon, GLboolean emitAll)
 {
        struct radeon_state_atom *atom;
 
-       if (radeon->vtbl.pre_emit_atoms)
-               radeon->vtbl.pre_emit_atoms(radeon);
-
        /* Emit actual atoms */
        if (radeon->hw.all_dirty || emitAll) {
                foreach(atom, &radeon->hw.atomlist)
@@ -532,20 +528,9 @@ static INLINE void radeonEmitAtoms(radeonContextPtr radeon, GLboolean emitAll)
        COMMIT_BATCH();
 }
 
-static GLboolean radeon_revalidate_bos(struct gl_context *ctx)
-{
-       radeonContextPtr radeon = RADEON_CONTEXT(ctx);
-       int ret;
-
-       ret = radeon_cs_space_check(radeon->cmdbuf.cs);
-       if (ret == RADEON_CS_SPACE_FLUSH)
-               return GL_FALSE;
-       return GL_TRUE;
-}
-
 void radeonEmitState(radeonContextPtr radeon)
 {
-       radeon_print(RADEON_STATE, RADEON_NORMAL, "%s\n", __FUNCTION__);
+       radeon_print(RADEON_STATE, RADEON_NORMAL, "%s\n", __func__);
 
        if (radeon->vtbl.pre_emit_state)
                radeon->vtbl.pre_emit_state(radeon);
@@ -576,7 +561,7 @@ void radeonFlush(struct gl_context *ctx)
 {
        radeonContextPtr radeon = RADEON_CONTEXT(ctx);
        if (RADEON_DEBUG & RADEON_IOCTL)
-               fprintf(stderr, "%s %d\n", __FUNCTION__, radeon->cmdbuf.cs->cdw);
+               fprintf(stderr, "%s %d\n", __func__, radeon->cmdbuf.cs->cdw);
 
        /* okay if we have no cmds in the buffer &&
           we have no DMA flush &&
@@ -590,7 +575,7 @@ void radeonFlush(struct gl_context *ctx)
                radeon->dma.flush( ctx );
 
        if (radeon->cmdbuf.cs->cdw)
-               rcommonFlushCmdBuf(radeon, __FUNCTION__);
+               rcommonFlushCmdBuf(radeon, __func__);
 
 flush_front:
        if (_mesa_is_winsys_fbo(ctx->DrawBuffer) && radeon->front_buffer_dirty) {
@@ -605,7 +590,7 @@ flush_front:
                         */
                        radeon->front_buffer_dirty = GL_FALSE;
 
-                       (*screen->dri2.loader->flushFrontBuffer)(drawable, drawable->loaderPrivate);
+                       screen->dri2.loader->flushFrontBuffer(drawable, drawable->loaderPrivate);
                }
        }
 }
@@ -649,7 +634,7 @@ int rcommonFlushCmdBufLocked(radeonContextPtr rmesa, const char *caller)
        rmesa->cmdbuf.flushing = 1;
 
        if (RADEON_DEBUG & RADEON_IOCTL) {
-               fprintf(stderr, "%s from %s\n", __FUNCTION__, caller);
+               fprintf(stderr, "%s from %s\n", __func__, caller);
        }
 
        radeonEmitQueryEnd(&rmesa->glCtx);
@@ -661,9 +646,8 @@ int rcommonFlushCmdBufLocked(radeonContextPtr rmesa, const char *caller)
        radeon_cs_erase(rmesa->cmdbuf.cs);
        rmesa->cmdbuf.flushing = 0;
 
-       if (radeon_revalidate_bos(&rmesa->glCtx) == GL_FALSE) {
+       if (!rmesa->vtbl.revalidate_all_buffers(&rmesa->glCtx))
                fprintf(stderr,"failed to revalidate buffers\n");
-       }
 
        return ret;
 }
@@ -708,6 +692,7 @@ void rcommonInitCmdBuf(radeonContextPtr rmesa)
 {
        GLuint size;
        struct drm_radeon_gem_info mminfo = { 0 };
+       int fd = rmesa->radeonScreen->driScreen->fd;
 
        /* Initialize command buffer */
        size = 256 * driQueryOptioni(&rmesa->optionCache,
@@ -726,8 +711,7 @@ void rcommonInitCmdBuf(radeonContextPtr rmesa)
                        "Allocating %d bytes command buffer (max state is %d bytes)\n",
                        size * 4, rmesa->hw.max_state_size * 4);
 
-       rmesa->cmdbuf.csm =
-               radeon_cs_manager_gem_ctor(rmesa->radeonScreen->driScreen->fd);
+       rmesa->cmdbuf.csm = radeon_cs_manager_gem_ctor(fd);
        if (rmesa->cmdbuf.csm == NULL) {
                /* FIXME: fatal error */
                return;
@@ -740,7 +724,7 @@ void rcommonInitCmdBuf(radeonContextPtr rmesa)
                                  (void (*)(void *))rmesa->glCtx.Driver.Flush, &rmesa->glCtx);
 
 
-       if (!drmCommandWriteRead(rmesa->dri.fd, DRM_RADEON_GEM_INFO,
+       if (!drmCommandWriteRead(fd, DRM_RADEON_GEM_INFO,
                                 &mminfo, sizeof(mminfo))) {
                radeon_cs_set_limit(rmesa->cmdbuf.cs, RADEON_GEM_DOMAIN_VRAM,
                                    mminfo.vram_visible);
@@ -759,7 +743,6 @@ void rcommonDestroyCmdBuf(radeonContextPtr rmesa)
 }
 
 void rcommonBeginBatch(radeonContextPtr rmesa, int n,
-                      int dostate,
                       const char *file,
                       const char *function,
                       int line)