flyinghead / flycast

Flycast is a multiplatform Sega Dreamcast, Naomi, Naomi 2 and Atomiswave emulator
GNU General Public License v2.0
1.38k stars 168 forks source link

HiDPI setting ignored with Wayland+Vulkan #648

Open sjnewbury opened 2 years ago

sjnewbury commented 2 years ago

There is currently no Wayland-Vulkan support outside of SDL2 and libretro, I'm not sure how much this matters.

With respect to SDL2, it works fine with OpenGL, but things goes quite wrong with Vulkan:

Under Wayland Vulkan surfaces are created with the size initially undefined until first used. This means the determination of the resolution and DPI fails since it uses SDL_Vulkan_GetDrawableSize() before any frames are rendered.

This results in the swap chain being created with the fallback 640x480 resolution and the output is unscaled appearing as a postage stamp on a 4K screen!

Changing the fallback resolution to the native display resolution does make the emulator usable although of course the UI isn't scaled.

This could be worked around when OpenGL is enabled by using a GL surface to get the resolution but that would be a horrible hack. The only real solution I can think of is to leave determining of the resolution and DPI until after the first frame is rendered.

sjnewbury commented 2 years ago

Another issue is window resizing isn't affecting the render resolution, at least in Sway. If resizing worked, the code to determine dpi/scaling could be factored out and be called on resize etc since it's probably necessary anyway to pick up on changes to the scaling factor, due to reconfiguration or change of output.

flyinghead commented 2 years ago

The internal render resolution is independent from the window size/screen resolution. One reason is that non-integer scaling factors introduce texture seams and bleeding. Even the built-in ".5" factors aren't recommended.

sjnewbury commented 2 years ago

I've not found a option which affects the initial internal resolution with wayland/vulkan. The surface gets resized to the Vulkan swap chain resolution which is the only way I've found to make it "work" with hard coded values (I'm also setting the uiScale so I can read the UI text!). Otherwise the window appears at 640x480 and the rendering stays that way even if the window is fullscreened. Interestingly, setting the internal resolution from the in-emulator settings menu works fine.

It works with Xorg/Xwayland because there the drawable is created immediately with the (scaled) window geometry, while on Wayland it's only created after the swap chain is set up and the drawable resized.

flyinghead commented 1 year ago

This should be fixed on the dev branch. Resizing now works and window decorations are managed by libdecor (if installed).

sjnewbury commented 1 year ago

Cool! I'll give it a spin!

sjnewbury commented 1 year ago

It's much better now, but still doesn't detect HiDPI scaling.

flyinghead commented 1 year ago

Is it just not detecting HiDPI or is the rendering surface sized incorrectly?

sjnewbury commented 1 year ago

@flyinghead hidpi scaling is set to 2.0 so my 3840x2160 screen appears like 1920x1080. This is necessary with a UHD TV view from meters away (believe me!). flycast detects the resolution of the underlying surface, rather than the presented hidpi display resolution so everything is too small to see. The code is there for scaling (which I assume is working on other platforms) it's just not detected on Wayland. Forcing the scaling by hacking the source works fine, so as a temporary workaround an argument could be used to override the scaling factor.

flyinghead commented 1 year ago

So to summarize the sizing of the surface is correct, but the scaling is not.

I assume Flycast must be getting the DPI of the low resolution surface to calculate scaling. It should be adjusted to the actual HiDPI resolution of the surface (x2 here).

sjnewbury commented 1 year ago

Yes, it's rendering fine, but UI elements and text are too small to comfortably see.

I'll need to read the code again to be sure what it's actually doing. I would say it's the opposite though as a guess. The windowing system co-ordinates and returned display mode geometry are scaled (at 2x by 0.5) the surface is of course the actual native resolution. In other projects I've usually just calculated the ratio between window geometry and surface resolution to get the scaling factor where the toolkit doesn't provide a hint.

vkedwardli commented 1 year ago

Is it possible to share your monitor's EDID info? (may be running sudo xrandr --verbose, not sure if it is supported in Wayland)

sjnewbury commented 1 year ago

As requested:

`edid-decode < /sys/class/drm/card0-DP-5/edid edid-decode (hex):

00 ff ff ff ff ff ff 00 4c 2d ef 0f 00 0e 00 01 01 1d 01 03 80 81 48 78 0a 23 ad a4 54 4d 99 26 0f 47 4a bd ef 80 71 4f 81 c0 81 00 81 80 95 00 a9 c0 b3 00 d1 c0 08 e8 00 30 f2 70 5a 80 b0 58 8a 00 50 1d 74 00 00 1e 56 5e 00 a0 a0 a0 29 50 30 20 35 00 50 1d 74 00 00 1a 00 00 00 fd 00 18 4b 0f 87 3c 00 0a 20 20 20 20 20 20 00 00 00 fc 00 53 41 4d 53 55 4e 47 0a 20 20 20 20 20 01 f3

02 03 57 f0 56 61 10 1f 04 13 05 14 20 21 22 5d 5e 5f 60 65 66 62 64 07 16 03 12 29 09 07 07 15 07 50 57 07 00 83 01 00 00 e2 00 4f e3 05 c3 01 6e 03 0c 00 30 00 b8 3c 28 00 80 01 02 03 04 68 d8 5d c4 01 78 80 03 02 e3 06 0d 01 e4 0f 01 e4 01 e5 01 00 00 00 00 02 3a 80 18 71 38 2d 40 58 2c 45 00 50 1d 74 00 00 1e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 79


Block 0, Base EDID: EDID Structure Version & Revision: 1.3 Vendor & Product Identification: Manufacturer: SAM Model: 4079 Serial Number: 16780800 Made in: week 1 of 2019 Basic Display Parameters & Features: Digital display Maximum image size: 129 cm x 72 cm Gamma: 2.20 RGB color display First detailed timing is the preferred timing Color Characteristics: Red : 0.6406, 0.3300 Green: 0.3007, 0.6005 Blue : 0.1503, 0.0605 White: 0.2802, 0.2900 Established Timings I & II: IBM : 720x400 70.082 Hz 9:5 31.467 kHz 28.320 MHz DMT 0x04: 640x480 59.940 Hz 4:3 31.469 kHz 25.175 MHz Apple : 640x480 66.667 Hz 4:3 35.000 kHz 30.240 MHz DMT 0x05: 640x480 72.809 Hz 4:3 37.861 kHz 31.500 MHz DMT 0x06: 640x480 75.000 Hz 4:3 37.500 kHz 31.500 MHz DMT 0x09: 800x600 60.317 Hz 4:3 37.879 kHz 40.000 MHz DMT 0x0a: 800x600 72.188 Hz 4:3 48.077 kHz 50.000 MHz DMT 0x0b: 800x600 75.000 Hz 4:3 46.875 kHz 49.500 MHz Apple : 832x624 74.551 Hz 4:3 49.726 kHz 57.284 MHz DMT 0x10: 1024x768 60.004 Hz 4:3 48.363 kHz 65.000 MHz DMT 0x11: 1024x768 70.069 Hz 4:3 56.476 kHz 75.000 MHz DMT 0x12: 1024x768 75.029 Hz 4:3 60.023 kHz 78.750 MHz DMT 0x24: 1280x1024 75.025 Hz 5:4 79.976 kHz 135.000 MHz Apple : 1152x870 75.062 Hz 192:145 68.681 kHz 100.000 MHz Standard Timings: DMT 0x15: 1152x864 75.000 Hz 4:3 67.500 kHz 108.000 MHz DMT 0x55: 1280x720 60.000 Hz 16:9 45.000 kHz 74.250 MHz DMT 0x1c: 1280x800 59.810 Hz 16:10 49.702 kHz 83.500 MHz DMT 0x23: 1280x1024 60.020 Hz 5:4 63.981 kHz 108.000 MHz DMT 0x2f: 1440x900 59.887 Hz 16:10 55.935 kHz 106.500 MHz DMT 0x53: 1600x900 60.000 Hz 16:9 60.000 kHz 108.000 MHz (RB) DMT 0x3a: 1680x1050 59.954 Hz 16:10 65.290 kHz 146.250 MHz DMT 0x52: 1920x1080 60.000 Hz 16:9 67.500 kHz 148.500 MHz Detailed Timing Descriptors: DTD 1: 3840x2160 60.000 Hz 16:9 135.000 kHz 594.000 MHz (1872 mm x 1053 mm) Hfront 176 Hsync 88 Hback 296 Hpol P Vfront 8 Vsync 10 Vback 72 Vpol P DTD 2: 2560x1440 59.951 Hz 16:9 88.787 kHz 241.500 MHz (1872 mm x 1053 mm) Hfront 48 Hsync 32 Hback 80 Hpol P Vfront 3 Vsync 5 Vback 33 Vpol N Display Range Limits: Monitor ranges (GTF): 24-75 Hz V, 15-135 kHz H, max dotclock 600 MHz Display Product Name: 'SAMSUNG' Extension blocks: 1 Checksum: 0xf3


Block 1, CTA-861 Extension Block: Revision: 3 Underscans IT Video Formats by default Basic audio support Supports YCbCr 4:4:4 Supports YCbCr 4:2:2 Native detailed modes: 0 Video Data Block: VIC 97: 3840x2160 60.000 Hz 16:9 135.000 kHz 594.000 MHz VIC 16: 1920x1080 60.000 Hz 16:9 67.500 kHz 148.500 MHz VIC 31: 1920x1080 50.000 Hz 16:9 56.250 kHz 148.500 MHz VIC 4: 1280x720 60.000 Hz 16:9 45.000 kHz 74.250 MHz VIC 19: 1280x720 50.000 Hz 16:9 37.500 kHz 74.250 MHz VIC 5: 1920x1080i 60.000 Hz 16:9 33.750 kHz 74.250 MHz VIC 20: 1920x1080i 50.000 Hz 16:9 28.125 kHz 74.250 MHz VIC 32: 1920x1080 24.000 Hz 16:9 27.000 kHz 74.250 MHz VIC 33: 1920x1080 25.000 Hz 16:9 28.125 kHz 74.250 MHz VIC 34: 1920x1080 30.000 Hz 16:9 33.750 kHz 74.250 MHz VIC 93: 3840x2160 24.000 Hz 16:9 54.000 kHz 297.000 MHz VIC 94: 3840x2160 25.000 Hz 16:9 56.250 kHz 297.000 MHz VIC 95: 3840x2160 30.000 Hz 16:9 67.500 kHz 297.000 MHz VIC 96: 3840x2160 50.000 Hz 16:9 112.500 kHz 594.000 MHz VIC 101: 4096x2160 50.000 Hz 256:135 112.500 kHz 594.000 MHz VIC 102: 4096x2160 60.000 Hz 256:135 135.000 kHz 594.000 MHz VIC 98: 4096x2160 24.000 Hz 256:135 54.000 kHz 297.000 MHz VIC 100: 4096x2160 30.000 Hz 256:135 67.500 kHz 297.000 MHz VIC 7: 1440x480i 59.940 Hz 16:9 15.734 kHz 27.000 MHz VIC 22: 1440x576i 50.000 Hz 16:9 15.625 kHz 27.000 MHz VIC 3: 720x480 59.940 Hz 16:9 31.469 kHz 27.000 MHz VIC 18: 720x576 50.000 Hz 16:9 31.250 kHz 27.000 MHz Audio Data Block: Linear PCM: Max channels: 2 Supported sample rates (kHz): 48 44.1 32 Supported sample sizes (bits): 24 20 16 AC-3: Max channels: 6 Supported sample rates (kHz): 48 44.1 32 Maximum bit rate: 640 kb/s Enhanced AC-3 (DD+): Max channels: 8 Supported sample rates (kHz): 48 44.1 32 Speaker Allocation Data Block: FL/FR - Front Left/Right Video Capability Data Block: YCbCr quantization: No Data RGB quantization: Selectable (via AVI Q) PT scan behavior: No Data IT scan behavior: Supports both over- and underscan CE scan behavior: Supports both over- and underscan Colorimetry Data Block: xvYCC601 xvYCC709 BT2020YCC BT2020RGB Vendor-Specific Data Block (HDMI), OUI 00-0C-03: Source physical address: 3.0.0.0 Supports_AI DC_36bit DC_30bit DC_Y444 Maximum TMDS clock: 300 MHz Supported Content Types: Game Extended HDMI video details: HDMI VICs: HDMI VIC 1: 3840x2160 30.000 Hz 16:9 67.500 kHz 297.000 MHz HDMI VIC 2: 3840x2160 25.000 Hz 16:9 56.250 kHz 297.000 MHz HDMI VIC 3: 3840x2160 24.000 Hz 16:9 54.000 kHz 297.000 MHz HDMI VIC 4: 4096x2160 24.000 Hz 256:135 54.000 kHz 297.000 MHz Vendor-Specific Data Block (HDMI Forum), OUI C4-5D-D8: Version: 1 Maximum TMDS Character Rate: 600 MHz SCDC Present Supports 12-bits/component Deep Color 4:2:0 Pixel Encoding Supports 10-bits/component Deep Color 4:2:0 Pixel Encoding Supports Auto Low-Latency Mode HDR Static Metadata Data Block: Electro optical transfer functions: Traditional gamma - SDR luminance range SMPTE ST2084 Hybrid Log-Gamma Supported static metadata descriptors: Static metadata type 1 YCbCr 4:2:0 Capability Map Data Block: VIC 97: 3840x2160 60.000 Hz 16:9 67.500 kHz 297.000 MHz VIC 93: 3840x2160 24.000 Hz 16:9 27.000 kHz 148.500 MHz VIC 96: 3840x2160 50.000 Hz 16:9 56.250 kHz 297.000 MHz VIC 101: 4096x2160 50.000 Hz 256:135 56.250 kHz 297.000 MHz VIC 102: 4096x2160 60.000 Hz 256:135 67.500 kHz 297.000 MHz VIC 98: 4096x2160 24.000 Hz 256:135 27.000 kHz 148.500 MHz Vendor-Specific Video Data Block, OUI 00-00-00: 00 '.' Detailed Timing Descriptors: DTD 3: 1920x1080 60.000 Hz 16:9 67.500 kHz 148.500 MHz (1872 mm x 1053 mm) Hfront 88 Hsync 44 Hback 148 Hpol P Vfront 4 Vsync 5 Vback 36 Vpol P Checksum: 0x79`