vk/formats: Fix incorrect depth formats
authorChad Versace <chad.versace@intel.com>
Fri, 26 Jun 2015 02:29:59 +0000 (19:29 -0700)
committerChad Versace <chad.versace@intel.com>
Fri, 26 Jun 2015 03:10:16 +0000 (20:10 -0700)
anv_format::surface_format was incorrect for Vulkan depth formats.
For example, the format table mapped

    VK_FORMAT_D24_UNORM -> .surface_format = D24_UNORM_X8_UINT
    VK_FORMAT_D32_FLOAT -> .surface_format = D32_FLOAT

but should have mapped

    VK_FORMAT_D24_UNORM -> .surface_format = R24_UNORM_X8_TYPELESS
    VK_FORMAT_D32_FLOAT -> .surface_format = R32_FLOAT

The Crucible test func.depthstencil.basic passed despite the bug, but
only because it did not attempt to texture from the depth surface.

The core problem is that RENDER_SURFACE_STATE.SurfaceFormat and
3DSTATE_DEPTH_BUFFER.SurfaceFormat are distinct types. Considering them
as enum spaces, the two enum spaces have incompatible collisions.

Fix this by adding a new field 'depth_format' to struct anv_format.

Refer to brw_surface_formats.c:translate_tex_format() for precedent.

src/vulkan/formats.c
src/vulkan/image.c
src/vulkan/private.h

index c88c7ce1ab9e84c3367fdde2ec1c8dc47ff92166..c5cac6db7f79fbc56b03fec5d0343f4a52df148a 100644 (file)
@@ -123,13 +123,13 @@ static const struct anv_format anv_formats[] = {
     * depth format. The field .has_stencil indicates whether or not there's a
     * stencil buffer.
     */
-   fmt(VK_FORMAT_D16_UNORM,               D16_UNORM,              .cpp = 2,   .num_channels = 1),
-   fmt(VK_FORMAT_D24_UNORM,               D24_UNORM_X8_UINT,      .cpp = 4,   .num_channels = 1),
-   fmt(VK_FORMAT_D32_SFLOAT,              D32_FLOAT,              .cpp = 4,   .num_channels = 1),
-   fmt(VK_FORMAT_S8_UINT,                 UNSUPPORTED,            .cpp = 0,   .num_channels = 1, .has_stencil = true),
-   fmt(VK_FORMAT_D16_UNORM_S8_UINT,       D16_UNORM,              .cpp = 2,   .num_channels = 2, .has_stencil = true),
-   fmt(VK_FORMAT_D24_UNORM_S8_UINT,       D24_UNORM_X8_UINT,      .cpp = 4,   .num_channels = 2, .has_stencil = true),
-   fmt(VK_FORMAT_D32_SFLOAT_S8_UINT,      D32_FLOAT,              .cpp = 4,   .num_channels = 2, .has_stencil = true),
+   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_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),
 
    fmt(VK_FORMAT_BC1_RGB_UNORM,           UNSUPPORTED),
    fmt(VK_FORMAT_BC1_RGB_SRGB,            UNSUPPORTED),
index 8a6f1952a4ad36dfc3c240c77c5a80a4c0ae9d07..5999318baaaa3175f6a83f167bf7e876dbebe541 100644 (file)
@@ -486,7 +486,7 @@ VkResult anv_CreateDepthStencilView(
 
    view->depth_stride = image->stride;
    view->depth_offset = image->offset;
-   view->depth_format = format->surface_format;
+   view->depth_format = format->depth_format;
 
    view->stencil_stride = image->stencil_stride;
    view->stencil_offset = image->offset + image->stencil_offset;
index f89e92af2d122b55588d711a4875d606ba133939..7833f080b534e1d2608482a1dea021ec9a84201d 100644 (file)
@@ -776,6 +776,7 @@ struct anv_format {
    uint16_t surface_format; /**< RENDER_SURFACE_STATE.SurfaceFormat */
    uint8_t cpp;
    uint8_t num_channels;
+   uint8_t depth_format; /**< 3DSTATE_DEPTH_BUFFER.SurfaceFormat */
    bool has_stencil;
 };