1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-04 10:03:36 +00:00

Add shaderStorage config option.

Support it for mupen64plus.
This commit is contained in:
Sergey Lipskiy 2015-10-08 22:29:55 +06:00
parent 38baef70de
commit 0482212f10
4 changed files with 62 additions and 15 deletions

View File

@ -1,4 +1,6 @@
#include <fstream>
#include <functional>
#include <stdio.h>
#include "OpenGL.h"
#include "Combiner.h"
@ -6,7 +8,9 @@
#include "UniformCollection.h"
#include "Debug.h"
#include "gDP.h"
#include "Config.h"
#include "PluginAPI.h"
#include "RSP.h"
static int saRGBExpanded[] =
{
@ -92,10 +96,10 @@ void CombinerInfo::init()
{
m_pCurrent = NULL;
m_pUniformCollection = createUniformCollection();
m_bShaderCacheSupported = OGLVideo::isExtensionSupported("GL_ARB_get_program_binary");
m_bShaderCacheSupported = config.generalEmulation.shaderStorage != Config::ssDoNotUse && OGLVideo::isExtensionSupported("GL_ARB_get_program_binary");
m_shadersLoaded = 0;
if (!_loadCombinersCache()) {
if (m_bShaderCacheSupported && !_loadCombinersCache()) {
for (Combiners::iterator cur = m_combiners.begin(); cur != m_combiners.end(); ++cur)
delete cur->second;
m_combiners.clear();
@ -107,7 +111,9 @@ void CombinerInfo::destroy()
delete m_pUniformCollection;
m_pUniformCollection = NULL;
m_pCurrent = NULL;
_saveCombinersCache();
if (m_bShaderCacheSupported)
_saveCombinersCache();
m_shadersLoaded = 0;
for (Combiners::iterator cur = m_combiners.begin(); cur != m_combiners.end(); ++cur)
delete cur->second;
m_combiners.clear();
@ -315,6 +321,15 @@ void CombinerInfo::updateParameters(OGLRender::RENDER_STATE _renderState)
m_pUniformCollection->updateUniforms(m_pCurrent, _renderState);
}
#ifndef GLES2
static
void getStorageFileName(wchar_t * _fileName)
{
wchar_t strIniFolderPath[PLUGIN_PATH_SIZE];
api().GetUserCachePath(strIniFolderPath);
swprintf(_fileName, PLUGIN_PATH_SIZE, L"%ls/GLideN64.%08lx.shaders", strIniFolderPath, config.generalEmulation.shaderStorage == Config::ssUseOneCommon ? 0 : std::hash<std::string>()(RSP.romname));
}
/*
Storage format:
uint32 - format version;
@ -328,26 +343,34 @@ Storage format:
static const u32 CombinersCacheFormatVersion = 0x01U;
void CombinerInfo::_saveCombinersCache() const
{
if (!m_bShaderCacheSupported || m_shadersLoaded >= m_combiners.size())
if (m_shadersLoaded >= m_combiners.size())
return;
wchar_t strIniFolderPath[PLUGIN_PATH_SIZE];
api().FindPluginPath(strIniFolderPath);
std::wstring fileName(strIniFolderPath);
fileName += L"/GLideN64.shaders.bin";
wchar_t fileName[PLUGIN_PATH_SIZE];
getStorageFileName(fileName);
#ifdef OS_WINDOWS
std::ofstream fout(fileName, std::ofstream::binary | std::ofstream::trunc);
#else
char fileName_c[PATH_MAX];
wcstombs(fileName_c, fileName, PATH_MAX);
std::ofstream fout(fileName_c, std::ofstream::binary | std::ofstream::trunc);
#endif
if (!fout)
return;
fout.write((char*)&CombinersCacheFormatVersion, sizeof(CombinersCacheFormatVersion));
const char * strRenderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
u32 len = strlen(strRenderer);
fout.write((char*)&len, sizeof(len));
fout.write(strRenderer, len);
const char * strGLVersion = reinterpret_cast<const char *>(glGetString(GL_VERSION));
len = strlen(strGLVersion);
fout.write((char*)&len, sizeof(len));
fout.write(strGLVersion, len);
len = m_combiners.size();
fout.write((char*)&len, sizeof(len));
for (Combiners::const_iterator cur = m_combiners.begin(); cur != m_combiners.end(); ++cur)
@ -358,14 +381,16 @@ void CombinerInfo::_saveCombinersCache() const
bool CombinerInfo::_loadCombinersCache()
{
if (!m_bShaderCacheSupported)
return false;
wchar_t fileName[PLUGIN_PATH_SIZE];
getStorageFileName(fileName);
wchar_t strIniFolderPath[PLUGIN_PATH_SIZE];
api().FindPluginPath(strIniFolderPath);
std::wstring fileName(strIniFolderPath);
fileName += L"/GLideN64.shaders.bin";
#ifdef OS_WINDOWS
std::ifstream fin(fileName, std::ofstream::binary);
#else
char fileName_c[PATH_MAX];
wcstombs(fileName_c, fileName, PATH_MAX);
std::ifstream fin(fileName_c, std::ofstream::binary);
#endif
if (!fin)
return false;
@ -397,7 +422,17 @@ bool CombinerInfo::_loadCombinersCache()
m_pUniformCollection->bindWithShaderCombiner(m_pCurrent);
m_combiners[m_pCurrent->getMux()] = m_pCurrent;
}
m_shadersLoaded = m_combiners.size();
fin.close();
return !isGLError();
}
#else // GLES2
void CombinerInfo::_saveCombinersCache() const
{}
bool CombinerInfo::_loadCombinersCache()
{
return true;
}
#endif //GLES2

View File

@ -34,6 +34,7 @@ void Config::resetToDefaults()
generalEmulation.enableNoise = 1;
generalEmulation.enableHWLighting = 0;
generalEmulation.enableCustomSettings = 1;
generalEmulation.shaderStorage = ssDoNotUse;
generalEmulation.hacks = 0;
#ifdef ANDROID
generalEmulation.forcePolygonOffset = 0;

View File

@ -8,7 +8,8 @@
#define CONFIG_VERSION_TWO 2U
#define CONFIG_VERSION_THREE 3U
#define CONFIG_VERSION_FOUR 4U // Remove ValidityCheckMethod setting
#define CONFIG_VERSION_CURRENT CONFIG_VERSION_FOUR
#define CONFIG_VERSION_FIVE 5U // Add shader storage option
#define CONFIG_VERSION_CURRENT CONFIG_VERSION_FIVE
#define BILINEAR_3POINT 0
#define BILINEAR_STANDARD 1
@ -39,12 +40,19 @@ struct Config
u32 screenShotFormat;
} texture;
enum ShaderStorage {
ssDoNotUse = 0, // Do not use shaders storage
ssUseOneCommon, // Use one shader storage for all games
ssUseOnePerGame // Use shader storage per game.
};
struct {
u32 enableFog;
u32 enableNoise;
u32 enableLOD;
u32 enableHWLighting;
u32 enableCustomSettings;
u32 shaderStorage;
u32 hacks;
#ifdef ANDROID
u32 forcePolygonOffset;

View File

@ -66,6 +66,8 @@ bool Config_SetDefault()
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableHWLighting", config.generalEmulation.enableHWLighting, "Enable hardware per-pixel lighting.");
assert(res == M64ERR_SUCCESS);
res = ConfigSetDefaultInt(g_configVideoGliden64, "ShaderStorage", config.generalEmulation.shaderStorage, "Use persistent storage for compiled shaders (0=not use, 1=use one for all, 2=use one per game)");
assert(res == M64ERR_SUCCESS);
#ifdef ANDROID
res = ConfigSetDefaultBool(g_configVideoGliden64, "ForcePolygonOffset", config.generalEmulation.forcePolygonOffset, "If true, use polygon offset values specified below");
assert(res == M64ERR_SUCCESS);
@ -179,6 +181,7 @@ void Config_LoadConfig()
config.generalEmulation.enableNoise = ConfigGetParamBool(g_configVideoGliden64, "EnableNoise");
config.generalEmulation.enableLOD = ConfigGetParamBool(g_configVideoGliden64, "EnableLOD");
config.generalEmulation.enableHWLighting = ConfigGetParamBool(g_configVideoGliden64, "EnableHWLighting");
config.generalEmulation.shaderStorage = ConfigGetParamInt(g_configVideoGliden64, "ShaderStorage");
#ifdef ANDROID
config.generalEmulation.forcePolygonOffset = ConfigGetParamBool(g_configVideoGliden64, "ForcePolygonOffset");
config.generalEmulation.polygonOffsetFactor = ConfigGetParamFloat(g_configVideoGliden64, "PolygonOffsetFactor");