diff options
author | Paul Berry <[email protected]> | 2012-04-15 10:35:01 -0700 |
---|---|---|
committer | Paul Berry <[email protected]> | 2012-05-07 10:47:49 -0700 |
commit | 3ec0e55b63db3c1067f3bbf4563beb3b98a19288 (patch) | |
tree | 88679007e52aacab9e67275178f26c047529cc4b /src/mesa/drivers/dri/i965/brw_misc_state.c | |
parent | 1c0f5d8324c4db2720247989ddc4a45315b55a85 (diff) |
i965: Fix mipmap offsets for HiZ and separate stencil buffers.
When rendering to a miplevel other than 0 within a color, depth,
stencil, or HiZ buffer, we need to tell the GPU to render to an offset
within the buffer, so that the data is written into the correct
miplevel. We do this using a coarse offset (in pages), and a fine
adjustment (the so-called "tile_x" and "tile_y" values, which are
measured in pixels).
We have always computed the coarse offset and fine adjustment using
intel_renderbuffer_tile_offsets() function. This worked fine for
color and combined depth/stencil buffers, but failed to work properly
when HiZ and separate stencil were in use. It failed to work because
there is only one set of fine adjustment controls shared by the HiZ,
depth, and stencil buffers, so we need to choose tile_x and tile_y
values that are compatible with the tiling of all three buffers, and
then compute separate coarse offsets for each buffer.
This patch fixes the HiZ and separate stencil case by replacing the
call to intel_renderbuffer_tile_offsets() with calls to two functions:
intel_region_get_tile_masks(), which determines how much of the
adjustment can be performed using offsets and how much can be
performed using tile_x and tile_y, and
intel_region_get_aligned_offset(), which computes the coarse offset.
intel_region_get_tile_offsets() is still used for color renderbuffers,
so to avoid code duplication, I've re-worked it to use
intel_region_get_tile_masks() and intel_region_get_aligned_offset().
On i965 Gen6, fixes piglit tests
"texturing/depthstencil-render-miplevels 1024 X" where X is one of
(depth, depth_and_stencil, depth_stencil_single_binding, depth_x,
depth_x_and_stencil, stencil, stencil_and_depth, stencil_and_depth_x).
On i965 Gen7, the variants of
"texturing/depthstencil-render-miplevels" that contain a stencil
buffer still fail, due to another problem: Gen7 seems to ignore the 3
LSB's of the tile_y adjustment (and possibly also tile_x).
v2: Removed spurious comments. Added assertions to check
preconditions of intel_region_get_aligned_offset().
Reviewed-by: Chad Versace <[email protected]>
Acked-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/mesa/drivers/dri/i965/brw_misc_state.c')
-rw-r--r-- | src/mesa/drivers/dri/i965/brw_misc_state.c | 96 |
1 files changed, 88 insertions, 8 deletions
diff --git a/src/mesa/drivers/dri/i965/brw_misc_state.c b/src/mesa/drivers/dri/i965/brw_misc_state.c index 51ea03b6a3f..7a0f5a31ac0 100644 --- a/src/mesa/drivers/dri/i965/brw_misc_state.c +++ b/src/mesa/drivers/dri/i965/brw_misc_state.c @@ -266,10 +266,45 @@ static void emit_depthbuffer(struct brw_context *brw) unsigned int len; bool separate_stencil = false; + /* Amount by which drawing should be offset in order to draw to the + * appropriate miplevel/zoffset/cubeface. We will extract these values + * from depth_irb or stencil_irb once we determine which is present. + */ + uint32_t draw_x = 0, draw_y = 0; + + /* Masks used to determine how much of the draw_x and draw_y offsets should + * be performed using the fine adjustment of "depth coordinate offset X/Y" + * (dw5 of 3DSTATE_DEPTH_BUFFER). Any remaining coarse adjustment will be + * performed by changing the base addresses of the buffers. + * + * Since the HiZ, depth, and stencil buffers all use the same "depth + * coordinate offset X/Y" values, we need to make sure that the coarse + * adjustment will be possible to apply to all three buffers. Since coarse + * adjustment can only be applied in multiples of the tile size, we will OR + * together the tile masks of all the buffers to determine which offsets to + * perform as fine adjustments. + */ + uint32_t tile_mask_x = 0, tile_mask_y = 0; + + if (depth_irb) { + intel_region_get_tile_masks(depth_irb->mt->region, + &tile_mask_x, &tile_mask_y); + } + if (depth_irb && depth_irb->mt && depth_irb->mt->hiz_mt) { hiz_region = depth_irb->mt->hiz_mt->region; + + uint32_t hiz_tile_mask_x, hiz_tile_mask_y; + intel_region_get_tile_masks(hiz_region, + &hiz_tile_mask_x, &hiz_tile_mask_y); + + /* Each HiZ row represents 2 rows of pixels */ + hiz_tile_mask_y = hiz_tile_mask_y << 1 | 1; + + tile_mask_x |= hiz_tile_mask_x; + tile_mask_y |= hiz_tile_mask_y; } /* 3DSTATE_DEPTH_BUFFER, 3DSTATE_STENCIL_BUFFER are both @@ -286,8 +321,21 @@ static void emit_depthbuffer(struct brw_context *brw) if (stencil_mt->stencil_mt) stencil_mt = stencil_mt->stencil_mt; - if (stencil_mt->format == MESA_FORMAT_S8) + if (stencil_mt->format == MESA_FORMAT_S8) { separate_stencil = true; + + /* Separate stencil buffer uses 64x64 tiles. */ + tile_mask_x |= 63; + tile_mask_y |= 63; + } else { + uint32_t stencil_tile_mask_x, stencil_tile_mask_y; + intel_region_get_tile_masks(stencil_mt->region, + &stencil_tile_mask_x, + &stencil_tile_mask_y); + + tile_mask_x |= stencil_tile_mask_x; + tile_mask_y |= stencil_tile_mask_y; + } } /* If there's a packed depth/stencil bound to stencil only, we need to @@ -321,6 +369,8 @@ static void emit_depthbuffer(struct brw_context *brw) ADVANCE_BATCH(); } else if (!depth_irb && separate_stencil) { + uint32_t tile_x, tile_y; + /* * There exists a separate stencil buffer but no depth buffer. * @@ -343,6 +393,11 @@ static void emit_depthbuffer(struct brw_context *brw) */ assert(intel->has_separate_stencil); + draw_x = stencil_irb->draw_x; + draw_y = stencil_irb->draw_y; + tile_x = draw_x & tile_mask_x; + tile_y = draw_y & tile_mask_y; + BEGIN_BATCH(len); OUT_BATCH(_3DSTATE_DEPTH_BUFFER << 16 | (len - 2)); OUT_BATCH((BRW_DEPTHFORMAT_D32_FLOAT << 18) | @@ -352,11 +407,15 @@ static void emit_depthbuffer(struct brw_context *brw) (1 << 27) | /* tiled surface */ (BRW_SURFACE_2D << 29)); OUT_BATCH(0); - OUT_BATCH(((stencil_irb->Base.Base.Width - 1) << 6) | - (stencil_irb->Base.Base.Height - 1) << 19); - OUT_BATCH(0); + OUT_BATCH(((stencil_irb->Base.Base.Width + tile_x - 1) << 6) | + (stencil_irb->Base.Base.Height + tile_y - 1) << 19); OUT_BATCH(0); + if (intel->is_g4x || intel->gen >= 5) + OUT_BATCH(tile_x | (tile_y << 16)); + else + assert(tile_x == 0 && tile_y == 0); + if (intel->gen >= 6) OUT_BATCH(0); @@ -369,11 +428,18 @@ static void emit_depthbuffer(struct brw_context *brw) /* If using separate stencil, hiz must be enabled. */ assert(!separate_stencil || hiz_region); - offset = intel_renderbuffer_tile_offsets(depth_irb, &tile_x, &tile_y); - assert(intel->gen < 6 || region->tiling == I915_TILING_Y); assert(!hiz_region || region->tiling == I915_TILING_Y); + draw_x = depth_irb->draw_x; + draw_y = depth_irb->draw_y; + tile_x = draw_x & tile_mask_x; + tile_y = draw_y & tile_mask_y; + + offset = intel_region_get_aligned_offset(region, + draw_x & ~tile_mask_x, + draw_y & ~tile_mask_y); + BEGIN_BATCH(len); OUT_BATCH(_3DSTATE_DEPTH_BUFFER << 16 | (len - 2)); OUT_BATCH(((region->pitch * region->cpp) - 1) | @@ -413,12 +479,17 @@ static void emit_depthbuffer(struct brw_context *brw) /* Emit hiz buffer. */ if (hiz_region) { + uint32_t hiz_offset = + intel_region_get_aligned_offset(hiz_region, + draw_x & ~tile_mask_x, + (draw_y & ~tile_mask_y) / 2); + BEGIN_BATCH(3); OUT_BATCH((_3DSTATE_HIER_DEPTH_BUFFER << 16) | (3 - 2)); OUT_BATCH(hiz_region->pitch * hiz_region->cpp - 1); OUT_RELOC(hiz_region->bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, - 0); + hiz_offset); ADVANCE_BATCH(); } else { BEGIN_BATCH(3); @@ -431,6 +502,15 @@ static void emit_depthbuffer(struct brw_context *brw) /* Emit stencil buffer. */ if (separate_stencil) { struct intel_region *region = stencil_mt->region; + + /* Note: we can't compute the stencil offset using + * intel_region_get_aligned_offset(), because stencil_region claims + * that the region is untiled; in fact it's W tiled. + */ + uint32_t stencil_offset = + (draw_y & ~tile_mask_y) * region->pitch + + (draw_x & ~tile_mask_x) * 64; + BEGIN_BATCH(3); OUT_BATCH((_3DSTATE_STENCIL_BUFFER << 16) | (3 - 2)); /* The stencil buffer has quirky pitch requirements. From Vol 2a, @@ -441,7 +521,7 @@ static void emit_depthbuffer(struct brw_context *brw) OUT_BATCH(2 * region->pitch * region->cpp - 1); OUT_RELOC(region->bo, I915_GEM_DOMAIN_RENDER, I915_GEM_DOMAIN_RENDER, - 0); + stencil_offset); ADVANCE_BATCH(); } else { BEGIN_BATCH(3); |