mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Initial implementation of GPUDevice for WebGPU
Added the WebIDL bindigs for GPUDevice, GPUObjectDescriptorBase, GPUDeviceDescriptor, GPUObjectBase Implemented the `requestDevice` function of `GPUAdapter`
This commit is contained in:
parent
7aa68c8fe7
commit
b15d2bb7d7
11 changed files with 270 additions and 16 deletions
|
@ -2,16 +2,29 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::GPUAdapterBinding::{self, GPUAdapterMethods};
|
||||
use crate::compartments::InCompartment;
|
||||
use crate::dom::bindings::codegen::Bindings::GPUAdapterBinding::{
|
||||
self, GPUAdapterMethods, GPUDeviceDescriptor,
|
||||
};
|
||||
use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowBinding::WindowMethods;
|
||||
use crate::dom::bindings::error::Error;
|
||||
use crate::dom::bindings::inheritance::Castable;
|
||||
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::str::DOMString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::gpu::response_async;
|
||||
use crate::dom::gpu::AsyncWGPUListener;
|
||||
use crate::dom::gpudevice::GPUDevice;
|
||||
use crate::dom::promise::Promise;
|
||||
use crate::dom::window::Window;
|
||||
use crate::script_runtime::JSContext as SafeJSContext;
|
||||
use dom_struct::dom_struct;
|
||||
use js::jsapi::{Heap, JSObject};
|
||||
use std::ptr::NonNull;
|
||||
use webgpu::WebGPUAdapter;
|
||||
use std::rc::Rc;
|
||||
use webgpu::{wgpu, WebGPUAdapter, WebGPURequest, WebGPUResponse};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct GPUAdapter {
|
||||
|
@ -60,4 +73,51 @@ impl GPUAdapterMethods for GPUAdapter {
|
|||
fn Extensions(&self, _cx: SafeJSContext) -> NonNull<JSObject> {
|
||||
NonNull::new(self.extensions.get()).unwrap()
|
||||
}
|
||||
|
||||
/// https://gpuweb.github.io/gpuweb/#dom-gpuadapter-requestdevice
|
||||
fn RequestDevice(&self, descriptor: &GPUDeviceDescriptor, comp: InCompartment) -> Rc<Promise> {
|
||||
let promise = Promise::new_in_current_compartment(&self.global(), comp);
|
||||
let sender = response_async(&promise, self);
|
||||
let desc = wgpu::DeviceDescriptor {
|
||||
extensions: wgpu::Extensions {
|
||||
anisotropic_filtering: descriptor.extensions.anisotropicFiltering,
|
||||
},
|
||||
limits: wgpu::Limits {
|
||||
max_bind_groups: descriptor.limits.maxBindGroups,
|
||||
},
|
||||
};
|
||||
if let Some(window) = self.global().downcast::<Window>() {
|
||||
let id = window.Navigator().create_device_id();
|
||||
match window.webgpu_channel() {
|
||||
Some(thread) => thread
|
||||
.0
|
||||
.send(WebGPURequest::RequestDevice(sender, self.adapter, desc, id))
|
||||
.unwrap(),
|
||||
None => promise.reject_error(Error::Type("No WebGPU thread...".to_owned())),
|
||||
}
|
||||
} else {
|
||||
promise.reject_error(Error::Type("No WebGPU thread...".to_owned()))
|
||||
};
|
||||
promise
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncWGPUListener for GPUAdapter {
|
||||
fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
|
||||
match response {
|
||||
WebGPUResponse::RequestDevice(device_id, _descriptor) => {
|
||||
let device = GPUDevice::new(
|
||||
&self.global(),
|
||||
&self,
|
||||
Heap::default(),
|
||||
Heap::default(),
|
||||
device_id,
|
||||
);
|
||||
promise.resolve_native(&device);
|
||||
},
|
||||
_ => promise.reject_error(Error::Type(
|
||||
"Wrong response type from WebGPU thread...".to_owned(),
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue