mirror of
https://github.com/denoland/deno.git
synced 2025-08-31 15:57:53 +00:00
refactor(ops): return BadResource errors in ResourceTable calls (#11710)
* refactor(ops): return BadResource errors in ResourceTable calls Instead of relying on callers to map Options to Results via `.ok_or_else(bad_resource_id)` at over 176 different call sites ...
This commit is contained in:
parent
18ff6bb053
commit
2ca454b402
34 changed files with 337 additions and 551 deletions
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::error::bad_resource_id;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::ResourceId;
|
||||
use deno_core::{OpState, Resource};
|
||||
|
@ -84,8 +83,7 @@ pub fn op_webgpu_create_bind_group_layout(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let mut entries = vec![];
|
||||
|
@ -217,17 +215,14 @@ pub fn op_webgpu_create_pipeline_layout(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let mut bind_group_layouts = vec![];
|
||||
|
||||
for rid in &args.bind_group_layouts {
|
||||
let bind_group_layout = state
|
||||
.resource_table
|
||||
.get::<WebGpuBindGroupLayout>(*rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let bind_group_layout =
|
||||
state.resource_table.get::<WebGpuBindGroupLayout>(*rid)?;
|
||||
bind_group_layouts.push(bind_group_layout.0);
|
||||
}
|
||||
|
||||
|
@ -271,8 +266,7 @@ pub fn op_webgpu_create_bind_group(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let mut entries = vec![];
|
||||
|
@ -282,26 +276,26 @@ pub fn op_webgpu_create_bind_group(
|
|||
binding: entry.binding,
|
||||
resource: match entry.kind.as_str() {
|
||||
"GPUSampler" => {
|
||||
let sampler_resource = state
|
||||
.resource_table
|
||||
.get::<super::sampler::WebGpuSampler>(entry.resource)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let sampler_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::sampler::WebGpuSampler>(entry.resource)?;
|
||||
wgpu_core::binding_model::BindingResource::Sampler(sampler_resource.0)
|
||||
}
|
||||
"GPUTextureView" => {
|
||||
let texture_view_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTextureView>(entry.resource)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let texture_view_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTextureView>(entry.resource)?;
|
||||
wgpu_core::binding_model::BindingResource::TextureView(
|
||||
texture_view_resource.0,
|
||||
)
|
||||
}
|
||||
"GPUBufferBinding" => {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(entry.resource)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let buffer_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(entry.resource)?;
|
||||
wgpu_core::binding_model::BindingResource::Buffer(
|
||||
wgpu_core::binding_model::BufferBinding {
|
||||
buffer_id: buffer_resource.0,
|
||||
|
@ -318,8 +312,7 @@ pub fn op_webgpu_create_bind_group(
|
|||
|
||||
let bind_group_layout = state
|
||||
.resource_table
|
||||
.get::<WebGpuBindGroupLayout>(args.layout)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuBindGroupLayout>(args.layout)?;
|
||||
|
||||
let descriptor = wgpu_core::binding_model::BindGroupDescriptor {
|
||||
label: args.label.map(Cow::from),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// 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::type_error;
|
||||
use deno_core::error::AnyError;
|
||||
|
@ -50,8 +49,7 @@ pub fn op_webgpu_create_buffer(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let descriptor = wgpu_core::resource::BufferDescriptor {
|
||||
|
@ -90,15 +88,12 @@ pub async fn op_webgpu_buffer_get_map_async(
|
|||
{
|
||||
let state_ = state.borrow();
|
||||
let instance = state_.borrow::<super::Instance>();
|
||||
let buffer_resource = state_
|
||||
.resource_table
|
||||
.get::<WebGpuBuffer>(args.buffer_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let buffer_resource =
|
||||
state_.resource_table.get::<WebGpuBuffer>(args.buffer_rid)?;
|
||||
let buffer = buffer_resource.0;
|
||||
let device_resource = state_
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
device = device_resource.0;
|
||||
|
||||
let boxed_sender = Box::new(sender);
|
||||
|
@ -180,10 +175,8 @@ pub fn op_webgpu_buffer_get_mapped_range(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let mut zero_copy = zero_copy.ok_or_else(null_opbuf)?;
|
||||
let instance = state.borrow::<super::Instance>();
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuBuffer>(args.buffer_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let buffer_resource =
|
||||
state.resource_table.get::<WebGpuBuffer>(args.buffer_rid)?;
|
||||
let buffer = buffer_resource.0;
|
||||
|
||||
let (slice_pointer, range_size) =
|
||||
|
@ -220,13 +213,10 @@ pub fn op_webgpu_buffer_unmap(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let mapped_resource = state
|
||||
.resource_table
|
||||
.take::<WebGpuBufferMapped>(args.mapped_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.take::<WebGpuBufferMapped>(args.mapped_rid)?;
|
||||
let instance = state.borrow::<super::Instance>();
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuBuffer>(args.buffer_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let buffer_resource =
|
||||
state.resource_table.get::<WebGpuBuffer>(args.buffer_rid)?;
|
||||
let buffer = buffer_resource.0;
|
||||
|
||||
let slice_pointer = mapped_resource.0;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// 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::ResourceId;
|
||||
|
@ -47,8 +46,7 @@ pub fn op_webgpu_create_render_bundle_encoder(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let mut color_formats = vec![];
|
||||
|
@ -98,10 +96,10 @@ pub fn op_webgpu_render_bundle_encoder_finish(
|
|||
args: RenderBundleEncoderFinishArgs,
|
||||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.take::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.take::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
let render_bundle_encoder = Rc::try_unwrap(render_bundle_encoder_resource)
|
||||
.ok()
|
||||
.expect("unwrapping render_bundle_encoder_resource should succeed")
|
||||
|
@ -134,14 +132,14 @@ pub fn op_webgpu_render_bundle_encoder_set_bind_group(
|
|||
args: RenderBundleEncoderSetBindGroupArgs,
|
||||
zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let bind_group_resource = state
|
||||
.resource_table
|
||||
.get::<super::binding::WebGpuBindGroup>(args.bind_group)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let bind_group_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::binding::WebGpuBindGroup>(args.bind_group)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
|
||||
// I know this might look like it can be easily deduplicated, but it can not
|
||||
// be due to the lifetime of the args.dynamic_offsets_data slice. Because we
|
||||
|
@ -190,10 +188,10 @@ pub fn op_webgpu_render_bundle_encoder_push_debug_group(
|
|||
args: RenderBundleEncoderPushDebugGroupArgs,
|
||||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
|
||||
unsafe {
|
||||
let label = std::ffi::CString::new(args.group_label).unwrap();
|
||||
|
@ -217,10 +215,10 @@ pub fn op_webgpu_render_bundle_encoder_pop_debug_group(
|
|||
args: RenderBundleEncoderPopDebugGroupArgs,
|
||||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_pop_debug_group(
|
||||
&mut render_bundle_encoder_resource.0.borrow_mut(),
|
||||
|
@ -241,10 +239,10 @@ pub fn op_webgpu_render_bundle_encoder_insert_debug_marker(
|
|||
args: RenderBundleEncoderInsertDebugMarkerArgs,
|
||||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
|
||||
unsafe {
|
||||
let label = std::ffi::CString::new(args.marker_label).unwrap();
|
||||
|
@ -269,14 +267,14 @@ pub fn op_webgpu_render_bundle_encoder_set_pipeline(
|
|||
args: RenderBundleEncoderSetPipelineArgs,
|
||||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pipeline_resource = state
|
||||
.resource_table
|
||||
.get::<super::pipeline::WebGpuRenderPipeline>(args.pipeline)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_pipeline_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::pipeline::WebGpuRenderPipeline>(args.pipeline)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_pipeline(
|
||||
&mut render_bundle_encoder_resource.0.borrow_mut(),
|
||||
|
@ -303,12 +301,11 @@ pub fn op_webgpu_render_bundle_encoder_set_index_buffer(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
|
||||
render_bundle_encoder_resource
|
||||
.0
|
||||
|
@ -340,12 +337,11 @@ pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_vertex_buffer(
|
||||
&mut render_bundle_encoder_resource.0.borrow_mut(),
|
||||
|
@ -373,10 +369,10 @@ pub fn op_webgpu_render_bundle_encoder_draw(
|
|||
args: RenderBundleEncoderDrawArgs,
|
||||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw(
|
||||
&mut render_bundle_encoder_resource.0.borrow_mut(),
|
||||
|
@ -405,10 +401,10 @@ pub fn op_webgpu_render_bundle_encoder_draw_indexed(
|
|||
args: RenderBundleEncoderDrawIndexedArgs,
|
||||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw_indexed(
|
||||
&mut render_bundle_encoder_resource.0.borrow_mut(),
|
||||
|
@ -437,12 +433,11 @@ pub fn op_webgpu_render_bundle_encoder_draw_indirect(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)?;
|
||||
let render_bundle_encoder_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderBundleEncoder>(args.render_bundle_encoder_rid)?;
|
||||
|
||||
wgpu_core::command::bundle_ffi::wgpu_render_bundle_draw_indirect(
|
||||
&mut render_bundle_encoder_resource.0.borrow_mut(),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::error::bad_resource_id;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::ResourceId;
|
||||
use deno_core::{OpState, Resource};
|
||||
|
@ -53,8 +52,7 @@ pub fn op_webgpu_create_command_encoder(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let descriptor = wgpu_types::CommandEncoderDescriptor {
|
||||
|
@ -109,16 +107,15 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
|
||||
let mut color_attachments = vec![];
|
||||
|
||||
for color_attachment in args.color_attachments {
|
||||
let texture_view_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTextureView>(color_attachment.view)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let texture_view_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTextureView>(color_attachment.view)?;
|
||||
|
||||
let attachment = wgpu_core::command::RenderPassColorAttachment {
|
||||
view: texture_view_resource.0,
|
||||
|
@ -128,7 +125,6 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
|
|||
state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTextureView>(rid)
|
||||
.ok_or_else(bad_resource_id)
|
||||
})
|
||||
.transpose()?
|
||||
.map(|texture| texture.0),
|
||||
|
@ -167,10 +163,10 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
|
|||
let mut depth_stencil_attachment = None;
|
||||
|
||||
if let Some(attachment) = args.depth_stencil_attachment {
|
||||
let texture_view_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTextureView>(attachment.view)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let texture_view_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTextureView>(attachment.view)?;
|
||||
|
||||
depth_stencil_attachment =
|
||||
Some(wgpu_core::command::RenderPassDepthStencilAttachment {
|
||||
|
@ -242,8 +238,7 @@ pub fn op_webgpu_command_encoder_begin_compute_pass(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
|
||||
let descriptor = wgpu_core::command::ComputePassDescriptor {
|
||||
label: args.label.map(Cow::from),
|
||||
|
@ -282,18 +277,17 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_buffer(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let source_buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.source)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let source_buffer_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.source)?;
|
||||
let source_buffer = source_buffer_resource.0;
|
||||
let destination_buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.destination)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let destination_buffer_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.destination)?;
|
||||
let destination_buffer = destination_buffer_resource.0;
|
||||
|
||||
gfx_ok!(command_encoder => instance.command_encoder_copy_buffer_to_buffer(
|
||||
|
@ -349,17 +343,16 @@ pub fn op_webgpu_command_encoder_copy_buffer_to_texture(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let source_buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.source.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let destination_texture_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTexture>(args.destination.texture)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let source_buffer_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.source.buffer)?;
|
||||
let destination_texture_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTexture>(args.destination.texture)?;
|
||||
|
||||
let source = wgpu_core::command::ImageCopyBuffer {
|
||||
buffer: source_buffer_resource.0,
|
||||
|
@ -410,17 +403,16 @@ pub fn op_webgpu_command_encoder_copy_texture_to_buffer(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let source_texture_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTexture>(args.source.texture)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let destination_buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.destination.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let source_texture_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTexture>(args.source.texture)?;
|
||||
let destination_buffer_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.destination.buffer)?;
|
||||
|
||||
let source = wgpu_core::command::ImageCopyTexture {
|
||||
texture: source_texture_resource.0,
|
||||
|
@ -474,17 +466,16 @@ pub fn op_webgpu_command_encoder_copy_texture_to_texture(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let source_texture_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTexture>(args.source.texture)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let destination_texture_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTexture>(args.destination.texture)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let source_texture_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTexture>(args.source.texture)?;
|
||||
let destination_texture_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTexture>(args.destination.texture)?;
|
||||
|
||||
let source = wgpu_core::command::ImageCopyTexture {
|
||||
texture: source_texture_resource.0,
|
||||
|
@ -536,8 +527,7 @@ pub fn op_webgpu_command_encoder_push_debug_group(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
|
||||
gfx_ok!(command_encoder => instance
|
||||
|
@ -558,8 +548,7 @@ pub fn op_webgpu_command_encoder_pop_debug_group(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
|
||||
gfx_ok!(command_encoder => instance.command_encoder_pop_debug_group(command_encoder))
|
||||
|
@ -580,8 +569,7 @@ pub fn op_webgpu_command_encoder_insert_debug_marker(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
|
||||
gfx_ok!(command_encoder => instance.command_encoder_insert_debug_marker(
|
||||
|
@ -606,13 +594,11 @@ pub fn op_webgpu_command_encoder_write_timestamp(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)?;
|
||||
|
||||
gfx_ok!(command_encoder => instance.command_encoder_write_timestamp(
|
||||
command_encoder,
|
||||
|
@ -640,17 +626,14 @@ pub fn op_webgpu_command_encoder_resolve_query_set(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)?;
|
||||
let destination_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.destination)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::buffer::WebGpuBuffer>(args.destination)?;
|
||||
|
||||
gfx_ok!(command_encoder => instance.command_encoder_resolve_query_set(
|
||||
command_encoder,
|
||||
|
@ -676,8 +659,7 @@ pub fn op_webgpu_command_encoder_finish(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.take::<WebGpuCommandEncoder>(args.command_encoder_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.take::<WebGpuCommandEncoder>(args.command_encoder_rid)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let instance = state.borrow::<super::Instance>();
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// 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::ResourceId;
|
||||
|
@ -33,14 +32,13 @@ pub fn op_webgpu_compute_pass_set_pipeline(
|
|||
args: ComputePassSetPipelineArgs,
|
||||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let compute_pipeline_resource = state
|
||||
.resource_table
|
||||
.get::<super::pipeline::WebGpuComputePipeline>(args.pipeline)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let compute_pipeline_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::pipeline::WebGpuComputePipeline>(args.pipeline)?;
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_set_pipeline(
|
||||
&mut compute_pass_resource.0.borrow_mut(),
|
||||
|
@ -66,8 +64,7 @@ pub fn op_webgpu_compute_pass_dispatch(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_dispatch(
|
||||
&mut compute_pass_resource.0.borrow_mut(),
|
||||
|
@ -94,12 +91,10 @@ pub fn op_webgpu_compute_pass_dispatch_indirect(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)?;
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_dispatch_indirect(
|
||||
&mut compute_pass_resource.0.borrow_mut(),
|
||||
|
@ -125,12 +120,10 @@ pub fn op_webgpu_compute_pass_begin_pipeline_statistics_query(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_begin_pipeline_statistics_query(
|
||||
&mut compute_pass_resource.0.borrow_mut(),
|
||||
|
@ -154,8 +147,7 @@ pub fn op_webgpu_compute_pass_end_pipeline_statistics_query(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_end_pipeline_statistics_query(
|
||||
&mut compute_pass_resource.0.borrow_mut(),
|
||||
|
@ -179,12 +171,10 @@ pub fn op_webgpu_compute_pass_write_timestamp(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_write_timestamp(
|
||||
&mut compute_pass_resource.0.borrow_mut(),
|
||||
|
@ -210,14 +200,12 @@ pub fn op_webgpu_compute_pass_end_pass(
|
|||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<super::command_encoder::WebGpuCommandEncoder>(
|
||||
args.command_encoder_rid,
|
||||
)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
args.command_encoder_rid,
|
||||
)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.take::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.take::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
let compute_pass = &compute_pass_resource.0.borrow();
|
||||
let instance = state.borrow::<super::Instance>();
|
||||
|
||||
|
@ -243,14 +231,13 @@ pub fn op_webgpu_compute_pass_set_bind_group(
|
|||
args: ComputePassSetBindGroupArgs,
|
||||
zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let bind_group_resource = state
|
||||
.resource_table
|
||||
.get::<super::binding::WebGpuBindGroup>(args.bind_group)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let bind_group_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::binding::WebGpuBindGroup>(args.bind_group)?;
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
|
||||
unsafe {
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_set_bind_group(
|
||||
|
@ -288,8 +275,7 @@ pub fn op_webgpu_compute_pass_push_debug_group(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
|
||||
unsafe {
|
||||
let label = std::ffi::CString::new(args.group_label).unwrap();
|
||||
|
@ -316,8 +302,7 @@ pub fn op_webgpu_compute_pass_pop_debug_group(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
|
||||
wgpu_core::command::compute_ffi::wgpu_compute_pass_pop_debug_group(
|
||||
&mut compute_pass_resource.0.borrow_mut(),
|
||||
|
@ -340,8 +325,7 @@ pub fn op_webgpu_compute_pass_insert_debug_marker(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let compute_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePass>(args.compute_pass_rid)?;
|
||||
|
||||
unsafe {
|
||||
let label = std::ffi::CString::new(args.marker_label).unwrap();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::error::not_supported;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::error::{bad_resource_id, not_supported};
|
||||
use deno_core::include_js_files;
|
||||
use deno_core::op_async;
|
||||
use deno_core::op_sync;
|
||||
|
@ -398,8 +398,7 @@ pub async fn op_webgpu_request_device(
|
|||
let mut state = state.borrow_mut();
|
||||
let adapter_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuAdapter>(args.adapter_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuAdapter>(args.adapter_rid)?;
|
||||
let adapter = adapter_resource.0;
|
||||
let instance = state.borrow::<Instance>();
|
||||
|
||||
|
@ -533,10 +532,8 @@ pub fn op_webgpu_create_query_set(
|
|||
args: CreateQuerySetArgs,
|
||||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let device_resource =
|
||||
state.resource_table.get::<WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
let instance = &state.borrow::<Instance>();
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::error::bad_resource_id;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::ResourceId;
|
||||
use deno_core::{OpState, Resource};
|
||||
|
@ -173,24 +172,20 @@ pub fn op_webgpu_create_compute_pipeline(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let pipeline_layout = if let Some(rid) = args.layout {
|
||||
let id = state
|
||||
.resource_table
|
||||
.get::<WebGpuPipelineLayout>(rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let id = state.resource_table.get::<WebGpuPipelineLayout>(rid)?;
|
||||
Some(id.0)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let compute_shader_module_resource = state
|
||||
.resource_table
|
||||
.get::<super::shader::WebGpuShaderModule>(args.compute.module)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let compute_shader_module_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::shader::WebGpuShaderModule>(args.compute.module)?;
|
||||
|
||||
let descriptor = wgpu_core::pipeline::ComputePipelineDescriptor {
|
||||
label: args.label.map(Cow::from),
|
||||
|
@ -246,8 +241,7 @@ pub fn op_webgpu_compute_pipeline_get_bind_group_layout(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let compute_pipeline_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuComputePipeline>(args.compute_pipeline_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuComputePipeline>(args.compute_pipeline_rid)?;
|
||||
let compute_pipeline = compute_pipeline_resource.0;
|
||||
|
||||
let (bind_group_layout, maybe_err) = gfx_select!(compute_pipeline => instance.compute_pipeline_get_bind_group_layout(compute_pipeline, args.index, std::marker::PhantomData));
|
||||
|
@ -464,24 +458,21 @@ pub fn op_webgpu_create_render_pipeline(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let layout = if let Some(rid) = args.layout {
|
||||
let pipeline_layout_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuPipelineLayout>(rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let pipeline_layout_resource =
|
||||
state.resource_table.get::<WebGpuPipelineLayout>(rid)?;
|
||||
Some(pipeline_layout_resource.0)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let vertex_shader_module_resource = state
|
||||
.resource_table
|
||||
.get::<super::shader::WebGpuShaderModule>(args.vertex.module)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let vertex_shader_module_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::shader::WebGpuShaderModule>(args.vertex.module)?;
|
||||
|
||||
let descriptor = wgpu_core::pipeline::RenderPipelineDescriptor {
|
||||
label: args.label.map(Cow::from),
|
||||
|
@ -601,7 +592,6 @@ pub fn op_webgpu_create_render_pipeline(
|
|||
let fragment_shader_module_resource = state
|
||||
.resource_table
|
||||
.get::<super::shader::WebGpuShaderModule>(fragment.module)
|
||||
.ok_or_else(bad_resource_id)
|
||||
.unwrap();
|
||||
|
||||
wgpu_core::pipeline::FragmentState {
|
||||
|
@ -666,8 +656,7 @@ pub fn op_webgpu_render_pipeline_get_bind_group_layout(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let render_pipeline_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPipeline>(args.render_pipeline_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPipeline>(args.render_pipeline_rid)?;
|
||||
let render_pipeline = render_pipeline_resource.0;
|
||||
|
||||
let (bind_group_layout, maybe_err) = gfx_select!(render_pipeline => instance.render_pipeline_get_bind_group_layout(render_pipeline, args.index, std::marker::PhantomData));
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
use deno_core::error::bad_resource_id;
|
||||
use deno_core::error::null_opbuf;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::OpState;
|
||||
|
@ -27,19 +26,17 @@ pub fn op_webgpu_queue_submit(
|
|||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let instance = state.borrow::<super::Instance>();
|
||||
let queue_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuQueue>(args.queue_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let queue_resource =
|
||||
state.resource_table.get::<WebGpuQueue>(args.queue_rid)?;
|
||||
let queue = queue_resource.0;
|
||||
|
||||
let mut ids = vec![];
|
||||
|
||||
for rid in args.command_buffers {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::command_encoder::WebGpuCommandBuffer>(rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let buffer_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::command_encoder::WebGpuCommandBuffer>(rid)?;
|
||||
ids.push(buffer_resource.0);
|
||||
}
|
||||
|
||||
|
@ -76,13 +73,10 @@ pub fn op_webgpu_write_buffer(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)?;
|
||||
let buffer = buffer_resource.0;
|
||||
let queue_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuQueue>(args.queue_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let queue_resource =
|
||||
state.resource_table.get::<WebGpuQueue>(args.queue_rid)?;
|
||||
let queue = queue_resource.0;
|
||||
|
||||
let data = match args.size {
|
||||
|
@ -118,12 +112,9 @@ pub fn op_webgpu_write_texture(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let texture_resource = state
|
||||
.resource_table
|
||||
.get::<super::texture::WebGpuTexture>(args.destination.texture)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let queue_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuQueue>(args.queue_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::texture::WebGpuTexture>(args.destination.texture)?;
|
||||
let queue_resource =
|
||||
state.resource_table.get::<WebGpuQueue>(args.queue_rid)?;
|
||||
let queue = queue_resource.0;
|
||||
|
||||
let destination = wgpu_core::command::ImageCopyTexture {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// 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::type_error;
|
||||
use deno_core::error::AnyError;
|
||||
|
@ -41,8 +40,7 @@ pub fn op_webgpu_render_pass_set_viewport(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_viewport(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -74,8 +72,7 @@ pub fn op_webgpu_render_pass_set_scissor_rect(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_scissor_rect(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -111,8 +108,7 @@ pub fn op_webgpu_render_pass_set_blend_constant(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_blend_constant(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -141,8 +137,7 @@ pub fn op_webgpu_render_pass_set_stencil_reference(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_stencil_reference(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -167,12 +162,10 @@ pub fn op_webgpu_render_pass_begin_pipeline_statistics_query(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_begin_pipeline_statistics_query(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -196,8 +189,7 @@ pub fn op_webgpu_render_pass_end_pipeline_statistics_query(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_end_pipeline_statistics_query(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -221,12 +213,10 @@ pub fn op_webgpu_render_pass_write_timestamp(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
let query_set_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuQuerySet>(args.query_set)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_write_timestamp(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -252,17 +242,16 @@ pub fn op_webgpu_render_pass_execute_bundles(
|
|||
let mut render_bundle_ids = vec![];
|
||||
|
||||
for rid in &args.bundles {
|
||||
let render_bundle_resource = state
|
||||
.resource_table
|
||||
.get::<super::bundle::WebGpuRenderBundle>(*rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_bundle_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::bundle::WebGpuRenderBundle>(*rid)?;
|
||||
render_bundle_ids.push(render_bundle_resource.0);
|
||||
}
|
||||
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
unsafe {
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_execute_bundles(
|
||||
|
@ -290,14 +279,12 @@ pub fn op_webgpu_render_pass_end_pass(
|
|||
let command_encoder_resource = state
|
||||
.resource_table
|
||||
.get::<super::command_encoder::WebGpuCommandEncoder>(
|
||||
args.command_encoder_rid,
|
||||
)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
args.command_encoder_rid,
|
||||
)?;
|
||||
let command_encoder = command_encoder_resource.0;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.take::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.take::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
let render_pass = &render_pass_resource.0.borrow();
|
||||
let instance = state.borrow::<super::Instance>();
|
||||
|
||||
|
@ -320,14 +307,13 @@ pub fn op_webgpu_render_pass_set_bind_group(
|
|||
args: RenderPassSetBindGroupArgs,
|
||||
zero_copy: Option<ZeroCopyBuf>,
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let bind_group_resource = state
|
||||
.resource_table
|
||||
.get::<super::binding::WebGpuBindGroup>(args.bind_group)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let bind_group_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::binding::WebGpuBindGroup>(args.bind_group)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
// I know this might look like it can be easily deduplicated, but it can not
|
||||
// be due to the lifetime of the args.dynamic_offsets_data slice. Because we
|
||||
|
@ -378,8 +364,7 @@ pub fn op_webgpu_render_pass_push_debug_group(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
unsafe {
|
||||
let label = std::ffi::CString::new(args.group_label).unwrap();
|
||||
|
@ -406,8 +391,7 @@ pub fn op_webgpu_render_pass_pop_debug_group(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_pop_debug_group(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -430,8 +414,7 @@ pub fn op_webgpu_render_pass_insert_debug_marker(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
unsafe {
|
||||
let label = std::ffi::CString::new(args.marker_label).unwrap();
|
||||
|
@ -457,14 +440,13 @@ pub fn op_webgpu_render_pass_set_pipeline(
|
|||
args: RenderPassSetPipelineArgs,
|
||||
_: (),
|
||||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pipeline_resource = state
|
||||
.resource_table
|
||||
.get::<super::pipeline::WebGpuRenderPipeline>(args.pipeline)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
let render_pipeline_resource =
|
||||
state
|
||||
.resource_table
|
||||
.get::<super::pipeline::WebGpuRenderPipeline>(args.pipeline)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_set_pipeline(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -491,12 +473,10 @@ pub fn op_webgpu_render_pass_set_index_buffer(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
let size = if let Some(size) = args.size {
|
||||
Some(
|
||||
|
@ -534,12 +514,10 @@ pub fn op_webgpu_render_pass_set_vertex_buffer(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::buffer::WebGpuBuffer>(args.buffer)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
let size = if let Some(size) = args.size {
|
||||
Some(
|
||||
|
@ -578,8 +556,7 @@ pub fn op_webgpu_render_pass_draw(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_draw(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -610,8 +587,7 @@ pub fn op_webgpu_render_pass_draw_indexed(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_draw_indexed(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -640,12 +616,10 @@ pub fn op_webgpu_render_pass_draw_indirect(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_draw_indirect(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
@ -671,12 +645,10 @@ pub fn op_webgpu_render_pass_draw_indexed_indirect(
|
|||
) -> Result<WebGpuResult, AnyError> {
|
||||
let buffer_resource = state
|
||||
.resource_table
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::buffer::WebGpuBuffer>(args.indirect_buffer)?;
|
||||
let render_pass_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuRenderPass>(args.render_pass_rid)?;
|
||||
|
||||
wgpu_core::command::render_ffi::wgpu_render_pass_draw_indexed_indirect(
|
||||
&mut render_pass_resource.0.borrow_mut(),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::error::bad_resource_id;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::ResourceId;
|
||||
use deno_core::{OpState, Resource};
|
||||
|
@ -84,8 +83,7 @@ pub fn op_webgpu_create_sampler(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let descriptor = wgpu_core::resource::SamplerDescriptor {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// 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::ResourceId;
|
||||
|
@ -35,8 +34,7 @@ pub fn op_webgpu_create_shader_module(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let source = match args.code {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::error::not_supported;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::error::{bad_resource_id, not_supported};
|
||||
use deno_core::ResourceId;
|
||||
use deno_core::{OpState, Resource};
|
||||
use serde::Deserialize;
|
||||
|
@ -149,8 +149,7 @@ pub fn op_webgpu_create_texture(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let device_resource = state
|
||||
.resource_table
|
||||
.get::<super::WebGpuDevice>(args.device_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<super::WebGpuDevice>(args.device_rid)?;
|
||||
let device = device_resource.0;
|
||||
|
||||
let descriptor = wgpu_core::resource::TextureDescriptor {
|
||||
|
@ -204,8 +203,7 @@ pub fn op_webgpu_create_texture_view(
|
|||
let instance = state.borrow::<super::Instance>();
|
||||
let texture_resource = state
|
||||
.resource_table
|
||||
.get::<WebGpuTexture>(args.texture_rid)
|
||||
.ok_or_else(bad_resource_id)?;
|
||||
.get::<WebGpuTexture>(args.texture_rid)?;
|
||||
let texture = texture_resource.0;
|
||||
|
||||
let descriptor = wgpu_core::resource::TextureViewDescriptor {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue