Skip to content

Conversation

atlv24
Copy link
Collaborator

@atlv24 atlv24 commented Aug 2, 2025

Connections
Fixes bevyengine/bevy#20379

Description
The unsafe in hal vk create_sampler is unsound.

Testing
Reproduction case:

use std::thread;
struct Example {}
impl crate::framework::Example for Example {
    fn init(
        _config: &wgpu::SurfaceConfiguration,
        _adapter: &wgpu::Adapter,
        device: &wgpu::Device,
        _queue: &wgpu::Queue,
    ) -> Self {
        thread::scope(move |s| {
            for i in 0..100 {
                s.spawn(|| {
                    for i in 0..100000 {
                        let _ = device.create_sampler(&wgpu::SamplerDescriptor {
                            label: Some("My Label"),
                            ..Default::default()
                        });
                    }
                });
            }
        });
        Self {}
    }
    fn resize(
        &mut self,
        _config: &wgpu::SurfaceConfiguration,
        _device: &wgpu::Device,
        _queue: &wgpu::Queue,
    ) {
    }
    fn update(&mut self, _event: winit::event::WindowEvent) {}
    fn render(&mut self, _view: &wgpu::TextureView, _device: &wgpu::Device, _queue: &wgpu::Queue) {}
}

Squash or Rebase?

squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

Copy link
Member

@ErichDonGubler ErichDonGubler left a comment

Choose a reason for hiding this comment

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

LGTM, minus a nit I'm going to fix right now.

@atlv24
Copy link
Collaborator Author

atlv24 commented Aug 5, 2025

One more note is set_object_name currently has a safety comment that says "must be valid to call set_object_name" and that's like... very undescriptive? It would be good to elaborate on when its valid to call, like no concurrent access (and any other requirements)

@ErichDonGubler ErichDonGubler enabled auto-merge (squash) August 5, 2025 14:33
@ErichDonGubler ErichDonGubler merged commit 7cb642e into gfx-rs:trunk Aug 5, 2025
40 checks passed
@ErichDonGubler
Copy link
Member

@atlv24: Just filed #8055.

atlv24 added a commit to atlv24/wgpu that referenced this pull request Aug 6, 2025
ErichDonGubler added a commit that referenced this pull request Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

STATUS_HEAP_CORRUPTION on startup during RenderStartup.
3 participants