intel/anv: Use #defines for all __gen_ helpers
[mesa.git] / src / intel / vulkan / anv_formats.c
index e7113e3633f8e7a9a07d0e1da5fcf6108b7ddbc9..ff59f479fd0377f0cdce6ea02aa7faf6c6d33fe2 100644 (file)
 #include "anv_private.h"
 #include "vk_format_info.h"
 
-#define ISL_SWIZZLE(r, g, b, a) { \
-   ISL_CHANNEL_SELECT_##r, \
-   ISL_CHANNEL_SELECT_##g, \
-   ISL_CHANNEL_SELECT_##b, \
-   ISL_CHANNEL_SELECT_##a, \
-}
-
 #define RGBA ISL_SWIZZLE(RED, GREEN, BLUE, ALPHA)
 #define BGRA ISL_SWIZZLE(BLUE, GREEN, RED, ALPHA)
 #define RGB1 ISL_SWIZZLE(RED, GREEN, BLUE, ONE)
@@ -50,7 +43,7 @@
  * bspec) names are in LSB -> MSB order while VK formats are MSB -> LSB.
  */
 static const struct anv_format anv_formats[] = {
-   fmt(VK_FORMAT_UNDEFINED,               ISL_FORMAT_RAW),
+   fmt(VK_FORMAT_UNDEFINED,               ISL_FORMAT_UNSUPPORTED),
    fmt(VK_FORMAT_R4G4_UNORM_PACK8,        ISL_FORMAT_UNSUPPORTED),
    fmt(VK_FORMAT_R4G4B4A4_UNORM_PACK16,   ISL_FORMAT_A4B4G4R4_UNORM),
    swiz_fmt(VK_FORMAT_B4G4R4A4_UNORM_PACK16,   ISL_FORMAT_A4B4G4R4_UNORM,  BGRA),
@@ -245,7 +238,7 @@ static const struct anv_format anv_formats[] = {
  * Exactly one bit must be set in \a aspect.
  */
 struct anv_format
-anv_get_format(const struct brw_device_info *devinfo, VkFormat vk_format,
+anv_get_format(const struct gen_device_info *devinfo, VkFormat vk_format,
                VkImageAspectFlags aspect, VkImageTiling tiling)
 {
    struct anv_format format = anv_formats[vk_format];
@@ -271,18 +264,19 @@ anv_get_format(const struct brw_device_info *devinfo, VkFormat vk_format,
       isl_format_get_layout(format.isl_format);
 
    if (tiling == VK_IMAGE_TILING_OPTIMAL &&
-       !util_is_power_of_two(isl_layout->bs)) {
+       !util_is_power_of_two(isl_layout->bpb)) {
       /* Tiled formats *must* be power-of-two because we need up upload
        * them with the render pipeline.  For 3-channel formats, we fix
        * this by switching them over to RGBX or RGBA formats under the
        * hood.
        */
       enum isl_format rgbx = isl_format_rgb_to_rgbx(format.isl_format);
-      if (rgbx != ISL_FORMAT_UNSUPPORTED) {
+      if (rgbx != ISL_FORMAT_UNSUPPORTED &&
+          isl_format_supports_rendering(devinfo, rgbx)) {
          format.isl_format = rgbx;
       } else {
          format.isl_format = isl_format_rgb_to_rgba(format.isl_format);
-         format.swizzle = (struct anv_format_swizzle) RGB1;
+         format.swizzle = RGB1;
       }
    }
 
@@ -302,7 +296,7 @@ anv_get_format(const struct brw_device_info *devinfo, VkFormat vk_format,
 // Format capabilities
 
 static VkFormatFeatureFlags
-get_image_format_properties(const struct brw_device_info *devinfo,
+get_image_format_properties(const struct gen_device_info *devinfo,
                             enum isl_format base, struct anv_format format)
 {
    if (format.isl_format == ISL_FORMAT_UNSUPPORTED)
@@ -343,7 +337,7 @@ get_image_format_properties(const struct brw_device_info *devinfo,
 }
 
 static VkFormatFeatureFlags
-get_buffer_format_properties(const struct brw_device_info *devinfo,
+get_buffer_format_properties(const struct gen_device_info *devinfo,
                              enum isl_format format)
 {
    if (format == ISL_FORMAT_UNSUPPORTED)
@@ -376,8 +370,9 @@ anv_physical_device_get_format_properties(struct anv_physical_device *physical_d
       gen += 5;
 
    VkFormatFeatureFlags linear = 0, tiled = 0, buffer = 0;
-   if (anv_formats[format].isl_format != ISL_FORMAT_UNSUPPORTED &&
-       vk_format_is_depth_or_stencil(format)) {
+   if (anv_formats[format].isl_format == ISL_FORMAT_UNSUPPORTED) {
+      /* Nothing to do here */
+   } else if (vk_format_is_depth_or_stencil(format)) {
       tiled |= VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT;
       if (physical_device->info->gen >= 8)
          tiled |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
@@ -408,7 +403,7 @@ anv_physical_device_get_format_properties(struct anv_physical_device *physical_d
        * what most clients will want.
        */
       if (linear_fmt.isl_format != ISL_FORMAT_UNSUPPORTED &&
-          !util_is_power_of_two(isl_format_layouts[linear_fmt.isl_format].bs) &&
+          !util_is_power_of_two(isl_format_layouts[linear_fmt.isl_format].bpb) &&
           isl_format_rgb_to_rgbx(linear_fmt.isl_format) == ISL_FORMAT_UNSUPPORTED) {
          tiled &= ~VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT &
                   ~VK_FORMAT_FEATURE_BLIT_DST_BIT;
@@ -506,25 +501,15 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties(
       sampleCounts = isl_device_get_sample_counts(&physical_device->isl_dev);
    }
 
-   if (usage & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) {
-      /* Meta implements transfers by sampling from the source image. */
-      if (!(format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {
-         goto unsupported;
-      }
-   }
-
-#if 0
-   if (usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
-      if (anv_format_for_vk_format(format)->has_stencil) {
-         /* Not yet implemented because copying to a W-tiled surface is crazy
-          * hard.
-          */
-         anv_finishme("support VK_IMAGE_USAGE_TRANSFER_DST_BIT for "
-                      "stencil format");
+   if (usage & (VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
+                VK_IMAGE_USAGE_TRANSFER_DST_BIT)) {
+      /* Accept transfers on anything we can sample from or renderer to. */
+      if (!(format_feature_flags & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT |
+                                    VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT |
+                                    VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT))) {
          goto unsupported;
       }
    }
-#endif
 
    if (usage & VK_IMAGE_USAGE_SAMPLED_BIT) {
       if (!(format_feature_flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT)) {