720: Fix validation errors + panics on empty buffers r=kvark a=rukai

**Description**
My previous PR left a vulkan validation error when creating an empty buffer.
This PR fixes that and also fixes a panic preventing the compute-example from running with no elements.

**Testing**
Unit test added in wgpu-rs PR. https://github.com/gfx-rs/wgpu-rs/pull/373
<!--
Non-trivial functional changes would need to be tested through:
  - [wgpu-rs](https://github.com/gfx-rs/wgpu-rs) - test the examples.
  - [wgpu-native](https://github.com/gfx-rs/wgpu-native/) - check the generated C header for sanity.

Ideally, a PR needs to link to the draft PRs in these projects with relevant modifications.
See https://github.com/gfx-rs/wgpu/pull/666 for an example.
If you can add a unit/integration test here in `wgpu`, that would be best.
-->


Co-authored-by: Rukai <rubickent@gmail.com>
This commit is contained in:
bors[bot]
2020-06-15 01:06:46 +00:00
committed by GitHub
2 changed files with 21 additions and 15 deletions

View File

@@ -683,21 +683,25 @@ impl<B: GfxBackend> LifetimeTracker<B> {
resource::BufferMapState::Waiting(pending_mapping) => pending_mapping,
_ => panic!("No pending mapping."),
};
log::debug!("Buffer {:?} map state -> Active", buffer_id);
let host = mapping.op.host;
let status = match super::map_buffer(raw, buffer, mapping.sub_range.clone(), host) {
Ok(ptr) => {
buffer.map_state = resource::BufferMapState::Active {
ptr,
sub_range: mapping.sub_range,
host,
};
resource::BufferMapAsyncStatus::Success
}
Err(e) => {
log::error!("Mapping failed {:?}", e);
resource::BufferMapAsyncStatus::Error
let status = if mapping.sub_range.size.map_or(true, |x| x != 0) {
log::debug!("Buffer {:?} map state -> Active", buffer_id);
let host = mapping.op.host;
match super::map_buffer(raw, buffer, mapping.sub_range.clone(), host) {
Ok(ptr) => {
buffer.map_state = resource::BufferMapState::Active {
ptr,
sub_range: mapping.sub_range,
host,
};
resource::BufferMapAsyncStatus::Success
}
Err(e) => {
log::error!("Mapping failed {:?}", e);
resource::BufferMapAsyncStatus::Error
}
}
} else {
resource::BufferMapAsyncStatus::Success
};
pending_callbacks.push((mapping.op, status));
}

View File

@@ -2767,7 +2767,9 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
hal::memory::Dependencies::empty(),
iter::once(transition_src).chain(iter::once(transition_dst)),
);
comb.copy_buffer(&stage_buffer, &buffer.raw, iter::once(region));
if buffer.size > 0 {
comb.copy_buffer(&stage_buffer, &buffer.raw, iter::once(region));
}
}
device
.pending_writes