@@ -5,11 +5,13 @@ use std::cell::RefCell;
5
5
6
6
use deno_core:: cppgc:: Ptr ;
7
7
use deno_core:: op2;
8
+ use deno_core:: v8;
9
+ use deno_core:: webidl:: { IntOptions , WebIdlConverter , WebIdlError } ;
8
10
use deno_core:: GarbageCollected ;
9
11
use deno_core:: WebIDL ;
10
12
use deno_error:: JsErrorBox ;
11
13
use wgpu_core:: command:: PassChannel ;
12
- use wgpu_types:: TexelCopyBufferInfo ;
14
+ use wgpu_types:: { BufferAddress , TexelCopyBufferInfo } ;
13
15
14
16
use crate :: buffer:: GPUBuffer ;
15
17
use crate :: command_buffer:: GPUCommandBuffer ;
@@ -171,15 +173,78 @@ impl GPUCommandEncoder {
171
173
}
172
174
}
173
175
174
- #[ required( 5 ) ]
175
- fn copy_buffer_to_buffer (
176
+ #[ required( 2 ) ]
177
+ fn copy_buffer_to_buffer < ' a > (
176
178
& self ,
179
+ scope : & mut v8:: HandleScope < ' a > ,
177
180
#[ 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
+
183
248
let err = self
184
249
. instance
185
250
. command_encoder_copy_buffer_to_buffer (
@@ -193,6 +258,8 @@ impl GPUCommandEncoder {
193
258
. err ( ) ;
194
259
195
260
self . error_handler . push_error ( err) ;
261
+
262
+ Ok ( ( ) )
196
263
}
197
264
198
265
#[ required( 3 ) ]
0 commit comments