Path: blob/master/GPU/Common/FramebufferManagerCommon.h
3186 views
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617// TODO: We now have the tools in thin3d to nearly eliminate the backend-specific framebuffer managers.18// Here's a list of functionality to unify into FramebufferManagerCommon:19// * DrawActiveTexture20// * BlitFramebuffer21//22// Also, in TextureCache we should be able to unify texture-based depal.2324#pragma once2526#include <vector>27#include <unordered_map>2829#include "Common/CommonTypes.h"30#include "Common/Log.h"31#include "Common/GPU/thin3d.h"32#include "Core/ConfigValues.h"33#include "GPU/GPU.h"34#include "GPU/ge_constants.h"35#include "GPU/GPUCommon.h"36#include "GPU/Common/Draw2D.h"3738enum {39FB_USAGE_DISPLAYED_FRAMEBUFFER = 1,40FB_USAGE_RENDER_COLOR = 2,41FB_USAGE_TEXTURE = 4,42FB_USAGE_CLUT = 8,43FB_USAGE_DOWNLOAD = 16,44FB_USAGE_DOWNLOAD_CLEAR = 32,45FB_USAGE_BLUE_TO_ALPHA = 64,46FB_USAGE_FIRST_FRAME_SAVED = 128,47FB_USAGE_RENDER_DEPTH = 256,48FB_USAGE_COLOR_MIXED_DEPTH = 512,49FB_USAGE_INVALIDATE_DEPTH = 1024, // used to clear depth buffers.50};5152enum {53FB_NON_BUFFERED_MODE = 0,54FB_BUFFERED_MODE = 1,55};5657namespace Draw {58class Framebuffer;59}6061class VulkanFBO;62class ShaderWriter;6364// We have to track VFBs and depth buffers together, since bits are shared between the color alpha channel65// and the stencil buffer on the PSP.66// Sometimes, virtual framebuffers need to share a Z buffer. We emulate this by copying from on to the next67// when such a situation is detected. In order to reliably detect this, we separately track depth buffers,68// and they know which color buffer they were used with last.69// Two VirtualFramebuffer can occupy the same address range as long as they have different fb_format.70// In that case, the one with the highest colorBindSeq number is the valid one.71struct VirtualFramebuffer {72u32 fb_address;73u32 z_address; // If 0, it's a "RAM" framebuffer.74u16 fb_stride;75u16 z_stride;7677// The original PSP format of the framebuffer.78// In reality they are all RGBA8888 for better quality but this is what the PSP thinks it is. This is necessary79// when we need to interpret the bits directly (depal or buffer aliasing).80// NOTE: CANNOT be changed after creation anymore!81GEBufferFormat fb_format;8283Draw::Framebuffer *fbo;8485// width/height: The detected size of the current framebuffer, in original PSP pixels.86u16 width;87u16 height;8889// bufferWidth/bufferHeight: The pre-scaling size of the buffer itself. May only be bigger than or equal to width/height.90// In original PSP pixels - actual framebuffer is this size times the render resolution multiplier.91// The buffer may be used to render a width or height from 0 to these values without being recreated.92u16 bufferWidth;93u16 bufferHeight;9495// renderWidth/renderHeight: The scaled size we render at. May be scaled to render at higher resolutions.96// These are simply bufferWidth/Height * renderScaleFactor and are thus redundant.97u16 renderWidth;98u16 renderHeight;99100// Attempt to keep track of a bounding rectangle of what's been actually drawn. Coarse, but might be smaller101// than width/height if framebuffer has been enlarged. In PSP pixels.102u16 drawnWidth;103u16 drawnHeight;104105// The dimensions at which we are confident that we can read back this buffer without stomping on irrelevant memory.106u16 safeWidth;107u16 safeHeight;108109// The scale factor at which we are rendering (to achieve higher resolution).110u8 renderScaleFactor;111112u16 usageFlags;113114// These are used to track state to try to avoid buffer size shifting back and forth.115// You might think that doesn't happen since we mostly grow framebuffers, but we do resize down,116// if the size has shrunk for a while and the framebuffer is also larger than the stride.117// At this point, the "safe" size is probably a lie, and we have had various issues with readbacks, so this resizes down to avoid them.118// An example would be a game that always uses the address 0x00154000 for temp buffers, and uses it for a full-screen effect for 3 frames, then goes back to using it for character shadows or something much smaller.119u16 newWidth;120u16 newHeight;121122// The frame number at which this was last resized.123int lastFrameNewSize;124125// Tracking for downloads-to-CLUT.126u16 clutUpdatedBytes;127128// Means that the whole image has already been read back to memory - used when combining small readbacks (gameUsesSequentialCopies_).129bool memoryUpdated;130131// TODO: Fold into usageFlags?132bool dirtyAfterDisplay;133bool reallyDirtyAfterDisplay; // takes frame skipping into account134135// Global sequence numbers for the last time these were bound.136// Not based on frames at all. Can be used to determine new-ness of one framebuffer over another,137// can even be within a frame.138int colorBindSeq;139int depthBindSeq;140141// These are mainly used for garbage collection purposes and similar.142// Cannot be used to determine new-ness against a similar other buffer, since they are143// only at frame granularity.144int last_frame_used;145int last_frame_attached;146int last_frame_render;147int last_frame_displayed;148int last_frame_clut;149int last_frame_failed;150int last_frame_depth_updated;151int last_frame_depth_render;152153// Convenience methods154inline int WidthInBytes() const { return width * BufferFormatBytesPerPixel(fb_format); }155inline int BufferWidthInBytes() const { return bufferWidth * BufferFormatBytesPerPixel(fb_format); }156inline int FbStrideInBytes() const { return fb_stride * BufferFormatBytesPerPixel(fb_format); }157inline int ZStrideInBytes() const { return z_stride * 2; }158159inline int Stride(RasterChannel channel) const { return channel == RASTER_COLOR ? fb_stride : z_stride; }160inline u32 Address(RasterChannel channel) const { return channel == RASTER_COLOR ? fb_address : z_address; }161inline GEBufferFormat Format(RasterChannel channel) const { return channel == RASTER_COLOR ? fb_format : GE_FORMAT_DEPTH16; }162inline int BindSeq(RasterChannel channel) const { return channel == RASTER_COLOR ? colorBindSeq : depthBindSeq; }163164// Computed from stride.165int BufferByteSize(RasterChannel channel) const { return BufferByteStride(channel) * height; }166int BufferByteStride(RasterChannel channel) const {167return channel == RASTER_COLOR ? fb_stride * (fb_format == GE_FORMAT_8888 ? 4 : 2) : z_stride * 2;168}169int BufferByteWidth(RasterChannel channel) const {170return channel == RASTER_COLOR ? width * (fb_format == GE_FORMAT_8888 ? 4 : 2) : width * 2;171}172};173174struct FramebufferHeuristicParams {175u32 fb_address;176u32 z_address;177u16 fb_stride;178u16 z_stride;179GEBufferFormat fb_format;180bool isClearingDepth;181bool isWritingDepth;182bool isDrawing;183bool isModeThrough;184bool isBlending;185int viewportWidth;186int viewportHeight;187int16_t regionWidth;188int16_t regionHeight;189int16_t scissorLeft;190int16_t scissorTop;191int16_t scissorRight;192int16_t scissorBottom;193};194195struct GPUgstate;196extern GPUgstate gstate;197198void GetFramebufferHeuristicInputs(FramebufferHeuristicParams *params, const GPUgstate &gstate);199200enum BindFramebufferColorFlags {201BINDFBCOLOR_SKIP_COPY = 0,202BINDFBCOLOR_MAY_COPY = 1,203BINDFBCOLOR_MAY_COPY_WITH_UV = 3, // includes BINDFBCOLOR_MAY_COPY204BINDFBCOLOR_APPLY_TEX_OFFSET = 4,205// Used when rendering to a temporary surface (e.g. not the current render target.)206BINDFBCOLOR_FORCE_SELF = 8,207BINDFBCOLOR_UNCACHED = 16,208};209210enum DrawTextureFlags {211DRAWTEX_NEAREST = 0,212DRAWTEX_LINEAR = 1,213DRAWTEX_TO_BACKBUFFER = 8,214DRAWTEX_DEPTH = 16,215};216217inline DrawTextureFlags operator | (const DrawTextureFlags &lhs, const DrawTextureFlags &rhs) {218return DrawTextureFlags((u32)lhs | (u32)rhs);219}220221enum class TempFBO {222DEPAL,223BLIT,224// For copies of framebuffers (e.g. shader blending.)225COPY,226// Used for copies when setting color to depth.227Z_COPY,228// Used to copy stencil data, means we need a stencil backing.229STENCIL,230};231232inline Draw::DataFormat GEFormatToThin3D(GEBufferFormat geFormat) {233switch (geFormat) {234case GE_FORMAT_4444:235return Draw::DataFormat::A4R4G4B4_UNORM_PACK16;236case GE_FORMAT_5551:237return Draw::DataFormat::A1R5G5B5_UNORM_PACK16;238case GE_FORMAT_565:239return Draw::DataFormat::R5G6B5_UNORM_PACK16;240case GE_FORMAT_8888:241return Draw::DataFormat::R8G8B8A8_UNORM;242case GE_FORMAT_DEPTH16:243return Draw::DataFormat::D16;244default:245// TODO: Assert?246return Draw::DataFormat::UNDEFINED;247}248}249250// Dimensions are in bytes, later steps get to convert back into real coordinates as appropriate.251// Makes it easy to see if blits match etc.252struct BlockTransferRect {253VirtualFramebuffer *vfb;254RasterChannel channel; // We usually only deal with color, but we have limited depth block transfer support now.255256int x_bytes;257int y;258int w_bytes;259int h;260261std::string ToString() const;262263int w_pixels() const {264return w_bytes / BufferFormatBytesPerPixel(vfb->fb_format);265}266int x_pixels() const {267return x_bytes / BufferFormatBytesPerPixel(vfb->fb_format);268}269};270271namespace Draw {272class DrawContext;273}274275struct DrawPixelsEntry {276Draw::Texture *tex;277uint64_t contentsHash;278int frameNumber;279};280281struct GPUDebugBuffer;282class DrawEngineCommon;283class PresentationCommon;284class ShaderManagerCommon;285class TextureCacheCommon;286287class FramebufferManagerCommon {288public:289FramebufferManagerCommon(Draw::DrawContext *draw);290virtual ~FramebufferManagerCommon();291292void SetTextureCache(TextureCacheCommon *tc) {293textureCache_ = tc;294}295void SetShaderManager(ShaderManagerCommon * sm) {296shaderManager_ = sm;297}298void SetDrawEngine(DrawEngineCommon *td) {299drawEngine_ = td;300}301302void Init(int msaaLevel);303virtual void BeginFrame();304void SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat format);305void DestroyFramebuf(VirtualFramebuffer *v);306307VirtualFramebuffer *DoSetRenderFrameBuffer(FramebufferHeuristicParams ¶ms, u32 skipDrawReason);308VirtualFramebuffer *SetRenderFrameBuffer(bool framebufChanged, int skipDrawReason, bool *changed) {309// Inlining this part since it's so frequent.310if (!framebufChanged && currentRenderVfb_) {311currentRenderVfb_->last_frame_render = gpuStats.numFlips;312currentRenderVfb_->dirtyAfterDisplay = true;313if (!skipDrawReason)314currentRenderVfb_->reallyDirtyAfterDisplay = true;315*changed = false;316return currentRenderVfb_;317} else {318// This is so that we will be able to drive DoSetRenderFramebuffer with inputs319// that come from elsewhere than gstate.320FramebufferHeuristicParams inputs;321GetFramebufferHeuristicInputs(&inputs, gstate);322VirtualFramebuffer *vfb = DoSetRenderFrameBuffer(inputs, skipDrawReason);323_dbg_assert_msg_(vfb, "DoSetRenderFramebuffer must return a valid framebuffer.");324_dbg_assert_msg_(currentRenderVfb_, "DoSetRenderFramebuffer must set a valid framebuffer.");325*changed = true;326return vfb;327}328}329void SetDepthFrameBuffer(bool isClearingDepth);330331void RebindFramebuffer(const char *tag);332std::vector<const VirtualFramebuffer *> GetFramebufferList() const;333334void CopyDisplayToOutput(bool reallyDirty);335336bool NotifyFramebufferCopy(u32 src, u32 dest, int size, GPUCopyFlag flags, u32 skipDrawReason);337void PerformWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat fmt);338void UpdateFromMemory(u32 addr, int size);339void ApplyClearToMemory(int x1, int y1, int x2, int y2, u32 clearColor);340bool PerformWriteStencilFromMemory(u32 addr, int size, WriteStencil flags);341342// We changed our depth mode, gotta start over.343// Ideally, we should convert depth buffers here, not just clear them.344void ClearAllDepthBuffers();345346// Returns true if it's sure this is a direct FBO->FBO transfer and it has already handle it.347// In that case we hardly need to actually copy the bytes in VRAM, they will be wrong anyway (unless348// read framebuffers is on, in which case this should always return false).349// If this returns false, a memory copy will happen and NotifyBlockTransferAfter will be called.350bool NotifyBlockTransferBefore(u32 dstBasePtr, int dstStride, int dstX, int dstY, u32 srcBasePtr, int srcStride, int srcX, int srcY, int w, int h, int bpp, u32 skipDrawReason);351352// This gets called after the memory copy, in case NotifyBlockTransferBefore returned false.353// Otherwise it doesn't get called.354void NotifyBlockTransferAfter(u32 dstBasePtr, int dstStride, int dstX, int dstY, u32 srcBasePtr, int srcStride, int srcX, int srcY, int w, int h, int bpp, u32 skipDrawReason);355356bool BindFramebufferAsColorTexture(int stage, VirtualFramebuffer *framebuffer, int flags, int layer);357void ReadFramebufferToMemory(VirtualFramebuffer *vfb, int x, int y, int w, int h, RasterChannel channel, Draw::ReadbackMode mode);358359void DownloadFramebufferForClut(u32 fb_address, u32 loadBytes);360bool DrawFramebufferToOutput(const u8 *srcPixels, int srcStride, GEBufferFormat srcPixelFormat);361362void DrawPixels(VirtualFramebuffer *vfb, int dstX, int dstY, const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height, RasterChannel channel, const char *tag);363364size_t NumVFBs() const { return vfbs_.size(); }365366u32 PrevDisplayFramebufAddr() const {367return prevDisplayFramebuf_ ? prevDisplayFramebuf_->fb_address : 0;368}369u32 CurrentDisplayFramebufAddr() const {370return displayFramebuf_ ? displayFramebuf_->fb_address : 0;371}372373u32 DisplayFramebufAddr() const {374return displayFramebufPtr_;375}376u32 DisplayFramebufStride() const {377return displayStride_;378}379GEBufferFormat DisplayFramebufFormat() const {380return displayFormat_;381}382383bool UseBufferedRendering() const {384return useBufferedRendering_;385}386387void ForceUseBufferedRendering(bool buf) {388useBufferedRendering_ = true;389}390391// TODO: Maybe just include the last depth buffer address in this, too.392bool MayIntersectFramebufferColor(u32 start) const {393// Clear the cache/kernel bits.394start &= 0x3FFFFFFF;395if (Memory::IsVRAMAddress(start))396start &= 0x041FFFFF;397// Most games only have two framebuffers at the start.398if (start >= framebufColorRangeEnd_ || start < PSP_GetVidMemBase()) {399return false;400}401return true;402}403404VirtualFramebuffer *GetCurrentRenderVFB() const {405return currentRenderVfb_;406}407408// This only checks for the color channel, and if there are multiple overlapping ones409// with different color depth, this might get things wrong.410// DEPRECATED FOR NEW USES - avoid whenever possible.411VirtualFramebuffer *GetVFBAt(u32 addr) const;412413// This will only return exact matches of addr+stride+format.414VirtualFramebuffer *GetExactVFB(u32 addr, int stride, GEBufferFormat format) const;415416// If this doesn't find the exact VFB, but one with a different color format with matching stride,417// it'll resolve the newest one at address to the format requested, and return that.418VirtualFramebuffer *ResolveVFB(u32 addr, int stride, GEBufferFormat format);419420// Utility to get the display VFB.421VirtualFramebuffer *GetDisplayVFB();422423int GetRenderWidth() const { return currentRenderVfb_ ? currentRenderVfb_->renderWidth : 480; }424int GetRenderHeight() const { return currentRenderVfb_ ? currentRenderVfb_->renderHeight : 272; }425int GetTargetWidth() const { return currentRenderVfb_ ? currentRenderVfb_->width : 480; }426int GetTargetHeight() const { return currentRenderVfb_ ? currentRenderVfb_->height : 272; }427int GetTargetBufferWidth() const { return currentRenderVfb_ ? currentRenderVfb_->bufferWidth : 480; }428int GetTargetBufferHeight() const { return currentRenderVfb_ ? currentRenderVfb_->bufferHeight : 272; }429int GetTargetStride() const { return currentRenderVfb_ ? currentRenderVfb_->fb_stride : 512; }430GEBufferFormat GetTargetFormat() const { return currentRenderVfb_ ? currentRenderVfb_->fb_format : displayFormat_; }431432void SetColorUpdated(int skipDrawReason) {433if (currentRenderVfb_) {434SetColorUpdated(currentRenderVfb_, skipDrawReason);435}436}437void SetSafeSize(u16 w, u16 h);438439void NotifyRenderResized(int msaaLevel);440virtual void NotifyDisplayResized();441void NotifyConfigChanged();442443void CheckPostShaders();444445virtual void DestroyAllFBOs();446447virtual void DeviceLost();448virtual void DeviceRestore(Draw::DrawContext *draw);449450Draw::Framebuffer *GetTempFBO(TempFBO reason, u16 w, u16 h);451452// Debug features453virtual bool GetFramebuffer(u32 fb_address, int fb_stride, GEBufferFormat format, GPUDebugBuffer &buffer, int maxRes);454virtual bool GetDepthbuffer(u32 fb_address, int fb_stride, u32 z_address, int z_stride, GPUDebugBuffer &buffer);455virtual bool GetStencilbuffer(u32 fb_address, int fb_stride, GPUDebugBuffer &buffer);456virtual bool GetOutputFramebuffer(GPUDebugBuffer &buffer);457458const std::vector<VirtualFramebuffer *> &Framebuffers() const {459return vfbs_;460}461462Draw2D *GetDraw2D() {463return &draw2D_;464}465466// If a vfb with the target format exists, resolve it (run CopyToColorFromOverlappingFramebuffers).467// If it doesn't exist, create it and do the same.468// Returns the resolved framebuffer.469VirtualFramebuffer *ResolveFramebufferColorToFormat(VirtualFramebuffer *vfb, GEBufferFormat newFormat);470471Draw2DPipeline *Get2DPipeline(Draw2DShader shader);472473// If from==to, returns a copy pipeline.474Draw2DPipeline *GetReinterpretPipeline(GEBufferFormat from, GEBufferFormat to, float *scaleFactorX);475476// Public to be used from the texture cache's depal shenanigans.477void BlitUsingRaster(478Draw::Framebuffer *src, float srcX1, float srcY1, float srcX2, float srcY2,479Draw::Framebuffer *dest, float destX1, float destY1, float destX2, float destY2,480bool linearFilter,481int scaleFactor, // usually unused, except for swizzle...482Draw2DPipeline *pipeline, const char *tag);483484void ReleasePipelines();485486int GetMSAALevel() const {487return msaaLevel_;488}489490void DiscardFramebufferCopy() {491currentFramebufferCopy_ = nullptr;492}493494bool PresentedThisFrame() const;495496const std::vector<VirtualFramebuffer *> &GetVFBs() const {497return vfbs_;498}499500protected:501virtual void ReadbackFramebuffer(VirtualFramebuffer *vfb, int x, int y, int w, int h, RasterChannel channel, Draw::ReadbackMode mode);502// Used for when a shader is required, such as GLES.503virtual bool ReadbackDepthbuffer(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint16_t *pixels, int pixelsStride, int destW, int destH, Draw::ReadbackMode mode);504virtual bool ReadbackStencilbuffer(Draw::Framebuffer *fbo, int x, int y, int w, int h, uint8_t *pixels, int pixelsStride, Draw::ReadbackMode mode);505void SetViewport2D(int x, int y, int w, int h);506Draw::Texture *MakePixelTexture(const u8 *srcPixels, GEBufferFormat srcPixelFormat, int srcStride, int width, int height);507void DrawActiveTexture(float x, float y, float w, float h, float destW, float destH, float u0, float v0, float u1, float v1, int uvRotation, int flags);508509void CopyToColorFromOverlappingFramebuffers(VirtualFramebuffer *dest);510void CopyToDepthFromOverlappingFramebuffers(VirtualFramebuffer *dest);511512bool UpdateRenderSize(int msaaLevel);513514void FlushBeforeCopy();515virtual void DecimateFBOs(); // keeping it virtual to let D3D do a little extra516517// Used by ReadFramebufferToMemory and later framebuffer block copies518void BlitFramebuffer(VirtualFramebuffer *dst, int dstX, int dstY, VirtualFramebuffer *src, int srcX, int srcY, int w, int h, int bpp, RasterChannel channel, const char *tag);519520void CopyFramebufferForColorTexture(VirtualFramebuffer *dst, VirtualFramebuffer *src, int flags, int layer, bool *partial);521522void EstimateDrawingSize(u32 fb_address, int fb_stride, GEBufferFormat fb_format, int viewport_width, int viewport_height, int region_width, int region_height, int scissor_width, int scissor_height, int &drawing_width, int &drawing_height);523524void NotifyRenderFramebufferCreated(VirtualFramebuffer *vfb);525static void NotifyRenderFramebufferUpdated(VirtualFramebuffer *vfb);526void NotifyRenderFramebufferSwitched(VirtualFramebuffer *prevVfb, VirtualFramebuffer *vfb, bool isClearingDepth);527528void BlitFramebufferDepth(VirtualFramebuffer *src, VirtualFramebuffer *dst, bool allowSizeMismatch = false);529530void ResizeFramebufFBO(VirtualFramebuffer *vfb, int w, int h, bool force = false, bool skipCopy = false);531532static bool ShouldDownloadFramebufferColor(const VirtualFramebuffer *vfb);533static bool ShouldDownloadFramebufferDepth(const VirtualFramebuffer *vfb);534void DownloadFramebufferOnSwitch(VirtualFramebuffer *vfb);535536bool FindTransferFramebuffer(u32 basePtr, int stride, int x, int y, int w, int h, int bpp, bool destination, BlockTransferRect *rect);537538VirtualFramebuffer *FindDownloadTempBuffer(VirtualFramebuffer *vfb, RasterChannel channel);539virtual void UpdateDownloadTempBuffer(VirtualFramebuffer *nvfb) {}540541VirtualFramebuffer *CreateRAMFramebuffer(uint32_t fbAddress, int width, int height, int stride, GEBufferFormat format);542543void UpdateFramebufUsage(VirtualFramebuffer *vfb) const;544545int GetFramebufferLayers() const;546547static void SetColorUpdated(VirtualFramebuffer *dstBuffer, int skipDrawReason) {548dstBuffer->memoryUpdated = false;549dstBuffer->clutUpdatedBytes = 0;550dstBuffer->dirtyAfterDisplay = true;551dstBuffer->drawnWidth = dstBuffer->width;552dstBuffer->drawnHeight = dstBuffer->height;553if ((skipDrawReason & SKIPDRAW_SKIPFRAME) == 0)554dstBuffer->reallyDirtyAfterDisplay = true;555}556557inline int GetBindSeqCount() {558return fbBindSeqCount_++;559}560561static SkipGPUReadbackMode GetSkipGPUReadbackMode();562563PresentationCommon *presentation_ = nullptr;564565Draw::DrawContext *draw_ = nullptr;566567TextureCacheCommon *textureCache_ = nullptr;568ShaderManagerCommon *shaderManager_ = nullptr;569DrawEngineCommon *drawEngine_ = nullptr;570571bool needBackBufferYSwap_ = false;572573u32 displayFramebufPtr_ = 0;574u32 displayStride_ = 0;575GEBufferFormat displayFormat_ = GE_FORMAT_565;576u32 prevDisplayFramebufPtr_ = 0;577578int fbBindSeqCount_ = 0;579580VirtualFramebuffer *displayFramebuf_ = nullptr;581VirtualFramebuffer *prevDisplayFramebuf_ = nullptr;582VirtualFramebuffer *prevPrevDisplayFramebuf_ = nullptr;583int frameLastFramebufUsed_ = 0;584585VirtualFramebuffer *currentRenderVfb_ = nullptr;586587Draw::Framebuffer *currentFramebufferCopy_ = nullptr;588589// The range of PSP memory that may contain FBOs. So we can skip iterating.590u32 framebufColorRangeEnd_ = 0;591592bool useBufferedRendering_ = false;593bool postShaderIsUpscalingFilter_ = false;594bool postShaderIsSupersampling_ = false;595596std::vector<VirtualFramebuffer *> vfbs_;597std::vector<VirtualFramebuffer *> bvfbs_; // blitting framebuffers (for download)598599std::vector<DrawPixelsEntry> drawPixelsCache_;600601bool gameUsesSequentialCopies_ = false;602603// Sampled in BeginFrame/UpdateSize for safety.604float renderWidth_ = 0.0f;605float renderHeight_ = 0.0f;606607int msaaLevel_ = 0;608int renderScaleFactor_ = 1;609int pixelWidth_ = 0;610int pixelHeight_ = 0;611int bloomHack_ = 0;612bool updatePostShaders_ = false;613614Draw::DataFormat preferredPixelsFormat_ = Draw::DataFormat::R8G8B8A8_UNORM;615616struct TempFBOInfo {617Draw::Framebuffer *fbo;618int last_frame_used;619};620621std::unordered_map<u64, TempFBOInfo> tempFBOs_;622623std::vector<Draw::Framebuffer *> fbosToDelete_;624625// Aggressively delete unused FBOs to save gpu memory.626enum {627FBO_OLD_AGE = 5,628FBO_OLD_USAGE_FLAG = 15,629};630631// Thin3D stuff for reinterpreting image data between the various 16-bit color formats.632// Safe, not optimal - there might be input attachment tricks, etc, but we can't use them633// since we don't want N different implementations.634Draw2DPipeline *reinterpretFromTo_[4][4]{};635636// Common implementation of stencil buffer upload. Also not 100% optimal, but not performance637// critical either.638Draw::Pipeline *stencilWritePipeline_ = nullptr;639Draw::SamplerState *stencilWriteSampler_ = nullptr;640641// Used on GLES where we can't directly readback depth or stencil, but here for simplicity.642Draw::Pipeline *stencilReadbackPipeline_ = nullptr;643Draw::SamplerState *stencilReadbackSampler_ = nullptr;644Draw::Pipeline *depthReadbackPipeline_ = nullptr;645Draw::SamplerState *depthReadbackSampler_ = nullptr;646647// Draw2D pipelines648Draw2DPipeline *draw2DPipelineCopyColor_ = nullptr;649Draw2DPipeline *draw2DPipelineColorRect2Lin_ = nullptr;650Draw2DPipeline *draw2DPipelineCopyDepth_ = nullptr;651Draw2DPipeline *draw2DPipelineEncodeDepth_ = nullptr;652Draw2DPipeline *draw2DPipeline565ToDepth_ = nullptr;653Draw2DPipeline *draw2DPipeline565ToDepthDeswizzle_ = nullptr;654655Draw2D draw2D_;656// The fragment shaders are "owned" by the pipelines since they're 1:1.657658// Depth readback helper state659u8 *convBuf_ = nullptr;660u32 convBufSize_ = 0;661};662663// Should probably live elsewhere.664bool GetOutputFramebuffer(Draw::DrawContext *draw, GPUDebugBuffer &buffer);665666667