From 82d036fd296ef36124e90fc01b852c4be82842f7 Mon Sep 17 00:00:00 2001 From: mlopezsegura <90263997+mlopezsegura@users.noreply.github.com> Date: Sat, 14 Nov 2026 13:53:48 +0100 Subject: [PATCH] RemoteIdd: lift the refresh-rate cap Sessions now go up to 500 fps (RemoteIdd's Hz follow them), the most an RDP session can compose since Windows ignores frame intervals under 2 ms. Above 250 fps the smooth composition interval drops to 3 or 2 ms instead of staying at 4 ms, which held every session at 250 Hz. The driver and install.ps1 accept up to 1000 Hz for manual tests. Co-Authored-By: Claude Opus 5.5 --- Core/Api/StreamSessionService.cs | 2 +- Core/Helpers/RdpSessionCreator.cs | 17 +++++++++++--- Core/wwwroot/index.html | 2 +- Native/RemoteIdd/Driver.cpp | 10 ++++++-- Native/RemoteIdd/Provider/install.ps1 | 2 +- .../CompositionIntervalTests.cs | 23 +++++++++++++++++++ 6 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 tests/OpenStreamMS.Tests/CompositionIntervalTests.cs diff --git a/Core/Api/StreamSessionService.cs b/Core/Api/StreamSessionService.cs index 3de5a93..ab6cc7d 100644 --- a/Core/Api/StreamSessionService.cs +++ b/Core/Api/StreamSessionService.cs @@ -1333,7 +1333,7 @@ private static RdpDisplayOptions DisplayOptions(StreamSession session) => new(session.RdpDisplayScale, session.RdpComposition); private static int NormalizeRdpFrameRate(int frameRate) => - Math.Clamp(frameRate > 0 ? frameRate : 60, 1, 240); + Math.Clamp(frameRate > 0 ? frameRate : 60, 1, RdpSessionCreator.MaxFrameRate); private static int NormalizeRdpColorDepth(int colorDepth) => colorDepth switch { diff --git a/Core/Helpers/RdpSessionCreator.cs b/Core/Helpers/RdpSessionCreator.cs index 5c1a60c..276119d 100644 --- a/Core/Helpers/RdpSessionCreator.cs +++ b/Core/Helpers/RdpSessionCreator.cs @@ -817,8 +817,10 @@ static void ApplyFrameRatePolicy(int frameRate, RdpCompositionMode mode) /// frame al llegar con tope de fps (display_base.cpp). Cada frame del juego sale en el /// siguiente tic de composicion: con 8 ms (125 Hz) salian a 16/24 ms y Moonlight /// descartaba hasta un 10 % por jitter; con 4 ms el desfase maximo es la mitad. No se - /// baja de 4 ms (500 Hz con 120 fps): el coste de componer y de RDP crece con el ritmo. - /// Windows ignora intervalos por debajo de 2 ms. + /// baja de 4 ms (250 Hz) mientras eso alcance a los fps: el coste de componer y de RDP crece + /// con el ritmo. Por encima de 250 fps se compone al intervalo entero que no se quede por + /// debajo de los fps (300 -> 3 ms, 334 Hz; 400 -> 2 ms, 500 Hz). Windows ignora intervalos + /// por debajo de 2 ms, así que 500 Hz es el techo. /// /// /// compone a los fps, redondeando al ms mas @@ -834,6 +836,8 @@ internal static int CompositionIntervalMs(int frameRate, RdpCompositionMode mode return Math.Max(2, 1000 / frameRate); if (mode == RdpCompositionMode.Efficient) return Math.Max(2, (int)Math.Round(1000.0 / frameRate, MidpointRounding.AwayFromZero)); + if (frameRate > 250) + return Math.Max(2, 1000 / frameRate); return Math.Max(4, 1000 / (4 * frameRate)); } @@ -1565,8 +1569,15 @@ static string NormalizeDomain(string? domain) => ? Environment.MachineName : domain.Trim(); + /// + /// Tope de fps de la sesión (y de Hz de RemoteIdd, que son los mismos). Windows no compone + /// una sesión RDP por debajo de 2 ms (): 500 es lo más + /// que puede llegar a salir. + /// + internal const int MaxFrameRate = 500; + static int NormalizeFrameRate(int frameRate) => - Math.Clamp(frameRate > 0 ? frameRate : 60, 1, 240); + Math.Clamp(frameRate > 0 ? frameRate : 60, 1, MaxFrameRate); static int NormalizeColorDepth(int colorDepth) => colorDepth switch { diff --git a/Core/wwwroot/index.html b/Core/wwwroot/index.html index 60c32b7..15fd6a2 100644 --- a/Core/wwwroot/index.html +++ b/Core/wwwroot/index.html @@ -396,7 +396,7 @@
Sesión RDP
- +
60 es lo recomendado. Más solo si el cliente y la red lo aguantan.
diff --git a/Native/RemoteIdd/Driver.cpp b/Native/RemoteIdd/Driver.cpp index 2ae97b7..0062b19 100644 --- a/Native/RemoteIdd/Driver.cpp +++ b/Native/RemoteIdd/Driver.cpp @@ -94,6 +94,12 @@ static void KeepSharedObjects(UINT32 session) // va también partido como los puestos en pantalla dividida: mitades (vertical: ancho/2; // horizontal: alto/2) y cuartos (ancho/2 y alto/2). Ver AllModes. struct ModeDef { DWORD Width, Height, VSync; }; + +// Hz que se aceptan del registro (OsmsRefreshHz) o del IOCTL. OpenStreamMS no pasa de 500 (en +// una sesión RDP Windows no compone más rápido), pero el driver admite hasta 1000 para probar +// un monitor a 1000 Hz que saque cada fotograma del juego en cuanto se presenta. +constexpr DWORD kMinHz = 24; +constexpr DWORD kMaxHz = 1000; static const ModeDef kBaseModes[] = { { 3840, 2160, 60 }, { 3840, 2160, 120 }, { 2560, 1440, 60 }, { 2560, 1440, 120 }, { 2560, 1440, 144 }, @@ -195,7 +201,7 @@ static void SeatFromDevice(WDFDEVICE device) DWORD scale = read(L"OsmsScalePercent"); AcquireSRWLockExclusive(&g_modeLock); - if (hz >= 24 && hz <= 500) + if (hz >= kMinHz && hz <= kMaxHz) g_seatMode.VSync = hz; if (width >= 640 && width <= 7680 && height >= 360 && height <= 4320) { @@ -632,7 +638,7 @@ void EvtDeviceIoControl(WDFDEVICE, WDFREQUEST request, size_t, size_t inputLengt g_seatMode.Width = in->Width; g_seatMode.Height = in->Height; } - if (in->RefreshHz >= 24 && in->RefreshHz <= 500) + if (in->RefreshHz >= kMinHz && in->RefreshHz <= kMaxHz) g_seatMode.VSync = in->RefreshHz; ReleaseSRWLockExclusive(&g_modeLock); } diff --git a/Native/RemoteIdd/Provider/install.ps1 b/Native/RemoteIdd/Provider/install.ps1 index 3257bfc..bd299ff 100644 --- a/Native/RemoteIdd/Provider/install.ps1 +++ b/Native/RemoteIdd/Provider/install.ps1 @@ -32,7 +32,7 @@ param( [string] $Bin, [string] $Package, - [ValidateRange(24, 500)] [int] $RefreshHz = 60, + [ValidateRange(24, 1000)] [int] $RefreshHz = 60, [switch] $AllConnections, [switch] $RestartTermService, [switch] $SkipTestSigningCheck diff --git a/tests/OpenStreamMS.Tests/CompositionIntervalTests.cs b/tests/OpenStreamMS.Tests/CompositionIntervalTests.cs new file mode 100644 index 0000000..3c432f9 --- /dev/null +++ b/tests/OpenStreamMS.Tests/CompositionIntervalTests.cs @@ -0,0 +1,23 @@ +using OpenStreamMS.Core.Helpers; +using Xunit; + +namespace OpenStreamMS.Tests; + +public class CompositionIntervalTests +{ + [Theory] + [InlineData(60, 4)] // 250 Hz: Sunshine marca el ritmo + [InlineData(120, 4)] + [InlineData(240, 4)] // 250 Hz alcanza a 240 fps + [InlineData(250, 4)] + [InlineData(300, 3)] // 334 Hz + [InlineData(400, 2)] // 500 Hz + [InlineData(500, 2)] // techo de Windows + [InlineData(100, 10)] // 1000/fps entero: compone a los fps + public void Smooth(int fps, int expectedMs) => + Assert.Equal(expectedMs, RdpSessionCreator.CompositionIntervalMs(fps)); + + [Fact] + public void FpsAboveCeilingIsClamped() => + Assert.Equal(2, RdpSessionCreator.CompositionIntervalMs(1000)); +}