Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial implementation of GPUDevice for WebGPU
Added the WebIDL bindigs for GPUDevice, GPUObjectDescriptorBase, GPUDeviceDescriptor, GPUObjectBase Implemented the `requestDevice` function of `GPUAdapter`
- Loading branch information
Istvan Miklos
committed
Dec 5, 2019
1 parent
7aa68c8
commit b15d2bb
Showing
11 changed files
with
270 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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::cell::DomRefCell; | ||
use crate::dom::bindings::codegen::Bindings::GPUDeviceBinding::{self, GPUDeviceMethods}; | ||
use crate::dom::bindings::reflector::reflect_dom_object; | ||
use crate::dom::bindings::root::{Dom, DomRoot}; | ||
use crate::dom::bindings::str::DOMString; | ||
use crate::dom::eventtarget::EventTarget; | ||
use crate::dom::globalscope::GlobalScope; | ||
use crate::dom::gpuadapter::GPUAdapter; | ||
use crate::script_runtime::JSContext as SafeJSContext; | ||
use dom_struct::dom_struct; | ||
use js::jsapi::{Heap, JSObject}; | ||
use std::ptr::NonNull; | ||
use webgpu::WebGPUDevice; | ||
|
||
#[dom_struct] | ||
pub struct GPUDevice { | ||
eventtarget: EventTarget, | ||
adapter: Dom<GPUAdapter>, | ||
#[ignore_malloc_size_of = "mozjs"] | ||
extensions: Heap<*mut JSObject>, | ||
#[ignore_malloc_size_of = "mozjs"] | ||
limits: Heap<*mut JSObject>, | ||
label: DomRefCell<Option<DOMString>>, | ||
device: WebGPUDevice, | ||
} | ||
|
||
impl GPUDevice { | ||
fn new_inherited( | ||
adapter: &GPUAdapter, | ||
extensions: Heap<*mut JSObject>, | ||
limits: Heap<*mut JSObject>, | ||
device: WebGPUDevice, | ||
) -> GPUDevice { | ||
Self { | ||
eventtarget: EventTarget::new_inherited(), | ||
adapter: Dom::from_ref(adapter), | ||
extensions, | ||
limits, | ||
label: DomRefCell::new(None), | ||
device, | ||
} | ||
} | ||
|
||
#[allow(unsafe_code)] | ||
pub fn new( | ||
global: &GlobalScope, | ||
adapter: &GPUAdapter, | ||
extensions: Heap<*mut JSObject>, | ||
limits: Heap<*mut JSObject>, | ||
device: WebGPUDevice, | ||
) -> DomRoot<GPUDevice> { | ||
reflect_dom_object( | ||
Box::new(GPUDevice::new_inherited( | ||
adapter, extensions, limits, device, | ||
)), | ||
global, | ||
GPUDeviceBinding::Wrap, | ||
) | ||
} | ||
} | ||
|
||
impl GPUDeviceMethods for GPUDevice { | ||
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-adapter | ||
fn Adapter(&self) -> DomRoot<GPUAdapter> { | ||
DomRoot::from_ref(&self.adapter) | ||
} | ||
|
||
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-extensions | ||
fn Extensions(&self, _cx: SafeJSContext) -> NonNull<JSObject> { | ||
NonNull::new(self.extensions.get()).unwrap() | ||
} | ||
|
||
/// https://gpuweb.github.io/gpuweb/#dom-gpudevice-limits | ||
fn Limits(&self, _cx: SafeJSContext) -> NonNull<JSObject> { | ||
NonNull::new(self.extensions.get()).unwrap() | ||
} | ||
|
||
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label | ||
fn GetLabel(&self) -> Option<DOMString> { | ||
self.label.borrow().clone() | ||
} | ||
|
||
/// https://gpuweb.github.io/gpuweb/#dom-gpuobjectbase-label | ||
fn SetLabel(&self, value: Option<DOMString>) { | ||
*self.label.borrow_mut() = value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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/. */ | ||
|
||
// https://gpuweb.github.io/gpuweb/#gpudevice | ||
[Exposed=(Window, DedicatedWorker)/*, Serializable */, Pref="dom.webgpu.enabled"] | ||
interface GPUDevice : EventTarget { | ||
readonly attribute GPUAdapter adapter; | ||
readonly attribute object extensions; | ||
readonly attribute object limits; | ||
|
||
/*GPUBuffer createBuffer(GPUBufferDescriptor descriptor); | ||
GPUMappedBuffer createBufferMapped(GPUBufferDescriptor descriptor); | ||
Promise<GPUMappedBuffer> createBufferMappedAsync(GPUBufferDescriptor descriptor); | ||
GPUTexture createTexture(GPUTextureDescriptor descriptor); | ||
GPUSampler createSampler(optional GPUSamplerDescriptor descriptor = {}); | ||
GPUBindGroupLayout createBindGroupLayout(GPUBindGroupLayoutDescriptor descriptor); | ||
GPUPipelineLayout createPipelineLayout(GPUPipelineLayoutDescriptor descriptor); | ||
GPUBindGroup createBindGroup(GPUBindGroupDescriptor descriptor); | ||
GPUShaderModule createShaderModule(GPUShaderModuleDescriptor descriptor); | ||
GPUComputePipeline createComputePipeline(GPUComputePipelineDescriptor descriptor); | ||
GPURenderPipeline createRenderPipeline(GPURenderPipelineDescriptor descriptor); | ||
GPUCommandEncoder createCommandEncoder(optional GPUCommandEncoderDescriptor descriptor = {}); | ||
GPURenderBundleEncoder createRenderBundleEncoder(GPURenderBundleEncoderDescriptor descriptor); | ||
GPUQueue getQueue();*/ | ||
}; | ||
GPUDevice includes GPUObjectBase; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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/. */ | ||
|
||
// https://gpuweb.github.io/gpuweb/#gpuobjectbase | ||
[Exposed=(Window)] | ||
interface mixin GPUObjectBase { | ||
attribute DOMString? label; | ||
}; | ||
|
||
dictionary GPUObjectDescriptorBase { | ||
DOMString? label; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters