Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework wgpu-rs Context #6619

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ serde_json = "1.0.133"
smallvec = "1"
static_assertions = "1.1.0"
strum = { version = "0.25.0", features = ["derive"] }
trybuild = "1"
tracy-client = "0.17"
thiserror = "1.0.69"
wgpu = { version = "23.0.1", path = "./wgpu", default-features = false }
Expand Down
10 changes: 8 additions & 2 deletions tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ name = "wgpu-test"
path = "tests/root.rs"
harness = false

[[test]]
name = "wgpu-compile-test"
path = "compile_tests/root.rs"
harness = true
Comment on lines +19 to +22
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lookie: Our test suite has grown a new feature. We can now ensure that a given bit of wgpu code does not compile. This is very useful to make sure that #6145 doesn't come back.


[features]
webgl = ["wgpu/webgl"]

Expand All @@ -27,6 +32,7 @@ bytemuck.workspace = true
cfg-if.workspace = true
ctor.workspace = true
futures-lite.workspace = true
glam.workspace = true
itertools.workspace = true
libtest-mimic.workspace = true
log.workspace = true
Expand All @@ -37,10 +43,10 @@ profiling.workspace = true
serde_json.workspace = true
serde.workspace = true
strum = { workspace = true, features = ["derive"] }
wgpu-macros.workspace = true
trybuild.workspace = true
wgpu = { workspace = true, features = ["wgsl"] }
wgpu-macros.workspace = true
wgt = { workspace = true, features = ["serde"] }
glam.workspace = true

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
env_logger.workspace = true
Expand Down
18 changes: 18 additions & 0 deletions tests/compile_tests/fail/cpass_lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Test to ensure that ComputePass without forget_lifetime does not compile
// when the ComputePass is dropped before the CommandBuffer is finished.
//
// See #6145 for more info.

fn main() {
let instance = wgpu::Instance::new(Default::default());
let adapter = pollster::block_on(instance.request_adapter(&Default::default())).unwrap();
let (device, queue) =
pollster::block_on(adapter.request_device(&Default::default(), None)).unwrap();

let mut encoder = device.create_command_encoder(&Default::default());
let _compute_pass = encoder.begin_compute_pass(&Default::default());
// set up the compute pass...

let cmd_buffer = encoder.finish();
queue.submit([cmd_buffer]);
}
13 changes: 13 additions & 0 deletions tests/compile_tests/fail/cpass_lifetime.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0505]: cannot move out of `encoder` because it is borrowed
--> compile_tests/fail/cpass_lifetime.rs:16:22
|
12 | let mut encoder = device.create_command_encoder(&Default::default());
| ----------- binding `encoder` declared here
13 | let _compute_pass = encoder.begin_compute_pass(&Default::default());
| ------- borrow of `encoder` occurs here
...
16 | let cmd_buffer = encoder.finish();
| ^^^^^^^ move out of `encoder` occurs here
17 | queue.submit([cmd_buffer]);
18 | }
| - borrow might be used here, when `_compute_pass` is dropped and runs the destructor for type `wgpu::ComputePass<'_>`
18 changes: 18 additions & 0 deletions tests/compile_tests/fail/rpass_lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Test to ensure that ComputePass without forget_lifetime does not compile
// when the ComputePass is dropped before the CommandBuffer is finished.
//
// See #6145 for more info.

fn main() {
let instance = wgpu::Instance::new(Default::default());
let adapter = pollster::block_on(instance.request_adapter(&Default::default())).unwrap();
let (device, queue) =
pollster::block_on(adapter.request_device(&Default::default(), None)).unwrap();

let mut encoder = device.create_command_encoder(&Default::default());
let _render_pass = encoder.begin_render_pass(&Default::default());
// set up the render pass...

let cmd_buffer = encoder.finish();
queue.submit([cmd_buffer]);
}
13 changes: 13 additions & 0 deletions tests/compile_tests/fail/rpass_lifetime.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0505]: cannot move out of `encoder` because it is borrowed
--> compile_tests/fail/rpass_lifetime.rs:16:22
|
12 | let mut encoder = device.create_command_encoder(&Default::default());
| ----------- binding `encoder` declared here
13 | let _render_pass = encoder.begin_render_pass(&Default::default());
| ------- borrow of `encoder` occurs here
...
16 | let cmd_buffer = encoder.finish();
| ^^^^^^^ move out of `encoder` occurs here
17 | queue.submit([cmd_buffer]);
18 | }
| - borrow might be used here, when `_render_pass` is dropped and runs the destructor for type `wgpu::RenderPass<'_>`
7 changes: 7 additions & 0 deletions tests/compile_tests/root.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Tests that ensure that various constructs that should not compile do not compile.

#[test]
fn compile_fail() {
let t = trybuild::TestCases::new();
t.compile_fail("compile_tests/fail/*.rs");
}
2 changes: 1 addition & 1 deletion tests/tests/external_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static IMAGE_BITMAP_IMPORT: GpuTestConfiguration =
origin: src_origin,
flip_y: src_flip_y,
},
wgpu::CopyExternalImageDestInfo {
wgt::CopyExternalImageDestInfo {
texture: &texture,
mip_level: 0,
origin: dest_origin,
Expand Down
8 changes: 7 additions & 1 deletion wgpu-core/src/global.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{fmt, sync::Arc};

use crate::{
hal_api::HalApi,
Expand Down Expand Up @@ -85,6 +85,12 @@ impl Global {
}
}

impl fmt::Debug for Global {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Global").finish()
}
}

impl Drop for Global {
fn drop(&mut self) {
profiling::scope!("Global::drop");
Expand Down
2 changes: 1 addition & 1 deletion wgpu-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ serde = ["dep:serde"]
counters = []

[dependencies]
bitflags.workspace = true
bitflags = { workspace = true, features = ["serde"] }
serde = { workspace = true, features = ["derive"], optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion wgpu/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ fn main() {
webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgl") },
webgpu: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgpu") },
Emscripten: { all(target_arch = "wasm32", target_os = "emscripten") },
wgpu_core: { any(native, webgl, emscripten) },
wgpu_core: { any(native, webgl, Emscripten) },
send_sync: { any(
not(target_arch = "wasm32"),
all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics"))
Expand Down
Loading
Loading