Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/bevy_anti_alias/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ bevy_shader = { path = "../bevy_shader", version = "0.18.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.18.0-dev" }
bevy_core_pipeline = { path = "../bevy_core_pipeline", version = "0.18.0-dev" }
bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.18.0-dev" }
bevy_platform = { path = "../bevy_platform", version = "0.18.0-dev" }

# other
tracing = { version = "0.1", default-features = false, features = ["std"] }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Mutex;

use crate::contrast_adaptive_sharpening::ViewCasPipeline;
use bevy_ecs::prelude::*;
use bevy_platform::sync::Mutex;
use bevy_render::{
diagnostic::RecordDiagnostics,
extract_component::{ComponentUniforms, DynamicUniformIndex},
Expand Down Expand Up @@ -73,7 +72,7 @@ impl Node for CasNode {
let source = view_target.source;
let destination = view_target.destination;

let mut cached_bind_group = self.cached_bind_group.lock().unwrap();
let mut cached_bind_group = self.cached_bind_group.lock();
let bind_group = match &mut *cached_bind_group {
Some((buffer_id, texture_id, bind_group))
if source.id() == *texture_id && uniforms_id == *buffer_id =>
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_anti_alias/src/dlss/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl ViewNode for DlssNode<DlssSuperResolutionFeature> {

let diagnostics = render_context.diagnostic_recorder();
let command_encoder = render_context.command_encoder();
let mut dlss_context = dlss_context.context.lock().unwrap();
let mut dlss_context = dlss_context.context.lock();

command_encoder.push_debug_group("dlss_super_resolution");
let time_span = diagnostics.time_span(command_encoder, "dlss_super_resolution");
Expand Down Expand Up @@ -148,7 +148,7 @@ impl ViewNode for DlssNode<DlssRayReconstructionFeature> {

let diagnostics = render_context.diagnostic_recorder();
let command_encoder = render_context.command_encoder();
let mut dlss_context = dlss_context.context.lock().unwrap();
let mut dlss_context = dlss_context.context.lock();

command_encoder.push_debug_group("dlss_ray_reconstruction");
let time_span = diagnostics.time_span(command_encoder, "dlss_ray_reconstruction");
Expand Down
7 changes: 3 additions & 4 deletions crates/bevy_anti_alias/src/dlss/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ use bevy_ecs::{
system::{Commands, Query, Res},
};
use bevy_math::Vec4Swizzles;
use bevy_platform::sync::{Arc, Mutex};
use bevy_render::{
camera::{MipBias, TemporalJitter},
render_resource::TextureUsages,
renderer::{RenderDevice, RenderQueue},
view::ExtractedView,
};
use dlss_wgpu::{DlssFeatureFlags, DlssPerfQualityMode};
use std::sync::{Arc, Mutex};

#[derive(Component)]
pub struct DlssRenderContext<F: DlssFeature> {
Expand Down Expand Up @@ -76,12 +76,11 @@ pub fn prepare_dlss<F: DlssFeature>(

match dlss_context.as_deref_mut() {
Some(dlss_context)
if upscaled_resolution
== F::upscaled_resolution(&dlss_context.context.lock().unwrap())
if upscaled_resolution == F::upscaled_resolution(&dlss_context.context.lock())
&& dlss.perf_quality_mode == dlss_context.perf_quality_mode
&& dlss_feature_flags == dlss_context.feature_flags =>
{
let dlss_context = dlss_context.context.lock().unwrap();
let dlss_context = dlss_context.context.lock();
let render_resolution = F::render_resolution(&dlss_context);
temporal_jitter.offset =
F::suggested_jitter(&dlss_context, frame_count.0, render_resolution);
Expand Down
5 changes: 2 additions & 3 deletions crates/bevy_anti_alias/src/fxaa/node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::sync::Mutex;

use crate::fxaa::{CameraFxaaPipeline, Fxaa, FxaaPipeline};
use bevy_ecs::{prelude::*, query::QueryItem};
use bevy_platform::sync::Mutex;
use bevy_render::{
diagnostic::RecordDiagnostics,
render_graph::{NodeRunError, RenderGraphContext, ViewNode},
Expand Down Expand Up @@ -48,7 +47,7 @@ impl ViewNode for FxaaNode {
let post_process = target.post_process_write();
let source = post_process.source;
let destination = post_process.destination;
let mut cached_bind_group = self.cached_texture_bind_group.lock().unwrap();
let mut cached_bind_group = self.cached_texture_bind_group.lock();
let bind_group = match &mut *cached_bind_group {
Some((id, bind_group)) if source.id() == *id => bind_group,
cached_bind_group => {
Expand Down
9 changes: 2 additions & 7 deletions crates/bevy_asset/src/io/embedded/embedded_watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::io::{
};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use bevy_platform::collections::HashMap;
use bevy_platform::sync::{PoisonError, RwLock};
use bevy_platform::sync::RwLock;
use core::time::Duration;
use notify_debouncer_full::{notify::RecommendedWatcher, Debouncer, RecommendedCache};
use std::{
Expand Down Expand Up @@ -64,12 +64,7 @@ impl FilesystemEventHandler for EmbeddedEventHandler {

fn get_path(&self, absolute_path: &Path) -> Option<(PathBuf, bool)> {
let (local_path, is_meta) = get_asset_path(&self.root, absolute_path);
let final_path = self
.root_paths
.read()
.unwrap_or_else(PoisonError::into_inner)
.get(local_path.as_path())?
.clone();
let final_path = self.root_paths.read().get(local_path.as_path())?.clone();
if is_meta {
warn!("Meta file asset hot-reloading is not supported yet: {final_path:?}");
}
Expand Down
4 changes: 1 addition & 3 deletions crates/bevy_asset/src/io/embedded/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use alloc::boxed::Box;
use bevy_app::App;
use bevy_ecs::{resource::Resource, world::World};
#[cfg(feature = "embedded_watcher")]
use bevy_platform::sync::{Arc, PoisonError, RwLock};
use bevy_platform::sync::{Arc, RwLock};
use std::path::{Path, PathBuf};

#[cfg(feature = "embedded_watcher")]
Expand Down Expand Up @@ -51,7 +51,6 @@ impl EmbeddedAssetRegistry {
#[cfg(feature = "embedded_watcher")]
self.root_paths
.write()
.unwrap_or_else(PoisonError::into_inner)
.insert(full_path.into(), asset_path.to_owned());
self.dir.insert_asset(asset_path, value);
}
Expand All @@ -71,7 +70,6 @@ impl EmbeddedAssetRegistry {
#[cfg(feature = "embedded_watcher")]
self.root_paths
.write()
.unwrap_or_else(PoisonError::into_inner)
.insert(full_path.into(), asset_path.to_owned());
self.dir.insert_meta(asset_path, value);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/bevy_asset/src/io/gated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::io::{AssetReader, AssetReaderError, PathStream, Reader};
use alloc::{boxed::Box, sync::Arc};
use async_channel::{Receiver, Sender};
use bevy_platform::{collections::HashMap, sync::RwLock};
use std::{path::Path, sync::PoisonError};
use std::path::Path;

/// A "gated" reader that will prevent asset reads from returning until
/// a given path has been "opened" using [`GateOpener`].
Expand Down Expand Up @@ -31,7 +31,7 @@ impl GateOpener {
/// Opens the `path` "gate", allowing a _single_ [`AssetReader`] operation to return for that path.
/// If multiple operations are expected, call `open` the expected number of calls.
pub fn open<P: AsRef<Path>>(&self, path: P) {
let mut gates = self.gates.write().unwrap_or_else(PoisonError::into_inner);
let mut gates = self.gates.write();
let gates = gates
.entry_ref(path.as_ref())
.or_insert_with(async_channel::unbounded);
Expand All @@ -57,7 +57,7 @@ impl<R: AssetReader> GatedReader<R> {
impl<R: AssetReader> AssetReader for GatedReader<R> {
async fn read<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
let receiver = {
let mut gates = self.gates.write().unwrap_or_else(PoisonError::into_inner);
let mut gates = self.gates.write();
let gates = gates
.entry_ref(path.as_ref())
.or_insert_with(async_channel::unbounded);
Expand Down
85 changes: 24 additions & 61 deletions crates/bevy_asset/src/io/memory.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::io::{AssetReader, AssetReaderError, PathStream, Reader};
use alloc::{borrow::ToOwned, boxed::Box, sync::Arc, vec::Vec};
use bevy_platform::{
collections::HashMap,
sync::{PoisonError, RwLock},
};
use bevy_platform::{collections::HashMap, sync::RwLock};
use core::{pin::Pin, task::Poll};
use futures_io::AsyncRead;
use futures_lite::{ready, Stream};
Expand Down Expand Up @@ -46,17 +43,13 @@ impl Dir {
if let Some(parent) = path.parent() {
dir = self.get_or_insert_dir(parent);
}
dir.0
.write()
.unwrap_or_else(PoisonError::into_inner)
.assets
.insert(
path.file_name().unwrap().to_string_lossy().into(),
Data {
value: value.into(),
path: path.to_owned(),
},
);
dir.0.write().assets.insert(
path.file_name().unwrap().to_string_lossy().into(),
Data {
value: value.into(),
path: path.to_owned(),
},
);
}

/// Removes the stored asset at `path` and returns the `Data` stored if found and otherwise `None`.
Expand All @@ -66,29 +59,21 @@ impl Dir {
dir = self.get_or_insert_dir(parent);
}
let key: Box<str> = path.file_name().unwrap().to_string_lossy().into();
dir.0
.write()
.unwrap_or_else(PoisonError::into_inner)
.assets
.remove(&key)
dir.0.write().assets.remove(&key)
}

pub fn insert_meta(&self, path: &Path, value: impl Into<Value>) {
let mut dir = self.clone();
if let Some(parent) = path.parent() {
dir = self.get_or_insert_dir(parent);
}
dir.0
.write()
.unwrap_or_else(PoisonError::into_inner)
.metadata
.insert(
path.file_name().unwrap().to_string_lossy().into(),
Data {
value: value.into(),
path: path.to_owned(),
},
);
dir.0.write().metadata.insert(
path.file_name().unwrap().to_string_lossy().into(),
Data {
value: value.into(),
path: path.to_owned(),
},
);
}

pub fn get_or_insert_dir(&self, path: &Path) -> Dir {
Expand All @@ -98,7 +83,7 @@ impl Dir {
full_path.push(c);
let name = c.as_os_str().to_string_lossy().into();
dir = {
let dirs = &mut dir.0.write().unwrap_or_else(PoisonError::into_inner).dirs;
let dirs = &mut dir.0.write().dirs;
dirs.entry(name)
.or_insert_with(|| Dir::new(full_path.clone()))
.clone()
Expand All @@ -112,13 +97,7 @@ impl Dir {
let mut dir = self.clone();
for p in path.components() {
let component = p.as_os_str().to_str().unwrap();
let next_dir = dir
.0
.read()
.unwrap_or_else(PoisonError::into_inner)
.dirs
.get(component)?
.clone();
let next_dir = dir.0.read().dirs.get(component)?.clone();
dir = next_dir;
}
Some(dir)
Expand All @@ -130,14 +109,8 @@ impl Dir {
dir = dir.get_dir(parent)?;
}

path.file_name().and_then(|f| {
dir.0
.read()
.unwrap_or_else(PoisonError::into_inner)
.assets
.get(f.to_str().unwrap())
.cloned()
})
path.file_name()
.and_then(|f| dir.0.read().assets.get(f.to_str().unwrap()).cloned())
}

pub fn get_metadata(&self, path: &Path) -> Option<Data> {
Expand All @@ -146,22 +119,12 @@ impl Dir {
dir = dir.get_dir(parent)?;
}

path.file_name().and_then(|f| {
dir.0
.read()
.unwrap_or_else(PoisonError::into_inner)
.metadata
.get(f.to_str().unwrap())
.cloned()
})
path.file_name()
.and_then(|f| dir.0.read().metadata.get(f.to_str().unwrap()).cloned())
}

pub fn path(&self) -> PathBuf {
self.0
.read()
.unwrap_or_else(PoisonError::into_inner)
.path
.to_owned()
self.0.read().path.to_owned()
}
}

Expand Down Expand Up @@ -189,7 +152,7 @@ impl Stream for DirStream {
_cx: &mut core::task::Context<'_>,
) -> Poll<Option<Self::Item>> {
let this = self.get_mut();
let dir = this.dir.0.read().unwrap_or_else(PoisonError::into_inner);
let dir = this.dir.0.read();

let dir_index = this.dir_index;
if let Some(dir_path) = dir
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ mod tests {
}
async fn read<'a>(&'a self, path: &'a Path) -> Result<impl Reader + 'a, AssetReaderError> {
let attempt_number = {
let mut attempt_counters = self.attempt_counters.lock().unwrap();
let mut attempt_counters = self.attempt_counters.lock();
if let Some(existing) = attempt_counters.get_mut(path) {
*existing += 1;
*existing
Expand Down
33 changes: 6 additions & 27 deletions crates/bevy_asset/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ use alloc::{borrow::ToOwned, boxed::Box, collections::VecDeque, sync::Arc, vec,
use bevy_ecs::prelude::*;
use bevy_platform::{
collections::{HashMap, HashSet},
sync::{PoisonError, RwLock},
sync::RwLock,
};
use bevy_tasks::IoTaskPool;
use futures_io::ErrorKind;
Expand Down Expand Up @@ -583,49 +583,28 @@ impl AssetProcessor {

/// Register a new asset processor.
pub fn register_processor<P: Process>(&self, processor: P) {
let mut process_plans = self
.data
.processors
.write()
.unwrap_or_else(PoisonError::into_inner);
let mut process_plans = self.data.processors.write();
#[cfg(feature = "trace")]
let processor = InstrumentedAssetProcessor(processor);
process_plans.insert(core::any::type_name::<P>(), Arc::new(processor));
}

/// Set the default processor for the given `extension`. Make sure `P` is registered with [`AssetProcessor::register_processor`].
pub fn set_default_processor<P: Process>(&self, extension: &str) {
let mut default_processors = self
.data
.default_processors
.write()
.unwrap_or_else(PoisonError::into_inner);
let mut default_processors = self.data.default_processors.write();
default_processors.insert(extension.into(), core::any::type_name::<P>());
}

/// Returns the default processor for the given `extension`, if it exists.
pub fn get_default_processor(&self, extension: &str) -> Option<Arc<dyn ErasedProcessor>> {
let default_processors = self
.data
.default_processors
.read()
.unwrap_or_else(PoisonError::into_inner);
let default_processors = self.data.default_processors.read();
let key = default_processors.get(extension)?;
self.data
.processors
.read()
.unwrap_or_else(PoisonError::into_inner)
.get(key)
.cloned()
self.data.processors.read().get(key).cloned()
}

/// Returns the processor with the given `processor_type_name`, if it exists.
pub fn get_processor(&self, processor_type_name: &str) -> Option<Arc<dyn ErasedProcessor>> {
let processors = self
.data
.processors
.read()
.unwrap_or_else(PoisonError::into_inner);
let processors = self.data.processors.read();
processors.get(processor_type_name).cloned()
}

Expand Down
Loading