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

Borderlands 2 problems #36

Closed
pchome opened this issue Apr 19, 2019 · 28 comments
Closed

Borderlands 2 problems #36

pchome opened this issue Apr 19, 2019 · 28 comments

Comments

@pchome
Copy link
Contributor

pchome commented Apr 19, 2019

Despite other glitches the main one is the constantly degrading GPU usage (so FPS).

From ~100FPS to ~5FPS in several minutes.

The perf utility says:

std::_Hashtable<dxvk::D3D9SamplerKey, std::pair<dxvk::D3D9SamplerKey const, dxvk::Rcdxvk::DxvkSampler >, std::allocator<std::pair<dxvk::D3D9SamplerKey const, dxvk::Rcdxvk::DxvkSampler > >, std::__detail::_Select1st, dxvk::D3D9SamplerKeyEq, dxvk::D3D9SamplerKeyHash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, std::__detail::_Hashtable_traits<true, false, true> >::_M_find_before_node (15,388 samples, 40.58%)

Test:

--- a/src/d3d9/d3d9_device.cpp
+++ b/src/d3d9/d3d9_device.cpp
@@ -3829,9 +3829,9 @@
     key.MaxMipLevel   = state[D3DSAMP_MAXMIPLEVEL];
     key.BorderColor   = D3DCOLOR(state[D3DSAMP_BORDERCOLOR]);
 
-    auto pair = m_samplers.find(key);
-    if (pair != m_samplers.end())
-      return pair->second;
+    //auto pair = m_samplers.find(key);
+    //if (pair != m_samplers.end())
+    //  return pair->second;
 
     auto mipFilter = DecodeMipFilter(key.MipFilter);
 
@@ -3855,7 +3855,7 @@
 
     Rc<DxvkSampler> sampler = m_dxvkDevice->createSampler(info);
 
-    m_samplers.insert(std::make_pair(key, sampler));
+    //m_samplers.insert(std::make_pair(key, sampler));
     return sampler;
   }
 

GPU usage seems OK with this patch, the problem indeed somewhere in the "sampler".


Other problems (FYI):

  • high and constantly growing VRAM usage
  • rotated Ammo/Weapon/Damage hints
  • red texture borders (black is red)

d9vk-borderlands-2

EDIT: "black is red"

@misyltoad
Copy link
Owner

It is truly incredible that the game requires this many samplers.

The way I am doing lookups now is not the best.

May be worth offloading that sampler lookup into CS somehow, would need a d3d9-only backend change. I might have a go at implementing some dynamic sampler system and seeing if that makes a difference.

I could perhaps compress the sampler data with the bitfield struct thing (:) and probably get it down to 128 bits maybe? Wouldn't affect hashing it now due to how its being done though.

@doitsujin
Copy link
Contributor

doitsujin commented Apr 19, 2019

would need a d3d9-only backend change

You can run your own code on the CS too, this doesn't (and shouldn't) be part of the backend.

Might also be worth checking if the game passes random/undefined data as sampler states, and normalize the key (e.g. set border colors to 0 if the sampler doesn't use border address mode). Usually there's no reason to have more than a few dozen samplers in total.

@misyltoad
Copy link
Owner

would need a d3d9-only backend change

You can run your own code on the CS too, this doesn't (and shouldn't) be part of the backend.

Might also be worth checking if the game passes random/undefined data as sampler states, and normalize the key (e.g. set border colors to 0 if the sampler doesn't use border address mode). Usually there's no reason to have more than a few dozen samplers in total.

Good idea. Will start with normalizing first, and then see if offloading helps

@misyltoad
Copy link
Owner

@pchome

I've pushed a couple of commits to help rectify this issue:
d9df0f9
and
b5f6e4d

Can you try at each of them and tell me at which commit you get better performance with BL2?

Cheers :)

@misyltoad
Copy link
Owner

To clarify for testing:

  1. Just using d9df0f9
  2. Using d9df0f9 and b5f6e4d (at head of sampler-offloading branch)

@pchome
Copy link
Contributor Author

pchome commented Apr 19, 2019

To clarify for testing:

  1. Just using d9df0f9
  2. Using d9df0f9 and b5f6e4d (at head of sampler-offloading branch)

No noticeable difference between 0, 1 and 2.

Performance still degrading, but faster (degrading) with 2 (probably ... :) ).

@misyltoad
Copy link
Owner

Can you produce an apitrace so I can attempt another fix locally?

@pchome
Copy link
Contributor Author

pchome commented Apr 19, 2019

Can you produce an apitrace so I can attempt another fix locally?

I have no luck to do this on linux/steam/proton yet, maybe someone can help and do this on windows ?

@misyltoad
Copy link
Owner

misyltoad commented Apr 19, 2019

A guide is located here:

https://tracehub.froggi.es/

@pchome
Copy link
Contributor Author

pchome commented Apr 19, 2019

Ok, I'll try to do my best.

@pchome
Copy link
Contributor Author

pchome commented Apr 20, 2019

https://github.com/Joshua-Ashton/d9vk/blob/0595a6adc3df4dce18bc99b7b83217572bf453c1/src/d3d9/d3d9_device.cpp#L3837

Looks like this produces different values every time.
Changing value to key.MipmapLodBias = 0; "fixes" problem.

P.S. I was able to create apitrace, but it's too huge (I was very accurate in data collecting :) ).
I should learn how to crop it, to preserve only valuable data. Maybe separate frame states, or so.

@mrdeathjr28
Copy link

d9vk/src/d3d9/d3d9_device.cpp

Line 3837 in 0595a6a

key.MipmapLodBias = bit::cast(state[D3DSAMP_MIPMAPLODBIAS]);
Looks like this produces different values every time.
Changing value to key.MipmapLodBias = 0; "fixes" problem.

P.S. I was able to create apitrace, but it's too huge (I was very accurate in data collecting :) ). I should learn how to crop it, to preserve only valuable data. Maybe separate frame states, or so.

Hi
If you have precompiled binary can test

@misyltoad
Copy link
Owner

d9vk/src/d3d9/d3d9_device.cpp

Line 3837 in 0595a6a
key.MipmapLodBias = bit::cast(state[D3DSAMP_MIPMAPLODBIAS]);

Looks like this produces different values every time.
Changing value to key.MipmapLodBias = 0; "fixes" problem.

P.S. I was able to create apitrace, but it's too huge (I was very accurate in data collecting :) ). I should learn how to crop it, to preserve only valuable data. Maybe separate frame states, or so.

Can you see if 55c86fa corrects your issue?

@pchome
Copy link
Contributor Author

pchome commented Apr 20, 2019

Can you see if 55c86fa corrects your issue?

Still there.

Here is the alert("") debugger output:

$ cat Borderlands2_d3d9.log | sort | uniq -c | grep new

      9 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 0 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 0 : 1
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 0 : 3.08894e-09
  14484 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 0 : -nan
      2 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 1 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 1 : 1.97692e-07
      2 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 2 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 2 : 1
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 2 : 2
      2 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 2 : 3.08894e-09
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 4 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 4 : 1
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 5 : 3.08894e-09
      2 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 6 : 3.08894e-09

Logger::warn(str::format("Direct3DDevice9Ex::CreateSampler: new sampler: ", Sampler, " : ", key.MipmapLodBias));

@misyltoad
Copy link
Owner

I imagine its failing to make with a -NAN MipmapLodBias perhaps?

@pchome
Copy link
Contributor Author

pchome commented Apr 20, 2019

yep

@misyltoad
Copy link
Owner

Cool, I'll work on a fix for that

@pchome
Copy link
Contributor Author

pchome commented Apr 20, 2019

Just for the record:

`$ cat Borderlands2_d3d9.log | sort | uniq -c | grep reused`
 163457 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 0 : 0
     16 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 0 : 1
   7213 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 0 : 3.08894e-09
  41351 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 1 : 0
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 10 : 0
     16 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 1 : 1
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 11 : 0
  10820 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 1 : 1.97692e-07
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 12 : 0
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 13 : 0
   7214 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 1 : 3.08894e-09
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 14 : 0
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 15 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 16 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 17 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 18 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 19 : 0
  59913 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 2 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 20 : 0
     82 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 2 : 1
     19 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 2 : 2
   3605 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 2 : 3.08894e-09
  28491 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 3 : 0
     31 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 3 : 1
   3607 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 3 : 3.08894e-09
  39281 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 4 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 4 : 1
   3607 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 4 : 3.08894e-09
  17026 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 5 : 0
   3606 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 5 : 3.08894e-09
  10798 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 6 : 0
   3605 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 6 : 3.08894e-09
   7796 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 7 : 0
   3607 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 7 : 3.08894e-09
   3509 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 8 : 0
   3507 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 8 : 3.08894e-09
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 9 : 0

@misyltoad
Copy link
Owner

Does bd8264e rectify the issue?

@misyltoad
Copy link
Owner

(I added a another commit to ensure the MipmapLodBias is 0 with NANs)

@pchome
Copy link
Contributor Author

pchome commented Apr 20, 2019

Current master looks ok.

`$ cat Borderlands2_d3d9.log | sort | uniq -c | grep new`
     10 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 0 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 0 : 1
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 0 : 3
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 0 : 3.08894e-09
      3 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 1 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 1 : 1.97692e-07
      3 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 2 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 2 : 1
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 2 : 2
      2 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 2 : 3.08894e-09
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 3 : 0
      3 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 4 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 4 : 1
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 5 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 5 : 3.08894e-09
      2 warn:  Direct3DDevice9Ex::CreateSampler: new sampler: 6 : 3.08894e-09
`$ cat Borderlands2_d3d9.log | sort | uniq -c | grep reused`
 913276 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 0 : 0
     49 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 0 : 1
      8 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 0 : 2
      7 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 0 : 3
  25715 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 0 : 3.08894e-09
 210570 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 1 : 0
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 10 : 0
     34 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 1 : 1
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 11 : 0
  38573 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 1 : 1.97692e-07
      8 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 1 : 2
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 12 : 0
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 13 : 0
  25716 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 1 : 3.08894e-09
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 14 : 0
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 15 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 16 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 17 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 18 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 19 : 0
 223036 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 2 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 20 : 0
    183 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 2 : 1
     19 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 2 : 2
  12856 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 2 : 3.08894e-09
 130386 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 3 : 0
     63 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 3 : 1
  12858 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 3 : 3.08894e-09
 125760 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 4 : 0
      1 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 4 : 1
  12858 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 4 : 3.08894e-09
  92525 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 5 : 0
  12680 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 5 : 3.08894e-09
  59734 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 6 : 0
  12679 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 6 : 3.08894e-09
  32812 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 7 : 0
  12626 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 7 : 3.08894e-09
   7914 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 8 : 0
   7912 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 8 : 3.08894e-09
      3 warn:  Direct3DDevice9Ex::CreateSampler: reused sampler: 9 : 0

@misyltoad
Copy link
Owner

@pchome Issue can be closed? :)

@pchome
Copy link
Contributor Author

pchome commented Apr 20, 2019

Issue can be closed? :)

Sure.
You could keep it opened, to track remaining problems in Borderlands 2.

@misyltoad
Copy link
Owner

Issue can be closed? :)

Sure.
You could keep it opened, to track remaining problems in Borderlands 2.

A separate issue with more detailed information on each issue would be better.

@pchome
Copy link
Contributor Author

pchome commented Apr 21, 2019

upd:
Other problems (FYI):

  • high and constantly growing VRAM usage
    Can't reproduce with recent build (~ e9af5d8), VRAM usage near 1000 (~200-300 usually used by system itself).
  • rotated Ammo/Weapon/Damage hints
    See attached image.
  • red texture borders (black is red)
    While bug still there, can be overridden in WillowEngine.ini:
    • partially: DefaultPostProcessName=WillowEngineMaterials.RyanScenePostProcess
    • completely: DefaultPostProcessName=WillowEngineMaterials.CinematicScenePostProcess
    • default: DefaultPostProcessName=WillowEngineMaterials.WillowScenePostProcess

d9vk-borderlands-2-bug-21ab453

@misyltoad
Copy link
Owner

Issue is probably my shader io mapping (masks and multiple semantics to one register)

I will try and fix this over the next couple of days

@mrdeathjr28
Copy link

upd:
Other problems (FYI):

  • high and constantly growing VRAM usage
    Can't reproduce with recent build (~ e9af5d8), VRAM usage near 1000 (~200-300 usually used by system itself).

  • rotated Ammo/Weapon/Damage hints
    See attached image.

  • red texture borders (black is red)
    While bug still there, can be overridden in WillowEngine.ini:

    • partially: DefaultPostProcessName=WillowEngineMaterials.RyanScenePostProcess
    • completely: DefaultPostProcessName=WillowEngineMaterials.CinematicScenePostProcess
    • default: DefaultPostProcessName=WillowEngineMaterials.WillowScenePostProcess

d9vk-borderlands-2-bug-21ab453

Confimed in my case for now in x-men wolverine vram dont pass 500mb

@K0bin
Copy link
Contributor

K0bin commented Apr 29, 2019

FYI the red lighting issue is fixed with 54a50c3

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

No branches or pull requests

5 participants