2016-12-06 13:42:46 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskvulkanimageprivate.h"
|
2016-12-15 23:22:23 +00:00
|
|
|
|
|
|
|
#include "gskvulkanbufferprivate.h"
|
2016-12-06 13:42:46 +00:00
|
|
|
#include "gskvulkanmemoryprivate.h"
|
2023-07-03 13:57:30 +00:00
|
|
|
#include "gskvulkanprivate.h"
|
2016-12-06 13:42:46 +00:00
|
|
|
|
2023-06-15 12:29:15 +00:00
|
|
|
#include "gdk/gdkmemoryformatprivate.h"
|
|
|
|
|
2016-12-06 13:42:46 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
struct _GskVulkanImage
|
|
|
|
{
|
2016-12-08 19:19:56 +00:00
|
|
|
GObject parent_instance;
|
|
|
|
|
2016-12-06 13:42:46 +00:00
|
|
|
GdkVulkanContext *vulkan;
|
|
|
|
|
2023-06-14 18:37:58 +00:00
|
|
|
GdkMemoryFormat format;
|
2023-06-17 14:05:09 +00:00
|
|
|
VkFormat vk_format;
|
2016-12-08 19:46:02 +00:00
|
|
|
gsize width;
|
|
|
|
gsize height;
|
2023-07-19 05:38:51 +00:00
|
|
|
VkImageTiling vk_tiling;
|
2017-09-20 23:11:42 +00:00
|
|
|
VkImageUsageFlags vk_usage;
|
2016-12-06 13:42:46 +00:00
|
|
|
VkImage vk_image;
|
|
|
|
VkImageView vk_image_view;
|
2023-07-08 18:10:04 +00:00
|
|
|
VkFramebuffer vk_framebuffer;
|
2023-07-19 04:14:55 +00:00
|
|
|
GskVulkanImagePostprocess postprocess;
|
2023-07-08 18:10:04 +00:00
|
|
|
|
2023-07-15 14:38:03 +00:00
|
|
|
VkPipelineStageFlags vk_pipeline_stage;
|
2017-09-20 23:11:42 +00:00
|
|
|
VkImageLayout vk_image_layout;
|
|
|
|
VkAccessFlags vk_access;
|
2016-12-06 13:42:46 +00:00
|
|
|
|
|
|
|
GskVulkanMemory *memory;
|
|
|
|
};
|
|
|
|
|
2016-12-08 19:19:56 +00:00
|
|
|
G_DEFINE_TYPE (GskVulkanImage, gsk_vulkan_image, G_TYPE_OBJECT)
|
|
|
|
|
2023-06-14 18:37:58 +00:00
|
|
|
typedef struct _GskMemoryFormatInfo GskMemoryFormatInfo;
|
|
|
|
|
|
|
|
struct _GskMemoryFormatInfo
|
|
|
|
{
|
|
|
|
VkFormat format;
|
|
|
|
VkComponentMapping components;
|
2023-07-19 04:14:55 +00:00
|
|
|
GskVulkanImagePostprocess postprocess;
|
2023-06-14 18:37:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const GskMemoryFormatInfo *
|
|
|
|
gsk_memory_format_get_vk_format_infos (GdkMemoryFormat format)
|
|
|
|
{
|
|
|
|
#define SWIZZLE(a, b, c, d) { VK_COMPONENT_SWIZZLE_ ## a, VK_COMPONENT_SWIZZLE_ ## b, VK_COMPONENT_SWIZZLE_ ## c, VK_COMPONENT_SWIZZLE_ ## d }
|
|
|
|
#define DEFAULT_SWIZZLE SWIZZLE (R, G, B, A)
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case GDK_MEMORY_B8G8R8A8_PREMULTIPLIED:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_B8G8R8A8_UNORM, DEFAULT_SWIZZLE, 0 },
|
|
|
|
{ VK_FORMAT_R8G8B8A8_UNORM, SWIZZLE(B, G, R, A), 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_A8R8G8B8_PREMULTIPLIED:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R8G8B8A8_UNORM, SWIZZLE(G, B, A, R), 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_R8G8B8A8_PREMULTIPLIED:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R8G8B8A8_UNORM, DEFAULT_SWIZZLE, 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-07-19 04:14:55 +00:00
|
|
|
case GDK_MEMORY_B8G8R8A8:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
|
|
|
{ VK_FORMAT_B8G8R8A8_UNORM, DEFAULT_SWIZZLE, GSK_VULKAN_IMAGE_PREMULTIPLY },
|
|
|
|
{ VK_FORMAT_R8G8B8A8_UNORM, SWIZZLE(B, G, R, A), GSK_VULKAN_IMAGE_PREMULTIPLY },
|
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_A8R8G8B8:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
|
|
|
{ VK_FORMAT_R8G8B8A8_UNORM, SWIZZLE(G, B, A, R), GSK_VULKAN_IMAGE_PREMULTIPLY },
|
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_R8G8B8A8:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
|
|
|
{ VK_FORMAT_R8G8B8A8_UNORM, DEFAULT_SWIZZLE, GSK_VULKAN_IMAGE_PREMULTIPLY },
|
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_A8B8G8R8:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
|
|
|
{ VK_FORMAT_R8G8B8A8_UNORM, SWIZZLE(A, B, G, R), GSK_VULKAN_IMAGE_PREMULTIPLY },
|
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
2023-06-14 18:37:58 +00:00
|
|
|
|
|
|
|
case GDK_MEMORY_R8G8B8:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R8G8B8_UNORM, DEFAULT_SWIZZLE, 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_B8G8R8:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_B8G8R8_UNORM, DEFAULT_SWIZZLE, 0 },
|
|
|
|
{ VK_FORMAT_R8G8B8_UNORM, SWIZZLE(B, G, R, A), 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_R16G16B16:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R16G16B16_UNORM, DEFAULT_SWIZZLE, 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_R16G16B16A16_PREMULTIPLIED:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R16G16B16A16_UNORM, DEFAULT_SWIZZLE, 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-07-19 04:14:55 +00:00
|
|
|
case GDK_MEMORY_R16G16B16A16:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
|
|
|
{ VK_FORMAT_R16G16B16A16_UNORM, DEFAULT_SWIZZLE, GSK_VULKAN_IMAGE_PREMULTIPLY },
|
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
2023-06-14 18:37:58 +00:00
|
|
|
|
|
|
|
case GDK_MEMORY_R16G16B16_FLOAT:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R16G16B16_SFLOAT, DEFAULT_SWIZZLE, 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R16G16B16A16_SFLOAT, DEFAULT_SWIZZLE, 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-07-19 04:14:55 +00:00
|
|
|
case GDK_MEMORY_R16G16B16A16_FLOAT:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
|
|
|
{ VK_FORMAT_R16G16B16A16_SFLOAT, DEFAULT_SWIZZLE, GSK_VULKAN_IMAGE_PREMULTIPLY },
|
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
2023-06-14 18:37:58 +00:00
|
|
|
|
|
|
|
case GDK_MEMORY_R32G32B32_FLOAT:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R32G32B32_SFLOAT, DEFAULT_SWIZZLE, 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R32G32B32A32_SFLOAT, DEFAULT_SWIZZLE, 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-07-19 04:14:55 +00:00
|
|
|
case GDK_MEMORY_R32G32B32A32_FLOAT:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
|
|
|
{ VK_FORMAT_R32G32B32A32_SFLOAT, DEFAULT_SWIZZLE, GSK_VULKAN_IMAGE_PREMULTIPLY },
|
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
2023-06-14 18:37:58 +00:00
|
|
|
|
|
|
|
case GDK_MEMORY_G8A8_PREMULTIPLIED:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R8G8_UNORM, SWIZZLE (R, R, R, G), 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-07-19 04:14:55 +00:00
|
|
|
case GDK_MEMORY_G8A8:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
|
|
|
{ VK_FORMAT_R8G8_UNORM, SWIZZLE (R, R, R, G), GSK_VULKAN_IMAGE_PREMULTIPLY },
|
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
2023-06-14 18:37:58 +00:00
|
|
|
|
|
|
|
case GDK_MEMORY_G8:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R8_UNORM, SWIZZLE (R, R, R, ONE), 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_G16A16_PREMULTIPLIED:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R16G16_UNORM, SWIZZLE (R, R, R, G), 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-07-19 04:14:55 +00:00
|
|
|
case GDK_MEMORY_G16A16:
|
2023-06-14 18:37:58 +00:00
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R16G16_UNORM, SWIZZLE (R, R, R, G), GSK_VULKAN_IMAGE_PREMULTIPLY },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-07-19 04:14:55 +00:00
|
|
|
case GDK_MEMORY_G16:
|
2023-06-14 18:37:58 +00:00
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R16_UNORM, SWIZZLE (R, R, R, ONE), 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-07-19 04:14:55 +00:00
|
|
|
case GDK_MEMORY_A8:
|
2023-06-14 18:37:58 +00:00
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R8_UNORM, SWIZZLE (R, R, R, R), 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-07-19 04:14:55 +00:00
|
|
|
case GDK_MEMORY_A16:
|
2023-06-14 18:37:58 +00:00
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
2023-07-19 04:14:55 +00:00
|
|
|
{ VK_FORMAT_R16_UNORM, SWIZZLE (R, R, R, R), 0 },
|
2023-06-14 18:37:58 +00:00
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-07-21 01:02:33 +00:00
|
|
|
case GDK_MEMORY_A16_FLOAT:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
|
|
|
{ VK_FORMAT_R16_SFLOAT, SWIZZLE (R, R, R, R), 0 },
|
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
case GDK_MEMORY_A32_FLOAT:
|
|
|
|
{
|
|
|
|
static const GskMemoryFormatInfo info[] = {
|
|
|
|
{ VK_FORMAT_R32_SFLOAT, SWIZZLE (R, R, R, R), 0 },
|
|
|
|
{ VK_FORMAT_UNDEFINED }
|
|
|
|
};
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
2023-06-14 18:37:58 +00:00
|
|
|
case GDK_MEMORY_N_FORMATS:
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#undef DEFAULT_SWIZZLE
|
|
|
|
#undef SWIZZLE
|
|
|
|
}
|
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
static GdkMemoryFormat
|
|
|
|
gsk_memory_format_get_fallback (GdkMemoryFormat format)
|
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case GDK_MEMORY_B8G8R8A8_PREMULTIPLIED:
|
|
|
|
case GDK_MEMORY_A8R8G8B8_PREMULTIPLIED:
|
|
|
|
case GDK_MEMORY_R8G8B8A8_PREMULTIPLIED:
|
|
|
|
case GDK_MEMORY_B8G8R8A8:
|
|
|
|
case GDK_MEMORY_A8R8G8B8:
|
|
|
|
case GDK_MEMORY_R8G8B8A8:
|
|
|
|
case GDK_MEMORY_A8B8G8R8:
|
|
|
|
case GDK_MEMORY_R8G8B8:
|
|
|
|
return GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
|
2023-07-19 04:13:28 +00:00
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_B8G8R8:
|
|
|
|
return GDK_MEMORY_R8G8B8;
|
2023-07-19 04:13:28 +00:00
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_R16G16B16A16_PREMULTIPLIED:
|
|
|
|
return GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED;
|
2023-07-19 04:13:28 +00:00
|
|
|
|
|
|
|
case GDK_MEMORY_R16G16B16:
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_R16G16B16A16:
|
|
|
|
return GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
|
2023-07-19 04:13:28 +00:00
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED:
|
|
|
|
return GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED;
|
2023-07-19 04:13:28 +00:00
|
|
|
|
|
|
|
case GDK_MEMORY_R16G16B16_FLOAT:
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_R16G16B16A16_FLOAT:
|
|
|
|
return GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED;
|
2023-07-19 04:13:28 +00:00
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED:
|
|
|
|
return GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
|
2023-07-19 04:13:28 +00:00
|
|
|
|
|
|
|
case GDK_MEMORY_R32G32B32_FLOAT:
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_R32G32B32A32_FLOAT:
|
|
|
|
return GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED;
|
2023-07-19 04:13:28 +00:00
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_G8A8_PREMULTIPLIED:
|
|
|
|
case GDK_MEMORY_G8A8:
|
2023-07-19 04:13:28 +00:00
|
|
|
return GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
|
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_G8:
|
|
|
|
return GDK_MEMORY_R8G8B8;
|
2023-07-19 04:13:28 +00:00
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_G16A16_PREMULTIPLIED:
|
|
|
|
case GDK_MEMORY_G16A16:
|
2023-07-19 04:13:28 +00:00
|
|
|
return GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
|
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_G16:
|
|
|
|
return GDK_MEMORY_R16G16B16;
|
2023-07-19 04:13:28 +00:00
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
case GDK_MEMORY_A8:
|
|
|
|
return GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
|
|
|
|
case GDK_MEMORY_A16:
|
|
|
|
return GDK_MEMORY_R16G16B16A16_PREMULTIPLIED;
|
2023-07-21 01:02:33 +00:00
|
|
|
case GDK_MEMORY_A16_FLOAT:
|
|
|
|
return GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED;
|
|
|
|
case GDK_MEMORY_A32_FLOAT:
|
|
|
|
return GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED;
|
2023-06-15 21:13:31 +00:00
|
|
|
|
|
|
|
case GDK_MEMORY_N_FORMATS:
|
|
|
|
default:
|
|
|
|
return GDK_MEMORY_R8G8B8A8_PREMULTIPLIED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-14 18:37:58 +00:00
|
|
|
static gboolean
|
2023-07-19 05:38:51 +00:00
|
|
|
gsk_vulkan_context_supports_format (GdkVulkanContext *context,
|
|
|
|
VkFormat format,
|
|
|
|
VkImageTiling tiling,
|
|
|
|
VkImageUsageFlags usage,
|
|
|
|
gsize width,
|
|
|
|
gsize height)
|
2023-06-14 18:37:58 +00:00
|
|
|
{
|
|
|
|
VkFormatProperties properties;
|
2023-07-19 05:38:51 +00:00
|
|
|
VkImageFormatProperties image_properties;
|
|
|
|
VkFormatFeatureFlags features, required;
|
|
|
|
VkResult res;
|
2023-06-14 18:37:58 +00:00
|
|
|
|
|
|
|
vkGetPhysicalDeviceFormatProperties (gdk_vulkan_context_get_physical_device (context),
|
|
|
|
format,
|
|
|
|
&properties);
|
|
|
|
|
2023-07-19 05:38:51 +00:00
|
|
|
switch ((int) tiling)
|
|
|
|
{
|
|
|
|
case VK_IMAGE_TILING_OPTIMAL:
|
|
|
|
features = properties.optimalTilingFeatures;
|
|
|
|
break;
|
|
|
|
case VK_IMAGE_TILING_LINEAR:
|
|
|
|
features = properties.optimalTilingFeatures;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
required = 0;
|
|
|
|
if (usage & VK_IMAGE_USAGE_SAMPLED_BIT)
|
|
|
|
required |= VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT;
|
|
|
|
if (usage & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT)
|
|
|
|
required |= VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT;
|
2023-06-14 18:37:58 +00:00
|
|
|
|
2023-07-19 05:38:51 +00:00
|
|
|
if ((features & required) != required)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
res = vkGetPhysicalDeviceImageFormatProperties (gdk_vulkan_context_get_physical_device (context),
|
|
|
|
format,
|
|
|
|
VK_IMAGE_TYPE_2D,
|
|
|
|
tiling,
|
|
|
|
usage,
|
|
|
|
0,
|
|
|
|
&image_properties);
|
|
|
|
if (res != VK_SUCCESS)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (image_properties.maxExtent.width < width ||
|
|
|
|
image_properties.maxExtent.height < height)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2023-06-14 18:37:58 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 18:36:14 +00:00
|
|
|
static void
|
2023-06-14 18:37:58 +00:00
|
|
|
gsk_vulkan_image_create_view (GskVulkanImage *self,
|
|
|
|
const GskMemoryFormatInfo *format)
|
2023-06-14 18:36:14 +00:00
|
|
|
{
|
|
|
|
GSK_VK_CHECK (vkCreateImageView, gdk_vulkan_context_get_device (self->vulkan),
|
|
|
|
&(VkImageViewCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
|
|
|
.image = self->vk_image,
|
|
|
|
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
2023-06-14 18:37:58 +00:00
|
|
|
.format = format->format,
|
|
|
|
.components = format->components,
|
2023-06-14 18:36:14 +00:00
|
|
|
.subresourceRange = {
|
|
|
|
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
.baseMipLevel = 0,
|
|
|
|
.levelCount = 1,
|
|
|
|
.baseArrayLayer = 0,
|
|
|
|
.layerCount = 1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->vk_image_view);
|
|
|
|
}
|
|
|
|
|
2016-12-06 13:42:46 +00:00
|
|
|
static GskVulkanImage *
|
2023-07-19 04:14:55 +00:00
|
|
|
gsk_vulkan_image_new (GdkVulkanContext *context,
|
|
|
|
GdkMemoryFormat format,
|
|
|
|
gsize width,
|
|
|
|
gsize height,
|
|
|
|
GskVulkanImagePostprocess allowed_postprocess,
|
|
|
|
VkImageTiling tiling,
|
|
|
|
VkImageUsageFlags usage,
|
|
|
|
VkPipelineStageFlags stage,
|
|
|
|
VkImageLayout layout,
|
|
|
|
VkAccessFlags access,
|
|
|
|
VkMemoryPropertyFlags memory)
|
2016-12-06 13:42:46 +00:00
|
|
|
{
|
|
|
|
VkMemoryRequirements requirements;
|
|
|
|
GskVulkanImage *self;
|
2023-06-14 18:37:58 +00:00
|
|
|
const GskMemoryFormatInfo *vk_format;
|
2016-12-06 13:42:46 +00:00
|
|
|
|
2023-05-09 22:08:24 +00:00
|
|
|
g_assert (width > 0 && height > 0);
|
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
while (TRUE)
|
2023-06-14 18:37:58 +00:00
|
|
|
{
|
2023-06-15 21:13:31 +00:00
|
|
|
for (vk_format = gsk_memory_format_get_vk_format_infos (format);
|
|
|
|
vk_format->format != VK_FORMAT_UNDEFINED;
|
|
|
|
vk_format++)
|
|
|
|
{
|
2023-07-19 04:14:55 +00:00
|
|
|
if (vk_format->postprocess & ~allowed_postprocess)
|
|
|
|
continue;
|
|
|
|
|
2023-07-19 05:38:51 +00:00
|
|
|
if (gsk_vulkan_context_supports_format (context,
|
|
|
|
vk_format->format,
|
|
|
|
tiling, usage,
|
|
|
|
width, height))
|
2023-06-15 21:13:31 +00:00
|
|
|
break;
|
2023-07-19 05:38:51 +00:00
|
|
|
|
|
|
|
if (tiling != VK_IMAGE_TILING_OPTIMAL &&
|
|
|
|
gsk_vulkan_context_supports_format (context,
|
|
|
|
vk_format->format,
|
|
|
|
VK_IMAGE_TILING_OPTIMAL, usage,
|
|
|
|
width, height))
|
|
|
|
{
|
|
|
|
tiling = VK_IMAGE_TILING_OPTIMAL;
|
|
|
|
break;
|
|
|
|
}
|
2023-06-15 21:13:31 +00:00
|
|
|
}
|
|
|
|
if (vk_format->format != VK_FORMAT_UNDEFINED)
|
2023-06-14 18:37:58 +00:00
|
|
|
break;
|
|
|
|
|
2023-06-15 21:13:31 +00:00
|
|
|
format = gsk_memory_format_get_fallback (format);
|
2023-06-14 18:37:58 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 19:19:56 +00:00
|
|
|
self = g_object_new (GSK_TYPE_VULKAN_IMAGE, NULL);
|
2016-12-06 13:42:46 +00:00
|
|
|
|
|
|
|
self->vulkan = g_object_ref (context);
|
2023-06-14 18:37:58 +00:00
|
|
|
self->format = format;
|
2023-06-17 14:05:09 +00:00
|
|
|
self->vk_format = vk_format->format;
|
2023-07-19 04:14:55 +00:00
|
|
|
self->postprocess = vk_format->postprocess;
|
2016-12-08 19:46:02 +00:00
|
|
|
self->width = width;
|
|
|
|
self->height = height;
|
2023-07-19 05:38:51 +00:00
|
|
|
self->vk_tiling = tiling;
|
2017-09-20 23:11:42 +00:00
|
|
|
self->vk_usage = usage;
|
2023-07-15 20:19:20 +00:00
|
|
|
self->vk_pipeline_stage = stage;
|
2017-09-20 23:11:42 +00:00
|
|
|
self->vk_image_layout = layout;
|
|
|
|
self->vk_access = access;
|
2016-12-06 13:42:46 +00:00
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreateImage, gdk_vulkan_context_get_device (context),
|
|
|
|
&(VkImageCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
|
|
|
|
.flags = 0,
|
|
|
|
.imageType = VK_IMAGE_TYPE_2D,
|
2023-06-14 18:37:58 +00:00
|
|
|
.format = vk_format->format,
|
2016-12-06 13:42:46 +00:00
|
|
|
.extent = { width, height, 1 },
|
|
|
|
.mipLevels = 1,
|
|
|
|
.arrayLayers = 1,
|
|
|
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
|
|
|
.tiling = tiling,
|
|
|
|
.usage = usage,
|
|
|
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
2017-09-20 23:11:42 +00:00
|
|
|
.initialLayout = self->vk_image_layout,
|
2016-12-06 13:42:46 +00:00
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->vk_image);
|
|
|
|
|
|
|
|
vkGetImageMemoryRequirements (gdk_vulkan_context_get_device (context),
|
|
|
|
self->vk_image,
|
|
|
|
&requirements);
|
|
|
|
|
|
|
|
self->memory = gsk_vulkan_memory_new (context,
|
|
|
|
requirements.memoryTypeBits,
|
|
|
|
memory,
|
|
|
|
requirements.size);
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkBindImageMemory, gdk_vulkan_context_get_device (context),
|
|
|
|
self->vk_image,
|
|
|
|
gsk_vulkan_memory_get_device_memory (self->memory),
|
|
|
|
0);
|
|
|
|
|
2023-06-14 18:37:58 +00:00
|
|
|
gsk_vulkan_image_create_view (self, vk_format);
|
2023-06-14 18:36:14 +00:00
|
|
|
|
|
|
|
return self;
|
2016-12-06 13:42:46 +00:00
|
|
|
}
|
|
|
|
|
2023-06-14 00:08:17 +00:00
|
|
|
GskVulkanImage *
|
2023-06-24 20:23:04 +00:00
|
|
|
gsk_vulkan_image_new_for_upload (GdkVulkanContext *context,
|
2023-06-14 18:37:58 +00:00
|
|
|
GdkMemoryFormat format,
|
2023-06-14 00:08:17 +00:00
|
|
|
gsize width,
|
|
|
|
gsize height)
|
|
|
|
{
|
|
|
|
GskVulkanImage *self;
|
|
|
|
|
2023-06-24 20:23:04 +00:00
|
|
|
self = gsk_vulkan_image_new (context,
|
2023-06-14 18:37:58 +00:00
|
|
|
format,
|
2023-06-14 00:08:17 +00:00
|
|
|
width,
|
|
|
|
height,
|
2023-07-19 04:14:55 +00:00
|
|
|
-1,
|
2023-06-14 01:21:24 +00:00
|
|
|
VK_IMAGE_TILING_LINEAR,
|
2023-06-14 00:08:17 +00:00
|
|
|
VK_IMAGE_USAGE_TRANSFER_DST_BIT |
|
|
|
|
VK_IMAGE_USAGE_SAMPLED_BIT,
|
2023-07-15 20:19:20 +00:00
|
|
|
VK_PIPELINE_STAGE_TRANSFER_BIT,
|
|
|
|
VK_IMAGE_LAYOUT_PREINITIALIZED,
|
2023-06-14 00:08:17 +00:00
|
|
|
VK_ACCESS_TRANSFER_WRITE_BIT,
|
|
|
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2023-07-11 13:14:22 +00:00
|
|
|
static gboolean
|
|
|
|
gsk_vulkan_image_can_map (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
if (GSK_DEBUG_CHECK (STAGING))
|
|
|
|
return FALSE;
|
|
|
|
|
2023-07-19 05:38:51 +00:00
|
|
|
if (self->vk_tiling != VK_IMAGE_TILING_LINEAR)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-07-15 20:19:20 +00:00
|
|
|
if (self->vk_image_layout != VK_IMAGE_LAYOUT_PREINITIALIZED &&
|
|
|
|
self->vk_image_layout != VK_IMAGE_LAYOUT_GENERAL)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-07-11 13:14:22 +00:00
|
|
|
return gsk_vulkan_memory_can_map (self->memory, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
guchar *
|
|
|
|
gsk_vulkan_image_try_map (GskVulkanImage *self,
|
|
|
|
gsize *out_stride)
|
|
|
|
{
|
|
|
|
VkImageSubresource image_res;
|
|
|
|
VkSubresourceLayout image_layout;
|
|
|
|
guchar *result;
|
|
|
|
|
|
|
|
if (!gsk_vulkan_image_can_map (self))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
result = gsk_vulkan_memory_map (self->memory);
|
|
|
|
if (result == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
image_res.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
|
|
image_res.mipLevel = 0;
|
|
|
|
image_res.arrayLayer = 0;
|
|
|
|
|
|
|
|
vkGetImageSubresourceLayout (gdk_vulkan_context_get_device (self->vulkan),
|
|
|
|
self->vk_image, &image_res, &image_layout);
|
|
|
|
|
|
|
|
*out_stride = image_layout.rowPitch;
|
|
|
|
|
|
|
|
return result + image_layout.offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_vulkan_image_unmap (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
gsk_vulkan_memory_unmap (self->memory);
|
|
|
|
}
|
|
|
|
|
2016-12-08 20:14:41 +00:00
|
|
|
GskVulkanImage *
|
|
|
|
gsk_vulkan_image_new_for_swapchain (GdkVulkanContext *context,
|
|
|
|
VkImage image,
|
|
|
|
VkFormat format,
|
|
|
|
gsize width,
|
|
|
|
gsize height)
|
|
|
|
{
|
|
|
|
GskVulkanImage *self;
|
|
|
|
|
|
|
|
self = g_object_new (GSK_TYPE_VULKAN_IMAGE, NULL);
|
|
|
|
|
|
|
|
self->vulkan = g_object_ref (context);
|
|
|
|
self->width = width;
|
|
|
|
self->height = height;
|
2023-07-19 05:38:51 +00:00
|
|
|
self->vk_tiling = VK_IMAGE_TILING_OPTIMAL;
|
2016-12-08 20:14:41 +00:00
|
|
|
self->vk_image = image;
|
2023-06-17 14:05:09 +00:00
|
|
|
self->vk_format = format;
|
2023-07-15 20:19:20 +00:00
|
|
|
self->vk_pipeline_stage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
|
|
|
self->vk_image_layout = VK_IMAGE_LAYOUT_UNDEFINED;
|
|
|
|
self->vk_access = 0;
|
2016-12-08 20:14:41 +00:00
|
|
|
|
2023-06-14 18:37:58 +00:00
|
|
|
gsk_vulkan_image_create_view (self,
|
|
|
|
&(GskMemoryFormatInfo) {
|
|
|
|
format,
|
|
|
|
{ VK_COMPONENT_SWIZZLE_R,
|
|
|
|
VK_COMPONENT_SWIZZLE_G,
|
|
|
|
VK_COMPONENT_SWIZZLE_B,
|
|
|
|
VK_COMPONENT_SWIZZLE_A
|
|
|
|
}
|
|
|
|
});
|
2016-12-08 20:14:41 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-12-22 18:01:07 +00:00
|
|
|
GskVulkanImage *
|
2017-09-20 23:11:42 +00:00
|
|
|
gsk_vulkan_image_new_for_atlas (GdkVulkanContext *context,
|
|
|
|
gsize width,
|
|
|
|
gsize height)
|
|
|
|
{
|
|
|
|
GskVulkanImage *self;
|
|
|
|
|
|
|
|
self = gsk_vulkan_image_new (context,
|
2023-06-14 18:37:58 +00:00
|
|
|
GDK_MEMORY_DEFAULT,
|
2017-09-20 23:11:42 +00:00
|
|
|
width,
|
|
|
|
height,
|
2023-07-19 04:14:55 +00:00
|
|
|
0,
|
2017-09-20 23:11:42 +00:00
|
|
|
VK_IMAGE_TILING_OPTIMAL,
|
|
|
|
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
2023-07-15 20:19:20 +00:00
|
|
|
VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT,
|
2017-09-20 23:11:42 +00:00
|
|
|
VK_IMAGE_LAYOUT_UNDEFINED,
|
|
|
|
0,
|
2016-12-22 18:01:07 +00:00
|
|
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-09-26 23:12:20 +00:00
|
|
|
GskVulkanImage *
|
2023-05-09 20:25:22 +00:00
|
|
|
gsk_vulkan_image_new_for_offscreen (GdkVulkanContext *context,
|
2023-06-14 19:32:26 +00:00
|
|
|
GdkMemoryFormat preferred_format,
|
2023-05-09 20:25:22 +00:00
|
|
|
gsize width,
|
|
|
|
gsize height)
|
2017-09-26 23:12:20 +00:00
|
|
|
{
|
|
|
|
GskVulkanImage *self;
|
|
|
|
|
|
|
|
self = gsk_vulkan_image_new (context,
|
2023-06-14 19:32:26 +00:00
|
|
|
preferred_format,
|
2017-09-26 23:12:20 +00:00
|
|
|
width,
|
|
|
|
height,
|
2023-07-19 04:14:55 +00:00
|
|
|
0,
|
2023-06-15 12:29:15 +00:00
|
|
|
VK_IMAGE_TILING_LINEAR,
|
2017-09-26 23:12:20 +00:00
|
|
|
VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
|
|
|
|
VK_IMAGE_USAGE_SAMPLED_BIT |
|
|
|
|
VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
|
2023-07-15 20:19:20 +00:00
|
|
|
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
|
2017-09-26 23:12:20 +00:00
|
|
|
VK_IMAGE_LAYOUT_UNDEFINED,
|
2023-05-09 20:25:22 +00:00
|
|
|
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
2017-09-26 23:12:20 +00:00
|
|
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT);
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-04-26 16:28:14 +00:00
|
|
|
static void
|
2016-12-08 19:19:56 +00:00
|
|
|
gsk_vulkan_image_finalize (GObject *object)
|
2016-12-06 13:42:46 +00:00
|
|
|
{
|
2016-12-08 19:19:56 +00:00
|
|
|
GskVulkanImage *self = GSK_VULKAN_IMAGE (object);
|
2023-07-08 18:10:04 +00:00
|
|
|
VkDevice device;
|
|
|
|
|
|
|
|
device = gdk_vulkan_context_get_device (self->vulkan);
|
|
|
|
|
|
|
|
if (self->vk_framebuffer != VK_NULL_HANDLE)
|
|
|
|
vkDestroyFramebuffer (device, self->vk_framebuffer, NULL);
|
2016-12-08 19:19:56 +00:00
|
|
|
|
2016-12-06 13:42:46 +00:00
|
|
|
if (self->vk_image_view != VK_NULL_HANDLE)
|
2023-07-08 18:10:04 +00:00
|
|
|
vkDestroyImageView (device, self->vk_image_view, NULL);
|
2016-12-06 13:42:46 +00:00
|
|
|
|
2016-12-08 20:14:41 +00:00
|
|
|
/* memory is NULL for for_swapchain() images, where we don't own
|
|
|
|
* the VkImage */
|
|
|
|
if (self->memory)
|
2023-07-08 18:10:04 +00:00
|
|
|
vkDestroyImage (device, self->vk_image, NULL);
|
2017-12-14 00:43:50 +00:00
|
|
|
|
2023-07-08 18:10:04 +00:00
|
|
|
g_clear_pointer (&self->memory, gsk_vulkan_memory_free);
|
2016-12-06 13:42:46 +00:00
|
|
|
|
|
|
|
g_object_unref (self->vulkan);
|
|
|
|
|
2016-12-08 19:19:56 +00:00
|
|
|
G_OBJECT_CLASS (gsk_vulkan_image_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_image_class_init (GskVulkanImageClass *klass)
|
|
|
|
{
|
|
|
|
G_OBJECT_CLASS (klass)->finalize = gsk_vulkan_image_finalize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_image_init (GskVulkanImage *self)
|
|
|
|
{
|
2016-12-06 13:42:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-08 18:10:04 +00:00
|
|
|
VkFramebuffer
|
|
|
|
gsk_vulkan_image_get_framebuffer (GskVulkanImage *self,
|
|
|
|
VkRenderPass render_pass)
|
|
|
|
{
|
|
|
|
if (self->vk_framebuffer)
|
|
|
|
return self->vk_framebuffer;
|
|
|
|
|
|
|
|
GSK_VK_CHECK (vkCreateFramebuffer, gdk_vulkan_context_get_device (self->vulkan),
|
|
|
|
&(VkFramebufferCreateInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
|
|
|
.renderPass = render_pass,
|
|
|
|
.attachmentCount = 1,
|
|
|
|
.pAttachments = (VkImageView[1]) {
|
|
|
|
self->vk_image_view,
|
|
|
|
},
|
|
|
|
.width = self->width,
|
|
|
|
.height = self->height,
|
|
|
|
.layers = 1
|
|
|
|
},
|
|
|
|
NULL,
|
|
|
|
&self->vk_framebuffer);
|
|
|
|
|
|
|
|
return self->vk_framebuffer;
|
|
|
|
}
|
|
|
|
|
2016-12-08 19:46:02 +00:00
|
|
|
gsize
|
|
|
|
gsk_vulkan_image_get_width (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
return self->width;
|
|
|
|
}
|
|
|
|
|
|
|
|
gsize
|
|
|
|
gsk_vulkan_image_get_height (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
return self->height;
|
|
|
|
}
|
|
|
|
|
2023-07-19 04:14:55 +00:00
|
|
|
GskVulkanImagePostprocess
|
|
|
|
gsk_vulkan_image_get_postprocess (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
return self->postprocess;
|
|
|
|
}
|
|
|
|
|
2016-12-06 13:42:46 +00:00
|
|
|
VkImage
|
2023-07-11 07:35:01 +00:00
|
|
|
gsk_vulkan_image_get_vk_image (GskVulkanImage *self)
|
2016-12-06 13:42:46 +00:00
|
|
|
{
|
|
|
|
return self->vk_image;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkImageView
|
|
|
|
gsk_vulkan_image_get_image_view (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
return self->vk_image_view;
|
|
|
|
}
|
2023-06-17 14:05:09 +00:00
|
|
|
|
2023-07-15 14:38:03 +00:00
|
|
|
VkPipelineStageFlags
|
|
|
|
gsk_vulkan_image_get_vk_pipeline_stage (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
return self->vk_pipeline_stage;
|
|
|
|
}
|
|
|
|
|
2023-07-11 07:35:01 +00:00
|
|
|
VkImageLayout
|
|
|
|
gsk_vulkan_image_get_vk_image_layout (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
return self->vk_image_layout;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkAccessFlags
|
|
|
|
gsk_vulkan_image_get_vk_access (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
return self->vk_access;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-07-15 14:38:03 +00:00
|
|
|
gsk_vulkan_image_set_vk_image_layout (GskVulkanImage *self,
|
|
|
|
VkPipelineStageFlags stage,
|
|
|
|
VkImageLayout image_layout,
|
|
|
|
VkAccessFlags access)
|
2023-07-11 07:35:01 +00:00
|
|
|
{
|
2023-07-15 14:38:03 +00:00
|
|
|
self->vk_pipeline_stage = stage;
|
2023-07-11 07:35:01 +00:00
|
|
|
self->vk_image_layout = image_layout;
|
|
|
|
self->vk_access = access;
|
|
|
|
}
|
|
|
|
|
2023-07-15 20:19:20 +00:00
|
|
|
void
|
|
|
|
gsk_vulkan_image_transition (GskVulkanImage *self,
|
|
|
|
VkCommandBuffer command_buffer,
|
|
|
|
VkPipelineStageFlags stage,
|
|
|
|
VkImageLayout image_layout,
|
|
|
|
VkAccessFlags access)
|
|
|
|
{
|
|
|
|
if (self->vk_pipeline_stage == stage &&
|
|
|
|
self->vk_image_layout == image_layout &&
|
|
|
|
self->vk_access == access)
|
|
|
|
return;
|
|
|
|
|
|
|
|
vkCmdPipelineBarrier (command_buffer,
|
|
|
|
self->vk_pipeline_stage,
|
|
|
|
stage,
|
|
|
|
0,
|
|
|
|
0, NULL,
|
|
|
|
0, NULL,
|
|
|
|
1, &(VkImageMemoryBarrier) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
|
|
|
|
.srcAccessMask = self->vk_access,
|
|
|
|
.dstAccessMask = access,
|
|
|
|
.oldLayout = self->vk_image_layout,
|
|
|
|
.newLayout = image_layout,
|
|
|
|
.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
|
|
|
.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED,
|
|
|
|
.image = self->vk_image,
|
|
|
|
.subresourceRange = {
|
|
|
|
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
|
|
|
.baseMipLevel = 0,
|
|
|
|
.levelCount = 1,
|
|
|
|
.baseArrayLayer = 0,
|
|
|
|
.layerCount = 1
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
gsk_vulkan_image_set_vk_image_layout (self, stage, image_layout, access);
|
|
|
|
}
|
|
|
|
|
2023-06-17 14:05:09 +00:00
|
|
|
VkFormat
|
|
|
|
gsk_vulkan_image_get_vk_format (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
return self->vk_format;
|
|
|
|
}
|
2023-06-24 22:56:13 +00:00
|
|
|
|
|
|
|
GdkMemoryFormat
|
|
|
|
gsk_vulkan_image_get_format (GskVulkanImage *self)
|
|
|
|
{
|
|
|
|
return self->format;
|
|
|
|
}
|
|
|
|
|