servo: Merge #13288 - Update webrender + shaders (from glennw:update-wr-lazy-shaders-scroll); r=pcwalton
authorGlenn Watson <github@intuitionlibrary.com>
Thu, 15 Sep 2016 20:23:30 -0500
changeset 339692 5eb97091e28d1933bc1df6137a1b65207534774c
parent 339691 8c37d635e5b41bbf32634077dcba35d3900087ef
child 339693 2d8819e94cb5f808abdae1477084d84f9dfd318c
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspcwalton
servo: Merge #13288 - Update webrender + shaders (from glennw:update-wr-lazy-shaders-scroll); r=pcwalton Source-Repo: https://github.com/servo/servo Source-Revision: 79dda5e8cb82b58a3cea8e6dbd2b6ab805f7b250
servo/components/servo/Cargo.lock
servo/components/servo/lib.rs
servo/components/util/opts.rs
servo/ports/cef/Cargo.lock
servo/resources/shaders/prim_shared.glsl
--- a/servo/components/servo/Cargo.lock
+++ b/servo/components/servo/Cargo.lock
@@ -2639,17 +2639,17 @@ dependencies = [
  "util 0.0.1",
  "uuid 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "webdriver 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "webrender"
 version = "0.5.1"
-source = "git+https://github.com/servo/webrender#db07ba36d02570b3fc70e9b31df7b09af3009abe"
+source = "git+https://github.com/servo/webrender#37dab545df3a9b6aa5e762f59272eb3d37227476"
 dependencies = [
  "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-graphics 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-text 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2664,17 +2664,17 @@ dependencies = [
  "rayon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
  "webrender_traits 0.5.1 (git+https://github.com/servo/webrender)",
 ]
 
 [[package]]
 name = "webrender_traits"
 version = "0.5.1"
-source = "git+https://github.com/servo/webrender#db07ba36d02570b3fc70e9b31df7b09af3009abe"
+source = "git+https://github.com/servo/webrender#37dab545df3a9b6aa5e762f59272eb3d37227476"
 dependencies = [
  "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-graphics 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
  "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
--- a/servo/components/servo/lib.rs
+++ b/servo/components/servo/lib.rs
@@ -151,16 +151,18 @@ impl<Window> Browser<Window> where Windo
                     webrender::Renderer::new(webrender::RendererOptions {
                         device_pixel_ratio: device_pixel_ratio,
                         resource_path: resource_path,
                         enable_aa: opts.enable_text_antialiasing,
                         enable_msaa: opts.use_msaa,
                         enable_profiler: opts.webrender_stats,
                         debug: opts.webrender_debug,
                         enable_recording: false,
+                        precache_shaders: opts.precache_shaders,
+                        enable_scrollbars: opts.output_file.is_none(),
                     });
                 (Some(webrender), Some(webrender_sender))
             } else {
                 (None, None)
             }
         } else {
             (None, None)
         };
--- a/servo/components/util/opts.rs
+++ b/servo/components/util/opts.rs
@@ -195,16 +195,21 @@ pub struct Opts {
     pub use_webrender: bool,
 
     /// True to show webrender profiling stats on screen.
     pub webrender_stats: bool,
 
     /// True to show webrender debug on screen.
     pub webrender_debug: bool,
 
+    /// True to compile all webrender shaders at init time. This is mostly
+    /// useful when modifying the shaders, to ensure they all compile
+    /// after each change is made.
+    pub precache_shaders: bool,
+
     /// True if WebRender should use multisample antialiasing.
     pub use_msaa: bool,
 
     /// Directory for a default config directory
     pub config_dir: Option<String>,
 
     // Which rendering API to use.
     pub render_api: RenderApi,
@@ -308,16 +313,20 @@ pub struct DebugOptions {
     pub webrender_debug: bool,
 
     /// Use multisample antialiasing in WebRender.
     pub use_msaa: bool,
 
     // don't skip any backtraces on panic
     pub full_backtraces: bool,
 
+    /// True to compile all webrender shaders at init time. This is mostly
+    /// useful when modifying the shaders, to ensure they all compile
+    /// after each change is made.
+    pub precache_shaders: bool,
 }
 
 
 impl DebugOptions {
     pub fn new(debug_string: &str) -> Result<DebugOptions, &str> {
         let mut debug_options = DebugOptions::default();
 
         for option in debug_string.split(',') {
@@ -346,16 +355,17 @@ impl DebugOptions {
                 "replace-surrogates" => debug_options.replace_surrogates = true,
                 "gc-profile" => debug_options.gc_profile = true,
                 "load-webfonts-synchronously" => debug_options.load_webfonts_synchronously = true,
                 "disable-vsync" => debug_options.disable_vsync = true,
                 "wr-stats" => debug_options.webrender_stats = true,
                 "wr-debug" => debug_options.webrender_debug = true,
                 "msaa" => debug_options.use_msaa = true,
                 "full-backtraces" => debug_options.full_backtraces = true,
+                "precache-shaders" => debug_options.precache_shaders = true,
                 "" => {},
                 _ => return Err(option)
             };
         };
 
         Ok(debug_options)
     }
 }
@@ -395,16 +405,17 @@ pub fn print_debug_usage(app: &str) -> !
     print_option("load-webfonts-synchronously",
                  "Load web fonts synchronously to avoid non-deterministic network-driven reflows");
     print_option("disable-vsync",
                  "Disable vsync mode in the compositor to allow profiling at more than monitor refresh rate");
     print_option("wr-stats", "Show WebRender profiler on screen.");
     print_option("msaa", "Use multisample antialiasing in WebRender.");
     print_option("full-backtraces", "Print full backtraces for all errors");
     print_option("wr-debug", "Display webrender tile borders. Must be used with -w option.");
+    print_option("precache-shaders", "Compile all shaders during init. Must be used with -w option.");
 
     println!("");
 
     process::exit(0)
 }
 
 #[derive(Clone)]
 #[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
@@ -532,16 +543,17 @@ pub fn default_opts() -> Opts {
         use_webrender: false,
         webrender_stats: false,
         use_msaa: false,
         render_api: DEFAULT_RENDER_API,
         config_dir: None,
         full_backtraces: false,
         is_printing_version: false,
         webrender_debug: false,
+        precache_shaders: false,
     }
 }
 
 pub fn from_cmdline_args(args: &[String]) -> ArgumentParsingResult {
     let (app_name, args) = args.split_first().unwrap();
 
     let mut opts = Options::new();
     opts.optflag("c", "cpu", "CPU painting (default)");
@@ -844,16 +856,17 @@ pub fn from_cmdline_args(args: &[String]
         enable_vsync: !debug_options.disable_vsync,
         use_webrender: use_webrender,
         webrender_stats: debug_options.webrender_stats,
         use_msaa: debug_options.use_msaa,
         config_dir: opt_match.opt_str("config-dir"),
         full_backtraces: debug_options.full_backtraces,
         is_printing_version: is_printing_version,
         webrender_debug: debug_options.webrender_debug,
+        precache_shaders: debug_options.precache_shaders,
     };
 
     set_defaults(opts);
 
     // These must happen after setting the default options, since the prefs rely on
     // on the resource path.
     // Note that command line preferences have the highest precedence
 
--- a/servo/ports/cef/Cargo.lock
+++ b/servo/ports/cef/Cargo.lock
@@ -2499,17 +2499,17 @@ dependencies = [
  "util 0.0.1",
  "uuid 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "webdriver 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "webrender"
 version = "0.5.1"
-source = "git+https://github.com/servo/webrender#db07ba36d02570b3fc70e9b31df7b09af3009abe"
+source = "git+https://github.com/servo/webrender#37dab545df3a9b6aa5e762f59272eb3d37227476"
 dependencies = [
  "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bincode 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-graphics 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-text 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -2524,17 +2524,17 @@ dependencies = [
  "rayon 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
  "webrender_traits 0.5.1 (git+https://github.com/servo/webrender)",
 ]
 
 [[package]]
 name = "webrender_traits"
 version = "0.5.1"
-source = "git+https://github.com/servo/webrender#db07ba36d02570b3fc70e9b31df7b09af3009abe"
+source = "git+https://github.com/servo/webrender#37dab545df3a9b6aa5e762f59272eb3d37227476"
 dependencies = [
  "app_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "core-graphics 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "euclid 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.2.22 (registry+https://github.com/rust-lang/crates.io-index)",
  "heapsize 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "ipc-channel 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
--- a/servo/resources/shaders/prim_shared.glsl
+++ b/servo/resources/shaders/prim_shared.glsl
@@ -25,42 +25,49 @@
 #define BORDER_STYLE_GROOVE       uint(6)
 #define BORDER_STYLE_RIDGE        uint(7)
 #define BORDER_STYLE_INSET        uint(8)
 #define BORDER_STYLE_OUTSET       uint(9)
 
 #define MAX_STOPS_PER_ANGLE_GRADIENT 8
 
 #ifdef WR_VERTEX_SHADER
+
+#define VECS_PER_LAYER      13
+#define LAYERS_PER_ROW      (WR_MAX_VERTEX_TEXTURE_WIDTH / VECS_PER_LAYER)
+
+#define VECS_PER_TILE       2
+#define TILES_PER_ROW       (WR_MAX_VERTEX_TEXTURE_WIDTH / VECS_PER_TILE)
+
 uniform sampler2D sLayers;
+uniform sampler2D sRenderTasks;
 
 struct Layer {
     mat4 transform;
     mat4 inv_transform;
     vec4 local_clip_rect;
     vec4 screen_vertices[4];
 };
 
 layout(std140) uniform Data {
     vec4 data[WR_MAX_UBO_VECTORS];
 };
 
-layout(std140) uniform Tiles {
-    vec4 tiles[WR_MAX_UBO_VECTORS];
-};
-
 Layer fetch_layer(int index) {
     Layer layer;
 
     // Create a UV base coord for each 8 texels.
     // This is required because trying to use an offset
     // of more than 8 texels doesn't work on some versions
     // of OSX.
-    ivec2 uv0 = ivec2(0, index);
-    ivec2 uv1 = ivec2(8, index);
+    int y = index / LAYERS_PER_ROW;
+    int x = VECS_PER_LAYER * (index % LAYERS_PER_ROW);
+
+    ivec2 uv0 = ivec2(x + 0, y);
+    ivec2 uv1 = ivec2(x + 8, y);
 
     layer.transform[0] = texelFetchOffset(sLayers, uv0, 0, ivec2(0, 0));
     layer.transform[1] = texelFetchOffset(sLayers, uv0, 0, ivec2(1, 0));
     layer.transform[2] = texelFetchOffset(sLayers, uv0, 0, ivec2(2, 0));
     layer.transform[3] = texelFetchOffset(sLayers, uv0, 0, ivec2(3, 0));
 
     layer.inv_transform[0] = texelFetchOffset(sLayers, uv0, 0, ivec2(4, 0));
     layer.inv_transform[1] = texelFetchOffset(sLayers, uv0, 0, ivec2(5, 0));
@@ -80,20 +87,23 @@ Layer fetch_layer(int index) {
 struct Tile {
     vec4 actual_rect;
     vec4 target_rect;
 };
 
 Tile fetch_tile(int index) {
     Tile tile;
 
-    int offset = index * 2;
+    int y = index / TILES_PER_ROW;
+    int x = VECS_PER_TILE * (index % TILES_PER_ROW);
 
-    tile.actual_rect = tiles[offset + 0];
-    tile.target_rect = tiles[offset + 1];
+    ivec2 uv = ivec2(x + 0, y);
+
+    tile.actual_rect = texelFetchOffset(sRenderTasks, uv, 0, ivec2(0, 0));
+    tile.target_rect = texelFetchOffset(sRenderTasks, uv, 0, ivec2(1, 0));
 
     return tile;
 }
 
 struct PrimitiveInfo {
     vec4 layer_tile;
     vec4 local_clip_rect;
     vec4 local_rect;