@@ -19,6 +19,7 @@ use crate::{
1919 device:: {
2020 bgl, Device , DeviceError , MissingDownlevelFlags , MissingFeatures , SHADER_STAGE_COUNT ,
2121 } ,
22+ error:: { AsWebGpuErrorType , ErrorType } ,
2223 id:: { BindGroupLayoutId , BufferId , SamplerId , TextureViewId , TlasId } ,
2324 init_tracker:: { BufferInitTrackerAction , TextureInitTrackerAction } ,
2425 pipeline:: { ComputePipeline , RenderPipeline } ,
@@ -78,6 +79,22 @@ pub enum CreateBindGroupLayoutError {
7879 InvalidVisibility ( wgt:: ShaderStages ) ,
7980}
8081
82+ impl AsWebGpuErrorType for CreateBindGroupLayoutError {
83+ fn as_webgpu_error_type ( & self ) -> ErrorType {
84+ match self {
85+ Self :: Device ( e) => e. as_webgpu_error_type ( ) ,
86+
87+ Self :: ConflictBinding ( _)
88+ | Self :: Entry { .. }
89+ | Self :: TooManyBindings ( _)
90+ | Self :: InvalidBindingIndex { .. }
91+ | Self :: InvalidVisibility ( _)
92+ | Self :: ContainsBothBindingArrayAndDynamicOffsetArray
93+ | Self :: ContainsBothBindingArrayAndUniformBuffer => ErrorType :: Validation ,
94+ }
95+ }
96+ }
97+
8198//TODO: refactor this to move out `enum BindingError`.
8299
83100#[ derive( Clone , Debug , Error ) ]
@@ -205,6 +222,45 @@ pub enum CreateBindGroupError {
205222 InvalidResource ( #[ from] InvalidResourceError ) ,
206223}
207224
225+ impl AsWebGpuErrorType for CreateBindGroupError {
226+ fn as_webgpu_error_type ( & self ) -> ErrorType {
227+ let e: & dyn AsWebGpuErrorType = match self {
228+ Self :: Device ( e) => e,
229+ Self :: DestroyedResource ( e) => e,
230+ Self :: MissingBufferUsage ( e) => e,
231+ Self :: MissingTextureUsage ( e) => e,
232+ Self :: ResourceUsageCompatibility ( e) => e,
233+ Self :: InvalidResource ( e) => e,
234+ Self :: BindingArrayPartialLengthMismatch { .. }
235+ | Self :: BindingArrayLengthMismatch { .. }
236+ | Self :: BindingArrayZeroLength
237+ | Self :: BindingRangeTooLarge { .. }
238+ | Self :: BindingSizeTooSmall { .. }
239+ | Self :: BindingsNumMismatch { .. }
240+ | Self :: BindingZeroSize ( _)
241+ | Self :: DuplicateBinding ( _)
242+ | Self :: MissingBindingDeclaration ( _)
243+ | Self :: SingleBindingExpected
244+ | Self :: UnalignedBufferOffset ( _, _, _)
245+ | Self :: BufferRangeTooLarge { .. }
246+ | Self :: WrongBindingType { .. }
247+ | Self :: InvalidTextureMultisample { .. }
248+ | Self :: InvalidTextureSampleType { .. }
249+ | Self :: InvalidTextureDimension { .. }
250+ | Self :: InvalidStorageTextureFormat { .. }
251+ | Self :: InvalidStorageTextureMipLevelCount { .. }
252+ | Self :: WrongSamplerComparison { .. }
253+ | Self :: WrongSamplerFiltering { .. }
254+ | Self :: DepthStencilAspect
255+ | Self :: StorageReadNotSupported ( _)
256+ | Self :: StorageWriteNotSupported ( _)
257+ | Self :: StorageReadWriteNotSupported ( _)
258+ | Self :: StorageAtomicNotSupported ( _) => return ErrorType :: Validation ,
259+ } ;
260+ e. as_webgpu_error_type ( )
261+ }
262+ }
263+
208264#[ derive( Clone , Debug , Error ) ]
209265pub enum BindingZone {
210266 #[ error( "Stage {0:?}" ) ]
@@ -222,6 +278,12 @@ pub struct BindingTypeMaxCountError {
222278 pub count : u32 ,
223279}
224280
281+ impl AsWebGpuErrorType for BindingTypeMaxCountError {
282+ fn as_webgpu_error_type ( & self ) -> ErrorType {
283+ ErrorType :: Validation
284+ }
285+ }
286+
225287#[ derive( Clone , Debug ) ]
226288pub enum BindingTypeMaxCountErrorKind {
227289 DynamicUniformBuffers ,
@@ -665,6 +727,22 @@ pub enum CreatePipelineLayoutError {
665727 InvalidResource ( #[ from] InvalidResourceError ) ,
666728}
667729
730+ impl AsWebGpuErrorType for CreatePipelineLayoutError {
731+ fn as_webgpu_error_type ( & self ) -> ErrorType {
732+ let e: & dyn AsWebGpuErrorType = match self {
733+ Self :: Device ( e) => e,
734+ Self :: MissingFeatures ( e) => e,
735+ Self :: InvalidResource ( e) => e,
736+ Self :: TooManyBindings ( e) => e,
737+ Self :: MisalignedPushConstantRange { .. }
738+ | Self :: MoreThanOnePushConstantRangePerStage { .. }
739+ | Self :: PushConstantRangeTooLarge { .. }
740+ | Self :: TooManyGroups { .. } => return ErrorType :: Validation ,
741+ } ;
742+ e. as_webgpu_error_type ( )
743+ }
744+ }
745+
668746#[ derive( Clone , Debug , Error ) ]
669747#[ non_exhaustive]
670748pub enum PushConstantUploadError {
@@ -696,6 +774,12 @@ pub enum PushConstantUploadError {
696774 Unaligned ( u32 ) ,
697775}
698776
777+ impl AsWebGpuErrorType for PushConstantUploadError {
778+ fn as_webgpu_error_type ( & self ) -> ErrorType {
779+ ErrorType :: Validation
780+ }
781+ }
782+
699783/// Describes a pipeline layout.
700784///
701785/// A `PipelineLayoutDescriptor` can be used to create a pipeline layout.
@@ -938,6 +1022,12 @@ pub enum BindError {
9381022 } ,
9391023}
9401024
1025+ impl AsWebGpuErrorType for BindError {
1026+ fn as_webgpu_error_type ( & self ) -> ErrorType {
1027+ ErrorType :: Validation
1028+ }
1029+ }
1030+
9411031#[ derive( Debug ) ]
9421032pub struct BindGroupDynamicBindingData {
9431033 /// The index of the binding.
@@ -1099,6 +1189,15 @@ pub enum GetBindGroupLayoutError {
10991189 InvalidResource ( #[ from] InvalidResourceError ) ,
11001190}
11011191
1192+ impl AsWebGpuErrorType for GetBindGroupLayoutError {
1193+ fn as_webgpu_error_type ( & self ) -> ErrorType {
1194+ match self {
1195+ Self :: InvalidGroupIndex ( _) => ErrorType :: Validation ,
1196+ Self :: InvalidResource ( e) => e. as_webgpu_error_type ( ) ,
1197+ }
1198+ }
1199+ }
1200+
11021201#[ derive( Clone , Debug , Error , Eq , PartialEq ) ]
11031202#[ error( "Buffer is bound with size {bound_size} where the shader expects {shader_size} in group[{group_index}] compact index {compact_index}" ) ]
11041203pub struct LateMinBufferBindingSizeMismatch {
0 commit comments