Fix memory mapper bounds
I have two pieces of allocated memory to be mapped, and the first one goes through just fine. Its region
is 0..256
. The second mapping fails the assertion size > 0
, and its region
is 256..512
. Looking at the mapper,
let start = match range.start_bound() {
Bound::Excluded(start) => start + 1,
Bound::Included(start) => *start,
Bound::Unbounded => 0,
} + region.start;
let size = match range.end_bound() {
Bound::Included(end) => end + 1,
Bound::Excluded(end) => *end,
Bound::Unbounded => region.size(),
} - start;
is how the size is calculated. Since my range
is unbounded in both mappings, the first allocation goes through because the size
it calculates is region.size() - (0 + region.start())
which is the same as 256 - (0 + 0)
and thus size
is 256 and everything is fine. However, on the second mapping, region.size() - (0 + region.start())
which is calculated to be 256 - (0 + 256)
and comes out to zero despite range
and region
both being correct. As far as I'm aware, the intended behavior is:
let start = match range.start_bound() {
Bound::Excluded(start) => start + 1,
Bound::Included(start) => *start,
Bound::Unbounded => 0,
};
let end = match range.end_bound() {
Bound::Included(end) => end + 1,
Bound::Excluded(end) => *end,
Bound::Unbounded => region.size(),
};
let size = end - start;
// ...
try_vk!(unsafe { device.map_memory(memory, start + region.start, size, None, &mut ptr) });
and that's what this MR implements. I've tested this in my own code and it seems to work, but there should probably be a test for this.