mirror of
https://github.com/servo/servo.git
synced 2025-08-02 20:20:14 +01:00
Share single gpu_id_hub among all threads in a process
This commit is contained in:
parent
6c506ba260
commit
e5065c7eb2
13 changed files with 54 additions and 8 deletions
|
@ -93,7 +93,7 @@ use net_traits::response::HttpsState;
|
|||
use net_traits::response::{Response, ResponseBody};
|
||||
use net_traits::storage_thread::StorageType;
|
||||
use net_traits::{Metadata, NetworkError, ReferrerPolicy, ResourceFetchTiming, ResourceThreads};
|
||||
use parking_lot::RwLock;
|
||||
use parking_lot::{Mutex as ParkMutex, RwLock};
|
||||
use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
||||
use profile_traits::time::ProfilerChan as TimeProfilerChan;
|
||||
use script_layout_interface::message::PendingRestyle;
|
||||
|
@ -544,7 +544,7 @@ unsafe_no_jsmanaged_fields!(WebGLTextureId);
|
|||
unsafe_no_jsmanaged_fields!(WebGLVertexArrayId);
|
||||
unsafe_no_jsmanaged_fields!(WebGLVersion);
|
||||
unsafe_no_jsmanaged_fields!(WebGLSLVersion);
|
||||
unsafe_no_jsmanaged_fields!(Identities);
|
||||
unsafe_no_jsmanaged_fields!(Arc<ParkMutex<Identities>>);
|
||||
unsafe_no_jsmanaged_fields!(WebGPU);
|
||||
unsafe_no_jsmanaged_fields!(WebGPUAdapter);
|
||||
unsafe_no_jsmanaged_fields!(WebGPUBuffer);
|
||||
|
|
|
@ -22,6 +22,7 @@ use crate::dom::errorevent::ErrorEvent;
|
|||
use crate::dom::event::{Event, EventBubbles, EventCancelable, EventStatus};
|
||||
use crate::dom::eventtarget::EventTarget;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::identityhub::Identities;
|
||||
use crate::dom::messageevent::MessageEvent;
|
||||
use crate::dom::worker::{TrustedWorkerAddress, Worker};
|
||||
use crate::dom::workerglobalscope::WorkerGlobalScope;
|
||||
|
@ -48,6 +49,7 @@ use net_traits::image_cache::ImageCache;
|
|||
use net_traits::request::{CredentialsMode, Destination, ParserMetadata};
|
||||
use net_traits::request::{Referrer, RequestBuilder, RequestMode};
|
||||
use net_traits::IpcSend;
|
||||
use parking_lot::Mutex;
|
||||
use script_traits::{WorkerGlobalScopeInit, WorkerScriptLoadOrigin};
|
||||
use servo_rand::random;
|
||||
use servo_url::ServoUrl;
|
||||
|
@ -223,6 +225,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
closing: Arc<AtomicBool>,
|
||||
image_cache: Arc<dyn ImageCache>,
|
||||
browsing_context: Option<BrowsingContextId>,
|
||||
gpu_id_hub: Arc<Mutex<Identities>>,
|
||||
) -> DedicatedWorkerGlobalScope {
|
||||
DedicatedWorkerGlobalScope {
|
||||
workerglobalscope: WorkerGlobalScope::new_inherited(
|
||||
|
@ -233,6 +236,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
runtime,
|
||||
from_devtools_receiver,
|
||||
Some(closing),
|
||||
gpu_id_hub,
|
||||
),
|
||||
task_queue: TaskQueue::new(receiver, own_sender.clone()),
|
||||
own_sender: own_sender,
|
||||
|
@ -257,6 +261,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
closing: Arc<AtomicBool>,
|
||||
image_cache: Arc<dyn ImageCache>,
|
||||
browsing_context: Option<BrowsingContextId>,
|
||||
gpu_id_hub: Arc<Mutex<Identities>>,
|
||||
) -> DomRoot<DedicatedWorkerGlobalScope> {
|
||||
let cx = runtime.cx();
|
||||
let scope = Box::new(DedicatedWorkerGlobalScope::new_inherited(
|
||||
|
@ -272,6 +277,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
closing,
|
||||
image_cache,
|
||||
browsing_context,
|
||||
gpu_id_hub,
|
||||
));
|
||||
unsafe { DedicatedWorkerGlobalScopeBinding::Wrap(SafeJSContext::from_ptr(cx), scope) }
|
||||
}
|
||||
|
@ -292,6 +298,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
closing: Arc<AtomicBool>,
|
||||
image_cache: Arc<dyn ImageCache>,
|
||||
browsing_context: Option<BrowsingContextId>,
|
||||
gpu_id_hub: Arc<Mutex<Identities>>,
|
||||
) {
|
||||
let serialized_worker_url = worker_url.to_string();
|
||||
let name = format!("WebWorker for {}", serialized_worker_url);
|
||||
|
@ -361,6 +368,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
closing,
|
||||
image_cache,
|
||||
browsing_context,
|
||||
gpu_id_hub,
|
||||
);
|
||||
// FIXME(njn): workers currently don't have a unique ID suitable for using in reporter
|
||||
// registration (#6631), so we instead use a random number and cross our fingers.
|
||||
|
|
|
@ -62,6 +62,7 @@ impl DissimilarOriginWindow {
|
|||
global_to_clone_from.microtask_queue().clone(),
|
||||
global_to_clone_from.is_headless(),
|
||||
global_to_clone_from.get_user_agent(),
|
||||
global_to_clone_from.wgpu_id_hub(),
|
||||
),
|
||||
window_proxy: Dom::from_ref(window_proxy),
|
||||
location: Default::default(),
|
||||
|
|
|
@ -88,6 +88,7 @@ use net_traits::filemanager_thread::{
|
|||
};
|
||||
use net_traits::image_cache::ImageCache;
|
||||
use net_traits::{CoreResourceMsg, CoreResourceThread, IpcSend, ResourceThreads};
|
||||
use parking_lot::Mutex;
|
||||
use profile_traits::{ipc as profile_ipc, mem as profile_mem, time as profile_time};
|
||||
use script_traits::serializable::{BlobData, BlobImpl, FileBlob};
|
||||
use script_traits::transferable::MessagePortImpl;
|
||||
|
@ -98,7 +99,7 @@ use script_traits::{
|
|||
use script_traits::{TimerEventId, TimerSchedulerMsg, TimerSource};
|
||||
use servo_url::{MutableOrigin, ServoUrl};
|
||||
use std::borrow::Cow;
|
||||
use std::cell::{Cell, RefCell, RefMut};
|
||||
use std::cell::Cell;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::{HashMap, VecDeque};
|
||||
use std::ffi::CString;
|
||||
|
@ -232,7 +233,7 @@ pub struct GlobalScope {
|
|||
user_agent: Cow<'static, str>,
|
||||
|
||||
#[ignore_malloc_size_of = "defined in wgpu"]
|
||||
gpu_id_hub: RefCell<Identities>,
|
||||
gpu_id_hub: Arc<Mutex<Identities>>,
|
||||
|
||||
// https://w3c.github.io/performance-timeline/#supportedentrytypes-attribute
|
||||
#[ignore_malloc_size_of = "mozjs"]
|
||||
|
@ -554,6 +555,7 @@ impl GlobalScope {
|
|||
microtask_queue: Rc<MicrotaskQueue>,
|
||||
is_headless: bool,
|
||||
user_agent: Cow<'static, str>,
|
||||
gpu_id_hub: Arc<Mutex<Identities>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
message_port_state: DomRefCell::new(MessagePortState::UnManaged),
|
||||
|
@ -584,7 +586,7 @@ impl GlobalScope {
|
|||
consumed_rejections: Default::default(),
|
||||
is_headless,
|
||||
user_agent,
|
||||
gpu_id_hub: RefCell::new(Identities::new()),
|
||||
gpu_id_hub,
|
||||
frozen_supported_performance_entry_types: DomRefCell::new(Default::default()),
|
||||
}
|
||||
}
|
||||
|
@ -2510,8 +2512,8 @@ impl GlobalScope {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn wgpu_id_hub(&self) -> RefMut<Identities> {
|
||||
self.gpu_id_hub.borrow_mut()
|
||||
pub fn wgpu_id_hub(&self) -> Arc<Mutex<Identities>> {
|
||||
self.gpu_id_hub.clone()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ impl GPUMethods for GPU {
|
|||
},
|
||||
None => wgpu::instance::PowerPreference::Default,
|
||||
};
|
||||
let ids = global.wgpu_id_hub().create_adapter_ids();
|
||||
let ids = global.wgpu_id_hub().lock().create_adapter_ids();
|
||||
|
||||
let script_to_constellation_chan = global.script_to_constellation_chan();
|
||||
if script_to_constellation_chan
|
||||
|
|
|
@ -91,6 +91,7 @@ impl GPUAdapterMethods for GPUAdapter {
|
|||
let id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_device_id(self.adapter.0.backend());
|
||||
if self
|
||||
.channel
|
||||
|
|
|
@ -171,6 +171,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_buffer_id(self.device.0.backend());
|
||||
self.channel
|
||||
.0
|
||||
|
@ -208,6 +209,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let buffer_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_buffer_id(self.device.0.backend());
|
||||
self.channel
|
||||
.0
|
||||
|
@ -393,6 +395,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let bind_group_layout_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_bind_group_layout_id(self.device.0.backend());
|
||||
self.channel
|
||||
.0
|
||||
|
@ -472,6 +475,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let pipeline_layout_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_pipeline_layout_id(self.device.0.backend());
|
||||
self.channel
|
||||
.0
|
||||
|
@ -532,6 +536,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let bind_group_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_bind_group_id(self.device.0.backend());
|
||||
self.channel
|
||||
.0
|
||||
|
@ -561,6 +566,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let program_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_shader_module_id(self.device.0.backend());
|
||||
self.channel
|
||||
.0
|
||||
|
@ -587,6 +593,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let compute_pipeline_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_compute_pipeline_id(self.device.0.backend());
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
self.channel
|
||||
|
@ -613,6 +620,7 @@ impl GPUDeviceMethods for GPUDevice {
|
|||
let command_encoder_id = self
|
||||
.global()
|
||||
.wgpu_id_hub()
|
||||
.lock()
|
||||
.create_command_encoder_id(self.device.0.backend());
|
||||
self.channel
|
||||
.0
|
||||
|
|
|
@ -18,6 +18,7 @@ use crate::dom::eventtarget::EventTarget;
|
|||
use crate::dom::extendableevent::ExtendableEvent;
|
||||
use crate::dom::extendablemessageevent::ExtendableMessageEvent;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::identityhub::Identities;
|
||||
use crate::dom::messageevent::MessageEvent;
|
||||
use crate::dom::worker::TrustedWorkerAddress;
|
||||
use crate::dom::workerglobalscope::WorkerGlobalScope;
|
||||
|
@ -38,10 +39,12 @@ use js::jsval::UndefinedValue;
|
|||
use msg::constellation_msg::PipelineId;
|
||||
use net_traits::request::{CredentialsMode, Destination, ParserMetadata, Referrer, RequestBuilder};
|
||||
use net_traits::{CustomResponseMediator, IpcSend};
|
||||
use parking_lot::Mutex;
|
||||
use script_traits::{ScopeThings, ServiceWorkerMsg, WorkerGlobalScopeInit, WorkerScriptLoadOrigin};
|
||||
use servo_config::pref;
|
||||
use servo_rand::random;
|
||||
use servo_url::ServoUrl;
|
||||
use std::sync::Arc;
|
||||
use std::thread;
|
||||
use std::time::{Duration, Instant};
|
||||
use style::thread_state::{self, ThreadState};
|
||||
|
@ -210,6 +213,7 @@ impl ServiceWorkerGlobalScope {
|
|||
runtime,
|
||||
from_devtools_receiver,
|
||||
None,
|
||||
Arc::new(Mutex::new(Identities::new())),
|
||||
),
|
||||
task_queue: TaskQueue::new(receiver, own_sender.clone()),
|
||||
own_sender: own_sender,
|
||||
|
|
|
@ -40,6 +40,7 @@ use crate::dom::eventtarget::EventTarget;
|
|||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::hashchangeevent::HashChangeEvent;
|
||||
use crate::dom::history::History;
|
||||
use crate::dom::identityhub::Identities;
|
||||
use crate::dom::location::Location;
|
||||
use crate::dom::mediaquerylist::{MediaQueryList, MediaQueryListMatchState};
|
||||
use crate::dom::mediaquerylistevent::MediaQueryListEvent;
|
||||
|
@ -100,6 +101,7 @@ use net_traits::image_cache::{PendingImageId, PendingImageResponse};
|
|||
use net_traits::storage_thread::StorageType;
|
||||
use net_traits::ResourceThreads;
|
||||
use num_traits::ToPrimitive;
|
||||
use parking_lot::Mutex as ParkMutex;
|
||||
use profile_traits::ipc as ProfiledIpc;
|
||||
use profile_traits::mem::ProfilerChan as MemProfilerChan;
|
||||
use profile_traits::time::{ProfilerChan as TimeProfilerChan, ProfilerMsg};
|
||||
|
@ -2322,6 +2324,7 @@ impl Window {
|
|||
user_agent: Cow<'static, str>,
|
||||
player_context: WindowGLContext,
|
||||
event_loop_waker: Option<Box<dyn EventLoopWaker>>,
|
||||
gpu_id_hub: Arc<ParkMutex<Identities>>,
|
||||
) -> DomRoot<Self> {
|
||||
let layout_rpc: Box<dyn LayoutRPC + Send> = {
|
||||
let (rpc_send, rpc_recv) = unbounded();
|
||||
|
@ -2345,6 +2348,7 @@ impl Window {
|
|||
microtask_queue,
|
||||
is_headless,
|
||||
user_agent,
|
||||
gpu_id_hub,
|
||||
),
|
||||
script_chan,
|
||||
task_manager,
|
||||
|
|
|
@ -139,6 +139,7 @@ impl Worker {
|
|||
closing,
|
||||
global.image_cache(),
|
||||
browsing_context,
|
||||
global.wgpu_id_hub(),
|
||||
);
|
||||
|
||||
Ok(worker)
|
||||
|
|
|
@ -21,6 +21,7 @@ use crate::dom::bindings::trace::RootedTraceableBox;
|
|||
use crate::dom::crypto::Crypto;
|
||||
use crate::dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::identityhub::Identities;
|
||||
use crate::dom::performance::Performance;
|
||||
use crate::dom::promise::Promise;
|
||||
use crate::dom::serviceworkerglobalscope::ServiceWorkerGlobalScope;
|
||||
|
@ -53,6 +54,7 @@ use net_traits::request::{
|
|||
CredentialsMode, Destination, ParserMetadata, RequestBuilder as NetRequestInit,
|
||||
};
|
||||
use net_traits::IpcSend;
|
||||
use parking_lot::Mutex;
|
||||
use script_traits::WorkerGlobalScopeInit;
|
||||
use servo_url::{MutableOrigin, ServoUrl};
|
||||
use std::default::Default;
|
||||
|
@ -125,6 +127,7 @@ impl WorkerGlobalScope {
|
|||
runtime: Runtime,
|
||||
from_devtools_receiver: Receiver<DevtoolScriptControlMsg>,
|
||||
closing: Option<Arc<AtomicBool>>,
|
||||
gpu_id_hub: Arc<Mutex<Identities>>,
|
||||
) -> Self {
|
||||
// Install a pipeline-namespace in the current thread.
|
||||
PipelineNamespace::auto_install();
|
||||
|
@ -141,6 +144,7 @@ impl WorkerGlobalScope {
|
|||
runtime.microtask_queue.clone(),
|
||||
init.is_headless,
|
||||
init.user_agent,
|
||||
gpu_id_hub,
|
||||
),
|
||||
worker_id: init.worker_id,
|
||||
worker_name,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
use crate::dom::bindings::inheritance::Castable;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::identityhub::Identities;
|
||||
use crate::dom::paintworkletglobalscope::PaintWorkletGlobalScope;
|
||||
use crate::dom::paintworkletglobalscope::PaintWorkletTask;
|
||||
use crate::dom::testworkletglobalscope::TestWorkletGlobalScope;
|
||||
|
@ -21,6 +22,7 @@ use js::rust::Runtime;
|
|||
use msg::constellation_msg::PipelineId;
|
||||
use net_traits::image_cache::ImageCache;
|
||||
use net_traits::ResourceThreads;
|
||||
use parking_lot::Mutex;
|
||||
use profile_traits::mem;
|
||||
use profile_traits::time;
|
||||
use script_traits::{Painter, ScriptMsg};
|
||||
|
@ -71,6 +73,7 @@ impl WorkletGlobalScope {
|
|||
Default::default(),
|
||||
init.is_headless,
|
||||
init.user_agent.clone(),
|
||||
init.gpu_id_hub.clone(),
|
||||
),
|
||||
base_url,
|
||||
to_script_thread_sender: init.to_script_thread_sender.clone(),
|
||||
|
@ -156,6 +159,8 @@ pub struct WorkletGlobalScopeInit {
|
|||
pub is_headless: bool,
|
||||
/// An optional string allowing the user agent to be set for testing
|
||||
pub user_agent: Cow<'static, str>,
|
||||
/// Channel to WebGPU
|
||||
pub gpu_id_hub: Arc<Mutex<Identities>>,
|
||||
}
|
||||
|
||||
/// <https://drafts.css-houdini.org/worklets/#worklet-global-scope-type>
|
||||
|
|
|
@ -55,6 +55,7 @@ use crate::dom::event::{Event, EventBubbles, EventCancelable};
|
|||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::htmlanchorelement::HTMLAnchorElement;
|
||||
use crate::dom::htmliframeelement::{HTMLIFrameElement, NavigationType};
|
||||
use crate::dom::identityhub::Identities;
|
||||
use crate::dom::mutationobserver::MutationObserver;
|
||||
use crate::dom::node::{
|
||||
from_untrusted_node_address, window_from_node, Node, NodeDamage, ShadowIncluding,
|
||||
|
@ -129,6 +130,7 @@ use net_traits::{
|
|||
Metadata, NetworkError, ReferrerPolicy, ResourceFetchTiming, ResourceThreads,
|
||||
ResourceTimingType,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use percent_encoding::percent_decode;
|
||||
use profile_traits::mem::{self as profile_mem, OpaqueSender, ReportsChan};
|
||||
use profile_traits::time::{self as profile_time, profile, ProfilerCategory};
|
||||
|
@ -698,6 +700,9 @@ pub struct ScriptThread {
|
|||
|
||||
/// Code is running as a consequence of a user interaction
|
||||
is_user_interacting: Cell<bool>,
|
||||
|
||||
/// Channel to WebGPU
|
||||
gpu_id_hub: Arc<Mutex<Identities>>,
|
||||
}
|
||||
|
||||
/// In the event of thread panic, all data on the stack runs its destructor. However, there
|
||||
|
@ -1151,6 +1156,7 @@ impl ScriptThread {
|
|||
image_cache: script_thread.image_cache.clone(),
|
||||
is_headless: script_thread.headless,
|
||||
user_agent: script_thread.user_agent.clone(),
|
||||
gpu_id_hub: script_thread.gpu_id_hub.clone(),
|
||||
};
|
||||
Rc::new(WorkletThreadPool::spawn(init))
|
||||
})
|
||||
|
@ -1396,6 +1402,7 @@ impl ScriptThread {
|
|||
|
||||
node_ids: Default::default(),
|
||||
is_user_interacting: Cell::new(false),
|
||||
gpu_id_hub: Arc::new(Mutex::new(Identities::new())),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3313,6 +3320,7 @@ impl ScriptThread {
|
|||
self.user_agent.clone(),
|
||||
self.player_context.clone(),
|
||||
self.event_loop_waker.as_ref().map(|w| (*w).clone_box()),
|
||||
self.gpu_id_hub.clone(),
|
||||
);
|
||||
|
||||
// Initialize the browsing context for the window.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue