https://bugs.winehq.org/show_bug.cgi?id=55262
Bug ID: 55262 Summary: [POTENTIAL PERFORMANCE BOOST] [POTENTIAL CPU USAGE REDUCTION] [PATCH PROVIDED] SIMPLE CODE CHANGE FOUND TO BOOST FPS AND SEVERELY DECREASE CPU USAGE CAUSED BY "wined3d_cs_run" Product: Wine Version: 8.11 Hardware: x86-64 OS: Linux Status: UNCONFIRMED Severity: major Priority: P2 Component: d3d Assignee: wine-bugs@winehq.org Reporter: CHECK_1234543212345@protonmail.com CC: z.figura12@gmail.com Distribution: ---
Created attachment 74878 --> https://bugs.winehq.org/attachment.cgi?id=74878 WINED3D_CS_QUERY_POLL_INTERVAL_from_10u_to_200000u_remove_high_cpu_usage_caused_by_WINED3D_CS_SPIN_COUNT.patch
⬤ FOUND CODE THAT CAN BE CHANGED TO BOOST FPS AND REDUCE CPU USAGE CAUSED BY "wined3d_cs_run" BY ALOT
- A way to boost FPS by increasing number of "WINED3D_CS_QUERY_POLL_INTERVAL" has been FOUND!!!
- A way to reduce the CPU USAGE caused by "wined3d_cs_run" has been FOUND!!!
⬤ SETTINGS: - Default Wine 8.11 - Ryzen 7 1700 locked to 2.5GHZ (to keep fps stable) - RX 580 locked CORE/MEMORY locked to 300MHZ (echo "low" > /sys/class/drm/card0/device/power_dpm_force_performance_level) (to keep fps stable) - Window Manager: OpenBox - Compositor: No Compositor, Xorg TearFree Disabled - 16 bit color used to boost FPS - Used Wine to run the Windows version of Steam to run these games - "perf top" command used to see overhead caused by "wined3d_cs_run" - DXVK not used
⬤ GAMES USED: - Grapple (Free) (Heavy on GPU) (https://store.steampowered.com/app/1428870/Grapple/) - Brawlhalla (Free) (Light on GPU) (https://store.steampowered.com/app/291550/Brawlhalla/)
⬤ RESULTS: --------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 10u (Wine Default) WINED3D_CS_SPIN_COUNT 10000000u (Wine Default) Grapple Level 1: 89 FPS Brawlhalla Character Select CPU USAGE: 130.2% Brawlhalla "perf top" wined3d_cs_run overhead: 63.12% ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 10u (Wine Default) WINED3D_CS_SPIN_COUNT 10000u Grapple Level 1: 89 FPS Brawlhalla Character Select CPU USAGE: 42.8% Brawlhalla "perf top" wined3d_cs_run overhead: 1.50% ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 10u (Wine Default) WINED3D_CS_SPIN_COUNT 1000u Grapple Level 1: 86 FPS Brawlhalla Character Select CPU USAGE: 41.1% Brawlhalla "perf top" wined3d_cs_run overhead: 0.43% ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 100u WINED3D_CS_SPIN_COUNT 1000u Grapple Level 1: 91 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 1000u WINED3D_CS_SPIN_COUNT 1000u Grapple Level 1: 94 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 10000u WINED3D_CS_SPIN_COUNT 1000u Grapple Level 1: 94-95 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 100000u WINED3D_CS_SPIN_COUNT 1000u Grapple Level 1: 94-95 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 200000u WINED3D_CS_SPIN_COUNT 1000u Grapple Level 1: 94-95 FPS Brawlhalla Character Select CPU USAGE: 41.0% Brawlhalla "perf top" wined3d_cs_run overhead: 0.40% ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 200000u WINED3D_CS_SPIN_COUNT 10000000u (Wine Default) Grapple Level 1: 94-95 FPS Brawlhalla Character Select CPU USAGE: 130.2% Brawlhalla "perf top" wined3d_cs_run overhead: 63.07% ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 250000u WINED3D_CS_SPIN_COUNT 1000u Grapple Level 1: 94 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 300000u WINED3D_CS_SPIN_COUNT 1000u Grapple Level 1: 94 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 1000000u WINED3D_CS_SPIN_COUNT 1000u Grapple Level 1: 93-94 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINED3D_CS_QUERY_POLL_INTERVAL 10000000u WINED3D_CS_SPIN_COUNT 1000u Grapple Level 1: 52 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- 2nd BEST: WINED3D_CS_QUERY_POLL_INTERVAL 200000u WINED3D_CS_SPIN_COUNT 1u Grapple Level 1: 96 FPS Brawlhalla Character Select CPU USAGE: 40.7% Brawlhalla "perf top" wined3d_cs_run overhead: "wined3d_cs_run" overhead too low, not able to see ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- BEST: PATCH PROVIDED WINED3D_CS_QUERY_POLL_INTERVAL 200000u "++spin_count >= WINED3D_CS_SPIN_COUNT && " removed in "dlls/wind3d/cs.c" Grapple Level 1: 96 FPS Brawlhalla Character Select CPU USAGE: 39.1% Brawlhalla "perf top" wined3d_cs_run overhead: "wined3d_cs_run" overhead too low, not able to see ---------------------------------------------------------------------------------------------------------------
⬤ CONCLUSION:
- 1. Increasing "WINED3D_CS_QUERY_POLL_INTERVAL" from "10u" to "200000u" BOOSTED the FPS!!!
- 2. Decreasing "WINED3D_CS_SPIN_COUNT" from "10000000u" to "1u" or removing "++spin_count >= WINED3D_CS_SPIN_COUNT && " in "dlls/wind3d/cs.c" fixes what causes games that are light on the GPU to have high CPU USAGE caused by "wined3d_cs_run" when checking using "perf top"!!!
- 3. I also tested other games and saw reduced CPU Usage by alot because of "wined3d_cs_run" now taking less CPU USAGE!!!
- 4. HOPEFULLY A DEVELOPER SEES THIS SO THAT THIS COULD BE APPLIED INTO WINE, CHANGING THOSE CODE GAVE A GOOD FPS BOOST AND REDUCED CPU USAGE CAUSED BY "wined3d_cs_run"!!!
- 5. I have not checked if changing those code increases the FPS when using DXVK
⬤ HOW TO APPLY PATCH:
- 1. "cd" into wine source code
- 2. do "patch -p0 < WINED3D_CS_QUERY_POLL_INTERVAL_from_10u_to_200000u_remove_high_cpu_usage_caused_by_WINED3D_CS_SPIN_COUNT.patch"
https://bugs.winehq.org/show_bug.cgi?id=55262
CHECK_1234 CHECK_1234543212345@protonmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |dark.shadow4@web.de
https://bugs.winehq.org/show_bug.cgi?id=55262
CHECK_1234 CHECK_1234543212345@protonmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |CHECK_1234543212345@protonm | |ail.com
https://bugs.winehq.org/show_bug.cgi?id=55262
CHECK_1234 CHECK_1234543212345@protonmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- CC| |matteo.mystral@gmail.com
https://bugs.winehq.org/show_bug.cgi?id=55262
--- Comment #1 from CHECK_1234 CHECK_1234543212345@protonmail.com --- ⬤ UPDATE 2:
I noticed that someone already reduced "WINED3D_CS_SPIN_COUNT" from 10000000u to 2000u with commit https://github.com/wine-mirror/wine/commit/f032ccc2715a5525601f741337a7bc7df... in Wine 8.12 (Did not know when I was making this bug report and I was still in Wine 8.11)!!!
But I saw "WINED3D_CS_QUERY_POLL_INTERVAL" was still set to "10u", and increasing "WINED3D_CS_QUERY_POLL_INTERVAL" to high number like "200000u" INCREASED MY FPS!!!
Hopefully that same person that decreased "WINED3D_CS_SPIN_COUNT" from "10000000u" to "2000u" could also make commit increasing "WINED3D_CS_QUERY_POLL_INTERVAL" from "10u" to a higher number like "200000u" which INCREASED MY FPS!!!
https://bugs.winehq.org/show_bug.cgi?id=55262
--- Comment #2 from CHECK_1234 CHECK_1234543212345@protonmail.com --- ⬤ UPDATE 3: PERFORMANCE REGRESSION IN WINE 8.12 FOUND
WINE 8.12: WINED3D_CS_QUERY_POLL_INTERVAL 200000u Grapple Level 1: 26 FPS
WINE 8.11: WINED3D_CS_QUERY_POLL_INTERVAL 200000u Grapple Level 1: 96 FPS
In WINE 8.12, setting "WINED3D_CS_QUERY_POLL_INTERVAL" to 200000u gives 26 FPS, but in WINE8.11 setting "WINED3D_CS_QUERY_POLL_INTERVAL" to 200000u gives 96 FPS!!!
https://bugs.winehq.org/show_bug.cgi?id=55262
--- Comment #3 from CHECK_1234 CHECK_1234543212345@protonmail.com --- ⬤ UPDATE 4: WINE 8.12 PERFORMANCE REGRESSION HAS BEEN SOLVED!!!
--------------------------------------------------------------------------------------------------------------- WINE 8.12: WINED3D_CS_QUERY_POLL_INTERVAL 10u (Default for Wine 8.12) Grapple Level 1: 88 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINE 8.12: WINED3D_CS_QUERY_POLL_INTERVAL 2500u Grapple Level 1: 96 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINE 8.12: WINED3D_CS_QUERY_POLL_INTERVAL 25000u Grapple Level 1: 87 FPS ---------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------- WINE 8.11: WINED3D_CS_QUERY_POLL_INTERVAL 200000u Grapple Level 1: 96 FPS ---------------------------------------------------------------------------------------------------------------
Wine 8.12 "WINED3D_CS_QUERY_POLL_INTERVAL" set to "2500u" now gives the same FPS as WINE 8.11 with "WINED3D_CS_QUERY_POLL_INTERVAL" set to 200000u.
Hopefully someone could now make it commit changing "WINED3D_CS_QUERY_POLL_INTERVAL" from "10u" to "2500u" which gave me an 8 FPS PERFORMANCE BOOST from the default of "WINED3D_CS_QUERY_POLL_INTERVAL" in Wine 8.12!!!
https://bugs.winehq.org/show_bug.cgi?id=55262
Fabian Maurer dark.shadow4@web.de changed:
What |Removed |Added ---------------------------------------------------------------------------- Summary|[POTENTIAL PERFORMANCE |Potential performance |BOOST] [POTENTIAL CPU USAGE |improvement in wined3d |REDUCTION] [PATCH PROVIDED] | |SIMPLE CODE CHANGE FOUND TO | |BOOST FPS AND SEVERELY | |DECREASE CPU USAGE CAUSED | |BY "wined3d_cs_run" | Severity|major |enhancement
--- Comment #4 from Fabian Maurer dark.shadow4@web.de --- Please stop it with the caps and the exclamation marks, it's considered rude and makes it less likely that someone takes your comments seriously.
Also keep in mind that those changes affect every game, I doubt it's that easy at it seems. But feel free to submit those changes as MR and see what the devs say?
https://bugs.winehq.org/show_bug.cgi?id=55262
Zeb Figura z.figura12@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |performance
--- Comment #5 from Zeb Figura z.figura12@gmail.com --- Reducing the spin count is a double-edged sword. On the one hand, it obviously means the CS takes less time spinning. On the other, it means the CS will be slower to respond to new commands if it's empty.
Increasing the query poll interval is also a double-edged sword. On the one hand, it will stop wasting time checking for queries which probably aren't ready yet, and thereby allow the CS thread to process commands faster. On the other, it means that we will notice queries that *are* ready later.
The effect is that both of these may very well end up being application- and driver-specific whether modifying them helps, hurts, or has no effect.
Now, in practice, wrt the spin count, it used to be that streaming buffer mapping and UpdateSubResource (which are both very common operations) were synchronous, which, among other things, had the effect that the CS would be empty more often, and that's one reason why the spin count had been set so high. That's no longer the case, and as a result we believe that at this point the spin count can be lowered, and perhaps even removed entirely (as you have experiemented with).
As for query polling, I'm less familiar with the concerns there, but it's certainly possible that the interval we have is categorically too low. We may also want to do polling based on time instead of spin count (i.e. poll at some interval after a command finishes).
The main point is that it can be dangerous to test one application and then assume that the updated settings are better for all applications.
https://bugs.winehq.org/show_bug.cgi?id=55262
--- Comment #6 from Austin English austinenglish@gmail.com --- (In reply to Zeb Figura from comment #5)
Reducing the spin count is a double-edged sword. On the one hand, it obviously means the CS takes less time spinning. On the other, it means the CS will be slower to respond to new commands if it's empty.
Could the setting be set in the registry, so users can experiment/tweak it without compiling, and allowing it to be set per prefix?