Hand Android's develop frame to the compositor as a texture again
With Skia drawing pre-rotated on wgpu's Vulkan swapchain, Android no longer needs to draw with Skia over OpenGL, which was the only reason the develop view read its frame back through memory (TD-1). So `unstable-wgpu-29` moves back to the common slint dependency. The android-activity backend then builds `SkiaRenderer::default_wgpu_29`, and `shared_gpu` loses its Android arm. The one wgpu device is handed to Slint through `BackendSelector::require_wgpu_29` on both platforms. `slint::android::init_with_event_listener` runs before `dr_ui::run`, so the selector reaches the Android adapter before its window exists. `renderer-femtovg-wgpu` stays desktop-only, since Android has no FemtoVG. The two `#[cfg(target_os = "android")]` readbacks in `develop::render` (the frame through `export_pixels` and the focus overlay through `read_overlay`) are gone. `read_overlay` stays for the tests that check what the overlay marks. Built for arm64 and release-signed. Not yet run on the tablet.
This commit is contained in:
@@ -278,29 +278,8 @@ impl DevelopSession {
|
||||
// in `AdjustPass`'s texture descriptor — so a failure here is a
|
||||
// descriptor that drifted, not anything the caller did. Say that,
|
||||
// rather than surfacing "InvalidUsage" to a photographer.
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
slint::Image::try_from(texture.clone())
|
||||
.map_err(|e| format!("the render target is not importable by the compositor: {e}"))
|
||||
}
|
||||
|
||||
// Android draws with Skia over OpenGL and cannot sample a
|
||||
// `wgpu::Texture`, so the frame comes back through memory. See
|
||||
// `crate::shared_gpu`'s Android arm for why that is the trade on this
|
||||
// platform. The pass still runs on the GPU; only this last hop does not.
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
let _ = texture;
|
||||
let (rgba, w, h) = self
|
||||
.adjust
|
||||
.export_pixels()
|
||||
.map_err(|e| format!("reading the rendered frame back: {e}"))?;
|
||||
let mut buf = slint::SharedPixelBuffer::<slint::Rgba8Pixel>::new(w, h);
|
||||
let wanted = (w as usize) * (h as usize) * 4;
|
||||
let src = &rgba[..wanted.min(rgba.len())];
|
||||
buf.make_mut_bytes()[..src.len()].copy_from_slice(src);
|
||||
Ok(slint::Image::from_rgba8(buf))
|
||||
}
|
||||
slint::Image::try_from(texture.clone())
|
||||
.map_err(|e| format!("the render target is not importable by the compositor: {e}"))
|
||||
}
|
||||
|
||||
/// TRACES: FR-DSP-7
|
||||
@@ -463,33 +442,12 @@ impl DevelopSession {
|
||||
.ok()?
|
||||
.clone();
|
||||
|
||||
#[cfg(not(target_os = "android"))]
|
||||
{
|
||||
// A layer over the canvas rather than a tint in it, so nothing
|
||||
// here reaches the histogram or an export — see `FocusPeakPass`
|
||||
// for the whole of that argument.
|
||||
slint::Image::try_from(overlay)
|
||||
.inspect_err(|e| log::warn!("the focus overlay is not importable: {e}"))
|
||||
.ok()
|
||||
}
|
||||
|
||||
// Android draws with Skia over OpenGL and cannot sample a
|
||||
// `wgpu::Texture`, so the overlay follows the frame it belongs to back
|
||||
// through memory (technical-debt.md TD-1). The measurement still
|
||||
// happens on the GPU; only this last hop does not.
|
||||
#[cfg(target_os = "android")]
|
||||
{
|
||||
let _ = overlay;
|
||||
let (rgba, w, h) = pass
|
||||
.read_overlay()
|
||||
.inspect_err(|e| log::warn!("reading the focus overlay back: {e}"))
|
||||
.ok()?;
|
||||
let mut buf = slint::SharedPixelBuffer::<slint::Rgba8Pixel>::new(w, h);
|
||||
let wanted = (w as usize) * (h as usize) * 4;
|
||||
let src = &rgba[..wanted.min(rgba.len())];
|
||||
buf.make_mut_bytes()[..src.len()].copy_from_slice(src);
|
||||
Some(slint::Image::from_rgba8(buf))
|
||||
}
|
||||
// A layer over the canvas rather than a tint in it, so nothing
|
||||
// here reaches the histogram or an export — see `FocusPeakPass`
|
||||
// for the whole of that argument.
|
||||
slint::Image::try_from(overlay)
|
||||
.inspect_err(|e| log::warn!("the focus overlay is not importable: {e}"))
|
||||
.ok()
|
||||
}
|
||||
|
||||
/// Render the *whole* frame for the crop overlay to be drawn over.
|
||||
|
||||
+9
-45
@@ -1071,7 +1071,13 @@ enum PointsUpdate {
|
||||
///
|
||||
/// `None` means develop is unavailable and the viewer falls back to embedded
|
||||
/// previews — the same degradation as a machine with no adapter at all.
|
||||
#[cfg(not(target_os = "android"))]
|
||||
///
|
||||
/// **The same on Android**, where Slint draws with Skia rather than FemtoVG
|
||||
/// but on this device all the same. It used to open a device of its own
|
||||
/// there and read every frame back (TD-1), because wgpu's Vulkan swapchain
|
||||
/// could not pre-rotate and a portrait window tore on the tablet's
|
||||
/// landscape-mounted panel. The patched wgpu-hal and Skia renderer in
|
||||
/// `third_party/` pre-rotate it now; see technical-debt.md TD-1.
|
||||
fn shared_gpu() -> Option<dr_gpu::GpuContext> {
|
||||
let shared = match pollster::block_on(dr_gpu::GpuContext::new_shared()) {
|
||||
Ok(shared) => shared,
|
||||
@@ -1112,45 +1118,6 @@ fn shared_gpu() -> Option<dr_gpu::GpuContext> {
|
||||
Some(ctx)
|
||||
}
|
||||
|
||||
/// TRACES: FR-DSP-1 | AC-8
|
||||
/// Open the compute device on Android — and do **not** give it to Slint.
|
||||
///
|
||||
/// # Why this platform is different
|
||||
///
|
||||
/// The desktop version above exists so one `wgpu::Texture` can be written by
|
||||
/// the adjust pass and sampled by the compositor without a round-trip. That
|
||||
/// requires Slint to be drawing with wgpu, and on Android drawing with wgpu
|
||||
/// means drawing on wgpu's Vulkan swapchain — which hardcodes
|
||||
/// `preTransform = IDENTITY` (gfx-rs/wgpu#3345).
|
||||
///
|
||||
/// On a tablet whose panel is mounted landscape, portrait then presents an
|
||||
/// unrotated buffer, every present returns `VK_SUBOPTIMAL_KHR`, and the frames
|
||||
/// arrive torn. Measured on the device: portrait sits on `composition=CLIENT`
|
||||
/// with `bufferTransform=ROT_270`, landscape on `composition=DEVICE` with
|
||||
/// `ROT_180`, and only portrait tore. Taking Slint off wgpu — it then uses
|
||||
/// Skia over OpenGL, where the driver owns the rotation — fixed it.
|
||||
///
|
||||
/// # What it costs, and why that is the right trade here
|
||||
///
|
||||
/// Without a shared device the display path needs a readback:
|
||||
/// `AdjustPass::export_pixels` instead of `Image::try_from(texture)`. That is
|
||||
/// the transfer ARCH §6.1 and AC-8 exist to avoid, and it is still the better
|
||||
/// bargain on this platform — the alternative is not a faster develop view, it
|
||||
/// is a torn one, in the orientation a tablet is mostly held in.
|
||||
///
|
||||
/// The compute passes are untouched: demosaic and adjust still run on the GPU,
|
||||
/// on this device. Only the last hop to the screen goes through memory.
|
||||
#[cfg(target_os = "android")]
|
||||
fn shared_gpu() -> Option<dr_gpu::GpuContext> {
|
||||
match pollster::block_on(dr_gpu::GpuContext::new_headless()) {
|
||||
Ok(ctx) => Some(ctx),
|
||||
Err(e) => {
|
||||
log::warn!("no GPU for the develop passes: {e}");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// TRACES: M-13 | M-14
|
||||
/// Build and run the viewer.
|
||||
pub fn run(paths: Vec<PathBuf>) -> Result<()> {
|
||||
@@ -1181,11 +1148,8 @@ pub fn run(paths: Vec<PathBuf>) -> Result<()> {
|
||||
// app still browses through the preview path, just without develop.
|
||||
//
|
||||
// Timed rather than moved: this is a Vulkan instance, an adapter
|
||||
// enumeration and a device request, none of which can be deferred on the
|
||||
// desktop because the backend must be chosen before a window exists. On
|
||||
// Android it could be — nothing shares that device with the compositor
|
||||
// (TD-1) — but "could be" is not "costs enough to be worth it", and this
|
||||
// line is what will say which.
|
||||
// enumeration and a device request, none of which can be deferred
|
||||
// because the backend must be chosen before a window exists.
|
||||
let gpu = shared_gpu();
|
||||
log::info!("gpu opened in {} ms", launch_began.elapsed().as_millis());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user