From a7ed7f4f12da4dd856cd140f8dd1a02c48e102a9 Mon Sep 17 00:00:00 2001 From: David Lenaerts <550217+DerSchmale@users.noreply.github.com> Date: Wed, 11 Feb 2026 08:47:11 +0100 Subject: [PATCH] Cause shader recompilation when changing shader constants in GLES (#8291) --- CHANGELOG.md | 1 + wgpu-hal/src/gles/device.rs | 12 ++++++++++++ wgpu-hal/src/gles/mod.rs | 1 + 3 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08f0c1d24..4cbdbd0a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -120,6 +120,7 @@ By @cwfitzgerald in [#8999](https://github.com/gfx-rs/wgpu/pull/8999). - `DisplayHandle` should now be passed to `InstanceDescriptor` for correct EGL initialization on Wayland. By @MarijnS95 in [#8012](https://github.com/gfx-rs/wgpu/pull/8012) Note that the existing workaround to create surfaces before the adapter is no longer valid. +- Changing shader constants now correctly recompiles the shader. By @DerSchmale in [#8291](https://github.com/gfx-rs/wgpu/pull/8291). ### Documentation diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 720a7d84e..cc50deea0 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -331,6 +331,7 @@ impl super::Device { shader_id: stage.module.id, entry_point: stage.entry_point.to_owned(), zero_initialize_workgroup_memory: stage.zero_initialize_workgroup_memory, + constant_hash: Self::create_constant_hash(stage), }); } let mut guard = self @@ -362,6 +363,17 @@ impl super::Device { Ok(program) } + fn create_constant_hash(stage: &crate::ProgrammableStage) -> Vec { + let mut buf: Vec = Vec::new(); + + for (key, value) in stage.constants.iter() { + buf.extend_from_slice(key.as_bytes()); + buf.extend_from_slice(&value.to_ne_bytes()); + } + + buf + } + unsafe fn create_program<'a>( gl: &glow::Context, shaders: ArrayVec, { crate::MAX_CONCURRENT_SHADER_STAGES }>, diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index d5d9c5ae7..8b5562f36 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -703,6 +703,7 @@ struct ProgramStage { shader_id: ShaderId, entry_point: String, zero_initialize_workgroup_memory: bool, + constant_hash: Vec, } #[derive(PartialEq, Eq, Hash)]