radeon: enable tiling fallbacks in 3D driver.
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_common_context.c
index eb0e5b35e5ecc6decc6b9f01c4034efecd8eb730..5e744f9deb724490a7dc621c8217c1f0bef896f5 100644 (file)
@@ -46,6 +46,10 @@ 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 */
+#include "r600_context.h"
+#endif
+
 #define DRIVER_DATE "20090101"
 
 #ifndef RADEON_DEBUG
@@ -81,6 +85,17 @@ static const char* get_chip_family_name(int chip_family)
        case CHIP_FAMILY_R580: return "R580";
        case CHIP_FAMILY_RV560: return "RV560";
        case CHIP_FAMILY_RV570: return "RV570";
+       case CHIP_FAMILY_R600: return "R600";
+       case CHIP_FAMILY_RV610: return "RV610";
+       case CHIP_FAMILY_RV630: return "RV630";
+       case CHIP_FAMILY_RV670: return "RV670";
+       case CHIP_FAMILY_RV620: return "RV620";
+       case CHIP_FAMILY_RV635: return "RV635";
+       case CHIP_FAMILY_RS780: return "RS780";
+       case CHIP_FAMILY_RV770: return "RV770";
+       case CHIP_FAMILY_RV730: return "RV730";
+       case CHIP_FAMILY_RV710: return "RV710";
+       case CHIP_FAMILY_RV740: return "RV740";
        default: return "unknown";
        }
 }
@@ -95,7 +110,9 @@ static const GLubyte *radeonGetString(GLcontext * ctx, GLenum name)
 
        switch (name) {
        case GL_VENDOR:
-               if (IS_R300_CLASS(radeon->radeonScreen))
+               if (IS_R600_CLASS(radeon->radeonScreen))
+                       return (GLubyte *) "Advanced Micro Devices, Inc.";
+               else if (IS_R300_CLASS(radeon->radeonScreen))
                        return (GLubyte *) "DRI R300 Project";
                else
                        return (GLubyte *) "Tungsten Graphics, Inc.";
@@ -108,7 +125,9 @@ static const GLubyte *radeonGetString(GLcontext * ctx, GLenum name)
                const char* chipclass;
                char hardwarename[32];
 
-               if (IS_R300_CLASS(radeon->radeonScreen))
+               if (IS_R600_CLASS(radeon->radeonScreen))
+                       chipclass = "R600";
+               else if (IS_R300_CLASS(radeon->radeonScreen))
                        chipclass = "R300";
                else if (IS_R200_CLASS(radeon->radeonScreen))
                        chipclass = "R200";
@@ -123,7 +142,9 @@ static const GLubyte *radeonGetString(GLcontext * ctx, GLenum name)
                offset = driGetRendererString(buffer, hardwarename, DRIVER_DATE,
                                              agp_mode);
 
-               if (IS_R300_CLASS(radeon->radeonScreen)) {
+               if (IS_R600_CLASS(radeon->radeonScreen)) {
+                       sprintf(&buffer[offset], " TCL");
+               } else if (IS_R300_CLASS(radeon->radeonScreen)) {
                        sprintf(&buffer[offset], " %sTCL",
                                (radeon->radeonScreen->chip_flags & RADEON_CHIPSET_TCL)
                                ? "" : "NO-");
@@ -184,6 +205,7 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
        ctx = radeon->glCtx;
        driContextPriv->driverPrivate = radeon;
 
+       meta_init_metaops(ctx, &radeon->meta);
        /* DRI fields */
        radeon->dri.context = driContextPriv;
        radeon->dri.screen = sPriv;
@@ -199,8 +221,11 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
        fthrottle_mode = driQueryOptioni(&radeon->optionCache, "fthrottle_mode");
        radeon->iw.irq_seq = -1;
        radeon->irqsEmitted = 0;
-       radeon->do_irqs = (fthrottle_mode == DRI_CONF_FTHROTTLE_IRQS &&
-                         radeon->radeonScreen->irq);
+       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_usleeps = (fthrottle_mode == DRI_CONF_FTHROTTLE_USLEEPS);
 
@@ -216,7 +241,26 @@ GLboolean radeonInitContext(radeonContextPtr radeon,
                 radeon->texture_depth = ( glVisual->rgbBits > 16 ) ?
                DRI_CONF_TEXTURE_DEPTH_32 : DRI_CONF_TEXTURE_DEPTH_16;
 
-       radeon->texture_row_align = 32;
+       if (IS_R600_CLASS(radeon->radeonScreen)) {
+               radeon->texture_row_align = 256;
+               radeon->texture_rect_row_align = 256;
+               radeon->texture_compressed_row_align = 256;
+       } else if (IS_R200_CLASS(radeon->radeonScreen) ||
+                  IS_R100_CLASS(radeon->radeonScreen)) {
+               radeon->texture_row_align = 32;
+               radeon->texture_rect_row_align = 64;
+               radeon->texture_compressed_row_align = 32;
+       } else { /* R300 - not sure this is all correct */
+               int chip_family = radeon->radeonScreen->chip_family;
+               if (chip_family == CHIP_FAMILY_RS600 ||
+                   chip_family == CHIP_FAMILY_RS690 ||
+                   chip_family == CHIP_FAMILY_RS740)
+                       radeon->texture_row_align = 64;
+               else
+                       radeon->texture_row_align = 32;
+               radeon->texture_rect_row_align = 64;
+               radeon->texture_compressed_row_align = 64;
+       }
 
        return GL_TRUE;
 }
@@ -251,20 +295,33 @@ void radeonDestroyContext(__DRIcontextPrivate *driContextPriv )
        radeonContextPtr radeon = (radeonContextPtr) driContextPriv->driverPrivate;
        radeonContextPtr current = ctx ? RADEON_CONTEXT(ctx) : NULL;
 
+    /* +r6/r7 */
+    __DRIscreenPrivate *sPriv = driContextPriv->driScreenPriv;
+       radeonScreenPtr screen = (radeonScreenPtr) (sPriv->private);
+    /* --------- */
+
        if (radeon == current) {
                radeon_firevertices(radeon);
                _mesa_make_current(NULL, NULL, NULL);
        }
 
        assert(radeon);
-       if (radeon) {
+       if (radeon) 
+    {
+
+#if RADEON_COMMON && defined(RADEON_COMMON_FOR_R600) /* +r6/r7 */
+           if (IS_R600_CLASS(screen))
+        {
+               r600DestroyContext(driContextPriv);
+        }
+#endif
 
                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 );
@@ -286,6 +343,9 @@ void radeonDestroyContext(__DRIcontextPrivate *driContextPriv )
 
                rcommonDestroyCmdBuf(radeon);
 
+#if RADEON_COMMON && defined(RADEON_COMMON_FOR_R600) /* +r6/r7 */
+           if (!IS_R600_CLASS(screen))
+#endif
                radeon_destroy_atom_list(radeon);
 
                if (radeon->state.scissor.pClipRects) {
@@ -326,48 +386,88 @@ radeon_make_kernel_renderbuffer_current(radeonContextPtr radeon,
 
        if ((rb = (void *)draw->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer)) {
                if (!rb->bo) {
+#ifdef RADEON_DEBUG_BO
+            rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
+                                               radeon->radeonScreen->frontOffset,
+                                               0,
+                                               0,
+                                               RADEON_GEM_DOMAIN_VRAM,
+                                               0,
+                        "Front Buf");
+#else
                        rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
                                                radeon->radeonScreen->frontOffset,
                                                0,
                                                0,
                                                RADEON_GEM_DOMAIN_VRAM,
                                                0);
+#endif /* RADEON_DEBUG_BO */
                }
                rb->cpp = radeon->radeonScreen->cpp;
                rb->pitch = radeon->radeonScreen->frontPitch * rb->cpp;
        }
        if ((rb = (void *)draw->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer)) {
                if (!rb->bo) {
+#ifdef RADEON_DEBUG_BO
                        rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
+                                               radeon->radeonScreen->backOffset,
+                                               0,
+                                               0,
+                                               RADEON_GEM_DOMAIN_VRAM,
+                                               0,
+                        "Back Buf");
+#else
+            rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
                                                radeon->radeonScreen->backOffset,
                                                0,
                                                0,
                                                RADEON_GEM_DOMAIN_VRAM,
                                                0);
+#endif /* RADEON_DEBUG_BO */
                }
                rb->cpp = radeon->radeonScreen->cpp;
                rb->pitch = radeon->radeonScreen->backPitch * rb->cpp;
        }
        if ((rb = (void *)draw->base.Attachment[BUFFER_DEPTH].Renderbuffer)) {
                if (!rb->bo) {
+#ifdef RADEON_DEBUG_BO
+            rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
+                                               radeon->radeonScreen->depthOffset,
+                                               0,
+                                               0,
+                                               RADEON_GEM_DOMAIN_VRAM,
+                                               0,
+                        "Z Buf");
+#else
                        rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
                                                radeon->radeonScreen->depthOffset,
                                                0,
                                                0,
                                                RADEON_GEM_DOMAIN_VRAM,
                                                0);
+#endif /* RADEON_DEBUG_BO */
                }
                rb->cpp = radeon->radeonScreen->cpp;
                rb->pitch = radeon->radeonScreen->depthPitch * rb->cpp;
        }
        if ((rb = (void *)draw->base.Attachment[BUFFER_STENCIL].Renderbuffer)) {
                if (!rb->bo) {
+#ifdef RADEON_DEBUG_BO
+            rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
+                                               radeon->radeonScreen->depthOffset,
+                                               0,
+                                               0,
+                                               RADEON_GEM_DOMAIN_VRAM,
+                                               0,
+                        "Stencil Buf");
+#else
                        rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
                                                radeon->radeonScreen->depthOffset,
                                                0,
                                                0,
                                                RADEON_GEM_DOMAIN_VRAM,
                                                0);
+#endif /* RADEON_DEBUG_BO */
                }
                rb->cpp = radeon->radeonScreen->cpp;
                rb->pitch = radeon->radeonScreen->depthPitch * rb->cpp;
@@ -390,6 +490,16 @@ radeon_make_renderbuffer_current(radeonContextPtr radeon,
 
        if ((rb = (void *)draw->base.Attachment[BUFFER_FRONT_LEFT].Renderbuffer)) {
                if (!rb->bo) {
+#ifdef RADEON_DEBUG_BO
+            rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
+                                               radeon->radeonScreen->frontOffset +
+                                               radeon->radeonScreen->fbLocation,
+                                               size,
+                                               4096,
+                                               RADEON_GEM_DOMAIN_VRAM,
+                                               0,
+                        "Front Buf");
+#else
                        rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
                                                radeon->radeonScreen->frontOffset +
                                                radeon->radeonScreen->fbLocation,
@@ -397,12 +507,23 @@ radeon_make_renderbuffer_current(radeonContextPtr radeon,
                                                4096,
                                                RADEON_GEM_DOMAIN_VRAM,
                                                0);
+#endif /* RADEON_DEBUG_BO */
                }
                rb->cpp = radeon->radeonScreen->cpp;
                rb->pitch = radeon->radeonScreen->frontPitch * rb->cpp;
        }
        if ((rb = (void *)draw->base.Attachment[BUFFER_BACK_LEFT].Renderbuffer)) {
                if (!rb->bo) {
+#ifdef RADEON_DEBUG_BO
+            rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
+                                               radeon->radeonScreen->backOffset +
+                                               radeon->radeonScreen->fbLocation,
+                                               size,
+                                               4096,
+                                               RADEON_GEM_DOMAIN_VRAM,
+                                               0,
+                        "Back Buf");
+#else
                        rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
                                                radeon->radeonScreen->backOffset +
                                                radeon->radeonScreen->fbLocation,
@@ -410,32 +531,55 @@ radeon_make_renderbuffer_current(radeonContextPtr radeon,
                                                4096,
                                                RADEON_GEM_DOMAIN_VRAM,
                                                0);
+#endif /* RADEON_DEBUG_BO */
                }
                rb->cpp = radeon->radeonScreen->cpp;
                rb->pitch = radeon->radeonScreen->backPitch * rb->cpp;
        }
        if ((rb = (void *)draw->base.Attachment[BUFFER_DEPTH].Renderbuffer)) {
                if (!rb->bo) {
+#ifdef RADEON_DEBUG_BO
                        rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
+                                               radeon->radeonScreen->depthOffset +
+                                               radeon->radeonScreen->fbLocation,
+                                               size,
+                                               4096,
+                                               RADEON_GEM_DOMAIN_VRAM,
+                                               0,
+                        "Z Buf");
+#else
+            rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
                                                radeon->radeonScreen->depthOffset +
                                                radeon->radeonScreen->fbLocation,
                                                size,
                                                4096,
                                                RADEON_GEM_DOMAIN_VRAM,
                                                0);
+#endif /* RADEON_DEBUG_BO */
                }
                rb->cpp = radeon->radeonScreen->cpp;
                rb->pitch = radeon->radeonScreen->depthPitch * rb->cpp;
        }
        if ((rb = (void *)draw->base.Attachment[BUFFER_STENCIL].Renderbuffer)) {
                if (!rb->bo) {
+#ifdef RADEON_DEBUG_BO
                        rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
+                                               radeon->radeonScreen->depthOffset +
+                                               radeon->radeonScreen->fbLocation,
+                                               size,
+                                               4096,
+                                               RADEON_GEM_DOMAIN_VRAM,
+                                               0,
+                        "Stencil Buf");
+#else
+            rb->bo = radeon_bo_open(radeon->radeonScreen->bom,
                                                radeon->radeonScreen->depthOffset +
                                                radeon->radeonScreen->fbLocation,
                                                size,
                                                4096,
                                                RADEON_GEM_DOMAIN_VRAM,
                                                0);
+#endif /* RADEON_DEBUG_BO */
                }
                rb->cpp = radeon->radeonScreen->cpp;
                rb->pitch = radeon->radeonScreen->depthPitch * rb->cpp;
@@ -487,8 +631,10 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
                struct radeon_renderbuffer *stencil_rb;
 
                i = 0;
-               if ((radeon->is_front_buffer_rendering || !draw->color_rb[1])
-                       && draw->color_rb[0]) {
+               if ((radeon->is_front_buffer_rendering ||
+                    radeon->is_front_buffer_reading ||
+                    !draw->color_rb[1])
+                   && draw->color_rb[0]) {
                        attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
                        attachments[i++] = radeon_bits_per_pixel(draw->color_rb[0]);
                }
@@ -606,8 +752,8 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
 
                rb->cpp = buffers[i].cpp;
                rb->pitch = buffers[i].pitch;
-               rb->width = drawable->w;
-               rb->height = drawable->h;
+               rb->base.Width = drawable->w;
+               rb->base.Height = drawable->h;
                rb->has_surface = 0;
 
                if (buffers[i].attachment == __DRI_BUFFER_STENCIL && depth_bo) {
@@ -616,18 +762,37 @@ radeon_update_renderbuffers(__DRIcontext *context, __DRIdrawable *drawable)
                        bo = depth_bo;
                        radeon_bo_ref(bo);
                } else {
+                       uint32_t tiling_flags = 0, pitch = 0;
+                       int ret;
+#ifdef RADEON_DEBUG_BO
+                       bo = radeon_bo_open(radeon->radeonScreen->bom,
+                                               buffers[i].name,
+                                               0,
+                                               0,
+                                               RADEON_GEM_DOMAIN_VRAM,
+                                               buffers[i].flags,
+                        regname);
+#else
                        bo = radeon_bo_open(radeon->radeonScreen->bom,
                                                buffers[i].name,
                                                0,
                                                0,
                                                RADEON_GEM_DOMAIN_VRAM,
                                                buffers[i].flags);
+#endif /* RADEON_DEBUG_BO */
                        if (bo == NULL) {
 
                                fprintf(stderr, "failed to attach %s %d\n",
                                        regname, buffers[i].name);
 
                        }
+
+                       ret = radeon_bo_get_tiling(bo, &tiling_flags, &pitch);
+                       if (tiling_flags & RADEON_TILING_MACRO)
+                               bo->flags |= RADEON_BO_FLAGS_MACRO_TILE;
+                       if (tiling_flags & RADEON_TILING_MICRO)
+                               bo->flags |= RADEON_BO_FLAGS_MICRO_TILE;
+                       
                }
 
                if (buffers[i].attachment == __DRI_BUFFER_DEPTH) {
@@ -695,7 +860,6 @@ GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
                radeon_make_renderbuffer_current(radeon, drfb);
        }
 
-
        if (RADEON_DEBUG & DEBUG_DRI)
             fprintf(stderr, "%s ctx %p dfb %p rfb %p\n", __FUNCTION__, radeon->glCtx, drfb, readfb);
 
@@ -733,6 +897,7 @@ GLboolean radeonMakeCurrent(__DRIcontextPrivate * driContextPriv,
 
        if (RADEON_DEBUG & DEBUG_DRI)
                fprintf(stderr, "End %s\n", __FUNCTION__);
+
        return GL_TRUE;
 }