diff --git a/Cargo.lock b/Cargo.lock index 1c708ef48..444aec0ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2419,6 +2419,7 @@ dependencies = [ "itertools 0.13.0", "log", "num-traits", + "once_cell", "petgraph 0.8.0", "pp-rs", "ron", diff --git a/naga/Cargo.toml b/naga/Cargo.toml index bc2e746c2..8795aa0d6 100644 --- a/naga/Cargo.toml +++ b/naga/Cargo.toml @@ -96,6 +96,7 @@ indexmap.workspace = true log = "0.4" # `half` requires 0.2.16 for `FromBytes` and `ToBytes`. num-traits = { version = "0.2.16", default-features = false } +once_cell = { workspace = true, features = ["alloc", "race"] } strum = { workspace = true, optional = true } spirv = { version = "0.3", optional = true } thiserror.workspace = true diff --git a/naga/src/proc/namer.rs b/naga/src/proc/namer.rs index 05678242f..74d28c488 100644 --- a/naga/src/proc/namer.rs +++ b/naga/src/proc/namer.rs @@ -1,11 +1,14 @@ use alloc::{ borrow::Cow, + boxed::Box, format, string::{String, ToString}, vec::Vec, }; use core::hash::{Hash, Hasher}; + use hashbrown::HashSet; +use once_cell::race::OnceBox; use crate::{arena::Handle, FastHashMap, FastHashSet}; @@ -46,15 +49,13 @@ pub struct Namer { reserved_prefixes: Vec<&'static str>, } -#[cfg(any(wgsl_out, glsl_out, msl_out, hlsl_out, test))] impl Default for Namer { fn default() -> Self { - use std::sync::LazyLock; - static DEFAULT_KEYWORDS: LazyLock> = LazyLock::new(HashSet::default); + static DEFAULT_KEYWORDS: OnceBox> = OnceBox::new(); Self { unique: Default::default(), - keywords: &DEFAULT_KEYWORDS, + keywords: DEFAULT_KEYWORDS.get_or_init(|| Box::new(HashSet::default())), keywords_case_insensitive: Default::default(), reserved_prefixes: Default::default(), }