Bring transient attachment in line with webgpu spec (#9568)

This commit is contained in:
Luo Zhihao authored and GitHub committed 2026-06-18 18:28:52 -07:00
1 parent 49102603b5
commit c841633bb3
23 files changed
+311 -106

No files matched your search

+2
View File
@@ -193,6 +193,8 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505).
- `TextureDescriptor::map_label_and_view_formats` and `SurfaceConfiguration::map_view_formats` now take `FnOnce(&V)` instead of `FnOnce(V)`.
- 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).
- Relaxed locking within `wgpu-core` to enable queue submission processing on one thread to proceed while another thread is blocked in a device poll. To facilitate this, `wgpu-hal` fences are now internally synchronized. By @Vecvec in [#9475](https://github.com/gfx-rs/wgpu/pull/9475).
- `AdapterInfo::transient_saves_memory` now is `Option<bool>` instead of `bool`. It is `None` on web and `Some` on native platforms. By @beicause in [#9568](https://github.com/gfx-rs/wgpu/pull/9568).
- BREAKING: `TextureUsages::TRANSIENT` is renamed to `TextureUsages::TRANSIENT_ATTACHMENT` and brought in line with WebGPU spec. Transient textures may now only be used with `LoadOp::Clear` or `LoadOp::DontCare` (if it is available) and `StoreOp::Discard`. By @beicause in [#9568](https://github.com/gfx-rs/wgpu/pull/9568).
#### Validation
+4
View File
@@ -133,12 +133,15 @@ webgpu:api,validation,createBindGroupLayout:visibility,*
webgpu:api,validation,createBindGroupLayout:visibility:*
webgpu:api,validation,createPipelineLayout:*
webgpu:api,validation,createSampler:*
webgpu:api,validation,createTexture:depthOrArrayLayers_and_mipLevelCount_for_transient_attachments:*
webgpu:api,validation,createTexture:dimension_type_and_format_compatibility:*
webgpu:api,validation,createTexture:mipLevelCount,*
webgpu:api,validation,createTexture:sample_count,*
webgpu:api,validation,createTexture:sampleCount,*
webgpu:api,validation,createTexture:texture_size,*
webgpu:api,validation,createTexture:texture_usage,*
webgpu:api,validation,createTexture:transient_viewFormats:*
webgpu:api,validation,createTexture:usage:*
webgpu:api,validation,createTexture:viewFormats:*
webgpu:api,validation,createTexture:zero_size_and_usage:*
webgpu:api,validation,createView:array_layers:*
@@ -147,6 +150,7 @@ webgpu:api,validation,createView:cube_faces_square:*
webgpu:api,validation,createView:dimension:*
webgpu:api,validation,createView:format:*
webgpu:api,validation,createView:mip_levels:*
webgpu:api,validation,createView:texture_view_usage_of_multiple_usages:*
webgpu:api,validation,createView:texture_view_usage_with_view_format:*
webgpu:api,validation,createView:texture_view_usage:*
webgpu:api,validation,debugMarker:*
+3
View File
@@ -482,6 +482,9 @@ class GPUTextureUsage {
static get RENDER_ATTACHMENT() {
return 0x10;
}
static get TRANSIENT_ATTACHMENT() {
return 0x20;
}
}
const GPUTextureViewPrototype = GPUTextureView.prototype;
+9
View File
@@ -74,6 +74,15 @@ impl GPUCanvasContext {
&self,
#[webidl] configuration: GPUCanvasConfiguration,
) -> Result<(), JsErrorBox> {
if configuration
.usage
.0
.contains(wgpu_types::TextureUsages::TRANSIENT_ATTACHMENT)
{
return Err(JsErrorBox::type_error(
"`GPUCanvasConfiguration.usage` must not include `TRANSIENT_ATTACHMENT`",
));
}
let format = configuration.format.clone().into();
let conf = wgpu_types::SurfaceConfiguration {
usage: configuration.usage.into(),
+2 -1
View File
@@ -112,7 +112,8 @@ impl Example {
sample_count,
dimension: wgpu::TextureDimension::D2,
format: config.view_formats[0],
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TRANSIENT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TRANSIENT_ATTACHMENT,
label: None,
view_formats: &[],
};
+2 -1
View File
@@ -192,7 +192,8 @@ impl Example {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: Self::DEPTH_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TRANSIENT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TRANSIENT_ATTACHMENT,
label: None,
view_formats: &[],
});
+2 -1
View File
@@ -80,7 +80,8 @@ impl Example {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: Self::DEPTH_FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TRANSIENT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TRANSIENT_ATTACHMENT,
label: None,
view_formats: &[],
});
+2 -1
View File
@@ -76,7 +76,8 @@ static RESOLVE_WITH_TRANSIENT: GpuTestConfiguration = GpuTestConfiguration::new(
sample_count: 4,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TRANSIENT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TRANSIENT_ATTACHMENT,
view_formats: &[],
});
+12 -9
View File
@@ -581,7 +581,7 @@ fn copy_buffer_to_texture_forbidden_format_aspect() {
}
}
/// Ensures that attempting to create a texture with [`wgpu::TextureUsages::TRANSIENT`]
/// Ensures that attempting to create a texture with [`wgpu::TextureUsages::TRANSIENT_ATTACHMENT`]
/// and its unsupported usages fails validation.
#[test]
fn transient_invalid_usage() {
@@ -595,9 +595,12 @@ fn transient_invalid_usage() {
let invalid_usages = wgpu::TextureUsages::all()
- wgpu::TextureUsages::RENDER_ATTACHMENT
- wgpu::TextureUsages::TRANSIENT;
- wgpu::TextureUsages::TRANSIENT_ATTACHMENT;
for usage in invalid_usages {
let usage = wgpu::TextureUsages::RENDER_ATTACHMENT
| wgpu::TextureUsages::TRANSIENT_ATTACHMENT
| usage;
let invalid_texture_descriptor = wgpu::TextureDescriptor {
label: None,
size,
@@ -605,13 +608,13 @@ fn transient_invalid_usage() {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TRANSIENT | usage,
usage,
view_formats: &[],
};
fail(
&device,
|| device.create_texture(&invalid_texture_descriptor),
Some(&format!("Texture usage TextureUsages(TRANSIENT) is not compatible with texture usage {usage:?}")),
Some(&format!("Transient texture usage must be equal to `TRANSIENT_ATTACHMENT | RENDER_ATTACHMENT`, but got `{usage:?}`")),
);
}
@@ -622,17 +625,17 @@ fn transient_invalid_usage() {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::TRANSIENT,
usage: wgpu::TextureUsages::TRANSIENT_ATTACHMENT,
view_formats: &[],
};
fail(
&device,
|| device.create_texture(&invalid_texture_descriptor),
Some("Invalid usage flags TextureUsages(TRANSIENT)"),
Some("Transient texture usage must be equal to `TRANSIENT_ATTACHMENT | RENDER_ATTACHMENT`, but got `TextureUsages(TRANSIENT_ATTACHMENT)`"),
);
}
/// Ensures that attempting to use a texture of [`wgpu::TextureUsages::TRANSIENT`]
/// Ensures that attempting to use a texture of [`wgpu::TextureUsages::TRANSIENT_ATTACHMENT`]
/// with [`wgpu::StoreOp::Store`] fails validation.
#[test]
fn transient_invalid_storeop() {
@@ -651,7 +654,7 @@ fn transient_invalid_storeop() {
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: wgpu::TextureFormat::Rgba8Unorm,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TRANSIENT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TRANSIENT_ATTACHMENT,
view_formats: &[],
});
@@ -681,6 +684,6 @@ fn transient_invalid_storeop() {
encoder.finish()
},
Some("Color attachment's usage contains TextureUsages(TRANSIENT). This can only be used with StoreOp::Discard, but StoreOp::Store was provided")
Some("Color attachment with `TRANSIENT_ATTACHMENT` usage can only be used with `LoadOp::Clear` or `LoadOp::DontCare` (if it is available) and `StoreOp::Discard`. Operations `(Clear(Color { r: 0.0, g: 0.0, b: 0.0, a: 0.0 }), Store)` were provided")
);
}
+179 -56
View File
@@ -809,8 +809,11 @@ pub enum ColorAttachmentError {
mip_level: u32,
depth_or_array_layer: u32,
},
#[error("Color attachment's usage contains {0:?}. This can only be used with StoreOp::{1:?}, but StoreOp::{2:?} was provided")]
InvalidUsageForStoreOp(TextureUsages, StoreOp, StoreOp),
#[error(
"Color attachment with `TRANSIENT_ATTACHMENT` usage can only be used with \
`LoadOp::Clear` or `LoadOp::DontCare` (if it is available) and `StoreOp::Discard`. Operations `{0:?}` were provided"
)]
InvalidTransientAttachmentOp((LoadOp<Color>, StoreOp)),
#[error("Color attachment's load op is `LoadOp::DontCare` but `InstanceFlags::STRICT_WEBGPU_COMPLIANCE` is set")]
LoadOpDontCareUnderStrictWebgpuCompliance,
}
@@ -826,6 +829,20 @@ impl WebGpuError for ColorAttachmentError {
pub enum AttachmentError {
#[error("The format of the depth-stencil attachment ({0:?}) is not a depth-or-stencil format")]
InvalidDepthStencilAttachmentFormat(wgt::TextureFormat),
#[error(
"Depth attachment with `TRANSIENT_ATTACHMENT` usage can only be used with \
`LoadOp::Clear` or `LoadOp::DontCare` (if it is available) and `StoreOp::Discard`. Operations `{0:?}` were provided"
)]
InvalidTransientDepthAttachmentOps((LoadOp<Option<f32>>, StoreOp)),
#[error("Depth attachment with `TRANSIENT_ATTACHMENT` usage cannot be read-only")]
ReadOnlyTransientDepthAttachment,
#[error(
"Stencil attachment with `TRANSIENT_ATTACHMENT` usage can only be used with \
`LoadOp::Clear` or `LoadOp::DontCare` (if it is available) and `StoreOp::Discard`. Operations `{0:?}` were provided"
)]
InvalidTransientStencilAttachmentOps((LoadOp<Option<u32>>, StoreOp)),
#[error("Stencil attachment with `TRANSIENT_ATTACHMENT` usage cannot be read-only")]
ReadOnlyTransientStencilAttachment,
#[error("LoadOp must be None for read-only attachments")]
ReadOnlyWithLoad,
#[error("StoreOp must be None for read-only attachments")]
@@ -878,6 +895,8 @@ pub enum RenderPassErrorInner {
location: AttachmentErrorLocation,
format: wgt::TextureFormat,
},
#[error("The {location} is not valid, because the texture has `TRANSIENT_ATTACHMENT` usage")]
InvalidTransientResolveTarget { location: AttachmentErrorLocation },
#[error("No color attachments or depth attachments were provided, at least one attachment of any kind must be provided")]
MissingAttachments,
#[error("The {location} is not renderable:")]
@@ -1054,6 +1073,7 @@ impl WebGpuError for RenderPassError {
RenderPassErrorInner::InvalidParentEncoder
| RenderPassErrorInner::UnsupportedResolveTargetFormat { .. }
| RenderPassErrorInner::InvalidTransientResolveTarget { .. }
| RenderPassErrorInner::MissingAttachments
| RenderPassErrorInner::TextureViewIsNotRenderable { .. }
| RenderPassErrorInner::AttachmentsDimensionMismatch { .. }
@@ -1546,6 +1566,15 @@ impl RenderPassInfo {
format: resolve_view.desc.format,
});
}
if resolve_view
.desc
.usage
.contains(TextureUsages::TRANSIENT_ATTACHMENT)
{
return Err(RenderPassErrorInner::InvalidTransientResolveTarget {
location: resolve_location,
});
}
texture_memory_actions.register_implicit_init(
&resolve_view.parent,
@@ -1766,6 +1795,13 @@ impl RenderPassInfo {
}
}
fn check_transient_attachment_ops<V>(load_op: LoadOp<V>, store_op: StoreOp) -> bool {
matches!(
(load_op, store_op),
(LoadOp::Clear(_) | LoadOp::DontCare(_), StoreOp::Discard)
)
}
impl Global {
/// Creates a render pass.
///
@@ -1816,7 +1852,6 @@ impl Global {
{
let view = texture_views.get(*view_id).get()?;
view.same_device(device)?;
if matches!(*load_op, LoadOp::DontCare(..))
&& device
.instance_flags
@@ -1827,15 +1862,16 @@ impl Global {
));
}
if view.desc.usage.contains(TextureUsages::TRANSIENT)
&& *store_op != StoreOp::Discard
if view
.desc
.usage
.contains(TextureUsages::TRANSIENT_ATTACHMENT)
&& !check_transient_attachment_ops(*load_op, *store_op)
{
return Err(RenderPassErrorInner::ColorAttachment(
ColorAttachmentError::InvalidUsageForStoreOp(
TextureUsages::TRANSIENT,
StoreOp::Discard,
*store_op,
),
ColorAttachmentError::InvalidTransientAttachmentOp((
*load_op, *store_op,
)),
));
}
@@ -1862,58 +1898,145 @@ impl Global {
}
}
arc_desc.depth_stencil_attachment =
// https://gpuweb.github.io/gpuweb/#abstract-opdef-gpurenderpassdepthstencilattachment-gpurenderpassdepthstencilattachment-valid-usage
if let Some(depth_stencil_attachment) = desc.depth_stencil_attachment.as_ref() {
let view = texture_views.get(depth_stencil_attachment.view).get()?;
view.same_device(device)?;
// https://gpuweb.github.io/gpuweb/#abstract-opdef-gpurenderpassdepthstencilattachment-gpurenderpassdepthstencilattachment-valid-usage
arc_desc.depth_stencil_attachment = if let Some(depth_stencil_attachment) =
desc.depth_stencil_attachment.as_ref()
{
let view = texture_views.get(depth_stencil_attachment.view).get()?;
view.same_device(device)?;
let format = view.desc.format;
if !format.is_depth_stencil_format() {
return Err(RenderPassErrorInner::InvalidAttachment(AttachmentError::InvalidDepthStencilAttachmentFormat(
view.desc.format,
)));
let format = view.desc.format;
if !format.is_depth_stencil_format() {
return Err(RenderPassErrorInner::InvalidAttachment(
AttachmentError::InvalidDepthStencilAttachmentFormat(view.desc.format),
));
}
if view
.desc
.usage
.contains(TextureUsages::TRANSIENT_ATTACHMENT)
{
// We raise errors here for transient depth/stencil attachments if they
// are read only, or use unsupported ops. `resolve` (called below)
// validates that operations are specified iff the attachment is not
// read-only.
if format.has_depth_aspect() {
match depth_stencil_attachment.depth {
PassChannel {
load_op: Some(load_op),
store_op: Some(store_op),
read_only: _,
} => {
if !check_transient_attachment_ops(load_op, store_op) {
return Err(RenderPassErrorInner::InvalidAttachment(
AttachmentError::InvalidTransientDepthAttachmentOps((
load_op, store_op,
)),
));
}
}
PassChannel {
read_only: true, ..
} => {
return Err(RenderPassErrorInner::InvalidAttachment(
AttachmentError::ReadOnlyTransientDepthAttachment,
))
}
_ => {}
}
}
Some(ResolvedRenderPassDepthStencilAttachment {
view,
depth: if format.has_depth_aspect() {
depth_stencil_attachment.depth.resolve(device.instance_flags, |clear| if let Some(clear) = clear {
// If this.depthLoadOp is "clear", this.depthClearValue must be provided and must be between 0.0 and 1.0, inclusive.
if !(0.0..=1.0).contains(&clear) {
Err(AttachmentError::ClearValueOutOfRange(clear))
} else {
Ok(clear)
if format.has_stencil_aspect() {
match depth_stencil_attachment.stencil {
PassChannel {
load_op: Some(load_op),
store_op: Some(store_op),
read_only: _,
} => {
if !check_transient_attachment_ops(load_op, store_op) {
return Err(RenderPassErrorInner::InvalidAttachment(
AttachmentError::InvalidTransientStencilAttachmentOps((
load_op, store_op,
)),
));
}
} else {
Err(AttachmentError::NoClearValue)
})?
} else {
if depth_stencil_attachment.depth.load_op.is_some() || depth_stencil_attachment.depth.store_op.is_some() {
return Err(RenderPassErrorInner::InvalidAttachment(AttachmentError::DepthOpsWithoutAspect {
format,
ops: (depth_stencil_attachment.depth.load_op, depth_stencil_attachment.depth.store_op)
}));
}
ResolvedPassChannel::ReadOnly
},
stencil: if format.has_stencil_aspect() {
depth_stencil_attachment.stencil.resolve(device.instance_flags, |clear| {
Ok(convert_stencil_value(clear.unwrap_or_default(), Some(format)))
})?
} else {
if depth_stencil_attachment.stencil.load_op.is_some() || depth_stencil_attachment.stencil.store_op.is_some() {
return Err(RenderPassErrorInner::InvalidAttachment(AttachmentError::StencilOpsWithoutAspect {
format,
ops: (depth_stencil_attachment.stencil.load_op, depth_stencil_attachment.stencil.store_op)
}));
PassChannel {
read_only: true, ..
} => {
return Err(RenderPassErrorInner::InvalidAttachment(
AttachmentError::ReadOnlyTransientStencilAttachment,
))
}
ResolvedPassChannel::ReadOnly
},
})
} else {
None
};
_ => {}
}
}
}
Some(ResolvedRenderPassDepthStencilAttachment {
view,
depth: if format.has_depth_aspect() {
depth_stencil_attachment
.depth
.resolve(device.instance_flags, |clear| {
if let Some(clear) = clear {
// If this.depthLoadOp is "clear", this.depthClearValue must be provided and must be between 0.0 and 1.0, inclusive.
if !(0.0..=1.0).contains(&clear) {
Err(AttachmentError::ClearValueOutOfRange(clear))
} else {
Ok(clear)
}
} else {
Err(AttachmentError::NoClearValue)
}
})?
} else {
if depth_stencil_attachment.depth.load_op.is_some()
|| depth_stencil_attachment.depth.store_op.is_some()
{
return Err(RenderPassErrorInner::InvalidAttachment(
AttachmentError::DepthOpsWithoutAspect {
format,
ops: (
depth_stencil_attachment.depth.load_op,
depth_stencil_attachment.depth.store_op,
),
},
));
}
ResolvedPassChannel::ReadOnly
},
stencil: if format.has_stencil_aspect() {
depth_stencil_attachment.stencil.resolve(
device.instance_flags,
|clear| {
Ok(convert_stencil_value(
clear.unwrap_or_default(),
Some(format),
))
},
)?
} else {
if depth_stencil_attachment.stencil.load_op.is_some()
|| depth_stencil_attachment.stencil.store_op.is_some()
{
return Err(RenderPassErrorInner::InvalidAttachment(
AttachmentError::StencilOpsWithoutAspect {
format,
ops: (
depth_stencil_attachment.stencil.load_op,
depth_stencil_attachment.stencil.store_op,
),
},
));
}
ResolvedPassChannel::ReadOnly
},
})
} else {
None
};
arc_desc.timestamp_writes = desc
.timestamp_writes
+2 -2
View File
@@ -131,7 +131,7 @@ pub fn map_texture_usage(
);
u.set(
wgt::TextureUses::TRANSIENT,
usage.contains(wgt::TextureUsages::TRANSIENT),
usage.contains(wgt::TextureUsages::TRANSIENT_ATTACHMENT),
);
u
}
@@ -193,7 +193,7 @@ pub fn map_texture_usage_from_hal(uses: wgt::TextureUses) -> wgt::TextureUsages
uses.contains(wgt::TextureUses::STORAGE_ATOMIC),
);
u.set(
wgt::TextureUsages::TRANSIENT,
wgt::TextureUsages::TRANSIENT_ATTACHMENT,
uses.contains(wgt::TextureUses::TRANSIENT),
);
u
+47 -10
View File
@@ -1400,6 +1400,16 @@ impl Device {
desc.format,
));
}
// Transient textures can only be 2D
if desc
.usage
.contains(wgt::TextureUsages::TRANSIENT_ATTACHMENT)
{
return Err(CreateTextureError::InvalidDimensionUsages(
wgt::TextureUsages::TRANSIENT_ATTACHMENT,
desc.dimension,
));
}
}
if desc.dimension != wgt::TextureDimension::D2
@@ -1503,20 +1513,32 @@ impl Device {
}
}
if desc.usage.contains(wgt::TextureUsages::TRANSIENT) {
if !desc.usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) {
return Err(CreateTextureError::InvalidUsage(
wgt::TextureUsages::TRANSIENT,
if desc
.usage
.contains(wgt::TextureUsages::TRANSIENT_ATTACHMENT)
{
if desc.usage
!= (wgt::TextureUsages::TRANSIENT_ATTACHMENT
| wgt::TextureUsages::RENDER_ATTACHMENT)
{
return Err(CreateTextureError::InvalidTransientTextureUsage(desc.usage));
}
if desc.mip_level_count != 1 {
return Err(CreateTextureError::InvalidTransientTextureMipLevelCount(
desc.mip_level_count,
));
}
let extra_usage =
desc.usage - wgt::TextureUsages::TRANSIENT - wgt::TextureUsages::RENDER_ATTACHMENT;
if !extra_usage.is_empty() {
return Err(CreateTextureError::IncompatibleUsage(
wgt::TextureUsages::TRANSIENT,
extra_usage,
if desc.size.depth_or_array_layers != 1 {
return Err(CreateTextureError::InvalidTransientTextureLayerCount(
desc.size.depth_or_array_layers,
));
}
if !desc.view_formats.is_empty() {
return Err(CreateTextureError::InvalidTransientTextureViewFormats);
}
}
let format_features = self
@@ -1787,6 +1809,21 @@ impl Device {
if usage.is_empty() {
texture.desc.usage
} else if texture.desc.usage.contains(usage) {
// Transient texture usage subsetting is disallowed
if texture
.desc
.usage
.contains(wgt::TextureUsages::TRANSIENT_ATTACHMENT)
&& texture.desc.usage != usage
{
return Err(
resource::CreateTextureViewError::InvalidTransientTextureViewUsage {
texture: texture.desc.usage,
view: usage,
},
);
}
usage
} else {
return Err(resource::CreateTextureViewError::InvalidTextureViewUsage {
+1 -1
View File
@@ -763,7 +763,7 @@ impl Adapter {
),
);
allowed_usages.set(
wgt::TextureUsages::RENDER_ATTACHMENT | wgt::TextureUsages::TRANSIENT,
wgt::TextureUsages::RENDER_ATTACHMENT | wgt::TextureUsages::TRANSIENT_ATTACHMENT,
caps.intersects(Tfc::COLOR_ATTACHMENT | Tfc::DEPTH_STENCIL_ATTACHMENT),
);
allowed_usages.set(
+1 -1
View File
@@ -325,7 +325,7 @@ mod tests {
backend: wgt::Backend::Vulkan,
subgroup_min_size: 32,
subgroup_max_size: 32,
transient_saves_memory: true,
transient_saves_memory: Some(true),
limit_bucket: None,
};
+20 -3
View File
@@ -1689,8 +1689,6 @@ pub enum CreateTextureError {
CreateTextureView(#[from] CreateTextureViewError),
#[error("Invalid usage flags {0:?}")]
InvalidUsage(wgt::TextureUsages),
#[error("Texture usage {0:?} is not compatible with texture usage {1:?}")]
IncompatibleUsage(wgt::TextureUsages, wgt::TextureUsages),
#[error(transparent)]
InvalidDimension(#[from] TextureDimensionError),
#[error("Depth texture ({1:?}) can't be created as {0:?}")]
@@ -1708,6 +1706,10 @@ pub enum CreateTextureError {
InvalidFormatUsages(wgt::TextureUsages, wgt::TextureFormat, bool),
#[error("The view format {0:?} is not compatible with texture format {1:?}, only changing srgb-ness is allowed.")]
InvalidViewFormat(wgt::TextureFormat, wgt::TextureFormat),
#[error("Transient texture usage must be equal to `TRANSIENT_ATTACHMENT | RENDER_ATTACHMENT`, but got `{0:?}`")]
InvalidTransientTextureUsage(wgt::TextureUsages),
#[error("Transient texture view formats must be empty")]
InvalidTransientTextureViewFormats,
#[error("Texture usages {0:?} are not allowed on a texture of dimensions {1:?}")]
InvalidDimensionUsages(wgt::TextureUsages, wgt::TextureDimension),
#[error("Texture usage STORAGE_BINDING is not allowed for multisampled textures")]
@@ -1718,6 +1720,10 @@ pub enum CreateTextureError {
InvalidSampleCount(u32, wgt::TextureFormat, Vec<u32>, Vec<u32>),
#[error("Multisampled textures must have RENDER_ATTACHMENT usage")]
MultisampledNotRenderAttachment,
#[error("Transient texture mip level count ({0}) must be 1")]
InvalidTransientTextureMipLevelCount(u32),
#[error("Transient texture layer count ({0}) must be 1")]
InvalidTransientTextureLayerCount(u32),
#[error("Texture format {0:?} can't be used due to missing features")]
MissingFeatures(wgt::TextureFormat, #[source] MissingFeatures),
#[error(transparent)]
@@ -1746,7 +1752,6 @@ impl WebGpuError for CreateTextureError {
Self::MissingDownlevelFlags(e) => e.webgpu_error_type(),
Self::InvalidUsage(_)
| Self::IncompatibleUsage(_, _)
| Self::InvalidDepthDimension(_, _)
| Self::InvalidCompressedDimension(_, _)
| Self::InvalidMipLevelCount { .. }
@@ -1756,6 +1761,10 @@ impl WebGpuError for CreateTextureError {
| Self::InvalidMultisampledStorageBinding
| Self::InvalidMultisampledFormat(_)
| Self::InvalidSampleCount(..)
| Self::InvalidTransientTextureUsage(_)
| Self::InvalidTransientTextureMipLevelCount(_)
| Self::InvalidTransientTextureLayerCount(_)
| Self::InvalidTransientTextureViewFormats
| Self::MultisampledNotRenderAttachment => ErrorType::Validation,
}
}
@@ -1956,6 +1965,13 @@ pub enum CreateTextureViewError {
texture: wgt::TextureFormat,
view: wgt::TextureFormat,
},
#[error(
"The texture view (`{view:?}`) from transient texture (`{texture:?}`) must have the same usage"
)]
InvalidTransientTextureViewUsage {
texture: wgt::TextureUsages,
view: wgt::TextureUsages,
},
#[error(transparent)]
InvalidResource(#[from] InvalidResourceError),
#[error(transparent)]
@@ -1984,6 +2000,7 @@ impl WebGpuError for CreateTextureViewError {
| Self::TextureViewFormatNotRenderable(_)
| Self::TextureViewFormatNotStorage(_)
| Self::InvalidTextureViewUsage { .. }
| Self::InvalidTransientTextureViewUsage { .. }
| Self::MissingFeatures(_) => ErrorType::Validation,
}
}
+1 -1
View File
@@ -207,7 +207,7 @@ impl super::Adapter {
driver_info: String::new(),
subgroup_min_size: features1.WaveLaneCountMin,
subgroup_max_size: features1.WaveLaneCountMax,
transient_saves_memory: false,
transient_saves_memory: Some(false),
limit_bucket: None,
};
+1 -1
View File
@@ -432,7 +432,7 @@ impl AdapterShared {
// for more information.
subgroup_min_size: 4,
subgroup_max_size: 64,
transient_saves_memory: shared.private_caps.supports_memoryless_storage,
transient_saves_memory: Some(shared.private_caps.supports_memoryless_storage),
..wgt::AdapterInfo::new(shared.private_caps.device_type(), wgt::Backend::Metal)
},
features,
+1 -1
View File
@@ -2187,7 +2187,7 @@ impl super::Instance {
.subgroup_size_control
.map(|subgroup_size| subgroup_size.max_subgroup_size)
.unwrap_or(wgt::MAXIMUM_SUBGROUP_MAX_SIZE),
transient_saves_memory: supports_lazily_allocated,
transient_saves_memory: Some(supports_lazily_allocated),
..wgt::AdapterInfo::new(device_type, wgt::Backend::Vulkan)
};
let mut workarounds = super::Workarounds::empty();
+1 -1
View File
@@ -122,7 +122,7 @@ fn print_adapter(output: &mut impl io::Write, report: &AdapterReport, idx: usize
writeln!(output, "\t Driver Info: {}", print_empty_string(driver_info))?;
writeln!(output, "\t Subgroup Min Size: {subgroup_min_size}")?;
writeln!(output, "\t Subgroup Max Size: {subgroup_max_size}")?;
writeln!(output, "\tTransient Saves Memory: {transient_saves_memory}")?;
writeln!(output, "\tTransient Saves Memory: {transient_saves_memory:?}")?;
writeln!(output, "\t Limit Bucket: {}", limit_bucket.as_ref().map_or("<disabled>", |b| &b.name))?;
writeln!(output, "\t WebGPU Compliant: {:?}", downlevel.is_webgpu_compliant())?;
+4 -3
View File
@@ -209,8 +209,9 @@ pub struct AdapterInfo {
/// - WARP: 4 or 128
/// - lavapipe: 8
pub subgroup_max_size: u32,
/// If true, adding [`TextureUsages::TRANSIENT`] to a texture will decrease memory usage.
pub transient_saves_memory: bool,
/// Whether adding [`TextureUsages::TRANSIENT_ATTACHMENT`] to a texture will decrease memory usage.
/// This is None on web, which means it is unknown from the adapter.
pub transient_saves_memory: Option<bool>,
/// If limit bucketing was requested, contains the name of the applied
/// bucket and the original capabilities of the adapter.
@@ -233,7 +234,7 @@ impl AdapterInfo {
backend,
subgroup_min_size: crate::MINIMUM_SUBGROUP_MIN_SIZE,
subgroup_max_size: crate::MAXIMUM_SUBGROUP_MAX_SIZE,
transient_saves_memory: false,
transient_saves_memory: None,
limit_bucket: None,
}
}
+11 -10
View File
@@ -186,9 +186,19 @@ bitflags::bitflags! {
const STORAGE_BINDING = 1 << 3;
/// Allows a texture to be an output attachment of a render pass.
///
/// Consider adding [`TextureUsages::TRANSIENT`] if the contents are not reused.
/// Consider adding [`TextureUsages::TRANSIENT_ATTACHMENT`] if the contents are not reused.
const RENDER_ATTACHMENT = 1 << 4;
/// Specifies the contents of this texture will not be used in another pass to potentially reduce memory usage and bandwidth.
///
/// No-op on platforms on platforms that do not benefit from transient textures.
/// Generally mobile and Apple chips care about this.
///
/// Incompatible with ALL other usages except [`TextureUsages::RENDER_ATTACHMENT`] and requires it.
///
/// Requires [`LoadOp::Clear`] or [`LoadOp::DontCare`] (if it is available) and [`StoreOp::Discard`].
const TRANSIENT_ATTACHMENT = 1 << 5;
//
// ---- Restart Numbering for Native Features ---
//
@@ -196,15 +206,6 @@ bitflags::bitflags! {
//
/// Allows a texture to be used with image atomics. Requires [`Features::TEXTURE_ATOMIC`].
const STORAGE_ATOMIC = 1 << 16;
/// Specifies the contents of this texture will not be used in another pass to potentially reduce memory usage and bandwidth.
///
/// No-op on platforms on platforms that do not benefit from transient textures.
/// Generally mobile and Apple chips care about this.
///
/// Incompatible with ALL other usages except [`TextureUsages::RENDER_ATTACHMENT`] and requires it.
///
/// Requires [`StoreOp::Discard`].
const TRANSIENT = 1 << 17;
}
}
+2 -1
View File
@@ -924,7 +924,8 @@ impl TextureFormat {
// Flags
let basic =
TextureUsages::COPY_SRC | TextureUsages::COPY_DST | TextureUsages::TEXTURE_BINDING;
let attachment = basic | TextureUsages::RENDER_ATTACHMENT | TextureUsages::TRANSIENT;
let attachment =
basic | TextureUsages::RENDER_ATTACHMENT | TextureUsages::TRANSIENT_ATTACHMENT;
let storage = basic | TextureUsages::STORAGE_BINDING;
let binding = TextureUsages::TEXTURE_BINDING;
let all_flags = attachment | storage | binding;
+2 -2
View File
@@ -897,7 +897,7 @@ fn map_adapter_info(adapter_info: &webgpu_sys::GpuAdapterInfo) -> wgt::AdapterIn
backend: wgt::Backend::BrowserWebGpu,
subgroup_min_size: adapter_info.subgroup_min_size(),
subgroup_max_size: adapter_info.subgroup_max_size(),
transient_saves_memory: false,
transient_saves_memory: None,
limit_bucket: None,
}
}
@@ -2373,7 +2373,7 @@ impl dispatch::DeviceInterface for WebDevice {
let mapped_desc = webgpu_sys::GpuTextureDescriptor::new_with_gpu_extent_3d_dict(
map_texture_format(desc.format),
&map_extent_3d(desc.size),
(desc.usage - crate::TextureUsages::TRANSIENT).bits(),
desc.usage.bits(),
);
if let Some(label) = desc.label {
mapped_desc.set_label(label);