Add Pixel Preview render mode and fix Vello rendering regression with a tilted viewport#3847
Add Pixel Preview render mode and fix Vello rendering regression with a tilted viewport#3847
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the editor's rendering capabilities by introducing a new 'Pixel Preview' mode, which allows users to inspect their designs at their final export resolution with pixel-perfect accuracy. Concurrently, it addresses and resolves a critical rendering regression that previously caused visual distortions when the viewport was tilted or rotated. These improvements ensure a more faithful and robust visual representation of the document under various viewing conditions. Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request successfully adds a Pixel Preview render mode and fixes a rendering regression with tilted viewports. The implementation for both features is solid. The fix for tilted viewports correctly uses a two-pass approach with an intermediate texture and resampling, and the calculation of the required transforms is accurate. The Pixel Preview mode also correctly renders at 100% scale and then upscales with nearest-neighbor filtering. I have a suggestion regarding uniform buffer construction.
| // Layout: mat2x2<f32> (4 floats = 16 bytes) + vec2<f32> (2 floats = 8 bytes) = 24 bytes | ||
| let mut params_data = [0_u8; 24]; | ||
| params_data[0..4].copy_from_slice(&source_transform.x_axis.x.to_le_bytes()); | ||
| params_data[4..8].copy_from_slice(&source_transform.x_axis.y.to_le_bytes()); | ||
| params_data[8..12].copy_from_slice(&source_transform.y_axis.x.to_le_bytes()); | ||
| params_data[12..16].copy_from_slice(&source_transform.y_axis.y.to_le_bytes()); | ||
| params_data[16..20].copy_from_slice(&source_offset.x.to_le_bytes()); | ||
| params_data[20..24].copy_from_slice(&source_offset.y.to_le_bytes()); | ||
| let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor { | ||
| label: Some("resample_params"), | ||
| size: 24, | ||
| usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST, | ||
| mapped_at_creation: false, | ||
| }); | ||
| queue.write_buffer(&uniform_buf, 0, ¶ms_data); |
There was a problem hiding this comment.
Manually constructing the params_data byte array and using a magic number for the size is error-prone. It would be safer and more readable to define a #[repr(C)] struct that matches the shader's uniform buffer layout and use bytemuck to safely cast it to a byte slice. This avoids manual byte manipulation and makes the code's intent clearer.
You would need to add bytemuck = { version = "1", features = ["derive"] } to your Cargo.toml and use bytemuck::{Pod, Zeroable};.
#[repr(C)]
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
struct Uniforms {
transform: glam::Mat2,
offset: glam::Vec2,
}
let params_data = *bytemuck::cast_ref(&Uniforms {
transform: source_transform,
offset: source_offset,
});
let uniform_buf = device.create_buffer(&wgpu::BufferDescriptor {
label: Some("resample_params"),
size: params_data.len() as u64,
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
mapped_at_creation: false,
});
queue.write_buffer(&uniform_buf, 0, ¶ms_data);
Closes #320. Fixes tilt behavior broken in #3722 with Vello rendering (the render modes Normal, Outline, and now this new mode Pixel Preview).