diff --git a/client/decoder/android/android_decoder.cpp b/client/decoder/android/android_decoder.cpp index 0d5f4217..bde67eff 100644 --- a/client/decoder/android/android_decoder.cpp +++ b/client/decoder/android/android_decoder.cpp @@ -409,7 +409,8 @@ std::shared_ptr 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 diff --git a/client/decoder/android/android_decoder.h b/client/decoder/android/android_decoder.h index 27d26c1f..3cfa3cb4 100644 --- a/client/decoder/android/android_decoder.h +++ b/client/decoder/android/android_decoder.h @@ -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 image_reader; diff --git a/client/decoder/decoder.h b/client/decoder/decoder.h index 1886759a..44497327 100644 --- a/client/decoder/decoder.h +++ b/client/decoder/decoder.h @@ -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 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 supported_codecs(); }; diff --git a/client/decoder/ffmpeg/ffmpeg_decoder.cpp b/client/decoder/ffmpeg/ffmpeg_decoder.cpp index afa61e4c..7f960b37 100644 --- a/client/decoder/ffmpeg/ffmpeg_decoder.cpp +++ b/client/decoder/ffmpeg/ffmpeg_decoder.cpp @@ -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; diff --git a/client/decoder/ffmpeg/ffmpeg_decoder.h b/client/decoder/ffmpeg/ffmpeg_decoder.h index 360de157..9bc121d5 100644 --- a/client/decoder/ffmpeg/ffmpeg_decoder.h +++ b/client/decoder/ffmpeg/ffmpeg_decoder.h @@ -65,7 +65,6 @@ private: vk::raii::Sampler rgb_sampler = nullptr; std::array decoded_images; - vk::Extent2D extent{}; std::vector free_images; std::unique_ptr codec; @@ -96,11 +95,6 @@ public: return *rgb_sampler; } - vk::Extent2D image_size() - { - return extent; - } - static void supported_codecs(std::vector &); }; } // namespace wivrn::ffmpeg diff --git a/client/decoder/shard_accumulator.h b/client/decoder/shard_accumulator.h index bcc7730b..a0145e22 100644 --- a/client/decoder/shard_accumulator.h +++ b/client/decoder/shard_accumulator.h @@ -105,6 +105,11 @@ public: return decoder_->sampler(); } + const vk::Extent2D extent() + { + return decoder_->extent(); + } + using blit_handle = decoder::blit_handle; private: diff --git a/client/scenes/blitter.cpp b/client/scenes/blitter.cpp index 39ec6982..e7da127e 100644 --- a/client/scenes/blitter.cpp +++ b/client/scenes/blitter.cpp @@ -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)); diff --git a/client/scenes/blitter.h b/client/scenes/blitter.h index c1a037e8..26685c72 100644 --- a/client/scenes/blitter.h +++ b/client/scenes/blitter.h @@ -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 diff --git a/client/scenes/stream.cpp b/client/scenes/stream.cpp index ecf72112..ed89a35c 100644 --- a/client/scenes/stream.cpp +++ b/client/scenes/stream.cpp @@ -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); } diff --git a/client/scenes/stream_defoveator.cpp b/client/scenes/stream_defoveator.cpp index 5343a4ee..7086e2a1 100644 --- a/client/scenes/stream_defoveator.cpp +++ b/client/scenes/stream_defoveator.cpp @@ -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, }; }