From 21203de7f07aec02ac1bb325462c729d9ae8fc38 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 21:33:05 +0100 Subject: [PATCH] Animated sprites: the CPU path also when the driver cannot build the compute pipeline An OpenGL driver can list compute shaders among its extensions while wgpu writes GLSL of its core version, which has none (seen under MESA_GL_VERSION_OVERRIDE=3.3: the pipeline failed and the game panicked). The pipeline is now created inside error scopes, and a failure falls back to the CPU path with one warning. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/gfx/animate.rs | 50 ++++++++++++++++-------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/crates/horizon-client/src/gfx/animate.rs b/crates/horizon-client/src/gfx/animate.rs index c94d8034e..5a70f3b0f 100644 --- a/crates/horizon-client/src/gfx/animate.rs +++ b/crates/horizon-client/src/gfx/animate.rs @@ -77,7 +77,7 @@ pub(super) struct SpriteAnimator { impl SpriteAnimator { /// `textures` are the sprite arrays, `split` layers each, `size` pixels /// wide; `animations` hold their frames at that size. `compute`: whether - /// the device runs compute shaders writing storage textures. + /// the device says it runs compute shaders writing storage textures. pub fn new( device: &wgpu::Device, animations: &[SpriteAnimation], @@ -87,8 +87,9 @@ impl SpriteAnimator { split: u32, compute: bool, ) -> Self { + let pipeline = if compute { pipeline(device) } else { None }; let limits = device.limits(); - let limit = if compute { + let limit = if pipeline.is_some() { limits .max_storage_buffer_binding_size .min(limits.max_buffer_size) @@ -145,7 +146,7 @@ impl SpriteAnimator { group, }); } - if !compute { + let Some(pipeline) = pipeline else { let groups = keys .iter() .zip(&counts) @@ -167,7 +168,7 @@ impl SpriteAnimator { size, changed: Vec::new(), }; - } + }; let frames: Vec<_> = frames .iter() .map(|data| { @@ -191,18 +192,6 @@ impl SpriteAnimator { usage: wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_DST, mapped_at_creation: false, }); - let module = device.create_shader_module(wgpu::ShaderModuleDescriptor { - label: Some("Animated sprites"), - source: wgpu::ShaderSource::Wgsl(include_str!("animate.wgsl").into()), - }); - let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { - label: Some("Animated sprites"), - layout: None, - module: &module, - entry_point: Some("animate"), - compilation_options: Default::default(), - cache: None, - }); let layout = pipeline.get_bind_group_layout(0); let groups = keys .iter() @@ -374,6 +363,35 @@ impl SpriteAnimator { } } +/// `animate.wgsl`'s pipeline, unless the device fails to make it: an OpenGL +/// driver can list compute shaders among its extensions while wgpu writes +/// the GLSL version of its core version, which has none (Mesa's +/// `MESA_GL_VERSION_OVERRIDE`, older drivers). +fn pipeline(device: &wgpu::Device) -> Option { + let validation = device.push_error_scope(wgpu::ErrorFilter::Validation); + let internal = device.push_error_scope(wgpu::ErrorFilter::Internal); + let module = device.create_shader_module(wgpu::ShaderModuleDescriptor { + label: Some("Animated sprites"), + source: wgpu::ShaderSource::Wgsl(include_str!("animate.wgsl").into()), + }); + let pipeline = device.create_compute_pipeline(&wgpu::ComputePipelineDescriptor { + label: Some("Animated sprites"), + layout: None, + module: &module, + entry_point: Some("animate"), + compilation_options: Default::default(), + cache: None, + }); + let internal = pollster::block_on(internal.pop()); + match internal.or(pollster::block_on(validation.pop())) { + None => Some(pipeline), + Some(e) => { + log::warn!("Horizon renderer: animated sprites drawn on the CPU ({e})"); + None + } + } +} + /// `animate.wgsl` on the CPU: one `width` wide level of a job /// (`[layer, current, next, millis, edge]`) from `frames`' chains. fn mix_level(frames: &[u8], [_, current, next, millis, edge]: [u32; 5], width: u32) -> Vec {