Add webgpu feature flag (#34444)

* Move script gpu files into webgpu folder

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* Modify gpu webidls

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* move gpu realted webidl

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* add webgpu feature to script

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* add dummy implementation for gpucanvascontext

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* fmt

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* add skip-if CARGO_FEATURE_WEBGPU

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* Move NavigatorGPU and workerNavigator GPU to webgpu idl

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* fmt and cleanup

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* review fix

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* enable webgpu by default and also some fmt fix

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

* Add pref back, fix imports, small cleanups

Signed-off-by: atbrakhi <atbrakhi@igalia.com>

---------

Signed-off-by: atbrakhi <atbrakhi@igalia.com>
This commit is contained in:
atbrakhi 2024-12-05 17:07:27 +01:00 committed by GitHub
parent bba3bc6ac2
commit 1591a3b506
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 295 additions and 105 deletions

View file

@ -21,8 +21,8 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpuadapter::GPUAdapter;
use crate::dom::promise::Promise;
use crate::dom::webgpu::gpuadapter::GPUAdapter;
use crate::realms::InRealm;
use crate::script_runtime::CanGc;
use crate::task_source::{TaskSource, TaskSourceName};

View file

@ -20,11 +20,11 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::gpusupportedfeatures::gpu_to_wgt_feature;
use crate::dom::promise::Promise;
use crate::dom::types::{GPUAdapterInfo, GPUSupportedLimits};
use crate::dom::webgpu::gpu::{response_async, AsyncWGPUListener};
use crate::dom::webgpu::gpudevice::GPUDevice;
use crate::dom::webgpu::gpusupportedfeatures::gpu_to_wgt_feature;
use crate::realms::InRealm;
use crate::script_runtime::CanGc;

View file

@ -16,8 +16,8 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::webgpu::gpubindgrouplayout::GPUBindGroupLayout;
use crate::dom::webgpu::gpudevice::GPUDevice;
#[dom_struct]
pub struct GPUBindGroup {

View file

@ -17,8 +17,8 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpuconvert::convert_bind_group_layout_entry;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::webgpu::gpuconvert::convert_bind_group_layout_entry;
use crate::dom::webgpu::gpudevice::GPUDevice;
#[dom_struct]
pub struct GPUBindGroupLayout {

View file

@ -23,9 +23,9 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::promise::Promise;
use crate::dom::webgpu::gpu::{response_async, AsyncWGPUListener};
use crate::dom::webgpu::gpudevice::GPUDevice;
use crate::realms::InRealm;
use crate::script_runtime::{CanGc, JSContext};

View file

@ -20,11 +20,12 @@ use webrender_api::ImageKey;
use super::gpuconvert::convert_texture_descriptor;
use super::gputexture::GPUTexture;
use crate::dom::bindings::codegen::Bindings::GPUCanvasContextBinding::GPUCanvasContextMethods;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::GPUTexture_Binding::GPUTextureMethods;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
GPUCanvasAlphaMode, GPUCanvasConfiguration, GPUCanvasContextMethods, GPUDeviceMethods,
GPUExtent3D, GPUExtent3DDict, GPUObjectDescriptorBase, GPUTextureDescriptor,
GPUTextureDimension, GPUTextureFormat, GPUTextureUsageConstants,
GPUCanvasAlphaMode, GPUCanvasConfiguration, GPUDeviceMethods, GPUExtent3D, GPUExtent3DDict,
GPUObjectDescriptorBase, GPUTextureDescriptor, GPUTextureDimension, GPUTextureFormat,
GPUTextureUsageConstants,
};
use crate::dom::bindings::codegen::UnionTypes::HTMLCanvasElementOrOffscreenCanvas;
use crate::dom::bindings::error::{Error, Fallible};

View file

@ -20,12 +20,12 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubuffer::GPUBuffer;
use crate::dom::gpucommandbuffer::GPUCommandBuffer;
use crate::dom::gpucomputepassencoder::GPUComputePassEncoder;
use crate::dom::gpuconvert::{convert_load_op, convert_store_op};
use crate::dom::gpudevice::GPUDevice;
use crate::dom::gpurenderpassencoder::GPURenderPassEncoder;
use crate::dom::webgpu::gpubuffer::GPUBuffer;
use crate::dom::webgpu::gpucommandbuffer::GPUCommandBuffer;
use crate::dom::webgpu::gpucomputepassencoder::GPUComputePassEncoder;
use crate::dom::webgpu::gpuconvert::{convert_load_op, convert_store_op};
use crate::dom::webgpu::gpudevice::GPUDevice;
use crate::dom::webgpu::gpurenderpassencoder::GPURenderPassEncoder;
#[dom_struct]
pub struct GPUCommandEncoder {

View file

@ -11,10 +11,10 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgroup::GPUBindGroup;
use crate::dom::gpubuffer::GPUBuffer;
use crate::dom::gpucommandencoder::GPUCommandEncoder;
use crate::dom::gpucomputepipeline::GPUComputePipeline;
use crate::dom::webgpu::gpubindgroup::GPUBindGroup;
use crate::dom::webgpu::gpubuffer::GPUBuffer;
use crate::dom::webgpu::gpucommandencoder::GPUCommandEncoder;
use crate::dom::webgpu::gpucomputepipeline::GPUComputePipeline;
#[dom_struct]
pub struct GPUComputePassEncoder {

View file

@ -16,8 +16,8 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::webgpu::gpubindgrouplayout::GPUBindGroupLayout;
use crate::dom::webgpu::gpudevice::GPUDevice;
#[dom_struct]
pub struct GPUComputePipeline {

View file

@ -42,24 +42,24 @@ use crate::dom::bindings::str::{DOMString, USVString};
use crate::dom::bindings::trace::RootedTraceableBox;
use crate::dom::eventtarget::EventTarget;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpuadapter::GPUAdapter;
use crate::dom::gpubindgroup::GPUBindGroup;
use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
use crate::dom::gpubuffer::GPUBuffer;
use crate::dom::gpucommandencoder::GPUCommandEncoder;
use crate::dom::gpucomputepipeline::GPUComputePipeline;
use crate::dom::gpupipelinelayout::GPUPipelineLayout;
use crate::dom::gpuqueue::GPUQueue;
use crate::dom::gpurenderbundleencoder::GPURenderBundleEncoder;
use crate::dom::gpurenderpipeline::GPURenderPipeline;
use crate::dom::gpusampler::GPUSampler;
use crate::dom::gpushadermodule::GPUShaderModule;
use crate::dom::gpusupportedfeatures::GPUSupportedFeatures;
use crate::dom::gputexture::GPUTexture;
use crate::dom::gpuuncapturederrorevent::GPUUncapturedErrorEvent;
use crate::dom::promise::Promise;
use crate::dom::types::GPUError;
use crate::dom::webgpu::gpu::response_async;
use crate::dom::webgpu::gpuadapter::GPUAdapter;
use crate::dom::webgpu::gpubindgroup::GPUBindGroup;
use crate::dom::webgpu::gpubindgrouplayout::GPUBindGroupLayout;
use crate::dom::webgpu::gpubuffer::GPUBuffer;
use crate::dom::webgpu::gpucommandencoder::GPUCommandEncoder;
use crate::dom::webgpu::gpucomputepipeline::GPUComputePipeline;
use crate::dom::webgpu::gpupipelinelayout::GPUPipelineLayout;
use crate::dom::webgpu::gpuqueue::GPUQueue;
use crate::dom::webgpu::gpurenderbundleencoder::GPURenderBundleEncoder;
use crate::dom::webgpu::gpurenderpipeline::GPURenderPipeline;
use crate::dom::webgpu::gpusampler::GPUSampler;
use crate::dom::webgpu::gpushadermodule::GPUShaderModule;
use crate::dom::webgpu::gpusupportedfeatures::GPUSupportedFeatures;
use crate::dom::webgpu::gputexture::GPUTexture;
use crate::dom::webgpu::gpuuncapturederrorevent::GPUUncapturedErrorEvent;
use crate::realms::InRealm;
use crate::script_runtime::CanGc;

View file

@ -16,7 +16,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::webgpu::gpudevice::GPUDevice;
#[dom_struct]
pub struct GPUPipelineLayout {

View file

@ -19,10 +19,10 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubuffer::GPUBuffer;
use crate::dom::gpucommandbuffer::GPUCommandBuffer;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::promise::Promise;
use crate::dom::webgpu::gpubuffer::GPUBuffer;
use crate::dom::webgpu::gpucommandbuffer::GPUCommandBuffer;
use crate::dom::webgpu::gpudevice::GPUDevice;
use crate::script_runtime::CanGc;
#[dom_struct]

View file

@ -20,11 +20,11 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgroup::GPUBindGroup;
use crate::dom::gpubuffer::GPUBuffer;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::gpurenderbundle::GPURenderBundle;
use crate::dom::gpurenderpipeline::GPURenderPipeline;
use crate::dom::webgpu::gpubindgroup::GPUBindGroup;
use crate::dom::webgpu::gpubuffer::GPUBuffer;
use crate::dom::webgpu::gpudevice::GPUDevice;
use crate::dom::webgpu::gpurenderbundle::GPURenderBundle;
use crate::dom::webgpu::gpurenderpipeline::GPURenderPipeline;
#[dom_struct]
pub struct GPURenderBundleEncoder {

View file

@ -15,11 +15,11 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgroup::GPUBindGroup;
use crate::dom::gpubuffer::GPUBuffer;
use crate::dom::gpucommandencoder::GPUCommandEncoder;
use crate::dom::gpurenderbundle::GPURenderBundle;
use crate::dom::gpurenderpipeline::GPURenderPipeline;
use crate::dom::webgpu::gpubindgroup::GPUBindGroup;
use crate::dom::webgpu::gpubuffer::GPUBuffer;
use crate::dom::webgpu::gpucommandencoder::GPUCommandEncoder;
use crate::dom::webgpu::gpurenderbundle::GPURenderBundle;
use crate::dom::webgpu::gpurenderpipeline::GPURenderPipeline;
#[dom_struct]
pub struct GPURenderPassEncoder {

View file

@ -14,8 +14,8 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpubindgrouplayout::GPUBindGroupLayout;
use crate::dom::gpudevice::{GPUDevice, PipelineLayout};
use crate::dom::webgpu::gpubindgrouplayout::GPUBindGroupLayout;
use crate::dom::webgpu::gpudevice::{GPUDevice, PipelineLayout};
#[dom_struct]
pub struct GPURenderPipeline {

View file

@ -14,7 +14,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::DomRoot;
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::webgpu::gpudevice::GPUDevice;
#[dom_struct]
pub struct GPUSampler {

View file

@ -19,8 +19,8 @@ use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpudevice::GPUDevice;
use crate::dom::gputextureview::GPUTextureView;
use crate::dom::webgpu::gpudevice::GPUDevice;
use crate::dom::webgpu::gputextureview::GPUTextureView;
#[dom_struct]
pub struct GPUTexture {

View file

@ -11,7 +11,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::USVString;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gputexture::GPUTexture;
use crate::dom::webgpu::gputexture::GPUTexture;
#[dom_struct]
pub struct GPUTextureView {

View file

@ -15,7 +15,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::bindings::str::DOMString;
use crate::dom::event::Event;
use crate::dom::globalscope::GlobalScope;
use crate::dom::gpuerror::GPUError;
use crate::dom::webgpu::gpuerror::GPUError;
use crate::script_runtime::CanGc;
#[dom_struct]

View file

@ -0,0 +1,199 @@
/* 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 webgpu::identity::{ComputePass, ComputePassId, RenderPass, RenderPassId};
use webgpu::wgc::id::markers::{
Adapter, BindGroup, BindGroupLayout, Buffer, CommandEncoder, ComputePipeline, Device,
PipelineLayout, Queue, RenderBundle, RenderPipeline, Sampler, ShaderModule, Texture,
TextureView,
};
use webgpu::wgc::id::{
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandEncoderId, ComputePipelineId,
DeviceId, PipelineLayoutId, QueueId, RenderBundleId, RenderPipelineId, SamplerId,
ShaderModuleId, TextureId, TextureViewId,
};
use webgpu::wgc::identity::IdentityManager;
#[derive(Debug)]
pub struct IdentityHub {
adapters: IdentityManager<Adapter>,
devices: IdentityManager<Device>,
queues: IdentityManager<Queue>,
buffers: IdentityManager<Buffer>,
bind_groups: IdentityManager<BindGroup>,
bind_group_layouts: IdentityManager<BindGroupLayout>,
compute_pipelines: IdentityManager<ComputePipeline>,
pipeline_layouts: IdentityManager<PipelineLayout>,
shader_modules: IdentityManager<ShaderModule>,
command_encoders: IdentityManager<CommandEncoder>,
textures: IdentityManager<Texture>,
texture_views: IdentityManager<TextureView>,
samplers: IdentityManager<Sampler>,
render_pipelines: IdentityManager<RenderPipeline>,
render_bundles: IdentityManager<RenderBundle>,
compute_passes: IdentityManager<ComputePass>,
render_passes: IdentityManager<RenderPass>,
}
impl Default for IdentityHub {
fn default() -> Self {
IdentityHub {
adapters: IdentityManager::new(),
devices: IdentityManager::new(),
queues: IdentityManager::new(),
buffers: IdentityManager::new(),
bind_groups: IdentityManager::new(),
bind_group_layouts: IdentityManager::new(),
compute_pipelines: IdentityManager::new(),
pipeline_layouts: IdentityManager::new(),
shader_modules: IdentityManager::new(),
command_encoders: IdentityManager::new(),
textures: IdentityManager::new(),
texture_views: IdentityManager::new(),
samplers: IdentityManager::new(),
render_pipelines: IdentityManager::new(),
render_bundles: IdentityManager::new(),
compute_passes: IdentityManager::new(),
render_passes: IdentityManager::new(),
}
}
}
impl IdentityHub {
pub fn create_device_id(&self) -> DeviceId {
self.devices.process()
}
pub fn free_device_id(&self, id: DeviceId) {
self.devices.free(id);
}
pub fn create_queue_id(&self) -> QueueId {
self.queues.process()
}
pub fn free_queue_id(&self, id: QueueId) {
self.queues.free(id);
}
pub fn create_adapter_id(&self) -> AdapterId {
self.adapters.process()
}
pub fn free_adapter_id(&self, id: AdapterId) {
self.adapters.free(id);
}
pub fn create_buffer_id(&self) -> BufferId {
self.buffers.process()
}
pub fn free_buffer_id(&self, id: BufferId) {
self.buffers.free(id);
}
pub fn create_bind_group_id(&self) -> BindGroupId {
self.bind_groups.process()
}
pub fn free_bind_group_id(&self, id: BindGroupId) {
self.bind_groups.free(id);
}
pub fn create_bind_group_layout_id(&self) -> BindGroupLayoutId {
self.bind_group_layouts.process()
}
pub fn free_bind_group_layout_id(&self, id: BindGroupLayoutId) {
self.bind_group_layouts.free(id);
}
pub fn create_compute_pipeline_id(&self) -> ComputePipelineId {
self.compute_pipelines.process()
}
pub fn free_compute_pipeline_id(&self, id: ComputePipelineId) {
self.compute_pipelines.free(id);
}
pub fn create_pipeline_layout_id(&self) -> PipelineLayoutId {
self.pipeline_layouts.process()
}
pub fn free_pipeline_layout_id(&self, id: PipelineLayoutId) {
self.pipeline_layouts.free(id);
}
pub fn create_shader_module_id(&self) -> ShaderModuleId {
self.shader_modules.process()
}
pub fn free_shader_module_id(&self, id: ShaderModuleId) {
self.shader_modules.free(id);
}
pub fn create_command_encoder_id(&self) -> CommandEncoderId {
self.command_encoders.process()
}
pub fn free_command_buffer_id(&self, id: CommandEncoderId) {
self.command_encoders.free(id);
}
pub fn create_sampler_id(&self) -> SamplerId {
self.samplers.process()
}
pub fn free_sampler_id(&self, id: SamplerId) {
self.samplers.free(id);
}
pub fn create_render_pipeline_id(&self) -> RenderPipelineId {
self.render_pipelines.process()
}
pub fn free_render_pipeline_id(&self, id: RenderPipelineId) {
self.render_pipelines.free(id);
}
pub fn create_texture_id(&self) -> TextureId {
self.textures.process()
}
pub fn free_texture_id(&self, id: TextureId) {
self.textures.free(id);
}
pub fn create_texture_view_id(&self) -> TextureViewId {
self.texture_views.process()
}
pub fn free_texture_view_id(&self, id: TextureViewId) {
self.texture_views.free(id);
}
pub fn create_render_bundle_id(&self) -> RenderBundleId {
self.render_bundles.process()
}
pub fn free_render_bundle_id(&self, id: RenderBundleId) {
self.render_bundles.free(id);
}
pub fn create_compute_pass_id(&self) -> ComputePassId {
self.compute_passes.process()
}
pub fn free_compute_pass_id(&self, id: ComputePassId) {
self.compute_passes.free(id);
}
pub fn create_render_pass_id(&self) -> RenderPassId {
self.render_passes.process()
}
pub fn free_render_pass_id(&self, id: RenderPassId) {
self.render_passes.free(id);
}
}

View file

@ -42,3 +42,4 @@ pub mod gputextureusage;
pub mod gputextureview;
pub mod gpuuncapturederrorevent;
pub mod gpuvalidationerror;
pub mod identityhub;