Port r200 tex tiling code to run on r300 but keep it disabled.
authorAapo Tahkola <aet@rasterburn.org>
Mon, 6 Mar 2006 19:28:10 +0000 (19:28 +0000)
committerAapo Tahkola <aet@rasterburn.org>
Mon, 6 Mar 2006 19:28:10 +0000 (19:28 +0000)
src/mesa/drivers/dri/r300/r300_context.c
src/mesa/drivers/dri/r300/r300_context.h
src/mesa/drivers/dri/r300/r300_texmem.c
src/mesa/drivers/dri/r300/r300_texstate.c

index 08293a00ae5736418482490ed3c19c4e61bfa0b5..46d64443c355593434193efa0c7786b169b08634 100644 (file)
@@ -76,6 +76,7 @@ int hw_tcl_on=1;
 #define need_GL_ARB_vertex_buffer_object
 #define need_GL_ARB_vertex_program
 #define need_GL_EXT_blend_minmax
+//#define need_GL_EXT_fog_coord
 #define need_GL_EXT_secondary_color
 #define need_GL_EXT_blend_equation_separate
 #define need_GL_EXT_blend_func_separate
@@ -100,6 +101,7 @@ const struct dri_extension card_extensions[] = {
   {"GL_EXT_blend_func_separate",       GL_EXT_blend_func_separate_functions},
   {"GL_EXT_blend_minmax",              GL_EXT_blend_minmax_functions},
   {"GL_EXT_blend_subtract",            NULL},
+//  {"GL_EXT_fog_coord",                       GL_EXT_fog_coord_functions },
   {"GL_EXT_secondary_color",           GL_EXT_secondary_color_functions},
   {"GL_EXT_stencil_wrap",              NULL},
   {"GL_EXT_texture_edge_clamp",                NULL},
@@ -189,6 +191,8 @@ GLboolean r300CreateContext(const __GLcontextModes * glVisual,
        driParseConfigFiles(&r300->radeon.optionCache, &screen->optionCache,
                            screen->driScreen->myNum, "r300");
 
+       //r300->texmicrotile = GL_TRUE;
+       
        /* Init default driver functions then plug in our R300-specific functions
         * (the texture functions are especially important)
         */
index 03c2e6612f34c6470399d6649c598c59492390a5..6aa3caf8de4e9e55e2f3044ac321605b7a68a457 100644 (file)
@@ -199,6 +199,8 @@ struct r300_tex_obj {
 
 
        GLboolean border_fallback;
+
+       GLuint tile_bits; /* hw texture tile bits used on this texture */
 };
 
 struct r300_texture_env_state {
@@ -884,6 +886,8 @@ struct r300_context {
        int mm_sem_id;
        struct radeon_memory_manager *rmm;
 #endif
+
+       GLboolean texmicrotile;
 };
 
 struct r300_buffer_object {
index f334880f27f47b288ddc05a7b986d53167c42524..d78ec3b12c70bad7ac740472286a2957cd6a3e30 100644 (file)
@@ -261,8 +261,11 @@ static void r300UploadRectSubImage(r300ContextPtr rmesa,
                        r300EmitBlit(rmesa,
                                     blit_format,
                                     dstPitch, GET_START(&region),
-                                    dstPitch, t->bufAddr,
-                                    0, 0, 0, done, width, lines);
+                                    dstPitch | (t->tile_bits >> 16),
+                                    t->bufAddr,
+                                    0, 0,
+                                    0, done,
+                                    width, lines);
 
                        r300EmitWait(rmesa, R300_WAIT_2D);
 
@@ -390,8 +393,8 @@ static void uploadSubImage( r300ContextPtr rmesa, r300TexObjPtr t,
       tex.pitch = MAX2((texImage->Width * texImage->TexFormat->TexelBytes) / 64, 1);
       tex.offset += tmp.x & ~1023;
       tmp.x = tmp.x % 1024;
-#if 0
-      if (t->tile_bits & R200_TXO_MICRO_TILE) {
+#if 1
+      if (t->tile_bits & R300_TXO_MICRO_TILE) {
         /* need something like "tiled coordinates" ? */
         tmp.y = tmp.x / (tex.pitch * 128) * 2;
         tmp.x = tmp.x % (tex.pitch * 128) / 2 / texImage->TexFormat->TexelBytes;
@@ -402,10 +405,10 @@ static void uploadSubImage( r300ContextPtr rmesa, r300TexObjPtr t,
       {
         tmp.x = tmp.x >> (texImage->TexFormat->TexelBytes >> 1);
       }
-#if 0
-      if ((t->tile_bits & R200_TXO_MACRO_TILE) &&
+#if 1
+      if ((t->tile_bits & R300_TXO_MACRO_TILE) &&
         (texImage->Width * texImage->TexFormat->TexelBytes >= 256) &&
-        ((!(t->tile_bits & R200_TXO_MICRO_TILE) && (texImage->Height >= 8)) ||
+        ((!(t->tile_bits & R300_TXO_MICRO_TILE) && (texImage->Height >= 8)) ||
            (texImage->Height >= 16))) {
         /* weird: R200 disables macro tiling if mip width is smaller than 256 bytes,
            OR if height is smaller than 8 automatically, but if micro tiling is active
@@ -502,6 +505,11 @@ int r300UploadTexImages(r300ContextPtr rmesa, r300TexObjPtr t, GLuint face)
                    + t->base.memBlock->ofs;
                t->offset = t->bufAddr;
 
+               if (!(t->base.tObj->Image[0][0]->IsClientData)) {
+                       /* hope it's safe to add that here... */
+                       t->offset |= t->tile_bits;
+               }
+
                /* Mark this texobj as dirty on all units:
                 */
                t->dirty_state = TEX_ALL;
index ca42afdc1fd886ace1e6722f0f1572b9a84d1061..32f87d2d95e95f958bc874e26b46ff6bed032ccf 100644 (file)
@@ -214,6 +214,31 @@ static void r300SetTexImages(r300ContextPtr rmesa,
         */
        curOffset = 0;
        blitWidth = BLIT_WIDTH_BYTES;
+       t->tile_bits = 0;
+
+       /* figure out if this texture is suitable for tiling. */
+#if 0 /* Disabled for now */
+       if (texelBytes) {
+               if (rmesa->texmicrotile  && (tObj->Target != GL_TEXTURE_RECTANGLE_NV) &&
+                  /* texrect might be able to use micro tiling too in theory? */
+                  (baseImage->Height > 1)) {
+                       
+                       /* allow 32 (bytes) x 1 mip (which will use two times the space
+                          the non-tiled version would use) max if base texture is large enough */
+                       if ((numLevels == 1) ||
+                               (((baseImage->Width * texelBytes / baseImage->Height) <= 32) &&
+                               (baseImage->Width * texelBytes > 64)) ||
+                               ((baseImage->Width * texelBytes / baseImage->Height) <= 16)) {
+                               t->tile_bits |= R300_TXO_MICRO_TILE;
+                       }
+               }
+               
+               if (tObj->Target != GL_TEXTURE_RECTANGLE_NV) {
+                       /* we can set macro tiling even for small textures, they will be untiled anyway */
+                       t->tile_bits |= R300_TXO_MACRO_TILE;
+               }
+       }
+#endif
 
        for (i = 0; i < numLevels; i++) {
          const struct gl_texture_image *texImage;
@@ -244,6 +269,13 @@ static void r300SetTexImages(r300ContextPtr rmesa,
          } else if (tObj->Target == GL_TEXTURE_RECTANGLE_NV) {
            size = ((texImage->Width * texelBytes + 63) & ~63) * texImage->Height;
            blitWidth = 64 / texelBytes;
+         } else if (t->tile_bits & R300_TXO_MICRO_TILE) {
+               /* tile pattern is 16 bytes x2. mipmaps stay 32 byte aligned,
+                  though the actual offset may be different (if texture is less than
+                  32 bytes width) to the untiled case */
+               int w = (texImage->Width * texelBytes * 2 + 31) & ~31;
+               size = (w * ((texImage->Height + 1) / 2)) * texImage->Depth;
+               blitWidth = MAX2(texImage->Width, 64 / texelBytes);
          } else {
            int w = (texImage->Width * texelBytes + 31) & ~31;
            size = w * texImage->Height * texImage->Depth;