diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-04-02 15:47:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-02 09:47:57 -0400 |
commit | 058579da562989ed15c86598053644bbc86c6747 (patch) | |
tree | 7f0f2bf30684dcbb350b93d987771f17a4abd250 /op_crates/webgpu | |
parent | adf57610904cb4f4ef25fb077f6e39c9017a4ea9 (diff) |
refactor(ops): remove variadic buffers (#9944)
Diffstat (limited to 'op_crates/webgpu')
-rw-r--r-- | op_crates/webgpu/binding.rs | 6 | ||||
-rw-r--r-- | op_crates/webgpu/buffer.rs | 16 | ||||
-rw-r--r-- | op_crates/webgpu/bundle.rs | 29 | ||||
-rw-r--r-- | op_crates/webgpu/command_encoder.rs | 26 | ||||
-rw-r--r-- | op_crates/webgpu/compute_pass.rs | 26 | ||||
-rw-r--r-- | op_crates/webgpu/lib.rs | 8 | ||||
-rw-r--r-- | op_crates/webgpu/pipeline.rs | 8 | ||||
-rw-r--r-- | op_crates/webgpu/queue.rs | 15 | ||||
-rw-r--r-- | op_crates/webgpu/render_pass.rs | 44 | ||||
-rw-r--r-- | op_crates/webgpu/sampler.rs | 2 | ||||
-rw-r--r-- | op_crates/webgpu/shader.rs | 16 | ||||
-rw-r--r-- | op_crates/webgpu/texture.rs | 4 |
12 files changed, 109 insertions, 91 deletions
diff --git a/op_crates/webgpu/binding.rs b/op_crates/webgpu/binding.rs index 512ba1608..296a968f1 100644 --- a/op_crates/webgpu/binding.rs +++ b/op_crates/webgpu/binding.rs @@ -82,7 +82,7 @@ pub struct CreateBindGroupLayoutArgs { pub fn op_webgpu_create_bind_group_layout( state: &mut OpState, args: CreateBindGroupLayoutArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let device_resource = state @@ -224,7 +224,7 @@ pub struct CreatePipelineLayoutArgs { pub fn op_webgpu_create_pipeline_layout( state: &mut OpState, args: CreatePipelineLayoutArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let device_resource = state @@ -287,7 +287,7 @@ pub struct CreateBindGroupArgs { pub fn op_webgpu_create_bind_group( state: &mut OpState, args: CreateBindGroupArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let device_resource = state diff --git a/op_crates/webgpu/buffer.rs b/op_crates/webgpu/buffer.rs index 91a44f214..ade4122d5 100644 --- a/op_crates/webgpu/buffer.rs +++ b/op_crates/webgpu/buffer.rs @@ -1,14 +1,15 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::bad_resource_id; +use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::futures::channel::oneshot; use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::OpState; +use deno_core::Resource; use deno_core::ResourceId; use deno_core::ZeroCopyBuf; -use deno_core::{BufVec, Resource}; use serde::Deserialize; use std::borrow::Cow; use std::cell::RefCell; @@ -45,7 +46,7 @@ pub struct CreateBufferArgs { pub fn op_webgpu_create_buffer( state: &mut OpState, args: CreateBufferArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let device_resource = state @@ -88,7 +89,7 @@ pub struct BufferGetMapAsyncArgs { pub async fn op_webgpu_buffer_get_map_async( state: Rc<RefCell<OpState>>, args: BufferGetMapAsyncArgs, - _bufs: BufVec, + _bufs: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let (sender, receiver) = oneshot::channel::<Result<(), AnyError>>(); @@ -177,8 +178,9 @@ pub struct BufferGetMappedRangeArgs { pub fn op_webgpu_buffer_get_mapped_range( state: &mut OpState, args: BufferGetMappedRangeArgs, - zero_copy: &mut [ZeroCopyBuf], + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { + let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?; let instance = state.borrow::<super::Instance>(); let buffer_resource = state .resource_table @@ -196,7 +198,7 @@ pub fn op_webgpu_buffer_get_mapped_range( let slice = unsafe { std::slice::from_raw_parts_mut(slice_pointer, args.size as usize) }; - zero_copy[0].copy_from_slice(slice); + zero_copy.copy_from_slice(slice); let rid = state .resource_table @@ -217,7 +219,7 @@ pub struct BufferUnmapArgs { pub fn op_webgpu_buffer_unmap( state: &mut OpState, args: BufferUnmapArgs, - zero_copy: &mut [ZeroCopyBuf], + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let mapped_resource = state .resource_table @@ -233,7 +235,7 @@ pub fn op_webgpu_buffer_unmap( let slice_pointer = mapped_resource.0; let size = mapped_resource.1; - if let Some(buffer) = zero_copy.get(0) { + if let Some(buffer) = zero_copy { let slice = unsafe { std::slice::from_raw_parts_mut(slice_pointer, size) }; slice.copy_from_slice(&buffer); } diff --git a/op_crates/webgpu/bundle.rs b/op_crates/webgpu/bundle.rs index 406b886cc..58915b108 100644 --- a/op_crates/webgpu/bundle.rs +++ b/op_crates/webgpu/bundle.rs @@ -1,6 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::bad_resource_id; +use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::serde_json::json; use deno_core::serde_json::Value; @@ -44,7 +45,7 @@ pub struct CreateRenderBundleEncoderArgs { pub fn op_webgpu_create_render_bundle_encoder( state: &mut OpState, args: CreateRenderBundleEncoderArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let device_resource = state .resource_table @@ -100,7 +101,7 @@ pub struct RenderBundleEncoderFinishArgs { pub fn op_webgpu_render_bundle_encoder_finish( state: &mut OpState, args: RenderBundleEncoderFinishArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_bundle_encoder_resource = state .resource_table @@ -143,8 +144,10 @@ pub struct RenderBundleEncoderSetBindGroupArgs { pub fn op_webgpu_render_bundle_encoder_set_bind_group( state: &mut OpState, args: RenderBundleEncoderSetBindGroupArgs, - zero_copy: &mut [ZeroCopyBuf], + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { + let zero_copy = zero_copy.ok_or_else(null_opbuf)?; + let bind_group_resource = state .resource_table .get::<super::binding::WebGpuBindGroup>(args.bind_group) @@ -170,7 +173,7 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group( ); }, None => { - let (prefix, data, suffix) = unsafe { zero_copy[0].align_to::<u32>() }; + let (prefix, data, suffix) = unsafe { zero_copy.align_to::<u32>() }; assert!(prefix.is_empty()); assert!(suffix.is_empty()); unsafe { @@ -198,7 +201,7 @@ pub struct RenderBundleEncoderPushDebugGroupArgs { pub fn op_webgpu_render_bundle_encoder_push_debug_group( state: &mut OpState, args: RenderBundleEncoderPushDebugGroupArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_bundle_encoder_resource = state .resource_table @@ -225,7 +228,7 @@ pub struct RenderBundleEncoderPopDebugGroupArgs { pub fn op_webgpu_render_bundle_encoder_pop_debug_group( state: &mut OpState, args: RenderBundleEncoderPopDebugGroupArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_bundle_encoder_resource = state .resource_table @@ -251,7 +254,7 @@ pub struct RenderBundleEncoderInsertDebugMarkerArgs { pub fn op_webgpu_render_bundle_encoder_insert_debug_marker( state: &mut OpState, args: RenderBundleEncoderInsertDebugMarkerArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_bundle_encoder_resource = state .resource_table @@ -279,7 +282,7 @@ pub struct RenderBundleEncoderSetPipelineArgs { pub fn op_webgpu_render_bundle_encoder_set_pipeline( state: &mut OpState, args: RenderBundleEncoderSetPipelineArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pipeline_resource = state .resource_table @@ -311,7 +314,7 @@ pub struct RenderBundleEncoderSetIndexBufferArgs { pub fn op_webgpu_render_bundle_encoder_set_index_buffer( state: &mut OpState, args: RenderBundleEncoderSetIndexBufferArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let buffer_resource = state .resource_table @@ -348,7 +351,7 @@ pub struct RenderBundleEncoderSetVertexBufferArgs { pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer( state: &mut OpState, args: RenderBundleEncoderSetVertexBufferArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let buffer_resource = state .resource_table @@ -383,7 +386,7 @@ pub struct RenderBundleEncoderDrawArgs { pub fn op_webgpu_render_bundle_encoder_draw( state: &mut OpState, args: RenderBundleEncoderDrawArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_bundle_encoder_resource = state .resource_table @@ -415,7 +418,7 @@ pub struct RenderBundleEncoderDrawIndexedArgs { pub fn op_webgpu_render_bundle_encoder_draw_indexed( state: &mut OpState, args: RenderBundleEncoderDrawIndexedArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_bundle_encoder_resource = state .resource_table @@ -445,7 +448,7 @@ pub struct RenderBundleEncoderDrawIndirectArgs { pub fn op_webgpu_render_bundle_encoder_draw_indirect( state: &mut OpState, args: RenderBundleEncoderDrawIndirectArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let buffer_resource = state .resource_table diff --git a/op_crates/webgpu/command_encoder.rs b/op_crates/webgpu/command_encoder.rs index 5ca26ccd0..801682f56 100644 --- a/op_crates/webgpu/command_encoder.rs +++ b/op_crates/webgpu/command_encoder.rs @@ -50,7 +50,7 @@ pub struct CreateCommandEncoderArgs { pub fn op_webgpu_create_command_encoder( state: &mut OpState, args: CreateCommandEncoderArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let device_resource = state @@ -116,7 +116,7 @@ pub struct CommandEncoderBeginRenderPassArgs { pub fn op_webgpu_command_encoder_begin_render_pass( state: &mut OpState, args: CommandEncoderBeginRenderPassArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let command_encoder_resource = state .resource_table @@ -251,7 +251,7 @@ pub struct CommandEncoderBeginComputePassArgs { pub fn op_webgpu_command_encoder_begin_compute_pass( state: &mut OpState, args: CommandEncoderBeginComputePassArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let command_encoder_resource = state .resource_table @@ -292,7 +292,7 @@ pub struct CommandEncoderCopyBufferToBufferArgs { pub fn op_webgpu_command_encoder_copy_buffer_to_buffer( state: &mut OpState, args: CommandEncoderCopyBufferToBufferArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let command_encoder_resource = state @@ -361,7 +361,7 @@ pub struct CommandEncoderCopyBufferToTextureArgs { pub fn op_webgpu_command_encoder_copy_buffer_to_texture( state: &mut OpState, args: CommandEncoderCopyBufferToTextureArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let command_encoder_resource = state @@ -424,7 +424,7 @@ pub struct CommandEncoderCopyTextureToBufferArgs { pub fn op_webgpu_command_encoder_copy_texture_to_buffer( state: &mut OpState, args: CommandEncoderCopyTextureToBufferArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let command_encoder_resource = state @@ -486,7 +486,7 @@ pub struct CommandEncoderCopyTextureToTextureArgs { pub fn op_webgpu_command_encoder_copy_texture_to_texture( state: &mut OpState, args: CommandEncoderCopyTextureToTextureArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let command_encoder_resource = state @@ -550,7 +550,7 @@ pub struct CommandEncoderPushDebugGroupArgs { pub fn op_webgpu_command_encoder_push_debug_group( state: &mut OpState, args: CommandEncoderPushDebugGroupArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let command_encoder_resource = state @@ -575,7 +575,7 @@ pub struct CommandEncoderPopDebugGroupArgs { pub fn op_webgpu_command_encoder_pop_debug_group( state: &mut OpState, args: CommandEncoderPopDebugGroupArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let command_encoder_resource = state @@ -599,7 +599,7 @@ pub struct CommandEncoderInsertDebugMarkerArgs { pub fn op_webgpu_command_encoder_insert_debug_marker( state: &mut OpState, args: CommandEncoderInsertDebugMarkerArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let command_encoder_resource = state @@ -627,7 +627,7 @@ pub struct CommandEncoderWriteTimestampArgs { pub fn op_webgpu_command_encoder_write_timestamp( state: &mut OpState, args: CommandEncoderWriteTimestampArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let command_encoder_resource = state @@ -665,7 +665,7 @@ pub struct CommandEncoderResolveQuerySetArgs { pub fn op_webgpu_command_encoder_resolve_query_set( state: &mut OpState, args: CommandEncoderResolveQuerySetArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let command_encoder_resource = state @@ -706,7 +706,7 @@ pub struct CommandEncoderFinishArgs { pub fn op_webgpu_command_encoder_finish( state: &mut OpState, args: CommandEncoderFinishArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let command_encoder_resource = state .resource_table diff --git a/op_crates/webgpu/compute_pass.rs b/op_crates/webgpu/compute_pass.rs index b9d5b12d3..2e1fb1ac1 100644 --- a/op_crates/webgpu/compute_pass.rs +++ b/op_crates/webgpu/compute_pass.rs @@ -1,6 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::bad_resource_id; +use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::serde_json::json; use deno_core::serde_json::Value; @@ -32,7 +33,7 @@ pub struct ComputePassSetPipelineArgs { pub fn op_webgpu_compute_pass_set_pipeline( state: &mut OpState, args: ComputePassSetPipelineArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let compute_pipeline_resource = state .resource_table @@ -63,7 +64,7 @@ pub struct ComputePassDispatchArgs { pub fn op_webgpu_compute_pass_dispatch( state: &mut OpState, args: ComputePassDispatchArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let compute_pass_resource = state .resource_table @@ -91,7 +92,7 @@ pub struct ComputePassDispatchIndirectArgs { pub fn op_webgpu_compute_pass_dispatch_indirect( state: &mut OpState, args: ComputePassDispatchIndirectArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let buffer_resource = state .resource_table @@ -122,7 +123,7 @@ pub struct ComputePassBeginPipelineStatisticsQueryArgs { pub fn op_webgpu_compute_pass_begin_pipeline_statistics_query( state: &mut OpState, args: ComputePassBeginPipelineStatisticsQueryArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let compute_pass_resource = state .resource_table @@ -153,7 +154,7 @@ pub struct ComputePassEndPipelineStatisticsQueryArgs { pub fn op_webgpu_compute_pass_end_pipeline_statistics_query( state: &mut OpState, args: ComputePassEndPipelineStatisticsQueryArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let compute_pass_resource = state .resource_table @@ -180,7 +181,7 @@ pub struct ComputePassWriteTimestampArgs { pub fn op_webgpu_compute_pass_write_timestamp( state: &mut OpState, args: ComputePassWriteTimestampArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let compute_pass_resource = state .resource_table @@ -212,7 +213,7 @@ pub struct ComputePassEndPassArgs { pub fn op_webgpu_compute_pass_end_pass( state: &mut OpState, args: ComputePassEndPassArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let command_encoder_resource = state .resource_table @@ -252,7 +253,7 @@ pub struct ComputePassSetBindGroupArgs { pub fn op_webgpu_compute_pass_set_bind_group( state: &mut OpState, args: ComputePassSetBindGroupArgs, - zero_copy: &mut [ZeroCopyBuf], + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let bind_group_resource = state .resource_table @@ -271,7 +272,8 @@ pub fn op_webgpu_compute_pass_set_bind_group( match args.dynamic_offsets_data { Some(data) => data.as_ptr(), None => { - let (prefix, data, suffix) = zero_copy[0].align_to::<u32>(); + let zero_copy = zero_copy.ok_or_else(null_opbuf)?; + let (prefix, data, suffix) = zero_copy.align_to::<u32>(); assert!(prefix.is_empty()); assert!(suffix.is_empty()); data[args.dynamic_offsets_data_start..].as_ptr() @@ -294,7 +296,7 @@ pub struct ComputePassPushDebugGroupArgs { pub fn op_webgpu_compute_pass_push_debug_group( state: &mut OpState, args: ComputePassPushDebugGroupArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let compute_pass_resource = state .resource_table @@ -322,7 +324,7 @@ pub struct ComputePassPopDebugGroupArgs { pub fn op_webgpu_compute_pass_pop_debug_group( state: &mut OpState, args: ComputePassPopDebugGroupArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let compute_pass_resource = state .resource_table @@ -346,7 +348,7 @@ pub struct ComputePassInsertDebugMarkerArgs { pub fn op_webgpu_compute_pass_insert_debug_marker( state: &mut OpState, args: ComputePassInsertDebugMarkerArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let compute_pass_resource = state .resource_table diff --git a/op_crates/webgpu/lib.rs b/op_crates/webgpu/lib.rs index 5c3b99329..b1c8a631d 100644 --- a/op_crates/webgpu/lib.rs +++ b/op_crates/webgpu/lib.rs @@ -7,9 +7,9 @@ use deno_core::error::{bad_resource_id, not_supported}; use deno_core::serde_json::json; use deno_core::serde_json::Value; use deno_core::OpState; +use deno_core::Resource; use deno_core::ResourceId; use deno_core::ZeroCopyBuf; -use deno_core::{BufVec, Resource}; use serde::Deserialize; use std::borrow::Cow; use std::cell::RefCell; @@ -194,7 +194,7 @@ pub struct RequestAdapterArgs { pub async fn op_webgpu_request_adapter( state: Rc<RefCell<OpState>>, args: RequestAdapterArgs, - _bufs: BufVec, + _bufs: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let mut state = state.borrow_mut(); check_unstable(&state, "navigator.gpu.requestAdapter"); @@ -299,7 +299,7 @@ pub struct RequestDeviceArgs { pub async fn op_webgpu_request_device( state: Rc<RefCell<OpState>>, args: RequestDeviceArgs, - _bufs: BufVec, + _bufs: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let mut state = state.borrow_mut(); let adapter_resource = state @@ -472,7 +472,7 @@ pub struct CreateQuerySetArgs { pub fn op_webgpu_create_query_set( state: &mut OpState, args: CreateQuerySetArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let device_resource = state .resource_table diff --git a/op_crates/webgpu/pipeline.rs b/op_crates/webgpu/pipeline.rs index 5e9d4534b..10e300a57 100644 --- a/op_crates/webgpu/pipeline.rs +++ b/op_crates/webgpu/pipeline.rs @@ -162,7 +162,7 @@ pub struct CreateComputePipelineArgs { pub fn op_webgpu_create_compute_pipeline( state: &mut OpState, args: CreateComputePipelineArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let device_resource = state @@ -229,7 +229,7 @@ pub struct ComputePipelineGetBindGroupLayoutArgs { pub fn op_webgpu_compute_pipeline_get_bind_group_layout( state: &mut OpState, args: ComputePipelineGetBindGroupLayoutArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let compute_pipeline_resource = state @@ -366,7 +366,7 @@ pub struct CreateRenderPipelineArgs { pub fn op_webgpu_create_render_pipeline( state: &mut OpState, args: CreateRenderPipelineArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let device_resource = state @@ -617,7 +617,7 @@ pub struct RenderPipelineGetBindGroupLayoutArgs { pub fn op_webgpu_render_pipeline_get_bind_group_layout( state: &mut OpState, args: RenderPipelineGetBindGroupLayoutArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let render_pipeline_resource = state diff --git a/op_crates/webgpu/queue.rs b/op_crates/webgpu/queue.rs index bbfb782de..c96e2a158 100644 --- a/op_crates/webgpu/queue.rs +++ b/op_crates/webgpu/queue.rs @@ -1,6 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::bad_resource_id; +use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::serde_json::json; use deno_core::serde_json::Value; @@ -23,7 +24,7 @@ pub struct QueueSubmitArgs { pub fn op_webgpu_queue_submit( state: &mut OpState, args: QueueSubmitArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let queue_resource = state @@ -69,8 +70,9 @@ pub struct QueueWriteBufferArgs { pub fn op_webgpu_write_buffer( state: &mut OpState, args: QueueWriteBufferArgs, - zero_copy: &mut [ZeroCopyBuf], + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { + let zero_copy = zero_copy.ok_or_else(null_opbuf)?; let instance = state.borrow::<super::Instance>(); let buffer_resource = state .resource_table @@ -84,8 +86,8 @@ pub fn op_webgpu_write_buffer( let queue = queue_resource.0; let data = match args.size { - Some(size) => &zero_copy[0][args.data_offset..(args.data_offset + size)], - None => &zero_copy[0][args.data_offset..], + Some(size) => &zero_copy[args.data_offset..(args.data_offset + size)], + None => &zero_copy[args.data_offset..], }; let maybe_err = gfx_select!(queue => instance.queue_write_buffer( queue, @@ -110,8 +112,9 @@ pub struct QueueWriteTextureArgs { pub fn op_webgpu_write_texture( state: &mut OpState, args: QueueWriteTextureArgs, - zero_copy: &mut [ZeroCopyBuf], + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { + let zero_copy = zero_copy.ok_or_else(null_opbuf)?; let instance = state.borrow::<super::Instance>(); let texture_resource = state .resource_table @@ -144,7 +147,7 @@ pub fn op_webgpu_write_texture( let maybe_err = gfx_select!(queue => instance.queue_write_texture( queue, &destination, - &*zero_copy[0], + &*zero_copy, &data_layout, &wgpu_types::Extent3d { width: args.size.width.unwrap_or(1), diff --git a/op_crates/webgpu/render_pass.rs b/op_crates/webgpu/render_pass.rs index 5c614024e..bf3bd092d 100644 --- a/op_crates/webgpu/render_pass.rs +++ b/op_crates/webgpu/render_pass.rs @@ -1,6 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::bad_resource_id; +use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::serde_json::json; use deno_core::serde_json::Value; @@ -37,7 +38,7 @@ pub struct RenderPassSetViewportArgs { pub fn op_webgpu_render_pass_set_viewport( state: &mut OpState, args: RenderPassSetViewportArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -70,7 +71,7 @@ pub struct RenderPassSetScissorRectArgs { pub fn op_webgpu_render_pass_set_scissor_rect( state: &mut OpState, args: RenderPassSetScissorRectArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -107,7 +108,7 @@ pub struct RenderPassSetBlendColorArgs { pub fn op_webgpu_render_pass_set_blend_color( state: &mut OpState, args: RenderPassSetBlendColorArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -137,7 +138,7 @@ pub struct RenderPassSetStencilReferenceArgs { pub fn op_webgpu_render_pass_set_stencil_reference( state: &mut OpState, args: RenderPassSetStencilReferenceArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -163,7 +164,7 @@ pub struct RenderPassBeginPipelineStatisticsQueryArgs { pub fn op_webgpu_render_pass_begin_pipeline_statistics_query( state: &mut OpState, args: RenderPassBeginPipelineStatisticsQueryArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -194,7 +195,7 @@ pub struct RenderPassEndPipelineStatisticsQueryArgs { pub fn op_webgpu_render_pass_end_pipeline_statistics_query( state: &mut OpState, args: RenderPassEndPipelineStatisticsQueryArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -221,7 +222,7 @@ pub struct RenderPassWriteTimestampArgs { pub fn op_webgpu_render_pass_write_timestamp( state: &mut OpState, args: RenderPassWriteTimestampArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -253,7 +254,7 @@ pub struct RenderPassExecuteBundlesArgs { pub fn op_webgpu_render_pass_execute_bundles( state: &mut OpState, args: RenderPassExecuteBundlesArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let mut render_bundle_ids = vec![]; @@ -291,7 +292,7 @@ pub struct RenderPassEndPassArgs { pub fn op_webgpu_render_pass_end_pass( state: &mut OpState, args: RenderPassEndPassArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let command_encoder_resource = state .resource_table @@ -326,8 +327,9 @@ pub struct RenderPassSetBindGroupArgs { pub fn op_webgpu_render_pass_set_bind_group( state: &mut OpState, args: RenderPassSetBindGroupArgs, - zero_copy: &mut [ZeroCopyBuf], + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { + let zero_copy = zero_copy.ok_or_else(null_opbuf)?; let bind_group_resource = state .resource_table .get::<super::binding::WebGpuBindGroup>(args.bind_group) @@ -353,7 +355,7 @@ pub fn op_webgpu_render_pass_set_bind_group( ); }, None => { - let (prefix, data, suffix) = unsafe { zero_copy[0].align_to::<u32>() }; + let (prefix, data, suffix) = unsafe { zero_copy.align_to::<u32>() }; assert!(prefix.is_empty()); assert!(suffix.is_empty()); unsafe { @@ -381,7 +383,7 @@ pub struct RenderPassPushDebugGroupArgs { pub fn op_webgpu_render_pass_push_debug_group( state: &mut OpState, args: RenderPassPushDebugGroupArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -409,7 +411,7 @@ pub struct RenderPassPopDebugGroupArgs { pub fn op_webgpu_render_pass_pop_debug_group( state: &mut OpState, args: RenderPassPopDebugGroupArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -433,7 +435,7 @@ pub struct RenderPassInsertDebugMarkerArgs { pub fn op_webgpu_render_pass_insert_debug_marker( state: &mut OpState, args: RenderPassInsertDebugMarkerArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -462,7 +464,7 @@ pub struct RenderPassSetPipelineArgs { pub fn op_webgpu_render_pass_set_pipeline( state: &mut OpState, args: RenderPassSetPipelineArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pipeline_resource = state .resource_table @@ -494,7 +496,7 @@ pub struct RenderPassSetIndexBufferArgs { pub fn op_webgpu_render_pass_set_index_buffer( state: &mut OpState, args: RenderPassSetIndexBufferArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let buffer_resource = state .resource_table @@ -528,7 +530,7 @@ pub struct RenderPassSetVertexBufferArgs { pub fn op_webgpu_render_pass_set_vertex_buffer( state: &mut OpState, args: RenderPassSetVertexBufferArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let buffer_resource = state .resource_table @@ -563,7 +565,7 @@ pub struct RenderPassDrawArgs { pub fn op_webgpu_render_pass_draw( state: &mut OpState, args: RenderPassDrawArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -595,7 +597,7 @@ pub struct RenderPassDrawIndexedArgs { pub fn op_webgpu_render_pass_draw_indexed( state: &mut OpState, args: RenderPassDrawIndexedArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let render_pass_resource = state .resource_table @@ -625,7 +627,7 @@ pub struct RenderPassDrawIndirectArgs { pub fn op_webgpu_render_pass_draw_indirect( state: &mut OpState, args: RenderPassDrawIndirectArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let buffer_resource = state .resource_table @@ -656,7 +658,7 @@ pub struct RenderPassDrawIndexedIndirectArgs { pub fn op_webgpu_render_pass_draw_indexed_indirect( state: &mut OpState, args: RenderPassDrawIndexedIndirectArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let buffer_resource = state .resource_table diff --git a/op_crates/webgpu/sampler.rs b/op_crates/webgpu/sampler.rs index fdff70b77..b759d0c11 100644 --- a/op_crates/webgpu/sampler.rs +++ b/op_crates/webgpu/sampler.rs @@ -82,7 +82,7 @@ pub struct CreateSamplerArgs { pub fn op_webgpu_create_sampler( state: &mut OpState, args: CreateSamplerArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let device_resource = state diff --git a/op_crates/webgpu/shader.rs b/op_crates/webgpu/shader.rs index 8a0613862..63578ce64 100644 --- a/op_crates/webgpu/shader.rs +++ b/op_crates/webgpu/shader.rs @@ -1,6 +1,7 @@ // Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. use deno_core::error::bad_resource_id; +use deno_core::error::null_opbuf; use deno_core::error::AnyError; use deno_core::serde_json::json; use deno_core::serde_json::Value; @@ -31,7 +32,7 @@ pub struct CreateShaderModuleArgs { pub fn op_webgpu_create_shader_module( state: &mut OpState, args: CreateShaderModuleArgs, - zero_copy: &mut [ZeroCopyBuf], + zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let device_resource = state @@ -45,10 +46,15 @@ pub fn op_webgpu_create_shader_module( wgpu_core::pipeline::ShaderModuleSource::Wgsl(Cow::from(code)) } None => wgpu_core::pipeline::ShaderModuleSource::SpirV(Cow::from(unsafe { - let (prefix, data, suffix) = zero_copy[0].align_to::<u32>(); - assert!(prefix.is_empty()); - assert!(suffix.is_empty()); - data + match &zero_copy { + Some(zero_copy) => { + let (prefix, data, suffix) = zero_copy.align_to::<u32>(); + assert!(prefix.is_empty()); + assert!(suffix.is_empty()); + data + } + None => return Err(null_opbuf()), + } })), }; diff --git a/op_crates/webgpu/texture.rs b/op_crates/webgpu/texture.rs index 2dcff5027..24824215c 100644 --- a/op_crates/webgpu/texture.rs +++ b/op_crates/webgpu/texture.rs @@ -147,7 +147,7 @@ pub struct CreateTextureArgs { pub fn op_webgpu_create_texture( state: &mut OpState, args: CreateTextureArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let device_resource = state @@ -209,7 +209,7 @@ pub struct CreateTextureViewArgs { pub fn op_webgpu_create_texture_view( state: &mut OpState, args: CreateTextureViewArgs, - _zero_copy: &mut [ZeroCopyBuf], + _zero_copy: Option<ZeroCopyBuf>, ) -> Result<Value, AnyError> { let instance = state.borrow::<super::Instance>(); let texture_resource = state |