mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Add Texture::as_hal()
This commit is contained in:
committed by
Dzmitry Malyshau
parent
9606f9cc40
commit
0a2be6099c
@@ -859,7 +859,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
trace_path: Option<&std::path::Path>,
|
||||
id_in: Input<G, DeviceId>,
|
||||
) -> (DeviceId, Option<RequestDeviceError>) {
|
||||
profiling::scope!("request_device", "Adapter");
|
||||
profiling::scope!("create_device_from_hal", "Adapter");
|
||||
|
||||
let hub = A::hub(self);
|
||||
let mut token = Token::root();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
device::{DeviceError, HostMap, MissingFeatures},
|
||||
hub::Resource,
|
||||
hub::{Global, GlobalIdentityHandlerFactory, HalApi, Resource, Token},
|
||||
id::{DeviceId, SurfaceId, TextureId, Valid},
|
||||
init_tracker::BufferInitTracker,
|
||||
track::{TextureSelector, DUMMY_SELECTOR},
|
||||
@@ -191,6 +191,27 @@ pub struct Texture<A: hal::Api> {
|
||||
pub(crate) life_guard: LifeGuard,
|
||||
}
|
||||
|
||||
impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw texture handle must not be manually destroyed
|
||||
pub unsafe fn texture_as_hal<A: HalApi, F: FnOnce(Option<&A::Texture>)>(
|
||||
&self,
|
||||
id: TextureId,
|
||||
hal_texture_callback: F,
|
||||
) {
|
||||
profiling::scope!("as_hal", "Texture");
|
||||
|
||||
let hub = A::hub(self);
|
||||
let mut token = Token::root();
|
||||
let (guard, _) = hub.textures.read(&mut token);
|
||||
let texture = guard.get(id).ok();
|
||||
let hal_texture = texture.map(|tex| tex.inner.as_raw().unwrap());
|
||||
|
||||
hal_texture_callback(hal_texture);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum TextureErrorDimension {
|
||||
X,
|
||||
|
||||
@@ -268,6 +268,15 @@ pub struct Texture {
|
||||
raw_flags: vk::ImageCreateFlags,
|
||||
}
|
||||
|
||||
impl Texture {
|
||||
/// # Safety
|
||||
///
|
||||
/// - The image handle must not be manually destroyed
|
||||
pub unsafe fn raw_handle(&self) -> vk::Image {
|
||||
self.raw
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct TextureView {
|
||||
raw: vk::ImageView,
|
||||
|
||||
@@ -118,6 +118,15 @@ impl Context {
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn texture_as_hal<A: wgc::hub::HalApi, F: FnOnce(Option<&A::Texture>)>(
|
||||
&self,
|
||||
texture: &Texture,
|
||||
hal_texture_callback: F,
|
||||
) {
|
||||
self.0
|
||||
.texture_as_hal::<A, F>(texture.id, hal_texture_callback)
|
||||
}
|
||||
|
||||
pub fn generate_report(&self) -> wgc::hub::GlobalReport {
|
||||
self.0.generate_report()
|
||||
}
|
||||
|
||||
@@ -2075,6 +2075,21 @@ impl Drop for Buffer {
|
||||
}
|
||||
|
||||
impl Texture {
|
||||
/// Returns the inner hal Texture using a callback. The hal texture will be `None` if the
|
||||
/// backend type argument does not match with this wgpu Texture
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// - The raw handle obtained from the hal Texture must not be manually destroyed
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub unsafe fn as_hal<A: wgc::hub::HalApi>(
|
||||
&self,
|
||||
hal_texture_callback: impl FnOnce(Option<&A::Texture>),
|
||||
) {
|
||||
self.context
|
||||
.texture_as_hal::<A, _>(&self.id, hal_texture_callback)
|
||||
}
|
||||
|
||||
/// Creates a view of this texture.
|
||||
pub fn create_view(&self, desc: &TextureViewDescriptor) -> TextureView {
|
||||
TextureView {
|
||||
|
||||
Reference in New Issue
Block a user