Drop mipmaps for foveation

This commit is contained in:
Patrick Nicolas
2025-06-06 20:04:40 +02:00
parent 5cebea6eda
commit aef8efba8a
15 changed files with 92 additions and 2893 deletions
+13 -31
View File
@@ -52,7 +52,7 @@ static const std::array pool_sizes =
{
vk::DescriptorPoolSize{
.type = vk::DescriptorType::eStorageImage,
.descriptorCount = 4,
.descriptorCount = 2,
}};
static const std::array<vk::DescriptorSetLayoutBinding, 2> layout_bindings{
@@ -60,10 +60,6 @@ static const std::array<vk::DescriptorSetLayoutBinding, 2> layout_bindings{
.descriptorType = vk::DescriptorType::eStorageImage,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eCompute},
vk::DescriptorSetLayoutBinding{.binding = 1,
.descriptorType = vk::DescriptorType::eStorageImage,
.descriptorCount = 1,
.stageFlags = vk::ShaderStageFlagBits::eCompute},
};
wivrn_foveation_renderer::wivrn_foveation_renderer(wivrn_vk_bundle & vk, vk::raii::CommandPool & cmd_pool) :
@@ -178,33 +174,19 @@ void wivrn_foveation_renderer::render_distortion_images(std::array<to_headset::f
{
// Descriptor set
std::array image_info{
vk::DescriptorImageInfo{
.imageView = vk::ImageView(image_views[eye]),
.imageLayout = vk::ImageLayout::eGeneral,
},
vk::DescriptorImageInfo{
.imageView = vk::ImageView(image_views[eye + 2]),
.imageLayout = vk::ImageLayout::eGeneral,
},
vk::DescriptorImageInfo image_info{
.imageView = vk::ImageView(image_views[eye]),
.imageLayout = vk::ImageLayout::eGeneral,
};
vk.device.updateDescriptorSets({
vk::WriteDescriptorSet{
.dstSet = ds[eye],
.dstBinding = 0,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eStorageImage,
.pImageInfo = &image_info[0],
},
vk::WriteDescriptorSet{
.dstSet = ds[eye],
.dstBinding = 1,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eStorageImage,
.pImageInfo = &image_info[1],
},
},
nullptr);
vk.device.updateDescriptorSets(
vk::WriteDescriptorSet{
.dstSet = ds[eye],
.dstBinding = 0,
.descriptorCount = 1,
.descriptorType = vk::DescriptorType::eStorageImage,
.pImageInfo = &image_info,
},
nullptr);
auto foveation = foveations[eye];
+1 -15
View File
@@ -52,13 +52,6 @@ static double foveate(double a, double b, double λ, double c, double x)
// df⁻¹(x)/dx = 1/scale for x = c
}
static double foveate_lod(double a, double b, double /*λ*/, double /*c*/, double x)
{
// derivate of foveate * scale
// bias it to favor sharper image
return std::max(0., log2(1 / (cos(a * x + b) * cos(a * x + b)) - 0.5));
}
static std::tuple<float, float> solve_foveation(float λ, float c)
{
// Compute a and b for the foveation function such that:
@@ -122,20 +115,17 @@ bool wivrn_hmd::wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_in
// result is in the input coordinates (from the application)
const auto & param = ((wivrn_hmd *)xdev)->foveation_parameters[view_index];
xrt_vec2 out;
xrt_vec2 lod;
if (param.x.scale < 1)
{
u = 2 * u - 1;
out.x = foveate(param.x.a, param.x.b, param.x.scale, param.x.center, u);
lod.x = foveate_lod(param.x.a, param.x.b, param.x.scale, param.x.center, u);
out.x = std::clamp<float>((1 + out.x) / 2, 0, 1);
}
else
{
out.x = u;
lod.x = 0;
}
if (param.y.scale < 1)
@@ -143,19 +133,15 @@ bool wivrn_hmd::wivrn_hmd_compute_distortion(xrt_device * xdev, uint32_t view_in
v = 2 * v - 1;
out.y = foveate(param.y.a, param.y.b, param.y.scale, param.y.center, v);
lod.y = foveate_lod(param.y.a, param.y.b, param.y.scale, param.y.center, v);
out.y = std::clamp<float>((1 + out.y) / 2, 0, 1);
}
else
{
out.y = v;
lod.y = 0;
}
U_LOG_D("distortion parameters: %f %f (%f %f)", lod.x, lod.y, u, v);
result->r = out;
result->g = lod;
result->g = out;
result->b = out;
return true;
-3
View File
@@ -288,9 +288,6 @@ void start_server(configuration config)
// there is no need for oversampling.
setenv("XRT_COMPOSITOR_SCALE_PERCENTAGE", "100", false);
// Enable mipmaps for distortion
setenv("XRT_DISTORTION_MIP_LEVELS", "0", false);
// FIXME: synchronization fails on gfx pipeline
setenv("XRT_COMPOSITOR_COMPUTE", "1", true);
-9
View File
@@ -21,7 +21,6 @@
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout(set = 0, binding = 0, rgba8) uniform writeonly restrict image2D target;
layout(set = 0, binding = 1, rgba8) uniform writeonly restrict image2D dtarget;
layout(push_constant) uniform PushConstants
{
@@ -37,11 +36,6 @@ float foveate(float a, float b, float scale, float c, float x) {
return scale / a * tan(a * x + b) + c;
}
float foveate_lod(float a, float b, float scale, float c, float x) {
// derivate foveation and add a bias
return max(0, log2(1 / (cos(a * x + b) * cos(a * x + b)) - 0.5));
}
void main()
{
ivec2 coords = ivec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y);
@@ -55,17 +49,14 @@ void main()
if (pcs.scale.x < 1.0) {
float u = uv.x * 2.0 - 1.0;
float val = foveate(pcs.a.x, pcs.b.x, pcs.scale.x, pcs.center.x, u);
duv.x = foveate_lod(pcs.a.x, pcs.b.x, pcs.scale.x, pcs.center.x, u);
uv.x = clamp((1.0 + val) / 2.0, 0.0, 1.0);
}
if (pcs.scale.y < 1.0) {
float v = uv.y * 2.0 - 1.0;
float val = foveate(pcs.a.y, pcs.b.y, pcs.scale.y, pcs.center.y, v);
duv.y= foveate_lod(pcs.a.y, pcs.b.y, pcs.scale.y, pcs.center.y, v);
uv.y = clamp((1.0 + val) / 2.0, 0.0, 1.0);
}
imageStore(target, coords, vec4(uv.x, uv.y, 0.0, 0.0));
imageStore(dtarget, coords, vec4(duv.x, duv.y, 0.0, 0.0));
}