mirror of
https://github.com/AsahiLinux/m1n1
synced 2024-11-10 09:44:13 +00:00
m1n1.agx.object: Be more efficient for pushes, verbose control
- Support compression - Avoid pushing objects which haven't changed (optionally) Signed-off-by: Asahi Lina <lina@asahilina.net>
This commit is contained in:
parent
f19625f8da
commit
6ce60e875c
2 changed files with 17 additions and 5 deletions
|
@ -15,6 +15,7 @@ class GPUContext:
|
|||
self.uat = self.agx.uat
|
||||
self.u = self.agx.u
|
||||
self.p = self.agx.p
|
||||
self.verbose = False
|
||||
|
||||
self.context_info = agx.kshared.new(ContextInfo)
|
||||
self.context_info.fb_ptr = 0
|
||||
|
|
|
@ -25,8 +25,9 @@ class GPUObject:
|
|||
self._alloc = allocator
|
||||
self._type = objtype
|
||||
self._addr = None
|
||||
self._last_data = None
|
||||
|
||||
def push(self):
|
||||
def push(self, if_needed=False):
|
||||
assert self._addr is not None
|
||||
stream = self._alloc.make_stream(self._addr)
|
||||
context = Container()
|
||||
|
@ -34,16 +35,25 @@ class GPUObject:
|
|||
context._building = True
|
||||
context._sizing = False
|
||||
context._params = context
|
||||
print(f"[{self._name} @{self._addr:#x}] pushing {self._size} bytes")
|
||||
|
||||
# build locally and push as a block for efficiency
|
||||
ios = io.BytesIO()
|
||||
self._type._build(self.val, ios, context, "(pushing)")
|
||||
stream.write(ios.getvalue())
|
||||
data = ios.getvalue()
|
||||
if if_needed and data == self._last_data:
|
||||
return self
|
||||
|
||||
if self._alloc.verbose:
|
||||
self._alloc.agx.log(f"[{self._name} @{self._addr:#x}] pushing {self._size} bytes")
|
||||
if self._size > 32768:
|
||||
self._alloc.agx.u.compressed_writemem(self._paddr, data)
|
||||
else:
|
||||
self._alloc.agx.iface.writemem(self._paddr, data)
|
||||
#stream.write(data)
|
||||
if isinstance(self._type, type) and issubclass(self._type, ConstructClassBase):
|
||||
print("setmeta", self._type)
|
||||
self.val.set_addr(self._addr, stream)
|
||||
|
||||
self._last_data = data
|
||||
return self
|
||||
|
||||
def pull(self):
|
||||
|
@ -54,7 +64,8 @@ class GPUObject:
|
|||
context._building = False
|
||||
context._sizing = False
|
||||
context._params = context
|
||||
print(f"[{self._name} @{self._addr:#x}] pulling {self._size} bytes")
|
||||
if self._alloc.verbose:
|
||||
self._alloc.agx.log(f"[{self._name} @{self._addr:#x}] pulling {self._size} bytes")
|
||||
self.val = self._type._parse(stream, context, "(pulling)")
|
||||
|
||||
return self
|
||||
|
|
Loading…
Reference in a new issue