diff --git a/gsk/Makefile.am b/gsk/Makefile.am index 06ed18e97e..9d13253956 100644 --- a/gsk/Makefile.am +++ b/gsk/Makefile.am @@ -62,39 +62,28 @@ gsk_private_vulkan_include_shaders = \ resources/vulkan/clip.vert.glsl \ resources/vulkan/constants.glsl \ resources/vulkan/rounded-rect.glsl +gsk_private_vulkan_fragment_shaders = \ + resources/vulkan/blend.frag \ + resources/vulkan/border.frag \ + resources/vulkan/color.frag \ + resources/vulkan/color-matrix.frag \ + resources/vulkan/linear.frag +gsk_private_vulkan_vertex_shaders = \ + resources/vulkan/blend.vert \ + resources/vulkan/border.vert \ + resources/vulkan/color.vert \ + resources/vulkan/color-matrix.vert \ + resources/vulkan/linear.vert gsk_private_vulkan_shaders = \ - resources/vulkan/blend-clip.frag.glsl \ - resources/vulkan/blend-clip-rounded.frag.glsl \ - resources/vulkan/blend-clip-rounded.vert.glsl \ - resources/vulkan/blend-clip.vert.glsl \ - resources/vulkan/blend.frag.glsl \ - resources/vulkan/blend.vert.glsl \ - resources/vulkan/border-clip.frag.glsl \ - resources/vulkan/border-clip.vert.glsl \ - resources/vulkan/border-clip-rounded.frag.glsl \ - resources/vulkan/border-clip-rounded.vert.glsl \ - resources/vulkan/border.frag.glsl \ - resources/vulkan/border.vert.glsl \ - resources/vulkan/color-clip.frag.glsl \ - resources/vulkan/color-clip-rounded.frag.glsl \ - resources/vulkan/color-clip-rounded.vert.glsl \ - resources/vulkan/color-clip.vert.glsl \ - resources/vulkan/color.frag.glsl \ - resources/vulkan/color.vert.glsl \ - resources/vulkan/color-matrix-clip.frag.glsl \ - resources/vulkan/color-matrix-clip-rounded.frag.glsl \ - resources/vulkan/color-matrix-clip-rounded.vert.glsl \ - resources/vulkan/color-matrix-clip.vert.glsl \ - resources/vulkan/color-matrix.frag.glsl \ - resources/vulkan/color-matrix.vert.glsl \ - resources/vulkan/linear-clip.frag.glsl \ - resources/vulkan/linear-clip-rounded.frag.glsl \ - resources/vulkan/linear-clip-rounded.vert.glsl \ - resources/vulkan/linear-clip.vert.glsl \ - resources/vulkan/linear.frag.glsl \ - resources/vulkan/linear.vert.glsl + $(gsk_private_vulkan_fragment_shaders) \ + $(gsk_private_vulkan_vertex_shaders) gsk_private_vulkan_compiled_shaders = \ - $(gsk_private_vulkan_shaders:.glsl=.spv) + $(gsk_private_vulkan_fragment_shaders:.frag=.frag.spv) \ + $(gsk_private_vulkan_vertex_shaders:.vert=.vert.spv) \ + $(gsk_private_vulkan_fragment_shaders:.frag=-clip.frag.spv) \ + $(gsk_private_vulkan_vertex_shaders:.vert=-clip.vert.spv) \ + $(gsk_private_vulkan_fragment_shaders:.frag=-clip-rounded.frag.spv) \ + $(gsk_private_vulkan_vertex_shaders:.vert=-clip-rounded.vert.spv) endif gsk_public_source_h = \ @@ -180,13 +169,29 @@ resource_files = \ $(gsk_private_vulkan_compiled_shaders) \ $(gsk_private_vulkan_shaders) -resources/vulkan/%.frag.spv: resources/vulkan/%.frag.glsl +resources/vulkan/%-clip-rounded.frag.spv: resources/vulkan/%.frag @if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi - $(AM_V_GEN) $(GLSLC) -fshader-stage=fragment -o $@.tmp $< && mv $@.tmp $@ + $(AM_V_GEN) $(GLSLC) -fshader-stage=fragment -DCLIP_ROUNDED_RECT -o $@.tmp $< && mv $@.tmp $@ -resources/vulkan/%.vert.spv: resources/vulkan/%.vert.glsl +resources/vulkan/%-clip-rounded.vert.spv: resources/vulkan/%.vert @if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi - $(AM_V_GEN) $(GLSLC) -fshader-stage=vertex -o $@.tmp $< && mv $@.tmp $@ + $(AM_V_GEN) $(GLSLC) -fshader-stage=vertex -DCLIP_ROUNDED_RECT -o $@.tmp $< && mv $@.tmp $@ + +resources/vulkan/%-clip.frag.spv: resources/vulkan/%.frag + @if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi + $(AM_V_GEN) $(GLSLC) -fshader-stage=fragment -DCLIP_RECT -o $@.tmp $< && mv $@.tmp $@ + +resources/vulkan/%-clip.vert.spv: resources/vulkan/%.vert + @if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi + $(AM_V_GEN) $(GLSLC) -fshader-stage=vertex -DCLIP_RECT -o $@.tmp $< && mv $@.tmp $@ + +resources/vulkan/%.frag.spv: resources/vulkan/%.frag + @if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi + $(AM_V_GEN) $(GLSLC) -fshader-stage=fragment -DCLIP_NONE -o $@.tmp $< && mv $@.tmp $@ + +resources/vulkan/%.vert.spv: resources/vulkan/%.vert + @if test -z "$(GLSLC)"; then echo "Missing glslc. See https://github.com/google/shaderc"; exit 1; fi + $(AM_V_GEN) $(GLSLC) -fshader-stage=vertex -DCLIP_NONE -o $@.tmp $< && mv $@.tmp $@ gsk.resources.xml: Makefile.am $(AM_V_GEN) echo "" > $@; \ diff --git a/gsk/resources/vulkan/blend-clip.frag.glsl b/gsk/resources/vulkan/blend-clip.frag.glsl deleted file mode 100644 index 4575c49848..0000000000 --- a/gsk/resources/vulkan/blend-clip.frag.glsl +++ /dev/null @@ -1,12 +0,0 @@ -#version 420 core - -layout(location = 0) in vec2 inTexCoord; - -layout(set = 0, binding = 0) uniform sampler2D inTexture; - -layout(location = 0) out vec4 color; - -void main() -{ - color = texture (inTexture, inTexCoord); -} diff --git a/gsk/resources/vulkan/blend-clip.frag.spv b/gsk/resources/vulkan/blend-clip.frag.spv index ef5dc6b6bf..9d337c7202 100644 Binary files a/gsk/resources/vulkan/blend-clip.frag.spv and b/gsk/resources/vulkan/blend-clip.frag.spv differ diff --git a/gsk/resources/vulkan/blend-clip.vert.glsl b/gsk/resources/vulkan/blend-clip.vert.glsl deleted file mode 100644 index 88ad7c75e6..0000000000 --- a/gsk/resources/vulkan/blend-clip.vert.glsl +++ /dev/null @@ -1,32 +0,0 @@ -#version 420 core - -#define CLIP_RECT -#include "clip.vert.glsl" - -layout(location = 0) in vec4 inRect; -layout(location = 1) in vec4 inTexRect; - -layout(location = 0) out vec2 outTexCoord; - -out gl_PerVertex { - vec4 gl_Position; -}; - -vec2 offsets[6] = { vec2(0.0, 0.0), - vec2(1.0, 0.0), - vec2(0.0, 1.0), - vec2(0.0, 1.0), - vec2(1.0, 0.0), - vec2(1.0, 1.0) }; - -void main() { - vec4 rect = clip (inRect); - vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex]; - gl_Position = push.mvp * vec4 (pos, 0.0, 1.0); - - vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw, - rect.zw / inRect.zw); - texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy, - inTexRect.zw * texrect.zw); - outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex]; -} diff --git a/gsk/resources/vulkan/blend-clip.vert.spv b/gsk/resources/vulkan/blend-clip.vert.spv index c8840cd5b8..cb6a9dadbb 100644 Binary files a/gsk/resources/vulkan/blend-clip.vert.spv and b/gsk/resources/vulkan/blend-clip.vert.spv differ diff --git a/gsk/resources/vulkan/blend-clip-rounded.frag.glsl b/gsk/resources/vulkan/blend.frag similarity index 91% rename from gsk/resources/vulkan/blend-clip-rounded.frag.glsl rename to gsk/resources/vulkan/blend.frag index 81bd003923..ee9eb459a9 100644 --- a/gsk/resources/vulkan/blend-clip-rounded.frag.glsl +++ b/gsk/resources/vulkan/blend.frag @@ -1,6 +1,5 @@ #version 420 core -#define CLIP_ROUNDED_RECT #include "clip.frag.glsl" layout(location = 0) in vec2 inPos; diff --git a/gsk/resources/vulkan/blend.frag.spv b/gsk/resources/vulkan/blend.frag.spv index 9dcff6d120..9d337c7202 100644 Binary files a/gsk/resources/vulkan/blend.frag.spv and b/gsk/resources/vulkan/blend.frag.spv differ diff --git a/gsk/resources/vulkan/blend-clip-rounded.vert.glsl b/gsk/resources/vulkan/blend.vert similarity index 97% rename from gsk/resources/vulkan/blend-clip-rounded.vert.glsl rename to gsk/resources/vulkan/blend.vert index fadf4b9247..c9bbb40906 100644 --- a/gsk/resources/vulkan/blend-clip-rounded.vert.glsl +++ b/gsk/resources/vulkan/blend.vert @@ -1,6 +1,5 @@ #version 420 core -#define CLIP_ROUNDED_RECT #include "clip.vert.glsl" layout(location = 0) in vec4 inRect; diff --git a/gsk/resources/vulkan/blend.vert.spv b/gsk/resources/vulkan/blend.vert.spv index 962a1b4e18..e814653f9b 100644 Binary files a/gsk/resources/vulkan/blend.vert.spv and b/gsk/resources/vulkan/blend.vert.spv differ diff --git a/gsk/resources/vulkan/border-clip-rounded.frag.spv b/gsk/resources/vulkan/border-clip-rounded.frag.spv index 3be544337c..690c02be05 100644 Binary files a/gsk/resources/vulkan/border-clip-rounded.frag.spv and b/gsk/resources/vulkan/border-clip-rounded.frag.spv differ diff --git a/gsk/resources/vulkan/border-clip-rounded.vert.glsl b/gsk/resources/vulkan/border-clip-rounded.vert.glsl deleted file mode 100644 index ed11255ad5..0000000000 --- a/gsk/resources/vulkan/border-clip-rounded.vert.glsl +++ /dev/null @@ -1,103 +0,0 @@ -#version 420 core - -#define CLIP_ROUNDED_RECT -#include "clip.vert.glsl" - -layout(location = 0) in vec4 inRect; -layout(location = 1) in vec4 inCornerWidths; -layout(location = 2) in vec4 inCornerHeights; -layout(location = 3) in vec4 inBorderWidths; -layout(location = 4) in mat4 inBorderColors; - -layout(location = 0) out vec2 outPos; -layout(location = 1) out flat vec4 outColor; -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; - -out gl_PerVertex { - vec4 gl_Position; -}; - -vec2 offsets[6] = { vec2(0.0, 0.0), - vec2(1.0, 0.0), - vec2(0.0, 1.0), - vec2(1.0, 1.0), - vec2(0.0, 1.0), - vec2(1.0, 0.0) }; - -#define TOP 0 -#define RIGHT 1 -#define BOTTOM 2 -#define LEFT 3 - -#define TOP_LEFT 0 -#define TOP_RIGHT 1 -#define BOTTOM_RIGHT 2 -#define BOTTOM_LEFT 3 - -#define SLICE_TOP_LEFT 0 -#define SLICE_TOP 1 -#define SLICE_TOP_RIGHT 2 -#define SLICE_RIGHT 3 -#define SLICE_BOTTOM_RIGHT 4 -#define SLICE_BOTTOM 5 -#define SLICE_BOTTOM_LEFT 6 -#define SLICE_LEFT 7 - -void main() { - int slice_index = gl_VertexIndex / 6; - int vert_index = gl_VertexIndex % 6; - - vec4 corner_widths = max (inCornerWidths, inBorderWidths.wyyw); - vec4 corner_heights = max (inCornerHeights, inBorderWidths.xxzz); - - vec4 rect; - - switch (slice_index) - { - case SLICE_TOP_LEFT: - rect = vec4(inRect.xy, corner_widths[TOP_LEFT], corner_heights[TOP_LEFT]); - vert_index = (vert_index + 3) % 6; - break; - case SLICE_TOP: - rect = vec4(inRect.x + corner_widths[TOP_LEFT], inRect.y, inRect.z - corner_widths[TOP_LEFT] - corner_widths[TOP_RIGHT], inBorderWidths[TOP]); - outColor = inBorderColors[TOP]; - break; - case SLICE_TOP_RIGHT: - rect = vec4(inRect.x + inRect.z - corner_widths[TOP_RIGHT], inRect.y, corner_widths[TOP_RIGHT], corner_heights[TOP_RIGHT]); - break; - case SLICE_RIGHT: - rect = vec4(inRect.x + inRect.z - inBorderWidths[RIGHT], inRect.y + corner_heights[TOP_RIGHT], inBorderWidths[RIGHT], inRect.w - corner_heights[TOP_RIGHT] - corner_heights[BOTTOM_RIGHT]); - outColor = inBorderColors[RIGHT]; - break; - case SLICE_BOTTOM_RIGHT: - rect = vec4(inRect.x + inRect.z - corner_widths[BOTTOM_RIGHT], inRect.y + inRect.w - corner_heights[BOTTOM_RIGHT], corner_widths[BOTTOM_RIGHT], corner_heights[BOTTOM_RIGHT]); - break; - case SLICE_BOTTOM: - rect = vec4(inRect.x + corner_widths[BOTTOM_LEFT], inRect.y + inRect.w - inBorderWidths[BOTTOM], inRect.z - corner_widths[BOTTOM_LEFT] - corner_widths[BOTTOM_RIGHT], inBorderWidths[BOTTOM]); - break; - case SLICE_BOTTOM_LEFT: - rect = vec4(inRect.x, inRect.y + inRect.w - corner_heights[BOTTOM_LEFT], corner_widths[BOTTOM_LEFT], corner_heights[BOTTOM_LEFT]); - vert_index = (vert_index + 3) % 6; - break; - case SLICE_LEFT: - rect = vec4(inRect.x, inRect.y + corner_heights[TOP_LEFT], inBorderWidths[LEFT], inRect.w - corner_heights[TOP_LEFT] - corner_heights[BOTTOM_LEFT]); - break; - } - - rect = clip (rect); - vec2 pos; - if ((slice_index % 4) != 0 || (vert_index % 3) != 2) - pos = rect.xy + rect.zw * offsets[vert_index]; - else - pos = rect.xy + rect.zw * vec2(1.0 - offsets[vert_index].x, offsets[vert_index].y); - gl_Position = push.mvp * vec4 (pos, 0.0, 1.0); - outColor = inBorderColors[((gl_VertexIndex / 3 + 15) / 4) % 4]; - outPos = pos; - outRect = inRect; - outCornerWidths = inCornerWidths; - outCornerHeights = inCornerHeights; - outBorderWidths = inBorderWidths; -} diff --git a/gsk/resources/vulkan/border-clip.frag.glsl b/gsk/resources/vulkan/border-clip.frag.glsl deleted file mode 100644 index 5f9d7090a1..0000000000 --- a/gsk/resources/vulkan/border-clip.frag.glsl +++ /dev/null @@ -1,23 +0,0 @@ -#version 420 core - -#include "rounded-rect.glsl" - -layout(location = 0) in vec2 inPos; -layout(location = 1) in flat vec4 inColor; -layout(location = 2) in flat vec4 inRect; -layout(location = 3) in flat vec4 inCornerWidths; -layout(location = 4) in flat vec4 inCornerHeights; -layout(location = 5) in flat vec4 inBorderWidths; - -layout(location = 0) out vec4 color; - -void main() -{ - RoundedRect routside = RoundedRect (vec4(inRect.xy, inRect.xy + inRect.zw), inCornerWidths, inCornerHeights); - RoundedRect rinside = rounded_rect_shrink (routside, inBorderWidths); - - float alpha = clamp (rounded_rect_coverage (routside, inPos) - - rounded_rect_coverage (rinside, inPos), - 0.0, 1.0); - color = inColor * alpha; -} diff --git a/gsk/resources/vulkan/border-clip.frag.spv b/gsk/resources/vulkan/border-clip.frag.spv index ab43d3dec8..1a3fda7d67 100644 Binary files a/gsk/resources/vulkan/border-clip.frag.spv and b/gsk/resources/vulkan/border-clip.frag.spv differ diff --git a/gsk/resources/vulkan/border-clip-rounded.frag.glsl b/gsk/resources/vulkan/border.frag similarity index 72% rename from gsk/resources/vulkan/border-clip-rounded.frag.glsl rename to gsk/resources/vulkan/border.frag index d31718abb9..988b1f6f4a 100644 --- a/gsk/resources/vulkan/border-clip-rounded.frag.glsl +++ b/gsk/resources/vulkan/border.frag @@ -1,6 +1,6 @@ #version 420 core -#include "constants.glsl" +#include "clip.frag.glsl" #include "rounded-rect.glsl" layout(location = 0) in vec2 inPos; @@ -12,14 +12,6 @@ layout(location = 5) in vec4 inBorderWidths; layout(location = 0) out vec4 color; -vec4 -clip (vec4 color) -{ - 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); -} - void main() { RoundedRect routside = RoundedRect (vec4(inRect.xy, inRect.xy + inRect.zw), inCornerWidths, inCornerHeights); @@ -28,5 +20,5 @@ void main() float alpha = clamp (rounded_rect_coverage (routside, inPos) - rounded_rect_coverage (rinside, inPos), 0.0, 1.0); - color = clip (inColor); + color = clip (inPos, inColor * alpha); } diff --git a/gsk/resources/vulkan/border.frag.spv b/gsk/resources/vulkan/border.frag.spv index ab43d3dec8..1a3fda7d67 100644 Binary files a/gsk/resources/vulkan/border.frag.spv and b/gsk/resources/vulkan/border.frag.spv differ diff --git a/gsk/resources/vulkan/border-clip.vert.glsl b/gsk/resources/vulkan/border.vert similarity index 99% rename from gsk/resources/vulkan/border-clip.vert.glsl rename to gsk/resources/vulkan/border.vert index 8e0fc8375e..b37ea9ec9c 100644 --- a/gsk/resources/vulkan/border-clip.vert.glsl +++ b/gsk/resources/vulkan/border.vert @@ -1,6 +1,5 @@ #version 420 core -#define CLIP_RECT #include "clip.vert.glsl" layout(location = 0) in vec4 inRect; diff --git a/gsk/resources/vulkan/border.vert.spv b/gsk/resources/vulkan/border.vert.spv index 6a6cf93865..dfa95f1b59 100644 Binary files a/gsk/resources/vulkan/border.vert.spv and b/gsk/resources/vulkan/border.vert.spv differ diff --git a/gsk/resources/vulkan/color-clip.frag.glsl b/gsk/resources/vulkan/color-clip.frag.glsl deleted file mode 100644 index 218ee854eb..0000000000 --- a/gsk/resources/vulkan/color-clip.frag.glsl +++ /dev/null @@ -1,10 +0,0 @@ -#version 420 core - -layout(location = 0) in vec4 inColor; - -layout(location = 0) out vec4 color; - -void main() -{ - color = vec4(inColor.rgb * inColor.a, inColor.a); -} diff --git a/gsk/resources/vulkan/color-clip.frag.spv b/gsk/resources/vulkan/color-clip.frag.spv index 29bbae9dfd..d3ef64ef49 100644 Binary files a/gsk/resources/vulkan/color-clip.frag.spv and b/gsk/resources/vulkan/color-clip.frag.spv differ diff --git a/gsk/resources/vulkan/color-clip.vert.glsl b/gsk/resources/vulkan/color-clip.vert.glsl deleted file mode 100644 index a869b8a625..0000000000 --- a/gsk/resources/vulkan/color-clip.vert.glsl +++ /dev/null @@ -1,28 +0,0 @@ -#version 420 core - -#define CLIP_RECT -#include "clip.vert.glsl" - -layout(location = 0) in vec4 inRect; -layout(location = 1) in vec4 inColor; - -out gl_PerVertex { - vec4 gl_Position; -}; - -layout(location = 0) out vec4 outColor; - -vec2 offsets[6] = { vec2(0.0, 0.0), - vec2(1.0, 0.0), - vec2(0.0, 1.0), - vec2(0.0, 1.0), - vec2(1.0, 0.0), - vec2(1.0, 1.0) }; - -void main() { - vec4 rect = clip (inRect); - - vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex]; - gl_Position = push.mvp * vec4 (pos, 0.0, 1.0); - outColor = inColor; -} diff --git a/gsk/resources/vulkan/color-clip.vert.spv b/gsk/resources/vulkan/color-clip.vert.spv index 0b2711b2d1..daaf33aa22 100644 Binary files a/gsk/resources/vulkan/color-clip.vert.spv and b/gsk/resources/vulkan/color-clip.vert.spv differ diff --git a/gsk/resources/vulkan/color-matrix-clip.frag.glsl b/gsk/resources/vulkan/color-matrix-clip.frag.glsl deleted file mode 100644 index 21a324e780..0000000000 --- a/gsk/resources/vulkan/color-matrix-clip.frag.glsl +++ /dev/null @@ -1,31 +0,0 @@ -#version 420 core - -layout(location = 0) in vec2 inTexCoord; -layout(location = 1) in flat mat4 inColorMatrix; -layout(location = 5) in flat vec4 inColorOffset; - -layout(set = 0, binding = 0) uniform sampler2D inTexture; - -layout(location = 0) out vec4 color; - -vec4 -color_matrix (vec4 color, mat4 color_matrix, vec4 color_offset) -{ - /* unpremultiply */ - if (color.a != 0.0) - color.rgb /= color.a; - - color = color_matrix * color + color_offset; - color = clamp(color, 0.0, 1.0); - - /* premultiply */ - if (color.a != 0.0) - color.rgb *= color.a; - - return color; -} - -void main() -{ - color = color_matrix (texture (inTexture, inTexCoord), inColorMatrix, inColorOffset); -} diff --git a/gsk/resources/vulkan/color-matrix-clip.frag.spv b/gsk/resources/vulkan/color-matrix-clip.frag.spv index 266c8777f5..ec29f263bb 100644 Binary files a/gsk/resources/vulkan/color-matrix-clip.frag.spv and b/gsk/resources/vulkan/color-matrix-clip.frag.spv differ diff --git a/gsk/resources/vulkan/color-matrix-clip.vert.glsl b/gsk/resources/vulkan/color-matrix-clip.vert.glsl deleted file mode 100644 index 6ae0817157..0000000000 --- a/gsk/resources/vulkan/color-matrix-clip.vert.glsl +++ /dev/null @@ -1,38 +0,0 @@ -#version 420 core - -#define CLIP_RECT -#include "clip.vert.glsl" - -layout(location = 0) in vec4 inRect; -layout(location = 1) in vec4 inTexRect; -layout(location = 2) in mat4 inColorMatrix; -layout(location = 6) in vec4 inColorOffset; - -layout(location = 0) out vec2 outTexCoord; -layout(location = 1) out flat mat4 outColorMatrix; -layout(location = 5) out flat vec4 outColorOffset; - -out gl_PerVertex { - vec4 gl_Position; -}; - -vec2 offsets[6] = { vec2(0.0, 0.0), - vec2(1.0, 0.0), - vec2(0.0, 1.0), - vec2(0.0, 1.0), - vec2(1.0, 0.0), - vec2(1.0, 1.0) }; - -void main() { - vec4 rect = clip (inRect); - vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex]; - gl_Position = push.mvp * vec4 (pos, 0.0, 1.0); - - vec4 texrect = vec4((rect.xy - inRect.xy) / inRect.zw, - rect.zw / inRect.zw); - texrect = vec4(inTexRect.xy + inTexRect.zw * texrect.xy, - inTexRect.zw * texrect.zw); - outTexCoord = texrect.xy + texrect.zw * offsets[gl_VertexIndex]; - outColorMatrix = inColorMatrix; - outColorOffset = inColorOffset; -} diff --git a/gsk/resources/vulkan/color-matrix-clip.vert.spv b/gsk/resources/vulkan/color-matrix-clip.vert.spv index 20b615e67b..f4951f6530 100644 Binary files a/gsk/resources/vulkan/color-matrix-clip.vert.spv and b/gsk/resources/vulkan/color-matrix-clip.vert.spv differ diff --git a/gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl b/gsk/resources/vulkan/color-matrix.frag similarity index 96% rename from gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl rename to gsk/resources/vulkan/color-matrix.frag index 88057c7915..00b7947286 100644 --- a/gsk/resources/vulkan/color-matrix-clip-rounded.frag.glsl +++ b/gsk/resources/vulkan/color-matrix.frag @@ -1,6 +1,5 @@ #version 420 core -#define CLIP_ROUNDED_RECT #include "clip.frag.glsl" layout(location = 0) in vec2 inPos; diff --git a/gsk/resources/vulkan/color-matrix.frag.spv b/gsk/resources/vulkan/color-matrix.frag.spv index 266c8777f5..ec29f263bb 100644 Binary files a/gsk/resources/vulkan/color-matrix.frag.spv and b/gsk/resources/vulkan/color-matrix.frag.spv differ diff --git a/gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl b/gsk/resources/vulkan/color-matrix.vert similarity index 97% rename from gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl rename to gsk/resources/vulkan/color-matrix.vert index 3888b7e460..eb3f4fa727 100644 --- a/gsk/resources/vulkan/color-matrix-clip-rounded.vert.glsl +++ b/gsk/resources/vulkan/color-matrix.vert @@ -1,6 +1,5 @@ #version 420 core -#define CLIP_ROUNDED_RECT #include "clip.vert.glsl" layout(location = 0) in vec4 inRect; diff --git a/gsk/resources/vulkan/color-matrix.vert.spv b/gsk/resources/vulkan/color-matrix.vert.spv index fa89276b21..89176d44e6 100644 Binary files a/gsk/resources/vulkan/color-matrix.vert.spv and b/gsk/resources/vulkan/color-matrix.vert.spv differ diff --git a/gsk/resources/vulkan/color-clip-rounded.frag.glsl b/gsk/resources/vulkan/color.frag similarity index 90% rename from gsk/resources/vulkan/color-clip-rounded.frag.glsl rename to gsk/resources/vulkan/color.frag index b66001c9f5..6b299dffd0 100644 --- a/gsk/resources/vulkan/color-clip-rounded.frag.glsl +++ b/gsk/resources/vulkan/color.frag @@ -1,6 +1,5 @@ #version 420 core -#define CLIP_ROUNDED_RECT #include "clip.frag.glsl" layout(location = 0) in vec2 inPos; diff --git a/gsk/resources/vulkan/color.frag.spv b/gsk/resources/vulkan/color.frag.spv index 29bbae9dfd..d3ef64ef49 100644 Binary files a/gsk/resources/vulkan/color.frag.spv and b/gsk/resources/vulkan/color.frag.spv differ diff --git a/gsk/resources/vulkan/color-clip-rounded.vert.glsl b/gsk/resources/vulkan/color.vert similarity index 96% rename from gsk/resources/vulkan/color-clip-rounded.vert.glsl rename to gsk/resources/vulkan/color.vert index 7f7a1e9226..ce85ea7fd3 100644 --- a/gsk/resources/vulkan/color-clip-rounded.vert.glsl +++ b/gsk/resources/vulkan/color.vert @@ -1,6 +1,5 @@ #version 420 core -#define CLIP_ROUNDED_RECT #include "clip.vert.glsl" layout(location = 0) in vec4 inRect; diff --git a/gsk/resources/vulkan/color.vert.spv b/gsk/resources/vulkan/color.vert.spv index 05d74a6b0b..4a0b396584 100644 Binary files a/gsk/resources/vulkan/color.vert.spv and b/gsk/resources/vulkan/color.vert.spv differ diff --git a/gsk/resources/vulkan/linear-clip.frag.glsl b/gsk/resources/vulkan/linear-clip.frag.glsl deleted file mode 100644 index 1d03553705..0000000000 --- a/gsk/resources/vulkan/linear-clip.frag.glsl +++ /dev/null @@ -1,33 +0,0 @@ -#version 420 core - -struct ColorStop { - float offset; - vec4 color; -}; - -layout(location = 0) in float inGradientPos; -layout(location = 1) in flat int inRepeating; -layout(location = 2) in flat int inStopCount; -layout(location = 3) in flat ColorStop inStops[8]; - -layout(location = 0) out vec4 outColor; - -void main() -{ - float pos; - if (inRepeating != 0) - pos = fract (inGradientPos); - else - pos = clamp (inGradientPos, 0, 1); - - vec4 color = inStops[0].color; - int n = clamp (inStopCount, 2, 8); - for (int i = 1; i < n; i++) - { - if (inStops[i].offset > inStops[i-1].offset) - color = mix (color, inStops[i].color, clamp((pos - inStops[i-1].offset) / (inStops[i].offset - inStops[i-1].offset), 0, 1)); - } - - //outColor = vec4(pos, pos, pos, 1.0); - outColor = color; -} diff --git a/gsk/resources/vulkan/linear-clip.frag.spv b/gsk/resources/vulkan/linear-clip.frag.spv index a95b58f59b..86f9ea0cb4 100644 Binary files a/gsk/resources/vulkan/linear-clip.frag.spv and b/gsk/resources/vulkan/linear-clip.frag.spv differ diff --git a/gsk/resources/vulkan/linear-clip.vert.glsl b/gsk/resources/vulkan/linear-clip.vert.glsl deleted file mode 100644 index 117642080e..0000000000 --- a/gsk/resources/vulkan/linear-clip.vert.glsl +++ /dev/null @@ -1,75 +0,0 @@ -#version 420 core - -#define CLIP_RECT -#include "clip.vert.glsl" - -struct ColorStop { - float offset; - vec4 color; -}; - -layout(location = 0) in vec4 inRect; -layout(location = 1) in vec2 inStart; -layout(location = 2) in vec2 inEnd; -layout(location = 3) in int inRepeating; -layout(location = 4) in int inStopCount; -layout(location = 5) in vec4 inOffsets0; -layout(location = 6) in vec4 inOffsets1; -layout(location = 7) in vec4 inColors0; -layout(location = 8) in vec4 inColors1; -layout(location = 9) in vec4 inColors2; -layout(location = 10) in vec4 inColors3; -layout(location = 11) in vec4 inColors4; -layout(location = 12) in vec4 inColors5; -layout(location = 13) in vec4 inColors6; -layout(location = 14) in vec4 inColors7; - -layout(location = 0) out float outGradientPos; -layout(location = 1) out flat int outRepeating; -layout(location = 2) out flat int outStopCount; -layout(location = 3) out flat ColorStop outStops[8]; - -out gl_PerVertex { - vec4 gl_Position; -}; - -vec2 offsets[6] = { vec2(0.0, 0.0), - vec2(1.0, 0.0), - vec2(0.0, 1.0), - vec2(0.0, 1.0), - vec2(1.0, 0.0), - vec2(1.0, 1.0) }; - -float -get_gradient_pos (vec2 pos) -{ - pos = pos - inStart; - vec2 grad = inEnd - inStart; - - return dot (pos, grad) / dot (grad, grad); -} - -void main() { - vec4 rect = clip (inRect); - vec2 pos = rect.xy + rect.zw * offsets[gl_VertexIndex]; - gl_Position = push.mvp * vec4 (pos, 0.0, 1.0); - outGradientPos = get_gradient_pos (pos); - outRepeating = inRepeating; - outStopCount = inStopCount; - outStops[0].offset = inOffsets0[0]; - outStops[0].color = inColors0 * vec4(inColors0.aaa, 1.0); - outStops[1].offset = inOffsets0[1]; - outStops[1].color = inColors1 * vec4(inColors1.aaa, 1.0); - outStops[2].offset = inOffsets0[2]; - outStops[2].color = inColors2 * vec4(inColors2.aaa, 1.0); - outStops[3].offset = inOffsets0[3]; - outStops[3].color = inColors3 * vec4(inColors3.aaa, 1.0); - outStops[4].offset = inOffsets1[0]; - outStops[4].color = inColors4 * vec4(inColors4.aaa, 1.0); - outStops[5].offset = inOffsets1[1]; - outStops[5].color = inColors5 * vec4(inColors5.aaa, 1.0); - outStops[6].offset = inOffsets1[2]; - outStops[6].color = inColors6 * vec4(inColors6.aaa, 1.0); - outStops[7].offset = inOffsets1[3]; - outStops[7].color = inColors7 * vec4(inColors7.aaa, 1.0); -} diff --git a/gsk/resources/vulkan/linear-clip.vert.spv b/gsk/resources/vulkan/linear-clip.vert.spv index 74b823059e..9124ffbe41 100644 Binary files a/gsk/resources/vulkan/linear-clip.vert.spv and b/gsk/resources/vulkan/linear-clip.vert.spv differ diff --git a/gsk/resources/vulkan/linear-clip-rounded.frag.glsl b/gsk/resources/vulkan/linear.frag similarity index 97% rename from gsk/resources/vulkan/linear-clip-rounded.frag.glsl rename to gsk/resources/vulkan/linear.frag index 1fbf0955ac..cb7727f641 100644 --- a/gsk/resources/vulkan/linear-clip-rounded.frag.glsl +++ b/gsk/resources/vulkan/linear.frag @@ -1,6 +1,5 @@ #version 420 core -#define CLIP_ROUNDED_RECT #include "clip.frag.glsl" struct ColorStop { diff --git a/gsk/resources/vulkan/linear.frag.spv b/gsk/resources/vulkan/linear.frag.spv index a95b58f59b..86f9ea0cb4 100644 Binary files a/gsk/resources/vulkan/linear.frag.spv and b/gsk/resources/vulkan/linear.frag.spv differ diff --git a/gsk/resources/vulkan/linear-clip-rounded.vert.glsl b/gsk/resources/vulkan/linear.vert similarity index 98% rename from gsk/resources/vulkan/linear-clip-rounded.vert.glsl rename to gsk/resources/vulkan/linear.vert index b574defc26..f9fd57cac6 100644 --- a/gsk/resources/vulkan/linear-clip-rounded.vert.glsl +++ b/gsk/resources/vulkan/linear.vert @@ -1,6 +1,5 @@ #version 420 core -#define CLIP_ROUNDED_RECT #include "clip.vert.glsl" struct ColorStop { diff --git a/gsk/resources/vulkan/linear.vert.spv b/gsk/resources/vulkan/linear.vert.spv index 8a40b6d17d..bcc3fcf17a 100644 Binary files a/gsk/resources/vulkan/linear.vert.spv and b/gsk/resources/vulkan/linear.vert.spv differ