Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vulkan: Allow custom texture upscaling shaders #13235

Merged
merged 3 commits into from
Aug 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,7 @@ static ConfigSetting graphicsSettings[] = {
ReportedConfigSetting("SplineBezierQuality", &g_Config.iSplineBezierQuality, 2, true, true),
ReportedConfigSetting("HardwareTessellation", &g_Config.bHardwareTessellation, false, true, true),
ReportedConfigSetting("PostShader", &g_Config.sPostShaderName, "Off", true, true),
ConfigSetting("TextureShader", &g_Config.sTextureShaderName, "Off", true, true),

ReportedConfigSetting("MemBlockTransferGPU", &g_Config.bBlockTransferGPU, true, true, true),
ReportedConfigSetting("DisableSlowFramebufEffects", &g_Config.bDisableSlowFramebufEffects, false, true, true),
Expand Down
1 change: 1 addition & 0 deletions Core/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ struct Config {
int iSplineBezierQuality; // 0 = low , 1 = Intermediate , 2 = High
bool bHardwareTessellation;
std::string sPostShaderName; // Off for off.
std::string sTextureShaderName;
std::map<std::string, float> mPostShaderSetting;
bool bGfxDebugOutput;
bool bGfxDebugSplitSubmit;
Expand Down
47 changes: 43 additions & 4 deletions GPU/Common/PostShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
#include "GPU/Common/PostShader.h"

static std::vector<ShaderInfo> shaderInfo;
// Okay, not really "post" shaders, but related.
static std::vector<TextureShaderInfo> textureShaderInfo;

// Scans the directories for shader ini files and collects info about all the shaders found.
// Additionally, scan the VFS assets. (TODO)

void LoadPostShaderInfo(std::vector<std::string> directories) {
void LoadPostShaderInfo(const std::vector<std::string> &directories) {
std::vector<ShaderInfo> notVisible;

shaderInfo.clear();
Expand All @@ -52,6 +53,12 @@ void LoadPostShaderInfo(std::vector<std::string> directories) {
}
shaderInfo.push_back(off);

textureShaderInfo.clear();
TextureShaderInfo textureOff{};
textureOff.name = "Off";
textureOff.section = "Off";
textureShaderInfo.push_back(textureOff);

auto appendShader = [&](const ShaderInfo &info) {
auto beginErase = std::remove(shaderInfo.begin(), shaderInfo.end(), info.name);
if (beginErase != shaderInfo.end()) {
Expand All @@ -60,12 +67,19 @@ void LoadPostShaderInfo(std::vector<std::string> directories) {
shaderInfo.push_back(info);
};

auto appendTextureShader = [&](const TextureShaderInfo &info) {
auto beginErase = std::remove(textureShaderInfo.begin(), textureShaderInfo.end(), info.name);
if (beginErase != textureShaderInfo.end()) {
textureShaderInfo.erase(beginErase, textureShaderInfo.end());
}
textureShaderInfo.push_back(info);
};

for (size_t d = 0; d < directories.size(); d++) {
std::vector<FileInfo> fileInfo;
getFilesInDir(directories[d].c_str(), &fileInfo, "ini:");

if (fileInfo.size() == 0) {
// TODO: Really gotta fix the filter, now it's gonna open shaders as ini files..
VFSGetFileListing(directories[d].c_str(), &fileInfo, "ini:");
}

Expand All @@ -90,7 +104,10 @@ void LoadPostShaderInfo(std::vector<std::string> directories) {
// Alright, let's loop through the sections and see if any is a shader.
for (size_t i = 0; i < ini.Sections().size(); i++) {
IniFile::Section &section = ini.Sections()[i];
if (section.Exists("Fragment") && section.Exists("Vertex")) {
std::string shaderType;
section.Get("Type", &shaderType, "render");

if (section.Exists("Fragment") && section.Exists("Vertex") && strncasecmp(shaderType.c_str(), "render", shaderType.size()) == 0) {
// Valid shader!
ShaderInfo info;
std::string temp;
Expand Down Expand Up @@ -135,6 +152,16 @@ void LoadPostShaderInfo(std::vector<std::string> directories) {
} else {
notVisible.push_back(info);
}
} else if (section.Exists("Compute") && strncasecmp(shaderType.c_str(), "texture", shaderType.size()) == 0) {
// This is a texture shader.
TextureShaderInfo info;
std::string temp;
info.section = section.name();
section.Get("Name", &info.name, section.name().c_str());
section.Get("Compute", &temp, "");
info.computeShaderFile = path + "/" + temp;

appendTextureShader(info);
}
}
}
Expand Down Expand Up @@ -189,3 +216,15 @@ std::vector<const ShaderInfo *> GetPostShaderChain(const std::string &name) {
const std::vector<ShaderInfo> &GetAllPostShaderInfo() {
return shaderInfo;
}

const TextureShaderInfo *GetTextureShaderInfo(const std::string &name) {
for (auto &info : textureShaderInfo) {
if (info.section == name) {
return &info;
}
}
return nullptr;
}
const std::vector<TextureShaderInfo> &GetAllTextureShaderInfo() {
return textureShaderInfo;
}
18 changes: 18 additions & 0 deletions GPU/Common/PostShader.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,26 @@ struct ShaderInfo {
}
};

struct TextureShaderInfo {
std::string iniFile;
std::string section;
std::string name;

std::string computeShaderFile;

bool operator == (const std::string &other) {
return name == other;
}
bool operator == (const TextureShaderInfo &other) {
return name == other.name;
}
};

void ReloadAllPostShaderInfo();

const ShaderInfo *GetPostShaderInfo(const std::string &name);
std::vector<const ShaderInfo *> GetPostShaderChain(const std::string &name);
const std::vector<ShaderInfo> &GetAllPostShaderInfo();

const TextureShaderInfo *GetTextureShaderInfo(const std::string &name);
const std::vector<TextureShaderInfo> &GetAllTextureShaderInfo();
2 changes: 1 addition & 1 deletion GPU/Common/TextureCacheCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class TextureCacheCommon {

// FramebufferManager keeps TextureCache updated about what regions of memory are being rendered to.
void NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffer, FramebufferNotification msg);
void NotifyConfigChanged();
virtual void NotifyConfigChanged();
void NotifyVideoUpload(u32 addr, int size, int width, GEBufferFormat fmt);

int AttachedDrawingHeight();
Expand Down
Loading