anv:Use VK_EXT_separate_stencil_usage to avoid stencil shadows on gen7
authorJason Ekstrand <jason@jlekstrand.net>
Mon, 17 Jun 2019 14:39:08 +0000 (09:39 -0500)
committerJason Ekstrand <jason@jlekstrand.net>
Mon, 17 Jun 2019 22:32:26 +0000 (22:32 +0000)
Whenever stencil texturing is not required (most of the time), we can
use VK_EXT_separate_stencil_usage to only create the shadow image when
VK_IMAGE_USAGE_SAMPLED_BIT is required for stencil.  Of course, this
depends on applications to use the extension but hopefully DXVK and
similar translators are doing so and that covers most of the apps.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
src/intel/vulkan/anv_extensions.py
src/intel/vulkan/anv_formats.c
src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_private.h

index 8468a72..c31d2cf 100644 (file)
@@ -142,6 +142,7 @@ EXTENSIONS = [
     Extension('VK_EXT_queue_family_foreign',              1, 'ANDROID'),
     Extension('VK_EXT_sampler_filter_minmax',             1, 'device->info.gen >= 9'),
     Extension('VK_EXT_scalar_block_layout',               1, True),
+    Extension('VK_EXT_separate_stencil_usage',            1, True),
     Extension('VK_EXT_shader_stencil_export',             1, 'device->info.gen >= 9'),
     Extension('VK_EXT_shader_viewport_index_layer',       1, True),
     Extension('VK_EXT_transform_feedback',                1, True),
index d46da75..3f18553 100644 (file)
@@ -1012,6 +1012,9 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2(
       case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO:
          external_info = (const void *) s;
          break;
+      case VK_STRUCTURE_TYPE_IMAGE_STENCIL_USAGE_CREATE_INFO_EXT:
+         /* Ignore but don't warn */
+         break;
       default:
          anv_debug_ignored_stype(s->sType);
          break;
index f405aa8..231b0fa 100644 (file)
@@ -338,7 +338,7 @@ make_surface(const struct anv_device *dev,
 
    if (dev->info.gen <= 7 &&
        aspect == VK_IMAGE_ASPECT_STENCIL_BIT &&
-       (image->usage & VK_IMAGE_USAGE_SAMPLED_BIT)) {
+       (image->stencil_usage & VK_IMAGE_USAGE_SAMPLED_BIT)) {
       needs_shadow = true;
    }
 
@@ -599,6 +599,15 @@ anv_image_create(VkDevice _device,
    image->drm_format_mod = isl_mod_info ? isl_mod_info->modifier :
                                           DRM_FORMAT_MOD_INVALID;
 
+   if (image->aspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
+      image->stencil_usage = pCreateInfo->usage;
+      const VkImageStencilUsageCreateInfoEXT *stencil_usage_info =
+         vk_find_struct_const(pCreateInfo->pNext,
+                              IMAGE_STENCIL_USAGE_CREATE_INFO_EXT);
+      if (stencil_usage_info)
+         image->stencil_usage = stencil_usage_info->stencilUsage;
+   }
+
    /* In case of external format, We don't know format yet,
     * so skip the rest for now.
     */
index 0cd66e0..9e59d79 100644 (file)
@@ -2978,7 +2978,8 @@ struct anv_image {
    uint32_t array_size;
    uint32_t samples; /**< VkImageCreateInfo::samples */
    uint32_t n_planes;
-   VkImageUsageFlags usage; /**< Superset of VkImageCreateInfo::usage. */
+   VkImageUsageFlags usage; /**< VkImageCreateInfo::usage. */
+   VkImageUsageFlags stencil_usage;
    VkImageCreateFlags create_flags; /* Flags used when creating image. */
    VkImageTiling tiling; /** VkImageCreateInfo::tiling */