<justsid>
I'm trying to track down a leak inside of Zink and I'm hoping someone can help me. Basically buffers created with `u_upload_alloc_buffer` (ending in `zink_create_resource`) are born inside of Zink witha +1 ref count and I can see it getting referenced and bumped when used in draws and then later on de-refed after getting submitted. However, it never goes below 1 and I'm not sure what that is. If I understand the code right,
<justsid>
`u_upload_alloc_buffer` is expected to be gifted a reference to the new object, so I'm guessing the state tracking there is correct, although I'll admit the whole private ref count thing is pretty wild. I can also see zink derefencing the object inside of `zink_reset_batch_state()`, but it just never hits 0. Eventually I'm all out of memory and that's the end of that. I'm hoping someone who understand Zink/Mesa better than me can
<justsid>
give me some pointers of how to track this down better?
<airlied>
justsid: sound like reset batch should be the final deref
<justsid>
That's what I assumed. Or at least, since the buffer is used as a magazine of sorts to stream index/vertex buffer data to, the last batch to reset should turn off the light. Yet no matter what, I'm left with a ref count of 1
<justsid>
Actually... Having made the wise choice of drinking some coffee at 7pm, I think I see the problem. reset_obj_list doesn't actually delete the resources, it just puts them back into the pool of available resources. So I think the missing piece is actually the fact that Zink doesn't recycle the object, and will only ever create more through zink_create_resource()
<justsid>
I swear I looked at the code before I wrote my question
<airlied>
oh it should get recycled
<justsid>
Actually it looks like it does de-ref it, just deferred through the bs->unref_resources list
<justsid>
Is the recycling part maybe missing? I don't see it getting added to a list other than the unref_resources list. I can see the ref count drop down to 1 in unref_resources() as part of Zink submitting its command buffer, and then nothing seems to ever look at the object again
<justsid>
And resource_object_create doesn't seem like it attempts to recycle any resources, just creating a new one. so u_upload_alloc_buffer will always create a fresh resource
<justsid>
At least within Zink I can see the refs and derefs adding up to net 0. But the object is born with a +1 ref count, so who is responsible for dropping the last ref? Is it possible that I'm not triggering a path in Mesa that would clean up streamed resources like this?
<justsid>
The object is created as part of some glBegin()/glEnd() calls. But we never end up swapping any buffers or even attempting to display anything, so I could imagine that scratch memory never gets cleaned up? Also sorry for being a bit spammy here, I'm just completetly clueless about the inner workings of Mesa so you are getting my inner monologue live
<airlied>
hmm yeah maybe some clean up is hooked in somewhere, I'd have to go dig
<airlied>
zmike would know but he's out for rest of year
<justsid>
He even asked me if I had any questions before leaving the office and I was all like "nah, this is perfect the way it is" (:
<airlied>
is unref_resources being called?
<justsid>
It is, yeah
<airlied>
so some queue submit should see the resource get destroyed
<justsid>
yeah, I can see the ref count drop through zink_end_batch -> submit_queue -> unref_resources -> zink_resource_object_reference -> pipe_reference_described
<justsid>
And I guess I figured out how the upload manager removes its last reference: When it makes a new buffer, it first derefs the old buffer. So that should be balanced too
<airlied>
yeah upload use of private refs is kinda funky, but explained in a comment
<justsid>
Yeah, it blew my mind so much I immediately considered stealing the design for our engine objects that suffer from similar problems lol
eukara has joined #zink
Akari has quit [Ping timeout: 480 seconds]
avane has quit [Ping timeout: 480 seconds]
justsid has quit [Quit: Leaving]
Akari has joined #zink
justsid has joined #zink
justsid has quit [Quit: Leaving]
Akari has quit [Ping timeout: 480 seconds]
avane has joined #zink
<kusma>
justsid: Are you on the latest version? This sounds a lot like a bug I fixed recently...