mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Coalesce bindings into a single write
This commit is contained in:
parent
962e4dbaf7
commit
0070bf703c
@ -30,7 +30,13 @@ use thiserror::Error;
|
|||||||
use wgt::{BufferAddress, BufferSize, InputStepMode, TextureDimension, TextureFormat};
|
use wgt::{BufferAddress, BufferSize, InputStepMode, TextureDimension, TextureFormat};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
borrow::Cow, collections::hash_map::Entry, iter, marker::PhantomData, mem, ops::Range, ptr,
|
borrow::Cow,
|
||||||
|
collections::{hash_map::Entry, BTreeMap},
|
||||||
|
iter,
|
||||||
|
marker::PhantomData,
|
||||||
|
mem,
|
||||||
|
ops::Range,
|
||||||
|
ptr,
|
||||||
sync::atomic::Ordering,
|
sync::atomic::Ordering,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1947,9 +1953,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
|||||||
let (texture_view_guard, mut token) = hub.texture_views.read(&mut token);
|
let (texture_view_guard, mut token) = hub.texture_views.read(&mut token);
|
||||||
let (sampler_guard, _) = hub.samplers.read(&mut token);
|
let (sampler_guard, _) = hub.samplers.read(&mut token);
|
||||||
|
|
||||||
//TODO: group writes into contiguous sections
|
// `BTreeMap` has ordered bindings as keys, which allows us to coalesce
|
||||||
let mut write_map =
|
// the descriptor writes into a single transaction.
|
||||||
FastHashMap::with_capacity_and_hasher(desc.entries.len(), Default::default());
|
let mut write_map = BTreeMap::new();
|
||||||
for entry in desc.entries.iter() {
|
for entry in desc.entries.iter() {
|
||||||
let binding = entry.binding;
|
let binding = entry.binding;
|
||||||
// Find the corresponding declaration in the layout
|
// Find the corresponding declaration in the layout
|
||||||
@ -2220,17 +2226,20 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let writes = write_map
|
if let Some(start_binding) = write_map.keys().next().cloned() {
|
||||||
.into_iter()
|
let descriptors = write_map
|
||||||
.map(|(binding, descriptors)| hal::pso::DescriptorSetWrite {
|
.into_iter()
|
||||||
|
.flat_map(|(_, list)| list)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
let write = hal::pso::DescriptorSetWrite {
|
||||||
set: desc_set.raw(),
|
set: desc_set.raw(),
|
||||||
binding,
|
binding: start_binding,
|
||||||
array_offset: 0,
|
array_offset: 0,
|
||||||
descriptors,
|
descriptors,
|
||||||
})
|
};
|
||||||
.collect::<Vec<_>>();
|
unsafe {
|
||||||
unsafe {
|
device.raw.write_descriptor_sets(iter::once(write));
|
||||||
device.raw.write_descriptor_sets(writes);
|
}
|
||||||
}
|
}
|
||||||
desc_set
|
desc_set
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user