Skip to content

Commit

Permalink
[WIP] vange-rs test
Browse files Browse the repository at this point in the history
  • Loading branch information
caiiiycuk committed Jan 26, 2022
1 parent 1beff75 commit 4d47ad6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
3 changes: 3 additions & 0 deletions wgpu-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,8 @@ hal = { path = "../wgpu-hal", package = "wgpu-hal", version = "0.12", features =
[target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies]
hal = { path = "../wgpu-hal", package = "wgpu-hal", version = "0.12", features = ["vulkan", "dx12", "renderdoc"] }

[target.'cfg(target_os = "emscripten")'.dependencies]
hal = { path = "../wgpu-hal", package = "wgpu-hal", version = "0.12", features = ["emscripten"] }

[build-dependencies]
cfg_aliases = "0.1"
2 changes: 1 addition & 1 deletion wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ package = "wgpu-types"
path = "../wgpu-types"
version = "0.12"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies.hal]
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies.hal]
package = "wgpu-hal"
path = "../wgpu-hal"
version = "0.12"
Expand Down
20 changes: 10 additions & 10 deletions wgpu/src/backend/direct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl fmt::Debug for Context {
}

impl Context {
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn from_hal_instance<A: wgc::hub::HalApi>(hal_instance: A::Instance) -> Self {
Self(wgc::hub::Global::from_hal_instance::<A>(
"wgpu",
Expand All @@ -51,23 +51,23 @@ impl Context {
&self.0
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub fn enumerate_adapters(&self, backends: wgt::Backends) -> Vec<wgc::id::AdapterId> {
self.0
.enumerate_adapters(wgc::instance::AdapterInputs::Mask(backends, |_| {
PhantomData
}))
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn create_adapter_from_hal<A: wgc::hub::HalApi>(
&self,
hal_adapter: hal::ExposedAdapter<A>,
) -> wgc::id::AdapterId {
self.0.create_adapter_from_hal(hal_adapter, PhantomData)
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn create_device_from_hal<A: wgc::hub::HalApi>(
&self,
adapter: &wgc::id::AdapterId,
Expand All @@ -94,7 +94,7 @@ impl Context {
Ok((device, device_id))
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn create_texture_from_hal<A: wgc::hub::HalApi>(
&self,
hal_texture: A::Texture,
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Context {
}
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn device_as_hal<A: wgc::hub::HalApi, F: FnOnce(Option<&A::Device>) -> R, R>(
&self,
device: &Device,
Expand All @@ -133,7 +133,7 @@ impl Context {
.device_as_hal::<A, F, R>(device.id, hal_device_callback)
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn texture_as_hal<A: wgc::hub::HalApi, F: FnOnce(Option<&A::Texture>)>(
&self,
texture: &Texture,
Expand All @@ -143,7 +143,7 @@ impl Context {
.texture_as_hal::<A, F>(texture.id, hal_texture_callback)
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub fn generate_report(&self) -> wgc::hub::GlobalReport {
self.0.generate_report()
}
Expand Down Expand Up @@ -1528,7 +1528,7 @@ impl crate::Context for Context {

#[cfg_attr(target_arch = "wasm32", allow(unused))]
fn device_drop(&self, device: &Self::DeviceId) {
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
{
let global = &self.0;
match wgc::gfx_select!(device.id => global.device_poll(device.id, true)) {
Expand All @@ -1537,7 +1537,7 @@ impl crate::Context for Context {
}
}
//TODO: make this work in general
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
#[cfg(feature = "metal-auto-capture")]
{
let global = &self.0;
Expand Down
16 changes: 8 additions & 8 deletions wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,7 @@ impl Instance {
/// # Safety
///
/// Refer to the creation of wgpu-hal Instance for every backend.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn from_hal<A: wgc::hub::HalApi>(hal_instance: A::Instance) -> Self {
Self {
context: Arc::new(C::from_hal_instance::<A>(hal_instance)),
Expand All @@ -1443,7 +1443,7 @@ impl Instance {
/// # Arguments
///
/// - `backends` - Backends from which to enumerate adapters.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub fn enumerate_adapters(&self, backends: Backends) -> impl Iterator<Item = Adapter> {
let context = Arc::clone(&self.context);
self.context
Expand Down Expand Up @@ -1474,7 +1474,7 @@ impl Instance {
/// # Safety
///
/// `hal_adapter` must be created from this instance internal handle.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn create_adapter_from_hal<A: wgc::hub::HalApi>(
&self,
hal_adapter: hal::ExposedAdapter<A>,
Expand Down Expand Up @@ -1555,7 +1555,7 @@ impl Instance {
}

/// Generates memory report.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub fn generate_report(&self) -> wgc::hub::GlobalReport {
self.context.generate_report()
}
Expand Down Expand Up @@ -1607,7 +1607,7 @@ impl Adapter {
///
/// - `hal_device` must be created from this adapter internal handle.
/// - `desc.features` must be a subset of `hal_device` features.
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn create_device_from_hal<A: wgc::hub::HalApi>(
&self,
hal_device: hal::OpenDevice<A>,
Expand Down Expand Up @@ -1846,7 +1846,7 @@ impl Device {
/// - `hal_texture` must be created from this device internal handle
/// - `hal_texture` must be created respecting `desc`
/// - `hal_texture` must be initialized
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn create_texture_from_hal<A: wgc::hub::HalApi>(
&self,
hal_texture: A::Texture,
Expand Down Expand Up @@ -1910,7 +1910,7 @@ impl Device {
/// # Safety
///
/// - The raw handle obtained from the hal Device must not be manually destroyed
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn as_hal<A: wgc::hub::HalApi, F: FnOnce(Option<&A::Device>) -> R, R>(
&self,
hal_device_callback: F,
Expand Down Expand Up @@ -2203,7 +2203,7 @@ impl Texture {
/// # Safety
///
/// - The raw handle obtained from the hal Texture must not be manually destroyed
#[cfg(not(target_arch = "wasm32"))]
#[cfg(any(not(target_arch = "wasm32"), feature = "emscripten"))]
pub unsafe fn as_hal<A: wgc::hub::HalApi, F: FnOnce(Option<&A::Texture>)>(
&self,
hal_texture_callback: F,
Expand Down

0 comments on commit 4d47ad6

Please sign in to comment.