Commit 7beea408 by alokp@chromium.org

Added API to query for active attribs and uniforms. These functions are modeled…

Added API to query for active attribs and uniforms. These functions are modeled after glGetShaderiv, glGetProgramiv, glGetActiveAttrib, and glGetActiveUniform. The main difference between this and OpenGL API is that we do not have programs - just shaders. BUG=26 Review URL: http://codereview.appspot.com/2183041 git-svn-id: https://angleproject.googlecode.com/svn/trunk@425 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 8d012dfc
......@@ -70,21 +70,6 @@ typedef struct
void ShInitBuiltInResource(TBuiltInResource* resources);
//
// Optimization level for the compiler.
//
typedef enum {
EShOptNoGeneration,
EShOptNone,
EShOptSimple, // Optimizations that can be done quickly
EShOptFull, // Optimizations that will take more time
} EShOptimizationLevel;
enum TDebugOptions {
EDebugOpNone = 0x000,
EDebugOpIntermediate = 0x001, // Writes intermediate tree into info-log.
};
//
// 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.
......@@ -99,6 +84,20 @@ typedef void* ShHandle;
ShHandle ShConstructCompiler(EShLanguage, EShSpec, const TBuiltInResource*);
void ShDestruct(ShHandle);
typedef enum {
// Performs validations only.
EShOptNone = 0x000,
// Writes intermediate tree to info log.
// Can be queried by calling ShGetInfoLog().
EShOptIntermediateTree = 0x001,
// Translates intermediate tree to glsl or hlsl shader.
// Can be queried by calling ShGetObjectCode().
EShOptObjectCode = 0x002,
// Extracts attributes and uniforms.
// Can be queried by calling ShGetActiveAttrib() and ShGetActiveUniform().
EShOptAttribsUniforms = 0x004,
} EShCompileOptions;
//
// The return value of ShCompile is boolean, indicating
// success or failure.
......@@ -110,16 +109,127 @@ int ShCompile(
const ShHandle,
const char* const shaderStrings[],
const int numStrings,
const EShOptimizationLevel,
int debugOptions
int compileOptions
);
// The names of the following enums have been derived by replacing GL prefix
// with SH. For example, SH_INFO_LOG_LENGTH is equivalent to GL_INFO_LOG_LENGTH.
// The enum values are also equal to the values of their GL counterpart. This
// is done to make it easier for applications to use the shader library.
//
// All the following return 0 if the information is not
// available in the object passed down, or the object is bad.
//
const char* ShGetInfoLog(const ShHandle);
const char* ShGetObjectCode(const ShHandle);
// The only exception to this rule is SH_OBJECT_CODE_LENGTH, which does not
// have a GL equivalent. It uses the value of GL_SHADER_SOURCE_LENGTH instead.
typedef enum {
SH_INFO_LOG_LENGTH = 0x8B84,
SH_OBJECT_CODE_LENGTH = 0x8B88, // equal to GL_SHADER_SOURCE_LENGTH.
SH_ACTIVE_UNIFORMS = 0x8B86,
SH_ACTIVE_UNIFORM_MAX_LENGTH = 0x8B87,
SH_ACTIVE_ATTRIBUTES = 0x8B89,
SH_ACTIVE_ATTRIBUTE_MAX_LENGTH = 0x8B8A,
} EShInfo;
typedef enum {
SH_FLOAT = 0x1406,
SH_FLOAT_VEC2 = 0x8B50,
SH_FLOAT_VEC3 = 0x8B51,
SH_FLOAT_VEC4 = 0x8B52,
SH_FLOAT_MAT2 = 0x8B5A,
SH_FLOAT_MAT3 = 0x8B5B,
SH_FLOAT_MAT4 = 0x8B5C,
SH_INT = 0x1404,
SH_INT_VEC2 = 0x8B53,
SH_INT_VEC3 = 0x8B54,
SH_INT_VEC4 = 0x8B55,
SH_BOOL = 0x8B56,
SH_BOOL_VEC2 = 0x8B57,
SH_BOOL_VEC3 = 0x8B58,
SH_BOOL_VEC4 = 0x8B59,
SH_SAMPLER_2D = 0x8B5E,
SH_SAMPLER_CUBE = 0x8B60,
} EShDataType;
// 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.
//
// params: Requested parameter
void ShGetInfo(const ShHandle handle, EShInfo 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);
// Returns information about an active attribute variable.
// Parameters:
// handle: Specifies the compiler
// index: Specifies the index of the attribute variable to be queried.
// length: Returns the number of characters actually written in the string
// indicated by name (excluding the null terminator) if a value other
// than NULL is passed.
// size: Returns the size of the attribute variable.
// type: Returns the data type of the attribute variable.
// name: Returns a null terminated string containing the name of the
// attribute variable. It is assumed that name has enough memory to
// accomodate the attribute variable name. The size of the buffer
// required to store the attribute variable name can be obtained by
// calling ShGetInfo with SH_ACTIVE_ATTRIBUTE_MAX_LENGTH.
void ShGetActiveAttrib(const ShHandle handle,
int index,
int* length,
int* size,
EShDataType* type,
char* name);
// Returns information about an active uniform variable.
// Parameters:
// handle: Specifies the compiler
// index: Specifies the index of the uniform variable to be queried.
// length: Returns the number of characters actually written in the string
// indicated by name (excluding the null terminator) if a value
// other than NULL is passed.
// size: Returns the size of the uniform variable.
// type: Returns the data type of the uniform variable.
// name: Returns a null terminated string containing the name of the
// uniform variable. It is assumed that name has enough memory to
// accomodate the uniform variable name. The size of the buffer required
// to store the uniform variable name can be obtained by calling
// ShGetInfo with SH_ACTIVE_UNIFORMS_MAX_LENGTH.
void ShGetActiveUniform(const ShHandle handle,
int index,
int* length,
int* size,
EShDataType* type,
char* name);
#ifdef __cplusplus
}
......
......@@ -54,12 +54,12 @@ int main(int argc, char* argv[])
{
TFailCode failCode = ESuccess;
int debugOptions = 0;
bool writeObjectCode = false;
int compileOptions = 0;
int numCompiles = 0;
ShHandle vertexCompiler = 0;
ShHandle fragmentCompiler = 0;
char* buffer = 0;
int bufferLen = 0;
ShInitialize();
......@@ -71,8 +71,8 @@ int main(int argc, char* argv[])
for (; (argc >= 1) && (failCode == ESuccess); argc--, argv++) {
if (argv[0][0] == '-' || argv[0][0] == '/') {
switch (argv[0][1]) {
case 'i': debugOptions |= EDebugOpIntermediate; break;
case 'o': writeObjectCode = true; break;
case 'i': compileOptions |= EShOptIntermediateTree; break;
case 'o': compileOptions |= EShOptObjectCode; break;
default: failCode = EFailUsage;
}
} else {
......@@ -91,15 +91,21 @@ int main(int argc, char* argv[])
default: break;
}
if (compiler) {
bool compiled = CompileFile(argv[0], compiler, debugOptions);
bool compiled = CompileFile(argv[0], compiler, compileOptions);
LogMsg("BEGIN", "COMPILER", numCompiles, "INFO LOG");
puts(ShGetInfoLog(compiler));
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &bufferLen);
buffer = (char*) realloc(buffer, bufferLen * sizeof(char));
ShGetInfoLog(compiler, buffer);
puts(buffer);
LogMsg("END", "COMPILER", numCompiles, "INFO LOG");
if (compiled && writeObjectCode) {
if (compiled && (compileOptions & EShOptObjectCode)) {
LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE");
puts(ShGetObjectCode(compiler));
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &bufferLen);
buffer = (char*) realloc(buffer, bufferLen * sizeof(char));
ShGetObjectCode(compiler, buffer);
puts(buffer);
LogMsg("END", "COMPILER", numCompiles, "OBJ CODE");
}
if (!compiled)
......@@ -120,6 +126,8 @@ int main(int argc, char* argv[])
ShDestruct(vertexCompiler);
if (fragmentCompiler)
ShDestruct(fragmentCompiler);
if (buffer)
free(buffer);
ShFinalize();
return failCode;
......@@ -153,7 +161,7 @@ static EShLanguage FindLanguage(char *name)
//
// Read a file's data into a string, and compile it using ShCompile
//
bool CompileFile(char *fileName, ShHandle compiler, int debugOptions)
bool CompileFile(char *fileName, ShHandle compiler, int compileOptions)
{
int ret;
char **data = ReadFileData(fileName);
......@@ -161,7 +169,7 @@ bool CompileFile(char *fileName, ShHandle compiler, int debugOptions)
if (!data)
return false;
ret = ShCompile(compiler, data, OutputMultipleStrings, EShOptNone, debugOptions);
ret = ShCompile(compiler, data, OutputMultipleStrings, compileOptions);
FreeFileData(data);
......
......@@ -91,6 +91,7 @@ public:
}
void erase() { sink.clear(); }
int size() { return static_cast<int>(sink.size()); }
const TPersistString& str() const { return sink; }
const char* c_str() const { return sink.c_str(); }
......
......@@ -180,9 +180,7 @@ int ShCompile(
const ShHandle handle,
const char* const shaderStrings[],
const int numStrings,
const EShOptimizationLevel optLevel,
int debugOptions
)
int compileOptions)
{
if (!InitThread())
return 0;
......@@ -227,40 +225,34 @@ int ShCompile(
if (!symbolTable.atGlobalLevel())
parseContext.infoSink.info.message(EPrefixInternalError, "Wrong symbol table level");
int ret = PaParseStrings(const_cast<char**>(shaderStrings), 0, numStrings, parseContext);
if (ret)
if (PaParseStrings(const_cast<char**>(shaderStrings), 0, numStrings, parseContext))
success = false;
if (success && parseContext.treeRoot) {
if (optLevel == EShOptNoGeneration)
parseContext.infoSink.info.message(EPrefixNone, "No errors. No code generation was requested.");
else {
success = intermediate.postProcess(parseContext.treeRoot, parseContext.language);
if (success) {
if (debugOptions & EDebugOpIntermediate)
intermediate.outputTree(parseContext.treeRoot);
//
// Call the machine dependent compiler
//
if (!compiler->compile(parseContext.treeRoot))
success = false;
}
success = intermediate.postProcess(parseContext.treeRoot, parseContext.language);
if (success) {
if (compileOptions & EShOptIntermediateTree)
intermediate.outputTree(parseContext.treeRoot);
//
// Call the machine dependent compiler
//
if (compileOptions & EShOptObjectCode)
success = compiler->compile(parseContext.treeRoot);
// TODO(alokp): Extract attributes and uniforms.
//if (compileOptions & EShOptAttribsUniforms)
}
} else if (!success) {
parseContext.infoSink.info.prefix(EPrefixError);
parseContext.infoSink.info << parseContext.numErrors << " compilation errors. No code generated.\n\n";
success = false;
if (debugOptions & EDebugOpIntermediate)
if (compileOptions & EShOptIntermediateTree)
intermediate.outputTree(parseContext.treeRoot);
} else if (!parseContext.treeRoot) {
parseContext.error(1, "Unexpected end of file.", "", "");
parseContext.infoSink.info << parseContext.numErrors << " compilation errors. No code generated.\n\n";
success = false;
if (debugOptions & EDebugOpIntermediate)
intermediate.outputTree(parseContext.treeRoot);
}
intermediate.remove(parseContext.treeRoot);
......@@ -281,43 +273,88 @@ int ShCompile(
return success ? 1 : 0;
}
void ShGetInfo(const ShHandle handle, EShInfo pname, int* params)
{
if (!handle || !params)
return;
TShHandleBase* base = static_cast<TShHandleBase*>(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_UNIFORMS:
UNIMPLEMENTED();
break;
case SH_ACTIVE_UNIFORM_MAX_LENGTH:
UNIMPLEMENTED();
break;
case SH_ACTIVE_ATTRIBUTES:
UNIMPLEMENTED();
break;
case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH:
UNIMPLEMENTED();
break;
default: UNREACHABLE();
}
}
//
// Return any compiler log of messages for the application.
//
const char* ShGetInfoLog(const ShHandle handle)
void ShGetInfoLog(const ShHandle handle, char* infoLog)
{
if (!InitThread())
return 0;
if (handle == 0)
return 0;
if (!handle || !infoLog)
return;
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
TInfoSink* infoSink = 0;
if (base->getAsCompiler())
infoSink = &(base->getAsCompiler()->getInfoSink());
TCompiler* compiler = base->getAsCompiler();
if (!compiler) return;
infoSink->info << infoSink->debug.c_str();
return infoSink->info.c_str();
TInfoSink& infoSink = compiler->getInfoSink();
strcpy(infoLog, infoSink.info.c_str());
}
//
// Return any object code.
//
const char* ShGetObjectCode(const ShHandle handle)
void ShGetObjectCode(const ShHandle handle, char* objCode)
{
if (!InitThread())
return 0;
if (handle == 0)
return 0;
if (!handle || !objCode)
return;
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
TInfoSink* infoSink;
TCompiler* compiler = base->getAsCompiler();
if (!compiler) return;
if (base->getAsCompiler())
infoSink = &(base->getAsCompiler()->getInfoSink());
TInfoSink& infoSink = compiler->getInfoSink();
strcpy(objCode, infoSink.obj.c_str());
}
return infoSink->obj.c_str();
void ShGetActiveAttrib(const ShHandle handle,
int index,
int* length,
int* size,
EShDataType* type,
char* name)
{
UNIMPLEMENTED();
}
void ShGetActiveUniform(const ShHandle handle,
int index,
int* length,
int* size,
EShDataType* type,
char* name)
{
UNIMPLEMENTED();
}
......@@ -21,8 +21,8 @@
//
class TOutputTraverser : public TIntermTraverser {
public:
TOutputTraverser(TInfoSink& i) : infoSink(i) { }
TInfoSink& infoSink;
TOutputTraverser(TInfoSinkBase& i) : sink(i) { }
TInfoSinkBase& sink;
protected:
void visitSymbol(TIntermSymbol*);
......@@ -56,14 +56,14 @@ TString TType::getCompleteString() const
// Helper functions for printing, not part of traversing.
//
void OutputTreeText(TInfoSink& infoSink, TIntermNode* node, const int depth)
void OutputTreeText(TInfoSinkBase& sink, TIntermNode* node, const int depth)
{
int i;
infoSink.debug.location(node->getLine());
sink.location(node->getLine());
for (i = 0; i < depth; ++i)
infoSink.debug << " ";
sink << " ";
}
//
......@@ -77,226 +77,226 @@ void OutputTreeText(TInfoSink& infoSink, TIntermNode* node, const int depth)
void TOutputTraverser::visitSymbol(TIntermSymbol* node)
{
OutputTreeText(infoSink, node, depth);
OutputTreeText(sink, node, depth);
infoSink.debug << "'" << node->getSymbol() << "' ";
infoSink.debug << "(" << node->getCompleteString() << ")\n";
sink << "'" << node->getSymbol() << "' ";
sink << "(" << node->getCompleteString() << ")\n";
}
bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary* node)
{
TInfoSink& out = infoSink;
TInfoSinkBase& out = sink;
OutputTreeText(out, node, depth);
switch (node->getOp()) {
case EOpAssign: out.debug << "move second child to first child"; break;
case EOpInitialize: out.debug << "initialize first child with second child"; break;
case EOpAddAssign: out.debug << "add second child into first child"; break;
case EOpSubAssign: out.debug << "subtract second child into first child"; break;
case EOpMulAssign: out.debug << "multiply second child into first child"; break;
case EOpVectorTimesMatrixAssign: out.debug << "matrix mult second child into first child"; break;
case EOpVectorTimesScalarAssign: out.debug << "vector scale second child into first child"; break;
case EOpMatrixTimesScalarAssign: out.debug << "matrix scale second child into first child"; break;
case EOpMatrixTimesMatrixAssign: out.debug << "matrix mult second child into first child"; break;
case EOpDivAssign: out.debug << "divide second child into first child"; break;
case EOpIndexDirect: out.debug << "direct index"; break;
case EOpIndexIndirect: out.debug << "indirect index"; break;
case EOpIndexDirectStruct: out.debug << "direct index for structure"; break;
case EOpVectorSwizzle: out.debug << "vector swizzle"; break;
case EOpAdd: out.debug << "add"; break;
case EOpSub: out.debug << "subtract"; break;
case EOpMul: out.debug << "component-wise multiply"; break;
case EOpDiv: out.debug << "divide"; break;
case EOpEqual: out.debug << "Compare Equal"; break;
case EOpNotEqual: out.debug << "Compare Not Equal"; break;
case EOpLessThan: out.debug << "Compare Less Than"; break;
case EOpGreaterThan: out.debug << "Compare Greater Than"; break;
case EOpLessThanEqual: out.debug << "Compare Less Than or Equal"; break;
case EOpGreaterThanEqual: out.debug << "Compare Greater Than or Equal"; break;
case EOpVectorTimesScalar: out.debug << "vector-scale"; break;
case EOpVectorTimesMatrix: out.debug << "vector-times-matrix"; break;
case EOpMatrixTimesVector: out.debug << "matrix-times-vector"; break;
case EOpMatrixTimesScalar: out.debug << "matrix-scale"; break;
case EOpMatrixTimesMatrix: out.debug << "matrix-multiply"; break;
case EOpLogicalOr: out.debug << "logical-or"; break;
case EOpLogicalXor: out.debug << "logical-xor"; break;
case EOpLogicalAnd: out.debug << "logical-and"; break;
default: out.debug << "<unknown op>";
case EOpAssign: out << "move second child to first child"; break;
case EOpInitialize: out << "initialize first child with second child"; break;
case EOpAddAssign: out << "add second child into first child"; break;
case EOpSubAssign: out << "subtract second child into first child"; break;
case EOpMulAssign: out << "multiply second child into first child"; break;
case EOpVectorTimesMatrixAssign: out << "matrix mult second child into first child"; break;
case EOpVectorTimesScalarAssign: out << "vector scale second child into first child"; break;
case EOpMatrixTimesScalarAssign: out << "matrix scale second child into first child"; break;
case EOpMatrixTimesMatrixAssign: out << "matrix mult second child into first child"; break;
case EOpDivAssign: out << "divide second child into first child"; break;
case EOpIndexDirect: out << "direct index"; break;
case EOpIndexIndirect: out << "indirect index"; break;
case EOpIndexDirectStruct: out << "direct index for structure"; break;
case EOpVectorSwizzle: out << "vector swizzle"; break;
case EOpAdd: out << "add"; break;
case EOpSub: out << "subtract"; break;
case EOpMul: out << "component-wise multiply"; break;
case EOpDiv: out << "divide"; break;
case EOpEqual: out << "Compare Equal"; break;
case EOpNotEqual: out << "Compare Not Equal"; break;
case EOpLessThan: out << "Compare Less Than"; break;
case EOpGreaterThan: out << "Compare Greater Than"; break;
case EOpLessThanEqual: out << "Compare Less Than or Equal"; break;
case EOpGreaterThanEqual: out << "Compare Greater Than or Equal"; break;
case EOpVectorTimesScalar: out << "vector-scale"; break;
case EOpVectorTimesMatrix: out << "vector-times-matrix"; break;
case EOpMatrixTimesVector: out << "matrix-times-vector"; break;
case EOpMatrixTimesScalar: out << "matrix-scale"; break;
case EOpMatrixTimesMatrix: out << "matrix-multiply"; break;
case EOpLogicalOr: out << "logical-or"; break;
case EOpLogicalXor: out << "logical-xor"; break;
case EOpLogicalAnd: out << "logical-and"; break;
default: out << "<unknown op>";
}
out.debug << " (" << node->getCompleteString() << ")";
out << " (" << node->getCompleteString() << ")";
out.debug << "\n";
out << "\n";
return true;
}
bool TOutputTraverser::visitUnary(Visit visit, TIntermUnary* node)
{
TInfoSink& out = infoSink;
TInfoSinkBase& out = sink;
OutputTreeText(out, node, depth);
switch (node->getOp()) {
case EOpNegative: out.debug << "Negate value"; break;
case EOpNegative: out << "Negate value"; break;
case EOpVectorLogicalNot:
case EOpLogicalNot: out.debug << "Negate conditional"; break;
case EOpPostIncrement: out.debug << "Post-Increment"; break;
case EOpPostDecrement: out.debug << "Post-Decrement"; break;
case EOpPreIncrement: out.debug << "Pre-Increment"; break;
case EOpPreDecrement: out.debug << "Pre-Decrement"; break;
case EOpConvIntToBool: out.debug << "Convert int to bool"; break;
case EOpConvFloatToBool:out.debug << "Convert float to bool";break;
case EOpConvBoolToFloat:out.debug << "Convert bool to float";break;
case EOpConvIntToFloat: out.debug << "Convert int to float"; break;
case EOpConvFloatToInt: out.debug << "Convert float to int"; break;
case EOpConvBoolToInt: out.debug << "Convert bool to int"; break;
case EOpRadians: out.debug << "radians"; break;
case EOpDegrees: out.debug << "degrees"; break;
case EOpSin: out.debug << "sine"; break;
case EOpCos: out.debug << "cosine"; break;
case EOpTan: out.debug << "tangent"; break;
case EOpAsin: out.debug << "arc sine"; break;
case EOpAcos: out.debug << "arc cosine"; break;
case EOpAtan: out.debug << "arc tangent"; break;
case EOpExp: out.debug << "exp"; break;
case EOpLog: out.debug << "log"; break;
case EOpExp2: out.debug << "exp2"; break;
case EOpLog2: out.debug << "log2"; break;
case EOpSqrt: out.debug << "sqrt"; break;
case EOpInverseSqrt: out.debug << "inverse sqrt"; break;
case EOpAbs: out.debug << "Absolute value"; break;
case EOpSign: out.debug << "Sign"; break;
case EOpFloor: out.debug << "Floor"; break;
case EOpCeil: out.debug << "Ceiling"; break;
case EOpFract: out.debug << "Fraction"; break;
case EOpLength: out.debug << "length"; break;
case EOpNormalize: out.debug << "normalize"; break;
// case EOpDPdx: out.debug << "dPdx"; break;
// case EOpDPdy: out.debug << "dPdy"; break;
// case EOpFwidth: out.debug << "fwidth"; break;
case EOpAny: out.debug << "any"; break;
case EOpAll: out.debug << "all"; break;
default: out.debug.message(EPrefixError, "Bad unary op");
case EOpLogicalNot: out << "Negate conditional"; break;
case EOpPostIncrement: out << "Post-Increment"; break;
case EOpPostDecrement: out << "Post-Decrement"; break;
case EOpPreIncrement: out << "Pre-Increment"; break;
case EOpPreDecrement: out << "Pre-Decrement"; break;
case EOpConvIntToBool: out << "Convert int to bool"; break;
case EOpConvFloatToBool:out << "Convert float to bool";break;
case EOpConvBoolToFloat:out << "Convert bool to float";break;
case EOpConvIntToFloat: out << "Convert int to float"; break;
case EOpConvFloatToInt: out << "Convert float to int"; break;
case EOpConvBoolToInt: out << "Convert bool to int"; break;
case EOpRadians: out << "radians"; break;
case EOpDegrees: out << "degrees"; break;
case EOpSin: out << "sine"; break;
case EOpCos: out << "cosine"; break;
case EOpTan: out << "tangent"; break;
case EOpAsin: out << "arc sine"; break;
case EOpAcos: out << "arc cosine"; break;
case EOpAtan: out << "arc tangent"; break;
case EOpExp: out << "exp"; break;
case EOpLog: out << "log"; break;
case EOpExp2: out << "exp2"; break;
case EOpLog2: out << "log2"; break;
case EOpSqrt: out << "sqrt"; break;
case EOpInverseSqrt: out << "inverse sqrt"; break;
case EOpAbs: out << "Absolute value"; break;
case EOpSign: out << "Sign"; break;
case EOpFloor: out << "Floor"; break;
case EOpCeil: out << "Ceiling"; break;
case EOpFract: out << "Fraction"; break;
case EOpLength: out << "length"; break;
case EOpNormalize: out << "normalize"; break;
// case EOpDPdx: out << "dPdx"; break;
// case EOpDPdy: out << "dPdy"; break;
// case EOpFwidth: out << "fwidth"; break;
case EOpAny: out << "any"; break;
case EOpAll: out << "all"; break;
default: out.message(EPrefixError, "Bad unary op");
}
out.debug << " (" << node->getCompleteString() << ")";
out << " (" << node->getCompleteString() << ")";
out.debug << "\n";
out << "\n";
return true;
}
bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate* node)
{
TInfoSink& out = infoSink;
TInfoSinkBase& out = sink;
if (node->getOp() == EOpNull) {
out.debug.message(EPrefixError, "node is still EOpNull!");
out.message(EPrefixError, "node is still EOpNull!");
return true;
}
OutputTreeText(out, node, depth);
switch (node->getOp()) {
case EOpSequence: out.debug << "Sequence\n"; return true;
case EOpComma: out.debug << "Comma\n"; return true;
case EOpFunction: out.debug << "Function Definition: " << node->getName(); break;
case EOpFunctionCall: out.debug << "Function Call: " << node->getName(); break;
case EOpParameters: out.debug << "Function Parameters: "; break;
case EOpConstructFloat: out.debug << "Construct float"; break;
case EOpConstructVec2: out.debug << "Construct vec2"; break;
case EOpConstructVec3: out.debug << "Construct vec3"; break;
case EOpConstructVec4: out.debug << "Construct vec4"; break;
case EOpConstructBool: out.debug << "Construct bool"; break;
case EOpConstructBVec2: out.debug << "Construct bvec2"; break;
case EOpConstructBVec3: out.debug << "Construct bvec3"; break;
case EOpConstructBVec4: out.debug << "Construct bvec4"; break;
case EOpConstructInt: out.debug << "Construct int"; break;
case EOpConstructIVec2: out.debug << "Construct ivec2"; break;
case EOpConstructIVec3: out.debug << "Construct ivec3"; break;
case EOpConstructIVec4: out.debug << "Construct ivec4"; break;
case EOpConstructMat2: out.debug << "Construct mat2"; break;
case EOpConstructMat3: out.debug << "Construct mat3"; break;
case EOpConstructMat4: out.debug << "Construct mat4"; break;
case EOpConstructStruct: out.debug << "Construct structure"; break;
case EOpLessThan: out.debug << "Compare Less Than"; break;
case EOpGreaterThan: out.debug << "Compare Greater Than"; break;
case EOpLessThanEqual: out.debug << "Compare Less Than or Equal"; break;
case EOpGreaterThanEqual: out.debug << "Compare Greater Than or Equal"; break;
case EOpVectorEqual: out.debug << "Equal"; break;
case EOpVectorNotEqual: out.debug << "NotEqual"; break;
case EOpMod: out.debug << "mod"; break;
case EOpPow: out.debug << "pow"; break;
case EOpAtan: out.debug << "arc tangent"; break;
case EOpMin: out.debug << "min"; break;
case EOpMax: out.debug << "max"; break;
case EOpClamp: out.debug << "clamp"; break;
case EOpMix: out.debug << "mix"; break;
case EOpStep: out.debug << "step"; break;
case EOpSmoothStep: out.debug << "smoothstep"; break;
case EOpDistance: out.debug << "distance"; break;
case EOpDot: out.debug << "dot-product"; break;
case EOpCross: out.debug << "cross-product"; break;
case EOpFaceForward: out.debug << "face-forward"; break;
case EOpReflect: out.debug << "reflect"; break;
case EOpRefract: out.debug << "refract"; break;
case EOpMul: out.debug << "component-wise multiply"; break;
default: out.debug.message(EPrefixError, "Bad aggregation op");
case EOpSequence: out << "Sequence\n"; return true;
case EOpComma: out << "Comma\n"; return true;
case EOpFunction: out << "Function Definition: " << node->getName(); break;
case EOpFunctionCall: out << "Function Call: " << node->getName(); break;
case EOpParameters: out << "Function Parameters: "; break;
case EOpConstructFloat: out << "Construct float"; break;
case EOpConstructVec2: out << "Construct vec2"; break;
case EOpConstructVec3: out << "Construct vec3"; break;
case EOpConstructVec4: out << "Construct vec4"; break;
case EOpConstructBool: out << "Construct bool"; break;
case EOpConstructBVec2: out << "Construct bvec2"; break;
case EOpConstructBVec3: out << "Construct bvec3"; break;
case EOpConstructBVec4: out << "Construct bvec4"; break;
case EOpConstructInt: out << "Construct int"; break;
case EOpConstructIVec2: out << "Construct ivec2"; break;
case EOpConstructIVec3: out << "Construct ivec3"; break;
case EOpConstructIVec4: out << "Construct ivec4"; break;
case EOpConstructMat2: out << "Construct mat2"; break;
case EOpConstructMat3: out << "Construct mat3"; break;
case EOpConstructMat4: out << "Construct mat4"; break;
case EOpConstructStruct: out << "Construct structure"; break;
case EOpLessThan: out << "Compare Less Than"; break;
case EOpGreaterThan: out << "Compare Greater Than"; break;
case EOpLessThanEqual: out << "Compare Less Than or Equal"; break;
case EOpGreaterThanEqual: out << "Compare Greater Than or Equal"; break;
case EOpVectorEqual: out << "Equal"; break;
case EOpVectorNotEqual: out << "NotEqual"; break;
case EOpMod: out << "mod"; break;
case EOpPow: out << "pow"; break;
case EOpAtan: out << "arc tangent"; break;
case EOpMin: out << "min"; break;
case EOpMax: out << "max"; break;
case EOpClamp: out << "clamp"; break;
case EOpMix: out << "mix"; break;
case EOpStep: out << "step"; break;
case EOpSmoothStep: out << "smoothstep"; break;
case EOpDistance: out << "distance"; break;
case EOpDot: out << "dot-product"; break;
case EOpCross: out << "cross-product"; break;
case EOpFaceForward: out << "face-forward"; break;
case EOpReflect: out << "reflect"; break;
case EOpRefract: out << "refract"; break;
case EOpMul: out << "component-wise multiply"; break;
default: out.message(EPrefixError, "Bad aggregation op");
}
if (node->getOp() != EOpSequence && node->getOp() != EOpParameters)
out.debug << " (" << node->getCompleteString() << ")";
out << " (" << node->getCompleteString() << ")";
out.debug << "\n";
out << "\n";
return true;
}
bool TOutputTraverser::visitSelection(Visit visit, TIntermSelection* node)
{
TInfoSink& out = infoSink;
TInfoSinkBase& out = sink;
OutputTreeText(out, node, depth);
out.debug << "Test condition and select";
out.debug << " (" << node->getCompleteString() << ")\n";
out << "Test condition and select";
out << " (" << node->getCompleteString() << ")\n";
++depth;
OutputTreeText(infoSink, node, depth);
out.debug << "Condition\n";
OutputTreeText(sink, node, depth);
out << "Condition\n";
node->getCondition()->traverse(this);
OutputTreeText(infoSink, node, depth);
OutputTreeText(sink, node, depth);
if (node->getTrueBlock()) {
out.debug << "true case\n";
out << "true case\n";
node->getTrueBlock()->traverse(this);
} else
out.debug << "true case is null\n";
out << "true case is null\n";
if (node->getFalseBlock()) {
OutputTreeText(infoSink, node, depth);
out.debug << "false case\n";
OutputTreeText(sink, node, depth);
out << "false case\n";
node->getFalseBlock()->traverse(this);
}
......@@ -307,7 +307,7 @@ bool TOutputTraverser::visitSelection(Visit visit, TIntermSelection* node)
void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node)
{
TInfoSink& out = infoSink;
TInfoSinkBase& out = sink;
int size = node->getType().getObjectSize();
......@@ -316,23 +316,23 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node)
switch (node->getUnionArrayPointer()[i].getType()) {
case EbtBool:
if (node->getUnionArrayPointer()[i].getBConst())
out.debug << "true";
out << "true";
else
out.debug << "false";
out << "false";
out.debug << " (" << "const bool" << ")";
out.debug << "\n";
out << " (" << "const bool" << ")";
out << "\n";
break;
case EbtFloat:
out.debug << node->getUnionArrayPointer()[i].getFConst();
out.debug << " (const float)\n";
out << node->getUnionArrayPointer()[i].getFConst();
out << " (const float)\n";
break;
case EbtInt:
out.debug << node->getUnionArrayPointer()[i].getIConst();
out.debug << " (const int)\n";
out << node->getUnionArrayPointer()[i].getIConst();
out << " (const int)\n";
break;
default:
out.info.message(EPrefixInternalError, "Unknown constant", node->getLine());
out.message(EPrefixInternalError, "Unknown constant", node->getLine());
break;
}
}
......@@ -340,34 +340,34 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node)
bool TOutputTraverser::visitLoop(Visit visit, TIntermLoop* node)
{
TInfoSink& out = infoSink;
TInfoSinkBase& out = sink;
OutputTreeText(out, node, depth);
out.debug << "Loop with condition ";
out << "Loop with condition ";
if (! node->testFirst())
out.debug << "not ";
out.debug << "tested first\n";
out << "not ";
out << "tested first\n";
++depth;
OutputTreeText(infoSink, node, depth);
OutputTreeText(sink, node, depth);
if (node->getTest()) {
out.debug << "Loop Condition\n";
out << "Loop Condition\n";
node->getTest()->traverse(this);
} else
out.debug << "No loop condition\n";
out << "No loop condition\n";
OutputTreeText(infoSink, node, depth);
OutputTreeText(sink, node, depth);
if (node->getBody()) {
out.debug << "Loop Body\n";
out << "Loop Body\n";
node->getBody()->traverse(this);
} else
out.debug << "No loop body\n";
out << "No loop body\n";
if (node->getTerminal()) {
OutputTreeText(infoSink, node, depth);
out.debug << "Loop Terminal Expression\n";
OutputTreeText(sink, node, depth);
out << "Loop Terminal Expression\n";
node->getTerminal()->traverse(this);
}
......@@ -378,25 +378,25 @@ bool TOutputTraverser::visitLoop(Visit visit, TIntermLoop* node)
bool TOutputTraverser::visitBranch(Visit visit, TIntermBranch* node)
{
TInfoSink& out = infoSink;
TInfoSinkBase& out = sink;
OutputTreeText(out, node, depth);
switch (node->getFlowOp()) {
case EOpKill: out.debug << "Branch: Kill"; break;
case EOpBreak: out.debug << "Branch: Break"; break;
case EOpContinue: out.debug << "Branch: Continue"; break;
case EOpReturn: out.debug << "Branch: Return"; break;
default: out.debug << "Branch: Unknown Branch"; break;
case EOpKill: out << "Branch: Kill"; break;
case EOpBreak: out << "Branch: Break"; break;
case EOpContinue: out << "Branch: Continue"; break;
case EOpReturn: out << "Branch: Return"; break;
default: out << "Branch: Unknown Branch"; break;
}
if (node->getExpression()) {
out.debug << " with expression\n";
out << " with expression\n";
++depth;
node->getExpression()->traverse(this);
--depth;
} else
out.debug << "\n";
out << "\n";
return false;
}
......@@ -411,7 +411,7 @@ void TIntermediate::outputTree(TIntermNode* root)
if (root == 0)
return;
TOutputTraverser it(infoSink);
TOutputTraverser it(infoSink.info);
root->traverse(&it);
}
......@@ -281,21 +281,23 @@ void Shader::compileToHLSL(void *compiler)
delete[] mInfoLog;
mInfoLog = NULL;
int result = ShCompile(compiler, &mSource, 1, EShOptNone, EDebugOpNone);
const char *obj = ShGetObjectCode(compiler);
const char *info = ShGetInfoLog(compiler);
int result = ShCompile(compiler, &mSource, 1, EShOptObjectCode);
if (result)
{
mHlsl = new char[strlen(obj) + 1];
strcpy(mHlsl, obj);
int objCodeLen = 0;
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen);
mHlsl = new char[objCodeLen];
ShGetObjectCode(compiler, mHlsl);
TRACE("\n%s", mHlsl);
}
else
{
mInfoLog = new char[strlen(info) + 1];
strcpy(mInfoLog, info);
int infoLogLen = 0;
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
mInfoLog = new char[infoLogLen];
ShGetInfoLog(compiler, 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