From 57222cc64c9c83b5136dbb18c1ac723822db9794 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Fri, 12 May 2023 03:59:44 +0200 Subject: [PATCH] vulkan: Add scale to push constants This way, it can be pushed to the shaders --- gsk/vulkan/gskvulkanpushconstants.c | 6 +++++- gsk/vulkan/gskvulkanpushconstantsprivate.h | 1 + gsk/vulkan/gskvulkanrenderpass.c | 3 +++ gsk/vulkan/resources/constants.glsl | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gsk/vulkan/gskvulkanpushconstants.c b/gsk/vulkan/gskvulkanpushconstants.c index 456fff712b..ebc38275bb 100644 --- a/gsk/vulkan/gskvulkanpushconstants.c +++ b/gsk/vulkan/gskvulkanpushconstants.c @@ -12,6 +12,7 @@ struct _GskVulkanPushConstantsWire struct { float mvp[16]; float clip[12]; + float scale[2]; } common; }; @@ -23,22 +24,25 @@ 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, mvp, clip); + gsk_vulkan_push_constants_wire_init (&wire, scale, mvp, clip); vkCmdPushConstants (command_buffer, pipeline_layout, diff --git a/gsk/vulkan/gskvulkanpushconstantsprivate.h b/gsk/vulkan/gskvulkanpushconstantsprivate.h index 6b8470d674..1e04e50154 100644 --- a/gsk/vulkan/gskvulkanpushconstantsprivate.h +++ b/gsk/vulkan/gskvulkanpushconstantsprivate.h @@ -12,6 +12,7 @@ uint32_t gsk_vulkan_push_constants_get_range_count (void) G 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); diff --git a/gsk/vulkan/gskvulkanrenderpass.c b/gsk/vulkan/gskvulkanrenderpass.c index 93a6dd3024..ffe9e5bc3d 100644 --- a/gsk/vulkan/gskvulkanrenderpass.c +++ b/gsk/vulkan/gskvulkanrenderpass.c @@ -99,6 +99,7 @@ struct _GskVulkanOpPushConstants { GskVulkanOpType type; GskRenderNode *node; /* node that's the source of this op */ + graphene_vec2_t scale; graphene_matrix_t mvp; GskRoundedRect clip; }; @@ -250,6 +251,7 @@ gsk_vulkan_render_pass_append_push_constants (GskVulkanRenderPass *self, GskVulkanOp op = { .constants.type = GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS, .constants.node = node, + .constants.scale= state->scale, .constants.mvp = state->mvp, .constants.clip = state->clip.rect, }; @@ -2268,6 +2270,7 @@ gsk_vulkan_render_pass_draw_rect (GskVulkanRenderPass *self, for (int j = 0; j < layout_count; j++) gsk_vulkan_push_constants_push (command_buffer, pipeline_layout[j], + &op->constants.scale, &op->constants.mvp, &op->constants.clip); diff --git a/gsk/vulkan/resources/constants.glsl b/gsk/vulkan/resources/constants.glsl index 427f42bc1a..9fe24ad475 100644 --- a/gsk/vulkan/resources/constants.glsl +++ b/gsk/vulkan/resources/constants.glsl @@ -6,6 +6,7 @@ layout(push_constant) uniform PushConstants { vec4 clip_bounds; vec4 clip_widths; vec4 clip_heights; + vec2 scale; } push; #endif