Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [
"tests",
"wgpu-core",
"wgpu-core/platform-deps/*",
"wgpu-core-remote",
"wgpu-hal",
"wgpu-info",
"wgpu-naga-bridge",
Expand Down
37 changes: 37 additions & 0 deletions wgpu-core-remote/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "wgpu-core-remote"
version.workspace = true
edition.workspace = true
description = "Remoting version of wgpu-core"
homepage.workspace = true
repository.workspace = true
keywords.workspace = true
license.workspace = true

# Override the workspace's `rust-version` key. `wgpu-core-remote` and its dependencies
# have a less strict MSRV, to allow firefox more leeway in updating their Rust toolchain.
#
# See the repo README for more information on MSRV policy.
rust-version = "1.87"

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
targets = [
"x86_64-unknown-linux-gnu",
"x86_64-apple-darwin",
"x86_64-pc-windows-msvc",
"wasm32-unknown-unknown",
]

[features]
## Enables serialization via `serde` on common wgpu types.
serde = ["dep:serde", "wgpu-types/serde", "wgpu-core/serde"]

[dependencies]
wgpu-core = { workspace = true, default-features = false }
wgpu-hal = { workspace = true, default-features = false }
wgpu-types.workspace = true
parking_lot.workspace = true
raw-window-handle.workspace = true
serde = { workspace = true, optional = true }
161 changes: 161 additions & 0 deletions wgpu-core-remote/src/global/as_hal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
use core::ops::Deref;

use crate::global::Global;
use crate::id::*;

impl Global {
/// # Safety
///
/// - The raw buffer handle must not be manually destroyed
pub unsafe fn buffer_as_hal<A: hal::Api>(
&self,
id: BufferId,
) -> Option<impl Deref<Target = A::Buffer>> {
let hub = &self.hub;

let buffer = hub.buffers.get(id);

unsafe { buffer.as_hal::<A>() }
}

/// # Safety
///
/// - The raw texture handle must not be manually destroyed
pub unsafe fn texture_as_hal<A: hal::Api>(
&self,
id: TextureId,
) -> Option<impl Deref<Target = A::Texture>> {
let hub = &self.hub;

let texture = hub.textures.get(id);

unsafe { texture.as_hal::<A>() }
}

/// # Safety
///
/// - The raw texture view handle must not be manually destroyed
pub unsafe fn texture_view_as_hal<A: hal::Api>(
&self,
id: TextureViewId,
) -> Option<impl Deref<Target = A::TextureView>> {
let hub = &self.hub;

let view = hub.texture_views.get(id);

unsafe { view.as_hal::<A>() }
}

/// # Safety
///
/// - The raw adapter handle must not be manually destroyed
pub unsafe fn adapter_as_hal<A: hal::Api>(
&self,
id: AdapterId,
) -> Option<impl Deref<Target = A::Adapter>> {
let hub = &self.hub;
let adapter = hub.adapters.get(id);

unsafe { adapter.as_hal::<A>() }
}

/// # Safety
///
/// - The raw device handle must not be manually destroyed
pub unsafe fn device_as_hal<A: hal::Api>(
&self,
id: DeviceId,
) -> Option<impl Deref<Target = A::Device>> {
let device = self.hub.devices.get(id);

unsafe { device.as_hal::<A>() }
}

/// # Safety
///
/// - The raw fence handle must not be manually destroyed
pub unsafe fn device_fence_as_hal<A: hal::Api>(
&self,
id: DeviceId,
) -> Option<impl Deref<Target = A::Fence>> {
let device = self.hub.devices.get(id);

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
///
/// If the command encoder has already been used with the wgpu encoding API.
///
/// # Safety
///
/// - The raw command encoder handle must not be manually destroyed
pub unsafe fn command_encoder_as_hal_mut<
A: hal::Api,
F: FnOnce(Option<&mut A::CommandEncoder>) -> R,
R,
>(
&self,
id: CommandEncoderId,
hal_command_encoder_callback: F,
) -> R {
let hub = &self.hub;

let cmd_enc = hub.command_encoders.get(id);
unsafe { cmd_enc.as_hal_mut::<A, F, R>(hal_command_encoder_callback) }
}

/// # Safety
///
/// - The raw queue handle must not be manually destroyed
pub unsafe fn queue_as_hal<A: hal::Api>(
&self,
id: QueueId,
) -> Option<impl Deref<Target = A::Queue>> {
let queue = self.hub.queues.get(id);

unsafe { queue.as_hal::<A>() }
}

/// # Safety
///
/// - The raw blas handle must not be manually destroyed
pub unsafe fn blas_as_hal<A: hal::Api>(
&self,
id: BlasId,
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
let hub = &self.hub;

let blas = hub.blas_s.get(id);

unsafe { blas.as_hal::<A>() }
}

/// # Safety
///
/// - The raw tlas handle must not be manually destroyed
pub unsafe fn tlas_as_hal<A: hal::Api>(
&self,
id: TlasId,
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
let hub = &self.hub;

let tlas = hub.tlas_s.get(id);

unsafe { tlas.as_hal::<A>() }
}
}
Loading
Loading