2023-07-09 20:33:54 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskvulkanrenderpassopprivate.h"
|
|
|
|
|
|
|
|
#include "gskrendernodeprivate.h"
|
|
|
|
#include "gskvulkanprivate.h"
|
|
|
|
|
|
|
|
#include "gdk/gdkvulkancontextprivate.h"
|
|
|
|
|
|
|
|
typedef struct _GskVulkanRenderPassOp GskVulkanRenderPassOp;
|
|
|
|
|
|
|
|
struct _GskVulkanRenderPassOp
|
|
|
|
{
|
|
|
|
GskVulkanOp op;
|
|
|
|
|
|
|
|
GskVulkanImage *image;
|
|
|
|
GskVulkanRenderPass *render_pass;
|
2023-07-13 12:30:16 +00:00
|
|
|
cairo_rectangle_int_t area;
|
|
|
|
graphene_size_t viewport_size;
|
|
|
|
|
|
|
|
VkImageLayout initial_layout;
|
|
|
|
VkImageLayout final_layout;
|
2023-07-09 20:33:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_render_pass_op_finish (GskVulkanOp *op)
|
|
|
|
{
|
|
|
|
GskVulkanRenderPassOp *self = (GskVulkanRenderPassOp *) op;
|
|
|
|
|
|
|
|
g_object_unref (self->image);
|
|
|
|
gsk_vulkan_render_pass_free (self->render_pass);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_render_pass_op_print (GskVulkanOp *op,
|
|
|
|
GString *string,
|
|
|
|
guint indent)
|
|
|
|
{
|
|
|
|
GskVulkanRenderPassOp *self = (GskVulkanRenderPassOp *) op;
|
|
|
|
|
|
|
|
print_indent (string, indent);
|
|
|
|
g_string_append_printf (string, "begin-render-pass %zux%zu ",
|
|
|
|
gsk_vulkan_image_get_width (self->image),
|
|
|
|
gsk_vulkan_image_get_height (self->image));
|
|
|
|
print_newline (string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gsize
|
|
|
|
gsk_vulkan_render_pass_op_count_vertex_data (GskVulkanOp *op,
|
|
|
|
gsize n_bytes)
|
|
|
|
{
|
|
|
|
return n_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_render_pass_op_collect_vertex_data (GskVulkanOp *op,
|
|
|
|
guchar *data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_render_pass_op_reserve_descriptor_sets (GskVulkanOp *op,
|
|
|
|
GskVulkanRender *render)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static GskVulkanOp *
|
|
|
|
gsk_vulkan_render_pass_op_command (GskVulkanOp *op,
|
|
|
|
GskVulkanRender *render,
|
|
|
|
VkPipelineLayout pipeline_layout,
|
|
|
|
VkCommandBuffer command_buffer)
|
|
|
|
{
|
|
|
|
GskVulkanRenderPassOp *self = (GskVulkanRenderPassOp *) op;
|
2023-07-13 09:17:04 +00:00
|
|
|
VkPipeline current_pipeline = VK_NULL_HANDLE;
|
|
|
|
const GskVulkanOpClass *current_pipeline_class = NULL;
|
|
|
|
const char *current_pipeline_clip_type = NULL;
|
|
|
|
VkRenderPass vk_render_pass;
|
|
|
|
|
2023-07-13 12:30:16 +00:00
|
|
|
vk_render_pass = gsk_vulkan_render_get_render_pass (render,
|
|
|
|
gsk_vulkan_image_get_vk_format (self->image),
|
|
|
|
self->initial_layout,
|
|
|
|
self->final_layout);
|
|
|
|
|
|
|
|
|
|
|
|
vkCmdSetViewport (command_buffer,
|
|
|
|
0,
|
|
|
|
1,
|
|
|
|
&(VkViewport) {
|
|
|
|
.x = 0,
|
|
|
|
.y = 0,
|
|
|
|
.width = self->viewport_size.width,
|
|
|
|
.height = self->viewport_size.height,
|
|
|
|
.minDepth = 0,
|
|
|
|
.maxDepth = 1
|
|
|
|
});
|
|
|
|
|
|
|
|
vkCmdBeginRenderPass (command_buffer,
|
|
|
|
&(VkRenderPassBeginInfo) {
|
|
|
|
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
|
|
|
|
.renderPass = vk_render_pass,
|
|
|
|
.framebuffer = gsk_vulkan_image_get_framebuffer (self->image,
|
|
|
|
vk_render_pass),
|
|
|
|
.renderArea = {
|
|
|
|
{ self->area.x, self->area.y },
|
|
|
|
{ self->area.width, self->area.height }
|
|
|
|
},
|
|
|
|
.clearValueCount = 1,
|
|
|
|
.pClearValues = (VkClearValue [1]) {
|
|
|
|
{ .color = { .float32 = { 0.f, 0.f, 0.f, 0.f } } }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
VK_SUBPASS_CONTENTS_INLINE);
|
2023-07-13 09:17:04 +00:00
|
|
|
|
|
|
|
op = op->next;
|
2023-07-13 09:23:02 +00:00
|
|
|
while (op->op_class->stage != GSK_VULKAN_STAGE_END_PASS)
|
2023-07-13 09:17:04 +00:00
|
|
|
{
|
|
|
|
if (op->op_class->shader_name &&
|
|
|
|
(op->op_class != current_pipeline_class ||
|
|
|
|
current_pipeline_clip_type != op->clip_type))
|
|
|
|
{
|
|
|
|
current_pipeline = gsk_vulkan_render_get_pipeline (render,
|
|
|
|
op->op_class,
|
|
|
|
op->clip_type,
|
|
|
|
gsk_vulkan_image_get_vk_format (self->image),
|
|
|
|
vk_render_pass);
|
|
|
|
vkCmdBindPipeline (command_buffer,
|
|
|
|
VK_PIPELINE_BIND_POINT_GRAPHICS,
|
|
|
|
current_pipeline);
|
|
|
|
current_pipeline_class = op->op_class;
|
|
|
|
current_pipeline_clip_type = op->clip_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
op = gsk_vulkan_op_command (op, render, pipeline_layout, command_buffer);
|
|
|
|
}
|
|
|
|
|
2023-07-13 09:23:02 +00:00
|
|
|
op = gsk_vulkan_op_command (op, render, pipeline_layout, command_buffer);
|
2023-07-13 09:17:04 +00:00
|
|
|
|
|
|
|
return op;
|
2023-07-09 20:33:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const GskVulkanOpClass GSK_VULKAN_RENDER_PASS_OP_CLASS = {
|
|
|
|
GSK_VULKAN_OP_SIZE (GskVulkanRenderPassOp),
|
|
|
|
GSK_VULKAN_STAGE_BEGIN_PASS,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
gsk_vulkan_render_pass_op_finish,
|
|
|
|
gsk_vulkan_render_pass_op_print,
|
|
|
|
gsk_vulkan_render_pass_op_count_vertex_data,
|
|
|
|
gsk_vulkan_render_pass_op_collect_vertex_data,
|
|
|
|
gsk_vulkan_render_pass_op_reserve_descriptor_sets,
|
|
|
|
gsk_vulkan_render_pass_op_command
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _GskVulkanRenderPassEndOp GskVulkanRenderPassEndOp;
|
|
|
|
|
|
|
|
struct _GskVulkanRenderPassEndOp
|
|
|
|
{
|
|
|
|
GskVulkanOp op;
|
|
|
|
|
|
|
|
GskVulkanImage *image;
|
2023-07-14 21:05:19 +00:00
|
|
|
VkImageLayout final_layout;
|
2023-07-09 20:33:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_render_pass_end_op_finish (GskVulkanOp *op)
|
|
|
|
{
|
|
|
|
GskVulkanRenderPassEndOp *self = (GskVulkanRenderPassEndOp *) op;
|
|
|
|
|
|
|
|
g_object_unref (self->image);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_render_pass_end_op_print (GskVulkanOp *op,
|
|
|
|
GString *string,
|
|
|
|
guint indent)
|
|
|
|
{
|
|
|
|
GskVulkanRenderPassEndOp *self = (GskVulkanRenderPassEndOp *) op;
|
|
|
|
|
|
|
|
print_indent (string, indent);
|
|
|
|
g_string_append_printf (string, "end-render-pass ");
|
|
|
|
print_image (string, self->image);
|
|
|
|
print_newline (string);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gsize
|
|
|
|
gsk_vulkan_render_pass_end_op_count_vertex_data (GskVulkanOp *op,
|
|
|
|
gsize n_bytes)
|
|
|
|
{
|
|
|
|
return n_bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_render_pass_end_op_collect_vertex_data (GskVulkanOp *op,
|
|
|
|
guchar *data)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gsk_vulkan_render_pass_end_op_reserve_descriptor_sets (GskVulkanOp *op,
|
|
|
|
GskVulkanRender *render)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static GskVulkanOp *
|
|
|
|
gsk_vulkan_render_pass_end_op_command (GskVulkanOp *op,
|
|
|
|
GskVulkanRender *render,
|
|
|
|
VkPipelineLayout pipeline_layout,
|
|
|
|
VkCommandBuffer command_buffer)
|
|
|
|
{
|
2023-07-14 21:05:19 +00:00
|
|
|
GskVulkanRenderPassEndOp *self = (GskVulkanRenderPassEndOp *) op;
|
|
|
|
|
2023-07-09 20:33:54 +00:00
|
|
|
vkCmdEndRenderPass (command_buffer);
|
|
|
|
|
2023-07-14 21:05:19 +00:00
|
|
|
gsk_vulkan_image_set_vk_image_layout (self->image,
|
|
|
|
self->final_layout,
|
|
|
|
gsk_vulkan_image_get_vk_access (self->image));
|
2023-07-09 20:33:54 +00:00
|
|
|
return op->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GskVulkanOpClass GSK_VULKAN_RENDER_PASS_END_OP_CLASS = {
|
|
|
|
GSK_VULKAN_OP_SIZE (GskVulkanRenderPassEndOp),
|
|
|
|
GSK_VULKAN_STAGE_END_PASS,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
gsk_vulkan_render_pass_end_op_finish,
|
|
|
|
gsk_vulkan_render_pass_end_op_print,
|
|
|
|
gsk_vulkan_render_pass_end_op_count_vertex_data,
|
|
|
|
gsk_vulkan_render_pass_end_op_collect_vertex_data,
|
|
|
|
gsk_vulkan_render_pass_end_op_reserve_descriptor_sets,
|
|
|
|
gsk_vulkan_render_pass_end_op_command
|
|
|
|
};
|
|
|
|
|
2023-07-10 01:42:55 +00:00
|
|
|
void
|
|
|
|
gsk_vulkan_render_pass_op (GskVulkanRender *render,
|
|
|
|
GdkVulkanContext *context,
|
|
|
|
GskVulkanImage *image,
|
|
|
|
cairo_region_t *clip,
|
|
|
|
const graphene_vec2_t *scale,
|
|
|
|
const graphene_rect_t *viewport,
|
|
|
|
GskRenderNode *node,
|
2023-07-14 21:05:19 +00:00
|
|
|
VkImageLayout initial_layout,
|
|
|
|
VkImageLayout final_layout)
|
2023-07-10 01:42:55 +00:00
|
|
|
{
|
|
|
|
GskVulkanRenderPassOp *self;
|
|
|
|
GskVulkanRenderPassEndOp *end;
|
|
|
|
|
|
|
|
self = (GskVulkanRenderPassOp *) gsk_vulkan_op_alloc (render, &GSK_VULKAN_RENDER_PASS_OP_CLASS);
|
|
|
|
|
|
|
|
self->image = image;
|
2023-07-14 21:05:19 +00:00
|
|
|
self->initial_layout = initial_layout;
|
|
|
|
self->final_layout = final_layout;
|
2023-07-13 12:30:16 +00:00
|
|
|
cairo_region_get_extents (clip, &self->area);
|
|
|
|
self->viewport_size = viewport->size;
|
2023-07-10 01:42:55 +00:00
|
|
|
|
|
|
|
self->render_pass = gsk_vulkan_render_pass_new (context,
|
|
|
|
render,
|
|
|
|
self->image,
|
|
|
|
scale,
|
|
|
|
viewport,
|
|
|
|
clip,
|
2023-07-13 12:30:16 +00:00
|
|
|
node);
|
2023-07-10 01:42:55 +00:00
|
|
|
|
|
|
|
/* This invalidates the self pointer */
|
|
|
|
gsk_vulkan_render_pass_add (self->render_pass, render, node);
|
|
|
|
|
|
|
|
end = (GskVulkanRenderPassEndOp *) gsk_vulkan_op_alloc (render, &GSK_VULKAN_RENDER_PASS_END_OP_CLASS);
|
|
|
|
|
|
|
|
end->image = g_object_ref (image);
|
2023-07-14 21:05:19 +00:00
|
|
|
end->final_layout = final_layout;
|
2023-07-10 01:42:55 +00:00
|
|
|
}
|
|
|
|
|
2023-07-09 20:33:54 +00:00
|
|
|
GskVulkanImage *
|
|
|
|
gsk_vulkan_render_pass_op_offscreen (GskVulkanRender *render,
|
|
|
|
GdkVulkanContext *context,
|
|
|
|
const graphene_vec2_t *scale,
|
|
|
|
const graphene_rect_t *viewport,
|
|
|
|
GskRenderNode *node)
|
|
|
|
{
|
|
|
|
graphene_rect_t view;
|
2023-07-10 01:42:55 +00:00
|
|
|
GskVulkanImage *image;
|
2023-07-09 20:33:54 +00:00
|
|
|
cairo_region_t *clip;
|
|
|
|
float scale_x, scale_y;
|
|
|
|
|
|
|
|
scale_x = graphene_vec2_get_x (scale);
|
|
|
|
scale_y = graphene_vec2_get_y (scale);
|
|
|
|
view = GRAPHENE_RECT_INIT (scale_x * viewport->origin.x,
|
|
|
|
scale_y * viewport->origin.y,
|
|
|
|
ceil (scale_x * viewport->size.width),
|
|
|
|
ceil (scale_y * viewport->size.height));
|
|
|
|
|
|
|
|
image = gsk_vulkan_image_new_for_offscreen (context,
|
|
|
|
gdk_vulkan_context_get_offscreen_format (context,
|
|
|
|
gsk_render_node_get_preferred_depth (node)),
|
|
|
|
view.size.width, view.size.height);
|
|
|
|
|
|
|
|
clip = cairo_region_create_rectangle (&(cairo_rectangle_int_t) {
|
|
|
|
0, 0,
|
2023-07-10 01:42:55 +00:00
|
|
|
gsk_vulkan_image_get_width (image),
|
|
|
|
gsk_vulkan_image_get_height (image)
|
2023-07-09 20:33:54 +00:00
|
|
|
});
|
|
|
|
|
2023-07-10 01:42:55 +00:00
|
|
|
gsk_vulkan_render_pass_op (render,
|
|
|
|
context,
|
|
|
|
image,
|
|
|
|
clip,
|
|
|
|
scale,
|
|
|
|
&view,
|
|
|
|
node,
|
2023-07-14 21:05:19 +00:00
|
|
|
VK_IMAGE_LAYOUT_UNDEFINED,
|
|
|
|
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
2023-07-09 20:33:54 +00:00
|
|
|
|
|
|
|
cairo_region_destroy (clip);
|
|
|
|
|
2023-07-10 01:42:55 +00:00
|
|
|
return image;
|
2023-07-09 20:33:54 +00:00
|
|
|
}
|