Skip to content

Commit

Permalink
Remove thiserror from bevy_render (#15765)
Browse files Browse the repository at this point in the history
# Objective

- Contributes to #15460

## Solution

- Removed `thiserror` from `bevy_render`
  • Loading branch information
bushrat011899 authored Oct 9, 2024
1 parent 3cc1527 commit 8718adc
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 183 deletions.
6 changes: 5 additions & 1 deletion crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ naga = { version = "22", features = ["wgsl-in"] }
serde = { version = "1", features = ["derive"] }
bytemuck = { version = "1.5", features = ["derive", "must_cast"] }
downcast-rs = "1.2.0"
thiserror = "1.0"
derive_more = { version = "1", default-features = false, features = [
"error",
"from",
"display",
] }
futures-lite = "2.0.1"
ktx2 = { version = "0.3.0", optional = true }
# For transcoding of UASTC/ETC1S universal formats, and for .basis file support
Expand Down
11 changes: 3 additions & 8 deletions crates/bevy_render/src/camera/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ use bevy_window::{
WindowScaleFactorChanged,
};
use core::ops::Range;
use derive_more::derive::From;
use wgpu::{BlendState, TextureFormat, TextureUsages};

use super::{ClearColorConfig, Projection};
Expand Down Expand Up @@ -710,7 +711,7 @@ impl CameraRenderGraph {

/// The "target" that a [`Camera`] will render to. For example, this could be a [`Window`]
/// swapchain or an [`Image`].
#[derive(Debug, Clone, Reflect)]
#[derive(Debug, Clone, Reflect, From)]
pub enum RenderTarget {
/// Window to which the camera's view is rendered.
Window(WindowRef),
Expand All @@ -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.
///
/// 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 {
/// Window to which the camera's view is rendered.
Window(NormalizedWindowRef),
Expand Down
9 changes: 2 additions & 7 deletions crates/bevy_render/src/camera/clear_color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ use bevy_color::Color;
use bevy_derive::{Deref, DerefMut};
use bevy_ecs::prelude::*;
use bevy_reflect::prelude::*;
use derive_more::derive::From;
use serde::{Deserialize, Serialize};

/// 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)]
pub enum ClearColorConfig {
/// The clear color is taken from the world's [`ClearColor`] resource.
Expand All @@ -20,12 +21,6 @@ pub enum ClearColorConfig {
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.
///
/// This color appears as the "background" color for simple apps,
Expand Down
15 changes: 2 additions & 13 deletions crates/bevy_render/src/camera/projection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use bevy_reflect::{
std_traits::ReflectDefault, GetTypeRegistration, Reflect, ReflectDeserialize, ReflectSerialize,
};
use bevy_transform::{components::GlobalTransform, TransformSystem};
use derive_more::derive::From;
use serde::{Deserialize, Serialize};

/// Adds [`Camera`](crate::camera::Camera) driver systems for a given projection type.
Expand Down Expand Up @@ -98,25 +99,13 @@ pub trait CameraProjection {
}

/// 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)]
pub enum Projection {
Perspective(PerspectiveProjection),
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 {
fn get_clip_from_view(&self) -> Mat4 {
match self {
Expand Down
17 changes: 3 additions & 14 deletions crates/bevy_render/src/mesh/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use bevy_derive::{Deref, DerefMut};
use bevy_ecs::{component::Component, reflect::ReflectComponent};
use bevy_reflect::{std_traits::ReflectDefault, Reflect};
use bevy_transform::components::Transform;
use derive_more::derive::From;

/// A component for rendering 2D meshes, typically with a [`MeshMaterial2d`] using a [`ColorMaterial`].
///
Expand Down Expand Up @@ -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)]
#[require(Transform, Visibility)]
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> {
fn from(mesh: Mesh2d) -> Self {
mesh.id()
Expand Down Expand Up @@ -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)]
#[require(Transform, Visibility)]
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> {
fn from(mesh: Mesh3d) -> Self {
mesh.id()
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_render/src/render_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ use bevy_utils::{
HashMap, HashSet,
};
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> {
#[error("Failed to prepare asset")]
#[display("Failed to prepare asset")]
RetryNextUpdate(E),
#[error("Failed to build bind group: {0}")]
#[display("Failed to build bind group: {_0}")]
AsBindGroupError(AsBindGroupError),
}

Expand Down
28 changes: 16 additions & 12 deletions crates/bevy_render/src/render_graph/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
};
use alloc::borrow::Cow;
use bevy_ecs::entity::Entity;
use thiserror::Error;
use derive_more::derive::{Display, Error};

use super::{InternedRenderSubGraph, RenderSubGraph};

Expand Down Expand Up @@ -231,19 +231,21 @@ impl<'a> RenderGraphContext<'a> {
}
}

#[derive(Error, Debug, Eq, PartialEq)]
#[derive(Error, Display, Debug, Eq, PartialEq)]
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),
#[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),
#[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 {
slot_index: usize,
slot_name: Cow<'static, str>,
graph_name: InternedRenderSubGraph,
},
#[error("attempted to use the wrong type for input slot")]
#[display("attempted to use the wrong type for input slot")]
MismatchedInputSlotType {
graph_name: InternedRenderSubGraph,
slot_index: usize,
Expand All @@ -253,23 +255,25 @@ pub enum RunSubGraphError {
},
}

#[derive(Error, Debug, Eq, PartialEq)]
#[derive(Error, Display, Debug, Eq, PartialEq)]
pub enum OutputSlotError {
#[error("output slot `{0:?}` does not exist")]
#[display("output slot `{_0:?}` does not exist")]
#[error(ignore)]
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 {
label: SlotLabel,
expected: SlotType,
actual: SlotType,
},
}

#[derive(Error, Debug, Eq, PartialEq)]
#[derive(Error, Display, Debug, Eq, PartialEq)]
pub enum InputSlotError {
#[error("input slot `{0:?}` does not exist")]
#[display("input slot `{_0:?}` does not exist")]
#[error(ignore)]
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 {
label: SlotLabel,
expected: SlotType,
Expand Down
29 changes: 17 additions & 12 deletions crates/bevy_render/src/render_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,45 @@ pub use graph::*;
pub use node::*;
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 {
#[error("node {0:?} does not exist")]
#[display("node {_0:?} does not exist")]
#[error(ignore)]
InvalidNode(InternedRenderLabel),
#[error("output node slot does not exist")]
#[display("output node slot does not exist")]
#[error(ignore)]
InvalidOutputNodeSlot(SlotLabel),
#[error("input node slot does not exist")]
#[display("input node slot does not exist")]
#[error(ignore)]
InvalidInputNodeSlot(SlotLabel),
#[error("node does not match the given type")]
#[display("node does not match the given type")]
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 {
output_node: InternedRenderLabel,
output_slot: usize,
input_node: InternedRenderLabel,
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),
#[error("attempted to remove an edge that does not exist")]
#[display("attempted to remove an edge that does not exist")]
#[error(ignore)]
EdgeDoesNotExist(Edge),
#[error("node {node:?} has an unconnected input slot {input_slot}")]
#[display("node {node:?} has an unconnected input slot {input_slot}")]
UnconnectedNodeInputSlot {
node: InternedRenderLabel,
input_slot: usize,
},
#[error("node {node:?} has an unconnected output slot {output_slot}")]
#[display("node {node:?} has an unconnected output slot {output_slot}")]
UnconnectedNodeOutputSlot {
node: InternedRenderLabel,
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 {
node: InternedRenderLabel,
input_slot: usize,
Expand Down
20 changes: 10 additions & 10 deletions crates/bevy_render/src/render_graph/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use bevy_ecs::{
};
use bevy_utils::all_tuples_with_size;
use core::fmt::Debug;
use derive_more::derive::{Display, Error, From};
use downcast_rs::{impl_downcast, Downcast};
use thiserror::Error;

pub use bevy_render_macros::RenderLabel;

Expand Down Expand Up @@ -90,16 +90,16 @@ pub trait Node: Downcast + Send + Sync + 'static {

impl_downcast!(Node);

#[derive(Error, Debug, Eq, PartialEq)]
#[derive(Error, Display, Debug, Eq, PartialEq, From)]
pub enum NodeRunError {
#[error("encountered an input slot error")]
InputSlotError(#[from] InputSlotError),
#[error("encountered an output slot error")]
OutputSlotError(#[from] OutputSlotError),
#[error("encountered an error when running a sub-graph")]
RunSubGraphError(#[from] RunSubGraphError),
#[error("encountered an error when executing draw command")]
DrawError(#[from] DrawError),
#[display("encountered an input slot error")]
InputSlotError(InputSlotError),
#[display("encountered an output slot error")]
OutputSlotError(OutputSlotError),
#[display("encountered an error when running a sub-graph")]
RunSubGraphError(RunSubGraphError),
#[display("encountered an error when executing draw command")]
DrawError(DrawError),
}

/// A collection of input and output [`Edges`](Edge) for a [`Node`].
Expand Down
Loading

0 comments on commit 8718adc

Please sign in to comment.