Skip to content

Commit a7ed7f4

Browse files
authored
Cause shader recompilation when changing shader constants in GLES (gfx-rs#8291)
1 parent 702c4ef commit a7ed7f4

3 files changed

Lines changed: 14 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ By @cwfitzgerald in [#8999](https://github.com/gfx-rs/wgpu/pull/8999).
120120

121121
- `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)
122122
Note that the existing workaround to create surfaces before the adapter is no longer valid.
123+
- Changing shader constants now correctly recompiles the shader. By @DerSchmale in [#8291](https://github.com/gfx-rs/wgpu/pull/8291).
123124

124125
### Documentation
125126

wgpu-hal/src/gles/device.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ impl super::Device {
331331
shader_id: stage.module.id,
332332
entry_point: stage.entry_point.to_owned(),
333333
zero_initialize_workgroup_memory: stage.zero_initialize_workgroup_memory,
334+
constant_hash: Self::create_constant_hash(stage),
334335
});
335336
}
336337
let mut guard = self
@@ -362,6 +363,17 @@ impl super::Device {
362363
Ok(program)
363364
}
364365

366+
fn create_constant_hash(stage: &crate::ProgrammableStage<super::ShaderModule>) -> Vec<u8> {
367+
let mut buf: Vec<u8> = Vec::new();
368+
369+
for (key, value) in stage.constants.iter() {
370+
buf.extend_from_slice(key.as_bytes());
371+
buf.extend_from_slice(&value.to_ne_bytes());
372+
}
373+
374+
buf
375+
}
376+
365377
unsafe fn create_program<'a>(
366378
gl: &glow::Context,
367379
shaders: ArrayVec<ShaderStage<'a>, { crate::MAX_CONCURRENT_SHADER_STAGES }>,

wgpu-hal/src/gles/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@ struct ProgramStage {
703703
shader_id: ShaderId,
704704
entry_point: String,
705705
zero_initialize_workgroup_memory: bool,
706+
constant_hash: Vec<u8>,
706707
}
707708

708709
#[derive(PartialEq, Eq, Hash)]

0 commit comments

Comments
 (0)