mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-29 11:06:18 +00:00
c/shaders: Add blit compute shader
This commit is contained in:
parent
53f96ed20d
commit
3b5e84fd6f
|
@ -113,6 +113,7 @@ endif()
|
|||
|
||||
if(XRT_HAVE_VULKAN)
|
||||
set(SHADERS
|
||||
shaders/blit.comp
|
||||
shaders/clear.comp
|
||||
shaders/distortion.comp
|
||||
shaders/layer.comp
|
||||
|
|
|
@ -79,6 +79,7 @@ render_calc_time_warp_matrix(const struct xrt_pose *src_pose,
|
|||
*/
|
||||
struct render_shaders
|
||||
{
|
||||
VkShaderModule blit_comp;
|
||||
VkShaderModule clear_comp;
|
||||
VkShaderModule layer_comp;
|
||||
VkShaderModule distortion_comp;
|
||||
|
@ -729,6 +730,15 @@ struct render_compute
|
|||
VkDescriptorSet distortion_descriptor_set;
|
||||
};
|
||||
|
||||
/*!
|
||||
* Push data that is sent to the blit shader.
|
||||
*/
|
||||
struct render_compute_blit_push_data
|
||||
{
|
||||
struct xrt_normalized_rect source_rect;
|
||||
struct xrt_rect target_rect;
|
||||
};
|
||||
|
||||
/*!
|
||||
* UBO data that is sent to the compute layer shaders.
|
||||
*
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "xrt/xrt_config_build.h"
|
||||
|
||||
#include "shaders/blit.comp.h"
|
||||
#include "shaders/clear.comp.h"
|
||||
#include "shaders/layer.comp.h"
|
||||
#include "shaders/distortion.comp.h"
|
||||
|
@ -89,6 +90,11 @@ shader_load(struct vk_bundle *vk, const uint32_t *code, size_t size, VkShaderMod
|
|||
bool
|
||||
render_shaders_load(struct render_shaders *s, struct vk_bundle *vk)
|
||||
{
|
||||
C(shader_load(vk, // vk_bundle
|
||||
shaders_blit_comp, // data
|
||||
sizeof(shaders_blit_comp), // size
|
||||
&s->blit_comp)); // out
|
||||
|
||||
C(shader_load(vk, // vk_bundle
|
||||
shaders_clear_comp, // data
|
||||
sizeof(shaders_clear_comp), // size
|
||||
|
@ -165,6 +171,7 @@ render_shaders_load(struct render_shaders *s, struct vk_bundle *vk)
|
|||
void
|
||||
render_shaders_close(struct render_shaders *s, struct vk_bundle *vk)
|
||||
{
|
||||
D(blit_comp);
|
||||
D(clear_comp);
|
||||
D(distortion_comp);
|
||||
D(layer_comp);
|
||||
|
|
63
src/xrt/compositor/shaders/blit.comp
Normal file
63
src/xrt/compositor/shaders/blit.comp
Normal file
|
@ -0,0 +1,63 @@
|
|||
// Copyright 2021-2023, Collabora Ltd.
|
||||
// Author: Jakob Bornecrantz <jakob@collabora.com>
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
#version 460
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#include "srgb.inc.glsl"
|
||||
|
||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||
|
||||
layout(set = 0, binding = 0) uniform sampler2D source;
|
||||
layout(set = 0, binding = 1, rgba8) uniform writeonly restrict image2D target;
|
||||
layout(push_constant) uniform Config
|
||||
{
|
||||
vec4 src_rect;
|
||||
ivec4 target_view;
|
||||
} push;
|
||||
|
||||
vec2 position_to_uv(ivec2 extent, uint ix, uint iy)
|
||||
{
|
||||
// Turn the index into floating point.
|
||||
vec2 xy = vec2(float(ix), float(iy));
|
||||
|
||||
// The inverse of the extent of the target image is the pixel size in [0 .. 1] space.
|
||||
vec2 extent_pixel_size = vec2(1.0 / float(extent.x), 1.0 / float(extent.y));
|
||||
|
||||
// Per-target pixel we move the size of the pixels.
|
||||
vec2 uv = xy * extent_pixel_size;
|
||||
|
||||
// Emulate a triangle sample position by offset half target pixel size.
|
||||
uv = uv + extent_pixel_size / 2.0;
|
||||
|
||||
// Transform with the normalized sample rect.
|
||||
uv = push.src_rect.xy + (uv * push.src_rect.zw);
|
||||
|
||||
return uv;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
uint ix = gl_GlobalInvocationID.x;
|
||||
uint iy = gl_GlobalInvocationID.y;
|
||||
|
||||
ivec2 offset = ivec2(push.target_view.xy);
|
||||
ivec2 extent = ivec2(push.target_view.zw);
|
||||
|
||||
if (ix >= extent.x || iy >= extent.y) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the UV we should sample from.
|
||||
vec2 uv = position_to_uv(extent, ix, iy);
|
||||
|
||||
// Do the sample.
|
||||
vec4 rgba = texture(source, uv);
|
||||
|
||||
// Do colour correction here since there are no automatic conversion in hardware available.
|
||||
rgba = vec4(from_linear_to_srgb(rgba.rgb), rgba.a);
|
||||
|
||||
// And finally write out.
|
||||
imageStore(target, ivec2(offset.x + ix, offset.y + iy), rgba);
|
||||
}
|
Loading…
Reference in a new issue