tangled
alpha
login
or
join now
matrixfurry.com
/
monado
0
fork
atom
The open source OpenXR runtime
0
fork
atom
overview
issues
pulls
pipelines
c/shaders: Add blit compute shader
Jakob Bornecrantz
2 years ago
3b5e84fd
53f96ed2
+81
4 changed files
expand all
collapse all
unified
split
src
xrt
compositor
CMakeLists.txt
render
render_interface.h
render_shaders.c
shaders
blit.comp
+1
src/xrt/compositor/CMakeLists.txt
···
113
113
114
114
if(XRT_HAVE_VULKAN)
115
115
set(SHADERS
116
116
+
shaders/blit.comp
116
117
shaders/clear.comp
117
118
shaders/distortion.comp
118
119
shaders/layer.comp
+10
src/xrt/compositor/render/render_interface.h
···
79
79
*/
80
80
struct render_shaders
81
81
{
82
82
+
VkShaderModule blit_comp;
82
83
VkShaderModule clear_comp;
83
84
VkShaderModule layer_comp;
84
85
VkShaderModule distortion_comp;
···
727
728
728
729
//! Descriptor set for distortion.
729
730
VkDescriptorSet distortion_descriptor_set;
731
731
+
};
732
732
+
733
733
+
/*!
734
734
+
* Push data that is sent to the blit shader.
735
735
+
*/
736
736
+
struct render_compute_blit_push_data
737
737
+
{
738
738
+
struct xrt_normalized_rect source_rect;
739
739
+
struct xrt_rect target_rect;
730
740
};
731
741
732
742
/*!
+7
src/xrt/compositor/render/render_shaders.c
···
23
23
24
24
#include "xrt/xrt_config_build.h"
25
25
26
26
+
#include "shaders/blit.comp.h"
26
27
#include "shaders/clear.comp.h"
27
28
#include "shaders/layer.comp.h"
28
29
#include "shaders/distortion.comp.h"
···
89
90
bool
90
91
render_shaders_load(struct render_shaders *s, struct vk_bundle *vk)
91
92
{
93
93
+
C(shader_load(vk, // vk_bundle
94
94
+
shaders_blit_comp, // data
95
95
+
sizeof(shaders_blit_comp), // size
96
96
+
&s->blit_comp)); // out
97
97
+
92
98
C(shader_load(vk, // vk_bundle
93
99
shaders_clear_comp, // data
94
100
sizeof(shaders_clear_comp), // size
···
165
171
void
166
172
render_shaders_close(struct render_shaders *s, struct vk_bundle *vk)
167
173
{
174
174
+
D(blit_comp);
168
175
D(clear_comp);
169
176
D(distortion_comp);
170
177
D(layer_comp);
+63
src/xrt/compositor/shaders/blit.comp
···
1
1
+
// Copyright 2021-2023, Collabora Ltd.
2
2
+
// Author: Jakob Bornecrantz <jakob@collabora.com>
3
3
+
// SPDX-License-Identifier: BSL-1.0
4
4
+
5
5
+
#version 460
6
6
+
#extension GL_GOOGLE_include_directive : require
7
7
+
8
8
+
#include "srgb.inc.glsl"
9
9
+
10
10
+
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
11
11
+
12
12
+
layout(set = 0, binding = 0) uniform sampler2D source;
13
13
+
layout(set = 0, binding = 1, rgba8) uniform writeonly restrict image2D target;
14
14
+
layout(push_constant) uniform Config
15
15
+
{
16
16
+
vec4 src_rect;
17
17
+
ivec4 target_view;
18
18
+
} push;
19
19
+
20
20
+
vec2 position_to_uv(ivec2 extent, uint ix, uint iy)
21
21
+
{
22
22
+
// Turn the index into floating point.
23
23
+
vec2 xy = vec2(float(ix), float(iy));
24
24
+
25
25
+
// The inverse of the extent of the target image is the pixel size in [0 .. 1] space.
26
26
+
vec2 extent_pixel_size = vec2(1.0 / float(extent.x), 1.0 / float(extent.y));
27
27
+
28
28
+
// Per-target pixel we move the size of the pixels.
29
29
+
vec2 uv = xy * extent_pixel_size;
30
30
+
31
31
+
// Emulate a triangle sample position by offset half target pixel size.
32
32
+
uv = uv + extent_pixel_size / 2.0;
33
33
+
34
34
+
// Transform with the normalized sample rect.
35
35
+
uv = push.src_rect.xy + (uv * push.src_rect.zw);
36
36
+
37
37
+
return uv;
38
38
+
}
39
39
+
40
40
+
void main()
41
41
+
{
42
42
+
uint ix = gl_GlobalInvocationID.x;
43
43
+
uint iy = gl_GlobalInvocationID.y;
44
44
+
45
45
+
ivec2 offset = ivec2(push.target_view.xy);
46
46
+
ivec2 extent = ivec2(push.target_view.zw);
47
47
+
48
48
+
if (ix >= extent.x || iy >= extent.y) {
49
49
+
return;
50
50
+
}
51
51
+
52
52
+
// Get the UV we should sample from.
53
53
+
vec2 uv = position_to_uv(extent, ix, iy);
54
54
+
55
55
+
// Do the sample.
56
56
+
vec4 rgba = texture(source, uv);
57
57
+
58
58
+
// Do colour correction here since there are no automatic conversion in hardware available.
59
59
+
rgba = vec4(from_linear_to_srgb(rgba.rgb), rgba.a);
60
60
+
61
61
+
// And finally write out.
62
62
+
imageStore(target, ivec2(offset.x + ix, offset.y + iy), rgba);
63
63
+
}