Skip to content

Commit

Permalink
Build only needed shaders with --cpu
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Nov 1, 2023
1 parent b5e3ae5 commit 8d372bf
Show file tree
Hide file tree
Showing 6 changed files with 344 additions and 353 deletions.
1 change: 1 addition & 0 deletions src/cpu_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub enum TypedBufGuard<'a, T: ?Sized> {
}

pub enum TypedBufGuardMut<'a, T: ?Sized> {
#[allow(dead_code)]
Slice(&'a mut T),
Interior(RefMut<'a, T>),
}
Expand Down
2 changes: 1 addition & 1 deletion src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{

pub type Error = Box<dyn std::error::Error>;

#[derive(Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Hash, Default)]
pub struct ShaderId(pub usize);

#[derive(Clone, Copy, PartialEq, Eq, Hash)]
Expand Down
14 changes: 4 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ pub struct RendererOptions {
impl Renderer {
/// Creates a new renderer for the specified device.
pub fn new(device: &Device, render_options: &RendererOptions) -> Result<Self> {
let mut engine = WgpuEngine::new();
let mut shaders = shaders::full_shaders(device, &mut engine)?;
if render_options.use_cpu {
shaders.install_cpu_shaders(&mut engine);
}
let mut engine = WgpuEngine::new(render_options.use_cpu);
let shaders = shaders::full_shaders(device, &mut engine)?;
let blit = render_options
.surface_format
.map(|surface_format| BlitPipeline::new(device, surface_format));
Expand Down Expand Up @@ -240,11 +237,8 @@ impl Renderer {
#[cfg(feature = "hot_reload")]
pub async fn reload_shaders(&mut self, device: &Device) -> Result<()> {
device.push_error_scope(wgpu::ErrorFilter::Validation);
let mut engine = WgpuEngine::new();
let mut shaders = shaders::full_shaders(device, &mut engine)?;
if self.use_cpu {
shaders.install_cpu_shaders(&mut engine);
}
let mut engine = WgpuEngine::new(self.use_cpu);
let shaders = shaders::full_shaders(device, &mut engine)?;
let error = device.pop_error_scope().await;
if let Some(error) = error {
return Err(error.into());
Expand Down
Loading

0 comments on commit 8d372bf

Please sign in to comment.