2016-12-14 06:21:21 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gskvulkanpushconstantsprivate.h"
|
|
|
|
|
2016-12-24 03:58:51 +00:00
|
|
|
#include "gskroundedrectprivate.h"
|
2021-03-06 00:35:04 +00:00
|
|
|
#include "gsktransform.h"
|
2016-12-14 06:21:21 +00:00
|
|
|
|
2017-01-17 04:20:07 +00:00
|
|
|
typedef struct _GskVulkanPushConstantsWire GskVulkanPushConstantsWire;
|
|
|
|
|
|
|
|
struct _GskVulkanPushConstantsWire
|
|
|
|
{
|
|
|
|
struct {
|
|
|
|
float mvp[16];
|
|
|
|
float clip[12];
|
|
|
|
} common;
|
|
|
|
};
|
|
|
|
|
2016-12-14 06:21:21 +00:00
|
|
|
void
|
|
|
|
gsk_vulkan_push_constants_init (GskVulkanPushConstants *constants,
|
2016-12-24 03:58:51 +00:00
|
|
|
const graphene_matrix_t *mvp,
|
|
|
|
const graphene_rect_t *viewport)
|
2016-12-14 06:21:21 +00:00
|
|
|
{
|
2016-12-24 03:10:00 +00:00
|
|
|
graphene_matrix_init_from_matrix (&constants->mvp, mvp);
|
2016-12-24 03:58:51 +00:00
|
|
|
gsk_vulkan_clip_init_empty (&constants->clip, viewport);
|
2016-12-14 06:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gsk_vulkan_push_constants_init_copy (GskVulkanPushConstants *self,
|
|
|
|
const GskVulkanPushConstants *src)
|
|
|
|
{
|
|
|
|
*self = *src;
|
|
|
|
}
|
|
|
|
|
2016-12-24 03:58:51 +00:00
|
|
|
gboolean
|
|
|
|
gsk_vulkan_push_constants_transform (GskVulkanPushConstants *self,
|
|
|
|
const GskVulkanPushConstants *src,
|
2021-03-06 00:35:04 +00:00
|
|
|
GskTransform *transform,
|
2016-12-24 03:58:51 +00:00
|
|
|
const graphene_rect_t *viewport)
|
2016-12-24 03:10:00 +00:00
|
|
|
|
2016-12-14 06:21:21 +00:00
|
|
|
{
|
2021-03-06 00:35:04 +00:00
|
|
|
graphene_matrix_t matrix;
|
|
|
|
|
2016-12-24 03:58:51 +00:00
|
|
|
if (!gsk_vulkan_clip_transform (&self->clip, &src->clip, transform, viewport))
|
|
|
|
return FALSE;
|
|
|
|
|
2021-03-06 00:35:04 +00:00
|
|
|
gsk_transform_to_matrix (transform, &matrix);
|
|
|
|
graphene_matrix_multiply (&matrix, &src->mvp, &self->mvp);
|
|
|
|
|
2016-12-24 03:58:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gsk_vulkan_push_constants_intersect_rect (GskVulkanPushConstants *self,
|
|
|
|
const GskVulkanPushConstants *src,
|
|
|
|
const graphene_rect_t *rect)
|
|
|
|
{
|
|
|
|
if (!gsk_vulkan_clip_intersect_rect (&self->clip, &src->clip, rect))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
graphene_matrix_init_from_matrix (&self->mvp, &src->mvp);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gsk_vulkan_push_constants_intersect_rounded (GskVulkanPushConstants *self,
|
|
|
|
const GskVulkanPushConstants *src,
|
|
|
|
const GskRoundedRect *rect)
|
|
|
|
{
|
|
|
|
if (!gsk_vulkan_clip_intersect_rounded_rect (&self->clip, &src->clip, rect))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
graphene_matrix_init_from_matrix (&self->mvp, &src->mvp);
|
|
|
|
return TRUE;
|
2016-12-14 06:21:21 +00:00
|
|
|
}
|
|
|
|
|
2016-12-24 03:10:00 +00:00
|
|
|
static void
|
|
|
|
gsk_vulkan_push_constants_wire_init (GskVulkanPushConstantsWire *wire,
|
|
|
|
const GskVulkanPushConstants *self)
|
2016-12-14 06:21:21 +00:00
|
|
|
{
|
2017-01-17 04:20:07 +00:00
|
|
|
graphene_matrix_to_float (&self->mvp, wire->common.mvp);
|
|
|
|
gsk_rounded_rect_to_float (&self->clip.rect, wire->common.clip);
|
2016-12-14 06:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-01-17 04:20:07 +00:00
|
|
|
gsk_vulkan_push_constants_push (const GskVulkanPushConstants *self,
|
|
|
|
VkCommandBuffer command_buffer,
|
|
|
|
VkPipelineLayout pipeline_layout)
|
2016-12-14 06:21:21 +00:00
|
|
|
{
|
2016-12-24 03:10:00 +00:00
|
|
|
GskVulkanPushConstantsWire wire;
|
|
|
|
|
|
|
|
gsk_vulkan_push_constants_wire_init (&wire, self);
|
|
|
|
|
2016-12-14 06:21:21 +00:00
|
|
|
vkCmdPushConstants (command_buffer,
|
|
|
|
pipeline_layout,
|
2017-01-17 04:20:07 +00:00
|
|
|
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
|
|
|
G_STRUCT_OFFSET (GskVulkanPushConstantsWire, common),
|
|
|
|
sizeof (wire.common),
|
|
|
|
&wire.common);
|
2016-12-14 06:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t
|
2017-09-23 17:15:30 +00:00
|
|
|
gsk_vulkan_push_constants_get_range_count (void)
|
2016-12-14 06:21:21 +00:00
|
|
|
{
|
2017-01-04 17:37:02 +00:00
|
|
|
return 1;
|
2016-12-14 06:21:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const VkPushConstantRange *
|
2017-09-23 17:15:30 +00:00
|
|
|
gsk_vulkan_push_constants_get_ranges (void)
|
2016-12-14 06:21:21 +00:00
|
|
|
{
|
2017-01-04 17:37:02 +00:00
|
|
|
static const VkPushConstantRange ranges[1] = {
|
2016-12-14 06:21:21 +00:00
|
|
|
{
|
2017-01-17 04:20:07 +00:00
|
|
|
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
|
|
|
.offset = G_STRUCT_OFFSET (GskVulkanPushConstantsWire, common),
|
|
|
|
.size = sizeof (((GskVulkanPushConstantsWire *) 0)->common)
|
2016-12-14 06:21:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return ranges;
|
|
|
|
}
|