aboutsummaryrefslogtreecommitdiffstats
path: root/components/webgpu/lib.rs
diff options
context:
space:
mode:
authorIstvan Miklos <istvan.miklos@h-lab.eu>2019-11-12 12:56:57 +0100
committerIstvan Miklos <istvan.miklos@h-lab.eu>2019-12-05 11:50:33 +0100
commitb15d2bb7d70870e26e1834099bf5fdcdcbb8d673 (patch)
tree80f2ab39a3afe7c38ec4934070cff03642e80521 /components/webgpu/lib.rs
parent7aa68c8fe7ca0865a7323ab1e5b9526efa588ca2 (diff)
downloadservo-b15d2bb7d70870e26e1834099bf5fdcdcbb8d673.tar.gz
servo-b15d2bb7d70870e26e1834099bf5fdcdcbb8d673.zip
Initial implementation of GPUDevice for WebGPU
Added the WebIDL bindigs for GPUDevice, GPUObjectDescriptorBase, GPUDeviceDescriptor, GPUObjectBase Implemented the `requestDevice` function of `GPUAdapter`
Diffstat (limited to 'components/webgpu/lib.rs')
-rw-r--r--components/webgpu/lib.rs45
1 files changed, 35 insertions, 10 deletions
diff --git a/components/webgpu/lib.rs b/components/webgpu/lib.rs
index 6439fc9f5e9..83df6d77e60 100644
--- a/components/webgpu/lib.rs
+++ b/components/webgpu/lib.rs
@@ -12,12 +12,12 @@ pub extern crate wgpu_native as wgpu;
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use servo_config::pref;
-use wgpu::adapter_get_info;
+use wgpu::{adapter_get_info, adapter_request_device};
#[derive(Debug, Deserialize, Serialize)]
pub enum WebGPUResponse {
RequestAdapter(String, WebGPUAdapter),
- RequestDevice,
+ RequestDevice(WebGPUDevice, wgpu::DeviceDescriptor),
}
pub type WebGPUResponseResult = Result<WebGPUResponse, String>;
@@ -29,7 +29,12 @@ pub enum WebGPURequest {
wgpu::RequestAdapterOptions,
wgpu::AdapterId,
),
- RequestDevice,
+ RequestDevice(
+ IpcSender<WebGPUResponseResult>,
+ WebGPUAdapter,
+ wgpu::DeviceDescriptor,
+ wgpu::DeviceId,
+ ),
Exit(IpcSender<()>),
}
@@ -124,7 +129,18 @@ impl WGPU {
)
}
},
- WebGPURequest::RequestDevice => {},
+ WebGPURequest::RequestDevice(sender, adapter, descriptor, id) => {
+ let _output = gfx_select!(id => adapter_request_device(&self.global, adapter.0, &descriptor, id));
+ let device = WebGPUDevice(id);
+ if let Err(e) =
+ sender.send(Ok(WebGPUResponse::RequestDevice(device, descriptor)))
+ {
+ warn!(
+ "Failed to send response to WebGPURequest::RequestDevice ({})",
+ e
+ )
+ }
+ },
WebGPURequest::Exit(sender) => {
self.deinit();
if let Err(e) = sender.send(()) {
@@ -137,11 +153,20 @@ impl WGPU {
}
}
-#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
-pub struct WebGPUAdapter(pub wgpu::AdapterId);
+macro_rules! webgpu_resource {
+ ($name:ident, $id:ty) => {
+ #[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, Serialize)]
+ pub struct $name(pub $id);
-impl MallocSizeOf for WebGPUAdapter {
- fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
- 0
- }
+ impl MallocSizeOf for $name {
+ fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
+ 0
+ }
+ }
+
+ impl Eq for $name {}
+ };
}
+
+webgpu_resource!(WebGPUAdapter, wgpu::AdapterId);
+webgpu_resource!(WebGPUDevice, wgpu::DeviceId);