@@ -5,14 +5,15 @@ 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
1819 #[ cfg( feature = "winit" ) ]
@@ -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,17 +69,14 @@ 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
7675 #[ cfg( feature = "winit" ) ]
7776 let surface = unsafe {
78- global . instance_create_surface (
77+ instance . create_surface (
7978 window. display_handle ( ) . unwrap ( ) . into ( ) ,
8079 window. window_handle ( ) . unwrap ( ) . into ( ) ,
81- Some ( wgc:: id:: Id :: zip ( 0 , 1 ) ) ,
8280 )
8381 }
8482 . unwrap ( ) ;
@@ -93,50 +91,43 @@ fn main() {
9391 None => ( wgt:: Backends :: all ( ) , wgt:: DeviceDescriptor :: default ( ) ) ,
9492 } ;
9593
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) ;
94+ let adapter = Arc :: new (
95+ instance
96+ . request_adapter (
97+ & wgt:: 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+ )
106+ . expect ( "Unable to obtain an adapter" ) ,
107+ ) ;
108+
109+ let info = adapter. get_info ( ) ;
111110 log:: info!( "Using '{}'" , info. name) ;
112111
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- }
112+ let ( device, queue) = adapter
113+ . create_device_and_queue ( & device_desc, instance_desc. flags )
114+ . unwrap ( ) ;
115+
116+ let mut player = Player :: default ( ) ;
119117
120118 log:: info!( "Executing actions" ) ;
121119 #[ cfg( not( feature = "winit" ) ) ]
122120 {
123121 unsafe { global. device_start_graphics_debugger_capture ( device) } ;
124122
125123 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- ) ;
124+ player. process ( & device, & queue, action, & dir) ;
134125 }
135126
136127 unsafe { global. device_stop_graphics_debugger_capture ( device) } ;
137- global
138- . device_poll ( device , wgt :: PollType :: wait_indefinitely ( ) )
139- . unwrap ( ) ;
128+ let ( user_closures , result ) = device . poll ( wgt :: PollType :: wait_indefinitely ( ) ) ;
129+ user_closures . fire ( ) ;
130+ result . unwrap ( ) ;
140131 }
141132 #[ cfg( feature = "winit" ) ]
142133 {
@@ -170,33 +161,25 @@ fn main() {
170161 resize_config = Some ( config) ;
171162 target. exit ( ) ;
172163 } else {
173- let error =
174- global. surface_configure ( surface, device, & config) ;
164+ let error = device. configure_surface ( & surface, & config) ;
175165 if let Some ( e) = error {
176166 panic ! ( "{e:?}" ) ;
177167 }
178168 }
179169 }
180- Some ( trace:: Action :: Present ( id ) ) => {
170+ Some ( trace:: Action :: Present ( _id ) ) => {
181171 frame_count += 1 ;
182172 log:: debug!( "Presenting frame {frame_count}" ) ;
183- global . surface_present ( id ) . unwrap ( ) ;
173+ surface . present ( ) . unwrap ( ) ;
184174 target. exit ( ) ;
185175 }
186- Some ( trace:: Action :: DiscardSurfaceTexture ( id ) ) => {
176+ Some ( trace:: Action :: DiscardSurfaceTexture ( _id ) ) => {
187177 log:: debug!( "Discarding frame {frame_count}" ) ;
188- global . surface_texture_discard ( id ) . unwrap ( ) ;
178+ surface . discard ( ) . unwrap ( ) ;
189179 target. exit ( ) ;
190180 }
191181 Some ( action) => {
192- global. process (
193- device,
194- queue,
195- action,
196- & dir,
197- & mut command_encoder_id_manager,
198- & mut command_buffer_id_manager,
199- ) ;
182+ player. process ( & device, & queue, action, & dir) ;
200183 }
201184 None => {
202185 if !done {
@@ -209,7 +192,7 @@ fn main() {
209192 }
210193 WindowEvent :: Resized ( _) => {
211194 if let Some ( config) = resize_config. take ( ) {
212- let error = global . surface_configure ( surface, device , & config) ;
195+ let error = device . configure_surface ( & surface, & config) ;
213196 if let Some ( e) = error {
214197 panic ! ( "{e:?}" ) ;
215198 }
@@ -229,9 +212,10 @@ fn main() {
229212 } ,
230213 Event :: LoopExiting => {
231214 log:: info!( "Closing" ) ;
232- global
233- . device_poll ( device, wgt:: PollType :: wait_indefinitely ( ) )
234- . unwrap ( ) ;
215+ let ( user_closures, result) =
216+ device. poll ( wgt:: PollType :: wait_indefinitely ( ) ) ;
217+ user_closures. fire ( ) ;
218+ result. unwrap ( ) ;
235219 }
236220 _ => { }
237221 }
0 commit comments