Support reloading the shader compiler

Trac #19900 Issue=291 - Move compiler initialization to a separate function - all this function to ensure the compiler is loaded when a compile is attempted (previously if the compiler was released, you'd have to create a new shader object to get it reloaded). Signed-off-by: Shannon Woods Signed-off-by: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@992 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 938009cf
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 0 #define MINOR_VERSION 0
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 985 #define BUILD_REVISION 992
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -28,33 +28,7 @@ Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mReso ...@@ -28,33 +28,7 @@ Shader::Shader(ResourceManager *manager, GLuint handle) : mHandle(handle), mReso
mInfoLog = NULL; mInfoLog = NULL;
uncompile(); uncompile();
initializeCompiler();
// Perform a one-time initialization of the shader compiler (or after being destructed by releaseCompiler)
if (!mFragmentCompiler)
{
int result = ShInitialize();
if (result)
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
Context *context = getContext();
resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS;
resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS;
resources.MaxVaryingVectors = context->getMaximumVaryingVectors();
resources.MaxVertexTextureImageUnits = context->getMaximumVertexTextureImageUnits();
resources.MaxCombinedTextureImageUnits = context->getMaximumCombinedTextureImageUnits();
resources.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
resources.MaxFragmentUniformVectors = context->getMaximumFragmentUniformVectors();
resources.MaxDrawBuffers = MAX_DRAW_BUFFERS;
resources.OES_standard_derivatives = 1;
// resources.OES_EGL_image_external = getDisplay()->isD3d9ExDevice() ? 1 : 0; // TODO: commented out until the extension is actually supported.
mFragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, SH_HLSL_OUTPUT, &resources);
mVertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, SH_HLSL_OUTPUT, &resources);
}
}
mRefCount = 0; mRefCount = 0;
mDeleteStatus = false; mDeleteStatus = false;
...@@ -246,6 +220,36 @@ void Shader::flagForDeletion() ...@@ -246,6 +220,36 @@ void Shader::flagForDeletion()
mDeleteStatus = true; mDeleteStatus = true;
} }
// Perform a one-time initialization of the shader compiler (or after being destructed by releaseCompiler)
void Shader::initializeCompiler()
{
if (!mFragmentCompiler)
{
int result = ShInitialize();
if (result)
{
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
Context *context = getContext();
resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS;
resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS;
resources.MaxVaryingVectors = context->getMaximumVaryingVectors();
resources.MaxVertexTextureImageUnits = context->getMaximumVertexTextureImageUnits();
resources.MaxCombinedTextureImageUnits = context->getMaximumCombinedTextureImageUnits();
resources.MaxTextureImageUnits = MAX_TEXTURE_IMAGE_UNITS;
resources.MaxFragmentUniformVectors = context->getMaximumFragmentUniformVectors();
resources.MaxDrawBuffers = MAX_DRAW_BUFFERS;
resources.OES_standard_derivatives = 1;
// resources.OES_EGL_image_external = getDisplay()->isD3d9ExDevice() ? 1 : 0; // TODO: commented out until the extension is actually supported.
mFragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, SH_HLSL_OUTPUT, &resources);
mVertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, SH_HLSL_OUTPUT, &resources);
}
}
}
void Shader::releaseCompiler() void Shader::releaseCompiler()
{ {
ShDestruct(mFragmentCompiler); ShDestruct(mFragmentCompiler);
...@@ -323,6 +327,9 @@ void Shader::compileToHLSL(void *compiler) ...@@ -323,6 +327,9 @@ void Shader::compileToHLSL(void *compiler)
source = mSource; source = mSource;
} }
// ensure the compiler is loaded
initializeCompiler();
int compileOptions = SH_OBJECT_CODE; int compileOptions = SH_OBJECT_CODE;
std::string sourcePath; std::string sourcePath;
if (perfActive()) if (perfActive())
......
...@@ -97,6 +97,8 @@ class Shader ...@@ -97,6 +97,8 @@ class Shader
private: private:
DISALLOW_COPY_AND_ASSIGN(Shader); DISALLOW_COPY_AND_ASSIGN(Shader);
void initializeCompiler();
const GLuint mHandle; const GLuint mHandle;
unsigned int mRefCount; // Number of program objects this shader is attached to unsigned int mRefCount; // Number of program objects this shader is attached to
bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment