@@ -5,14 +5,15 @@ 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
19
#[ cfg( feature = "winit" ) ]
@@ -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,17 +69,14 @@ 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
76
75
#[ cfg( feature = "winit" ) ]
77
76
let surface = unsafe {
78
- global . instance_create_surface (
77
+ instance . create_surface (
79
78
window. display_handle ( ) . unwrap ( ) . into ( ) ,
80
79
window. window_handle ( ) . unwrap ( ) . into ( ) ,
81
- Some ( wgc:: id:: Id :: zip ( 0 , 1 ) ) ,
82
80
)
83
81
}
84
82
. unwrap ( ) ;
@@ -93,50 +91,43 @@ fn main() {
93
91
None => ( wgt:: Backends :: all ( ) , wgt:: DeviceDescriptor :: default ( ) ) ,
94
92
} ;
95
93
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 ( ) ;
111
110
log:: info!( "Using '{}'" , info. name) ;
112
111
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 ( ) ;
119
117
120
118
log:: info!( "Executing actions" ) ;
121
119
#[ cfg( not( feature = "winit" ) ) ]
122
120
{
123
121
unsafe { global. device_start_graphics_debugger_capture ( device) } ;
124
122
125
123
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) ;
134
125
}
135
126
136
127
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 ( ) ;
140
131
}
141
132
#[ cfg( feature = "winit" ) ]
142
133
{
@@ -170,33 +161,25 @@ fn main() {
170
161
resize_config = Some ( config) ;
171
162
target. exit ( ) ;
172
163
} else {
173
- let error =
174
- global. surface_configure ( surface, device, & config) ;
164
+ let error = device. configure_surface ( & surface, & config) ;
175
165
if let Some ( e) = error {
176
166
panic ! ( "{e:?}" ) ;
177
167
}
178
168
}
179
169
}
180
- Some ( trace:: Action :: Present ( id ) ) => {
170
+ Some ( trace:: Action :: Present ( _id ) ) => {
181
171
frame_count += 1 ;
182
172
log:: debug!( "Presenting frame {frame_count}" ) ;
183
- global . surface_present ( id ) . unwrap ( ) ;
173
+ surface . present ( ) . unwrap ( ) ;
184
174
target. exit ( ) ;
185
175
}
186
- Some ( trace:: Action :: DiscardSurfaceTexture ( id ) ) => {
176
+ Some ( trace:: Action :: DiscardSurfaceTexture ( _id ) ) => {
187
177
log:: debug!( "Discarding frame {frame_count}" ) ;
188
- global . surface_texture_discard ( id ) . unwrap ( ) ;
178
+ surface . discard ( ) . unwrap ( ) ;
189
179
target. exit ( ) ;
190
180
}
191
181
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) ;
200
183
}
201
184
None => {
202
185
if !done {
@@ -209,7 +192,7 @@ fn main() {
209
192
}
210
193
WindowEvent :: Resized ( _) => {
211
194
if let Some ( config) = resize_config. take ( ) {
212
- let error = global . surface_configure ( surface, device , & config) ;
195
+ let error = device . configure_surface ( & surface, & config) ;
213
196
if let Some ( e) = error {
214
197
panic ! ( "{e:?}" ) ;
215
198
}
@@ -229,9 +212,10 @@ fn main() {
229
212
} ,
230
213
Event :: LoopExiting => {
231
214
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 ( ) ;
235
219
}
236
220
_ => { }
237
221
}
0 commit comments