Bug 1631778 - Ensure webrender's shaders.rs is filled deterministically. r=jrmuizel

The list of pre-optimized shaders was being generated in a
non-deterministic order, causing large build time regressions. This
sort the list of shaders before writing them to the shaders.rs file.

Differential Revision: https://phabricator.services.mozilla.com/D71905
This commit is contained in:
Jamie Nicol 2020-04-22 13:51:13 +00:00
Родитель 0310c689ca
Коммит 5acad1e764
2 изменённых файлов: 34 добавлений и 25 удалений

Просмотреть файл

@ -28,12 +28,17 @@ fn escape_include_path(path: &Path) -> String {
full_name
}
fn write_unoptimized_shaders(glsl_files: Vec<PathBuf>, shader_file: &mut File) -> Result<(), std::io::Error> {
fn write_unoptimized_shaders(mut glsl_files: Vec<PathBuf>, shader_file: &mut File) -> Result<(), std::io::Error> {
writeln!(
shader_file,
" pub static ref UNOPTIMIZED_SHADERS: HashMap<&'static str, SourceWithDigest> = {{"
)?;
writeln!(shader_file, " let mut shaders = HashMap::new();")?;
// Sort the file list so that the shaders.rs file is filled
// deterministically.
glsl_files.sort_by(|a, b| a.file_name().cmp(&b.file_name()));
for glsl in glsl_files {
// Compute the shader name.
assert!(glsl.is_file());
@ -189,25 +194,33 @@ fn write_optimized_shaders(shader_dir: &Path, shader_file: &mut File, out_dir: &
}, &shaders);
match outputs {
Ok(outputs) => for shader in outputs {
writeln!(
shader_file,
" shaders.insert(({}, \"{}\"), OptimizedSourceWithDigest {{",
shader.gl_version.variant_name(),
shader.full_shader_name,
)?;
writeln!(
shader_file,
" vert_source: include_str!(\"{}\"),",
escape_include_path(&shader.vert_file_path),
)?;
writeln!(
shader_file,
" frag_source: include_str!(\"{}\"),",
escape_include_path(&shader.frag_file_path),
)?;
writeln!(shader_file, " digest: \"{}\",", shader.digest)?;
writeln!(shader_file, " }});")?;
Ok(mut outputs) => {
// Sort the shader list so that the shaders.rs file is filled
// deterministically.
outputs.sort_by(|a, b| {
(a.gl_version, a.full_shader_name.clone()).cmp(&(b.gl_version, b.full_shader_name.clone()))
});
for shader in outputs {
writeln!(
shader_file,
" shaders.insert(({}, \"{}\"), OptimizedSourceWithDigest {{",
shader.gl_version.variant_name(),
shader.full_shader_name,
)?;
writeln!(
shader_file,
" vert_source: include_str!(\"{}\"),",
escape_include_path(&shader.vert_file_path),
)?;
writeln!(
shader_file,
" frag_source: include_str!(\"{}\"),",
escape_include_path(&shader.frag_file_path),
)?;
writeln!(shader_file, " digest: \"{}\",", shader.digest)?;
writeln!(shader_file, " }});")?;
}
}
Err(err) => match err {
build_parallel::Error::BuildError(err) => {
@ -241,10 +254,6 @@ fn main() -> Result<(), std::io::Error> {
}
}
// Sort the file list so that the shaders.rs file is filled
// deterministically.
glsl_files.sort_by(|a, b| a.file_name().cmp(&b.file_name()));
let mut shader_file = File::create(shaders_file_path)?;
writeln!(shader_file, "/// AUTO GENERATED BY build.rs\n")?;

Просмотреть файл

@ -27,7 +27,7 @@ pub enum ShaderKind {
Fragment,
}
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub enum ShaderVersion {
Gl,
Gles,