Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove expose-ids Feature #4841

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ This adds a way to allow a Vulkan driver which is non-compliant per VK_KHR_drive

Previously, `DeviceExt::create_texture_with_data` only allowed data to be provided in layer major order. There is now a `order` parameter which allows you to specify if the data is in layer major or mip major order.

### `expose-ids` feature now available unconditionally

This feature allowed you to call `global_id` on any wgpu opaque handle to get a unique hashable identity for the given resource. This is now available without the feature flag. By @cwfitzgerald in [#4841](https://github.com/gfx-rs/wgpu/pull/4841)

### New Features

#### General
Expand Down
1 change: 0 additions & 1 deletion wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ angle = ["wgc/gles"]
webgl = ["hal", "wgc/gles"]
# Enables the Vulkan backend on macOS & iOS
vulkan-portability = ["wgc/vulkan"]
expose-ids = []
# Implement `Send` and `Sync` on Wasm.
fragile-send-sync-non-atomic-wasm = [
"hal/fragile-send-sync-non-atomic-wasm",
Expand Down
33 changes: 11 additions & 22 deletions wgpu/src/backend/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use std::{
fmt,
future::Future,
marker::PhantomData,
num::NonZeroU64,
ops::Range,
pin::Pin,
rc::Rc,
sync::atomic::{AtomicU64, Ordering},
task::{self, Poll},
};
use wasm_bindgen::{prelude::*, JsCast};
Expand All @@ -20,15 +22,12 @@ use crate::{
};

fn create_identified<T>(value: T) -> (Identified<T>, Sendable<T>) {
cfg_if::cfg_if! {
if #[cfg(feature = "expose-ids")] {
static NEXT_ID: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
let id = NEXT_ID.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
(Identified(core::num::NonZeroU64::new(id).unwrap(), PhantomData), Sendable(value))
} else {
(Identified(PhantomData), Sendable(value))
}
}
static NEXT_ID: AtomicU64 = AtomicU64::new(1);
let id = NEXT_ID.fetch_add(1, Ordering::Relaxed);
(
Identified(NonZeroU64::new(id).unwrap(), PhantomData),
Sendable(value),
)
}

// We need to make a wrapper for some of the handle types returned by the web backend to make them
Expand All @@ -39,25 +38,18 @@ fn create_identified<T>(value: T) -> (Identified<T>, Sendable<T>) {
// type is (for now) harmless. Eventually wasm32 will support threading, and depending on how this
// is integrated (or not integrated) with values like those in webgpu, this may become unsound.

#[allow(unused_variables)]
impl<T> From<ObjectId> for Identified<T> {
fn from(object_id: ObjectId) -> Self {
Self(
#[cfg(feature = "expose-ids")]
object_id.global_id(),
PhantomData,
)
Self(object_id.global_id(), PhantomData)
}
}

#[allow(unused_variables)]
impl<T> From<Identified<T>> for ObjectId {
fn from(identified: Identified<T>) -> Self {
Self::new(
// TODO: the ID isn't used, so we hardcode it to 1 for now until we rework this
// API.
core::num::NonZeroU64::new(1).unwrap(),
#[cfg(feature = "expose-ids")]
NonZeroU64::new(1).unwrap(),
identified.0,
)
}
Expand All @@ -77,10 +69,7 @@ unsafe impl<T> Send for Sendable<T> {}
unsafe impl<T> Sync for Sendable<T> {}

#[derive(Clone, Debug)]
pub(crate) struct Identified<T>(
#[cfg(feature = "expose-ids")] std::num::NonZeroU64,
PhantomData<T>,
);
pub(crate) struct Identified<T>(std::num::NonZeroU64, PhantomData<T>);
#[cfg(all(
feature = "fragile-send-sync-non-atomic-wasm",
not(target_feature = "atomics")
Expand Down
8 changes: 1 addition & 7 deletions wgpu/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1033,22 +1033,19 @@ pub trait Context: Debug + WasmNotSendSync + Sized {
pub struct ObjectId {
/// ID that is unique at any given time
id: Option<NonZeroU64>,
#[cfg(feature = "expose-ids")]
/// ID that is unique at all times
global_id: Option<NonZeroU64>,
}

impl ObjectId {
pub(crate) const UNUSED: Self = ObjectId {
id: None,
#[cfg(feature = "expose-ids")]
global_id: None,
};

pub fn new(id: NonZeroU64, #[cfg(feature = "expose-ids")] global_id: NonZeroU64) -> Self {
pub fn new(id: NonZeroU64, global_id: NonZeroU64) -> Self {
Self {
id: Some(id),
#[cfg(feature = "expose-ids")]
global_id: Some(global_id),
}
}
Expand All @@ -1057,7 +1054,6 @@ impl ObjectId {
pub fn from_global_id(global_id: NonZeroU64) -> Self {
Self {
id: Some(global_id),
#[cfg(feature = "expose-ids")]
global_id: Some(global_id),
}
}
Expand All @@ -1067,8 +1063,6 @@ impl ObjectId {
self.id.unwrap()
}

#[cfg(feature = "expose-ids")]
#[cfg_attr(docsrs, doc(cfg(feature = "expose-ids")))]
pub fn global_id(&self) -> NonZeroU64 {
self.global_id.unwrap()
}
Expand Down
Loading
Loading