memoryformat: Add Vulkan format information

This is not used yet, but I want to add it, so that it exists.

That way, when we add new formats, people don't forget to add the Vulkan
formats.
This commit is contained in:
Benjamin Otte 2023-12-15 08:27:09 +01:00
parent f357623170
commit ff082a7758
2 changed files with 180 additions and 0 deletions

View File

@ -342,6 +342,9 @@ struct _GdkMemoryFormatDescription
GdkMemoryFormat rgba_format;
GLint rgba_swizzle[4];
} gl;
#ifdef GDK_RENDERING_VULKAN
VkFormat vk_format;
#endif
/* no premultiplication going on here */
void (* to_float) (float *, const guchar*, gsize);
void (* from_float) (guchar *, const float *, gsize);
@ -374,6 +377,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.rgba_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
.rgba_swizzle = { GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA },
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_B8G8R8A8_UNORM,
#endif
.to_float = b8g8r8a8_premultiplied_to_float,
.from_float = b8g8r8a8_premultiplied_from_float,
},
@ -395,6 +401,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.rgba_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
.rgba_swizzle = { GL_GREEN, GL_BLUE, GL_ALPHA, GL_RED },
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
.to_float = a8r8g8b8_premultiplied_to_float,
.from_float = a8r8g8b8_premultiplied_from_float,
},
@ -415,6 +424,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8B8A8_UNORM,
#endif
.to_float = r8g8b8a8_premultiplied_to_float,
.from_float = r8g8b8a8_premultiplied_from_float,
},
@ -436,6 +448,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.rgba_format = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
.rgba_swizzle = { GL_ALPHA, GL_BLUE, GL_GREEN, GL_RED },
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
.to_float = a8b8g8r8_premultiplied_to_float,
.from_float = a8b8g8r8_premultiplied_from_float,
},
@ -457,6 +472,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.rgba_format = GDK_MEMORY_R8G8B8A8,
.rgba_swizzle = { GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA },
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_B8G8R8A8_UNORM,
#endif
.to_float = b8g8r8a8_to_float,
.from_float = b8g8r8a8_from_float,
},
@ -478,6 +496,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.rgba_format = GDK_MEMORY_R8G8B8A8,
.rgba_swizzle = { GL_GREEN, GL_BLUE, GL_ALPHA, GL_RED },
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
.to_float = a8r8g8b8_to_float,
.from_float = a8r8g8b8_from_float,
},
@ -498,6 +519,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8B8A8_UNORM,
#endif
.to_float = r8g8b8a8_to_float,
.from_float = r8g8b8a8_from_float,
},
@ -519,6 +543,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.rgba_format = GDK_MEMORY_R8G8B8A8,
.rgba_swizzle = { GL_ALPHA, GL_BLUE, GL_GREEN, GL_RED },
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
.to_float = a8b8g8r8_to_float,
.from_float = a8b8g8r8_from_float,
},
@ -541,6 +568,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.rgba_format = GDK_MEMORY_R8G8B8X8,
.rgba_swizzle = { GL_BLUE, GL_GREEN, GL_RED, GL_ONE },
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_B8G8R8A8_UNORM,
#endif
.to_float = b8g8r8x8_to_float,
.from_float = b8g8r8x8_from_float,
},
@ -563,6 +593,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.rgba_format = GDK_MEMORY_R8G8B8A8,
.rgba_swizzle = { GL_GREEN, GL_BLUE, GL_ALPHA, GL_ONE },
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
.to_float = x8r8g8b8_to_float,
.from_float = x8r8g8b8_from_float,
},
@ -584,6 +617,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ONE },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8B8A8_UNORM,
#endif
.to_float = r8g8b8x8_to_float,
.from_float = r8g8b8x8_from_float,
},
@ -606,6 +642,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.rgba_format = GDK_MEMORY_R8G8B8A8,
.rgba_swizzle = { GL_ALPHA, GL_BLUE, GL_GREEN, GL_ONE },
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_UNDEFINED,
#endif
.to_float = x8b8g8r8_to_float,
.from_float = x8b8g8r8_from_float,
},
@ -627,6 +666,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8B8_UNORM,
#endif
.to_float = r8g8b8_to_float,
.from_float = r8g8b8_from_float,
},
@ -649,6 +691,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.rgba_format = GDK_MEMORY_R8G8B8,
.rgba_swizzle = { GL_BLUE, GL_GREEN, GL_RED, GL_ALPHA },
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_B8G8R8_UNORM,
#endif
.to_float = b8g8r8_to_float,
.from_float = b8g8r8_from_float,
},
@ -673,6 +718,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16_UNORM,
#endif
.to_float = r16g16b16_to_float,
.from_float = r16g16b16_from_float,
},
@ -696,6 +744,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16A16_UNORM,
#endif
.to_float = r16g16b16a16_to_float,
.from_float = r16g16b16a16_from_float,
},
@ -719,6 +770,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16A16_UNORM,
#endif
.to_float = r16g16b16a16_to_float,
.from_float = r16g16b16a16_from_float,
},
@ -742,6 +796,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16_SFLOAT,
#endif
.to_float = r16g16b16_float_to_float,
.from_float = r16g16b16_float_from_float,
},
@ -764,6 +821,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16A16_SFLOAT,
#endif
.to_float = r16g16b16a16_float_to_float,
.from_float = r16g16b16a16_float_from_float,
},
@ -786,6 +846,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16B16A16_SFLOAT,
#endif
.to_float = r16g16b16a16_float_to_float,
.from_float = r16g16b16a16_float_from_float,
},
@ -809,6 +872,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R32G32B32_SFLOAT,
#endif
.to_float = r32g32b32_float_to_float,
.from_float = r32g32b32_float_from_float,
},
@ -831,6 +897,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R32G32B32A32_SFLOAT,
#endif
.to_float = r32g32b32a32_float_to_float,
.from_float = r32g32b32a32_float_from_float,
},
@ -853,6 +922,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R32G32B32A32_SFLOAT,
#endif
.to_float = r32g32b32a32_float_to_float,
.from_float = r32g32b32a32_float_from_float,
},
@ -874,6 +946,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_RED, GL_RED, GL_GREEN },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8_UNORM,
#endif
.to_float = g8a8_premultiplied_to_float,
.from_float = g8a8_premultiplied_from_float,
},
@ -895,6 +970,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_RED, GL_RED, GL_GREEN },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8G8_UNORM,
#endif
.to_float = g8a8_to_float,
.from_float = g8a8_from_float,
},
@ -916,6 +994,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_RED, GL_RED, GL_ONE },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8_UNORM,
#endif
.to_float = g8_to_float,
.from_float = g8_from_float,
},
@ -940,6 +1021,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_RED, GL_RED, GL_GREEN },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16_UNORM,
#endif
.to_float = g16a16_premultiplied_to_float,
.from_float = g16a16_premultiplied_from_float,
},
@ -964,6 +1048,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_RED, GL_RED, GL_GREEN },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16G16_UNORM,
#endif
.to_float = g16a16_to_float,
.from_float = g16a16_from_float,
},
@ -988,6 +1075,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_RED, GL_RED, GL_ONE },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16_UNORM,
#endif
.to_float = g16_to_float,
.from_float = g16_from_float,
},
@ -1009,6 +1099,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_RED, GL_RED, GL_RED },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R8_UNORM,
#endif
.to_float = a8_to_float,
.from_float = a8_from_float,
},
@ -1033,6 +1126,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_RED, GL_RED, GL_RED },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16_UNORM,
#endif
.to_float = a16_to_float,
.from_float = a16_from_float,
},
@ -1056,6 +1152,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_RED, GL_RED, GL_RED },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R16_SFLOAT,
#endif
.to_float = a16_float_to_float,
.from_float = a16_float_from_float,
},
@ -1079,6 +1178,9 @@ static const GdkMemoryFormatDescription memory_formats[] = {
.swizzle = { GL_RED, GL_RED, GL_RED, GL_RED },
.rgba_format = -1,
},
#ifdef GDK_RENDERING_VULKAN
.vk_format = VK_FORMAT_R32_SFLOAT,
#endif
.to_float = a32_float_to_float,
.from_float = a32_float_from_float,
}
@ -1306,6 +1408,72 @@ gdk_memory_format_gl_rgba_format (GdkMemoryFormat format,
return TRUE;
}
#ifdef GDK_RENDERING_VULKAN
static VkComponentSwizzle
vk_swizzle_from_gl_swizzle_one (GLint swizzle)
{
switch (swizzle)
{
case GL_RED:
return VK_COMPONENT_SWIZZLE_R;
case GL_GREEN:
return VK_COMPONENT_SWIZZLE_G;
case GL_BLUE:
return VK_COMPONENT_SWIZZLE_B;
case GL_ALPHA:
return VK_COMPONENT_SWIZZLE_A;
case GL_ZERO:
return VK_COMPONENT_SWIZZLE_ZERO;
case GL_ONE:
return VK_COMPONENT_SWIZZLE_ONE;
default:
g_assert_not_reached ();
return VK_COMPONENT_SWIZZLE_IDENTITY;
}
}
static void
vk_swizzle_from_gl_swizzle (VkComponentMapping *vk_swizzle,
const GLint gl_swizzle[4])
{
vk_swizzle->r = vk_swizzle_from_gl_swizzle_one (gl_swizzle[0]);
vk_swizzle->g = vk_swizzle_from_gl_swizzle_one (gl_swizzle[1]);
vk_swizzle->b = vk_swizzle_from_gl_swizzle_one (gl_swizzle[2]);
vk_swizzle->a = vk_swizzle_from_gl_swizzle_one (gl_swizzle[3]);
}
/* Vulkan version of gdk_memory_format_gl_format()
* Returns VK_FORMAT_UNDEFINED on failure */
VkFormat
gdk_memory_format_vk_format (GdkMemoryFormat format,
VkComponentMapping *out_swizzle)
{
if (out_swizzle)
vk_swizzle_from_gl_swizzle (out_swizzle, memory_formats[format].gl.swizzle);
return memory_formats[format].vk_format;
}
/* Vulkan version of gdk_memory_format_gl_rgba_format()
* Returns VK_FORMAT_UNDEFINED on failure */
VkFormat
gdk_memory_format_vk_rgba_format (GdkMemoryFormat format,
GdkMemoryFormat *out_rgba_format,
VkComponentMapping *out_swizzle)
{
GdkMemoryFormat actual = memory_formats[format].gl.rgba_format;
if (actual == -1)
return VK_FORMAT_UNDEFINED;
if (out_rgba_format)
*out_rgba_format = actual;
if (out_swizzle)
vk_swizzle_from_gl_swizzle (out_swizzle, memory_formats[format].gl.rgba_swizzle);
return memory_formats[actual].vk_format;
}
#endif
static void
premultiply (float *rgba,
gsize n)

View File

@ -24,6 +24,10 @@
#include <epoxy/gl.h>
#ifdef GDK_RENDERING_VULKAN
#include <vulkan/vulkan.h>
#endif
G_BEGIN_DECLS
typedef enum {
@ -61,6 +65,14 @@ gboolean gdk_memory_format_gl_rgba_format (GdkMemoryFormat
GLenum *out_format,
GLenum *out_type,
GLint out_swizzle[4]);
#ifdef GDK_RENDERING_VULKAN
VkFormat gdk_memory_format_vk_format (GdkMemoryFormat format,
VkComponentMapping *out_swizzle);
VkFormat gdk_memory_format_vk_rgba_format (GdkMemoryFormat format,
GdkMemoryFormat *out_rgba_format,
VkComponentMapping *out_swizzle);
#endif
void gdk_memory_convert (guchar *dest_data,
gsize dest_stride,