Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[d3d8] Add an option to respect DISCARD only for dynamic write-only buffers #4143

Merged
merged 2 commits into from
Sep 26, 2024

Conversation

WinterSnowfall
Copy link
Contributor

@WinterSnowfall WinterSnowfall commented Jul 13, 2024

Fixes missing geometry in Rayman 3, a problem that based on online testimonies started to occur with the transition to Windows 7.

Test on Windows XP have shown that the game renders properly, so native behavior on age-accurate systems seem to differ from d3d9, as in D3DLOCK_DISCARD appears to be respected only for D3DUSAGE_DYNAMIC + D3DUSAGE_WRITEONLY.

Making it a draft for now, as it would need more testing to ensure there are no regressions in other titles.

@WinterSnowfall
Copy link
Contributor Author

Turns out this isn't exactly free (performance-wise), so I've hidden it behind a config option and enabled it only for Rayman 3. I have yet to see another game relying on this type of behavior, anyway.

@WinterSnowfall WinterSnowfall force-pushed the d3d8-bufferfix branch 2 times, most recently from d0ad615 to 3170f22 Compare July 14, 2024 00:05
@WinterSnowfall WinterSnowfall changed the title [d3d8] Respect D3DLOCK_DISCARD only for dynamic write-only buffers [d3d8] Add an option to respect DISCARD only for dynamic write-only buffers Jul 14, 2024
@WinterSnowfall WinterSnowfall marked this pull request as ready for review July 14, 2024 00:18
@mrdeathjr28
Copy link

i can confirm game render are fixed

rmn3fx

@K0bin
Copy link
Collaborator

K0bin commented Jul 14, 2024

The docs only mention DYNAMIC. Does WRITEONLY make a difference for DISCARD?

@WinterSnowfall
Copy link
Contributor Author

WinterSnowfall commented Jul 14, 2024

The docs only mention DYNAMIC. Does WRITEONLY make a difference for DISCARD?

For this game in particular, yes. For what it's worth d3d8to9 is already doing this globally, however handling it this way appears to add a few queue syncs and is generally slower at times, hence the config option.

As mentioned in the commit, this behavior seems to have been default on Windows XP, but modern Windows will behave inline with what D3D9 does, namely allow DISCARD for both DYNAMIC and DYNAMIC + WRITEONLY, which is why the game is also broken on native currently.

The workarounds you'll find online involve disabling HWVP entirely, using a game ini config option, specifically in order to disallow DISCARD on the affected buffers.

@doitsujin doitsujin merged commit 97091aa into doitsujin:master Sep 26, 2024
4 checks passed
@WinterSnowfall WinterSnowfall deleted the d3d8-bufferfix branch September 26, 2024 05:46
@RibShark
Copy link

RibShark commented Oct 5, 2024

It makes a difference because Rayman 3 is doing undefined behaviour, namely writing to buffers after unlocking them (off by one error in reference counting I believe). Handling that is probably the more correct fix for this issue.

@WinterSnowfall
Copy link
Contributor Author

It makes a difference because Rayman 3 is doing undefined behaviour, namely writing to buffers after unlocking them (off by one error in reference counting I believe). Handling that is probably the more correct fix for this issue.

If that were indeed the only problem, it would have been fixed just by disabling direct buffer mapping. Which it was not.

@doitsujin
Copy link
Owner

doitsujin commented Oct 5, 2024

It makes a difference because Rayman 3 is doing undefined behaviour, namely writing to buffers after unlocking them (off by one error in reference counting I believe). Handling that is probably the more correct fix for this issue.

Pretty sure we already handle this on the D3D9 side, which this calls into.

If we implemented Lock/Unlock strictly as documented, we wouldn't be running a single D3D9 game because they are literally all broken in one way or another (write after unlock, writing a READONLY buffer, relying on DISCARD not actually discarding, all sorts of fun interactions depending on which pool a buffer is in and what it's used for, ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants