Skip to content
This repository has been archived by the owner on Apr 17, 2022. It is now read-only.

Display scaling, live window resizing, and high-DPI support #4720

Closed
wzdev-ci opened this issue Jan 26, 2018 · 35 comments
Closed

Display scaling, live window resizing, and high-DPI support #4720

wzdev-ci opened this issue Jan 26, 2018 · 35 comments

Comments

@wzdev-ci
Copy link
Contributor

resolution_fixed type_patch (an actual patch, not a request for one) | by pastdue


PR: Warzone2100/warzone2100#113
Patch: https://github.com/Warzone2100/warzone2100/pull/113.patch


Issue migrated from trac:4720 at 2022-04-16 13:01:03 -0700

@wzdev-ci
Copy link
Contributor Author

pastdue commented


=== Overview

  1. Internal enhancements to support screen / game / rendering scaling factors.
  2. Internal enhancements to support live window resizing / resolution changes.
  3. Internal enhancements to support UI layout recalculation.
  4. Support for live window resizing / resolution changes.^[SDL backend]^
  5. "Display Scale" option in the Video options menu, offering 100%+ display scaling options. ^[SDL backend]^
  6. Automatic high-DPI ("retina") display support. ^[macOS-only]^
  7. Better caching of text rasterization and reduction in unnecessary OpenGL state changes (required to support higher display scaling levels).
  8. Better clipping and other small tweaks (required to support higher display scaling levels).

=== General

These changes all essentially depend on each other, thus this is a single PR.

=== Additional Details

  1. Text and other rendering now supports scaling factors.

  2. New functions in all of the various UI-related components / files enable a call to a new parent gameScreenSizeDidChange function that distributes notifications of screen size changes.

  3. Several enhancements of note:

    • WIDGET now supports a new calcLayout callback function / lambda that is called when layout needs to be recalculated.
    • WIDGET now supports a new onDelete callback function / lambda that is called when the instance is about to be deleted.
    • W_INIT now supports a new initPUserDataFunc attribute which can be used to initialize the pUserData pointer per widget instance.
    • Parent WIDGETs automatically distribute screen size change notifications to all children.
    • Where needed, UI widgets have been migrated to setting a calcLayout lambda.
  4. Simply open the Video options and change the Resolution. Or resize the window at the corners / edges (as supported by your OS).

    Current Limitations:

    • Only live resolution changes in the current mode are supported. If you change the display mode (windowed / fullscreen), changes will be queued until Warzone is restarted (matching previous behavior). This is due to several current SDL quirks.
    • Live resizing is disabled while in a multiplayer game because pausing is disabled in multiplayer games (and with how the current event loop + SDL works, the game effectively pauses while the window is being actively resized).
    • Only the SDL backend currently supports live resizing. Compiling with the QT backend will revert to the prior behavior.
  5. Open the Video options and select from the new Display Scale percentages (100%+) available at the current window size. (Display scale options are limited by the window / screen size, as no combination can result in a logical screen size lower than the minimum supported by Warzone. Hence, only users with very large displays - and the Warzone window expanded on those displays - will see the highest display scaling options. Most users probably won't see over 250% available.)

    Current Limitations:

    • Only the SDL backend currently supports Display Scale options. Compiling with the QT backend will not currently show the Display Scale option in the menu.
  6. On macOS, automatic support for high-DPI ("retina") displays is enabled. Once a future version of SDL enables proper high-DPI support for other OSes, they can be automatically supported too.

  7. Some highlights:

    • Switched over most text rendering to using the improved WzText, which caches and reduces text rasterization calls by over 99%, for a significant performance win. (Previously, most text was being re-rasterized on every frame, even if unchanged.)
    • A lot of time was previously being wasted enabling / disabling shaders... in loops that just kept enabling / disabling the same shader. New functions to batch calls and moving pie_DeactivateShader outside of loops yield a significant performance improvement (especially when running at higher display scaling modes that necessarily stress the engine more).
  8. Previously, the game engine spent a lot of time rendering things that were far off the visible screen. More accurate clipping techniques yield a large reduction in wasted non-visible drawing / calculations.

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file 4720_make_error.log (202.8 KiB)

complete command line output of ./make

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file git_apply.log (0.3 KiB)

complete command line output of git apply 113.patch

@wzdev-ci
Copy link
Contributor Author

Forgon changed blocking which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

Forgon changed blockedby which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

Forgon changed _comment0 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

Forgon commented


Your patch failed compilation in make due to an unused variable:

intdisplay.cpp: In function ‘void intDisplayEditBox(WIDGET*, UDWORD, UDWORD)’:
intdisplay.cpp:1228:18: error: variable ‘iDX’ set but not used [-Werror=unused-but-set-variable]
  UDWORD  iX, iY, iDX, iXRight;
                  ^~~

It also contained several whitespace errors. git apply 113.patch printed:

113.patch:307: trailing whitespace.
	
113.patch:360: trailing whitespace.
	
113.patch:530: trailing whitespace.
	
113.patch:582: trailing whitespace.
	
113.patch:595: trailing whitespace.
	
warning: squelched 187 whitespace errors
warning: 192 lines add whitespace errors.

These problems are now fixed (see attached file [raw-attachment:4720_update.patch]), yet others remain:

  • performance on my system is so bad that I must wait several seconds after starting a game until pressing keys to avoid a shutdown.
  • when rescaling the window, the cursor position is not updated, making the game unusable.

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 27, 2018

pastdue commented


Replying to Warzone2100/old-trac-import#4720 (comment:2):

These problems are now fixed (see attached file [raw-attachment:4720_update.patch]), yet others remain:

  • performance on my system is so bad that I must wait several seconds after starting a game until pressing keys to avoid a shutdown.
  • when rescaling the window, the cursor position is not updated, making the game unusable.

Hmm. I tested on several Mac and Windows systems, and I saw better performance in all cases. It makes me wonder if there is an SDL quirk triggering constant recalculations (or something similar).

Could I please get some more details on your system? (What OS / version? What graphics cards / hardware specs? Are you using the SDL backend? What version of SDL?)

@wzdev-ci
Copy link
Contributor Author

Forgon changed _comment0 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

Forgon changed _comment1 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 27, 2018

Forgon commented


Replying to Warzone2100/old-trac-import#4720 (comment:3):

Replying to Warzone2100/old-trac-import#4720 (comment:2):

These problems are now fixed (see attached file [raw-attachment:4720_update.patch]), yet others remain:

  • performance on my system is so bad that I must wait several seconds after starting a game until pressing keys to avoid a shutdown.
  • when rescaling the window, the cursor position is not updated, making the game unusable.

Hmm. I tested on several Mac and Windows systems, and I saw better performance in all cases. It makes me wonder if there is an SDL quirk triggering constant recalculations (or something similar).

Could I please get some more details on your system? (What OS / version? What graphics cards / hardware specs? Are you using the SDL backend? What version of SDL?)

I use ArchLinux with i3 (possibly the most important factor), the integrated graphics card of the Intel i5-2540M processor and SDL 2.0.7-1.

Edit: I updated the commit message for the updated patch to fix an erroneous newline and mention the displayScale config file variable you introduced

@wzdev-ci
Copy link
Contributor Author

Forgon uploaded file 4720_update.patch (272.2 KiB)

patch file created with git format-patch

@wzdev-ci
Copy link
Contributor Author

pastdue changed _comment0 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

pastdue changed _comment1 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 27, 2018

pastdue commented


Replying to Warzone2100/old-trac-import#4720 (comment:4):

I use ArchLinux with i3 (possibly the most important factor), the integrated graphics card of the Intel i5-2540M processor and SDL 2.0.7-1.

Edit: I updated the commit message for the updated patch to fix an erroneous newline and mention the displayScale config file variable you introduced

If you disable shadows, does it resolve the performance issues you are seeing on your system? Also, what version is your compiler?

EDIT: I believe I got this to reproduce, it does appear to be related to shadows. I have a working fix coming shortly.

EDIT(2): See 4720_b-part1.patch​, and 4720_b-part2.patch​ (split into two patches, per GitHub PR request).

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 27, 2018

Quenton commented


Replying to Warzone2100/old-trac-import#4720 (comment:3):

Hmm. I tested on several Mac and Windows systems, and I saw better performance in all cases. It makes me wonder if there is an SDL quirk triggering constant recalculations (or something similar).

can you upload the windows builds someplace? I got 2 testers for windows.

@wzdev-ci
Copy link
Contributor Author

pastdue uploaded file 4720_b-part1.patch (244.9 KiB)

Revised patch - part 1

@wzdev-ci
Copy link
Contributor Author

pastdue uploaded file 4720_b-part2.patch (28.8 KiB)

Revised patch - part 2

@wzdev-ci
Copy link
Contributor Author

Forgon commented


After applying [raw-attachment:4720_b-part1.patch] and [raw-attachment:4720_b-part2.patch], I still experience significant delays when pressing arrow keys that occasionally cause crashes, for which the last line of terminal output is:

i965: Failed to submit batch buffer: Input/output error

@wzdev-ci
Copy link
Contributor Author

pastdue changed _comment0 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

pastdue changed _comment1 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 28, 2018

pastdue commented


Replying to Warzone2100/old-trac-import#4720 (comment:7):

After applying [raw-attachment:4720_b-part1.patch] and [raw-attachment:4720_b-part2.patch], I still experience significant delays when pressing arrow keys that occasionally cause crashes, for which the last line of terminal output is:

i965: Failed to submit batch buffer: Input/output error

So just to confirm: When pressing the arrow keys in-game to move the camera, the game freezes before each tick of camera movement? Or does the game not freeze, but there is just a delay before the input has an effect? Would it be possible to record a short screen capture showing exactly what you see?

Would it be possible to get a log from a run of (patched) Warzone run with the --debug=ALL option where you:

  • Start a new game
  • Try to move the camera around with the arrow keys for however long it takes to show the delays.
  • Then immediately quit Warzone

Also, do you still see this same behavior on your system with just 4720_b-part1.patch applied?

And finally, what is the result of using showfps before these patches, after patch-1, and after patch-1&2 on your system?

@wzdev-ci
Copy link
Contributor Author

past-due <30942300+past-due@...> changed status from new to closed

@wzdev-ci
Copy link
Contributor Author

past-due <30942300+past-due@...> changed owner from `` to past-due <30942300+past-due@users.noreply.github.com>

@wzdev-ci
Copy link
Contributor Author

past-due <30942300+past-due@...> changed resolution from `` to fixed

@wzdev-ci
Copy link
Contributor Author

past-due <30942300+past-due@...> committed [413]


In Warzone2100/warzone2100@413a219:

#CommitTicketReference repository="" revision="413a2199acc48394f12e1e59b113c869c20018ad"
Fixes #4720: Display scaling, live window resizing, and high-DPI support

- Internal enhancements to support screen / game / rendering scaling factors.
- Internal enhancements to support live window resizing / resolution changes.
- Internal enhancements to support UI layout recalculation.
- [SDL backend] Support for live window resizing / resolution changes. (*Cannot currently change between Windowed / Fullscreen without restarting Warzone because of SDL quirks, but live resolution changes in the current mode are supported.)
- [SDL backend] New "displayScale" variable for config file (can also be set as "Display Scale" in video options), offering 100%-500%* display scaling options (*scaling options are limited by the window/screen size, as no combination can result in a logical screen size lower than the minimum supported by Warzone).
- [macOS] Automatic high-DPI ("retina") display support. (Currently limited to macOS because of SDL 2.0.x high-DPI support limitations.)
- Better caching of text rasterization (through judicious use of the improved WzText).

@wzdev-ci
Copy link
Contributor Author

pastdue changed status from closed to reopened

@wzdev-ci
Copy link
Contributor Author

pastdue changed resolution from fixed to ``

@wzdev-ci
Copy link
Contributor Author

Forgon changed _comment0 which not transferred by tractive

@wzdev-ci
Copy link
Contributor Author

wzdev-ci commented Jan 28, 2018

Forgon commented


Replying to Warzone2100/old-trac-import#4720 (comment:8):

Replying to Warzone2100/old-trac-import#4720 (comment:7):

After applying [raw-attachment:4720_b-part1.patch] and [raw-attachment:4720_b-part2.patch], I still experience significant delays when pressing arrow keys that occasionally cause crashes, for which the last line of terminal output is:

i965: Failed to submit batch buffer: Input/output error

So just to confirm: When pressing the arrow keys in-game to move the camera, the game freezes before each tick of camera movement? Or does the game not freeze, but there is just a delay before the input has an effect? Would it be possible to record a short screen capture showing exactly what you see?

Would it be possible to get a log from a run of (patched) Warzone run with the --debug=ALL option where you:

  • Start a new game
  • Try to move the camera around with the arrow keys for however long it takes to show the delays.
  • Then immediately quit Warzone

Also, do you still see this same behavior on your system with just 4720_b-part1.patch applied?

And finally, what is the result of using showfps before these patches, after patch-1, and after patch-1&2 on your system?

I have unfortunately not had the time to test yet -- but I will do so and show you the results.
Is it correct that you just undid your patch in Github, which now consists of 4 parts?

You wrote in the pull request:

@per: So I dug into this a bit more, and there's still an issue caused by a bug in SDL (not picking up "window manager resized the window" events) and attempting to set the windowed window size via the Video options menu. (Testing with i3 window manager on Ubuntu).

This issue (which deserves its own bug report) did already exist before your patch. Must live resizing in windowed mode be disabled for all systems? If it only fails with Unix, I would prefer to keep it enabled for all other systems by utilizing conditional compilation.

Also, does this patch require SDL version 2.0.4 or 2.0.5?

@wzdev-ci
Copy link
Contributor Author

pastdue commented


The Github PR now has 4 parts, yes. (I have not yet updated the patches here in Trac.)

It still enables everything we're talking about. That 4th commit simply disables "using the Resolution option in the Video options menu to change the windowed resolution".

You can still:

  • Live-resize the window using whatever options are available on your OS / window manager (dragging the sides / corners, etc).
  • Change the Resolution in Fullscreen mode using the menu.

You just can't use the Resolution menu option in Windowed mode to change the resolution - it just displays the current resolution. (There were more bugs with this than just the issue with SDL + tiling window managers. Now that live-resizing is available, using the menu option is unnecessary in Windowed mode.)

@wzdev-ci
Copy link
Contributor Author

pastdue commented


According to Forgon (via IRC), the issue he experienced related to performance degradation occurs even without this patch. (It's some combination of specific resolutions, anti-aliasing, and specifics of his system - perhaps the graphics driver.) He will be digging into that separately to try to track down what's going on his system.

The bottom line: This patch can be eliminated as a cause of the behavior Forgon is seeing. All feedback thus far relating to the patch yields a performance improvement.

@wzdev-ci
Copy link
Contributor Author

past-due <30942300+past-due@...> changed status from reopened to closed

@wzdev-ci
Copy link
Contributor Author

past-due <30942300+past-due@...> changed resolution from `` to fixed

@wzdev-ci
Copy link
Contributor Author

past-due <30942300+past-due@...> committed [619]


In Warzone2100/warzone2100@619e84d:

#CommitTicketReference repository="" revision="619e84d56189f45138ff18b3aea733dc15d9ca0c"
Fixes #4720: Display scaling, live window resizing, and high-DPI support

- Internal enhancements to support screen / game / rendering scaling factors.
- Internal enhancements to support live window resizing / resolution changes.
- Internal enhancements to support UI layout recalculation.
- [SDL backend] Support for live window resizing / resolution changes. (*Cannot currently change between Windowed / Fullscreen without restarting Warzone because of SDL quirks, but live resolution changes in the current mode are supported.)
- [SDL backend] New "displayScale" variable for config file (can also be set as "Display Scale" in video options), offering 100%-500%* display scaling options (*scaling options are limited by the window/screen size, as no combination can result in a logical screen size lower than the minimum supported by Warzone).
- [macOS] Automatic high-DPI ("retina") display support. (Currently limited to macOS because of SDL 2.0.x high-DPI support limitations.)
- Better caching of text rasterization (through judicious use of the improved WzText).

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

No branches or pull requests

1 participant