aboutsummaryrefslogtreecommitdiff
path: root/render/vulkan/shaders
diff options
context:
space:
mode:
authornyorain <nyorain@gmail.com>2021-02-21 18:30:12 +0100
committerSimon Ser <contact@emersion.fr>2021-10-18 11:51:13 +0200
commit8e346922508aa3eaccd6e12f2917f6574f349843 (patch)
tree550742b8a086287b6d478db1ade14b2cc4a21294 /render/vulkan/shaders
parent2edf468aeb7d4703aa211cea3b58f04cbc73298c (diff)
render/vulkan: add Vulkan renderer
This new renderer is implemented with the existing wlr_renderer API (which is known to be sub-optimal for some operations). It's not used by default, but users can opt-in by setting WLR_RENDERER=vulkan. The renderer depends on VK_EXT_image_drm_format_modifier and VK_EXT_physical_device_drm. Co-authored-by: Simon Ser <contact@emersion.fr> Co-authored-by: Jan Beich <jbeich@FreeBSD.org>
Diffstat (limited to 'render/vulkan/shaders')
-rw-r--r--render/vulkan/shaders/common.vert25
-rw-r--r--render/vulkan/shaders/meson.build20
-rw-r--r--render/vulkan/shaders/quad.frag10
-rw-r--r--render/vulkan/shaders/texture.frag25
4 files changed, 80 insertions, 0 deletions
diff --git a/render/vulkan/shaders/common.vert b/render/vulkan/shaders/common.vert
new file mode 100644
index 00000000..fa31d26c
--- /dev/null
+++ b/render/vulkan/shaders/common.vert
@@ -0,0 +1,25 @@
+#version 450
+
+// we use a mat4 since it uses the same size as mat3 due to
+// alignment. Easier to deal with (tighly-packed) mat4 though.
+layout(push_constant, row_major) uniform UBO {
+ mat4 proj;
+ vec2 uv_offset;
+ vec2 uv_size;
+} data;
+
+layout(location = 0) out vec2 uv;
+
+// 4 outlining points and uv coords
+const vec2[] values = {
+ {0, 0},
+ {1, 0},
+ {1, 1},
+ {0, 1},
+};
+
+void main() {
+ vec2 pos = values[gl_VertexIndex % 4];
+ uv = data.uv_offset + pos * data.uv_size;
+ gl_Position = data.proj * vec4(pos, 0.0, 1.0);
+}
diff --git a/render/vulkan/shaders/meson.build b/render/vulkan/shaders/meson.build
new file mode 100644
index 00000000..b183c46c
--- /dev/null
+++ b/render/vulkan/shaders/meson.build
@@ -0,0 +1,20 @@
+vulkan_shaders_src = [
+ 'common.vert',
+ 'texture.frag',
+ 'quad.frag',
+]
+
+vulkan_shaders = []
+foreach shader : vulkan_shaders_src
+ name = shader.underscorify() + '_data'
+ args = [glslang, '-V', '@INPUT@', '-o', '@OUTPUT@', '--vn', name]
+ header = custom_target(
+ shader + '_spv',
+ output: shader + '.h',
+ input: shader,
+ command: args)
+
+ vulkan_shaders += [header]
+endforeach
+
+wlr_files += vulkan_shaders
diff --git a/render/vulkan/shaders/quad.frag b/render/vulkan/shaders/quad.frag
new file mode 100644
index 00000000..affd1f11
--- /dev/null
+++ b/render/vulkan/shaders/quad.frag
@@ -0,0 +1,10 @@
+#version 450
+
+layout(location = 0) out vec4 out_color;
+layout(push_constant) uniform UBO {
+ layout(offset = 80) vec4 color;
+} data;
+
+void main() {
+ out_color = data.color;
+}
diff --git a/render/vulkan/shaders/texture.frag b/render/vulkan/shaders/texture.frag
new file mode 100644
index 00000000..7a7b8c57
--- /dev/null
+++ b/render/vulkan/shaders/texture.frag
@@ -0,0 +1,25 @@
+#version 450
+
+layout(set = 0, binding = 0) uniform sampler2D tex;
+
+layout(location = 0) in vec2 uv;
+layout(location = 0) out vec4 out_color;
+
+layout(push_constant) uniform UBO {
+ layout(offset = 80) float alpha;
+} data;
+
+void main() {
+ out_color = textureLod(tex, uv, 0);
+
+ // We expect this shader to output pre-alpha-multiplied color values.
+ // alpha < 0.0 means that this shader should ignore the texture's alpha
+ // value.
+ if (data.alpha < 0.0) {
+ out_color.a = -data.alpha;
+ out_color.rgb *= -data.alpha;
+ } else {
+ out_color *= data.alpha;
+ }
+}
+