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:
@@ -409,7 +409,8 @@ std::shared_ptr<decoder::mapped_hardware_buffer> decoder::map_hardware_buffer(AI
|
||||
if (!*ycbcr_sampler || memcmp(&ahb_format, &format_properties, sizeof(format_properties)))
|
||||
{
|
||||
memcpy(&ahb_format, &format_properties, sizeof(format_properties));
|
||||
extent = {buffer_desc.width, buffer_desc.height};
|
||||
extent_ = {buffer_desc.width, buffer_desc.height};
|
||||
spdlog::info("decoded image size: {}x{}", buffer_desc.width, buffer_desc.height);
|
||||
create_sampler(buffer_desc, ahb_format);
|
||||
hardware_buffer_map.clear();
|
||||
// TODO tell the reprojector to recreate the pipeline
|
||||
|
||||
@@ -74,7 +74,6 @@ private:
|
||||
vk::AndroidHardwareBufferFormatPropertiesANDROID ahb_format;
|
||||
vk::raii::SamplerYcbcrConversion ycbcr_conversion = nullptr;
|
||||
vk::raii::Sampler ycbcr_sampler = nullptr;
|
||||
vk::Extent2D extent{};
|
||||
|
||||
std::mutex hbm_mutex;
|
||||
std::shared_ptr<AImageReader> image_reader;
|
||||
|
||||
@@ -50,6 +50,7 @@ public:
|
||||
protected:
|
||||
decoder(const wivrn::to_headset::video_stream_description::item & description) :
|
||||
description(description) {}
|
||||
vk::Extent2D extent_; // Must be populated when sampler is set
|
||||
|
||||
public:
|
||||
static std::shared_ptr<decoder> make(
|
||||
@@ -68,6 +69,10 @@ public:
|
||||
const to_headset::video_stream_data_shard::view_info_t & view_info) = 0;
|
||||
|
||||
virtual vk::Sampler sampler() = 0;
|
||||
const vk::Extent2D extent()
|
||||
{
|
||||
return extent_;
|
||||
}
|
||||
|
||||
static std::vector<wivrn::video_codec> supported_codecs();
|
||||
};
|
||||
|
||||
@@ -137,7 +137,7 @@ decoder::decoder(
|
||||
decoded_images[i].image = image_allocation(device, image_info, alloc_info);
|
||||
|
||||
decoded_images[i].image.map();
|
||||
extent = vk::Extent2D{description.width, description.height};
|
||||
extent_ = vk::Extent2D{description.width, description.height};
|
||||
|
||||
vk::ImageSubresource resource;
|
||||
resource.aspectMask = vk::ImageAspectFlagBits::eColor;
|
||||
|
||||
@@ -65,7 +65,6 @@ private:
|
||||
vk::raii::Sampler rgb_sampler = nullptr;
|
||||
|
||||
std::array<image, image_count> decoded_images;
|
||||
vk::Extent2D extent{};
|
||||
std::vector<int> free_images;
|
||||
|
||||
std::unique_ptr<AVCodecContext, void (*)(AVCodecContext *)> codec;
|
||||
@@ -96,11 +95,6 @@ public:
|
||||
return *rgb_sampler;
|
||||
}
|
||||
|
||||
vk::Extent2D image_size()
|
||||
{
|
||||
return extent;
|
||||
}
|
||||
|
||||
static void supported_codecs(std::vector<wivrn::video_codec> &);
|
||||
};
|
||||
} // namespace wivrn::ffmpeg
|
||||
|
||||
@@ -105,6 +105,11 @@ public:
|
||||
return decoder_->sampler();
|
||||
}
|
||||
|
||||
const vk::Extent2D extent()
|
||||
{
|
||||
return decoder_->extent();
|
||||
}
|
||||
|
||||
using blit_handle = decoder::blit_handle;
|
||||
|
||||
private:
|
||||
|
||||
@@ -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