mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-20 09:03:28 +00:00
clean up draw list handling
our implementantation of Buffer can't (currently) dynamically grow the size of the object to serialize things that are bigger than a page, so we have to enforce Vec-like objects to have a serialized size of less than the page limit. This is a bit of a moving target because it depends on implementation specific details. A conservative bodge was put in to try and work around this problem for now.
This commit is contained in:
parent
dbdc157ccf
commit
f8bbf97724
2 changed files with 29 additions and 5 deletions
|
|
@ -59,15 +59,36 @@ impl ObjectList {
|
||||||
/// bounds that the system can handle. Thus, this method can fail returning the pushed object,
|
/// bounds that the system can handle. Thus, this method can fail returning the pushed object,
|
||||||
/// at which point one should send the draw list to the graphics engine, and retry the push.
|
/// at which point one should send the draw list to the graphics engine, and retry the push.
|
||||||
pub fn push(&mut self, item: ClipObjectType) -> Result<(), ClipObjectType> {
|
pub fn push(&mut self, item: ClipObjectType) -> Result<(), ClipObjectType> {
|
||||||
|
let serialized_size =
|
||||||
|
self.list.capacity() * size_of::<ClipObjectType>() + size_of::<Vec<ClipObjectType>>();
|
||||||
|
log::debug!("sersize {}", serialized_size);
|
||||||
// TODO: export the capacity limit of a buffer. The origin of the capacity limit is equal to
|
// TODO: export the capacity limit of a buffer. The origin of the capacity limit is equal to
|
||||||
// the size of a page of memory, plus 256 bytes for "scratch" area for rkyv to work in. I did
|
// the size of a page of memory, plus 256 bytes for "scratch" area for rkyv to work in. I did
|
||||||
// try to use the .replace() method with an allocation of a large enough buffer to hold the whole
|
// try to use the .replace() method with an allocation of a large enough buffer to hold the whole
|
||||||
// Vec, but it seems to fail. I think it could be that the scratch space hard-coded into the IPC
|
// Vec, but it seems to fail. I think it could be that the scratch space hard-coded into the IPC
|
||||||
// library is not big enough...
|
// library is not big enough...
|
||||||
if self.list.capacity() * size_of::<ClipObjectType>() + size_of::<Vec<ClipObjectType>>() < 4096 - 256
|
//
|
||||||
{
|
// Update: in a later version of Rust, this is even worse - the margin seems to need to be
|
||||||
|
// fairly large for serialization to work. Setting it to 1k short of 4096 now.
|
||||||
|
if serialized_size < 3072 {
|
||||||
|
if serialized_size > 2048 {
|
||||||
|
// pushing can cause a re-allocation that breaks sending the vec. Allocs happen on roughly
|
||||||
|
// power-of-two boundaries in this implementation, so as a heuristic flag a problem only after
|
||||||
|
// we've exceeded half the page size
|
||||||
|
if self.list.capacity() > self.list.len() {
|
||||||
|
// we're almost out of space, but we still have reserved capacity
|
||||||
self.list.push(item);
|
self.list.push(item);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
} else {
|
||||||
|
// pushing it would cause a capacity bump to over our acceptable size
|
||||||
|
Err(item)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// if the size is less than half a page, go ahead and do the push; a re-alloc won't bring
|
||||||
|
// us over the page size
|
||||||
|
self.list.push(item);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(item)
|
Err(item)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -715,10 +715,13 @@ impl Gfx {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// V2-only API
|
/// V2-only API
|
||||||
pub fn draw_object_list(&self, list: ObjectList) -> Result<(), xous::Error> {
|
pub fn draw_object_list(&self, mut list: ObjectList) -> Result<(), xous::Error> {
|
||||||
|
list.list.shrink_to_fit();
|
||||||
|
let size = list.list.capacity() * size_of::<ClipObjectType>() + size_of::<Vec<ClipObjectType>>();
|
||||||
let buf = match Buffer::into_buf(list) {
|
let buf = match Buffer::into_buf(list) {
|
||||||
Ok(b) => b,
|
Ok(b) => b,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
log::info!("size {}", size);
|
||||||
log::error!("err: {:?}", e);
|
log::error!("err: {:?}", e);
|
||||||
panic!("error")
|
panic!("error")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue