From ff8eeccc330ebeff9b8987a51e99e35a88f95c5f Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Fri, 14 Aug 2026 10:31:01 +0200 Subject: [PATCH] [core-remote] remove Surface stuff from global Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- wgpu-core-remote/src/global/as_hal.rs | 12 ----- wgpu-core-remote/src/global/device.rs | 68 +------------------------ wgpu-core-remote/src/global/instance.rs | 42 ++------------- wgpu-core-remote/src/global/mod.rs | 12 +---- 4 files changed, 7 insertions(+), 127 deletions(-) diff --git a/wgpu-core-remote/src/global/as_hal.rs b/wgpu-core-remote/src/global/as_hal.rs index 2014ab65c..33b64142d 100644 --- a/wgpu-core-remote/src/global/as_hal.rs +++ b/wgpu-core-remote/src/global/as_hal.rs @@ -83,18 +83,6 @@ impl Global { unsafe { device.fence_as_hal::() } } - /// # Safety - /// - /// - The raw surface handle must not be manually destroyed - pub unsafe fn surface_as_hal( - &self, - id: SurfaceId, - ) -> Option> { - let surface = self.surfaces.get(id); - - unsafe { surface.as_hal::() } - } - /// Encode commands using the raw HAL command encoder. /// /// # Panics diff --git a/wgpu-core-remote/src/global/device.rs b/wgpu-core-remote/src/global/device.rs index 8de5a1736..72c248f9d 100644 --- a/wgpu-core-remote/src/global/device.rs +++ b/wgpu-core-remote/src/global/device.rs @@ -5,12 +5,10 @@ use wgpu_core::{ binding_model::{self}, command, device::{Device, DeviceError, DeviceLostClosure, WaitIdleError}, - instance::{self, Adapter, Surface}, pipeline::{ self, MeshState, ProgrammableStageDescriptor, RenderPipelineVertexProcessor, ResolvedGeneralRenderPipelineDescriptor, TaskState, }, - present, resource::{ self, BufferAccessError, BufferAccessResult, BufferMapOperation, CreateBufferError, }, @@ -19,11 +17,11 @@ use wgpu_core::{ use crate::{ global::Global, - id::{self, AdapterId, DeviceId, QueueId, SurfaceId}, + id::{self, DeviceId, QueueId}, storage::Storage, }; -use wgt::{BufferAddress, TextureFormat}; +use wgt::BufferAddress; pub type BindGroupDescriptor<'a> = binding_model::BindGroupDescriptor< 'a, @@ -84,56 +82,6 @@ pub type GeneralRenderPipelineDescriptor<'a> = pipeline::GeneralRenderPipelineDe >; impl Global { - pub fn adapter_is_surface_supported( - &self, - adapter_id: AdapterId, - surface_id: SurfaceId, - ) -> bool { - let surface = self.surfaces.get(surface_id); - let adapter = self.hub.adapters.get(adapter_id); - adapter.is_surface_supported(&surface) - } - - pub fn surface_get_capabilities( - &self, - surface_id: SurfaceId, - adapter_id: AdapterId, - ) -> Result { - self.fetch_adapter_and_surface::<_, _>(surface_id, adapter_id, |adapter, surface| { - surface.get_capabilities(adapter) - }) - } - - /// Returns the HDR and luminance characteristics of the display backing - /// `surface_id` on `adapter_id`. - /// - /// Reports the raw display state, independent of the surface's configured - /// color space; see [`wgt::DisplayHdrInfo`] for per-field platform coverage. - /// Returns [`wgt::DisplayHdrInfo::default`] (all fields `None`) when nothing - /// is known: the surface is not on `adapter_id`'s backend, the backend has - /// no display-query path, or the Metal backend is queried off the main - /// thread. - pub fn surface_display_hdr_info( - &self, - surface_id: SurfaceId, - adapter_id: AdapterId, - ) -> wgt::DisplayHdrInfo { - self.fetch_adapter_and_surface(surface_id, adapter_id, |adapter, surface| { - surface.display_hdr_info(adapter) - }) - } - - fn fetch_adapter_and_surface B, B>( - &self, - surface_id: SurfaceId, - adapter_id: AdapterId, - get_supported_callback: F, - ) -> B { - let surface = self.surfaces.get(surface_id); - let adapter = self.hub.adapters.get(adapter_id); - get_supported_callback(&adapter, &surface) - } - pub fn device_features(&self, device_id: DeviceId) -> wgt::Features { let device = self.hub.devices.get(device_id); *device.features() @@ -1126,18 +1074,6 @@ impl Global { let _cache = hub.pipeline_caches.remove(pipeline_cache_id); } - pub fn surface_configure( - &self, - surface_id: SurfaceId, - device_id: DeviceId, - config: &wgt::SurfaceConfiguration>, - ) -> Option { - let device = self.hub.devices.get(device_id); - let surface = self.surfaces.get(surface_id); - - surface.configure(&device, config) - } - /// Check `device_id` for freeable resources and completed buffer mappings. /// /// Return `queue_empty` indicating whether there are more queue submissions still in flight. diff --git a/wgpu-core-remote/src/global/instance.rs b/wgpu-core-remote/src/global/instance.rs index 8aa988add..359a76a55 100644 --- a/wgpu-core-remote/src/global/instance.rs +++ b/wgpu-core-remote/src/global/instance.rs @@ -1,46 +1,13 @@ use wgpu_core::device::DeviceDescriptor; -use wgpu_core::instance::{CreateSurfaceError, RequestDeviceError}; +use wgpu_core::instance::RequestDeviceError; use wgt::Backends; use crate::global::Global; -use crate::id::{AdapterId, DeviceId, QueueId, SurfaceId}; +use crate::id::{AdapterId, DeviceId, QueueId}; -pub type RequestAdapterOptions = wgt::RequestAdapterOptions; +pub type RequestAdapterOptions = wgt::RequestAdapterOptions<()>; impl Global { - /// Creates a new surface targeting the given display/window handles. - /// - /// Internally attempts to create hal surfaces for all enabled backends. - /// - /// Fails only if creation for surfaces for all enabled backends fails in which case - /// the error for each enabled backend is listed. - /// Vice versa, if creation for any backend succeeds, success is returned. - /// Surface creation errors are logged to the debug log in any case. - /// - /// id_in: - /// - If `Some`, the id to assign to the surface. A new one will be generated otherwise. - /// - /// # Safety - /// - /// - `display_handle` must be a valid object to create a surface upon, - /// falls back to the instance display handle otherwise. - /// - `window_handle` must remain valid as long as the returned - /// [`SurfaceId`] is being used. - pub unsafe fn instance_create_surface( - &self, - display_handle: Option, - window_handle: raw_window_handle::RawWindowHandle, - id_in: Option, - ) -> Result { - let surface = unsafe { self.instance.create_surface(display_handle, window_handle) }?; - let id = self.surfaces.prepare(id_in).assign(surface); - Ok(id) - } - - pub fn surface_drop(&self, id: SurfaceId) { - self.surfaces.remove(id); - } - pub fn enumerate_adapters( &self, backends: Backends, @@ -61,11 +28,10 @@ impl Global { backends: Backends, id_in: Option, ) -> Result { - let compatible_surface = desc.compatible_surface.map(|id| self.surfaces.get(id)); let desc = wgt::RequestAdapterOptions { power_preference: desc.power_preference, force_fallback_adapter: desc.force_fallback_adapter, - compatible_surface: compatible_surface.as_deref(), + compatible_surface: None, apply_limit_buckets: desc.apply_limit_buckets, }; let adapter = self.instance.request_adapter(&desc, backends)?; diff --git a/wgpu-core-remote/src/global/mod.rs b/wgpu-core-remote/src/global/mod.rs index d53da1ae9..5cc22da39 100644 --- a/wgpu-core-remote/src/global/mod.rs +++ b/wgpu-core-remote/src/global/mod.rs @@ -4,7 +4,7 @@ use wgpu_core::binding_model::{BindGroupLayout, PipelineLayout}; use wgpu_core::command::{CommandBuffer, CommandEncoder}; use wgpu_core::device::queue::Queue; use wgpu_core::device::Device; -use wgpu_core::instance::{Adapter, Instance, Surface}; +use wgpu_core::instance::{Adapter, Instance}; use wgpu_core::pipeline::{ComputePipeline, RenderPipeline}; use wgpu_core::resource::{Buffer, QuerySet, Texture}; @@ -13,7 +13,6 @@ use crate::id::{ AdapterId, BindGroupLayoutId, BufferId, CommandBufferId, CommandEncoderId, ComputePipelineId, DeviceId, PipelineLayoutId, QuerySetId, QueueId, RenderPipelineId, TextureId, }; -use crate::registry::{Registry, RegistryReport}; mod as_hal; mod bundle; @@ -26,21 +25,16 @@ mod render_pass; #[derive(Debug, PartialEq, Eq)] pub struct GlobalReport { - pub surfaces: RegistryReport, pub hub: HubReport, } impl GlobalReport { - pub fn surfaces(&self) -> &RegistryReport { - &self.surfaces - } pub fn hub_report(&self) -> &HubReport { &self.hub } } pub struct Global { - pub(crate) surfaces: Registry>, pub(crate) hub: Hub, // the instance must be dropped last pub instance: Arc, @@ -54,7 +48,6 @@ impl Global { ) -> Self { Self { instance: Instance::new(name, instance_desc, telemetry), - surfaces: Registry::new(), hub: Hub::new(), } } @@ -65,7 +58,6 @@ impl Global { pub unsafe fn from_hal_instance(name: &str, hal_instance: A::Instance) -> Self { Self { instance: Instance::from_hal_instance::(name.to_owned(), hal_instance), - surfaces: Registry::new(), hub: Hub::new(), } } @@ -83,14 +75,12 @@ impl Global { pub unsafe fn from_instance(instance: Arc) -> Self { Self { instance, - surfaces: Registry::new(), hub: Hub::new(), } } pub fn generate_report(&self) -> GlobalReport { GlobalReport { - surfaces: self.surfaces.generate_report(), hub: self.hub.generate_report(), } }