Skip to content

Commit cad0278

Browse files
authored
Add configurable extra memory (shadps4-emu#3513)
* Add configurable extra memory * lowercase getter and setter * Refactor memory setup to configure maximum memory limits at runtime * sir clang offnir, the all-formatting * Correctly update BackingSize on W*ndows too * small format change * remove total_memory_to_use from the header * i have no idea how to name this commit "addressing review comments" is a good name i guess * Do not include extraDmem in the general config
1 parent 6c5a84d commit cad0278

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

src/common/config.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class ConfigEntry {
115115
static ConfigEntry<int> volumeSlider(100);
116116
static ConfigEntry<bool> isNeo(false);
117117
static ConfigEntry<bool> isDevKit(false);
118+
static ConfigEntry<int> extraDmemInMbytes(0);
118119
static ConfigEntry<bool> isPSNSignedIn(false);
119120
static ConfigEntry<bool> isTrophyPopupDisabled(false);
120121
static ConfigEntry<double> trophyNotificationDuration(6.0);
@@ -286,6 +287,14 @@ bool isDevKitConsole() {
286287
return isDevKit.get();
287288
}
288289

290+
int getExtraDmemInMbytes() {
291+
return extraDmemInMbytes.get();
292+
}
293+
294+
void setExtraDmemInMbytes(int value) {
295+
extraDmemInMbytes.base_value = 0;
296+
}
297+
289298
bool getIsFullscreen() {
290299
return isFullscreen.get();
291300
}
@@ -830,6 +839,9 @@ void load(const std::filesystem::path& path, bool is_game_specific) {
830839
volumeSlider.setFromToml(general, "volumeSlider", is_game_specific);
831840
isNeo.setFromToml(general, "isPS4Pro", is_game_specific);
832841
isDevKit.setFromToml(general, "isDevKit", is_game_specific);
842+
if (is_game_specific) { // do not get this value from the base config
843+
extraDmemInMbytes.setFromToml(general, "extraDmemInMbytes", is_game_specific);
844+
}
833845
isPSNSignedIn.setFromToml(general, "isPSNSignedIn", is_game_specific);
834846
isTrophyPopupDisabled.setFromToml(general, "isTrophyPopupDisabled", is_game_specific);
835847
trophyNotificationDuration.setFromToml(general, "trophyNotificationDuration",
@@ -1032,6 +1044,9 @@ void save(const std::filesystem::path& path, bool is_game_specific) {
10321044
isSideTrophy.setTomlValue(data, "General", "sideTrophy", is_game_specific);
10331045
isNeo.setTomlValue(data, "General", "isPS4Pro", is_game_specific);
10341046
isDevKit.setTomlValue(data, "General", "isDevKit", is_game_specific);
1047+
if (is_game_specific) {
1048+
extraDmemInMbytes.setTomlValue(data, "General", "extraDmemInMbytes", is_game_specific);
1049+
}
10351050
isPSNSignedIn.setTomlValue(data, "General", "isPSNSignedIn", is_game_specific);
10361051
isConnectedToNetwork.setTomlValue(data, "General", "isConnectedToNetwork", is_game_specific);
10371052

@@ -1155,6 +1170,7 @@ void setDefaultValues(bool is_game_specific) {
11551170
isPSNSignedIn.set(false, is_game_specific);
11561171
isConnectedToNetwork.set(false, is_game_specific);
11571172
directMemoryAccessEnabled.set(false, is_game_specific);
1173+
extraDmemInMbytes.set(0, is_game_specific);
11581174
}
11591175

11601176
// Entries with game-specific settings that are in both the game-specific and global GUI

src/common/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ bool isDevKitConsole();
116116
void setDevKitConsole(bool enable, bool is_game_specific = false);
117117

118118
bool vkValidationGpuEnabled(); // no set
119+
int getExtraDmemInMbytes();
120+
void setExtraDmemInMbytes(int value);
119121
bool getIsMotionControlsEnabled();
120122
void setIsMotionControlsEnabled(bool use, bool is_game_specific = false);
121123
std::string getDefaultControllerID();

src/core/address_space.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "common/alignment.h"
77
#include "common/arch.h"
88
#include "common/assert.h"
9+
#include "common/config.h"
910
#include "common/error.h"
1011
#include "core/address_space.h"
1112
#include "core/libraries/kernel/memory.h"
@@ -27,7 +28,7 @@ asm(".zerofill SYSTEM_RESERVED,SYSTEM_RESERVED,__SYSTEM_RESERVED,0x7C0004000");
2728

2829
namespace Core {
2930

30-
static constexpr size_t BackingSize = ORBIS_KERNEL_TOTAL_MEM_DEV_PRO;
31+
static size_t BackingSize = ORBIS_KERNEL_TOTAL_MEM_DEV_PRO;
3132

3233
#ifdef _WIN32
3334

@@ -71,6 +72,7 @@ struct MemoryRegion {
7172

7273
struct AddressSpace::Impl {
7374
Impl() : process{GetCurrentProcess()} {
75+
BackingSize += Config::getExtraDmemInMbytes() * 1_MB;
7476
// Allocate virtual address placeholder for our address space.
7577
MEM_ADDRESS_REQUIREMENTS req{};
7678
MEM_EXTENDED_PARAMETER param{};
@@ -432,6 +434,7 @@ enum PosixPageProtection {
432434

433435
struct AddressSpace::Impl {
434436
Impl() {
437+
BackingSize += Config::getExtraDmemInMbytes() * 1_MB;
435438
// Allocate virtual address placeholder for our address space.
436439
system_managed_size = SystemManagedSize;
437440
system_reserved_size = SystemReservedSize;

src/core/memory.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ void MemoryManager::SetupMemoryRegions(u64 flexible_size, bool use_extended_mem1
4242
if (Config::isDevKitConsole()) {
4343
total_size = is_neo ? ORBIS_KERNEL_TOTAL_MEM_DEV_PRO : ORBIS_KERNEL_TOTAL_MEM_DEV;
4444
}
45+
s32 extra_dmem = Config::getExtraDmemInMbytes();
46+
if (Config::getExtraDmemInMbytes() != 0) {
47+
LOG_WARNING(Kernel_Vmm,
48+
"extraDmemInMbytes is {} MB! Old Direct Size: {:#x} -> New Direct Size: {:#x}",
49+
extra_dmem, total_size, total_size + extra_dmem * 1_MB);
50+
total_size += extra_dmem * 1_MB;
51+
}
4552
if (!use_extended_mem1 && is_neo) {
4653
total_size -= 256_MB;
4754
}
@@ -58,7 +65,7 @@ void MemoryManager::SetupMemoryRegions(u64 flexible_size, bool use_extended_mem1
5865

5966
// Insert an area that covers the flexible memory physical address block.
6067
// Note that this should never be called after flexible memory allocations have been made.
61-
const auto remaining_physical_space = ORBIS_KERNEL_TOTAL_MEM_DEV_PRO - total_direct_size;
68+
const auto remaining_physical_space = total_size - total_direct_size;
6269
fmem_map.clear();
6370
fmem_map.emplace(total_direct_size,
6471
FlexibleMemoryArea{total_direct_size, remaining_physical_space});

0 commit comments

Comments
 (0)