Unify GetTempFBO

This commit is contained in:
Henrik Rydgard 2017-02-07 00:24:38 +01:00
parent 06addecb3d
commit 19868b5df7
10 changed files with 33 additions and 53 deletions

View File

@ -1100,6 +1100,24 @@ void FramebufferManagerCommon::GetCardboardSettings(CardboardSettings *cardboard
cardboardSettings->screenHeight = cardboardScreenHeight;
}
Draw::Framebuffer *FramebufferManagerCommon::GetTempFBO(u16 w, u16 h, Draw::FBColorDepth depth) {
u64 key = ((u64)depth << 32) | ((u32)w << 16) | h;
auto it = tempFBOs_.find(key);
if (it != tempFBOs_.end()) {
it->second.last_frame_used = gpuStats.numFlips;
return it->second.fbo;
}
textureCache_->ForgetLastTexture();
Draw::Framebuffer *fbo = draw_->CreateFramebuffer({ w, h, 1, 1, false, depth });
if (!fbo)
return fbo;
draw_->BindFramebufferAsRenderTarget(fbo);
ClearBuffer(true);
const TempFBO info = { fbo, gpuStats.numFlips };
tempFBOs_[key] = info;
return fbo;
}
void FramebufferManagerCommon::UpdateFramebufUsage(VirtualFramebuffer *vfb) {
auto checkFlag = [&](u16 flag, int last_frame) {

View File

@ -24,6 +24,7 @@
#include "Core/MemMap.h"
#include "GPU/GPU.h"
#include "GPU/ge_constants.h"
#include "thin3d/thin3d.h"
enum {
FB_USAGE_DISPLAYED_FRAMEBUFFER = 1,
@ -249,6 +250,8 @@ public:
virtual void Resized() = 0;
Draw::Framebuffer *GetTempFBO(u16 w, u16 h, Draw::FBColorDepth depth = Draw::FBO_8888);
protected:
// Cardboard Settings Calculator
void GetCardboardSettings(CardboardSettings *cardboardSettings);
@ -336,6 +339,14 @@ protected:
// Used by post-processing shaders
std::vector<Draw::Framebuffer *> extraFBOs_;
struct TempFBO {
Draw::Framebuffer *fbo;
int last_frame_used;
};
std::map<u64, TempFBO> tempFBOs_;
// Aggressively delete unused FBOs to save gpu memory.
enum {
FBO_OLD_AGE = 5,

View File

@ -57,6 +57,7 @@ public:
virtual bool SetOffsetTexture(u32 offset) = 0;
virtual void Invalidate(u32 addr, int size, GPUInvalidationType type) = 0;
virtual void InvalidateAll(GPUInvalidationType type) = 0;
virtual void ForgetLastTexture() = 0;
// FramebufferManager keeps TextureCache updated about what regions of memory are being rendered to.
void NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffer, FramebufferNotification msg);

View File

@ -618,27 +618,6 @@ static void DXSetViewport(float x, float y, float w, float h, float minZ, float
}
}
Draw::Framebuffer *FramebufferManagerDX9::GetTempFBO(u16 w, u16 h, Draw::FBColorDepth depth) {
u64 key = ((u64)depth << 32) | ((u32)w << 16) | h;
auto it = tempFBOs_.find(key);
if (it != tempFBOs_.end()) {
it->second.last_frame_used = gpuStats.numFlips;
return it->second.fbo;
}
textureCacheDX9_->ForgetLastTexture();
Draw::Framebuffer *fbo = draw_->CreateFramebuffer({ w, h, 1, 1, false, depth });
if (!fbo)
return fbo;
draw_->BindFramebufferAsRenderTarget(fbo);
dxstate.viewport.force(0, 0, w, h);
ClearBuffer(true);
dxstate.viewport.restore();
const TempFBO info = {fbo, gpuStats.numFlips};
tempFBOs_[key] = info;
return fbo;
}
LPDIRECT3DSURFACE9 FramebufferManagerDX9::GetOffscreenSurface(LPDIRECT3DSURFACE9 similarSurface, VirtualFramebuffer *vfb) {
D3DSURFACE_DESC desc = {};
HRESULT hr = similarSurface->GetDesc(&desc);

View File

@ -86,7 +86,6 @@ public:
virtual void RebindFramebuffer() override;
Draw::Framebuffer *GetTempFBO(u16 w, u16 h, Draw::FBColorDepth depth = Draw::FBO_8888);
LPDIRECT3DSURFACE9 GetOffscreenSurface(LPDIRECT3DSURFACE9 similarSurface, VirtualFramebuffer *vfb);
LPDIRECT3DSURFACE9 GetOffscreenSurface(D3DFORMAT fmt, u32 w, u32 h);

View File

@ -65,7 +65,7 @@ public:
// Only used by Qt UI?
bool DecodeTexture(u8 *output, const GPUgstate &state);
void ForgetLastTexture();
void ForgetLastTexture() override;
void SetFramebufferSamplingParams(u16 bufferWidth, u16 bufferHeight);

View File

@ -709,25 +709,6 @@ void FramebufferManagerGLES::BlitFramebufferDepth(VirtualFramebuffer *src, Virtu
}
}
Draw::Framebuffer *FramebufferManagerGLES::GetTempFBO(u16 w, u16 h, Draw::FBColorDepth depth) {
u64 key = ((u64)depth << 32) | ((u32)w << 16) | h;
auto it = tempFBOs_.find(key);
if (it != tempFBOs_.end()) {
it->second.last_frame_used = gpuStats.numFlips;
return it->second.fbo;
}
textureCacheGL_->ForgetLastTexture();
Draw::Framebuffer *fbo = draw_->CreateFramebuffer({ w, h, 1, 1, false, depth });
if (!fbo)
return fbo;
draw_->BindFramebufferAsRenderTarget(fbo);
ClearBuffer(true);
const TempFBO info = {fbo, gpuStats.numFlips};
tempFBOs_[key] = info;
return fbo;
}
void FramebufferManagerGLES::BindFramebufferColor(int stage, u32 fbRawAddress, VirtualFramebuffer *framebuffer, int flags) {
if (framebuffer == NULL) {
framebuffer = currentRenderVfb_;

View File

@ -102,8 +102,6 @@ public:
virtual void RebindFramebuffer() override;
Draw::Framebuffer *GetTempFBO(u16 w, u16 h, Draw::FBColorDepth depth = Draw::FBO_8888);
protected:
void DisableState() override;
void ClearBuffer(bool keepState = false) override;
@ -150,13 +148,6 @@ private:
bool resized_;
struct TempFBO {
Draw::Framebuffer *fbo;
int last_frame_used;
};
std::map<u64, TempFBO> tempFBOs_;
// Not used under ES currently.
AsyncPBO *pixelBufObj_; //this isn't that large
u8 currentPBO_;

View File

@ -72,7 +72,7 @@ public:
return cache.size();
}
void ForgetLastTexture() {
void ForgetLastTexture() override {
lastBoundTexture = -1;
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
}

View File

@ -119,7 +119,7 @@ public:
return cache.size();
}
void ForgetLastTexture() {
void ForgetLastTexture() override {
lastBoundTexture = nullptr;
gstate_c.Dirty(DIRTY_TEXTURE_PARAMS);
}