amerkoleci / Vortice.Windows

.NET bindings for Direct3D12, Direct3D11, WIC, Direct2D1, XInput, XAudio, X3DAudio, DXC, Direct3D9 and DirectInput.
MIT License
1.01k stars 73 forks source link

Is there a way to force an object into disposing on the gpu? #409

Closed BradChase2011 closed 11 months ago

BradChase2011 commented 11 months ago

We have an issue where if we have an object with a resource, in our case two ID3D12Resource for a texture to stage on the gpu, and we pass the holding object through a callback, the resources never release on the shared memory portion of the gpu.

Is there a way to FORCE the resources into disposing the memory on the shared memory of the gpu side? Using any means necessary to do so would help a ton. I am unfamiliar with SharpGen, but if we could create a helper class to call DirectX's underlying dispose, it would help a ton.

We use callbacks because we try to destroy the memory only after it is no longer used in any buffers and we would like our buffers to call back when they are completed and track all buffer usage. We use the same routines on our Vulkan side and they clear up just fine and would hate to move it into a more single threaded approach to transfer buffers. Thanks much!

amerkoleci commented 11 months ago

Hi Is this supported by native directx? If so can you point me to which method to call? IUnknown.Release?

BradChase2011 commented 11 months ago

Hi Is this supported by native directx? If so can you point me to which method to call? IUnknown.Release?

I am not entirely sure. I am new to directx 12 and all the info available for it seems to suggest just calling Release. So I guess I can pose a new question, is this not wrapper thing and more of a directx com thing? To reiterate, if I copy the resource directly with no callback, I have zero leaks on the shared memory side. The minute I place the containing object of the resource into a callback as an object state, I can no longer release the memory. Is this expected and I just don't have the knowledge to release it or is passing a resource through a callback a big no no? Sorry I can't help more.

Edit: to add, I did type cast it to IUnknown and called the release on that but it still didn't fix it.

amerkoleci commented 11 months ago

Do you call Dispose on the resource once not needed?

BradChase2011 commented 11 months ago

I tried both dispose and release, neither seem to get rid of it. I'm trying some other stuff like making a temporary manager that marks them by guid and then I only pass the guid around. I doubt it's my drivers but I'm also updating those as we speak. I'm going to keep digging around and try to limit it, strangely the resource (texture) on the gpu memory does release just fine as that doesn't grow at all and yet that is kept on the containing object just like the staging memory in shared.

amerkoleci commented 11 months ago

Can you put a small example on github so I can reproduce the issue?

BradChase2011 commented 11 months ago

I would love to but the engine is massive unfortunately. I have a helloworld example I moved over to the vortice library, so I'll see if I can have it write a ton of textures out and if it leaks there. Side note, my live objects are NOT growing... The resource count stays down yet the shared memory keeps going up. Would the live objects grow if they were not disposed correctly? By the live objects not growing is what gave me the assumption that somehow the driver was holding onto the memory by a ref counter some how, but I could be all washed up :). Btw I want to make sure to tell ya thanks for the help and support, really appreciate it.

BradChase2011 commented 11 months ago

Can you put a small example on github so I can reproduce the issue?

Well it seems the command allocator was holding on to the copy commands. Stupid mistake on my part. With some temporary code in to reset the allocators on the transfer queues, it is absolutely fine and does not grow. Guess thats what I get for being a newbie to DirectX 12 :). I want to say thanks much for the help and advice and I am very happy someone picked up the mantle after SharpDX went by the way side.

amerkoleci commented 11 months ago

Nope, feel free to ask any questions under Discussion tab and share progress of your engine.

Cheers!