Handle zero-sized bindings as an error

This commit is contained in:
Dzmitry Malyshau
2021-01-25 22:33:44 -05:00
parent c2c8d2203e
commit c233a70afc
3 changed files with 13 additions and 1 deletions

View File

@@ -58,11 +58,18 @@ pub enum CreateBindGroupError {
BindingArrayLengthMismatch { actual: usize, expected: usize },
#[error("bound buffer range {range:?} does not fit in buffer of size {size}")]
BindingRangeTooLarge {
buffer: BufferId,
range: Range<wgt::BufferAddress>,
size: u64,
},
#[error("buffer binding size {actual} is less than minimum {min}")]
BindingSizeTooSmall { actual: u64, min: u64 },
BindingSizeTooSmall {
buffer: BufferId,
actual: u64,
min: u64,
},
#[error("buffer binding size is zero")]
BindingZeroSize(BufferId),
#[error("number of bindings in bind group descriptor ({actual}) does not match the number of bindings defined in the bind group layout ({expected})")]
BindingsNumMismatch { actual: usize, expected: usize },
#[error("binding {0} is used at least twice in the descriptor")]

View File

@@ -870,6 +870,7 @@ impl<'a, B: GfxBackend> RenderPassInfo<'a, B> {
TextureViewInner::SwapChain { ref image, .. } => Borrow::borrow(image),
});
//Note: the order of iteration has to match `AttachmentData::all()`
let attachments = color_attachments
.iter()
.zip(&rp_key.colors)

View File

@@ -1296,6 +1296,7 @@ impl<B: GfxBackend> Device<B> {
let end = bb.offset + size.get();
if end > buffer.size {
return Err(Error::BindingRangeTooLarge {
buffer: bb.buffer_id,
range: bb.offset..end,
size: buffer.size,
});
@@ -1322,10 +1323,13 @@ impl<B: GfxBackend> Device<B> {
let min_size = non_zero.get();
if min_size > bind_size {
return Err(Error::BindingSizeTooSmall {
buffer: bb.buffer_id,
actual: bind_size,
min: min_size,
});
}
} else if bind_size == 0 {
return Err(Error::BindingZeroSize(bb.buffer_id));
}
let sub_range = hal::buffer::SubRange {