diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index 6c849accd4da..4d603fd5e980 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -3990,6 +3990,64 @@ static BOOL madeira_force_builtin_dll( const WCHAR *name ) return FALSE; } +/*********************************************************************** + * madeira_dxc_native + * + * madeira-duo: with MADEIRA_DXC_NATIVE=1 in the environment, dxcompiler.dll + * is taken from system32, where the bundle's ARM64EC build of the same DXC + * release (arm64ec-windows/dxcompiler.dll, build/dxc-arm64ec) is linked, + * instead of the x64 copy a game ships next to its exe, which would run + * emulated. Like the XInput names above, the application directory is never + * searched for it then; a load by full path is treated as a load by name. + */ +static BOOL madeira_dxc_native( const WCHAR *name ) +{ + static int native = -1; + const WCHAR *base = name, *p; + + for (p = name; *p; p++) if (*p == '\\' || *p == '/') base = p + 1; + if (wcsicmp( base, L"dxcompiler.dll" ) && wcsicmp( base, L"dxcompiler" )) return FALSE; + if (native < 0) + { + UNICODE_STRING nm, val; + WCHAR buf[8]; + RtlInitUnicodeString( &nm, L"MADEIRA_DXC_NATIVE" ); + val.Buffer = buf; val.Length = 0; val.MaximumLength = sizeof(buf); + native = (!RtlQueryEnvironmentVariable_U( NULL, &nm, &val ) && val.Length && buf[0] == '1'); + if (native) ERR( "[dxc-native] dxcompiler.dll is loaded from system32 (MADEIRA_DXC_NATIVE=1)\n" ); + } + return native; +} + +/*********************************************************************** + * madeira_xess_builtin + * + * madeira-duo xess-metalfx: with MADEIRA_XESS_METALFX=1, libxess.dll is + * Madeira's (system32, from the bundle's arm64ec-windows), which answers XeSS + * with MetalFX temporal upscaling, instead of the game's own Intel DLL: the iOS + * loader never replaces an app-folder image with a builtin, so + * WINEDLLOVERRIDES cannot do it (PoE2 loaded its 74 MB x64 libxess with + * libxess=b, and with libxess= too). + */ +static BOOL madeira_xess_builtin( const WCHAR *name ) +{ + static int on = -1; + const WCHAR *base = name, *p; + + for (p = name; *p; p++) if (*p == '\\' || *p == '/') base = p + 1; + if (wcsicmp( base, L"libxess.dll" ) && wcsicmp( base, L"libxess" )) return FALSE; + if (on < 0) + { + UNICODE_STRING nm, val; + WCHAR buf[8]; + RtlInitUnicodeString( &nm, L"MADEIRA_XESS_METALFX" ); + val.Buffer = buf; val.Length = 0; val.MaximumLength = sizeof(buf); + on = (!RtlQueryEnvironmentVariable_U( NULL, &nm, &val ) && val.Length && buf[0] == '1'); + if (on) ERR( "[xess-metalfx] libxess.dll is loaded from system32 (MADEIRA_XESS_METALFX=1)\n" ); + } + return on; +} + /*********************************************************************** * find_dll_file * @@ -4039,9 +4097,15 @@ static NTSTATUS find_dll_file( const WCHAR *load_path, const WCHAR *libname, UNI /* Win 7/2008R2 and up seem to re-enable WoW64 FS redirection when loading libraries */ RtlWow64EnableFsRedirectionEx( 0, &wow64_old_value ); + if (RtlDetermineDosPathNameType_U( libname ) != RtlPathTypeRelative && madeira_dxc_native( libname )) + libname = L"dxcompiler.dll"; + /* PoE2 loads \libxess.dll by its full path */ + if (RtlDetermineDosPathNameType_U( libname ) != RtlPathTypeRelative && madeira_xess_builtin( libname )) + libname = L"libxess.dll"; + if (RtlDetermineDosPathNameType_U( libname ) == RtlPathTypeRelative) { - if (madeira_force_builtin_dll( libname )) + if (madeira_force_builtin_dll( libname ) || madeira_dxc_native( libname ) || madeira_xess_builtin( libname )) { TRACE( "%s: searching system32 only, for the builtin\n", debugstr_w(libname) ); load_path = system_dir; diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c index b6e0c060fa35..2c93676c9d18 100644 --- a/dlls/ntdll/sync.c +++ b/dlls/ntdll/sync.c @@ -1287,6 +1287,12 @@ struct futex_queue { struct list queue; LONG lock; + /* Madeira wake fast path: number of entries currently queued in this + * bucket. It lives in the 4 bytes of padding after `lock`, so the struct + * stays 24 bytes and keeps matching the unix side's shared table + * (struct ios_shared_futex_queue, dlls/ntdll/unix/sync.c). Every ntdll + * copy that queues waiters on the shared table must maintain it. */ + LONG waiters; }; static struct futex_queue futex_queues[256]; @@ -1396,10 +1402,16 @@ NTSTATUS WINAPI RtlWaitOnAddress( const void *addr, const void *cmp, SIZE_T size spin_lock( &queue->lock ); + /* Announce the waiter before comparing. Paired with the barrier in + * futex_queue_has_waiters(): either this compare sees the waker's new + * value, or the waker sees waiters != 0 and takes the locked path. */ + InterlockedIncrement( &queue->waiters ); + /* Do the comparison inside of the spinlock, to reduce spurious wakeups. */ if (!compare_addr( addr, cmp, size )) { + InterlockedDecrement( &queue->waiters ); spin_unlock( &queue->lock ); return STATUS_SUCCESS; } @@ -1443,7 +1455,10 @@ NTSTATUS WINAPI RtlWaitOnAddress( const void *addr, const void *cmp, SIZE_T size { spin_lock( &queue->lock ); if (entry.addr) + { list_remove( &entry.entry ); + InterlockedDecrement( &queue->waiters ); + } spin_unlock( &queue->lock ); } @@ -1453,6 +1468,18 @@ NTSTATUS WINAPI RtlWaitOnAddress( const void *addr, const void *cmp, SIZE_T size return ret; } +/* Madeira wake fast path. Games release SRW locks and signal condition + * variables far more often than anyone waits on them (Path of Exile 2: about + * a million RtlWakeAddress* calls a second against a few thousand waits), and + * every one of those wakes took this bucket's spinlock: a shared cache line + * bounced between all the game's threads for nothing. A wake with no queued + * waiter in the bucket now returns after one full barrier and one load. */ +static inline BOOL futex_queue_has_waiters( struct futex_queue *queue ) +{ + MemoryBarrier(); /* order the caller's store to *addr before the load below */ + return ReadNoFence( &queue->waiters ) != 0; +} + /*********************************************************************** * RtlWakeAddressAll (NTDLL.@) */ @@ -1468,6 +1495,7 @@ void WINAPI RtlWakeAddressAll( const void *addr ) TRACE("%p\n", addr); if (!addr) return; + if (!futex_queue_has_waiters( queue )) return; spin_lock( &queue->lock ); @@ -1480,6 +1508,7 @@ void WINAPI RtlWakeAddressAll( const void *addr ) { entry->addr = NULL; list_remove( &entry->entry ); + InterlockedDecrement( &queue->waiters ); if (count == ARRAY_SIZE(tids)) { NtAlertMultipleThreadByThreadId( tids, count, NULL, NULL ); @@ -1511,6 +1540,7 @@ void WINAPI RtlWakeAddressSingle( const void *addr ) TRACE("%p\n", addr); if (!addr) return; + if (!futex_queue_has_waiters( queue )) return; spin_lock( &queue->lock ); @@ -1530,6 +1560,7 @@ void WINAPI RtlWakeAddressSingle( const void *addr ) * calls must wake at least two waiters if they exist. */ entry->addr = NULL; list_remove( &entry->entry ); + InterlockedDecrement( &queue->waiters ); break; } } diff --git a/dlls/shell32/shellpath.c b/dlls/shell32/shellpath.c index 6eb5d5cc3457..af3e89f5472d 100644 --- a/dlls/shell32/shellpath.c +++ b/dlls/shell32/shellpath.c @@ -2921,6 +2921,24 @@ HRESULT WINAPI SHGetFolderPathAndSubDirA( return hr; } +/* Madeira: PoE2 asks for Local AppData ~100x a second, and every answer is a chain of + * registry opens and reads (ProfileList, User Shell Folders, Shell Folders) through the + * wineserver. A shell folder's base path doesn't change during a session unless shell32 + * itself redirects or re-registers it, so keep the expanded base path per (folder, flags) + * for the calling user (hToken NULL). The subpath, existence check and create still run + * every call. */ +static SRWLOCK madeira_folder_lock = SRWLOCK_INIT; +static BYTE madeira_folder_valid[2][ARRAY_SIZE(CSIDL_Data)]; +static WCHAR madeira_folder_path[2][ARRAY_SIZE(CSIDL_Data)][MAX_PATH]; +static LONG madeira_folder_hits; + +static void madeira_folder_cache_clear(void) +{ + AcquireSRWLockExclusive(&madeira_folder_lock); + memset(madeira_folder_valid, 0, sizeof(madeira_folder_valid)); + ReleaseSRWLockExclusive(&madeira_folder_lock); +} + /************************************************************************* * SHGetFolderPathAndSubDirW [SHELL32.@] */ @@ -2937,6 +2955,7 @@ HRESULT WINAPI SHGetFolderPathAndSubDirW( DWORD folder = nFolder & CSIDL_FOLDER_MASK; CSIDL_Type type; int ret; + BOOL cacheable, cached = FALSE; TRACE("%p,%#x,%p,%#lx,%s,%p\n", hwndOwner, nFolder, hToken, dwFlags, debugstr_w(pszSubPath), pszPath); @@ -2952,6 +2971,26 @@ HRESULT WINAPI SHGetFolderPathAndSubDirW( return E_INVALIDARG; szTemp[0] = 0; type = CSIDL_Data[folder].type; + cacheable = !hToken && (type == CSIDL_Type_User || type == CSIDL_Type_AllUsers || + type == CSIDL_Type_ProgramData || type == CSIDL_Type_CurrVer); + if (cacheable) + { + AcquireSRWLockShared(&madeira_folder_lock); + if (madeira_folder_valid[dwFlags][folder]) + { + lstrcpyW(szBuildPath, madeira_folder_path[dwFlags][folder]); + cached = TRUE; + } + ReleaseSRWLockShared(&madeira_folder_lock); + } + if (cached) + { + LONG n = InterlockedIncrement(&madeira_folder_hits); + if (n == 1 || !(n & 16383)) + ERR("[folder-cache] #%ld csidl %#lx flags %lu served from cache: %s\n", n, folder, dwFlags, debugstr_w(szBuildPath)); + hr = S_OK; + goto have_path; + } switch (type) { case CSIDL_Type_Disallowed: @@ -2999,6 +3038,16 @@ HRESULT WINAPI SHGetFolderPathAndSubDirW( if (FAILED(hr)) goto end; + if (cacheable && hr == S_OK && szBuildPath[0]) + { + AcquireSRWLockExclusive(&madeira_folder_lock); + lstrcpyW(madeira_folder_path[dwFlags][folder], szBuildPath); + madeira_folder_valid[dwFlags][folder] = 1; + ReleaseSRWLockExclusive(&madeira_folder_lock); + } + +have_path: + if(pszSubPath) { /* make sure the new path does not exceed the buffer length * and remember to backslash and terminate it */ @@ -3098,6 +3147,7 @@ static HRESULT _SHRegisterFolders(HKEY hRootKey, HANDLE hToken, TRACE("%p,%p,%s,%p,%u\n", hRootKey, hToken, debugstr_w(szUserShellFolderPath), folders, foldersLen); + madeira_folder_cache_clear(); ret = RegCreateKeyW(hRootKey, szUserShellFolderPath, &hUserKey); if (ret) hr = HRESULT_FROM_WIN32(ret); @@ -3769,6 +3819,8 @@ static HRESULT redirect_known_folder( if(SUCCEEDED(hr)) hr = get_known_folder_redirection_place(rfid, &rootKey); + madeira_folder_cache_clear(); + /* write redirection information */ if(SUCCEEDED(hr)) hr = HRESULT_FROM_WIN32(RegCreateKeyExW(rootKey, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders", 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL)); diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index b868454594e7..012d73ac8f68 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -1400,6 +1400,48 @@ static HWND set_window_owner( HWND hwnd, HWND owner ) } /* Helper function for SetWindowLong(). */ +/* madeira-duo (6 Nov 2026): a top-level window that loses its frame while at least as + * large as the monitor is snapped to the monitor. + * + * PoE2's borderless fullscreen creates a framed window of its saved size plus the frame, + * then removes the frame with SWP_NOSIZE. The frameless window is all client, the game + * saves that client size, and the next launch adds the frame again: 1440x900 grew 8x34 a + * launch to 1504x1156 on the 1440x900 desktop, which then showed shrunk with black bars. + * On Windows the framed window never got past the monitor-sized track limit. + * Opt-in: MADEIRA_SNAP_BORDERLESS=1 turns it on. */ +static void madeira_snap_borderless_window( HWND hwnd, DWORD old_style, DWORD new_style ) +{ + static int enabled = -1; + const DWORD frame_styles = WS_CAPTION | WS_THICKFRAME; + RECT window_rect, monitor_rect; + UINT dpi = get_thread_dpi(); + int window_width, window_height, monitor_width, monitor_height; + + if (enabled < 0) + { + const char *env = getenv( "MADEIRA_SNAP_BORDERLESS" ); + enabled = env && env[0] == '1' && !env[1]; + } + if (!enabled) return; + if (new_style & WS_CHILD) return; + if (!(old_style & frame_styles) || (new_style & frame_styles)) return; /* not a frame removal */ + if (NtUserGetAncestor( hwnd, GA_PARENT ) != get_desktop_window()) return; + if (!get_window_rect( hwnd, &window_rect, dpi )) return; + + monitor_rect = get_primary_monitor_rect( dpi ); + window_width = window_rect.right - window_rect.left; + window_height = window_rect.bottom - window_rect.top; + monitor_width = monitor_rect.right - monitor_rect.left; + monitor_height = monitor_rect.bottom - monitor_rect.top; + if (window_width < monitor_width || window_height < monitor_height) return; + if (window_width == monitor_width && window_height == monitor_height) return; + + TRACE( "snapping borderless %p from %s to monitor %s\n", hwnd, + wine_dbgstr_rect( &window_rect ), wine_dbgstr_rect( &monitor_rect )); + NtUserSetWindowPos( hwnd, 0, monitor_rect.left, monitor_rect.top, monitor_width, monitor_height, + SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER ); +} + LONG_PTR set_window_long( HWND hwnd, INT offset, UINT size, LONG_PTR newval, BOOL ansi ) { BOOL ok, made_visible = FALSE, layered = FALSE; @@ -1577,6 +1619,7 @@ LONG_PTR set_window_long( HWND hwnd, INT offset, UINT size, LONG_PTR newval, BOO user_driver->pSetWindowStyle( hwnd, offset, &style ); if (made_visible || layered) update_window_state( hwnd ); send_message( hwnd, WM_STYLECHANGED, offset, (LPARAM)&style ); + if (offset == GWL_STYLE) madeira_snap_borderless_window( hwnd, style.styleOld, style.styleNew ); } return retval;