1
1
use wgpu:: { Adapter , Device , Instance , Queue } ;
2
2
use wgt:: { Backends , Features , Limits } ;
3
3
4
+ use crate :: report:: AdapterReport ;
5
+
4
6
/// Initialize the logger for the test runner.
5
7
pub fn init_logger ( ) {
6
8
// We don't actually care if it fails
@@ -11,7 +13,7 @@ pub fn init_logger() {
11
13
}
12
14
13
15
/// Initialize a wgpu instance with the options from the environment.
14
- pub fn initialize_instance ( force_fxc : bool ) -> Instance {
16
+ pub fn initialize_instance ( backends : wgpu :: Backends , force_fxc : bool ) -> Instance {
15
17
// We ignore `WGPU_BACKEND` for now, merely using test filtering to only run a single backend's tests.
16
18
//
17
19
// We can potentially work support back into the test runner in the future, but as the adapters are matched up
@@ -23,9 +25,9 @@ pub fn initialize_instance(force_fxc: bool) -> Instance {
23
25
// To "disable" webgpu regardless, we do this by removing the webgpu backend whenever we see
24
26
// the webgl feature.
25
27
let backends = if cfg ! ( feature = "webgl" ) {
26
- Backends :: all ( ) - Backends :: BROWSER_WEBGPU
28
+ backends - wgpu :: Backends :: BROWSER_WEBGPU
27
29
} else {
28
- Backends :: all ( )
30
+ backends
29
31
} ;
30
32
// Some tests need to be able to force demote to FXC, to specifically test workarounds for FXC
31
33
// behavior.
@@ -43,12 +45,16 @@ pub fn initialize_instance(force_fxc: bool) -> Instance {
43
45
} )
44
46
}
45
47
46
- /// Initialize a wgpu adapter, taking the `n`th adapter from the instance .
48
+ /// Initialize a wgpu adapter, using the given adapter report to match the adapter .
47
49
pub async fn initialize_adapter (
48
- adapter_index : usize ,
50
+ adapter_report : Option < & AdapterReport > ,
49
51
force_fxc : bool ,
50
52
) -> ( Instance , Adapter , Option < SurfaceGuard > ) {
51
- let instance = initialize_instance ( force_fxc) ;
53
+ let backends = adapter_report
54
+ . map ( |report| Backends :: from ( report. info . backend ) )
55
+ . unwrap_or_default ( ) ;
56
+
57
+ let instance = initialize_instance ( backends, force_fxc) ;
52
58
#[ allow( unused_variables) ]
53
59
let surface: Option < wgpu:: Surface > ;
54
60
let surface_guard: Option < SurfaceGuard > ;
@@ -82,13 +88,24 @@ pub async fn initialize_adapter(
82
88
83
89
cfg_if:: cfg_if! {
84
90
if #[ cfg( not( target_arch = "wasm32" ) ) ] {
85
- let adapter_iter = instance. enumerate_adapters( wgpu:: Backends :: all( ) ) ;
86
- let adapter_count = adapter_iter. len( ) ;
91
+ let adapter_iter = instance. enumerate_adapters( backends) ;
87
92
let adapter = adapter_iter. into_iter( )
88
- . nth( adapter_index)
89
- . unwrap_or_else( || panic!( "Tried to get index {adapter_index} adapter, but adapter list was only {adapter_count} long. Is .gpuconfig out of date?" ) ) ;
93
+ // If we have a report, we only want to match the adapter with the same info.
94
+ //
95
+ // If we don't have a report, we just take the first adapter.
96
+ . find( |adapter| if let Some ( adapter_report) = adapter_report {
97
+ adapter. get_info( ) == adapter_report. info
98
+ } else {
99
+ true
100
+ } ) ;
101
+ let Some ( adapter) = adapter else {
102
+ panic!(
103
+ "Could not find adapter with info {:#?} in {:#?}" ,
104
+ adapter_report. map( |r| & r. info) ,
105
+ instance. enumerate_adapters( backends) . into_iter( ) . map( |a| a. get_info( ) ) . collect:: <Vec <_>>( ) ,
106
+ ) ;
107
+ } ;
90
108
} else {
91
- assert_eq!( adapter_index, 0 ) ;
92
109
let adapter = instance. request_adapter( & wgpu:: RequestAdapterOptions {
93
110
compatible_surface: surface. as_ref( ) ,
94
111
..Default :: default ( )
0 commit comments