Skip to content

Commit e15347b

Browse files
refactor: s/once_cell::Lazy/std::sync::LazyLock
Weaken our dependence on the `once_cell` crate by using functionality from `std` instead that was upstreamed from `once_cell`, this time with what's available in Rust 1.80+. It's not yet possible to eliminate this dependency entirely, but do what we can for now.
1 parent 40ee8e0 commit e15347b

File tree

8 files changed

+22
-26
lines changed

8 files changed

+22
-26
lines changed

Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benches/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ naga = { workspace = true, features = [
4343
"wgsl-out",
4444
] }
4545
nanorand.workspace = true
46-
once_cell.workspace = true
4746
pollster.workspace = true
4847
profiling.workspace = true
4948
rayon.workspace = true

benches/benches/computepass.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::{
55

66
use criterion::{criterion_group, Criterion, Throughput};
77
use nanorand::{Rng, WyRand};
8-
use once_cell::sync::Lazy;
98
use rayon::iter::{IntoParallelIterator, ParallelIterator};
9+
use std::sync::LazyLock;
1010

1111
use crate::DeviceState;
1212

@@ -424,7 +424,7 @@ impl ComputepassState {
424424
}
425425

426426
fn run_bench(ctx: &mut Criterion) {
427-
let state = Lazy::new(ComputepassState::new);
427+
let state = LazyLock::new(ComputepassState::new);
428428

429429
let dispatch_count = dispatch_count();
430430
let dispatch_count_bindless = dispatch_count_bindless();
@@ -449,7 +449,7 @@ fn run_bench(ctx: &mut Criterion) {
449449
group.bench_function(
450450
format!("{cpasses} computepasses x {dispatch_per_pass} dispatches ({label})"),
451451
|b| {
452-
Lazy::force(&state);
452+
LazyLock::force(&state);
453453

454454
b.iter_custom(|iters| {
455455
profiling::scope!("benchmark invocation");
@@ -498,7 +498,7 @@ fn run_bench(ctx: &mut Criterion) {
498498
group.bench_function(
499499
format!("{threads} threads x {dispatch_per_pass} dispatch"),
500500
|b| {
501-
Lazy::force(&state);
501+
LazyLock::force(&state);
502502

503503
b.iter_custom(|iters| {
504504
profiling::scope!("benchmark invocation");
@@ -538,7 +538,7 @@ fn run_bench(ctx: &mut Criterion) {
538538
group.throughput(Throughput::Elements(dispatch_count_bindless as _));
539539

540540
group.bench_function(format!("{dispatch_count_bindless} dispatch"), |b| {
541-
Lazy::force(&state);
541+
LazyLock::force(&state);
542542

543543
b.iter_custom(|iters| {
544544
profiling::scope!("benchmark invocation");
@@ -579,7 +579,7 @@ fn run_bench(ctx: &mut Criterion) {
579579
texture_count + storage_texture_count + storage_buffer_count
580580
),
581581
|b| {
582-
Lazy::force(&state);
582+
LazyLock::force(&state);
583583

584584
b.iter(|| state.device_state.queue.submit([]));
585585
},

benches/benches/renderpass.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use std::{
55

66
use criterion::{criterion_group, Criterion, Throughput};
77
use nanorand::{Rng, WyRand};
8-
use once_cell::sync::Lazy;
98
use rayon::iter::{IntoParallelIterator, ParallelIterator};
9+
use std::sync::LazyLock;
1010

1111
use crate::DeviceState;
1212

@@ -427,7 +427,7 @@ impl RenderpassState {
427427
}
428428

429429
fn run_bench(ctx: &mut Criterion) {
430-
let state = Lazy::new(RenderpassState::new);
430+
let state = LazyLock::new(RenderpassState::new);
431431

432432
let draw_count = draw_count();
433433
let vertex_buffer_count = draw_count * VERTEX_BUFFERS_PER_DRAW;
@@ -450,7 +450,7 @@ fn run_bench(ctx: &mut Criterion) {
450450
group.bench_function(
451451
format!("{rpasses} renderpasses x {draws_per_pass} draws ({label})"),
452452
|b| {
453-
Lazy::force(&state);
453+
LazyLock::force(&state);
454454

455455
b.iter_custom(|iters| {
456456
profiling::scope!("benchmark invocation");
@@ -502,7 +502,7 @@ fn run_bench(ctx: &mut Criterion) {
502502
for threads in [2, 4, 8] {
503503
let draws_per_pass = draw_count / threads;
504504
group.bench_function(format!("{threads} threads x {draws_per_pass} draws"), |b| {
505-
Lazy::force(&state);
505+
LazyLock::force(&state);
506506

507507
b.iter_custom(|iters| {
508508
profiling::scope!("benchmark invocation");
@@ -541,7 +541,7 @@ fn run_bench(ctx: &mut Criterion) {
541541
group.throughput(Throughput::Elements(draw_count as _));
542542

543543
group.bench_function(format!("{draw_count} draws"), |b| {
544-
Lazy::force(&state);
544+
LazyLock::force(&state);
545545

546546
b.iter_custom(|iters| {
547547
profiling::scope!("benchmark invocation");
@@ -577,7 +577,7 @@ fn run_bench(ctx: &mut Criterion) {
577577
texture_count + vertex_buffer_count
578578
),
579579
|b| {
580-
Lazy::force(&state);
580+
LazyLock::force(&state);
581581

582582
b.iter(|| state.device_state.queue.submit([]));
583583
},

benches/benches/resource_creation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::time::{Duration, Instant};
22

33
use criterion::{criterion_group, Criterion, Throughput};
4-
use once_cell::sync::Lazy;
54
use rayon::iter::{IntoParallelIterator, ParallelIterator};
5+
use std::sync::LazyLock;
66

77
use crate::DeviceState;
88

99
fn run_bench(ctx: &mut Criterion) {
10-
let state = Lazy::new(DeviceState::new);
10+
let state = LazyLock::new(DeviceState::new);
1111

1212
const RESOURCES_TO_CREATE: usize = 8;
1313

@@ -19,7 +19,7 @@ fn run_bench(ctx: &mut Criterion) {
1919
group.bench_function(
2020
format!("{threads} threads x {resources_per_thread} resource"),
2121
|b| {
22-
Lazy::force(&state);
22+
LazyLock::force(&state);
2323

2424
b.iter_custom(|iters| {
2525
profiling::scope!("benchmark invocation");

wgpu-hal/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ parking_lot.workspace = true
124124
profiling = { workspace = true, default-features = false }
125125
raw-window-handle.workspace = true
126126
thiserror.workspace = true
127-
once_cell.workspace = true
128127

129128
# backends common
130129
arrayvec.workspace = true

wgpu-hal/src/gles/egl.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use glow::HasContext;
2-
use once_cell::sync::Lazy;
32
use parking_lot::{MappedMutexGuard, Mutex, MutexGuard, RwLock};
43

54
use std::{
6-
collections::HashMap, ffi, mem::ManuallyDrop, os::raw, ptr, rc::Rc, sync::Arc, time::Duration,
5+
collections::HashMap, ffi, mem::ManuallyDrop, os::raw, ptr, rc::Rc, sync::Arc, sync::LazyLock,
6+
time::Duration,
77
};
88

99
/// The amount of time to wait while trying to obtain a lock to the adapter context
@@ -469,7 +469,8 @@ struct Inner {
469469
// Different calls to `eglGetPlatformDisplay` may return the same `Display`, making it a global
470470
// state of all our `EglContext`s. This forces us to track the number of such context to prevent
471471
// terminating the display if it's currently used by another `EglContext`.
472-
static DISPLAYS_REFERENCE_COUNT: Lazy<Mutex<HashMap<usize, usize>>> = Lazy::new(Default::default);
472+
static DISPLAYS_REFERENCE_COUNT: LazyLock<Mutex<HashMap<usize, usize>>> =
473+
LazyLock::new(Default::default);
473474

474475
fn initialize_display(
475476
egl: &EglInstance,

wgpu-hal/src/gles/wgl.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{
66
ptr,
77
sync::{
88
mpsc::{sync_channel, SyncSender},
9-
Arc,
9+
Arc, LazyLock,
1010
},
1111
thread,
1212
time::Duration,
@@ -17,7 +17,6 @@ use glutin_wgl_sys::wgl_extra::{
1717
Wgl, CONTEXT_CORE_PROFILE_BIT_ARB, CONTEXT_DEBUG_BIT_ARB, CONTEXT_FLAGS_ARB,
1818
CONTEXT_PROFILE_MASK_ARB,
1919
};
20-
use once_cell::sync::Lazy;
2120
use parking_lot::{Mutex, MutexGuard, RwLock};
2221
use raw_window_handle::{RawDisplayHandle, RawWindowHandle};
2322
use wgt::InstanceFlags;
@@ -319,8 +318,8 @@ fn create_global_window_class() -> Result<CString, crate::InstanceError> {
319318
}
320319

321320
fn get_global_window_class() -> Result<CString, crate::InstanceError> {
322-
static GLOBAL: Lazy<Result<CString, crate::InstanceError>> =
323-
Lazy::new(create_global_window_class);
321+
static GLOBAL: LazyLock<Result<CString, crate::InstanceError>> =
322+
LazyLock::new(create_global_window_class);
324323
GLOBAL.clone()
325324
}
326325

0 commit comments

Comments
 (0)