gtk/gsk/vulkan/gskvulkanuploadop.c
Benjamin Otte 2aba50efa0 vulkan: Move the render ops to the Render
This is a massive refactoring because it collects all the renderops
of all renderpasses into one long array in the Render object.

Lots of code in there is still flaky and needs cleanup. That will
follow in further commits.

Other than that it does work fine though.
2023-07-16 12:13:00 +02:00

114 lines
3.2 KiB
C

#include "config.h"
#include "gskvulkanuploadopprivate.h"
#include "gskvulkanprivate.h"
typedef struct _GskVulkanUploadOp GskVulkanUploadOp;
struct _GskVulkanUploadOp
{
GskVulkanOp op;
GskVulkanImage *image;
GdkTexture *texture;
};
static void
gsk_vulkan_upload_op_finish (GskVulkanOp *op)
{
GskVulkanUploadOp *self = (GskVulkanUploadOp *) op;
g_object_unref (self->image);
g_object_unref (self->texture);
}
static void
gsk_vulkan_upload_op_print (GskVulkanOp *op,
GString *string,
guint indent)
{
GskVulkanUploadOp *self = (GskVulkanUploadOp *) op;
print_indent (string, indent);
g_string_append (string, "upload ");
print_image (string, self->image);
print_newline (string);
}
static void
gsk_vulkan_upload_op_upload (GskVulkanOp *op,
GskVulkanUploader *uploader)
{
GskVulkanUploadOp *self = (GskVulkanUploadOp *) op;
GdkTextureDownloader *downloader;
GskVulkanImageMap map;
downloader = gdk_texture_downloader_new (self->texture);
gdk_texture_downloader_set_format (downloader, gsk_vulkan_image_get_format (self->image));
gsk_vulkan_image_map_memory (self->image, uploader, GSK_VULKAN_WRITE, &map);
gdk_texture_downloader_download_into (downloader, map.data, map.stride);
gsk_vulkan_image_unmap_memory (self->image, uploader, &map);
gdk_texture_downloader_free (downloader);
}
static gsize
gsk_vulkan_upload_op_count_vertex_data (GskVulkanOp *op,
gsize n_bytes)
{
return n_bytes;
}
static void
gsk_vulkan_upload_op_collect_vertex_data (GskVulkanOp *op,
guchar *data)
{
}
static void
gsk_vulkan_upload_op_reserve_descriptor_sets (GskVulkanOp *op,
GskVulkanRender *render)
{
}
static GskVulkanOp *
gsk_vulkan_upload_op_command (GskVulkanOp *op,
GskVulkanRender *render,
VkPipelineLayout pipeline_layout,
VkCommandBuffer command_buffer)
{
return op->next;
}
static const GskVulkanOpClass GSK_VULKAN_UPLOAD_OP_CLASS = {
GSK_VULKAN_OP_SIZE (GskVulkanUploadOp),
GSK_VULKAN_STAGE_UPLOAD,
NULL,
NULL,
gsk_vulkan_upload_op_finish,
gsk_vulkan_upload_op_print,
gsk_vulkan_upload_op_upload,
gsk_vulkan_upload_op_count_vertex_data,
gsk_vulkan_upload_op_collect_vertex_data,
gsk_vulkan_upload_op_reserve_descriptor_sets,
gsk_vulkan_upload_op_command
};
GskVulkanImage *
gsk_vulkan_upload_op (GskVulkanRender *render,
GdkVulkanContext *context,
GdkTexture *texture)
{
GskVulkanUploadOp *self;
self = (GskVulkanUploadOp *) gsk_vulkan_op_alloc (render, &GSK_VULKAN_UPLOAD_OP_CLASS);
self->texture = g_object_ref (texture);
self->image = gsk_vulkan_image_new_for_upload (context,
gdk_texture_get_format (texture),
gdk_texture_get_width (texture),
gdk_texture_get_height (texture));
return self->image;
}