Skip to content

Commit

Permalink
Helpers to check pipeline cache status (bevyengine#5796)
Browse files Browse the repository at this point in the history
# 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
  • Loading branch information
mockersf authored and james7132 committed Oct 28, 2022
1 parent 6a7f623 commit ee4ccc9
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions crates/bevy_render/src/render_resource/pipeline_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ use crate::{
use bevy_asset::{AssetEvent, Assets, Handle};
use bevy_ecs::system::{Res, ResMut};
use bevy_ecs::{event::EventReader, system::Resource};
use bevy_utils::{default, tracing::error, Entry, HashMap, HashSet};
use bevy_utils::{
default,
tracing::{debug, error},
Entry, HashMap, HashSet,
};
use std::{hash::Hash, iter::FusedIterator, mem, ops::Deref, sync::Arc};
use thiserror::Error;
use wgpu::{
BufferBindingType, PipelineLayoutDescriptor, ShaderModule,
VertexBufferLayout as RawVertexBufferLayout,
};

enum PipelineDescriptor {
pub enum PipelineDescriptor {
RenderPipelineDescriptor(Box<RenderPipelineDescriptor>),
ComputePipelineDescriptor(Box<ComputePipelineDescriptor>),
}
Expand All @@ -47,9 +51,9 @@ impl CachedComputePipelineId {
pub const INVALID: Self = CachedComputePipelineId(usize::MAX);
}

struct CachedPipeline {
descriptor: PipelineDescriptor,
state: CachedPipelineState,
pub struct CachedPipeline {
pub descriptor: PipelineDescriptor,
pub state: CachedPipelineState,
}

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

debug!(
"processing shader {:?}, with shader defs {:?}",
handle, shader_defs
);
let processed = self.processor.process(
shader,
&shader_defs,
Expand Down Expand Up @@ -273,6 +281,10 @@ pub struct PipelineCache {
}

impl PipelineCache {
pub fn pipelines(&self) -> impl Iterator<Item = &CachedPipeline> {
self.pipelines.iter()
}

pub fn new(device: RenderDevice) -> Self {
Self {
device,
Expand Down

0 comments on commit ee4ccc9

Please sign in to comment.