Skip to main content

wgpu_3dgs_core/
error.rs

1use thiserror::Error;
2
3use crate::{SpzGaussianPosition, SpzGaussianRotation, SpzGaussianSh, SpzGaussianShDegree};
4
5/// The error type for [`SpzGaussians::from_iter`](crate::SpzGaussians::from_iter).
6#[derive(Debug, Error)]
7pub enum SpzGaussiansFromIterError {
8    #[error("invalid mixed position variant: {0:?}")]
9    InvalidMixedPositionVariant(SpzGaussiansCollectError<SpzGaussianPosition>),
10    #[error("invalid mixed rotation variant: {0:?}")]
11    InvalidMixedRotationVariant(SpzGaussiansCollectError<SpzGaussianRotation>),
12    #[error("invalid mixed SH variant: {0:?}")]
13    InvalidMixedShVariant(SpzGaussiansCollectError<SpzGaussianSh>),
14    #[error("Gaussians count mismatch: {actual_count} != {header_count}")]
15    CountMismatch {
16        actual_count: usize,
17        header_count: usize,
18    },
19    #[error("Position float16 format mismatch: {is_float16} != {header_uses_float16}")]
20    PositionFloat16Mismatch {
21        is_float16: bool,
22        header_uses_float16: bool,
23    },
24    #[error(
25        "Rotation smallest three format mismatch: \
26        {is_quat_smallest_three} != {header_uses_quat_smallest_three}\
27        "
28    )]
29    RotationQuatSmallestThreeMismatch {
30        is_quat_smallest_three: bool,
31        header_uses_quat_smallest_three: bool,
32    },
33    #[error("SH degree mismatch: {sh_degree:?} != {header_sh_degree:?}")]
34    ShDegreeMismatch {
35        sh_degree: SpzGaussianShDegree,
36        header_sh_degree: SpzGaussianShDegree,
37    },
38    #[error("{0}")]
39    Io(#[from] std::io::Error),
40}
41
42/// The error type for collecting SPZ Gaussians.
43#[derive(Debug, Error)]
44pub enum SpzGaussiansCollectError<T> {
45    #[error("invalid mixed variant: {first_variant} != {current_variant}")]
46    InvalidMixedVariant {
47        first_variant: T,
48        current_variant: T,
49    },
50    #[error("empty iterator")]
51    EmptyIterator,
52}
53
54/// The error type for downloading buffer.
55#[derive(Debug, Error)]
56pub enum DownloadBufferError {
57    #[error("{0}")]
58    OneShotRecv(#[from] oneshot::RecvError),
59    #[error("{0}")]
60    Async(#[from] wgpu::BufferAsyncError),
61    #[error("{0}")]
62    Poll(#[from] wgpu::PollError),
63    #[error("{0}")]
64    MapRange(#[from] wgpu::MapRangeError),
65}
66
67/// The error type for [`GaussiansBuffer`](crate::GaussiansBuffer) update functions.
68#[derive(Debug, Error)]
69pub enum GaussiansBufferUpdateError {
70    #[error("Gaussians count mismatch: {count} != {expected_count}")]
71    CountMismatch { count: usize, expected_count: usize },
72}
73
74/// The error type for [`GaussiansBuffer`](crate::GaussiansBuffer) update range functions.
75#[derive(Debug, Error)]
76pub enum GaussiansBufferUpdateRangeError {
77    #[error("Gaussians count mismatch: {count} + {start} > {expected_count}")]
78    CountMismatch {
79        count: usize,
80        start: usize,
81        expected_count: usize,
82    },
83}
84
85/// The error type for [`GaussiansBuffer`](crate::GaussiansBuffer)'s [`TryFrom`] implementation for
86/// [`wgpu::Buffer`].
87#[derive(Debug, Error)]
88pub enum GaussiansBufferTryFromBufferError {
89    #[error(
90        "buffer size and expected multiple size mismatch: {buffer_size} % {expected_multiple_size} != 0"
91    )]
92    BufferSizeNotMultiple {
93        buffer_size: wgpu::BufferAddress,
94        expected_multiple_size: wgpu::BufferAddress,
95    },
96}
97
98/// The error type for [`FixedSizeBufferWrapper`](crate::FixedSizeBufferWrapper).
99#[derive(Debug, Error)]
100pub enum FixedSizeBufferWrapperError {
101    #[error("buffer size and expected size mismatch: {buffer_size} != {expected_size}")]
102    BufferSizeMismatched {
103        buffer_size: wgpu::BufferAddress,
104        expected_size: wgpu::BufferAddress,
105    },
106}
107
108/// The error type for [`ComputeBundle`](crate::ComputeBundle) creation.
109#[derive(Debug, Error)]
110pub enum ComputeBundleCreateError {
111    #[error(
112        "resource count and bind group layout count mismatch: \
113        {resource_count} != {bind_group_layout_count}\
114        "
115    )]
116    ResourceCountMismatch {
117        resource_count: usize,
118        bind_group_layout_count: usize,
119    },
120    #[error(
121        "workgroup size exceeds device limit: \
122        {workgroup_size} > {device_limit}"
123    )]
124    WorkgroupSizeExceedsDeviceLimit {
125        workgroup_size: u32,
126        device_limit: u32,
127    },
128}
129
130/// The error type for [`ComputeBundleBuilder::build`](crate::ComputeBundleBuilder::build) function.
131#[derive(Debug, Error)]
132pub enum ComputeBundleBuildError {
133    #[error("{0}")]
134    Wesl(#[from] wesl::Error),
135    #[error("{0}")]
136    Create(#[from] ComputeBundleCreateError),
137    #[error("missing bind group layout for compute bundle")]
138    MissingBindGroupLayout,
139    #[error("missing resolver for compute bundle")]
140    MissingResolver,
141    #[error("missing entry point for compute bundle")]
142    MissingEntryPoint,
143    #[error("missing main shader for compute bundle")]
144    MissingMainShader,
145}