Commit graph

27241 commits

Author SHA1 Message Date
Zephyron
21594b73aa Android: Implement TLB optimization to prevent deadlocks and improve performance
This commit addresses critical TLB (Translation Lookaside Buffer) issues on Android by implementing several optimizations:

- Add new BufferCacheAccelerator to manage memory range overlap detection
- Implement TLB-aware memory barriers to prevent unnecessary invalidations
- Add a TLB caching system to avoid redundant flushing operations
- Create a counter to limit outstanding memory operations and prevent TLB thrashing
- Implement TLB prefetching for better memory access patterns
- Add targeted memory barriers for more precise synchronization

These changes significantly reduce the likelihood of the "0.0 FPS deadlock" issue on Android devices by maintaining a more stable TLB state and preventing cache thrashing.

TODO: Merge & Adapt Camille LaVey's TLB Method To Further Improve
Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-03-14 18:56:16 +10:00
Zephyron
d869045b77 build: Move PGO configuration to earlier in CMakeLists.txt
The Profile-Guided Optimization configuration was previously placed at the
end of the CMakeLists.txt file, after all targets were already defined.
This was causing the PGO flags to have no effect on the build process.

This commit moves the PGO configuration to immediately after the initial
compiler flags setup and before any targets are defined, ensuring that
all targets will properly receive the PGO instrumentation or optimization
flags when those options are enabled.

This allows both CITRON_ENABLE_PGO_INSTRUMENT and CITRON_ENABLE_PGO_OPTIMIZE
to function correctly for all build targets.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-03-13 17:03:21 +10:00
Zephyron
f2931c7566 vulkan: Implement AMD driver workaround for logic operations
- Added conditional check for AMD graphics drivers
- Automatically disable logic operations when float vertex attributes
  are present to work around driver quirks
- Maintain original logic op state to preserve emulator behavior
- Prepare dynamic state management infrastructure for future
  OpenGL implementation changes

OpenGL implementation will follow in subsequent commits.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-03-13 16:30:23 +10:00
Zephyron
12c63997d2 core(base_clock_rate): Revert Back To 1,020 MHz
- This Commit Accidentally Slipped By In A Previous Commit (dad8859679)
- This Has Caused Many Errors & Networking Issues Particularly On Android
- Now Uses Safe, Default 1.02 GHz

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-03-13 16:10:04 +10:00
Zephyron
1023125be5 android: Add mandatory firmware and title.keys setup steps
- Downgrade Kotlin and Android plugin versions to ensure build compatibility.
- Add setup steps for title.keys installation and mandatory firmware setup.
- Persist auto-generated keys to improve emulator compatibility.
- Update key manager to write derived keys to filesystem.
- Implement UI handling for mandatory firmware installation checks.
2025-03-13 16:04:11 +10:00
Zephyron
dad8859679 android: Update build system and optimize ARM NCE implementation
- Update Kotlin from 1.9.20 to 2.1.20-RC2
- Upgrade Java version from 17 to 21
- Update Android Gradle plugin from 8.1.2 to 8.9.0
- Update Gradle wrapper from 8.10.2 to 8.11.1
- Update NDK version to 29.0.13113456 rc1
- Update all Android dependencies to latest versions
- Simplify ARM NCE implementation by removing custom TLB handling
- Improve alignment and access fault handling
- Update hardware BASE_CLOCK_RATE from 1.02GHz to 1.785GHz
- Add citron Emulator Project copyright notices

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-03-11 20:48:51 +10:00
Zephyron
834cc89548 externals: Update Vulkan and vcpkg submodules
Update the following external dependencies:
- Vulkan-Headers: 0f0cfd8 → cacef303
- Vulkan-Utility-Libraries: 50563f4 → bc3a4d9f
- vcpkg: cd1099f4 → e40d24cb

This commit updates the external dependencies to their latest
compatible versions to ensure we're using up-to-date libraries.
2025-03-11 15:47:53 +10:00
vampiric_x
38b259d099 Fix a few strings 2025-03-10 23:16:30 +01:00
vampiric_x
e7e9453667 android: Initial multiplayer support
And give room owners mod access on both Android and QT
2025-03-10 22:37:56 +01:00
Zephyron
ae75413cc3 Remove quickstart guide references to address legal concerns
- Removed "Open Quickstart Guide" menu item and associated functions
- Replaced ROM loading error popup containing quickstart guide links
  with a neutral disclaimer stating the software is provided as-is
  without warranty or support
- This change helps minimize legal liability by avoiding
  specific instructional content while directing users to community
  resources for assistance
2025-03-09 22:23:54 +10:00
Zephyron
6a31da5905 cmake: Add Profile-Guided Optimization (PGO) support
Adds support for Profile-Guided Optimization builds on both Windows (MSVC)
and Linux (GCC/Clang) platforms. This allows for performance optimizations
based on real usage patterns.

For MSVC:
- Adds /GL and /LTCG:PGINSTRUMENT flags for instrumentation
- Adds /GL and /LTCG:PGOPTIMIZE flags for optimization

For GCC:
- Adds -fprofile-generate flags for instrumentation
- Adds -fprofile-use flags for optimization

For Clang:
- Adds -fprofile-instr-generate flags for instrumentation
- Adds -fprofile-instr-use flags for optimization

Controlled by two new CMake options:
- CITRON_ENABLE_PGO_INSTRUMENT: Enable instrumentation build
- CITRON_ENABLE_PGO_OPTIMIZE: Enable optimization build

Updated submodules:
- Vulkan-Headers to 0f0cfd8
- Vulkan-Utility-Libraries to 50563f4
- vcpkg to cd1099f
2025-03-07 20:23:23 +10:00
Zephyron
a5125d008a revert 78b0080b96
revert TLB: Parallel Page Table Walk Logic Implementation
2025-03-06 06:44:38 +00:00
Zephyron
b24dd921aa revert 31694994f2
revert arm_nce: Hash TLB to MLP L2 Update
2025-03-06 06:44:06 +00:00
Zephyron
9a65205dba revert ee3d858935
revert Follow Up Of the previous commit with the update of TLB update
2025-03-06 06:43:37 +00:00
Zephyron
af4f08be33 revert 6565055865
revert Fix: Core_Memory logging and ARM_NCE Mutex logging
2025-03-06 06:42:48 +00:00
Zephyron
0d0963d32f revert 90a8165f77
revert Added: Core_Memory to filter logging class
2025-03-06 06:42:30 +00:00
Zephyron
4491127f52 revert 031c635095
revert arm: corrected declarations
2025-03-06 06:41:01 +00:00
Zephyron
c304afe2b3 revert 78b0080b96
revert TLB: Parallel Page Table Walk Logic Implementation
2025-03-06 06:40:24 +00:00
Zephyron
b8240b4214 revert 644ed69285
revert arm:
2025-03-06 06:40:17 +00:00
Zephyron
91487f6d96 revert 3554f55fc9
revert TLB Update
2025-03-06 06:39:49 +00:00
CamilleLaVey
031c635095 arm: corrected declarations 2025-03-05 11:12:44 -04:00
CamilleLaVey
90a8165f77 Added: Core_Memory to filter logging class 2025-03-05 01:31:22 -04:00
CamilleLaVey
6565055865 Fix: Core_Memory logging and ARM_NCE Mutex logging 2025-03-05 00:25:31 -04:00
CamilleLaVey
ee3d858935 Follow Up Of the previous commit with the update of TLB update 2025-03-04 22:50:01 -04:00
CamilleLaVey
31694994f2 arm_nce: Hash TLB to MLP L2 Update 2025-03-04 22:28:03 -04:00
CamilleLaVey
4197fa84a0 revert e4342324fe
revert Changes of the previous commits
2025-03-04 02:33:14 +00:00
CamilleLaVey
e4342324fe Changes of the previous commits 2025-03-03 21:49:07 -04:00
CamilleLaVey
78b0080b96 TLB: Parallel Page Table Walk Logic Implementation 2025-03-03 21:44:56 -04:00
CamilleLaVey
644ed69285 arm: 2025-03-03 21:23:13 -04:00
CamilleLaVey
3554f55fc9 TLB Update 2025-03-03 20:55:08 -04:00
Zephyron
dc9532b4d1 Revert "CMake: Enable C++ latest and coroutines for MSVC builds"
This reverts commit 1308e2b935.
2025-03-03 17:13:29 +10:00
Zephyron
1308e2b935 CMake: Enable C++ latest and coroutines for MSVC builds
Add /std:c++latest and /await compiler flags for MSVC builds to enable
the latest C++ features and coroutine support.
2025-03-03 16:35:57 +10:00
Zephyron
5caecd8151 Android: Remove redundant firmware check
Remove duplicate firmware presence check in EmulationActivity. The
isFirmwareAvailable() check already handles this functionality, making
checkFirmwarePresence() redundant.
2025-03-03 16:35:18 +10:00
Zephyron
dc9fbcc893 Android: Downgrade build dependencies and SDK versions
- Revert Android Gradle plugin from 8.8.1 to 8.1.2
- Downgrade Kotlin version from 2.1.20-RC to 1.9.20
- Lower Java/JVM target from 21 to 17
- Reduce CMake version from 3.31.5 to 3.22.1
- Update various Android dependencies to stable versions:
  - Navigation Safe Args plugin to 2.6.0
  - ktlint to 0.47.1
  - Play Publisher plugin to 3.8.6
- Remove custom APK naming scheme
- Fix CMake boolean arguments (OFF -> 0)
- Remove citron copyright header
2025-03-03 16:34:35 +10:00
Zephyron
b1d5d4e5be Update external dependencies
- Update Vulkan-Utility-Libraries submodule to 5f41f2a
- Update vcpkg submodule to efb1e74
2025-03-03 16:33:01 +10:00
CamilleLaVey
f0d8daf755 revert cbb9a35166
revert Re-Enabled Vulkan Functions disabled on Adreno to improve compatibility and performance and check further issues within the current changes.
2025-03-03 04:00:13 +00:00
CamilleLaVey
cbb9a35166 Re-Enabled Vulkan Functions disabled on Adreno to improve compatibility and performance and check further issues within the current changes. 2025-03-02 23:17:43 -04:00
Zephyron
cfe437aacf arm: Improve TLB implementation and fault handling in NCE
This commit enhances the Translation Lookaside Buffer (TLB) implementation
in the ARM Native Code Execution (NCE) component to increase stability,
particularly on Android devices. The changes prioritize robustness and
error recovery over performance optimizations.

Key improvements:
- Replace set-associative TLB with a simpler linear search implementation
- Implement a basic LRU replacement policy for TLB entries
- Add validation checks for memory addresses before TLB insertion
- Ensure proper page alignment for guest and host addresses
- Enhance alignment fault handling with instruction skipping as fallback
- Add comprehensive debug logging for memory access errors
- Improve error recovery in guest memory access scenarios

These changes should significantly reduce crashes during emulation on
Android devices by gracefully handling memory access edge cases that
previously resulted in hard crashes.

Co-Authored-By: Camille LaVey <camillelavey@citron-emu.org>
Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-02-28 17:11:07 +10:00
Zephyron
9b293c3a98 shader_recompiler: Implement vertex count lookup for Geometry stage
Add proper handling of input topologies in the Geometry stage for all three
shader backends (GLASM, GLSL, SPIRV). This implementation uses a lookup table
approach to determine vertex counts based on input topology type (Points,
Lines, LinesAdjacency, Triangles, TrianglesAdjacency) and shifts the vertex
count by 16 bits as required by the invocation info format.

Additional changes:
- Fixed TessellationControl and TessellationEval stages to properly break
  after emitting code
- Added proper header include for runtime_info.h in GLASM backend
- Improved code documentation with clear commenting patterns

This change ensures accurate geometry shader behavior across all backends,
improving compatibility with games that rely on proper vertex count reporting.

Signed-off-by: Zephyron <zephyron@citron-emu.org>
2025-02-28 17:08:27 +10:00
Zephyron
84e5fbc089 feat: Make firmware mandatory for title launching
This commit implements a requirement for firmware to be installed before titles
can be launched, similar to how keys are required.

Changes include:
- Add IsFirmwareAvailable method to KeyManager to check for essential keys
- Add CheckFirmwarePresence method to verify actual firmware files (NCAs)
- Add firmware checks in game loading process for both desktop and Android
- Add error messages when firmware is missing
- Add strings for firmware-related error messages

The implementation checks for both essential keys and the presence of system
applets like Mii Edit and Home Menu to ensure proper firmware is installed.
Games will not launch if firmware is missing, and users will be shown an
appropriate error message.
2025-02-28 16:15:10 +10:00
Zephyron
a442078ee4 feat: Remove autogenerated key functionality
This commit removes the functionality that automatically generates and writes
keys to *_autogenerated files. The key derivation logic is preserved, but
derived keys are now only stored in memory and not written to disk.

Changes include:
- Remove loading from *_autogenerated key files
- Make WriteKeyToFile a no-op function
- Remove all file writing operations in SetKey methods
- Remove file writing for keyblobs and other derived keys
- Update copyright notices

This change improves security by not storing derived keys on disk and
simplifies the key management system.
2025-02-28 15:27:12 +10:00
Zephyron
cc610ad9b6 renderer: Disable async presentation due to crashes
- Disable async presentation by default on both Android and desktop platforms due to stability issues.
2025-02-27 13:19:08 +10:00
Zephyron
5a65f9a094 Update external dependencies
- Vulkan-Utility-Libraries: 6be00ca → 2d8f273
- FFmpeg: d161604 → 99e2af4
- vcpkg: 9a7a33f → 23b33f5
2025-02-27 13:08:19 +10:00
Zephyron
5ca1f0e365 core/arm/nce: Implement TLB caching system
Adds a software TLB cache to improve memory access performance in the NCE
(Native Code Execution) system. Key changes include:

- Implement set-associative TLB with 64 sets and 8 ways
- Add TLB lookup before memory access in HandleGuestAccessFault
- Implement LRU replacement policy with access frequency consideration
- Add thread context caching to reduce overhead
- Add proper synchronization with mutex locks
- Add helper functions for TLB management (lookup, insert, invalidate)

This change should improve performance by reducing redundant memory
translations and providing faster access to frequently used pages.
2025-02-25 18:37:14 +10:00
Zephyron
a36baad0f0 externals: Update submodule versions
- vcpkg: 37d46ed → 9a7a33f
- Vulkan-Headers: 234c4b7 → 952f776
- Vulkan-Utility-Libraries: fe7a09b → 6be00ca
- ffmpeg: 9c1294e → d161604
2025-02-25 18:34:32 +10:00
Zephyron
ed115d3f72 Revert "settings: Enable auto-stub by default"
This reverts commit 7903415fa4.
2025-02-24 19:05:05 +10:00
Zephyron
d9619b7eed vulkan: Improve memory allocation robustness
Enhances the Vulkan memory allocator with better OOM handling and memory
alignment:

* Add memory recovery by cleaning up empty allocations before failing
* Implement proper fallback to non-device-local memory
* Simplify memory alignment handling for different vendors
* Add better error logging for allocation failures
* Add IsEmpty() helper to track unused allocations
* Fix alignment requirements for Adreno (4KB) vs other vendors

These changes improve the robustness of memory allocation, particularly
in low-memory situations, and streamline vendor-specific alignment
requirements.
2025-02-22 19:08:42 +10:00
Zephyron
dbe5bf1d18 android: Update build dependencies and configurations
Updates various build dependencies and configurations for the Android build:

* Upgrade Android Gradle Plugin to 8.8.1
* Update Kotlin to 2.1.20-RC
* Upgrade NDK to 28.0.13004108
* Update target/compile SDK to Android 35
* Upgrade Java/Kotlin target to JVM 21
* Enable additional release optimizations (shrinkResources, proguard-android-optimize)
* Update CMake to 3.31.5
* Update various AndroidX and support library dependencies
* Change CMake boolean flags from 0/1 to OFF/ON
* Update ktlint to 0.51.1 and related plugins

This commit modernizes the Android build system and enables additional
optimizations for release builds.
2025-02-22 19:07:53 +10:00
Zephyron
7903415fa4 settings: Enable auto-stub by default
Changes the default value of use_auto_stub from false to true in the settings.
This setting controls whether unimplemented functions should be automatically
stubbed during execution.
2025-02-22 19:07:16 +10:00
Zephyron
3bb4d97e9e cmake: Optimize Android VVL download logic
Improve the Vulkan Validation Layer (VVL) download logic for Android by checking
for the final library file instead of just the zip archive. This prevents
unnecessary re-downloads and extractions when the library is already in place.

The check now looks for libVkLayer_khronos_validation.so in the final
destination path before attempting to download and extract the archive.
2025-02-22 19:06:05 +10:00