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

Device::as_hal crashes after ID removal in #6134 #6169

Closed
ErichDonGubler opened this issue Aug 27, 2024 · 4 comments · Fixed by #6179
Closed

Device::as_hal crashes after ID removal in #6134 #6169

ErichDonGubler opened this issue Aug 27, 2024 · 4 comments · Fixed by #6179

Comments

@ErichDonGubler
Copy link
Member

ErichDonGubler commented Aug 27, 2024

Description

@MarijnS95 noted in this comment from #6134 that Device::as_hal appears to have regressed to crashing when called in some (?) cases.

Repro steps

TBD by @MarijnS95.

Expected vs observed behavior

We should keep previous behavior, that is, Device::as_hal should not crash.

Platform

Windows on DX12.

@MarijnS95
Copy link
Contributor

Platform is Windows. I was running a modified version of the hello_triangle sample while playing with DirectComposition (needed access to the D3D12Device for that).

Will push a repro branch soon.

@gfx-rs gfx-rs deleted a comment from GoldenCaterpie Aug 27, 2024
@MarijnS95
Copy link
Contributor

MarijnS95 commented Aug 27, 2024

Try https://github.com/MarijnS95/wgpu/compare/repro-6169 with:

$ WGPU_BACKEND=dx12 cargo r -p wgpu-examples hello_triangle
...
thread 'main' panicked at wgpu\src\context.rs:737:5:
assertion failed: data.is::<T>()
stack backtrace:
...

Note that in this caseit's already failing for surface, before even getting to adapter or device which also both fail. Only instance.as_hal() is successful.

@ErichDonGubler
Copy link
Member Author

Confirmed locally on my M1 Mac that the suggested repro crashes, and that latest trunk does not reproduce the crash. I did this on Mac, instead of Windows, by replacing dx12 with metal in the tip commit of the suggested repro, i.e.:

diff --git a/examples/src/hello_triangle/mod.rs b/examples/src/hello_triangle/mod.rs
index 7c82d49cf0..0100b79024 100644
--- a/examples/src/hello_triangle/mod.rs
+++ b/examples/src/hello_triangle/mod.rs
@@ -12,7 +12,10 @@
 
     let instance = wgpu::Instance::default();
 
-    let surface = instance.create_surface(&window).unwrap();
+    unsafe { instance.as_hal::<wgpu::hal::metal::Api>() };
+
+    let mut surface = instance.create_surface(&window).unwrap();
+    unsafe { surface.as_hal::<wgpu::hal::metal::Api, _, _>(|s| ()) };
     let adapter = instance
         .request_adapter(&wgpu::RequestAdapterOptions {
             power_preference: wgpu::PowerPreference::default(),
@@ -22,6 +25,7 @@
         })
         .await
         .expect("Failed to find an appropriate adapter");
+    unsafe { adapter.as_hal::<wgpu::hal::metal::Api, _, _>(|a| ()) };
 
     // Create the logical device and command queue
     let (device, queue) = adapter
@@ -38,6 +42,7 @@
         )
         .await
         .expect("Failed to create device");
+    unsafe { device.as_hal::<wgpu::hal::metal::Api, _, _>(|d| ()) };
 
     // Load the shaders from disk
     let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {

@MarijnS95
Copy link
Contributor

Yep, the repro branch no longer crashes after rebasing, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants