Fix defoveation for low scale values
The effective image size may be different from the size in description, we have to only consider the useful size
This commit is contained in:
@@ -76,10 +76,7 @@ void blitter::reset(const to_headset::video_stream_description & desc)
|
||||
.x = int32_t(view * w) - item.offset_x,
|
||||
.y = 0,
|
||||
},
|
||||
.extent = {
|
||||
.width = uint32_t(item.video_width * item.subsampling),
|
||||
.height = uint32_t(item.video_height * item.subsampling),
|
||||
}};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -201,13 +198,14 @@ void blitter::begin(vk::raii::CommandBuffer & cmd)
|
||||
vk::SubpassContents::eInline);
|
||||
}
|
||||
|
||||
void blitter::push_image(vk::raii::CommandBuffer & cmd, uint8_t stream, vk::Sampler sampler, vk::ImageView image, vk::ImageLayout layout)
|
||||
void blitter::push_image(vk::raii::CommandBuffer & cmd, uint8_t stream, vk::Sampler sampler, const vk::Extent2D & extent_, vk::ImageView image, vk::ImageLayout layout)
|
||||
{
|
||||
if (stream == passthrough_rgb)
|
||||
{
|
||||
current.rgb = image;
|
||||
current.sampler_rgb = sampler;
|
||||
current.layout_rgb = layout;
|
||||
current.rect_rgb.extent = extent_;
|
||||
return;
|
||||
}
|
||||
if (stream == passthrough_a)
|
||||
@@ -215,6 +213,7 @@ void blitter::push_image(vk::raii::CommandBuffer & cmd, uint8_t stream, vk::Samp
|
||||
current.a = image;
|
||||
current.sampler_a = sampler;
|
||||
current.layout_a = layout;
|
||||
current.rect_a.extent = extent_;
|
||||
return;
|
||||
}
|
||||
if (pipelines.empty())
|
||||
@@ -245,8 +244,8 @@ void blitter::push_image(vk::raii::CommandBuffer & cmd, uint8_t stream, vk::Samp
|
||||
});
|
||||
|
||||
auto vert_constants = make_specialization_constants(
|
||||
float(description.width) / description.video_width,
|
||||
float(description.height) / description.video_height);
|
||||
float(description.width) / extent_.width,
|
||||
float(description.height) / extent_.height);
|
||||
|
||||
auto frag_constants = make_specialization_constants(
|
||||
VkBool32(alpha));
|
||||
|
||||
@@ -66,7 +66,7 @@ public:
|
||||
|
||||
void reset(const to_headset::video_stream_description & desc);
|
||||
void begin(vk::raii::CommandBuffer &);
|
||||
void push_image(vk::raii::CommandBuffer & buf, uint8_t stream, vk::Sampler sampler, vk::ImageView image, vk::ImageLayout);
|
||||
void push_image(vk::raii::CommandBuffer & buf, uint8_t stream, vk::Sampler sampler, const vk::Extent2D &, vk::ImageView image, vk::ImageLayout);
|
||||
output end(vk::raii::CommandBuffer &);
|
||||
};
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -877,7 +877,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
{
|
||||
if (not blit_handle)
|
||||
continue;
|
||||
b.push_image(command_buffer, j, decoders[j].decoder->sampler(), blit_handle->image_view, blit_handle->current_layout);
|
||||
b.push_image(command_buffer, j, decoders[j].decoder->sampler(), decoders[j].decoder->extent(), blit_handle->image_view, blit_handle->current_layout);
|
||||
}
|
||||
blitted[i] = b.end(command_buffer);
|
||||
}
|
||||
|
||||
@@ -394,6 +394,7 @@ void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
||||
|
||||
for (size_t view = 0; view < view_count; ++view)
|
||||
{
|
||||
const auto out_size = defoveated_size(foveation[view]);
|
||||
auto vertices = get_vertices(view);
|
||||
const auto & [px, py] = foveation[view];
|
||||
assert(px.size() % 2 == 1);
|
||||
@@ -402,42 +403,42 @@ void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
||||
const int n_ratio_x = (px.size() - 1) / 2;
|
||||
|
||||
glm::uvec2 in(0);
|
||||
glm::vec2 out(0); // pixel coordinates
|
||||
glm::vec2 out_pixel_size(2. / output_extent.width,
|
||||
2. / output_extent.height);
|
||||
glm::vec2 out(-0.5 * out_size.width, -0.5 * out_size.height); // pixel coordinates
|
||||
glm::vec2 out_pixel_size(2. / out_size.width,
|
||||
2. / out_size.height);
|
||||
for (auto [iy, n_out_y]: utils::enumerate_range(py))
|
||||
{
|
||||
// number of output pixels per source pixels
|
||||
const int ratio_y = std::abs(n_ratio_y - int(iy)) + 1;
|
||||
in.x = 0;
|
||||
out.x = 0;
|
||||
out.x = -0.5 * out_size.width;
|
||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||
{
|
||||
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
|
||||
glm::uvec2 rate = glm::uvec2(shading_rate(ratio_x, ratio_y), 0);
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in | rate,
|
||||
};
|
||||
*vertices++ = {
|
||||
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size - glm::vec2(1),
|
||||
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size,
|
||||
.uv = (in + glm::uvec2(0, n_out_y)) | rate,
|
||||
};
|
||||
in.x += n_out_x;
|
||||
out.x += n_out_x * ratio_x;
|
||||
}
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
in.y += n_out_y;
|
||||
out.y += n_out_y * ratio_y;
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size - glm::vec2(1),
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user