Skip to content

Commit 127cbab

Browse files
committed
CLEAR_COMMANDS extension is now more of a window into wgpu zero-init
this has mostly implications on the constraints, but also allows a more leaky documentation which makes sense for this non-standard function as there is no other place to look it up
1 parent 6fc0587 commit 127cbab

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

wgpu-core/src/command/clear.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum ClearError {
4141
end_offset: BufferAddress,
4242
buffer_size: BufferAddress,
4343
},
44-
#[error("destination buffer/texture is missing the `COPY_DST` usage flag")]
44+
#[error("destination buffer is missing the `COPY_DST` usage flag")]
4545
MissingCopyDstUsageFlag(Option<BufferId>, Option<TextureId>),
4646
#[error("texture lacks the aspects that were specified in the image subresource range. Texture with format {texture_format:?}, specified was {subresource_range_aspects:?}")]
4747
MissingTextureAspect {
@@ -250,9 +250,6 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
250250
.inner
251251
.as_raw()
252252
.ok_or(ClearError::InvalidTexture(dst))?;
253-
if !dst_texture.desc.usage.contains(TextureUsages::COPY_DST) {
254-
return Err(ClearError::MissingCopyDstUsageFlag(None, Some(dst)));
255-
}
256253

257254
// actual hal barrier & operation
258255
let dst_barrier = dst_pending.map(|pending| pending.into_hal(dst_texture));

wgpu/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,12 +2337,16 @@ impl CommandEncoder {
23372337

23382338
/// Clears texture to zero.
23392339
///
2340-
/// Where possible it may be significantly more efficient to perform clears via render passes!
2340+
/// Note that unlike with clear_buffer, `COPY_DST` usage is not required.
2341+
///
2342+
/// # Implementation notes
2343+
///
2344+
/// - implemented either via buffer copies, render/depth target clear
2345+
/// - behaves like texture zero init, but is performed immediately (clearing is *not* delayed via marking it as uninitialized)
23412346
///
23422347
/// # Panics
23432348
///
23442349
/// - `CLEAR_COMMANDS` extension not enabled
2345-
/// - Texture does not have `COPY_DST` usage.
23462350
/// - Range is out of bounds
23472351
pub fn clear_texture(&mut self, texture: &Texture, subresource_range: &ImageSubresourceRange) {
23482352
Context::command_encoder_clear_texture(
@@ -2355,6 +2359,12 @@ impl CommandEncoder {
23552359

23562360
/// Clears buffer to zero.
23572361
///
2362+
/// # Implementation notes
2363+
///
2364+
/// - implemented via backend specific function which may be emulated with buffer copies
2365+
/// - behaves like delayed buffer zero init (i.e. lazy zero init for buffers that weren't mapped at creation),
2366+
/// but is performed immediately (clearing is *not* delayed via marking it as uninitialized)
2367+
///
23582368
/// # Panics
23592369
///
23602370
/// - `CLEAR_COMMANDS` extension not enabled

wgpu/tests/clear_texture.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ fn single_texture_clear_test(
131131
sample_count: 1, // multisampling is not supported for clear
132132
dimension,
133133
format,
134-
usage: wgpu::TextureUsages::COPY_DST,
134+
// Forces internally the required usages to be able to clear it.
135+
// This is not visible on the API level.
136+
usage: wgpu::TextureUsages::TEXTURE_BINDING,
135137
});
136138
let mut encoder = ctx
137139
.device

0 commit comments

Comments
 (0)