diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 0fcfb3ea3a5..046340bdbab 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -194,6 +194,7 @@ impl<'app> WgpuWinitApp<'app> { self.native_options.stencil_buffer, ), dithering: self.native_options.dithering, + ..Default::default() }, )); diff --git a/crates/egui-wgpu/src/egui.wgsl b/crates/egui-wgpu/src/egui.wgsl index 2921be74fcb..39210841bde 100644 --- a/crates/egui-wgpu/src/egui.wgsl +++ b/crates/egui-wgpu/src/egui.wgsl @@ -8,10 +8,13 @@ struct VertexOutput { struct Locals { screen_size: vec2, - 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 r_locals: Locals; @@ -95,10 +98,42 @@ fn vs_main( @group(1) @binding(0) var r_tex_color: texture_2d; @group(1) @binding(1) var r_tex_sampler: sampler; +fn sample_texture(in: VertexOutput) -> vec4 { + 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(textureDimensions(r_tex_color, 0)); + let texture_size_f = vec2(texture_size); + let pixel_coord = in.tex_coord * texture_size_f - 0.5; + let pixel_fract = fract(pixel_coord); + let pixel_floor = vec2(floor(pixel_coord)); + + // Manual texture clamping + let max_coord = texture_size - vec2(1, 1); + let p00 = clamp(pixel_floor + vec2(0, 0), vec2(0, 0), max_coord); + let p10 = clamp(pixel_floor + vec2(1, 0), vec2(0, 0), max_coord); + let p01 = clamp(pixel_floor + vec2(0, 1), vec2(0, 0), max_coord); + let p11 = clamp(pixel_floor + vec2(1, 1), vec2(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 { // 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 { @fragment fn fs_main_gamma_framebuffer(in: VertexOutput) -> @location(0) vec4 { // 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. diff --git a/crates/egui-wgpu/src/renderer.rs b/crates/egui-wgpu/src/renderer.rs index 815ee3e7281..108aa31c35d 100644 --- a/crates/egui-wgpu/src/renderer.rs +++ b/crates/egui-wgpu/src/renderer.rs @@ -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 . + 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 . + 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"); diff --git a/crates/egui_demo_app/tests/snapshots/imageviewer.png b/crates/egui_demo_app/tests/snapshots/imageviewer.png index d16d7a2e904..e1d518a96b4 100644 --- a/crates/egui_demo_app/tests/snapshots/imageviewer.png +++ b/crates/egui_demo_app/tests/snapshots/imageviewer.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6b09dbb2e4038c57e28e946604b56123a01f63aa8aa029245448ed77c83ee910 -size 100070 +oid sha256:dc9c22567b76193a7f6753c4217adb3c92afa921c488ba1cf2e14b403814e7ac +size 99841 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Clipboard Test.png b/crates/egui_demo_lib/tests/snapshots/demos/Clipboard Test.png index 86e0a32377a..373adc23413 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Clipboard Test.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Clipboard Test.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b418b7f9d94244fe355fd81866ab9dc9750ff4e0cb7db39d902dd9892eae5246 +oid sha256:cb944eca56724f6a2106ea8db2043dc94c0ea40bdd4cdeb0e520790f97cc9598 size 27049 diff --git a/crates/egui_demo_lib/tests/snapshots/demos/Scene.png b/crates/egui_demo_lib/tests/snapshots/demos/Scene.png index 9bf99914386..2344a386845 100644 --- a/crates/egui_demo_lib/tests/snapshots/demos/Scene.png +++ b/crates/egui_demo_lib/tests/snapshots/demos/Scene.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:17c8a6bc3ea09fe5940011e6d96ad26e47aee6ee672b92bd4fa23b40e4a0f790 -size 34493 +oid sha256:2855bd95ab33b5232edada1f65684bbba2748025b6b64eb9ac68a5f2d10ad4bd +size 34491 diff --git a/crates/egui_demo_lib/tests/snapshots/image_blending/image_x1.png b/crates/egui_demo_lib/tests/snapshots/image_blending/image_x1.png index 7ef5676bbd2..e06a95c9262 100644 --- a/crates/egui_demo_lib/tests/snapshots/image_blending/image_x1.png +++ b/crates/egui_demo_lib/tests/snapshots/image_blending/image_x1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e057c0bba4ec4c30e890c39153bd6dd17c511f410bfb894e66ef3ef9973d8fd4 +oid sha256:614046db82ef103f65bec3c09cc6afd9ee2b3835e9d32e2adff98f6d56714b22 size 807 diff --git a/crates/egui_demo_lib/tests/snapshots/image_blending/image_x2.png b/crates/egui_demo_lib/tests/snapshots/image_blending/image_x2.png index 89fad98f9a9..42ee2f1dda8 100644 --- a/crates/egui_demo_lib/tests/snapshots/image_blending/image_x2.png +++ b/crates/egui_demo_lib/tests/snapshots/image_blending/image_x2.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c8b573f58a41efe26a0bf335e27cc123ffd4c13b24576e46d96ddedfed68b606 +oid sha256:a6298072b162623cec47d268fed5f8aa6189a2cf69074924a6eba26994fc6330 size 2027 diff --git a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.00.png b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.00.png index 5824e7a8e54..640d84c2beb 100644 --- a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.00.png +++ b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.00.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:69442b230ab0eb5291b47290c6ec08eff21bb2032f164592b1b0205065a8b035 -size 621404 +oid sha256:f9980486c36a0242f3b043a172c411d4fc9573543d3cd7c1c43bf020c18868a9 +size 619816 diff --git a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.25.png b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.25.png index 20777b41a38..df05ada25f6 100644 --- a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.25.png +++ b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.25.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d38bfa32246e60a408495101004c7346220e43e430440aba82737131206e5053 -size 826006 +oid sha256:040e2e486ae4773a084da99513a53c620e8e2bba215183ec26c6e489381d6254 +size 823086 diff --git a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.50.png b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.50.png index 80435c8513f..c6aa2914ff3 100644 --- a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.50.png +++ b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.50.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2fc6621f8a548991b198db4e1510f2aab04716c814fd5d7c4642c354dfb060f3 -size 1039325 +oid sha256:439a5f942a5f05b9c09685ef90be94c150a21a68d1d235af22372b9b6a7b7389 +size 1035734 diff --git a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.67.png b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.67.png index 1866afd6072..1344edcfb16 100644 --- a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.67.png +++ b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.67.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0f541e682b229cefc00220c07bb8fd929de98041403e3cfdbc1f45000fa96e32 -size 1209860 +oid sha256:9b7d7e290b97a8042af3af3cd9ceb274950cf607dd7e9cd6c71d5a113d3b57a5 +size 1206155 diff --git a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.75.png b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.75.png index a678c72336a..9804e294293 100644 --- a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.75.png +++ b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_1.75.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f3c9ede7cf36cb5704f80ac4544953db22c84c6b69b24d94c072f7d35ee79698 -size 1236290 +oid sha256:fedd5546e36a89121c0bb0a780b0bbe081611c2c04013064872801181503fb83 +size 1231599 diff --git a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_2.00.png b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_2.00.png index e6a694435af..04d4bb4ea01 100644 --- a/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_2.00.png +++ b/crates/egui_demo_lib/tests/snapshots/rendering_test/dpi_2.00.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c36f92a5ced3be65e7b9b6364670f1f50702fcc330a0fab794d20efbc6367148 -size 1466940 +oid sha256:69a7040336fc92c6d7b158283aabbc5817980c2fa84a1120b788516cf437b985 +size 1461979 diff --git a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Additive rectangle.png b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Additive rectangle.png index 6a9f5b77e28..50e84c90082 100644 --- a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Additive rectangle.png +++ b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Additive rectangle.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:07443de8d14d8179e10b82b82be76531e68b1367fdbfe06993bb2e068ca92b0d -size 46794 +oid sha256:1a32d361afa20fc8c20122a89b01fe14b45849da42663991e589579f70fb8577 +size 46790 diff --git a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Blurred stroke.png b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Blurred stroke.png index e98af25c978..ca5a23f97d8 100644 --- a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Blurred stroke.png +++ b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Blurred stroke.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:096baabe30a44b013a893eb6e529bc24cb7b6a205edd22c1319cf1f137ac83da -size 88561 +oid sha256:c8d55205cf4225123da33895ed45eb186e5e57184ef5928400a4bae3ab6092be +size 88548 diff --git a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Blurred.png b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Blurred.png index 19320ca47ef..41f9ef2f5e0 100644 --- a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Blurred.png +++ b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Blurred.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0d7fa14c81618b24b316df464d3a95954f94149e21cf2086acbaef7912ea2920 -size 120651 +oid sha256:77ab9e2e18c788f8cdbec171269afe4d0a90c52abeda7063cae3766dcaa5e93b +size 120612 diff --git a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Minimal rounding.png b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Minimal rounding.png index e21e75fdf21..85d844c795e 100644 --- a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Minimal rounding.png +++ b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Minimal rounding.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3dfced2f1f04816366b7688614339d2e5aee4b655d399f02692125ecfb1b17df -size 53066 +oid sha256:36622a2f934503a7b60ded2f44b002e37eedde22d548dcf5a209f54c19548665 +size 53064 diff --git a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Normal.png b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Normal.png index 95d683c9e26..6e6d9f0f2f5 100644 --- a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Normal.png +++ b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Normal.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2314aefa3f38b20600c918413a146c9d31e90b379b44cf53b378da845b8a1199 -size 56280 +oid sha256:4adeb7a77a0d0fe85097fcd190a99b49858dce11bde601d30335afcb6cc3d5f6 +size 56276 diff --git a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thick stroke, minimal rounding.png b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thick stroke, minimal rounding.png index 6de0d75d4b9..eefbac2bb73 100644 --- a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thick stroke, minimal rounding.png +++ b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thick stroke, minimal rounding.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b258e241726f19d9b0842fbd0fe5c7b39ea61ecae9ee925c1c1f7b18be0bdea1 -size 56737 +oid sha256:f45249f7cc90433a64856905c727571c4ef20468e2c7d3ac2029e18a0477932d +size 56743 diff --git a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thin filled.png b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thin filled.png index d4a3c94b0d7..08178eaa8cf 100644 --- a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thin filled.png +++ b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thin filled.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:a8c7a56c6f29756cf49edbefe38ec2a6bd164b400dd458686405655e5e7f1c77 -size 37596 +oid sha256:d437f68c521f3e627a1b50d46605e8b0b343c5fc3716d9669e8c4436c8992b6f +size 37602 diff --git a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thin stroked.png b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thin stroked.png index c329ebf3248..13f057df9a2 100644 --- a/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thin stroked.png +++ b/crates/egui_demo_lib/tests/snapshots/tessellation_test/Thin stroked.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c0c4a3625ba10777e0878bea1b26c8ac06d0558f777f9b82c9bbe987195c6d60 -size 37623 +oid sha256:08ba98437403a08cca825ed8e288c9f088a46d9a1081f0b0a4ed7fbb9b49bb85 +size 37640 diff --git a/crates/egui_demo_lib/tests/snapshots/widget_gallery_dark_x1.png b/crates/egui_demo_lib/tests/snapshots/widget_gallery_dark_x1.png index c672710c6b4..ab2db5eb53e 100644 --- a/crates/egui_demo_lib/tests/snapshots/widget_gallery_dark_x1.png +++ b/crates/egui_demo_lib/tests/snapshots/widget_gallery_dark_x1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:dae36303c3b75ae100a43511436a9598190f556af2ce7f48b97f02ec09a7d81c -size 66858 +oid sha256:e1ed0e40d08b2b9ea978a07a4b7bf282c9e2cba8c52896f12210f396241e1b78 +size 66859 diff --git a/crates/egui_demo_lib/tests/snapshots/widget_gallery_dark_x2.png b/crates/egui_demo_lib/tests/snapshots/widget_gallery_dark_x2.png index b0cf0e18e91..e84863bf4a6 100644 --- a/crates/egui_demo_lib/tests/snapshots/widget_gallery_dark_x2.png +++ b/crates/egui_demo_lib/tests/snapshots/widget_gallery_dark_x2.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:82a2c649f039a7b6549391253bb20fbbe4dcb404fec98850488155a7297f4353 -size 158896 +oid sha256:28f9862dd6f16b99523f5880bf90346fd9455d0d44e7bdd530d523e0b2ef2d2c +size 158892 diff --git a/crates/egui_demo_lib/tests/snapshots/widget_gallery_light_x1.png b/crates/egui_demo_lib/tests/snapshots/widget_gallery_light_x1.png index ac962e05eae..87eb5ce70e2 100644 --- a/crates/egui_demo_lib/tests/snapshots/widget_gallery_light_x1.png +++ b/crates/egui_demo_lib/tests/snapshots/widget_gallery_light_x1.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c1fc06217640ee574a1cebd6c2351d7b8fb52ad263144175d0eed64ea46109d2 +oid sha256:98c40c99a237f8388d82259fba4388d7b1759fe7b4bf657d326532934135c934 size 61119 diff --git a/crates/egui_demo_lib/tests/snapshots/widget_gallery_light_x2.png b/crates/egui_demo_lib/tests/snapshots/widget_gallery_light_x2.png index 63c5e8b74f1..c2c4705e168 100644 --- a/crates/egui_demo_lib/tests/snapshots/widget_gallery_light_x2.png +++ b/crates/egui_demo_lib/tests/snapshots/widget_gallery_light_x2.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:cb4408cd1654af081e9ffff1af2d6132dce9b395af3657cd2dc97cbcd3919310 -size 152219 +oid sha256:90d36311ce5b1dcf81cab22113620a3362f255059d1f52c6794c8249f960549e +size 152215