webgpu: Sync GPUBuffer (#33154)

* More helpers on `Promise`

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Sync `GPUBuffer`

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Set some good expectations

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Some bad expect

also on firefox

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Extract DataBlock, DataView impl from GPUBuffer

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

* Fix size check to work on 32bit platforms

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>

---------

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
Samson 2024-08-27 09:54:55 +02:00 committed by GitHub
parent bb5926b329
commit 7fce24f9d5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 690 additions and 1163 deletions

View file

@ -52,6 +52,12 @@ pub struct Promise {
permanent_js_root: Heap<JSVal>,
}
impl PartialEq for Promise {
fn eq(&self, other: &Self) -> bool {
self.reflector == other.reflector
}
}
/// Private helper to enable adding new methods to `Rc<Promise>`.
trait PromiseHelper {
fn initialize(&self, cx: SafeJSContext);
@ -231,6 +237,18 @@ impl Promise {
matches!(state, PromiseState::Rejected | PromiseState::Fulfilled)
}
#[allow(unsafe_code)]
pub fn is_rejected(&self) -> bool {
let state = unsafe { GetPromiseState(self.promise_obj()) };
matches!(state, PromiseState::Rejected)
}
#[allow(unsafe_code)]
pub fn is_pending(&self) -> bool {
let state = unsafe { GetPromiseState(self.promise_obj()) };
matches!(state, PromiseState::Pending)
}
#[allow(unsafe_code)]
pub fn promise_obj(&self) -> HandleObject {
let obj = self.reflector().get_jsobject();