r300g: do not use HiZ if HiZ RAM is not properly initialized
authorMarek Olšák <maraeo@gmail.com>
Sun, 15 Aug 2010 01:14:25 +0000 (03:14 +0200)
committerMarek Olšák <maraeo@gmail.com>
Sun, 15 Aug 2010 06:07:11 +0000 (08:07 +0200)
src/gallium/drivers/r300/r300_blit.c
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_hyperz.c
src/gallium/drivers/r300/r300_state.c

index 29393109fac175a6c6660a10b5cb59bf600a9b0f..559936cec68c178a23e9dc62057a6a5a1d3d2152 100644 (file)
@@ -172,6 +172,8 @@ static void r300_clear(struct pipe_context* pipe,
         (struct pipe_framebuffer_state*)r300->fb_state.state;
     struct r300_hyperz_state *hyperz =
         (struct r300_hyperz_state*)r300->hyperz_state.state;
+    struct r300_texture *zstex =
+            fb->zsbuf ? r300_texture(fb->zsbuf->texture) : NULL;
     uint32_t width = fb->width;
     uint32_t height = fb->height;
     boolean has_hyperz = r300->rws->get_value(r300->rws, R300_CAN_HYPERZ);
@@ -184,11 +186,11 @@ static void r300_clear(struct pipe_context* pipe,
             r300_depth_clear_value(fb->zsbuf->format, depth, stencil);
 
         r300_mark_fb_state_dirty(r300, R300_CHANGED_ZCLEAR_FLAG);
-        if (r300_texture(fb->zsbuf->texture)->zmask_mem[fb->zsbuf->level]) {
+        if (zstex->zmask_mem[fb->zsbuf->level]) {
             r300->zmask_clear.dirty = TRUE;
             buffers &= ~PIPE_CLEAR_DEPTHSTENCIL;
         }
-        if (r300->hiz_enable)
+        if (zstex->hiz_mem[fb->zsbuf->level])
             r300->hiz_clear.dirty = TRUE;
     }
 
@@ -249,12 +251,13 @@ static void r300_clear(struct pipe_context* pipe,
         r300_mark_fb_state_dirty(r300, R300_CHANGED_CBZB_FLAG);
     }
 
-    /* Enable fastfill.
+    /* Enable fastfill and/or hiz.
      *
-     * If we cleared the zmask, it's in use now. The Hyper-Z state update
-     * looks if zmask is in use and enables fastfill accordingly. */
-    if (fb->zsbuf &&
-        r300_texture(fb->zsbuf->texture)->zmask_in_use[fb->zsbuf->level]) {
+     * If we cleared zmask/hiz, it's in use now. The Hyper-Z state update
+     * looks if zmask/hiz is in use and enables fastfill accordingly. */
+    if (zstex &&
+        (zstex->zmask_in_use[fb->zsbuf->level] ||
+         zstex->hiz_in_use[fb->zsbuf->level])) {
         r300->hyperz_state.dirty = TRUE;
     }
 
index 6c4c396982fdce50e81598e6a1cc87ca15afe9f4..6fa7f470f986e0f51a975eed42214891ee6738ca 100644 (file)
@@ -398,6 +398,7 @@ struct r300_texture {
     struct mem_block *hiz_mem[R300_MAX_TEXTURE_LEVELS];
     struct mem_block *zmask_mem[R300_MAX_TEXTURE_LEVELS];
     boolean zmask_in_use[R300_MAX_TEXTURE_LEVELS];
+    boolean hiz_in_use[R300_MAX_TEXTURE_LEVELS];
 
     /* This is the level tiling flags were last time set for.
      * It's used to prevent redundant tiling-flags changes from happening.*/
@@ -568,7 +569,6 @@ struct r300_context {
 #define R300_Z_COMPRESS_44 1
 #define RV350_Z_COMPRESS_88 2
     int z_compression;
-    boolean hiz_enable;
     boolean cbzb_clear;
     boolean z_decomp_rd;
 
index fe334c924e4e9b4694f9154673695ea185d72975..d0fd45349e3b37cc513113c29700592a865d203c 100644 (file)
@@ -1046,6 +1046,9 @@ void r300_emit_hiz_clear(struct r300_context *r300, unsigned size, void *state)
         r300_emit_hiz_line_clear(r300, offset, stride, 0xffffffff);
     }
     z->current_func = -1;
+
+    /* Mark the current zbuffer's hiz ram as in use. */
+    tex->hiz_in_use[fb->zsbuf->level] = TRUE;
 }
 
 void r300_emit_zmask_clear(struct r300_context *r300, unsigned size, void *state)
index 9cce195eb46ac495b638e9ec94e36a3c6c9cda85..811b5646e163ab8c2eb138c78f6ae2bb0a81eb3e 100644 (file)
@@ -131,7 +131,10 @@ static void r300_update_hyperz(struct r300_context* r300)
         (struct r300_hyperz_state*)r300->hyperz_state.state;
     struct pipe_framebuffer_state *fb =
         (struct pipe_framebuffer_state*)r300->fb_state.state;
+    struct r300_texture *zstex =
+            fb->zsbuf ? r300_texture(fb->zsbuf->texture) : NULL;
     boolean zmask_in_use = FALSE;
+    boolean hiz_in_use = FALSE;
 
     z->gb_z_peq_config = 0;
     z->zb_bw_cntl = 0;
@@ -143,13 +146,14 @@ static void r300_update_hyperz(struct r300_context* r300)
         return;
     }
 
-    if (!fb->zsbuf)
+    if (!zstex)
         return;
 
     if (!r300->rws->get_value(r300->rws, R300_CAN_HYPERZ))
         return;
 
-    zmask_in_use = r300_texture(fb->zsbuf->texture)->zmask_in_use[fb->zsbuf->level];
+    zmask_in_use = zstex->zmask_in_use[fb->zsbuf->level];
+    hiz_in_use = zstex->hiz_in_use[fb->zsbuf->level];
 
     /* Z fastfill. */
     if (zmask_in_use) {
@@ -167,7 +171,7 @@ static void r300_update_hyperz(struct r300_context* r300)
     if (r300->z_compression == RV350_Z_COMPRESS_88)
         z->gb_z_peq_config |= R300_GB_Z_PEQ_CONFIG_Z_PEQ_SIZE_8_8;
 
-    if (r300->hiz_enable) {
+    if (hiz_in_use) {
         bool can_hiz = r300_can_hiz(r300);
         if (can_hiz) {
             z->zb_bw_cntl |= R300_HIZ_ENABLE;
@@ -177,8 +181,8 @@ static void r300_update_hyperz(struct r300_context* r300)
         }
     }
 
+    /* R500-specific features and optimizations. */
     if (r300->screen->caps.is_r500) {
-        /* XXX Are these bits really available on RV350? */
         z->zb_bw_cntl |= R500_HIZ_FP_EXP_BITS_3;
         z->zb_bw_cntl |=
                 R500_HIZ_EQUAL_REJECT_ENABLE |
index 9afaa5f6516d5ad8467b20b4569c1c243b8f420d..239edd98e320d34f7a19ebe4a2b83a645eea12aa 100644 (file)
@@ -752,7 +752,6 @@ static void
 
     r300_mark_fb_state_dirty(r300, R300_CHANGED_FB_STATE);
 
-    r300->hiz_enable = false;
     r300->z_compression = false;
     
     if (state->zsbuf) {
@@ -779,17 +778,13 @@ static void
             /* work out whether we can support zmask features on this buffer */
             r300_zmask_alloc_block(r300, zs_surf, compress);
 
-            if (tex->hiz_mem[level]) {
-                r300->hiz_enable = 1;
-            }
-
             if (tex->zmask_mem[level]) {
                 /* compression causes hangs on 16-bit */
                 if (zbuffer_bpp == 24)
                     r300->z_compression = compress;
             }
             DBG(r300, DBG_HYPERZ,
-                "hyper-z features: hiz: %d @ %08x z-compression: %d z-fastfill: %d @ %08x\n", r300->hiz_enable,
+                "hyper-z features: hiz: %d @ %08x z-compression: %d z-fastfill: %d @ %08x\n", tex->hiz_mem[level] ? 1 : 0,
                 tex->hiz_mem[level] ? tex->hiz_mem[level]->ofs : 0xdeadbeef,
                 r300->z_compression, tex->zmask_mem[level] ? 1 : 0,
                 tex->zmask_mem[level] ? tex->zmask_mem[level]->ofs : 0xdeadbeef);