Commit 0bdc0f3e by Zhenyao Mo

Switch to new APIs in samples/translator/translator.cpp

Also, fix a few issuse for ninja build "all" to finish. BUG=angle:775 TEST=translator.cc compiles OK Change-Id: I6507e9143882a628a7737dd139efb6d8d358b0db Reviewed-on: https://chromium-review.googlesource.com/227490Tested-by: 's avatarZhenyao Mo <zmo@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 657cd684
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
'angle_build_winrt%': '0', 'angle_build_winrt%': '0',
'angle_build_winphone%': '0', 'angle_build_winphone%': '0',
}, },
'msvs_disabled_warnings': [ 4100, 4127, 4239, 4244, 4245, 4251, 4512, 4702, 4530, 4718, 4267, 4264, 4447, 4075 ], 'msvs_disabled_warnings': [ 4075, 4100, 4127, 4239, 4244, 4245, 4251, 4264, 4267, 4447, 4512, 4530, 4702, 4718 ],
'conditions': 'conditions':
[ [
['angle_build_winrt==0', ['angle_build_winrt==0',
......
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
// //
// Return codes from main. // Return codes from main.
// //
enum TFailCode { enum TFailCode
{
ESuccess = 0, ESuccess = 0,
EFailUsage, EFailUsage,
EFailCompile, EFailCompile,
...@@ -25,22 +26,23 @@ enum TFailCode { ...@@ -25,22 +26,23 @@ enum TFailCode {
}; };
static void usage(); static void usage();
static sh::GLenum FindShaderType(const char* fileName); static sh::GLenum FindShaderType(const char *fileName);
static bool CompileFile(char* fileName, ShHandle compiler, int compileOptions); static bool CompileFile(char *fileName, ShHandle compiler, int compileOptions);
static void LogMsg(const char* msg, const char* name, const int num, const char* logName); static void LogMsg(const char *msg, const char *name, const int num, const char *logName);
static void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType); static void PrintVariable(const std::string &prefix, size_t index, const sh::ShaderVariable &var);
static void PrintActiveVariables(ShHandle compiler);
// If NUM_SOURCE_STRINGS is set to a value > 1, the input file data is // If NUM_SOURCE_STRINGS is set to a value > 1, the input file data is
// broken into that many chunks. // broken into that many chunks.
const unsigned int NUM_SOURCE_STRINGS = 2; const unsigned int NUM_SOURCE_STRINGS = 2;
typedef std::vector<char*> ShaderSource; typedef std::vector<char *> ShaderSource;
static bool ReadShaderSource(const char* fileName, ShaderSource& source); static bool ReadShaderSource(const char *fileName, ShaderSource &source);
static void FreeShaderSource(ShaderSource& source); static void FreeShaderSource(ShaderSource &source);
// //
// Set up the per compile resources // Set up the per compile resources
// //
void GenerateResources(ShBuiltInResources* resources) void GenerateResources(ShBuiltInResources *resources)
{ {
ShInitBuiltInResources(resources); ShInitBuiltInResources(resources);
...@@ -57,7 +59,7 @@ void GenerateResources(ShBuiltInResources* resources) ...@@ -57,7 +59,7 @@ void GenerateResources(ShBuiltInResources* resources)
resources->OES_EGL_image_external = 0; resources->OES_EGL_image_external = 0;
} }
int main(int argc, char* argv[]) int main(int argc, char *argv[])
{ {
TFailCode failCode = ESuccess; TFailCode failCode = ESuccess;
...@@ -65,8 +67,6 @@ int main(int argc, char* argv[]) ...@@ -65,8 +67,6 @@ int main(int argc, char* argv[])
int numCompiles = 0; int numCompiles = 0;
ShHandle vertexCompiler = 0; ShHandle vertexCompiler = 0;
ShHandle fragmentCompiler = 0; ShHandle fragmentCompiler = 0;
char* buffer = 0;
size_t bufferLen = 0;
ShShaderSpec spec = SH_GLES2_SPEC; ShShaderSpec spec = SH_GLES2_SPEC;
ShShaderOutput output = SH_ESSL_OUTPUT; ShShaderOutput output = SH_ESSL_OUTPUT;
...@@ -77,9 +77,12 @@ int main(int argc, char* argv[]) ...@@ -77,9 +77,12 @@ int main(int argc, char* argv[])
argc--; argc--;
argv++; argv++;
for (; (argc >= 1) && (failCode == ESuccess); argc--, argv++) { for (; (argc >= 1) && (failCode == ESuccess); argc--, argv++)
if (argv[0][0] == '-') { {
switch (argv[0][1]) { if (argv[0][0] == '-')
{
switch (argv[0][1])
{
case 'i': compileOptions |= SH_INTERMEDIATE_TREE; break; case 'i': compileOptions |= SH_INTERMEDIATE_TREE; break;
case 'o': compileOptions |= SH_OBJECT_CODE; break; case 'o': compileOptions |= SH_OBJECT_CODE; break;
case 'u': compileOptions |= SH_VARIABLES; break; case 'u': compileOptions |= SH_VARIABLES; break;
...@@ -88,20 +91,26 @@ int main(int argc, char* argv[]) ...@@ -88,20 +91,26 @@ int main(int argc, char* argv[])
case 'd': compileOptions |= SH_DEPENDENCY_GRAPH; break; case 'd': compileOptions |= SH_DEPENDENCY_GRAPH; break;
case 't': compileOptions |= SH_TIMING_RESTRICTIONS; break; case 't': compileOptions |= SH_TIMING_RESTRICTIONS; break;
case 's': case 's':
if (argv[0][2] == '=') { if (argv[0][2] == '=')
switch (argv[0][3]) { {
switch (argv[0][3])
{
case 'e': spec = SH_GLES2_SPEC; break; case 'e': spec = SH_GLES2_SPEC; break;
case 'w': spec = SH_WEBGL_SPEC; break; case 'w': spec = SH_WEBGL_SPEC; break;
case 'c': spec = SH_CSS_SHADERS_SPEC; break; case 'c': spec = SH_CSS_SHADERS_SPEC; break;
default: failCode = EFailUsage; default: failCode = EFailUsage;
} }
} else { }
else
{
failCode = EFailUsage; failCode = EFailUsage;
} }
break; break;
case 'b': case 'b':
if (argv[0][2] == '=') { if (argv[0][2] == '=')
switch (argv[0][3]) { {
switch (argv[0][3])
{
case 'e': output = SH_ESSL_OUTPUT; break; case 'e': output = SH_ESSL_OUTPUT; break;
case 'g': output = SH_GLSL_OUTPUT; break; case 'g': output = SH_GLSL_OUTPUT; break;
case 'h': case 'h':
...@@ -116,77 +125,86 @@ int main(int argc, char* argv[]) ...@@ -116,77 +125,86 @@ int main(int argc, char* argv[])
break; break;
default: failCode = EFailUsage; default: failCode = EFailUsage;
} }
} else { }
else
{
failCode = EFailUsage; failCode = EFailUsage;
} }
break; break;
case 'x': case 'x':
if (argv[0][2] == '=') { if (argv[0][2] == '=')
switch (argv[0][3]) { {
switch (argv[0][3])
{
case 'i': resources.OES_EGL_image_external = 1; break; case 'i': resources.OES_EGL_image_external = 1; break;
case 'd': resources.OES_standard_derivatives = 1; break; case 'd': resources.OES_standard_derivatives = 1; break;
case 'r': resources.ARB_texture_rectangle = 1; break; case 'r': resources.ARB_texture_rectangle = 1; break;
case 'l': resources.EXT_shader_texture_lod = 1; break; case 'l': resources.EXT_shader_texture_lod = 1; break;
default: failCode = EFailUsage; default: failCode = EFailUsage;
} }
} else { }
else
{
failCode = EFailUsage; failCode = EFailUsage;
} }
break; break;
default: failCode = EFailUsage; default: failCode = EFailUsage;
} }
} else { }
else
{
ShHandle compiler = 0; ShHandle compiler = 0;
switch (FindShaderType(argv[0])) { switch (FindShaderType(argv[0]))
{
case GL_VERTEX_SHADER: case GL_VERTEX_SHADER:
if (vertexCompiler == 0) if (vertexCompiler == 0)
{
vertexCompiler = ShConstructCompiler( vertexCompiler = ShConstructCompiler(
GL_VERTEX_SHADER, spec, output, &resources); GL_VERTEX_SHADER, spec, output, &resources);
}
compiler = vertexCompiler; compiler = vertexCompiler;
break; break;
case GL_FRAGMENT_SHADER: case GL_FRAGMENT_SHADER:
if (fragmentCompiler == 0) if (fragmentCompiler == 0)
{
fragmentCompiler = ShConstructCompiler( fragmentCompiler = ShConstructCompiler(
GL_FRAGMENT_SHADER, spec, output, &resources); GL_FRAGMENT_SHADER, spec, output, &resources);
}
compiler = fragmentCompiler; compiler = fragmentCompiler;
break; break;
default: break; default: break;
} }
if (compiler) { if (compiler)
{
bool compiled = CompileFile(argv[0], compiler, compileOptions); bool compiled = CompileFile(argv[0], compiler, compileOptions);
LogMsg("BEGIN", "COMPILER", numCompiles, "INFO LOG"); LogMsg("BEGIN", "COMPILER", numCompiles, "INFO LOG");
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &bufferLen); std::string log = ShGetInfoLog(compiler);
buffer = (char*) realloc(buffer, bufferLen * sizeof(char)); puts(log.c_str());
ShGetInfoLog(compiler, buffer);
puts(buffer);
LogMsg("END", "COMPILER", numCompiles, "INFO LOG"); LogMsg("END", "COMPILER", numCompiles, "INFO LOG");
printf("\n\n"); printf("\n\n");
if (compiled && (compileOptions & SH_OBJECT_CODE)) { if (compiled && (compileOptions & SH_OBJECT_CODE))
{
LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE"); LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE");
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &bufferLen); std::string code = ShGetObjectCode(compiler);
buffer = (char*) realloc(buffer, bufferLen * sizeof(char)); puts(code.c_str());
ShGetObjectCode(compiler, buffer);
puts(buffer);
LogMsg("END", "COMPILER", numCompiles, "OBJ CODE"); LogMsg("END", "COMPILER", numCompiles, "OBJ CODE");
printf("\n\n"); printf("\n\n");
} }
if (compiled && (compileOptions & SH_VARIABLES)) { if (compiled && (compileOptions & SH_VARIABLES))
LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE ATTRIBS"); {
PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES); LogMsg("BEGIN", "COMPILER", numCompiles, "VARIABLES");
LogMsg("END", "COMPILER", numCompiles, "ACTIVE ATTRIBS"); PrintActiveVariables(compiler);
printf("\n\n"); LogMsg("END", "COMPILER", numCompiles, "VARIABLES");
LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE UNIFORMS");
PrintActiveVariables(compiler, SH_ACTIVE_UNIFORMS);
LogMsg("END", "COMPILER", numCompiles, "ACTIVE UNIFORMS");
printf("\n\n"); printf("\n\n");
} }
if (!compiled) if (!compiled)
failCode = EFailCompile; failCode = EFailCompile;
++numCompiles; ++numCompiles;
} else { }
else
{
failCode = EFailCompilerCreate; failCode = EFailCompilerCreate;
} }
} }
...@@ -201,8 +219,6 @@ int main(int argc, char* argv[]) ...@@ -201,8 +219,6 @@ int main(int argc, char* argv[])
ShDestruct(vertexCompiler); ShDestruct(vertexCompiler);
if (fragmentCompiler) if (fragmentCompiler)
ShDestruct(fragmentCompiler); ShDestruct(fragmentCompiler);
if (buffer)
free(buffer);
ShFinalize(); ShFinalize();
return failCode; return failCode;
...@@ -216,9 +232,8 @@ void usage() ...@@ -216,9 +232,8 @@ void usage()
printf("Usage: translate [-i -m -o -u -l -e -b=e -b=g -b=h -x=i -x=d] file1 file2 ...\n" printf("Usage: translate [-i -m -o -u -l -e -b=e -b=g -b=h -x=i -x=d] file1 file2 ...\n"
"Where: filename : filename ending in .frag or .vert\n" "Where: filename : filename ending in .frag or .vert\n"
" -i : print intermediate tree\n" " -i : print intermediate tree\n"
" -m : map long variable names\n"
" -o : print translated code\n" " -o : print translated code\n"
" -u : print active attribs and uniforms\n" " -u : print active attribs, uniforms, and varyings\n"
" -l : unroll for-loops with integer indices\n" " -l : unroll for-loops with integer indices\n"
" -e : emulate certain built-in functions (workaround for driver bugs)\n" " -e : emulate certain built-in functions (workaround for driver bugs)\n"
" -t : enforce experimental timing restrictions\n" " -t : enforce experimental timing restrictions\n"
...@@ -243,17 +258,18 @@ void usage() ...@@ -243,17 +258,18 @@ void usage()
// .frag* = fragment shader // .frag* = fragment shader
// .vert* = vertex shader // .vert* = vertex shader
// //
sh::GLenum FindShaderType(const char* fileName) sh::GLenum FindShaderType(const char *fileName)
{ {
assert(fileName); assert(fileName);
const char* ext = strrchr(fileName, '.'); const char *ext = strrchr(fileName, '.');
if (ext && strcmp(ext, ".sl") == 0) if (ext && strcmp(ext, ".sl") == 0)
for (; ext > fileName && ext[0] != '.'; ext--); for (; ext > fileName && ext[0] != '.'; ext--);
ext = strrchr(fileName, '.'); ext = strrchr(fileName, '.');
if (ext) { if (ext)
{
if (strncmp(ext, ".frag", 4) == 0) return GL_FRAGMENT_SHADER; if (strncmp(ext, ".frag", 4) == 0) return GL_FRAGMENT_SHADER;
if (strncmp(ext, ".vert", 4) == 0) return GL_VERTEX_SHADER; if (strncmp(ext, ".vert", 4) == 0) return GL_VERTEX_SHADER;
} }
...@@ -264,7 +280,7 @@ sh::GLenum FindShaderType(const char* fileName) ...@@ -264,7 +280,7 @@ sh::GLenum FindShaderType(const char* fileName)
// //
// Read a file's data into a string, and compile it using ShCompile // Read a file's data into a string, and compile it using ShCompile
// //
bool CompileFile(char* fileName, ShHandle compiler, int compileOptions) bool CompileFile(char *fileName, ShHandle compiler, int compileOptions)
{ {
ShaderSource source; ShaderSource source;
if (!ReadShaderSource(fileName, source)) if (!ReadShaderSource(fileName, source))
...@@ -276,44 +292,16 @@ bool CompileFile(char* fileName, ShHandle compiler, int compileOptions) ...@@ -276,44 +292,16 @@ bool CompileFile(char* fileName, ShHandle compiler, int compileOptions)
return ret ? true : false; return ret ? true : false;
} }
void LogMsg(const char* msg, const char* name, const int num, const char* logName) void LogMsg(const char *msg, const char *name, const int num, const char *logName)
{ {
printf("#### %s %s %d %s ####\n", msg, name, num, logName); printf("#### %s %s %d %s ####\n", msg, name, num, logName);
} }
void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType) void PrintVariable(const std::string &prefix, size_t index, const sh::ShaderVariable &var)
{ {
size_t nameSize = 0; std::string typeName;
switch (varType) { switch (var.type)
case SH_ACTIVE_ATTRIBUTES: {
ShGetInfo(compiler, SH_ACTIVE_ATTRIBUTE_MAX_LENGTH, &nameSize);
break;
case SH_ACTIVE_UNIFORMS:
ShGetInfo(compiler, SH_ACTIVE_UNIFORM_MAX_LENGTH, &nameSize);
break;
default: assert(0);
}
if (nameSize <= 1) return;
char* name = new char[nameSize];
size_t activeVars = 0;
int size = 0;
sh::GLenum type = GL_NONE;
ShPrecisionType precision = SH_PRECISION_UNDEFINED;
int staticUse = 0;
const char* typeName = NULL;
ShGetInfo(compiler, varType, &activeVars);
for (size_t i = 0; i < activeVars; ++i) {
switch (varType) {
case SH_ACTIVE_ATTRIBUTES:
ShGetVariableInfo(compiler, SH_ACTIVE_ATTRIBUTES, static_cast<int>(i), NULL, &size, &type, &precision, &staticUse, name, NULL);
break;
case SH_ACTIVE_UNIFORMS:
ShGetVariableInfo(compiler, SH_ACTIVE_UNIFORMS, static_cast<int>(i), NULL, &size, &type, &precision, &staticUse, name, NULL);
break;
default: assert(0);
}
switch (type) {
case GL_FLOAT: typeName = "GL_FLOAT"; break; case GL_FLOAT: typeName = "GL_FLOAT"; break;
case GL_FLOAT_VEC2: typeName = "GL_FLOAT_VEC2"; break; case GL_FLOAT_VEC2: typeName = "GL_FLOAT_VEC2"; break;
case GL_FLOAT_VEC3: typeName = "GL_FLOAT_VEC3"; break; case GL_FLOAT_VEC3: typeName = "GL_FLOAT_VEC3"; break;
...@@ -342,16 +330,67 @@ void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType) ...@@ -342,16 +330,67 @@ void PrintActiveVariables(ShHandle compiler, ShShaderInfo varType)
case GL_SAMPLER_2D: typeName = "GL_SAMPLER_2D"; break; case GL_SAMPLER_2D: typeName = "GL_SAMPLER_2D"; break;
case GL_SAMPLER_CUBE: typeName = "GL_SAMPLER_CUBE"; break; case GL_SAMPLER_CUBE: typeName = "GL_SAMPLER_CUBE"; break;
case GL_SAMPLER_EXTERNAL_OES: typeName = "GL_SAMPLER_EXTERNAL_OES"; break; case GL_SAMPLER_EXTERNAL_OES: typeName = "GL_SAMPLER_EXTERNAL_OES"; break;
default: assert(0); default: typeName = "UNKNOWN"; break;
}
printf("%s %lu : name=%s, type=%s, arraySize=%u\n",
prefix.c_str(), index, var.name.c_str(), typeName.c_str(), var.arraySize);
if (var.fields.size())
{
std::string structPrefix;
for (size_t i = 0; i < prefix.size(); ++i)
structPrefix += ' ';
printf("%s struct %s\n", structPrefix.c_str(), var.structName.c_str());
structPrefix += " field";
for (size_t i = 0; i < var.fields.size(); ++i)
PrintVariable(structPrefix, i, var.fields[i]);
}
}
static void PrintActiveVariables(ShHandle compiler)
{
const std::vector<sh::Uniform> *uniforms = ShGetUniforms(compiler);
const std::vector<sh::Varying> *varyings = ShGetVaryings(compiler);
const std::vector<sh::Attribute> *attributes = ShGetAttributes(compiler);
for (size_t varCategory = 0; varCategory < 3; ++varCategory)
{
size_t numVars = 0;
std::string varCategoryName;
if (varCategory == 0)
{
numVars = uniforms->size();
varCategoryName = "uniform";
}
else if (varCategory == 1)
{
numVars = varyings->size();
varCategoryName = "varying";
}
else
{
numVars = attributes->size();
varCategoryName = "attribute";
}
for (size_t i = 0; i < numVars; ++i)
{
const sh::ShaderVariable *var;
if (varCategory == 0)
var = &((*uniforms)[i]);
else if (varCategory == 1)
var = &((*varyings)[i]);
else
var = &((*attributes)[i]);
PrintVariable(varCategoryName, i, *var);
} }
printf("%lu: name:%s type:%s size:%d\n", i, name, typeName, size); printf("\n");
} }
delete [] name;
} }
static bool ReadShaderSource(const char* fileName, ShaderSource& source) { static bool ReadShaderSource(const char *fileName, ShaderSource &source)
FILE* in = fopen(fileName, "rb"); {
if (!in) { FILE *in = fopen(fileName, "rb");
if (!in)
{
printf("Error: unable to open input file: %s\n", fileName); printf("Error: unable to open input file: %s\n", fileName);
return false; return false;
} }
...@@ -366,21 +405,25 @@ static bool ReadShaderSource(const char* fileName, ShaderSource& source) { ...@@ -366,21 +405,25 @@ static bool ReadShaderSource(const char* fileName, ShaderSource& source) {
// Notice the usage of do-while instead of a while loop here. // Notice the usage of do-while instead of a while loop here.
// It is there to handle empty files in which case a single empty // It is there to handle empty files in which case a single empty
// string is added to vector. // string is added to vector.
do { do
char* data = new char[len + 1]; {
char *data = new char[len + 1];
size_t nread = fread(data, 1, len, in); size_t nread = fread(data, 1, len, in);
data[nread] = '\0'; data[nread] = '\0';
source.push_back(data); source.push_back(data);
count -= nread; count -= nread;
} while (count > 0); }
while (count > 0);
fclose(in); fclose(in);
return true; return true;
} }
static void FreeShaderSource(ShaderSource& source) { static void FreeShaderSource(ShaderSource &source)
for (ShaderSource::size_type i = 0; i < source.size(); ++i) { {
for (ShaderSource::size_type i = 0; i < source.size(); ++i)
{
delete [] source[i]; delete [] source[i];
} }
source.clear(); source.clear();
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
// classes TextureStorage11_2D and TextureStorage11_Cube, which act as the interface to the D3D11 texture. // classes TextureStorage11_2D and TextureStorage11_Cube, which act as the interface to the D3D11 texture.
#include "libGLESv2/renderer/d3d/d3d11/TextureStorage11.h" #include "libGLESv2/renderer/d3d/d3d11/TextureStorage11.h"
#include <tuple>
#include "libGLESv2/renderer/d3d/d3d11/Renderer11.h" #include "libGLESv2/renderer/d3d/d3d11/Renderer11.h"
#include "libGLESv2/renderer/d3d/d3d11/RenderTarget11.h" #include "libGLESv2/renderer/d3d/d3d11/RenderTarget11.h"
#include "libGLESv2/renderer/d3d/d3d11/SwapChain11.h" #include "libGLESv2/renderer/d3d/d3d11/SwapChain11.h"
......
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