@@ -17,7 +17,7 @@ use wgpu::{
17
17
PipelineStatisticsTypes , QuerySet , QuerySetDescriptor , QueryType , Queue , RenderPass ,
18
18
} ;
19
19
20
- use crate :: renderer:: RenderDevice ;
20
+ use crate :: renderer:: { RenderDevice , WgpuWrapper } ;
21
21
22
22
use super :: RecordDiagnostics ;
23
23
@@ -28,17 +28,19 @@ const MAX_PIPELINE_STATISTICS: u32 = 128;
28
28
const TIMESTAMP_SIZE : u64 = 8 ;
29
29
const PIPELINE_STATISTICS_SIZE : u64 = 40 ;
30
30
31
- /// Records diagnostics into [`QuerySet`]'s keeping track of the mapping between
32
- /// spans and indices to the corresponding entries in the [`QuerySet`].
33
- #[ derive( Resource ) ]
34
- pub struct DiagnosticsRecorder {
31
+ struct DiagnosticsRecorderInternal {
35
32
timestamp_period_ns : f32 ,
36
33
features : Features ,
37
34
current_frame : Mutex < FrameData > ,
38
35
submitted_frames : Vec < FrameData > ,
39
36
finished_frames : Vec < FrameData > ,
40
37
}
41
38
39
+ /// Records diagnostics into [`QuerySet`]'s keeping track of the mapping between
40
+ /// spans and indices to the corresponding entries in the [`QuerySet`].
41
+ #[ derive( Resource ) ]
42
+ pub struct DiagnosticsRecorder ( WgpuWrapper < DiagnosticsRecorderInternal > ) ;
43
+
42
44
impl DiagnosticsRecorder {
43
45
/// Creates the new `DiagnosticsRecorder`.
44
46
pub fn new ( device : & RenderDevice , queue : & Queue ) -> DiagnosticsRecorder {
@@ -50,30 +52,32 @@ impl DiagnosticsRecorder {
50
52
0.0
51
53
} ;
52
54
53
- DiagnosticsRecorder {
55
+ DiagnosticsRecorder ( WgpuWrapper :: new ( DiagnosticsRecorderInternal {
54
56
timestamp_period_ns,
55
57
features,
56
58
current_frame : Mutex :: new ( FrameData :: new ( device, features) ) ,
57
59
submitted_frames : Vec :: new ( ) ,
58
60
finished_frames : Vec :: new ( ) ,
59
- }
61
+ } ) )
60
62
}
61
63
62
64
fn current_frame_mut ( & mut self ) -> & mut FrameData {
63
- self . current_frame . get_mut ( ) . expect ( "lock poisoned" )
65
+ self . 0 . current_frame . get_mut ( ) . expect ( "lock poisoned" )
64
66
}
65
67
66
68
fn current_frame_lock ( & self ) -> impl DerefMut < Target = FrameData > + ' _ {
67
- self . current_frame . lock ( ) . expect ( "lock poisoned" )
69
+ self . 0 . current_frame . lock ( ) . expect ( "lock poisoned" )
68
70
}
69
71
70
72
/// Begins recording diagnostics for a new frame.
71
73
pub fn begin_frame ( & mut self ) {
74
+ let internal = & mut self . 0 ;
72
75
let mut idx = 0 ;
73
- while idx < self . submitted_frames . len ( ) {
74
- if self . submitted_frames [ idx] . run_mapped_callback ( self . timestamp_period_ns ) {
75
- self . finished_frames
76
- . push ( self . submitted_frames . swap_remove ( idx) ) ;
76
+ while idx < internal. submitted_frames . len ( ) {
77
+ let timestamp = internal. timestamp_period_ns ;
78
+ if internal. submitted_frames [ idx] . run_mapped_callback ( timestamp) {
79
+ let removed = internal. submitted_frames . swap_remove ( idx) ;
80
+ internal. finished_frames . push ( removed) ;
77
81
} else {
78
82
idx += 1 ;
79
83
}
@@ -100,16 +104,24 @@ impl DiagnosticsRecorder {
100
104
device : & RenderDevice ,
101
105
callback : impl FnOnce ( RenderDiagnostics ) + Send + Sync + ' static ,
102
106
) {
103
- self . current_frame_mut ( ) . finish ( callback) ;
107
+ let internal = & mut self . 0 ;
108
+ internal
109
+ . current_frame
110
+ . get_mut ( )
111
+ . expect ( "lock poisoned" )
112
+ . finish ( callback) ;
104
113
105
114
// reuse one of the finished frames, if we can
106
- let new_frame = match self . finished_frames . pop ( ) {
115
+ let new_frame = match internal . finished_frames . pop ( ) {
107
116
Some ( frame) => frame,
108
- None => FrameData :: new ( device, self . features ) ,
117
+ None => FrameData :: new ( device, internal . features ) ,
109
118
} ;
110
119
111
- let old_frame = std:: mem:: replace ( self . current_frame_mut ( ) , new_frame) ;
112
- self . submitted_frames . push ( old_frame) ;
120
+ let old_frame = std:: mem:: replace (
121
+ internal. current_frame . get_mut ( ) . expect ( "lock poisoned" ) ,
122
+ new_frame,
123
+ ) ;
124
+ internal. submitted_frames . push ( old_frame) ;
113
125
}
114
126
}
115
127
0 commit comments