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

D3D9: Copy only dirty regions #1987

Merged
merged 7 commits into from
Apr 22, 2021
Merged

Conversation

K0bin
Copy link
Collaborator

@K0bin K0bin commented Mar 22, 2021

  • Remove implicit discard
  • Copy the dirty parts of a resource when flushing it (or when the managed buffer is otherwise used)
  • So unless we recently wrote to the managed buffer (GetRenderTargetData), the game can do whatever the hell it wants with that data.

This has a number of advantages over the current approach:

  • When a game uses dirty regions, we only need to make a copy of those parts. Previously we had to copy the entire resource.
    This is significant in Nostale which keeps reusing a single 512x512 managed texture and writes data into it before every draw call. The data written is usually just ~60x60px so we only have to copy that instead of the whole 512x512 texture over and over again.
  • Should result in slightly less GPU load because the GPU also has to do less copying.
  • We don't need to synchronize the CS thread at all when a game locks a managed/sysmem resource
  • It works with broken games that keep the managed pointer for too long (Warhammer Online)

Nine (or rather Radeonsi) also does it this way. The downside is, that games that only lock and write their managed textures once might need more memory/address space and might load a bit slower. We copy the entire texture for textures that need to be converted in a compute shader because it seemed a bit painful to only copy the dirty parts there. I don't think that's a big deal anyway.

I'm rather scared of this, so it's gonna need a lot of testing.

src/d3d9/d3d9_device.cpp Outdated Show resolved Hide resolved
@K0bin K0bin force-pushed the copy-only-dirty branch 2 times, most recently from 5f668e1 to 2e31250 Compare March 31, 2021 13:44
@K0bin K0bin marked this pull request as ready for review March 31, 2021 13:47
@mirh
Copy link

mirh commented Mar 31, 2021

Mass Effect is crashing so hard and badly for me with the last commit (950M, 461.92 and 465.89) that if it happens when I have MSI afterburner open, my whole pc shuts down too.

EDIT: I could get this meagre log, but it's not very much useful

@K0bin K0bin force-pushed the copy-only-dirty branch 2 times, most recently from cbb21df to 90ffcb3 Compare March 31, 2021 21:18
@K0bin
Copy link
Collaborator Author

K0bin commented Mar 31, 2021

@mirh Don't use MSI Afterburner with DXVK. It's broken and known to cause issues.

That said, there were bugs in the PR that are fixed now.

@mirh
Copy link

mirh commented Mar 31, 2021

The crash was there even without overlays, that only transformed it in an entire system lock.
Anyway, now everything works properly (including rivatuner)

@Wishbringer71
Copy link

Wishbringer71 commented Apr 1, 2021

In Everquest 2 these new patch causes some texture issues.
(Wrong textures or texture overlays: Grass in desert, blue grass where green grass was expected)

Edit:
Win 10 21H1,AMD Radeon 5700XT, Driver 21.3.2

@K0bin
Copy link
Collaborator Author

K0bin commented Apr 1, 2021

@Wishbringer71 Can you make an apitrace of Everquest 2? Doesn't matter whether you use the PR, regular DXVK or WineD3D for that.

@Wishbringer71
Copy link

Wishbringer71 commented Apr 1, 2021

@K0bin:
Desert normal
Green Desert

I am not familar with apitrace

Did a "apitrace trace -a d3d9 everquest2.exe" and got around 18 GB for 5 minutes ingame.
Don't think I should upload.
Any specific command how to trace?

@K0bin
Copy link
Collaborator Author

K0bin commented Apr 1, 2021

@Wishbringer71

You'd usually just drop the 32bit apitrace wrapper d3d9.dll next to the games exe file. Your approach works too. Large files are to be expected. 18GB is on the larger side but not entirely unheard of. I don't need you to run it for 5 minutes either. Anything between 30s and 2 minutes should do the trick.

On top of that, trace files can usually be compress very well.

@Wishbringer71
Copy link

Wishbringer71 commented Apr 1, 2021

@K0bin
Will try it later after work.
Just recognized: when using above command it uses not dxvk d3d9 lib and only apitrace wrapper and original d3d9 (no graphic issue).
dxvk d3d9.dll is next to everquest2.exe, d3d9.dll wrapper of apitrace is in apitrace/lib subfolder.
Copying wrapper lib next to everquest2.exe would overwrite dxvk d3d9.dll
Using Apitrace command with linking to d3d9.dll of dxvk gives graphic errors, but no tracefile.
Maybe I have to copy dxvk d3d9.dll to syswow64, but atm windows refuses.

Edit:
Or do you only want a trace of EQ2, regardless of issue and dxvk lib?

@K0bin
Copy link
Collaborator Author

K0bin commented Apr 1, 2021

@Wishbringer71

Just recognized: when using above command it uses not dxvk d3d9 lib and only apitrace wrapper and original d3d9 (no graphic issue).

That's not a problem. Even if you can't reproduce the issue while making the trace, I will be able to when I replay the trace with DXVK afterwards.

Maybe I have to copy dxvk d3d9.dll to syswow64, but atm windows refuses.

Don't do that. That's a bad idea and might potentially break your Windows installation.

If your original method worked for you, you can just do it that way again. That's perfectly fine too.

@Wishbringer71
Copy link

Wishbringer71 commented Apr 1, 2021

@K0bin
Apitrace EQ2 compressed .7z
expired at 06.04.2021

@K0bin
Copy link
Collaborator Author

K0bin commented Apr 1, 2021

@Wishbringer71 The Everquest 2 issue is also present on master and I can even reproduce it with 1.8.1 and 1.7.3. So it seems like its not caused by this PR. I'll look into it nonetheless.

@Wishbringer71
Copy link

@K0bin
Thanks!
I recognized issue (pictures above) only in builds with your "copy on dirty regions",
otherwise I would have normally reported it under issues.

@K0bin K0bin force-pushed the copy-only-dirty branch 4 times, most recently from 3a2343e to 846f870 Compare April 2, 2021 00:09
@K0bin
Copy link
Collaborator Author

K0bin commented Apr 2, 2021

Split it up into smaller commits.

@K0bin
Copy link
Collaborator Author

K0bin commented Apr 2, 2021

@Wishbringer71 Are you sure it works on DXVK master?

I can reproduce the problem using your trace all the way back to DXVK 1.5.5. That's just the oldest version I've tested.
grafik

@Wishbringer71
Copy link

Wishbringer71 commented Apr 2, 2021

@K0bin
At least it worked with 1.8.1 and master with AMD 21.3.2 at a Radeon RX 5700XT.
Maybe it‘s an additional problem with NVidia (seeing your drivers 465.89.0)

I had your bug years ago with an RX 580 and too high vram clocks.

@K0bin
Copy link
Collaborator Author

K0bin commented Apr 3, 2021

Someone reported another problem with it on Discord.

pr 1987 causes a rendering issue with some of the text elements on the menu in Remember Me. Tested on Windows, nvidia turing. Bisected and the offending commit is "[d3d9] Only copy dirty parts of managed/sysmem resources". Apitrace: https://www8.zippyshare.com/v/fVbi43VK/file.html

https://mega.nz/#!UjgBiQbC!hNh--CBYZXKJbcrEvTgSFni_iprMDaBBrpQ_EsSrM-I

@K0bin
Copy link
Collaborator Author

K0bin commented Apr 3, 2021

Fixed.
@Wishbringer71 Could you pls retest Everquest? Perhabs it's the same bug.

@DadSchoorse
Copy link
Contributor

Screenshot_20210409_151911
The apitrace replays fine (I think that's how it's supposed to look?) for me. Can you reproduce the issue when replaying the apitrace with dxvk?

@Wishbringer71
Copy link

@DadSchoorse
For me it plays fine with actual dxvk master and of course with original d3d9 (includes issues with AMD drivers).
Only with D3D9: Copy only dirty regions I get green areas instead of desert.

atm I use dxvk on windows only to escape d3d9 issues with AMD drivers for RX 5700XT (wrong anisotropy and washed out textures)

@mirh
Copy link

mirh commented Apr 9, 2021

I smell an amdvlk issue coming here 🙄

@K0bin K0bin force-pushed the copy-only-dirty branch 2 times, most recently from 1a080dd to 43a4e94 Compare April 11, 2021 11:20
@K0bin
Copy link
Collaborator Author

K0bin commented Apr 11, 2021

@Wishbringer71

Sry that I have to keep bothering you but I'd like to fix this and I can't reproduce it locally.
Could you make another apitrace at the exact same spot but this time use the dlls in this zip file:
apitrace_dxvk.zip

Just put both of them into the Everquest 2 folder right next to the exe file and start the game.

@Wishbringer71
Copy link

Wishbringer71 commented Apr 11, 2021

@K0bin
No problem, compressing trace atm.
Here a short video of trace
https://1drv.ms/u/s!AqyqBv-ep8SMhofCEm3GdyOaefiM_Rk?e=1CQuKh
And here is the trace
https://1drv.ms/u/s!AqyqBv-ep8SMhofCE_nMMhCsmjBoqsM?e=PzxpsL

@K0bin
Copy link
Collaborator Author

K0bin commented Apr 13, 2021

The Everquest 2 issue appears to be a driver bug. Someone else tested that exact same spot with this PR and it was fine.

@Wishbringer71
Copy link

Wishbringer71 commented Apr 13, 2021

@K0bin
ok, thanks for Info,
will test it with some older driver versions and new ones when released.
Report to AMD is out.

Issue is there with AMD Radeon Adrenaline drivers 21.2.3 - 21.3.2 at RX5700XT and RX550.
Older ones not tested atm.

src/d3d9/d3d9_device.cpp Outdated Show resolved Hide resolved
src/d3d9/d3d9_device.cpp Outdated Show resolved Hide resolved
src/d3d9/d3d9_device.cpp Outdated Show resolved Hide resolved
src/d3d9/d3d9_device.cpp Outdated Show resolved Hide resolved
@K0bin K0bin force-pushed the copy-only-dirty branch 2 times, most recently from 7d005e9 to ceedc40 Compare April 15, 2021 18:31
src/d3d9/d3d9_device.cpp Outdated Show resolved Hide resolved
src/d3d9/d3d9_device.cpp Outdated Show resolved Hide resolved
src/d3d9/d3d9_device.cpp Outdated Show resolved Hide resolved
@Wishbringer71
Copy link

@K0bin
Afeter some testing:
with newest driver 21.4.1 issue is still there,
traced back to 20.5.1 hws (oldest driver I had, 11 months old), issue was there too.
So if it is a driver bug, it's a very long lasting one.

Copy link
Collaborator

@Joshua-Ashton Joshua-Ashton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine upon initial review, I am sure we will find edgecases down the line :-)

@Joshua-Ashton Joshua-Ashton merged commit 0bc8b0b into doitsujin:master Apr 22, 2021
@K0bin K0bin deleted the copy-only-dirty branch April 22, 2021 16:46
@SveSop
Copy link
Contributor

SveSop commented Jun 28, 2021

@Joshua-Ashton

Looks fine upon initial review, I am sure we will find edgecases down the line :-)

I think i might have just found one of those... With Star Wars - The Old Republic, although not with "Dirty Regions" but rather "Use staging buffer for managed copies" 4261ff6

I run SWTOR through steam, and upon last Proton6.3-5 update, dxvk got updated to 1.9 and the "stutter out of hell" problem happened. Reverting DXVK to 1.8.1 i have no issues. Bisecting this, it started happening at the above linked commit. It is a bit better on 1.9+GIT, as when i turn around it stutters for 10-20 seconds and seems to even out.. until i move forward a bit and stuttering starts again.

Can you work with a apitrace from windows? (Saw a link above with d3d9.dll and d3d9_dxvk.dll posted)... as i think i need a "for-dummies" explanation if i should get this working from proton...

If so, ill create a new issue for this, since source has changed quite a bit since this PR.

@K0bin
Copy link
Collaborator Author

K0bin commented Jun 28, 2021

A Windows apitrace works fine, doesnt even have to be made with DXVK and yes, pls also open a separate issue.

This is pretty weird though. If anything the changes should reduce stuttering. I'll have to investigate that.

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.

None yet

6 participants