@@ -5,18 +5,19 @@ fn main() {
55 extern crate wgpu_core as wgc;
66 extern crate wgpu_types as wgt;
77
8- use player:: GlobalPlay as _ ;
8+ use player:: Player ;
99 use wgc:: device:: trace;
10- use wgpu_core:: { command:: IdReferences , identity :: IdentityManager } ;
10+ use wgpu_core:: command:: PointerReferences ;
1111
1212 use std:: {
1313 fs,
1414 path:: { Path , PathBuf } ,
1515 process:: exit,
16+ sync:: Arc ,
1617 } ;
1718
18- #[ cfg( feature = "winit" ) ]
19- use raw_window_handle:: { HasDisplayHandle , HasWindowHandle } ;
19+ // #[cfg(feature = "winit")]
20+ // use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
2021 #[ cfg( feature = "winit" ) ]
2122 use winit:: {
2223 event:: KeyEvent ,
@@ -52,7 +53,7 @@ fn main() {
5253
5354 log:: info!( "Loading trace '{trace:?}'" ) ;
5455 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 ( ) ;
5657 actions. reverse ( ) ; // allows us to pop from the top
5758 log:: info!( "Found {} actions" , actions. len( ) ) ;
5859
@@ -68,11 +69,10 @@ fn main() {
6869 . build ( & event_loop)
6970 . unwrap ( ) ;
7071
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) ;
7574
75+ /*
7676 #[cfg(feature = "winit")]
7777 let surface = unsafe {
7878 global.instance_create_surface(
@@ -82,6 +82,7 @@ fn main() {
8282 )
8383 }
8484 .unwrap();
85+ */
8586
8687 let ( backends, device_desc) =
8788 match actions. pop_if ( |action| matches ! ( action, trace:: Action :: Init { .. } ) ) {
@@ -93,48 +94,43 @@ fn main() {
9394 None => ( wgt:: Backends :: all ( ) , wgt:: DeviceDescriptor :: default ( ) ) ,
9495 } ;
9596
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 ( ) ;
111113 log:: info!( "Using '{}'" , info. name) ;
112114
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 ( ) ;
119120
120121 log:: info!( "Executing actions" ) ;
121122 #[ cfg( not( feature = "winit" ) ) ]
122123 {
123- unsafe { global. device_start_graphics_debugger_capture ( device) } ;
124+ // unsafe { global.device_start_graphics_debugger_capture(device) };
124125
125126 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) ;
134128 }
135129
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 ( ) ;
138134 }
139135 #[ cfg( feature = "winit" ) ]
140136 {
@@ -168,33 +164,28 @@ fn main() {
168164 resize_config = Some ( config) ;
169165 target. exit ( ) ;
170166 } else {
167+ /*
171168 let error =
172169 global.surface_configure(surface, device, &config);
173170 if let Some(e) = error {
174171 panic!("{e:?}");
175172 }
173+ */
176174 }
177175 }
178- Some ( trace:: Action :: Present ( id ) ) => {
176+ Some ( trace:: Action :: Present ( _id ) ) => {
179177 frame_count += 1 ;
180178 log:: debug!( "Presenting frame {frame_count}" ) ;
181- global. surface_present ( id) . unwrap ( ) ;
179+ // global.surface_present(id).unwrap();
182180 target. exit ( ) ;
183181 }
184- Some ( trace:: Action :: DiscardSurfaceTexture ( id ) ) => {
182+ Some ( trace:: Action :: DiscardSurfaceTexture ( _id ) ) => {
185183 log:: debug!( "Discarding frame {frame_count}" ) ;
186- global. surface_texture_discard ( id) . unwrap ( ) ;
184+ // global.surface_texture_discard(id).unwrap();
187185 target. exit ( ) ;
188186 }
189187 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) ;
198189 }
199190 None => {
200191 if !done {
@@ -206,12 +197,14 @@ fn main() {
206197 }
207198 }
208199 WindowEvent :: Resized ( _) => {
200+ /*
209201 if let Some(config) = resize_config.take() {
210202 let error = global.surface_configure(surface, device, &config);
211203 if let Some(e) = error {
212204 panic!("{e:?}");
213205 }
214206 }
207+ */
215208 }
216209 WindowEvent :: KeyboardInput {
217210 event :
@@ -227,7 +220,9 @@ fn main() {
227220 } ,
228221 Event :: LoopExiting => {
229222 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 ( ) ;
231226 }
232227 _ => { }
233228 }
0 commit comments