• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

djeedai / bevy_hanabi / 12737152027

12 Jan 2025 09:16PM UTC coverage: 46.643% (-0.1%) from 46.755%
12737152027

push

github

web-flow
Add `DebugSettings` for GPU capture (#415)

Add a new `DebugSettings` resource controlling some debugging settings.

Add the ability via debugging settings to instruct a GPU debugger
attached to the application to capture one or more GPU frames, either
right now or each time a new effect is spawned.

6 of 34 new or added lines in 4 files covered. (17.65%)

3223 of 6910 relevant lines covered (46.64%)

20.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
/src/render/shader_cache.rs
1
use std::hash::{Hash, Hasher};
2

3
use bevy::{
4
    asset::{Assets, Handle},
5
    ecs::{change_detection::ResMut, system::Resource},
6
    log::{debug, trace},
7
    render::render_resource::Shader,
8
    utils::HashMap,
9
};
10

11
/// Cache of baked shaders variants.
12
///
13
/// Baked shader variants are shaders where the placeholders `{{PLACEHOLDER}}`
14
/// present in the WGSL template code have been replaced by actual WGSL code,
15
/// making them a valid shader from the point of view of the Bevy renderer.
16
///
17
/// Shaders present in the cache are allocated [`Shader`] resources. Note that a
18
/// [`Shader`] resource _may_ further be preprocessed to replace `#define`
19
/// directives; to this extent, some entries may not be compilable WGSL as is.
20
#[derive(Default, Resource)]
21
pub struct ShaderCache {
22
    /// Map of allocated shader resources from their baked shader code.
23
    cache: HashMap<String, Handle<Shader>>,
24
}
25

26
impl ShaderCache {
27
    /// Get an existing baked shader variant, or insert it into the cache and
28
    /// allocate a new [`Shader`] resource for it.
29
    ///
30
    /// Returns the [`Shader`] resource associated with `source`.
31
    pub fn get_or_insert(
15✔
32
        &mut self,
33
        filename: &str,
34
        suffix: &str,
35
        source: &str,
36
        shaders: &mut ResMut<Assets<Shader>>,
37
    ) -> Handle<Shader> {
38
        if let Some(handle) = self.cache.get(source) {
18✔
39
            handle.clone()
40
        } else {
41
            let mut hasher = bevy::utils::AHasher::default();
12✔
42
            source.hash(&mut hasher);
12✔
43
            let hash = hasher.finish();
12✔
44
            let shader = Shader::from_wgsl(
45
                source.to_string(),
12✔
46
                format!("hanabi/{}_{}_{}.wgsl", filename, suffix, hash),
12✔
47
            );
48
            trace!(
12✔
49
                "Shader path={} import_path={:?} imports={:?}",
×
50
                shader.path,
51
                shader.import_path,
52
                shader.imports
53
            );
54
            let shader_path = shader.path.clone();
12✔
55
            let handle = shaders.add(shader);
12✔
56
            debug!(
12✔
NEW
57
                "Inserted new configured shader {}: {:?}\n{}",
×
58
                shader_path, handle, source
59
            );
60
            self.cache.insert(source.to_string(), handle.clone());
12✔
61
            handle
12✔
62
        }
63
    }
64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc