0
0
mirror of https://github.com/Ishan09811/pine.git synced 2025-04-24 08:55:10 +00:00

Implement Vsync option (#46)

This commit is contained in:
Ishan09811 2025-01-02 18:49:59 +05:30 committed by GitHub
parent 58536da1a4
commit a649516149
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 50 additions and 45 deletions

View File

@ -38,7 +38,7 @@ namespace skyline {
systemRegion = ktSettings.GetInt<skyline::region::RegionCode>("systemRegion");
isInternetEnabled = ktSettings.GetBool("isInternetEnabled");
forceTripleBuffering = ktSettings.GetBool("forceTripleBuffering");
disableFrameThrottling = ktSettings.GetBool("disableFrameThrottling");
vsyncMode = ktSettings.GetInt<int>("vsyncMode");
gpuDriver = ktSettings.GetString("gpuDriver");
gpuDriverLibraryName = ktSettings.GetString("gpuDriverLibraryName");
executorSlotCountScale = ktSettings.GetInt<u32>("executorSlotCountScale");

View File

@ -70,7 +70,7 @@ namespace skyline {
// Display
Setting<bool> forceTripleBuffering; //!< If the presentation engine should always triple buffer even if the swapchain supports double buffering
Setting<bool> disableFrameThrottling; //!< Allow the guest to submit frames without any blocking calls
Setting<int> vsyncMode;
Setting<bool> disableShaderCache; //!< Prevents cached shaders from being loaded and disables caching of new shaders
// CPU

View File

@ -211,7 +211,10 @@ namespace skyline::gpu {
}); // We don't care about suboptimal images as they are caused by not respecting the transform hint, we handle transformations externally
}
timestamp = (timestamp && !*state.settings->disableFrameThrottling) ? timestamp : getMonotonicNsNow(); // We tie FPS to the submission time rather than presentation timestamp, if we don't have the presentation timestamp available or if frame throttling is disabled as we want the maximum measured FPS to not be restricted to the refresh rate
timestamp = (timestamp && (*state.settings->vsyncMode != 0 || *state.settings->vsyncMode != 1)) ? timestamp : getMonotonicNsNow(); // We tie FPS to the submission time rather than presentation timestamp, if we don't have the presentation timestamp available or if frame throttling is disabled as we want the maximum measured FPS to not be restricted to the refresh rate
if (timestamp > getMonotonicNsNow() || *state.settings->vsyncMode == 0 || *state.settings->vsyncMode == 1) {
timestamp = getMonotonicNsNow();
}
if (frameTimestamp) {
i64 sampleWeight{Fps ? Fps : 1}; //!< The weight of each sample in calculating the average, we want to roughly average the past second
@ -315,7 +318,28 @@ namespace skyline::gpu {
if ((capabilities.supportedUsageFlags & presentUsage) != presentUsage)
throw exception("Swapchain doesn't support image usage '{}': {}", vk::to_string(presentUsage), vk::to_string(capabilities.supportedUsageFlags));
auto requestedMode{*state.settings->disableFrameThrottling ? vk::PresentModeKHR::eMailbox : vk::PresentModeKHR::eFifo};
auto requestedMode{vk::PresentModeKHR::eFifo};
switch (*state.settings->vsyncMode) {
case 0: // Immediate
requestedMode = vk::PresentModeKHR::eImmediate;
break;
case 1: // Mailbox
requestedMode = vk::PresentModeKHR::eMailbox;
break;
case 2: // FIFO
requestedMode = vk::PresentModeKHR::eFifo;
break;
case 3: // Relaxed FIFO
requestedMode = vk::PresentModeKHR::eFifoRelaxed;
break;
default: // Default FIFO
requestedMode = vk::PresentModeKHR::eFifo;
break;
}
auto modes{gpu.vkPhysicalDevice.getSurfacePresentModesKHR(**vkSurface)};
if (std::find(modes.begin(), modes.end(), requestedMode) == modes.end())
throw exception("Swapchain doesn't support present mode: {}", vk::to_string(requestedMode));

View File

@ -387,19 +387,11 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
}
}
if (emulationSettings.perfStats) {
if (emulationSettings.disableFrameThrottling)
binding.perfStats.setTextColor(getColor(R.color.colorPerfStatsSecondary))
enablePerfStats(true)
}
if (emulationSettings.perfStats) enablePerfStats(true)
enableThermalIndicator(emulationSettings.perfStats)
enableDynamicResolution(emulationSettings.enableDynamicResolution)
window.setSustainedPerformanceMode(emulationSettings.enableSustainedPerf)
force60HzRefreshRate(!emulationSettings.maxRefreshRate)
getSystemService<DisplayManager>()?.registerDisplayListener(this, null)
@ -485,7 +477,9 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
true
}
R.id.menu_settings -> {
startActivity(Intent(this@EmulationActivity, SettingsActivity::class.java))
startActivity(Intent(this@EmulationActivity, SettingsActivity::class.java).apply {
if (!emulationSettings.isGlobal && emulationSettings.useCustomSettings) putExtra("AppItemTag", item)
})
true
}
R.id.menu_exit -> {

View File

@ -52,7 +52,7 @@ class EmulationSettings private constructor(context : Context, prefName : String
// GPU
var gpuDriver by sharedPreferences(context, SYSTEM_GPU_DRIVER, prefName = prefName)
var forceTripleBuffering by sharedPreferences(context, true, prefName = prefName)
var disableFrameThrottling by sharedPreferences(context, false, prefName = prefName)
var vsyncMode by sharedPreferences(context, 2, prefName = prefName)
var executorSlotCountScale by sharedPreferences(context, 6, prefName = prefName)
var executorFlushThreshold by sharedPreferences(context, 256, prefName = prefName)
var useDirectMemoryImport by sharedPreferences(context, false, prefName = prefName)

View File

@ -50,14 +50,6 @@ class GameSettingsFragment : PreferenceFragmentCompat() {
findPreference("category_debug")
).forEach { it?.dependency = "use_custom_settings" }
// Uncheck `disable_frame_throttling` if `force_triple_buffering` gets disabled
val disableFrameThrottlingPref = findPreference<TwoStatePreference>("disable_frame_throttling")!!
findPreference<TwoStatePreference>("force_triple_buffering")?.setOnPreferenceChangeListener { _, newValue ->
if (newValue == false)
disableFrameThrottlingPref.isChecked = false
true
}
// Only show validation layer setting in debug builds
@Suppress("SENSELESS_COMPARISON")
if (BuildConfig.BUILD_TYPE != "release")

View File

@ -60,15 +60,7 @@ class GlobalSettingsFragment : PreferenceFragmentCompat() {
}
}
}
// Uncheck `disable_frame_throttling` if `force_triple_buffering` gets disabled
val disableFrameThrottlingPref = findPreference<TwoStatePreference>("disable_frame_throttling")!!
findPreference<TwoStatePreference>("force_triple_buffering")?.setOnPreferenceChangeListener { _, newValue ->
if (newValue == false)
disableFrameThrottlingPref.isChecked = false
true
}
// Only show validation layer setting in debug builds
@Suppress("SENSELESS_COMPARISON")
if (BuildConfig.BUILD_TYPE != "release")

View File

@ -31,7 +31,7 @@ data class NativeSettings(
var gpuDriver : String,
var gpuDriverLibraryName : String,
var forceTripleBuffering : Boolean,
var disableFrameThrottling : Boolean,
var vsyncMode : Int,
var executorSlotCountScale : Int,
var executorFlushThreshold : Int,
var useDirectMemoryImport : Boolean,
@ -60,7 +60,7 @@ data class NativeSettings(
if (pref.gpuDriver == EmulationSettings.SYSTEM_GPU_DRIVER) "" else pref.gpuDriver,
if (pref.gpuDriver == EmulationSettings.SYSTEM_GPU_DRIVER) "" else GpuDriverHelper.getLibraryName(context, pref.gpuDriver),
pref.forceTripleBuffering,
pref.disableFrameThrottling,
pref.vsyncMode,
pref.executorSlotCountScale,
pref.executorFlushThreshold,
pref.useDirectMemoryImport,

View File

@ -107,6 +107,12 @@
<item>0</item>
<item>8</item>
</integer-array>
<string-array name="vsync_modes">
<item>Immediate (Off)</item>
<item>Mailbox</item>
<item>FIFO (On)</item>
<item>FIFO (Relaxed)</item>
</string-array>
<string-array name="credits_entries">
<item>j0hnnybrav0</item>
<item>Ell Jensen</item>

View File

@ -146,9 +146,7 @@
<string name="force_triple_buffering">Force Triple Buffering</string>
<string name="triple_buffering_enabled">Utilize at least three swapchain buffers (Higher FPS but more input lag)</string>
<string name="triple_buffering_disabled">Utilize at least two swapchain buffers (Lower FPS but less input lag)</string>
<string name="disable_frame_throttling">Disable Frame Throttling</string>
<string name="disable_frame_throttling_enabled">Game is allowed to submit frames as fast as possible (Only for benchmarking)\n\n<b>Note:</b> An alternative method is utilized to measure the FPS with this enabled, the figures must not be compared to throttled FPS figures</string>
<string name="disable_frame_throttling_disabled">Only allow the game to submit frames at the display refresh rate</string>
<string name="vsync_mode">VSync Mode</string>
<string name="executor_slot_count_scale">Executor Slot Count Scale</string>
<string name="executor_slot_count_scale_desc">Scale controlling the maximum number of simultaneous GPU executions (Higher may sometimes perform better but will use more RAM)</string>
<string name="executor_flush_threshold">Executor Flush Threshold</string>

View File

@ -134,13 +134,12 @@
android:summaryOn="@string/triple_buffering_enabled"
app:key="force_triple_buffering"
app:title="@string/force_triple_buffering" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:dependency="force_triple_buffering"
android:summaryOff="@string/disable_frame_throttling_disabled"
android:summaryOn="@string/disable_frame_throttling_enabled"
app:key="disable_frame_throttling"
app:title="@string/disable_frame_throttling" />
<emu.skyline.preference.IntegerListPreference
android:defaultValue="2"
android:entries="@array/vsync_modes"
app:key="vsync_mode"
app:title="@string/vsync_mode"
app:useSimpleSummaryProvider="true"/>
<SeekBarPreference
android:defaultValue="4"
android:max="6"