Commit 21c51c7d by Nicolas Capens

Eliminate the abstract shader compiler interface.

Bug 19331817 Change-Id: I13bc44264ac8727aa246f25960e054ab2875ecec Reviewed-on: https://swiftshader-review.googlesource.com/2152Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 7a8ccc48
...@@ -7,13 +7,6 @@ ...@@ -7,13 +7,6 @@
#ifndef _SHHANDLE_INCLUDED_ #ifndef _SHHANDLE_INCLUDED_
#define _SHHANDLE_INCLUDED_ #define _SHHANDLE_INCLUDED_
//
// Machine independent part of the compiler private objects
// sent as ShHandle to the driver.
//
// This should not be included by driver code.
//
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "ExtensionBehavior.h" #include "ExtensionBehavior.h"
......
...@@ -38,137 +38,22 @@ int ShFinalize() ...@@ -38,137 +38,22 @@ int ShFinalize()
// //
// Initialize built-in resources with minimum expected values. // Initialize built-in resources with minimum expected values.
// //
void ShInitBuiltInResources(ShBuiltInResources* resources) ShBuiltInResources::ShBuiltInResources()
{ {
// Constants. // Constants.
resources->MaxVertexAttribs = 8; MaxVertexAttribs = 8;
resources->MaxVertexUniformVectors = 128; MaxVertexUniformVectors = 128;
resources->MaxVaryingVectors = 8; MaxVaryingVectors = 8;
resources->MaxVertexTextureImageUnits = 0; MaxVertexTextureImageUnits = 0;
resources->MaxCombinedTextureImageUnits = 8; MaxCombinedTextureImageUnits = 8;
resources->MaxTextureImageUnits = 8; MaxTextureImageUnits = 8;
resources->MaxFragmentUniformVectors = 16; MaxFragmentUniformVectors = 16;
resources->MaxDrawBuffers = 1; MaxDrawBuffers = 1;
// Extensions. // Extensions.
resources->OES_standard_derivatives = 0; OES_standard_derivatives = 0;
resources->OES_fragment_precision_high = 0; OES_fragment_precision_high = 0;
resources->OES_EGL_image_external = 0; OES_EGL_image_external = 0;
resources->MaxCallStackDepth = UINT_MAX; MaxCallStackDepth = UINT_MAX;
}
//
// Driver calls these to create and destroy compiler objects.
//
ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources* resources)
{
TCompiler* base = ConstructCompiler(type, spec);
TCompiler* compiler = base->getAsCompiler();
if (compiler == 0)
return 0;
// Generate built-in symbol table.
if (!compiler->Init(*resources)) {
ShDestruct(base);
return 0;
}
return reinterpret_cast<void*>(base);
}
void ShDestruct(ShHandle handle)
{
if (handle == 0)
return;
TCompiler* base = static_cast<TCompiler*>(handle);
if (base->getAsCompiler())
DeleteCompiler(base->getAsCompiler());
}
//
// Do an actual compile on the given strings. The result is left
// in the given compile object.
//
// Return: The return value of ShCompile is really boolean, indicating
// success or failure.
//
int ShCompile(
const ShHandle handle,
const char* const shaderStrings[],
const int numStrings,
int compileOptions)
{
if (handle == 0)
return 0;
TCompiler* base = reinterpret_cast<TCompiler*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (compiler == 0)
return 0;
bool success = compiler->compile(shaderStrings, numStrings, compileOptions);
return success ? 1 : 0;
}
void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params)
{
if (!handle || !params)
return;
TCompiler* base = static_cast<TCompiler*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (!compiler) return;
switch(pname)
{
case SH_INFO_LOG_LENGTH:
*params = compiler->getInfoSink().info.size() + 1;
break;
case SH_OBJECT_CODE_LENGTH:
*params = compiler->getInfoSink().obj.size() + 1;
break;
case SH_ACTIVE_UNIFORM_MAX_LENGTH:
*params = 1 + MAX_SYMBOL_NAME_LEN;
break;
case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH:
*params = 1 + MAX_SYMBOL_NAME_LEN;
break;
default: UNREACHABLE();
}
}
//
// Return any compiler log of messages for the application.
//
void ShGetInfoLog(const ShHandle handle, char* infoLog)
{
if (!handle || !infoLog)
return;
TCompiler* base = static_cast<TCompiler*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (!compiler) return;
TInfoSink& infoSink = compiler->getInfoSink();
strcpy(infoLog, infoSink.info.c_str());
}
//
// Return any object code.
//
void ShGetObjectCode(const ShHandle handle, char* objCode)
{
if (!handle || !objCode)
return;
TCompiler* base = static_cast<TCompiler*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (!compiler) return;
TInfoSink& infoSink = compiler->getInfoSink();
strcpy(objCode, infoSink.obj.c_str());
} }
...@@ -69,8 +69,10 @@ int ShFinalize(); ...@@ -69,8 +69,10 @@ int ShFinalize();
// Implementation dependent built-in resources (constants and extensions). // Implementation dependent built-in resources (constants and extensions).
// The names for these resources has been obtained by stripping gl_/GL_. // The names for these resources has been obtained by stripping gl_/GL_.
// //
typedef struct struct ShBuiltInResources
{ {
ShBuiltInResources();
// Constants. // Constants.
int MaxVertexAttribs; int MaxVertexAttribs;
int MaxVertexUniformVectors; int MaxVertexUniformVectors;
...@@ -88,109 +90,7 @@ typedef struct ...@@ -88,109 +90,7 @@ typedef struct
int OES_EGL_image_external; int OES_EGL_image_external;
unsigned int MaxCallStackDepth; unsigned int MaxCallStackDepth;
} ShBuiltInResources; };
//
// Initialize built-in resources with minimum expected values.
//
void ShInitBuiltInResources(ShBuiltInResources* resources);
//
// ShHandle held by but opaque to the driver. It is allocated,
// managed, and de-allocated by the compiler. It's contents
// are defined by and used by the compiler.
//
// If handle creation fails, 0 will be returned.
//
typedef void* ShHandle;
//
// Driver calls these to create and destroy compiler objects.
//
// Returns the handle of constructed compiler.
// Parameters:
// type: Specifies the type of shader - SH_FRAGMENT_SHADER or SH_VERTEX_SHADER.
// spec: Specifies the language spec the compiler must conform to -
// SH_GLES2_SPEC or SH_WEBGL_SPEC.
// resources: Specifies the built-in resources.
ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources* resources);
void ShDestruct(ShHandle handle);
//
// Compiles the given shader source.
// If the function succeeds, the return value is nonzero, else zero.
// Parameters:
// handle: Specifies the handle of compiler to be used.
// shaderStrings: Specifies an array of pointers to null-terminated strings
// containing the shader source code.
// numStrings: Specifies the number of elements in shaderStrings array.
// compileOptions: A mask containing the following parameters:
// SH_VALIDATE: Validates shader to ensure that it conforms to the spec
// specified during compiler construction.
// SH_VALIDATE_LOOP_INDEXING: Validates loop and indexing in the shader to
// ensure that they do not exceed the minimum
// functionality mandated in GLSL 1.0 spec,
// Appendix A, Section 4 and 5.
// There is no need to specify this parameter when
// compiling for WebGL - it is implied.
// SH_INTERMEDIATE_TREE: Writes intermediate tree to info log.
// Can be queried by calling ShGetInfoLog().
// SH_OBJECT_CODE: Translates intermediate tree to glsl or hlsl shader.
// Can be queried by calling ShGetObjectCode().
// SH_ATTRIBUTES_UNIFORMS: Extracts attributes and uniforms.
// Can be queried by calling ShGetActiveAttrib() and
// ShGetActiveUniform().
//
int ShCompile(
const ShHandle handle,
const char* const shaderStrings[],
const int numStrings,
int compileOptions
);
// Returns a parameter from a compiled shader.
// Parameters:
// handle: Specifies the compiler
// pname: Specifies the parameter to query.
// The following parameters are defined:
// SH_INFO_LOG_LENGTH: the number of characters in the information log
// including the null termination character.
// SH_OBJECT_CODE_LENGTH: the number of characters in the object code
// including the null termination character.
// SH_ACTIVE_ATTRIBUTES: the number of active attribute variables.
// SH_ACTIVE_ATTRIBUTE_MAX_LENGTH: the length of the longest active attribute
// variable name including the null
// termination character.
// SH_ACTIVE_UNIFORMS: the number of active uniform variables.
// SH_ACTIVE_UNIFORM_MAX_LENGTH: the length of the longest active uniform
// variable name including the null
// termination character.
// SH_MAPPED_NAME_MAX_LENGTH: the length of the mapped variable name including
// the null termination character.
//
// params: Requested parameter
void ShGetInfo(const ShHandle handle, ShShaderInfo pname, int* params);
// Returns nul-terminated information log for a compiled shader.
// Parameters:
// handle: Specifies the compiler
// infoLog: Specifies an array of characters that is used to return
// the information log. It is assumed that infoLog has enough memory
// to accomodate the information log. The size of the buffer required
// to store the returned information log can be obtained by calling
// ShGetInfo with SH_INFO_LOG_LENGTH.
void ShGetInfoLog(const ShHandle handle, char* infoLog);
// Returns null-terminated object code for a compiled shader.
// Parameters:
// handle: Specifies the compiler
// infoLog: Specifies an array of characters that is used to return
// the object code. It is assumed that infoLog has enough memory to
// accomodate the object code. The size of the buffer required to
// store the returned object code can be obtained by calling
// ShGetInfo with SH_OBJECT_CODE_LENGTH.
void ShGetObjectCode(const ShHandle handle, char* objCode);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -165,7 +165,6 @@ TranslatorASM *Shader::createCompiler(ShShaderType type) ...@@ -165,7 +165,6 @@ TranslatorASM *Shader::createCompiler(ShShaderType type)
TranslatorASM *assembler = new TranslatorASM(this, type, SH_GLES2_SPEC); TranslatorASM *assembler = new TranslatorASM(this, type, SH_GLES2_SPEC);
ShBuiltInResources resources; ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS; resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS;
resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS; resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS;
resources.MaxVaryingVectors = MAX_VARYING_VECTORS; resources.MaxVaryingVectors = MAX_VARYING_VECTORS;
...@@ -382,7 +381,7 @@ void VertexShader::compile() ...@@ -382,7 +381,7 @@ void VertexShader::compile()
source = mSource; source = mSource;
} }
int success = ShCompile(compiler, &source, 1, SH_OBJECT_CODE); bool success = compiler->compile(&source, 1, SH_OBJECT_CODE);
if(false) if(false)
{ {
...@@ -401,10 +400,9 @@ void VertexShader::compile() ...@@ -401,10 +400,9 @@ void VertexShader::compile()
delete vertexShader; delete vertexShader;
vertexShader = 0; vertexShader = 0;
int infoLogLen = 0; int infoLogLen = compiler->getInfoSink().info.size() + 1;
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
mInfoLog = new char[infoLogLen]; mInfoLog = new char[infoLogLen];
ShGetInfoLog(compiler, mInfoLog); strcpy(mInfoLog, compiler->getInfoSink().info.c_str());
TRACE("\n%s", mInfoLog); TRACE("\n%s", mInfoLog);
} }
...@@ -468,7 +466,7 @@ void FragmentShader::compile() ...@@ -468,7 +466,7 @@ void FragmentShader::compile()
source = mSource; source = mSource;
} }
int success = ShCompile(compiler, &source, 1, SH_OBJECT_CODE); bool success = compiler->compile(&source, 1, SH_OBJECT_CODE);
if(false) if(false)
{ {
...@@ -487,10 +485,9 @@ void FragmentShader::compile() ...@@ -487,10 +485,9 @@ void FragmentShader::compile()
delete pixelShader; delete pixelShader;
pixelShader = 0; pixelShader = 0;
int infoLogLen = 0; int infoLogLen = compiler->getInfoSink().info.size() + 1;
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
mInfoLog = new char[infoLogLen]; mInfoLog = new char[infoLogLen];
ShGetInfoLog(compiler, mInfoLog); strcpy(mInfoLog, compiler->getInfoSink().info.c_str());
TRACE("\n%s", mInfoLog); TRACE("\n%s", mInfoLog);
} }
......
...@@ -164,8 +164,7 @@ TranslatorASM *Shader::createCompiler(ShShaderType type) ...@@ -164,8 +164,7 @@ TranslatorASM *Shader::createCompiler(ShShaderType type)
TranslatorASM *assembler = new TranslatorASM(this, type, SH_GLES2_SPEC); TranslatorASM *assembler = new TranslatorASM(this, type, SH_GLES2_SPEC);
ShBuiltInResources resources; ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS; resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS;
resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS; resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS;
resources.MaxVaryingVectors = MAX_VARYING_VECTORS; resources.MaxVaryingVectors = MAX_VARYING_VECTORS;
...@@ -382,7 +381,7 @@ void VertexShader::compile() ...@@ -382,7 +381,7 @@ void VertexShader::compile()
source = mSource; source = mSource;
} }
int success = ShCompile(compiler, &source, 1, SH_OBJECT_CODE); bool success = compiler->compile(&source, 1, SH_OBJECT_CODE);
if(false) if(false)
{ {
...@@ -401,10 +400,9 @@ void VertexShader::compile() ...@@ -401,10 +400,9 @@ void VertexShader::compile()
delete vertexShader; delete vertexShader;
vertexShader = 0; vertexShader = 0;
int infoLogLen = 0; int infoLogLen = compiler->getInfoSink().info.size() + 1;
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
mInfoLog = new char[infoLogLen]; mInfoLog = new char[infoLogLen];
ShGetInfoLog(compiler, mInfoLog); strcpy(mInfoLog, compiler->getInfoSink().info.c_str());
TRACE("\n%s", mInfoLog); TRACE("\n%s", mInfoLog);
} }
...@@ -468,7 +466,7 @@ void FragmentShader::compile() ...@@ -468,7 +466,7 @@ void FragmentShader::compile()
source = mSource; source = mSource;
} }
int success = ShCompile(compiler, &source, 1, SH_OBJECT_CODE); bool success = compiler->compile(&source, 1, SH_OBJECT_CODE);
if(false) if(false)
{ {
...@@ -487,10 +485,9 @@ void FragmentShader::compile() ...@@ -487,10 +485,9 @@ void FragmentShader::compile()
delete pixelShader; delete pixelShader;
pixelShader = 0; pixelShader = 0;
int infoLogLen = 0; int infoLogLen = compiler->getInfoSink().info.size() + 1;
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
mInfoLog = new char[infoLogLen]; mInfoLog = new char[infoLogLen];
ShGetInfoLog(compiler, mInfoLog); strcpy(mInfoLog, compiler->getInfoSink().info.c_str());
TRACE("\n%s", mInfoLog); TRACE("\n%s", mInfoLog);
} }
......
...@@ -165,7 +165,6 @@ TranslatorASM *Shader::createCompiler(ShShaderType type) ...@@ -165,7 +165,6 @@ TranslatorASM *Shader::createCompiler(ShShaderType type)
TranslatorASM *assembler = new TranslatorASM(this, type, SH_GLES2_SPEC); TranslatorASM *assembler = new TranslatorASM(this, type, SH_GLES2_SPEC);
ShBuiltInResources resources; ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS; resources.MaxVertexAttribs = MAX_VERTEX_ATTRIBS;
resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS; resources.MaxVertexUniformVectors = MAX_VERTEX_UNIFORM_VECTORS;
resources.MaxVaryingVectors = MAX_VARYING_VECTORS; resources.MaxVaryingVectors = MAX_VARYING_VECTORS;
...@@ -382,7 +381,7 @@ void VertexShader::compile() ...@@ -382,7 +381,7 @@ void VertexShader::compile()
source = mSource; source = mSource;
} }
int success = ShCompile(compiler, &source, 1, SH_OBJECT_CODE); bool success = compiler->compile(&source, 1, SH_OBJECT_CODE);
if(false) if(false)
{ {
...@@ -401,10 +400,9 @@ void VertexShader::compile() ...@@ -401,10 +400,9 @@ void VertexShader::compile()
delete vertexShader; delete vertexShader;
vertexShader = 0; vertexShader = 0;
int infoLogLen = 0; int infoLogLen = compiler->getInfoSink().info.size() + 1;
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
mInfoLog = new char[infoLogLen]; mInfoLog = new char[infoLogLen];
ShGetInfoLog(compiler, mInfoLog); strcpy(mInfoLog, compiler->getInfoSink().info.c_str());
TRACE("\n%s", mInfoLog); TRACE("\n%s", mInfoLog);
} }
...@@ -468,7 +466,7 @@ void FragmentShader::compile() ...@@ -468,7 +466,7 @@ void FragmentShader::compile()
source = mSource; source = mSource;
} }
int success = ShCompile(compiler, &source, 1, SH_OBJECT_CODE); bool success = compiler->compile(&source, 1, SH_OBJECT_CODE);
if(false) if(false)
{ {
...@@ -487,10 +485,9 @@ void FragmentShader::compile() ...@@ -487,10 +485,9 @@ void FragmentShader::compile()
delete pixelShader; delete pixelShader;
pixelShader = 0; pixelShader = 0;
int infoLogLen = 0; int infoLogLen = compiler->getInfoSink().info.size() + 1;
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
mInfoLog = new char[infoLogLen]; mInfoLog = new char[infoLogLen];
ShGetInfoLog(compiler, mInfoLog); strcpy(mInfoLog, compiler->getInfoSink().info.c_str());
TRACE("\n%s", mInfoLog); TRACE("\n%s", mInfoLog);
} }
......
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