Skip to content

Commit

Permalink
deno_webgpu: Don't confuse zero with "to the end of the buffer".
Browse files Browse the repository at this point in the history
`RenderBundleEncoder::set_index_buffer` and `set_vertex_buffer`
interpret a `size` of `None` to mean "from the given offset to the end
of the buffer", but `std::num::NonZeroU64::new` produces `None` when
its argument is zero, which is quite different. Fix this similarly to
the way it's handled in `op_webgpu_render_pass_set_index_buffer`.

The WebGPU spec says this should work; filed as gfx-rs#3170.
  • Loading branch information
jimblandy committed Nov 3, 2022
1 parent 8a7240c commit 3a4b985
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions deno_webgpu/src/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

use deno_core::error::AnyError;
use deno_core::error::{type_error, AnyError};
use deno_core::op;
use deno_core::OpState;
use deno_core::Resource;
Expand Down Expand Up @@ -255,16 +255,14 @@ pub fn op_webgpu_render_bundle_encoder_set_index_buffer(
let render_bundle_encoder_resource = state
.resource_table
.get::<WebGpuRenderBundleEncoder>(render_bundle_encoder_rid)?;
let size = Some(
std::num::NonZeroU64::new(size).ok_or_else(|| type_error("size must be larger than 0"))?,
);

render_bundle_encoder_resource
.0
.borrow_mut()
.set_index_buffer(
buffer_resource.0,
index_format,
offset,
std::num::NonZeroU64::new(size),
);
.set_index_buffer(buffer_resource.0, index_format, offset, size);

Ok(WebGpuResult::empty())
}
Expand All @@ -284,13 +282,16 @@ pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer(
let render_bundle_encoder_resource = state
.resource_table
.get::<WebGpuRenderBundleEncoder>(render_bundle_encoder_rid)?;
let size = Some(
std::num::NonZeroU64::new(size).ok_or_else(|| type_error("size must be larger than 0"))?,
);

wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_vertex_buffer(
&mut render_bundle_encoder_resource.0.borrow_mut(),
slot,
buffer_resource.0,
offset,
std::num::NonZeroU64::new(size),
size,
);

Ok(WebGpuResult::empty())
Expand Down

0 comments on commit 3a4b985

Please sign in to comment.