Skip to content

Commit

Permalink
Merge pull request #16523 from hrydgard/post-shader-cleanup
Browse files Browse the repository at this point in the history
Post shader cleanup
  • Loading branch information
hrydgard committed Dec 8, 2022
2 parents 6ae799d + 2a9d4b5 commit 141e076
Show file tree
Hide file tree
Showing 58 changed files with 245 additions and 352 deletions.
7 changes: 7 additions & 0 deletions Common/UI/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@ struct Margins {
int vert() const {
return top + bottom;
}
void SetAll(float f) {
int8_t i = (int)f;
top = i;
bottom = i;
left = i;
right = i;
}

int8_t top;
int8_t bottom;
Expand Down
44 changes: 23 additions & 21 deletions Common/UI/ViewGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,19 +539,19 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
MeasureSpec v = vert;
if (v.type == UNSPECIFIED && measuredHeight_ != 0.0f)
v = MeasureSpec(AT_MOST, measuredHeight_);
view->Measure(dc, MeasureSpec(UNSPECIFIED, measuredWidth_), v - (float)margins.vert());
if (horiz.type == AT_MOST && view->GetMeasuredWidth() + margins.horiz() > horiz.size - weightZeroSum) {
view->Measure(dc, MeasureSpec(UNSPECIFIED, measuredWidth_), v - (float)margins.vert() - (float)padding.vert());
if (horiz.type == AT_MOST && view->GetMeasuredWidth() + margins.horiz() + padding.horiz() > horiz.size - weightZeroSum) {
// Try again, this time with AT_MOST.
view->Measure(dc, horiz, v - (float)margins.vert());
view->Measure(dc, horiz, v - (float)margins.vert() - (float)padding.vert());
}
} else if (orientation_ == ORIENT_VERTICAL) {
MeasureSpec h = horiz;
if (h.type == UNSPECIFIED && measuredWidth_ != 0.0f)
h = MeasureSpec(AT_MOST, measuredWidth_);
view->Measure(dc, h - (float)margins.horiz(), MeasureSpec(UNSPECIFIED, measuredHeight_));
if (vert.type == AT_MOST && view->GetMeasuredHeight() + margins.vert() > vert.size - weightZeroSum) {
view->Measure(dc, h - (float)margins.horiz() - (float)padding.horiz(), MeasureSpec(UNSPECIFIED, measuredHeight_));
if (vert.type == AT_MOST && view->GetMeasuredHeight() + margins.vert() + padding.horiz() > vert.size - weightZeroSum) {
// Try again, this time with AT_MOST.
view->Measure(dc, h - (float)margins.horiz(), vert);
view->Measure(dc, h - (float)margins.horiz() - (float)padding.horiz(), vert);
}
}

Expand All @@ -575,20 +575,20 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
}
}

weightZeroSum += spacing_ * (numVisible - 1);
weightZeroSum += spacing_ * (numVisible - 1); // +(orientation_ == ORIENT_HORIZONTAL) ? padding.horiz() : padding.vert();

// Alright, got the sum. Let's take the remaining space after the fixed-size views,
// and distribute among the weighted ones.
if (orientation_ == ORIENT_HORIZONTAL) {
MeasureBySpec(layoutParams_->width, weightZeroSum, horiz, &measuredWidth_);
MeasureBySpec(layoutParams_->width, weightZeroSum + padding.horiz(), horiz, &measuredWidth_);

// If we've got stretch, allow growing to fill the parent.
float allowedWidth = measuredWidth_;
if (horiz.type == AT_MOST && measuredWidth_ < horiz.size) {
allowedWidth = horiz.size;
}

float usedWidth = 0.0f;
float usedWidth = 0.0f + padding.horiz();

// Redistribute the stretchy ones! and remeasure the children!
for (View *view : views_) {
Expand All @@ -615,7 +615,7 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
if (horiz.type == EXACTLY) {
h.type = EXACTLY;
}
view->Measure(dc, h, v - (float)margins.vert());
view->Measure(dc, h, v - (float)margins.vert() - (float)padding.vert());
usedWidth += view->GetMeasuredWidth();
maxOther = std::max(maxOther, view->GetMeasuredHeight() + margins.vert());
}
Expand All @@ -626,17 +626,17 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
}

// Measure here in case maxOther moved (can happen due to word wrap.)
MeasureBySpec(layoutParams_->height, maxOther, vert, &measuredHeight_);
MeasureBySpec(layoutParams_->height, maxOther + padding.vert(), vert, &measuredHeight_);
} else {
MeasureBySpec(layoutParams_->height, weightZeroSum, vert, &measuredHeight_);
MeasureBySpec(layoutParams_->height, weightZeroSum + padding.vert(), vert, &measuredHeight_);

// If we've got stretch, allow growing to fill the parent.
float allowedHeight = measuredHeight_;
if (vert.type == AT_MOST && measuredHeight_ < vert.size) {
allowedHeight = vert.size;
}

float usedHeight = 0.0f;
float usedHeight = 0.0f + padding.vert();

// Redistribute the stretchy ones! and remeasure the children!
for (View *view : views_) {
Expand All @@ -663,7 +663,7 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
if (vert.type == EXACTLY) {
v.type = EXACTLY;
}
view->Measure(dc, h - (float)margins.horiz(), v);
view->Measure(dc, h - (float)margins.horiz() - (float)padding.horiz(), v);
usedHeight += view->GetMeasuredHeight();
maxOther = std::max(maxOther, view->GetMeasuredWidth() + margins.horiz());
}
Expand All @@ -674,7 +674,7 @@ void LinearLayout::Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec v
}

// Measure here in case maxOther moved (can happen due to word wrap.)
MeasureBySpec(layoutParams_->width, maxOther, horiz, &measuredWidth_);
MeasureBySpec(layoutParams_->width, maxOther + padding.horiz(), horiz, &measuredWidth_);
}
}

Expand All @@ -686,13 +686,13 @@ void LinearLayout::Layout() {
float pos;

if (orientation_ == ORIENT_HORIZONTAL) {
pos = bounds.x;
itemBounds.y = bounds.y;
itemBounds.h = measuredHeight_;
pos = bounds.x + padding.left;
itemBounds.y = bounds.y + padding.top;
itemBounds.h = measuredHeight_ - padding.vert();
} else {
pos = bounds.y;
itemBounds.x = bounds.x;
itemBounds.w = measuredWidth_;
pos = bounds.y + padding.top;
itemBounds.x = bounds.x + padding.left;
itemBounds.w = measuredWidth_ - padding.horiz();
}

for (size_t i = 0; i < views_.size(); i++) {
Expand Down Expand Up @@ -928,6 +928,8 @@ void ScrollView::Draw(UIContext &dc) {
}

dc.PushScissor(bounds_);
dc.FillRect(bg_, bounds_);

// For debugging layout issues, this can be useful.
// dc.FillRect(Drawable(0x60FF00FF), bounds_);
views_[0]->Draw(dc);
Expand Down
2 changes: 2 additions & 0 deletions Common/UI/ViewGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class ViewGroup : public View {
// It simply centers the child view.
class FrameLayout : public ViewGroup {
public:
FrameLayout(LayoutParams *layoutParams = nullptr) : ViewGroup(layoutParams) {}
void Measure(const UIContext &dc, MeasureSpec horiz, MeasureSpec vert) override;
void Layout() override;
};
Expand Down Expand Up @@ -193,6 +194,7 @@ class LinearLayout : public ViewGroup {
spacing_ = spacing;
}
std::string DescribeLog() const override { return (orientation_ == ORIENT_HORIZONTAL ? "LinearLayoutHoriz: " : "LinearLayoutVert: ") + View::DescribeLog(); }
Margins padding;

protected:
Orientation orientation_;
Expand Down
10 changes: 10 additions & 0 deletions GPU/Common/PostShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,16 @@ void ReloadAllPostShaderInfo(Draw::DrawContext *draw) {
LoadPostShaderInfo(draw, directories);
}

void RemoveUnknownPostShaders(std::vector<std::string> *names) {
for (auto iter = names->begin(); iter != names->end(); ) {
if (GetPostShaderInfo(*iter) == nullptr) {
iter = names->erase(iter);
} else {
++iter;
}
}
}

const ShaderInfo *GetPostShaderInfo(const std::string &name) {
for (size_t i = 0; i < shaderInfo.size(); i++) {
if (shaderInfo[i].section == name)
Expand Down
1 change: 1 addition & 0 deletions GPU/Common/PostShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,4 @@ const std::vector<ShaderInfo> &GetAllPostShaderInfo();

const TextureShaderInfo *GetTextureShaderInfo(const std::string &name);
const std::vector<TextureShaderInfo> &GetAllTextureShaderInfo();
void RemoveUnknownPostShaders(std::vector<std::string> *names);
1 change: 1 addition & 0 deletions GPU/Common/PresentationCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@ void PresentationCommon::CalculateRenderResolution(int *width, int *height, int
std::vector<const ShaderInfo *> shaderInfo;
if (!g_Config.vPostShaderNames.empty()) {
ReloadAllPostShaderInfo(draw_);
RemoveUnknownPostShaders(&g_Config.vPostShaderNames);
shaderInfo = GetFullPostShadersChain(g_Config.vPostShaderNames);
}

Expand Down
23 changes: 18 additions & 5 deletions UI/DisplayLayoutScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,21 +203,28 @@ void DisplayLayoutScreen::CreateViews() {
// impossible.
root_->SetExclusiveTouch(true);

ScrollView *leftScrollView = new ScrollView(ORIENT_VERTICAL, new AnchorLayoutParams(400.0f, FILL_PARENT, 10.f, 10.f, NONE, 10.f, false));
ViewGroup *leftColumn = new LinearLayout(ORIENT_VERTICAL);
ScrollView *leftScrollView = new ScrollView(ORIENT_VERTICAL, new AnchorLayoutParams(420.0f, FILL_PARENT, 0.f, 0.f, NONE, 0.f, false));
LinearLayout *leftColumn = new LinearLayout(ORIENT_VERTICAL);
leftColumn->padding.SetAll(8.0f);
leftScrollView->Add(leftColumn);
leftScrollView->SetClickableBackground(true);
root_->Add(leftScrollView);

ScrollView *rightScrollView = new ScrollView(ORIENT_VERTICAL, new AnchorLayoutParams(300.0f, FILL_PARENT, NONE, 10.f, 10.f, 10.f, false));
ViewGroup *rightColumn = new LinearLayout(ORIENT_VERTICAL);
ScrollView *rightScrollView = new ScrollView(ORIENT_VERTICAL, new AnchorLayoutParams(300.0f, FILL_PARENT, NONE, 0.f, 0.f, 0.f, false));
LinearLayout *rightColumn = new LinearLayout(ORIENT_VERTICAL);
rightColumn->padding.SetAll(8.0f);
rightScrollView->Add(rightColumn);
rightScrollView->SetClickableBackground(true);
root_->Add(rightScrollView);

LinearLayout *bottomControls = new LinearLayout(ORIENT_HORIZONTAL, new AnchorLayoutParams(NONE, NONE, NONE, 10.0f, false));
root_->Add(bottomControls);

// Set backgrounds for readability
Drawable backgroundWithAlpha(GetBackgroundColorWithAlpha(*screenManager()->getUIContext()));
leftColumn->SetBG(backgroundWithAlpha);
rightColumn->SetBG(backgroundWithAlpha);

if (!IsVREnabled()) {
auto stretch = new CheckBox(&g_Config.bDisplayStretch, gr->T("Stretch"));
rightColumn->Add(stretch);
Expand Down Expand Up @@ -273,7 +280,13 @@ void DisplayLayoutScreen::CreateViews() {
leftColumn->Add(new ItemHeader(gr->T("Postprocessing shaders")));

std::set<std::string> alreadyAddedShader;
settingsVisible_.resize(g_Config.vPostShaderNames.size());
// If there's a single post shader and we're just entering the dialog,
// auto-open the settings.
if (settingsVisible_.empty() && g_Config.vPostShaderNames.size() == 1) {
settingsVisible_.push_back(true);
} else if (settingsVisible_.size() < g_Config.vPostShaderNames.size()) {
settingsVisible_.resize(g_Config.vPostShaderNames.size());
}

static ContextMenuItem postShaderContextMenu[] = {
{ "Move Up", "I_ARROW_UP" },
Expand Down
6 changes: 5 additions & 1 deletion UI/MiscScreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ void DrawBackground(UIContext &dc, float alpha, float x, float y, float z) {
}
}

uint32_t GetBackgroundColorWithAlpha(UIContext &dc) {
return colorAlpha(colorBlend(dc.GetTheme().backgroundColor, 0, 0.5f), 0.65f); // 0.65 = 166 = A6
}

void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, float z, bool darkenBackground) {
using namespace Draw;
using namespace UI;
Expand All @@ -379,7 +383,7 @@ void DrawGameBackground(UIContext &dc, const Path &gamePath, float x, float y, f
dc.Begin();

if (darkenBackground) {
uint32_t color = colorAlpha(colorBlend(dc.GetTheme().backgroundColor, 0, 0.5f), 0.65f);
uint32_t color = GetBackgroundColorWithAlpha(dc);
dc.FillRect(UI::Drawable(color), dc.GetBounds());
dc.Flush();
}
Expand Down
2 changes: 2 additions & 0 deletions UI/MiscScreens.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,5 @@ class SettingInfoMessage : public UI::LinearLayout {
float cutOffY_;
bool showing_ = false;
};

uint32_t GetBackgroundColorWithAlpha(UIContext &dc);
30 changes: 1 addition & 29 deletions UWP/UWP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1597,34 +1597,6 @@
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
</None>
<None Include="Content\shaders\grayscale.fsh">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='UWP Gold|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='UWP Gold|Win32'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='UWP Gold|ARM64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='UWP Gold|ARM'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
</None>
<None Include="Content\shaders\inversecolors.fsh">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='UWP Gold|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='UWP Gold|Win32'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='UWP Gold|ARM64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='UWP Gold|ARM'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</DeploymentContent>
</None>
<None Include="Content\shaders\natural.fsh">
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='UWP Gold|x64'">true</DeploymentContent>
<DeploymentContent Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</DeploymentContent>
Expand Down Expand Up @@ -1774,4 +1746,4 @@
<Import Project="$(VSINSTALLDIR)\Common7\IDE\Extensions\Microsoft\VsGraphics\MeshContentTask.targets" />
<Import Project="$(VSINSTALLDIR)\Common7\IDE\Extensions\Microsoft\VsGraphics\ShaderGraphContentTask.targets" />
</ImportGroup>
</Project>
</Project>
8 changes: 1 addition & 7 deletions UWP/UWP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,6 @@
<None Include="Content\shaders\GaussianDownscale.fsh">
<Filter>Content\shaders</Filter>
</None>
<None Include="Content\shaders\grayscale.fsh">
<Filter>Content\shaders</Filter>
</None>
<None Include="Content\shaders\inversecolors.fsh">
<Filter>Content\shaders</Filter>
</None>
<None Include="Content\flash0\font\jpn0.pgf">
<Filter>Content\flash0\font</Filter>
</None>
Expand Down Expand Up @@ -377,4 +371,4 @@
<Filter>Content</Filter>
</Font>
</ItemGroup>
</Project>
</Project>
10 changes: 4 additions & 6 deletions assets/lang/ar_AE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -831,9 +831,9 @@ Undo last save = Undo last save

[PostShaders]
(duplicated setting, previous slider will be used) = (duplicated setting, previous slider will be used)
4xHqGLSL = 4×HQ GLSL
5xBR = 5xBR
5xBR-lv2 = 5xBR-lv2
4xHqGLSL = 4xHQ pixel art upscaler
5xBR = 5xBR pixel art upscaler
5xBR-lv2 = 5xBR-lv2 pixel art upscaler
AAColor = ‎AA-لون
Amount = Amount
Animation speed (0 -> disable) = Animation speed (0 -> disable)
Expand All @@ -848,10 +848,8 @@ Contrast = Contrast
CRT = ‎CRT خطوط الفحص
FXAA = ‎FXAA منعم الحواف
Gamma = Gamma
Grayscale = ‎التدرج الرمادي
GreenLevel = GreenLevel
GreenLevel = Green level
Intensity = Intensity
InverseColors = ‎عكس الألوان
MitchellNetravali = Bicubic (Mitchell-Netravali) Upscaler
Natural = ‎الألوان الحقيقية
NaturalA = Natural Colors (no blur)
Expand Down
10 changes: 4 additions & 6 deletions assets/lang/az_AZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,9 @@ Undo last save = Undo last save

[PostShaders]
(duplicated setting, previous slider will be used) = (duplicated setting, previous slider will be used)
4xHqGLSL = 4×HQ GLSL
5xBR = 5xBR
5xBR-lv2 = 5xBR-lv2
4xHqGLSL = 4xHQ pixel art upscaler
5xBR = 5xBR pixel art upscaler
5xBR-lv2 = 5xBR-lv2 pixel art upscaler
AAColor = AA-Color
Amount = Amount
Animation speed (0 -> disable) = Animation speed (0 -> disable)
Expand All @@ -840,10 +840,8 @@ Contrast = Contrast
CRT = CRT scanlines
FXAA = FXAA Antialiasing
Gamma = Gamma
Grayscale = Grayscale
GreenLevel = GreenLevel
GreenLevel = Green level
Intensity = Intensity
InverseColors = Inverse Colors
MitchellNetravali = Bicubic (Mitchell-Netravali) Upscaler
Natural = Natural Colors
NaturalA = Natural Colors (no blur)
Expand Down
10 changes: 4 additions & 6 deletions assets/lang/bg_BG.ini
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,9 @@ Undo last save = Undo last save
[PostShaders]
(duplicated setting, previous slider will be used) = (duplicated setting, previous slider will be used)
4xHqGLSL = 4×HQ GLSL
5xBR = 5xBR
5xBR-lv2 = 5xBR-lv2
4xHqGLSL = 4xHQ pixel art upscaler
5xBR = 5xBR pixel art upscaler
5xBR-lv2 = 5xBR-lv2 pixel art upscaler
AAColor = AA-Color
Amount = Amount
Animation speed (0 -> disable) = Animation speed (0 -> disable)
Expand All @@ -840,10 +840,8 @@ Contrast = Contrast
CRT = CRT scanlines
FXAA = FXAA Antialiasing
Gamma = Gamma
Grayscale = Сива скала
GreenLevel = GreenLevel
GreenLevel = Green level
Intensity = Intensity
InverseColors = Противоположни цветове
MitchellNetravali = Bicubic (Mitchell-Netravali) Upscaler
Natural = Natural Colors
NaturalA = Natural Colors (no blur)
Expand Down
Loading

0 comments on commit 141e076

Please sign in to comment.