forked from AuroraMiddleware/gtk
vulkan: Turn swapchain image targets into GskVulkanImages
This gives us proper refcounting here, too. And there's no longer a difference between the different types of images.
This commit is contained in:
parent
17c11dd97b
commit
8756deec58
@ -109,14 +109,15 @@ gsk_vulkan_image_upload_data (GskVulkanImage *self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gsk_vulkan_image_ensure_view (GskVulkanImage *self)
|
gsk_vulkan_image_ensure_view (GskVulkanImage *self,
|
||||||
|
VkFormat format)
|
||||||
{
|
{
|
||||||
GSK_VK_CHECK (vkCreateImageView, gdk_vulkan_context_get_device (self->vulkan),
|
GSK_VK_CHECK (vkCreateImageView, gdk_vulkan_context_get_device (self->vulkan),
|
||||||
&(VkImageViewCreateInfo) {
|
&(VkImageViewCreateInfo) {
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||||
.image = self->vk_image,
|
.image = self->vk_image,
|
||||||
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
||||||
.format = VK_FORMAT_B8G8R8A8_SRGB,
|
.format = format,
|
||||||
.components = {
|
.components = {
|
||||||
.r = VK_COMPONENT_SWIZZLE_R,
|
.r = VK_COMPONENT_SWIZZLE_R,
|
||||||
.g = VK_COMPONENT_SWIZZLE_G,
|
.g = VK_COMPONENT_SWIZZLE_G,
|
||||||
@ -261,7 +262,7 @@ gsk_vulkan_image_new_from_data_via_staging_image (GdkVulkanContext *context,
|
|||||||
/* XXX: Is this okay or do we need to keep the staging image around until the commands execute */
|
/* XXX: Is this okay or do we need to keep the staging image around until the commands execute */
|
||||||
g_object_unref (staging);
|
g_object_unref (staging);
|
||||||
|
|
||||||
gsk_vulkan_image_ensure_view (self);
|
gsk_vulkan_image_ensure_view (self, VK_FORMAT_B8G8R8A8_SRGB);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -311,7 +312,7 @@ gsk_vulkan_image_new_from_data_directly (GdkVulkanContext *context,
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
gsk_vulkan_image_ensure_view (self);
|
gsk_vulkan_image_ensure_view (self, VK_FORMAT_B8G8R8A8_SRGB);
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
@ -330,6 +331,27 @@ gsk_vulkan_image_new_from_data (GdkVulkanContext *context,
|
|||||||
return gsk_vulkan_image_new_from_data_directly (context, command_buffer, data, width, height, stride);
|
return gsk_vulkan_image_new_from_data_directly (context, command_buffer, data, width, height, stride);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
self->vk_image = image;
|
||||||
|
|
||||||
|
gsk_vulkan_image_ensure_view (self, VK_FORMAT_B8G8R8A8_SRGB);
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gsk_vulkan_image_finalize (GObject *object)
|
gsk_vulkan_image_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
@ -342,11 +364,16 @@ gsk_vulkan_image_finalize (GObject *object)
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* memory is NULL for for_swapchain() images, where we don't own
|
||||||
|
* the VkImage */
|
||||||
|
if (self->memory)
|
||||||
|
{
|
||||||
gsk_vulkan_memory_free (self->memory);
|
gsk_vulkan_memory_free (self->memory);
|
||||||
|
|
||||||
vkDestroyImage (gdk_vulkan_context_get_device (self->vulkan),
|
vkDestroyImage (gdk_vulkan_context_get_device (self->vulkan),
|
||||||
self->vk_image,
|
self->vk_image,
|
||||||
NULL);
|
NULL);
|
||||||
|
}
|
||||||
|
|
||||||
g_object_unref (self->vulkan);
|
g_object_unref (self->vulkan);
|
||||||
|
|
||||||
|
@ -9,6 +9,11 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
G_DECLARE_FINAL_TYPE (GskVulkanImage, gsk_vulkan_image, GSK, VULKAN_IMAGE, GObject)
|
G_DECLARE_FINAL_TYPE (GskVulkanImage, gsk_vulkan_image, GSK, VULKAN_IMAGE, GObject)
|
||||||
|
|
||||||
|
GskVulkanImage * gsk_vulkan_image_new_for_swapchain (GdkVulkanContext *context,
|
||||||
|
VkImage image,
|
||||||
|
VkFormat format,
|
||||||
|
gsize width,
|
||||||
|
gsize height);
|
||||||
GskVulkanImage * gsk_vulkan_image_new_from_data (GdkVulkanContext *context,
|
GskVulkanImage * gsk_vulkan_image_new_from_data (GdkVulkanContext *context,
|
||||||
VkCommandBuffer command_buffer,
|
VkCommandBuffer command_buffer,
|
||||||
guchar *data,
|
guchar *data,
|
||||||
|
@ -57,56 +57,37 @@ struct _GskVulkanRendererClass
|
|||||||
G_DEFINE_TYPE (GskVulkanRenderer, gsk_vulkan_renderer, GSK_TYPE_RENDERER)
|
G_DEFINE_TYPE (GskVulkanRenderer, gsk_vulkan_renderer, GSK_TYPE_RENDERER)
|
||||||
|
|
||||||
struct _GskVulkanTarget {
|
struct _GskVulkanTarget {
|
||||||
VkImage image;
|
GskVulkanImage *image;
|
||||||
VkImageView image_view;
|
|
||||||
VkFramebuffer framebuffer;
|
VkFramebuffer framebuffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GskVulkanTarget *
|
static GskVulkanTarget *
|
||||||
gsk_vulkan_target_new_for_image (GskVulkanRenderer *self,
|
gsk_vulkan_target_new_for_image (GskVulkanRenderer *self,
|
||||||
VkImage image)
|
VkImage image,
|
||||||
|
gsize width,
|
||||||
|
gsize height)
|
||||||
{
|
{
|
||||||
GskVulkanTarget *target;
|
GskVulkanTarget *target;
|
||||||
GdkWindow *window;
|
|
||||||
VkDevice device;
|
VkDevice device;
|
||||||
|
|
||||||
device = gdk_vulkan_context_get_device (self->vulkan);
|
device = gdk_vulkan_context_get_device (self->vulkan);
|
||||||
window = gdk_draw_context_get_window (GDK_DRAW_CONTEXT (self->vulkan));
|
|
||||||
|
|
||||||
target = g_slice_new0 (GskVulkanTarget);
|
target = g_slice_new0 (GskVulkanTarget);
|
||||||
|
|
||||||
target->image = image;
|
target->image = gsk_vulkan_image_new_for_swapchain (self->vulkan,
|
||||||
|
image,
|
||||||
GSK_VK_CHECK (vkCreateImageView, device,
|
gdk_vulkan_context_get_image_format (self->vulkan),
|
||||||
&(VkImageViewCreateInfo) {
|
width, height);
|
||||||
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
|
||||||
.image = target->image,
|
|
||||||
.viewType = VK_IMAGE_VIEW_TYPE_2D,
|
|
||||||
.format = gdk_vulkan_context_get_image_format (self->vulkan),
|
|
||||||
.components = {
|
|
||||||
.r = VK_COMPONENT_SWIZZLE_R,
|
|
||||||
.g = VK_COMPONENT_SWIZZLE_G,
|
|
||||||
.b = VK_COMPONENT_SWIZZLE_B,
|
|
||||||
.a = VK_COMPONENT_SWIZZLE_A,
|
|
||||||
},
|
|
||||||
.subresourceRange = {
|
|
||||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
|
||||||
.baseMipLevel = 0,
|
|
||||||
.levelCount = 1,
|
|
||||||
.baseArrayLayer = 0,
|
|
||||||
.layerCount = 1,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
NULL,
|
|
||||||
&target->image_view);
|
|
||||||
GSK_VK_CHECK (vkCreateFramebuffer, device,
|
GSK_VK_CHECK (vkCreateFramebuffer, device,
|
||||||
&(VkFramebufferCreateInfo) {
|
&(VkFramebufferCreateInfo) {
|
||||||
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
||||||
.renderPass = self->render_pass,
|
.renderPass = self->render_pass,
|
||||||
.attachmentCount = 1,
|
.attachmentCount = 1,
|
||||||
.pAttachments = &target->image_view,
|
.pAttachments = (VkImageView[1]) {
|
||||||
.width = gdk_window_get_width (window),
|
gsk_vulkan_image_get_image_view (target->image)
|
||||||
.height = gdk_window_get_height (window),
|
},
|
||||||
|
.width = width,
|
||||||
|
.height = height,
|
||||||
.layers = 1
|
.layers = 1
|
||||||
},
|
},
|
||||||
NULL,
|
NULL,
|
||||||
@ -126,9 +107,8 @@ gsk_vulkan_target_free (GskVulkanRenderer *self,
|
|||||||
vkDestroyFramebuffer (device,
|
vkDestroyFramebuffer (device,
|
||||||
target->framebuffer,
|
target->framebuffer,
|
||||||
NULL);
|
NULL);
|
||||||
vkDestroyImageView (device,
|
|
||||||
target->image_view,
|
g_object_unref (target->image);
|
||||||
NULL);
|
|
||||||
|
|
||||||
g_slice_free (GskVulkanTarget, target);
|
g_slice_free (GskVulkanTarget, target);
|
||||||
}
|
}
|
||||||
@ -151,6 +131,9 @@ static void
|
|||||||
gsk_vulkan_renderer_update_images_cb (GdkVulkanContext *context,
|
gsk_vulkan_renderer_update_images_cb (GdkVulkanContext *context,
|
||||||
GskVulkanRenderer *self)
|
GskVulkanRenderer *self)
|
||||||
{
|
{
|
||||||
|
GdkWindow *window;
|
||||||
|
gint scale_factor;
|
||||||
|
gsize width, height;
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
gsk_vulkan_renderer_free_targets (self);
|
gsk_vulkan_renderer_free_targets (self);
|
||||||
@ -158,10 +141,16 @@ gsk_vulkan_renderer_update_images_cb (GdkVulkanContext *context,
|
|||||||
self->n_targets = gdk_vulkan_context_get_n_images (context);
|
self->n_targets = gdk_vulkan_context_get_n_images (context);
|
||||||
self->targets = g_new (GskVulkanTarget *, self->n_targets);
|
self->targets = g_new (GskVulkanTarget *, self->n_targets);
|
||||||
|
|
||||||
|
window = gsk_renderer_get_window (GSK_RENDERER (self));
|
||||||
|
scale_factor = gdk_window_get_scale_factor (window);
|
||||||
|
width = gdk_window_get_width (window) * scale_factor;
|
||||||
|
height = gdk_window_get_height (window) * scale_factor;
|
||||||
|
|
||||||
for (i = 0; i < self->n_targets; i++)
|
for (i = 0; i < self->n_targets; i++)
|
||||||
{
|
{
|
||||||
self->targets[i] = gsk_vulkan_target_new_for_image (self,
|
self->targets[i] = gsk_vulkan_target_new_for_image (self,
|
||||||
gdk_vulkan_context_get_image (context, i));
|
gdk_vulkan_context_get_image (context, i),
|
||||||
|
width, height);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user