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}
64
65/// The error type for [`GaussiansBuffer`](crate::GaussiansBuffer) update functions.
66#[derive(Debug, Error)]
67pub enum GaussiansBufferUpdateError {
68    #[error("Gaussians count mismatch: {count} != {expected_count}")]
69    CountMismatch { count: usize, expected_count: usize },
70}
71
72/// The error type for [`GaussiansBuffer`](crate::GaussiansBuffer) update range functions.
73#[derive(Debug, Error)]
74pub enum GaussiansBufferUpdateRangeError {
75    #[error("Gaussians count mismatch: {count} + {start} > {expected_count}")]
76    CountMismatch {
77        count: usize,
78        start: usize,
79        expected_count: usize,
80    },
81}
82
83/// The error type for [`GaussiansBuffer`](crate::GaussiansBuffer)'s [`TryFrom`] implementation for
84/// [`wgpu::Buffer`].
85#[derive(Debug, Error)]
86pub enum GaussiansBufferTryFromBufferError {
87    #[error(
88        "buffer size and expected multiple size mismatch: {buffer_size} % {expected_multiple_size} != 0"
89    )]
90    BufferSizeNotMultiple {
91        buffer_size: wgpu::BufferAddress,
92        expected_multiple_size: wgpu::BufferAddress,
93    },
94}
95
96/// The error type for [`FixedSizeBufferWrapper`](crate::FixedSizeBufferWrapper).
97#[derive(Debug, Error)]
98pub enum FixedSizeBufferWrapperError {
99    #[error("buffer size and expected size mismatch: {buffer_size} != {expected_size}")]
100    BufferSizeMismatched {
101        buffer_size: wgpu::BufferAddress,
102        expected_size: wgpu::BufferAddress,
103    },
104}
105
106/// The error type for [`ComputeBundle`](crate::ComputeBundle) creation.
107#[derive(Debug, Error)]
108pub enum ComputeBundleCreateError {
109    #[error(
110        "resource count and bind group layout count mismatch: \
111        {resource_count} != {bind_group_layout_count}\
112        "
113    )]
114    ResourceCountMismatch {
115        resource_count: usize,
116        bind_group_layout_count: usize,
117    },
118    #[error(
119        "workgroup size exceeds device limit: \
120        {workgroup_size} > {device_limit}"
121    )]
122    WorkgroupSizeExceedsDeviceLimit {
123        workgroup_size: u32,
124        device_limit: u32,
125    },
126}
127
128/// The error type for [`ComputeBundleBuilder::build`](crate::ComputeBundleBuilder::build) function.
129#[derive(Debug, Error)]
130pub enum ComputeBundleBuildError {
131    #[error("{0}")]
132    Wesl(#[from] wesl::Error),
133    #[error("{0}")]
134    Create(#[from] ComputeBundleCreateError),
135    #[error("missing bind group layout for compute bundle")]
136    MissingBindGroupLayout,
137    #[error("missing resolver for compute bundle")]
138    MissingResolver,
139    #[error("missing entry point for compute bundle")]
140    MissingEntryPoint,
141    #[error("missing main shader for compute bundle")]
142    MissingMainShader,
143}