hajimehoshi / ebiten

Ebitengine - A dead simple 2D game engine for Go
https://ebitengine.org
Apache License 2.0
11.13k stars 663 forks source link

Vsync not working on some PCs #3003

Closed erexo closed 6 months ago

erexo commented 6 months ago

Ebitengine Version

86e0bcc26472c8da05fac66d84d5dd3869d55e00

Operating System

Go Version (go version)

go version go1.20.13 windows/amd64

What steps will reproduce the problem?

When I upgraded my game to latest ebitengine (d0aaa23005312a245f6d735964637f1aabad36b4) one of my players noticed that the ebiten.SetVsyncEnabled(true) does not work, that is the FPSes are not capped and the GPU usage is very, very high. It's quite strange because he is the only reported case, other players (including myself) can limit their FPSes.

His dxdiag:


------------------
System Information
------------------
      Time of this report: 5/29/2024, 00:06:15
             Machine name: DESKTOP-F44N2BQ
               Machine Id: {CABE96D1-EEFE-4041-A864-C0598CD2C59B}
         Operating System: Windows 10 Pro 64-bit (10.0, Build 19045) (19041.vb_release.191206-1406)
                 Language: Polish (Regional Setting: Polish)
      System Manufacturer: Gigabyte Technology Co., Ltd.
             System Model: To be filled by O.E.M.
                     BIOS: F5 (type: UEFI)
                Processor: AMD A8-6600K APU with Radeon(tm) HD Graphics    (4 CPUs), ~3.9GHz
                   Memory: 28672MB RAM
      Available OS Memory: 28612MB RAM
                Page File: 6017MB used, 22593MB available
              Windows Dir: C:\Windows
          DirectX Version: DirectX 12
      DX Setup Parameters: Not found
         User DPI Setting: 96 DPI (100 percent)
       System DPI Setting: 96 DPI (100 percent)
          DWM DPI Scaling: Disabled
                 Miracast: Available, no HDCP
Microsoft Graphics Hybrid: Not Supported
 DirectX Database Version: 1.0.8
           DxDiag Version: 10.00.19041.4355 64bit Unicode

------------
DxDiag Notes
------------
      Display Tab 1: No problems found.
        Sound Tab 1: No problems found.
        Sound Tab 2: No problems found.
        Sound Tab 3: No problems found.
        Sound Tab 4: No problems found.
          Input Tab: No problems found.

--------------------
DirectX Debug Levels
--------------------
Direct3D:    0/4 (retail)
DirectDraw:  0/4 (retail)
DirectInput: 0/5 (retail)
DirectMusic: 0/5 (retail)
DirectPlay:  0/9 (retail)
DirectSound: 0/5 (retail)
DirectShow:  0/6 (retail)

---------------
Display Devices
---------------
           Card name: NVIDIA GeForce GT 710
        Manufacturer: NVIDIA
           Chip type: NVIDIA GeForce GT 710
            DAC type: Integrated RAMDAC
         Device Type: Full Device (POST)
          Device Key: Enum\PCI\VEN_10DE&DEV_128B&SUBSYS_8C931462&REV_A1
       Device Status: 0180200A [DN_DRIVER_LOADED|DN_STARTED|DN_DISABLEABLE|DN_NT_ENUMERATOR|DN_NT_DRIVER] 
 Device Problem Code: No Problem
 Driver Problem Code: Unknown
      Display Memory: 16313 MB
    Dedicated Memory: 2007 MB
       Shared Memory: 14305 MB
        Current Mode: 1920 x 1080 (32 bit) (60Hz)
         HDR Support: Not Supported
    Display Topology: Internal
 Display Color Space: DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
     Color Primaries: Red(0.646484,0.333008), Green(0.321289,0.625977), Blue(0.157227,0.060547), White Point(0.312500,0.329102)
   Display Luminance: Min Luminance = 0.500000, Max Luminance = 270.000000, MaxFullFrameLuminance = 270.000000
        Monitor Name: Generic PnP Monitor
       Monitor Model: S22D300
          Monitor Id: SAM0B3B
         Native Mode: 1920 x 1080(p) (60.000Hz)
         Output Type: HDMI
Monitor Capabilities: HDR Not Supported
Display Pixel Format: DISPLAYCONFIG_PIXELFORMAT_32BPP
      Advanced Color: Not Supported
         Driver Name: C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_964d6838c79da0a2\nvldumdx.dll,C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_964d6838c79da0a2\nvldumdx.dll,C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_964d6838c79da0a2\nvldumdx.dll,C:\Windows\System32\DriverStore\FileRepository\nv_dispi.inf_amd64_964d6838c79da0a2\nvldumdx.dll
 Driver File Version: 30.00.0014.7482 (English)
      Driver Version: 30.0.14.7482
         DDI Version: 12
      Feature Levels: 11_0,10_1,10_0,9_3,9_2,9_1
        Driver Model: WDDM 2.7
 Hardware Scheduling: Supported:False Enabled:False 
 Graphics Preemption: DMA
  Compute Preemption: DMA
            Miracast: Not Supported
      Detachable GPU: No
 Hybrid Graphics GPU: Not Supported
      Power P-states: Not Supported
      Virtualization: Paravirtualization 
          Block List: No Blocks
  Catalog Attributes: Universal:False Declarative:True 
   Driver Attributes: Final Retail
    Driver Date/Size: 14.01.2024 02:00:00, 1057168 bytes
         WHQL Logo'd: Yes
     WHQL Date Stamp: Unknown
   Device Identifier: {D7B71E3E-51CB-11CF-E86A-9DAC0EC2D335}
           Vendor ID: 0x10DE
           Device ID: 0x128B
           SubSys ID: 0x8C931462... (Pozostało: 51 KB)

I've managed to pinpoint this issue to this strange commit 86e0bcc26472c8da05fac66d84d5dd3869d55e00, that is one commit after everything was working as expected.

Additionally some players reported that their GPU usage is noticeably higher even if the vsync is working correctly, and the problem also seems to be it this particular commit.

What is the expected result?

vsync should work, GPU usage should be limited

What happens instead?

for unknown reason one player reported that vsync is completely not working and others report increased resources usage

Anything else you feel useful to add?

~~ It does not seems to be related to OpenGL/DirectX ~~

erexo commented 6 months ago

EDIT: when I reverted changes made in this particular commit, it seems that vsync is now working properly on OpenGL (and DirectX still not) for that user, and others claim that the GPU usage is reduced

hajimehoshi commented 6 months ago

This change was only for OpenGL. Let me think, but I feel like reverting the change should be less risky.

erexo commented 6 months ago

As I mentioned reverting this commit fixes the OpenGL case, but people also report that DirectX still can take up to 95% of GPU resources. I'll try to investigate more

hajimehoshi commented 6 months ago

Perhaps, didn't the environment disable vsync in a hardware setting? (e.g. Nvidia Control Panel)

https://www.nvidia.com/en-us/geforce/technologies/adaptive-vsync/technology/

erexo commented 6 months ago

I'm not sure, but I sent one player two game clients, first with this commit and second without it, and he claims that he run both of those clients one by one, and the client "with" the commit was using extreme amounts of GPU, and the one "without" was fine.

Currently my released version is using more or less HEAD with changes in this commit specifically excluded and I heard no complains about anything really.

And it's not only the vsync problem, as I mentioned some of the players report that the GPU usage was increased (while the vsync is working correctly), and also just by removing this commit I was able to return the GPU usage to the proper values

hajimehoshi commented 6 months ago

OK I reverted the suspicious commit. Thanks!