nvk: simple format table
authorKarol Herbst <kherbst@redhat.com>
Tue, 7 Jun 2022 17:11:00 +0000 (19:11 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:31:53 +0000 (21:31 +0000)
this is enough to run the image copy and blit tests on a couple of formats

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

src/nouveau/vulkan/meson.build
src/nouveau/vulkan/nvk_format.c [new file with mode: 0644]
src/nouveau/vulkan/nvk_format.h [new file with mode: 0644]
src/nouveau/vulkan/nvk_image.c
src/nouveau/vulkan/nvk_image.h
src/nouveau/vulkan/nvk_physical_device.c

index 3640fb5..81388c9 100644 (file)
@@ -14,6 +14,8 @@ nvk_files = files(
   'nvk_device.h',
   'nvk_device_memory.c',
   'nvk_device_memory.h',
+  'nvk_format.c',
+  'nvk_format.h',
   'nvk_image.c',
   'nvk_image.h',
   'nvk_image_view.c',
diff --git a/src/nouveau/vulkan/nvk_format.c b/src/nouveau/vulkan/nvk_format.c
new file mode 100644 (file)
index 0000000..f840478
--- /dev/null
@@ -0,0 +1,160 @@
+#include "nvk_format.h"
+
+#include "nvtypes.h"
+#include "classes/cl902d.h"
+
+/*
+ * nvidia names
+ *   _: UNORM
+ *   F: SFLOAT (and maybe UFLOAT?)
+ *   L: SINT and UINT
+ *   N: SNORM
+ * and for whatever reason, 8 bit format names are in BE order
+ *
+ * TODO: swizzles
+ * TODO: X formats
+ * TODO: Y formats
+ * TODO: Z formats
+ * TODO: O formats
+ */
+
+struct nvk_format nvk_formats[NVK_FORMATS] = {
+   {
+      .vk_format = VK_FORMAT_R8_UNORM,
+      .hw_format = 0x0,
+      .supports_2d_blit = false,
+   },
+
+   {
+      .vk_format = VK_FORMAT_A1R5G5B5_UNORM_PACK16,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A1R5G5B5,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_A2B10G10R10_UNORM_PACK32,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A2B10G10R10,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_A2R10G10B10_UNORM_PACK32,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A2R10G10B10,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_A8B8G8R8_SINT_PACK32,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A8BL8GL8RL8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_A8B8G8R8_SNORM_PACK32,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_AN8BN8GN8RN8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_A8B8G8R8_UINT_PACK32,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A8BL8GL8RL8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_A8B8G8R8_UNORM_PACK32,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A8B8G8R8,
+      .supports_2d_blit = true,
+   },
+
+   {
+      .vk_format = VK_FORMAT_B8G8R8A8_SINT,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A8RL8GL8BL8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_B8G8R8A8_UINT,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A8RL8GL8BL8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_B8G8R8A8_UNORM,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A8R8G8B8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_B10G11R11_UFLOAT_PACK32,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_BF10GF11RF11,
+      .supports_2d_blit = true,
+   },
+
+   {
+      .vk_format = VK_FORMAT_R5G6B5_UNORM_PACK16,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_R5G6B5,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R8G8_SNORM,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_GN8RN8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R8G8_UNORM,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_G8R8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R8G8B8A8_SINT,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A8BL8GL8RL8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R8G8B8A8_SNORM,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_AN8BN8GN8RN8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R8G8B8A8_UINT,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A8BL8GL8RL8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R8G8B8A8_UNORM,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_A8B8G8R8,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R16G16_SFLOAT,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_RF16_GF16,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R16G16_SNORM,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_RN16_GN16,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R16G16_UNORM,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_R16_G16,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R16G16B16A16_SFLOAT,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_RF16_GF16_BF16_AF16,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R16G16B16A16_SNORM,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_RN16_GN16_BN16_AN16,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R16G16B16A16_UNORM,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_R16_G16_B16_A16,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R32G32_SFLOAT,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_RF32_GF32,
+      .supports_2d_blit = true,
+   },
+   {
+      .vk_format = VK_FORMAT_R32G32B32A32_SFLOAT,
+      .hw_format = NV902D_SET_SRC_FORMAT_V_RF32_GF32_BF32_AF32,
+      .supports_2d_blit = true,
+   },
+};
diff --git a/src/nouveau/vulkan/nvk_format.h b/src/nouveau/vulkan/nvk_format.h
new file mode 100644 (file)
index 0000000..0659fe9
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef NVK_FORMAT_H
+#define NVK_FORMAT_H 1
+
+#include "nvk_private.h"
+
+struct nvk_format {
+   VkFormat vk_format;
+   uint8_t hw_format;
+
+   bool supports_2d_blit:1;
+};
+
+#define NVK_FORMATS 27
+extern struct nvk_format nvk_formats[NVK_FORMATS];
+
+#endif
index 7f634d8..c4ef7ba 100644 (file)
@@ -4,6 +4,7 @@
 
 #include "nvk_device.h"
 #include "nvk_device_memory.h"
+#include "nvk_format.h"
 #include "nvk_physical_device.h"
 
 /* calculates optimal tiling for a given CreateInfo
@@ -92,6 +93,16 @@ static VkResult nvk_image_init(struct nvk_device *device,
 
    vk_image_init(&device->vk, &image->vk, pCreateInfo);
 
+   for (unsigned i = 0; i < ARRAY_SIZE(nvk_formats); i++) {
+      struct nvk_format *format = &nvk_formats[i];
+
+      if (format->vk_format != pCreateInfo->format)
+         continue;
+
+      image->format = format;
+   }
+   assert(image->format);
+
    image->tile = tile;
    image->row_stride = align(image->vk.extent.width * block_size, block.width);
    image->layer_stride = align(image->vk.extent.height, block.height) * image->row_stride;
index 86f4792..a0b3528 100644 (file)
@@ -23,6 +23,7 @@ struct nvk_tile {
    bool is_tiled:1;
 };
 
+struct nvk_format;
 struct nvk_image {
    struct vk_image vk;
    struct nvk_device_memory *mem;
@@ -30,6 +31,7 @@ struct nvk_image {
 
    VkDeviceSize min_size;
 
+   struct nvk_format *format;
    uint32_t row_stride;
    uint32_t layer_stride;
    struct nvk_tile tile;
index 1d30073..22c67e2 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "nvk_bo_sync.h"
 #include "nvk_entrypoints.h"
+#include "nvk_format.h"
 #include "nvk_instance.h"
 #include "nvk_wsi.h"
 
@@ -71,6 +72,9 @@ nvk_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
       .deviceType = pdevice->dev->is_integrated ? VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
                                                 : VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU,
       .limits = (VkPhysicalDeviceLimits) {
+         .maxImageArrayLayers = 2048,
+         .maxImageDimension1D = pdevice->dev->chipset >= 0x130 ? 0x8000 : 0x4000,
+         .maxImageDimension2D = pdevice->dev->chipset >= 0x130 ? 0x8000 : 0x4000,
          .nonCoherentAtomSize = 64,
       },
 
@@ -388,6 +392,11 @@ nvk_GetPhysicalDeviceFormatProperties2(VkPhysicalDevice physicalDevice,
    VkFormat vk_format,
    VkFormatProperties2 *pFormatProperties)
 {
+   pFormatProperties->formatProperties.linearTilingFeatures =
+      VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
+   pFormatProperties->formatProperties.optimalTilingFeatures =
+      VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT;
+
    vk_foreach_struct(ext, pFormatProperties->pNext)
    {
       /* Use unsigned since some cases are not in the VkStructureType enum. */
@@ -404,5 +413,50 @@ nvk_GetPhysicalDeviceImageFormatProperties2(VkPhysicalDevice physicalDevice,
    const VkPhysicalDeviceImageFormatInfo2 *base_info,
    VkImageFormatProperties2 *base_props)
 {
+   if (base_info->usage & ~(VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT))
+      return VK_ERROR_FORMAT_NOT_SUPPORTED;
+
+   for (unsigned i = 0; i < ARRAY_SIZE(nvk_formats); i++) {
+      struct nvk_format *format = &nvk_formats[i];
+
+      if (format->vk_format != base_info->format)
+         continue;
+
+      if (!format->supports_2d_blit)
+         return VK_ERROR_FORMAT_NOT_SUPPORTED;
+
+      if (base_info->type == VK_IMAGE_TYPE_1D)
+         base_props->imageFormatProperties.maxExtent = (VkExtent3D){32768, 1, 1};
+      else if (base_info->type == VK_IMAGE_TYPE_2D)
+         base_props->imageFormatProperties.maxExtent = (VkExtent3D){32768, 32768, 1};
+      else
+         return VK_ERROR_FORMAT_NOT_SUPPORTED;
+
+      base_props->imageFormatProperties.maxMipLevels = 0;
+      base_props->imageFormatProperties.maxArrayLayers = 2048;
+      base_props->imageFormatProperties.sampleCounts = 0;
+      base_props->imageFormatProperties.maxResourceSize = 0xffffffff; // TODO proper value
+
+      vk_foreach_struct(s, base_props->pNext) {
+         switch (s->sType) {
+         default:
+            nvk_debug_ignored_stype(s->sType);
+            break;
+         }
+      }
+
+      vk_foreach_struct(ext, base_info->pNext)
+      {
+         /* Use unsigned since some cases are not in the VkStructureType enum. */
+         switch ((unsigned)ext->sType) {
+         default:
+            nvk_debug_ignored_stype(ext->sType);
+            break;
+         }
+      }
+
+      return VK_SUCCESS;
+   }
+
    return VK_ERROR_FORMAT_NOT_SUPPORTED;
 }