From b883031b9163346700cf67be80c69a1412637167 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Tue, 1 Aug 2023 23:49:24 -0500 Subject: [PATCH] nvk: Improve image format properties and limits Part-of: --- src/nouveau/vulkan/nvk_image.c | 56 +++++++++++++++++++++----------- src/nouveau/vulkan/nvk_image.h | 4 +++ src/nouveau/vulkan/nvk_physical_device.c | 8 ++--- 3 files changed, 45 insertions(+), 23 deletions(-) diff --git a/src/nouveau/vulkan/nvk_image.c b/src/nouveau/vulkan/nvk_image.c index 513336d..62e4216 100644 --- a/src/nouveau/vulkan/nvk_image.c +++ b/src/nouveau/vulkan/nvk_image.c @@ -136,6 +136,21 @@ vk_image_usage_to_format_features(VkImageUsageFlagBits usage_flag) } } +uint32_t +nvk_image_max_dimension(const struct nvk_physical_device *pdev, + VkImageType image_type) +{ + switch (image_type) { + case VK_IMAGE_TYPE_1D: + case VK_IMAGE_TYPE_2D: + return pdev->info.chipset >= 0x130 ? 0x8000 : 0x4000; + case VK_IMAGE_TYPE_3D: + return 0x4000; + default: + unreachable("Invalid image type"); + } +} + VKAPI_ATTR VkResult VKAPI_CALL nvk_GetPhysicalDeviceImageFormatProperties2( VkPhysicalDevice physicalDevice, @@ -167,41 +182,44 @@ nvk_GetPhysicalDeviceImageFormatProperties2( if (ycbcr_info && pImageFormatInfo->type != VK_IMAGE_TYPE_2D) return VK_ERROR_FORMAT_NOT_SUPPORTED; + const uint32_t max_dim = nvk_image_max_dimension(pdev, VK_IMAGE_TYPE_1D); VkExtent3D maxExtent; - uint32_t maxMipLevels; uint32_t maxArraySize; - VkSampleCountFlags sampleCounts; switch (pImageFormatInfo->type) { case VK_IMAGE_TYPE_1D: - maxExtent = (VkExtent3D) { 16384, 1, 1 }, - maxMipLevels = 15; + maxExtent = (VkExtent3D) { max_dim, 1, 1 }; maxArraySize = 2048; - sampleCounts = VK_SAMPLE_COUNT_1_BIT; break; case VK_IMAGE_TYPE_2D: - maxExtent = (VkExtent3D) { 16384, 16384, 1 }; + maxExtent = (VkExtent3D) { max_dim, max_dim, 1 }; maxArraySize = 2048; - if(ycbcr_info) { - maxMipLevels = 1; - sampleCounts = VK_SAMPLE_COUNT_1_BIT; - } else { - maxMipLevels = 15; - sampleCounts = VK_SAMPLE_COUNT_1_BIT | - VK_SAMPLE_COUNT_2_BIT | - VK_SAMPLE_COUNT_4_BIT | - VK_SAMPLE_COUNT_8_BIT; - } break; case VK_IMAGE_TYPE_3D: - maxExtent = (VkExtent3D) { 2048, 2048, 2048 }; - maxMipLevels = 12; + maxExtent = (VkExtent3D) { max_dim, max_dim, max_dim }; maxArraySize = 1; - sampleCounts = VK_SAMPLE_COUNT_1_BIT; break; default: unreachable("Invalid image type"); } + assert(util_is_power_of_two_nonzero(max_dim)); + uint32_t maxMipLevels = util_logbase2(max_dim) + 1; + if (ycbcr_info != NULL) + maxMipLevels = 1; + + VkSampleCountFlags sampleCounts = VK_SAMPLE_COUNT_1_BIT; + if (pImageFormatInfo->tiling == VK_IMAGE_TILING_OPTIMAL && + pImageFormatInfo->type == VK_IMAGE_TYPE_2D && + (features & (VK_FORMAT_FEATURE_2_COLOR_ATTACHMENT_BIT | + VK_FORMAT_FEATURE_2_DEPTH_STENCIL_ATTACHMENT_BIT)) && + !(pImageFormatInfo->flags & VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT) && + !(pImageFormatInfo->usage & VK_IMAGE_USAGE_STORAGE_BIT)) { + sampleCounts = VK_SAMPLE_COUNT_1_BIT | + VK_SAMPLE_COUNT_2_BIT | + VK_SAMPLE_COUNT_4_BIT | + VK_SAMPLE_COUNT_8_BIT; + } + /* From the Vulkan 1.2.199 spec: * * "VK_IMAGE_CREATE_EXTENDED_USAGE_BIT specifies that the image can be diff --git a/src/nouveau/vulkan/nvk_image.h b/src/nouveau/vulkan/nvk_image.h index 7bd269b..3deea02 100644 --- a/src/nouveau/vulkan/nvk_image.h +++ b/src/nouveau/vulkan/nvk_image.h @@ -18,6 +18,10 @@ VkFormatFeatureFlags2 nvk_get_image_format_features(struct nvk_physical_device *pdevice, VkFormat format, VkImageTiling tiling); +uint32_t +nvk_image_max_dimension(const struct nvk_physical_device *pdev, + VkImageType image_type); + struct nvk_image_plane { struct nil_image nil; uint64_t addr; diff --git a/src/nouveau/vulkan/nvk_physical_device.c b/src/nouveau/vulkan/nvk_physical_device.c index ac9222a..6aaab6f 100644 --- a/src/nouveau/vulkan/nvk_physical_device.c +++ b/src/nouveau/vulkan/nvk_physical_device.c @@ -53,9 +53,9 @@ nvk_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, .limits = (VkPhysicalDeviceLimits) { .maxImageArrayLayers = 2048, - .maxImageDimension1D = pdev->info.chipset >= 0x130 ? 0x8000 : 0x4000, - .maxImageDimension2D = pdev->info.chipset >= 0x130 ? 0x8000 : 0x4000, - .maxImageDimension3D = 0x4000, + .maxImageDimension1D = nvk_image_max_dimension(pdev, VK_IMAGE_TYPE_1D), + .maxImageDimension2D = nvk_image_max_dimension(pdev, VK_IMAGE_TYPE_2D), + .maxImageDimension3D = nvk_image_max_dimension(pdev, VK_IMAGE_TYPE_3D), .maxImageDimensionCube = 0x8000, .maxPushConstantsSize = NVK_MAX_PUSH_SIZE, .maxMemoryAllocationCount = 1024, @@ -156,7 +156,7 @@ nvk_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, .sampledImageDepthSampleCounts = sample_counts, .sampledImageIntegerSampleCounts = sample_counts, .sampledImageStencilSampleCounts = sample_counts, - .storageImageSampleCounts = sample_counts, + .storageImageSampleCounts = VK_SAMPLE_COUNT_1_BIT, .standardSampleLocations = true, .optimalBufferCopyOffsetAlignment = 1, .optimalBufferCopyRowPitchAlignment = 1, -- 2.7.4