You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add DestroyEvent and CreateEvent to IDeviceContext, preventing a guaranteed memory leak
This PR provides a fix for https://jira.unity3d.com/browse/UUM-66351. The bug is caused by a design flaw in the IDeviceContext API. For the OpenCL implementation, events allocate, and must be released when they are no longer needed. The result is an unavoidable memory leak. The API doesn't provide a way to do this, so I've added it. It's also useful for the other implementations - currently, we are forced to hold on to certain data associated with events indefinitely, since we don't know when the user might want to query it.
After discussing with team members, to keep the API symmetric, I've added a corresponding function to create events, and changed WriteBuffer() and ReadBuffer() to have the allocated event passed in, if the user wants to track completion. The result is that calling code which looked like this before:
```cs
var evt = ctx.WriteBuffer(slice, arr); // unavoidable leak on this line
```
Will now look like this:
```cs
var evt = ctx.CreateEvent(); // allocate event
ctx.WriteBuffer(slice, arr, evt); // bind event to write
ctx.DestroyEvent(evt); // clean up
```
Or optionally like this if the user just wants to fire-and-forget, and doesn't care about tracking completion:
```cs
ctx.WriteBuffer(slice, arr); // return type is void, no leak
```
For any viewers unaware: This is a very new API added early so the APV could use it. It doesn't exist in any non-techstream releases yet. The flaw is blocking APV and causes instabilities in our tests.
0 commit comments