-
Notifications
You must be signed in to change notification settings - Fork 979
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
Synchronous alternatives to functions that return a Future. #3509
Comments
Hi! 👋 For now if you want to block on these functions we'd recommend something like pollster as you mentioned. I don't think there's much interest in providing synchronous alternatives at the API level right now. |
Pollster definitely works. However, I'd be shocked if others wouldn't want synchronous versions of these functions. In fact, if you look at the implementation of Instance::request_adapter in wpgu_core it isn't even an async function. So using pollster just adds an unnecessary dependency and unnecessary overhead for what could just be a simple synchronous function call. |
In fact, I'd argue that the only reason anyone would use Pollster is because they explicitly do not want to be using async versions of these functions. If they did want the async functionality they'd use something like Tokio. |
Right, this is meant to be an implementation detail for now. The overhead of going through pollster should be very low for Some of the other native functions are asynchronous and use callbacks internally (triggered by some GPU state change), so it would be good to avoid blocking on some of these functions in general. |
Fair enough. I agree that the overhead is minimal. Coming from JavaScript/Node.js hell I'm just a little wary of the code base being littered with async code. Most developers come to Rust to avoid that sort of thing :). |
Looking at the WebGPU spec:
ConclusionIn our implementation we could add sync variants for: GPU.requestAdapter()
GPUAdapter.requestDevice()
GPUShaderModule.compilationInfo()
GPUDevice.popErrorScope()
GPUAdapter.requestAdapterInfo() and possibly for IssueThe main issue is that to add even the easy ones ( |
Some previous discussion: #2970. |
It's not easily possible to polyfill them when targeting WebGPU because we have to yield to the browser's runtime and not block (i.e., |
As far as I am concerned, the synchronous versions aren't even need when targeting the web. Only enable them for native (non-web) platforms. For folks that want to target both native and web platforms they can either use the async versions or add a few compile time checks to handle both cases. |
This sounds like what I had in mind where the WebAssembly runtime will inject some extra machinery to make the async call look like a sync one. |
Ideally, functions like Instance::request_adapter, Adapter::request_device, etc. should have alternatives i.e. Instance::request_adapter_sync, Adapter::.request_device_sync, etc. that resolve immediately without returning a future. Using the asynchronous version that currently exists is annoying when only targeting desktop and involves having to either use a third-party library like pollster to wait for the Future, write the equivalent code ourselves to synchronously resolve the Future, or introduce a runtime like Tokio.
The WebGPU spec states that the following functions return Promises:
Having the corresponding synchronous versions of these functions would certainly be nice.
The text was updated successfully, but these errors were encountered: