webgpu: Refactor webgpu crate (#32255)

* wgpu(_core) -> wgc

* Refactor webgpu crate

split lib.rs into multiple modules
This commit is contained in:
Samson 2024-05-08 15:53:39 +02:00 committed by GitHub
parent c4f8599404
commit 168d43f24a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 1475 additions and 1413 deletions

View file

@ -56,8 +56,7 @@ use script_traits::{
}; };
use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl}; use servo_url::{ImmutableOrigin, MutableOrigin, ServoUrl};
use uuid::Uuid; use uuid::Uuid;
use webgpu::identity::WebGPUOpResult; use webgpu::{ErrorScopeId, WebGPUDevice, WebGPUOpResult};
use webgpu::{ErrorScopeId, WebGPUDevice};
use super::bindings::trace::HashMapTracedValues; use super::bindings::trace::HashMapTracedValues;
use crate::dom::bindings::cell::{DomRefCell, RefMut}; use crate::dom::bindings::cell::{DomRefCell, RefMut};

View file

@ -10,7 +10,7 @@ use ipc_channel::router::ROUTER;
use js::jsapi::Heap; use js::jsapi::Heap;
use script_traits::ScriptMsg; use script_traits::ScriptMsg;
use webgpu::wgt::PowerPreference; use webgpu::wgt::PowerPreference;
use webgpu::{wgpu, WebGPUResponse, WebGPUResponseResult}; use webgpu::{wgc, WebGPUResponse, WebGPUResponseResult};
use super::bindings::codegen::Bindings::WebGPUBinding::GPUTextureFormat; use super::bindings::codegen::Bindings::WebGPUBinding::GPUTextureFormat;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{ use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{
@ -117,7 +117,7 @@ impl GPUMethods for GPU {
if script_to_constellation_chan if script_to_constellation_chan
.send(ScriptMsg::RequestAdapter( .send(ScriptMsg::RequestAdapter(
sender, sender,
wgpu::instance::RequestAdapterOptions { wgc::instance::RequestAdapterOptions {
power_preference, power_preference,
compatible_surface: None, compatible_surface: None,
force_fallback_adapter: options.forceFallbackAdapter, force_fallback_adapter: options.forceFallbackAdapter,

View file

@ -11,9 +11,10 @@ use std::sync::{Arc, Mutex};
use dom_struct::dom_struct; use dom_struct::dom_struct;
use ipc_channel::ipc::IpcSharedMemory; use ipc_channel::ipc::IpcSharedMemory;
use js::typedarray::{ArrayBuffer, ArrayBufferU8}; use js::typedarray::{ArrayBuffer, ArrayBufferU8};
use webgpu::identity::WebGPUOpResult; use webgpu::wgc::device::HostMap;
use webgpu::wgpu::device::HostMap; use webgpu::{
use webgpu::{WebGPU, WebGPUBuffer, WebGPURequest, WebGPUResponse, WebGPUResponseResult}; WebGPU, WebGPUBuffer, WebGPUOpResult, WebGPURequest, WebGPUResponse, WebGPUResponseResult,
};
use super::bindings::buffer_source::{create_new_external_array_buffer, HeapBufferSource}; use super::bindings::buffer_source::{create_new_external_array_buffer, HeapBufferSource};
use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::cell::DomRefCell;

View file

@ -9,7 +9,7 @@ use dom_struct::dom_struct;
use euclid::default::Size2D; use euclid::default::Size2D;
use ipc_channel::ipc; use ipc_channel::ipc;
use script_layout_interface::HTMLCanvasDataSource; use script_layout_interface::HTMLCanvasDataSource;
use webgpu::wgpu::id; use webgpu::wgc::id;
use webgpu::{wgt, WebGPU, WebGPURequest, WebGPUTexture, PRESENTATION_BUFFER_COUNT}; use webgpu::{wgt, WebGPU, WebGPURequest, WebGPUTexture, PRESENTATION_BUFFER_COUNT};
use webrender_api::{ use webrender_api::{
units, ExternalImageData, ExternalImageId, ExternalImageType, ImageData, ImageDescriptor, units, ExternalImageData, ExternalImageId, ExternalImageType, ImageData, ImageDescriptor,

View file

@ -7,7 +7,7 @@ use std::cell::Cell;
use std::collections::HashSet; use std::collections::HashSet;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use webgpu::wgpu::command as wgpu_com; use webgpu::wgc::command as wgpu_com;
use webgpu::{self, wgt, WebGPU, WebGPURequest}; use webgpu::{self, wgt, WebGPU, WebGPURequest};
use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::cell::DomRefCell;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct; use dom_struct::dom_struct;
use webgpu::wgpu::command::{compute_commands as wgpu_comp, ComputePass}; use webgpu::wgc::command::{compute_commands as wgpu_comp, ComputePass};
use webgpu::{WebGPU, WebGPURequest}; use webgpu::{WebGPU, WebGPURequest};
use super::bindings::error::Fallible; use super::bindings::error::Fallible;

View file

@ -4,7 +4,7 @@
use std::borrow::Cow; use std::borrow::Cow;
use webgpu::wgpu::command as wgpu_com; use webgpu::wgc::command as wgpu_com;
use webgpu::wgt; use webgpu::wgt;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{ use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{

View file

@ -13,12 +13,11 @@ use std::sync::{Arc, Mutex};
use dom_struct::dom_struct; use dom_struct::dom_struct;
use js::jsapi::{Heap, JSObject}; use js::jsapi::{Heap, JSObject};
use webgpu::identity::WebGPUOpResult; use webgpu::wgc::id::{BindGroupLayoutId, PipelineLayoutId};
use webgpu::wgpu::id::{BindGroupLayoutId, PipelineLayoutId}; use webgpu::wgc::{
use webgpu::wgpu::{
binding_model as wgpu_bind, command as wgpu_com, pipeline as wgpu_pipe, resource as wgpu_res, binding_model as wgpu_bind, command as wgpu_com, pipeline as wgpu_pipe, resource as wgpu_res,
}; };
use webgpu::{self, wgt, ErrorScopeId, WebGPU, WebGPURequest}; use webgpu::{self, wgt, ErrorScopeId, WebGPU, WebGPUOpResult, WebGPURequest};
use super::bindings::codegen::UnionTypes::GPUPipelineLayoutOrGPUAutoLayoutMode; use super::bindings::codegen::UnionTypes::GPUPipelineLayoutOrGPUAutoLayoutMode;
use super::bindings::error::Fallible; use super::bindings::error::Fallible;

View file

@ -6,8 +6,7 @@ use std::rc::Rc;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use ipc_channel::ipc::IpcSharedMemory; use ipc_channel::ipc::IpcSharedMemory;
use webgpu::identity::WebGPUOpResult; use webgpu::{wgt, WebGPU, WebGPUOpResult, WebGPUQueue, WebGPURequest, WebGPUResponse};
use webgpu::{wgt, WebGPU, WebGPUQueue, WebGPURequest, WebGPUResponse};
use super::bindings::codegen::Bindings::WebGPUBinding::{GPUImageCopyTexture, GPUImageDataLayout}; use super::bindings::codegen::Bindings::WebGPUBinding::{GPUImageCopyTexture, GPUImageDataLayout};
use super::gpu::{response_async, AsyncWGPUListener}; use super::gpu::{response_async, AsyncWGPUListener};

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct; use dom_struct::dom_struct;
use webgpu::wgpu::command::{bundle_ffi as wgpu_bundle, RenderBundleEncoder}; use webgpu::wgc::command::{bundle_ffi as wgpu_bundle, RenderBundleEncoder};
use webgpu::{wgt, WebGPU, WebGPURenderBundle, WebGPURequest}; use webgpu::{wgt, WebGPU, WebGPURenderBundle, WebGPURequest};
use super::bindings::codegen::Bindings::WebGPUBinding::GPUIndexFormat; use super::bindings::codegen::Bindings::WebGPUBinding::GPUIndexFormat;

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use dom_struct::dom_struct; use dom_struct::dom_struct;
use webgpu::wgpu::command::{render_commands as wgpu_render, RenderPass}; use webgpu::wgc::command::{render_commands as wgpu_render, RenderPass};
use webgpu::{wgt, WebGPU, WebGPURequest}; use webgpu::{wgt, WebGPU, WebGPURequest};
use super::bindings::codegen::Bindings::WebGPUBinding::GPUIndexFormat; use super::bindings::codegen::Bindings::WebGPUBinding::GPUIndexFormat;

View file

@ -6,9 +6,8 @@ use std::cell::Cell;
use std::string::String; use std::string::String;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use webgpu::identity::WebGPUOpResult; use webgpu::wgc::resource;
use webgpu::wgpu::resource; use webgpu::{wgt, WebGPU, WebGPUOpResult, WebGPURequest, WebGPUTexture, WebGPUTextureView};
use webgpu::{wgt, WebGPU, WebGPURequest, WebGPUTexture, WebGPUTextureView};
use crate::dom::bindings::cell::DomRefCell; use crate::dom::bindings::cell::DomRefCell;
use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{ use crate::dom::bindings::codegen::Bindings::WebGPUBinding::{

View file

@ -3,16 +3,16 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use smallvec::SmallVec; use smallvec::SmallVec;
use webgpu::wgpu::id::markers::{ use webgpu::wgc::id::markers::{
Adapter, BindGroup, BindGroupLayout, Buffer, CommandEncoder, ComputePipeline, Device, Adapter, BindGroup, BindGroupLayout, Buffer, CommandEncoder, ComputePipeline, Device,
PipelineLayout, RenderBundle, RenderPipeline, Sampler, ShaderModule, Texture, TextureView, PipelineLayout, RenderBundle, RenderPipeline, Sampler, ShaderModule, Texture, TextureView,
}; };
use webgpu::wgpu::id::{ use webgpu::wgc::id::{
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandEncoderId, ComputePipelineId, AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandEncoderId, ComputePipelineId,
DeviceId, PipelineLayoutId, RenderBundleId, RenderPipelineId, SamplerId, ShaderModuleId, DeviceId, PipelineLayoutId, RenderBundleId, RenderPipelineId, SamplerId, ShaderModuleId,
TextureId, TextureViewId, TextureId, TextureViewId,
}; };
use webgpu::wgpu::identity::IdentityManager; use webgpu::wgc::identity::IdentityManager;
use webgpu::wgt::Backend; use webgpu::wgt::Backend;
#[derive(Debug)] #[derive(Debug)]

View file

@ -95,7 +95,7 @@ use style::dom::OpaqueNode;
use style::thread_state::{self, ThreadState}; use style::thread_state::{self, ThreadState};
use time::precise_time_ns; use time::precise_time_ns;
use url::Position; use url::Position;
use webgpu::identity::WebGPUMsg; use webgpu::WebGPUMsg;
use webrender_api::units::LayoutPixel; use webrender_api::units::LayoutPixel;
use webrender_api::DocumentId; use webrender_api::DocumentId;

View file

@ -55,7 +55,7 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
use servo_atoms::Atom; use servo_atoms::Atom;
use servo_url::{ImmutableOrigin, ServoUrl}; use servo_url::{ImmutableOrigin, ServoUrl};
use style_traits::{CSSPixel, SpeculativePainter}; use style_traits::{CSSPixel, SpeculativePainter};
use webgpu::identity::WebGPUMsg; use webgpu::WebGPUMsg;
use webrender_api::units::{DeviceIntSize, DevicePixel, DevicePoint, LayoutPixel, LayoutPoint}; use webrender_api::units::{DeviceIntSize, DevicePixel, DevicePoint, LayoutPixel, LayoutPoint};
use webrender_api::{ use webrender_api::{
BuiltDisplayList, BuiltDisplayListDescriptor, DocumentId, ExternalImageData, ExternalScrollId, BuiltDisplayList, BuiltDisplayListDescriptor, DocumentId, ExternalImageData, ExternalScrollId,

View file

@ -24,7 +24,7 @@ use serde::{Deserialize, Serialize};
use servo_url::{ImmutableOrigin, ServoUrl}; use servo_url::{ImmutableOrigin, ServoUrl};
use smallvec::SmallVec; use smallvec::SmallVec;
use style_traits::CSSPixel; use style_traits::CSSPixel;
use webgpu::{wgpu, WebGPU, WebGPUResponseResult}; use webgpu::{wgc, WebGPU, WebGPUResponseResult};
use webrender_api::units::{DeviceIntPoint, DeviceIntSize}; use webrender_api::units::{DeviceIntPoint, DeviceIntSize};
use crate::{ use crate::{
@ -258,8 +258,8 @@ pub enum ScriptMsg {
/// Create a WebGPU Adapter instance /// Create a WebGPU Adapter instance
RequestAdapter( RequestAdapter(
IpcSender<Option<WebGPUResponseResult>>, IpcSender<Option<WebGPUResponseResult>>,
wgpu::instance::RequestAdapterOptions, wgc::instance::RequestAdapterOptions,
SmallVec<[wgpu::id::AdapterId; 4]>, SmallVec<[wgc::id::AdapterId; 4]>,
), ),
/// Get WebGPU channel /// Get WebGPU channel
GetWebGPUChan(IpcSender<Option<WebGPU>>), GetWebGPUChan(IpcSender<Option<WebGPU>>),

View file

@ -0,0 +1,254 @@
/* 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/. */
//! IPC massages that are send/received from GPU DOM objects.
use std::borrow::Cow;
use arrayvec::ArrayVec;
use ipc_channel::ipc::{IpcSender, IpcSharedMemory};
use msg::constellation_msg::PipelineId;
use serde::{Deserialize, Serialize};
use smallvec::SmallVec;
use webrender_api::{ExternalImageId, ImageData, ImageDescriptor, ImageKey};
use wgc::binding_model::{
BindGroupDescriptor, BindGroupLayoutDescriptor, PipelineLayoutDescriptor,
};
use wgc::command::{
ComputePass, ImageCopyBuffer, ImageCopyTexture, RenderBundleDescriptor, RenderBundleEncoder,
RenderPass,
};
use wgc::device::HostMap;
use wgc::id;
use wgc::instance::RequestAdapterOptions;
use wgc::pipeline::{ComputePipelineDescriptor, RenderPipelineDescriptor};
use wgc::resource::{
BufferDescriptor, SamplerDescriptor, TextureDescriptor, TextureViewDescriptor,
};
pub use {wgpu_core as wgc, wgpu_types as wgt};
use crate::identity::*;
use crate::{WebGPU, PRESENTATION_BUFFER_COUNT};
#[derive(Debug, Deserialize, Serialize)]
#[allow(clippy::large_enum_variant)]
pub enum WebGPUResponse {
RequestAdapter {
adapter_info: wgt::AdapterInfo,
adapter_id: WebGPUAdapter,
features: wgt::Features,
limits: wgt::Limits,
channel: WebGPU,
},
RequestDevice {
device_id: WebGPUDevice,
queue_id: WebGPUQueue,
descriptor: wgt::DeviceDescriptor<Option<String>>,
},
BufferMapAsync(IpcSharedMemory),
SubmittedWorkDone,
}
pub type WebGPUResponseResult = Result<WebGPUResponse, String>;
#[derive(Debug, Deserialize, Serialize)]
pub enum WebGPURequest {
BufferMapAsync {
sender: IpcSender<Option<WebGPUResponseResult>>,
buffer_id: id::BufferId,
device_id: id::DeviceId,
host_map: HostMap,
offset: u64,
size: Option<u64>,
},
CommandEncoderFinish {
command_encoder_id: id::CommandEncoderId,
device_id: id::DeviceId,
is_error: bool,
// TODO(zakorgy): Serialize CommandBufferDescriptor in wgpu-core
// wgc::command::CommandBufferDescriptor,
},
CopyBufferToBuffer {
command_encoder_id: id::CommandEncoderId,
source_id: id::BufferId,
source_offset: wgt::BufferAddress,
destination_id: id::BufferId,
destination_offset: wgt::BufferAddress,
size: wgt::BufferAddress,
},
CopyBufferToTexture {
command_encoder_id: id::CommandEncoderId,
source: ImageCopyBuffer,
destination: ImageCopyTexture,
copy_size: wgt::Extent3d,
},
CopyTextureToBuffer {
command_encoder_id: id::CommandEncoderId,
source: ImageCopyTexture,
destination: ImageCopyBuffer,
copy_size: wgt::Extent3d,
},
CopyTextureToTexture {
command_encoder_id: id::CommandEncoderId,
source: ImageCopyTexture,
destination: ImageCopyTexture,
copy_size: wgt::Extent3d,
},
CreateBindGroup {
device_id: id::DeviceId,
bind_group_id: id::BindGroupId,
descriptor: BindGroupDescriptor<'static>,
},
CreateBindGroupLayout {
device_id: id::DeviceId,
bind_group_layout_id: id::BindGroupLayoutId,
descriptor: Option<BindGroupLayoutDescriptor<'static>>,
},
CreateBuffer {
device_id: id::DeviceId,
buffer_id: id::BufferId,
descriptor: Option<BufferDescriptor<'static>>,
},
CreateCommandEncoder {
device_id: id::DeviceId,
// TODO(zakorgy): Serialize CommandEncoderDescriptor in wgpu-core
// wgc::command::CommandEncoderDescriptor,
command_encoder_id: id::CommandEncoderId,
label: Option<Cow<'static, str>>,
},
CreateComputePipeline {
device_id: id::DeviceId,
compute_pipeline_id: id::ComputePipelineId,
descriptor: ComputePipelineDescriptor<'static>,
implicit_ids: Option<(id::PipelineLayoutId, Vec<id::BindGroupLayoutId>)>,
},
CreateContext(IpcSender<ExternalImageId>),
CreatePipelineLayout {
device_id: id::DeviceId,
pipeline_layout_id: id::PipelineLayoutId,
descriptor: PipelineLayoutDescriptor<'static>,
},
CreateRenderPipeline {
device_id: id::DeviceId,
render_pipeline_id: id::RenderPipelineId,
descriptor: Option<RenderPipelineDescriptor<'static>>,
implicit_ids: Option<(id::PipelineLayoutId, Vec<id::BindGroupLayoutId>)>,
},
CreateSampler {
device_id: id::DeviceId,
sampler_id: id::SamplerId,
descriptor: SamplerDescriptor<'static>,
},
CreateShaderModule {
device_id: id::DeviceId,
program_id: id::ShaderModuleId,
program: String,
label: Option<String>,
},
CreateSwapChain {
device_id: id::DeviceId,
buffer_ids: ArrayVec<id::BufferId, PRESENTATION_BUFFER_COUNT>,
external_id: u64,
sender: IpcSender<ImageKey>,
image_desc: ImageDescriptor,
image_data: ImageData,
},
CreateTexture {
device_id: id::DeviceId,
texture_id: id::TextureId,
descriptor: Option<TextureDescriptor<'static>>,
},
CreateTextureView {
texture_id: id::TextureId,
texture_view_id: id::TextureViewId,
device_id: id::DeviceId,
descriptor: Option<TextureViewDescriptor<'static>>,
},
DestroyBuffer(id::BufferId),
DestroyDevice(id::DeviceId),
DestroyTexture {
device_id: id::DeviceId,
texture_id: id::TextureId,
},
DestroySwapChain {
external_id: u64,
image_key: ImageKey,
},
DropTexture(id::TextureId),
DropAdapter(id::AdapterId),
DropDevice(id::DeviceId),
DropBuffer(id::BufferId),
DropPipelineLayout(id::PipelineLayoutId),
DropComputePipeline(id::ComputePipelineId),
DropRenderPipeline(id::RenderPipelineId),
DropBindGroup(id::BindGroupId),
DropBindGroupLayout(id::BindGroupLayoutId),
DropCommandBuffer(id::CommandBufferId),
DropTextureView(id::TextureViewId),
DropSampler(id::SamplerId),
DropShaderModule(id::ShaderModuleId),
DropRenderBundle(id::RenderBundleId),
DropQuerySet(id::QuerySetId),
Exit(IpcSender<()>),
RenderBundleEncoderFinish {
render_bundle_encoder: RenderBundleEncoder,
descriptor: RenderBundleDescriptor<'static>,
render_bundle_id: id::RenderBundleId,
device_id: id::DeviceId,
},
RequestAdapter {
sender: IpcSender<Option<WebGPUResponseResult>>,
options: RequestAdapterOptions,
ids: SmallVec<[id::AdapterId; 4]>,
},
RequestDevice {
sender: IpcSender<Option<WebGPUResponseResult>>,
adapter_id: WebGPUAdapter,
descriptor: wgt::DeviceDescriptor<Option<String>>,
device_id: id::DeviceId,
pipeline_id: PipelineId,
},
RunComputePass {
command_encoder_id: id::CommandEncoderId,
compute_pass: Option<ComputePass>,
},
RunRenderPass {
command_encoder_id: id::CommandEncoderId,
render_pass: Option<RenderPass>,
},
Submit {
queue_id: id::QueueId,
command_buffers: Vec<id::CommandBufferId>,
},
SwapChainPresent {
external_id: u64,
texture_id: id::TextureId,
encoder_id: id::CommandEncoderId,
},
UnmapBuffer {
buffer_id: id::BufferId,
device_id: id::DeviceId,
array_buffer: IpcSharedMemory,
is_map_read: bool,
offset: u64,
size: u64,
},
WriteBuffer {
queue_id: id::QueueId,
buffer_id: id::BufferId,
buffer_offset: u64,
data: IpcSharedMemory,
},
WriteTexture {
queue_id: id::QueueId,
texture_cv: ImageCopyTexture,
data_layout: wgt::ImageDataLayout,
size: wgt::Extent3d,
data: IpcSharedMemory,
},
QueueOnSubmittedWorkDone {
sender: IpcSender<Option<WebGPUResponseResult>>,
queue_id: id::QueueId,
},
}

View file

@ -2,51 +2,44 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use msg::constellation_msg::PipelineId; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::wgpu::id::{ use crate::wgc::id::{
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, ComputePipelineId, AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, CommandEncoderId,
DeviceId, PipelineLayoutId, QuerySetId, RenderBundleId, RenderPipelineId, SamplerId, ComputePipelineId, DeviceId, PipelineLayoutId, QueueId, RenderBundleId, RenderPipelineId,
ShaderModuleId, StagingBufferId, SurfaceId, TextureId, TextureViewId, SamplerId, ShaderModuleId, SurfaceId, TextureId, TextureViewId,
}; };
use crate::{ErrorScopeId, WebGPUDevice};
#[derive(Clone, Debug, Deserialize, Serialize)] macro_rules! webgpu_resource {
pub enum WebGPUOpResult { ($name:ident, $id:ty) => {
ValidationError(String), #[derive(Clone, Copy, Debug, Deserialize, Hash, PartialEq, Serialize)]
OutOfMemoryError, pub struct $name(pub $id);
Success,
impl MallocSizeOf for $name {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
0
}
} }
#[derive(Clone, Debug, Deserialize, Serialize)] impl Eq for $name {}
pub enum WebGPUMsg { };
FreeAdapter(AdapterId),
FreeDevice(DeviceId),
FreeBuffer(BufferId),
FreePipelineLayout(PipelineLayoutId),
FreeComputePipeline(ComputePipelineId),
FreeRenderPipeline(RenderPipelineId),
FreeBindGroup(BindGroupId),
FreeBindGroupLayout(BindGroupLayoutId),
FreeCommandBuffer(CommandBufferId),
FreeTexture(TextureId),
FreeTextureView(TextureViewId),
FreeSampler(SamplerId),
FreeSurface(SurfaceId),
FreeShaderModule(ShaderModuleId),
FreeRenderBundle(RenderBundleId),
FreeStagingBuffer(StagingBufferId),
FreeQuerySet(QuerySetId),
WebGPUOpResult {
device: WebGPUDevice,
scope_id: Option<ErrorScopeId>,
pipeline_id: PipelineId,
result: WebGPUOpResult,
},
CleanDevice {
device: WebGPUDevice,
pipeline_id: PipelineId,
},
Exit,
} }
webgpu_resource!(WebGPUAdapter, AdapterId);
webgpu_resource!(WebGPUBindGroup, BindGroupId);
webgpu_resource!(WebGPUBindGroupLayout, BindGroupLayoutId);
webgpu_resource!(WebGPUBuffer, BufferId);
webgpu_resource!(WebGPUCommandBuffer, CommandBufferId);
webgpu_resource!(WebGPUCommandEncoder, CommandEncoderId);
webgpu_resource!(WebGPUComputePipeline, ComputePipelineId);
webgpu_resource!(WebGPUDevice, DeviceId);
webgpu_resource!(WebGPUPipelineLayout, PipelineLayoutId);
webgpu_resource!(WebGPUQueue, QueueId);
webgpu_resource!(WebGPURenderBundle, RenderBundleId);
webgpu_resource!(WebGPURenderPipeline, RenderPipelineId);
webgpu_resource!(WebGPUSampler, SamplerId);
webgpu_resource!(WebGPUShaderModule, ShaderModuleId);
webgpu_resource!(WebGPUSurface, SurfaceId);
webgpu_resource!(WebGPUTexture, TextureId);
webgpu_resource!(WebGPUTextureView, TextureViewId);

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,55 @@
/* 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/. */
//! IPC massages that are send to script thread (global scope).
use msg::constellation_msg::PipelineId;
use serde::{Deserialize, Serialize};
use crate::identity::WebGPUDevice;
use crate::wgc::id::{
AdapterId, BindGroupId, BindGroupLayoutId, BufferId, CommandBufferId, ComputePipelineId,
DeviceId, PipelineLayoutId, QuerySetId, RenderBundleId, RenderPipelineId, SamplerId,
ShaderModuleId, StagingBufferId, SurfaceId, TextureId, TextureViewId,
};
use crate::ErrorScopeId;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum WebGPUOpResult {
ValidationError(String),
OutOfMemoryError,
Success,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub enum WebGPUMsg {
FreeAdapter(AdapterId),
FreeDevice(DeviceId),
FreeBuffer(BufferId),
FreePipelineLayout(PipelineLayoutId),
FreeComputePipeline(ComputePipelineId),
FreeRenderPipeline(RenderPipelineId),
FreeBindGroup(BindGroupId),
FreeBindGroupLayout(BindGroupLayoutId),
FreeCommandBuffer(CommandBufferId),
FreeTexture(TextureId),
FreeTextureView(TextureViewId),
FreeSampler(SamplerId),
FreeSurface(SurfaceId),
FreeShaderModule(ShaderModuleId),
FreeRenderBundle(RenderBundleId),
FreeStagingBuffer(StagingBufferId),
FreeQuerySet(QuerySetId),
WebGPUOpResult {
device: WebGPUDevice,
scope_id: Option<ErrorScopeId>,
pipeline_id: PipelineId,
result: WebGPUOpResult,
},
CleanDevice {
device: WebGPUDevice,
pipeline_id: PipelineId,
},
Exit,
}

File diff suppressed because it is too large Load diff