Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

NX-FPS Switch: Difference between revisions

From GameBrew
No edit summary
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Infobox Switch Homebrews
{{Infobox Switch Homebrews
|title=NX-FPS
|title=NX-FPS
|image=nxfpsswitch.png
|image=nxfps.png
|description=SaltyNX Plugin collecting FPS data
|description=SaltyNX plugin collecting FPS data.
|author=masagrator
|author=masagrator
|lastupdated=2023/05/06
|lastupdated=2023/07/02
|type=Plugins
|type=Plugins
|version=1.4.1
|version=1.5.5
|license=MIT
|license=MIT
|download=https://dlhb.gamebrew.org/switchhomebrews/nxfpsswitch.7z
|download=https://dlhb.gamebrew.org/switchhomebrews/nxfpsswitch.7z
Line 13: Line 13:
|donation=https://ko-fi.com/masagrator
|donation=https://ko-fi.com/masagrator
}}
}}
{{#seo:
{{obsolete}}
|title=Switch Homebrew Apps (Plugins) - GameBrew
NX-FPS is a [[SaltyNX Switch|SaltyNX]] plugin that collects FPS data in Nintendo Switch games.  
|title_mode=append
 
|image=nxfpsswitch.png
'''Note:''' Since SaltyNX v0.7.0 NX-FPS is an intergral part of SaltyNX Core. Please delete NX-FPS plugin from SaltySD/plugins folder and update to SaltyNX 0.7.0+.
|image_alt=NX-FPS
}}
NX-FPS is a SaltyNX plugin that collects FPS data in Nintendo Switch games. It requires the fork of [[SaltyNX Switch]] 0.5.0+ installed.


==Installation==
==Installation==
Once you've installed the necessary software, simply put the NX-FPS.elf file into <code>/SaltySD/plugins</code>. This plugin currently supports graphics APIs such as NVN, EGL, and Vulkan.
It requires the fork of [[SaltyNX Switch|SaltyNX]] 0.5.0+ installed.
 
==Read FPS Data==
To read FPS data from the plugin, you can either use the Status Monitor Overlay 0.8.1+ from [https://github.com/masagrator/Status-Monitor-Overlay here] or write your own code. If you're interested in writing your own code, I've provided instructions based on the Status Monitor Overlay code:


# You'll need to include the old ipc.h file from [https://github.com/masagrator/ReverseNX-RT/blob/master/Overlay/include/ipc.h here] as well as SaltyNX.h from [https://github.com/masagrator/ReverseNX-RT/blob/master/Overlay/include/SaltyNX.h here].
To install NX-FPS, put the NX-FPS.elf file into <code>/SaltySD/plugins/</code>.  
# Connect to SaltyNX SharedMemory by connecting to SaltyNX, retrieving the SharedMemory handle, terminating the connection with SaltyNX, and then assigning SharedMemory to your homebrew.


==Media==
To read FPS data from the plugin, you can either use the [[Status Monitor Overlay Switch|Status Monitor Overlay 0.8.1+]] or make your own homebrew to use this.
'''How to overclock the Nintendo Switch and view FPS - Sysclk & NX FPS Homebrew mods Atmosphere CFW - ([https://www.youtube.com/watch?v=0svgC4wuB18 Nevercholt])'''<br>
<youtube>0svgC4wuB18</youtube>


'''Resident Evil 5 (Nintendo Switch) - Status Monitor Overlay and NX-FPS - ([https://www.youtube.com/watch?v=9RqGEk4talI Marek])'''<br>
==User guide==
<youtube>9RqGEk4talI</youtube>
Currently supports graphics APIs are:  
*NVN.
*EGL.
*Vulkan.


==Helper==
When game is booted, plugin outputs one file <code>/SaltySD/FPSoffset.hex</code>.
<pre>Handle remoteSharedMemory = 1;
SharedMemory _sharedmemory = {};
bool SharedMemoryUsed = false;


//Function pinging SaltyNX InjectServ port to check if it's alive.
There is stored address, where you can find PFPS, FPS has address PFPS - 0x8.
bool CheckPort () {
*PFPS - Pushed Frames Per Second (u8), it counts how many frames were actually pushed to display in second that passed.
    Handle saltysd;
*FPS - Frames Per Second (float) calculated from averaged frametime, refreshed with each new frame.
    for (int i = 0; i &lt; 67; i++) {
        if (R_SUCCEEDED(svcConnectToNamedPort(&amp;saltysd, &quot;InjectServ&quot;))) {
            svcCloseHandle(saltysd);
            break;
        }
        else {
            if (i == 66) return false;
            svcSleepThread(1'000'000);
        }
    }
    for (int i = 0; i &lt; 67; i++) {
        if (R_SUCCEEDED(svcConnectToNamedPort(&amp;saltysd, &quot;InjectServ&quot;))) {
            svcCloseHandle(saltysd);
            return true;
        }
        else svcSleepThread(1'000'000);
    }
    return false;
}


bool LoadSharedMemory() {
If file is already there, it's rewritten by new address with each new game boot.
    //Connect to main SaltyNX port. On failed attempt return false
    if (SaltySD_Connect())
      return false;
    //Retrieve handle necessary to get access to SaltyNX SharedMemory
    SaltySD_GetSharedMemoryHandle(&amp;remoteSharedMemory);
    //Terminate SaltyNX main port connection
    SaltySD_Term();
   
    //Prepare struct that will be passed to shmemMap to get access to SaltyNX SharedMemory
    shmemLoadRemote(&amp;_sharedmemory, remoteSharedMemory, 0x1000, Perm_Rw);
    //Try to get access to SaltyNX SharedMemory
    if (!shmemMap(&amp;_sharedmemory)) {
      //On success change bool of SharedMemoryUsed to true and return true
      SharedMemoryUsed = true;
      return true;
    }
    //On failed attemp return false
    return false;
}


//By connecting to InjectServ port we can check if SaltyNX is alive and is not stuck anywhere.
===Notes===
bool SaltyNX = CheckPort();
//Check if SaltyNX signaled anything, if yes then use LoadSharedMemory() to get access to SaltyNX SharedMemory
if (SaltyNX) LoadSharedMemory();</pre>
 
* Next we need to find where our plugin is inside SharedMemory. For this our plugin stores magic 0x465053 as uint32_t. We need to find magic and based on that we know where our plugin is.
 
<pre>uint32_t* MAGIC_shared = 0;
uint8_t* FPS_shared = 0;
float* FPSavg_shared = 0;
bool* pluginActive = 0;
 
//Function searching for NX-FPS magic through SharedMemory.
//SaltyNX is page aligning any SharedMemory reservation request to 4, that's why we check every 4th byte for MAGIC.
ptrdiff_t searchSharedMemoryBlock(uintptr_t base) {
    ptrdiff_t search_offset = 0;
    while(search_offset &lt; 0x1000) {
        MAGIC_shared = (uint32_t*)(base + search_offset);
        if (*MAGIC_shared == 0x465053) {
            return search_offset;
        }
        else search_offset += 4;
    }
    return -1;
}
 
//Get virtual address of SaltyNX SharedMemory
uintptr_t base = (uintptr_t)shmemGetAddr(&amp;_sharedmemory);
//Pass retrieved virtual address of SaltyNX SharedMemory to function that will search for NX-FPS magic
ptrdiff_t rel_offset = searchSharedMemoryBlock(base);
//If magic will be found, you will get offset that starts before magic. It cannot be lower than 0.
if (rel_offset &gt; -1) {
  //Pass correct addresses inside SharedMemory to our pointers
  //It shows how many frames passed in one second
  FPS_shared = (uint8_t*)(base + rel_offset + 4);
  //It calculates average FPS based on last 10 readings
  FPSavg_shared = (float*)(base + rel_offset + 5);
  //Pointer where plugin writes true for every frame.
  pluginActive = (bool*)(base + rel_offset + 9);
  ///By passing false to *pluginActive and checking later if it has changed to true we can be sure plugin is working.
  *pluginActive = false;
}</pre>
 
<blockquote>WARNING
</blockquote>
Plugin brings some instability to boot process for some games. It is recommended to not close game before ~10 seconds have passed from showing Nintendo logo, otherwise you risk Kernel panic, which results in crashing OS.
Plugin brings some instability to boot process for some games. It is recommended to not close game before ~10 seconds have passed from showing Nintendo logo, otherwise you risk Kernel panic, which results in crashing OS.
-----


Not working games with this plugin (You can find games not compatible with SaltyNX [https://github.com/masagrator/SaltyNX/blob/master/README.md here])
Not working games with this plugin (You can find games not compatible with SaltyNX [https://github.com/masagrator/SaltyNX/blob/master/README.md here])


{| class="wikitable"
{| class="wikitable"
! Title
! Title||Version(s)||Why
! Version(s)
! Why?
|-
|-
| Final Fantasy VIII Remastered
| Final Fantasy VIII Remastered||all||Framework stuff is included in NROs which SaltyNX doesn't support.
| all
|-
| Framework stuff is included in NROs which SaltyNX doesn't support
| Final Fantasy X/X-2||all||Framework stuff is included in NROs which SaltyNX doesn't support.
|-
| LEGO Harry Potter Collection||all||Framework stuff is included in NROs which SaltyNX doesn't support.
|-
|-
| Final Fantasy X/X-2
| all
| Framework stuff is included in NROs which SaltyNX doesn't support
|}
|}


== Troubleshooting ==
=== Troubleshooting ===
'''Q: Why I got constantly 255?'''<br>
'''Q. Why I got constantly 255?'''
A: 255 is default value before plugin starts counting frames. This may be a sign that:
 
255 is default value before plugin starts counting frames. This may be a sign that:
* Game is using different API or function than what is currently supported
* Game is using different API or function than what is currently supported
* Plugin missed symbol when initializing (for whatever reason)
* Plugin missed symbol when initializing (for whatever reason)


Try first to run game again few times. If it's still 255, make an issue and state name of game. Next updates will include support for other graphics APIs.
Try first to run game again few times. If it's still 255, make an issue and state name of game. Next updates will include support for other graphics APIs.
==Screenshots==
https://dlhb.gamebrew.org/switchhomebrews/nxfps2.png
==Media==
'''Resident Evil 5 (Nintendo Switch) - Status Monitor Overlay and NX-FPS ([https://www.youtube.com/watch?v=9RqGEk4talI Marek])'''<br>
<youtube>9RqGEk4talI</youtube>
'''How to overclock the Nintendo Switch and view FPS - Sysclk & NX FPS Homebrew mods Atmosphere CFW ([https://www.youtube.com/watch?v=0svgC4wuB18 Nevercholt])'''<br>
<youtube>0svgC4wuB18</youtube>


==Changelog==
==Changelog==
'''1.4.1'''
'''1.5.5 2023/07/02'''
* Add support for new Vulkan command:
** NvSwapchain::QueuePresentKHR(VkQueue_T*, const VkPresentInfoKHR*)
* It solves an issue with FPS Counter not working in Undead Horde 2.
'''1.5.4 2023/06/09'''
*Allow setting max available buffers in games that don't utilize all available buffers (for example We Love Katamari REROLL is reserving 3 buffers, but force game to use only 2. We can now force game to use all 3 buffers for smoother FPS drops)
'''1.5.3 2023/05/23'''
*Allow setting double buffer in games that are using triple buffer.
'''1.5.2 2023/05/20'''
* Fix migrating to other threads when delaying frames (fixes issue with long loading times in Tears of the Kingdom).
* Improve performance of Window Sync Semi-Enabled mode.
'''1.5.1 2023/05/20'''
*Add support for Semi-Enabled Window Sync Wait.
'''1.5.0 2023/05/15'''
* Support MASTER_WRITE entry in FPSLocker patches.
* Disable Sync Wait only if passed nvnSync to nvnSyncWait matches nvnSync passed to nvnWindowAcquireTexture (prevents games from crashing, enabling more games to unsync from double buffer vsync - f.e. The Legend of Zelda: Tears of the Kingdom).
'''1.4.1 2023/05/06'''
*Pull from NVN info about number of buffered frames.
*Pull from NVN info about number of buffered frames.
'''1.4.0'''
'''1.4.0 2023/04/22'''
* Adjust dynamically FPS lock (fixing issue with CPU speed affecting lock's precision)
* Adjust dynamically FPS lock (fixing issue with CPU speed affecting lock's precision).
* Add array of last 10 frames timings to read from SharedMemory
* Add array of last 10 frames timings to read from SharedMemory.
'''1.3.3'''
'''1.3.3 2023/04/16'''
*Fix NVN interval detection in games using more than 1 nvnWindow. Now f.e. WRC Generations can be unlocked with plugin alone.
*Fix NVN interval detection in games using more than 1 nvnWindow. Now f.e. WRC Generations can be unlocked with plugin alone.
'''1.3.2'''
'''1.3.2 2023/04/07'''
*Fixes loading patches for some games.
*Fixes loading patches for some games.
*If you have downloaded version 1.3.1, it's bugged more than 1.3. Update it.
*If you have downloaded version 1.3.1, it's bugged more than 1.3. Update it.
'''1.3'''
'''1.3 2023/04/05'''
* Provide better API detection
* Provide better API detection.
* Add support for eglSwapInterval
* Add support for eglSwapInterval.
* Fix eglSwapBuffers return
* Fix eglSwapBuffers return.
'''1.2.1'''
'''1.2.1 2023/04/02'''
*Fix "main" address detection
*Fix "main" address detection.
'''1.2'''
'''1.2 2023/04/01'''
*Add support for nvnQueueAcquireTexture that was used with some old games (for example Outlast) before deprecation.
*Add support for nvnQueueAcquireTexture that was used with some old games (for example <code>Outlast</code>) before deprecation.
'''1.1'''
'''1.1 2023/03/19'''
*Allow loading LOCK bins produced by FPSLocker 1.1+
*Allow loading LOCK bins produced by FPSLocker 1.1+.
'''1.0'''
'''1.0 2023/03/08'''
*Allow manipulating FPS
*Allow manipulating FPS.
'''0.4'''
'''0.4 2023/03/03'''
*Move writing data into SaltyNX SharedMemory. Requires SaltyNX 0.5.0+ to work.
*Move writing data into SaltyNX SharedMemory. Requires SaltyNX 0.5.0+ to work.
*If you use Status Monitor Overlay, you must update it to version 0.8.1+ to use it.
*If you use Status Monitor Overlay, you must update it to version 0.8.1+ to use it.
'''0.3'''
'''0.3 2020/03/21'''
*Added support for Vulkan, so games like The Talos Principle and DOOM 64 are now supported.
*Added support for Vulkan, so games like The Talos Principle and DOOM 64 are now supported.
'''0.2'''
'''0.2 2020/03/01'''
*Added support for EGL, which means games like The Unholy Society and Layton's Mystery Journey: Katrielle and the Millionaires' Conspiracy are now supported.
*Added support for EGL, which means games like <code>The Unholy Society</code> and <code>Layton's Mystery Journey: Katrielle and the Millionaires' Conspiracy</code> are now supported.
'''0.1'''
'''0.1 2020/02/29'''
* First Release.
* First Release.


== Thanks to ==
== Credits ==
* RetroNX channel for help with coding stuff,
* RetroNX channel for help with coding stuff,
* CTCaer for providing many useful informations and convincing me to the end that I should target high precision,
* CTCaer for providing many useful informations and convincing me to the end that I should target high precision,
Line 198: Line 129:


== External links ==
== External links ==
* Official Website - https://gbatemp.net/threads/nx-fps-saltynx-plugin-collecting-fps-data.559065/
* GitHub - https://github.com/masagrator/NX-FPS
* Github - https://github.com/masagrator/NX-FPS
* GBAtemp - https://gbatemp.net/threads/nx-fps-saltynx-plugin-collecting-fps-data.559065/

Latest revision as of 09:25, 11 February 2024

NX-FPS
Nxfps.png
General
Authormasagrator
TypePlugins
Version1.5.5
LicenseMIT License
Last Updated2023/07/02
Links
Download
Website
Source
Support Author

NX-FPS is a SaltyNX plugin that collects FPS data in Nintendo Switch games.

Note: Since SaltyNX v0.7.0 NX-FPS is an intergral part of SaltyNX Core. Please delete NX-FPS plugin from SaltySD/plugins folder and update to SaltyNX 0.7.0+.

Installation

It requires the fork of SaltyNX 0.5.0+ installed.

To install NX-FPS, put the NX-FPS.elf file into /SaltySD/plugins/.

To read FPS data from the plugin, you can either use the Status Monitor Overlay 0.8.1+ or make your own homebrew to use this.

User guide

Currently supports graphics APIs are:

  • NVN.
  • EGL.
  • Vulkan.

When game is booted, plugin outputs one file /SaltySD/FPSoffset.hex.

There is stored address, where you can find PFPS, FPS has address PFPS - 0x8.

  • PFPS - Pushed Frames Per Second (u8), it counts how many frames were actually pushed to display in second that passed.
  • FPS - Frames Per Second (float) calculated from averaged frametime, refreshed with each new frame.

If file is already there, it's rewritten by new address with each new game boot.

Notes

Plugin brings some instability to boot process for some games. It is recommended to not close game before ~10 seconds have passed from showing Nintendo logo, otherwise you risk Kernel panic, which results in crashing OS.

Not working games with this plugin (You can find games not compatible with SaltyNX here)

Title Version(s) Why
Final Fantasy VIII Remastered all Framework stuff is included in NROs which SaltyNX doesn't support.
Final Fantasy X/X-2 all Framework stuff is included in NROs which SaltyNX doesn't support.
LEGO Harry Potter Collection all Framework stuff is included in NROs which SaltyNX doesn't support.

Troubleshooting

Q. Why I got constantly 255?

255 is default value before plugin starts counting frames. This may be a sign that:

  • Game is using different API or function than what is currently supported
  • Plugin missed symbol when initializing (for whatever reason)

Try first to run game again few times. If it's still 255, make an issue and state name of game. Next updates will include support for other graphics APIs.

Screenshots

nxfps2.png

Media

Resident Evil 5 (Nintendo Switch) - Status Monitor Overlay and NX-FPS (Marek)

How to overclock the Nintendo Switch and view FPS - Sysclk & NX FPS Homebrew mods Atmosphere CFW (Nevercholt)

Changelog

1.5.5 2023/07/02

  • Add support for new Vulkan command:
    • NvSwapchain::QueuePresentKHR(VkQueue_T*, const VkPresentInfoKHR*)
  • It solves an issue with FPS Counter not working in Undead Horde 2.

1.5.4 2023/06/09

  • Allow setting max available buffers in games that don't utilize all available buffers (for example We Love Katamari REROLL is reserving 3 buffers, but force game to use only 2. We can now force game to use all 3 buffers for smoother FPS drops)

1.5.3 2023/05/23

  • Allow setting double buffer in games that are using triple buffer.

1.5.2 2023/05/20

  • Fix migrating to other threads when delaying frames (fixes issue with long loading times in Tears of the Kingdom).
  • Improve performance of Window Sync Semi-Enabled mode.

1.5.1 2023/05/20

  • Add support for Semi-Enabled Window Sync Wait.

1.5.0 2023/05/15

  • Support MASTER_WRITE entry in FPSLocker patches.
  • Disable Sync Wait only if passed nvnSync to nvnSyncWait matches nvnSync passed to nvnWindowAcquireTexture (prevents games from crashing, enabling more games to unsync from double buffer vsync - f.e. The Legend of Zelda: Tears of the Kingdom).

1.4.1 2023/05/06

  • Pull from NVN info about number of buffered frames.

1.4.0 2023/04/22

  • Adjust dynamically FPS lock (fixing issue with CPU speed affecting lock's precision).
  • Add array of last 10 frames timings to read from SharedMemory.

1.3.3 2023/04/16

  • Fix NVN interval detection in games using more than 1 nvnWindow. Now f.e. WRC Generations can be unlocked with plugin alone.

1.3.2 2023/04/07

  • Fixes loading patches for some games.
  • If you have downloaded version 1.3.1, it's bugged more than 1.3. Update it.

1.3 2023/04/05

  • Provide better API detection.
  • Add support for eglSwapInterval.
  • Fix eglSwapBuffers return.

1.2.1 2023/04/02

  • Fix "main" address detection.

1.2 2023/04/01

  • Add support for nvnQueueAcquireTexture that was used with some old games (for example Outlast) before deprecation.

1.1 2023/03/19

  • Allow loading LOCK bins produced by FPSLocker 1.1+.

1.0 2023/03/08

  • Allow manipulating FPS.

0.4 2023/03/03

  • Move writing data into SaltyNX SharedMemory. Requires SaltyNX 0.5.0+ to work.
  • If you use Status Monitor Overlay, you must update it to version 0.8.1+ to use it.

0.3 2020/03/21

  • Added support for Vulkan, so games like The Talos Principle and DOOM 64 are now supported.

0.2 2020/03/01

  • Added support for EGL, which means games like The Unholy Society and Layton's Mystery Journey: Katrielle and the Millionaires' Conspiracy are now supported.

0.1 2020/02/29

  • First Release.

Credits

  • RetroNX channel for help with coding stuff,
  • CTCaer for providing many useful informations and convincing me to the end that I should target high precision,
  • Herbaciarz for providing video footage.

External links

Advertising: