Skip to content

Commit db3b9cc

Browse files
mockersfItsDoot
authored andcommitted
Helpers to check pipeline cache status (bevyengine#5796)
# Objective - In WASM, creating a pipeline can easily take 2 seconds, freezing the game while doing so - Preloading pipelines can be done during a "loading" state, but it is not trivial to know which pipeline to preload, or when it's done ## Solution - Add a log with shaders being loaded and their shader defs - add a function on `PipelineCache` to return the number of ready pipelines
1 parent 7601a89 commit db3b9cc

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

crates/bevy_render/src/render_resource/pipeline_cache.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ use crate::{
1212
use bevy_asset::{AssetEvent, Assets, Handle};
1313
use bevy_ecs::system::{Res, ResMut};
1414
use bevy_ecs::{event::EventReader, system::Resource};
15-
use bevy_utils::{default, tracing::error, Entry, HashMap, HashSet};
15+
use bevy_utils::{
16+
default,
17+
tracing::{debug, error},
18+
Entry, HashMap, HashSet,
19+
};
1620
use std::{hash::Hash, iter::FusedIterator, mem, ops::Deref, sync::Arc};
1721
use thiserror::Error;
1822
use wgpu::{
1923
BufferBindingType, PipelineLayoutDescriptor, ShaderModule,
2024
VertexBufferLayout as RawVertexBufferLayout,
2125
};
2226

23-
enum PipelineDescriptor {
27+
pub enum PipelineDescriptor {
2428
RenderPipelineDescriptor(Box<RenderPipelineDescriptor>),
2529
ComputePipelineDescriptor(Box<ComputePipelineDescriptor>),
2630
}
@@ -47,9 +51,9 @@ impl CachedComputePipelineId {
4751
pub const INVALID: Self = CachedComputePipelineId(usize::MAX);
4852
}
4953

50-
struct CachedPipeline {
51-
descriptor: PipelineDescriptor,
52-
state: CachedPipelineState,
54+
pub struct CachedPipeline {
55+
pub descriptor: PipelineDescriptor,
56+
pub state: CachedPipelineState,
5357
}
5458

5559
#[derive(Debug)]
@@ -137,6 +141,10 @@ impl ShaderCache {
137141
shader_defs.push(String::from("NO_STORAGE_BUFFERS_SUPPORT"));
138142
}
139143

144+
debug!(
145+
"processing shader {:?}, with shader defs {:?}",
146+
handle, shader_defs
147+
);
140148
let processed = self.processor.process(
141149
shader,
142150
&shader_defs,
@@ -273,6 +281,10 @@ pub struct PipelineCache {
273281
}
274282

275283
impl PipelineCache {
284+
pub fn pipelines(&self) -> impl Iterator<Item = &CachedPipeline> {
285+
self.pipelines.iter()
286+
}
287+
276288
pub fn new(device: RenderDevice) -> Self {
277289
Self {
278290
device,

0 commit comments

Comments
 (0)