Merge branch 'mesa_7_6_branch' into mesa_7_7_branch
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common_context.c
index 35622099bf0665d94c2d072a010f5f444dac07c7..71f70d724b9458b9af7675b4997c626783ef0af0 100644 (file)
@@ -37,6 +37,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "utils.h"
 #include "vblank.h"
 #include "drirenderbuffer.h"
+#include "drivers/common/meta.h"
 #include "main/context.h"
 #include "main/framebuffer.h"
 #include "main/renderbuffer.h"
@@ -46,7 +47,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #include "swrast_setup/swrast_setup.h"
 #include "tnl/tnl.h"
 
-#if RADEON_COMMON && defined(RADEON_COMMON_FOR_R600) /* +r6/r7 */
+#if defined(RADEON_R600)
 #include "r600_context.h"
 #endif
 
@@ -92,6 +93,7 @@ static const char* get_chip_family_name(int chip_family)
        case CHIP_FAMILY_RV620: return "RV620";
        case CHIP_FAMILY_RV635: return "RV635";
        case CHIP_FAMILY_RS780: return "RS780";
+       case CHIP_FAMILY_RS880: return "RS880";
        case CHIP_FAMILY_RV770: return "RV770";
        case CHIP_FAMILY_RV730: return "RV730";
        case CHIP_FAMILY_RV710: return "RV710";
@@ -206,6 +208,9 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
        driContextPriv->driverPrivate = radeon;
 
        meta_init_metaops(ctx, &radeon->meta);
+
+       _mesa_meta_init(ctx);
+
        /* DRI fields */
        radeon->dri.context = driContextPriv;
        radeon->dri.screen = sPriv;
@@ -222,11 +227,8 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
        fthrottle_mode = driQueryOptioni(&radeon->optionCache, "fthrottle_mode");
        radeon->iw.irq_seq = -1;
        radeon->irqsEmitted = 0;
-       if (IS_R600_CLASS(radeon->radeonScreen))
-               radeon->do_irqs = 0;
-       else
-               radeon->do_irqs = (fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS &&
-                                  radeon->radeonScreen->irq);
+       radeon->do_irqs = (fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS &&
+                          radeon->radeonScreen->irq);
 
        radeon->do_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
 
@@ -260,10 +262,10 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
                else
                        radeon->texture_row_align = 32;
                radeon->texture_rect_row_align = 64;
-               radeon->texture_compressed_row_align = 64;
+               radeon->texture_compressed_row_align = 32;
        }
 
-       make_empty_list(&radeon->query.not_flushed_head);
+       radeon_init_dma(radeon);
 
        return GL_TRUE;
 }
@@ -297,54 +299,49 @@ void radeonDestroyContext(__DRIcontextPrivate *driContextPriv )
        GET_CURRENT_CONTEXT(ctx);
        radeonContextPtr radeon = (radeonContextPtr) driContextPriv->driverPrivate;
        radeonContextPtr current = ctx ? RADEON_CONTEXT(ctx) : NULL;
-#if RADEON_COMMON && defined(RADEON_COMMON_FOR_R600) /* +r6/r7 */
-       __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
-       radeonScreenPtr screen = (radeonScreenPtr) (sPriv->private);
-#endif
+
+       assert(radeon);
+
+       _mesa_meta_free(radeon->glCtx);
 
        if (radeon == current) {
                radeon_firevertices(radeon);
                _mesa_make_current(NULL, NULL, NULL);
        }
 
-       assert(radeon);
-       if (radeon) {
-               if (radeon->dma.current) {
-                       rcommonFlushCmdBuf( radeon, __FUNCTION__ );
-               }
-
-               radeonReleaseArrays(radeon->glCtx, ~0);
-               meta_destroy_metaops(&radeon->meta);
-               if (radeon->vtbl.free_context)
-                       radeon->vtbl.free_context(radeon->glCtx);
-               _swsetup_DestroyContext( radeon->glCtx );
-               _tnl_DestroyContext( radeon->glCtx );
-               _vbo_DestroyContext( radeon->glCtx );
-               _swrast_DestroyContext( radeon->glCtx );
-
-               /* free atom list */
-               /* free the Mesa context */
-               _mesa_destroy_context(radeon->glCtx);
-
-               /* _mesa_destroy_context() might result in calls to functions that
-                * depend on the DriverCtx, so don't set it to NULL before.
-                *
-                * radeon->glCtx->DriverCtx = NULL;
-                */
-               /* free the option cache */
-               driDestroyOptionCache(&radeon->optionCache);
-
-               rcommonDestroyCmdBuf(radeon);
-
-#if RADEON_COMMON && defined(RADEON_COMMON_FOR_R600) /* +r6/r7 */
-           if (!IS_R600_CLASS(screen))
-#endif
-               radeon_destroy_atom_list(radeon);
+       if (!is_empty_list(&radeon->dma.reserved)) {
+               rcommonFlushCmdBuf( radeon, __FUNCTION__ );
+       }
 
-               if (radeon->state.scissor.pClipRects) {
-                       FREE(radeon->state.scissor.pClipRects);
-                       radeon->state.scissor.pClipRects = 0;
-               }
+       radeonFreeDmaRegions(radeon);
+       radeonReleaseArrays(radeon->glCtx, ~0);
+       meta_destroy_metaops(&radeon->meta);
+       if (radeon->vtbl.free_context)
+               radeon->vtbl.free_context(radeon->glCtx);
+       _swsetup_DestroyContext( radeon->glCtx );
+       _tnl_DestroyContext( radeon->glCtx );
+       _vbo_DestroyContext( radeon->glCtx );
+       _swrast_DestroyContext( radeon->glCtx );
+
+       /* free atom list */
+       /* free the Mesa context */
+       _mesa_destroy_context(radeon->glCtx);
+
+       /* _mesa_destroy_context() might result in calls to functions that
+        * depend on the DriverCtx, so don't set it to NULL before.
+        *
+        * radeon->glCtx->DriverCtx = NULL;
+        */
+       /* free the option cache */
+       driDestroyOptionCache(&radeon->optionCache);
+
+       rcommonDestroyCmdBuf(radeon);
+
+       radeon_destroy_atom_list(radeon);
+
+       if (radeon->state.scissor.pClipRects) {
+               FREE(radeon->state.scissor.pClipRects);
+               radeon->state.scissor.pClipRects = 0;
        }
 #ifdef RADEON_BO_TRACK
        track = fopen("/tmp/tracklog", "w");
@@ -362,7 +359,7 @@ GLboolean radeonUnbindContext(__DRIcontextPrivate * driContextPriv)
 {
        radeonContextPtr radeon = (radeonContextPtr) driContextPriv->driverPrivate;
 
-       if (RADEON_DEBUG & DEBUG_DRI)
+       if (RADEON_DEBUG & RADEON_DRI)
                fprintf(stderr, "%s ctx %p\n", __FUNCTION__,
                        radeon->glCtx);
 
@@ -498,19 +495,7 @@ radeon_make_renderbuffer_current(radeonContextPtr radeon,
 static unsigned
 radeon_bits_per_pixel(const struct radeon_renderbuffer *rb)
 {
-   switch (rb->base._ActualFormat) {
-   case GL_RGB5:
-   case GL_DEPTH_COMPONENT16:
-      return 16;
-   case GL_RGB8:
-   case GL_RGBA8:
-   case GL_DEPTH_COMPONENT24:
-   case GL_DEPTH24_STENCIL8_EXT:
-   case GL_STENCIL_INDEX8_EXT:
-      return 32;
-   default:
-      return 0;
-   }
+   return _mesa_get_format_bytes(rb->base.Format) * 8; 
 }
 
 void
@@ -526,7 +511,7 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
        char *regname;
        struct radeon_bo *depth_bo = NULL, *bo;
 
-       if (RADEON_DEBUG & DEBUG_DRI)
+       if (RADEON_DEBUG & RADEON_DRI)
            fprintf(stderr, "enter %s, drawable %p\n", __func__, drawable);
 
        draw = drawable->driverPrivate;
@@ -653,7 +638,7 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
                                continue;
                }
 
-               if (RADEON_DEBUG & DEBUG_DRI)
+               if (RADEON_DEBUG & RADEON_DRI)
                        fprintf(stderr,
                                "attaching buffer %s, %d, at %d, cpp %d, pitch %d\n",
                                regname, buffers[i].name, buffers[i].attachment,
@@ -666,7 +651,7 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
                rb->has_surface = 0;
 
                if (buffers[i].attachment == __DRI_BUFFER_STENCIL && depth_bo) {
-                       if (RADEON_DEBUG & DEBUG_DRI)
+                       if (RADEON_DEBUG & RADEON_DRI)
                                fprintf(stderr, "(reusing depth buffer as stencil)\n");
                        bo = depth_bo;
                        radeon_bo_ref(bo);
@@ -739,7 +724,7 @@ GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
        struct gl_framebuffer *readfb;
 
        if (!driContextPriv) {
-               if (RADEON_DEBUG & DEBUG_DRI)
+               if (RADEON_DEBUG & RADEON_DRI)
                        fprintf(stderr, "%s ctx is null\n", __FUNCTION__);
                _mesa_make_current(NULL, NULL, NULL);
                return GL_TRUE;
@@ -761,7 +746,7 @@ GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
                radeon_make_renderbuffer_current(radeon, drfb);
        }
 
-       if (RADEON_DEBUG & DEBUG_DRI)
+       if (RADEON_DEBUG & RADEON_DRI)
             fprintf(stderr, "%s ctx %p dfb %p rfb %p\n", __FUNCTION__, radeon->glCtx, drfb, readfb);
 
        driUpdateFramebufferSize(radeon->glCtx, driDrawPriv);
@@ -796,7 +781,7 @@ GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
        }
 
 
-       if (RADEON_DEBUG & DEBUG_DRI)
+       if (RADEON_DEBUG & RADEON_DRI)
                fprintf(stderr, "End %s\n", __FUNCTION__);
 
        return GL_TRUE;