2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2011 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:29:41 +00:00
|
|
|
// Refer to the license.txt file included.
|
2011-12-09 23:30:05 +00:00
|
|
|
|
2015-12-21 15:15:17 +00:00
|
|
|
#include <memory>
|
2014-03-30 18:58:05 +00:00
|
|
|
#include <string>
|
|
|
|
|
2015-09-28 15:57:16 +00:00
|
|
|
#include "Common/Common.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/MathUtil.h"
|
2014-06-03 05:08:54 +00:00
|
|
|
#include "Common/StringUtil.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
|
|
|
|
#include "VideoBackends/OGL/ProgramShaderCache.h"
|
|
|
|
#include "VideoBackends/OGL/Render.h"
|
|
|
|
#include "VideoBackends/OGL/StreamBuffer.h"
|
|
|
|
|
|
|
|
#include "VideoCommon/Debugger.h"
|
|
|
|
#include "VideoCommon/DriverDetails.h"
|
2014-12-14 20:23:13 +00:00
|
|
|
#include "VideoCommon/GeometryShaderManager.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/ImageWrite.h"
|
|
|
|
#include "VideoCommon/PixelShaderManager.h"
|
2014-02-19 11:14:09 +00:00
|
|
|
#include "VideoCommon/Statistics.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "VideoCommon/VertexShaderManager.h"
|
2011-12-10 21:58:44 +00:00
|
|
|
|
2011-12-01 03:00:21 +00:00
|
|
|
namespace OGL
|
|
|
|
{
|
2011-12-21 06:15:48 +00:00
|
|
|
|
2013-02-22 09:25:38 +00:00
|
|
|
static const u32 UBO_LENGTH = 32*1024*1024;
|
2013-01-25 12:20:42 +00:00
|
|
|
|
2013-01-14 12:58:11 +00:00
|
|
|
u32 ProgramShaderCache::s_ubo_buffer_size;
|
2013-10-07 15:19:47 +00:00
|
|
|
s32 ProgramShaderCache::s_ubo_align;
|
2011-12-26 05:15:54 +00:00
|
|
|
|
2015-12-21 15:15:17 +00:00
|
|
|
static std::unique_ptr<StreamBuffer> s_buffer;
|
2013-05-04 21:30:13 +00:00
|
|
|
static int num_failures = 0;
|
2013-01-31 22:11:53 +00:00
|
|
|
|
2014-07-08 13:58:25 +00:00
|
|
|
static LinearDiskCache<SHADERUID, u8> g_program_disk_cache;
|
2013-02-13 20:34:48 +00:00
|
|
|
static GLuint CurrentProgram = 0;
|
|
|
|
ProgramShaderCache::PCache ProgramShaderCache::pshaders;
|
2013-02-13 12:12:19 +00:00
|
|
|
ProgramShaderCache::PCacheEntry* ProgramShaderCache::last_entry;
|
|
|
|
SHADERUID ProgramShaderCache::last_uid;
|
2015-10-29 13:43:05 +00:00
|
|
|
UidChecker<PixelShaderUid, ShaderCode> ProgramShaderCache::pixel_uid_checker;
|
|
|
|
UidChecker<VertexShaderUid, ShaderCode> ProgramShaderCache::vertex_uid_checker;
|
|
|
|
UidChecker<GeometryShaderUid, ShaderCode> ProgramShaderCache::geometry_uid_checker;
|
2013-01-28 21:32:38 +00:00
|
|
|
|
2015-11-04 00:56:02 +00:00
|
|
|
static std::string s_glsl_header = "";
|
2013-02-13 20:34:48 +00:00
|
|
|
|
2014-07-08 12:29:26 +00:00
|
|
|
static std::string GetGLSLVersionString()
|
2014-03-30 18:58:05 +00:00
|
|
|
{
|
|
|
|
GLSL_VERSION v = g_ogl_config.eSupportedGLSLVersion;
|
|
|
|
switch(v)
|
|
|
|
{
|
|
|
|
case GLSLES_300:
|
|
|
|
return "#version 300 es";
|
|
|
|
case GLSLES_310:
|
|
|
|
return "#version 310 es";
|
2015-08-26 05:09:32 +00:00
|
|
|
case GLSLES_320:
|
|
|
|
return "#version 320 es";
|
2014-03-30 18:58:05 +00:00
|
|
|
case GLSL_130:
|
|
|
|
return "#version 130";
|
|
|
|
case GLSL_140:
|
|
|
|
return "#version 140";
|
|
|
|
case GLSL_150:
|
|
|
|
return "#version 150";
|
2015-09-06 11:58:18 +00:00
|
|
|
case GLSL_330:
|
|
|
|
return "#version 330";
|
|
|
|
case GLSL_400:
|
|
|
|
return "#version 400";
|
2014-12-03 00:20:52 +00:00
|
|
|
default:
|
|
|
|
// Shouldn't ever hit this
|
|
|
|
return "#version ERROR";
|
2014-03-30 18:58:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
void SHADER::SetProgramVariables()
|
2011-12-26 05:15:54 +00:00
|
|
|
{
|
2014-06-07 05:29:21 +00:00
|
|
|
// Bind UBO and texture samplers
|
2014-03-30 18:58:05 +00:00
|
|
|
if (!g_ActiveConfig.backend_info.bSupportsBindingLayout)
|
2011-12-11 10:08:18 +00:00
|
|
|
{
|
2014-06-07 05:29:21 +00:00
|
|
|
// glsl shader must be bind to set samplers if we don't support binding layout
|
|
|
|
Bind();
|
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
GLint PSBlock_id = glGetUniformBlockIndex(glprogid, "PSBlock");
|
|
|
|
GLint VSBlock_id = glGetUniformBlockIndex(glprogid, "VSBlock");
|
2014-12-14 20:23:13 +00:00
|
|
|
GLint GSBlock_id = glGetUniformBlockIndex(glprogid, "GSBlock");
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-03-10 11:30:55 +00:00
|
|
|
if (PSBlock_id != -1)
|
2013-02-13 12:12:19 +00:00
|
|
|
glUniformBlockBinding(glprogid, PSBlock_id, 1);
|
2014-03-10 11:30:55 +00:00
|
|
|
if (VSBlock_id != -1)
|
2013-02-13 12:12:19 +00:00
|
|
|
glUniformBlockBinding(glprogid, VSBlock_id, 2);
|
2014-12-14 20:23:13 +00:00
|
|
|
if (GSBlock_id != -1)
|
|
|
|
glUniformBlockBinding(glprogid, GSBlock_id, 3);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2015-10-11 13:47:15 +00:00
|
|
|
// Bind Texture Samplers
|
2014-06-07 05:29:21 +00:00
|
|
|
for (int a = 0; a <= 9; ++a)
|
|
|
|
{
|
2015-11-04 00:56:02 +00:00
|
|
|
std::string name = StringFromFormat(a < 8 ? "samp[%d]" : "samp%d", a);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-06-07 05:29:21 +00:00
|
|
|
// Still need to get sampler locations since we aren't binding them statically in the shaders
|
2015-11-04 00:56:02 +00:00
|
|
|
int loc = glGetUniformLocation(glprogid, name.c_str());
|
2014-06-07 05:29:21 +00:00
|
|
|
if (loc != -1)
|
|
|
|
glUniform1i(loc, a);
|
|
|
|
}
|
2012-12-31 01:34:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
void SHADER::SetProgramBindings()
|
2012-12-31 01:34:27 +00:00
|
|
|
{
|
2013-01-14 19:00:33 +00:00
|
|
|
if (g_ActiveConfig.backend_info.bSupportsDualSourceBlend)
|
2012-12-31 01:34:27 +00:00
|
|
|
{
|
2013-01-02 15:56:08 +00:00
|
|
|
// So we do support extended blending
|
|
|
|
// So we need to set a few more things here.
|
|
|
|
// Bind our out locations
|
2013-02-13 12:12:19 +00:00
|
|
|
glBindFragDataLocationIndexed(glprogid, 0, 0, "ocol0");
|
|
|
|
glBindFragDataLocationIndexed(glprogid, 0, 1, "ocol1");
|
2013-08-20 12:00:24 +00:00
|
|
|
}
|
2012-12-31 01:34:27 +00:00
|
|
|
// Need to set some attribute locations
|
2013-02-13 12:12:19 +00:00
|
|
|
glBindAttribLocation(glprogid, SHADER_POSITION_ATTRIB, "rawpos");
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-04-24 07:30:05 +00:00
|
|
|
glBindAttribLocation(glprogid, SHADER_POSMTX_ATTRIB, "posmtx");
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
glBindAttribLocation(glprogid, SHADER_COLOR0_ATTRIB, "color0");
|
|
|
|
glBindAttribLocation(glprogid, SHADER_COLOR1_ATTRIB, "color1");
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
glBindAttribLocation(glprogid, SHADER_NORM0_ATTRIB, "rawnorm0");
|
|
|
|
glBindAttribLocation(glprogid, SHADER_NORM1_ATTRIB, "rawnorm1");
|
|
|
|
glBindAttribLocation(glprogid, SHADER_NORM2_ATTRIB, "rawnorm2");
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-08-15 18:09:53 +00:00
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
2015-11-04 00:56:02 +00:00
|
|
|
std::string attrib_name = StringFromFormat("tex%d", i);
|
|
|
|
glBindAttribLocation(glprogid, SHADER_TEXTURE0_ATTRIB+i, attrib_name.c_str());
|
2013-01-14 21:59:08 +00:00
|
|
|
}
|
2011-12-26 05:15:54 +00:00
|
|
|
}
|
2011-12-11 10:14:02 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
void SHADER::Bind()
|
|
|
|
{
|
2014-03-10 11:30:55 +00:00
|
|
|
if (CurrentProgram != glprogid)
|
2013-02-13 12:12:19 +00:00
|
|
|
{
|
2014-06-02 18:11:46 +00:00
|
|
|
INCSTAT(stats.thisFrame.numShaderChanges);
|
2013-02-13 12:12:19 +00:00
|
|
|
glUseProgram(glprogid);
|
|
|
|
CurrentProgram = glprogid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ProgramShaderCache::UploadConstants()
|
2011-12-26 05:15:54 +00:00
|
|
|
{
|
2014-12-14 20:23:13 +00:00
|
|
|
if (PixelShaderManager::dirty || VertexShaderManager::dirty || GeometryShaderManager::dirty)
|
2013-10-07 15:19:47 +00:00
|
|
|
{
|
2014-01-30 15:38:11 +00:00
|
|
|
auto buffer = s_buffer->Map(s_ubo_buffer_size, s_ubo_align);
|
2014-01-22 17:02:55 +00:00
|
|
|
|
2014-01-30 15:38:11 +00:00
|
|
|
memcpy(buffer.first,
|
|
|
|
&PixelShaderManager::constants, sizeof(PixelShaderConstants));
|
2014-01-22 17:02:55 +00:00
|
|
|
|
2014-01-30 15:38:11 +00:00
|
|
|
memcpy(buffer.first + ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align),
|
|
|
|
&VertexShaderManager::constants, sizeof(VertexShaderConstants));
|
2013-10-16 11:27:58 +00:00
|
|
|
|
2014-12-14 20:23:13 +00:00
|
|
|
memcpy(buffer.first + ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align) + ROUND_UP(sizeof(VertexShaderConstants), s_ubo_align),
|
|
|
|
&GeometryShaderManager::constants, sizeof(GeometryShaderConstants));
|
|
|
|
|
2014-01-30 15:38:11 +00:00
|
|
|
s_buffer->Unmap(s_ubo_buffer_size);
|
|
|
|
glBindBufferRange(GL_UNIFORM_BUFFER, 1, s_buffer->m_buffer, buffer.second,
|
|
|
|
sizeof(PixelShaderConstants));
|
|
|
|
glBindBufferRange(GL_UNIFORM_BUFFER, 2, s_buffer->m_buffer, buffer.second + ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align),
|
|
|
|
sizeof(VertexShaderConstants));
|
2014-12-14 20:23:13 +00:00
|
|
|
glBindBufferRange(GL_UNIFORM_BUFFER, 3, s_buffer->m_buffer, buffer.second + ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align) + ROUND_UP(sizeof(VertexShaderConstants), s_ubo_align),
|
|
|
|
sizeof(GeometryShaderConstants));
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-01-30 15:38:11 +00:00
|
|
|
PixelShaderManager::dirty = false;
|
|
|
|
VertexShaderManager::dirty = false;
|
2014-12-14 20:23:13 +00:00
|
|
|
GeometryShaderManager::dirty = false;
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-05-23 19:07:01 +00:00
|
|
|
ADDSTAT(stats.thisFrame.bytesUniformStreamed, s_ubo_buffer_size);
|
2011-12-11 10:32:57 +00:00
|
|
|
}
|
2013-02-13 12:12:19 +00:00
|
|
|
}
|
|
|
|
|
2015-11-01 21:39:31 +00:00
|
|
|
SHADER* ProgramShaderCache::SetShader(DSTALPHA_MODE dstAlphaMode, u32 primitive_type)
|
2013-02-13 12:12:19 +00:00
|
|
|
{
|
|
|
|
SHADERUID uid;
|
2015-11-01 21:39:31 +00:00
|
|
|
GetShaderId(&uid, dstAlphaMode, primitive_type);
|
2013-03-26 21:16:29 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
// Check if the shader is already set
|
|
|
|
if (last_entry)
|
|
|
|
{
|
|
|
|
if (uid == last_uid)
|
|
|
|
{
|
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
|
|
|
last_entry->shader.Bind();
|
|
|
|
return &last_entry->shader;
|
|
|
|
}
|
|
|
|
}
|
2013-03-29 19:33:28 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
last_uid = uid;
|
2013-03-29 19:33:28 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
// Check if shader is already in cache
|
|
|
|
PCache::iterator iter = pshaders.find(uid);
|
2011-12-26 05:15:54 +00:00
|
|
|
if (iter != pshaders.end())
|
2011-12-11 10:32:57 +00:00
|
|
|
{
|
2013-02-13 12:12:19 +00:00
|
|
|
PCacheEntry *entry = &iter->second;
|
|
|
|
last_entry = entry;
|
|
|
|
|
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
|
|
|
last_entry->shader.Bind();
|
|
|
|
return &last_entry->shader;
|
|
|
|
}
|
2013-03-29 19:33:28 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
// Make an entry in the table
|
|
|
|
PCacheEntry& newentry = pshaders[uid];
|
|
|
|
last_entry = &newentry;
|
2013-02-13 15:30:15 +00:00
|
|
|
newentry.in_cache = 0;
|
2013-03-29 19:33:28 +00:00
|
|
|
|
2015-11-03 02:47:05 +00:00
|
|
|
ShaderCode vcode = GenerateVertexShaderCode(API_OPENGL);
|
|
|
|
ShaderCode pcode = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL);
|
2014-10-16 16:52:32 +00:00
|
|
|
ShaderCode gcode;
|
2014-12-19 12:10:06 +00:00
|
|
|
if (g_ActiveConfig.backend_info.bSupportsGeometryShaders && !uid.guid.GetUidData()->IsPassthrough())
|
2015-11-03 02:47:05 +00:00
|
|
|
gcode = GenerateGeometryShaderCode(primitive_type, API_OPENGL);
|
2013-03-29 19:33:28 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
if (g_ActiveConfig.bEnableShaderDebugging)
|
|
|
|
{
|
2013-03-26 21:16:29 +00:00
|
|
|
newentry.shader.strvprog = vcode.GetBuffer();
|
|
|
|
newentry.shader.strpprog = pcode.GetBuffer();
|
2014-10-16 16:52:32 +00:00
|
|
|
newentry.shader.strgprog = gcode.GetBuffer();
|
2011-12-11 11:13:05 +00:00
|
|
|
}
|
2011-12-11 10:08:18 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
#if defined(_DEBUG) || defined(DEBUGFAST)
|
2014-06-03 05:08:54 +00:00
|
|
|
if (g_ActiveConfig.iLog & CONF_SAVESHADERS)
|
|
|
|
{
|
2013-02-13 12:12:19 +00:00
|
|
|
static int counter = 0;
|
2014-06-03 05:08:54 +00:00
|
|
|
std::string filename = StringFromFormat("%svs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
|
|
|
SaveData(filename, vcode.GetBuffer());
|
|
|
|
|
|
|
|
filename = StringFromFormat("%sps_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
|
|
|
SaveData(filename, pcode.GetBuffer());
|
2014-10-16 16:52:32 +00:00
|
|
|
|
2015-12-26 21:00:23 +00:00
|
|
|
if (!gcode.GetBuffer().empty())
|
2014-10-16 16:52:32 +00:00
|
|
|
{
|
|
|
|
filename = StringFromFormat("%sgs_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(), counter++);
|
|
|
|
SaveData(filename, gcode.GetBuffer());
|
|
|
|
}
|
2013-02-13 12:12:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-12-26 05:15:54 +00:00
|
|
|
|
2014-10-16 16:52:32 +00:00
|
|
|
if (!CompileShader(newentry.shader, vcode.GetBuffer(), pcode.GetBuffer(), gcode.GetBuffer()))
|
2014-08-15 18:09:53 +00:00
|
|
|
{
|
2013-02-13 12:12:19 +00:00
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_ERROR, true);
|
2014-03-09 20:14:26 +00:00
|
|
|
return nullptr;
|
2013-02-13 12:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
INCSTAT(stats.numPixelShadersCreated);
|
|
|
|
SETSTAT(stats.numPixelShadersAlive, pshaders.size());
|
|
|
|
GFX_DEBUGGER_PAUSE_AT(NEXT_PIXEL_SHADER_CHANGE, true);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
last_entry->shader.Bind();
|
|
|
|
return &last_entry->shader;
|
|
|
|
}
|
|
|
|
|
2015-12-26 21:00:23 +00:00
|
|
|
bool ProgramShaderCache::CompileShader(SHADER& shader, const std::string& vcode, const std::string& pcode, const std::string& gcode)
|
2013-02-13 12:12:19 +00:00
|
|
|
{
|
|
|
|
GLuint vsid = CompileSingleShader(GL_VERTEX_SHADER, vcode);
|
|
|
|
GLuint psid = CompileSingleShader(GL_FRAGMENT_SHADER, pcode);
|
2013-03-29 19:33:28 +00:00
|
|
|
|
2014-10-16 16:52:32 +00:00
|
|
|
// Optional geometry shader
|
|
|
|
GLuint gsid = 0;
|
2015-12-26 21:00:23 +00:00
|
|
|
if (!gcode.empty())
|
2014-10-16 16:52:32 +00:00
|
|
|
gsid = CompileSingleShader(GL_GEOMETRY_SHADER, gcode);
|
|
|
|
|
2015-12-26 21:00:23 +00:00
|
|
|
if (!vsid || !psid || (!gcode.empty() && !gsid))
|
2013-02-13 12:12:19 +00:00
|
|
|
{
|
|
|
|
glDeleteShader(vsid);
|
|
|
|
glDeleteShader(psid);
|
2014-10-16 16:52:32 +00:00
|
|
|
glDeleteShader(gsid);
|
2013-02-13 12:12:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-09-10 16:17:38 +00:00
|
|
|
GLuint pid = shader.glprogid = glCreateProgram();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
glAttachShader(pid, vsid);
|
|
|
|
glAttachShader(pid, psid);
|
2014-10-31 15:51:37 +00:00
|
|
|
if (gsid)
|
|
|
|
glAttachShader(pid, gsid);
|
2011-12-26 05:15:54 +00:00
|
|
|
|
2013-03-25 14:14:24 +00:00
|
|
|
if (g_ogl_config.bSupportsGLSLCache)
|
2013-02-13 12:12:19 +00:00
|
|
|
glProgramParameteri(pid, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
|
2011-12-26 05:15:54 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
shader.SetProgramBindings();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
glLinkProgram(pid);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
// original shaders aren't needed any more
|
|
|
|
glDeleteShader(vsid);
|
|
|
|
glDeleteShader(psid);
|
2014-10-16 16:52:32 +00:00
|
|
|
glDeleteShader(gsid);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-03-07 19:26:56 +00:00
|
|
|
GLint linkStatus;
|
|
|
|
glGetProgramiv(pid, GL_LINK_STATUS, &linkStatus);
|
2013-02-07 11:47:41 +00:00
|
|
|
GLsizei length = 0;
|
2013-02-13 12:12:19 +00:00
|
|
|
glGetProgramiv(pid, GL_INFO_LOG_LENGTH, &length);
|
2013-03-07 19:26:56 +00:00
|
|
|
if (linkStatus != GL_TRUE || (length > 1 && DEBUG_GLSL))
|
2013-02-07 11:47:41 +00:00
|
|
|
{
|
|
|
|
GLsizei charsWritten;
|
|
|
|
GLchar* infoLog = new GLchar[length];
|
2013-02-13 12:12:19 +00:00
|
|
|
glGetProgramInfoLog(pid, length, &charsWritten, infoLog);
|
2013-02-07 11:47:41 +00:00
|
|
|
ERROR_LOG(VIDEO, "Program info log:\n%s", infoLog);
|
2014-06-03 05:08:54 +00:00
|
|
|
|
|
|
|
std::string filename = StringFromFormat("%sbad_p_%d.txt", File::GetUserPath(D_DUMP_IDX).c_str(), num_failures++);
|
2013-03-07 19:37:28 +00:00
|
|
|
std::ofstream file;
|
2014-06-03 05:08:54 +00:00
|
|
|
OpenFStream(file, filename, std::ios_base::out);
|
2014-10-16 16:52:32 +00:00
|
|
|
file << s_glsl_header << vcode << s_glsl_header << pcode;
|
2015-12-26 21:00:23 +00:00
|
|
|
if (!gcode.empty())
|
2014-10-16 16:52:32 +00:00
|
|
|
file << s_glsl_header << gcode;
|
|
|
|
file << infoLog;
|
2013-03-07 19:37:28 +00:00
|
|
|
file.close();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-03-10 11:30:55 +00:00
|
|
|
if (linkStatus != GL_TRUE)
|
2014-08-15 18:09:53 +00:00
|
|
|
{
|
2015-03-15 15:42:22 +00:00
|
|
|
PanicAlert("Failed to link shaders: %s\n"
|
|
|
|
"Debug info (%s, %s, %s):\n%s",
|
|
|
|
filename.c_str(),
|
|
|
|
g_ogl_config.gl_vendor, g_ogl_config.gl_renderer, g_ogl_config.gl_version, infoLog);
|
2014-08-15 18:09:53 +00:00
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-03-07 19:37:28 +00:00
|
|
|
delete [] infoLog;
|
2013-02-07 11:47:41 +00:00
|
|
|
}
|
|
|
|
if (linkStatus != GL_TRUE)
|
|
|
|
{
|
|
|
|
// Compile failed
|
|
|
|
ERROR_LOG(VIDEO, "Program linking failed; see info log");
|
|
|
|
|
|
|
|
// Don't try to use this shader
|
2013-02-13 12:12:19 +00:00
|
|
|
glDeleteProgram(pid);
|
|
|
|
return false;
|
2013-02-07 11:47:41 +00:00
|
|
|
}
|
2011-12-26 05:15:54 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
shader.SetProgramVariables();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
return true;
|
2011-12-26 05:15:54 +00:00
|
|
|
}
|
|
|
|
|
2015-12-26 21:00:23 +00:00
|
|
|
GLuint ProgramShaderCache::CompileSingleShader(GLuint type, const std::string& code)
|
2011-12-26 05:15:54 +00:00
|
|
|
{
|
2013-02-13 12:12:19 +00:00
|
|
|
GLuint result = glCreateShader(type);
|
|
|
|
|
2015-12-26 21:00:23 +00:00
|
|
|
const char *src[] = {s_glsl_header.c_str(), code.c_str()};
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-03-09 20:14:26 +00:00
|
|
|
glShaderSource(result, 2, src, nullptr);
|
2013-02-13 12:12:19 +00:00
|
|
|
glCompileShader(result);
|
2013-03-07 19:26:56 +00:00
|
|
|
GLint compileStatus;
|
|
|
|
glGetShaderiv(result, GL_COMPILE_STATUS, &compileStatus);
|
2013-02-13 12:12:19 +00:00
|
|
|
GLsizei length = 0;
|
|
|
|
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &length);
|
2013-06-18 15:24:36 +00:00
|
|
|
|
2013-03-07 19:26:56 +00:00
|
|
|
if (compileStatus != GL_TRUE || (length > 1 && DEBUG_GLSL))
|
2013-02-13 12:12:19 +00:00
|
|
|
{
|
|
|
|
GLsizei charsWritten;
|
|
|
|
GLchar* infoLog = new GLchar[length];
|
|
|
|
glGetShaderInfoLog(result, length, &charsWritten, infoLog);
|
2014-10-16 16:52:32 +00:00
|
|
|
ERROR_LOG(VIDEO, "%s Shader info log:\n%s", type==GL_VERTEX_SHADER ? "VS" : type==GL_FRAGMENT_SHADER ? "PS" : "GS", infoLog);
|
2014-06-03 05:08:54 +00:00
|
|
|
|
|
|
|
std::string filename = StringFromFormat("%sbad_%s_%04i.txt",
|
2013-10-29 05:23:17 +00:00
|
|
|
File::GetUserPath(D_DUMP_IDX).c_str(),
|
2014-10-16 16:52:32 +00:00
|
|
|
type==GL_VERTEX_SHADER ? "vs" : type==GL_FRAGMENT_SHADER ? "ps" : "gs",
|
2013-05-04 21:30:13 +00:00
|
|
|
num_failures++);
|
2013-03-07 19:37:28 +00:00
|
|
|
std::ofstream file;
|
2014-06-03 05:08:54 +00:00
|
|
|
OpenFStream(file, filename, std::ios_base::out);
|
2013-08-16 21:05:35 +00:00
|
|
|
file << s_glsl_header << code << infoLog;
|
2013-03-07 19:37:28 +00:00
|
|
|
file.close();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-03-10 11:30:55 +00:00
|
|
|
if (compileStatus != GL_TRUE)
|
2014-08-15 18:09:53 +00:00
|
|
|
{
|
2015-03-15 15:42:22 +00:00
|
|
|
PanicAlert("Failed to compile %s shader: %s\n"
|
|
|
|
"Debug info (%s, %s, %s):\n%s",
|
|
|
|
type == GL_VERTEX_SHADER ? "vertex" : type==GL_FRAGMENT_SHADER ? "pixel" : "geometry",
|
|
|
|
filename.c_str(),
|
|
|
|
g_ogl_config.gl_vendor, g_ogl_config.gl_renderer, g_ogl_config.gl_version, infoLog);
|
2014-08-15 18:09:53 +00:00
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
delete[] infoLog;
|
|
|
|
}
|
|
|
|
if (compileStatus != GL_TRUE)
|
|
|
|
{
|
|
|
|
// Compile failed
|
|
|
|
ERROR_LOG(VIDEO, "Shader compilation failed; see info log");
|
|
|
|
|
|
|
|
// Don't try to use this shader
|
|
|
|
glDeleteShader(result);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-10-26 08:53:22 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
return result;
|
2011-12-26 05:15:54 +00:00
|
|
|
}
|
|
|
|
|
2015-11-01 21:39:31 +00:00
|
|
|
void ProgramShaderCache::GetShaderId(SHADERUID* uid, DSTALPHA_MODE dstAlphaMode, u32 primitive_type)
|
2011-12-26 05:15:54 +00:00
|
|
|
{
|
2015-11-03 02:47:05 +00:00
|
|
|
uid->puid = GetPixelShaderUid(dstAlphaMode, API_OPENGL);
|
|
|
|
uid->vuid = GetVertexShaderUid(API_OPENGL);
|
|
|
|
uid->guid = GetGeometryShaderUid(primitive_type, API_OPENGL);
|
2013-04-29 19:00:39 +00:00
|
|
|
|
|
|
|
if (g_ActiveConfig.bEnableShaderDebugging)
|
|
|
|
{
|
2015-11-03 02:47:05 +00:00
|
|
|
ShaderCode pcode = GeneratePixelShaderCode(dstAlphaMode, API_OPENGL);
|
2013-04-29 19:00:39 +00:00
|
|
|
pixel_uid_checker.AddToIndexAndCheck(pcode, uid->puid, "Pixel", "p");
|
|
|
|
|
2015-11-03 02:47:05 +00:00
|
|
|
ShaderCode vcode = GenerateVertexShaderCode(API_OPENGL);
|
2013-04-29 19:00:39 +00:00
|
|
|
vertex_uid_checker.AddToIndexAndCheck(vcode, uid->vuid, "Vertex", "v");
|
2014-10-16 16:52:32 +00:00
|
|
|
|
2015-11-03 02:47:05 +00:00
|
|
|
ShaderCode gcode = GenerateGeometryShaderCode(primitive_type, API_OPENGL);
|
2014-10-16 16:52:32 +00:00
|
|
|
geometry_uid_checker.AddToIndexAndCheck(gcode, uid->guid, "Geometry", "g");
|
2013-04-29 19:00:39 +00:00
|
|
|
}
|
2013-03-29 13:54:44 +00:00
|
|
|
}
|
2013-02-13 12:12:19 +00:00
|
|
|
|
2014-08-15 18:09:53 +00:00
|
|
|
ProgramShaderCache::PCacheEntry ProgramShaderCache::GetShaderProgram()
|
2011-12-26 05:15:54 +00:00
|
|
|
{
|
2013-02-13 12:12:19 +00:00
|
|
|
return *last_entry;
|
2011-12-26 05:15:54 +00:00
|
|
|
}
|
|
|
|
|
2014-08-15 18:09:53 +00:00
|
|
|
void ProgramShaderCache::Init()
|
2011-12-26 05:15:54 +00:00
|
|
|
{
|
|
|
|
// We have to get the UBO alignment here because
|
|
|
|
// if we generate a buffer that isn't aligned
|
|
|
|
// then the UBO will fail.
|
2014-01-30 15:38:11 +00:00
|
|
|
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &s_ubo_align);
|
2011-12-26 05:15:54 +00:00
|
|
|
|
2014-12-14 20:23:13 +00:00
|
|
|
s_ubo_buffer_size = ROUND_UP(sizeof(PixelShaderConstants), s_ubo_align) + ROUND_UP(sizeof(VertexShaderConstants), s_ubo_align) + ROUND_UP(sizeof(GeometryShaderConstants), s_ubo_align);
|
2011-12-26 05:15:54 +00:00
|
|
|
|
2014-01-30 15:38:11 +00:00
|
|
|
// We multiply by *4*4 because we need to get down to basic machine units.
|
|
|
|
// So multiply by four to get how many floats we have from vec4s
|
|
|
|
// Then once more to get bytes
|
|
|
|
s_buffer = StreamBuffer::Create(GL_UNIFORM_BUFFER, UBO_LENGTH);
|
2011-12-26 05:15:54 +00:00
|
|
|
|
|
|
|
// Read our shader cache, only if supported
|
2013-12-09 15:45:20 +00:00
|
|
|
if (g_ogl_config.bSupportsGLSLCache && !g_Config.bEnableShaderDebugging)
|
2011-12-11 10:19:11 +00:00
|
|
|
{
|
2013-02-13 15:30:15 +00:00
|
|
|
GLint Supported;
|
|
|
|
glGetIntegerv(GL_NUM_PROGRAM_BINARY_FORMATS, &Supported);
|
2014-03-10 11:30:55 +00:00
|
|
|
if (!Supported)
|
2013-02-13 15:30:15 +00:00
|
|
|
{
|
|
|
|
ERROR_LOG(VIDEO, "GL_ARB_get_program_binary is supported, but no binary format is known. So disable shader cache.");
|
2013-03-25 14:14:24 +00:00
|
|
|
g_ogl_config.bSupportsGLSLCache = false;
|
2013-02-13 15:30:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-02-13 15:50:56 +00:00
|
|
|
if (!File::Exists(File::GetUserPath(D_SHADERCACHE_IDX)))
|
2014-03-12 19:33:41 +00:00
|
|
|
File::CreateDir(File::GetUserPath(D_SHADERCACHE_IDX));
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-06-03 05:08:54 +00:00
|
|
|
std::string cache_filename = StringFromFormat("%sogl-%s-shaders.cache", File::GetUserPath(D_SHADERCACHE_IDX).c_str(),
|
2015-06-12 11:56:53 +00:00
|
|
|
SConfig::GetInstance().m_strUniqueID.c_str());
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 15:30:15 +00:00
|
|
|
ProgramShaderCacheInserter inserter;
|
|
|
|
g_program_disk_cache.OpenAndRead(cache_filename, inserter);
|
|
|
|
}
|
|
|
|
SETSTAT(stats.numPixelShadersAlive, pshaders.size());
|
2011-12-11 10:19:11 +00:00
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 20:34:48 +00:00
|
|
|
CreateHeader();
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-01-15 13:22:40 +00:00
|
|
|
CurrentProgram = 0;
|
2014-03-09 20:14:26 +00:00
|
|
|
last_entry = nullptr;
|
2011-12-26 05:15:54 +00:00
|
|
|
}
|
|
|
|
|
2014-08-15 18:09:53 +00:00
|
|
|
void ProgramShaderCache::Shutdown()
|
2011-12-26 05:15:54 +00:00
|
|
|
{
|
2013-02-13 15:30:15 +00:00
|
|
|
// store all shaders in cache on disk
|
2013-12-09 15:45:20 +00:00
|
|
|
if (g_ogl_config.bSupportsGLSLCache && !g_Config.bEnableShaderDebugging)
|
2011-12-11 10:08:18 +00:00
|
|
|
{
|
2014-03-03 05:25:15 +00:00
|
|
|
for (auto& entry : pshaders)
|
2011-12-26 15:27:18 +00:00
|
|
|
{
|
2015-03-02 13:59:18 +00:00
|
|
|
// Clear any prior error code
|
|
|
|
glGetError();
|
|
|
|
|
2014-03-10 11:30:55 +00:00
|
|
|
if (entry.second.in_cache)
|
2014-03-03 05:25:15 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2015-03-02 13:59:18 +00:00
|
|
|
GLint link_status = GL_FALSE, delete_status = GL_TRUE, binary_size = 0;
|
|
|
|
glGetProgramiv(entry.second.shader.glprogid, GL_LINK_STATUS, &link_status);
|
|
|
|
glGetProgramiv(entry.second.shader.glprogid, GL_DELETE_STATUS, &delete_status);
|
2014-03-03 05:25:15 +00:00
|
|
|
glGetProgramiv(entry.second.shader.glprogid, GL_PROGRAM_BINARY_LENGTH, &binary_size);
|
2015-03-02 13:59:18 +00:00
|
|
|
if (glGetError() != GL_NO_ERROR || link_status == GL_FALSE || delete_status == GL_TRUE || !binary_size)
|
2014-03-03 05:25:15 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2015-03-02 13:59:18 +00:00
|
|
|
std::vector<u8> data(binary_size + sizeof(GLenum));
|
|
|
|
u8* binary = &data[sizeof(GLenum)];
|
|
|
|
GLenum* prog_format = (GLenum*)&data[0];
|
2014-03-09 20:14:26 +00:00
|
|
|
glGetProgramBinary(entry.second.shader.glprogid, binary_size, nullptr, prog_format, binary);
|
2015-03-02 13:59:18 +00:00
|
|
|
if (glGetError() != GL_NO_ERROR)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2015-03-02 13:59:18 +00:00
|
|
|
g_program_disk_cache.Append(entry.first, &data[0], binary_size + sizeof(GLenum));
|
2011-12-26 15:27:18 +00:00
|
|
|
}
|
2011-12-11 10:11:57 +00:00
|
|
|
|
2011-12-26 05:15:54 +00:00
|
|
|
g_program_disk_cache.Sync();
|
|
|
|
g_program_disk_cache.Close();
|
|
|
|
}
|
|
|
|
|
2013-01-15 16:10:43 +00:00
|
|
|
glUseProgram(0);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-03-03 05:25:15 +00:00
|
|
|
for (auto& entry : pshaders)
|
|
|
|
{
|
|
|
|
entry.second.Destroy();
|
|
|
|
}
|
2011-12-26 05:15:54 +00:00
|
|
|
pshaders.clear();
|
|
|
|
|
2013-04-29 19:00:39 +00:00
|
|
|
pixel_uid_checker.Invalidate();
|
|
|
|
vertex_uid_checker.Invalidate();
|
|
|
|
|
2015-12-21 15:15:17 +00:00
|
|
|
s_buffer.reset();
|
2011-12-01 03:00:21 +00:00
|
|
|
}
|
|
|
|
|
2014-08-15 18:09:53 +00:00
|
|
|
void ProgramShaderCache::CreateHeader()
|
2013-02-13 20:34:48 +00:00
|
|
|
{
|
2013-04-08 12:50:58 +00:00
|
|
|
GLSL_VERSION v = g_ogl_config.eSupportedGLSLVersion;
|
2015-02-28 01:38:51 +00:00
|
|
|
bool is_glsles = v >= GLSLES_300;
|
2015-08-26 05:09:32 +00:00
|
|
|
std::string SupportedESPointSize;
|
2015-09-01 10:23:43 +00:00
|
|
|
std::string SupportedESTextureBuffer;
|
2015-08-26 05:09:32 +00:00
|
|
|
switch (g_ogl_config.SupportedESPointSize)
|
|
|
|
{
|
|
|
|
case 1: SupportedESPointSize = "#extension GL_OES_geometry_point_size : enable"; break;
|
|
|
|
case 2: SupportedESPointSize = "#extension GL_EXT_geometry_point_size : enable"; break;
|
|
|
|
default: SupportedESPointSize = ""; break;
|
|
|
|
}
|
2014-12-07 05:29:36 +00:00
|
|
|
|
2015-09-01 10:23:43 +00:00
|
|
|
switch (g_ogl_config.SupportedESTextureBuffer)
|
|
|
|
{
|
|
|
|
case ES_TEXBUF_TYPE::TEXBUF_EXT:
|
|
|
|
SupportedESTextureBuffer = "#extension GL_EXT_texture_buffer : enable";
|
|
|
|
break;
|
|
|
|
case ES_TEXBUF_TYPE::TEXBUF_OES:
|
|
|
|
SupportedESTextureBuffer = "#extension GL_OES_texture_buffer : enable";
|
|
|
|
break;
|
|
|
|
case ES_TEXBUF_TYPE::TEXBUF_CORE:
|
|
|
|
case ES_TEXBUF_TYPE::TEXBUF_NONE:
|
|
|
|
SupportedESTextureBuffer = "";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-10-17 13:37:14 +00:00
|
|
|
std::string earlyz_string = "";
|
|
|
|
if (g_ActiveConfig.backend_info.bSupportsEarlyZ)
|
2015-10-17 11:43:22 +00:00
|
|
|
{
|
|
|
|
if (g_ogl_config.bSupportsEarlyFragmentTests)
|
|
|
|
{
|
2015-10-17 13:37:14 +00:00
|
|
|
earlyz_string = "#define FORCE_EARLY_Z layout(early_fragment_tests) in\n";
|
|
|
|
if (!is_glsles) // GLES supports this by default
|
|
|
|
earlyz_string += "#extension GL_ARB_shader_image_load_store : enable\n";
|
2015-10-17 11:43:22 +00:00
|
|
|
}
|
|
|
|
else if(g_ogl_config.bSupportsConservativeDepth)
|
|
|
|
{
|
|
|
|
// See PixelShaderGen for details about this fallback.
|
2015-10-17 13:37:14 +00:00
|
|
|
earlyz_string = "#define FORCE_EARLY_Z layout(depth_unchanged) out float gl_FragDepth\n";
|
|
|
|
earlyz_string += "#extension GL_ARB_conservative_depth : enable\n";
|
2015-10-17 11:43:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-04 00:56:02 +00:00
|
|
|
s_glsl_header = StringFromFormat(
|
2013-10-06 08:12:13 +00:00
|
|
|
"%s\n"
|
2013-02-13 20:34:48 +00:00
|
|
|
"%s\n" // ubo
|
2013-08-21 09:48:39 +00:00
|
|
|
"%s\n" // early-z
|
2014-01-05 09:38:45 +00:00
|
|
|
"%s\n" // 420pack
|
2014-05-01 10:45:05 +00:00
|
|
|
"%s\n" // msaa
|
2014-06-07 05:29:21 +00:00
|
|
|
"%s\n" // Sampler binding
|
2014-11-13 22:26:49 +00:00
|
|
|
"%s\n" // storage buffer
|
2014-10-16 16:52:32 +00:00
|
|
|
"%s\n" // shader5
|
2015-09-07 20:21:11 +00:00
|
|
|
"%s\n" // SSAA
|
2015-08-26 05:09:32 +00:00
|
|
|
"%s\n" // Geometry point size
|
2014-12-07 05:29:36 +00:00
|
|
|
"%s\n" // AEP
|
2015-02-20 23:12:27 +00:00
|
|
|
"%s\n" // texture buffer
|
2015-09-01 10:23:43 +00:00
|
|
|
"%s\n" // ES texture buffer
|
2015-09-05 01:25:59 +00:00
|
|
|
"%s\n" // ES dual source blend
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2014-03-30 18:58:05 +00:00
|
|
|
// Precision defines for GLSL ES
|
2013-10-06 08:12:13 +00:00
|
|
|
"%s\n"
|
2013-10-06 22:52:34 +00:00
|
|
|
"%s\n"
|
2014-11-29 07:27:47 +00:00
|
|
|
"%s\n"
|
2015-09-01 10:23:43 +00:00
|
|
|
"%s\n"
|
2015-09-01 05:17:24 +00:00
|
|
|
"%s\n"
|
2013-10-06 08:12:13 +00:00
|
|
|
|
2013-02-13 20:34:48 +00:00
|
|
|
// Silly differences
|
|
|
|
"#define float2 vec2\n"
|
|
|
|
"#define float3 vec3\n"
|
|
|
|
"#define float4 vec4\n"
|
2013-08-14 13:06:47 +00:00
|
|
|
"#define uint2 uvec2\n"
|
|
|
|
"#define uint3 uvec3\n"
|
|
|
|
"#define uint4 uvec4\n"
|
2013-11-25 14:49:13 +00:00
|
|
|
"#define int2 ivec2\n"
|
|
|
|
"#define int3 ivec3\n"
|
|
|
|
"#define int4 ivec4\n"
|
2013-02-13 20:34:48 +00:00
|
|
|
|
2013-06-18 12:52:36 +00:00
|
|
|
// hlsl to glsl function translation
|
2013-06-18 17:42:14 +00:00
|
|
|
"#define frac fract\n"
|
|
|
|
"#define lerp mix\n"
|
2013-06-18 12:52:36 +00:00
|
|
|
|
2014-03-30 18:58:05 +00:00
|
|
|
, GetGLSLVersionString().c_str()
|
2015-09-06 11:58:18 +00:00
|
|
|
, v < GLSL_140 ? "#extension GL_ARB_uniform_buffer_object : enable" : ""
|
2015-10-17 13:37:14 +00:00
|
|
|
, earlyz_string.c_str()
|
2014-03-30 18:58:05 +00:00
|
|
|
, (g_ActiveConfig.backend_info.bSupportsBindingLayout && v < GLSLES_310) ? "#extension GL_ARB_shading_language_420pack : enable" : ""
|
2014-05-01 10:45:05 +00:00
|
|
|
, (g_ogl_config.bSupportsMSAA && v < GLSL_150) ? "#extension GL_ARB_texture_multisample : enable" : ""
|
2014-06-07 05:29:21 +00:00
|
|
|
, g_ActiveConfig.backend_info.bSupportsBindingLayout ? "#define SAMPLER_BINDING(x) layout(binding = x)" : "#define SAMPLER_BINDING(x)"
|
2015-11-23 20:47:43 +00:00
|
|
|
, !is_glsles && g_ActiveConfig.backend_info.bSupportsBBox ? "#extension GL_ARB_shader_storage_buffer_object : enable" : ""
|
2015-09-06 11:58:18 +00:00
|
|
|
, v < GLSL_400 && g_ActiveConfig.backend_info.bSupportsGSInstancing ? "#extension GL_ARB_gpu_shader5 : enable" : ""
|
2015-09-07 20:21:11 +00:00
|
|
|
, v < GLSL_400 && g_ActiveConfig.backend_info.bSupportsSSAA ? "#extension GL_ARB_sample_shading : enable" : ""
|
2015-08-26 05:09:32 +00:00
|
|
|
, SupportedESPointSize.c_str()
|
2014-12-07 05:29:36 +00:00
|
|
|
, g_ogl_config.bSupportsAEP ? "#extension GL_ANDROID_extension_pack_es31a : enable" : ""
|
2015-09-06 11:58:18 +00:00
|
|
|
, v < GLSL_140 && g_ActiveConfig.backend_info.bSupportsPaletteConversion ? "#extension GL_ARB_texture_buffer_object : enable" : ""
|
2015-09-01 10:23:43 +00:00
|
|
|
, SupportedESTextureBuffer.c_str()
|
2015-09-05 01:25:59 +00:00
|
|
|
, is_glsles && g_ActiveConfig.backend_info.bSupportsDualSourceBlend ? "#extension GL_EXT_blend_func_extended : enable" : ""
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2015-02-28 01:38:51 +00:00
|
|
|
, is_glsles ? "precision highp float;" : ""
|
|
|
|
, is_glsles ? "precision highp int;" : ""
|
|
|
|
, is_glsles ? "precision highp sampler2DArray;" : ""
|
2015-09-01 10:23:43 +00:00
|
|
|
, (is_glsles && g_ActiveConfig.backend_info.bSupportsPaletteConversion) ? "precision highp usamplerBuffer;" : ""
|
2015-09-01 05:17:24 +00:00
|
|
|
, v > GLSLES_300 ? "precision highp sampler2DMS;" : ""
|
2013-02-13 20:34:48 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-15 18:15:23 +00:00
|
|
|
void ProgramShaderCache::ProgramShaderCacheInserter::Read(const SHADERUID& key, const u8* value, u32 value_size)
|
2013-02-13 12:12:19 +00:00
|
|
|
{
|
2013-02-13 15:30:15 +00:00
|
|
|
const u8 *binary = value+sizeof(GLenum);
|
|
|
|
GLenum *prog_format = (GLenum*)value;
|
|
|
|
GLint binary_size = value_size-sizeof(GLenum);
|
2013-10-29 05:23:17 +00:00
|
|
|
|
2013-02-13 12:12:19 +00:00
|
|
|
PCacheEntry entry;
|
2013-02-13 15:30:15 +00:00
|
|
|
entry.in_cache = 1;
|
2013-02-13 12:12:19 +00:00
|
|
|
entry.shader.glprogid = glCreateProgram();
|
2013-02-13 15:30:15 +00:00
|
|
|
glProgramBinary(entry.shader.glprogid, *prog_format, binary, binary_size);
|
2013-02-13 12:12:19 +00:00
|
|
|
|
|
|
|
GLint success;
|
|
|
|
glGetProgramiv(entry.shader.glprogid, GL_LINK_STATUS, &success);
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
{
|
|
|
|
pshaders[key] = entry;
|
|
|
|
entry.shader.SetProgramVariables();
|
|
|
|
}
|
2013-02-13 15:30:15 +00:00
|
|
|
else
|
2014-08-15 18:09:53 +00:00
|
|
|
{
|
2013-02-13 15:30:15 +00:00
|
|
|
glDeleteProgram(entry.shader.glprogid);
|
2014-08-15 18:09:53 +00:00
|
|
|
}
|
2013-02-13 12:12:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-26 05:15:54 +00:00
|
|
|
} // namespace OGL
|