Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / amd / vulkan / vk_format.h
index e0087f1dea500cad30d74f5200834146b19871d7..285de63528f05eee9e0575edb767bef76817d52f 100644 (file)
  * IN THE SOFTWARE.
  */
 
-#pragma once
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef VK_FORMAT_H
+#define VK_FORMAT_H
 
 #include <assert.h>
 #include <vulkan/vulkan.h>
+#include <util/macros.h>
+
 enum vk_format_layout {
        /**
         * Formats with vk_format_block::width == vk_format_block::height == 1
@@ -75,7 +74,12 @@ enum vk_format_layout {
        /**
         * Everything else that doesn't fit in any of the above layouts.
         */
-       VK_FORMAT_LAYOUT_OTHER = 9
+       VK_FORMAT_LAYOUT_OTHER = 9,
+
+       /**
+        * Formats that contain multiple planes.
+        */
+       VK_FORMAT_LAYOUT_MULTIPLANE = 10,
 };
 
 struct vk_format_block
@@ -134,6 +138,11 @@ struct vk_format_description
        unsigned char swizzle[4];
 
        enum vk_format_colorspace colorspace;
+
+       unsigned plane_count:2;
+       unsigned width_divisor:2;
+       unsigned height_divisor:2;
+       VkFormat plane_formats[3];
 };
 
 extern const struct vk_format_description vk_format_description_table[];
@@ -143,7 +152,7 @@ const struct vk_format_description *vk_format_description(VkFormat format);
 /**
  * Return total bits needed for the pixel format per block.
  */
-static inline uint
+static inline unsigned
 vk_format_get_blocksizebits(VkFormat format)
 {
        const struct vk_format_description *desc = vk_format_description(format);
@@ -159,11 +168,11 @@ vk_format_get_blocksizebits(VkFormat format)
 /**
  * Return bytes per block (not pixel) for the given format.
  */
-static inline uint
+static inline unsigned
 vk_format_get_blocksize(VkFormat format)
 {
-       uint bits = vk_format_get_blocksizebits(format);
-       uint bytes = bits / 8;
+       unsigned bits = vk_format_get_blocksizebits(format);
+       unsigned bytes = bits / 8;
 
        assert(bits % 8 == 0);
        assert(bytes > 0);
@@ -174,7 +183,7 @@ vk_format_get_blocksize(VkFormat format)
        return bytes;
 }
 
-static inline uint
+static inline unsigned
 vk_format_get_blockwidth(VkFormat format)
 {
        const struct vk_format_description *desc = vk_format_description(format);
@@ -187,7 +196,7 @@ vk_format_get_blockwidth(VkFormat format)
        return desc->block.width;
 }
 
-static inline uint
+static inline unsigned
 vk_format_get_blockheight(VkFormat format)
 {
        const struct vk_format_description *desc = vk_format_description(format);
@@ -257,12 +266,13 @@ vk_format_aspects(VkFormat format)
 }
 
 static inline enum vk_swizzle
-radv_swizzle_conv(int idx, const unsigned char chan[4], VkComponentSwizzle vk_swiz)
+radv_swizzle_conv(VkComponentSwizzle component, const unsigned char chan[4], VkComponentSwizzle vk_swiz)
 {
        int x;
+
+       if (vk_swiz == VK_COMPONENT_SWIZZLE_IDENTITY)
+               vk_swiz = component;
        switch (vk_swiz) {
-       case VK_COMPONENT_SWIZZLE_IDENTITY:
-               return chan[idx];
        case VK_COMPONENT_SWIZZLE_ZERO:
                return VK_SWIZZLE_0;
        case VK_COMPONENT_SWIZZLE_ONE:
@@ -270,25 +280,25 @@ radv_swizzle_conv(int idx, const unsigned char chan[4], VkComponentSwizzle vk_sw
        case VK_COMPONENT_SWIZZLE_R:
                for (x = 0; x < 4; x++)
                        if (chan[x] == 0)
-                               return x;
+                               return (enum vk_swizzle)x;
                return VK_SWIZZLE_0;
        case VK_COMPONENT_SWIZZLE_G:
                for (x = 0; x < 4; x++)
                        if (chan[x] == 1)
-                               return x;
+                               return (enum vk_swizzle)x;
                return VK_SWIZZLE_0;
        case VK_COMPONENT_SWIZZLE_B:
                for (x = 0; x < 4; x++)
                        if (chan[x] == 2)
-                               return x;
+                               return (enum vk_swizzle)x;
                return VK_SWIZZLE_0;
        case VK_COMPONENT_SWIZZLE_A:
                for (x = 0; x < 4; x++)
                        if (chan[x] == 3)
-                               return x;
+                               return (enum vk_swizzle)x;
                return VK_SWIZZLE_1;
        default:
-               return chan[idx];
+               unreachable("Illegal swizzle");
        }
 }
 
@@ -296,10 +306,10 @@ static inline void vk_format_compose_swizzles(const VkComponentMapping *mapping,
                                              const unsigned char swz[4],
                                              enum vk_swizzle dst[4])
 {
-       dst[0] = radv_swizzle_conv(0, swz, mapping->r);
-       dst[1] = radv_swizzle_conv(1, swz, mapping->g);
-       dst[2] = radv_swizzle_conv(2, swz, mapping->b);
-       dst[3] = radv_swizzle_conv(3, swz, mapping->a);
+       dst[0] = radv_swizzle_conv(VK_COMPONENT_SWIZZLE_R, swz, mapping->r);
+       dst[1] = radv_swizzle_conv(VK_COMPONENT_SWIZZLE_G, swz, mapping->g);
+       dst[2] = radv_swizzle_conv(VK_COMPONENT_SWIZZLE_B, swz, mapping->b);
+       dst[3] = radv_swizzle_conv(VK_COMPONENT_SWIZZLE_A, swz, mapping->a);
 }
 
 static inline bool
@@ -325,6 +335,19 @@ vk_format_is_compressed(VkFormat format)
        }
 }
 
+static inline bool
+vk_format_is_subsampled(VkFormat format)
+{
+       const struct vk_format_description *desc = vk_format_description(format);
+
+       assert(desc);
+       if (!desc) {
+               return false;
+       }
+
+       return desc->layout == VK_FORMAT_LAYOUT_SUBSAMPLED;
+}
+
 static inline bool
 vk_format_has_depth(const struct vk_format_description *desc)
 {
@@ -366,6 +389,19 @@ vk_format_is_depth(VkFormat format)
        return vk_format_has_depth(desc);
 }
 
+static inline bool
+vk_format_is_stencil(VkFormat format)
+{
+       const struct vk_format_description *desc = vk_format_description(format);
+
+       assert(desc);
+       if (!desc) {
+               return false;
+       }
+
+       return vk_format_has_stencil(desc);
+}
+
 static inline bool
 vk_format_is_color(VkFormat format)
 {
@@ -396,16 +432,63 @@ vk_format_is_int(VkFormat format)
        return channel >= 0 && desc->channel[channel].pure_integer;
 }
 
+static inline bool
+vk_format_is_srgb(VkFormat format)
+{
+       const struct vk_format_description *desc = vk_format_description(format);
+       return desc->colorspace == VK_FORMAT_COLORSPACE_SRGB;
+}
+
+static inline VkFormat
+vk_format_no_srgb(VkFormat format)
+{
+       switch(format) {
+       case VK_FORMAT_R8_SRGB:
+               return VK_FORMAT_R8_UNORM;
+       case VK_FORMAT_R8G8_SRGB:
+               return VK_FORMAT_R8G8_UNORM;
+       case VK_FORMAT_R8G8B8_SRGB:
+               return VK_FORMAT_R8G8B8_UNORM;
+       case VK_FORMAT_B8G8R8_SRGB:
+               return VK_FORMAT_B8G8R8_UNORM;
+       case VK_FORMAT_R8G8B8A8_SRGB:
+               return VK_FORMAT_R8G8B8A8_UNORM;
+       case VK_FORMAT_B8G8R8A8_SRGB:
+               return VK_FORMAT_B8G8R8A8_UNORM;
+       case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
+               return VK_FORMAT_A8B8G8R8_UNORM_PACK32;
+       case VK_FORMAT_BC1_RGB_SRGB_BLOCK:
+               return VK_FORMAT_BC1_RGB_UNORM_BLOCK;
+       case VK_FORMAT_BC1_RGBA_SRGB_BLOCK:
+               return VK_FORMAT_BC1_RGBA_UNORM_BLOCK;
+       case VK_FORMAT_BC2_SRGB_BLOCK:
+               return VK_FORMAT_BC2_UNORM_BLOCK;
+       case VK_FORMAT_BC3_SRGB_BLOCK:
+               return VK_FORMAT_BC3_UNORM_BLOCK;
+       case VK_FORMAT_BC7_SRGB_BLOCK:
+               return VK_FORMAT_BC7_UNORM_BLOCK;
+       case VK_FORMAT_ETC2_R8G8B8_SRGB_BLOCK:
+               return VK_FORMAT_ETC2_R8G8B8_UNORM_BLOCK;
+       case VK_FORMAT_ETC2_R8G8B8A1_SRGB_BLOCK:
+               return VK_FORMAT_ETC2_R8G8B8A1_UNORM_BLOCK;
+       case VK_FORMAT_ETC2_R8G8B8A8_SRGB_BLOCK:
+               return VK_FORMAT_ETC2_R8G8B8A8_UNORM_BLOCK;
+       default:
+               assert(!vk_format_is_srgb(format));
+               return format;
+       }
+}
+
 static inline VkFormat
 vk_format_stencil_only(VkFormat format)
 {
        return VK_FORMAT_S8_UINT;
 }
 
-static inline uint
+static inline unsigned
 vk_format_get_component_bits(VkFormat format,
                             enum vk_format_colorspace colorspace,
-                            uint component)
+                            unsigned component)
 {
        const struct vk_format_description *desc = vk_format_description(format);
        enum vk_format_colorspace desc_colorspace;
@@ -444,6 +527,59 @@ vk_format_get_component_bits(VkFormat format,
                return 0;
        }
 }
-#ifdef __cplusplus
-} // extern "C" {
-#endif
+
+static inline VkFormat
+vk_to_non_srgb_format(VkFormat format)
+{
+       switch(format) {
+       case VK_FORMAT_R8_SRGB :
+               return VK_FORMAT_R8_UNORM;
+       case VK_FORMAT_R8G8_SRGB:
+               return VK_FORMAT_R8G8_UNORM;
+       case VK_FORMAT_R8G8B8_SRGB:
+               return VK_FORMAT_R8G8B8_UNORM;
+       case VK_FORMAT_B8G8R8_SRGB:
+               return VK_FORMAT_B8G8R8_UNORM;
+       case VK_FORMAT_R8G8B8A8_SRGB :
+               return VK_FORMAT_R8G8B8A8_UNORM;
+       case VK_FORMAT_B8G8R8A8_SRGB:
+               return VK_FORMAT_B8G8R8A8_UNORM;
+       case VK_FORMAT_A8B8G8R8_SRGB_PACK32:
+               return VK_FORMAT_A8B8G8R8_UNORM_PACK32;
+       default:
+               return format;
+       }
+}
+
+static inline unsigned
+vk_format_get_nr_components(VkFormat format)
+{
+       const struct vk_format_description *desc = vk_format_description(format);
+       return desc->nr_channels;
+}
+
+static inline unsigned
+vk_format_get_plane_count(VkFormat format)
+{
+       const struct vk_format_description *desc = vk_format_description(format);
+
+       return desc->plane_count;
+}
+
+static inline VkFormat
+vk_format_get_plane_format(VkFormat format, unsigned plane_id)
+{
+       const struct vk_format_description *desc = vk_format_description(format);
+
+       if (desc->layout != VK_FORMAT_LAYOUT_MULTIPLANE) {
+               assert(plane_id == 0);
+               return format;
+       }
+
+       assert(plane_id < desc->plane_count);
+
+       return desc->plane_formats[plane_id];
+}
+
+
+#endif /* VK_FORMAT_H */