Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Respect integrated GPU preference in Windows Settings #93985

Merged
merged 2 commits into from
Aug 27, 2024

Conversation

alvinhochun
Copy link
Contributor

@alvinhochun alvinhochun commented Jul 5, 2024

Tested locally with Vulkan.

Fixes #81870
Related to #58430

@alvinhochun
Copy link
Contributor Author

alvinhochun commented Jul 6, 2024

Using Sysinternals Process Monitor I can observe that opengl32.dll reads the same registry key as this PR. It also reads the value DirectXUserGlobalSettings, however setting it manually doesn't seem to affect the GPU selection when using gl_compatibilty. So I'd wager this is good enough at least for when running as non-packaged desktop app.

However, I neglected that Windows Settings also allows selecting the preference for a packaged app, and the current change doesn't handle this case. It is slightly more annoying to test but implementation should be trivial (using GetCurrentPackageFamilyName GetCurrentApplicationUserModelId).

@alvinhochun
Copy link
Contributor Author

Windows Settings also allows selecting the preference for a packaged app

This is now implemented, and I've verified that it works by hijacking another packaged app.

@akien-mga akien-mga changed the title Repect integrated GPU preference in Windows Settings Respect integrated GPU preference in Windows Settings Jul 6, 2024
@alvinhochun alvinhochun force-pushed the windows-gpu-pref branch 2 times, most recently from 3bae236 to 9ab19fd Compare July 7, 2024 10:41
}

DWORD size = 0;
result = RegGetValueW(hkey, nullptr, value_name, RRF_RT_REG_SZ, nullptr, nullptr, &size);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reg. key name size is limited to 16K chars, I wounder what would happen if you try to set GPU preferences for app with longer path (will it truncate it or won't set it at all).

Probably not relevant in practice, Godot won't handle long paths without #91902, and CreateProcess can't handle long current directory paths, so it's unlikely will ever be over 260.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting point to consider. Though things are really whacky even when I make the Godot exe path just 256 chars -- it crashes when using the NVIDIA GPU and explorer.exe; even if I set it to use the Intel GPU (OpenGL selection is handled by the system) it still crashed explorer.exe (though it did run the project manager).

I think I am comfortable with leaving the code like this. It is obviously not a supported scenario (unless MS decides to raise the limit of the value name, which I doubt would ever happen) and RegOpenKeyExW should just return an error and the function returns false.

@akien-mga akien-mga modified the milestones: 4.x, 4.4 Jul 17, 2024
@akien-mga akien-mga merged commit 330fca1 into godotengine:master Aug 27, 2024
18 checks passed
@akien-mga
Copy link
Member

Thanks!

@alvinhochun alvinhochun deleted the windows-gpu-pref branch August 28, 2024 09:25
@akien-mga akien-mga changed the title Respect integrated GPU preference in Windows Settings Windows: Respect integrated GPU preference in Windows Settings Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Godot Editor engages dedicated 3d card on laptop, against both windows and nvidia driver settings.
4 participants