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 #3170.
  • Loading branch information
jimblandy committed Nov 3, 2022
1 parent 7f64498 commit 9fb9dbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ Bottom level categories:

- Fixed WebGL not displaying srgb targets correctly if a non-screen filling viewport was previously set. By @Wumpf in [#3093](https://github.com/gfx-rs/wgpu/pull/3093)

#### deno-webgpu

- Let `setVertexBuffer` and `setIndexBuffer` calls on
`GPURenderBundleEncoder` throw an error if the `size` argument is
zero, rather than treating that as "until the end of the buffer".
By @jimblandy in [#3171](https://github.com/gfx-rs/wgpu/pull/3171)

### Examples
- Log adapter info in hello example on wasm target by @JolifantoBambla in [#2858](https://github.com/gfx-rs/wgpu/pull/2858)

Expand Down
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 9fb9dbf

Please sign in to comment.