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",
"pollster",
"roxmltree",
"wgpu",
"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
[dependencies]
wgpu = "0.14"
piet-wgsl = { path = "../../../piet-wgsl" }
piet-scene = { path = "../../../piet-scene" }
winit = "0.27.5"

View file

@ -96,6 +96,7 @@ async fn run() -> Result<()> {
)
.expect("failed to render to surface");
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) {
let coords = xy_uint + vec2(i, 0u);
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

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
return backdrop * (1.0 - src.a) + src;
}
// Un-premultiply colors for blending
let inv_src_a = 1.0 / (src.a + EPSILON);
// Un-premultiply colors for blending. Max with a small epsilon to avoid NaNs.
let inv_src_a = 1.0 / max(src.a, EPSILON);
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 mix_mode = mode >> 8u;
let mixed = blend_mix(cb, cs, mix_mode);

View file

@ -143,7 +143,6 @@ impl Renderer {
}
struct TargetTexture {
texture: Texture,
view: TextureView,
width: u32,
height: u32,
@ -166,7 +165,6 @@ impl TargetTexture {
});
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
Self {
texture,
view,
width,
height,
@ -185,20 +183,20 @@ impl BlitPipeline {
@vertex
fn vs_main(@builtin(vertex_index) ix: u32) -> @builtin(position) vec4<f32> {
// Generate a full screen quad in NDCs
var vertex = vec2<f32>(-1.0, 1.0);
var vertex = vec2(-1.0, 1.0);
switch ix {
case 1u: {
vertex = vec2<f32>(-1.0, -1.0);
vertex = vec2(-1.0, -1.0);
}
case 2u, 4u: {
vertex = vec2<f32>(1.0, -1.0);
vertex = vec2(1.0, -1.0);
}
case 5u: {
vertex = vec2<f32>(1.0, 1.0);
vertex = vec2(1.0, 1.0);
}
default: {}
}
return vec4<f32>(vertex, 0.0, 1.0);
return vec4(vertex, 0.0, 1.0);
}
@group(0) @binding(0)
@ -206,7 +204,8 @@ impl BlitPipeline {
@fragment
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 {
($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,
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!("config"),
shared_shader!("cubic"),
shared_shader!("bbox"),
shared_shader!("drawtag"),
shared_shader!("pathtag"),
shared_shader!("ptcl"),