GPU: Alternate FBOs for chained postshaders.

If you apply 4 in a row at the same resolution, we only need two actual
FBOs.  This will use less VRAM.
This commit is contained in:
Unknown W. Brackets committed 2020-05-17 09:26:15 -07:00
1 parent 49db27b6d3
commit 230fe82ee6
2 files changed
+35 -4

No files matched your search

+27 -4
View File
@@ -258,13 +258,10 @@ bool PresentationCommon::BuildPostShader(const ShaderInfo *shaderInfo, const Sha
nextHeight = (int)h;
}
// No depth/stencil for post processing
Draw::Framebuffer *fbo = draw_->CreateFramebuffer({ nextWidth, nextHeight, 1, 1, false, Draw::FBO_8888 });
if (!fbo) {
if (!AllocateFramebuffer(nextWidth, nextHeight)) {
pipeline->Release();
return false;
}
postShaderFramebuffers_.push_back(fbo);
}
postShaderPipelines_.push_back(pipeline);
@@ -272,6 +269,31 @@ bool PresentationCommon::BuildPostShader(const ShaderInfo *shaderInfo, const Sha
return true;
}
bool PresentationCommon::AllocateFramebuffer(int w, int h) {
using namespace Draw;
// First, let's try to find a framebuffer of the right size that is NOT the most recent.
Framebuffer *last = postShaderFramebuffers_.empty() ? nullptr : postShaderFramebuffers_.back();
for (const auto &prev : postShaderFBOUsage_) {
if (prev.w == w && prev.h == h && prev.fbo != last) {
// Great, this one's perfect. Ref it for when we release.
prev.fbo->AddRef();
postShaderFramebuffers_.push_back(prev.fbo);
return true;
}
}
// No depth/stencil for post processing
Draw::Framebuffer *fbo = draw_->CreateFramebuffer({ w, h, 1, 1, false, Draw::FBO_8888 });
if (!fbo) {
return false;
}
postShaderFBOUsage_.push_back({ fbo, w, h });
postShaderFramebuffers_.push_back(fbo);
return true;
}
void PresentationCommon::ShowPostShaderError(const std::string &errorString) {
// let's show the first line of the error string as an OSM.
std::set<std::string> blacklistedLines;
@@ -406,6 +428,7 @@ void PresentationCommon::DestroyPostShader() {
DoReleaseVector(postShaderPipelines_);
DoReleaseVector(postShaderFramebuffers_);
postShaderInfo_.clear();
postShaderFBOUsage_.clear();
}
Draw::ShaderModule *PresentationCommon::CompileShaderModule(Draw::ShaderStage stage, ShaderLanguage lang, const std::string &src, std::string *errorString) {
+8
View File
@@ -112,6 +112,7 @@ protected:
Draw::ShaderModule *CompileShaderModule(Draw::ShaderStage stage, ShaderLanguage lang, const std::string &src, std::string *errorString);
Draw::Pipeline *CreatePipeline(std::vector<Draw::ShaderModule *> shaders, bool postShader, const Draw::UniformBufferDesc *uniformDesc);
bool BuildPostShader(const ShaderInfo *shaderInfo, const ShaderInfo *next);
bool AllocateFramebuffer(int w, int h);
void BindSource();
@@ -145,4 +146,11 @@ protected:
bool usePostShader_ = false;
bool restorePostShader_ = false;
ShaderLanguage lang_;
struct PrevFBO {
Draw::Framebuffer *fbo;
int w;
int h;
};
std::vector<PrevFBO> postShaderFBOUsage_;
};