mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Remove wgpu_core::hal_api::HalApi
This commit is contained in:
parent
0dbe5fb28e
commit
1ed61877b5
@ -6,7 +6,6 @@ use hal::DynResource;
|
|||||||
use crate::{
|
use crate::{
|
||||||
device::Device,
|
device::Device,
|
||||||
global::Global,
|
global::Global,
|
||||||
hal_api::HalApi,
|
|
||||||
id::{
|
id::{
|
||||||
AdapterId, BlasId, BufferId, CommandEncoderId, DeviceId, QueueId, SurfaceId, TextureId,
|
AdapterId, BlasId, BufferId, CommandEncoderId, DeviceId, QueueId, SurfaceId, TextureId,
|
||||||
TextureViewId, TlasId,
|
TextureViewId, TlasId,
|
||||||
@ -226,7 +225,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw buffer handle must not be manually destroyed
|
/// - The raw buffer handle must not be manually destroyed
|
||||||
pub unsafe fn buffer_as_hal<A: HalApi>(
|
pub unsafe fn buffer_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
id: BufferId,
|
id: BufferId,
|
||||||
) -> Option<impl Deref<Target = A::Buffer>> {
|
) -> Option<impl Deref<Target = A::Buffer>> {
|
||||||
@ -242,7 +241,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw texture handle must not be manually destroyed
|
/// - The raw texture handle must not be manually destroyed
|
||||||
pub unsafe fn texture_as_hal<A: HalApi>(
|
pub unsafe fn texture_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
id: TextureId,
|
id: TextureId,
|
||||||
) -> Option<impl Deref<Target = A::Texture>> {
|
) -> Option<impl Deref<Target = A::Texture>> {
|
||||||
@ -258,7 +257,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw texture view handle must not be manually destroyed
|
/// - The raw texture view handle must not be manually destroyed
|
||||||
pub unsafe fn texture_view_as_hal<A: HalApi>(
|
pub unsafe fn texture_view_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
id: TextureViewId,
|
id: TextureViewId,
|
||||||
) -> Option<impl Deref<Target = A::TextureView>> {
|
) -> Option<impl Deref<Target = A::TextureView>> {
|
||||||
@ -274,7 +273,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw adapter handle must not be manually destroyed
|
/// - The raw adapter handle must not be manually destroyed
|
||||||
pub unsafe fn adapter_as_hal<A: HalApi>(
|
pub unsafe fn adapter_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
id: AdapterId,
|
id: AdapterId,
|
||||||
) -> Option<impl Deref<Target = A::Adapter>> {
|
) -> Option<impl Deref<Target = A::Adapter>> {
|
||||||
@ -291,7 +290,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw device handle must not be manually destroyed
|
/// - The raw device handle must not be manually destroyed
|
||||||
pub unsafe fn device_as_hal<A: HalApi>(
|
pub unsafe fn device_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
id: DeviceId,
|
id: DeviceId,
|
||||||
) -> Option<impl Deref<Target = A::Device>> {
|
) -> Option<impl Deref<Target = A::Device>> {
|
||||||
@ -305,7 +304,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw fence handle must not be manually destroyed
|
/// - The raw fence handle must not be manually destroyed
|
||||||
pub unsafe fn device_fence_as_hal<A: HalApi>(
|
pub unsafe fn device_fence_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
id: DeviceId,
|
id: DeviceId,
|
||||||
) -> Option<impl Deref<Target = A::Fence>> {
|
) -> Option<impl Deref<Target = A::Fence>> {
|
||||||
@ -318,7 +317,7 @@ impl Global {
|
|||||||
|
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// - The raw surface handle must not be manually destroyed
|
/// - The raw surface handle must not be manually destroyed
|
||||||
pub unsafe fn surface_as_hal<A: HalApi>(
|
pub unsafe fn surface_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
id: SurfaceId,
|
id: SurfaceId,
|
||||||
) -> Option<impl Deref<Target = A::Surface>> {
|
) -> Option<impl Deref<Target = A::Surface>> {
|
||||||
@ -335,7 +334,7 @@ impl Global {
|
|||||||
///
|
///
|
||||||
/// - The raw command encoder handle must not be manually destroyed
|
/// - The raw command encoder handle must not be manually destroyed
|
||||||
pub unsafe fn command_encoder_as_hal_mut<
|
pub unsafe fn command_encoder_as_hal_mut<
|
||||||
A: HalApi,
|
A: hal::Api,
|
||||||
F: FnOnce(Option<&mut A::CommandEncoder>) -> R,
|
F: FnOnce(Option<&mut A::CommandEncoder>) -> R,
|
||||||
R,
|
R,
|
||||||
>(
|
>(
|
||||||
@ -363,7 +362,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw queue handle must not be manually destroyed
|
/// - The raw queue handle must not be manually destroyed
|
||||||
pub unsafe fn queue_as_hal<A: HalApi>(
|
pub unsafe fn queue_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
id: QueueId,
|
id: QueueId,
|
||||||
) -> Option<impl Deref<Target = A::Queue>> {
|
) -> Option<impl Deref<Target = A::Queue>> {
|
||||||
@ -377,7 +376,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw blas handle must not be manually destroyed
|
/// - The raw blas handle must not be manually destroyed
|
||||||
pub unsafe fn blas_as_hal<A: HalApi>(
|
pub unsafe fn blas_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
id: BlasId,
|
id: BlasId,
|
||||||
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
||||||
@ -393,7 +392,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw tlas handle must not be manually destroyed
|
/// - The raw tlas handle must not be manually destroyed
|
||||||
pub unsafe fn tlas_as_hal<A: HalApi>(
|
pub unsafe fn tlas_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
id: TlasId,
|
id: TlasId,
|
||||||
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
||||||
|
|||||||
@ -13,7 +13,6 @@ use crate::{
|
|||||||
conv,
|
conv,
|
||||||
device::{bgl, life::WaitIdleError, DeviceError, DeviceLostClosure},
|
device::{bgl, life::WaitIdleError, DeviceError, DeviceLostClosure},
|
||||||
global::Global,
|
global::Global,
|
||||||
hal_api::HalApi,
|
|
||||||
id::{self, AdapterId, DeviceId, QueueId, SurfaceId},
|
id::{self, AdapterId, DeviceId, QueueId, SurfaceId},
|
||||||
instance::{self, Adapter, Surface},
|
instance::{self, Adapter, Surface},
|
||||||
pipeline::{
|
pipeline::{
|
||||||
@ -386,7 +385,7 @@ impl Global {
|
|||||||
/// - `hal_buffer` must be created respecting `desc`
|
/// - `hal_buffer` must be created respecting `desc`
|
||||||
/// - `hal_buffer` must be initialized
|
/// - `hal_buffer` must be initialized
|
||||||
/// - `hal_buffer` must not have zero size.
|
/// - `hal_buffer` must not have zero size.
|
||||||
pub unsafe fn create_buffer_from_hal<A: HalApi>(
|
pub unsafe fn create_buffer_from_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
hal_buffer: A::Buffer,
|
hal_buffer: A::Buffer,
|
||||||
device_id: DeviceId,
|
device_id: DeviceId,
|
||||||
|
|||||||
@ -2,7 +2,6 @@ use alloc::{borrow::ToOwned as _, sync::Arc};
|
|||||||
use core::fmt;
|
use core::fmt;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
hal_api::HalApi,
|
|
||||||
hub::{Hub, HubReport},
|
hub::{Hub, HubReport},
|
||||||
instance::{Instance, Surface},
|
instance::{Instance, Surface},
|
||||||
registry::{Registry, RegistryReport},
|
registry::{Registry, RegistryReport},
|
||||||
@ -44,7 +43,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// Refer to the creation of wgpu-hal Instance for every backend.
|
/// Refer to the creation of wgpu-hal Instance for every backend.
|
||||||
pub unsafe fn from_hal_instance<A: HalApi>(name: &str, hal_instance: A::Instance) -> Self {
|
pub unsafe fn from_hal_instance<A: hal::Api>(name: &str, hal_instance: A::Instance) -> Self {
|
||||||
profiling::scope!("Global::new");
|
profiling::scope!("Global::new");
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
@ -57,7 +56,7 @@ impl Global {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw instance handle returned must not be manually destroyed.
|
/// - The raw instance handle returned must not be manually destroyed.
|
||||||
pub unsafe fn instance_as_hal<A: HalApi>(&self) -> Option<&A::Instance> {
|
pub unsafe fn instance_as_hal<A: hal::Api>(&self) -> Option<&A::Instance> {
|
||||||
unsafe { self.instance.as_hal::<A>() }
|
unsafe { self.instance.as_hal::<A>() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,29 +0,0 @@
|
|||||||
use wgt::{Backend, WasmNotSendSync};
|
|
||||||
|
|
||||||
pub trait HalApi: hal::Api + 'static + WasmNotSendSync {
|
|
||||||
const VARIANT: Backend;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl HalApi for hal::api::Noop {
|
|
||||||
const VARIANT: Backend = Backend::Noop;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(vulkan)]
|
|
||||||
impl HalApi for hal::api::Vulkan {
|
|
||||||
const VARIANT: Backend = Backend::Vulkan;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(metal)]
|
|
||||||
impl HalApi for hal::api::Metal {
|
|
||||||
const VARIANT: Backend = Backend::Metal;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(dx12)]
|
|
||||||
impl HalApi for hal::api::Dx12 {
|
|
||||||
const VARIANT: Backend = Backend::Dx12;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(gles)]
|
|
||||||
impl HalApi for hal::api::Gles {
|
|
||||||
const VARIANT: Backend = Backend::Gl;
|
|
||||||
}
|
|
||||||
@ -15,7 +15,6 @@ use crate::{
|
|||||||
api_log, api_log_debug,
|
api_log, api_log_debug,
|
||||||
device::{queue::Queue, resource::Device, DeviceDescriptor, DeviceError},
|
device::{queue::Queue, resource::Device, DeviceDescriptor, DeviceError},
|
||||||
global::Global,
|
global::Global,
|
||||||
hal_api::HalApi,
|
|
||||||
id::{markers, AdapterId, DeviceId, QueueId, SurfaceId},
|
id::{markers, AdapterId, DeviceId, QueueId, SurfaceId},
|
||||||
lock::{rank, Mutex},
|
lock::{rank, Mutex},
|
||||||
present::Presentation,
|
present::Presentation,
|
||||||
@ -117,7 +116,7 @@ impl Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Helper for `Instance::new()`; attempts to add a single `wgpu-hal` backend to this instance.
|
/// Helper for `Instance::new()`; attempts to add a single `wgpu-hal` backend to this instance.
|
||||||
fn try_add_hal<A: HalApi>(&mut self, _: A, instance_desc: &wgt::InstanceDescriptor) {
|
fn try_add_hal<A: hal::Api>(&mut self, _: A, instance_desc: &wgt::InstanceDescriptor) {
|
||||||
// Whether or not the backend was requested, and whether or not it succeeds,
|
// Whether or not the backend was requested, and whether or not it succeeds,
|
||||||
// note that we *could* try it.
|
// note that we *could* try it.
|
||||||
self.supported_backends |= A::VARIANT.into();
|
self.supported_backends |= A::VARIANT.into();
|
||||||
@ -151,7 +150,7 @@ impl Instance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_hal_instance<A: HalApi>(
|
pub(crate) fn from_hal_instance<A: hal::Api>(
|
||||||
name: String,
|
name: String,
|
||||||
hal_instance: <A as hal::Api>::Instance,
|
hal_instance: <A as hal::Api>::Instance,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -175,7 +174,7 @@ impl Instance {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw instance handle returned must not be manually destroyed.
|
/// - The raw instance handle returned must not be manually destroyed.
|
||||||
pub unsafe fn as_hal<A: HalApi>(&self) -> Option<&A::Instance> {
|
pub unsafe fn as_hal<A: hal::Api>(&self) -> Option<&A::Instance> {
|
||||||
self.raw(A::VARIANT).map(|instance| {
|
self.raw(A::VARIANT).map(|instance| {
|
||||||
instance
|
instance
|
||||||
.as_any()
|
.as_any()
|
||||||
|
|||||||
@ -72,7 +72,6 @@ mod conv;
|
|||||||
pub mod device;
|
pub mod device;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod global;
|
pub mod global;
|
||||||
pub mod hal_api;
|
|
||||||
mod hash_utils;
|
mod hash_utils;
|
||||||
pub mod hub;
|
pub mod hub;
|
||||||
pub mod id;
|
pub mod id;
|
||||||
|
|||||||
@ -397,6 +397,8 @@ impl D3DBlob {
|
|||||||
pub struct Api;
|
pub struct Api;
|
||||||
|
|
||||||
impl crate::Api for Api {
|
impl crate::Api for Api {
|
||||||
|
const VARIANT: wgt::Backend = wgt::Backend::Dx12;
|
||||||
|
|
||||||
type Instance = Instance;
|
type Instance = Instance;
|
||||||
type Surface = Surface;
|
type Surface = Surface;
|
||||||
type Adapter = Adapter;
|
type Adapter = Adapter;
|
||||||
|
|||||||
@ -141,6 +141,8 @@ const MAX_PUSH_CONSTANTS: usize = 64;
|
|||||||
const MAX_PUSH_CONSTANT_COMMANDS: usize = MAX_PUSH_CONSTANTS * crate::MAX_CONCURRENT_SHADER_STAGES;
|
const MAX_PUSH_CONSTANT_COMMANDS: usize = MAX_PUSH_CONSTANTS * crate::MAX_CONCURRENT_SHADER_STAGES;
|
||||||
|
|
||||||
impl crate::Api for Api {
|
impl crate::Api for Api {
|
||||||
|
const VARIANT: wgt::Backend = wgt::Backend::Gl;
|
||||||
|
|
||||||
type Instance = Instance;
|
type Instance = Instance;
|
||||||
type Surface = Surface;
|
type Surface = Surface;
|
||||||
type Adapter = Adapter;
|
type Adapter = Adapter;
|
||||||
|
|||||||
@ -472,7 +472,9 @@ impl InstanceError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Api: Clone + fmt::Debug + Sized {
|
pub trait Api: Clone + fmt::Debug + Sized + WasmNotSendSync + 'static {
|
||||||
|
const VARIANT: wgt::Backend;
|
||||||
|
|
||||||
type Instance: DynInstance + Instance<A = Self>;
|
type Instance: DynInstance + Instance<A = Self>;
|
||||||
type Surface: DynSurface + Surface<A = Self>;
|
type Surface: DynSurface + Surface<A = Self>;
|
||||||
type Adapter: DynAdapter + Adapter<A = Self>;
|
type Adapter: DynAdapter + Adapter<A = Self>;
|
||||||
|
|||||||
@ -47,6 +47,8 @@ pub struct Api;
|
|||||||
type ResourceIndex = u32;
|
type ResourceIndex = u32;
|
||||||
|
|
||||||
impl crate::Api for Api {
|
impl crate::Api for Api {
|
||||||
|
const VARIANT: wgt::Backend = wgt::Backend::Metal;
|
||||||
|
|
||||||
type Instance = Instance;
|
type Instance = Instance;
|
||||||
type Surface = Surface;
|
type Surface = Surface;
|
||||||
type Adapter = Adapter;
|
type Adapter = Adapter;
|
||||||
|
|||||||
@ -31,6 +31,8 @@ pub struct Fence {
|
|||||||
type DeviceResult<T> = Result<T, crate::DeviceError>;
|
type DeviceResult<T> = Result<T, crate::DeviceError>;
|
||||||
|
|
||||||
impl crate::Api for Api {
|
impl crate::Api for Api {
|
||||||
|
const VARIANT: wgt::Backend = wgt::Backend::Noop;
|
||||||
|
|
||||||
type Instance = Context;
|
type Instance = Context;
|
||||||
type Surface = Context;
|
type Surface = Context;
|
||||||
type Adapter = Context;
|
type Adapter = Context;
|
||||||
|
|||||||
@ -56,6 +56,8 @@ const MAX_TOTAL_ATTACHMENTS: usize = crate::MAX_COLOR_ATTACHMENTS * 2 + 1;
|
|||||||
pub struct Api;
|
pub struct Api;
|
||||||
|
|
||||||
impl crate::Api for Api {
|
impl crate::Api for Api {
|
||||||
|
const VARIANT: wgt::Backend = wgt::Backend::Vulkan;
|
||||||
|
|
||||||
type Instance = Instance;
|
type Instance = Instance;
|
||||||
type Surface = Surface;
|
type Surface = Surface;
|
||||||
type Adapter = Adapter;
|
type Adapter = Adapter;
|
||||||
|
|||||||
@ -73,7 +73,7 @@ impl Adapter {
|
|||||||
/// - `hal_device` must be created from this adapter internal handle.
|
/// - `hal_device` must be created from this adapter internal handle.
|
||||||
/// - `desc.features` must be a subset of `hal_device`'s supported features.
|
/// - `desc.features` must be a subset of `hal_device`'s supported features.
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn create_device_from_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn create_device_from_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
hal_device: hal::OpenDevice<A>,
|
hal_device: hal::OpenDevice<A>,
|
||||||
desc: &DeviceDescriptor<'_>,
|
desc: &DeviceDescriptor<'_>,
|
||||||
@ -127,7 +127,7 @@ impl Adapter {
|
|||||||
///
|
///
|
||||||
/// [`A::Adapter`]: hal::Api::Adapter
|
/// [`A::Adapter`]: hal::Api::Adapter
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
) -> Option<impl Deref<Target = A::Adapter> + WasmNotSendSync> {
|
) -> Option<impl Deref<Target = A::Adapter> + WasmNotSendSync> {
|
||||||
let adapter = self.inner.as_core_opt()?;
|
let adapter = self.inner.as_core_opt()?;
|
||||||
|
|||||||
@ -192,7 +192,7 @@ impl Blas {
|
|||||||
///
|
///
|
||||||
/// [`A::AccelerationStructure`]: hal::Api::AccelerationStructure
|
/// [`A::AccelerationStructure`]: hal::Api::AccelerationStructure
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn as_hal<A: hal::Api>(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> Option<impl Deref<Target = A::AccelerationStructure> + WasmNotSendSync> {
|
) -> Option<impl Deref<Target = A::AccelerationStructure> + WasmNotSendSync> {
|
||||||
let blas = self.inner.as_core_opt()?;
|
let blas = self.inner.as_core_opt()?;
|
||||||
|
|||||||
@ -239,7 +239,7 @@ impl Buffer {
|
|||||||
///
|
///
|
||||||
/// [`A::Buffer`]: hal::Api::Buffer
|
/// [`A::Buffer`]: hal::Api::Buffer
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
) -> Option<impl Deref<Target = A::Buffer> + WasmNotSendSync> {
|
) -> Option<impl Deref<Target = A::Buffer> + WasmNotSendSync> {
|
||||||
let buffer = self.inner.as_core_opt()?;
|
let buffer = self.inner.as_core_opt()?;
|
||||||
|
|||||||
@ -258,11 +258,7 @@ impl CommandEncoder {
|
|||||||
/// - The wgpu command encoder must not be interacted with in any way while recording is
|
/// - The wgpu command encoder must not be interacted with in any way while recording is
|
||||||
/// happening to the wgpu_hal or backend command encoder.
|
/// happening to the wgpu_hal or backend command encoder.
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn as_hal_mut<
|
pub unsafe fn as_hal_mut<A: hal::Api, F: FnOnce(Option<&mut A::CommandEncoder>) -> R, R>(
|
||||||
A: wgc::hal_api::HalApi,
|
|
||||||
F: FnOnce(Option<&mut A::CommandEncoder>) -> R,
|
|
||||||
R,
|
|
||||||
>(
|
|
||||||
&mut self,
|
&mut self,
|
||||||
hal_command_encoder_callback: F,
|
hal_command_encoder_callback: F,
|
||||||
) -> R {
|
) -> R {
|
||||||
|
|||||||
@ -305,7 +305,7 @@ impl Device {
|
|||||||
/// - `hal_texture` must be initialized
|
/// - `hal_texture` must be initialized
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub unsafe fn create_texture_from_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn create_texture_from_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
hal_texture: A::Texture,
|
hal_texture: A::Texture,
|
||||||
desc: &TextureDescriptor<'_>,
|
desc: &TextureDescriptor<'_>,
|
||||||
@ -345,7 +345,7 @@ impl Device {
|
|||||||
/// - `hal_buffer` must not have zero size
|
/// - `hal_buffer` must not have zero size
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub unsafe fn create_buffer_from_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn create_buffer_from_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
hal_buffer: A::Buffer,
|
hal_buffer: A::Buffer,
|
||||||
desc: &BufferDescriptor<'_>,
|
desc: &BufferDescriptor<'_>,
|
||||||
@ -515,7 +515,7 @@ impl Device {
|
|||||||
///
|
///
|
||||||
/// [`A::Device`]: hal::Api::Device
|
/// [`A::Device`]: hal::Api::Device
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
) -> Option<impl Deref<Target = A::Device> + WasmNotSendSync> {
|
) -> Option<impl Deref<Target = A::Device> + WasmNotSendSync> {
|
||||||
let device = self.inner.as_core_opt()?;
|
let device = self.inner.as_core_opt()?;
|
||||||
|
|||||||
@ -325,7 +325,7 @@ impl Instance {
|
|||||||
/// - The `hal_instance` must be a valid and usable instance of the backend specified by `A`.
|
/// - The `hal_instance` must be a valid and usable instance of the backend specified by `A`.
|
||||||
/// - wgpu will act like it has complete ownership of this instance, and will destroy it
|
/// - wgpu will act like it has complete ownership of this instance, and will destroy it
|
||||||
/// when the last reference to the instance, internal or external, is dropped.
|
/// when the last reference to the instance, internal or external, is dropped.
|
||||||
pub unsafe fn from_hal<A: wgc::hal_api::HalApi>(hal_instance: A::Instance) -> Self {
|
pub unsafe fn from_hal<A: hal::Api>(hal_instance: A::Instance) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inner: unsafe {
|
inner: unsafe {
|
||||||
crate::backend::ContextWgpuCore::from_hal_instance::<A>(hal_instance).into()
|
crate::backend::ContextWgpuCore::from_hal_instance::<A>(hal_instance).into()
|
||||||
@ -362,7 +362,7 @@ impl Instance {
|
|||||||
/// - All the safety requirements of wgpu-hal must be upheld.
|
/// - All the safety requirements of wgpu-hal must be upheld.
|
||||||
///
|
///
|
||||||
/// [`A::Instance`]: hal::Api::Instance
|
/// [`A::Instance`]: hal::Api::Instance
|
||||||
pub unsafe fn as_hal<A: wgc::hal_api::HalApi>(&self) -> Option<&A::Instance> {
|
pub unsafe fn as_hal<A: hal::Api>(&self) -> Option<&A::Instance> {
|
||||||
self.inner
|
self.inner
|
||||||
.as_core_opt()
|
.as_core_opt()
|
||||||
.and_then(|ctx| unsafe { ctx.instance_as_hal::<A>() })
|
.and_then(|ctx| unsafe { ctx.instance_as_hal::<A>() })
|
||||||
@ -382,7 +382,7 @@ impl Instance {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// `hal_adapter` must be created from this instance internal handle.
|
/// `hal_adapter` must be created from this instance internal handle.
|
||||||
pub unsafe fn create_adapter_from_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn create_adapter_from_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
hal_adapter: hal::ExposedAdapter<A>,
|
hal_adapter: hal::ExposedAdapter<A>,
|
||||||
) -> Adapter {
|
) -> Adapter {
|
||||||
|
|||||||
@ -312,7 +312,7 @@ impl Queue {
|
|||||||
///
|
///
|
||||||
/// [`A::Queue`]: hal::Api::Queue
|
/// [`A::Queue`]: hal::Api::Queue
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
) -> Option<impl Deref<Target = A::Queue> + WasmNotSendSync> {
|
) -> Option<impl Deref<Target = A::Queue> + WasmNotSendSync> {
|
||||||
let queue = self.inner.as_core_opt()?;
|
let queue = self.inner.as_core_opt()?;
|
||||||
|
|||||||
@ -182,7 +182,7 @@ impl Surface<'_> {
|
|||||||
///
|
///
|
||||||
/// [`A::Surface`]: hal::Api::Surface
|
/// [`A::Surface`]: hal::Api::Surface
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
) -> Option<impl Deref<Target = A::Surface> + WasmNotSendSync> {
|
) -> Option<impl Deref<Target = A::Surface> + WasmNotSendSync> {
|
||||||
let core_surface = self.inner.as_core_opt()?;
|
let core_surface = self.inner.as_core_opt()?;
|
||||||
|
|||||||
@ -58,9 +58,7 @@ impl Texture {
|
|||||||
///
|
///
|
||||||
/// [`A::Texture`]: hal::Api::Texture
|
/// [`A::Texture`]: hal::Api::Texture
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn as_hal<A: hal::Api>(&self) -> Option<impl Deref<Target = A::Texture>> {
|
||||||
&self,
|
|
||||||
) -> Option<impl Deref<Target = A::Texture>> {
|
|
||||||
let texture = self.inner.as_core_opt()?;
|
let texture = self.inner.as_core_opt()?;
|
||||||
unsafe { texture.context.texture_as_hal::<A>(texture) }
|
unsafe { texture.context.texture_as_hal::<A>(texture) }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,9 +70,7 @@ impl TextureView {
|
|||||||
///
|
///
|
||||||
/// [`A::TextureView`]: hal::Api::TextureView
|
/// [`A::TextureView`]: hal::Api::TextureView
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn as_hal<A: hal::Api>(&self) -> Option<impl Deref<Target = A::TextureView>> {
|
||||||
&self,
|
|
||||||
) -> Option<impl Deref<Target = A::TextureView>> {
|
|
||||||
let view = self.inner.as_core_opt()?;
|
let view = self.inner.as_core_opt()?;
|
||||||
unsafe { view.context.texture_view_as_hal::<A>(view) }
|
unsafe { view.context.texture_view_as_hal::<A>(view) }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -68,7 +68,7 @@ impl Tlas {
|
|||||||
///
|
///
|
||||||
/// [`A::AccelerationStructure`]: hal::Api::AccelerationStructure
|
/// [`A::AccelerationStructure`]: hal::Api::AccelerationStructure
|
||||||
#[cfg(wgpu_core)]
|
#[cfg(wgpu_core)]
|
||||||
pub unsafe fn as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn as_hal<A: hal::Api>(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
||||||
let tlas = self.inner.as_core_opt()?;
|
let tlas = self.inner.as_core_opt()?;
|
||||||
|
|||||||
@ -55,7 +55,7 @@ impl fmt::Debug for ContextWgpuCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ContextWgpuCore {
|
impl ContextWgpuCore {
|
||||||
pub unsafe fn from_hal_instance<A: wgc::hal_api::HalApi>(hal_instance: A::Instance) -> Self {
|
pub unsafe fn from_hal_instance<A: hal::Api>(hal_instance: A::Instance) -> Self {
|
||||||
Self(unsafe {
|
Self(unsafe {
|
||||||
Arc::new(wgc::global::Global::from_hal_instance::<A>(
|
Arc::new(wgc::global::Global::from_hal_instance::<A>(
|
||||||
"wgpu",
|
"wgpu",
|
||||||
@ -67,7 +67,7 @@ impl ContextWgpuCore {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// - The raw instance handle returned must not be manually destroyed.
|
/// - The raw instance handle returned must not be manually destroyed.
|
||||||
pub unsafe fn instance_as_hal<A: wgc::hal_api::HalApi>(&self) -> Option<&A::Instance> {
|
pub unsafe fn instance_as_hal<A: hal::Api>(&self) -> Option<&A::Instance> {
|
||||||
unsafe { self.0.instance_as_hal::<A>() }
|
unsafe { self.0.instance_as_hal::<A>() }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,28 +80,28 @@ impl ContextWgpuCore {
|
|||||||
self.0.enumerate_adapters(backends)
|
self.0.enumerate_adapters(backends)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn create_adapter_from_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn create_adapter_from_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
hal_adapter: hal::ExposedAdapter<A>,
|
hal_adapter: hal::ExposedAdapter<A>,
|
||||||
) -> wgc::id::AdapterId {
|
) -> wgc::id::AdapterId {
|
||||||
unsafe { self.0.create_adapter_from_hal(hal_adapter.into(), None) }
|
unsafe { self.0.create_adapter_from_hal(hal_adapter.into(), None) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn adapter_as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn adapter_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
adapter: &CoreAdapter,
|
adapter: &CoreAdapter,
|
||||||
) -> Option<impl Deref<Target = A::Adapter> + WasmNotSendSync> {
|
) -> Option<impl Deref<Target = A::Adapter> + WasmNotSendSync> {
|
||||||
unsafe { self.0.adapter_as_hal::<A>(adapter.id) }
|
unsafe { self.0.adapter_as_hal::<A>(adapter.id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn buffer_as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn buffer_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
buffer: &CoreBuffer,
|
buffer: &CoreBuffer,
|
||||||
) -> Option<impl Deref<Target = A::Buffer>> {
|
) -> Option<impl Deref<Target = A::Buffer>> {
|
||||||
unsafe { self.0.buffer_as_hal::<A>(buffer.id) }
|
unsafe { self.0.buffer_as_hal::<A>(buffer.id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn create_device_from_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn create_device_from_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
adapter: &CoreAdapter,
|
adapter: &CoreAdapter,
|
||||||
hal_device: hal::OpenDevice<A>,
|
hal_device: hal::OpenDevice<A>,
|
||||||
@ -140,7 +140,7 @@ impl ContextWgpuCore {
|
|||||||
Ok((device, queue))
|
Ok((device, queue))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn create_texture_from_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn create_texture_from_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
hal_texture: A::Texture,
|
hal_texture: A::Texture,
|
||||||
device: &CoreDevice,
|
device: &CoreDevice,
|
||||||
@ -172,7 +172,7 @@ impl ContextWgpuCore {
|
|||||||
/// - `hal_buffer` must be created respecting `desc`
|
/// - `hal_buffer` must be created respecting `desc`
|
||||||
/// - `hal_buffer` must be initialized
|
/// - `hal_buffer` must be initialized
|
||||||
/// - `hal_buffer` must not have zero size.
|
/// - `hal_buffer` must not have zero size.
|
||||||
pub unsafe fn create_buffer_from_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn create_buffer_from_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
hal_buffer: A::Buffer,
|
hal_buffer: A::Buffer,
|
||||||
device: &CoreDevice,
|
device: &CoreDevice,
|
||||||
@ -201,28 +201,28 @@ impl ContextWgpuCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn device_as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn device_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
device: &CoreDevice,
|
device: &CoreDevice,
|
||||||
) -> Option<impl Deref<Target = A::Device>> {
|
) -> Option<impl Deref<Target = A::Device>> {
|
||||||
unsafe { self.0.device_as_hal::<A>(device.id) }
|
unsafe { self.0.device_as_hal::<A>(device.id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn surface_as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn surface_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
surface: &CoreSurface,
|
surface: &CoreSurface,
|
||||||
) -> Option<impl Deref<Target = A::Surface>> {
|
) -> Option<impl Deref<Target = A::Surface>> {
|
||||||
unsafe { self.0.surface_as_hal::<A>(surface.id) }
|
unsafe { self.0.surface_as_hal::<A>(surface.id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn texture_as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn texture_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
texture: &CoreTexture,
|
texture: &CoreTexture,
|
||||||
) -> Option<impl Deref<Target = A::Texture>> {
|
) -> Option<impl Deref<Target = A::Texture>> {
|
||||||
unsafe { self.0.texture_as_hal::<A>(texture.id) }
|
unsafe { self.0.texture_as_hal::<A>(texture.id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn texture_view_as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn texture_view_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
texture_view: &CoreTextureView,
|
texture_view: &CoreTextureView,
|
||||||
) -> Option<impl Deref<Target = A::TextureView>> {
|
) -> Option<impl Deref<Target = A::TextureView>> {
|
||||||
@ -231,7 +231,7 @@ impl ContextWgpuCore {
|
|||||||
|
|
||||||
/// This method will start the wgpu_core level command recording.
|
/// This method will start the wgpu_core level command recording.
|
||||||
pub unsafe fn command_encoder_as_hal_mut<
|
pub unsafe fn command_encoder_as_hal_mut<
|
||||||
A: wgc::hal_api::HalApi,
|
A: hal::Api,
|
||||||
F: FnOnce(Option<&mut A::CommandEncoder>) -> R,
|
F: FnOnce(Option<&mut A::CommandEncoder>) -> R,
|
||||||
R,
|
R,
|
||||||
>(
|
>(
|
||||||
@ -247,14 +247,14 @@ impl ContextWgpuCore {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn blas_as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn blas_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
blas: &CoreBlas,
|
blas: &CoreBlas,
|
||||||
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
||||||
unsafe { self.0.blas_as_hal::<A>(blas.id) }
|
unsafe { self.0.blas_as_hal::<A>(blas.id) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn tlas_as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn tlas_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
tlas: &CoreTlas,
|
tlas: &CoreTlas,
|
||||||
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
) -> Option<impl Deref<Target = A::AccelerationStructure>> {
|
||||||
@ -369,7 +369,7 @@ impl ContextWgpuCore {
|
|||||||
format!("Validation Error\n\nCaused by:\n{output}")
|
format!("Validation Error\n\nCaused by:\n{output}")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn queue_as_hal<A: wgc::hal_api::HalApi>(
|
pub unsafe fn queue_as_hal<A: hal::Api>(
|
||||||
&self,
|
&self,
|
||||||
queue: &CoreQueue,
|
queue: &CoreQueue,
|
||||||
) -> Option<impl Deref<Target = A::Queue> + WasmNotSendSync> {
|
) -> Option<impl Deref<Target = A::Queue> + WasmNotSendSync> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user