From: Chad Versace Date: Fri, 26 Jun 2015 16:47:17 +0000 (-0700) Subject: vk/formats: Remove the cpp=0 stencil hack X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=37d6e04ba14eae96b57fc1f4f0da5daf16821060;p=mesa.git vk/formats: Remove the cpp=0 stencil hack The format table defined cpp = 0 for stencil-only formats. The real cpp is 1. When code begins to lie, especially about stencil buffers, code becomes increasingly fragile as time progresses, and the damage becomes increasingly hard to undo. (For precedent, see the painful history of stencil buffer cpp in the git log for gen6 and gen7 in the i965 driver). Let's undo the stencil buffer cpp lie now to avoid future pain. In the format table, set cpp = 1 for VK_FORMAT_S8; replace checks for cpp == 0; and delete all comments about the hack. --- diff --git a/src/vulkan/formats.c b/src/vulkan/formats.c index a40181414d0..eb96e94bb61 100644 --- a/src/vulkan/formats.c +++ b/src/vulkan/formats.c @@ -119,14 +119,10 @@ static const struct anv_format anv_formats[] = { fmt(VK_FORMAT_R11G11B10_UFLOAT, R11G11B10_FLOAT, .cpp = 4, .num_channels = 3), fmt(VK_FORMAT_R9G9B9E5_UFLOAT, R9G9B9E5_SHAREDEXP, .cpp = 4, .num_channels = 3), - /* For depth/stencil formats, the .format and .cpp fields describe the - * depth format. The field .has_stencil indicates whether or not there's a - * stencil buffer. - */ fmt(VK_FORMAT_D16_UNORM, R16_UNORM, .cpp = 2, .num_channels = 1, .depth_format = D16_UNORM), fmt(VK_FORMAT_D24_UNORM, R24_UNORM_X8_TYPELESS, .cpp = 4, .num_channels = 1, .depth_format = D24_UNORM_X8_UINT), fmt(VK_FORMAT_D32_SFLOAT, R32_FLOAT, .cpp = 4, .num_channels = 1, .depth_format = D32_FLOAT), - fmt(VK_FORMAT_S8_UINT, UNSUPPORTED, .cpp = 0, .num_channels = 1, .has_stencil = true), + fmt(VK_FORMAT_S8_UINT, UNSUPPORTED, .cpp = 1, .num_channels = 1, .has_stencil = true), fmt(VK_FORMAT_D16_UNORM_S8_UINT, R16_UNORM, .cpp = 2, .num_channels = 2, .depth_format = D16_UNORM, .has_stencil = true), fmt(VK_FORMAT_D24_UNORM_S8_UINT, R24_UNORM_X8_TYPELESS, .cpp = 4, .num_channels = 2, .depth_format = D24_UNORM_X8_UINT, .has_stencil = true), fmt(VK_FORMAT_D32_SFLOAT_S8_UINT, R32_FLOAT, .cpp = 4, .num_channels = 2, .depth_format = D32_FLOAT, .has_stencil = true), diff --git a/src/vulkan/image.c b/src/vulkan/image.c index c8a26f66130..9cf9d35a0f7 100644 --- a/src/vulkan/image.c +++ b/src/vulkan/image.c @@ -151,19 +151,14 @@ VkResult anv_image_create( const struct anv_format *format_info = anv_format_for_vk_format(pCreateInfo->format); - assert(format_info->cpp > 0 || format_info->has_stencil); uint32_t image_stride = 0; uint32_t image_size = 0; uint32_t stencil_offset = 0; uint32_t stencil_stride = 0; - /* First allocate space for the color or depth buffer. info->cpp gives us - * the cpp of the color or depth in case of depth/stencil formats. Stencil - * only (VK_FORMAT_S8_UINT) has info->cpp == 0 and doesn't allocate - * anything here. - */ - if (format_info->cpp > 0) { + if (!format_info->has_stencil || format_info->depth_format) { + /* The format has a color or depth component. Calculate space for it. */ uint32_t aligned_height; image_stride = ALIGN_I32(extent->width * format_info->cpp, @@ -172,13 +167,12 @@ VkResult anv_image_create( image_size = image_stride * aligned_height; } - /* Formats with a stencil buffer (either combined depth/stencil or - * VK_FORMAT_S8_UINT) have info->has_stencil == true. The stencil buffer is - * placed after the depth buffer and is a separate buffer from the GPU - * point of view, but as far as the API is concerned, depth and stencil are - * in the same image. - */ if (format_info->has_stencil) { + /* From the GPU's perspective, the depth buffer and stencil buffer are + * separate buffers. From Vulkan's perspective, though, depth and + * stencil reside in the same image. To satisfy Vulkan and the GPU, we + * place the depth and stencil buffers in the same bo. + */ const struct anv_tile_info *w_info = &anv_tile_info_table[WMAJOR]; uint32_t aligned_height; uint32_t stencil_size;