Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix ArrayBuffer creation in buffer mapping
  • Loading branch information
kunalmohan committed Jun 27, 2020
1 parent b484836 commit db2d313
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 4 additions & 6 deletions components/script/dom/gpubuffer.rs
Expand Up @@ -19,7 +19,6 @@ use dom_struct::dom_struct;
use js::jsapi::{Heap, JSObject};
use js::jsval::UndefinedValue;
use js::rust::jsapi_wrapped::{DetachArrayBuffer, IsPromiseObject, RejectPromise};
use js::rust::MutableHandle;
use js::typedarray::{ArrayBuffer, CreateWith};
use std::cell::Cell;
use std::ops::Range;
Expand Down Expand Up @@ -277,12 +276,10 @@ impl AsyncWGPUListener for GPUBuffer {
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
match response {
WebGPUResponse::BufferMapAsync(bytes) => {
let cx = self.global().get_cx();
rooted!(in(*cx) let mut array_buffer = ptr::null_mut::<JSObject>());
match unsafe {
ArrayBuffer::create(
*self.global().get_cx(),
CreateWith::Slice(&bytes),
MutableHandle::from_raw(self.mapping.handle_mut()),
)
ArrayBuffer::create(*cx, CreateWith::Slice(&bytes), array_buffer.handle_mut())
} {
Ok(_) => promise.resolve_native(&()),
Err(()) => {
Expand All @@ -293,6 +290,7 @@ impl AsyncWGPUListener for GPUBuffer {
promise.reject_error(Error::Operation);
},
}
self.mapping.set(array_buffer.get());
self.state.set(GPUBufferState::Mapped);
},
_ => {
Expand Down
10 changes: 6 additions & 4 deletions components/script/dom/gpudevice.rs
Expand Up @@ -54,9 +54,8 @@ use crate::script_runtime::JSContext as SafeJSContext;
use arrayvec::ArrayVec;
use dom_struct::dom_struct;
use js::jsapi::{Heap, JSObject};
use js::rust::MutableHandle;
use js::typedarray::{ArrayBuffer, CreateWith};
use std::ptr::NonNull;
use std::ptr::{self, NonNull};
use webgpu::wgpu::binding_model::BufferBinding;
use webgpu::{self, wgt, WebGPU, WebGPUBindings, WebGPURequest};

Expand Down Expand Up @@ -182,14 +181,17 @@ impl GPUDeviceMethods for GPUDevice {
let state;
let mapping_range;
if descriptor.mappedAtCreation {
let cx = self.global().get_cx();
rooted!(in(*cx) let mut array_buffer = ptr::null_mut::<JSObject>());
unsafe {
assert!(ArrayBuffer::create(
*self.global().get_cx(),
*cx,
CreateWith::Length(descriptor.size as u32),
MutableHandle::from_raw(mapping.handle_mut()),
array_buffer.handle_mut(),
)
.is_ok());
}
mapping.set(array_buffer.get());
state = GPUBufferState::MappedAtCreation;
mapping_range = 0..descriptor.size;
} else {
Expand Down

0 comments on commit db2d313

Please sign in to comment.