Skip to content

Commit

Permalink
[valid] avoid OOM with large sparse resource bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy authored and jimblandy committed Oct 16, 2023
1 parent 9eb3a1d commit 841d360
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 2 additions & 8 deletions src/valid/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,6 @@ impl super::Validator {
return Err(EntryPointError::MissingVertexOutputPosition.with_span());
}

for bg in self.bind_group_masks.iter_mut() {
bg.clear();
}

#[cfg(feature = "validate")]
{
let used_push_constants = module
Expand All @@ -728,6 +724,7 @@ impl super::Validator {
}
}

self.ep_resource_bindings.clear();
#[cfg(feature = "validate")]
for (var_handle, var) in module.global_variables.iter() {
let usage = info[var_handle];
Expand Down Expand Up @@ -768,10 +765,7 @@ impl super::Validator {
}

if let Some(ref bind) = var.binding {
while self.bind_group_masks.len() <= bind.group as usize {
self.bind_group_masks.push(BitSet::new());
}
if !self.bind_group_masks[bind.group as usize].insert(bind.binding as usize) {
if !self.ep_resource_bindings.insert(bind.clone()) {
if self.flags.contains(super::ValidationFlags::BINDINGS) {
return Err(EntryPointError::BindingCollision(var_handle)
.with_span_handle(var_handle, &module.global_variables));
Expand Down
6 changes: 3 additions & 3 deletions src/valid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub struct Validator {
types: Vec<r#type::TypeInfo>,
layouter: Layouter,
location_mask: BitSet,
bind_group_masks: Vec<BitSet>,
ep_resource_bindings: FastHashSet<crate::ResourceBinding>,
#[allow(dead_code)]
switch_values: FastHashSet<crate::SwitchValue>,
valid_expression_list: Vec<Handle<crate::Expression>>,
Expand Down Expand Up @@ -290,7 +290,7 @@ impl Validator {
types: Vec::new(),
layouter: Layouter::default(),
location_mask: BitSet::new(),
bind_group_masks: Vec::new(),
ep_resource_bindings: FastHashSet::default(),
switch_values: FastHashSet::default(),
valid_expression_list: Vec::new(),
valid_expression_set: BitSet::new(),
Expand All @@ -302,7 +302,7 @@ impl Validator {
self.types.clear();
self.layouter.clear();
self.location_mask.clear();
self.bind_group_masks.clear();
self.ep_resource_bindings.clear();
self.switch_values.clear();
self.valid_expression_list.clear();
self.valid_expression_set.clear();
Expand Down

0 comments on commit 841d360

Please sign in to comment.