Merge pull request #215 from dfrg/small-fixes

Hodgepodge of small fixes
This commit is contained in:
Chad Brokaw 2022-11-28 14:12:22 -05:00 committed by GitHub
commit ab3ef4381d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 20 additions and 15 deletions

1
Cargo.lock generated
View file

@ -1704,6 +1704,7 @@ dependencies = [
"piet-wgsl", "piet-wgsl",
"pollster", "pollster",
"roxmltree", "roxmltree",
"wgpu",
"winit 0.27.5", "winit 0.27.5",
] ]

View file

@ -7,6 +7,7 @@ publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
wgpu = "0.14"
piet-wgsl = { path = "../../../piet-wgsl" } piet-wgsl = { path = "../../../piet-wgsl" }
piet-scene = { path = "../../../piet-scene" } piet-scene = { path = "../../../piet-scene" }
winit = "0.27.5" winit = "0.27.5"

View file

@ -96,6 +96,7 @@ async fn run() -> Result<()> {
) )
.expect("failed to render to surface"); .expect("failed to render to surface");
surface_texture.present(); surface_texture.present();
render_cx.device.poll(wgpu::Maintain::Wait);
} }
_ => {} _ => {}
}); });

View file

@ -281,7 +281,11 @@ fn main(
for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) { for (var i = 0u; i < PIXELS_PER_THREAD; i += 1u) {
let coords = xy_uint + vec2(i, 0u); let coords = xy_uint + vec2(i, 0u);
if coords.x < config.target_width && coords.y < config.target_height { if coords.x < config.target_width && coords.y < config.target_height {
textureStore(output, vec2<i32>(coords), rgba[i]); let fg = rgba[i];
// Max with a small epsilon to avoid NaNs
let a_inv = 1.0 / max(fg.a, 1e-6);
let rgba_sep = vec4(fg.rgb * a_inv, fg.a);
textureStore(output, vec2<i32>(coords), rgba_sep);
} }
} }
#else #else

View file

@ -318,10 +318,10 @@ fn blend_mix_compose(backdrop: vec4<f32>, src: vec4<f32>, mode: u32) -> vec4<f32
// Both normal+src_over blend and clip case // Both normal+src_over blend and clip case
return backdrop * (1.0 - src.a) + src; return backdrop * (1.0 - src.a) + src;
} }
// Un-premultiply colors for blending // Un-premultiply colors for blending. Max with a small epsilon to avoid NaNs.
let inv_src_a = 1.0 / (src.a + EPSILON); let inv_src_a = 1.0 / max(src.a, EPSILON);
var cs = src.rgb * inv_src_a; var cs = src.rgb * inv_src_a;
let inv_backdrop_a = 1.0 / (backdrop.a + EPSILON); let inv_backdrop_a = 1.0 / max(backdrop.a, EPSILON);
let cb = backdrop.rgb * inv_backdrop_a; let cb = backdrop.rgb * inv_backdrop_a;
let mix_mode = mode >> 8u; let mix_mode = mode >> 8u;
let mixed = blend_mix(cb, cs, mix_mode); let mixed = blend_mix(cb, cs, mix_mode);

View file

@ -143,7 +143,6 @@ impl Renderer {
} }
struct TargetTexture { struct TargetTexture {
texture: Texture,
view: TextureView, view: TextureView,
width: u32, width: u32,
height: u32, height: u32,
@ -166,7 +165,6 @@ impl TargetTexture {
}); });
let view = texture.create_view(&wgpu::TextureViewDescriptor::default()); let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
Self { Self {
texture,
view, view,
width, width,
height, height,
@ -185,20 +183,20 @@ impl BlitPipeline {
@vertex @vertex
fn vs_main(@builtin(vertex_index) ix: u32) -> @builtin(position) vec4<f32> { fn vs_main(@builtin(vertex_index) ix: u32) -> @builtin(position) vec4<f32> {
// Generate a full screen quad in NDCs // Generate a full screen quad in NDCs
var vertex = vec2<f32>(-1.0, 1.0); var vertex = vec2(-1.0, 1.0);
switch ix { switch ix {
case 1u: { case 1u: {
vertex = vec2<f32>(-1.0, -1.0); vertex = vec2(-1.0, -1.0);
} }
case 2u, 4u: { case 2u, 4u: {
vertex = vec2<f32>(1.0, -1.0); vertex = vec2(1.0, -1.0);
} }
case 5u: { case 5u: {
vertex = vec2<f32>(1.0, 1.0); vertex = vec2(1.0, 1.0);
} }
default: {} default: {}
} }
return vec4<f32>(vertex, 0.0, 1.0); return vec4(vertex, 0.0, 1.0);
} }
@group(0) @binding(0) @group(0) @binding(0)
@ -206,7 +204,8 @@ impl BlitPipeline {
@fragment @fragment
fn fs_main(@builtin(position) pos: vec4<f32>) -> @location(0) vec4<f32> { fn fs_main(@builtin(position) pos: vec4<f32>) -> @location(0) vec4<f32> {
return textureLoad(fine_output, vec2<i32>(pos.xy), 0); let rgba_sep = textureLoad(fine_output, vec2<i32>(pos.xy), 0);
return vec4(rgba_sep.rgb * rgba_sep.a, rgba_sep.a);
} }
"#; "#;

View file

@ -32,7 +32,7 @@ pub const CLIP_REDUCE_WG: u32 = 256;
macro_rules! shader { macro_rules! shader {
($name:expr) => { ($name:expr) => {
include_str!(concat!(concat!("../shader/", $name), ".wgsl")) include_str!(concat!("../shader/", $name, ".wgsl"))
}; };
} }
@ -314,7 +314,7 @@ macro_rules! shared_shader {
($name:expr) => { ($name:expr) => {
( (
$name, $name,
include_str!(concat!(concat!("../shader/shared/", $name), ".wgsl")), include_str!(concat!("../shader/shared/", $name, ".wgsl")),
) )
}; };
} }
@ -326,7 +326,6 @@ const SHARED_SHADERS: &[(&str, &str)] = &[
shared_shader!("clip"), shared_shader!("clip"),
shared_shader!("config"), shared_shader!("config"),
shared_shader!("cubic"), shared_shader!("cubic"),
shared_shader!("bbox"),
shared_shader!("drawtag"), shared_shader!("drawtag"),
shared_shader!("pathtag"), shared_shader!("pathtag"),
shared_shader!("ptcl"), shared_shader!("ptcl"),