Mesa (master): r300g: move ZTOP to separate file

Marek Olšák mareko at kemper.freedesktop.org
Tue Apr 27 23:07:31 UTC 2010


Module: Mesa
Branch: master
Commit: 20c96759940b0bbe5afdb592cda1c410bfa6e665
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=20c96759940b0bbe5afdb592cda1c410bfa6e665

Author: Marek Olšák <maraeo at gmail.com>
Date:   Sun Apr 18 05:10:43 2010 +0200

r300g: move ZTOP to separate file

Ideally, HiZ should go in r300_hyperz.c next to ZTOP.

---

 src/gallium/drivers/r300/Makefile             |    1 +
 src/gallium/drivers/r300/SConscript           |    1 +
 src/gallium/drivers/r300/r300_emit.c          |    1 -
 src/gallium/drivers/r300/r300_hyperz.c        |  108 +++++++++++++++++++++++++
 src/gallium/drivers/r300/r300_hyperz.h        |   30 +++++++
 src/gallium/drivers/r300/r300_state_derived.c |   74 +----------------
 6 files changed, 142 insertions(+), 73 deletions(-)

diff --git a/src/gallium/drivers/r300/Makefile b/src/gallium/drivers/r300/Makefile
index 5a8e00f..d3cd6be 100644
--- a/src/gallium/drivers/r300/Makefile
+++ b/src/gallium/drivers/r300/Makefile
@@ -11,6 +11,7 @@ C_SOURCES = \
 	r300_emit.c \
 	r300_flush.c \
 	r300_fs.c \
+	r300_hyperz.c \
 	r300_query.c \
 	r300_render.c \
 	r300_resource.c \
diff --git a/src/gallium/drivers/r300/SConscript b/src/gallium/drivers/r300/SConscript
index 08aec42..3921085 100644
--- a/src/gallium/drivers/r300/SConscript
+++ b/src/gallium/drivers/r300/SConscript
@@ -21,6 +21,7 @@ r300 = env.ConvenienceLibrary(
         'r300_emit.c',
         'r300_flush.c',
         'r300_fs.c',
+        'r300_hyperz.c',
         'r300_query.c',
         'r300_render.c',
         'r300_resource.c',
diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c
index 0353b90..92b7517 100644
--- a/src/gallium/drivers/r300/r300_emit.c
+++ b/src/gallium/drivers/r300/r300_emit.c
@@ -100,7 +100,6 @@ void r300_emit_clip_state(struct r300_context* r300,
         OUT_CS_REG(R300_VAP_CLIP_CNTL, R300_CLIP_DISABLE);
         END_CS;
     }
-
 }
 
 void r300_emit_dsa_state(struct r300_context* r300, unsigned size, void* state)
diff --git a/src/gallium/drivers/r300/r300_hyperz.c b/src/gallium/drivers/r300/r300_hyperz.c
new file mode 100644
index 0000000..b41b6b1
--- /dev/null
+++ b/src/gallium/drivers/r300/r300_hyperz.c
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2008 Corbin Simpson <MostAwesomeDude at gmail.com>
+ * Copyright 2009 Marek Olšák <maraeo at gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+
+#include "r300_hyperz.h"
+#include "r300_context.h"
+#include "r300_reg.h"
+#include "r300_fs.h"
+
+/*****************************************************************************/
+/* The ZTOP state                                                            */
+/*****************************************************************************/
+
+static boolean r300_dsa_writes_depth_stencil(struct r300_dsa_state* dsa)
+{
+    /* We are interested only in the cases when a new depth or stencil value
+     * can be written and changed. */
+
+    /* We might optionally check for [Z func: never] and inspect the stencil
+     * state in a similar fashion, but it's not terribly important. */
+    return (dsa->z_buffer_control & R300_Z_WRITE_ENABLE) ||
+           (dsa->stencil_ref_mask & R300_STENCILWRITEMASK_MASK) ||
+           ((dsa->z_buffer_control & R500_STENCIL_REFMASK_FRONT_BACK) &&
+            (dsa->stencil_ref_bf & R300_STENCILWRITEMASK_MASK));
+}
+
+static boolean r300_dsa_alpha_test_enabled(struct r300_dsa_state* dsa)
+{
+    /* We are interested only in the cases when alpha testing can kill
+     * a fragment. */
+    uint32_t af = dsa->alpha_function;
+
+    return (af & R300_FG_ALPHA_FUNC_ENABLE) &&
+           (af & R300_FG_ALPHA_FUNC_ALWAYS) != R300_FG_ALPHA_FUNC_ALWAYS;
+}
+
+static void r300_update_ztop(struct r300_context* r300)
+{
+    struct r300_ztop_state* ztop_state =
+        (struct r300_ztop_state*)r300->ztop_state.state;
+
+    /* 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.
+     *
+     * (3) will never apply since we do not support chroma-keyed operations.
+     * (4) will need to be re-examined (and this comment updated) if/when
+     * Hyper-Z becomes supported.
+     *
+     * Additionally, the following conditions require disabled ZTOP:
+     * 5) Depth writes in fragment shader
+     * 6) Outstanding occlusion queries
+     *
+     * This register causes stalls all the way from SC to CB when changed,
+     * but it is buffered on-chip so it does not hurt to write it if it has
+     * not changed.
+     *
+     * ~C.
+     */
+
+    /* ZS writes */
+    if (r300_dsa_writes_depth_stencil(r300->dsa_state.state) &&
+           (r300_dsa_alpha_test_enabled(r300->dsa_state.state) ||  /* (1) */
+            r300_fs(r300)->shader->info.uses_kill)) {              /* (2) */
+        ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
+    } else if (r300_fragment_shader_writes_depth(r300_fs(r300))) { /* (5) */
+        ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
+    } else if (r300->query_current) {                              /* (6) */
+        ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
+    } else {
+        ztop_state->z_buffer_top = R300_ZTOP_ENABLE;
+    }
+
+    r300->ztop_state.dirty = TRUE;
+}
+
+void r300_update_hyperz_state(struct r300_context* r300)
+{
+    r300_update_ztop(r300);
+}
diff --git a/src/gallium/drivers/r300/r300_hyperz.h b/src/gallium/drivers/r300/r300_hyperz.h
new file mode 100644
index 0000000..3df5053
--- /dev/null
+++ b/src/gallium/drivers/r300/r300_hyperz.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2010 Marek Olšák <maraeo at gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE. */
+
+#ifndef R300_HYPERZ_H
+#define R300_HYPERZ_H
+
+struct r300_context;
+
+void r300_update_hyperz_state(struct r300_context* r300);
+
+#endif
diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c
index 46c192e..10ea579 100644
--- a/src/gallium/drivers/r300/r300_state_derived.c
+++ b/src/gallium/drivers/r300/r300_state_derived.c
@@ -28,6 +28,7 @@
 
 #include "r300_context.h"
 #include "r300_fs.h"
+#include "r300_hyperz.h"
 #include "r300_screen.h"
 #include "r300_shader_semantics.h"
 #include "r300_state.h"
@@ -402,77 +403,6 @@ static void r300_update_derived_shader_state(struct r300_context* r300)
     r300_update_rs_block(r300, &vs->outputs, &r300_fs(r300)->shader->inputs);
 }
 
-static boolean r300_dsa_writes_depth_stencil(struct r300_dsa_state* dsa)
-{
-    /* We are interested only in the cases when a new depth or stencil value
-     * can be written and changed. */
-
-    /* We might optionally check for [Z func: never] and inspect the stencil
-     * state in a similar fashion, but it's not terribly important. */
-    return (dsa->z_buffer_control & R300_Z_WRITE_ENABLE) ||
-           (dsa->stencil_ref_mask & R300_STENCILWRITEMASK_MASK) ||
-           ((dsa->z_buffer_control & R500_STENCIL_REFMASK_FRONT_BACK) &&
-            (dsa->stencil_ref_bf & R300_STENCILWRITEMASK_MASK));
-}
-
-static boolean r300_dsa_alpha_test_enabled(struct r300_dsa_state* dsa)
-{
-    /* We are interested only in the cases when alpha testing can kill
-     * a fragment. */
-    uint32_t af = dsa->alpha_function;
-
-    return (af & R300_FG_ALPHA_FUNC_ENABLE) &&
-           (af & R300_FG_ALPHA_FUNC_ALWAYS) != R300_FG_ALPHA_FUNC_ALWAYS;
-}
-
-static void r300_update_ztop(struct r300_context* r300)
-{
-    struct r300_ztop_state* ztop_state =
-        (struct r300_ztop_state*)r300->ztop_state.state;
-
-    /* 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.
-     *
-     * (3) will never apply since we do not support chroma-keyed operations.
-     * (4) will need to be re-examined (and this comment updated) if/when
-     * Hyper-Z becomes supported.
-     *
-     * Additionally, the following conditions require disabled ZTOP:
-     * 5) Depth writes in fragment shader
-     * 6) Outstanding occlusion queries
-     *
-     * This register causes stalls all the way from SC to CB when changed,
-     * but it is buffered on-chip so it does not hurt to write it if it has
-     * not changed.
-     *
-     * ~C.
-     */
-
-    /* ZS writes */
-    if (r300_dsa_writes_depth_stencil(r300->dsa_state.state) &&
-           (r300_dsa_alpha_test_enabled(r300->dsa_state.state) ||  /* (1) */
-            r300_fs(r300)->shader->info.uses_kill)) {              /* (2) */
-        ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
-    } else if (r300_fragment_shader_writes_depth(r300_fs(r300))) { /* (5) */
-        ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
-    } else if (r300->query_current) {                              /* (6) */
-        ztop_state->z_buffer_top = R300_ZTOP_DISABLE;
-    } else {
-        ztop_state->z_buffer_top = R300_ZTOP_ENABLE;
-    }
-
-    r300->ztop_state.dirty = TRUE;
-}
-
 static void r300_merge_textures_and_samplers(struct r300_context* r300)
 {
     struct r300_textures_state *state =
@@ -578,5 +508,5 @@ void r300_update_derived_state(struct r300_context* r300)
         r300_swtcl_vertex_psc(r300);
     }
 
-    r300_update_ztop(r300);
+    r300_update_hyperz_state(r300);
 }




More information about the mesa-commit mailing list