aboutsummaryrefslogtreecommitdiffstats
path: root/third_party/webrender/webrender_build
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/webrender/webrender_build')
-rw-r--r--third_party/webrender/webrender_build/src/shader.rs18
-rw-r--r--third_party/webrender/webrender_build/src/shader_features.rs228
2 files changed, 73 insertions, 173 deletions
diff --git a/third_party/webrender/webrender_build/src/shader.rs b/third_party/webrender/webrender_build/src/shader.rs
index 331e858bdac..3c15f4f4148 100644
--- a/third_party/webrender/webrender_build/src/shader.rs
+++ b/third_party/webrender/webrender_build/src/shader.rs
@@ -170,7 +170,6 @@ pub fn build_shader_prefix_string<F: FnMut(&str)>(
// GLSL requires that the version number comes first.
let gl_version_string = match gl_version {
ShaderVersion::Gl => "#version 150\n",
- ShaderVersion::Gles if features.contains(&"TEXTURE_EXTERNAL_ESSL1") => "#version 100\n",
ShaderVersion::Gles => "#version 300 es\n",
};
output(gl_version_string);
@@ -194,23 +193,6 @@ pub fn build_shader_prefix_string<F: FnMut(&str)>(
};
output(kind_string);
- // detect which platform we're targeting
- let is_macos = match std::env::var("CARGO_CFG_TARGET_OS") {
- Ok(os) => os == "macos",
- // if this is not called from build.rs (e.g. the gpu_cache_update shader or
- // if the optimized shader pref is disabled) we want to use the runtime value
- Err(_) => cfg!(target_os = "macos"),
- };
- let is_android = match std::env::var("CARGO_CFG_TARGET_OS") {
- Ok(os) => os == "android",
- Err(_) => cfg!(target_os = "android"),
- };
- if is_macos {
- output("#define PLATFORM_MACOS\n");
- } else if is_android {
- output("#define PLATFORM_ANDROID\n");
- }
-
// Define a constant for the vertex texture width.
output("#define WR_MAX_VERTEX_TEXTURE_WIDTH ");
output(&MAX_VERTEX_TEXTURE_WIDTH_STRING);
diff --git a/third_party/webrender/webrender_build/src/shader_features.rs b/third_party/webrender/webrender_build/src/shader_features.rs
index 19c4ebb45f1..06e6b0da8a7 100644
--- a/third_party/webrender/webrender_build/src/shader_features.rs
+++ b/third_party/webrender/webrender_build/src/shader_features.rs
@@ -12,50 +12,25 @@ bitflags! {
const ADVANCED_BLEND_EQUATION = 1 << 8;
const DUAL_SOURCE_BLENDING = 1 << 9;
- const DITHERING = 1 << 10;
- const TEXTURE_EXTERNAL = 1 << 11;
- const TEXTURE_EXTERNAL_ESSL1 = 1 << 12;
- const DEBUG = 1 << 13;
+ const PIXEL_LOCAL_STORAGE = 1 << 10;
+ const DITHERING = 1 << 11;
+ const TEXTURE_EXTERNAL = 1 << 12;
}
}
pub type ShaderFeatures = HashMap<&'static str, Vec<String>>;
-/// Builder for a list of features.
-#[derive(Clone)]
-struct FeatureList<'a> {
- list: Vec<&'a str>,
+macro_rules! features {
+ ($($str:expr),*) => { vec![$(String::from($str),)*] as Vec<String> };
}
-impl<'a> FeatureList<'a> {
- fn new() -> Self {
- FeatureList {
- list: Vec::new(),
- }
- }
-
- fn add(&mut self, feature: &'a str) {
- assert!(!feature.contains(','));
- self.list.push(feature);
- }
-
- fn with(&self, feature: &'a str) -> Self {
- let mut other = self.clone();
- other.add(feature);
- other
- }
-
- fn concat(&self, other: &Self) -> Self {
- let mut list = self.list.clone();
- list.extend_from_slice(&other.list);
- FeatureList {
- list
- }
- }
-
- fn finish(&mut self) -> String {
- self.list.sort_unstable();
- self.list.join(",")
+fn concat_features(a: &str, b: &str) -> String {
+ if a.is_empty() {
+ b.to_string()
+ } else if b.is_empty() {
+ a.to_string()
+ } else {
+ [a, b].join(",")
}
}
@@ -64,72 +39,51 @@ pub fn get_shader_features(flags: ShaderFeatureFlags) -> ShaderFeatures {
let mut shaders = ShaderFeatures::new();
// Clip shaders
- shaders.insert("cs_clip_rectangle", vec![String::new(), "FAST_PATH".to_string()]);
- shaders.insert("cs_clip_image", vec!["TEXTURE_2D".to_string()]);
- shaders.insert("cs_clip_box_shadow", vec!["TEXTURE_2D".to_string()]);
+ shaders.insert("cs_clip_rectangle", features!["", "FAST_PATH"]);
+ for name in &["cs_clip_image", "cs_clip_box_shadow"] {
+ shaders.insert(name, features![""]);
+ }
// Cache shaders
- shaders.insert("cs_blur", vec!["ALPHA_TARGET".to_string(), "COLOR_TARGET".to_string()]);
-
- for name in &[
- "cs_line_decoration",
- "cs_fast_linear_gradient",
- "cs_border_segment",
- "cs_border_solid",
- "cs_svg_filter",
- ] {
- shaders.insert(name, vec![String::new()]);
+ shaders.insert("cs_blur", features!["ALPHA_TARGET", "COLOR_TARGET"]);
+
+ for name in &["cs_line_decoration", "cs_gradient", "cs_border_segment", "cs_border_solid", "cs_svg_filter"] {
+ shaders.insert(name, features![""]);
}
- for name in &[
- "cs_linear_gradient",
- "cs_radial_gradient",
- "cs_conic_gradient",
- ] {
- let mut features = Vec::new();
- features.push(String::new());
- if flags.contains(ShaderFeatureFlags::DITHERING) {
- features.push("DITHERING".to_string());
+ shaders.insert("cs_scale", features![""]);
+
+ // Pixel local storage shaders
+ let pls_feature = if flags.contains(ShaderFeatureFlags::PIXEL_LOCAL_STORAGE) {
+ for name in &["pls_init", "pls_resolve"] {
+ shaders.insert(name, features!["PIXEL_LOCAL_STORAGE"]);
}
- shaders.insert(name, features);
- }
- let mut base_prim_features = FeatureList::new();
+ "PIXEL_LOCAL_STORAGE"
+ } else {
+ ""
+ };
// Brush shaders
- let mut brush_alpha_features = base_prim_features.with("ALPHA_PASS");
- for name in &["brush_solid", "brush_blend", "brush_mix_blend"] {
- let mut features: Vec<String> = Vec::new();
- features.push(base_prim_features.finish());
- features.push(brush_alpha_features.finish());
- features.push("DEBUG_OVERDRAW".to_string());
- shaders.insert(name, features);
+ let brush_alpha_features = concat_features("ALPHA_PASS", pls_feature);
+ for name in &["brush_solid", "brush_blend", "brush_mix_blend", "brush_opacity"] {
+ shaders.insert(name, features!["", &brush_alpha_features, "DEBUG_OVERDRAW"]);
}
- for name in &["brush_linear_gradient"] {
+ for name in &["brush_conic_gradient", "brush_radial_gradient", "brush_linear_gradient"] {
let mut features: Vec<String> = Vec::new();
- let mut list = FeatureList::new();
- if flags.contains(ShaderFeatureFlags::DITHERING) {
- list.add("DITHERING");
- }
- features.push(list.concat(&base_prim_features).finish());
- features.push(list.concat(&brush_alpha_features).finish());
- features.push(list.with("DEBUG_OVERDRAW").finish());
+ let base = if flags.contains(ShaderFeatureFlags::DITHERING) {
+ "DITHERING"
+ } else {
+ ""
+ };
+ features.push(base.to_string());
+ features.push(concat_features(base, &brush_alpha_features));
+ features.push(concat_features(base, "DEBUG_OVERDRAW"));
shaders.insert(name, features);
}
- {
- let mut features: Vec<String> = Vec::new();
- features.push(base_prim_features.finish());
- features.push(brush_alpha_features.finish());
- features.push(base_prim_features.with("ANTIALIASING").finish());
- features.push(brush_alpha_features.with("ANTIALIASING").finish());
- features.push("ANTIALIASING,DEBUG_OVERDRAW".to_string());
- features.push("DEBUG_OVERDRAW".to_string());
- shaders.insert("brush_opacity", features);
- }
-
// Image brush shaders
- let mut texture_types = vec!["TEXTURE_2D"];
+ let mut texture_types = vec!["", "TEXTURE_2D"];
if flags.contains(ShaderFeatureFlags::GL) {
texture_types.push("TEXTURE_RECT");
}
@@ -138,96 +92,60 @@ pub fn get_shader_features(flags: ShaderFeatureFlags) -> ShaderFeatures {
}
let mut image_features: Vec<String> = Vec::new();
for texture_type in &texture_types {
- let mut fast = FeatureList::new();
- if !texture_type.is_empty() {
- fast.add(texture_type);
- }
- image_features.push(fast.concat(&base_prim_features).finish());
- image_features.push(fast.concat(&brush_alpha_features).finish());
- image_features.push(fast.with("DEBUG_OVERDRAW").finish());
- let mut slow = fast.clone();
- slow.add("REPETITION");
- slow.add("ANTIALIASING");
- image_features.push(slow.concat(&base_prim_features).finish());
- image_features.push(slow.concat(&brush_alpha_features).finish());
- image_features.push(slow.with("DEBUG_OVERDRAW").finish());
+ let fast = texture_type.to_string();
+ image_features.push(fast.clone());
+ image_features.push(concat_features(&fast, &brush_alpha_features));
+ image_features.push(concat_features(&fast, "DEBUG_OVERDRAW"));
+ let slow = concat_features(texture_type, "REPETITION,ANTIALIASING");
+ image_features.push(slow.clone());
+ image_features.push(concat_features(&slow, &brush_alpha_features));
+ image_features.push(concat_features(&slow, "DEBUG_OVERDRAW"));
if flags.contains(ShaderFeatureFlags::ADVANCED_BLEND_EQUATION) {
- let advanced_blend_features = brush_alpha_features.with("ADVANCED_BLEND");
- image_features.push(fast.concat(&advanced_blend_features).finish());
- image_features.push(slow.concat(&advanced_blend_features).finish());
+ let advanced_blend_features = concat_features(&brush_alpha_features, "ADVANCED_BLEND");
+ image_features.push(concat_features(&fast, &advanced_blend_features));
+ image_features.push(concat_features(&slow, &advanced_blend_features));
}
if flags.contains(ShaderFeatureFlags::DUAL_SOURCE_BLENDING) {
- let dual_source_features = brush_alpha_features.with("DUAL_SOURCE_BLENDING");
- image_features.push(fast.concat(&dual_source_features).finish());
- image_features.push(slow.concat(&dual_source_features).finish());
+ let dual_source_features = concat_features(&brush_alpha_features, "DUAL_SOURCE_BLENDING");
+ image_features.push(concat_features(&fast, &dual_source_features));
+ image_features.push(concat_features(&slow, &dual_source_features));
}
}
shaders.insert("brush_image", image_features);
- let mut composite_texture_types = texture_types.clone();
- if flags.contains(ShaderFeatureFlags::TEXTURE_EXTERNAL_ESSL1) {
- composite_texture_types.push("TEXTURE_EXTERNAL_ESSL1");
- }
let mut composite_features: Vec<String> = Vec::new();
- for texture_type in &composite_texture_types {
- let base = texture_type.to_string();
- composite_features.push(base);
+ for texture_type in &texture_types {
+ let base = concat_features("", texture_type);
+ composite_features.push(base.clone());
}
- shaders.insert("cs_scale", composite_features.clone());
-
- // YUV image brush and composite shaders
+ // YUV image brush shaders
let mut yuv_features: Vec<String> = Vec::new();
for texture_type in &texture_types {
- let mut list = FeatureList::new();
- if !texture_type.is_empty() {
- list.add(texture_type);
- }
- list.add("YUV");
- composite_features.push(list.finish());
- yuv_features.push(list.concat(&base_prim_features).finish());
- yuv_features.push(list.concat(&brush_alpha_features).finish());
- yuv_features.push(list.with("DEBUG_OVERDRAW").finish());
- }
- shaders.insert("brush_yuv_image", yuv_features);
-
- // Fast path composite shaders
- for texture_type in &composite_texture_types {
- let mut list = FeatureList::new();
- if !texture_type.is_empty() {
- list.add(texture_type);
- }
- list.add("FAST_PATH");
- composite_features.push(list.finish());
+ let base = concat_features("YUV", texture_type);
+ composite_features.push(base.clone());
+ yuv_features.push(base.clone());
+ yuv_features.push(concat_features(&base, &brush_alpha_features));
+ yuv_features.push(concat_features(&base, "DEBUG_OVERDRAW"));
}
shaders.insert("composite", composite_features);
+ shaders.insert("brush_yuv_image", yuv_features);
// Prim shaders
- let mut text_types = vec![""];
+ let mut text_types = vec![pls_feature];
if flags.contains(ShaderFeatureFlags::DUAL_SOURCE_BLENDING) {
text_types.push("DUAL_SOURCE_BLENDING");
}
let mut text_features: Vec<String> = Vec::new();
for text_type in &text_types {
- let mut list = base_prim_features.with("TEXTURE_2D");
- if !text_type.is_empty() {
- list.add(text_type);
- }
- let mut alpha_list = list.with("ALPHA_PASS");
- text_features.push(alpha_list.finish());
- text_features.push(alpha_list.with("GLYPH_TRANSFORM").finish());
- text_features.push(list.with("DEBUG_OVERDRAW").finish());
+ text_features.push(concat_features(text_type, "ALPHA_PASS"));
+ text_features.push(concat_features(text_type, "GLYPH_TRANSFORM,ALPHA_PASS"));
+ text_features.push(concat_features(text_type, "DEBUG_OVERDRAW"));
}
shaders.insert("ps_text_run", text_features);
- shaders.insert("ps_split_composite", vec![base_prim_features.finish()]);
-
- shaders.insert("ps_clear", vec![base_prim_features.finish()]);
+ shaders.insert("ps_split_composite", features![pls_feature]);
- if flags.contains(ShaderFeatureFlags::DEBUG) {
- for name in &["debug_color", "debug_font"] {
- shaders.insert(name, vec![String::new()]);
- }
- }
+ shaders.insert("ps_clear", features![""]);
shaders
}