Skip to content

Commit

Permalink
fix(webgpu): don't default to 0 for setVertexBuffer.size & properly u…
Browse files Browse the repository at this point in the history
…se webidl.setlike (denoland#17800)
  • Loading branch information
crowlKats authored Feb 23, 2023
1 parent 6233c0a commit 451b45e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
10 changes: 10 additions & 0 deletions cli/tests/unit/webgpu_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ Deno.test({
Deno.close(Number(resources[resources.length - 1]));
});

Deno.test({
ignore: isWsl || isLinuxOrMacCI,
}, async function webgpuAdapterHasFeatures() {
const adapter = await navigator.gpu.requestAdapter();
assert(adapter);
assert(adapter.features);
const resources = Object.keys(Deno.resources());
Deno.close(Number(resources[resources.length - 1]));
});

async function checkIsWsl() {
return Deno.build.os === "linux" && await hasMicrosoftProcVersion();

Expand Down
17 changes: 10 additions & 7 deletions ext/webgpu/01_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,12 @@ function createGPUSupportedFeatures(features) {
/** @type {GPUSupportedFeatures} */
const supportedFeatures = webidl.createBranded(GPUSupportedFeatures);
supportedFeatures[webidl.setlikeInner] = new Set(features);
return webidl.setlike(
webidl.setlike(
supportedFeatures,
GPUSupportedFeaturesPrototype,
true,
);
return supportedFeatures;
}

class GPUSupportedFeatures {
Expand Down Expand Up @@ -4903,14 +4904,14 @@ class GPURenderBundleEncoder {
* @param {number} offset
* @param {number} size
*/
setVertexBuffer(slot, buffer, offset = 0, size = 0) {
setVertexBuffer(slot, buffer, offset = 0, size) {
webidl.assertBranded(this, GPURenderBundleEncoderPrototype);
const prefix =
"Failed to execute 'setVertexBuffer' on 'GPURenderBundleEncoder'";
webidl.requiredArguments(arguments.length, 2, { prefix });
slot = webidl.converters.GPUSize32(slot, {
prefix,
context: "Argument 2",
context: "Argument 1",
});
buffer = webidl.converters.GPUBuffer(buffer, {
prefix,
Expand All @@ -4920,10 +4921,12 @@ class GPURenderBundleEncoder {
prefix,
context: "Argument 3",
});
size = webidl.converters.GPUSize64(size, {
prefix,
context: "Argument 4",
});
if (size !== undefined) {
size = webidl.converters.GPUSize64(size, {
prefix,
context: "Argument 4",
});
}
const device = assertDevice(this, { prefix, context: "this" });
const renderBundleEncoderRid = assertResource(this, {
prefix,
Expand Down
14 changes: 9 additions & 5 deletions ext/webgpu/bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer(
slot: u32,
buffer: ResourceId,
offset: u64,
size: u64,
size: Option<u64>,
) -> Result<WebGpuResult, AnyError> {
let buffer_resource = state
.resource_table
Expand All @@ -298,10 +298,14 @@ pub fn op_webgpu_render_bundle_encoder_set_vertex_buffer(
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"))?,
);
let size = if let Some(size) = size {
Some(
std::num::NonZeroU64::new(size)
.ok_or_else(|| type_error("size must be larger than 0"))?,
)
} else {
None
};

wgpu_core::command::bundle_ffi::wgpu_render_bundle_set_vertex_buffer(
&mut render_bundle_encoder_resource.0.borrow_mut(),
Expand Down

0 comments on commit 451b45e

Please sign in to comment.