mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
c/render: Make distortion shader optionally do timewarp
This commit is contained in:
parent
0be36ccc9d
commit
95d5343c9a
|
@ -242,6 +242,7 @@ create_compute_descriptor_set_layout(struct vk_bundle *vk,
|
||||||
struct compute_distortion_params
|
struct compute_distortion_params
|
||||||
{
|
{
|
||||||
uint32_t distortion_texel_count;
|
uint32_t distortion_texel_count;
|
||||||
|
VkBool32 do_timewarp;
|
||||||
};
|
};
|
||||||
|
|
||||||
static VkResult
|
static VkResult
|
||||||
|
@ -252,13 +253,18 @@ create_compute_distortion_pipeline(struct vk_bundle *vk,
|
||||||
const struct compute_distortion_params *params,
|
const struct compute_distortion_params *params,
|
||||||
VkPipeline *out_compute_pipeline)
|
VkPipeline *out_compute_pipeline)
|
||||||
{
|
{
|
||||||
VkSpecializationMapEntry entries[1] = {
|
#define ENTRY(ID, FIELD) \
|
||||||
{
|
{ \
|
||||||
.constantID = 0,
|
.constantID = ID, \
|
||||||
.offset = offsetof(struct compute_distortion_params, distortion_texel_count),
|
.offset = offsetof(struct compute_distortion_params, FIELD), \
|
||||||
.size = sizeof(params->distortion_texel_count),
|
sizeof(params->FIELD), \
|
||||||
},
|
}
|
||||||
|
|
||||||
|
VkSpecializationMapEntry entries[2] = {
|
||||||
|
ENTRY(0, distortion_texel_count),
|
||||||
|
ENTRY(1, do_timewarp),
|
||||||
};
|
};
|
||||||
|
#undef ENTRY
|
||||||
|
|
||||||
VkSpecializationInfo specialization_info = {
|
VkSpecializationInfo specialization_info = {
|
||||||
.mapEntryCount = ARRAY_SIZE(entries),
|
.mapEntryCount = ARRAY_SIZE(entries),
|
||||||
|
@ -693,6 +699,7 @@ render_resources_init(struct render_resources *r,
|
||||||
|
|
||||||
struct compute_distortion_params distortion_params = {
|
struct compute_distortion_params distortion_params = {
|
||||||
.distortion_texel_count = COMP_DISTORTION_IMAGE_DIMENSIONS,
|
.distortion_texel_count = COMP_DISTORTION_IMAGE_DIMENSIONS,
|
||||||
|
.do_timewarp = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
C(create_compute_distortion_pipeline( //
|
C(create_compute_distortion_pipeline( //
|
||||||
|
@ -705,12 +712,13 @@ render_resources_init(struct render_resources *r,
|
||||||
|
|
||||||
struct compute_distortion_params distortion_timewarp_params = {
|
struct compute_distortion_params distortion_timewarp_params = {
|
||||||
.distortion_texel_count = COMP_DISTORTION_IMAGE_DIMENSIONS,
|
.distortion_texel_count = COMP_DISTORTION_IMAGE_DIMENSIONS,
|
||||||
|
.do_timewarp = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
C(create_compute_distortion_pipeline( //
|
C(create_compute_distortion_pipeline( //
|
||||||
vk, // vk_bundle
|
vk, // vk_bundle
|
||||||
r->pipeline_cache, // pipeline_cache
|
r->pipeline_cache, // pipeline_cache
|
||||||
r->shaders->distortion_timewarp_comp, // shader
|
r->shaders->distortion_comp, // shader
|
||||||
r->compute.pipeline_layout, // pipeline_layout
|
r->compute.pipeline_layout, // pipeline_layout
|
||||||
&distortion_timewarp_params, // params
|
&distortion_timewarp_params, // params
|
||||||
&r->compute.distortion_timewarp_pipeline)); // out_compute_pipeline
|
&r->compute.distortion_timewarp_pipeline)); // out_compute_pipeline
|
||||||
|
|
|
@ -11,6 +11,9 @@
|
||||||
// The size of the distortion texture dimensions in texels.
|
// The size of the distortion texture dimensions in texels.
|
||||||
layout(constant_id = 0) const int distortion_texel_count = 2;
|
layout(constant_id = 0) const int distortion_texel_count = 2;
|
||||||
|
|
||||||
|
// Should we do timewarp.
|
||||||
|
layout(constant_id = 1) const bool do_timewarp = false;
|
||||||
|
|
||||||
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
|
||||||
|
|
||||||
layout(set = 0, binding = 0) uniform sampler2D source[2];
|
layout(set = 0, binding = 0) uniform sampler2D source[2];
|
||||||
|
@ -57,7 +60,7 @@ vec2 position_to_uv(ivec2 extent, uint ix, uint iy)
|
||||||
return dist_uv;
|
return dist_uv;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec2 transform_uv(vec2 uv, uint iz)
|
vec2 transform_uv_subimage(vec2 uv, uint iz)
|
||||||
{
|
{
|
||||||
vec2 values = uv;
|
vec2 values = uv;
|
||||||
|
|
||||||
|
@ -68,6 +71,37 @@ vec2 transform_uv(vec2 uv, uint iz)
|
||||||
return values.xy;
|
return values.xy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vec2 transform_uv_timewarp(vec2 uv, uint iz)
|
||||||
|
{
|
||||||
|
vec4 values = vec4(uv, -1, 1);
|
||||||
|
|
||||||
|
// From uv to tan angle (tanget space).
|
||||||
|
values.xy = values.xy * ubo.pre_transform[iz].zw + ubo.pre_transform[iz].xy;
|
||||||
|
values.y = -values.y; // Flip to OpenXR coordinate system.
|
||||||
|
|
||||||
|
// Timewarp.
|
||||||
|
values = ubo.transform[iz] * values;
|
||||||
|
values.xy = values.xy * (1.0 / max(values.w, 0.00001));
|
||||||
|
|
||||||
|
// From [-1, 1] to [0, 1]
|
||||||
|
values.xy = values.xy * 0.5 + 0.5;
|
||||||
|
|
||||||
|
// To deal with OpenGL flip and sub image view.
|
||||||
|
values.xy = values.xy * ubo.post_transform[iz].zw + ubo.post_transform[iz].xy;
|
||||||
|
|
||||||
|
// Done.
|
||||||
|
return values.xy;
|
||||||
|
}
|
||||||
|
|
||||||
|
vec2 transform_uv(vec2 uv, uint iz)
|
||||||
|
{
|
||||||
|
if (do_timewarp) {
|
||||||
|
return transform_uv_timewarp(uv, iz);
|
||||||
|
} else {
|
||||||
|
return transform_uv_subimage(uv, iz);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
uint ix = gl_GlobalInvocationID.x;
|
uint ix = gl_GlobalInvocationID.x;
|
||||||
|
|
Loading…
Reference in a new issue