[core-remote] remove Surface stuff from global

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev authored and Teodor Tanasoaia committed 2026-08-14 16:30:02 +02:00
1 parent 2e14c1c28d
commit ff8eeccc33
4 files changed
+7 -127

No files matched your search

-12
View File
@@ -83,18 +83,6 @@ impl Global {
unsafe { device.fence_as_hal::<A>() }
}
/// # Safety
///
/// - The raw surface handle must not be manually destroyed
pub unsafe fn surface_as_hal<A: hal::Api>(
&self,
id: SurfaceId,
) -> Option<impl Deref<Target = A::Surface>> {
let surface = self.surfaces.get(id);
unsafe { surface.as_hal::<A>() }
}
/// Encode commands using the raw HAL command encoder.
///
/// # Panics
+2 -66
View File
@@ -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<wgt::SurfaceCapabilities, instance::GetSurfaceSupportError> {
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<F: FnOnce(&Adapter, &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<Vec<TextureFormat>>,
) -> Option<present::ConfigureSurfaceError> {
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.
+4 -38
View File
@@ -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<SurfaceId>;
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<raw_window_handle::RawDisplayHandle>,
window_handle: raw_window_handle::RawWindowHandle,
id_in: Option<SurfaceId>,
) -> Result<SurfaceId, CreateSurfaceError> {
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<AdapterId>,
) -> Result<AdapterId, wgt::RequestAdapterError> {
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)?;
+1 -11
View File
@@ -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<Arc<Surface>>,
pub(crate) hub: Hub,
// the instance must be dropped last
pub instance: Arc<Instance>,
@@ -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<A: hal::Api>(name: &str, hal_instance: A::Instance) -> Self {
Self {
instance: Instance::from_hal_instance::<A>(name.to_owned(), hal_instance),
surfaces: Registry::new(),
hub: Hub::new(),
}
}
@@ -83,14 +75,12 @@ impl Global {
pub unsafe fn from_instance(instance: Arc<Instance>) -> 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(),
}
}