mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Report errors from void returning operations
This commit is contained in:
parent
6499367fe2
commit
8cb5fad828
10 changed files with 140 additions and 38 deletions
|
@ -8,10 +8,11 @@ use crate::dom::bindings::codegen::Bindings::GPUMapModeBinding::GPUMapModeConsta
|
|||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::reflector::DomObject;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::gpu::{response_async, AsyncWGPUListener};
|
||||
use crate::dom::gpudevice::GPUDevice;
|
||||
use crate::dom::promise::Promise;
|
||||
use crate::realms::InRealm;
|
||||
use crate::script_runtime::JSContext;
|
||||
|
@ -25,9 +26,7 @@ use std::ffi::c_void;
|
|||
use std::ops::Range;
|
||||
use std::ptr::NonNull;
|
||||
use std::rc::Rc;
|
||||
use webgpu::{
|
||||
wgpu::device::HostMap, WebGPU, WebGPUBuffer, WebGPUDevice, WebGPURequest, WebGPUResponse,
|
||||
};
|
||||
use webgpu::{wgpu::device::HostMap, WebGPU, WebGPUBuffer, WebGPURequest, WebGPUResponse};
|
||||
|
||||
const RANGE_OFFSET_ALIGN_MASK: u64 = 8;
|
||||
const RANGE_SIZE_ALIGN_MASK: u64 = 4;
|
||||
|
@ -61,7 +60,7 @@ pub struct GPUBuffer {
|
|||
label: DomRefCell<Option<USVString>>,
|
||||
state: Cell<GPUBufferState>,
|
||||
buffer: WebGPUBuffer,
|
||||
device: WebGPUDevice,
|
||||
device: Dom<GPUDevice>,
|
||||
size: GPUSize64,
|
||||
#[ignore_malloc_size_of = "promises are hard"]
|
||||
map_promise: DomRefCell<Option<Rc<Promise>>>,
|
||||
|
@ -72,7 +71,7 @@ impl GPUBuffer {
|
|||
fn new_inherited(
|
||||
channel: WebGPU,
|
||||
buffer: WebGPUBuffer,
|
||||
device: WebGPUDevice,
|
||||
device: &GPUDevice,
|
||||
state: GPUBufferState,
|
||||
size: GPUSize64,
|
||||
map_info: DomRefCell<Option<GPUBufferMapInfo>>,
|
||||
|
@ -83,7 +82,7 @@ impl GPUBuffer {
|
|||
channel,
|
||||
label: DomRefCell::new(label),
|
||||
state: Cell::new(state),
|
||||
device,
|
||||
device: Dom::from_ref(device),
|
||||
buffer,
|
||||
map_promise: DomRefCell::new(None),
|
||||
size,
|
||||
|
@ -96,7 +95,7 @@ impl GPUBuffer {
|
|||
global: &GlobalScope,
|
||||
channel: WebGPU,
|
||||
buffer: WebGPUBuffer,
|
||||
device: WebGPUDevice,
|
||||
device: &GPUDevice,
|
||||
state: GPUBufferState,
|
||||
size: GPUSize64,
|
||||
map_info: DomRefCell<Option<GPUBufferMapInfo>>,
|
||||
|
@ -145,6 +144,8 @@ impl GPUBufferMethods for GPUBuffer {
|
|||
let m_range = m_info.mapping_range.clone();
|
||||
if let Err(e) = self.channel.0.send(WebGPURequest::UnmapBuffer {
|
||||
buffer_id: self.id().0,
|
||||
device_id: self.device.id().0,
|
||||
scope_id: self.device.use_current_scope(),
|
||||
array_buffer: IpcSharedMemory::from_bytes(m_info.mapping.borrow().as_slice()),
|
||||
is_map_read: m_info.map_mode == Some(GPUMapModeConstants::READ),
|
||||
offset: m_range.start,
|
||||
|
|
|
@ -29,7 +29,7 @@ use std::borrow::Cow;
|
|||
use std::cell::Cell;
|
||||
use std::collections::HashSet;
|
||||
use webgpu::wgpu::command as wgpu_com;
|
||||
use webgpu::{self, wgt, WebGPU, WebGPURequest};
|
||||
use webgpu::{self, identity::WebGPUOpResult, wgt, WebGPU, WebGPURequest};
|
||||
|
||||
// https://gpuweb.github.io/gpuweb/#enumdef-encoder-state
|
||||
#[derive(MallocSizeOf, PartialEq)]
|
||||
|
@ -103,6 +103,10 @@ impl GPUCommandEncoder {
|
|||
*self.state.borrow_mut() = GPUCommandEncoderState::Closed;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn device(&self) -> &GPUDevice {
|
||||
&*self.device
|
||||
}
|
||||
}
|
||||
|
||||
impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
||||
|
@ -254,9 +258,15 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
size: GPUSize64,
|
||||
) {
|
||||
let valid = *self.state.borrow() == GPUCommandEncoderState::Open;
|
||||
let scope_id = self.device.use_current_scope();
|
||||
|
||||
if !valid {
|
||||
// TODO: Record an error in the current scope.
|
||||
self.device.handle_server_msg(
|
||||
scope_id,
|
||||
WebGPUOpResult::ValidationError(String::from(
|
||||
"CommandEncoder is not in Open State",
|
||||
)),
|
||||
);
|
||||
self.valid.set(false);
|
||||
return;
|
||||
}
|
||||
|
@ -269,6 +279,8 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
.0
|
||||
.send(WebGPURequest::CopyBufferToBuffer {
|
||||
command_encoder_id: self.encoder.0,
|
||||
device_id: self.device.id().0,
|
||||
scope_id,
|
||||
source_id: source.id().0,
|
||||
source_offset,
|
||||
destination_id: destination.id().0,
|
||||
|
@ -286,9 +298,15 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
copy_size: GPUExtent3D,
|
||||
) {
|
||||
let valid = *self.state.borrow() == GPUCommandEncoderState::Open;
|
||||
let scope_id = self.device.use_current_scope();
|
||||
|
||||
if !valid {
|
||||
// TODO: Record an error in the current scope.
|
||||
self.device.handle_server_msg(
|
||||
scope_id,
|
||||
WebGPUOpResult::ValidationError(String::from(
|
||||
"CommandEncoder is not in Open State",
|
||||
)),
|
||||
);
|
||||
self.valid.set(false);
|
||||
return;
|
||||
}
|
||||
|
@ -301,6 +319,8 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
.0
|
||||
.send(WebGPURequest::CopyBufferToTexture {
|
||||
command_encoder_id: self.encoder.0,
|
||||
device_id: self.device.id().0,
|
||||
scope_id,
|
||||
source: convert_buffer_cv(source),
|
||||
destination: convert_texture_cv(destination),
|
||||
copy_size: convert_texture_size_to_wgt(&convert_texture_size_to_dict(©_size)),
|
||||
|
@ -316,9 +336,15 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
copy_size: GPUExtent3D,
|
||||
) {
|
||||
let valid = *self.state.borrow() == GPUCommandEncoderState::Open;
|
||||
let scope_id = self.device.use_current_scope();
|
||||
|
||||
if !valid {
|
||||
// TODO: Record an error in the current scope.
|
||||
self.device.handle_server_msg(
|
||||
scope_id,
|
||||
WebGPUOpResult::ValidationError(String::from(
|
||||
"CommandEncoder is not in Open State",
|
||||
)),
|
||||
);
|
||||
self.valid.set(false);
|
||||
return;
|
||||
}
|
||||
|
@ -331,6 +357,8 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
.0
|
||||
.send(WebGPURequest::CopyTextureToBuffer {
|
||||
command_encoder_id: self.encoder.0,
|
||||
device_id: self.device.id().0,
|
||||
scope_id,
|
||||
source: convert_texture_cv(source),
|
||||
destination: convert_buffer_cv(destination),
|
||||
copy_size: convert_texture_size_to_wgt(&convert_texture_size_to_dict(©_size)),
|
||||
|
@ -346,9 +374,15 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
copy_size: GPUExtent3D,
|
||||
) {
|
||||
let valid = *self.state.borrow() == GPUCommandEncoderState::Open;
|
||||
let scope_id = self.device.use_current_scope();
|
||||
|
||||
if !valid {
|
||||
// TODO: Record an error in the current scope.
|
||||
self.device.handle_server_msg(
|
||||
scope_id,
|
||||
WebGPUOpResult::ValidationError(String::from(
|
||||
"CommandEncoder is not in Open State",
|
||||
)),
|
||||
);
|
||||
self.valid.set(false);
|
||||
return;
|
||||
}
|
||||
|
@ -357,6 +391,8 @@ impl GPUCommandEncoderMethods for GPUCommandEncoder {
|
|||
.0
|
||||
.send(WebGPURequest::CopyTextureToTexture {
|
||||
command_encoder_id: self.encoder.0,
|
||||
device_id: self.device.id().0,
|
||||
scope_id,
|
||||
source: convert_texture_cv(source),
|
||||
destination: convert_texture_cv(destination),
|
||||
copy_size: convert_texture_size_to_wgt(&convert_texture_size_to_dict(©_size)),
|
||||
|
|
|
@ -93,6 +93,8 @@ impl GPUComputePassEncoderMethods for GPUComputePassEncoder {
|
|||
.0
|
||||
.send(WebGPURequest::RunComputePass {
|
||||
command_encoder_id: self.command_encoder.id().0,
|
||||
device_id: self.command_encoder.device().id().0,
|
||||
scope_id: self.command_encoder.device().use_current_scope(),
|
||||
compute_pass,
|
||||
})
|
||||
.expect("Failed to send RunComputePass");
|
||||
|
|
|
@ -148,12 +148,14 @@ impl GPUDevice {
|
|||
label: Option<String>,
|
||||
) -> DomRoot<Self> {
|
||||
let queue = GPUQueue::new(global, channel.clone(), queue);
|
||||
reflect_dom_object(
|
||||
let device = reflect_dom_object(
|
||||
Box::new(GPUDevice::new_inherited(
|
||||
channel, adapter, extensions, limits, device, &queue, label,
|
||||
)),
|
||||
global,
|
||||
)
|
||||
);
|
||||
queue.set_device(&*device);
|
||||
device
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,7 +343,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
&self.global(),
|
||||
self.channel.clone(),
|
||||
buffer,
|
||||
self.device,
|
||||
&self,
|
||||
state,
|
||||
descriptor.size,
|
||||
map_info,
|
||||
|
|
|
@ -11,24 +11,25 @@ use crate::dom::bindings::codegen::Bindings::GPUQueueBinding::GPUQueueMethods;
|
|||
use crate::dom::bindings::codegen::Bindings::GPUTextureBinding::GPUExtent3D;
|
||||
use crate::dom::bindings::error::{Error, Fallible};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::str::USVString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::gpubuffer::{GPUBuffer, GPUBufferState};
|
||||
use crate::dom::gpucommandbuffer::GPUCommandBuffer;
|
||||
use crate::dom::gpucommandencoder::{convert_texture_cv, convert_texture_data_layout};
|
||||
use crate::dom::gpudevice::{convert_texture_size_to_dict, convert_texture_size_to_wgt};
|
||||
use crate::dom::gpudevice::{convert_texture_size_to_dict, convert_texture_size_to_wgt, GPUDevice};
|
||||
use dom_struct::dom_struct;
|
||||
use ipc_channel::ipc::IpcSharedMemory;
|
||||
use js::rust::CustomAutoRooterGuard;
|
||||
use js::typedarray::ArrayBuffer;
|
||||
use webgpu::{wgt, WebGPU, WebGPUQueue, WebGPURequest};
|
||||
use webgpu::{identity::WebGPUOpResult, wgt, WebGPU, WebGPUQueue, WebGPURequest};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct GPUQueue {
|
||||
reflector_: Reflector,
|
||||
#[ignore_malloc_size_of = "defined in webgpu"]
|
||||
channel: WebGPU,
|
||||
device: DomRefCell<Option<Dom<GPUDevice>>>,
|
||||
label: DomRefCell<Option<USVString>>,
|
||||
queue: WebGPUQueue,
|
||||
}
|
||||
|
@ -38,6 +39,7 @@ impl GPUQueue {
|
|||
GPUQueue {
|
||||
channel,
|
||||
reflector_: Reflector::new(),
|
||||
device: DomRefCell::new(None),
|
||||
label: DomRefCell::new(None),
|
||||
queue,
|
||||
}
|
||||
|
@ -48,6 +50,12 @@ impl GPUQueue {
|
|||
}
|
||||
}
|
||||
|
||||
impl GPUQueue {
|
||||
pub fn set_device(&self, device: &GPUDevice) {
|
||||
*self.device.borrow_mut() = Some(Dom::from_ref(device));
|
||||
}
|
||||
}
|
||||
|
||||
impl GPUQueueMethods for GPUQueue {
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label
|
||||
fn GetLabel(&self) -> Option<USVString> {
|
||||
|
@ -67,8 +75,14 @@ impl GPUQueueMethods for GPUQueue {
|
|||
_ => false,
|
||||
})
|
||||
});
|
||||
let scope_id = self.device.borrow().as_ref().unwrap().use_current_scope();
|
||||
if !valid {
|
||||
// TODO: Generate error to the ErrorScope
|
||||
self.device.borrow().as_ref().unwrap().handle_server_msg(
|
||||
scope_id,
|
||||
WebGPUOpResult::ValidationError(String::from(
|
||||
"Referenced GPUBuffer(s) are not Unmapped",
|
||||
)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
let command_buffers = command_buffers.iter().map(|cb| cb.id().0).collect();
|
||||
|
@ -76,6 +90,7 @@ impl GPUQueueMethods for GPUQueue {
|
|||
.0
|
||||
.send(WebGPURequest::Submit {
|
||||
queue_id: self.queue.0,
|
||||
scope_id,
|
||||
command_buffers,
|
||||
})
|
||||
.unwrap();
|
||||
|
@ -111,6 +126,7 @@ impl GPUQueueMethods for GPUQueue {
|
|||
);
|
||||
if let Err(e) = self.channel.0.send(WebGPURequest::WriteBuffer {
|
||||
queue_id: self.queue.0,
|
||||
scope_id: self.device.borrow().as_ref().unwrap().use_current_scope(),
|
||||
buffer_id: buffer.id().0,
|
||||
buffer_offset,
|
||||
data: final_data,
|
||||
|
@ -144,6 +160,7 @@ impl GPUQueueMethods for GPUQueue {
|
|||
|
||||
if let Err(e) = self.channel.0.send(WebGPURequest::WriteTexture {
|
||||
queue_id: self.queue.0,
|
||||
scope_id: self.device.borrow().as_ref().unwrap().use_current_scope(),
|
||||
texture_cv,
|
||||
data_layout: texture_layout,
|
||||
size: write_size,
|
||||
|
|
|
@ -165,6 +165,8 @@ impl GPURenderPassEncoderMethods for GPURenderPassEncoder {
|
|||
.0
|
||||
.send(WebGPURequest::RunRenderPass {
|
||||
command_encoder_id: self.command_encoder.id().0,
|
||||
device_id: self.command_encoder.device().id().0,
|
||||
scope_id: self.command_encoder.device().use_current_scope(),
|
||||
render_pass,
|
||||
})
|
||||
.expect("Failed to send RunRenderPass");
|
||||
|
|
|
@ -5,8 +5,7 @@
|
|||
// https://gpuweb.github.io/gpuweb/#gpu-interface
|
||||
[Exposed=(Window, DedicatedWorker), Pref="dom.webgpu.enabled"]
|
||||
interface GPU {
|
||||
// May reject with DOMException // TODO: DOMException("OperationError")?
|
||||
Promise<GPUAdapter> requestAdapter(optional GPURequestAdapterOptions options = {});
|
||||
Promise<GPUAdapter?> requestAdapter(optional GPURequestAdapterOptions options = {});
|
||||
};
|
||||
|
||||
// https://gpuweb.github.io/gpuweb/#dictdef-gpurequestadapteroptions
|
||||
|
|
|
@ -9,8 +9,7 @@ interface GPUAdapter {
|
|||
readonly attribute object extensions;
|
||||
//readonly attribute GPULimits limits; Don’t expose higher limits for now.
|
||||
|
||||
// May reject with DOMException // TODO: DOMException("OperationError")?
|
||||
Promise<GPUDevice> requestDevice(optional GPUDeviceDescriptor descriptor = {});
|
||||
Promise<GPUDevice?> requestDevice(optional GPUDeviceDescriptor descriptor = {});
|
||||
};
|
||||
|
||||
dictionary GPUDeviceDescriptor : GPUObjectDescriptorBase {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue