-
Notifications
You must be signed in to change notification settings - Fork 259
fix: preserve image atlas across patchless resolves #1664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
waywardmonkeys
wants to merge
1
commit into
linebender:main
Choose a base branch
from
waywardmonkeys:fix/image-atlas-patchless-resolve
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,21 @@ | |
|
|
||
| //! Tests to ensure that certain issues which don't deserve a test scene don't regress | ||
|
|
||
| use std::sync::Arc; | ||
|
|
||
| use scenes::ImageCache; | ||
| use scenes::SimpleText; | ||
| use vello::{ | ||
| AaConfig, Scene, | ||
| AaConfig, RendererOptions, Scene, | ||
| kurbo::{Affine, Rect, RoundedRect, Stroke}, | ||
| peniko::{ | ||
| Color, ColorStop, Extend, Gradient, ImageQuality, InterpolationAlphaSpace, color::palette, | ||
| Blob, Brush, Color, ColorStop, Extend, Gradient, ImageAlphaType, ImageBrush, ImageData, | ||
| ImageFormat, ImageQuality, InterpolationAlphaSpace, color::palette, | ||
| }, | ||
| util::{RenderContext, block_on_wgpu}, | ||
| wgpu::{ | ||
| self, BufferDescriptor, BufferUsages, CommandEncoderDescriptor, Extent3d, | ||
| TexelCopyBufferInfo, TextureDescriptor, TextureFormat, TextureUsages, | ||
| }, | ||
| }; | ||
| use vello_tests::{TestParams, smoke_snapshot_test_sync, snapshot_test_sync}; | ||
|
|
@@ -144,6 +152,187 @@ fn text_stroke_width_zero() { | |
| .assert_mean_less_than(0.001); | ||
| } | ||
|
|
||
| const GLYPH_IMAGE_BACKGROUND: [u8; 4] = [247, 243, 236, 255]; | ||
|
|
||
| fn glyph_image_background() -> Color { | ||
| Color::from_rgba8( | ||
| GLYPH_IMAGE_BACKGROUND[0], | ||
| GLYPH_IMAGE_BACKGROUND[1], | ||
| GLYPH_IMAGE_BACKGROUND[2], | ||
| GLYPH_IMAGE_BACKGROUND[3], | ||
| ) | ||
| } | ||
|
|
||
| fn glyph_image_data() -> ImageData { | ||
| let width = 96_u32; | ||
| let height = 96_u32; | ||
| let mut bytes = Vec::with_capacity(usize::try_from(width * height * 4).unwrap()); | ||
| for y in 0..height { | ||
| for x in 0..width { | ||
| let r = 32 + u8::try_from((223 * x) / (width - 1)).unwrap(); | ||
| let g = 36 + u8::try_from((170 * y) / (height - 1)).unwrap(); | ||
| let stripe = if ((x / 8) + (y / 8)) % 2 == 0 { 34 } else { 0 }; | ||
| let b = 82 + stripe; | ||
| bytes.extend_from_slice(&[r, g, b, 255]); | ||
| } | ||
| } | ||
| ImageData { | ||
| data: Blob::new(Arc::new(bytes)), | ||
| format: ImageFormat::Rgba8, | ||
| width, | ||
| height, | ||
| alpha_type: ImageAlphaType::Alpha, | ||
| } | ||
| } | ||
|
|
||
| fn glyph_image_brush(image: &ImageData) -> Brush { | ||
| Brush::Image( | ||
| ImageBrush::new(image.clone()) | ||
| .with_quality(ImageQuality::Medium) | ||
| .with_extend(Extend::Repeat), | ||
| ) | ||
| } | ||
|
|
||
| fn glyph_image_brush_scene(image: &ImageData) -> Scene { | ||
| let mut scene = Scene::new(); | ||
| let mut text = SimpleText::new(); | ||
| scene.fill( | ||
| vello::peniko::Fill::NonZero, | ||
| Affine::IDENTITY, | ||
| glyph_image_background(), | ||
| None, | ||
| &Rect::new(0.0, 0.0, 256.0, 256.0), | ||
| ); | ||
| let brush = glyph_image_brush(image); | ||
| text.add_var_run( | ||
| &mut scene, | ||
| None, | ||
| 42.0, | ||
| &[], | ||
| &brush, | ||
| Affine::translate((14.0, 116.0)), | ||
| None, | ||
| None, | ||
| vello::peniko::Fill::NonZero, | ||
| "texture", | ||
| true, | ||
| ); | ||
| scene | ||
| } | ||
|
|
||
| fn image_free_scene() -> Scene { | ||
| let mut scene = Scene::new(); | ||
| scene.fill( | ||
| vello::peniko::Fill::NonZero, | ||
| Affine::IDENTITY, | ||
| Color::from_rgb8(30, 30, 34), | ||
| None, | ||
| &Rect::new(0.0, 0.0, 256.0, 256.0), | ||
| ); | ||
| scene | ||
| } | ||
|
|
||
| #[test] | ||
| #[cfg_attr(skip_gpu_tests, ignore)] | ||
| fn glyph_image_brush_survives_image_free_render() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be doing an awful lot of the harness work from scratch as opposed to using existing harnesses. In particular, it seems to duplicate a lot of logic in |
||
| pollster::block_on(async { | ||
| let width = 256; | ||
| let height = 256; | ||
| let image = glyph_image_data(); | ||
| let mut context = RenderContext::new(); | ||
| let device_id = context.device(None).await.expect("compatible device"); | ||
| let device_handle = &mut context.devices[device_id]; | ||
| let device = &device_handle.device; | ||
| let queue = &device_handle.queue; | ||
| let mut renderer = vello::Renderer::new( | ||
| device, | ||
| RendererOptions { | ||
| num_init_threads: std::num::NonZeroUsize::new(1), | ||
| antialiasing_support: std::iter::once(AaConfig::Area).collect(), | ||
| ..RendererOptions::default() | ||
| }, | ||
| ) | ||
| .expect("create renderer"); | ||
| let size = Extent3d { | ||
| width, | ||
| height, | ||
| depth_or_array_layers: 1, | ||
| }; | ||
| let target = device.create_texture(&TextureDescriptor { | ||
| label: Some("glyph image brush target"), | ||
| size, | ||
| mip_level_count: 1, | ||
| sample_count: 1, | ||
| dimension: wgpu::TextureDimension::D2, | ||
| format: TextureFormat::Rgba8Unorm, | ||
| usage: TextureUsages::STORAGE_BINDING | ||
| | TextureUsages::TEXTURE_BINDING | ||
| | TextureUsages::COPY_SRC, | ||
| view_formats: &[], | ||
| }); | ||
| let view = target.create_view(&wgpu::TextureViewDescriptor::default()); | ||
| let params = vello::RenderParams { | ||
| base_color: Color::from_rgba8(0, 0, 0, 0), | ||
| width, | ||
| height, | ||
| antialiasing_method: AaConfig::Area, | ||
| }; | ||
|
|
||
| for scene in [ | ||
| glyph_image_brush_scene(&image), | ||
| image_free_scene(), | ||
| glyph_image_brush_scene(&image), | ||
| ] { | ||
| renderer | ||
| .render_to_texture(device, queue, &scene, &view, ¶ms) | ||
| .expect("render scene"); | ||
| } | ||
|
|
||
| let padded_byte_width = (width * 4).next_multiple_of(256); | ||
| let buffer_size = u64::from(padded_byte_width) * u64::from(height); | ||
| let buffer = device.create_buffer(&BufferDescriptor { | ||
| label: Some("glyph image brush readback"), | ||
| size: buffer_size, | ||
| usage: BufferUsages::MAP_READ | BufferUsages::COPY_DST, | ||
| mapped_at_creation: false, | ||
| }); | ||
| let mut encoder = device.create_command_encoder(&CommandEncoderDescriptor { | ||
| label: Some("glyph image brush copy"), | ||
| }); | ||
| encoder.copy_texture_to_buffer( | ||
| target.as_image_copy(), | ||
| TexelCopyBufferInfo { | ||
| buffer: &buffer, | ||
| layout: wgpu::TexelCopyBufferLayout { | ||
| offset: 0, | ||
| bytes_per_row: Some(padded_byte_width), | ||
| rows_per_image: None, | ||
| }, | ||
| }, | ||
| size, | ||
| ); | ||
| queue.submit([encoder.finish()]); | ||
| let buf_slice = buffer.slice(..); | ||
| let (sender, receiver) = futures_intrusive::channel::shared::oneshot_channel(); | ||
| buf_slice.map_async(wgpu::MapMode::Read, move |v| sender.send(v).unwrap()); | ||
| block_on_wgpu(device, receiver.receive()) | ||
| .expect("map callback") | ||
| .expect("map readback"); | ||
| let data = buf_slice.get_mapped_range(); | ||
| let unpadded_byte_width = usize::try_from(width * 4).unwrap(); | ||
| let padded_byte_width = usize::try_from(padded_byte_width).unwrap(); | ||
| let non_background_pixels = data | ||
| .chunks(padded_byte_width) | ||
| .flat_map(|row| row[..unpadded_byte_width].chunks_exact(4)) | ||
| .filter(|pixel| **pixel != GLYPH_IMAGE_BACKGROUND) | ||
| .count(); | ||
| assert!( | ||
| non_background_pixels > 0, | ||
| "image brush glyph run rendered as a blank image after an image-free render" | ||
| ); | ||
| }); | ||
| } | ||
|
|
||
| /// <https://github.com/web-platform-tests/wpt/blob/18c64a74b1/html/canvas/element/fill-and-stroke-styles/2d.gradient.interpolate.coloralpha.html> | ||
| /// See <https://github.com/linebender/vello/issues/1056>. | ||
| #[test] | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name "id_byte" is confusing to me, it's not an id, it seems to be the image contents.