vulkan: Turn push constants into an op
This removes the last remaining original op from the gskvulkanrenderpass.c, so that file got some cleanup, too.
This commit is contained in:
@@ -126,7 +126,7 @@ if have_vulkan
|
||||
'vulkan/gskvulkanop.c',
|
||||
'vulkan/gskvulkanoutsetshadowop.c',
|
||||
'vulkan/gskvulkanpipeline.c',
|
||||
'vulkan/gskvulkanpushconstants.c',
|
||||
'vulkan/gskvulkanpushconstantsop.c',
|
||||
'vulkan/gskvulkanrender.c',
|
||||
'vulkan/gskvulkanrenderer.c',
|
||||
'vulkan/gskvulkanrenderpass.c',
|
||||
|
||||
@@ -1,73 +0,0 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gskvulkanpushconstantsprivate.h"
|
||||
|
||||
#include "gskroundedrectprivate.h"
|
||||
#include "gsktransform.h"
|
||||
|
||||
typedef struct _GskVulkanPushConstantsWire GskVulkanPushConstantsWire;
|
||||
|
||||
struct _GskVulkanPushConstantsWire
|
||||
{
|
||||
struct {
|
||||
float mvp[16];
|
||||
float clip[12];
|
||||
float scale[2];
|
||||
} common;
|
||||
};
|
||||
|
||||
/* This is the value we know every conformant GPU must provide.
|
||||
* See value for maxPushConstantsSize in table 55 of
|
||||
* https://registry.khronos.org/vulkan/specs/1.3-extensions/html/vkspec.html#limits-minmax
|
||||
*/
|
||||
G_STATIC_ASSERT (sizeof (GskVulkanPushConstantsWire) <= 128);
|
||||
|
||||
static void
|
||||
gsk_vulkan_push_constants_wire_init (GskVulkanPushConstantsWire *wire,
|
||||
const graphene_vec2_t *scale,
|
||||
const graphene_matrix_t *mvp,
|
||||
const GskRoundedRect *clip)
|
||||
{
|
||||
graphene_matrix_to_float (mvp, wire->common.mvp);
|
||||
gsk_rounded_rect_to_float (clip, graphene_point_zero (), wire->common.clip);
|
||||
graphene_vec2_to_float (scale, wire->common.scale);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_vulkan_push_constants_push (VkCommandBuffer command_buffer,
|
||||
VkPipelineLayout pipeline_layout,
|
||||
const graphene_vec2_t *scale,
|
||||
const graphene_matrix_t *mvp,
|
||||
const GskRoundedRect *clip)
|
||||
{
|
||||
GskVulkanPushConstantsWire wire;
|
||||
|
||||
gsk_vulkan_push_constants_wire_init (&wire, scale, mvp, clip);
|
||||
|
||||
vkCmdPushConstants (command_buffer,
|
||||
pipeline_layout,
|
||||
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
G_STRUCT_OFFSET (GskVulkanPushConstantsWire, common),
|
||||
sizeof (wire.common),
|
||||
&wire.common);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
gsk_vulkan_push_constants_get_range_count (void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
const VkPushConstantRange *
|
||||
gsk_vulkan_push_constants_get_ranges (void)
|
||||
{
|
||||
static const VkPushConstantRange ranges[1] = {
|
||||
{
|
||||
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
.offset = G_STRUCT_OFFSET (GskVulkanPushConstantsWire, common),
|
||||
.size = sizeof (((GskVulkanPushConstantsWire *) 0)->common)
|
||||
}
|
||||
};
|
||||
|
||||
return ranges;
|
||||
}
|
||||
126
gsk/vulkan/gskvulkanpushconstantsop.c
Normal file
126
gsk/vulkan/gskvulkanpushconstantsop.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gskvulkanpushconstantsopprivate.h"
|
||||
|
||||
#include "gskroundedrectprivate.h"
|
||||
|
||||
typedef struct _GskVulkanPushConstantsOp GskVulkanPushConstantsOp;
|
||||
typedef struct _GskVulkanPushConstantsInstance GskVulkanPushConstantsInstance;
|
||||
|
||||
struct _GskVulkanPushConstantsInstance
|
||||
{
|
||||
float mvp[16];
|
||||
float clip[12];
|
||||
float scale[2];
|
||||
};
|
||||
|
||||
struct _GskVulkanPushConstantsOp
|
||||
{
|
||||
GskVulkanOp op;
|
||||
|
||||
GskVulkanPushConstantsInstance instance;
|
||||
};
|
||||
|
||||
uint32_t
|
||||
gsk_vulkan_push_constants_get_range_count (void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
const VkPushConstantRange *
|
||||
gsk_vulkan_push_constants_get_ranges (void)
|
||||
{
|
||||
static const VkPushConstantRange ranges[1] = {
|
||||
{
|
||||
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
.offset = 0,
|
||||
.size = sizeof (GskVulkanPushConstantsInstance)
|
||||
}
|
||||
};
|
||||
|
||||
return ranges;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_push_constants_op_finish (GskVulkanOp *op)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_push_constants_op_upload (GskVulkanOp *op,
|
||||
GskVulkanRenderPass *pass,
|
||||
GskVulkanRender *render,
|
||||
GskVulkanUploader *uploader)
|
||||
{
|
||||
}
|
||||
|
||||
static gsize
|
||||
gsk_vulkan_push_constants_op_count_vertex_data (GskVulkanOp *op,
|
||||
gsize n_bytes)
|
||||
{
|
||||
return n_bytes;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_push_constants_op_collect_vertex_data (GskVulkanOp *op,
|
||||
GskVulkanRenderPass *pass,
|
||||
GskVulkanRender *render,
|
||||
guchar *data)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_push_constants_op_reserve_descriptor_sets (GskVulkanOp *op,
|
||||
GskVulkanRender *render)
|
||||
{
|
||||
}
|
||||
|
||||
static VkPipeline
|
||||
gsk_vulkan_push_constants_op_get_pipeline (GskVulkanOp *op)
|
||||
{
|
||||
return VK_NULL_HANDLE;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_push_constants_op_command (GskVulkanOp *op,
|
||||
GskVulkanRender *render,
|
||||
VkPipelineLayout pipeline_layout,
|
||||
VkCommandBuffer command_buffer)
|
||||
{
|
||||
GskVulkanPushConstantsOp *self = (GskVulkanPushConstantsOp *) op;
|
||||
|
||||
vkCmdPushConstants (command_buffer,
|
||||
pipeline_layout,
|
||||
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
0,
|
||||
sizeof (self->instance),
|
||||
&self->instance);
|
||||
}
|
||||
|
||||
static const GskVulkanOpClass GSK_VULKAN_PUSH_CONSTANTS_OP_CLASS = {
|
||||
GSK_VULKAN_OP_SIZE (GskVulkanPushConstantsOp),
|
||||
NULL,
|
||||
NULL,
|
||||
gsk_vulkan_push_constants_op_finish,
|
||||
gsk_vulkan_push_constants_op_upload,
|
||||
gsk_vulkan_push_constants_op_count_vertex_data,
|
||||
gsk_vulkan_push_constants_op_collect_vertex_data,
|
||||
gsk_vulkan_push_constants_op_reserve_descriptor_sets,
|
||||
gsk_vulkan_push_constants_op_get_pipeline,
|
||||
gsk_vulkan_push_constants_op_command
|
||||
};
|
||||
|
||||
void
|
||||
gsk_vulkan_push_constants_op (GskVulkanRenderPass *render_pass,
|
||||
const graphene_vec2_t *scale,
|
||||
const graphene_matrix_t *mvp,
|
||||
const GskRoundedRect *clip)
|
||||
{
|
||||
GskVulkanPushConstantsOp *self;
|
||||
|
||||
self = (GskVulkanPushConstantsOp *) gsk_vulkan_op_alloc (render_pass, &GSK_VULKAN_PUSH_CONSTANTS_OP_CLASS);
|
||||
|
||||
graphene_matrix_to_float (mvp, self->instance.mvp);
|
||||
gsk_rounded_rect_to_float (clip, graphene_point_zero (), self->instance.clip);
|
||||
graphene_vec2_to_float (scale, self->instance.scale);
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <graphene.h>
|
||||
#include "gskvulkanclipprivate.h"
|
||||
#include "gskvulkanopprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -10,11 +8,11 @@ const VkPushConstantRange *
|
||||
gsk_vulkan_push_constants_get_ranges (void) G_GNUC_PURE;
|
||||
uint32_t gsk_vulkan_push_constants_get_range_count (void) G_GNUC_PURE;
|
||||
|
||||
void gsk_vulkan_push_constants_push (VkCommandBuffer command_buffer,
|
||||
VkPipelineLayout pipeline_layout,
|
||||
void gsk_vulkan_push_constants_op (GskVulkanRenderPass *render_pass,
|
||||
const graphene_vec2_t *scale,
|
||||
const graphene_matrix_t *mvp,
|
||||
const GskRoundedRect *clip);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -9,11 +9,10 @@
|
||||
#include "gskvulkancommandpoolprivate.h"
|
||||
#include "gskvulkanglyphcacheprivate.h"
|
||||
#include "gskvulkanpipelineprivate.h"
|
||||
#include "gskvulkanpushconstantsopprivate.h"
|
||||
#include "gskvulkanrendererprivate.h"
|
||||
#include "gskvulkanrenderpassprivate.h"
|
||||
|
||||
#include "gskvulkanpushconstantsprivate.h"
|
||||
|
||||
#include "gdk/gdkvulkancontextprivate.h"
|
||||
|
||||
#define DESCRIPTOR_POOL_MAXITEMS 50000
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
#include "gskvulkanimageprivate.h"
|
||||
#include "gskvulkanoffscreenopprivate.h"
|
||||
#include "gskvulkanoutsetshadowopprivate.h"
|
||||
#include "gskvulkanpushconstantsprivate.h"
|
||||
#include "gskvulkanpushconstantsopprivate.h"
|
||||
#include "gskvulkanscissoropprivate.h"
|
||||
#include "gskvulkantextureopprivate.h"
|
||||
#include "gskvulkanuploadcairoopprivate.h"
|
||||
@@ -44,38 +44,6 @@
|
||||
|
||||
typedef struct _GskVulkanParseState GskVulkanParseState;
|
||||
|
||||
typedef struct _GskVulkanOpAny GskVulkanOpAny;
|
||||
typedef union _GskVulkanOpAll GskVulkanOpAll;
|
||||
typedef struct _GskVulkanOpPushConstants GskVulkanOpPushConstants;
|
||||
|
||||
typedef enum {
|
||||
/* GskVulkanOpPushConstants */
|
||||
GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS,
|
||||
} GskVulkanOpType;
|
||||
|
||||
struct _GskVulkanOpPushConstants
|
||||
{
|
||||
GskVulkanOp base;
|
||||
GskVulkanOpType type;
|
||||
GskRenderNode *node; /* node that's the source of this op */
|
||||
graphene_vec2_t scale;
|
||||
graphene_matrix_t mvp;
|
||||
GskRoundedRect clip;
|
||||
};
|
||||
|
||||
struct _GskVulkanOpAny
|
||||
{
|
||||
GskVulkanOp base;
|
||||
GskVulkanOpType type;
|
||||
GskRenderNode *node; /* node that's the source of this op */
|
||||
};
|
||||
|
||||
union _GskVulkanOpAll
|
||||
{
|
||||
GskVulkanOpAny any;
|
||||
GskVulkanOpPushConstants constants;
|
||||
};
|
||||
|
||||
struct _GskVulkanRenderPass
|
||||
{
|
||||
GdkVulkanContext *vulkan;
|
||||
@@ -257,10 +225,6 @@ gsk_vulkan_render_pass_alloc_op (GskVulkanRenderPass *self,
|
||||
return gsk_vulkan_render_ops_index (&self->render_ops, pos);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_render_pass_add_op (GskVulkanRenderPass *self,
|
||||
GskVulkanOp *op);
|
||||
|
||||
static void
|
||||
gsk_vulkan_render_pass_append_scissor (GskVulkanRenderPass *self,
|
||||
GskRenderNode *node,
|
||||
@@ -274,22 +238,17 @@ gsk_vulkan_render_pass_append_push_constants (GskVulkanRenderPass *self,
|
||||
GskRenderNode *node,
|
||||
const GskVulkanParseState *state)
|
||||
{
|
||||
GskVulkanOpPushConstants op = {
|
||||
.type = GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS,
|
||||
.node = node,
|
||||
.scale = state->scale,
|
||||
.clip = state->clip.rect,
|
||||
};
|
||||
graphene_matrix_t mvp;
|
||||
|
||||
if (state->modelview)
|
||||
{
|
||||
gsk_transform_to_matrix (state->modelview, &op.mvp);
|
||||
graphene_matrix_multiply (&op.mvp, &state->projection, &op.mvp);
|
||||
gsk_transform_to_matrix (state->modelview, &mvp);
|
||||
graphene_matrix_multiply (&mvp, &state->projection, &mvp);
|
||||
}
|
||||
else
|
||||
graphene_matrix_init_from_matrix (&op.mvp, &state->projection);
|
||||
graphene_matrix_init_from_matrix (&mvp, &state->projection);
|
||||
|
||||
gsk_vulkan_render_pass_add_op (self, (GskVulkanOp *) &op);
|
||||
gsk_vulkan_push_constants_op (self, &state->scale, &mvp, &state->clip.rect);
|
||||
}
|
||||
|
||||
#define FALLBACK(...) G_STMT_START { \
|
||||
@@ -1428,23 +1387,6 @@ gsk_vulkan_render_pass_upload (GskVulkanRenderPass *self,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_render_op_upload (GskVulkanOp *op_,
|
||||
GskVulkanRenderPass *self,
|
||||
GskVulkanRender *render,
|
||||
GskVulkanUploader *uploader)
|
||||
{
|
||||
GskVulkanOpAll *op = (GskVulkanOpAll *) op_;
|
||||
|
||||
switch (op->any.type)
|
||||
{
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static gsize
|
||||
gsk_vulkan_render_pass_count_vertex_data (GskVulkanRenderPass *self)
|
||||
{
|
||||
@@ -1463,24 +1405,6 @@ gsk_vulkan_render_pass_count_vertex_data (GskVulkanRenderPass *self)
|
||||
return n_bytes;
|
||||
}
|
||||
|
||||
static gsize
|
||||
gsk_vulkan_render_op_count_vertex_data (GskVulkanOp *op_,
|
||||
gsize n_bytes)
|
||||
{
|
||||
GskVulkanOpAll *op = (GskVulkanOpAll *) op_;
|
||||
|
||||
switch (op->any.type)
|
||||
{
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
|
||||
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
|
||||
break;
|
||||
}
|
||||
|
||||
return n_bytes;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_render_pass_collect_vertex_data (GskVulkanRenderPass *self,
|
||||
GskVulkanRender *render,
|
||||
@@ -1497,23 +1421,6 @@ gsk_vulkan_render_pass_collect_vertex_data (GskVulkanRenderPass *self,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_render_op_collect_vertex_data (GskVulkanOp *op_,
|
||||
GskVulkanRenderPass *pass,
|
||||
GskVulkanRender *render,
|
||||
guchar *data)
|
||||
{
|
||||
GskVulkanOpAll *op = (GskVulkanOpAll *) op_;
|
||||
|
||||
switch (op->any.type)
|
||||
{
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static GskVulkanBuffer *
|
||||
gsk_vulkan_render_pass_get_vertex_data (GskVulkanRenderPass *self,
|
||||
GskVulkanRender *render)
|
||||
@@ -1567,22 +1474,6 @@ gsk_vulkan_render_pass_reserve_descriptor_sets (GskVulkanRenderPass *self,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_render_op_reserve_descriptor_sets (GskVulkanOp *op_,
|
||||
GskVulkanRender *render)
|
||||
{
|
||||
GskVulkanOpAll *op = (GskVulkanOpAll *) op_;
|
||||
|
||||
switch (op->any.type)
|
||||
{
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
|
||||
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass *self,
|
||||
GskVulkanRender *render,
|
||||
@@ -1634,46 +1525,6 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass *self,
|
||||
}
|
||||
}
|
||||
|
||||
static VkPipeline
|
||||
gsk_vulkan_render_op_get_pipeline (GskVulkanOp *op_)
|
||||
{
|
||||
GskVulkanOpAll *op = (GskVulkanOpAll *) op_;
|
||||
|
||||
switch (op->any.type)
|
||||
{
|
||||
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
|
||||
return NULL;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_render_op_command (GskVulkanOp *op_,
|
||||
GskVulkanRender *render,
|
||||
VkPipelineLayout pipeline_layout,
|
||||
VkCommandBuffer command_buffer)
|
||||
{
|
||||
GskVulkanOpAll *op = (GskVulkanOpAll *) op_;
|
||||
|
||||
switch (op->any.type)
|
||||
{
|
||||
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
|
||||
gsk_vulkan_push_constants_push (command_buffer,
|
||||
pipeline_layout,
|
||||
&op->constants.scale,
|
||||
&op->constants.mvp,
|
||||
&op->constants.clip);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gsk_vulkan_render_pass_draw (GskVulkanRenderPass *self,
|
||||
GskVulkanRender *render,
|
||||
@@ -1719,33 +1570,3 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass *self,
|
||||
vkCmdEndRenderPass (command_buffer);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_vulkan_render_op_finish (GskVulkanOp *op)
|
||||
{
|
||||
}
|
||||
|
||||
static const GskVulkanOpClass GSK_VULKAN_OP_ALL_CLASS = {
|
||||
sizeof (GskVulkanOpAll),
|
||||
NULL,
|
||||
NULL,
|
||||
gsk_vulkan_render_op_finish,
|
||||
gsk_vulkan_render_op_upload,
|
||||
gsk_vulkan_render_op_count_vertex_data,
|
||||
gsk_vulkan_render_op_collect_vertex_data,
|
||||
gsk_vulkan_render_op_reserve_descriptor_sets,
|
||||
gsk_vulkan_render_op_get_pipeline,
|
||||
gsk_vulkan_render_op_command
|
||||
};
|
||||
|
||||
static void
|
||||
gsk_vulkan_render_pass_add_op (GskVulkanRenderPass *self,
|
||||
GskVulkanOp *op)
|
||||
{
|
||||
GskVulkanOpAll *alloc;
|
||||
|
||||
alloc = gsk_vulkan_render_pass_alloc_op (self, GSK_VULKAN_OP_ALL_CLASS.size);
|
||||
|
||||
op->op_class = &GSK_VULKAN_OP_ALL_CLASS;
|
||||
*alloc = *(GskVulkanOpAll *) op;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user