`ShaderCache::get` re-composes a shader's whole WESL import tree from source for every variant

Open
#26,597 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
rust
Domain
performance

Research direction

Start with crates/bevy_shader/src/shader_cache.rs and trace ShaderCache::get through WESL composition and load_module; the issue identifies repeated source parsing as the measured cost. Read the WESL resolver notes in the issue before assessing whether parsed modules can be reused across compile calls. Done means reducing repeated composition work across shader variants and making the separate composition and module loading costs visible, with measurements against the provided reproduction.

Written by the indexing model from the issue text.

Description

Bevy version and features

0.20.1, with the features in the Cargo.toml below. The code involved is unchanged on main (42265b2).

What you did

Ran the headless reproduction below in release. It specializes 30 main-pass pbr.wesl fragment variants (5 vertex layouts by 6 StandardMaterial setups, two views), then times ShaderCache::get for each variant on a cold ShaderCache, splitting the time between WESL composition (wesl::compile and the WGSL text it is turned into) and load_module (naga's parse and create_shader_module).

What went wrong

ShaderCache::get (crates/bevy_shader/src/shader_cache.rs) composes every &[ShaderDefVal] variant with wesl::compile from the raw source of each module in the shader's import tree, turns the result into WGSL text (80 to 90 KiB for a pbr.wesl variant), and naga parses that text again. Nothing parsed is kept from one variant to the next, so pbr_functions, pbr_fragment, pbr_lighting, shadows and the rest are lexed and parsed again for every variant. Across the 30 variants, composition takes 87.6% of ShaderCache::get, and naga's parse with module creation 12.4%:

=== Bevy 0.20.1 Reproduction 01: ShaderCache WESL Re-composition vs Naga Parse ===
scene_pipelines_specialized: 104 (settled in 106 frames, 1062.46 ms end-to-end)
registered_shader_assets: 97
unique_pbr_main_fragment_variants: 30
unique_other_shader_variants: 69

variant    total_ms      wesl_ms      naga_ms   wesl_pct   wgsl_bytes
#01           31.44        27.56         3.89      87.6%        88757
#02           32.71        28.32         4.38      86.6%        89314
#03           32.02        28.28         3.74      88.3%        90306
#04           30.91        26.59         4.33      86.0%        88620
#05           32.52        28.43         4.09      87.4%        89177
#06           33.51        28.86         4.65      86.1%        90169
#07           33.92        30.10         3.82      88.7%        85181
#08           31.74        28.06         3.68      88.4%        85738
#09           32.17        28.13         4.05      87.4%        85113
#10           33.89        30.19         3.70      89.1%        88535
#11           33.30        28.97         4.33      87.0%        89092
#12           32.83        28.98         3.85      88.3%        90084
...      (remaining PBR fragment variants omitted for brevity; included in totals)
#30           27.90        24.58         3.32      88.1%        79120

--- Summary (median across 3 cold ShaderCache trials, serialized under 1 lock) ---
pbr_fragment_total_ms: 923.75 ms across 30 variants (mean 30.79 ms/variant)
pbr_fragment_wesl_compile_ms: 808.79 ms (mean 26.96 ms/variant, 87.6% of ShaderCache::get)
pbr_fragment_naga_load_module_ms: 114.95 ms (mean 3.83 ms/variant, 12.4% of ShaderCache::get)
pbr_fragment_composed_wgsl_bytes: 2543106 bytes total (mean 82.8 KiB/variant)
pbr_fragment_warm_cache_hits_ms: 0.0204 ms across all 30 variants
other_variants_total_ms: 223.63 ms across 69 variants (mean 3.24 ms/variant; wesl 197.04 ms, naga 26.59 ms)
all_shader_variants_serial_lock_time_ms: 1147.37 ms

Neither wesl::compile nor load_module has a tracing span, and load_module creates the module with label: None, so a trace or a GPU profiler cannot tell the two apart or name the shader.

#26152 is about the lock ShaderCache::get holds while it does this; this report is about the work itself, which stays the same once composition runs in parallel.

Additional information

  • wesl's Resolver hands modules over as source text (VirtualResolver::add_translation_unit turns a syntax tree back into text), so keeping each module's parse between variants needs wesl to accept parsed modules, or to cache them across compile calls; Bevy could then key them by the AssetId<Shader> that set_shader registers.
  • A tracing span around wesl::compile and around load_module, and the shader's path as the module's label, would make the split visible.
Reproduction: Cargo.toml and src/main.rs
[package]
name = "bevy-repros"
version = "0.1.0"
edition = "2024"
publish = false

[dependencies]
bevy = { version = "0.20.1", default-features = false, features = [
    "std",
    "async_executor",
    "multi_threaded",
    "reflect_auto_register",
    "bevy_asset",
    "bevy_camera",
    "bevy_color",
    "bevy_core_pipeline",
    "bevy_image",
    "bevy_light",
    "bevy_log",
    "bevy_material",
    "bevy_mesh",
    "bevy_mikktspace",
    "bevy_pbr",
    "bevy_post_process",
    "bevy_render",
    "bevy_shader",
    "bevy_window",
    "bevy_winit",
    "bluenoise_texture",
    "ktx2",
    "tonemapping_luts",
    "zstd_rust",
] }
//! Minimal headless reproduction for Bevy 0.20.1:
//! `ShaderCache::get` re-runs `wesl::compile` across the entire WESL import tree
//! from raw source strings and serializes ~80-90 KiB of WGSL text for `naga` to parse
//! again on every distinct `ShaderDefVal` variant.

use std::{
    borrow::Cow,
    collections::HashSet,
    sync::atomic::{AtomicU64, Ordering},
    time::Instant,
};

use bevy::{
    asset::RenderAssetUsages,
    camera::RenderTarget,
    core_pipeline::tonemapping::Tonemapping,
    log::LogPlugin,
    mesh::VertexAttributeValues,
    prelude::*,
    render::{
        RenderApp,
        pipelined_rendering::PipelinedRenderingPlugin,
        render_resource::{
            Extent3d, PipelineCache, PipelineDescriptor, ShaderModule, ShaderModuleDescriptor,
            ShaderSource, TextureDimension, TextureFormat, TextureUsages,
        },
        renderer::RenderDevice,
    },
    shader::{
        Shader, ShaderCache, ShaderCacheError, ShaderCacheSource, ShaderDefVal, ValidateShader,
    },
    window::ExitCondition,
    winit::WinitPlugin,
};

static LAST_LOAD_MODULE_NS: AtomicU64 = AtomicU64::new(0);
static LAST_WGSL_BYTES: AtomicU64 = AtomicU64::new(0);

fn timed_load_module(
    render_device: &RenderDevice,
    shader_source: ShaderCacheSource,
    validate_shader: &ValidateShader,
) -> Result<ShaderModule, ShaderCacheError> {
    let wgsl_len = match &shader_source {
        ShaderCacheSource::Wgsl(src) => src.len() as u64,
        ShaderCacheSource::SpirV(bytes) => bytes.len() as u64,
    };
    LAST_WGSL_BYTES.store(wgsl_len, Ordering::Relaxed);

    let source = match shader_source {
        ShaderCacheSource::Wgsl(src) => ShaderSource::Wgsl(Cow::Owned(src)),
        ShaderCacheSource::SpirV(_) => unreachable!("WGSL path under test"),
    };
    let desc = ShaderModuleDescriptor {
        label: None,
        source,
    };

    let t0 = Instant::now();
    let module = match validate_shader {
        ValidateShader::Enabled => render_device.create_and_validate_shader_module(desc),
        // Matches `bevy_render::render_resource::pipeline_cache::load_module` default path.
        ValidateShader::Disabled => unsafe { render_device.create_shader_module(desc) },
    };
    LAST_LOAD_MODULE_NS.store(t0.elapsed().as_nanos() as u64, Ordering::Relaxed);

    Ok(module)
}

fn global_shader_defs_for_device(device: &RenderDevice) -> Vec<ShaderDefVal> {
    let available = device.limits().max_storage_buffers_per_shader_stage;
    vec![
        ShaderDefVal::UInt("AVAILABLE_STORAGE_BUFFER_BINDINGS".into(), available),
        ShaderDefVal::Bool("AVAILABLE_STORAGE_BUFFER_BINDINGS__GE_3".into(), available >= 3),
        ShaderDefVal::Bool("AVAILABLE_STORAGE_BUFFER_BINDINGS__GE_6".into(), available >= 6),
    ]
}

fn make_1x1_texture(rgba: [u8; 4], is_srgb: bool) -> Image {
    Image::new_fill(
        Extent3d {
            width: 1,
            height: 1,
            depth_or_array_layers: 1,
        },
        TextureDimension::D2,
        &rgba,
        if is_srgb {
            TextureFormat::Rgba8UnormSrgb
        } else {
            TextureFormat::Rgba8Unorm
        },
        RenderAssetUsages::default(),
    )
}

fn build_mesh_variants(meshes: &mut Assets<Mesh>) -> Vec<Handle<Mesh>> {
    let base: Mesh = Cuboid::new(0.8, 0.8, 0.8).into();
    let with_tangents = base
        .clone()
        .with_generated_tangents()
        .expect("cuboid tangents");

    let mut with_colors = base.clone();
    let vcount = with_colors.count_vertices();
    with_colors.insert_attribute(
        Mesh::ATTRIBUTE_COLOR,
        VertexAttributeValues::Float32x4(vec![[1.0, 1.0, 1.0, 1.0]; vcount]),
    );

    let mut with_tangents_and_colors = with_tangents.clone();
    with_tangents_and_colors.insert_attribute(
        Mesh::ATTRIBUTE_COLOR,
        VertexAttributeValues::Float32x4(vec![[1.0, 1.0, 1.0, 1.0]; vcount]),
    );

    let mut with_uv1 = with_tangents.clone();
    if let Some(VertexAttributeValues::Float32x2(uv0)) =
        with_uv1.attribute(Mesh::ATTRIBUTE_UV_0).cloned()
    {
        with_uv1.insert_attribute(Mesh::ATTRIBUTE_UV_1, VertexAttributeValues::Float32x2(uv0));
    }

    vec![
        meshes.add(base),
        meshes.add(with_tangents),
        meshes.add(with_colors),
        meshes.add(with_tangents_and_colors),
        meshes.add(with_uv1),
    ]
}

fn main() {
    let mut app = App::new();
    app.add_plugins(
        DefaultPlugins
            .set(WindowPlugin {
                primary_window: None,
                exit_condition: ExitCondition::DontExit,
                ..default()
            })
            .disable::<WinitPlugin>()
            .disable::<PipelinedRenderingPlugin>()
            .disable::<LogPlugin>(),
    );
    app.finish();
    app.cleanup();

    // Populate headless scene with standard mesh/material combinations and two tonemapping views
    // so `PipelineCache` specializes genuine PBR shader variants.
    {
        let world = app.world_mut();
        let tex_color = world
            .resource_mut::<Assets<Image>>()
            .add(make_1x1_texture([220, 200, 180, 255], true));
        let tex_linear = world
            .resource_mut::<Assets<Image>>()
            .add(make_1x1_texture([128, 128, 255, 255], false));

        let mut target_a =
            Image::new_target_texture(64, 64, TextureFormat::Rgba8UnormSrgb, None);
        target_a.texture_descriptor.usage |= TextureUsages::COPY_SRC;
        let target_a_handle = world.resource_mut::<Assets<Image>>().add(target_a);

        let mut target_b =
            Image::new_target_texture(64, 64, TextureFormat::Rgba8UnormSrgb, None);
        target_b.texture_descriptor.usage |= TextureUsages::COPY_SRC;
        let target_b_handle = world.resource_mut::<Assets<Image>>().add(target_b);

        let mesh_handles =
            world.resource_scope(|_world, mut meshes: Mut<Assets<Mesh>>| build_mesh_variants(&mut meshes));

        let mat_handles = world.resource_scope(
            |_world, mut materials: Mut<Assets<StandardMaterial>>| {
                vec![
                    materials.add(StandardMaterial {
                        base_color: Color::srgb(0.8, 0.3, 0.2),
                        ..default()
                    }),
                    materials.add(StandardMaterial {
                        base_color_texture: Some(tex_color.clone()),
                        normal_map_texture: Some(tex_linear.clone()),
                        ..default()
                    }),
                    materials.add(StandardMaterial {
                        base_color_texture: Some(tex_color.clone()),
                        metallic_roughness_texture: Some(tex_linear.clone()),
                        occlusion_texture: Some(tex_linear.clone()),
                        ..default()
                    }),
                    materials.add(StandardMaterial {
                        base_color_texture: Some(tex_color.clone()),
                        alpha_mode: AlphaMode::Mask(0.5),
                        double_sided: true,
                        cull_mode: None,
                        ..default()
                    }),
                    materials.add(StandardMaterial {
                        base_color: Color::srgba(0.3, 0.7, 0.9, 0.6),
                        alpha_mode: AlphaMode::Blend,
                        ..default()
                    }),
                    materials.add(StandardMaterial {
                        unlit: true,
                        emissive_texture: Some(tex_color.clone()),
                        ..default()
                    }),
                ]
            },
        );

        let mut idx = 0usize;
        for mesh in &mesh_handles {
            for mat in &mat_handles {
                let x = (idx % 6) as f32 * 1.5 - 3.75;
                let y = (idx / 6) as f32 * 1.5 - 3.0;
                world.spawn((
                    Mesh3d(mesh.clone()),
                    MeshMaterial3d(mat.clone()),
                    Transform::from_xyz(x, y, 0.0),
                ));
                idx += 1;
            }
        }

        world.spawn((
            DirectionalLight {
                shadow_maps_enabled: true,
                ..default()
            },
            Transform::from_xyz(4.0, 8.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y),
        ));
        world.spawn((
            PointLight {
                shadow_maps_enabled: false,
                ..default()
            },
            Transform::from_xyz(-3.0, 3.0, 4.0),
        ));

        world.spawn((
            Camera3d::default(),
            Camera {
                order: 0,
                ..default()
            },
            RenderTarget::Image(target_a_handle.into()),
            Tonemapping::TonyMcMapface,
            Transform::from_xyz(0.0, 0.0, 12.0).looking_at(Vec3::ZERO, Vec3::Y),
        ));
        world.spawn((
            Camera3d::default(),
            Camera {
                order: 1,
                ..default()
            },
            RenderTarget::Image(target_b_handle.into()),
            Tonemapping::AcesFitted,
            DistanceFog {
                color: Color::srgb(0.2, 0.2, 0.25),
                falloff: FogFalloff::Linear {
                    start: 5.0,
                    end: 30.0,
                },
                ..default()
            },
            Transform::from_xyz(0.0, 0.0, 12.0).looking_at(Vec3::ZERO, Vec3::Y),
        ));
    }

    // Drive headless frames until all specialized pipelines finish compiling.
    let mut frames_to_settle = 0usize;
    let pipeline_wall_start = Instant::now();
    for frame in 1..=200 {
        app.update();
        let waiting = app
            .sub_app(RenderApp)
            .world()
            .resource::<PipelineCache>()
            .waiting_pipelines()
            .count();
        if frame >= 3 && waiting == 0 {
            frames_to_settle = frame;
            break;
        }
        std::thread::sleep(std::time::Duration::from_millis(5));
    }
    let pipeline_wall_ms = pipeline_wall_start.elapsed().as_secs_f64() * 1000.0;

    // Collect all shader assets and all deduplicated `(AssetId<Shader>, Vec<ShaderDefVal>)`
    // requests specialized by `PipelineCache`.
    let shaders_snapshot: Vec<(AssetId<Shader>, Shader)> = app
        .world()
        .resource::<Assets<Shader>>()
        .iter()
        .map(|(id, s)| (id, s.clone()))
        .collect();

    let (render_device, total_pipelines, pbr_frag_variants, other_shader_variants) = {
        let render_world = app.sub_app(RenderApp).world();
        let render_device = render_world.resource::<RenderDevice>().clone();
        let pipeline_cache = render_world.resource::<PipelineCache>();

        let mut seen = HashSet::<(AssetId<Shader>, Vec<ShaderDefVal>)>::new();
        let mut pbr_frag = Vec::<(AssetId<Shader>, Vec<ShaderDefVal>)>::new();
        let mut other = Vec::<(AssetId<Shader>, Vec<ShaderDefVal>)>::new();
        let mut count_pipelines = 0usize;

        let mut record_stage = |handle: &Handle<Shader>, defs: &[ShaderDefVal], is_frag: bool| {
            let id = handle.id();
            let key = (id, defs.to_vec());
            if !seen.insert(key.clone()) {
                return;
            }
            let path_str = handle
                .path()
                .map(|p| p.path().to_string_lossy().into_owned())
                .unwrap_or_default();
            let is_prepass = defs
                .iter()
                .any(|d| matches!(d, ShaderDefVal::Bool(k, true) if k == "PREPASS_PIPELINE"));
            if is_frag && path_str.ends_with("pbr.wesl") && !is_prepass {
                pbr_frag.push(key);
            } else {
                other.push(key);
            }
        };

        for cached in pipeline_cache.pipelines() {
            count_pipelines += 1;
            match &cached.descriptor {
                PipelineDescriptor::RenderPipelineDescriptor(desc) => {
                    record_stage(&desc.vertex.shader, &desc.vertex.shader_defs, false);
                    if let Some(frag) = &desc.fragment {
                        record_stage(&frag.shader, &frag.shader_defs, true);
                    }
                }
                PipelineDescriptor::ComputePipelineDescriptor(desc) => {
                    record_stage(&desc.shader, &desc.shader_defs, false);
                }
                PipelineDescriptor::MeshPipelineDescriptor(desc) => {
                    if let Some(task) = &desc.task {
                        record_stage(&task.shader, &task.shader_defs, false);
                    }
                    record_stage(&desc.mesh.shader, &desc.mesh.shader_defs, false);
                    if let Some(frag) = &desc.fragment {
                        record_stage(&frag.shader, &frag.shader_defs, true);
                    }
                }
            }
        }

        (render_device, count_pipelines, pbr_frag, other)
    };

    let global_defs = global_shader_defs_for_device(&render_device);

    let build_fresh_cache = || {
        let mut cache =
            ShaderCache::<ShaderModule, RenderDevice>::new(render_device.clone(), timed_load_module);
        for (id, mut shader) in shaders_snapshot.iter().cloned() {
            shader
                .shader_defs
                .splice(0..0, global_defs.iter().cloned());
            cache.set_shader(id, shader);
        }
        cache
    };

    // Warm allocator / code pages once, then run 3 cold-cache trials and report median per variant.
    let _warmup_cache = {
        let mut c = build_fresh_cache();
        if let Some((id, defs)) = pbr_frag_variants.first() {
            let _ = c.get(0, *id, defs).expect("warmup shader compile");
        }
        c
    };

    const TRIALS: usize = 3;
    let mut pbr_samples: Vec<Vec<(f64, f64, f64, u64)>> =
        vec![Vec::with_capacity(TRIALS); pbr_frag_variants.len()];
    let mut other_totals_ms = Vec::with_capacity(TRIALS);
    let mut other_wesl_ms = Vec::with_capacity(TRIALS);
    let mut other_naga_ms = Vec::with_capacity(TRIALS);
    let mut cache_hit_total_ms = 0.0;

    for trial in 0..TRIALS {
        let mut cache = build_fresh_cache();
        for (v_idx, (id, defs)) in pbr_frag_variants.iter().enumerate() {
            LAST_LOAD_MODULE_NS.store(0, Ordering::Relaxed);
            LAST_WGSL_BYTES.store(0, Ordering::Relaxed);
            let t0 = Instant::now();
            let _module = cache
                .get(v_idx, *id, defs)
                .expect("PBR fragment variant should compile");
            let total_ns = t0.elapsed().as_nanos() as u64;
            let naga_ns = LAST_LOAD_MODULE_NS.load(Ordering::Relaxed);
            let wesl_ns = total_ns.saturating_sub(naga_ns);
            let bytes = LAST_WGSL_BYTES.load(Ordering::Relaxed);
            pbr_samples[v_idx].push((
                total_ns as f64 / 1_000_000.0,
                wesl_ns as f64 / 1_000_000.0,
                naga_ns as f64 / 1_000_000.0,
                bytes,
            ));
        }

        if trial == TRIALS - 1 {
            let t_hit = Instant::now();
            for (v_idx, (id, defs)) in pbr_frag_variants.iter().enumerate() {
                let _ = cache.get(v_idx, *id, defs).expect("cache hit");
            }
            cache_hit_total_ms = t_hit.elapsed().as_secs_f64() * 1000.0;
        }

        let mut o_total = 0.0;
        let mut o_wesl = 0.0;
        let mut o_naga = 0.0;
        for (o_idx, (id, defs)) in other_shader_variants.iter().enumerate() {
            LAST_LOAD_MODULE_NS.store(0, Ordering::Relaxed);
            let t0 = Instant::now();
            if cache
                .get(pbr_frag_variants.len() + o_idx, *id, defs)
                .is_ok()
            {
                let total_ns = t0.elapsed().as_nanos() as u64;
                let naga_ns = LAST_LOAD_MODULE_NS.load(Ordering::Relaxed);
                let wesl_ns = total_ns.saturating_sub(naga_ns);
                o_total += total_ns as f64 / 1_000_000.0;
                o_wesl += wesl_ns as f64 / 1_000_000.0;
                o_naga += naga_ns as f64 / 1_000_000.0;
            }
        }
        other_totals_ms.push(o_total);
        other_wesl_ms.push(o_wesl);
        other_naga_ms.push(o_naga);
    }

    println!("=== Bevy 0.20.1 Reproduction 01: ShaderCache WESL Re-composition vs Naga Parse ===");
    println!(
        "scene_pipelines_specialized: {} (settled in {} frames, {:.2} ms end-to-end)",
        total_pipelines, frames_to_settle, pipeline_wall_ms
    );
    println!(
        "registered_shader_assets: {}",
        shaders_snapshot.len()
    );
    println!(
        "unique_pbr_main_fragment_variants: {}",
        pbr_frag_variants.len()
    );
    println!(
        "unique_other_shader_variants: {}",
        other_shader_variants.len()
    );
    println!();
    println!(
        "{:<8} {:>10} {:>12} {:>12} {:>10} {:>12}",
        "variant", "total_ms", "wesl_ms", "naga_ms", "wesl_pct", "wgsl_bytes"
    );

    let mut sum_total_ms = 0.0;
    let mut sum_wesl_ms = 0.0;
    let mut sum_naga_ms = 0.0;
    let mut sum_wgsl_bytes = 0u64;

    for (idx, samples) in pbr_samples.iter_mut().enumerate() {
        samples.sort_by(|a, b| a.0.total_cmp(&b.0));
        let (total_ms, wesl_ms, naga_ms, bytes) = samples[TRIALS / 2];
        let wesl_pct = if total_ms > 0.0 {
            (wesl_ms / total_ms) * 100.0
        } else {
            0.0
        };
        sum_total_ms += total_ms;
        sum_wesl_ms += wesl_ms;
        sum_naga_ms += naga_ms;
        sum_wgsl_bytes += bytes;
        if idx < 12 || idx + 1 == pbr_frag_variants.len() {
            println!(
                "{:<8} {:>10.2} {:>12.2} {:>12.2} {:>9.1}% {:>12}",
                format!("#{:02}", idx + 1),
                total_ms,
                wesl_ms,
                naga_ms,
                wesl_pct,
                bytes
            );
        } else if idx == 12 {
            println!("...      (remaining PBR fragment variants omitted for brevity; included in totals)");
        }
    }

    let n_pbr = pbr_frag_variants.len().max(1) as f64;
    let pbr_wesl_share = (sum_wesl_ms / sum_total_ms.max(1e-9)) * 100.0;

    other_totals_ms.sort_by(|a, b| a.total_cmp(b));
    other_wesl_ms.sort_by(|a, b| a.total_cmp(b));
    other_naga_ms.sort_by(|a, b| a.total_cmp(b));
    let med_other_total = other_totals_ms[TRIALS / 2];
    let med_other_wesl = other_wesl_ms[TRIALS / 2];
    let med_other_naga = other_naga_ms[TRIALS / 2];

    println!();
    println!("--- Summary (median across {} cold ShaderCache trials, serialized under 1 lock) ---", TRIALS);
    println!(
        "pbr_fragment_total_ms: {:.2} ms across {} variants (mean {:.2} ms/variant)",
        sum_total_ms,
        pbr_frag_variants.len(),
        sum_total_ms / n_pbr
    );
    println!(
        "pbr_fragment_wesl_compile_ms: {:.2} ms (mean {:.2} ms/variant, {:.1}% of ShaderCache::get)",
        sum_wesl_ms,
        sum_wesl_ms / n_pbr,
        pbr_wesl_share
    );
    println!(
        "pbr_fragment_naga_load_module_ms: {:.2} ms (mean {:.2} ms/variant, {:.1}% of ShaderCache::get)",
        sum_naga_ms,
        sum_naga_ms / n_pbr,
        100.0 - pbr_wesl_share
    );
    println!(
        "pbr_fragment_composed_wgsl_bytes: {} bytes total (mean {:.1} KiB/variant)",
        sum_wgsl_bytes,
        (sum_wgsl_bytes as f64 / n_pbr) / 1024.0
    );
    println!(
        "pbr_fragment_warm_cache_hits_ms: {:.4} ms across all {} variants",
        cache_hit_total_ms,
        pbr_frag_variants.len()
    );
    println!(
        "other_variants_total_ms: {:.2} ms across {} variants (mean {:.2} ms/variant; wesl {:.2} ms, naga {:.2} ms)",
        med_other_total,
        other_shader_variants.len(),
        med_other_total / (other_shader_variants.len().max(1) as f64),
        med_other_wesl,
        med_other_naga
    );
    println!(
        "all_shader_variants_serial_lock_time_ms: {:.2} ms",
        sum_total_ms + med_other_total
    );
}
Dominant language
Rust
Stars
49.8k
Forks
5.1k
Avg merge
3d 4h
Merged PRs (30d)
136

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from bevyengine/bevy

All issues in bevyengine/bevy

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.