forked from AuroraMiddleware/gtk
vulkan: Add push constants to fragment shader
That way we don't need to move the clip rounded rect manually through the vertex shader into the fragment shader but can just look at the push constants. Simplifies shaders a lot.
This commit is contained in:
parent
c7d899c535
commit
6a60e335cd
@ -4,6 +4,16 @@
|
||||
|
||||
#include "gskroundedrectprivate.h"
|
||||
|
||||
typedef struct _GskVulkanPushConstantsWire GskVulkanPushConstantsWire;
|
||||
|
||||
struct _GskVulkanPushConstantsWire
|
||||
{
|
||||
struct {
|
||||
float mvp[16];
|
||||
float clip[12];
|
||||
} common;
|
||||
};
|
||||
|
||||
void
|
||||
gsk_vulkan_push_constants_init (GskVulkanPushConstants *constants,
|
||||
const graphene_matrix_t *mvp,
|
||||
@ -62,14 +72,14 @@ static void
|
||||
gsk_vulkan_push_constants_wire_init (GskVulkanPushConstantsWire *wire,
|
||||
const GskVulkanPushConstants *self)
|
||||
{
|
||||
graphene_matrix_to_float (&self->mvp, wire->vertex.mvp);
|
||||
gsk_rounded_rect_to_float (&self->clip.rect, wire->vertex.clip);
|
||||
graphene_matrix_to_float (&self->mvp, wire->common.mvp);
|
||||
gsk_rounded_rect_to_float (&self->clip.rect, wire->common.clip);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_vulkan_push_constants_push_vertex (const GskVulkanPushConstants *self,
|
||||
VkCommandBuffer command_buffer,
|
||||
VkPipelineLayout pipeline_layout)
|
||||
gsk_vulkan_push_constants_push (const GskVulkanPushConstants *self,
|
||||
VkCommandBuffer command_buffer,
|
||||
VkPipelineLayout pipeline_layout)
|
||||
{
|
||||
GskVulkanPushConstantsWire wire;
|
||||
|
||||
@ -77,27 +87,12 @@ gsk_vulkan_push_constants_push_vertex (const GskVulkanPushConstants *self,
|
||||
|
||||
vkCmdPushConstants (command_buffer,
|
||||
pipeline_layout,
|
||||
VK_SHADER_STAGE_VERTEX_BIT,
|
||||
G_STRUCT_OFFSET (GskVulkanPushConstantsWire, vertex),
|
||||
sizeof (wire.vertex),
|
||||
&wire.vertex);
|
||||
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
G_STRUCT_OFFSET (GskVulkanPushConstantsWire, common),
|
||||
sizeof (wire.common),
|
||||
&wire.common);
|
||||
}
|
||||
|
||||
#if 0
|
||||
void
|
||||
gsk_vulkan_push_constants_push_fragment (GskVulkanPushConstants *self,
|
||||
VkCommandBuffer command_buffer,
|
||||
VkPipelineLayout pipeline_layout)
|
||||
{
|
||||
vkCmdPushConstants (command_buffer,
|
||||
pipeline_layout,
|
||||
VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
G_STRUCT_OFFSET (GskVulkanPushConstants, fragment),
|
||||
sizeof (self->fragment),
|
||||
&self->fragment);
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t
|
||||
gst_vulkan_push_constants_get_range_count (void)
|
||||
{
|
||||
@ -109,16 +104,9 @@ gst_vulkan_push_constants_get_ranges (void)
|
||||
{
|
||||
static const VkPushConstantRange ranges[1] = {
|
||||
{
|
||||
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT,
|
||||
.offset = G_STRUCT_OFFSET (GskVulkanPushConstantsWire, vertex),
|
||||
.size = sizeof (((GskVulkanPushConstantsWire *) 0)->vertex)
|
||||
#if 0
|
||||
},
|
||||
{
|
||||
.stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
.offset = G_STRUCT_OFFSET (GskVulkanPushConstants, fragment),
|
||||
.size = sizeof (((GskVulkanPushConstants *) 0)->fragment)
|
||||
#endif
|
||||
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
|
||||
.offset = G_STRUCT_OFFSET (GskVulkanPushConstantsWire, common),
|
||||
.size = sizeof (((GskVulkanPushConstantsWire *) 0)->common)
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,6 @@
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GskVulkanPushConstants GskVulkanPushConstants;
|
||||
typedef struct _GskVulkanPushConstantsWire GskVulkanPushConstantsWire;
|
||||
|
||||
struct _GskVulkanPushConstants
|
||||
{
|
||||
@ -16,18 +15,6 @@ struct _GskVulkanPushConstants
|
||||
GskVulkanClip clip;
|
||||
};
|
||||
|
||||
struct _GskVulkanPushConstantsWire
|
||||
{
|
||||
struct {
|
||||
float mvp[16];
|
||||
float clip[12];
|
||||
} vertex;
|
||||
#if 0
|
||||
struct {
|
||||
} fragment;
|
||||
#endif
|
||||
};
|
||||
|
||||
const VkPushConstantRange *
|
||||
gst_vulkan_push_constants_get_ranges (void) G_GNUC_PURE;
|
||||
uint32_t gst_vulkan_push_constants_get_range_count (void) G_GNUC_PURE;
|
||||
@ -49,7 +36,7 @@ gboolean gsk_vulkan_push_constants_intersect_rounded (GskVulk
|
||||
const GskVulkanPushConstants *src,
|
||||
const GskRoundedRect *rect);
|
||||
|
||||
void gsk_vulkan_push_constants_push_vertex (const GskVulkanPushConstants *self,
|
||||
void gsk_vulkan_push_constants_push (const GskVulkanPushConstants *self,
|
||||
VkCommandBuffer command_buffer,
|
||||
VkPipelineLayout pipeline_layout);
|
||||
|
||||
|
@ -886,9 +886,9 @@ gsk_vulkan_render_pass_draw (GskVulkanRenderPass *self,
|
||||
break;
|
||||
|
||||
case GSK_VULKAN_OP_PUSH_VERTEX_CONSTANTS:
|
||||
gsk_vulkan_push_constants_push_vertex (&op->constants.constants,
|
||||
command_buffer,
|
||||
gsk_vulkan_pipeline_layout_get_pipeline_layout (layout));
|
||||
gsk_vulkan_push_constants_push (&op->constants.constants,
|
||||
command_buffer,
|
||||
gsk_vulkan_pipeline_layout_get_pipeline_layout (layout));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -1,5 +1,7 @@
|
||||
#version 420 core
|
||||
|
||||
#include "constants.glsl"
|
||||
|
||||
struct RoundedRect {
|
||||
vec4 bounds;
|
||||
vec4 corners;
|
||||
@ -7,8 +9,6 @@ struct RoundedRect {
|
||||
|
||||
layout(location = 0) in vec2 inPos;
|
||||
layout(location = 1) in vec2 inTexCoord;
|
||||
layout(location = 2) in flat vec4 inClipBounds;
|
||||
layout(location = 3) in flat vec4 inClipWidths;
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D inTexture;
|
||||
|
||||
@ -51,7 +51,7 @@ float clip(vec2 pos, RoundedRect r) {
|
||||
|
||||
void main()
|
||||
{
|
||||
RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
|
||||
RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths);
|
||||
|
||||
color = texture (inTexture, inTexCoord) * clip (inPos, r);
|
||||
}
|
||||
|
Binary file not shown.
@ -7,8 +7,6 @@ layout(location = 1) in vec4 inTexRect;
|
||||
|
||||
layout(location = 0) out vec2 outPos;
|
||||
layout(location = 1) out vec2 outTexCoord;
|
||||
layout(location = 2) out flat vec4 outClipBounds;
|
||||
layout(location = 3) out flat vec4 outClipWidths;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
@ -37,8 +35,6 @@ void main() {
|
||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
||||
|
||||
outPos = pos;
|
||||
outClipBounds = push.clip_bounds;
|
||||
outClipWidths = push.clip_widths;
|
||||
|
||||
vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
|
||||
rect.zw / inRect.zw);
|
||||
|
Binary file not shown.
@ -1,5 +1,6 @@
|
||||
#version 420 core
|
||||
|
||||
#include "constants.glsl"
|
||||
#include "rounded-rect.glsl"
|
||||
|
||||
layout(location = 0) in vec2 inPos;
|
||||
@ -8,16 +9,13 @@ layout(location = 2) in vec4 inRect;
|
||||
layout(location = 3) in vec4 inCornerWidths;
|
||||
layout(location = 4) in vec4 inCornerHeights;
|
||||
layout(location = 5) in vec4 inBorderWidths;
|
||||
layout(location = 6) in flat vec4 inClipBounds;
|
||||
layout(location = 7) in flat vec4 inClipWidths;
|
||||
layout(location = 8) in flat vec4 inClipHeights;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
vec4
|
||||
clip (vec4 color)
|
||||
{
|
||||
RoundedRect r = RoundedRect (vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths, inClipHeights);
|
||||
RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths, push.clip_heights);
|
||||
|
||||
return color * rounded_rect_coverage (r, inPos);
|
||||
}
|
||||
|
Binary file not shown.
@ -14,9 +14,6 @@ layout(location = 2) out flat vec4 outRect;
|
||||
layout(location = 3) out flat vec4 outCornerWidths;
|
||||
layout(location = 4) out flat vec4 outCornerHeights;
|
||||
layout(location = 5) out flat vec4 outBorderWidths;
|
||||
layout(location = 6) out flat vec4 outClipBounds;
|
||||
layout(location = 7) out flat vec4 outClipWidths;
|
||||
layout(location = 8) out flat vec4 outClipHeights;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
@ -112,7 +109,4 @@ void main() {
|
||||
outCornerWidths = inCornerWidths;
|
||||
outCornerHeights = inCornerHeights;
|
||||
outBorderWidths = inBorderWidths;
|
||||
outClipBounds = push.clip_bounds;
|
||||
outClipWidths = push.clip_widths;
|
||||
outClipHeights = push.clip_heights;
|
||||
}
|
||||
|
Binary file not shown.
@ -1,9 +1,9 @@
|
||||
#version 420 core
|
||||
|
||||
#include "constants.glsl"
|
||||
|
||||
layout(location = 0) in vec2 inPos;
|
||||
layout(location = 1) in vec4 inColor;
|
||||
layout(location = 2) in vec4 inClipBounds;
|
||||
layout(location = 3) in vec4 inClipWidths;
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
@ -50,7 +50,7 @@ float clip(vec2 pos, RoundedRect r) {
|
||||
|
||||
void main()
|
||||
{
|
||||
RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
|
||||
RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths);
|
||||
|
||||
color = vec4(inColor.rgb * inColor.a, inColor.a) * clip (inPos, r);
|
||||
color = vec4(inColor.rgb * inColor.a, inColor.a) * clip (inPos, r);
|
||||
}
|
||||
|
Binary file not shown.
@ -7,8 +7,6 @@ layout(location = 1) in vec4 inColor;
|
||||
|
||||
layout(location = 0) out vec2 outPos;
|
||||
layout(location = 1) out flat vec4 outColor;
|
||||
layout(location = 2) out flat vec4 outClipBounds;
|
||||
layout(location = 3) out flat vec4 outClipWidths;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
@ -26,6 +24,4 @@ void main() {
|
||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
||||
outPos = pos;
|
||||
outColor = inColor;
|
||||
outClipBounds = push.clip_bounds;
|
||||
outClipWidths = push.clip_widths;
|
||||
}
|
||||
|
Binary file not shown.
@ -1,5 +1,7 @@
|
||||
#version 420 core
|
||||
|
||||
#include "constants.glsl"
|
||||
|
||||
struct RoundedRect {
|
||||
vec4 bounds;
|
||||
vec4 corners;
|
||||
@ -7,10 +9,8 @@ struct RoundedRect {
|
||||
|
||||
layout(location = 0) in vec2 inPos;
|
||||
layout(location = 1) in vec2 inTexCoord;
|
||||
layout(location = 2) in flat vec4 inClipBounds;
|
||||
layout(location = 3) in flat vec4 inClipWidths;
|
||||
layout(location = 4) in flat mat4 inColorMatrix;
|
||||
layout(location = 8) in flat vec4 inColorOffset;
|
||||
layout(location = 2) in flat mat4 inColorMatrix;
|
||||
layout(location = 6) in flat vec4 inColorOffset;
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D inTexture;
|
||||
|
||||
@ -70,7 +70,7 @@ color_matrix (vec4 color, mat4 color_matrix, vec4 color_offset)
|
||||
|
||||
void main()
|
||||
{
|
||||
RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
|
||||
RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths);
|
||||
|
||||
color = color_matrix (texture (inTexture, inTexCoord), inColorMatrix, inColorOffset) * clip (inPos, r);
|
||||
}
|
||||
|
Binary file not shown.
@ -9,10 +9,8 @@ layout(location = 6) in vec4 inColorOffset;
|
||||
|
||||
layout(location = 0) out vec2 outPos;
|
||||
layout(location = 1) out vec2 outTexCoord;
|
||||
layout(location = 2) out flat vec4 outClipBounds;
|
||||
layout(location = 3) out flat vec4 outClipWidths;
|
||||
layout(location = 4) out flat mat4 outColorMatrix;
|
||||
layout(location = 8) out flat vec4 outColorOffset;
|
||||
layout(location = 2) out flat mat4 outColorMatrix;
|
||||
layout(location = 6) out flat vec4 outColorOffset;
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
@ -41,8 +39,6 @@ void main() {
|
||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
||||
|
||||
outPos = pos;
|
||||
outClipBounds = push.clip_bounds;
|
||||
outClipWidths = push.clip_widths;
|
||||
|
||||
vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw,
|
||||
rect.zw / inRect.zw);
|
||||
|
Binary file not shown.
@ -1,5 +1,7 @@
|
||||
#version 420 core
|
||||
|
||||
#include "constants.glsl"
|
||||
|
||||
struct ColorStop {
|
||||
float offset;
|
||||
vec4 color;
|
||||
@ -14,9 +16,7 @@ layout(location = 0) in vec2 inPos;
|
||||
layout(location = 1) in float inGradientPos;
|
||||
layout(location = 2) in flat int inRepeating;
|
||||
layout(location = 3) in flat int inStopCount;
|
||||
layout(location = 4) in flat vec4 inClipBounds;
|
||||
layout(location = 5) in flat vec4 inClipWidths;
|
||||
layout(location = 6) in flat ColorStop inStops[8];
|
||||
layout(location = 4) in flat ColorStop inStops[8];
|
||||
|
||||
layout(location = 0) out vec4 outColor;
|
||||
|
||||
@ -57,7 +57,7 @@ float clip(vec2 pos, RoundedRect r) {
|
||||
|
||||
void main()
|
||||
{
|
||||
RoundedRect r = RoundedRect(vec4(inClipBounds.xy, inClipBounds.xy + inClipBounds.zw), inClipWidths);
|
||||
RoundedRect r = RoundedRect(vec4(push.clip_bounds.xy, push.clip_bounds.xy + push.clip_bounds.zw), push.clip_widths);
|
||||
|
||||
float pos;
|
||||
if (inRepeating != 0)
|
||||
|
Binary file not shown.
@ -27,9 +27,7 @@ layout(location = 0) out vec2 outPos;
|
||||
layout(location = 1) out float outGradientPos;
|
||||
layout(location = 2) out flat int outRepeating;
|
||||
layout(location = 3) out flat int outStopCount;
|
||||
layout(location = 4) out flat vec4 outClipBounds;
|
||||
layout(location = 5) out flat vec4 outClipWidths;
|
||||
layout(location = 6) out flat ColorStop outStops[8];
|
||||
layout(location = 4) out flat ColorStop outStops[8];
|
||||
|
||||
out gl_PerVertex {
|
||||
vec4 gl_Position;
|
||||
@ -56,8 +54,6 @@ void main() {
|
||||
gl_Position = push.mvp * vec4 (pos, 0.0, 1.0);
|
||||
outPos = pos;
|
||||
outGradientPos = get_gradient_pos (pos);
|
||||
outClipBounds = push.clip_bounds;
|
||||
outClipWidths = push.clip_widths;
|
||||
outRepeating = inRepeating;
|
||||
outStopCount = inStopCount;
|
||||
outStops[0].offset = inOffsets0[0];
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user