crosire / d3d8to9

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

Atomic refcounters, fixed device release #2

Closed CookiePLMonster closed 7 years ago

CookiePLMonster commented 7 years ago

It could solve issues with inconsistent device refcounters in games which expect d3d8 to be thread safe.

crosire commented 7 years ago

Looks good. But could you please remove the spaces between braces and arguments in the function calls to stay true to the rest of the code? =)

CookiePLMonster commented 7 years ago

Sure, will do. I noticed the initial issue I was trying to fix by this is still happening at times though :(

"Reference count for 'IDirect3DDevice8' object 1AAFEA88 (2) is inconsistent."

crosire commented 7 years ago

That's not necessarily an issue. It can happen if the game does not release its objects in the reverse order it created them, which is quite common. I don't think a lot of D3D8 games do multi-threading actually (though the API seems to support it partially). Still these changes can't hurt.

CookiePLMonster commented 7 years ago

These interlocked ops are literally compiled to a single locked assembly instruction so they are not any slower than regular operations (the perf difference doesn't really make a difference in the context of d3d rendering) so it's a win-win.

CookiePLMonster commented 7 years ago

I have updated the PR with a fix for device refcounts. See the comments in the code for an explaination on what happened.

crosire commented 7 years ago

Ah. Nice catch.