@@ -11,7 +11,7 @@ use deno_core::v8;
1111use deno_core:: webidl:: WebIdlInterfaceConverter ;
1212use deno_core:: GarbageCollected ;
1313use deno_error:: JsErrorBox ;
14- use wgpu_core:: binding_model:: BindingResource ;
14+ use wgpu_core:: binding_model:: { BindingResource , CreateBindGroupError } ;
1515use wgpu_core:: pipeline:: ProgrammableStageDescriptor ;
1616use wgpu_types:: BindingType ;
1717
@@ -404,49 +404,73 @@ impl GPUDevice {
404404 & self ,
405405 #[ webidl] descriptor : super :: bind_group:: GPUBindGroupDescriptor ,
406406 ) -> GPUBindGroup {
407- let entries = descriptor
408- . entries
409- . into_iter ( )
410- . map ( |entry| wgpu_core:: binding_model:: BindGroupEntry {
411- binding : entry. binding ,
412- resource : match entry. resource {
413- GPUBindingResource :: Sampler ( sampler) => {
414- BindingResource :: Sampler ( sampler. id )
415- }
416- GPUBindingResource :: Texture ( texture) => {
417- BindingResource :: TextureView ( texture. default_view_id ( ) )
418- }
419- GPUBindingResource :: TextureView ( texture_view) => {
420- BindingResource :: TextureView ( texture_view. id )
421- }
422- GPUBindingResource :: Buffer ( buffer) => {
423- BindingResource :: Buffer ( wgpu_core:: binding_model:: BufferBinding {
424- buffer : buffer. id ,
425- offset : 0 ,
426- size : NonZeroU64 :: new ( buffer. size ) ,
427- } )
428- }
429- GPUBindingResource :: BufferBinding ( buffer_binding) => {
430- BindingResource :: Buffer ( wgpu_core:: binding_model:: BufferBinding {
431- buffer : buffer_binding. buffer . id ,
432- offset : buffer_binding. offset ,
433- size : buffer_binding. size . and_then ( NonZeroU64 :: new) ,
434- } )
435- }
436- } ,
437- } )
438- . collect :: < Vec < _ > > ( ) ;
407+ let mut entries = Vec :: with_capacity ( descriptor. entries . len ( ) ) ;
408+ let ( id, err) = ' error: {
409+ for entry in descriptor. entries . iter ( ) {
410+ entries. push ( wgpu_core:: binding_model:: BindGroupEntry {
411+ binding : entry. binding ,
412+ resource : match & entry. resource {
413+ GPUBindingResource :: Sampler ( sampler) => {
414+ BindingResource :: Sampler ( sampler. id )
415+ }
416+ GPUBindingResource :: Texture ( texture) => {
417+ BindingResource :: TextureView ( texture. default_view_id ( ) )
418+ }
419+ GPUBindingResource :: TextureView ( texture_view) => {
420+ BindingResource :: TextureView ( texture_view. id )
421+ }
422+ GPUBindingResource :: Buffer ( buffer) => {
423+ BindingResource :: Buffer ( wgpu_core:: binding_model:: BufferBinding {
424+ buffer : buffer. id ,
425+ offset : 0 ,
426+ size : NonZeroU64 :: new ( buffer. size ) ,
427+ } )
428+ }
429+ GPUBindingResource :: BufferBinding ( buffer_binding) => {
430+ let size = buffer_binding. size . map ( NonZeroU64 :: new) ;
431+ match size {
432+ None | Some ( Some ( _) ) => {
433+ // Size non-zero or omitted
434+ BindingResource :: Buffer (
435+ wgpu_core:: binding_model:: BufferBinding {
436+ buffer : buffer_binding. buffer . id ,
437+ offset : buffer_binding. offset ,
438+ size : size. unwrap_or_default ( ) ,
439+ } ,
440+ )
441+ }
442+ Some ( None ) => {
443+ // Explicit zero size. Not representable in wgpu API.
444+ let id = self . instance . create_bind_group_error (
445+ None ,
446+ crate :: transform_label ( descriptor. label . clone ( ) ) ,
447+ ) ;
448+ let error_ident =
449+ wgpu_core:: resource:: ResourceErrorIdent :: new (
450+ "Buffer" ,
451+ buffer_binding. buffer . label . clone ( ) ,
452+ ) ;
453+ break ' error (
454+ id,
455+ Some ( CreateBindGroupError :: BindingZeroSize ( error_ident) ) ,
456+ ) ;
457+ }
458+ }
459+ }
460+ } ,
461+ } ) ;
462+ }
439463
440- let wgpu_descriptor = wgpu_core:: binding_model:: BindGroupDescriptor {
441- label : crate :: transform_label ( descriptor. label . clone ( ) ) ,
442- layout : descriptor. layout . id ,
443- entries : Cow :: Owned ( entries) ,
444- } ;
464+ let wgpu_descriptor = wgpu_core:: binding_model:: BindGroupDescriptor {
465+ label : crate :: transform_label ( descriptor. label . clone ( ) ) ,
466+ layout : descriptor. layout . id ,
467+ entries : Cow :: Owned ( entries) ,
468+ } ;
445469
446- let ( id, err) =
447470 self
448471 . instance
449- . device_create_bind_group ( self . id , & wgpu_descriptor, None ) ;
472+ . device_create_bind_group ( self . id , & wgpu_descriptor, None )
473+ } ;
450474
451475 self . error_handler . push_error ( err) ;
452476
0 commit comments