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

Fix discrete GPU preference symbols being exported from the wrong place #1406

Merged
merged 1 commit into from Apr 28, 2018

Conversation

binary1248
Copy link
Member

@binary1248 binary1248 commented Apr 7, 2018

Moved NvOptimusEnablement and AmdPowerXpressRequestHighPerformance out of sfml-main and into a macro the user can place in their own translation unit when they need it.

The current implementation suffers from a bunch of problems:

  • It doesn't work when using the console subsystem, see NvOptimusEnablement not exported for /SUBSYSTEM:CONSOLE #1192
  • It can't work when linking all of SFML dynamically (this implies not linking sfml-main obviously)
  • When linking sfml-main for portability, the user can't opt out of preferring the discrete GPU when they know they won't need the extra performance
  • This "feature" was never documented, only people following the commit history or who browse through the code will know this exists
  • Exporting symbols via __declspec(dllexport) from a static library is just weird in itself anyway

With this change, the user will have full control over when they want this preference to be made, and the symbols will always be exported from the right place: the final executable. And there is the added bonus that this will actually show up in the documentation as well (might still be hard to find though).

@LaurentGomila
Copy link
Member

I'm not sure if the top of Window.hpp is the right place to define this stuff. Maybe it would deserve its own header?

this will actually show up in the documentation as well (might still be hard to find though)

I don't know if it works with macros too, but you can use \relates Class to attach it to the documentation page of Class.

@MarioLiebisch
Copy link
Member

@binary1248 binary1248 force-pushed the bugfix/discrete_gpu_preference branch from d60ea66 to 0f6660a Compare April 7, 2018 10:27
@binary1248
Copy link
Member Author

@LaurentGomila @MarioLiebisch I moved the definition into its own file and added a paragraph with a reference to it in Window.hpp. \relates doesn't seem to work on macros.

@eXpl0it3r
Copy link
Member

Shouldn't header be included in the top-level Window.hpp as well, so you don't specifically have to include the header and define the macro?

@eXpl0it3r eXpl0it3r added this to Discussion in SFML 2.5.0 via automation Apr 7, 2018
@eXpl0it3r eXpl0it3r added this to the 2.5 milestone Apr 7, 2018
@binary1248
Copy link
Member Author

I was thinking of providing this as a "convenience header" much like what <SFML/OpenGL.hpp> is now. But... if it makes more sense to automatically include this with <SFML/Window.hpp> then I can fix that too. What do the others think?

@eXpl0it3r eXpl0it3r moved this from Discussion to Review & Testing in SFML 2.5.0 Apr 7, 2018
@eXpl0it3r
Copy link
Member

I mean, it doesn't really do any harm in directly including it and potentially reduces one extra step when explaining how to use it.

@binary1248 binary1248 force-pushed the bugfix/discrete_gpu_preference branch from 0f6660a to f3e1eec Compare April 7, 2018 20:31
@binary1248
Copy link
Member Author

@eXpl0it3r Done.

/// the final executable. Typically it is best to place it
/// where the main function is also defined.
///
///
Copy link
Member

Choose a reason for hiding this comment

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

Because I found nothing else to say: there's one empty line that should be removed here 😁

@binary1248 binary1248 force-pushed the bugfix/discrete_gpu_preference branch from f3e1eec to f7c4e22 Compare April 8, 2018 09:50
@binary1248
Copy link
Member Author

@LaurentGomila Fixed.

@Ceylo
Copy link
Contributor

Ceylo commented Apr 8, 2018

Shouldn't it be part of current Window module? ie in SFML/Window/GpuPreference.hpp
You include it automatically from <SFML/Window.hpp> and it changes the OpenGL setup in some way, which is currently the Window module responsibility with Context settings & such. Both make me think it should belong to the Window module.

@binary1248
Copy link
Member Author

Theoretically you can use this macro even in a console application in which you only make use of sfml-network even though it wouldn't make much sense. I wouldn't go so far as to say it changes any behaviour we should handle differently. This also expresses a preference, not a demand, we can't and shouldn't rely on it having any effect. When choosing a spot to place it, I figured this has a similar purpose as <SFML/OpenGL.hpp>, being more of a convenience than a necessity so I might as well place it in the same location.

@LaurentGomila
Copy link
Member

I didn't notice that before, and yes I admit that it looks confusing. Either make it part of the window module and include it in SFML/Window.hpp, or leave it as a standalone functionality and don't include it in any module by default.

Which solution to choose, I'm not sure 😬

@binary1248
Copy link
Member Author

Well... until now, the user could always assume that using something from an include file would imply having to link against that module as well. This works out for <SFML/OpenGL.hpp> as well since it is not actually part of any module and only a convenience header. The same can be said about <SFML/GpuPreference.hpp>. If the user is so inclined, they could even include both of these headers for mere convenience and use something else for their window management needs.

@LaurentGomila
Copy link
Member

Ok, so let's keep it separate from the Window module.

@eXpl0it3r
Copy link
Member

I didn't realize that it wasn't "part" of a module when I suggested to add it to Window.hpp. Should have taken a closer look. Since it really is unrelated to SFML window or graphics, I think it's okay to just have it similar to the OpenGL header.

@eXpl0it3r eXpl0it3r moved this from Review & Testing to Requires Adjustments in SFML 2.5.0 Apr 8, 2018
@eXpl0it3r
Copy link
Member

Cna you revert it again, @binary1248? 😄

@binary1248
Copy link
Member Author

What do you mean with revert it again?

Copy link
Member

@MarioLiebisch MarioLiebisch left a comment

Choose a reason for hiding this comment

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

Maybe it's just me, but I'd consider it useful to rename this from GpuPreference to GpuSelection as it feels more intuitive. In addition, I'd also provide a second set of macros to prefer the on-board GPU even though they wouldn't do anything in your everyday app. It would still provide confirmation "yes, indeed use the on-board one!" though.

@eXpl0it3r
Copy link
Member

Remove it from the general Window.hpp as to keep it separate from the Window module.

@binary1248
Copy link
Member Author

@MarioLiebisch Selection is misleading, because we don't select anything. We express a preference/hint. It is still up to the driver to pick a GPU for us. If the user chooses to do so, they can still override which GPU will be used. The opposite is also true, there is no way to express a preference for the iGPU. The hints only have an effect when they are exported and their values set to 1. Setting their values to 0 would be the same as not exporting them at all meaning "no preference". In that case it is up to the driver to guess which GPU to use.

Copy link
Member

@MarioLiebisch MarioLiebisch left a comment

Choose a reason for hiding this comment

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

Yeah, true.

How reliable would it be to try detect on-board cards and spit out a warning on context creation for debug builds in case the macro isn't used (e.g. due to not knowing about it)?

@binary1248
Copy link
Member Author

Not reliable at all? An iGPU in a hybrid graphics setup could be the only available GPU in another system. OpenGL also doesn't provide any reliable way of enumerating adapters like D3D or Vulkan does, so that is also sort of out of the question.

@binary1248 binary1248 force-pushed the bugfix/discrete_gpu_preference branch from f7c4e22 to 9a453ed Compare April 14, 2018 14:50
@binary1248
Copy link
Member Author

@eXpl0it3r Done.

@eXpl0it3r eXpl0it3r moved this from Requires Adjustments to Ready in SFML 2.5.0 Apr 28, 2018
…t of sfml-main and into a macro the user can place in their own translation unit when they need it. Fixes #1192
@eXpl0it3r eXpl0it3r force-pushed the bugfix/discrete_gpu_preference branch from 9a453ed to cd13874 Compare April 28, 2018 11:22
@eXpl0it3r eXpl0it3r merged commit cd13874 into master Apr 28, 2018
SFML 2.5.0 automation moved this from Ready to Merged / Superseded Apr 28, 2018
@eXpl0it3r eXpl0it3r deleted the bugfix/discrete_gpu_preference branch April 28, 2018 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
SFML 2.5.0
  
Merged / Superseded
Development

Successfully merging this pull request may close these issues.

None yet

5 participants