diff options
author | Marek Olšák <[email protected]> | 2011-06-10 19:00:50 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2011-06-10 19:45:45 +0200 |
commit | bbebbdd3e726b6faaa58b5e1d0044e2b9010969f (patch) | |
tree | 97a5ce2a860c0414b5c18c26aaed71fcd04b53a3 /src/gallium | |
parent | e5408efb20327c46fe67d35e18348ddd6300e282 (diff) |
r300g: fix occlusion queries when depth test is disabled or zbuffer is missing
From now on, depth test is always enabled in hardware.
If depth test is disabled in Gallium, the hardware Z function is set to ALWAYS.
If there is no zbuffer set, the colorbuffer0 memory is set as a zbuffer
to silence the CS checker.
This fixes piglit:
- occlusion-query-discard
- NV_conditional_render/bitmap
- NV_conditional_render/drawpixels
- NV_conditional_render/vertex_array
(cherry picked from commit f76787b3eae3f0b8af839fabfb24b57715a017f6)
Conflicts:
src/gallium/drivers/r300/r300_state.c
Squashed with cherry-picked b1246cf13bc4e301b499a95d33e0cab26655fed5.
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/drivers/r300/r300_emit.c | 17 | ||||
-rw-r--r-- | src/gallium/drivers/r300/r300_state.c | 16 |
2 files changed, 29 insertions, 4 deletions
diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c index 972f58f5f7b..01e63dd74b6 100644 --- a/src/gallium/drivers/r300/r300_emit.c +++ b/src/gallium/drivers/r300/r300_emit.c @@ -448,6 +448,23 @@ void r300_emit_fb_state(struct r300_context* r300, unsigned size, void* state) OUT_CS_REG(R300_ZB_ZMASK_PITCH, 0); } } + /* Set up a dummy zbuffer. Otherwise occlusion queries won't work. + * Use the first colorbuffer, we will disable writes in the DSA state + * so as not to corrupt it. */ + } else if (fb->nr_cbufs) { + surf = r300_surface(fb->cbufs[0]); + unsigned tiling = + r300->rws->get_value(r300->rws, R300_VID_SQUARE_TILING_SUPPORT) ? + R300_DEPTHMICROTILE_TILED_SQUARE : + R300_DEPTHMICROTILE_TILED; + + OUT_CS_REG(R300_ZB_FORMAT, R300_DEPTHFORMAT_16BIT_INT_Z); + + OUT_CS_REG_SEQ(R300_ZB_DEPTHOFFSET, 1); + OUT_CS_RELOC(surf->cs_buffer, 0, 0, surf->domain); + + OUT_CS_REG_SEQ(R300_ZB_DEPTHPITCH, 1); + OUT_CS_RELOC(surf->cs_buffer, 4 | tiling, 0, surf->domain); } END_CS; diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c index f902db54cc1..d3fc9405bd4 100644 --- a/src/gallium/drivers/r300/r300_state.c +++ b/src/gallium/drivers/r300/r300_state.c @@ -485,6 +485,10 @@ static void* dsa->z_stencil_control |= (r300_translate_depth_stencil_function(state->depth.func) << R300_Z_FUNC_SHIFT); + } else { + /* We must enable depth test, otherwise occlusion queries won't work. */ + dsa->z_buffer_control |= R300_Z_ENABLE; + dsa->z_stencil_control |= R300_ZS_ALWAYS; } /* Stencil buffer setup. */ @@ -554,11 +558,13 @@ static void* OUT_CB_REG(R500_ZB_STENCILREFMASK_BF, dsa->stencil_ref_bf); END_CB; + /* We must enable depth test, otherwise occlusion queries won't work. + * We setup a dummy zbuffer to silent the CS checker, see emit_fb_state. */ BEGIN_CB(dsa->cb_no_readwrite, 8); OUT_CB_REG(R300_FG_ALPHA_FUNC, dsa->alpha_function); OUT_CB_REG_SEQ(R300_ZB_CNTL, 3); - OUT_CB(0); - OUT_CB(0); + OUT_CB(R300_Z_ENABLE); + OUT_CB(R300_ZS_ALWAYS); OUT_CB(0); OUT_CB_REG(R500_ZB_STENCILREFMASK_BF, 0); END_CB; @@ -699,12 +705,14 @@ void r300_mark_fb_state_dirty(struct r300_context *r300, /* Now compute the fb_state atom size. */ r300->fb_state.size = 2 + (8 * state->nr_cbufs); - if (r300->cbzb_clear) + if (r300->cbzb_clear) { r300->fb_state.size += 10; - else if (state->zsbuf) { + } else if (state->zsbuf) { r300->fb_state.size += 10; if (can_hyperz) r300->fb_state.size += r300->screen->caps.hiz_ram ? 8 : 4; + } else if (state->nr_cbufs) { + r300->fb_state.size += 10; } /* The size of the rest of atoms stays the same. */ |