diff --git a/src/intel/vulkan/anv_formats.c b/src/intel/vulkan/anv_formats.c index 95c9b0abc3f..cbf6e84b2d1 100644 --- a/src/intel/vulkan/anv_formats.c +++ b/src/intel/vulkan/anv_formats.c @@ -2116,7 +2116,8 @@ void anv_GetPhysicalDeviceSparseImageFormatProperties2( pFormatInfo->tiling, pFormatInfo->samples, pFormatInfo->type, - pFormatInfo->format) != VK_SUCCESS) { + pFormatInfo->format, + NULL /* valid_samples_out */) != VK_SUCCESS) { return; } diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 9ad037405c4..c786910a6b0 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -2047,7 +2047,8 @@ anv_image_init_from_create_info(struct anv_device *device, pCreateInfo->tiling, pCreateInfo->samples, pCreateInfo->imageType, - pCreateInfo->format); + pCreateInfo->format, + NULL /* valid_samples_out */); if (result != VK_SUCCESS) return result; } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index 28d3b02644b..a8eed0cec2b 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -3526,7 +3526,8 @@ VkResult anv_sparse_image_check_support(struct anv_physical_device *pdevice, VkImageTiling tiling, VkSampleCountFlagBits samples, VkImageType type, - VkFormat format); + VkFormat format, + VkSampleCountFlagBits *valid_samples_out); struct anv_buffer { struct vk_buffer vk; diff --git a/src/intel/vulkan/anv_sparse.c b/src/intel/vulkan/anv_sparse.c index 3077e186882..3b0516aa36a 100644 --- a/src/intel/vulkan/anv_sparse.c +++ b/src/intel/vulkan/anv_sparse.c @@ -1543,14 +1543,23 @@ anv_sparse_bind_image_memory(struct anv_queue *queue, return VK_SUCCESS; } +/* Checks if we support sparse images with the support parameters. + * + * We also return in the optional pointer 'valid_samples_out' a subset of the + * 'samples' argument containing only the sample counts supported, in case + * more than one flag is passed. + */ VkResult anv_sparse_image_check_support(struct anv_physical_device *pdevice, VkImageCreateFlags flags, VkImageTiling tiling, VkSampleCountFlagBits samples, VkImageType type, - VkFormat vk_format) + VkFormat vk_format, + VkSampleCountFlagBits *valid_samples_out) { + VkSampleCountFlagBits valid_samples = samples; + assert(flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT); /* The spec says: @@ -1594,17 +1603,24 @@ anv_sparse_image_check_support(struct anv_physical_device *pdevice, if (tiling == VK_IMAGE_TILING_LINEAR) return VK_ERROR_FORMAT_NOT_SUPPORTED; - if ((samples & VK_SAMPLE_COUNT_2_BIT && - !pdevice->vk.supported_features.sparseResidency2Samples) || - (samples & VK_SAMPLE_COUNT_4_BIT && - !pdevice->vk.supported_features.sparseResidency4Samples) || - (samples & VK_SAMPLE_COUNT_8_BIT && - !pdevice->vk.supported_features.sparseResidency8Samples) || - (samples & VK_SAMPLE_COUNT_16_BIT && - !pdevice->vk.supported_features.sparseResidency16Samples) || - samples & VK_SAMPLE_COUNT_32_BIT || - samples & VK_SAMPLE_COUNT_64_BIT) + if (!pdevice->vk.supported_features.sparseResidency2Samples) + valid_samples &= ~VK_SAMPLE_COUNT_2_BIT; + if (!pdevice->vk.supported_features.sparseResidency4Samples) + valid_samples &= ~VK_SAMPLE_COUNT_4_BIT; + if (!pdevice->vk.supported_features.sparseResidency8Samples) + valid_samples &= ~VK_SAMPLE_COUNT_8_BIT; + if (!pdevice->vk.supported_features.sparseResidency16Samples) + valid_samples &= ~VK_SAMPLE_COUNT_16_BIT; + valid_samples &= ~(VK_SAMPLE_COUNT_32_BIT | VK_SAMPLE_COUNT_64_BIT); + + /* Here we return NOT_PRESENT since the user is asking for sample counts we + * already reported we don't support with sparse. + */ + if (!valid_samples) { + if (valid_samples_out) + *valid_samples_out = 0; return VK_ERROR_FEATURE_NOT_PRESENT; + } /* While the Vulkan spec allows us to support depth/stencil sparse images * everywhere, sometimes we're not able to have them with the tiling @@ -1623,8 +1639,7 @@ anv_sparse_image_check_support(struct anv_physical_device *pdevice, * depth/stencil are different, and only the color layout is compatible * with the standard block shapes. */ - if (samples != VK_SAMPLE_COUNT_1_BIT) - return VK_ERROR_FORMAT_NOT_SUPPORTED; + valid_samples &= VK_SAMPLE_COUNT_1_BIT; /* For 125+, isl_gfx125_filter_tiling() claims 3D is not supported. * For the previous platforms, isl_gfx6_filter_tiling() says only 2D is @@ -1677,5 +1692,11 @@ anv_sparse_image_check_support(struct anv_physical_device *pdevice, vk_format == VK_FORMAT_B8G8R8G8_422_UNORM) return VK_ERROR_FORMAT_NOT_SUPPORTED; + if (valid_samples_out) + *valid_samples_out = valid_samples; + + if (!valid_samples) + return VK_ERROR_FORMAT_NOT_SUPPORTED; + return VK_SUCCESS; }