@@ -5,11 +5,13 @@ use std::cell::RefCell;
55
66use deno_core:: cppgc:: Ptr ;
77use deno_core:: op2;
8+ use deno_core:: v8;
9+ use deno_core:: webidl:: { IntOptions , WebIdlConverter , WebIdlError } ;
810use deno_core:: GarbageCollected ;
911use deno_core:: WebIDL ;
1012use deno_error:: JsErrorBox ;
1113use wgpu_core:: command:: PassChannel ;
12- use wgpu_types:: TexelCopyBufferInfo ;
14+ use wgpu_types:: { BufferAddress , TexelCopyBufferInfo } ;
1315
1416use crate :: buffer:: GPUBuffer ;
1517use crate :: command_buffer:: GPUCommandBuffer ;
@@ -171,15 +173,78 @@ impl GPUCommandEncoder {
171173 }
172174 }
173175
174- #[ required( 5 ) ]
175- fn copy_buffer_to_buffer (
176+ #[ required( 2 ) ]
177+ fn copy_buffer_to_buffer < ' a > (
176178 & self ,
179+ scope : & mut v8:: HandleScope < ' a > ,
177180 #[ webidl] source : Ptr < GPUBuffer > ,
178- #[ webidl( options( enforce_range = true ) ) ] source_offset : u64 ,
179- #[ webidl] destination : Ptr < GPUBuffer > ,
180- #[ webidl( options( enforce_range = true ) ) ] destination_offset : u64 ,
181- #[ webidl( options( enforce_range = true ) ) ] size : Option < u64 > ,
182- ) {
181+ arg2 : v8:: Local < ' a , v8:: Value > ,
182+ arg3 : v8:: Local < ' a , v8:: Value > ,
183+ arg4 : v8:: Local < ' a , v8:: Value > ,
184+ arg5 : v8:: Local < ' a , v8:: Value > ,
185+ ) -> Result < ( ) , WebIdlError > {
186+ let prefix = "Failed to execute 'GPUCommandEncoder.copyBufferToBuffer'" ;
187+ let int_options = IntOptions {
188+ clamp : false ,
189+ enforce_range : true ,
190+ } ;
191+
192+ let source_offset: BufferAddress ;
193+ let destination: Ptr < GPUBuffer > ;
194+ let destination_offset: BufferAddress ;
195+ let size: Option < BufferAddress > ;
196+ // Note that the last argument to either overload of `copy_buffer_to_buffer`
197+ // is optional, so `arg5.is_undefined()` would not work here.
198+ if arg4. is_undefined ( ) {
199+ // 3-argument overload
200+ source_offset = 0 ;
201+ destination = Ptr :: < GPUBuffer > :: convert (
202+ scope,
203+ arg2,
204+ Cow :: Borrowed ( prefix) ,
205+ ( || Cow :: Borrowed ( "destination" ) ) . into ( ) ,
206+ & ( ) ,
207+ ) ?;
208+ destination_offset = 0 ;
209+ size = <Option < u64 > >:: convert (
210+ scope,
211+ arg3,
212+ Cow :: Borrowed ( prefix) ,
213+ ( || Cow :: Borrowed ( "size" ) ) . into ( ) ,
214+ & int_options,
215+ ) ?;
216+ } else {
217+ // 5-argument overload
218+ source_offset = u64:: convert (
219+ scope,
220+ arg2,
221+ Cow :: Borrowed ( prefix) ,
222+ ( || Cow :: Borrowed ( "sourceOffset" ) ) . into ( ) ,
223+ & int_options,
224+ ) ?;
225+ destination = Ptr :: < GPUBuffer > :: convert (
226+ scope,
227+ arg3,
228+ Cow :: Borrowed ( prefix) ,
229+ ( || Cow :: Borrowed ( "destination" ) ) . into ( ) ,
230+ & ( ) ,
231+ ) ?;
232+ destination_offset = u64:: convert (
233+ scope,
234+ arg4,
235+ Cow :: Borrowed ( prefix) ,
236+ ( || Cow :: Borrowed ( "destinationOffset" ) ) . into ( ) ,
237+ & int_options,
238+ ) ?;
239+ size = <Option < u64 > >:: convert (
240+ scope,
241+ arg5,
242+ Cow :: Borrowed ( prefix) ,
243+ ( || Cow :: Borrowed ( "size" ) ) . into ( ) ,
244+ & int_options,
245+ ) ?;
246+ }
247+
183248 let err = self
184249 . instance
185250 . command_encoder_copy_buffer_to_buffer (
@@ -193,6 +258,8 @@ impl GPUCommandEncoder {
193258 . err ( ) ;
194259
195260 self . error_handler . push_error ( err) ;
261+
262+ Ok ( ( ) )
196263 }
197264
198265 #[ required( 3 ) ]
0 commit comments