mirror of
https://github.com/storytold/wgpu.git
synced 2026-12-01 02:24:35 +01:00
This will help users determine whether the problem is: * a backend is not statically enabled * a backend is not dynamically enabled * no drivers or physical adapters are present for that backend (further distinction would be useful here) * no adapters met the required criteria There are deficiencies in the reporting of WebGPU vs. WebGL support. Those would best be fixed by also fixing the mutual exclusion of those backends.
44 lines
1.5 KiB
Rust
44 lines
1.5 KiB
Rust
//! Tests of [`wgpu::Backend::Noop`].
|
|
|
|
use std::sync::atomic::{AtomicBool, Ordering::Relaxed};
|
|
use std::sync::Arc;
|
|
|
|
#[test]
|
|
fn device_is_not_available_by_default() {
|
|
let instance = wgpu::Instance::new(&wgpu::InstanceDescriptor {
|
|
backends: wgpu::Backends::NOOP,
|
|
..Default::default()
|
|
});
|
|
|
|
pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions::default()))
|
|
.expect_err("noop backend adapter present when it should not be");
|
|
}
|
|
|
|
#[test]
|
|
fn device_and_buffers() {
|
|
let (device, queue) = crate::request_noop_device();
|
|
|
|
// Demonstrate that creating and *writing* to a buffer succeeds.
|
|
// This also involves creation of a staging buffer.
|
|
let buffer = device.create_buffer(&wgpu::BufferDescriptor {
|
|
label: Some("hello world"),
|
|
size: 8,
|
|
usage: wgpu::BufferUsages::COPY_DST | wgpu::BufferUsages::COPY_SRC,
|
|
mapped_at_creation: false,
|
|
});
|
|
assert_eq!(buffer.size(), 8);
|
|
queue.write_buffer(&buffer, 0, &[1, 2, 3, 4]);
|
|
queue.write_buffer(&buffer, 4, &[5, 6, 7, 8]);
|
|
|
|
// Demonstrate that we can read back data from the buffer.
|
|
// This also involves copy_buffer_to_buffer().
|
|
let done: Arc<AtomicBool> = Arc::default();
|
|
let done2 = done.clone();
|
|
wgpu::util::DownloadBuffer::read_buffer(&device, &queue, &buffer.slice(..), move |result| {
|
|
assert_eq!(*result.unwrap(), [1, 2, 3, 4, 5, 6, 7, 8],);
|
|
done.store(true, Relaxed);
|
|
});
|
|
device.poll(wgpu::PollType::Wait).unwrap();
|
|
assert!(done2.load(Relaxed));
|
|
}
|