1+ use crate :: buffer;
12use crate :: core:: { Color , Size , Transformation } ;
23use crate :: graphics:: backend;
34use crate :: graphics:: color;
@@ -30,6 +31,7 @@ pub struct Backend {
3031 pipeline_storage : pipeline:: Storage ,
3132 #[ cfg( any( feature = "image" , feature = "svg" ) ) ]
3233 image_pipeline : image:: Pipeline ,
34+ staging_belt : wgpu:: util:: StagingBelt ,
3335}
3436
3537impl Backend {
@@ -61,6 +63,13 @@ impl Backend {
6163
6264 #[ cfg( any( feature = "image" , feature = "svg" ) ) ]
6365 image_pipeline,
66+
67+ // TODO: Resize belt smartly (?)
68+ // It would be great if the `StagingBelt` API exposed methods
69+ // for introspection to detect when a resize may be worth it.
70+ staging_belt : wgpu:: util:: StagingBelt :: new (
71+ buffer:: MAX_WRITE_SIZE as u64 ,
72+ ) ,
6473 }
6574 }
6675
@@ -105,6 +114,8 @@ impl Backend {
105114 & layers,
106115 ) ;
107116
117+ self . staging_belt . finish ( ) ;
118+
108119 self . render (
109120 device,
110121 encoder,
@@ -123,12 +134,20 @@ impl Backend {
123134 self . image_pipeline . end_frame ( ) ;
124135 }
125136
137+ /// Recalls staging memory for future uploads.
138+ ///
139+ /// This method should be called after the command encoder
140+ /// has been submitted.
141+ pub fn recall ( & mut self ) {
142+ self . staging_belt . recall ( ) ;
143+ }
144+
126145 fn prepare (
127146 & mut self ,
128147 device : & wgpu:: Device ,
129148 queue : & wgpu:: Queue ,
130149 format : wgpu:: TextureFormat ,
131- _encoder : & mut wgpu:: CommandEncoder ,
150+ encoder : & mut wgpu:: CommandEncoder ,
132151 scale_factor : f32 ,
133152 target_size : Size < u32 > ,
134153 transformation : Transformation ,
@@ -144,7 +163,8 @@ impl Backend {
144163 if !layer. quads . is_empty ( ) {
145164 self . quad_pipeline . prepare (
146165 device,
147- queue,
166+ encoder,
167+ & mut self . staging_belt ,
148168 & layer. quads ,
149169 transformation,
150170 scale_factor,
@@ -157,7 +177,8 @@ impl Backend {
157177
158178 self . triangle_pipeline . prepare (
159179 device,
160- queue,
180+ encoder,
181+ & mut self . staging_belt ,
161182 & layer. meshes ,
162183 scaled,
163184 ) ;
@@ -171,8 +192,8 @@ impl Backend {
171192
172193 self . image_pipeline . prepare (
173194 device,
174- queue ,
175- _encoder ,
195+ encoder ,
196+ & mut self . staging_belt ,
176197 & layer. images ,
177198 scaled,
178199 scale_factor,
@@ -184,6 +205,7 @@ impl Backend {
184205 self . text_pipeline . prepare (
185206 device,
186207 queue,
208+ encoder,
187209 & layer. text ,
188210 layer. bounds ,
189211 scale_factor,
0 commit comments