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+dxso] Rely on robustness for unset SWVP constants #2282

Merged
merged 4 commits into from
Oct 15, 2021

Conversation

K0bin
Copy link
Collaborator

@K0bin K0bin commented Sep 8, 2021

This implements Joshuas idea to rely on robustness2 for constants that the application hasn't set yet.

SWVP:

  • Split the constant buffer into 3 based on the data type.
  • Track the highest used constant for each type and create a buffer with the required size. Copy the data.

HWVP/PS:

  • Reorder the constant buffer to put the ints in front. There's only 16 Int constants (16 x 4 ints) so we just copy those every time.
  • Track the highest used float constant and copy only the required data. Instead of creating differently sized buffers we just bind a smaller range.
  • I think it still makes sense for this case because we theoretically need to copy up to 3840 bytes less data (on Nvidia). 256 * 16 total compared to the minimum 256 bytes for size alignment.

When robustness2 is not supported or the alignment does not work out (It does work on Nvidia), we just copy everything like we did before.

Fixes #2264

@K0bin K0bin force-pushed the constant-buffer-robustness branch 2 times, most recently from ee7a374 to b89b8d8 Compare September 8, 2021 22:31
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 constant-buffer-robustness branch 2 times, most recently from 7c49968 to 2c5d5cd Compare September 9, 2021 22:12
@K0bin
Copy link
Collaborator Author

K0bin commented Sep 9, 2021

TODO:

  • fallback to SSBOs when robustness2 isnt supported
  • always use UBOs when it is (the huge SWVP buffer has been split up so it's well within the limits)
  • make sure we don't go out of bounds anywhere due to robustness2 alignment (256bytes)
  • remove swvp game hacks
  • store the robustness2 alignment somewhere to reduce pointer chasing
  • clean it up
  • figure out if it's worth it doing that for regular shaders

EDIT:
Done

@K0bin K0bin marked this pull request as ready for review September 10, 2021 19:03
@K0bin K0bin force-pushed the constant-buffer-robustness branch 2 times, most recently from 1738088 to 8fe9415 Compare September 10, 2021 19:36
@pchome
Copy link
Contributor

pchome commented Sep 13, 2021

Pls do not forget about dxvk.conf

dxvk/dxvk.conf

Lines 442 to 451 in 67391a7

# SWVP Constant Counts
#
# The number of constants available when using Software Vertex Processing.
#
# Supported values:
# - Integers
# d3d9.swvpFloatCount = 8192
# d3d9.swvpIntCount = 2048
# d3d9.swvpBoolCount = 2048

@K0bin
Copy link
Collaborator Author

K0bin commented Sep 13, 2021

Nice catch, will remove that soon.

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
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 constant-buffer-robustness branch 3 times, most recently from 7cfca50 to c18ac33 Compare September 13, 2021 21:38
@K0bin
Copy link
Collaborator Author

K0bin commented Sep 13, 2021

Thanks for the review @DadSchoorse. Implemented all your feedback.

@K0bin K0bin added the d3d9 label Sep 14, 2021
@K0bin
Copy link
Collaborator Author

K0bin commented Sep 14, 2021

I decided to remove the SSBO fallback when robustness2 is not supported. Instead we just copy everything like we did before. Same thing also happens when any of the constant buffers does not match the robustness2 alignment. Luckily, it all works out in practice with the 256 byte alignment on Nvidia hardware.

@K0bin K0bin force-pushed the constant-buffer-robustness branch 4 times, most recently from 94141e8 to 97dd2c8 Compare September 14, 2021 18:14
@Joshua-Ashton Joshua-Ashton merged commit 7f89fe1 into doitsujin:master Oct 15, 2021
@K0bin K0bin deleted the constant-buffer-robustness branch October 15, 2021 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[d3d9] Total War: MEDIEVAL II: ridiculously high system memory usage when loading battles
4 participants