@@ -5,18 +5,19 @@ fn main() {
5
5
extern crate wgpu_core as wgc;
6
6
extern crate wgpu_types as wgt;
7
7
8
- use player:: GlobalPlay as _ ;
8
+ use player:: Player ;
9
9
use wgc:: device:: trace;
10
- use wgpu_core:: { command:: IdReferences , identity :: IdentityManager } ;
10
+ use wgpu_core:: command:: PointerReferences ;
11
11
12
12
use std:: {
13
13
fs,
14
14
path:: { Path , PathBuf } ,
15
15
process:: exit,
16
+ sync:: Arc ,
16
17
} ;
17
18
18
- #[ cfg( feature = "winit" ) ]
19
- use raw_window_handle:: { HasDisplayHandle , HasWindowHandle } ;
19
+ // #[cfg(feature = "winit")]
20
+ // use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
20
21
#[ cfg( feature = "winit" ) ]
21
22
use winit:: {
22
23
event:: KeyEvent ,
@@ -52,7 +53,7 @@ fn main() {
52
53
53
54
log:: info!( "Loading trace '{trace:?}'" ) ;
54
55
let file = fs:: File :: open ( trace) . unwrap ( ) ;
55
- let mut actions: Vec < trace:: Action < IdReferences > > = ron:: de:: from_reader ( file) . unwrap ( ) ;
56
+ let mut actions: Vec < trace:: Action < PointerReferences > > = ron:: de:: from_reader ( file) . unwrap ( ) ;
56
57
actions. reverse ( ) ; // allows us to pop from the top
57
58
log:: info!( "Found {} actions" , actions. len( ) ) ;
58
59
@@ -68,11 +69,10 @@ fn main() {
68
69
. build ( & event_loop)
69
70
. unwrap ( ) ;
70
71
71
- let global =
72
- wgc:: global:: Global :: new ( "player" , & wgt:: InstanceDescriptor :: from_env_or_default ( ) ) ;
73
- let mut command_encoder_id_manager = IdentityManager :: new ( ) ;
74
- let mut command_buffer_id_manager = IdentityManager :: new ( ) ;
72
+ let instance_desc = wgt:: InstanceDescriptor :: from_env_or_default ( ) ;
73
+ let instance = wgc:: instance:: Instance :: new ( "player" , & instance_desc) ;
75
74
75
+ /*
76
76
#[cfg(feature = "winit")]
77
77
let surface = unsafe {
78
78
global.instance_create_surface(
@@ -82,6 +82,7 @@ fn main() {
82
82
)
83
83
}
84
84
.unwrap();
85
+ */
85
86
86
87
let ( backends, device_desc) =
87
88
match actions. pop_if ( |action| matches ! ( action, trace:: Action :: Init { .. } ) ) {
@@ -93,48 +94,43 @@ fn main() {
93
94
None => ( wgt:: Backends :: all ( ) , wgt:: DeviceDescriptor :: default ( ) ) ,
94
95
} ;
95
96
96
- let adapter = global
97
- . request_adapter (
98
- & wgc:: instance:: RequestAdapterOptions {
99
- #[ cfg( feature = "winit" ) ]
100
- compatible_surface : Some ( surface) ,
101
- #[ cfg( not( feature = "winit" ) ) ]
102
- compatible_surface : None ,
103
- ..Default :: default ( )
104
- } ,
105
- backends,
106
- Some ( wgc:: id:: AdapterId :: zip ( 0 , 1 ) ) ,
107
- )
108
- . expect ( "Unable to obtain an adapter" ) ;
109
-
110
- let info = global. adapter_get_info ( adapter) ;
97
+ let adapter = Arc :: new (
98
+ instance
99
+ . request_adapter (
100
+ & wgt:: RequestAdapterOptions {
101
+ //#[cfg(feature = "winit")]
102
+ //compatible_surface: Some(surface),
103
+ //#[cfg(not(feature = "winit"))]
104
+ compatible_surface : None ,
105
+ ..Default :: default ( )
106
+ } ,
107
+ backends,
108
+ )
109
+ . expect ( "Unable to obtain an adapter" ) ,
110
+ ) ;
111
+
112
+ let info = adapter. get_info ( ) ;
111
113
log:: info!( "Using '{}'" , info. name) ;
112
114
113
- let device = wgc:: id:: Id :: zip ( 0 , 1 ) ;
114
- let queue = wgc:: id:: Id :: zip ( 0 , 1 ) ;
115
- let res = global. adapter_request_device ( adapter, & device_desc, Some ( device) , Some ( queue) ) ;
116
- if let Err ( e) = res {
117
- panic ! ( "{e:?}" ) ;
118
- }
115
+ let ( device, queue) = adapter
116
+ . create_device_and_queue ( & device_desc, instance_desc. flags )
117
+ . unwrap ( ) ;
118
+
119
+ let mut player = Player :: new ( ) ;
119
120
120
121
log:: info!( "Executing actions" ) ;
121
122
#[ cfg( not( feature = "winit" ) ) ]
122
123
{
123
- unsafe { global. device_start_graphics_debugger_capture ( device) } ;
124
+ // unsafe { global.device_start_graphics_debugger_capture(device) };
124
125
125
126
while let Some ( action) = actions. pop ( ) {
126
- global. process (
127
- device,
128
- queue,
129
- action,
130
- & dir,
131
- & mut command_encoder_id_manager,
132
- & mut command_buffer_id_manager,
133
- ) ;
127
+ player. process ( & device, & queue, action, & dir) ;
134
128
}
135
129
136
- unsafe { global. device_stop_graphics_debugger_capture ( device) } ;
137
- global. device_poll ( device, wgt:: PollType :: wait ( ) ) . unwrap ( ) ;
130
+ //unsafe { global.device_stop_graphics_debugger_capture(device) };
131
+ let ( user_closures, result) = device. poll ( wgt:: PollType :: wait ( ) ) ;
132
+ user_closures. fire ( ) ;
133
+ result. unwrap ( ) ;
138
134
}
139
135
#[ cfg( feature = "winit" ) ]
140
136
{
@@ -168,33 +164,28 @@ fn main() {
168
164
resize_config = Some ( config) ;
169
165
target. exit ( ) ;
170
166
} else {
167
+ /*
171
168
let error =
172
169
global.surface_configure(surface, device, &config);
173
170
if let Some(e) = error {
174
171
panic!("{e:?}");
175
172
}
173
+ */
176
174
}
177
175
}
178
- Some ( trace:: Action :: Present ( id ) ) => {
176
+ Some ( trace:: Action :: Present ( _id ) ) => {
179
177
frame_count += 1 ;
180
178
log:: debug!( "Presenting frame {frame_count}" ) ;
181
- global. surface_present ( id) . unwrap ( ) ;
179
+ // global.surface_present(id).unwrap();
182
180
target. exit ( ) ;
183
181
}
184
- Some ( trace:: Action :: DiscardSurfaceTexture ( id ) ) => {
182
+ Some ( trace:: Action :: DiscardSurfaceTexture ( _id ) ) => {
185
183
log:: debug!( "Discarding frame {frame_count}" ) ;
186
- global. surface_texture_discard ( id) . unwrap ( ) ;
184
+ // global.surface_texture_discard(id).unwrap();
187
185
target. exit ( ) ;
188
186
}
189
187
Some ( action) => {
190
- global. process (
191
- device,
192
- queue,
193
- action,
194
- & dir,
195
- & mut command_encoder_id_manager,
196
- & mut command_buffer_id_manager,
197
- ) ;
188
+ player. process ( & device, & queue, action, & dir) ;
198
189
}
199
190
None => {
200
191
if !done {
@@ -206,12 +197,14 @@ fn main() {
206
197
}
207
198
}
208
199
WindowEvent :: Resized ( _) => {
200
+ /*
209
201
if let Some(config) = resize_config.take() {
210
202
let error = global.surface_configure(surface, device, &config);
211
203
if let Some(e) = error {
212
204
panic!("{e:?}");
213
205
}
214
206
}
207
+ */
215
208
}
216
209
WindowEvent :: KeyboardInput {
217
210
event :
@@ -227,7 +220,9 @@ fn main() {
227
220
} ,
228
221
Event :: LoopExiting => {
229
222
log:: info!( "Closing" ) ;
230
- global. device_poll ( device, wgt:: PollType :: wait ( ) ) . unwrap ( ) ;
223
+ let ( user_closures, result) = device. poll ( wgt:: PollType :: wait ( ) ) ;
224
+ user_closures. fire ( ) ;
225
+ result. unwrap ( ) ;
231
226
}
232
227
_ => { }
233
228
}
0 commit comments