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",
"bit-vec",
"bitflags 2.4.1",
"cfg_aliases",
"codespan-reporting",
"indexmap",
"log",
@ -4063,6 +4064,7 @@ dependencies = [
"bitflags 2.4.1",
"block",
"cfg-if",
"cfg_aliases",
"core-graphics-types",
"d3d12",
"env_logger",

View File

@ -128,3 +128,6 @@ web-sys = { version = "0.3.66", features = [
"HtmlCanvasElement",
"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 {
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
#[cfg(vulkan)]
if self.downcast_ref::<hal::api::Vulkan>().is_some() {
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() {
return Backend::Metal;
}
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
if self.downcast_ref::<hal::api::Dx12>().is_some() {
return Backend::Dx12;
}
#[cfg(feature = "gles")]
#[cfg(gles)]
if self.downcast_ref::<hal::api::Gles>().is_some() {
return Backend::Gl;
}
@ -90,19 +90,7 @@ impl fmt::Debug for AnySurface {
}
}
#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
#[cfg(send_sync)]
unsafe impl Send for AnySurface {}
#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
#[cfg(send_sync)]
unsafe impl Sync for AnySurface {}

View File

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

View File

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

View File

@ -2164,22 +2164,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut closures = UserClosures::default();
let mut all_queue_empty = true;
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
#[cfg(vulkan)]
{
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 =
self.poll_device::<hal::api::Metal>(force_wait, &mut closures)? && all_queue_empty;
}
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
{
all_queue_empty =
self.poll_device::<hal::api::Dx12>(force_wait, &mut closures)? && all_queue_empty;
}
#[cfg(feature = "gles")]
#[cfg(gles)]
{
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(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
#[cfg(send_sync)]
pub type DeviceLostCallback = Box<dyn Fn(DeviceLostReason, String) + Send + 'static>;
#[cfg(not(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
)))]
#[cfg(not(send_sync))]
pub type DeviceLostCallback = Box<dyn Fn(DeviceLostReason, String) + 'static>;
pub struct DeviceLostClosureRust {
@ -242,13 +230,7 @@ pub struct DeviceLostClosureC {
called: bool,
}
#[cfg(any(
not(target_arch = "wasm32"),
all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
)
))]
#[cfg(send_sync)]
unsafe impl Send for DeviceLostClosureC {}
impl Drop for DeviceLostClosureC {

View File

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

View File

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

View File

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

View File

@ -62,13 +62,13 @@ fn downlevel_default_limits_less_than_default_limits() {
pub struct Instance {
#[allow(dead_code)]
pub name: String,
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
#[cfg(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>>,
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
pub dx12: Option<HalInstance<hal::api::Dx12>>,
#[cfg(feature = "gles")]
#[cfg(gles)]
pub gl: Option<HalInstance<hal::api::Gles>>,
pub flags: wgt::InstanceFlags,
}
@ -105,13 +105,13 @@ impl Instance {
Self {
name: name.to_string(),
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
#[cfg(vulkan)]
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),
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
dx12: init(hal::api::Dx12, &instance_desc),
#[cfg(feature = "gles")]
#[cfg(gles)]
gl: init(hal::api::Gles, &instance_desc),
flags: instance_desc.flags,
}
@ -134,13 +134,13 @@ impl Instance {
}
}
match surface.raw.backend() {
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
#[cfg(vulkan)]
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),
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
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),
_ => unreachable!(),
}
@ -497,22 +497,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
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() {
hal_surface =
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() {
hal_surface =
init::<hal::api::Metal>(&self.instance.metal, display_handle, window_handle);
}
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
if hal_surface.is_none() {
hal_surface =
init::<hal::api::Dx12>(&self.instance.dx12, display_handle, window_handle);
}
#[cfg(feature = "gles")]
#[cfg(gles)]
if hal_surface.is_none() {
hal_surface = init::<hal::api::Gles>(&self.instance.gl, display_handle, window_handle);
}
@ -533,7 +533,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
/// # Safety
///
/// `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(
&self,
layer: *mut std::ffi::c_void,
@ -565,7 +565,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
id
}
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
/// # Safety
///
/// 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
}
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
/// # Safety
///
/// 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
}
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
/// # Safety
///
/// 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);
if let Some(surface) = Arc::into_inner(surface.unwrap()) {
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);
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
#[cfg(metal)]
unconfigure::<_, hal::api::Metal>(self, &surface.raw, &present);
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
unconfigure::<_, hal::api::Dx12>(self, &surface.raw, &present);
#[cfg(feature = "gles")]
#[cfg(gles)]
unconfigure::<_, hal::api::Gles>(self, &surface.raw, &present);
}
@ -733,23 +733,23 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let mut adapters = Vec::new();
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
#[cfg(vulkan)]
self.enumerate(
hal::api::Vulkan,
&self.instance.vulkan,
&inputs,
&mut adapters,
);
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
#[cfg(metal)]
self.enumerate(
hal::api::Metal,
&self.instance.metal,
&inputs,
&mut adapters,
);
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
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);
adapters
@ -831,7 +831,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
let compatible_surface = compatible_surface.as_ref().map(|surface| surface.as_ref());
let mut device_types = Vec::new();
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
#[cfg(vulkan)]
let (id_vulkan, adapters_vk) = gather(
hal::api::Vulkan,
self.instance.vulkan.as_ref(),
@ -840,7 +840,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc.force_fallback_adapter,
&mut device_types,
);
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
#[cfg(metal)]
let (id_metal, adapters_metal) = gather(
hal::api::Metal,
self.instance.metal.as_ref(),
@ -849,7 +849,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc.force_fallback_adapter,
&mut device_types,
);
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
let (id_dx12, adapters_dx12) = gather(
hal::api::Dx12,
self.instance.dx12.as_ref(),
@ -858,7 +858,7 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
desc.force_fallback_adapter,
&mut device_types,
);
#[cfg(feature = "gles")]
#[cfg(gles)]
let (id_gl, adapters_gl) = gather(
hal::api::Gles,
self.instance.gl.as_ref(),
@ -919,19 +919,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
};
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) {
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) {
return Ok(id);
}
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
if let Some(id) = self.select(&mut selected, id_dx12, adapters_dx12) {
return Ok(id);
}
#[cfg(feature = "gles")]
#[cfg(gles)]
if let Some(id) = self.select(&mut selected, id_gl, adapters_gl) {
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>>) =
match A::VARIANT {
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
#[cfg(vulkan)]
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)),
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
Backend::Dx12 => fid.assign(Adapter::new(hal_adapter)),
#[cfg(feature = "gles")]
#[cfg(gles)]
Backend::Gl => fid.assign(Adapter::new(hal_adapter)),
_ => unreachable!(),
};

View File

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

View File

@ -160,6 +160,9 @@ path = "../naga"
version = "0.14.0"
features = ["clone"]
[build-dependencies]
cfg_aliases.workspace = true
# DEV dependencies
[dev-dependencies.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)]
pub enum DxgiFactoryType {
#[cfg(feature = "dx11")]
Factory1,
Factory2,
Factory4,
Factory6,

View File

@ -1,7 +1,7 @@
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
pub(super) mod dxgi;
#[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))]
#[cfg(all(native, feature = "renderdoc"))]
pub(super) mod renderdoc;
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) {}
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(webgl)]
unsafe fn copy_external_image_to_texture<T>(
&mut self,
src: &wgt::ImageCopyExternalImage,

View File

@ -198,14 +198,14 @@ impl super::Adapter {
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.
// 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") } {
(GL_UNMASKED_VENDOR_WEBGL, GL_UNMASKED_RENDERER_WEBGL)
} else {
(glow::VENDOR, glow::RENDERER)
}
// 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)
} else {
(glow::VENDOR, glow::RENDERER)
@ -282,7 +282,7 @@ impl super::Adapter {
let value = sl_major as u16 * 100 + sl_minor as u16 * 10;
naga::back::glsl::Version::Embedded {
version: value,
is_webgl: cfg!(target_arch = "wasm32"),
is_webgl: cfg!(any(webgl, Emscripten)),
}
}
};
@ -407,16 +407,16 @@ impl super::Adapter {
}
downlevel_flags.set(
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
downlevel_flags.set(
wgt::DownlevelFlags::UNRESTRICTED_INDEX_BUFFER,
!cfg!(target_arch = "wasm32"),
!cfg!(any(webgl, Emscripten)),
);
downlevel_flags.set(
wgt::DownlevelFlags::UNRESTRICTED_EXTERNAL_TEXTURE_COPIES,
!cfg!(target_arch = "wasm32"),
!cfg!(any(webgl, Emscripten)),
);
downlevel_flags.set(
wgt::DownlevelFlags::FULL_DRAW_INDEX_UINT32,
@ -490,7 +490,7 @@ impl super::Adapter {
"EXT_texture_compression_rgtc",
"EXT_texture_compression_bptc",
];
let bcn_exts = if cfg!(target_arch = "wasm32") {
let bcn_exts = if cfg!(any(webgl, Emscripten)) {
&webgl_bcn_exts[..]
} else if es_ver.is_some() {
&gles_bcn_exts[..]
@ -501,7 +501,7 @@ impl super::Adapter {
wgt::Features::TEXTURE_COMPRESSION_BC,
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")
} else {
// 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")
|| extensions.contains("GL_OES_texture_compression_astc")
{
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(webgl)]
{
if 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_HDR);
@ -582,11 +582,11 @@ impl super::Adapter {
);
private_caps.set(
super::PrivateCapabilities::INDEX_BUFFER_ROLE_CHANGE,
!cfg!(target_arch = "wasm32"),
!cfg!(any(webgl, Emscripten)),
);
private_caps.set(
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")
|| extensions.contains("GL_ARB_color_buffer_float")
@ -759,7 +759,7 @@ impl super::Adapter {
workarounds.set(
super::Workarounds::EMULATE_BUFFER_MAP,
cfg!(target_arch = "wasm32"),
cfg!(any(webgl, Emscripten)),
);
let r = renderer.to_lowercase();
@ -917,7 +917,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
device: super::Device {
shared: Arc::clone(&self.shared),
main_vao,
#[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))]
#[cfg(all(native, feature = "renderdoc"))]
render_doc: Default::default(),
},
queue: super::Queue {
@ -1112,13 +1112,13 @@ impl crate::Adapter<super::Api> for super::Adapter {
if surface.presentable {
let mut formats = vec![
wgt::TextureFormat::Rgba8Unorm,
#[cfg(not(target_arch = "wasm32"))]
#[cfg(native)]
wgt::TextureFormat::Bgra8Unorm,
];
if surface.supports_srgb() {
formats.extend([
wgt::TextureFormat::Rgba8UnormSrgb,
#[cfg(not(target_arch = "wasm32"))]
#[cfg(native)]
wgt::TextureFormat::Bgra8UnormSrgb,
])
}
@ -1178,17 +1178,9 @@ impl super::AdapterShared {
}
}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Sync for super::Adapter {}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Send for super::Adapter {}
#[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>(
&mut self,
src: &wgt::ImageCopyExternalImage,
@ -507,7 +507,7 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
.iter()
.filter_map(|at| at.as_ref())
.any(|at| match at.target.view.inner {
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(webgl)]
super::TextureInner::ExternalFramebuffer { .. } => true,
_ => false,
});

View File

@ -9,7 +9,7 @@ use std::{
};
use arrayvec::ArrayVec;
#[cfg(not(target_arch = "wasm32"))]
#[cfg(native)]
use std::mem;
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
/// [`Some`], the texture must be valid until the drop implementation
/// 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(
&self,
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
/// [`Some`], the renderbuffer must be valid until the drop implementation
/// 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(
&self,
name: std::num::NonZeroU32,
@ -176,7 +176,7 @@ impl super::Device {
};
let raw = unsafe { gl.create_shader(target) }.unwrap();
#[cfg(not(target_arch = "wasm32"))]
#[cfg(native)]
if gl.supports_debug() {
//TODO: remove all transmutes from `object_label`
// https://github.com/grovesNL/glow/issues/186
@ -342,7 +342,7 @@ impl super::Device {
naga::back::glsl::Version::Desktop(version) => format!("{version}"),
};
let program = unsafe { gl.create_program() }.unwrap();
#[cfg(not(target_arch = "wasm32"))]
#[cfg(native)]
if let Some(label) = label {
if private_caps.contains(PrivateCapabilities::DEBUG_FNS) {
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`?
#[cfg(not(target_arch = "wasm32"))]
#[cfg(native)]
if let Some(label) = desc.label {
if self
.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 self
.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 self
.shared
@ -939,7 +939,7 @@ impl crate::Device<super::Api> for super::Device {
super::TextureInner::Texture { raw, .. } => {
unsafe { gl.delete_texture(raw) };
}
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(webgl)]
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 self
.shared
@ -1432,7 +1432,7 @@ impl crate::Device<super::Api> for super::Device {
) -> Result<bool, crate::DeviceError> {
if fence.last_completed < wait_value {
let gl = &self.shared.context.lock();
let timeout_ns = if cfg!(target_arch = "wasm32") {
let timeout_ns = if cfg!(any(webgl, Emscripten)) {
0
} else {
(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)
} {
// for some reason firefox returns WAIT_FAILED, to investigate
#[cfg(target_arch = "wasm32")]
#[cfg(any(webgl, Emscripten))]
glow::WAIT_FAILED => {
log::warn!("wait failed!");
Ok(false)
@ -1461,7 +1461,7 @@ impl crate::Device<super::Api> for super::Device {
}
unsafe fn start_capture(&self) -> bool {
#[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))]
#[cfg(all(native, feature = "renderdoc"))]
return unsafe {
self.render_doc
.start_frame_capture(self.shared.context.raw_context(), ptr::null_mut())
@ -1470,7 +1470,7 @@ impl crate::Device<super::Api> for super::Device {
false
}
unsafe fn stop_capture(&self) {
#[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))]
#[cfg(all(native, feature = "renderdoc"))]
unsafe {
self.render_doc
.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: ()) {}
}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Sync for super::Device {}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
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);
#[cfg(not(target_os = "emscripten"))]
#[cfg(not(Emscripten))]
type EglInstance = khronos_egl::DynamicInstance<khronos_egl::EGL1_4>;
#[cfg(target_os = "emscripten")]
#[cfg(Emscripten)]
type EglInstance = khronos_egl::Instance<khronos_egl::Static>;
type WlEglWindowCreateFun = unsafe extern "system" fn(
@ -434,9 +434,9 @@ struct Inner {
version: (i32, i32),
supports_native_window: bool,
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>,
#[cfg_attr(target_os = "emscripten", allow(dead_code))]
#[cfg_attr(Emscripten, allow(dead_code))]
force_gles_minor_version: wgt::Gles3MinorVersion,
/// Method by which the framebuffer should support srgb
srgb_kind: SrgbFrameBufferKind,
@ -569,7 +569,7 @@ impl Inner {
// and creating dummy pbuffer surface if not.
let pbuffer = if version >= (1, 5)
|| display_extensions.contains("EGL_KHR_surfaceless_context")
|| cfg!(target_os = "emscripten")
|| cfg!(Emscripten)
{
log::debug!("\tEGL context: +surfaceless");
None
@ -675,11 +675,11 @@ unsafe impl Sync for Instance {}
impl crate::Instance<super::Api> for Instance {
unsafe fn init(desc: &crate::InstanceDescriptor) -> Result<Self, crate::InstanceError> {
profiling::scope!("Init OpenGL (EGL) Backend");
#[cfg(target_os = "emscripten")]
#[cfg(Emscripten)]
let egl_result: Result<EglInstance, khronos_egl::Error> =
Ok(khronos_egl::Instance::new(khronos_egl::Static));
#[cfg(not(target_os = "emscripten"))]
#[cfg(not(Emscripten))]
let egl_result = if cfg!(windows) {
unsafe {
khronos_egl::DynamicInstance::<khronos_egl::EGL1_4>::load_required_from_filename(
@ -732,10 +732,10 @@ impl crate::Instance<super::Api> for Instance {
None
};
#[cfg(not(target_os = "emscripten"))]
#[cfg(not(Emscripten))]
let egl1_5 = egl.upcast::<khronos_egl::EGL1_5>();
#[cfg(target_os = "emscripten")]
#[cfg(Emscripten)]
let egl1_5: Option<&Arc<EglInstance>> = Some(&egl);
let (display, display_owner, wsi_kind) =
@ -842,10 +842,7 @@ impl crate::Instance<super::Api> for Instance {
) -> Result<Surface, crate::InstanceError> {
use raw_window_handle::RawWindowHandle as Rwh;
#[cfg_attr(
any(target_os = "android", target_os = "emscripten"),
allow(unused_mut)
)]
#[cfg_attr(any(target_os = "android", Emscripten), allow(unused_mut))]
let mut inner = self.inner.lock();
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)) => {
if inner
.wl_display
@ -920,7 +917,7 @@ impl crate::Instance<super::Api> for Instance {
drop(old_inner);
}
}
#[cfg(target_os = "emscripten")]
#[cfg(Emscripten)]
(Rwh::Web(_), _) => {}
other => {
return Err(crate::InstanceError::new(format!(
@ -1172,7 +1169,7 @@ impl crate::Surface<super::Api> for Surface {
wl_window = Some(window);
window
}
#[cfg(target_os = "emscripten")]
#[cfg(Emscripten)]
(WindowKind::Unknown, Rwh::Web(handle)) => handle.id as *mut std::ffi::c_void,
(WindowKind::Unknown, Rwh::Win32(handle)) => {
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);
#[cfg(not(target_os = "emscripten"))]
#[cfg(not(Emscripten))]
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);
// 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
#[cfg(not(any(windows, all(target_arch = "wasm32", not(target_os = "emscripten")))))]
#[cfg(not(any(windows, webgl)))]
mod egl;
#[cfg(target_os = "emscripten")]
#[cfg(Emscripten)]
mod emscripten;
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(webgl)]
mod web;
#[cfg(windows)]
mod wgl;
@ -99,14 +99,14 @@ mod queue;
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};
#[cfg(not(any(windows, all(target_arch = "wasm32", not(target_os = "emscripten")))))]
#[cfg(not(any(windows, webgl)))]
use self::egl::{Instance, Surface};
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(webgl)]
pub use self::web::AdapterContext;
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(webgl)]
use self::web::{Instance, Surface};
#[cfg(windows)]
@ -260,7 +260,7 @@ pub struct Adapter {
pub struct Device {
shared: Arc<AdapterShared>,
main_vao: glow::VertexArray,
#[cfg(all(not(target_arch = "wasm32"), feature = "renderdoc"))]
#[cfg(all(native, feature = "renderdoc"))]
render_doc: crate::auxil::renderdoc::RenderDoc,
}
@ -291,17 +291,9 @@ pub struct Buffer {
data: Option<Arc<std::sync::Mutex<Vec<u8>>>>,
}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Sync for Buffer {}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Send for Buffer {}
#[derive(Clone, Debug)]
@ -314,23 +306,15 @@ pub enum TextureInner {
raw: glow::Texture,
target: BindTarget,
},
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(webgl)]
ExternalFramebuffer {
inner: web_sys::WebGlFramebuffer,
},
}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Sync for TextureInner {}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Send for TextureInner {}
impl TextureInner {
@ -340,7 +324,7 @@ impl TextureInner {
panic!("Unexpected renderbuffer");
}
Self::Texture { raw, target } => (raw, target),
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(webgl)]
Self::ExternalFramebuffer { .. } => panic!("Unexpected external framebuffer"),
}
}
@ -524,17 +508,9 @@ struct PushConstantDesc {
size_bytes: u32,
}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Sync for PushConstantDesc {}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Send for PushConstantDesc {}
/// 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,
}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Sync for RenderPipeline {}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Send for RenderPipeline {}
#[derive(Debug)]
@ -620,17 +588,9 @@ pub struct ComputePipeline {
inner: Arc<PipelineInner>,
}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Sync for ComputePipeline {}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Send for ComputePipeline {}
#[derive(Debug)]
@ -792,7 +752,7 @@ enum Command {
dst_target: BindTarget,
copy: crate::BufferCopy,
},
#[cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))]
#[cfg(webgl)]
CopyExternalImageToTexture {
src: wgt::ImageCopyExternalImage,
dst: glow::Texture,
@ -951,17 +911,9 @@ impl fmt::Debug for CommandBuffer {
}
}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Sync for CommandBuffer {}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Send for CommandBuffer {}
//TODO: we would have something like `Arc<typed_arena::Arena>`
@ -982,20 +934,12 @@ impl fmt::Debug for CommandEncoder {
}
}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
unsafe impl Sync for CommandEncoder {}
#[cfg(all(
target_arch = "wasm32",
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
))]
#[cfg(send_sync)]
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) {
let source_str = match source {
glow::DEBUG_SOURCE_API => "API",

View File

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

View File

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

View File

@ -52,30 +52,30 @@
)]
/// DirectX12 API internals.
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
pub mod dx12;
/// A dummy API implementation.
pub mod empty;
/// GLES API internals.
#[cfg(feature = "gles")]
#[cfg(gles)]
pub mod gles;
/// Metal API internals.
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
#[cfg(metal)]
pub mod metal;
/// Vulkan API internals.
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
#[cfg(vulkan)]
pub mod vulkan;
pub mod auxil;
pub mod api {
#[cfg(all(feature = "dx12", windows))]
#[cfg(dx12)]
pub use super::dx12::Api as Dx12;
pub use super::empty::Api as Empty;
#[cfg(feature = "gles")]
#[cfg(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;
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
#[cfg(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.
/// Note: `dst` current usage has to be `TextureUses::COPY_DST`.
/// 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>(
&mut self,
src: &wgt::ImageCopyExternalImage,

View File

@ -508,7 +508,7 @@ impl super::Instance {
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(
&self,
view: *mut c_void,

View File

@ -3,7 +3,7 @@ fn main() {
native: { not(target_arch = "wasm32") },
webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), 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(
not(target_arch = "wasm32"),
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::{
context::{ObjectId, Unused},
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}"),
}
}
#[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) {
#[cfg(any(native, emscripten))]
#[cfg(any(native, Emscripten))]
{
let global = &self.0;
match wgc::gfx_select!(device => global.device_poll(*device, wgt::Maintain::wait())) {