Force postshaders with the usePreviousFrame flag to the end of the order

This commit is contained in:
Henrik Rydgård committed 2022-12-09 17:19:08 +01:00
1 parent 241277e08d
commit 4280a9f51c
4 files changed
+33 -1

No files matched your search

+22
View File
@@ -324,3 +324,25 @@ const TextureShaderInfo *GetTextureShaderInfo(const std::string &name) {
const std::vector<TextureShaderInfo> &GetAllTextureShaderInfo() {
return textureShaderInfo;
}
void FixPostShaderOrder(std::vector<std::string> *names) {
// There's one rule only that we enforce - only one shader can use UsePreviousFrame,
// and it has to be the last one. So we simply remove any we find from the list,
// and then append it to the end if there is one.
std::string prevFrameShader;
for (auto iter = names->begin(); iter != names->end(); ) {
const ShaderInfo *info = GetPostShaderInfo(*iter);
if (info) {
if (info->usePreviousFrame) {
prevFrameShader = *iter;
iter = names->erase(iter++);
continue;
}
}
++iter;
}
if (!prevFrameShader.empty()) {
names->push_back(prevFrameShader);
}
}
+5
View File
@@ -115,3 +115,8 @@ const std::vector<ShaderInfo> &GetAllPostShaderInfo();
const TextureShaderInfo *GetTextureShaderInfo(const std::string &name);
const std::vector<TextureShaderInfo> &GetAllTextureShaderInfo();
void RemoveUnknownPostShaders(std::vector<std::string> *names);
// Call this any time you alter the postshader list. It makes sure
// that "usePrevFrame" shaders are at the end, and that there's only one.
// It'll also enforce any similar future rules.
void FixPostShaderOrder(std::vector<std::string> *names);
+1
View File
@@ -880,6 +880,7 @@ void PresentationCommon::CalculateRenderResolution(int *width, int *height, int
if (!g_Config.vPostShaderNames.empty()) {
ReloadAllPostShaderInfo(draw_);
RemoveUnknownPostShaders(&g_Config.vPostShaderNames);
FixPostShaderOrder(&g_Config.vPostShaderNames);
shaderInfo = GetFullPostShadersChain(g_Config.vPostShaderNames);
}
+5 -1
View File
@@ -152,6 +152,7 @@ void DisplayLayoutScreen::dialogFinished(const Screen *dialog, DialogResult resu
UI::EventReturn DisplayLayoutScreen::OnPostProcShaderChange(UI::EventParams &e) {
// Remove the virtual "Off" entry. TODO: Get rid of it generally.
g_Config.vPostShaderNames.erase(std::remove(g_Config.vPostShaderNames.begin(), g_Config.vPostShaderNames.end(), "Off"), g_Config.vPostShaderNames.end());
FixPostShaderOrder(&g_Config.vPostShaderNames);
NativeMessageReceived("gpu_configChanged", "");
NativeMessageReceived("gpu_renderResized", ""); // To deal with shaders that can change render resolution like upscaling.
@@ -370,7 +371,9 @@ void DisplayLayoutScreen::CreateViews() {
moreButton->OnClick.Add([=](EventParams &e) -> UI::EventReturn {
PopupContextMenuScreen *contextMenu = new UI::PopupContextMenuScreen(postShaderContextMenu, ARRAY_SIZE(postShaderContextMenu), di.get(), moreButton);
screenManager()->push(contextMenu);
contextMenu->SetEnabled(0, i > 0);
const ShaderInfo *info = GetPostShaderInfo(g_Config.vPostShaderNames[i]);
bool usesLastFrame = info ? info->usePreviousFrame : false;
contextMenu->SetEnabled(0, i > 0 && !usesLastFrame);
contextMenu->SetEnabled(1, i < g_Config.vPostShaderNames.size() - 1);
contextMenu->OnChoice.Add([=](EventParams &e) -> UI::EventReturn {
switch (e.a) {
@@ -386,6 +389,7 @@ void DisplayLayoutScreen::CreateViews() {
default:
return UI::EVENT_DONE;
}
FixPostShaderOrder(&g_Config.vPostShaderNames);
NativeMessageReceived("gpu_configChanged", "");
RecreateViews();
return UI::EVENT_DONE;