Bug 1541078 - Add pre/post frames hooks into save_capture r=kvark
authorDoug Thayer <dothayer@mozilla.com>
Mon, 06 May 2019 17:21:22 +0000
changeset 531539 f53e8b390527be63434af20acb36b2012829c982
parent 531538 d4a4c9ad62fd31f0830763c7a46ebfd4d1f40301
child 531540 2547daf183e553ec60d8cb5ccbfb47358a17fb4d
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskvark
bugs1541078
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1541078 - Add pre/post frames hooks into save_capture r=kvark There's two ways we could get around this. We could add a path around the prepared_for_frames assertion in GpuCache::end_frame, or we can do this, and leave the TODO explicit with the assertion. I took the latter approach because we can clear the GpuCache / TextureCache through other routes than frame building anyway, so we could hit this failure path before any of the patches in this bug landed. Differential Revision: https://phabricator.services.mozilla.com/D29884
gfx/wr/webrender/src/gpu_cache.rs
gfx/wr/webrender/src/render_backend.rs
--- a/gfx/wr/webrender/src/gpu_cache.rs
+++ b/gfx/wr/webrender/src/gpu_cache.rs
@@ -723,16 +723,17 @@ impl GpuCache {
     /// Creates a GpuCache and sets it up with a valid `FrameStamp`, which
     /// is useful for avoiding panics when instantiating the `GpuCache`
     /// directly from unit test code.
     #[cfg(test)]
     pub fn new_for_testing() -> Self {
         let mut cache = Self::new();
         let mut now = FrameStamp::first(DocumentId::new(IdNamespace(1), 1));
         now.advance();
+        cache.prepared_for_frames = true;
         cache.begin_frame(now);
         cache
     }
 
     /// Drops everything in the GPU cache. Must not be called once gpu cache entries
     /// for the next frame have already been requested.
     pub fn clear(&mut self) {
         assert!(self.texture.updates.is_empty(), "Clearing with pending updates");
--- a/gfx/wr/webrender/src/render_backend.rs
+++ b/gfx/wr/webrender/src/render_backend.rs
@@ -1660,16 +1660,20 @@ impl RenderBackend {
         debug!("capture: saving {:?}", root);
         if !root.is_dir() {
             if let Err(e) = fs::create_dir_all(&root) {
                 panic!("Unable to create capture dir: {:?}", e);
             }
         }
         let config = CaptureConfig::new(root, bits);
 
+        if config.bits.contains(CaptureBits::FRAME) {
+            self.prepare_for_frames();
+        }
+
         for (&id, doc) in &mut self.documents {
             debug!("\tdocument {:?}", id);
             if config.bits.contains(CaptureBits::SCENE) {
                 let file_name = format!("scene-{}-{}", id.namespace_id.0, id.id);
                 config.serialize(&doc.scene, file_name);
             }
             if config.bits.contains(CaptureBits::FRAME) {
                 let rendered_document = doc.build_frame(
@@ -1701,16 +1705,24 @@ impl RenderBackend {
                     &mut svg_file
                 ).unwrap();
             }
 
             let data_stores_name = format!("data-stores-{}-{}", id.namespace_id.0, id.id);
             config.serialize(&doc.data_stores, data_stores_name);
         }
 
+        if config.bits.contains(CaptureBits::FRAME) {
+            // TODO: there is no guarantee that we won't hit this case, but we want to
+            // report it here if we do. If we don't, it will simply crash in
+            // Renderer::render_impl and give us less information about the source.
+            assert!(!self.requires_frame_build(), "Caches were cleared during a capture.");
+            self.bookkeep_after_frames();
+        }
+
         debug!("\tscene builder");
         self.scene_tx.send(SceneBuilderRequest::SaveScene(config.clone())).unwrap();
 
         debug!("\tresource cache");
         let (resources, deferred) = self.resource_cache.save_capture(&config.root);
 
         info!("\tbackend");
         let backend = PlainRenderBackend {