Skip to content

Commit 02ac81b

Browse files
committed
fix Firefox color rendering by respecting surface texture format preference
1 parent eb30ee7 commit 02ac81b

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

  • editor/src/node_graph_executor
  • node-graph/libraries/wgpu-executor/src

editor/src/node_graph_executor/runtime.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,13 @@ impl NodeRuntime {
348348
// Configure the surface at physical resolution (for HiDPI displays)
349349
let surface_inner = &surface.surface.inner;
350350
let surface_caps = surface_inner.get_capabilities(&executor.context.adapter);
351+
// Use the surface's preferred format (Firefox WebGL prefers Bgra8Unorm, Chrome prefers Rgba8Unorm)
352+
let surface_format = surface_caps.formats.iter().copied().find(|f| f.is_srgb()).unwrap_or(surface_caps.formats[0]);
351353
surface_inner.configure(
352354
&executor.context.device,
353355
&vello::wgpu::SurfaceConfiguration {
354356
usage: vello::wgpu::TextureUsages::RENDER_ATTACHMENT | vello::wgpu::TextureUsages::COPY_DST,
355-
format: vello::wgpu::TextureFormat::Rgba8Unorm,
357+
format: surface_format,
356358
width: physical_resolution.x,
357359
height: physical_resolution.y,
358360
present_mode: surface_caps.present_modes[0],
@@ -365,21 +367,11 @@ impl NodeRuntime {
365367
let surface_texture = surface_inner.get_current_texture().expect("Failed to get surface texture");
366368
self.current_viewport_texture = Some(image_texture.clone());
367369

368-
encoder.copy_texture_to_texture(
369-
vello::wgpu::TexelCopyTextureInfoBase {
370-
texture: image_texture.texture.as_ref(),
371-
mip_level: 0,
372-
origin: Default::default(),
373-
aspect: Default::default(),
374-
},
375-
vello::wgpu::TexelCopyTextureInfoBase {
376-
texture: &surface_texture.texture,
377-
mip_level: 0,
378-
origin: Default::default(),
379-
aspect: Default::default(),
380-
},
381-
image_texture.texture.size(),
382-
);
370+
// Use the blitter to copy the texture to the surface, handling format conversion
371+
// (e.g., Rgba8Unorm source to Bgra8Unorm surface on Firefox)
372+
let source_view = image_texture.texture.create_view(&vello::wgpu::TextureViewDescriptor::default());
373+
let target_view = surface_texture.texture.create_view(&vello::wgpu::TextureViewDescriptor::default());
374+
surface.surface.blitter.copy(&executor.context.device, &mut encoder, &source_view, &target_view);
383375

384376
executor.context.queue.submit([encoder.finish()]);
385377
surface_texture.present();

node-graph/libraries/wgpu-executor/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,10 @@ impl WgpuExecutor {
173173
}
174174

175175
pub fn create_surface_inner(&self, surface: wgpu::Surface<'static>, window_id: SurfaceId) -> Result<SurfaceHandle<Surface>> {
176-
let blitter = TextureBlitter::new(&self.context.device, VELLO_SURFACE_FORMAT);
176+
// Get the surface's preferred format (Firefox WebGL may prefer Bgra8Unorm, Chrome prefers Rgba8Unorm)
177+
let surface_caps = surface.get_capabilities(&self.context.adapter);
178+
let surface_format = surface_caps.formats.iter().copied().find(|f| f.is_srgb()).unwrap_or(surface_caps.formats[0]);
179+
let blitter = TextureBlitter::new(&self.context.device, surface_format);
177180
Ok(SurfaceHandle {
178181
window_id,
179182
surface: Surface {

0 commit comments

Comments
 (0)