wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

No-op backend, for application logic + validation testing

Open kpreid opened this issue 2 years ago • 0 comments

Is your feature request related to a problem? Please describe. I'd like to be able to write #[test]s for code that manages one or more wgpu objects, without needing to make the test conditional on the presence of a GPU or software render driver.

Describe the solution you'd like I'd like a way to create a Device and Queue that always succeeds, and the resulting device would always allow creating objects such as Textures (subject to wgpu validation checks), but where all operations that would read the results of computations (i.e. mapping buffers for read) always fail since they have no real implementation. Perhaps this would look like a special backend bit to pass to wgpu::Instance::new().

Tests written using this mechanism would be able to test that the application code succeeds on all CPU-side matters while ignoring the GPU state, and also that it does not trigger any wgpu validation errors.

Describe alternatives you've considered An alternative approach to this problem would be a software renderer backend that's an optional dependency of wgpu (rather than being an OS driver that might be absent), but while that would be nifty, it's more than we need here.

In individual cases, the application code could be modified to allow skipping all wgpu operations, but that would often be awkward and require providing alternative data storage used only for testing (e.g. for Texture::size()).

#2291 "Add a Dummy backend" is similar, but if I understand correctly, is asking only for a way to compile applications with no backends (presumably Instance::request_adapter() would always fail). This feature would subsume that feature.

kpreid avatar Feb 10 '24 21:02 kpreid