Skip to content

Commit

Permalink
User chain support
Browse files Browse the repository at this point in the history
  • Loading branch information
iota97 committed May 18, 2020
1 parent e29d79a commit 20bdc84
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 44 deletions.
40 changes: 39 additions & 1 deletion Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,6 @@ static ConfigSetting graphicsSettings[] = {
// Not really a graphics setting...
ReportedConfigSetting("SplineBezierQuality", &g_Config.iSplineBezierQuality, 2, true, true),
ReportedConfigSetting("HardwareTessellation", &g_Config.bHardwareTessellation, false, true, true),
ReportedConfigSetting("PostShader", &g_Config.sPostShaderName, "Off", true, true),

ReportedConfigSetting("MemBlockTransferGPU", &g_Config.bBlockTransferGPU, true, true, true),
ReportedConfigSetting("DisableSlowFramebufEffects", &g_Config.bDisableSlowFramebufEffects, false, true, true),
Expand Down Expand Up @@ -1201,6 +1200,14 @@ void Config::Load(const char *iniFileName, const char *controllerIniFilename) {
mPostShaderSetting[it.first] = std::stof(it.second);
}

auto postShaderChain = iniFile.GetOrCreateSection("PostShaderList")->ToMap();
vPostShaderNames.clear();
for (auto it = postShaderChain.begin(), end = postShaderChain.end(); it != end; ++it) {
vPostShaderNames.push_back(it->second); // Push by order not number
}
if (vPostShaderNames.empty())
vPostShaderNames.push_back("Off");

// This caps the exponent 4 (so 16x.)
if (iAnisotropyLevel > 4) {
iAnisotropyLevel = 4;
Expand Down Expand Up @@ -1318,6 +1325,13 @@ void Config::Save(const char *saveReason) {
for (auto it = mPostShaderSetting.begin(), end = mPostShaderSetting.end(); it != end; ++it) {
postShaderSetting->Set(it->first.c_str(), it->second);
}
IniFile::Section *postShaderChain = iniFile.GetOrCreateSection("PostShaderList");
postShaderChain->Clear();
for (size_t i = 0; i < vPostShaderNames.size(); ++i) {
char keyName[64];
snprintf(keyName, sizeof(keyName), "PostShader%d", (int)i+1);
postShaderChain->Set(keyName, vPostShaderNames[i]);
}
}

IniFile::Section *control = iniFile.GetOrCreateSection("Control");
Expand Down Expand Up @@ -1576,6 +1590,14 @@ bool Config::saveGameConfig(const std::string &pGameId, const std::string &title
postShaderSetting->Set(it->first.c_str(), it->second);
}

IniFile::Section *postShaderChain = iniFile.GetOrCreateSection("PostShaderList");
postShaderChain->Clear();
for (size_t i = 0; i < vPostShaderNames.size(); ++i) {
char keyName[64];
snprintf(keyName, sizeof(keyName), "PostShader%d", (int)i+1);
postShaderChain->Set(keyName, vPostShaderNames[i]);
}

KeyMap::SaveToIni(iniFile);
iniFile.Save(fullIniFilePath);

Expand All @@ -1600,6 +1622,14 @@ bool Config::loadGameConfig(const std::string &pGameId, const std::string &title
mPostShaderSetting[it.first] = std::stof(it.second);
}

auto postShaderChain = iniFile.GetOrCreateSection("PostShaderList")->ToMap();
vPostShaderNames.clear();
for (auto it = postShaderChain.begin(), end = postShaderChain.end(); it != end; ++it) {
vPostShaderNames.push_back(it->second); // Push by order not number
}
if (vPostShaderNames.empty())
vPostShaderNames.push_back("Off");

IterateSettings(iniFile, [](IniFile::Section *section, ConfigSetting *setting) {
if (setting->perGame_) {
setting->Get(section);
Expand Down Expand Up @@ -1630,6 +1660,14 @@ void Config::unloadGameConfig() {
mPostShaderSetting[it.first] = std::stof(it.second);
}

auto postShaderChain = iniFile.GetOrCreateSection("PostShaderList")->ToMap();
vPostShaderNames.clear();
for (auto it = postShaderChain.begin(), end = postShaderChain.end(); it != end; ++it) {
vPostShaderNames.push_back(it->second); // Push by order not number
}
if (vPostShaderNames.empty())
vPostShaderNames.push_back("Off");

LoadStandardControllerIni();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ struct Config {
bool bFragmentTestCache;
int iSplineBezierQuality; // 0 = low , 1 = Intermediate , 2 = High
bool bHardwareTessellation;
std::string sPostShaderName; // Off for off.
std::vector<std::string> vPostShaderNames; // Off for off or chain end.
std::map<std::string, float> mPostShaderSetting;
bool bGfxDebugOutput;
bool bGfxDebugSplitSubmit;
Expand Down
7 changes: 1 addition & 6 deletions Core/HLE/sceDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -752,15 +752,10 @@ void __DisplayFlip(int cyclesLate) {
// But, let's flip at least once every 10 vblanks, to update fps, etc.
const bool noRecentFlip = g_Config.iRenderingMode != FB_NON_BUFFERED_MODE && numVBlanksSinceFlip >= 10;
// Also let's always flip for animated shaders.
const ShaderInfo *shaderInfo = g_Config.sPostShaderName == "Off" ? nullptr : GetPostShaderInfo(g_Config.sPostShaderName);
bool postEffectRequiresFlip = false;
// postEffectRequiresFlip is not compatible with frameskip unthrottling, see #12325.
if (g_Config.iRenderingMode != FB_NON_BUFFERED_MODE && !(g_Config.bFrameSkipUnthrottle && !FrameTimingThrottled())) {
if (shaderInfo) {
postEffectRequiresFlip = (shaderInfo->requires60fps || g_Config.bRenderDuplicateFrames);
} else {
postEffectRequiresFlip = g_Config.bRenderDuplicateFrames;
}
postEffectRequiresFlip = g_Config.bRenderDuplicateFrames || PostShaderChainRequires60FPS(GetFullPostShadersChain(g_Config.vPostShaderNames));
}

const bool fbDirty = gpu->FramebufferDirty();
Expand Down
19 changes: 19 additions & 0 deletions GPU/Common/PostShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,25 @@ std::vector<const ShaderInfo *> GetPostShaderChain(const std::string &name) {
return backwards;
}

std::vector<const ShaderInfo *> GetFullPostShadersChain(const std::vector<std::string> &names) {
std::vector<const ShaderInfo *> fullChain;
for (int i = 0; i < names.size(); ++i) {
if (names[i] == "Off")
break;
auto shaderChain = GetPostShaderChain(names[i]);
fullChain.insert(fullChain.end(), shaderChain.begin(), shaderChain.end());
}
return fullChain;
}

bool PostShaderChainRequires60FPS(const std::vector<const ShaderInfo *> &chain) {
for (auto shaderInfo : chain) {
if (shaderInfo->requires60fps)
return true;
}
return false;
}

const std::vector<ShaderInfo> &GetAllPostShaderInfo() {
return shaderInfo;
}
2 changes: 2 additions & 0 deletions GPU/Common/PostShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,6 @@ void ReloadAllPostShaderInfo();

const ShaderInfo *GetPostShaderInfo(const std::string &name);
std::vector<const ShaderInfo *> GetPostShaderChain(const std::string &name);
std::vector<const ShaderInfo *> GetFullPostShadersChain(const std::vector<std::string> &names);
bool PostShaderChainRequires60FPS(const std::vector<const ShaderInfo *> &chain);
const std::vector<ShaderInfo> &GetAllPostShaderInfo();
8 changes: 4 additions & 4 deletions GPU/Common/PresentationCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ static std::string ReadShaderSrc(const std::string &filename) {
// Note: called on resize and settings changes.
bool PresentationCommon::UpdatePostShader() {
std::vector<const ShaderInfo *> shaderInfo;
if (g_Config.sPostShaderName != "Off") {
if (g_Config.vPostShaderNames[0] != "Off") {
ReloadAllPostShaderInfo();
shaderInfo = GetPostShaderChain(g_Config.sPostShaderName);
shaderInfo = GetFullPostShadersChain(g_Config.vPostShaderNames);
}

DestroyPostShader();
Expand Down Expand Up @@ -685,9 +685,9 @@ void PresentationCommon::CopyToOutput(OutputFlags flags, int uvRotation, float u
void PresentationCommon::CalculateRenderResolution(int *width, int *height, bool *upscaling, bool *ssaa) {
// Check if postprocessing shader is doing upscaling as it requires native resolution
std::vector<const ShaderInfo *> shaderInfo;
if (g_Config.sPostShaderName != "Off") {
if (g_Config.vPostShaderNames[0] != "Off") {
ReloadAllPostShaderInfo();
shaderInfo = GetPostShaderChain(g_Config.sPostShaderName);
shaderInfo = GetFullPostShadersChain(g_Config.vPostShaderNames);
}

bool firstIsUpscalingFilter = shaderInfo.empty() ? false : shaderInfo.front()->isUpscalingFilter;
Expand Down
55 changes: 31 additions & 24 deletions UI/GameSettingsScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,24 +283,39 @@ void GameSettingsScreen::CreateViews() {
altSpeed2->SetZeroLabel(gr->T("Unlimited"));
altSpeed2->SetNegativeDisable(gr->T("Disabled"));

graphicsSettings->Add(new ItemHeader(gr->T("Features")));
postProcChoice_ = graphicsSettings->Add(new ChoiceWithValueDisplay(&g_Config.sPostShaderName, gr->T("Postprocessing Shader"), &PostShaderTranslateName));
postProcChoice_->OnClick.Handle(this, &GameSettingsScreen::OnPostProcShader);
postProcChoice_->SetEnabledFunc([] {
return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
});
graphicsSettings->Add(new ItemHeader(gr->T("Postprocessing effect")));

for (int i = 0; i < g_Config.vPostShaderNames.size(); ++i) {
postProcChoice_ = graphicsSettings->Add(new ChoiceWithValueDisplay(&g_Config.vPostShaderNames[i], StringFromFormat("%s #%d", gr->T("Postprocessing Shader"), i + 1), &PostShaderTranslateName));
postProcChoice_->OnClick.Add([=](EventParams &e) {
auto gr = GetI18NCategory("Graphics");
auto procScreen = new PostProcScreen(gr->T("Postprocessing Shader"), i);
procScreen->OnChoice.Handle(this, &GameSettingsScreen::OnPostProcShaderChange);
if (e.v)
procScreen->SetPopupOrigin(e.v);
screenManager()->push(procScreen);
return UI::EVENT_DONE;
});
postProcChoice_->SetEnabledFunc([] {
return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
});

auto shaderChain = GetPostShaderChain(g_Config.sPostShaderName);
for (auto shaderInfo : shaderChain) {
for (size_t i = 0; i < ARRAY_SIZE(shaderInfo->settings); ++i) {
auto &setting = shaderInfo->settings[i];
if (!setting.name.empty()) {
auto &value = g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderInfo->section.c_str(), i + 1)];
graphicsSettings->Add(new PopupSliderChoiceFloat(&value, setting.minValue, setting.maxValue, ps->T(setting.name), setting.step, screenManager()));
auto shaderChain = GetPostShaderChain(g_Config.vPostShaderNames[i]);
for (auto shaderInfo : shaderChain) {
for (size_t i = 0; i < ARRAY_SIZE(shaderInfo->settings); ++i) {
auto &setting = shaderInfo->settings[i];
if (!setting.name.empty()) {
auto &value = g_Config.mPostShaderSetting[StringFromFormat("%sSettingValue%d", shaderInfo->section.c_str(), i + 1)];
PopupSliderChoiceFloat *settingValue = graphicsSettings->Add(new PopupSliderChoiceFloat(&value, setting.minValue, setting.maxValue, ps->T(setting.name), setting.step, screenManager()));
settingValue->SetEnabledFunc([] {
return g_Config.iRenderingMode != FB_NON_BUFFERED_MODE;
});
}
}
}
}

graphicsSettings->Add(new ItemHeader(gr->T("Screen layout")));
#if !defined(MOBILE_DEVICE)
graphicsSettings->Add(new CheckBox(&g_Config.bFullScreen, gr->T("FullScreen", "Full Screen")))->OnClick.Handle(this, &GameSettingsScreen::OnFullscreenChange);
if (System_GetPropertyInt(SYSPROP_DISPLAY_COUNT) > 1) {
Expand Down Expand Up @@ -1408,19 +1423,11 @@ UI::EventReturn GameSettingsScreen::OnLanguageChange(UI::EventParams &e) {
return UI::EVENT_DONE;
}

UI::EventReturn GameSettingsScreen::OnPostProcShader(UI::EventParams &e) {
auto gr = GetI18NCategory("Graphics");
auto procScreen = new PostProcScreen(gr->T("Postprocessing Shader"));
procScreen->OnChoice.Handle(this, &GameSettingsScreen::OnPostProcShaderChange);
if (e.v)
procScreen->SetPopupOrigin(e.v);
screenManager()->push(procScreen);
return UI::EVENT_DONE;
}

UI::EventReturn GameSettingsScreen::OnPostProcShaderChange(UI::EventParams &e) {
NativeMessageReceived("gpu_resized", "");
RecreateViews(); // Update setting name
g_Config.vPostShaderNames.erase(std::remove(g_Config.vPostShaderNames.begin(), g_Config.vPostShaderNames.end(), "Off"), g_Config.vPostShaderNames.end());
g_Config.vPostShaderNames.push_back("Off");
RecreateViews();
return UI::EVENT_DONE;
}

Expand Down
1 change: 0 additions & 1 deletion UI/GameSettingsScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class GameSettingsScreen : public UIDialogScreenWithGameBackground {
UI::EventReturn OnLanguage(UI::EventParams &e);
UI::EventReturn OnLanguageChange(UI::EventParams &e);
UI::EventReturn OnAutoFrameskip(UI::EventParams &e);
UI::EventReturn OnPostProcShader(UI::EventParams &e);
UI::EventReturn OnPostProcShaderChange(UI::EventParams &e);
UI::EventReturn OnDeveloperTools(UI::EventParams &e);
UI::EventReturn OnRemoteISO(UI::EventParams &e);
Expand Down
6 changes: 3 additions & 3 deletions UI/MiscScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void PromptScreen::TriggerFinish(DialogResult result) {
UIDialogScreenWithBackground::TriggerFinish(result);
}

PostProcScreen::PostProcScreen(const std::string &title) : ListPopupScreen(title) {
PostProcScreen::PostProcScreen(const std::string &title, int id) : ListPopupScreen(title), id_(id) {
auto ps = GetI18NCategory("PostShaders");
ReloadAllPostShaderInfo();
shaders_ = GetAllPostShaderInfo();
Expand All @@ -308,7 +308,7 @@ PostProcScreen::PostProcScreen(const std::string &title) : ListPopupScreen(title
for (int i = 0; i < (int)shaders_.size(); i++) {
if (!shaders_[i].visible)
continue;
if (shaders_[i].section == g_Config.sPostShaderName)
if (shaders_[i].section == g_Config.vPostShaderNames[id_])
selected = i;
items.push_back(ps->T(shaders_[i].section.c_str(), shaders_[i].name.c_str()));
}
Expand All @@ -318,7 +318,7 @@ PostProcScreen::PostProcScreen(const std::string &title) : ListPopupScreen(title
void PostProcScreen::OnCompleted(DialogResult result) {
if (result != DR_OK)
return;
g_Config.sPostShaderName = shaders_[listView_->GetSelected()].section;
g_Config.vPostShaderNames[id_] = shaders_[listView_->GetSelected()].section;
}

NewLanguageScreen::NewLanguageScreen(const std::string &title) : ListPopupScreen(title) {
Expand Down
3 changes: 2 additions & 1 deletion UI/MiscScreens.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@ class NewLanguageScreen : public ListPopupScreen {

class PostProcScreen : public ListPopupScreen {
public:
PostProcScreen(const std::string &title);
PostProcScreen(const std::string &title, int id);

private:
void OnCompleted(DialogResult result) override;
bool ShowButtons() const override { return true; }
std::vector<ShaderInfo> shaders_;
int id_;
};

class LogoScreen : public UIScreen {
Expand Down
6 changes: 3 additions & 3 deletions Windows/MainWindowMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ namespace MainWindow {
int item = ID_SHADERS_BASE + 1;

for (size_t i = 0; i < availableShaders.size(); i++)
CheckMenuItem(menu, item++, ((g_Config.sPostShaderName == availableShaders[i]) ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(menu, item++, ((g_Config.vPostShaderNames[0] == availableShaders[i]) ? MF_CHECKED : MF_UNCHECKED));
}

bool CreateShadersSubmenu(HMENU menu) {
Expand Down Expand Up @@ -185,7 +185,7 @@ namespace MainWindow {
continue;
int checkedStatus = MF_UNCHECKED;
availableShaders.push_back(i->section);
if (g_Config.sPostShaderName == i->section) {
if (g_Config.vPostShaderNames[0] == i->section) {
checkedStatus = MF_CHECKED;
}

Expand Down Expand Up @@ -1056,7 +1056,7 @@ namespace MainWindow {
// ID_SHADERS_BASE and an additional 1 off it.
u32 index = (wParam - ID_SHADERS_BASE - 1);
if (index < availableShaders.size()) {
g_Config.sPostShaderName = availableShaders[index];
g_Config.vPostShaderNames[0] = availableShaders[index];

NativeMessageReceived("gpu_resized", "");
break;
Expand Down

0 comments on commit 20bdc84

Please sign in to comment.