[gtk+] vulkan: Change handling of push constants
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] vulkan: Change handling of push constants
- Date: Sat, 24 Dec 2016 05:21:57 +0000 (UTC)
commit 18b65a23789008a68c53e0430aa2dffadcc259f4
Author: Benjamin Otte <otte redhat com>
Date: Sat Dec 24 04:10:00 2016 +0100
vulkan: Change handling of push constants
Instead of storing the wire format, store the true structs and only
convert to the wire format when needed.
gsk/gskvulkanpushconstants.c | 42 ++++++++++++++++++----------------
gsk/gskvulkanpushconstantsprivate.h | 14 +++++++----
gsk/gskvulkanrenderpass.c | 3 +-
3 files changed, 32 insertions(+), 27 deletions(-)
---
diff --git a/gsk/gskvulkanpushconstants.c b/gsk/gskvulkanpushconstants.c
index 2b119fc..4487687 100644
--- a/gsk/gskvulkanpushconstants.c
+++ b/gsk/gskvulkanpushconstants.c
@@ -8,7 +8,7 @@ void
gsk_vulkan_push_constants_init (GskVulkanPushConstants *constants,
const graphene_matrix_t *mvp)
{
- gsk_vulkan_push_constants_set_mvp (constants, mvp);
+ graphene_matrix_init_from_matrix (&constants->mvp, mvp);
}
void
@@ -19,34 +19,36 @@ gsk_vulkan_push_constants_init_copy (GskVulkanPushConstants *self,
}
void
-gsk_vulkan_push_constants_set_mvp (GskVulkanPushConstants *self,
- const graphene_matrix_t *mvp)
+gsk_vulkan_push_constants_init_transform (GskVulkanPushConstants *self,
+ const GskVulkanPushConstants *src,
+ const graphene_matrix_t *transform)
+
{
- graphene_matrix_to_float (mvp, self->vertex.mvp);
+ graphene_matrix_multiply (transform, &src->mvp, &self->mvp);
}
-void
-gsk_vulkan_push_constants_multiply_mvp (GskVulkanPushConstants *self,
- const graphene_matrix_t *transform)
+static void
+gsk_vulkan_push_constants_wire_init (GskVulkanPushConstantsWire *wire,
+ const GskVulkanPushConstants *self)
{
- graphene_matrix_t old_mvp, new_mvp;
-
- graphene_matrix_init_from_float (&old_mvp, self->vertex.mvp);
- graphene_matrix_multiply (transform, &old_mvp, &new_mvp);
- gsk_vulkan_push_constants_set_mvp (self, &new_mvp);
+ graphene_matrix_to_float (&self->mvp, wire->vertex.mvp);
}
void
-gsk_vulkan_push_constants_push_vertex (GskVulkanPushConstants *self,
- VkCommandBuffer command_buffer,
- VkPipelineLayout pipeline_layout)
+gsk_vulkan_push_constants_push_vertex (const GskVulkanPushConstants *self,
+ VkCommandBuffer command_buffer,
+ VkPipelineLayout pipeline_layout)
{
+ GskVulkanPushConstantsWire wire;
+
+ gsk_vulkan_push_constants_wire_init (&wire, self);
+
vkCmdPushConstants (command_buffer,
pipeline_layout,
VK_SHADER_STAGE_VERTEX_BIT,
- G_STRUCT_OFFSET (GskVulkanPushConstants, vertex),
- sizeof (self->vertex),
- &self->vertex);
+ G_STRUCT_OFFSET (GskVulkanPushConstantsWire, vertex),
+ sizeof (wire.vertex),
+ &wire.vertex);
}
#if 0
@@ -76,8 +78,8 @@ gst_vulkan_push_constants_get_ranges (void)
static const VkPushConstantRange ranges[2] = {
{
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
- .offset = G_STRUCT_OFFSET (GskVulkanPushConstants, vertex),
- .size = sizeof (((GskVulkanPushConstants *) 0)->vertex)
+ .offset = G_STRUCT_OFFSET (GskVulkanPushConstantsWire, vertex),
+ .size = sizeof (((GskVulkanPushConstantsWire *) 0)->vertex)
#if 0
},
{
diff --git a/gsk/gskvulkanpushconstantsprivate.h b/gsk/gskvulkanpushconstantsprivate.h
index 6b86085..bdfd111 100644
--- a/gsk/gskvulkanpushconstantsprivate.h
+++ b/gsk/gskvulkanpushconstantsprivate.h
@@ -7,9 +7,15 @@
G_BEGIN_DECLS
typedef struct _GskVulkanPushConstants GskVulkanPushConstants;
+typedef struct _GskVulkanPushConstantsWire GskVulkanPushConstantsWire;
struct _GskVulkanPushConstants
{
+ graphene_matrix_t mvp;
+};
+
+struct _GskVulkanPushConstantsWire
+{
struct {
float mvp[16];
} vertex;
@@ -27,13 +33,11 @@ void gsk_vulkan_push_constants_init (GskVulk
const graphene_matrix_t
*mvp);
void gsk_vulkan_push_constants_init_copy (GskVulkanPushConstants
*self,
const GskVulkanPushConstants
*src);
-
-void gsk_vulkan_push_constants_set_mvp (GskVulkanPushConstants
*self,
- const graphene_matrix_t
*mvp);
-void gsk_vulkan_push_constants_multiply_mvp (GskVulkanPushConstants
*self,
+void gsk_vulkan_push_constants_init_transform (GskVulkanPushConstants
*self,
+ const GskVulkanPushConstants *src,
const graphene_matrix_t
*transform);
-void gsk_vulkan_push_constants_push_vertex (GskVulkanPushConstants
*self,
+void gsk_vulkan_push_constants_push_vertex (const GskVulkanPushConstants
*self,
VkCommandBuffer
command_buffer,
VkPipelineLayout
pipeline_layout);
diff --git a/gsk/gskvulkanrenderpass.c b/gsk/gskvulkanrenderpass.c
index 8a74cf7..796ba62 100644
--- a/gsk/gskvulkanrenderpass.c
+++ b/gsk/gskvulkanrenderpass.c
@@ -156,8 +156,7 @@ gsk_vulkan_render_pass_add_node (GskVulkanRenderPass *self,
gsk_transform_node_get_transform (node, &transform);
op.type = GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS;
- gsk_vulkan_push_constants_init_copy (&op.constants.constants, constants);
- gsk_vulkan_push_constants_multiply_mvp (&op.constants.constants, &transform);
+ gsk_vulkan_push_constants_init_transform (&op.constants.constants, constants, &transform);
g_array_append_val (self->render_ops, op);
graphene_matrix_transform_bounds (&transform, &clip->rect.bounds, &rect);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]