Bug 1441308 - Map document layers to z ranges r=gw
☠☠ backed out by 699a6b6bee44 ☠ ☠
authorDoug Thayer <dothayer@mozilla.com>
Thu, 21 Mar 2019 23:15:23 +0000
changeset 465588 d8b4d6ec9b40
parent 465587 e2f83e4816dd
child 465589 32f7793dfd1a
push id81167
push userdothayer@mozilla.com
push dateFri, 22 Mar 2019 06:31:43 +0000
treeherderautoland@1764701d11d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgw
bugs1441308
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 1441308 - Map document layers to z ranges r=gw As discussed in IRC. AFAICT the ORTHO_NEAR|FAR_PLANE should match up with the ranges of valid ZBufferIds, but please double-check me. Differential Revision: https://phabricator.services.mozilla.com/D23599
gfx/wr/webrender/src/frame_builder.rs
gfx/wr/webrender/src/gpu_types.rs
gfx/wr/webrender/src/internal_types.rs
--- a/gfx/wr/webrender/src/frame_builder.rs
+++ b/gfx/wr/webrender/src/frame_builder.rs
@@ -607,17 +607,17 @@ impl FrameBuilder {
                     output_size,
                     &mut passes,
                     self.config.gpu_supports_fast_clears,
                 );
                 passes[passes_start..].reverse();
             }
 
             // Used to generated a unique z-buffer value per primitive.
-            let mut z_generator = ZBufferIdGenerator::new();
+            let mut z_generator = ZBufferIdGenerator::new(layer);
             let use_dual_source_blending = self.config.dual_source_blending_is_enabled &&
                                            self.config.dual_source_blending_is_supported;
 
             for pass in &mut passes {
                 let mut ctx = RenderTargetContext {
                     global_device_pixel_scale,
                     prim_store: &self.prim_store,
                     resource_cache,
--- a/gfx/wr/webrender/src/gpu_types.rs
+++ b/gfx/wr/webrender/src/gpu_types.rs
@@ -1,13 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-use api::PremultipliedColorF;
+use api::{DocumentLayer, PremultipliedColorF};
 use api::units::*;
 use clip_scroll_tree::{ClipScrollTree, ROOT_SPATIAL_NODE_INDEX, SpatialNodeIndex};
 use gpu_cache::{GpuCacheAddress, GpuDataRequest};
 use internal_types::FastHashMap;
 use prim_store::EdgeAaSegmentMask;
 use render_task::RenderTaskAddress;
 use std::i32;
 use util::{TransformedRectKind, MatrixHelpers};
@@ -17,38 +17,52 @@ use util::{TransformedRectKind, MatrixHe
 pub const VECS_PER_TRANSFORM: usize = 8;
 
 #[derive(Copy, Clone, Debug, PartialEq)]
 #[repr(C)]
 #[cfg_attr(feature = "capture", derive(Serialize))]
 #[cfg_attr(feature = "replay", derive(Deserialize))]
 pub struct ZBufferId(i32);
 
+// We get 24 bits of Z value - use up 22 bits of it to give us
+// 4 bits to account for GPU issues. This seems to manifest on
+// some GPUs under certain perspectives due to z interpolation
+// precision problems.
+const MAX_DOCUMENT_LAYERS : i8 = 1 << 3;
+const MAX_ITEMS_PER_DOCUMENT_LAYER : i32 = 1 << 19;
+const MAX_DOCUMENT_LAYER_VALUE : i8 = MAX_DOCUMENT_LAYERS / 2 - 1;
+const MIN_DOCUMENT_LAYER_VALUE : i8 = -MAX_DOCUMENT_LAYERS / 2;
+
 impl ZBufferId {
     pub fn invalid() -> Self {
         ZBufferId(i32::MAX)
     }
 }
 
 #[derive(Debug)]
 #[cfg_attr(feature = "capture", derive(Serialize))]
 #[cfg_attr(feature = "replay", derive(Deserialize))]
 pub struct ZBufferIdGenerator {
+    base: i32,
     next: i32,
 }
 
 impl ZBufferIdGenerator {
-    pub fn new() -> Self {
+    pub fn new(layer: DocumentLayer) -> Self {
+        debug_assert!(layer >= MIN_DOCUMENT_LAYER_VALUE);
+        debug_assert!(layer <= MAX_DOCUMENT_LAYER_VALUE);
         ZBufferIdGenerator {
+            base: layer as i32 * MAX_ITEMS_PER_DOCUMENT_LAYER,
             next: 0
         }
     }
 
     pub fn next(&mut self) -> ZBufferId {
-        let id = ZBufferId(self.next);
+        debug_assert!(self.next < MAX_ITEMS_PER_DOCUMENT_LAYER);
+        let id = ZBufferId(self.next + self.base);
         self.next += 1;
         id
     }
 }
 
 #[derive(Debug, Copy, Clone)]
 #[cfg_attr(feature = "capture", derive(Serialize))]
 #[cfg_attr(feature = "replay", derive(Deserialize))]
--- a/gfx/wr/webrender/src/internal_types.rs
+++ b/gfx/wr/webrender/src/internal_types.rs
@@ -87,18 +87,20 @@ pub enum TextureSource {
     /// The color target of the immediately-preceding pass.
     PrevPassColor,
     /// A render target from an earlier pass. Unlike the immediately-preceding
     /// passes, these are not made available automatically, but are instead
     /// opt-in by the `RenderTask` (see `mark_for_saving()`).
     RenderTaskCache(SavedTargetIndex),
 }
 
-pub const ORTHO_NEAR_PLANE: f32 = -100000.0;
-pub const ORTHO_FAR_PLANE: f32 = 100000.0;
+// See gpu_types.rs where we declare the number of possible documents and
+// number of items per document. This should match up with that.
+pub const ORTHO_NEAR_PLANE: f32 = -(1 << 22) as f32;
+pub const ORTHO_FAR_PLANE: f32 = ((1 << 22) - 1) as f32;
 
 #[derive(Copy, Clone, Debug, PartialEq)]
 #[cfg_attr(feature = "capture", derive(Serialize))]
 #[cfg_attr(feature = "replay", derive(Deserialize))]
 pub struct RenderTargetInfo {
     pub has_depth: bool,
 }