-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Screen: Autoenable Vulkan display backend on macOS ARM in various sit…
…uations. On Apple Silicon Macs under macOS, visual stimulus presentation timing and timestamping is utterly broken when using Apples proprietary OpenGL only on Apples proprietary gpu. Only our Vulkan display backend allows proper timing. Therefore, in a typical fullscreen display configuration, the Vulkan display backend should always be used, so that scripts which don't explicitely request UseVulkanDisplay via PsychImaging still get timing of similar precision as on Intel based Macs. This commit adds auto-enable support for Vulkan on macOS on ARM: 1) PsychImaging('OpenWindow', ...) will auto-opt-in to Vulkan in typical usage scenarios. 2) To deal with legacy scripts that use Screen('OpenWindow', ...) without PsychImaging, add some detection logic so Screen('OpenWindow') can detect if it wasn't called through PsychImaging. In that case it will call PsychImaging('OpenWindow', ...) to trigger case 1) and thereby get those legacy scripts also promoted to use of the Vulkan display backend. The new kPsychBackendDecisionMade specialflag is used by PsychImaging to signal to Screen when it is in charge of controlling display backend choice.
- Loading branch information
Showing
4 changed files
with
107 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Psychtoolbox/PsychGLImageProcessing/kPsychBackendDecisionMade.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
function rval = kPsychBackendDecisionMade | ||
% rval = kPsychBackendDecisionMade | ||
% | ||
% This flag can be passed to the optional 'specialFlags' parameter of | ||
% Screen('OpenWindow', ...) or PsychImaging('OpenWindow', ...). | ||
% | ||
% This flag tells Screen('OpenWindow', ...) that a higher level calling | ||
% function of Screen('OpenWindow', ...), e.g., PsychImaging('OpenWindow', ...), | ||
% has made an appropriate, explicit, and intentional choice of the display | ||
% backend that Screen() should use for visual stimulus presentation for the | ||
% given onscreen window, and performed / performs all needed setup, so | ||
% Screen() should not take any initiative on its own, but simply obey | ||
% whatever the calling code has decided for it. Absence of the flag is an | ||
% indicator that Screen('OpenWindow', ...) is called by user written | ||
% experiment scripts directly, which are unaware of specific display | ||
% backend requirements on a given setup, so Screen() may have to make | ||
% backend selection decisions on its own. | ||
% | ||
% In practice, as of November 2024, this flag matters for Screen() running | ||
% on top of macOS on a Apple Silicon Mac with Apples own proprietary gpu | ||
% and display engine on top of Apples proprietary OpenGL implementation, | ||
% which requires use of the Vulkan display backend in most cases for proper | ||
% visual stimulus presentation timing and timestamping. If Screen() detects | ||
% it is running on macOS for Apple Silicon and the flag is present, then it | ||
% knows that high-level code like PsychImaging('OpenWindow', ...) has taken | ||
% care of proper setup. Absence of the flag signals that Screen was likely | ||
% called directly by a users legacy experiment script that was unaware of | ||
% the special requirements of the macOS + Apple Silicon platform. In this | ||
% case, Screen('Openwindow') will recursively call PsychImaging('OpenWindow') | ||
% so PsychImaging can then do the needed appropriate backend decisions and | ||
% itself call back into Screen() with the flag set, to perform actual | ||
% proper configuration. It is essentially a backwards compatibility measure | ||
% to make old legacy scripts work transparently on this special snowflake | ||
% platform. | ||
|
||
rval = 2^36; | ||
return |