-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix footprint transform #4280
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
base: master
Are you sure you want to change the base?
Fix footprint transform #4280
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -345,12 +345,10 @@ pub async fn render_output_cache<'a: 'n>( | |||||||||||||||||
| return data.eval(context.into_context()).await; | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| let device_scale = render_params.scale; | ||||||||||||||||||
| let zoom = footprint.scale_magnitudes().x; | ||||||||||||||||||
| let zoom = footprint.scale_magnitudes().x / render_params.scale; | ||||||||||||||||||
|
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. P1: Unvalidated Prompt for AI agents
Suggested change
|
||||||||||||||||||
| let rotation = footprint.decompose_rotation(); | ||||||||||||||||||
|
|
||||||||||||||||||
| let viewport_origin_offset = footprint.transform.translation; | ||||||||||||||||||
| let device_origin_offset = viewport_origin_offset * device_scale; | ||||||||||||||||||
| let device_origin_offset = footprint.transform.translation; | ||||||||||||||||||
| let viewport_bounds_device = AxisAlignedBbox { | ||||||||||||||||||
| start: -device_origin_offset, | ||||||||||||||||||
| end: footprint.resolution.as_dvec2() - device_origin_offset, | ||||||||||||||||||
|
|
@@ -361,7 +359,7 @@ pub async fn render_output_cache<'a: 'n>( | |||||||||||||||||
| let cache_key = CacheKey::new( | ||||||||||||||||||
| max_region_area, | ||||||||||||||||||
| render_params.render_mode as u64, | ||||||||||||||||||
| device_scale, | ||||||||||||||||||
| render_params.scale, | ||||||||||||||||||
| zoom, | ||||||||||||||||||
| rotation, | ||||||||||||||||||
| render_params.for_export, | ||||||||||||||||||
|
|
@@ -387,8 +385,8 @@ pub async fn render_output_cache<'a: 'n>( | |||||||||||||||||
| ctx.clone(), | ||||||||||||||||||
| render_params, | ||||||||||||||||||
| &footprint.transform, | ||||||||||||||||||
| &viewport_origin_offset, | ||||||||||||||||||
| device_scale, | ||||||||||||||||||
| &device_origin_offset, | ||||||||||||||||||
| render_params.scale, | ||||||||||||||||||
| ) | ||||||||||||||||||
| .await; | ||||||||||||||||||
| new_regions.push(region); | ||||||||||||||||||
|
|
@@ -406,7 +404,9 @@ pub async fn render_output_cache<'a: 'n>( | |||||||||||||||||
|
|
||||||||||||||||||
| let executor = executor.expect("GPU executor not available"); | ||||||||||||||||||
| let output_texture = executor.request_texture(physical_resolution).await; | ||||||||||||||||||
| let combined_metadata = composite_cached_regions(&all_regions, &output_texture, &device_origin_offset, &footprint.transform, &executor); | ||||||||||||||||||
|
|
||||||||||||||||||
| let logical_viewport_transform = DAffine2::from_scale(DVec2::splat(1.0 / render_params.scale)) * footprint.transform; | ||||||||||||||||||
| let combined_metadata = composite_cached_regions(&all_regions, &output_texture, &device_origin_offset, &logical_viewport_transform, executor); | ||||||||||||||||||
|
|
||||||||||||||||||
| RenderOutput { | ||||||||||||||||||
| data: RenderOutputType::Texture(output_texture.into()), | ||||||||||||||||||
|
|
@@ -433,7 +433,7 @@ where | |||||||||||||||||
| let tile_count = (max_tile - min_tile) + IVec2::ONE; | ||||||||||||||||||
| let region_pixel_size = (tile_count * TILE_SIZE as i32).as_uvec2(); | ||||||||||||||||||
|
|
||||||||||||||||||
| let tile_global_offset = min_tile.as_dvec2() * (TILE_SIZE as f64 / device_scale) + *viewport_origin_offset; | ||||||||||||||||||
| let tile_global_offset = min_tile.as_dvec2() * TILE_SIZE as f64 + *viewport_origin_offset; | ||||||||||||||||||
| let region_transform = DAffine2::from_translation(-tile_global_offset) * *viewport_transform; | ||||||||||||||||||
| let region_footprint = Footprint { | ||||||||||||||||||
| transform: region_transform, | ||||||||||||||||||
|
|
@@ -449,7 +449,8 @@ where | |||||||||||||||||
| unreachable!("render_missing_region: expected texture output from Vello render"); | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| let pixel_to_document = region_transform.inverse(); | ||||||||||||||||||
| let logical_region_transform = DAffine2::from_scale(DVec2::splat(1.0 / device_scale)) * region_transform; | ||||||||||||||||||
| let pixel_to_document = logical_region_transform.inverse(); | ||||||||||||||||||
| result.metadata.apply_transform(pixel_to_document); | ||||||||||||||||||
|
|
||||||||||||||||||
| let memory_size = (region_pixel_size.x * region_pixel_size.y) as usize * BYTES_PER_PIXEL; | ||||||||||||||||||
|
|
||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,7 +21,7 @@ pub async fn render_pixel_preview<'a: 'n>( | |||||||||||||||
| let physical_scale = render_params.scale; | ||||||||||||||||
|
|
||||||||||||||||
| let footprint = *ctx.footprint(); | ||||||||||||||||
| let viewport_zoom = footprint.scale_magnitudes().x * physical_scale; | ||||||||||||||||
| let viewport_zoom = footprint.scale_magnitudes().x; | ||||||||||||||||
|
|
||||||||||||||||
| if render_params.render_mode != RenderMode::PixelPreview || !matches!(render_params.render_output_type, RenderOutputTypeRequest::Vello) || viewport_zoom <= 1. { | ||||||||||||||||
| let context = OwnedContextImpl::from(ctx).into_context(); | ||||||||||||||||
|
|
@@ -32,6 +32,7 @@ pub async fn render_pixel_preview<'a: 'n>( | |||||||||||||||
| let logical_resolution = physical_resolution.as_dvec2() / physical_scale; | ||||||||||||||||
|
|
||||||||||||||||
| let logical_footprint = Footprint { | ||||||||||||||||
| transform: DAffine2::from_scale(DVec2::splat(1. / physical_scale)) * footprint.transform, | ||||||||||||||||
| resolution: logical_resolution.as_uvec2().max(UVec2::ONE), | ||||||||||||||||
| ..footprint | ||||||||||||||||
| }; | ||||||||||||||||
|
|
@@ -45,7 +46,7 @@ pub async fn render_pixel_preview<'a: 'n>( | |||||||||||||||
| let upstream_resolution = upstream_size.as_uvec2().max(UVec2::ONE); | ||||||||||||||||
|
|
||||||||||||||||
| let upstream_footprint = Footprint { | ||||||||||||||||
| transform: DAffine2::from_scale(DVec2::splat(1. / physical_scale)) * DAffine2::from_translation(-upstream_min), | ||||||||||||||||
| transform: DAffine2::from_translation(-upstream_min), | ||||||||||||||||
| resolution: upstream_resolution, | ||||||||||||||||
| quality: footprint.quality, | ||||||||||||||||
| }; | ||||||||||||||||
|
|
@@ -55,7 +56,8 @@ pub async fn render_pixel_preview<'a: 'n>( | |||||||||||||||
|
|
||||||||||||||||
| let RenderOutputType::Texture(ref source_texture) = result.data else { return result }; | ||||||||||||||||
|
|
||||||||||||||||
| let transform = DAffine2::from_translation(-upstream_min) * footprint.transform.inverse() * DAffine2::from_scale(logical_resolution); | ||||||||||||||||
| let logical_transform = DAffine2::from_scale(DVec2::splat(1. / physical_scale)) * footprint.transform; | ||||||||||||||||
| let transform = DAffine2::from_translation(-upstream_min) * logical_transform.inverse() * DAffine2::from_scale(logical_resolution); | ||||||||||||||||
|
|
||||||||||||||||
| let resampled = pipeline | ||||||||||||||||
| .run::<PixelPreview>(&PixelPreviewArgs { | ||||||||||||||||
|
|
@@ -69,7 +71,7 @@ pub async fn render_pixel_preview<'a: 'n>( | |||||||||||||||
|
|
||||||||||||||||
| result | ||||||||||||||||
| .metadata | ||||||||||||||||
| .apply_transform(footprint.transform * DAffine2::from_translation(upstream_min) * DAffine2::from_scale(DVec2::splat(physical_scale))); | ||||||||||||||||
| .apply_transform(logical_transform * DAffine2::from_translation(upstream_min) * DAffine2::from_scale(DVec2::splat(physical_scale))); | ||||||||||||||||
|
Comment on lines
72
to
+74
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. With
Suggested change
|
||||||||||||||||
|
|
||||||||||||||||
| result | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
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.
P2: Unconditional
1.0 / render_params.scalecan create non-finite transforms when scale is 0. Guard scale before inversion to avoid invalid SVG transform output.Prompt for AI agents