Skip to content

Commit

Permalink
Merge pull request #18548 from hrydgard/adrenotools-followup
Browse files Browse the repository at this point in the history
Adrenotools followup
  • Loading branch information
hrydgard committed Dec 14, 2023
2 parents 578a90f + 47caa63 commit 88b1943
Show file tree
Hide file tree
Showing 47 changed files with 133 additions and 79 deletions.
5 changes: 2 additions & 3 deletions Common/File/FileUtil.cpp
Expand Up @@ -1209,12 +1209,11 @@ bool WriteStringToFile(bool text_file, const std::string &str, const Path &filen
return true;
}

bool WriteDataToFile(bool text_file, const void* data, const unsigned int size, const Path &filename) {
bool WriteDataToFile(bool text_file, const void* data, size_t size, const Path &filename) {
FILE *f = File::OpenCFile(filename, text_file ? "w" : "wb");
if (!f)
return false;
size_t len = size;
if (len != fwrite(data, 1, len, f))
if (size != fwrite(data, 1, size, f))
{
fclose(f);
return false;
Expand Down
2 changes: 1 addition & 1 deletion Common/File/FileUtil.h
Expand Up @@ -201,7 +201,7 @@ class IOFile {

// Whole-file reading/writing
bool WriteStringToFile(bool text_file, const std::string &str, const Path &filename);
bool WriteDataToFile(bool text_file, const void* data, const unsigned int size, const Path &filename);
bool WriteDataToFile(bool text_file, const void* data, size_t size, const Path &filename);

bool ReadFileToString(bool text_file, const Path &filename, std::string &str);
// Return value must be delete[]-d.
Expand Down
156 changes: 85 additions & 71 deletions UI/GameSettingsScreen.cpp
Expand Up @@ -107,8 +107,16 @@ bool SupportsCustomDriver() {
return android_get_device_api_level() >= 28 && CheckKgslPresent();
}

#else

bool SupportsCustomDriver() {
return false;
}

#endif

static void TriggerRestart(const char *why, bool editThenRestore, const Path &gamePath);

GameSettingsScreen::GameSettingsScreen(const Path &gamePath, std::string gameID, bool editThenRestore)
: TabbedUIDialogScreenWithGameBackground(gamePath), gameID_(gameID), editThenRestore_(editThenRestore) {
prevInflightFrames_ = g_Config.iInflightFrames;
Expand Down Expand Up @@ -282,27 +290,6 @@ void GameSettingsScreen::CreateGraphicsSettings(UI::ViewGroup *graphicsSettings)
// If we're not the first instance, can't save the setting, and it requires a restart, so...
renderingBackendChoice->SetEnabled(false);
}

#if PPSSPP_PLATFORM(ANDROID) && PPSSPP_ARCH(ARM64)
if (GetGPUBackend() == GPUBackend::VULKAN && SupportsCustomDriver()) {
const Path driverPath = g_Config.internalDataDirectory / "drivers";

std::vector<File::FileInfo> listing;
File::GetFilesInDir(driverPath, &listing);

std::vector<std::string> availableDrivers;
availableDrivers.push_back("Default");

for (auto driver : listing) {
availableDrivers.push_back(driver.name);
}
auto driverChoice = graphicsSettings->Add(new PopupMultiChoiceDynamic(&g_Config.customDriver, gr->T("Current GPU Driver"), availableDrivers, I18NCat::NONE, screenManager()));
driverChoice->OnChoice.Handle(this, &GameSettingsScreen::OnCustomDriverChange);

auto customDriverInstallChoice = graphicsSettings->Add(new Choice(gr->T("Install Custom Driver...")));
customDriverInstallChoice->OnClick.Handle(this, &GameSettingsScreen::OnCustomDriverInstall);
}
#endif
#endif

// Backends that don't allow a device choice will only expose one device.
Expand Down Expand Up @@ -1249,67 +1236,75 @@ void GameSettingsScreen::CreateVRSettings(UI::ViewGroup *vrSettings) {
vrSettings->Add(new PopupMultiChoice(&g_Config.iCameraPitch, vr->T("Camera type"), cameraPitchModes, 0, 3, I18NCat::NONE, screenManager()));
}

UI::EventReturn GameSettingsScreen::OnCustomDriverChange(UI::EventParams &e) {
auto di = GetI18NCategory(I18NCat::DIALOG);
UI::EventReturn DeveloperToolsScreen::OnCustomDriverChange(UI::EventParams &e) {
auto di = GetI18NCategory(I18NCat::DIALOG);

screenManager()->push(new PromptScreen(gamePath_, di->T("Changing this setting requires PPSSPP to restart."), di->T("Restart"), di->T("Cancel"), [=](bool yes) {
if (yes) {
TriggerRestart("GameSettingsScreen::CustomDriverYes");
}
}));
return UI::EVENT_DONE;
screenManager()->push(new PromptScreen(gamePath_, di->T("Changing this setting requires PPSSPP to restart."), di->T("Restart"), di->T("Cancel"), [=](bool yes) {
if (yes) {
TriggerRestart("GameSettingsScreen::CustomDriverYes", false, gamePath_);
}
}));
return UI::EVENT_DONE;
}

UI::EventReturn GameSettingsScreen::OnCustomDriverInstall(UI::EventParams &e) {
auto gr = GetI18NCategory(I18NCat::GRAPHICS);
UI::EventReturn DeveloperToolsScreen::OnCustomDriverInstall(UI::EventParams &e) {
auto gr = GetI18NCategory(I18NCat::GRAPHICS);

System_BrowseForFile(gr->T("Install Custom Driver..."), BrowseFileType::ANY, [this](const std::string &value, int) {
const Path driverPath = g_Config.internalDataDirectory / "drivers";
System_BrowseForFile(gr->T("Install Custom Driver..."), BrowseFileType::ANY, [this](const std::string &value, int) {
const Path driverPath = g_Config.internalDataDirectory / "drivers";

if (!value.empty()) {
Path zipPath = Path(value);
if (!value.empty()) {
Path zipPath = Path(value);

if (zipPath.GetFileExtension() == ".zip") {
ZipFileReader *zipFileReader = ZipFileReader::Create(zipPath, "");
bool success = false;

size_t metaDataSize;
uint8_t *metaData = zipFileReader->ReadFile("meta.json", &metaDataSize);
if (zipPath.GetFileExtension() == ".zip") {
ZipFileReader *zipFileReader = ZipFileReader::Create(zipPath, "");

Path tempMeta = Path(g_Config.internalDataDirectory / "meta.json");
size_t metaDataSize;
uint8_t *metaData = zipFileReader->ReadFile("meta.json", &metaDataSize);

File::CreateEmptyFile(tempMeta);
File::WriteDataToFile(false, metaData, metaDataSize, tempMeta);
Path tempMeta = Path(g_Config.internalDataDirectory / "meta.json");

delete[] metaData;
File::CreateEmptyFile(tempMeta);
File::WriteDataToFile(false, metaData, metaDataSize, tempMeta);

json::JsonReader meta = json::JsonReader((g_Config.internalDataDirectory / "meta.json").c_str());
if (meta.ok()) {
std::string driverName = meta.root().get("name")->value.toString();
delete[] metaData;

Path newCustomDriver = driverPath / driverName;
File::CreateFullPath(newCustomDriver);
json::JsonReader meta = json::JsonReader((g_Config.internalDataDirectory / "meta.json").c_str());
if (meta.ok()) {
std::string driverName = meta.root().get("name")->value.toString();

std::vector<File::FileInfo> zipListing;
zipFileReader->GetFileListing("", &zipListing, nullptr);
Path newCustomDriver = driverPath / driverName;
File::CreateFullPath(newCustomDriver);

for (auto file : zipListing) {
File::CreateEmptyFile(newCustomDriver / file.name);
std::vector<File::FileInfo> zipListing;
zipFileReader->GetFileListing("", &zipListing, nullptr);

size_t size;
uint8_t *data = zipFileReader->ReadFile(file.name.c_str(), &size);
File::WriteDataToFile(false, data, size, newCustomDriver / file.name);
for (auto file : zipListing) {
File::CreateEmptyFile(newCustomDriver / file.name);

delete[] data;
}
size_t size;
uint8_t *data = zipFileReader->ReadFile(file.name.c_str(), &size);
File::WriteDataToFile(false, data, size, newCustomDriver / file.name);

File::Delete(tempMeta);
delete[] data;
}

RecreateViews();
}
}
}
});
return UI::EVENT_DONE;
File::Delete(tempMeta);

success = true;

RecreateViews();
}
}
if (!success) {
auto gr = GetI18NCategory(I18NCat::GRAPHICS);
g_OSD.Show(OSDType::MESSAGE_ERROR, gr->T("The file is not a ZIP file containing a compatible driver."));
}
}
});
return UI::EVENT_DONE;
}

UI::EventReturn GameSettingsScreen::OnAutoFrameskip(UI::EventParams &e) {
Expand Down Expand Up @@ -1533,16 +1528,16 @@ void GameSettingsScreen::CallbackMemstickFolder(bool yes) {
}
}

void GameSettingsScreen::TriggerRestart(const char *why) {
static void TriggerRestart(const char *why, bool editThenRestore, const Path &gamePath) {
// Extra save here to make sure the choice really gets saved even if there are shutdown bugs in
// the GPU backend code.
g_Config.Save(why);
std::string param = "--gamesettings";
if (editThenRestore_) {
if (editThenRestore) {
// We won't pass the gameID, so don't resume back into settings.
param.clear();
} else if (!gamePath_.empty()) {
param += " \"" + ReplaceAll(ReplaceAll(gamePath_.ToString(), "\\", "\\\\"), "\"", "\\\"") + "\"";
} else if (!gamePath.empty()) {
param += " \"" + ReplaceAll(ReplaceAll(gamePath.ToString(), "\\", "\\\\"), "\"", "\\\"") + "\"";
}
// Make sure the new instance is considered the first.
ShutdownInstanceCounter();
Expand All @@ -1556,7 +1551,7 @@ UI::EventReturn GameSettingsScreen::OnRenderingBackend(UI::EventParams &e) {
if (g_Config.iGPUBackend != (int)GetGPUBackend()) {
screenManager()->push(new PromptScreen(gamePath_, di->T("Changing this setting requires PPSSPP to restart."), di->T("Restart"), di->T("Cancel"), [=](bool yes) {
if (yes) {
TriggerRestart("GameSettingsScreen::RenderingBackendYes");
TriggerRestart("GameSettingsScreen::RenderingBackendYes", editThenRestore_, gamePath_);
} else {
g_Config.iGPUBackend = (int)GetGPUBackend();
}
Expand All @@ -1575,7 +1570,7 @@ UI::EventReturn GameSettingsScreen::OnRenderingDevice(UI::EventParams &e) {
// If the user ends up deciding not to restart, set the config back to the current backend
// so it doesn't get switched by accident.
if (yes) {
TriggerRestart("GameSettingsScreen::RenderingDeviceYes");
TriggerRestart("GameSettingsScreen::RenderingDeviceYes", editThenRestore_, gamePath_);
} else {
std::string *deviceNameSetting = GPUDeviceNameSetting();
if (deviceNameSetting)
Expand All @@ -1593,7 +1588,7 @@ UI::EventReturn GameSettingsScreen::OnInflightFramesChoice(UI::EventParams &e) {
if (g_Config.iInflightFrames != prevInflightFrames_) {
screenManager()->push(new PromptScreen(gamePath_, di->T("Changing this setting requires PPSSPP to restart."), di->T("Restart"), di->T("Cancel"), [=](bool yes) {
if (yes) {
TriggerRestart("GameSettingsScreen::InflightFramesYes");
TriggerRestart("GameSettingsScreen::InflightFramesYes", editThenRestore_, gamePath_);
} else {
g_Config.iInflightFrames = prevInflightFrames_;
}
Expand Down Expand Up @@ -1807,6 +1802,25 @@ void DeveloperToolsScreen::CreateViews() {
});
}

if (GetGPUBackend() == GPUBackend::VULKAN && SupportsCustomDriver()) {
const Path driverPath = g_Config.internalDataDirectory / "drivers";

std::vector<File::FileInfo> listing;
File::GetFilesInDir(driverPath, &listing);

std::vector<std::string> availableDrivers;
availableDrivers.push_back("Default");

for (auto driver : listing) {
availableDrivers.push_back(driver.name);
}
auto driverChoice = list->Add(new PopupMultiChoiceDynamic(&g_Config.customDriver, gr->T("Current GPU Driver"), availableDrivers, I18NCat::NONE, screenManager()));
driverChoice->OnChoice.Handle(this, &DeveloperToolsScreen::OnCustomDriverChange);

auto customDriverInstallChoice = list->Add(new Choice(gr->T("Install Custom Driver...")));
customDriverInstallChoice->OnClick.Handle(this, &DeveloperToolsScreen::OnCustomDriverInstall);
}

// For now, we only implement GPU driver tests for Vulkan and OpenGL. This is simply
// because the D3D drivers are generally solid enough to not need this type of investigation.
if (g_Config.iGPUBackend == (int)GPUBackend::VULKAN || g_Config.iGPUBackend == (int)GPUBackend::OPENGL) {
Expand Down
6 changes: 2 additions & 4 deletions UI/GameSettingsScreen.h
Expand Up @@ -54,8 +54,6 @@ class GameSettingsScreen : public TabbedUIDialogScreenWithGameBackground {
void CreateSystemSettings(UI::ViewGroup *systemSettings);
void CreateVRSettings(UI::ViewGroup *vrSettings);

void TriggerRestart(const char *why);

std::string gameID_;
UI::CheckBox *enableReportsCheckbox_ = nullptr;
UI::Choice *layoutEditorChoice_ = nullptr;
Expand Down Expand Up @@ -98,8 +96,6 @@ class GameSettingsScreen : public TabbedUIDialogScreenWithGameBackground {
UI::EventReturn OnRenderingBackend(UI::EventParams &e);
UI::EventReturn OnRenderingDevice(UI::EventParams &e);
UI::EventReturn OnInflightFramesChoice(UI::EventParams &e);
UI::EventReturn OnCustomDriverChange(UI::EventParams &e);
UI::EventReturn OnCustomDriverInstall(UI::EventParams &e);
UI::EventReturn OnCameraDeviceChange(UI::EventParams& e);
UI::EventReturn OnMicDeviceChange(UI::EventParams& e);
UI::EventReturn OnAudioDevice(UI::EventParams &e);
Expand Down Expand Up @@ -155,6 +151,8 @@ class DeveloperToolsScreen : public UIDialogScreenWithGameBackground {
UI::EventReturn OnFramedumpTest(UI::EventParams &e);
UI::EventReturn OnTouchscreenTest(UI::EventParams &e);
UI::EventReturn OnCopyStatesToRoot(UI::EventParams &e);
UI::EventReturn OnCustomDriverChange(UI::EventParams &e);
UI::EventReturn OnCustomDriverInstall(UI::EventParams &e);

bool allowDebugger_ = false;
bool canAllowDebugger_ = true;
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ar_AE.ini
Expand Up @@ -674,6 +674,7 @@ Texture Filtering = ‎مفلتر الرسوم
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = ‎تكبير الرسوم
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = ‎لا محدود
Up to 1 = Up to 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/az_AZ.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = Texture filtering
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Texture scaling
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Unlimited
Up to 1 = Up to 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/bg_BG.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = Текстурно филтриране
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Текстурно мащабиране
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Unlimited
Up to 1 = Up to 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/ca_ES.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = Filtrat de textures
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Escalat de textures
Texture Shader = Shader de textura
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Desactivant tessel·lat per maquinari: no suportat.
Unlimited = Il·limitat
Up to 1 = Fins a 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/cz_CZ.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = Filtrování textur
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Změna velikosti textur
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Neomezené
Up to 1 = Up to 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/da_DK.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = Texturfiltrering
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Texturskalering
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Ubegrænset
Up to 1 = Up to 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/de_DE.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = Texturfilterung
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Texturskalierung
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = "Hardware Tessellierung" ausschalten: Nicht unterstützt
Unlimited = Unbegrenzt
Up to 1 = Up to 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/dr_ID.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = Saring i Texture
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Petonggoi Texture
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Unlimited
Up to 1 = Up to 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/en_US.ini
Expand Up @@ -690,6 +690,7 @@ Texture Filtering = Texture filtering
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Texture scaling
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = Unlimited
Up to 1 = Up to 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/es_ES.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = Filtrado de texturas
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Escalado de texturas
Texture Shader = Shader de textura
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Desactivando teselado por hardware: no soportado.
Unlimited = Ilimitado
Up to 1 = Hasta 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/es_LA.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = Filtrado de texturas
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = Escalado de texturas
Texture Shader = Shader de texturas
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Desactivando Teselado por Hardware: no es soportado.
Unlimited = Ilimitado
Up to 1 = Hasta 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fa_IR.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = ‎فیلتر کردن تکسچر
Texture replacement pack activated = Texture replacement pack activated
Texture Scaling = ‎تغییر سایز تکسچر ها
Texture Shader = Texture shader
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Turn off "hardware tessellation": unsupported
Unlimited = ‎نامحدود
Up to 1 = Up to 1
Expand Down
1 change: 1 addition & 0 deletions assets/lang/fi_FI.ini
Expand Up @@ -666,6 +666,7 @@ Texture Filtering = Tekstuurin suodatus
Texture replacement pack activated = Tekstuurin korvauspaketti aktivoidu
Texture Scaling = Tekstuurin skaalaus
Texture Shader = Tekstuurin varjostin
The file is not a ZIP file containing a compatible driver. = The file is not a ZIP file containing a compatible driver.
Turn off Hardware Tessellation - unsupported = Ota pois käytöstä "laitteistotessellaatio": ei tuettu
Unlimited = Rajoittamaton
Up to 1 = Enintään 1
Expand Down

0 comments on commit 88b1943

Please sign in to comment.