2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
25 #include "r300_hyperz.h"
26 #include "r300_context.h"
30 /*****************************************************************************/
32 /*****************************************************************************/
34 static boolean
r300_dsa_writes_stencil(
35 struct pipe_stencil_state
*s
)
37 return s
->enabled
&& s
->writemask
&&
38 (s
->fail_op
!= PIPE_STENCIL_OP_KEEP
||
39 s
->zfail_op
!= PIPE_STENCIL_OP_KEEP
||
40 s
->zpass_op
!= PIPE_STENCIL_OP_KEEP
);
43 static boolean
r300_dsa_writes_depth_stencil(
44 struct pipe_depth_stencil_alpha_state
*dsa
)
46 /* We are interested only in the cases when a depth or stencil value
49 if (dsa
->depth
.enabled
&& dsa
->depth
.writemask
&&
50 dsa
->depth
.func
!= PIPE_FUNC_NEVER
)
53 if (r300_dsa_writes_stencil(&dsa
->stencil
[0]) ||
54 r300_dsa_writes_stencil(&dsa
->stencil
[1]))
60 static boolean
r300_dsa_alpha_test_enabled(
61 struct pipe_depth_stencil_alpha_state
*dsa
)
63 /* We are interested only in the cases when alpha testing can kill
66 return dsa
->alpha
.enabled
&& dsa
->alpha
.func
!= PIPE_FUNC_ALWAYS
;
69 static void r300_update_ztop(struct r300_context
* r300
)
71 struct r300_ztop_state
* ztop_state
=
72 (struct r300_ztop_state
*)r300
->ztop_state
.state
;
73 uint32_t old_ztop
= ztop_state
->z_buffer_top
;
75 /* This is important enough that I felt it warranted a comment.
77 * According to the docs, these are the conditions where ZTOP must be
79 * 1) Alpha testing enabled
80 * 2) Texture kill instructions in fragment shader
81 * 3) Chroma key culling enabled
82 * 4) W-buffering enabled
84 * The docs claim that for the first three cases, if no ZS writes happen,
85 * then ZTOP can be used.
87 * (3) will never apply since we do not support chroma-keyed operations.
88 * (4) will need to be re-examined (and this comment updated) if/when
89 * Hyper-Z becomes supported.
91 * Additionally, the following conditions require disabled ZTOP:
92 * 5) Depth writes in fragment shader
93 * 6) Outstanding occlusion queries
95 * This register causes stalls all the way from SC to CB when changed,
96 * but it is buffered on-chip so it does not hurt to write it if it has
103 if (r300_dsa_writes_depth_stencil(r300
->dsa_state
.state
) &&
104 (r300_dsa_alpha_test_enabled(r300
->dsa_state
.state
) || /* (1) */
105 r300_fs(r300
)->shader
->info
.uses_kill
)) { /* (2) */
106 ztop_state
->z_buffer_top
= R300_ZTOP_DISABLE
;
107 } else if (r300_fragment_shader_writes_depth(r300_fs(r300
))) { /* (5) */
108 ztop_state
->z_buffer_top
= R300_ZTOP_DISABLE
;
109 } else if (r300
->query_current
) { /* (6) */
110 ztop_state
->z_buffer_top
= R300_ZTOP_DISABLE
;
112 ztop_state
->z_buffer_top
= R300_ZTOP_ENABLE
;
115 if (ztop_state
->z_buffer_top
!= old_ztop
)
116 r300
->ztop_state
.dirty
= TRUE
;
119 void r300_update_hyperz_state(struct r300_context
* r300
)
121 r300_update_ztop(r300
);