990: Simplify descriptor writes r=cwfitzgerald a=kvark

**Connections**
Reverts #980 and #970
Takes advantage of https://github.com/gfx-rs/gfx/pull/3410

**Description**
Weighting all the pros and cons, I figured it's easier to adjust the Vulkan backend a little than treating it as a lowest common denominator for this issue.

**Testing**
Tested on wgpu-rs examples (on Vulkan).

Co-authored-by: Dzmitry Malyshau <kvark@fastmail.com>
This commit is contained in:
bors[bot]
2020-10-15 20:19:20 +00:00
committed by GitHub
4 changed files with 22 additions and 30 deletions

4
Cargo.lock generated
View File

@@ -500,9 +500,9 @@ dependencies = [
[[package]]
name = "gfx-backend-vulkan"
version = "0.6.1"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a84bda4200a82e1912d575801e2bb76ae19c6256359afbc0adfbbaec02fcadc6"
checksum = "26d6c5b718953362f4252575a9d77c22bd73eb8308e7b3af8237deace565e7ca"
dependencies = [
"arrayvec",
"ash",

View File

@@ -50,15 +50,15 @@ version = "0.6"
[target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies]
gfx-backend-metal = { version = "0.6" }
gfx-backend-vulkan = { version = "0.6", optional = true }
gfx-backend-vulkan = { version = "0.6.4", optional = true }
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
gfx-backend-vulkan = { version = "0.6.1" }
gfx-backend-vulkan = { version = "0.6.4" }
[target.'cfg(windows)'.dependencies]
gfx-backend-dx12 = { version = "0.6" }
gfx-backend-dx11 = { version = "0.6" }
gfx-backend-vulkan = { version = "0.6" }
gfx-backend-vulkan = { version = "0.6.4" }
[dev-dependencies]
loom = "0.3"

View File

@@ -702,13 +702,13 @@ impl<B: GfxBackend> Device<B> {
.map_or(1, |v| v.get() as hal::pso::DescriptorArrayIndex), //TODO: consolidate
stage_flags: conv::map_shader_stage_flags(entry.visibility),
immutable_samplers: false, // TODO
});
let desc_counts = raw_bindings.clone().collect();
})
.collect::<Vec<_>>(); //TODO: avoid heap allocation
let raw = unsafe {
let mut raw_layout = self
.raw
.create_descriptor_set_layout(raw_bindings, &[])
.create_descriptor_set_layout(&raw_bindings, &[])
.or(Err(DeviceError::OutOfMemory))?;
if let Some(label) = label {
self.raw
@@ -734,7 +734,7 @@ impl<B: GfxBackend> Device<B> {
ref_count: self.life_guard.add_ref(),
},
multi_ref_count: MultiRefCount::new(),
desc_counts,
desc_counts: raw_bindings.iter().cloned().collect(),
dynamic_count: entry_map
.values()
.filter(|b| b.ty.has_dynamic_offset())
@@ -2358,27 +2358,19 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
}
}
if !write_map.is_empty() {
let mut writes = Vec::<hal::pso::DescriptorSetWrite<_, SmallVec<[_; 1]>>>::new();
let mut prev_stages = wgt::ShaderStage::empty();
let mut prev_ty = wgt::BindingType::Sampler { comparison: false }; // doesn't matter
for (binding, list) in write_map {
let layout = &bind_group_layout.entries[&binding];
if layout.visibility == prev_stages && layout.ty == prev_ty {
writes.last_mut().unwrap().descriptors.extend(list);
} else {
prev_stages = layout.visibility;
prev_ty = layout.ty;
writes.push(hal::pso::DescriptorSetWrite {
set: desc_set.raw(),
binding,
array_offset: 0,
descriptors: list,
});
}
}
if let Some(start_binding) = write_map.keys().next().cloned() {
let descriptors = write_map
.into_iter()
.flat_map(|(_, list)| list)
.collect::<Vec<_>>();
let write = hal::pso::DescriptorSetWrite {
set: desc_set.raw(),
binding: start_binding,
array_offset: 0,
descriptors,
};
unsafe {
device.raw.write_descriptor_sets(writes);
device.raw.write_descriptor_sets(iter::once(write));
}
}
desc_set

View File

@@ -1720,7 +1720,7 @@ pub struct TextureDataLayout {
/// Specific type of a binding.
///
/// WebGPU spec: https://gpuweb.github.io/gpuweb/#dictdef-gpubindgrouplayoutentry
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "trace", derive(Serialize))]
#[cfg_attr(feature = "replay", derive(Deserialize))]
pub enum BindingType {