@@ -12,6 +12,7 @@ fn main() {
12
12
use std:: {
13
13
fs,
14
14
path:: { Path , PathBuf } ,
15
+ process:: exit,
15
16
} ;
16
17
17
18
#[ cfg( feature = "winit" ) ]
@@ -29,13 +30,28 @@ fn main() {
29
30
//TODO: setting for the backend bits
30
31
//TODO: setting for the target frame, or controls
31
32
32
- let dir = match std:: env:: args ( ) . nth ( 1 ) {
33
- Some ( arg) if Path :: new ( & arg) . is_dir ( ) => PathBuf :: from ( arg) ,
34
- _ => panic ! ( "Provide the dir path as the parameter" ) ,
33
+ const HELP : & str = "\
34
+ Usage: play <trace directory> | <trace file>\n \
35
+ \n \
36
+ Play a wgpu trace from the specified file or directory. If the trace contains\n \
37
+ buffers, textures, or shaders, the directory form must be used.\n ";
38
+
39
+ let ( dir, trace) = match std:: env:: args ( ) . nth ( 1 ) {
40
+ Some ( arg) if Path :: new ( & arg) . is_dir ( ) => (
41
+ PathBuf :: from ( arg. clone ( ) ) ,
42
+ PathBuf :: from ( arg) . join ( trace:: FILE_NAME ) ,
43
+ ) ,
44
+ Some ( arg) if Path :: new ( & arg) . is_file ( ) => {
45
+ ( PathBuf :: from ( "/nonexistent" ) , PathBuf :: from ( arg) )
46
+ }
47
+ _ => {
48
+ eprintln ! ( "{HELP}" ) ;
49
+ exit ( 1 ) ;
50
+ }
35
51
} ;
36
52
37
- log:: info!( "Loading trace '{dir :?}'" ) ;
38
- let file = fs:: File :: open ( dir . join ( trace:: FILE_NAME ) ) . unwrap ( ) ;
53
+ log:: info!( "Loading trace '{trace :?}'" ) ;
54
+ let file = fs:: File :: open ( trace) . unwrap ( ) ;
39
55
let mut actions: Vec < trace:: Action > = ron:: de:: from_reader ( file) . unwrap ( ) ;
40
56
actions. reverse ( ) ; // allows us to pop from the top
41
57
log:: info!( "Found {} actions" , actions. len( ) ) ;
@@ -66,37 +82,39 @@ fn main() {
66
82
}
67
83
. unwrap ( ) ;
68
84
69
- let ( device, queue) = match actions. pop ( ) {
70
- Some ( trace:: Action :: Init { desc, backend } ) => {
71
- log:: info!( "Initializing the device for backend: {backend:?}" ) ;
72
- let adapter = global
73
- . request_adapter (
74
- & wgc:: instance:: RequestAdapterOptions {
75
- power_preference : wgt:: PowerPreference :: None ,
76
- force_fallback_adapter : false ,
77
- #[ cfg( feature = "winit" ) ]
78
- compatible_surface : Some ( surface) ,
79
- #[ cfg( not( feature = "winit" ) ) ]
80
- compatible_surface : None ,
81
- } ,
82
- wgt:: Backends :: from ( backend) ,
83
- Some ( wgc:: id:: AdapterId :: zip ( 0 , 1 ) ) ,
84
- )
85
- . expect ( "Unable to find an adapter for selected backend" ) ;
86
-
87
- let info = global. adapter_get_info ( adapter) ;
88
- log:: info!( "Picked '{}'" , info. name) ;
89
- let device_id = wgc:: id:: Id :: zip ( 0 , 1 ) ;
90
- let queue_id = wgc:: id:: Id :: zip ( 0 , 1 ) ;
91
- let res =
92
- global. adapter_request_device ( adapter, & desc, Some ( device_id) , Some ( queue_id) ) ;
93
- if let Err ( e) = res {
94
- panic ! ( "{e:?}" ) ;
85
+ let ( backends, device_desc) =
86
+ match actions. pop_if ( |action| matches ! ( action, trace:: Action :: Init { .. } ) ) {
87
+ Some ( trace:: Action :: Init { desc, backend } ) => {
88
+ log:: info!( "Initializing the device for backend: {backend:?}" ) ;
89
+ ( wgt:: Backends :: from ( backend) , desc)
95
90
}
96
- ( device_id, queue_id)
97
- }
98
- _ => panic ! ( "Expected Action::Init" ) ,
99
- } ;
91
+ Some ( _) => unreachable ! ( ) ,
92
+ None => ( wgt:: Backends :: all ( ) , wgt:: DeviceDescriptor :: default ( ) ) ,
93
+ } ;
94
+
95
+ let adapter = global
96
+ . request_adapter (
97
+ & wgc:: instance:: RequestAdapterOptions {
98
+ #[ cfg( feature = "winit" ) ]
99
+ compatible_surface : Some ( surface) ,
100
+ #[ cfg( not( feature = "winit" ) ) ]
101
+ compatible_surface : None ,
102
+ ..Default :: default ( )
103
+ } ,
104
+ backends,
105
+ Some ( wgc:: id:: AdapterId :: zip ( 0 , 1 ) ) ,
106
+ )
107
+ . expect ( "Unable to obtain an adapter" ) ;
108
+
109
+ let info = global. adapter_get_info ( adapter) ;
110
+ log:: info!( "Using '{}'" , info. name) ;
111
+
112
+ let device = wgc:: id:: Id :: zip ( 0 , 1 ) ;
113
+ let queue = wgc:: id:: Id :: zip ( 0 , 1 ) ;
114
+ let res = global. adapter_request_device ( adapter, & device_desc, Some ( device) , Some ( queue) ) ;
115
+ if let Err ( e) = res {
116
+ panic ! ( "{e:?}" ) ;
117
+ }
100
118
101
119
log:: info!( "Executing actions" ) ;
102
120
#[ cfg( not( feature = "winit" ) ) ]
0 commit comments