From 14e1d58fb79ccb5034587092eaa3678f2642edc5 Mon Sep 17 00:00:00 2001 From: Chad Versace Date: Fri, 28 Aug 2015 08:03:31 -0700 Subject: [PATCH] vk: Fix stride of stencil buffers Stencil buffers have strange pitch. The PRM says: The pitch must be set to 2x the value computed based on width, as the stencil buffer is stored with two rows interleaved. --- src/vulkan/gen7_cmd_buffer.c | 9 ++++++++- src/vulkan/gen8_cmd_buffer.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/vulkan/gen7_cmd_buffer.c b/src/vulkan/gen7_cmd_buffer.c index 8fe59bab1c8..b149673f405 100644 --- a/src/vulkan/gen7_cmd_buffer.c +++ b/src/vulkan/gen7_cmd_buffer.c @@ -585,7 +585,14 @@ gen7_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer) if (has_stencil) { anv_batch_emit(&cmd_buffer->batch, GEN7_3DSTATE_STENCIL_BUFFER, .StencilBufferObjectControlState = GEN7_MOCS, - .SurfacePitch = image->stencil_surface.stride - 1, + + /* Stencil buffers have strange pitch. The PRM says: + * + * The pitch must be set to 2x the value computed based on width, + * as the stencil buffer is stored with two rows interleaved. + */ + .SurfacePitch = 2 * image->stencil_surface.stride - 1, + .SurfaceBaseAddress = { .bo = image->bo, .offset = image->offset + image->stencil_surface.offset, diff --git a/src/vulkan/gen8_cmd_buffer.c b/src/vulkan/gen8_cmd_buffer.c index 3a7f009dc66..5737879ffe7 100644 --- a/src/vulkan/gen8_cmd_buffer.c +++ b/src/vulkan/gen8_cmd_buffer.c @@ -520,7 +520,14 @@ gen8_cmd_buffer_emit_depth_stencil(struct anv_cmd_buffer *cmd_buffer) anv_batch_emit(&cmd_buffer->batch, GEN8_3DSTATE_STENCIL_BUFFER, .StencilBufferEnable = true, .StencilBufferObjectControlState = GEN8_MOCS, - .SurfacePitch = image->stencil_surface.stride - 1, + + /* Stencil buffers have strange pitch. The PRM says: + * + * The pitch must be set to 2x the value computed based on width, + * as the stencil buffer is stored with two rows interleaved. + */ + .SurfacePitch = 2 * image->stencil_surface.stride - 1, + .SurfaceBaseAddress = { .bo = image->bo, .offset = image->offset + image->stencil_surface.offset, -- 2.30.2