Skip to content

Conversation

@andyleiserson
Copy link
Contributor

Of createRenderPipelineAsync, the spec says:

If pipeline creation fails, the returned Promise rejects with an GPUPipelineError. (A GPUError is not dispatched to the device.)

This changes the deno bindings to do as it says.

Ancillary note: Since pipeline creation is not actually async, the only reason to use these functions would be to follow the spec's recommendation that they are preferred, possibly in hopes of a future performance improvement.

To simplify the pipeline creation functions, this change also adds some WebIDL converters, which eliminates an explicit error return from new_render_pipeline. These changes are in separate commits.

Testing
By the CTS.

Squash or Rebase? Rebase (after squashing any fixups)

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • This might be salient for a Deno changelog, but doesn't seem important to note in the wgpu changelog.

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not the deno_webgpu owner, but these changes look good to me.

#[derive(Clone, Copy)]
pub(crate) struct GPUTextureUsageFlags(pub(crate) wgpu_types::TextureUsages);

impl<'a> WebIdlConverter<'a> for GPUTextureUsageFlags {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly doing it this way is better than performing ad-hoc fallible conversions elsewhere. But these three converters are pretty repetitive. If there are other flag-like types that would benefit from this treatment, it might be worth figuring out some way to do this with generic code, or at least a macro.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, my only hesitation is that there might even be something out-of-the-box that can do it if we investigate. But otherwise a macro is a good idea.

Copy link
Member

@ErichDonGubler ErichDonGubler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had accidentally re-invented this myself with, i.e., 9d684eb, during last week. 😅 So, I can say with confidence that this LGTM, too! In my recent experience, this has blocked full coverage of the tests I wanted to enable for #8652 and #8762.

Comment on lines +398 to +421
pub(crate) fn make_pipeline_error<'a>(
scope: &mut v8::HandleScope<'a>,
reason: GPUPipelineErrorReason,
message: &str,
) -> v8::Local<'a, v8::Object> {
let state = JsRuntime::op_state_from(scope);
let class = state
.borrow()
.borrow::<crate::PipelineErrorClass>()
.0
.clone();
let constructor =
v8::Local::<v8::Function>::try_from(v8::Local::new(scope, class)).unwrap();
let message_str = v8::String::new(scope, message).unwrap();
let reason_str = v8::String::new(scope, &reason.to_string()).unwrap();

let options = v8::Object::new(scope);
let key = v8::String::new(scope, "reason").unwrap();
options.set(scope, key.into(), reason_str.into());

constructor
.new_instance(scope, &[message_str.into(), options.into()])
.unwrap()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: It's so annoying that we have to work around the error registry system this way. We're definitely not the first to run into this pain…but I'm not sure what solutions upstream would accept to even start to tackle it. 😐

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually didn't see a lot of precedent for this so I'd be interested what you were looking at. Most of the error handling stuff seemed to be about ways to wrap Rust errors for JS, which didn't seem like what we want here since we want to produce a precise spec-defined thing.

@andyleiserson andyleiserson merged commit b9324e9 into gfx-rs:trunk Dec 19, 2025
47 checks passed
@andyleiserson andyleiserson deleted the push-mxnpupsnorln branch December 19, 2025 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants