mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implement GPUBuffer.getMappedRange()
This commit is contained in:
parent
19b36bd795
commit
575036bb88
4 changed files with 132 additions and 91 deletions
|
@ -4,7 +4,7 @@
|
|||
|
||||
#![allow(unsafe_code)]
|
||||
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::cell::{DomRefCell, RefCell};
|
||||
use crate::dom::bindings::codegen::Bindings::GPUBindGroupBinding::{
|
||||
GPUBindGroupDescriptor, GPUBindingResource,
|
||||
};
|
||||
|
@ -54,8 +54,8 @@ use crate::script_runtime::JSContext as SafeJSContext;
|
|||
use arrayvec::ArrayVec;
|
||||
use dom_struct::dom_struct;
|
||||
use js::jsapi::{Heap, JSObject};
|
||||
use js::typedarray::{ArrayBuffer, CreateWith};
|
||||
use std::ptr::{self, NonNull};
|
||||
use std::ptr::NonNull;
|
||||
use std::rc::Rc;
|
||||
use webgpu::wgpu::binding_model::BufferBinding;
|
||||
use webgpu::{self, wgt, WebGPU, WebGPUBindings, WebGPURequest};
|
||||
|
||||
|
@ -177,24 +177,16 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
.expect("Failed to create WebGPU buffer");
|
||||
|
||||
let buffer = webgpu::WebGPUBuffer(id);
|
||||
let mapping = RootedTraceableBox::new(Heap::default());
|
||||
let mapping;
|
||||
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(
|
||||
*cx,
|
||||
CreateWith::Length(descriptor.size as u32),
|
||||
array_buffer.handle_mut(),
|
||||
)
|
||||
.is_ok());
|
||||
}
|
||||
mapping.set(array_buffer.get());
|
||||
let buf_data = vec![0u8; descriptor.size as usize];
|
||||
mapping = Rc::new(RefCell::new(Some(buf_data)));
|
||||
state = GPUBufferState::MappedAtCreation;
|
||||
mapping_range = 0..descriptor.size;
|
||||
} else {
|
||||
mapping = Rc::new(RefCell::new(None));
|
||||
state = GPUBufferState::Unmapped;
|
||||
mapping_range = 0..0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue