f1d64e5
From 982c22f16c8eeee9be81779fbfe17d8d3f9b6897 Mon Sep 17 00:00:00 2001
f1d64e5
From: Adam Jackson <ajax@redhat.com>
f1d64e5
Date: Thu, 14 Apr 2011 16:04:50 -0400
f1d64e5
Subject: [PATCH] R520: Fix textures larger than 2k
f1d64e5
f1d64e5
Ported from the equivalent fix in Mesa.
f1d64e5
---
f1d64e5
 src/radeon_exa_render.c          |   30 +++++++++++++++++++++++++++---
f1d64e5
 src/radeon_reg.h                 |    1 +
f1d64e5
 src/radeon_textured_videofuncs.c |   27 ++++++++++++++++++++++++---
f1d64e5
 3 files changed, 52 insertions(+), 6 deletions(-)
f1d64e5
f1d64e5
diff --git a/src/radeon_exa_render.c b/src/radeon_exa_render.c
f1d64e5
index 43d3555..e5c231f 100644
f1d64e5
--- a/src/radeon_exa_render.c
f1d64e5
+++ b/src/radeon_exa_render.c
f1d64e5
@@ -1180,10 +1180,10 @@ static Bool FUNC_NAME(R300TextureSetup)(PicturePtr pPict, PixmapPtr pPix,
f1d64e5
 					int unit)
f1d64e5
 {
f1d64e5
     RINFO_FROM_SCREEN(pPix->drawable.pScreen);
f1d64e5
-    uint32_t txfilter, txformat0, txformat1, txoffset, txpitch;
f1d64e5
+    uint32_t txfilter, txformat0, txformat1, txoffset, txpitch, us_format = 0;
f1d64e5
     int w = pPict->pDrawable->width;
f1d64e5
     int h = pPict->pDrawable->height;
f1d64e5
-    int i, pixel_shift;
f1d64e5
+    int i, pixel_shift, out_size = 6;
f1d64e5
     unsigned int repeatType = pPict->repeat ? pPict->repeatType : RepeatNone;
f1d64e5
     struct radeon_exa_pixmap_priv *driver_priv;
f1d64e5
     ACCEL_PREAMBLE();
f1d64e5
@@ -1230,6 +1230,26 @@ static Bool FUNC_NAME(R300TextureSetup)(PicturePtr pPict, PixmapPtr pPix,
f1d64e5
     if (IS_R500_3D && ((h - 1) & 0x800))
f1d64e5
 	txpitch |= R500_TXHEIGHT_11;
f1d64e5
 
f1d64e5
+    if (info->ChipFamily == CHIP_FAMILY_R520) {
f1d64e5
+	unsigned us_width = (w - 1) & 0x7ff;
f1d64e5
+	unsigned us_height = (h - 1) & 0x7ff;
f1d64e5
+	unsigned us_depth = 0;
f1d64e5
+
f1d64e5
+	if (w > 2048) {
f1d64e5
+	    us_width = (0x7ff + us_width) >> 1;
f1d64e5
+	    us_depth |= 0x0d;
f1d64e5
+	}
f1d64e5
+	if (h > 2048) {
f1d64e5
+	    us_height = (0x7ff + us_height) >> 1;
f1d64e5
+	    us_depth |= 0x0e;
f1d64e5
+	}
f1d64e5
+
f1d64e5
+	us_format = (us_width << R300_TXWIDTH_SHIFT) |
f1d64e5
+		    (us_height << R300_TXHEIGHT_SHIFT) |
f1d64e5
+		    (us_depth << R300_TXDEPTH_SHIFT);
f1d64e5
+	out_size++;
f1d64e5
+    }
f1d64e5
+
f1d64e5
     /* Use TXPITCH instead of TXWIDTH for address computations: we could
f1d64e5
      * omit this if there is no padding, but there is no apparent advantage
f1d64e5
      * in doing so.
f1d64e5
@@ -1276,7 +1296,9 @@ static Bool FUNC_NAME(R300TextureSetup)(PicturePtr pPict, PixmapPtr pPix,
f1d64e5
 	RADEON_FALLBACK(("Bad filter 0x%x\n", pPict->filter));
f1d64e5
     }
f1d64e5
 
f1d64e5
-    BEGIN_ACCEL_RELOC(repeatType == RepeatNone ? 7 : 6, 1);
f1d64e5
+    if (repeatType == RepeatNone)
f1d64e5
+	out_size++;
f1d64e5
+    BEGIN_ACCEL_RELOC(out_size, 1);
f1d64e5
     OUT_ACCEL_REG(R300_TX_FILTER0_0 + (unit * 4), txfilter);
f1d64e5
     OUT_ACCEL_REG(R300_TX_FILTER1_0 + (unit * 4), 0);
f1d64e5
     OUT_ACCEL_REG(R300_TX_FORMAT0_0 + (unit * 4), txformat0);
f1d64e5
@@ -1287,6 +1309,8 @@ static Bool FUNC_NAME(R300TextureSetup)(PicturePtr pPict, PixmapPtr pPix,
f1d64e5
 
f1d64e5
     if (repeatType == RepeatNone)
f1d64e5
 	OUT_ACCEL_REG(R300_TX_BORDER_COLOR_0 + (unit * 4), 0);
f1d64e5
+    if (info->ChipFamily == CHIP_FAMILY_R520)
f1d64e5
+	OUT_ACCEL_REG(R500_US_FORMAT0_0 + (unit * 4), us_format);
f1d64e5
     FINISH_ACCEL();
f1d64e5
 
f1d64e5
     if (pPict->transform != 0) {
f1d64e5
diff --git a/src/radeon_reg.h b/src/radeon_reg.h
f1d64e5
index e61c29d..fbf1558 100644
f1d64e5
--- a/src/radeon_reg.h
f1d64e5
+++ b/src/radeon_reg.h
f1d64e5
@@ -4688,6 +4688,7 @@
f1d64e5
 #define R300_TX_FORMAT0_2				0x4488
f1d64e5
 #       define R300_TXWIDTH_SHIFT                       0
f1d64e5
 #       define R300_TXHEIGHT_SHIFT                      11
f1d64e5
+#       define R300_TXDEPTH_SHIFT                       22
f1d64e5
 #       define R300_NUM_LEVELS_SHIFT                    26
f1d64e5
 #       define R300_NUM_LEVELS_MASK                     0x
f1d64e5
 #       define R300_TXPROJECTED                         (1 << 30)
f1d64e5
diff --git a/src/radeon_textured_videofuncs.c b/src/radeon_textured_videofuncs.c
f1d64e5
index a22c416..84aba6f 100644
f1d64e5
--- a/src/radeon_textured_videofuncs.c
f1d64e5
+++ b/src/radeon_textured_videofuncs.c
f1d64e5
@@ -2661,11 +2661,11 @@ FUNC_NAME(R500PrepareTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
f1d64e5
     PixmapPtr pPixmap = pPriv->pPixmap;
f1d64e5
     struct radeon_exa_pixmap_priv *driver_priv;
f1d64e5
     struct radeon_bo *src_bo = pPriv->src_bo[pPriv->currentBuffer];
f1d64e5
-    uint32_t txfilter, txformat0, txformat1, txoffset, txpitch;
f1d64e5
+    uint32_t txfilter, txformat0, txformat1, txoffset, txpitch, us_format = 0;
f1d64e5
     uint32_t dst_pitch, dst_format;
f1d64e5
     uint32_t txenable, colorpitch, bicubic_offset;
f1d64e5
     uint32_t output_fmt;
f1d64e5
-    int pixel_shift;
f1d64e5
+    int pixel_shift, out_size = 6;
f1d64e5
     ACCEL_PREAMBLE();
f1d64e5
 
f1d64e5
 #ifdef XF86DRM_MODE
f1d64e5
@@ -2791,15 +2791,36 @@ FUNC_NAME(R500PrepareTexturedVideo)(ScrnInfoPtr pScrn, RADEONPortPrivPtr pPriv)
f1d64e5
     if ((pPriv->h - 1) & 0x800)
f1d64e5
 	txpitch |= R500_TXHEIGHT_11;
f1d64e5
 
f1d64e5
+    if (info->ChipFamily == CHIP_FAMILY_R520) {
f1d64e5
+	unsigned us_width = (pPriv->w - 1) & 0x7ff;
f1d64e5
+	unsigned us_height = (pPriv->h - 1) & 0x7ff;
f1d64e5
+	unsigned us_depth = 0;
f1d64e5
+
f1d64e5
+	if (pPriv->w > 2048) {
f1d64e5
+	    us_width = (0x7ff + us_width) >> 1;
f1d64e5
+	    us_depth |= 0x0d;
f1d64e5
+	}
f1d64e5
+	if (pPriv->h > 2048) {
f1d64e5
+	    us_height = (0x7ff + us_height) >> 1;
f1d64e5
+	    us_depth |= 0x0e;
f1d64e5
+	}
f1d64e5
+	us_format = (us_width << R300_TXWIDTH_SHIFT) |
f1d64e5
+		    (us_height << R300_TXHEIGHT_SHIFT) |
f1d64e5
+		    (us_depth << R300_TXDEPTH_SHIFT);
f1d64e5
+	out_size++;
f1d64e5
+    }
f1d64e5
+
f1d64e5
     txoffset = info->cs ? 0 : pPriv->src_offset;
f1d64e5
 
f1d64e5
-    BEGIN_ACCEL_RELOC(6, 1);
f1d64e5
+    BEGIN_ACCEL_RELOC(out_size, 1);
f1d64e5
     OUT_ACCEL_REG(R300_TX_FILTER0_0, txfilter);
f1d64e5
     OUT_ACCEL_REG(R300_TX_FILTER1_0, 0);
f1d64e5
     OUT_ACCEL_REG(R300_TX_FORMAT0_0, txformat0);
f1d64e5
     OUT_ACCEL_REG(R300_TX_FORMAT1_0, txformat1);
f1d64e5
     OUT_ACCEL_REG(R300_TX_FORMAT2_0, txpitch);
f1d64e5
     OUT_TEXTURE_REG(R300_TX_OFFSET_0, txoffset, src_bo);
f1d64e5
+    if (info->ChipFamily == CHIP_FAMILY_R520)
f1d64e5
+	OUT_ACCEL_REG(R500_US_FORMAT0_0, us_format);
f1d64e5
     FINISH_ACCEL();
f1d64e5
 
f1d64e5
     txenable = R300_TEX_0_ENABLE;
f1d64e5
-- 
f1d64e5
1.7.4.4
f1d64e5