crosire / d3d8to9

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

Fix resource leak and prevent pure device creation #175

Closed elishacloud closed 2 months ago

elishacloud commented 2 months ago

This fixes a resource leak that happens in GetTexture() because we query for the interface after getting the texture and never release the extra reference that creates.

Also, this prevents the game from creating a pure device. d3d8to9 won't work with a pure device because it requires many Get functions that won't work if a game creates a pure device.

WinterSnowfall commented 2 months ago

d3d8to9 won't work with a pure device because it requires many Get functions that won't work if a game creates a pure device.

Has it been a problem so far? AFAIK a lot of games will request D3DCREATE_PUREDEVICE in order to signal they need HWVP only, so getting rid of it entirely may also come with some performance implications.

elishacloud commented 2 months ago

Has it been a problem so far? AFAIK a lot of games will request D3DCREATE_PUREDEVICE in order to signal they need HWVP only, so getting rid of it entirely may also come with some performance implications.

You can search for GetDesc in the code and see the number of functions that would fail. Even simple functions like CopyRects() and UpdateTexture() will fail with d3d8to9 in a pure device.

Maybe pure devices are more common in Direct3D9 games than in Direct3D8 or maybe these are the reason for a number of games that already fail or have issues with d3d8to9 that hasn't been investigated yet. I know several.

Either way if a game uses a pure device it is unlikely to work right with d3d8to9.

WinterSnowfall commented 2 months ago

You can search for GetDesc in the code

Not all Get* functions are actually disabled, rather only the ones affecting state, if docs are to be believed. See here.

Polymega commented 2 months ago

Maybe pure devices are more common in Direct3D9 games than in Direct3D8 or maybe these are the reason for a number of games that already fail or have issues with d3d8to9 that hasn't been investigated yet. I know several.

Wonder if this would fix Silent Hill 3's unique DX8 shaders? Right now, all advanced beauty shaders made by SH3 don't render at all when using d3d8to9.

elishacloud commented 2 months ago

Not all Get* functions are actually disabled, rather only the ones affecting state, if docs are to be believed. See here.

Ok, I removed the code that prevents pure device creation.

elishacloud commented 2 months ago

Ok, good call. I fixed it to release the base texture in each block.