mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Update wgpu and impl WGSLLanguageFeatures
(#34928)
* Update wgpu and impl `WGSLLanguageFeatures`
dc9b2eb718
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
* Update expectations
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
---------
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
7ac0dfb5b5
commit
4e51c7be43
9 changed files with 148 additions and 659 deletions
|
@ -170,7 +170,7 @@ DOMInterfaces = {
|
|||
|
||||
'GPU': {
|
||||
'inRealms': ['RequestAdapter'],
|
||||
'canGc': ['RequestAdapter'],
|
||||
'canGc': ['RequestAdapter', 'WgslLanguageFeatures'],
|
||||
},
|
||||
|
||||
'GPUAdapter': {
|
||||
|
|
|
@ -12,13 +12,14 @@ use script_traits::ScriptMsg;
|
|||
use webgpu::wgt::PowerPreference;
|
||||
use webgpu::{wgc, WebGPUResponse};
|
||||
|
||||
use super::wgsllanguagefeatures::WGSLLanguageFeatures;
|
||||
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
|
||||
GPUMethods, GPUPowerPreference, GPURequestAdapterOptions, GPUTextureFormat,
|
||||
};
|
||||
use crate::dom::bindings::error::Error;
|
||||
use crate::dom::bindings::refcounted::{Trusted, TrustedPromise};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::promise::Promise;
|
||||
|
@ -30,12 +31,15 @@ use crate::script_runtime::CanGc;
|
|||
#[allow(clippy::upper_case_acronyms)]
|
||||
pub(crate) struct GPU {
|
||||
reflector_: Reflector,
|
||||
/// Same object for <https://www.w3.org/TR/webgpu/#dom-gpu-wgsllanguagefeatures>
|
||||
wgsl_language_features: MutNullableDom<WGSLLanguageFeatures>,
|
||||
}
|
||||
|
||||
impl GPU {
|
||||
pub(crate) fn new_inherited() -> GPU {
|
||||
GPU {
|
||||
reflector_: Reflector::new(),
|
||||
wgsl_language_features: MutNullableDom::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -133,11 +137,17 @@ impl GPUMethods<crate::DomTypeHolder> for GPU {
|
|||
promise
|
||||
}
|
||||
|
||||
// https://gpuweb.github.io/gpuweb/#dom-gpu-getpreferredcanvasformat
|
||||
/// <https://gpuweb.github.io/gpuweb/#dom-gpu-getpreferredcanvasformat>
|
||||
fn GetPreferredCanvasFormat(&self) -> GPUTextureFormat {
|
||||
// TODO: real implementation
|
||||
GPUTextureFormat::Rgba8unorm
|
||||
}
|
||||
|
||||
/// <https://www.w3.org/TR/webgpu/#dom-gpu-wgsllanguagefeatures>
|
||||
fn WgslLanguageFeatures(&self, can_gc: CanGc) -> DomRoot<WGSLLanguageFeatures> {
|
||||
self.wgsl_language_features
|
||||
.or_init(|| WGSLLanguageFeatures::new(&self.global(), None, can_gc))
|
||||
}
|
||||
}
|
||||
|
||||
impl AsyncWGPUListener for GPU {
|
||||
|
|
|
@ -45,3 +45,4 @@ pub(crate) mod gpuuncapturederrorevent;
|
|||
pub(crate) mod gpuvalidationerror;
|
||||
#[allow(dead_code)]
|
||||
pub(crate) mod identityhub;
|
||||
pub(crate) mod wgsllanguagefeatures;
|
||||
|
|
86
components/script/dom/webgpu/wgsllanguagefeatures.rs
Normal file
86
components/script/dom/webgpu/wgsllanguagefeatures.rs
Normal file
|
@ -0,0 +1,86 @@
|
|||
/* 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/. */
|
||||
|
||||
// check-tidy: no specs after this line
|
||||
|
||||
use dom_struct::dom_struct;
|
||||
use indexmap::IndexSet;
|
||||
use js::rust::HandleObject;
|
||||
use webgpu::wgc::naga::front::wgsl::ImplementedLanguageExtension;
|
||||
|
||||
use crate::dom::bindings::cell::DomRefCell;
|
||||
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::WGSLLanguageFeaturesMethods;
|
||||
use crate::dom::bindings::like::Setlike;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object_with_proto, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::str::DOMString;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::script_runtime::CanGc;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct WGSLLanguageFeatures {
|
||||
reflector: Reflector,
|
||||
// internal storage for features
|
||||
#[custom_trace]
|
||||
internal: DomRefCell<IndexSet<DOMString>>,
|
||||
}
|
||||
|
||||
impl WGSLLanguageFeatures {
|
||||
pub(crate) fn new(
|
||||
global: &GlobalScope,
|
||||
proto: Option<HandleObject>,
|
||||
can_gc: CanGc,
|
||||
) -> DomRoot<Self> {
|
||||
let set = ImplementedLanguageExtension::all()
|
||||
.iter()
|
||||
.map(|le| le.to_ident().into())
|
||||
.collect();
|
||||
reflect_dom_object_with_proto(
|
||||
Box::new(Self {
|
||||
reflector: Reflector::new(),
|
||||
internal: DomRefCell::new(set),
|
||||
}),
|
||||
global,
|
||||
proto,
|
||||
can_gc,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl WGSLLanguageFeaturesMethods<crate::DomTypeHolder> for WGSLLanguageFeatures {
|
||||
fn Size(&self) -> u32 {
|
||||
self.internal.size()
|
||||
}
|
||||
}
|
||||
|
||||
// this error is wrong because if we inline Self::Key and Self::Value all errors are gone
|
||||
#[allow(crown::unrooted_must_root)]
|
||||
impl Setlike for WGSLLanguageFeatures {
|
||||
type Key = DOMString;
|
||||
|
||||
#[inline(always)]
|
||||
fn get_index(&self, index: u32) -> Option<Self::Key> {
|
||||
self.internal.get_index(index)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn size(&self) -> u32 {
|
||||
self.internal.size()
|
||||
}
|
||||
#[inline(always)]
|
||||
fn add(&self, _key: Self::Key) {
|
||||
unreachable!("readonly");
|
||||
}
|
||||
#[inline(always)]
|
||||
fn has(&self, key: Self::Key) -> bool {
|
||||
self.internal.has(key)
|
||||
}
|
||||
#[inline(always)]
|
||||
fn clear(&self) {
|
||||
unreachable!("readonly");
|
||||
}
|
||||
#[inline(always)]
|
||||
fn delete(&self, _key: Self::Key) -> bool {
|
||||
unreachable!("readonly");
|
||||
}
|
||||
}
|
|
@ -57,6 +57,11 @@ interface GPUSupportedFeatures {
|
|||
readonly setlike<DOMString>;
|
||||
};
|
||||
|
||||
[Exposed=(Window, DedicatedWorker), Pref="dom.webgpu.enabled"]
|
||||
interface WGSLLanguageFeatures {
|
||||
readonly setlike<DOMString>;
|
||||
};
|
||||
|
||||
[Exposed=(Window, DedicatedWorker), Pref="dom.webgpu.enabled"]
|
||||
interface GPUAdapterInfo {
|
||||
readonly attribute DOMString vendor;
|
||||
|
@ -77,6 +82,7 @@ interface GPU {
|
|||
[NewObject]
|
||||
Promise<GPUAdapter?> requestAdapter(optional GPURequestAdapterOptions options = {});
|
||||
GPUTextureFormat getPreferredCanvasFormat();
|
||||
[SameObject] readonly attribute WGSLLanguageFeatures wgslLanguageFeatures;
|
||||
};
|
||||
|
||||
dictionary GPURequestAdapterOptions {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue