aboutsummaryrefslogtreecommitdiffstats
path: root/components/webgpu/lib.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2019-12-05 13:59:34 -0500
committerGitHub <noreply@github.com>2019-12-05 13:59:34 -0500
commitbb00a83ec404215c54e013d85227bf467be563f4 (patch)
tree65a98947475263b159f119ef63bcbfb6052b6512 /components/webgpu/lib.rs
parentc90dd15feccdb121af5422d13b32ea0cc3bc0ac6 (diff)
parentb15d2bb7d70870e26e1834099bf5fdcdcbb8d673 (diff)
downloadservo-bb00a83ec404215c54e013d85227bf467be563f4.tar.gz
servo-bb00a83ec404215c54e013d85227bf467be563f4.zip
Auto merge of #25029 - szeged:wgpu_request_device, r=jdm
Initial implementation of GPUDevice for WebGPU Added the WebIDL bindigs for GPUDevice, GPUObjectDescriptorBase, GPUDeviceDescriptor, GPUObjectBase Implemented the `requestDevice` function of `GPUAdapter` <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes addresses a part of #24706 cc @jdm, @kvark, @zakorgy <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
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);