-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thiserror errors instead of internal unwrap/except on user errors (#45)
Co-authored-by: Imbris <[email protected]>
- Loading branch information
Showing
7 changed files
with
179 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
fn create_device() -> (wgpu::Adapter, wgpu::Device, wgpu::Queue) { | ||
async fn create_default_device_async() -> (wgpu::Adapter, wgpu::Device, wgpu::Queue) { | ||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::default()); | ||
let adapter = instance.request_adapter(&wgpu::RequestAdapterOptions::default()).await.unwrap(); | ||
let (device, queue) = adapter | ||
.request_device( | ||
&wgpu::DeviceDescriptor { | ||
features: wgpu::Features::TIMESTAMP_QUERY, | ||
..Default::default() | ||
}, | ||
None, | ||
) | ||
.await | ||
.unwrap(); | ||
(adapter, device, queue) | ||
} | ||
|
||
futures_lite::future::block_on(create_default_device_async()) | ||
} | ||
|
||
#[test] | ||
fn end_frame_unclosed_scope() { | ||
let (adapter, device, queue) = create_device(); | ||
|
||
let mut profiler = wgpu_profiler::GpuProfiler::new(&adapter, &device, &queue, 1); | ||
{ | ||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); | ||
profiler.begin_scope("open scope", &mut encoder, &device); | ||
profiler.resolve_queries(&mut encoder); | ||
} | ||
|
||
assert_eq!( | ||
profiler.end_frame(), | ||
Err(wgpu_profiler::EndFrameError::UnclosedScopes(vec!["open scope".to_string()])) | ||
); | ||
|
||
// Make sure we can recover from this. | ||
{ | ||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); | ||
profiler.end_scope(&mut encoder).unwrap(); | ||
profiler.resolve_queries(&mut encoder); | ||
} | ||
assert_eq!(profiler.end_frame(), Ok(())); | ||
} | ||
|
||
#[test] | ||
fn end_frame_unresolved_scope() { | ||
let (adapter, device, queue) = create_device(); | ||
|
||
let mut profiler = wgpu_profiler::GpuProfiler::new(&adapter, &device, &queue, 1); | ||
{ | ||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); | ||
profiler.begin_scope("open scope", &mut encoder, &device); | ||
profiler.end_scope(&mut encoder).unwrap(); | ||
} | ||
|
||
assert_eq!(profiler.end_frame(), Err(wgpu_profiler::EndFrameError::UnresolvedQueries(2))); | ||
|
||
// Make sure we can recover from this! | ||
{ | ||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); | ||
profiler.resolve_queries(&mut encoder); | ||
} | ||
assert_eq!(profiler.end_frame(), Ok(())); | ||
} | ||
|
||
#[test] | ||
fn no_open_scope() { | ||
let (adapter, device, queue) = create_device(); | ||
|
||
let mut profiler = wgpu_profiler::GpuProfiler::new(&adapter, &device, &queue, 1); | ||
{ | ||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); | ||
assert_eq!(profiler.end_scope(&mut encoder), Err(wgpu_profiler::ScopeError::NoOpenScope)); | ||
} | ||
// Make sure we can recover from this. | ||
{ | ||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); | ||
profiler.begin_scope("open scope", &mut encoder, &device); | ||
assert_eq!(profiler.end_scope(&mut encoder), Ok(())); | ||
profiler.resolve_queries(&mut encoder); | ||
} | ||
assert_eq!(profiler.end_frame(), Ok(())); | ||
} |