Remove thiserror from bevy_render (#15765)

# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_render`
This commit is contained in:
Zachary Harrold 2024-10-10 01:26:28 +11:00 committed by GitHub
parent 3cc1527e9e
commit 8718adc74f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 118 additions and 183 deletions

View File

@ -78,7 +78,11 @@ naga = { version = "22", features = ["wgsl-in"] }
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
bytemuck = { version = "1.5", features = ["derive", "must_cast"] } bytemuck = { version = "1.5", features = ["derive", "must_cast"] }
downcast-rs = "1.2.0" downcast-rs = "1.2.0"
thiserror = "1.0" derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
futures-lite = "2.0.1" futures-lite = "2.0.1"
ktx2 = { version = "0.3.0", optional = true } ktx2 = { version = "0.3.0", optional = true }
# For transcoding of UASTC/ETC1S universal formats, and for .basis file support # For transcoding of UASTC/ETC1S universal formats, and for .basis file support

View File

@ -37,6 +37,7 @@ use bevy_window::{
WindowScaleFactorChanged, WindowScaleFactorChanged,
}; };
use core::ops::Range; use core::ops::Range;
use derive_more::derive::From;
use wgpu::{BlendState, TextureFormat, TextureUsages}; use wgpu::{BlendState, TextureFormat, TextureUsages};
use super::{ClearColorConfig, Projection}; use super::{ClearColorConfig, Projection};
@ -710,7 +711,7 @@ impl CameraRenderGraph {
/// The "target" that a [`Camera`] will render to. For example, this could be a [`Window`] /// The "target" that a [`Camera`] will render to. For example, this could be a [`Window`]
/// swapchain or an [`Image`]. /// swapchain or an [`Image`].
#[derive(Debug, Clone, Reflect)] #[derive(Debug, Clone, Reflect, From)]
pub enum RenderTarget { pub enum RenderTarget {
/// Window to which the camera's view is rendered. /// Window to which the camera's view is rendered.
Window(WindowRef), Window(WindowRef),
@ -727,16 +728,10 @@ impl Default for RenderTarget {
} }
} }
impl From<Handle<Image>> for RenderTarget {
fn from(handle: Handle<Image>) -> Self {
Self::Image(handle)
}
}
/// Normalized version of the render target. /// Normalized version of the render target.
/// ///
/// Once we have this we shouldn't need to resolve it down anymore. /// Once we have this we shouldn't need to resolve it down anymore.
#[derive(Debug, Clone, Reflect, PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(Debug, Clone, Reflect, PartialEq, Eq, Hash, PartialOrd, Ord, From)]
pub enum NormalizedRenderTarget { pub enum NormalizedRenderTarget {
/// Window to which the camera's view is rendered. /// Window to which the camera's view is rendered.
Window(NormalizedWindowRef), Window(NormalizedWindowRef),

View File

@ -3,10 +3,11 @@ use bevy_color::Color;
use bevy_derive::{Deref, DerefMut}; use bevy_derive::{Deref, DerefMut};
use bevy_ecs::prelude::*; use bevy_ecs::prelude::*;
use bevy_reflect::prelude::*; use bevy_reflect::prelude::*;
use derive_more::derive::From;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// For a camera, specifies the color used to clear the viewport before rendering. /// For a camera, specifies the color used to clear the viewport before rendering.
#[derive(Reflect, Serialize, Deserialize, Copy, Clone, Debug, Default)] #[derive(Reflect, Serialize, Deserialize, Copy, Clone, Debug, Default, From)]
#[reflect(Serialize, Deserialize, Default)] #[reflect(Serialize, Deserialize, Default)]
pub enum ClearColorConfig { pub enum ClearColorConfig {
/// The clear color is taken from the world's [`ClearColor`] resource. /// The clear color is taken from the world's [`ClearColor`] resource.
@ -20,12 +21,6 @@ pub enum ClearColorConfig {
None, None,
} }
impl From<Color> for ClearColorConfig {
fn from(color: Color) -> Self {
Self::Custom(color)
}
}
/// A [`Resource`] that stores the color that is used to clear the screen between frames. /// A [`Resource`] that stores the color that is used to clear the screen between frames.
/// ///
/// This color appears as the "background" color for simple apps, /// This color appears as the "background" color for simple apps,

View File

@ -11,6 +11,7 @@ use bevy_reflect::{
std_traits::ReflectDefault, GetTypeRegistration, Reflect, ReflectDeserialize, ReflectSerialize, std_traits::ReflectDefault, GetTypeRegistration, Reflect, ReflectDeserialize, ReflectSerialize,
}; };
use bevy_transform::{components::GlobalTransform, TransformSystem}; use bevy_transform::{components::GlobalTransform, TransformSystem};
use derive_more::derive::From;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
/// Adds [`Camera`](crate::camera::Camera) driver systems for a given projection type. /// Adds [`Camera`](crate::camera::Camera) driver systems for a given projection type.
@ -98,25 +99,13 @@ pub trait CameraProjection {
} }
/// A configurable [`CameraProjection`] that can select its projection type at runtime. /// A configurable [`CameraProjection`] that can select its projection type at runtime.
#[derive(Component, Debug, Clone, Reflect)] #[derive(Component, Debug, Clone, Reflect, From)]
#[reflect(Component, Default, Debug)] #[reflect(Component, Default, Debug)]
pub enum Projection { pub enum Projection {
Perspective(PerspectiveProjection), Perspective(PerspectiveProjection),
Orthographic(OrthographicProjection), Orthographic(OrthographicProjection),
} }
impl From<PerspectiveProjection> for Projection {
fn from(p: PerspectiveProjection) -> Self {
Self::Perspective(p)
}
}
impl From<OrthographicProjection> for Projection {
fn from(p: OrthographicProjection) -> Self {
Self::Orthographic(p)
}
}
impl CameraProjection for Projection { impl CameraProjection for Projection {
fn get_clip_from_view(&self) -> Mat4 { fn get_clip_from_view(&self) -> Mat4 {
match self { match self {

View File

@ -4,6 +4,7 @@ use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{component::Component, reflect::ReflectComponent}; use bevy_ecs::{component::Component, reflect::ReflectComponent};
use bevy_reflect::{std_traits::ReflectDefault, Reflect}; use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_transform::components::Transform; use bevy_transform::components::Transform;
use derive_more::derive::From;
/// A component for rendering 2D meshes, typically with a [`MeshMaterial2d`] using a [`ColorMaterial`]. /// A component for rendering 2D meshes, typically with a [`MeshMaterial2d`] using a [`ColorMaterial`].
/// ///
@ -35,17 +36,11 @@ use bevy_transform::components::Transform;
/// )); /// ));
/// } /// }
/// ``` /// ```
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
#[reflect(Component, Default)] #[reflect(Component, Default)]
#[require(Transform, Visibility)] #[require(Transform, Visibility)]
pub struct Mesh2d(pub Handle<Mesh>); pub struct Mesh2d(pub Handle<Mesh>);
impl From<Handle<Mesh>> for Mesh2d {
fn from(handle: Handle<Mesh>) -> Self {
Self(handle)
}
}
impl From<Mesh2d> for AssetId<Mesh> { impl From<Mesh2d> for AssetId<Mesh> {
fn from(mesh: Mesh2d) -> Self { fn from(mesh: Mesh2d) -> Self {
mesh.id() mesh.id()
@ -91,17 +86,11 @@ impl From<&Mesh2d> for AssetId<Mesh> {
/// )); /// ));
/// } /// }
/// ``` /// ```
#[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq)] #[derive(Component, Clone, Debug, Default, Deref, DerefMut, Reflect, PartialEq, Eq, From)]
#[reflect(Component, Default)] #[reflect(Component, Default)]
#[require(Transform, Visibility)] #[require(Transform, Visibility)]
pub struct Mesh3d(pub Handle<Mesh>); pub struct Mesh3d(pub Handle<Mesh>);
impl From<Handle<Mesh>> for Mesh3d {
fn from(handle: Handle<Mesh>) -> Self {
Self(handle)
}
}
impl From<Mesh3d> for AssetId<Mesh> { impl From<Mesh3d> for AssetId<Mesh> {
fn from(mesh: Mesh3d) -> Self { fn from(mesh: Mesh3d) -> Self {
mesh.id() mesh.id()

View File

@ -16,13 +16,13 @@ use bevy_utils::{
HashMap, HashSet, HashMap, HashSet,
}; };
use core::marker::PhantomData; use core::marker::PhantomData;
use thiserror::Error; use derive_more::derive::{Display, Error};
#[derive(Debug, Error)] #[derive(Debug, Error, Display)]
pub enum PrepareAssetError<E: Send + Sync + 'static> { pub enum PrepareAssetError<E: Send + Sync + 'static> {
#[error("Failed to prepare asset")] #[display("Failed to prepare asset")]
RetryNextUpdate(E), RetryNextUpdate(E),
#[error("Failed to build bind group: {0}")] #[display("Failed to build bind group: {_0}")]
AsBindGroupError(AsBindGroupError), AsBindGroupError(AsBindGroupError),
} }

View File

@ -4,7 +4,7 @@ use crate::{
}; };
use alloc::borrow::Cow; use alloc::borrow::Cow;
use bevy_ecs::entity::Entity; use bevy_ecs::entity::Entity;
use thiserror::Error; use derive_more::derive::{Display, Error};
use super::{InternedRenderSubGraph, RenderSubGraph}; use super::{InternedRenderSubGraph, RenderSubGraph};
@ -231,19 +231,21 @@ impl<'a> RenderGraphContext<'a> {
} }
} }
#[derive(Error, Debug, Eq, PartialEq)] #[derive(Error, Display, Debug, Eq, PartialEq)]
pub enum RunSubGraphError { pub enum RunSubGraphError {
#[error("attempted to run sub-graph `{0:?}`, but it does not exist")] #[display("attempted to run sub-graph `{_0:?}`, but it does not exist")]
#[error(ignore)]
MissingSubGraph(InternedRenderSubGraph), MissingSubGraph(InternedRenderSubGraph),
#[error("attempted to pass inputs to sub-graph `{0:?}`, which has no input slots")] #[display("attempted to pass inputs to sub-graph `{_0:?}`, which has no input slots")]
#[error(ignore)]
SubGraphHasNoInputs(InternedRenderSubGraph), SubGraphHasNoInputs(InternedRenderSubGraph),
#[error("sub graph (name: `{graph_name:?}`) could not be run because slot `{slot_name}` at index {slot_index} has no value")] #[display("sub graph (name: `{graph_name:?}`) could not be run because slot `{slot_name}` at index {slot_index} has no value")]
MissingInput { MissingInput {
slot_index: usize, slot_index: usize,
slot_name: Cow<'static, str>, slot_name: Cow<'static, str>,
graph_name: InternedRenderSubGraph, graph_name: InternedRenderSubGraph,
}, },
#[error("attempted to use the wrong type for input slot")] #[display("attempted to use the wrong type for input slot")]
MismatchedInputSlotType { MismatchedInputSlotType {
graph_name: InternedRenderSubGraph, graph_name: InternedRenderSubGraph,
slot_index: usize, slot_index: usize,
@ -253,11 +255,12 @@ pub enum RunSubGraphError {
}, },
} }
#[derive(Error, Debug, Eq, PartialEq)] #[derive(Error, Display, Debug, Eq, PartialEq)]
pub enum OutputSlotError { pub enum OutputSlotError {
#[error("output slot `{0:?}` does not exist")] #[display("output slot `{_0:?}` does not exist")]
#[error(ignore)]
InvalidSlot(SlotLabel), InvalidSlot(SlotLabel),
#[error("attempted to output a value of type `{actual}` to output slot `{label:?}`, which has type `{expected}`")] #[display("attempted to output a value of type `{actual}` to output slot `{label:?}`, which has type `{expected}`")]
MismatchedSlotType { MismatchedSlotType {
label: SlotLabel, label: SlotLabel,
expected: SlotType, expected: SlotType,
@ -265,11 +268,12 @@ pub enum OutputSlotError {
}, },
} }
#[derive(Error, Debug, Eq, PartialEq)] #[derive(Error, Display, Debug, Eq, PartialEq)]
pub enum InputSlotError { pub enum InputSlotError {
#[error("input slot `{0:?}` does not exist")] #[display("input slot `{_0:?}` does not exist")]
#[error(ignore)]
InvalidSlot(SlotLabel), InvalidSlot(SlotLabel),
#[error("attempted to retrieve a value of type `{actual}` from input slot `{label:?}`, which has type `{expected}`")] #[display("attempted to retrieve a value of type `{actual}` from input slot `{label:?}`, which has type `{expected}`")]
MismatchedSlotType { MismatchedSlotType {
label: SlotLabel, label: SlotLabel,
expected: SlotType, expected: SlotType,

View File

@ -12,40 +12,45 @@ pub use graph::*;
pub use node::*; pub use node::*;
pub use node_slot::*; pub use node_slot::*;
use thiserror::Error; use derive_more::derive::{Display, Error};
#[derive(Error, Debug, Eq, PartialEq)] #[derive(Error, Display, Debug, Eq, PartialEq)]
pub enum RenderGraphError { pub enum RenderGraphError {
#[error("node {0:?} does not exist")] #[display("node {_0:?} does not exist")]
#[error(ignore)]
InvalidNode(InternedRenderLabel), InvalidNode(InternedRenderLabel),
#[error("output node slot does not exist")] #[display("output node slot does not exist")]
#[error(ignore)]
InvalidOutputNodeSlot(SlotLabel), InvalidOutputNodeSlot(SlotLabel),
#[error("input node slot does not exist")] #[display("input node slot does not exist")]
#[error(ignore)]
InvalidInputNodeSlot(SlotLabel), InvalidInputNodeSlot(SlotLabel),
#[error("node does not match the given type")] #[display("node does not match the given type")]
WrongNodeType, WrongNodeType,
#[error("attempted to connect output slot {output_slot} from node {output_node:?} to incompatible input slot {input_slot} from node {input_node:?}")] #[display("attempted to connect output slot {output_slot} from node {output_node:?} to incompatible input slot {input_slot} from node {input_node:?}")]
MismatchedNodeSlots { MismatchedNodeSlots {
output_node: InternedRenderLabel, output_node: InternedRenderLabel,
output_slot: usize, output_slot: usize,
input_node: InternedRenderLabel, input_node: InternedRenderLabel,
input_slot: usize, input_slot: usize,
}, },
#[error("attempted to add an edge that already exists")] #[display("attempted to add an edge that already exists")]
#[error(ignore)]
EdgeAlreadyExists(Edge), EdgeAlreadyExists(Edge),
#[error("attempted to remove an edge that does not exist")] #[display("attempted to remove an edge that does not exist")]
#[error(ignore)]
EdgeDoesNotExist(Edge), EdgeDoesNotExist(Edge),
#[error("node {node:?} has an unconnected input slot {input_slot}")] #[display("node {node:?} has an unconnected input slot {input_slot}")]
UnconnectedNodeInputSlot { UnconnectedNodeInputSlot {
node: InternedRenderLabel, node: InternedRenderLabel,
input_slot: usize, input_slot: usize,
}, },
#[error("node {node:?} has an unconnected output slot {output_slot}")] #[display("node {node:?} has an unconnected output slot {output_slot}")]
UnconnectedNodeOutputSlot { UnconnectedNodeOutputSlot {
node: InternedRenderLabel, node: InternedRenderLabel,
output_slot: usize, output_slot: usize,
}, },
#[error("node {node:?} input slot {input_slot} already occupied by {occupied_by_node:?}")] #[display("node {node:?} input slot {input_slot} already occupied by {occupied_by_node:?}")]
NodeInputSlotAlreadyOccupied { NodeInputSlotAlreadyOccupied {
node: InternedRenderLabel, node: InternedRenderLabel,
input_slot: usize, input_slot: usize,

View File

@ -15,8 +15,8 @@ use bevy_ecs::{
}; };
use bevy_utils::all_tuples_with_size; use bevy_utils::all_tuples_with_size;
use core::fmt::Debug; use core::fmt::Debug;
use derive_more::derive::{Display, Error, From};
use downcast_rs::{impl_downcast, Downcast}; use downcast_rs::{impl_downcast, Downcast};
use thiserror::Error;
pub use bevy_render_macros::RenderLabel; pub use bevy_render_macros::RenderLabel;
@ -90,16 +90,16 @@ pub trait Node: Downcast + Send + Sync + 'static {
impl_downcast!(Node); impl_downcast!(Node);
#[derive(Error, Debug, Eq, PartialEq)] #[derive(Error, Display, Debug, Eq, PartialEq, From)]
pub enum NodeRunError { pub enum NodeRunError {
#[error("encountered an input slot error")] #[display("encountered an input slot error")]
InputSlotError(#[from] InputSlotError), InputSlotError(InputSlotError),
#[error("encountered an output slot error")] #[display("encountered an output slot error")]
OutputSlotError(#[from] OutputSlotError), OutputSlotError(OutputSlotError),
#[error("encountered an error when running a sub-graph")] #[display("encountered an error when running a sub-graph")]
RunSubGraphError(#[from] RunSubGraphError), RunSubGraphError(RunSubGraphError),
#[error("encountered an error when executing draw command")] #[display("encountered an error when executing draw command")]
DrawError(#[from] DrawError), DrawError(DrawError),
} }
/// A collection of input and output [`Edges`](Edge) for a [`Node`]. /// A collection of input and output [`Edges`](Edge) for a [`Node`].

View File

@ -1,6 +1,7 @@
use alloc::borrow::Cow; use alloc::borrow::Cow;
use bevy_ecs::entity::Entity; use bevy_ecs::entity::Entity;
use core::fmt; use core::fmt;
use derive_more::derive::From;
use crate::render_resource::{Buffer, Sampler, TextureView}; use crate::render_resource::{Buffer, Sampler, TextureView};
@ -11,7 +12,7 @@ use crate::render_resource::{Buffer, Sampler, TextureView};
/// [`Buffer`], [`TextureView`], [`Sampler`] and [`Entity`]. /// [`Buffer`], [`TextureView`], [`Sampler`] and [`Entity`].
/// ///
/// These values do not contain the actual render data, but only the ids to retrieve them. /// These values do not contain the actual render data, but only the ids to retrieve them.
#[derive(Debug, Clone)] #[derive(Debug, Clone, From)]
pub enum SlotValue { pub enum SlotValue {
/// A GPU-accessible [`Buffer`]. /// A GPU-accessible [`Buffer`].
Buffer(Buffer), Buffer(Buffer),
@ -35,30 +36,6 @@ impl SlotValue {
} }
} }
impl From<Buffer> for SlotValue {
fn from(value: Buffer) -> Self {
SlotValue::Buffer(value)
}
}
impl From<TextureView> for SlotValue {
fn from(value: TextureView) -> Self {
SlotValue::TextureView(value)
}
}
impl From<Sampler> for SlotValue {
fn from(value: Sampler) -> Self {
SlotValue::Sampler(value)
}
}
impl From<Entity> for SlotValue {
fn from(value: Entity) -> Self {
SlotValue::Entity(value)
}
}
/// Describes the render resources created (output) or used (input) by /// Describes the render resources created (output) or used (input) by
/// the render [`Nodes`](super::Node). /// the render [`Nodes`](super::Node).
/// ///
@ -90,7 +67,7 @@ impl fmt::Display for SlotType {
/// A [`SlotLabel`] is used to reference a slot by either its name or index /// A [`SlotLabel`] is used to reference a slot by either its name or index
/// inside the [`RenderGraph`](super::RenderGraph). /// inside the [`RenderGraph`](super::RenderGraph).
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq, From)]
pub enum SlotLabel { pub enum SlotLabel {
Index(usize), Index(usize),
Name(Cow<'static, str>), Name(Cow<'static, str>),
@ -114,18 +91,6 @@ impl From<&'static str> for SlotLabel {
} }
} }
impl From<Cow<'static, str>> for SlotLabel {
fn from(value: Cow<'static, str>) -> Self {
SlotLabel::Name(value)
}
}
impl From<usize> for SlotLabel {
fn from(value: usize) -> Self {
SlotLabel::Index(value)
}
}
/// The internal representation of a slot, which specifies its [`SlotType`] and name. /// The internal representation of a slot, which specifies its [`SlotType`] and name.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct SlotInfo { pub struct SlotInfo {

View File

@ -8,8 +8,8 @@ use bevy_ecs::{
}; };
use bevy_utils::{all_tuples, TypeIdMap}; use bevy_utils::{all_tuples, TypeIdMap};
use core::{any::TypeId, fmt::Debug, hash::Hash}; use core::{any::TypeId, fmt::Debug, hash::Hash};
use derive_more::derive::{Display, Error};
use std::sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard}; use std::sync::{PoisonError, RwLock, RwLockReadGuard, RwLockWriteGuard};
use thiserror::Error;
/// A draw function used to draw [`PhaseItem`]s. /// A draw function used to draw [`PhaseItem`]s.
/// ///
@ -34,13 +34,14 @@ pub trait Draw<P: PhaseItem>: Send + Sync + 'static {
) -> Result<(), DrawError>; ) -> Result<(), DrawError>;
} }
#[derive(Error, Debug, PartialEq, Eq)] #[derive(Error, Display, Debug, PartialEq, Eq)]
pub enum DrawError { pub enum DrawError {
#[error("Failed to execute render command {0:?}")] #[display("Failed to execute render command {_0:?}")]
#[error(ignore)]
RenderCommandFailure(&'static str), RenderCommandFailure(&'static str),
#[error("Failed to get execute view query")] #[display("Failed to get execute view query")]
InvalidViewQuery, InvalidViewQuery,
#[error("View entity not found")] #[display("View entity not found")]
ViewEntityNotFound, ViewEntityNotFound,
} }

View File

@ -10,8 +10,8 @@ use alloc::sync::Arc;
use bevy_ecs::system::{SystemParam, SystemParamItem}; use bevy_ecs::system::{SystemParam, SystemParamItem};
pub use bevy_render_macros::AsBindGroup; pub use bevy_render_macros::AsBindGroup;
use core::ops::Deref; use core::ops::Deref;
use derive_more::derive::{Display, Error};
use encase::ShaderType; use encase::ShaderType;
use thiserror::Error;
use wgpu::{BindGroupEntry, BindGroupLayoutEntry, BindingResource}; use wgpu::{BindGroupEntry, BindGroupLayoutEntry, BindingResource};
define_atomic_id!(BindGroupId); define_atomic_id!(BindGroupId);
@ -354,12 +354,12 @@ pub trait AsBindGroup {
} }
/// An error that occurs during [`AsBindGroup::as_bind_group`] calls. /// An error that occurs during [`AsBindGroup::as_bind_group`] calls.
#[derive(Debug, Error)] #[derive(Debug, Error, Display)]
pub enum AsBindGroupError { pub enum AsBindGroupError {
/// The bind group could not be generated. Try again next frame. /// The bind group could not be generated. Try again next frame.
#[error("The bind group could not be generated")] #[display("The bind group could not be generated")]
RetryNextUpdate, RetryNextUpdate,
#[error("At binding index{0}, the provided image sampler `{1}` does not match the required sampler type(s) `{2}`.")] #[display("At binding index{0}, the provided image sampler `{_1}` does not match the required sampler type(s) `{_2}`.")]
InvalidSamplerType(u32, String, String), InvalidSamplerType(u32, String, String),
} }

View File

@ -18,9 +18,9 @@ use bevy_utils::{
HashMap, HashSet, HashMap, HashSet,
}; };
use core::{future::Future, hash::Hash, mem, ops::Deref}; use core::{future::Future, hash::Hash, mem, ops::Deref};
use derive_more::derive::{Display, Error, From};
use naga::valid::Capabilities; use naga::valid::Capabilities;
use std::sync::{Mutex, PoisonError}; use std::sync::{Mutex, PoisonError};
use thiserror::Error;
#[cfg(feature = "shader_format_spirv")] #[cfg(feature = "shader_format_spirv")]
use wgpu::util::make_spirv; use wgpu::util::make_spirv;
use wgpu::{ use wgpu::{
@ -973,17 +973,19 @@ fn create_pipeline_task(
} }
/// Type of error returned by a [`PipelineCache`] when the creation of a GPU pipeline object failed. /// Type of error returned by a [`PipelineCache`] when the creation of a GPU pipeline object failed.
#[derive(Error, Debug)] #[derive(Error, Display, Debug, From)]
pub enum PipelineCacheError { pub enum PipelineCacheError {
#[error( #[display(
"Pipeline could not be compiled because the following shader could not be loaded: {0:?}" "Pipeline could not be compiled because the following shader could not be loaded: {_0:?}"
)] )]
#[error(ignore)]
ShaderNotLoaded(AssetId<Shader>), ShaderNotLoaded(AssetId<Shader>),
#[error(transparent)]
ProcessShaderError(#[from] naga_oil::compose::ComposerError), ProcessShaderError(naga_oil::compose::ComposerError),
#[error("Shader import not yet available.")] #[display("Shader import not yet available.")]
ShaderImportNotYetAvailable, ShaderImportNotYetAvailable,
#[error("Could not create shader module: {0}")] #[display("Could not create shader module: {_0}")]
#[error(ignore)]
CreateShaderModule(String), CreateShaderModule(String),
} }

View File

@ -13,7 +13,7 @@ use bevy_utils::{
Entry, HashMap, Entry, HashMap,
}; };
use core::{fmt::Debug, hash::Hash}; use core::{fmt::Debug, hash::Hash};
use thiserror::Error; use derive_more::derive::{Display, Error, From};
pub trait SpecializedRenderPipeline { pub trait SpecializedRenderPipeline {
type Key: Clone + Hash + PartialEq + Eq; type Key: Clone + Hash + PartialEq + Eq;
@ -183,8 +183,7 @@ impl<S: SpecializedMeshPipeline> SpecializedMeshPipelines<S> {
} }
} }
#[derive(Error, Debug)] #[derive(Error, Display, Debug, From)]
pub enum SpecializedMeshPipelineError { pub enum SpecializedMeshPipelineError {
#[error(transparent)] MissingVertexAttribute(MissingVertexAttributeError),
MissingVertexAttribute(#[from] MissingVertexAttributeError),
} }

View File

@ -3,24 +3,21 @@ use crate::define_atomic_id;
use alloc::borrow::Cow; use alloc::borrow::Cow;
use bevy_asset::{io::Reader, Asset, AssetLoader, AssetPath, Handle, LoadContext}; use bevy_asset::{io::Reader, Asset, AssetLoader, AssetPath, Handle, LoadContext};
use bevy_reflect::TypePath; use bevy_reflect::TypePath;
use bevy_utils::tracing::error;
use core::marker::Copy; use core::marker::Copy;
use thiserror::Error; use derive_more::derive::{Display, Error, From};
define_atomic_id!(ShaderId); define_atomic_id!(ShaderId);
#[derive(Error, Debug)] #[derive(Error, Display, Debug, From)]
pub enum ShaderReflectError { pub enum ShaderReflectError {
#[error(transparent)] WgslParse(naga::front::wgsl::ParseError),
WgslParse(#[from] naga::front::wgsl::ParseError),
#[cfg(feature = "shader_format_glsl")] #[cfg(feature = "shader_format_glsl")]
#[error("GLSL Parse Error: {0:?}")] #[display("GLSL Parse Error: {_0:?}")]
#[error(ignore)]
GlslParse(Vec<naga::front::glsl::Error>), GlslParse(Vec<naga::front::glsl::Error>),
#[cfg(feature = "shader_format_spirv")] #[cfg(feature = "shader_format_spirv")]
#[error(transparent)] SpirVParse(naga::front::spv::Error),
SpirVParse(#[from] naga::front::spv::Error), Validation(naga::WithSpan<naga::valid::ValidationError>),
#[error(transparent)]
Validation(#[from] naga::WithSpan<naga::valid::ValidationError>),
} }
/// A shader, as defined by its [`ShaderSource`](wgpu::ShaderSource) and [`ShaderStage`](naga::ShaderStage) /// A shader, as defined by its [`ShaderSource`](wgpu::ShaderSource) and [`ShaderStage`](naga::ShaderStage)
/// This is an "unprocessed" shader. It can contain preprocessor directives. /// This is an "unprocessed" shader. It can contain preprocessor directives.
@ -247,12 +244,12 @@ impl From<&Source> for naga_oil::compose::ShaderType {
pub struct ShaderLoader; pub struct ShaderLoader;
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Error)] #[derive(Debug, Error, Display, From)]
pub enum ShaderLoaderError { pub enum ShaderLoaderError {
#[error("Could not load shader: {0}")] #[display("Could not load shader: {_0}")]
Io(#[from] std::io::Error), Io(std::io::Error),
#[error("Could not parse shader: {0}")] #[display("Could not parse shader: {_0}")]
Parse(#[from] alloc::string::FromUtf8Error), Parse(alloc::string::FromUtf8Error),
} }
impl AssetLoader for ShaderLoader { impl AssetLoader for ShaderLoader {

View File

@ -4,8 +4,8 @@ use bevy_utils::tracing::info_span;
use bevy_utils::HashMap; use bevy_utils::HashMap;
use alloc::{borrow::Cow, collections::VecDeque}; use alloc::{borrow::Cow, collections::VecDeque};
use derive_more::derive::{Display, Error, From};
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use thiserror::Error;
use crate::{ use crate::{
diagnostic::internal::{DiagnosticsRecorder, RenderDiagnosticsMutex}, diagnostic::internal::{DiagnosticsRecorder, RenderDiagnosticsMutex},
@ -29,30 +29,29 @@ use crate::{
/// [`CommandBuffer`]: wgpu::CommandBuffer /// [`CommandBuffer`]: wgpu::CommandBuffer
pub(crate) struct RenderGraphRunner; pub(crate) struct RenderGraphRunner;
#[derive(Error, Debug)] #[derive(Error, Display, Debug, From)]
pub enum RenderGraphRunnerError { pub enum RenderGraphRunnerError {
#[error(transparent)] NodeRunError(NodeRunError),
NodeRunError(#[from] NodeRunError), #[display("node output slot not set (index {slot_index}, name {slot_name})")]
#[error("node output slot not set (index {slot_index}, name {slot_name})")]
EmptyNodeOutputSlot { EmptyNodeOutputSlot {
type_name: &'static str, type_name: &'static str,
slot_index: usize, slot_index: usize,
slot_name: Cow<'static, str>, slot_name: Cow<'static, str>,
}, },
#[error("graph '{sub_graph:?}' could not be run because slot '{slot_name}' at index {slot_index} has no value")] #[display("graph '{sub_graph:?}' could not be run because slot '{slot_name}' at index {slot_index} has no value")]
MissingInput { MissingInput {
slot_index: usize, slot_index: usize,
slot_name: Cow<'static, str>, slot_name: Cow<'static, str>,
sub_graph: Option<InternedRenderSubGraph>, sub_graph: Option<InternedRenderSubGraph>,
}, },
#[error("attempted to use the wrong type for input slot")] #[display("attempted to use the wrong type for input slot")]
MismatchedInputSlotType { MismatchedInputSlotType {
slot_index: usize, slot_index: usize,
label: SlotLabel, label: SlotLabel,
expected: SlotType, expected: SlotType,
actual: SlotType, actual: SlotType,
}, },
#[error( #[display(
"node (name: '{node_name:?}') has {slot_count} input slots, but was provided {value_count} values" "node (name: '{node_name:?}') has {slot_count} input slots, but was provided {value_count} values"
)] )]
MismatchedInputCount { MismatchedInputCount {

View File

@ -1,15 +1,14 @@
use super::{Image, ImageFormat, ImageFormatSetting, ImageLoader, ImageLoaderSettings}; use super::{Image, ImageFormat, ImageFormatSetting, ImageLoader, ImageLoaderSettings};
use bevy_asset::saver::{AssetSaver, SavedAsset}; use bevy_asset::saver::{AssetSaver, SavedAsset};
use derive_more::derive::{Display, Error, From};
use futures_lite::AsyncWriteExt; use futures_lite::AsyncWriteExt;
use thiserror::Error;
pub struct CompressedImageSaver; pub struct CompressedImageSaver;
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Error)] #[derive(Debug, Error, Display, From)]
pub enum CompressedImageSaverError { pub enum CompressedImageSaverError {
#[error(transparent)] Io(std::io::Error),
Io(#[from] std::io::Error),
} }
impl AssetSaver for CompressedImageSaver { impl AssetSaver for CompressedImageSaver {

View File

@ -1,6 +1,6 @@
use bevy_asset::{io::Reader, AssetLoader, LoadContext}; use bevy_asset::{io::Reader, AssetLoader, LoadContext};
use bevy_ecs::prelude::{FromWorld, World}; use bevy_ecs::prelude::{FromWorld, World};
use thiserror::Error; use derive_more::derive::{Display, Error, From};
use crate::{ use crate::{
render_asset::RenderAssetUsages, render_asset::RenderAssetUsages,
@ -45,12 +45,12 @@ impl Default for ImageLoaderSettings {
} }
#[non_exhaustive] #[non_exhaustive]
#[derive(Debug, Error)] #[derive(Debug, Error, Display, From)]
pub enum ImageLoaderError { pub enum ImageLoaderError {
#[error("Could load shader: {0}")] #[display("Could load shader: {_0}")]
Io(#[from] std::io::Error), Io(std::io::Error),
#[error("Could not load texture file: {0}")] #[display("Could not load texture file: {_0}")]
FileTexture(#[from] FileTextureError), FileTexture(FileTextureError),
} }
impl AssetLoader for ImageLoader { impl AssetLoader for ImageLoader {
@ -120,17 +120,9 @@ impl FromWorld for ImageLoader {
} }
/// An error that occurs when loading a texture from a file. /// An error that occurs when loading a texture from a file.
#[derive(Error, Debug)] #[derive(Error, Display, Debug)]
#[display("Error reading image file {path}: {error}, this is an error in `bevy_render`.")]
pub struct FileTextureError { pub struct FileTextureError {
error: TextureError, error: TextureError,
path: String, path: String,
} }
impl core::fmt::Display for FileTextureError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> Result<(), core::fmt::Error> {
write!(
f,
"Error reading image file {}: {}, this is an error in `bevy_render`.",
self.path, self.error
)
}
}