crosire / d3d8to9

A D3D8 pseudo-driver which converts API calls and bytecode shaders to equivalent D3D9 ones.
BSD 2-Clause "Simplified" License
875 stars 77 forks source link

D3D8.1 Pixel and Vertex Shader Lifetimes Seem To Be Incorrect #155

Closed nv-ajaus closed 1 year ago

nv-ajaus commented 1 year ago

I've noticed that D3D9 Devices and D3D9 Pixel/Vertex Shaders have been leaking with some applications. Looking through the D3D8to9 code, I think there is some mismanagement of the D3D9 Shader refcounts because of some behavioral differences between D3D8.1 and D3D9.

In D3D8.1 Pixel and Vertex Shaders do not increase the refcount of the device they are created from, but they do in D3D9 (This was confirmed through testing on both ends). Similarly, in D3D9, a device reset preserves the Shader objects, but the Microsoft documentation for D3D9 Lost Devices mentions that "In Direct3D 9, vertex shaders and pixel shaders don't need to be re-created after reset. They will be remembered. In previous versions of DirectX, a lost device required shaders to be re-created." (https://learn.microsoft.com/en-us/windows/win32/direct3d9/lost-devices).

D3D8to9 only calls for a release on D3D9 Shader objects when there is a call to DeletePixelShader or DeleteVertexShader, but I think to maintain compatible or expected behavior, the device object in D3D8to9 should keep track of the handles of any shaders created through it and explicitly release them on a release or reset call to the device.

nv-ajaus commented 1 year ago

Closed with PR #158