Add cfg_aliases to wgpu-core and wgpu-hal (#5055)

This commit is contained in:
daxpedda 2024-01-14 06:59:59 +01:00 committed by GitHub
parent 552f06da2f
commit 580340f2d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 237 additions and 433 deletions

2
Cargo.lock generated
View File

@ -4001,6 +4001,7 @@ dependencies = [
"arrayvec 0.7.4", "arrayvec 0.7.4",
"bit-vec", "bit-vec",
"bitflags 2.4.1", "bitflags 2.4.1",
"cfg_aliases",
"codespan-reporting", "codespan-reporting",
"indexmap", "indexmap",
"log", "log",
@ -4063,6 +4064,7 @@ dependencies = [
"bitflags 2.4.1", "bitflags 2.4.1",
"block", "block",
"cfg-if", "cfg-if",
"cfg_aliases",
"core-graphics-types", "core-graphics-types",
"d3d12", "d3d12",
"env_logger", "env_logger",

View File

@ -128,3 +128,6 @@ web-sys = { version = "0.3.66", features = [
"HtmlCanvasElement", "HtmlCanvasElement",
"OffscreenCanvas", "OffscreenCanvas",
] } ] }
[build-dependencies]
cfg_aliases.workspace = true

13
wgpu-core/build.rs Normal file
View File

@ -0,0 +1,13 @@
fn main() {
cfg_aliases::cfg_aliases! {
send_sync: { any(
not(target_arch = "wasm32"),
all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics"))
) },
webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), gles) },
dx12: { all(target_os = "windows", feature = "dx12") },
gles: { all(feature = "gles") },
metal: { all(any(target_os = "ios", target_os = "macos"), feature = "metal") },
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") }
}
}

View File

@ -23,19 +23,19 @@ impl AnySurface {
} }
pub fn backend(&self) -> Backend { pub fn backend(&self) -> Backend {
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
if self.downcast_ref::<hal::api::Vulkan>().is_some() { if self.downcast_ref::<hal::api::Vulkan>().is_some() {
return Backend::Vulkan; return Backend::Vulkan;
} }
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
if self.downcast_ref::<hal::api::Metal>().is_some() { if self.downcast_ref::<hal::api::Metal>().is_some() {
return Backend::Metal; return Backend::Metal;
} }
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
if self.downcast_ref::<hal::api::Dx12>().is_some() { if self.downcast_ref::<hal::api::Dx12>().is_some() {
return Backend::Dx12; return Backend::Dx12;
} }
#[cfg(feature = "gles")] #[cfg(gles)]
if self.downcast_ref::<hal::api::Gles>().is_some() { if self.downcast_ref::<hal::api::Gles>().is_some() {
return Backend::Gl; return Backend::Gl;
} }
@ -90,19 +90,7 @@ impl fmt::Debug for AnySurface {
} }
} }
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl Send for AnySurface {} unsafe impl Send for AnySurface {}
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl Sync for AnySurface {} unsafe impl Sync for AnySurface {}

View File

@ -777,21 +777,9 @@ impl<A: HalApi> Drop for RenderBundle<A> {
} }
} }
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl<A: HalApi> Send for RenderBundle<A> {} unsafe impl<A: HalApi> Send for RenderBundle<A> {}
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl<A: HalApi> Sync for RenderBundle<A> {} unsafe impl<A: HalApi> Sync for RenderBundle<A> {}
impl<A: HalApi> RenderBundle<A> { impl<A: HalApi> RenderBundle<A> {

View File

@ -70,19 +70,7 @@ impl fmt::Debug for AnyDevice {
} }
} }
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl Send for AnyDevice {} unsafe impl Send for AnyDevice {}
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl Sync for AnyDevice {} unsafe impl Sync for AnyDevice {}

View File

@ -2164,22 +2164,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut closures = UserClosures::default(); let mut closures = UserClosures::default();
let mut all_queue_empty = true; let mut all_queue_empty = true;
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
{ {
all_queue_empty = all_queue_empty =
self.poll_device::<hal::api::Vulkan>(force_wait, &mut closures)? && all_queue_empty; self.poll_device::<hal::api::Vulkan>(force_wait, &mut closures)? && all_queue_empty;
} }
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
{ {
all_queue_empty = all_queue_empty =
self.poll_device::<hal::api::Metal>(force_wait, &mut closures)? && all_queue_empty; self.poll_device::<hal::api::Metal>(force_wait, &mut closures)? && all_queue_empty;
} }
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
{ {
all_queue_empty = all_queue_empty =
self.poll_device::<hal::api::Dx12>(force_wait, &mut closures)? && all_queue_empty; self.poll_device::<hal::api::Dx12>(force_wait, &mut closures)? && all_queue_empty;
} }
#[cfg(feature = "gles")] #[cfg(gles)]
{ {
all_queue_empty = all_queue_empty =
self.poll_device::<hal::api::Gles>(force_wait, &mut closures)? && all_queue_empty; self.poll_device::<hal::api::Gles>(force_wait, &mut closures)? && all_queue_empty;

View File

@ -205,21 +205,9 @@ impl UserClosures {
} }
} }
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
pub type DeviceLostCallback = Box<dyn Fn(DeviceLostReason, String) + Send + 'static>; pub type DeviceLostCallback = Box<dyn Fn(DeviceLostReason, String) + Send + 'static>;
#[cfg(not(any( #[cfg(not(send_sync))]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
)))]
pub type DeviceLostCallback = Box<dyn Fn(DeviceLostReason, String) + 'static>; pub type DeviceLostCallback = Box<dyn Fn(DeviceLostReason, String) + 'static>;
pub struct DeviceLostClosureRust { pub struct DeviceLostClosureRust {
@ -242,13 +230,7 @@ pub struct DeviceLostClosureC {
called: bool, called: bool,
} }
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl Send for DeviceLostClosureC {} unsafe impl Send for DeviceLostClosureC {}
impl Drop for DeviceLostClosureC { impl Drop for DeviceLostClosureC {

View File

@ -71,13 +71,7 @@ pub struct SubmittedWorkDoneClosureC {
pub user_data: *mut u8, pub user_data: *mut u8,
} }
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl Send for SubmittedWorkDoneClosureC {} unsafe impl Send for SubmittedWorkDoneClosureC {}
pub struct SubmittedWorkDoneClosure { pub struct SubmittedWorkDoneClosure {
@ -86,21 +80,9 @@ pub struct SubmittedWorkDoneClosure {
inner: SubmittedWorkDoneClosureInner, inner: SubmittedWorkDoneClosureInner,
} }
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
type SubmittedWorkDoneCallback = Box<dyn FnOnce() + Send + 'static>; type SubmittedWorkDoneCallback = Box<dyn FnOnce() + Send + 'static>;
#[cfg(not(any( #[cfg(not(send_sync))]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
)))]
type SubmittedWorkDoneCallback = Box<dyn FnOnce() + 'static>; type SubmittedWorkDoneCallback = Box<dyn FnOnce() + 'static>;
enum SubmittedWorkDoneClosureInner { enum SubmittedWorkDoneClosureInner {
@ -911,7 +893,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
Ok(()) Ok(())
} }
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
pub fn queue_copy_external_image_to_texture<A: HalApi>( pub fn queue_copy_external_image_to_texture<A: HalApi>(
&self, &self,
queue_id: QueueId, queue_id: QueueId,

View File

@ -162,21 +162,9 @@ pub fn format_pretty_any(
#[derive(Debug)] #[derive(Debug)]
pub struct ContextError { pub struct ContextError {
pub string: &'static str, pub string: &'static str,
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
pub cause: Box<dyn Error + Send + Sync + 'static>, pub cause: Box<dyn Error + Send + Sync + 'static>,
#[cfg(not(any( #[cfg(not(send_sync))]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
)))]
pub cause: Box<dyn Error + 'static>, pub cause: Box<dyn Error + 'static>,
pub label_key: &'static str, pub label_key: &'static str,
pub label: String, pub label: String,

View File

@ -16,13 +16,13 @@ use crate::{
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct GlobalReport { pub struct GlobalReport {
pub surfaces: RegistryReport, pub surfaces: RegistryReport,
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
pub vulkan: Option<HubReport>, pub vulkan: Option<HubReport>,
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
pub metal: Option<HubReport>, pub metal: Option<HubReport>,
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
pub dx12: Option<HubReport>, pub dx12: Option<HubReport>,
#[cfg(feature = "gles")] #[cfg(gles)]
pub gl: Option<HubReport>, pub gl: Option<HubReport>,
} }
@ -32,13 +32,13 @@ impl GlobalReport {
} }
pub fn hub_report(&self, backend: Backend) -> &HubReport { pub fn hub_report(&self, backend: Backend) -> &HubReport {
match backend { match backend {
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
Backend::Vulkan => self.vulkan.as_ref().unwrap(), Backend::Vulkan => self.vulkan.as_ref().unwrap(),
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
Backend::Metal => self.metal.as_ref().unwrap(), Backend::Metal => self.metal.as_ref().unwrap(),
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
Backend::Dx12 => self.dx12.as_ref().unwrap(), Backend::Dx12 => self.dx12.as_ref().unwrap(),
#[cfg(feature = "gles")] #[cfg(gles)]
Backend::Gl => self.gl.as_ref().unwrap(), Backend::Gl => self.gl.as_ref().unwrap(),
_ => panic!("HubReport is not supported on this backend"), _ => panic!("HubReport is not supported on this backend"),
} }
@ -110,25 +110,25 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
pub fn generate_report(&self) -> GlobalReport { pub fn generate_report(&self) -> GlobalReport {
GlobalReport { GlobalReport {
surfaces: self.surfaces.generate_report(), surfaces: self.surfaces.generate_report(),
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
vulkan: if self.instance.vulkan.is_some() { vulkan: if self.instance.vulkan.is_some() {
Some(self.hubs.vulkan.generate_report()) Some(self.hubs.vulkan.generate_report())
} else { } else {
None None
}, },
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
metal: if self.instance.metal.is_some() { metal: if self.instance.metal.is_some() {
Some(self.hubs.metal.generate_report()) Some(self.hubs.metal.generate_report())
} else { } else {
None None
}, },
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
dx12: if self.instance.dx12.is_some() { dx12: if self.instance.dx12.is_some() {
Some(self.hubs.dx12.generate_report()) Some(self.hubs.dx12.generate_report())
} else { } else {
None None
}, },
#[cfg(feature = "gles")] #[cfg(gles)]
gl: if self.instance.gl.is_some() { gl: if self.instance.gl.is_some() {
Some(self.hubs.gl.generate_report()) Some(self.hubs.gl.generate_report())
} else { } else {
@ -145,19 +145,19 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
let mut surfaces_locked = self.surfaces.write(); let mut surfaces_locked = self.surfaces.write();
// destroy hubs before the instance gets dropped // destroy hubs before the instance gets dropped
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
{ {
self.hubs.vulkan.clear(&surfaces_locked, true); self.hubs.vulkan.clear(&surfaces_locked, true);
} }
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
{ {
self.hubs.metal.clear(&surfaces_locked, true); self.hubs.metal.clear(&surfaces_locked, true);
} }
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
{ {
self.hubs.dx12.clear(&surfaces_locked, true); self.hubs.dx12.clear(&surfaces_locked, true);
} }
#[cfg(feature = "gles")] #[cfg(gles)]
{ {
self.hubs.gl.clear(&surfaces_locked, true); self.hubs.gl.clear(&surfaces_locked, true);
} }
@ -175,16 +175,7 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
} }
} }
#[cfg(all( #[cfg(send_sync)]
test,
any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
)
))]
fn _test_send_sync(global: &Global<crate::identity::IdentityManagerFactory>) { fn _test_send_sync(global: &Global<crate::identity::IdentityManagerFactory>) {
fn test_internal<T: Send + Sync>(_: T) {} fn test_internal<T: Send + Sync>(_: T) {}
test_internal(global) test_internal(global)

View File

@ -31,7 +31,7 @@ impl HalApi for hal::api::Empty {
} }
} }
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
impl HalApi for hal::api::Vulkan { impl HalApi for hal::api::Vulkan {
const VARIANT: Backend = Backend::Vulkan; const VARIANT: Backend = Backend::Vulkan;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance { fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
@ -52,7 +52,7 @@ impl HalApi for hal::api::Vulkan {
} }
} }
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
impl HalApi for hal::api::Metal { impl HalApi for hal::api::Metal {
const VARIANT: Backend = Backend::Metal; const VARIANT: Backend = Backend::Metal;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance { fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
@ -73,7 +73,7 @@ impl HalApi for hal::api::Metal {
} }
} }
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
impl HalApi for hal::api::Dx12 { impl HalApi for hal::api::Dx12 {
const VARIANT: Backend = Backend::Dx12; const VARIANT: Backend = Backend::Dx12;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance { fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
@ -94,7 +94,7 @@ impl HalApi for hal::api::Dx12 {
} }
} }
#[cfg(feature = "gles")] #[cfg(gles)]
impl HalApi for hal::api::Gles { impl HalApi for hal::api::Gles {
const VARIANT: Backend = Backend::Gl; const VARIANT: Backend = Backend::Gl;
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance { fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {

View File

@ -302,40 +302,30 @@ impl<A: HalApi> Hub<A> {
} }
pub struct Hubs { pub struct Hubs {
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
pub(crate) vulkan: Hub<hal::api::Vulkan>, pub(crate) vulkan: Hub<hal::api::Vulkan>,
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
pub(crate) metal: Hub<hal::api::Metal>, pub(crate) metal: Hub<hal::api::Metal>,
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
pub(crate) dx12: Hub<hal::api::Dx12>, pub(crate) dx12: Hub<hal::api::Dx12>,
#[cfg(feature = "gles")] #[cfg(gles)]
pub(crate) gl: Hub<hal::api::Gles>, pub(crate) gl: Hub<hal::api::Gles>,
#[cfg(all( #[cfg(all(not(vulkan), not(metal), not(dx12), not(gles)))]
not(all(feature = "vulkan", not(target_arch = "wasm32"))),
not(all(feature = "metal", any(target_os = "macos", target_os = "ios"))),
not(all(feature = "dx12", windows)),
not(feature = "gles"),
))]
pub(crate) empty: Hub<hal::api::Empty>, pub(crate) empty: Hub<hal::api::Empty>,
} }
impl Hubs { impl Hubs {
pub(crate) fn new<F: GlobalIdentityHandlerFactory>(factory: &F) -> Self { pub(crate) fn new<F: GlobalIdentityHandlerFactory>(factory: &F) -> Self {
Self { Self {
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
vulkan: Hub::new(factory), vulkan: Hub::new(factory),
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
metal: Hub::new(factory), metal: Hub::new(factory),
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
dx12: Hub::new(factory), dx12: Hub::new(factory),
#[cfg(feature = "gles")] #[cfg(gles)]
gl: Hub::new(factory), gl: Hub::new(factory),
#[cfg(all( #[cfg(all(not(vulkan), not(metal), not(dx12), not(gles)))]
not(all(feature = "vulkan", not(target_arch = "wasm32"))),
not(all(feature = "metal", any(target_os = "macos", target_os = "ios"))),
not(all(feature = "dx12", windows)),
not(feature = "gles"),
))]
empty: Hub::new(factory), empty: Hub::new(factory),
} }
} }

View File

@ -62,13 +62,13 @@ fn downlevel_default_limits_less_than_default_limits() {
pub struct Instance { pub struct Instance {
#[allow(dead_code)] #[allow(dead_code)]
pub name: String, pub name: String,
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
pub vulkan: Option<HalInstance<hal::api::Vulkan>>, pub vulkan: Option<HalInstance<hal::api::Vulkan>>,
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
pub metal: Option<HalInstance<hal::api::Metal>>, pub metal: Option<HalInstance<hal::api::Metal>>,
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
pub dx12: Option<HalInstance<hal::api::Dx12>>, pub dx12: Option<HalInstance<hal::api::Dx12>>,
#[cfg(feature = "gles")] #[cfg(gles)]
pub gl: Option<HalInstance<hal::api::Gles>>, pub gl: Option<HalInstance<hal::api::Gles>>,
pub flags: wgt::InstanceFlags, pub flags: wgt::InstanceFlags,
} }
@ -105,13 +105,13 @@ impl Instance {
Self { Self {
name: name.to_string(), name: name.to_string(),
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
vulkan: init(hal::api::Vulkan, &instance_desc), vulkan: init(hal::api::Vulkan, &instance_desc),
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
metal: init(hal::api::Metal, &instance_desc), metal: init(hal::api::Metal, &instance_desc),
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
dx12: init(hal::api::Dx12, &instance_desc), dx12: init(hal::api::Dx12, &instance_desc),
#[cfg(feature = "gles")] #[cfg(gles)]
gl: init(hal::api::Gles, &instance_desc), gl: init(hal::api::Gles, &instance_desc),
flags: instance_desc.flags, flags: instance_desc.flags,
} }
@ -134,13 +134,13 @@ impl Instance {
} }
} }
match surface.raw.backend() { match surface.raw.backend() {
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
Backend::Vulkan => destroy(hal::api::Vulkan, &self.vulkan, surface.raw), Backend::Vulkan => destroy(hal::api::Vulkan, &self.vulkan, surface.raw),
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
Backend::Metal => destroy(hal::api::Metal, &self.metal, surface.raw), Backend::Metal => destroy(hal::api::Metal, &self.metal, surface.raw),
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
Backend::Dx12 => destroy(hal::api::Dx12, &self.dx12, surface.raw), Backend::Dx12 => destroy(hal::api::Dx12, &self.dx12, surface.raw),
#[cfg(feature = "gles")] #[cfg(gles)]
Backend::Gl => destroy(hal::api::Gles, &self.gl, surface.raw), Backend::Gl => destroy(hal::api::Gles, &self.gl, surface.raw),
_ => unreachable!(), _ => unreachable!(),
} }
@ -497,22 +497,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut hal_surface: Option<Result<AnySurface, hal::InstanceError>> = None; let mut hal_surface: Option<Result<AnySurface, hal::InstanceError>> = None;
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
if hal_surface.is_none() { if hal_surface.is_none() {
hal_surface = hal_surface =
init::<hal::api::Vulkan>(&self.instance.vulkan, display_handle, window_handle); init::<hal::api::Vulkan>(&self.instance.vulkan, display_handle, window_handle);
} }
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
if hal_surface.is_none() { if hal_surface.is_none() {
hal_surface = hal_surface =
init::<hal::api::Metal>(&self.instance.metal, display_handle, window_handle); init::<hal::api::Metal>(&self.instance.metal, display_handle, window_handle);
} }
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
if hal_surface.is_none() { if hal_surface.is_none() {
hal_surface = hal_surface =
init::<hal::api::Dx12>(&self.instance.dx12, display_handle, window_handle); init::<hal::api::Dx12>(&self.instance.dx12, display_handle, window_handle);
} }
#[cfg(feature = "gles")] #[cfg(gles)]
if hal_surface.is_none() { if hal_surface.is_none() {
hal_surface = init::<hal::api::Gles>(&self.instance.gl, display_handle, window_handle); hal_surface = init::<hal::api::Gles>(&self.instance.gl, display_handle, window_handle);
} }
@ -533,7 +533,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
/// # Safety /// # Safety
/// ///
/// `layer` must be a valid pointer. /// `layer` must be a valid pointer.
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
pub unsafe fn instance_create_surface_metal( pub unsafe fn instance_create_surface_metal(
&self, &self,
layer: *mut std::ffi::c_void, layer: *mut std::ffi::c_void,
@ -565,7 +565,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
id id
} }
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
/// # Safety /// # Safety
/// ///
/// The visual must be valid and able to be used to make a swapchain with. /// The visual must be valid and able to be used to make a swapchain with.
@ -596,7 +596,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
id id
} }
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
/// # Safety /// # Safety
/// ///
/// The surface_handle must be valid and able to be used to make a swapchain with. /// The surface_handle must be valid and able to be used to make a swapchain with.
@ -629,7 +629,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
id id
} }
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
/// # Safety /// # Safety
/// ///
/// The swap_chain_panel must be valid and able to be used to make a swapchain with. /// The swap_chain_panel must be valid and able to be used to make a swapchain with.
@ -683,13 +683,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let surface = self.surfaces.unregister(id); let surface = self.surfaces.unregister(id);
if let Some(surface) = Arc::into_inner(surface.unwrap()) { if let Some(surface) = Arc::into_inner(surface.unwrap()) {
if let Some(present) = surface.presentation.lock().take() { if let Some(present) = surface.presentation.lock().take() {
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
unconfigure::<_, hal::api::Vulkan>(self, &surface.raw, &present); unconfigure::<_, hal::api::Vulkan>(self, &surface.raw, &present);
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
unconfigure::<_, hal::api::Metal>(self, &surface.raw, &present); unconfigure::<_, hal::api::Metal>(self, &surface.raw, &present);
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
unconfigure::<_, hal::api::Dx12>(self, &surface.raw, &present); unconfigure::<_, hal::api::Dx12>(self, &surface.raw, &present);
#[cfg(feature = "gles")] #[cfg(gles)]
unconfigure::<_, hal::api::Gles>(self, &surface.raw, &present); unconfigure::<_, hal::api::Gles>(self, &surface.raw, &present);
} }
@ -733,23 +733,23 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut adapters = Vec::new(); let mut adapters = Vec::new();
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
self.enumerate( self.enumerate(
hal::api::Vulkan, hal::api::Vulkan,
&self.instance.vulkan, &self.instance.vulkan,
&inputs, &inputs,
&mut adapters, &mut adapters,
); );
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
self.enumerate( self.enumerate(
hal::api::Metal, hal::api::Metal,
&self.instance.metal, &self.instance.metal,
&inputs, &inputs,
&mut adapters, &mut adapters,
); );
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
self.enumerate(hal::api::Dx12, &self.instance.dx12, &inputs, &mut adapters); self.enumerate(hal::api::Dx12, &self.instance.dx12, &inputs, &mut adapters);
#[cfg(feature = "gles")] #[cfg(gles)]
self.enumerate(hal::api::Gles, &self.instance.gl, &inputs, &mut adapters); self.enumerate(hal::api::Gles, &self.instance.gl, &inputs, &mut adapters);
adapters adapters
@ -831,7 +831,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let compatible_surface = compatible_surface.as_ref().map(|surface| surface.as_ref()); let compatible_surface = compatible_surface.as_ref().map(|surface| surface.as_ref());
let mut device_types = Vec::new(); let mut device_types = Vec::new();
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
let (id_vulkan, adapters_vk) = gather( let (id_vulkan, adapters_vk) = gather(
hal::api::Vulkan, hal::api::Vulkan,
self.instance.vulkan.as_ref(), self.instance.vulkan.as_ref(),
@ -840,7 +840,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc.force_fallback_adapter, desc.force_fallback_adapter,
&mut device_types, &mut device_types,
); );
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
let (id_metal, adapters_metal) = gather( let (id_metal, adapters_metal) = gather(
hal::api::Metal, hal::api::Metal,
self.instance.metal.as_ref(), self.instance.metal.as_ref(),
@ -849,7 +849,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc.force_fallback_adapter, desc.force_fallback_adapter,
&mut device_types, &mut device_types,
); );
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
let (id_dx12, adapters_dx12) = gather( let (id_dx12, adapters_dx12) = gather(
hal::api::Dx12, hal::api::Dx12,
self.instance.dx12.as_ref(), self.instance.dx12.as_ref(),
@ -858,7 +858,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc.force_fallback_adapter, desc.force_fallback_adapter,
&mut device_types, &mut device_types,
); );
#[cfg(feature = "gles")] #[cfg(gles)]
let (id_gl, adapters_gl) = gather( let (id_gl, adapters_gl) = gather(
hal::api::Gles, hal::api::Gles,
self.instance.gl.as_ref(), self.instance.gl.as_ref(),
@ -919,19 +919,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}; };
let mut selected = preferred_gpu.unwrap_or(0); let mut selected = preferred_gpu.unwrap_or(0);
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
if let Some(id) = self.select(&mut selected, id_vulkan, adapters_vk) { if let Some(id) = self.select(&mut selected, id_vulkan, adapters_vk) {
return Ok(id); return Ok(id);
} }
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
if let Some(id) = self.select(&mut selected, id_metal, adapters_metal) { if let Some(id) = self.select(&mut selected, id_metal, adapters_metal) {
return Ok(id); return Ok(id);
} }
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
if let Some(id) = self.select(&mut selected, id_dx12, adapters_dx12) { if let Some(id) = self.select(&mut selected, id_dx12, adapters_dx12) {
return Ok(id); return Ok(id);
} }
#[cfg(feature = "gles")] #[cfg(gles)]
if let Some(id) = self.select(&mut selected, id_gl, adapters_gl) { if let Some(id) = self.select(&mut selected, id_gl, adapters_gl) {
return Ok(id); return Ok(id);
} }
@ -955,13 +955,13 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let (id, _adapter): (crate::id::Id<Adapter<hal::empty::Api>>, Arc<Adapter<A>>) = let (id, _adapter): (crate::id::Id<Adapter<hal::empty::Api>>, Arc<Adapter<A>>) =
match A::VARIANT { match A::VARIANT {
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
Backend::Vulkan => fid.assign(Adapter::new(hal_adapter)), Backend::Vulkan => fid.assign(Adapter::new(hal_adapter)),
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
Backend::Metal => fid.assign(Adapter::new(hal_adapter)), Backend::Metal => fid.assign(Adapter::new(hal_adapter)),
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
Backend::Dx12 => fid.assign(Adapter::new(hal_adapter)), Backend::Dx12 => fid.assign(Adapter::new(hal_adapter)),
#[cfg(feature = "gles")] #[cfg(gles)]
Backend::Gl => fid.assign(Adapter::new(hal_adapter)), Backend::Gl => fid.assign(Adapter::new(hal_adapter)),
_ => unreachable!(), _ => unreachable!(),
}; };

View File

@ -203,21 +203,9 @@ pub(crate) enum BufferMapState<A: HalApi> {
Idle, Idle,
} }
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl<A: HalApi> Send for BufferMapState<A> {} unsafe impl<A: HalApi> Send for BufferMapState<A> {}
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl<A: HalApi> Sync for BufferMapState<A> {} unsafe impl<A: HalApi> Sync for BufferMapState<A> {}
#[repr(C)] #[repr(C)]
@ -226,13 +214,7 @@ pub struct BufferMapCallbackC {
pub user_data: *mut u8, pub user_data: *mut u8,
} }
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
unsafe impl Send for BufferMapCallbackC {} unsafe impl Send for BufferMapCallbackC {}
#[derive(Debug)] #[derive(Debug)]
@ -242,21 +224,9 @@ pub struct BufferMapCallback {
inner: BufferMapCallbackInner, inner: BufferMapCallbackInner,
} }
#[cfg(any( #[cfg(send_sync)]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
type BufferMapCallbackCallback = Box<dyn FnOnce(BufferAccessResult) + Send + 'static>; type BufferMapCallbackCallback = Box<dyn FnOnce(BufferAccessResult) + Send + 'static>;
#[cfg(not(any( #[cfg(not(send_sync))]
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
)))]
type BufferMapCallbackCallback = Box<dyn FnOnce(BufferAccessResult) + 'static>; type BufferMapCallbackCallback = Box<dyn FnOnce(BufferAccessResult) + 'static>;
enum BufferMapCallbackInner { enum BufferMapCallbackInner {

View File

@ -160,6 +160,9 @@ path = "../naga"
version = "0.14.0" version = "0.14.0"
features = ["clone"] features = ["clone"]
[build-dependencies]
cfg_aliases.workspace = true
# DEV dependencies # DEV dependencies
[dev-dependencies.naga] [dev-dependencies.naga]
path = "../naga" path = "../naga"

15
wgpu-hal/build.rs Normal file
View File

@ -0,0 +1,15 @@
fn main() {
cfg_aliases::cfg_aliases! {
native: { not(target_arch = "wasm32") },
send_sync: { any(
not(target_arch = "wasm32"),
all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics"))
) },
webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), gles) },
Emscripten: { all(target_os = "emscripten", gles) },
dx12: { all(target_os = "windows", feature = "dx12") },
gles: { all(feature = "gles") },
metal: { all(any(target_os = "ios", target_os = "macos"), feature = "metal") },
vulkan: { all(not(target_arch = "wasm32"), feature = "vulkan") }
}
}

View File

@ -7,8 +7,6 @@ use super::result::HResult as _;
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] #[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum DxgiFactoryType { pub enum DxgiFactoryType {
#[cfg(feature = "dx11")]
Factory1,
Factory2, Factory2,
Factory4, Factory4,
Factory6, Factory6,

View File

@ -1,7 +1,7 @@
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
pub(super) mod dxgi; pub(super) mod dxgi;
#[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))] #[cfg(all(native, feature = "renderdoc"))]
pub(super) mod renderdoc; pub(super) mod renderdoc;
pub mod db { pub mod db {

View File

@ -284,7 +284,7 @@ impl crate::CommandEncoder<Api> for Encoder {
unsafe fn copy_buffer_to_buffer<T>(&mut self, src: &Resource, dst: &Resource, regions: T) {} unsafe fn copy_buffer_to_buffer<T>(&mut self, src: &Resource, dst: &Resource, regions: T) {}
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
unsafe fn copy_external_image_to_texture<T>( unsafe fn copy_external_image_to_texture<T>(
&mut self, &mut self,
src: &wgt::ImageCopyExternalImage, src: &wgt::ImageCopyExternalImage,

View File

@ -198,14 +198,14 @@ impl super::Adapter {
let (vendor_const, renderer_const) = if extensions.contains("WEBGL_debug_renderer_info") { let (vendor_const, renderer_const) = if extensions.contains("WEBGL_debug_renderer_info") {
// emscripten doesn't enable "WEBGL_debug_renderer_info" extension by default. so, we do it manually. // emscripten doesn't enable "WEBGL_debug_renderer_info" extension by default. so, we do it manually.
// See https://github.com/gfx-rs/wgpu/issues/3245 for context // See https://github.com/gfx-rs/wgpu/issues/3245 for context
#[cfg(target_os = "emscripten")] #[cfg(Emscripten)]
if unsafe { super::emscripten::enable_extension("WEBGL_debug_renderer_info\0") } { if unsafe { super::emscripten::enable_extension("WEBGL_debug_renderer_info\0") } {
(GL_UNMASKED_VENDOR_WEBGL, GL_UNMASKED_RENDERER_WEBGL) (GL_UNMASKED_VENDOR_WEBGL, GL_UNMASKED_RENDERER_WEBGL)
} else { } else {
(glow::VENDOR, glow::RENDERER) (glow::VENDOR, glow::RENDERER)
} }
// glow already enables WEBGL_debug_renderer_info on wasm32-unknown-unknown target by default. // glow already enables WEBGL_debug_renderer_info on wasm32-unknown-unknown target by default.
#[cfg(not(target_os = "emscripten"))] #[cfg(not(Emscripten))]
(GL_UNMASKED_VENDOR_WEBGL, GL_UNMASKED_RENDERER_WEBGL) (GL_UNMASKED_VENDOR_WEBGL, GL_UNMASKED_RENDERER_WEBGL)
} else { } else {
(glow::VENDOR, glow::RENDERER) (glow::VENDOR, glow::RENDERER)
@ -282,7 +282,7 @@ impl super::Adapter {
let value = sl_major as u16 * 100 + sl_minor as u16 * 10; let value = sl_major as u16 * 100 + sl_minor as u16 * 10;
naga::back::glsl::Version::Embedded { naga::back::glsl::Version::Embedded {
version: value, version: value,
is_webgl: cfg!(target_arch = "wasm32"), is_webgl: cfg!(any(webgl, Emscripten)),
} }
} }
}; };
@ -407,16 +407,16 @@ impl super::Adapter {
} }
downlevel_flags.set( downlevel_flags.set(
wgt::DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED, wgt::DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED,
!(cfg!(target_arch = "wasm32") || is_angle), !(cfg!(any(webgl, Emscripten)) || is_angle),
); );
// see https://registry.khronos.org/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING // see https://registry.khronos.org/webgl/specs/latest/2.0/#BUFFER_OBJECT_BINDING
downlevel_flags.set( downlevel_flags.set(
wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER, wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER,
!cfg!(target_arch = "wasm32"), !cfg!(any(webgl, Emscripten)),
); );
downlevel_flags.set( downlevel_flags.set(
wgt::DownlevelFlags::UNRESTRICTED_EXTERNAL_TEXTURE_COPIES, wgt::DownlevelFlags::UNRESTRICTED_EXTERNAL_TEXTURE_COPIES,
!cfg!(target_arch = "wasm32"), !cfg!(any(webgl, Emscripten)),
); );
downlevel_flags.set( downlevel_flags.set(
wgt::DownlevelFlags::FULL_DRAW_INDEX_UINT32, wgt::DownlevelFlags::FULL_DRAW_INDEX_UINT32,
@ -490,7 +490,7 @@ impl super::Adapter {
"EXT_texture_compression_rgtc", "EXT_texture_compression_rgtc",
"EXT_texture_compression_bptc", "EXT_texture_compression_bptc",
]; ];
let bcn_exts = if cfg!(target_arch = "wasm32") { let bcn_exts = if cfg!(any(webgl, Emscripten)) {
&webgl_bcn_exts[..] &webgl_bcn_exts[..]
} else if es_ver.is_some() { } else if es_ver.is_some() {
&gles_bcn_exts[..] &gles_bcn_exts[..]
@ -501,7 +501,7 @@ impl super::Adapter {
wgt::Features::TEXTURE_COMPRESSION_BC, wgt::Features::TEXTURE_COMPRESSION_BC,
bcn_exts.iter().all(|&ext| extensions.contains(ext)), bcn_exts.iter().all(|&ext| extensions.contains(ext)),
); );
let has_etc = if cfg!(target_arch = "wasm32") { let has_etc = if cfg!(any(webgl, Emscripten)) {
extensions.contains("WEBGL_compressed_texture_etc") extensions.contains("WEBGL_compressed_texture_etc")
} else { } else {
// This is a required part of GLES3, but not part of Desktop GL at all. // This is a required part of GLES3, but not part of Desktop GL at all.
@ -513,7 +513,7 @@ impl super::Adapter {
if extensions.contains("WEBGL_compressed_texture_astc") if extensions.contains("WEBGL_compressed_texture_astc")
|| extensions.contains("GL_OES_texture_compression_astc") || extensions.contains("GL_OES_texture_compression_astc")
{ {
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
{ {
if context if context
.glow_context .glow_context
@ -529,7 +529,7 @@ impl super::Adapter {
} }
} }
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] #[cfg(any(native, Emscripten))]
{ {
features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC); features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC);
features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC_HDR); features.insert(wgt::Features::TEXTURE_COMPRESSION_ASTC_HDR);
@ -582,11 +582,11 @@ impl super::Adapter {
); );
private_caps.set( private_caps.set(
super::PrivateCapabilities::INDEX_BUFFER_ROLE_CHANGE, super::PrivateCapabilities::INDEX_BUFFER_ROLE_CHANGE,
!cfg!(target_arch = "wasm32"), !cfg!(any(webgl, Emscripten)),
); );
private_caps.set( private_caps.set(
super::PrivateCapabilities::GET_BUFFER_SUB_DATA, super::PrivateCapabilities::GET_BUFFER_SUB_DATA,
cfg!(target_arch = "wasm32") || full_ver.is_some(), cfg!(any(webgl, Emscripten)) || full_ver.is_some(),
); );
let color_buffer_float = extensions.contains("GL_EXT_color_buffer_float") let color_buffer_float = extensions.contains("GL_EXT_color_buffer_float")
|| extensions.contains("GL_ARB_color_buffer_float") || extensions.contains("GL_ARB_color_buffer_float")
@ -759,7 +759,7 @@ impl super::Adapter {
workarounds.set( workarounds.set(
super::Workarounds::EMULATE_BUFFER_MAP, super::Workarounds::EMULATE_BUFFER_MAP,
cfg!(target_arch = "wasm32"), cfg!(any(webgl, Emscripten)),
); );
let r = renderer.to_lowercase(); let r = renderer.to_lowercase();
@ -917,7 +917,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
device: super::Device { device: super::Device {
shared: Arc::clone(&self.shared), shared: Arc::clone(&self.shared),
main_vao, main_vao,
#[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))] #[cfg(all(native, feature = "renderdoc"))]
render_doc: Default::default(), render_doc: Default::default(),
}, },
queue: super::Queue { queue: super::Queue {
@ -1112,13 +1112,13 @@ impl crate::Adapter<super::Api> for super::Adapter {
if surface.presentable { if surface.presentable {
let mut formats = vec![ let mut formats = vec![
wgt::TextureFormat::Rgba8Unorm, wgt::TextureFormat::Rgba8Unorm,
#[cfg(not(target_arch = "wasm32"))] #[cfg(native)]
wgt::TextureFormat::Bgra8Unorm, wgt::TextureFormat::Bgra8Unorm,
]; ];
if surface.supports_srgb() { if surface.supports_srgb() {
formats.extend([ formats.extend([
wgt::TextureFormat::Rgba8UnormSrgb, wgt::TextureFormat::Rgba8UnormSrgb,
#[cfg(not(target_arch = "wasm32"))] #[cfg(native)]
wgt::TextureFormat::Bgra8UnormSrgb, wgt::TextureFormat::Bgra8UnormSrgb,
]) ])
} }
@ -1178,17 +1178,9 @@ impl super::AdapterShared {
} }
} }
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for super::Adapter {} unsafe impl Sync for super::Adapter {}
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for super::Adapter {} unsafe impl Send for super::Adapter {}
#[cfg(test)] #[cfg(test)]

View File

@ -349,7 +349,7 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
} }
} }
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
unsafe fn copy_external_image_to_texture<T>( unsafe fn copy_external_image_to_texture<T>(
&mut self, &mut self,
src: &wgt::ImageCopyExternalImage, src: &wgt::ImageCopyExternalImage,
@ -507,7 +507,7 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
.iter() .iter()
.filter_map(|at| at.as_ref()) .filter_map(|at| at.as_ref())
.any(|at| match at.target.view.inner { .any(|at| match at.target.view.inner {
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
super::TextureInner::ExternalFramebuffer { .. } => true, super::TextureInner::ExternalFramebuffer { .. } => true,
_ => false, _ => false,
}); });

View File

@ -9,7 +9,7 @@ use std::{
}; };
use arrayvec::ArrayVec; use arrayvec::ArrayVec;
#[cfg(not(target_arch = "wasm32"))] #[cfg(native)]
use std::mem; use std::mem;
use std::sync::atomic::Ordering; use std::sync::atomic::Ordering;
@ -115,7 +115,7 @@ impl super::Device {
/// - If `drop_guard` is [`None`], wgpu-hal will take ownership of the texture. If `drop_guard` is /// - If `drop_guard` is [`None`], wgpu-hal will take ownership of the texture. If `drop_guard` is
/// [`Some`], the texture must be valid until the drop implementation /// [`Some`], the texture must be valid until the drop implementation
/// of the drop guard is called. /// of the drop guard is called.
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] #[cfg(any(native, Emscripten))]
pub unsafe fn texture_from_raw( pub unsafe fn texture_from_raw(
&self, &self,
name: std::num::NonZeroU32, name: std::num::NonZeroU32,
@ -143,7 +143,7 @@ impl super::Device {
/// - If `drop_guard` is [`None`], wgpu-hal will take ownership of the renderbuffer. If `drop_guard` is /// - If `drop_guard` is [`None`], wgpu-hal will take ownership of the renderbuffer. If `drop_guard` is
/// [`Some`], the renderbuffer must be valid until the drop implementation /// [`Some`], the renderbuffer must be valid until the drop implementation
/// of the drop guard is called. /// of the drop guard is called.
#[cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))] #[cfg(any(native, Emscripten))]
pub unsafe fn texture_from_raw_renderbuffer( pub unsafe fn texture_from_raw_renderbuffer(
&self, &self,
name: std::num::NonZeroU32, name: std::num::NonZeroU32,
@ -176,7 +176,7 @@ impl super::Device {
}; };
let raw = unsafe { gl.create_shader(target) }.unwrap(); let raw = unsafe { gl.create_shader(target) }.unwrap();
#[cfg(not(target_arch = "wasm32"))] #[cfg(native)]
if gl.supports_debug() { if gl.supports_debug() {
//TODO: remove all transmutes from `object_label` //TODO: remove all transmutes from `object_label`
// https://github.com/grovesNL/glow/issues/186 // https://github.com/grovesNL/glow/issues/186
@ -342,7 +342,7 @@ impl super::Device {
naga::back::glsl::Version::Desktop(version) => format!("{version}"), naga::back::glsl::Version::Desktop(version) => format!("{version}"),
}; };
let program = unsafe { gl.create_program() }.unwrap(); let program = unsafe { gl.create_program() }.unwrap();
#[cfg(not(target_arch = "wasm32"))] #[cfg(native)]
if let Some(label) = label { if let Some(label) = label {
if private_caps.contains(PrivateCapabilities::DEBUG_FNS) { if private_caps.contains(PrivateCapabilities::DEBUG_FNS) {
let name = unsafe { mem::transmute(program) }; let name = unsafe { mem::transmute(program) };
@ -591,7 +591,7 @@ impl crate::Device<super::Api> for super::Device {
} }
//TODO: do we need `glow::MAP_UNSYNCHRONIZED_BIT`? //TODO: do we need `glow::MAP_UNSYNCHRONIZED_BIT`?
#[cfg(not(target_arch = "wasm32"))] #[cfg(native)]
if let Some(label) = desc.label { if let Some(label) = desc.label {
if self if self
.shared .shared
@ -734,7 +734,7 @@ impl crate::Device<super::Api> for super::Device {
}; };
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(native)]
if let Some(label) = desc.label { if let Some(label) = desc.label {
if self if self
.shared .shared
@ -902,7 +902,7 @@ impl crate::Device<super::Api> for super::Device {
}; };
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(native)]
if let Some(label) = desc.label { if let Some(label) = desc.label {
if self if self
.shared .shared
@ -939,7 +939,7 @@ impl crate::Device<super::Api> for super::Device {
super::TextureInner::Texture { raw, .. } => { super::TextureInner::Texture { raw, .. } => {
unsafe { gl.delete_texture(raw) }; unsafe { gl.delete_texture(raw) };
} }
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
super::TextureInner::ExternalFramebuffer { .. } => {} super::TextureInner::ExternalFramebuffer { .. } => {}
} }
} }
@ -1045,7 +1045,7 @@ impl crate::Device<super::Api> for super::Device {
}; };
} }
#[cfg(not(target_arch = "wasm32"))] #[cfg(native)]
if let Some(label) = desc.label { if let Some(label) = desc.label {
if self if self
.shared .shared
@ -1432,7 +1432,7 @@ impl crate::Device<super::Api> for super::Device {
) -> Result<bool, crate::DeviceError> { ) -> Result<bool, crate::DeviceError> {
if fence.last_completed < wait_value { if fence.last_completed < wait_value {
let gl = &self.shared.context.lock(); let gl = &self.shared.context.lock();
let timeout_ns = if cfg!(target_arch = "wasm32") { let timeout_ns = if cfg!(any(webgl, Emscripten)) {
0 0
} else { } else {
(timeout_ms as u64 * 1_000_000).min(!0u32 as u64) (timeout_ms as u64 * 1_000_000).min(!0u32 as u64)
@ -1446,7 +1446,7 @@ impl crate::Device<super::Api> for super::Device {
gl.client_wait_sync(sync, glow::SYNC_FLUSH_COMMANDS_BIT, timeout_ns as i32) gl.client_wait_sync(sync, glow::SYNC_FLUSH_COMMANDS_BIT, timeout_ns as i32)
} { } {
// for some reason firefox returns WAIT_FAILED, to investigate // for some reason firefox returns WAIT_FAILED, to investigate
#[cfg(target_arch = "wasm32")] #[cfg(any(webgl, Emscripten))]
glow::WAIT_FAILED => { glow::WAIT_FAILED => {
log::warn!("wait failed!"); log::warn!("wait failed!");
Ok(false) Ok(false)
@ -1461,7 +1461,7 @@ impl crate::Device<super::Api> for super::Device {
} }
unsafe fn start_capture(&self) -> bool { unsafe fn start_capture(&self) -> bool {
#[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))] #[cfg(all(native, feature = "renderdoc"))]
return unsafe { return unsafe {
self.render_doc self.render_doc
.start_frame_capture(self.shared.context.raw_context(), ptr::null_mut()) .start_frame_capture(self.shared.context.raw_context(), ptr::null_mut())
@ -1470,7 +1470,7 @@ impl crate::Device<super::Api> for super::Device {
false false
} }
unsafe fn stop_capture(&self) { unsafe fn stop_capture(&self) {
#[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))] #[cfg(all(native, feature = "renderdoc"))]
unsafe { unsafe {
self.render_doc self.render_doc
.end_frame_capture(ptr::null_mut(), ptr::null_mut()) .end_frame_capture(ptr::null_mut(), ptr::null_mut())
@ -1497,15 +1497,7 @@ impl crate::Device<super::Api> for super::Device {
unsafe fn destroy_acceleration_structure(&self, _acceleration_structure: ()) {} unsafe fn destroy_acceleration_structure(&self, _acceleration_structure: ()) {}
} }
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for super::Device {} unsafe impl Sync for super::Device {}
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for super::Device {} unsafe impl Send for super::Device {}

View File

@ -28,10 +28,10 @@ type WlDisplayConnectFun =
type WlDisplayDisconnectFun = unsafe extern "system" fn(display: *const raw::c_void); type WlDisplayDisconnectFun = unsafe extern "system" fn(display: *const raw::c_void);
#[cfg(not(target_os = "emscripten"))] #[cfg(not(Emscripten))]
type EglInstance = khronos_egl::DynamicInstance<khronos_egl::EGL1_4>; type EglInstance = khronos_egl::DynamicInstance<khronos_egl::EGL1_4>;
#[cfg(target_os = "emscripten")] #[cfg(Emscripten)]
type EglInstance = khronos_egl::Instance<khronos_egl::Static>; type EglInstance = khronos_egl::Instance<khronos_egl::Static>;
type WlEglWindowCreateFun = unsafe extern "system" fn( type WlEglWindowCreateFun = unsafe extern "system" fn(
@ -434,9 +434,9 @@ struct Inner {
version: (i32, i32), version: (i32, i32),
supports_native_window: bool, supports_native_window: bool,
config: khronos_egl::Config, config: khronos_egl::Config,
#[cfg_attr(target_os = "emscripten", allow(dead_code))] #[cfg_attr(Emscripten, allow(dead_code))]
wl_display: Option<*mut raw::c_void>, wl_display: Option<*mut raw::c_void>,
#[cfg_attr(target_os = "emscripten", allow(dead_code))] #[cfg_attr(Emscripten, allow(dead_code))]
force_gles_minor_version: wgt::Gles3MinorVersion, force_gles_minor_version: wgt::Gles3MinorVersion,
/// Method by which the framebuffer should support srgb /// Method by which the framebuffer should support srgb
srgb_kind: SrgbFrameBufferKind, srgb_kind: SrgbFrameBufferKind,
@ -569,7 +569,7 @@ impl Inner {
// and creating dummy pbuffer surface if not. // and creating dummy pbuffer surface if not.
let pbuffer = if version >= (1, 5) let pbuffer = if version >= (1, 5)
|| display_extensions.contains("EGL_KHR_surfaceless_context") || display_extensions.contains("EGL_KHR_surfaceless_context")
|| cfg!(target_os = "emscripten") || cfg!(Emscripten)
{ {
log::debug!("\tEGL context: +surfaceless"); log::debug!("\tEGL context: +surfaceless");
None None
@ -675,11 +675,11 @@ unsafe impl Sync for Instance {}
impl crate::Instance<super::Api> for Instance { impl crate::Instance<super::Api> for Instance {
unsafe fn init(desc: &crate::InstanceDescriptor) -> Result<Self, crate::InstanceError> { unsafe fn init(desc: &crate::InstanceDescriptor) -> Result<Self, crate::InstanceError> {
profiling::scope!("Init OpenGL (EGL) Backend"); profiling::scope!("Init OpenGL (EGL) Backend");
#[cfg(target_os = "emscripten")] #[cfg(Emscripten)]
let egl_result: Result<EglInstance, khronos_egl::Error> = let egl_result: Result<EglInstance, khronos_egl::Error> =
Ok(khronos_egl::Instance::new(khronos_egl::Static)); Ok(khronos_egl::Instance::new(khronos_egl::Static));
#[cfg(not(target_os = "emscripten"))] #[cfg(not(Emscripten))]
let egl_result = if cfg!(windows) { let egl_result = if cfg!(windows) {
unsafe { unsafe {
khronos_egl::DynamicInstance::<khronos_egl::EGL1_4>::load_required_from_filename( khronos_egl::DynamicInstance::<khronos_egl::EGL1_4>::load_required_from_filename(
@ -732,10 +732,10 @@ impl crate::Instance<super::Api> for Instance {
None None
}; };
#[cfg(not(target_os = "emscripten"))] #[cfg(not(Emscripten))]
let egl1_5 = egl.upcast::<khronos_egl::EGL1_5>(); let egl1_5 = egl.upcast::<khronos_egl::EGL1_5>();
#[cfg(target_os = "emscripten")] #[cfg(Emscripten)]
let egl1_5: Option<&Arc<EglInstance>> = Some(&egl); let egl1_5: Option<&Arc<EglInstance>> = Some(&egl);
let (display, display_owner, wsi_kind) = let (display, display_owner, wsi_kind) =
@ -842,10 +842,7 @@ impl crate::Instance<super::Api> for Instance {
) -> Result<Surface, crate::InstanceError> { ) -> Result<Surface, crate::InstanceError> {
use raw_window_handle::RawWindowHandle as Rwh; use raw_window_handle::RawWindowHandle as Rwh;
#[cfg_attr( #[cfg_attr(any(target_os = "android", Emscripten), allow(unused_mut))]
any(target_os = "android", target_os = "emscripten"),
allow(unused_mut)
)]
let mut inner = self.inner.lock(); let mut inner = self.inner.lock();
match (window_handle, display_handle) { match (window_handle, display_handle) {
@ -875,7 +872,7 @@ impl crate::Instance<super::Api> for Instance {
))); )));
} }
} }
#[cfg(not(target_os = "emscripten"))] #[cfg(not(Emscripten))]
(Rwh::Wayland(_), raw_window_handle::RawDisplayHandle::Wayland(display_handle)) => { (Rwh::Wayland(_), raw_window_handle::RawDisplayHandle::Wayland(display_handle)) => {
if inner if inner
.wl_display .wl_display
@ -920,7 +917,7 @@ impl crate::Instance<super::Api> for Instance {
drop(old_inner); drop(old_inner);
} }
} }
#[cfg(target_os = "emscripten")] #[cfg(Emscripten)]
(Rwh::Web(_), _) => {} (Rwh::Web(_), _) => {}
other => { other => {
return Err(crate::InstanceError::new(format!( return Err(crate::InstanceError::new(format!(
@ -1172,7 +1169,7 @@ impl crate::Surface<super::Api> for Surface {
wl_window = Some(window); wl_window = Some(window);
window window
} }
#[cfg(target_os = "emscripten")] #[cfg(Emscripten)]
(WindowKind::Unknown, Rwh::Web(handle)) => handle.id as *mut std::ffi::c_void, (WindowKind::Unknown, Rwh::Web(handle)) => handle.id as *mut std::ffi::c_void,
(WindowKind::Unknown, Rwh::Win32(handle)) => { (WindowKind::Unknown, Rwh::Win32(handle)) => {
handle.hwnd.get() as *mut std::ffi::c_void handle.hwnd.get() as *mut std::ffi::c_void
@ -1229,10 +1226,10 @@ impl crate::Surface<super::Api> for Surface {
} }
attributes.push(khronos_egl::ATTRIB_NONE as i32); attributes.push(khronos_egl::ATTRIB_NONE as i32);
#[cfg(not(target_os = "emscripten"))] #[cfg(not(Emscripten))]
let egl1_5 = self.egl.instance.upcast::<khronos_egl::EGL1_5>(); let egl1_5 = self.egl.instance.upcast::<khronos_egl::EGL1_5>();
#[cfg(target_os = "emscripten")] #[cfg(Emscripten)]
let egl1_5: Option<&Arc<EglInstance>> = Some(&self.egl.instance); let egl1_5: Option<&Arc<EglInstance>> = Some(&self.egl.instance);
// Careful, we can still be in 1.4 version even if `upcast` succeeds // Careful, we can still be in 1.4 version even if `upcast` succeeds

View File

@ -82,11 +82,11 @@ we don't bother with that combination.
*/ */
///cbindgen:ignore ///cbindgen:ignore
#[cfg(not(any(windows, all(target_arch = "wasm32", not(target_os = "emscripten")))))] #[cfg(not(any(windows, webgl)))]
mod egl; mod egl;
#[cfg(target_os = "emscripten")] #[cfg(Emscripten)]
mod emscripten; mod emscripten;
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
mod web; mod web;
#[cfg(windows)] #[cfg(windows)]
mod wgl; mod wgl;
@ -99,14 +99,14 @@ mod queue;
use crate::{CopyExtent, TextureDescriptor}; use crate::{CopyExtent, TextureDescriptor};
#[cfg(not(any(windows, all(target_arch = "wasm32", not(target_os = "emscripten")))))] #[cfg(not(any(windows, webgl)))]
pub use self::egl::{AdapterContext, AdapterContextLock}; pub use self::egl::{AdapterContext, AdapterContextLock};
#[cfg(not(any(windows, all(target_arch = "wasm32", not(target_os = "emscripten")))))] #[cfg(not(any(windows, webgl)))]
use self::egl::{Instance, Surface}; use self::egl::{Instance, Surface};
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
pub use self::web::AdapterContext; pub use self::web::AdapterContext;
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
use self::web::{Instance, Surface}; use self::web::{Instance, Surface};
#[cfg(windows)] #[cfg(windows)]
@ -260,7 +260,7 @@ pub struct Adapter {
pub struct Device { pub struct Device {
shared: Arc<AdapterShared>, shared: Arc<AdapterShared>,
main_vao: glow::VertexArray, main_vao: glow::VertexArray,
#[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))] #[cfg(all(native, feature = "renderdoc"))]
render_doc: crate::auxil::renderdoc::RenderDoc, render_doc: crate::auxil::renderdoc::RenderDoc,
} }
@ -291,17 +291,9 @@ pub struct Buffer {
data: Option<Arc<std::sync::Mutex<Vec<u8>>>>, data: Option<Arc<std::sync::Mutex<Vec<u8>>>>,
} }
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for Buffer {} unsafe impl Sync for Buffer {}
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for Buffer {} unsafe impl Send for Buffer {}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -314,23 +306,15 @@ pub enum TextureInner {
raw: glow::Texture, raw: glow::Texture,
target: BindTarget, target: BindTarget,
}, },
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
ExternalFramebuffer { ExternalFramebuffer {
inner: web_sys::WebGlFramebuffer, inner: web_sys::WebGlFramebuffer,
}, },
} }
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for TextureInner {} unsafe impl Sync for TextureInner {}
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for TextureInner {} unsafe impl Send for TextureInner {}
impl TextureInner { impl TextureInner {
@ -340,7 +324,7 @@ impl TextureInner {
panic!("Unexpected renderbuffer"); panic!("Unexpected renderbuffer");
} }
Self::Texture { raw, target } => (raw, target), Self::Texture { raw, target } => (raw, target),
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
Self::ExternalFramebuffer { .. } => panic!("Unexpected external framebuffer"), Self::ExternalFramebuffer { .. } => panic!("Unexpected external framebuffer"),
} }
} }
@ -524,17 +508,9 @@ struct PushConstantDesc {
size_bytes: u32, size_bytes: u32,
} }
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for PushConstantDesc {} unsafe impl Sync for PushConstantDesc {}
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for PushConstantDesc {} unsafe impl Send for PushConstantDesc {}
/// For each texture in the pipeline layout, store the index of the only /// For each texture in the pipeline layout, store the index of the only
@ -602,17 +578,9 @@ pub struct RenderPipeline {
alpha_to_coverage_enabled: bool, alpha_to_coverage_enabled: bool,
} }
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for RenderPipeline {} unsafe impl Sync for RenderPipeline {}
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for RenderPipeline {} unsafe impl Send for RenderPipeline {}
#[derive(Debug)] #[derive(Debug)]
@ -620,17 +588,9 @@ pub struct ComputePipeline {
inner: Arc<PipelineInner>, inner: Arc<PipelineInner>,
} }
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for ComputePipeline {} unsafe impl Sync for ComputePipeline {}
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for ComputePipeline {} unsafe impl Send for ComputePipeline {}
#[derive(Debug)] #[derive(Debug)]
@ -792,7 +752,7 @@ enum Command {
dst_target: BindTarget, dst_target: BindTarget,
copy: crate::BufferCopy, copy: crate::BufferCopy,
}, },
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
CopyExternalImageToTexture { CopyExternalImageToTexture {
src: wgt::ImageCopyExternalImage, src: wgt::ImageCopyExternalImage,
dst: glow::Texture, dst: glow::Texture,
@ -951,17 +911,9 @@ impl fmt::Debug for CommandBuffer {
} }
} }
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for CommandBuffer {} unsafe impl Sync for CommandBuffer {}
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for CommandBuffer {} unsafe impl Send for CommandBuffer {}
//TODO: we would have something like `Arc<typed_arena::Arena>` //TODO: we would have something like `Arc<typed_arena::Arena>`
@ -982,20 +934,12 @@ impl fmt::Debug for CommandEncoder {
} }
} }
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for CommandEncoder {} unsafe impl Sync for CommandEncoder {}
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for CommandEncoder {} unsafe impl Send for CommandEncoder {}
#[cfg(not(all(target_arch = "wasm32", not(target_os = "emscripten"))))] #[cfg(not(webgl))]
fn gl_debug_message_callback(source: u32, gltype: u32, id: u32, severity: u32, message: &str) { fn gl_debug_message_callback(source: u32, gltype: u32, id: u32, severity: u32, message: &str) {
let source_str = match source { let source_str = match source {
glow::DEBUG_SOURCE_API => "API", glow::DEBUG_SOURCE_API => "API",

View File

@ -109,7 +109,7 @@ impl super::Queue {
super::TextureInner::Texture { raw, target } => { super::TextureInner::Texture { raw, target } => {
let num_layers = view.array_layers.end - view.array_layers.start; let num_layers = view.array_layers.end - view.array_layers.start;
if num_layers > 1 { if num_layers > 1 {
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))] #[cfg(webgl)]
unsafe { unsafe {
gl.framebuffer_texture_multiview_ovr( gl.framebuffer_texture_multiview_ovr(
fbo_target, fbo_target,
@ -143,7 +143,7 @@ impl super::Queue {
}; };
} }
} }
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
super::TextureInner::ExternalFramebuffer { ref inner } => unsafe { super::TextureInner::ExternalFramebuffer { ref inner } => unsafe {
gl.bind_external_framebuffer(glow::FRAMEBUFFER, inner); gl.bind_external_framebuffer(glow::FRAMEBUFFER, inner);
}, },
@ -432,7 +432,7 @@ impl super::Queue {
unsafe { gl.bind_buffer(copy_dst_target, None) }; unsafe { gl.bind_buffer(copy_dst_target, None) };
} }
} }
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
C::CopyExternalImageToTexture { C::CopyExternalImageToTexture {
ref src, ref src,
dst, dst,
@ -1805,15 +1805,7 @@ impl crate::Queue<super::Api> for super::Queue {
} }
} }
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for super::Queue {} unsafe impl Sync for super::Queue {}
#[cfg(all( #[cfg(send_sync)]
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for super::Queue {} unsafe impl Send for super::Queue {}

View File

@ -111,15 +111,9 @@ impl Instance {
} }
} }
#[cfg(all( #[cfg(send_sync)]
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for Instance {} unsafe impl Sync for Instance {}
#[cfg(all( #[cfg(send_sync)]
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for Instance {} unsafe impl Send for Instance {}
impl crate::Instance<super::Api> for Instance { impl crate::Instance<super::Api> for Instance {
@ -210,15 +204,9 @@ impl Clone for Surface {
} }
} }
#[cfg(all( #[cfg(send_sync)]
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Sync for Surface {} unsafe impl Sync for Surface {}
#[cfg(all( #[cfg(send_sync)]
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
unsafe impl Send for Surface {} unsafe impl Send for Surface {}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]

View File

@ -52,30 +52,30 @@
)] )]
/// DirectX12 API internals. /// DirectX12 API internals.
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
pub mod dx12; pub mod dx12;
/// A dummy API implementation. /// A dummy API implementation.
pub mod empty; pub mod empty;
/// GLES API internals. /// GLES API internals.
#[cfg(feature = "gles")] #[cfg(gles)]
pub mod gles; pub mod gles;
/// Metal API internals. /// Metal API internals.
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
pub mod metal; pub mod metal;
/// Vulkan API internals. /// Vulkan API internals.
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
pub mod vulkan; pub mod vulkan;
pub mod auxil; pub mod auxil;
pub mod api { pub mod api {
#[cfg(all(feature = "dx12", windows))] #[cfg(dx12)]
pub use super::dx12::Api as Dx12; pub use super::dx12::Api as Dx12;
pub use super::empty::Api as Empty; pub use super::empty::Api as Empty;
#[cfg(feature = "gles")] #[cfg(gles)]
pub use super::gles::Api as Gles; pub use super::gles::Api as Gles;
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))] #[cfg(metal)]
pub use super::metal::Api as Metal; pub use super::metal::Api as Metal;
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))] #[cfg(vulkan)]
pub use super::vulkan::Api as Vulkan; pub use super::vulkan::Api as Vulkan;
} }
@ -463,7 +463,7 @@ pub trait CommandEncoder<A: Api>: WasmNotSendSync + fmt::Debug {
/// Works with a single array layer. /// Works with a single array layer.
/// Note: `dst` current usage has to be `TextureUses::COPY_DST`. /// Note: `dst` current usage has to be `TextureUses::COPY_DST`.
/// Note: the copy extent is in physical size (rounded to the block size) /// Note: the copy extent is in physical size (rounded to the block size)
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))] #[cfg(webgl)]
unsafe fn copy_external_image_to_texture<T>( unsafe fn copy_external_image_to_texture<T>(
&mut self, &mut self,
src: &wgt::ImageCopyExternalImage, src: &wgt::ImageCopyExternalImage,

View File

@ -508,7 +508,7 @@ impl super::Instance {
Ok(self.create_surface_from_vk_surface_khr(surface)) Ok(self.create_surface_from_vk_surface_khr(surface))
} }
#[cfg(all(any(target_os = "macos", target_os = "ios"), feature = "metal"))] #[cfg(metal)]
fn create_surface_from_view( fn create_surface_from_view(
&self, &self,
view: *mut c_void, view: *mut c_void,

View File

@ -3,7 +3,7 @@ fn main() {
native: { not(target_arch = "wasm32") }, native: { not(target_arch = "wasm32") },
webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgl") }, webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgl") },
webgpu: { all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "webgl")) }, webgpu: { all(target_arch = "wasm32", not(target_os = "emscripten"), not(feature = "webgl")) },
emscripten: { all(target_arch = "wasm32", target_os = "emscripten") }, Emscripten: { all(target_arch = "wasm32", target_os = "emscripten") },
send_sync: { any( send_sync: { any(
not(target_arch = "wasm32"), not(target_arch = "wasm32"),
all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics")) all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics"))

View File

@ -1,5 +1,3 @@
#![allow(clippy::mismatched_target_os)]
use crate::{ use crate::{
context::{ObjectId, Unused}, context::{ObjectId, Unused},
AdapterInfo, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource, BufferBinding, AdapterInfo, BindGroupDescriptor, BindGroupLayoutDescriptor, BindingResource, BufferBinding,
@ -1398,9 +1396,9 @@ impl crate::Context for Context {
Err(e) => panic!("Error in Device::create_render_bundle_encoder: {e}"), Err(e) => panic!("Error in Device::create_render_bundle_encoder: {e}"),
} }
} }
#[cfg_attr(not(any(native, emscripten)), allow(unused))] #[cfg_attr(not(any(native, Emscripten)), allow(unused))]
fn device_drop(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) { fn device_drop(&self, device: &Self::DeviceId, _device_data: &Self::DeviceData) {
#[cfg(any(native, emscripten))] #[cfg(any(native, Emscripten))]
{ {
let global = &self.0; let global = &self.0;
match wgc::gfx_select!(device => global.device_poll(*device, wgt::Maintain::wait())) { match wgc::gfx_select!(device => global.device_poll(*device, wgt::Maintain::wait())) {