r300/compiler: Fix error in OMOD optimization
[mesa.git] / src / gallium / drivers / r300 / r300_blit.c
index 95a43fe675245c6ac8b02525e8eb1fb30ac2b05e..3c1b3648a24e91ea5d190ded3c7c568a1baa4ec6 100644 (file)
 
 enum r300_blitter_op /* bitmask */
 {
-    R300_CLEAR         = 1,
-    R300_CLEAR_SURFACE = 2,
-    R300_COPY          = 4
+    R300_STOP_QUERY         = 1,
+    R300_SAVE_TEXTURES      = 2,
+    R300_SAVE_FRAMEBUFFER   = 4,
+    R300_IGNORE_RENDER_COND = 8,
+
+    R300_CLEAR         = R300_STOP_QUERY,
+
+    R300_CLEAR_SURFACE = R300_STOP_QUERY | R300_SAVE_FRAMEBUFFER,
+
+    R300_COPY          = R300_STOP_QUERY | R300_SAVE_FRAMEBUFFER |
+                         R300_SAVE_TEXTURES | R300_IGNORE_RENDER_COND,
+
+    R300_DECOMPRESS    = R300_STOP_QUERY | R300_IGNORE_RENDER_COND,
 };
 
 static void r300_blitter_begin(struct r300_context* r300, enum r300_blitter_op op)
 {
-    if (r300->query_current) {
+    if ((op & R300_STOP_QUERY) && r300->query_current) {
         r300->blitter_saved_query = r300->query_current;
         r300_stop_query(r300);
     }
@@ -57,11 +67,11 @@ static void r300_blitter_begin(struct r300_context* r300, enum r300_blitter_op o
     util_blitter_save_vertex_buffers(r300->blitter, r300->vbuf_mgr->nr_vertex_buffers,
                                      r300->vbuf_mgr->vertex_buffer);
 
-    if (op & (R300_CLEAR_SURFACE | R300_COPY)) {
+    if (op & R300_SAVE_FRAMEBUFFER) {
         util_blitter_save_framebuffer(r300->blitter, r300->fb_state.state);
     }
 
-    if (op & R300_COPY) {
+    if (op & R300_SAVE_TEXTURES) {
         struct r300_textures_state* state =
             (struct r300_textures_state*)r300->textures_state.state;
 
@@ -73,6 +83,14 @@ static void r300_blitter_begin(struct r300_context* r300, enum r300_blitter_op o
             r300->blitter, state->sampler_view_count,
             (struct pipe_sampler_view**)state->sampler_views);
     }
+
+    if (op & R300_IGNORE_RENDER_COND) {
+        /* Save the flag. */
+        r300->blitter_saved_skip_rendering = r300->skip_rendering+1;
+        r300->skip_rendering = FALSE;
+    } else {
+        r300->blitter_saved_skip_rendering = 0;
+    }
 }
 
 static void r300_blitter_end(struct r300_context *r300)
@@ -81,6 +99,11 @@ static void r300_blitter_end(struct r300_context *r300)
         r300_resume_query(r300, r300->blitter_saved_query);
         r300->blitter_saved_query = NULL;
     }
+
+    if (r300->blitter_saved_skip_rendering) {
+        /* Restore the flag. */
+        r300->skip_rendering = r300->blitter_saved_skip_rendering-1;
+    }
 }
 
 static uint32_t r300_depth_clear_cb_value(enum pipe_format format,
@@ -113,7 +136,7 @@ static boolean r300_fast_zclear_allowed(struct r300_context *r300)
     struct pipe_framebuffer_state *fb =
         (struct pipe_framebuffer_state*)r300->fb_state.state;
 
-    return r300_resource(fb->zsbuf->texture)->tex.zmask_dwords[fb->zsbuf->u.tex.level];
+    return r300_resource(fb->zsbuf->texture)->tex.zmask_dwords[fb->zsbuf->u.tex.level] != 0;
 }
 
 static boolean r300_hiz_clear_allowed(struct r300_context *r300)
@@ -121,7 +144,7 @@ static boolean r300_hiz_clear_allowed(struct r300_context *r300)
     struct pipe_framebuffer_state *fb =
         (struct pipe_framebuffer_state*)r300->fb_state.state;
 
-    return r300_resource(fb->zsbuf->texture)->tex.hiz_dwords[fb->zsbuf->u.tex.level];
+    return r300_resource(fb->zsbuf->texture)->tex.hiz_dwords[fb->zsbuf->u.tex.level] != 0;
 }
 
 static uint32_t r300_depth_clear_value(enum pipe_format format,
@@ -151,7 +174,7 @@ static uint32_t r300_hiz_clear_value(double depth)
 /* Clear currently bound buffers. */
 static void r300_clear(struct pipe_context* pipe,
                        unsigned buffers,
-                       const float* rgba,
+                       const union pipe_color_union *color,
                        double depth,
                        unsigned stencil)
 {
@@ -206,23 +229,50 @@ static void r300_clear(struct pipe_context* pipe,
         (struct r300_hyperz_state*)r300->hyperz_state.state;
     uint32_t width = fb->width;
     uint32_t height = fb->height;
-    boolean can_hyperz = r300->rws->get_value(r300->rws, RADEON_VID_CAN_HYPERZ);
     uint32_t hyperz_dcv = hyperz->zb_depthclearvalue;
 
     /* Enable fast Z clear.
      * The zbuffer must be in micro-tiled mode, otherwise it locks up. */
-    if ((buffers & PIPE_CLEAR_DEPTHSTENCIL) && can_hyperz) {
-        if (r300_fast_zclear_allowed(r300)) {
-            hyperz_dcv = hyperz->zb_depthclearvalue =
-                r300_depth_clear_value(fb->zsbuf->format, depth, stencil);
-
-            r300_mark_atom_dirty(r300, &r300->zmask_clear);
-            buffers &= ~PIPE_CLEAR_DEPTHSTENCIL;
-        }
-
-        if (r300_hiz_clear_allowed(r300)) {
-            r300->hiz_clear_value = r300_hiz_clear_value(depth);
-            r300_mark_atom_dirty(r300, &r300->hiz_clear);
+    if (buffers & PIPE_CLEAR_DEPTHSTENCIL) {
+        boolean zmask_clear, hiz_clear;
+
+        zmask_clear = r300_fast_zclear_allowed(r300);
+        hiz_clear = r300_hiz_clear_allowed(r300);
+
+        /* If we need Hyper-Z. */
+        if (zmask_clear || hiz_clear) {
+            r300->num_z_clears++;
+
+            /* Try to obtain the access to Hyper-Z buffers if we don't have one. */
+            if (!r300->hyperz_enabled) {
+                r300->hyperz_enabled =
+                    r300->rws->cs_request_feature(r300->cs,
+                                                RADEON_FID_R300_HYPERZ_ACCESS,
+                                                TRUE);
+                if (r300->hyperz_enabled) {
+                   /* Need to emit HyperZ buffer regs for the first time. */
+                   r300_mark_fb_state_dirty(r300, R300_CHANGED_HYPERZ_FLAG);
+                }
+            }
+
+            /* Setup Hyper-Z clears. */
+            if (r300->hyperz_enabled) {
+                DBG(r300, DBG_HYPERZ, "r300: Clear memory: %s%s\n",
+                    zmask_clear ? "ZMASK " : "", hiz_clear ? "HIZ" : "");
+
+                if (zmask_clear) {
+                    hyperz_dcv = hyperz->zb_depthclearvalue =
+                        r300_depth_clear_value(fb->zsbuf->format, depth, stencil);
+
+                    r300_mark_atom_dirty(r300, &r300->zmask_clear);
+                    buffers &= ~PIPE_CLEAR_DEPTHSTENCIL;
+                }
+
+                if (hiz_clear) {
+                    r300->hiz_clear_value = r300_hiz_clear_value(depth);
+                    r300_mark_atom_dirty(r300, &r300->hiz_clear);
+                }
+            }
         }
     }
 
@@ -231,7 +281,7 @@ static void r300_clear(struct pipe_context* pipe,
         struct r300_surface *surf = r300_surface(fb->cbufs[0]);
 
         hyperz->zb_depthclearvalue =
-                r300_depth_clear_cb_value(surf->base.format, rgba);
+                r300_depth_clear_cb_value(surf->base.format, color->f);
 
         width = surf->cbzb_width;
         height = surf->cbzb_height;
@@ -248,7 +298,7 @@ static void r300_clear(struct pipe_context* pipe,
                            width,
                            height,
                            fb->nr_cbufs,
-                           buffers, rgba, depth, stencil);
+                           buffers, color, depth, stencil);
         r300_blitter_end(r300);
     } else if (r300->zmask_clear.dirty || r300->hiz_clear.dirty) {
         /* Just clear zmask and hiz now, this does not use the standard draw
@@ -298,14 +348,14 @@ static void r300_clear(struct pipe_context* pipe,
 /* Clear a region of a color surface to a constant value. */
 static void r300_clear_render_target(struct pipe_context *pipe,
                                      struct pipe_surface *dst,
-                                     const float *rgba,
+                                     const union pipe_color_union *color,
                                      unsigned dstx, unsigned dsty,
                                      unsigned width, unsigned height)
 {
     struct r300_context *r300 = r300_context(pipe);
 
     r300_blitter_begin(r300, R300_CLEAR_SURFACE);
-    util_blitter_clear_render_target(r300->blitter, dst, rgba,
+    util_blitter_clear_render_target(r300->blitter, dst, color,
                                      dstx, dsty, width, height);
     r300_blitter_end(r300);
 }
@@ -347,7 +397,7 @@ void r300_decompress_zmask(struct r300_context *r300)
     r300->zmask_decompress = TRUE;
     r300_mark_atom_dirty(r300, &r300->hyperz_state);
 
-    r300_blitter_begin(r300, R300_CLEAR);
+    r300_blitter_begin(r300, R300_DECOMPRESS);
     util_blitter_clear_depth_custom(r300->blitter, fb->width, fb->height, 0,
                                     r300->dsa_decompress_zmask);
     r300_blitter_end(r300);
@@ -359,10 +409,11 @@ void r300_decompress_zmask(struct r300_context *r300)
 
 void r300_decompress_zmask_locked_unsafe(struct r300_context *r300)
 {
-    struct pipe_framebuffer_state fb = {0};
+    struct pipe_framebuffer_state fb;
+
+    memset(&fb, 0, sizeof(fb));
     fb.width = r300->locked_zbuffer->width;
     fb.height = r300->locked_zbuffer->height;
-    fb.nr_cbufs = 0;
     fb.zsbuf = r300->locked_zbuffer;
 
     r300->context.set_framebuffer_state(&r300->context, &fb);
@@ -371,8 +422,9 @@ void r300_decompress_zmask_locked_unsafe(struct r300_context *r300)
 
 void r300_decompress_zmask_locked(struct r300_context *r300)
 {
-    struct pipe_framebuffer_state saved_fb = {0};
+    struct pipe_framebuffer_state saved_fb;
 
+    memset(&saved_fb, 0, sizeof(saved_fb));
     util_copy_framebuffer_state(&saved_fb, r300->fb_state.state);
     r300_decompress_zmask_locked_unsafe(r300);
     r300->context.set_framebuffer_state(&r300->context, &saved_fb);
@@ -393,8 +445,8 @@ static void r300_hw_copy_region(struct pipe_context* pipe,
     struct r300_context* r300 = r300_context(pipe);
 
     r300_blitter_begin(r300, R300_COPY);
-    util_blitter_copy_region(r300->blitter, dst, dst_level, dstx, dsty, dstz,
-                             src, src_level, src_box, TRUE);
+    util_blitter_copy_texture(r300->blitter, dst, dst_level, dstx, dsty, dstz,
+                              src, src_level, src_box, TRUE);
     r300_blitter_end(r300);
 }