Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webgpu): don't default to 0 for setVertexBuffer.size & properly use webidl.setlike #17800

Merged
merged 5 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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