Skip to content

armgit / raea

Public Imported from GitHub
0

Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.

An image larger than Vello's atlas is decoded at a size that fits it (#245: a 1080x18000 site capture drawn 880 wide was refused; fit to the atlas's side, 16384, not the device's 32768); a Snapdragon's Adreno runs on DX12 on Windows, where Vulkan drew Vello's 2D pages striped (#82)

shinyobjectz561e7a569ced
diff --git a/gpu/device/src/lib.rs b/gpu/device/src/lib.rs
index 03f59c79..b3aeebc6 100644
--- a/gpu/device/src/lib.rs
+++ b/gpu/device/src/lib.rs
@@ -34,6 +34,8 @@ pub fn device() -> Result<Handles, String> {
/// Intel's and AMD's PCI vendor ids, as DXGI and Vulkan report them.
const INTEL: u32 = 0x8086;
const AMD: u32 = 0x1002;
+/// Qualcomm's (Adreno, on a Windows on ARM PC): DXGI reports "QCOM" as its vendor, some drivers 0x5143
+const QUALCOMM: [u32; 2] = [0x4D4F_4351, 0x5143];
/// Whether the shared device runs on DX12 alone: on Windows, when WGPU_BACKEND isn't set and DX12 lists Intel's or
/// AMD's own hardware among its GPUs (`dx12`: each one's vendor and kind; WARP, Windows' software DirectX, is a Cpu),
@@ -41,10 +43,12 @@ const AMD: u32 = 0x1002;
/// 0.1.3's app crashed before its window in AMD's OpenGL driver (atio6axx.dll, 0xc0000005) on a laptop with an AMD
/// 780M beside an RTX 5060, under wgpu's every-backend default and under Vulkan alike (#155); both ran with
/// WGPU_BACKEND=dx12. On that laptop DX12's high-performance pick is the NVIDIA GPU, so the rule looks at every GPU,
-/// not the pick. A PC with only NVIDIA's GPUs, a PC with no GPU, a Mac or Linux, and a WGPU_BACKEND someone set
+/// not the pick. A Snapdragon PC's Adreno too (#82): under Vulkan Vello's 2D pages came out striped and with grey boxes
+/// behind fading text on an Adreno X1-85, and on DX12 they were clean. A PC with only NVIDIA's GPUs, a PC with no GPU,
+/// a Mac or Linux, and a WGPU_BACKEND someone set
/// (Windows' check sets vulkan, for lavapipe) keep wgpu's own pick.
pub fn dx12_first(windows: bool, env: Option<wgpu::Backends>, dx12: &[(u32, wgpu::DeviceType)]) -> bool {
- windows && env.is_none() && dx12.iter().any(|&(vendor, kind)| matches!(vendor, INTEL | AMD) && kind != wgpu::DeviceType::Cpu)
+ windows && env.is_none() && dx12.iter().any(|&(vendor, kind)| (matches!(vendor, INTEL | AMD) || QUALCOMM.contains(&vendor)) && kind != wgpu::DeviceType::Cpu)
}
/// The backends every wgpu instance of raea's asks for (the shared device's, Bevy's own when it isn't there, systems/k's
@@ -147,6 +151,8 @@ mod tests {
assert!(dx12_first(true, None, &[(AMD, igpu), (0x10de, dgpu), warp]), "#155: an AMD 780M beside an RTX 5060 (DX12 picks the NVIDIA)");
assert!(dx12_first(true, None, &[(0x10de, dgpu), (AMD, igpu)]), "the same laptop listed NVIDIA first");
assert!(dx12_first(true, None, &[(AMD, dgpu)]), "an AMD Radeon card");
+ assert!(dx12_first(true, None, &[(0x4D4F_4351, igpu), warp]), "#82: a Snapdragon's Adreno (DXGI's QCOM)");
+ assert!(dx12_first(true, None, &[(0x5143, igpu)]), "#82: an Adreno reported by its PCI id");
assert!(dx12_first(true, None, &[(INTEL, igpu), (0x10de, dgpu)]), "an Intel laptop with an NVIDIA GPU");
assert!(!dx12_first(true, Some(Backends::VULKAN), &[(INTEL, igpu)]), "WGPU_BACKEND=vulkan is kept");
assert!(!dx12_first(true, Some(Backends::DX12), &[(AMD, igpu)]), "WGPU_BACKEND set: wgpu's own read of it");
diff --git a/systems/page/src/draw.rs b/systems/page/src/draw.rs
index e31240e5..f7b5ca44 100644
--- a/systems/page/src/draw.rs
+++ b/systems/page/src/draw.rs
@@ -159,6 +159,9 @@ pub fn draw(mut scenes: ResMut<Scenes>, mut vello: ResMut<Vello>, device: Res<Re
}
// the image atlas (each filtered element is an image in it) as large as the device can make, not Vello's 8192
vello::low_level::vello_encoding::set_max_atlas_size(device.limits().max_texture_dimension_2d);
+ // and an image larger than the atlas (16384 at most, whatever the device allows) decoded at a size that fits it
+ // (raea#245: an M5's GPU allows 32768, and a 1080x18000 picture was kept whole and refused)
+ blitz_dom::net::set_max_image_side(vello::low_level::vello_encoding::max_atlas_size());
vello::Renderer::new(
device,
vello::RendererOptions { antialiasing_support: vello::AaSupport::area_only(), num_init_threads: std::num::NonZeroUsize::new(1), ..default() },
diff --git a/vendor/blitz-dom/src/net.rs b/vendor/blitz-dom/src/net.rs
index 3507b8bc..930dccdd 100644
--- a/vendor/blitz-dom/src/net.rs
+++ b/vendor/blitz-dom/src/net.rs
@@ -585,13 +585,27 @@ impl NetHandler for ResourceHandler<ImageHandler> {
/// cards ask theirs at the card's size (raea-feed src/feed/media.ts): a 2560x1440 still held 14.7 MB decoded on a card
/// drawn 1440 pixels wide at most, 4.7 MB fitted (raea-feed e2e/memory.spec.ts). Area-averaged (`thumbnail`), on
/// premultiplied pixels when any is see-through, so no edge takes the colour of the transparent pixels beside it.
-pub fn fit(url: &str, w: u32, h: u32, mut rgba: Vec<u8>) -> (u32, u32, Vec<u8>) {
+///
+/// And one larger than the GPU's largest texture on either side (`set_max_image_side`, the side of Vello's image
+/// atlas) is scaled down to fit it, its shape kept: Vello can only draw an image that fits its atlas, and a full-page
+/// site capture (1080x18000) drawn 880 wide was refused outright (raea#245). Chrome draws it; here it's drawn from a
+/// copy at most the atlas's side tall, which a page never draws larger than its own size anyway.
+pub fn fit(url: &str, w: u32, h: u32, rgba: Vec<u8>) -> (u32, u32, Vec<u8>) {
+ fit_within(url, w, h, rgba, MAX_IMAGE_SIDE.load(std::sync::atomic::Ordering::Relaxed))
+}
+
+fn fit_within(url: &str, w: u32, h: u32, mut rgba: Vec<u8>, side: u32) -> (u32, u32, Vec<u8>) {
let query = url.split('#').next().and_then(|u| u.split_once('?')).map_or("", |(_, q)| q);
let want = |k: &str| query.split('&').find_map(|kv| kv.strip_prefix(k)?.strip_prefix('=')?.parse::<u32>().ok()).filter(|n| *n > 0);
- let scale = [want("raea-w").map(|n| n as f64 / w.max(1) as f64), want("raea-h").map(|n| n as f64 / h.max(1) as f64)]
- .into_iter()
- .flatten()
- .fold(1.0f64, f64::min);
+ let side = side.max(1) as f64;
+ let scale = [
+ want("raea-w").map(|n| n as f64 / w.max(1) as f64),
+ want("raea-h").map(|n| n as f64 / h.max(1) as f64),
+ (w.max(h) as f64 > side).then(|| side / w.max(h) as f64),
+ ]
+ .into_iter()
+ .flatten()
+ .fold(1.0f64, f64::min);
if scale >= 1.0 || w == 0 || h == 0 || rgba.len() != w as usize * h as usize * 4 {
return (w, h, rgba);
}
@@ -620,6 +634,17 @@ pub fn fit(url: &str, w: u32, h: u32, mut rgba: Vec<u8>) -> (u32, u32, Vec<u8>)
(nw, nh, out)
}
+/// raea: the longest side a decoded image keeps (`fit`): Vello's image atlas's side (the GPU's largest texture, 16384 at most).
+/// 16384 until the page's renderer says (systems/page draw.rs, from the device's `max_texture_dimension_2d`)
+static MAX_IMAGE_SIDE: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(16384);
+
+/// raea: the longest side an image is decoded at, from here on (the device's largest texture)
+pub fn set_max_image_side(px: u32) {
+ if px > 0 {
+ MAX_IMAGE_SIDE.store(px, std::sync::atomic::Ordering::Relaxed);
+ }
+}
+
impl ImageHandler {
fn parse(&self, bytes: Bytes, url: &str) -> Result<Resource, String> {
if let Some((width, height, rgba)) = IMAGE_DECODER.get().and_then(|d| d(url, &bytes)) {
@@ -728,3 +753,25 @@ mod tests {
);
}
}
+
+#[cfg(test)]
+mod fit_tests {
+ use super::fit_within;
+
+ // raea#245: a picture taller than the GPU's largest texture is decoded at a size that fits it, its shape kept
+ #[test]
+ fn an_image_past_the_atlas_side_is_fitted_to_it() {
+ let (w, h) = (54, 900);
+ let (nw, nh, px) = fit_within("tall.png", w, h, vec![200; (w * h * 4) as usize], 819);
+ assert_eq!((nw, nh), (49, 819));
+ assert_eq!(px.len(), (nw * nh * 4) as usize);
+ assert!(px.iter().all(|&c| c == 200));
+ }
+
+ #[test]
+ fn an_image_inside_it_is_left_alone_and_a_url_s_size_still_wins() {
+ let (w, h) = (54, 800);
+ assert_eq!(fit_within("a.png", w, h, vec![0; (w * h * 4) as usize], 819).0, 54);
+ assert_eq!(fit_within("a.png?raea-h=400", w, h, vec![0; (w * h * 4) as usize], 819).1, 400);
+ }
+}