Don't require COPY_DST on surface textures

This commit is contained in:
Dzmitry Malyshau 2021-10-31 00:37:14 -04:00
parent 8e5b1f281e
commit 1b33d996a0
3 changed files with 9 additions and 8 deletions

View File

@ -300,9 +300,6 @@ impl<A: hal::Api> BakedCommands<A> {
.as_raw()
.ok_or(DestroyedTextureError(texture_use.id))?;
debug_assert!(texture.hal_usage.contains(hal::TextureUses::COPY_DST),
"Every texture needs to have the COPY_DST flag. Otherwise we can't ensure initialized memory!");
let mut texture_barriers = Vec::new();
let mut zero_buffer_copy_regions = Vec::new();
for range in &ranges {
@ -332,6 +329,8 @@ impl<A: hal::Api> BakedCommands<A> {
}
if !zero_buffer_copy_regions.is_empty() {
debug_assert!(texture.hal_usage.contains(hal::TextureUses::COPY_DST),
"Texture needs to have the COPY_DST flag. Otherwise we can't ensure initialized memory!");
unsafe {
// TODO: Could safe on transition_textures calls by bundling barriers from *all* textures.
// (a bbit more tricky because a naive approach would have to borrow same texture several times then)

View File

@ -65,9 +65,7 @@ pub fn map_texture_usage(
usage: wgt::TextureUsages,
aspect: hal::FormatAspects,
) -> hal::TextureUses {
// Enforce COPY_DST, otherwise we wouldn't be able to initialize the texture.
let mut u = hal::TextureUses::COPY_DST;
let mut u = hal::TextureUses::empty();
u.set(
hal::TextureUses::COPY_SRC,
usage.contains(wgt::TextureUsages::COPY_SRC),

View File

@ -625,7 +625,9 @@ impl<A: HalApi> Device<A> {
adapter: &crate::instance::Adapter<A>,
desc: &resource::TextureDescriptor,
) -> Result<resource::Texture<A>, resource::CreateTextureError> {
let hal_usage = conv::map_texture_usage(desc.usage, desc.format.into());
// Enforce COPY_DST, otherwise we wouldn't be able to initialize the texture.
let hal_usage =
conv::map_texture_usage(desc.usage, desc.format.into()) | hal::TextureUses::COPY_DST;
let hal_desc = hal::TextureDescriptor {
label: desc.label.borrow_option(),
@ -685,7 +687,9 @@ impl<A: HalApi> Device<A> {
.map_err(DeviceError::from)?
};
Ok(self.create_texture_from_hal(raw, self_id, desc, format_features))
let mut texture = self.create_texture_from_hal(raw, self_id, desc, format_features);
texture.hal_usage = hal_usage;
Ok(texture)
}
fn create_texture_view(