mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Add shaderStorage config option.
Support it for mupen64plus.
This commit is contained in:
parent
38baef70de
commit
0482212f10
|
@ -1,4 +1,6 @@
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <functional>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "OpenGL.h"
|
#include "OpenGL.h"
|
||||||
#include "Combiner.h"
|
#include "Combiner.h"
|
||||||
|
@ -6,7 +8,9 @@
|
||||||
#include "UniformCollection.h"
|
#include "UniformCollection.h"
|
||||||
#include "Debug.h"
|
#include "Debug.h"
|
||||||
#include "gDP.h"
|
#include "gDP.h"
|
||||||
|
#include "Config.h"
|
||||||
#include "PluginAPI.h"
|
#include "PluginAPI.h"
|
||||||
|
#include "RSP.h"
|
||||||
|
|
||||||
static int saRGBExpanded[] =
|
static int saRGBExpanded[] =
|
||||||
{
|
{
|
||||||
|
@ -92,10 +96,10 @@ void CombinerInfo::init()
|
||||||
{
|
{
|
||||||
m_pCurrent = NULL;
|
m_pCurrent = NULL;
|
||||||
m_pUniformCollection = createUniformCollection();
|
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;
|
m_shadersLoaded = 0;
|
||||||
if (!_loadCombinersCache()) {
|
if (m_bShaderCacheSupported && !_loadCombinersCache()) {
|
||||||
for (Combiners::iterator cur = m_combiners.begin(); cur != m_combiners.end(); ++cur)
|
for (Combiners::iterator cur = m_combiners.begin(); cur != m_combiners.end(); ++cur)
|
||||||
delete cur->second;
|
delete cur->second;
|
||||||
m_combiners.clear();
|
m_combiners.clear();
|
||||||
|
@ -107,7 +111,9 @@ void CombinerInfo::destroy()
|
||||||
delete m_pUniformCollection;
|
delete m_pUniformCollection;
|
||||||
m_pUniformCollection = NULL;
|
m_pUniformCollection = NULL;
|
||||||
m_pCurrent = NULL;
|
m_pCurrent = NULL;
|
||||||
_saveCombinersCache();
|
if (m_bShaderCacheSupported)
|
||||||
|
_saveCombinersCache();
|
||||||
|
m_shadersLoaded = 0;
|
||||||
for (Combiners::iterator cur = m_combiners.begin(); cur != m_combiners.end(); ++cur)
|
for (Combiners::iterator cur = m_combiners.begin(); cur != m_combiners.end(); ++cur)
|
||||||
delete cur->second;
|
delete cur->second;
|
||||||
m_combiners.clear();
|
m_combiners.clear();
|
||||||
|
@ -315,6 +321,15 @@ void CombinerInfo::updateParameters(OGLRender::RENDER_STATE _renderState)
|
||||||
m_pUniformCollection->updateUniforms(m_pCurrent, _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:
|
Storage format:
|
||||||
uint32 - format version;
|
uint32 - format version;
|
||||||
|
@ -328,26 +343,34 @@ Storage format:
|
||||||
static const u32 CombinersCacheFormatVersion = 0x01U;
|
static const u32 CombinersCacheFormatVersion = 0x01U;
|
||||||
void CombinerInfo::_saveCombinersCache() const
|
void CombinerInfo::_saveCombinersCache() const
|
||||||
{
|
{
|
||||||
if (!m_bShaderCacheSupported || m_shadersLoaded >= m_combiners.size())
|
if (m_shadersLoaded >= m_combiners.size())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
wchar_t strIniFolderPath[PLUGIN_PATH_SIZE];
|
wchar_t fileName[PLUGIN_PATH_SIZE];
|
||||||
api().FindPluginPath(strIniFolderPath);
|
getStorageFileName(fileName);
|
||||||
std::wstring fileName(strIniFolderPath);
|
|
||||||
fileName += L"/GLideN64.shaders.bin";
|
#ifdef OS_WINDOWS
|
||||||
std::ofstream fout(fileName, std::ofstream::binary | std::ofstream::trunc);
|
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)
|
if (!fout)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
fout.write((char*)&CombinersCacheFormatVersion, sizeof(CombinersCacheFormatVersion));
|
fout.write((char*)&CombinersCacheFormatVersion, sizeof(CombinersCacheFormatVersion));
|
||||||
|
|
||||||
const char * strRenderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
|
const char * strRenderer = reinterpret_cast<const char *>(glGetString(GL_RENDERER));
|
||||||
u32 len = strlen(strRenderer);
|
u32 len = strlen(strRenderer);
|
||||||
fout.write((char*)&len, sizeof(len));
|
fout.write((char*)&len, sizeof(len));
|
||||||
fout.write(strRenderer, len);
|
fout.write(strRenderer, len);
|
||||||
|
|
||||||
const char * strGLVersion = reinterpret_cast<const char *>(glGetString(GL_VERSION));
|
const char * strGLVersion = reinterpret_cast<const char *>(glGetString(GL_VERSION));
|
||||||
len = strlen(strGLVersion);
|
len = strlen(strGLVersion);
|
||||||
fout.write((char*)&len, sizeof(len));
|
fout.write((char*)&len, sizeof(len));
|
||||||
fout.write(strGLVersion, len);
|
fout.write(strGLVersion, len);
|
||||||
|
|
||||||
len = m_combiners.size();
|
len = m_combiners.size();
|
||||||
fout.write((char*)&len, sizeof(len));
|
fout.write((char*)&len, sizeof(len));
|
||||||
for (Combiners::const_iterator cur = m_combiners.begin(); cur != m_combiners.end(); ++cur)
|
for (Combiners::const_iterator cur = m_combiners.begin(); cur != m_combiners.end(); ++cur)
|
||||||
|
@ -358,14 +381,16 @@ void CombinerInfo::_saveCombinersCache() const
|
||||||
|
|
||||||
bool CombinerInfo::_loadCombinersCache()
|
bool CombinerInfo::_loadCombinersCache()
|
||||||
{
|
{
|
||||||
if (!m_bShaderCacheSupported)
|
wchar_t fileName[PLUGIN_PATH_SIZE];
|
||||||
return false;
|
getStorageFileName(fileName);
|
||||||
|
|
||||||
wchar_t strIniFolderPath[PLUGIN_PATH_SIZE];
|
#ifdef OS_WINDOWS
|
||||||
api().FindPluginPath(strIniFolderPath);
|
|
||||||
std::wstring fileName(strIniFolderPath);
|
|
||||||
fileName += L"/GLideN64.shaders.bin";
|
|
||||||
std::ifstream fin(fileName, std::ofstream::binary);
|
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)
|
if (!fin)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -397,7 +422,17 @@ bool CombinerInfo::_loadCombinersCache()
|
||||||
m_pUniformCollection->bindWithShaderCombiner(m_pCurrent);
|
m_pUniformCollection->bindWithShaderCombiner(m_pCurrent);
|
||||||
m_combiners[m_pCurrent->getMux()] = m_pCurrent;
|
m_combiners[m_pCurrent->getMux()] = m_pCurrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_shadersLoaded = m_combiners.size();
|
m_shadersLoaded = m_combiners.size();
|
||||||
fin.close();
|
fin.close();
|
||||||
return !isGLError();
|
return !isGLError();
|
||||||
}
|
}
|
||||||
|
#else // GLES2
|
||||||
|
void CombinerInfo::_saveCombinersCache() const
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool CombinerInfo::_loadCombinersCache()
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif //GLES2
|
||||||
|
|
|
@ -34,6 +34,7 @@ void Config::resetToDefaults()
|
||||||
generalEmulation.enableNoise = 1;
|
generalEmulation.enableNoise = 1;
|
||||||
generalEmulation.enableHWLighting = 0;
|
generalEmulation.enableHWLighting = 0;
|
||||||
generalEmulation.enableCustomSettings = 1;
|
generalEmulation.enableCustomSettings = 1;
|
||||||
|
generalEmulation.shaderStorage = ssDoNotUse;
|
||||||
generalEmulation.hacks = 0;
|
generalEmulation.hacks = 0;
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
generalEmulation.forcePolygonOffset = 0;
|
generalEmulation.forcePolygonOffset = 0;
|
||||||
|
|
10
src/Config.h
10
src/Config.h
|
@ -8,7 +8,8 @@
|
||||||
#define CONFIG_VERSION_TWO 2U
|
#define CONFIG_VERSION_TWO 2U
|
||||||
#define CONFIG_VERSION_THREE 3U
|
#define CONFIG_VERSION_THREE 3U
|
||||||
#define CONFIG_VERSION_FOUR 4U // Remove ValidityCheckMethod setting
|
#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_3POINT 0
|
||||||
#define BILINEAR_STANDARD 1
|
#define BILINEAR_STANDARD 1
|
||||||
|
@ -39,12 +40,19 @@ struct Config
|
||||||
u32 screenShotFormat;
|
u32 screenShotFormat;
|
||||||
} texture;
|
} 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 {
|
struct {
|
||||||
u32 enableFog;
|
u32 enableFog;
|
||||||
u32 enableNoise;
|
u32 enableNoise;
|
||||||
u32 enableLOD;
|
u32 enableLOD;
|
||||||
u32 enableHWLighting;
|
u32 enableHWLighting;
|
||||||
u32 enableCustomSettings;
|
u32 enableCustomSettings;
|
||||||
|
u32 shaderStorage;
|
||||||
u32 hacks;
|
u32 hacks;
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
u32 forcePolygonOffset;
|
u32 forcePolygonOffset;
|
||||||
|
|
|
@ -66,6 +66,8 @@ bool Config_SetDefault()
|
||||||
assert(res == M64ERR_SUCCESS);
|
assert(res == M64ERR_SUCCESS);
|
||||||
res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableHWLighting", config.generalEmulation.enableHWLighting, "Enable hardware per-pixel lighting.");
|
res = ConfigSetDefaultBool(g_configVideoGliden64, "EnableHWLighting", config.generalEmulation.enableHWLighting, "Enable hardware per-pixel lighting.");
|
||||||
assert(res == M64ERR_SUCCESS);
|
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
|
#ifdef ANDROID
|
||||||
res = ConfigSetDefaultBool(g_configVideoGliden64, "ForcePolygonOffset", config.generalEmulation.forcePolygonOffset, "If true, use polygon offset values specified below");
|
res = ConfigSetDefaultBool(g_configVideoGliden64, "ForcePolygonOffset", config.generalEmulation.forcePolygonOffset, "If true, use polygon offset values specified below");
|
||||||
assert(res == M64ERR_SUCCESS);
|
assert(res == M64ERR_SUCCESS);
|
||||||
|
@ -179,6 +181,7 @@ void Config_LoadConfig()
|
||||||
config.generalEmulation.enableNoise = ConfigGetParamBool(g_configVideoGliden64, "EnableNoise");
|
config.generalEmulation.enableNoise = ConfigGetParamBool(g_configVideoGliden64, "EnableNoise");
|
||||||
config.generalEmulation.enableLOD = ConfigGetParamBool(g_configVideoGliden64, "EnableLOD");
|
config.generalEmulation.enableLOD = ConfigGetParamBool(g_configVideoGliden64, "EnableLOD");
|
||||||
config.generalEmulation.enableHWLighting = ConfigGetParamBool(g_configVideoGliden64, "EnableHWLighting");
|
config.generalEmulation.enableHWLighting = ConfigGetParamBool(g_configVideoGliden64, "EnableHWLighting");
|
||||||
|
config.generalEmulation.shaderStorage = ConfigGetParamInt(g_configVideoGliden64, "ShaderStorage");
|
||||||
#ifdef ANDROID
|
#ifdef ANDROID
|
||||||
config.generalEmulation.forcePolygonOffset = ConfigGetParamBool(g_configVideoGliden64, "ForcePolygonOffset");
|
config.generalEmulation.forcePolygonOffset = ConfigGetParamBool(g_configVideoGliden64, "ForcePolygonOffset");
|
||||||
config.generalEmulation.polygonOffsetFactor = ConfigGetParamFloat(g_configVideoGliden64, "PolygonOffsetFactor");
|
config.generalEmulation.polygonOffsetFactor = ConfigGetParamFloat(g_configVideoGliden64, "PolygonOffsetFactor");
|
||||||
|
|
Loading…
Reference in New Issue
Block a user