Use software texture filtering in kittest (#7602)
This commit is contained in:
parent
718a82b013
commit
47a437403f
|
|
@ -194,6 +194,7 @@ impl<'app> WgpuWinitApp<'app> {
|
|||
self.native_options.stencil_buffer,
|
||||
),
|
||||
dithering: self.native_options.dithering,
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
|
||||
|
|
|
|||
|
|
@ -8,10 +8,13 @@ struct VertexOutput {
|
|||
|
||||
struct Locals {
|
||||
screen_size: vec2<f32>,
|
||||
dithering: u32, // 1 if dithering is enabled, 0 otherwise
|
||||
// Uniform buffers need to be at least 16 bytes in WebGL.
|
||||
// See https://github.com/gfx-rs/wgpu/issues/2072
|
||||
_padding: u32,
|
||||
|
||||
/// 1 if dithering is enabled, 0 otherwise
|
||||
dithering: u32,
|
||||
|
||||
/// 1 to do manual filtering for more predictable kittest snapshot images.
|
||||
/// See also https://github.com/emilk/egui/issues/5295
|
||||
predictable_texture_filtering: u32,
|
||||
};
|
||||
@group(0) @binding(0) var<uniform> r_locals: Locals;
|
||||
|
||||
|
|
@ -95,10 +98,42 @@ fn vs_main(
|
|||
@group(1) @binding(0) var r_tex_color: texture_2d<f32>;
|
||||
@group(1) @binding(1) var r_tex_sampler: sampler;
|
||||
|
||||
fn sample_texture(in: VertexOutput) -> vec4<f32> {
|
||||
if r_locals.predictable_texture_filtering == 0 {
|
||||
// Hardware filtering: fast, but varies across GPUs and drivers.
|
||||
return textureSample(r_tex_color, r_tex_sampler, in.tex_coord);
|
||||
} else {
|
||||
// Manual bilinear filtering with four taps at pixel centers using textureLoad
|
||||
let texture_size = vec2<i32>(textureDimensions(r_tex_color, 0));
|
||||
let texture_size_f = vec2<f32>(texture_size);
|
||||
let pixel_coord = in.tex_coord * texture_size_f - 0.5;
|
||||
let pixel_fract = fract(pixel_coord);
|
||||
let pixel_floor = vec2<i32>(floor(pixel_coord));
|
||||
|
||||
// Manual texture clamping
|
||||
let max_coord = texture_size - vec2<i32>(1, 1);
|
||||
let p00 = clamp(pixel_floor + vec2<i32>(0, 0), vec2<i32>(0, 0), max_coord);
|
||||
let p10 = clamp(pixel_floor + vec2<i32>(1, 0), vec2<i32>(0, 0), max_coord);
|
||||
let p01 = clamp(pixel_floor + vec2<i32>(0, 1), vec2<i32>(0, 0), max_coord);
|
||||
let p11 = clamp(pixel_floor + vec2<i32>(1, 1), vec2<i32>(0, 0), max_coord);
|
||||
|
||||
// Load at pixel centers
|
||||
let tl = textureLoad(r_tex_color, p00, 0);
|
||||
let tr = textureLoad(r_tex_color, p10, 0);
|
||||
let bl = textureLoad(r_tex_color, p01, 0);
|
||||
let br = textureLoad(r_tex_color, p11, 0);
|
||||
|
||||
// Manual bilinear interpolation
|
||||
let top = mix(tl, tr, pixel_fract.x);
|
||||
let bottom = mix(bl, br, pixel_fract.x);
|
||||
return mix(top, bottom, pixel_fract.y);
|
||||
}
|
||||
}
|
||||
|
||||
@fragment
|
||||
fn fs_main_linear_framebuffer(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||
// We expect "normal" textures that are NOT sRGB-aware.
|
||||
let tex_gamma = textureSample(r_tex_color, r_tex_sampler, in.tex_coord);
|
||||
let tex_gamma = sample_texture(in);
|
||||
var out_color_gamma = in.color * tex_gamma;
|
||||
// Dither the float color down to eight bits to reduce banding.
|
||||
// This step is optional for egui backends.
|
||||
|
|
@ -115,7 +150,7 @@ fn fs_main_linear_framebuffer(in: VertexOutput) -> @location(0) vec4<f32> {
|
|||
@fragment
|
||||
fn fs_main_gamma_framebuffer(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||
// We expect "normal" textures that are NOT sRGB-aware.
|
||||
let tex_gamma = textureSample(r_tex_color, r_tex_sampler, in.tex_coord);
|
||||
let tex_gamma = sample_texture(in);
|
||||
var out_color_gamma = in.color * tex_gamma;
|
||||
// Dither the float color down to eight bits to reduce banding.
|
||||
// This step is optional for egui backends.
|
||||
|
|
|
|||
|
|
@ -141,21 +141,16 @@ impl ScreenDescriptor {
|
|||
}
|
||||
|
||||
/// Uniform buffer used when rendering.
|
||||
#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
#[repr(C)]
|
||||
struct UniformBuffer {
|
||||
screen_size_in_points: [f32; 2],
|
||||
dithering: u32,
|
||||
// Uniform buffers need to be at least 16 bytes in WebGL.
|
||||
// See https://github.com/gfx-rs/wgpu/issues/2072
|
||||
_padding: u32,
|
||||
}
|
||||
|
||||
impl PartialEq for UniformBuffer {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.screen_size_in_points == other.screen_size_in_points
|
||||
&& self.dithering == other.dithering
|
||||
}
|
||||
/// 1 to do manual filtering for more predictable kittest snapshot images.
|
||||
///
|
||||
/// See also <https://github.com/emilk/egui/issues/5295>.
|
||||
predictable_texture_filtering: u32,
|
||||
}
|
||||
|
||||
struct SlicedBuffer {
|
||||
|
|
@ -204,6 +199,16 @@ pub struct RendererOptions {
|
|||
///
|
||||
/// Defaults to true.
|
||||
pub dithering: bool,
|
||||
|
||||
/// Perform texture filtering in software?
|
||||
///
|
||||
/// This is useful when you want predictable rendering across
|
||||
/// different hardware, e.g. for kittest snapshots.
|
||||
///
|
||||
/// Default is `false`.
|
||||
///
|
||||
/// See also <https://github.com/emilk/egui/issues/5295>.
|
||||
pub predictable_texture_filtering: bool,
|
||||
}
|
||||
|
||||
impl RendererOptions {
|
||||
|
|
@ -214,6 +219,7 @@ impl RendererOptions {
|
|||
msaa_samples: 1,
|
||||
depth_stencil_format: None,
|
||||
dithering: false,
|
||||
predictable_texture_filtering: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -223,6 +229,7 @@ impl Default for RendererOptions {
|
|||
msaa_samples: 0,
|
||||
depth_stencil_format: None,
|
||||
dithering: true,
|
||||
predictable_texture_filtering: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -280,7 +287,7 @@ impl Renderer {
|
|||
contents: bytemuck::cast_slice(&[UniformBuffer {
|
||||
screen_size_in_points: [0.0, 0.0],
|
||||
dithering: u32::from(options.dithering),
|
||||
_padding: Default::default(),
|
||||
predictable_texture_filtering: u32::from(options.predictable_texture_filtering),
|
||||
}]),
|
||||
usage: wgpu::BufferUsages::UNIFORM | wgpu::BufferUsages::COPY_DST,
|
||||
});
|
||||
|
|
@ -895,7 +902,7 @@ impl Renderer {
|
|||
let uniform_buffer_content = UniformBuffer {
|
||||
screen_size_in_points,
|
||||
dithering: u32::from(self.options.dithering),
|
||||
_padding: Default::default(),
|
||||
predictable_texture_filtering: u32::from(self.options.predictable_texture_filtering),
|
||||
};
|
||||
if uniform_buffer_content != self.previous_uniform_buffer_content {
|
||||
profiling::scope!("update uniforms");
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6b09dbb2e4038c57e28e946604b56123a01f63aa8aa029245448ed77c83ee910
|
||||
size 100070
|
||||
oid sha256:dc9c22567b76193a7f6753c4217adb3c92afa921c488ba1cf2e14b403814e7ac
|
||||
size 99841
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b418b7f9d94244fe355fd81866ab9dc9750ff4e0cb7db39d902dd9892eae5246
|
||||
oid sha256:cb944eca56724f6a2106ea8db2043dc94c0ea40bdd4cdeb0e520790f97cc9598
|
||||
size 27049
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:17c8a6bc3ea09fe5940011e6d96ad26e47aee6ee672b92bd4fa23b40e4a0f790
|
||||
size 34493
|
||||
oid sha256:2855bd95ab33b5232edada1f65684bbba2748025b6b64eb9ac68a5f2d10ad4bd
|
||||
size 34491
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:e057c0bba4ec4c30e890c39153bd6dd17c511f410bfb894e66ef3ef9973d8fd4
|
||||
oid sha256:614046db82ef103f65bec3c09cc6afd9ee2b3835e9d32e2adff98f6d56714b22
|
||||
size 807
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c8b573f58a41efe26a0bf335e27cc123ffd4c13b24576e46d96ddedfed68b606
|
||||
oid sha256:a6298072b162623cec47d268fed5f8aa6189a2cf69074924a6eba26994fc6330
|
||||
size 2027
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:69442b230ab0eb5291b47290c6ec08eff21bb2032f164592b1b0205065a8b035
|
||||
size 621404
|
||||
oid sha256:f9980486c36a0242f3b043a172c411d4fc9573543d3cd7c1c43bf020c18868a9
|
||||
size 619816
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:d38bfa32246e60a408495101004c7346220e43e430440aba82737131206e5053
|
||||
size 826006
|
||||
oid sha256:040e2e486ae4773a084da99513a53c620e8e2bba215183ec26c6e489381d6254
|
||||
size 823086
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:2fc6621f8a548991b198db4e1510f2aab04716c814fd5d7c4642c354dfb060f3
|
||||
size 1039325
|
||||
oid sha256:439a5f942a5f05b9c09685ef90be94c150a21a68d1d235af22372b9b6a7b7389
|
||||
size 1035734
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0f541e682b229cefc00220c07bb8fd929de98041403e3cfdbc1f45000fa96e32
|
||||
size 1209860
|
||||
oid sha256:9b7d7e290b97a8042af3af3cd9ceb274950cf607dd7e9cd6c71d5a113d3b57a5
|
||||
size 1206155
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f3c9ede7cf36cb5704f80ac4544953db22c84c6b69b24d94c072f7d35ee79698
|
||||
size 1236290
|
||||
oid sha256:fedd5546e36a89121c0bb0a780b0bbe081611c2c04013064872801181503fb83
|
||||
size 1231599
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c36f92a5ced3be65e7b9b6364670f1f50702fcc330a0fab794d20efbc6367148
|
||||
size 1466940
|
||||
oid sha256:69a7040336fc92c6d7b158283aabbc5817980c2fa84a1120b788516cf437b985
|
||||
size 1461979
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:07443de8d14d8179e10b82b82be76531e68b1367fdbfe06993bb2e068ca92b0d
|
||||
size 46794
|
||||
oid sha256:1a32d361afa20fc8c20122a89b01fe14b45849da42663991e589579f70fb8577
|
||||
size 46790
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:096baabe30a44b013a893eb6e529bc24cb7b6a205edd22c1319cf1f137ac83da
|
||||
size 88561
|
||||
oid sha256:c8d55205cf4225123da33895ed45eb186e5e57184ef5928400a4bae3ab6092be
|
||||
size 88548
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0d7fa14c81618b24b316df464d3a95954f94149e21cf2086acbaef7912ea2920
|
||||
size 120651
|
||||
oid sha256:77ab9e2e18c788f8cdbec171269afe4d0a90c52abeda7063cae3766dcaa5e93b
|
||||
size 120612
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3dfced2f1f04816366b7688614339d2e5aee4b655d399f02692125ecfb1b17df
|
||||
size 53066
|
||||
oid sha256:36622a2f934503a7b60ded2f44b002e37eedde22d548dcf5a209f54c19548665
|
||||
size 53064
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:2314aefa3f38b20600c918413a146c9d31e90b379b44cf53b378da845b8a1199
|
||||
size 56280
|
||||
oid sha256:4adeb7a77a0d0fe85097fcd190a99b49858dce11bde601d30335afcb6cc3d5f6
|
||||
size 56276
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b258e241726f19d9b0842fbd0fe5c7b39ea61ecae9ee925c1c1f7b18be0bdea1
|
||||
size 56737
|
||||
oid sha256:f45249f7cc90433a64856905c727571c4ef20468e2c7d3ac2029e18a0477932d
|
||||
size 56743
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:a8c7a56c6f29756cf49edbefe38ec2a6bd164b400dd458686405655e5e7f1c77
|
||||
size 37596
|
||||
oid sha256:d437f68c521f3e627a1b50d46605e8b0b343c5fc3716d9669e8c4436c8992b6f
|
||||
size 37602
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c0c4a3625ba10777e0878bea1b26c8ac06d0558f777f9b82c9bbe987195c6d60
|
||||
size 37623
|
||||
oid sha256:08ba98437403a08cca825ed8e288c9f088a46d9a1081f0b0a4ed7fbb9b49bb85
|
||||
size 37640
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:dae36303c3b75ae100a43511436a9598190f556af2ce7f48b97f02ec09a7d81c
|
||||
size 66858
|
||||
oid sha256:e1ed0e40d08b2b9ea978a07a4b7bf282c9e2cba8c52896f12210f396241e1b78
|
||||
size 66859
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:82a2c649f039a7b6549391253bb20fbbe4dcb404fec98850488155a7297f4353
|
||||
size 158896
|
||||
oid sha256:28f9862dd6f16b99523f5880bf90346fd9455d0d44e7bdd530d523e0b2ef2d2c
|
||||
size 158892
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:c1fc06217640ee574a1cebd6c2351d7b8fb52ad263144175d0eed64ea46109d2
|
||||
oid sha256:98c40c99a237f8388d82259fba4388d7b1759fe7b4bf657d326532934135c934
|
||||
size 61119
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:cb4408cd1654af081e9ffff1af2d6132dce9b395af3657cd2dc97cbcd3919310
|
||||
size 152219
|
||||
oid sha256:90d36311ce5b1dcf81cab22113620a3362f255059d1f52c6794c8249f960549e
|
||||
size 152215
|
||||
|
|
|
|||
Loading…
Reference in New Issue