diff options
author | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
commit | 15740faf9fe9fe4be08965098bbf2947e096aeeb (patch) | |
tree | a730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/GfxDevice/VramLimits.cpp |
Diffstat (limited to 'Runtime/GfxDevice/VramLimits.cpp')
-rw-r--r-- | Runtime/GfxDevice/VramLimits.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/Runtime/GfxDevice/VramLimits.cpp b/Runtime/GfxDevice/VramLimits.cpp new file mode 100644 index 0000000..36bfe50 --- /dev/null +++ b/Runtime/GfxDevice/VramLimits.cpp @@ -0,0 +1,39 @@ +#include "UnityPrefix.h" +#include "VramLimits.h" +#include "Runtime/Shaders/GraphicsCaps.h" + + +int ChooseSuitableFSAALevel( int width, int height, int backbufferBPP, int frontbufferBPP, int depthBPP, int fsaa ) +{ + // no AA support? + if( !gGraphicsCaps.hasMultiSample ) + return 0; + + // figure out appropriate AA level based on VRAM and screen size + int vramKB = int(gGraphicsCaps.videoMemoryMB * 1024); + + const int vramAllowedByPortion = int(vramKB * 0.5f); // allow max. 50% of total VRAM for screen + const int vramAllowedMax = 256 * 1024; // max 256MB for screen + // Make sure at least this amount of free of VRAM left after the screen. + // E.g. on a 32MB VRAM PPC MacMini, going 1280x960 2xAA still corrupts the screen (VRAM taken: 23.5MB). + // So we need to keep somewhat more free than 8MB... 16MB works. + const int vramAllowedWithKeepingSomeFree = int(vramKB - 16*1024); + + int vramAllowedKB = std::min(vramAllowedByPortion, std::min(vramAllowedMax,vramAllowedWithKeepingSomeFree)); + int vramNeededKB; + do { + vramNeededKB = width * height * (std::max(fsaa,1) * (backbufferBPP+depthBPP) + frontbufferBPP) / 1024; + if( vramNeededKB < vramAllowedKB ) + break; + + #if !UNITY_RELEASE + printf_console("Screen %ix%i at %ixAA won't fit, reducing AA (needed mem=%i allowedmem=%i)\n", width, height, fsaa, vramNeededKB, vramAllowedKB ); + #endif + fsaa /= 2; + } while( fsaa > 1 ); + + if( fsaa == 1 ) + fsaa = 0; + + return fsaa; +} |