Skip to content
Open
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 @@ -171,6 +171,10 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505).
- Added new `InvalidWorkgroupSizeError`, which is now used by `DrawError::InvalidGroupSize` and `StageError::InvalidWorkgroupSize`.
- Added `BuildAccelerationStructureError` variant `OffsetLimitedTo4GB` and changed `IndirectBufferOverrun` to contain offset and size rather than start and end offsets.
- `IndexFormat::byte_size` now returns `u32` instead of `usize`.
- BREAKING: `map_label` helpers have changed slightly. By @beicause and @andyleiserson in [#9480](https://github.com/gfx-rs/wgpu/pull/9480), [#9481](https://github.com/gfx-rs/wgpu/pull/9481), and TBD.
- `SurfaceConfiguration::map_label` now takes `FnOnce(&V) -> M` instead of `FnOnce(V) -> M`.
- All `map_label` helpers except `CreateShaderModuleDescriptorPassthrough` now have the signature `map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K)` (previously the lifetimes were implicit and thus could differ).
- `create_texture` now takes a descriptor with `view_formats` having the parameterized type `V: AsRef<[TextureFormat]>`.

#### Validation

Expand Down
2 changes: 1 addition & 1 deletion wgpu-types/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct BufferDescriptor<L> {
impl<L> BufferDescriptor<L> {
/// Takes a closure and maps the label of the buffer descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> BufferDescriptor<K> {
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> BufferDescriptor<K> {
BufferDescriptor {
label: fun(&self.label),
size: self.size,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-types/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct DeviceDescriptor<L> {
impl<L> DeviceDescriptor<L> {
/// Takes a closure and maps the label of the device descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> DeviceDescriptor<K> {
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> DeviceDescriptor<K> {
DeviceDescriptor {
label: fun(&self.label),
required_features: self.required_features,
Expand Down
4 changes: 2 additions & 2 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ pub struct CommandEncoderDescriptor<L> {
impl<L> CommandEncoderDescriptor<L> {
/// Takes a closure and maps the label of the command encoder descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> CommandEncoderDescriptor<K> {
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> CommandEncoderDescriptor<K> {
CommandEncoderDescriptor {
label: fun(&self.label),
}
Expand Down Expand Up @@ -489,7 +489,7 @@ pub struct CommandBufferDescriptor<L> {
impl<L> CommandBufferDescriptor<L> {
/// Takes a closure and maps the label of the command buffer descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> CommandBufferDescriptor<K> {
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> CommandBufferDescriptor<K> {
CommandBufferDescriptor {
label: fun(&self.label),
}
Expand Down
4 changes: 2 additions & 2 deletions wgpu-types/src/ray_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub struct CreateBlasDescriptor<L> {

impl<L> CreateBlasDescriptor<L> {
/// Takes a closure and maps the label of the blas descriptor into another.
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> CreateBlasDescriptor<K> {
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> CreateBlasDescriptor<K> {
CreateBlasDescriptor {
label: fun(&self.label),
flags: self.flags,
Expand All @@ -112,7 +112,7 @@ pub struct CreateTlasDescriptor<L> {

impl<L> CreateTlasDescriptor<L> {
/// Takes a closure and maps the label of the blas descriptor into another.
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> CreateTlasDescriptor<K> {
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> CreateTlasDescriptor<K> {
CreateTlasDescriptor {
label: fun(&self.label),
flags: self.flags,
Expand Down
2 changes: 1 addition & 1 deletion wgpu-types/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ pub struct RenderBundleDescriptor<L> {
impl<L> RenderBundleDescriptor<L> {
/// Takes a closure and maps the label of the render bundle descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> RenderBundleDescriptor<K> {
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> RenderBundleDescriptor<K> {
RenderBundleDescriptor {
label: fun(&self.label),
}
Expand Down
7 changes: 5 additions & 2 deletions wgpu-types/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,10 @@ pub struct SurfaceConfiguration<V> {

impl<V: Clone> SurfaceConfiguration<V> {
/// Map `view_formats` of the texture descriptor into another.
pub fn map_view_formats<M>(&self, fun: impl FnOnce(V) -> M) -> SurfaceConfiguration<M> {
pub fn map_view_formats<'a, M>(
&'a self,
fun: impl FnOnce(&'a V) -> M,
) -> SurfaceConfiguration<M> {
SurfaceConfiguration {
usage: self.usage,
format: self.format,
Expand All @@ -250,7 +253,7 @@ impl<V: Clone> SurfaceConfiguration<V> {
present_mode: self.present_mode,
desired_maximum_frame_latency: self.desired_maximum_frame_latency,
alpha_mode: self.alpha_mode,
view_formats: fun(self.view_formats.clone()),
view_formats: fun(&self.view_formats),
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions wgpu-types/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ pub struct TextureViewDescriptor<L> {
impl<L> TextureViewDescriptor<L> {
/// Takes a closure and maps the label of the texture view descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureViewDescriptor<K> {
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> TextureViewDescriptor<K> {
TextureViewDescriptor {
label: fun(&self.label),
format: self.format,
Expand Down Expand Up @@ -530,7 +530,7 @@ pub struct TextureDescriptor<L, V> {
impl<L, V> TextureDescriptor<L, V> {
/// Takes a closure and maps the label of the texture descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureDescriptor<K, V>
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> TextureDescriptor<K, V>
where
V: Clone,
{
Expand All @@ -548,10 +548,10 @@ impl<L, V> TextureDescriptor<L, V> {

/// Maps the label and view formats of the texture descriptor into another.
#[must_use]
pub fn map_label_and_view_formats<K, M>(
&self,
l_fun: impl FnOnce(&L) -> K,
v_fun: impl FnOnce(&V) -> M,
pub fn map_label_and_view_formats<'a, K, M>(
&'a self,
l_fun: impl FnOnce(&'a L) -> K,
v_fun: impl FnOnce(&'a V) -> M,
) -> TextureDescriptor<K, M> {
TextureDescriptor {
label: l_fun(&self.label),
Expand Down Expand Up @@ -703,7 +703,7 @@ impl<L: Default> Default for SamplerDescriptor<L> {
impl<L> SamplerDescriptor<L> {
/// Takes a closure and maps the label of the sampler descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> SamplerDescriptor<K> {
pub fn map_label<'a, K>(&'a self, fun: impl FnOnce(&'a L) -> K) -> SamplerDescriptor<K> {
SamplerDescriptor {
label: fun(&self.label),
address_mode_u: self.address_mode_u,
Expand Down
5 changes: 4 additions & 1 deletion wgpu-types/src/texture/external_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ pub struct ExternalTextureDescriptor<L> {
impl<L> ExternalTextureDescriptor<L> {
/// Takes a closure and maps the label of the external texture descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> ExternalTextureDescriptor<K> {
pub fn map_label<'a, K>(
&'a self,
fun: impl FnOnce(&'a L) -> K,
) -> ExternalTextureDescriptor<K> {
ExternalTextureDescriptor {
label: fun(&self.label),
width: self.width,
Expand Down
11 changes: 3 additions & 8 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ angle = ["wgpu-core?/angle"]
vulkan-portability = ["wgpu-core?/vulkan-portability"]

## Enables the GLES backend on WebAssembly only.
webgl = ["web", "wgpu-core/webgl", "dep:wgpu-hal", "dep:smallvec"]
webgl = ["web", "wgpu-core/webgl", "dep:wgpu-hal"]

#! ### Backend features

Expand All @@ -96,7 +96,7 @@ drm = ["wgpu-core?/drm"]
## but performs no computation.
## Because it lacks basic functionality, it is only actually used if explicitly enabled
## through `NoopBackendOptions`.
noop = ["wgpu-core/noop", "dep:wgpu-hal", "dep:smallvec"]
noop = ["wgpu-core/noop", "dep:wgpu-hal"]

#! **Note:** In the documentation, if you see that an item depends on a backend,
#! it means that the item is only available when that backend is enabled _and_ the backend
Expand Down Expand Up @@ -220,6 +220,7 @@ hashbrown.workspace = true
parking_lot = { workspace = true, optional = true }
profiling.workspace = true
raw-window-handle = { workspace = true, features = ["alloc"] }
smallvec.workspace = true
static_assertions.workspace = true

########################################
Expand All @@ -238,8 +239,6 @@ wgpu-core = { workspace = true, features = [
] }
wgpu-hal.workspace = true

smallvec.workspace = true

###############
# Webassembly #
###############
Expand All @@ -256,8 +255,6 @@ web-sys = { workspace = true, optional = true, features = [
wgpu-core = { workspace = true, optional = true }
wgpu-hal = { workspace = true, optional = true }

smallvec = { workspace = true, optional = true }

# Needed for the webgpu backend. Optional as webgpu is optional on WebAssembly.
wasm-bindgen-futures = { workspace = true, optional = true }

Expand All @@ -268,8 +265,6 @@ wasm-bindgen-futures = { workspace = true, optional = true }
wgpu-core.workspace = true
wgpu-hal.workspace = true

smallvec.workspace = true

[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
portable-atomic.workspace = true

Expand Down
23 changes: 11 additions & 12 deletions wgpu/src/api/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use alloc::{boxed::Box, string::String, sync::Arc, vec};
use core::ops::Deref;
use core::{error, fmt, future::Future, marker::PhantomData};

use smallvec::SmallVec;

use crate::api::blas::{Blas, BlasGeometrySizeDescriptors, CreateBlasDescriptor};
use crate::api::tlas::{CreateTlasDescriptor, Tlas};
use crate::util::Mutex;
Expand Down Expand Up @@ -291,16 +293,17 @@ impl Device {
///
/// `desc` specifies the general format of the texture.
#[must_use]
pub fn create_texture(&self, desc: &TextureDescriptor<'_>) -> Texture {
let texture = self.inner.create_texture(desc);
pub fn create_texture<V>(&self, desc: &wgt::TextureDescriptor<Label<'_>, V>) -> Texture
where
V: AsRef<[TextureFormat]>,
{
let descriptor = desc.map_label_and_view_formats(Option::clone, |v| v.as_ref());
let texture = self.inner.create_texture(&descriptor);

Texture {
inner: texture,
descriptor: TextureDescriptor {
label: None,
view_formats: &[],
..desc.clone()
},
descriptor: descriptor
.map_label_and_view_formats(|_| None, |v| SmallVec::from_slice(v)),
}
}

Expand Down Expand Up @@ -335,11 +338,7 @@ impl Device {
};
Texture {
inner: texture.into(),
descriptor: TextureDescriptor {
label: None,
view_formats: &[],
..desc.clone()
},
descriptor: desc.map_label_and_view_formats(|_| None, |v| SmallVec::from_slice(v)),
}
}

Expand Down
4 changes: 3 additions & 1 deletion wgpu/src/api/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use core::ops::Deref;
use core::{error, fmt};

use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
use smallvec::SmallVec;

use crate::util::Mutex;
use crate::*;
Expand Down Expand Up @@ -154,7 +155,8 @@ impl Surface<'_> {
let surface_texture = SurfaceTexture {
texture: Texture {
inner: texture,
descriptor,
descriptor: descriptor
.map_label_and_view_formats(|_| None, |v| SmallVec::from_slice(v)),
},
presented: false,
detail,
Expand Down
13 changes: 7 additions & 6 deletions wgpu/src/api/texture.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#[cfg(wgpu_core)]
use core::ops::Deref;

use smallvec::SmallVec;

use crate::*;

/// Handle to a texture on the GPU.
Expand All @@ -11,7 +13,10 @@ use crate::*;
#[derive(Debug, Clone)]
pub struct Texture {
pub(crate) inner: dispatch::DispatchTexture,
pub(crate) descriptor: TextureDescriptor<'static>,

/// The descriptor that was used to create this texture.
/// The label is not saved and will always be `None` in this copy.
pub(crate) descriptor: wgt::TextureDescriptor<Label<'static>, SmallVec<[TextureFormat; 1]>>,
}
#[cfg(send_sync)]
static_assertions::assert_impl_all!(Texture: Send, Sync);
Expand Down Expand Up @@ -77,11 +82,7 @@ impl Texture {
) -> Self {
Self {
inner: dispatch::DispatchTexture::custom(texture),
descriptor: TextureDescriptor {
label: None,
view_formats: &[],
..desc.clone()
},
descriptor: desc.map_label_and_view_formats(|_| None, |v| SmallVec::from_slice(v)),
}
}

Expand Down
Loading