vk/image: Linear stencil buffers are illegal
authorChad Versace <chad.versace@intel.com>
Fri, 28 Aug 2015 15:04:59 +0000 (08:04 -0700)
committerChad Versace <chad.versace@intel.com>
Fri, 28 Aug 2015 15:04:59 +0000 (08:04 -0700)
The hardware requires that stencil buffer memory be W-tiled.

From the Sandybridge PRM:
   This buffer is supported only in Tile W memory.

src/vulkan/anv_image.c

index 656193f774e765e228eb2512fc73b583346f5245..736a76881ffafbd5bfb1127323e3702dfe293b84 100644 (file)
@@ -103,20 +103,32 @@ static const struct anv_tile_info {
    [WMAJOR] = { 128, 32, 4096 },
 };
 
-static uint32_t
+/**
+ * Return -1 on failure.
+ */
+static int8_t
 anv_image_choose_tile_mode(const struct anv_image_create_info *anv_info)
 {
    if (anv_info->force_tile_mode)
       return anv_info->tile_mode;
 
-   if (anv_info->vk_info->format == VK_FORMAT_S8_UINT)
-      return WMAJOR;
+   /* The Sandybridge PRM says that the stencil buffer "is supported
+    * only in Tile W memory".
+    */
 
    switch (anv_info->vk_info->tiling) {
    case VK_IMAGE_TILING_LINEAR:
-      return LINEAR;
+      if (unlikely(anv_info->vk_info->format == VK_FORMAT_S8_UINT)) {
+         return -1;
+      } else {
+         return LINEAR;
+      }
    case VK_IMAGE_TILING_OPTIMAL:
-      return YMAJOR;
+      if (unlikely(anv_info->vk_info->format == VK_FORMAT_S8_UINT)) {
+         return WMAJOR;
+      } else {
+         return YMAJOR;
+      }
    default:
       assert(!"bad VKImageTiling");
       return LINEAR;
@@ -143,7 +155,9 @@ anv_image_make_surface(const struct anv_image_create_info *create_info,
    const uint32_t levels = create_info->vk_info->mipLevels;
    const uint32_t array_size = create_info->vk_info->arraySize;
 
-   const uint8_t tile_mode = anv_image_choose_tile_mode(create_info);
+   const int8_t tile_mode = anv_image_choose_tile_mode(create_info);
+   if (tile_mode == -1)
+      return vk_error(VK_ERROR_INVALID_IMAGE);
 
    const struct anv_tile_info *tile_info =
        &anv_tile_info_table[tile_mode];