From 0951b033a7c81b464231e3202dfb88cc28476c11 Mon Sep 17 00:00:00 2001 From: killian Date: Tue, 11 Oct 2022 21:14:10 +0200 Subject: [PATCH] Implement Hash for DepthStencilState and DepthBiasState (#3092) * Implement Hash for DepthStencilState and DepthBiasState * Fix clippy error * cargo fmt * Fix Hash implementation Co-authored-by: char0313 --- CHANGELOG.md | 1 + wgpu-types/src/lib.rs | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55f93aaf66..28ebf8ef1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,7 @@ Bottom level categories: #### General +- Implement `Hash` for `DepthStencilState` and `DepthBiasState` - Add the `"wgsl"` feature, to enable WGSL shaders in `wgpu-core` and `wgpu`. Enabled by default in `wgpu`. By @daxpedda in [#2890](https://github.com/gfx-rs/wgpu/pull/2890). - Implement `Clone` for `ShaderSource` and `ShaderModuleDescriptor` in `wgpu`. By @daxpedda in [#3086](https://github.com/gfx-rs/wgpu/pull/3086). diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 369615d1e9..42845642b9 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -10,6 +10,7 @@ #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +use std::hash::{Hash, Hasher}; use std::{num::NonZeroU32, ops::Range}; /// Integral type used for buffer offsets. @@ -3152,7 +3153,7 @@ impl StencilState { /// Corresponds to a portion of [WebGPU `GPUDepthStencilState`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpudepthstencilstate). #[repr(C)] -#[derive(Clone, Copy, Debug, Default, PartialEq)] +#[derive(Clone, Copy, Debug, Default)] #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] pub struct DepthBiasState { @@ -3171,12 +3172,28 @@ impl DepthBiasState { } } +impl Hash for DepthBiasState { + fn hash(&self, state: &mut H) { + self.constant.hash(state); + self.slope_scale.to_bits().hash(state); + self.clamp.to_bits().hash(state); + } +} + +impl PartialEq for DepthBiasState { + fn eq(&self, other: &Self) -> bool { + (self.constant == other.constant) + && (self.slope_scale.to_bits() == other.slope_scale.to_bits()) + && (self.clamp.to_bits() == other.clamp.to_bits()) + } +} + /// Describes the depth/stencil state in a render pipeline. /// /// Corresponds to [WebGPU `GPUDepthStencilState`]( /// https://gpuweb.github.io/gpuweb/#dictdef-gpudepthstencilstate). #[repr(C)] -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, Hash, PartialEq)] #[cfg_attr(feature = "trace", derive(Serialize))] #[cfg_attr(feature = "replay", derive(Deserialize))] pub struct DepthStencilState {