Bug 1624396 - update SWGL to use the centralized WR shader list. r=jrmuizel
authorLee Salzman <lsalzman@mozilla.com>
Tue, 24 Mar 2020 19:13:49 +0000
changeset 520296 72cbbe719b5d526b950d77691d36c234d21395fe
parent 520295 178ba8ef059cb90937f458692617a660bc961562
child 520297 86954fd812617a5b7e5d3e4182184c44b3bb0a33
push id37246
push useropoprus@mozilla.com
push dateWed, 25 Mar 2020 03:40:33 +0000
treeherdermozilla-central@14b59d4adc95 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1624396
milestone76.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 1624396 - update SWGL to use the centralized WR shader list. r=jrmuizel Depends on D67958 Differential Revision: https://phabricator.services.mozilla.com/D67959
Cargo.lock
gfx/wr/Cargo.lock
gfx/wr/swgl/Cargo.toml
gfx/wr/swgl/build.rs
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4178,16 +4178,17 @@ checksum = "c666f0fed8e1e20e057af770af90
 
 [[package]]
 name = "swgl"
 version = "0.1.0"
 dependencies = [
  "cc",
  "gleam",
  "glsl-to-cxx",
+ "webrender_build",
 ]
 
 [[package]]
 name = "syn"
 version = "1.0.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf"
 dependencies = [
--- a/gfx/wr/Cargo.lock
+++ b/gfx/wr/Cargo.lock
@@ -1537,16 +1537,17 @@ source = "registry+https://github.com/ru
 
 [[package]]
 name = "swgl"
 version = "0.1.0"
 dependencies = [
  "cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
  "gleam 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "glsl-to-cxx 0.1.0",
+ "webrender_build 0.0.1",
 ]
 
 [[package]]
 name = "syn"
 version = "0.15.30"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "proc-macro2 0.4.25 (registry+https://github.com/rust-lang/crates.io-index)",
--- a/gfx/wr/swgl/Cargo.toml
+++ b/gfx/wr/swgl/Cargo.toml
@@ -4,11 +4,12 @@ version = "0.1.0"
 license = "MPL-2.0"
 authors = ["The Mozilla Project Developers"]
 build = "build.rs"
 description = "Software OpenGL implementation for WebRender."
 
 [build-dependencies]
 cc = "1.0.46"
 glsl-to-cxx = { path = "../glsl-to-cxx" }
+webrender_build = { path = "../webrender_build" }
 
 [dependencies]
 gleam = "0.10.0"
--- a/gfx/wr/swgl/build.rs
+++ b/gfx/wr/swgl/build.rs
@@ -1,20 +1,22 @@
 /* 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/. */
 
 extern crate cc;
 extern crate glsl_to_cxx;
+extern crate webrender_build;
 
 use std::collections::HashSet;
 use std::fmt::Write;
+use webrender_build::shader::{ShaderFeatureFlags, get_shader_features};
 
-fn write_load_shader(shader_keys: &[&str]) {
-    let shaders: Vec<_> = shader_keys.iter().map(|s| s.replace(':', "_")).collect();
+fn write_load_shader(shader_keys: &[String]) {
+    let shaders: Vec<_> = shader_keys.iter().map(|s| s.replace(',', "_")).collect();
     let mut load_shader = String::new();
     for s in &shaders {
         let _ = write!(load_shader, "#include \"{}.h\"\n", s);
     }
     load_shader.push_str("ProgramLoader load_shader(const char* name) {\n");
     for s in &shaders {
         let _ = write!(load_shader, "  if (!strcmp(name, \"{0}\")) {{ return {0}_program::loader; }}\n", s);
     }
@@ -43,25 +45,25 @@ fn process_imports(shader_dir: &str, sha
     }
 }
 
 fn translate_shader(shader_key: &str, shader_dir: &str) {
     let mut imported = String::new();
     imported.push_str("#define SWGL 1\n");
     imported.push_str("#define WR_MAX_VERTEX_TEXTURE_WIDTH 1024U\n");
 
-    let mut features = shader_key.split(':');
+    let mut features = shader_key.split(',');
     let basename = features.next().unwrap();
     for feature in features {
         let _ = write!(imported, "#define WR_FEATURE_{}\n", feature);
     }
 
     process_imports(shader_dir, basename, &mut HashSet::new(), &mut imported);
 
-    let shader = shader_key.replace(':', "_");
+    let shader = shader_key.replace(',', "_");
 
     let out_dir = std::env::var("OUT_DIR").unwrap();
     let imp_name = format!("{}/{}.c", out_dir, shader);
     std::fs::write(&imp_name, imported).unwrap();
 
     let mut build = cc::Build::new();
     if build.get_compiler().is_like_msvc() {
         build.flag("/EP");
@@ -89,78 +91,37 @@ fn translate_shader(shader_key: &str, sh
     if std::path::Path::new(&frag_include).exists() {
         println!("cargo:rerun-if-changed={}/{}.frag.h", shader_dir, shader);
         args.push(frag_include);
     }
     let result = glsl_to_cxx::translate(&mut args.into_iter());
     std::fs::write(format!("{}/{}.h", out_dir, shader), result).unwrap();
 }
 
-const WR_SHADERS: &'static [&'static str] = &[
-    "brush_blend:ALPHA_PASS",
-    "brush_blend",
-    "brush_image:ALPHA_PASS",
-    "brush_image",
-    "brush_image:REPETITION:ANTIALIASING:ALPHA_PASS",
-    "brush_image:REPETITION:ANTIALIASING",
-    "brush_linear_gradient:ALPHA_PASS",
-    "brush_linear_gradient:DITHERING:ALPHA_PASS",
-    "brush_linear_gradient:DITHERING",
-    "brush_linear_gradient",
-    "brush_mix_blend:ALPHA_PASS",
-    "brush_mix_blend",
-    "brush_opacity:ALPHA_PASS",
-    "brush_radial_gradient:ALPHA_PASS",
-    "brush_radial_gradient:DITHERING:ALPHA_PASS",
-    "brush_radial_gradient:DITHERING",
-    "brush_radial_gradient",
-    "brush_solid:ALPHA_PASS",
-    "brush_solid",
-    "brush_yuv_image",
-    "brush_yuv_image:TEXTURE_2D:YUV:NV12",
-    "brush_yuv_image:YUV",
-    "brush_yuv_image:YUV:ALPHA_PASS",
-    "brush_yuv_image:YUV:INTERLEAVED",
-    "brush_yuv_image:YUV:NV12:ALPHA_PASS",
-    "brush_yuv_image:YUV:NV12",
-    "brush_yuv_image:YUV:PLANAR",
-    "composite",
-    "composite:YUV",
-    "cs_blur:ALPHA_TARGET",
-    "cs_blur:COLOR_TARGET",
-    "cs_border_segment",
-    "cs_border_solid",
-    "cs_clip_box_shadow",
-    "cs_clip_image",
-    "cs_clip_rectangle:FAST_PATH",
-    "cs_clip_rectangle",
-    "cs_gradient",
-    "cs_line_decoration",
-    "cs_scale",
-    "cs_svg_filter",
-    "debug_color",
-    "debug_font",
-    "ps_split_composite",
-    "ps_text_run:DUAL_SOURCE_BLENDING:ALPHA_PASS",
-    "ps_text_run:GLYPH_TRANSFORM:ALPHA_PASS",
-    "ps_text_run:DUAL_SOURCE_BLENDING:GLYPH_TRANSFORM:ALPHA_PASS",
-    "ps_text_run:ALPHA_PASS",
-];
-
 fn main() {
     let shader_dir = match std::env::var("MOZ_SRC") {
         Ok(dir) => dir + "/gfx/wr/webrender/res",
         Err(_) => std::env::var("CARGO_MANIFEST_DIR").unwrap() + "/../webrender/res",
     };
 
-    for shader in WR_SHADERS {
+    let shader_flags =
+        ShaderFeatureFlags::GL |
+        ShaderFeatureFlags::DUAL_SOURCE_BLENDING;
+    let mut shaders: Vec<String> = Vec::new();
+    for (name, features) in get_shader_features(shader_flags) {
+        shaders.extend(features.iter().map(|f| {
+            if f.is_empty() { name.to_owned() } else { format!("{},{}", name, f) }
+        }));
+    }
+
+    for shader in &shaders {
         translate_shader(shader, &shader_dir);
     }
 
-    write_load_shader(WR_SHADERS);
+    write_load_shader(&shaders);
 
     println!("cargo:rerun-if-changed=src/gl_defs.h");
     println!("cargo:rerun-if-changed=src/glsl.h");
     println!("cargo:rerun-if-changed=src/program.h");
     println!("cargo:rerun-if-changed=src/texture.h");
     println!("cargo:rerun-if-changed=src/vector_type.h");
     println!("cargo:rerun-if-changed=src/gl.cc");
     cc::Build::new()