r300g: Move ztop to derived state.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Wed, 14 Oct 2009 10:09:41 +0000 (03:09 -0700)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Wed, 14 Oct 2009 10:09:41 +0000 (03:09 -0700)
Need to get it into its own atom instead of piggybacking on DSA.

src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_state_derived.c

index 95e2943baa5298d19be99c5211b6ecd0c045000e..8359850966b5194835cc1224464f6157b9789a0c 100644 (file)
@@ -190,7 +190,6 @@ static void*
         r300_create_dsa_state(struct pipe_context* pipe,
                               const struct pipe_depth_stencil_alpha_state* state)
 {
-    struct r300_context* r300 = r300_context(pipe);
     struct r300_dsa_state* dsa = CALLOC_STRUCT(r300_dsa_state);
 
     /* Depth test setup. */
@@ -250,15 +249,6 @@ static void*
                                      0, 1023);
     }
 
-    dsa->z_buffer_top = R300_ZTOP_ENABLE;
-    /* XXX TODO: add frag prog rules for ztop disable */
-    if (r300_fragment_shader_writes_depth(r300->fs))
-       dsa->z_buffer_top = R300_ZTOP_DISABLE;
-    if (state->alpha.enabled && state->alpha.func != PIPE_FUNC_ALWAYS)
-       dsa->z_buffer_top = R300_ZTOP_DISABLE;
-    if (r300->query_current)
-       dsa->z_buffer_top = R300_ZTOP_DISABLE;
-
     return (void*)dsa;
 }
 
index 335b54820aaf34b176be3fe6901466d2bc6189aa..5d323a26b143090768fc07833a2b750bc24b60fd 100644 (file)
@@ -444,6 +444,37 @@ static void r300_update_rs_block(struct r300_context* r300)
     rs->inst_count = MAX2(MAX2(col_count - 1, tex_count - 1), 0);
 }
 
+static void r300_update_ztop(struct r300_context* r300)
+{
+    r300->dsa_state->z_buffer_top = R300_ZTOP_ENABLE;
+
+    /* This is important enough that I felt it warranted a comment.
+     *
+     * According to the docs, these are the conditions where ZTOP must be
+     * disabled:
+     * 1) Alpha testing enabled
+     * 2) Texture kill instructions in fragment shader
+     * 3) Chroma key culling enabled
+     * 4) W-buffering enabled
+     *
+     * The docs claim that for the first three cases, if no ZS writes happen,
+     * then ZTOP can be used.
+     *
+     * Additionally, the following conditions require disabled ZTOP:
+     * ~) Depth writes in fragment shader
+     * ~) Outstanding occlusion queries
+     *
+     * ~C.
+     */
+    if (r300->dsa_state->alpha_function) {
+        r300->dsa_state->z_buffer_top = R300_ZTOP_DISABLE;
+    } else if (r300_fragment_shader_writes_depth(r300->fs)) {
+        r300->dsa_state->z_buffer_top = R300_ZTOP_DISABLE;
+    } else if (r300->query_current) {
+        r300->dsa_state->z_buffer_top = R300_ZTOP_DISABLE;
+    }
+}
+
 void r300_update_derived_state(struct r300_context* r300)
 {
     if (r300->dirty_state &
@@ -455,4 +486,9 @@ void r300_update_derived_state(struct r300_context* r300)
         r300_update_fs_tab(r300);
         r300_update_rs_block(r300);
     }
+
+    if (r300->dirty_state &
+            (R300_NEW_DSA | R300_NEW_FRAGMENT_SHADER | R300_NEW_QUERY)) {
+        r300_update_ztop(r300);
+    }
 }