Skip to content

Commit 625bf3b

Browse files
committed
Remove Feature::TRANSIENT_ATTACHMENTS and add validation
1 parent 2185cd8 commit 625bf3b

File tree

8 files changed

+30
-20
lines changed

8 files changed

+30
-20
lines changed

wgpu-core/src/command/render.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,8 @@ pub enum ColorAttachmentError {
625625
mip_level: u32,
626626
depth_or_array_layer: u32,
627627
},
628+
#[error("Color attachment's usage cannot contain {0:?} if StoreOp is {1:?}")]
629+
InvalidUsageForStoreOp(TextureUsages, StoreOp),
628630
}
629631

630632
impl WebGpuError for ColorAttachmentError {
@@ -1585,6 +1587,17 @@ impl Global {
15851587
let view = texture_views.get(*view_id).get()?;
15861588
view.same_device(device)?;
15871589

1590+
if view.desc.usage.contains(TextureUsages::TRANSIENT)
1591+
&& *store_op != StoreOp::Discard
1592+
{
1593+
return Err(RenderPassErrorInner::ColorAttachment(
1594+
ColorAttachmentError::InvalidUsageForStoreOp(
1595+
TextureUsages::TRANSIENT,
1596+
*store_op,
1597+
),
1598+
));
1599+
}
1600+
15881601
let resolve_target = if let Some(resolve_target_id) = resolve_target {
15891602
let rt_arc = texture_views.get(*resolve_target_id).get()?;
15901603
rt_arc.same_device(device)?;

wgpu-core/src/device/resource.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,17 @@ impl Device {
12621262
}
12631263
}
12641264

1265+
if desc.usage.contains(wgt::TextureUsages::TRANSIENT) {
1266+
let extra_usage =
1267+
desc.usage - wgt::TextureUsages::TRANSIENT - wgt::TextureUsages::RENDER_ATTACHMENT;
1268+
if !extra_usage.is_empty() {
1269+
return Err(CreateTextureError::IncompatibleUsage(
1270+
wgt::TextureUsages::TRANSIENT,
1271+
extra_usage,
1272+
));
1273+
}
1274+
}
1275+
12651276
let format_features = self
12661277
.describe_format_features(desc.format)
12671278
.map_err(|error| CreateTextureError::MissingFeatures(desc.format, error))?;
@@ -4464,10 +4475,6 @@ impl Device {
44644475
{
44654476
format_features.flags.set(tfsc::FILTERABLE, false);
44664477
}
4467-
format_features.allowed_usages.set(
4468-
wgt::TextureUsages::TRANSIENT,
4469-
self.features.contains(wgt::Features::TRANSIENT_ATTACHMENTS),
4470-
);
44714478
format_features
44724479
}
44734480

wgpu-core/src/instance.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ impl Adapter {
706706
wgt::TextureUsages::STORAGE_ATOMIC,
707707
caps.contains(Tfc::STORAGE_ATOMIC),
708708
);
709+
allowed_usages |= wgt::TextureUsages::TRANSIENT;
709710

710711
let mut flags = wgt::TextureFormatFeatureFlags::empty();
711712
flags.set(

wgpu-core/src/resource.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,8 @@ pub enum CreateTextureError {
15091509
CreateTextureView(#[from] CreateTextureViewError),
15101510
#[error("Invalid usage flags {0:?}")]
15111511
InvalidUsage(wgt::TextureUsages),
1512+
#[error("Texture usage {0:?} is not compatible with texture usage {1:?}")]
1513+
IncompatibleUsage(wgt::TextureUsages, wgt::TextureUsages),
15121514
#[error(transparent)]
15131515
InvalidDimension(#[from] TextureDimensionError),
15141516
#[error("Depth texture ({1:?}) can't be created as {0:?}")]
@@ -1564,6 +1566,7 @@ impl WebGpuError for CreateTextureError {
15641566
Self::MissingDownlevelFlags(e) => e,
15651567

15661568
Self::InvalidUsage(_)
1569+
| Self::IncompatibleUsage(_, _)
15671570
| Self::InvalidDepthDimension(_, _)
15681571
| Self::InvalidCompressedDimension(_, _)
15691572
| Self::InvalidMipLevelCount { .. }

wgpu-hal/src/metal/adapter.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,8 +1002,6 @@ impl super::PrivateCapabilities {
10021002
features.insert(F::SUBGROUP | F::SUBGROUP_BARRIER);
10031003
}
10041004

1005-
features.set(F::TRANSIENT_ATTACHMENTS, self.supports_memoryless_storage);
1006-
10071005
features
10081006
}
10091007

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,7 @@ impl PhysicalDeviceFeatures {
560560
| F::PIPELINE_CACHE
561561
| F::SHADER_EARLY_DEPTH_TEST
562562
| F::TEXTURE_ATOMIC
563-
| F::EXPERIMENTAL_PASSTHROUGH_SHADERS
564-
| F::TRANSIENT_ATTACHMENTS;
563+
| F::EXPERIMENTAL_PASSTHROUGH_SHADERS;
565564

566565
let mut dl_flags = Df::COMPUTE_SHADERS
567566
| Df::BASE_VERTEX

wgpu-types/src/features.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,17 +1231,6 @@ bitflags_array! {
12311231
///
12321232
/// [`Device::create_shader_module_passthrough`]: https://docs.rs/wgpu/latest/wgpu/struct.Device.html#method.create_shader_module_passthrough
12331233
const EXPERIMENTAL_PASSTHROUGH_SHADERS = 1 << 52;
1234-
1235-
/// Allows transient attachments to be created with [`TextureUsages::TRANSIENT`]
1236-
///
1237-
/// Supported platforms
1238-
/// - Vulkan
1239-
/// - Metal
1240-
///
1241-
/// This is a native only feature
1242-
///
1243-
/// [`TextureUsages::TRANSIENT`]: super::TextureUsages::TRANSIENT
1244-
const TRANSIENT_ATTACHMENTS = 1 << 53;
12451234
}
12461235

12471236
/// Features that are not guaranteed to be supported.

wgpu-types/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5610,7 +5610,7 @@ bitflags::bitflags! {
56105610
//
56115611
/// Allows a texture to be used with image atomics. Requires [`Features::TEXTURE_ATOMIC`].
56125612
const STORAGE_ATOMIC = 1 << 16;
5613-
/// Allows a texture to be transient. Requires [`Features::TRANSIENT_ATTACHMENTS`].
5613+
/// Allows a texture to be transient. No-op on platforms other than Vulkan and Metal.
56145614
const TRANSIENT = 1 << 17;
56155615
}
56165616
}

0 commit comments

Comments
 (0)