Commit 4de44cb6 by Zhenyao Mo

Change ShaderLang APIs from c style to c++ style.

BUG=angle:816 TEST=gpu_unittests,angle_unittests,webgl_conformance Change-Id: I0b46c11f6055a82511bb946a6dc491360835526e Reviewed-on: https://chromium-review.googlesource.com/226410Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent f108df24
...@@ -27,6 +27,10 @@ ...@@ -27,6 +27,10 @@
#include "KHR/khrplatform.h" #include "KHR/khrplatform.h"
#include <map>
#include <string>
#include <vector>
// //
// This is the platform independent interface between an OGL driver // This is the platform independent interface between an OGL driver
// and the shading language compiler. // and the shading language compiler.
...@@ -42,13 +46,9 @@ typedef unsigned int GLenum; ...@@ -42,13 +46,9 @@ typedef unsigned int GLenum;
// Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h // Note: make sure to increment ANGLE_SH_VERSION when changing ShaderVars.h
#include "ShaderVars.h" #include "ShaderVars.h"
#ifdef __cplusplus
extern "C" {
#endif
// Version number for shader translation API. // Version number for shader translation API.
// It is incremented every time the API changes. // It is incremented every time the API changes.
#define ANGLE_SH_VERSION 131 #define ANGLE_SH_VERSION 132
typedef enum { typedef enum {
SH_GLES2_SPEC = 0x8B40, SH_GLES2_SPEC = 0x8B40,
...@@ -88,18 +88,6 @@ typedef enum { ...@@ -88,18 +88,6 @@ typedef enum {
SH_HLSL11_OUTPUT = 0x8B48 SH_HLSL11_OUTPUT = 0x8B48
} ShShaderOutput; } ShShaderOutput;
typedef enum {
SH_INFO_LOG_LENGTH = 0x8B84,
SH_OBJECT_CODE_LENGTH = 0x8B88, // GL_SHADER_SOURCE_LENGTH
SH_MAPPED_NAME_MAX_LENGTH = 0x6000,
SH_NAME_MAX_LENGTH = 0x6001,
SH_HASHED_NAME_MAX_LENGTH = 0x6002,
SH_HASHED_NAMES_COUNT = 0x6003,
SH_SHADER_VERSION = 0x6004,
SH_RESOURCES_STRING_LENGTH = 0x6005,
SH_OUTPUT_TYPE = 0x6006
} ShShaderInfo;
// Compile options. // Compile options.
typedef enum { typedef enum {
SH_VALIDATE = 0, SH_VALIDATE = 0,
...@@ -198,14 +186,14 @@ typedef enum { ...@@ -198,14 +186,14 @@ typedef enum {
// //
// Driver must call this first, once, before doing any other // Driver must call this first, once, before doing any other
// compiler operations. // compiler operations.
// If the function succeeds, the return value is nonzero, else zero. // If the function succeeds, the return value is true, else false.
// //
COMPILER_EXPORT int ShInitialize(); COMPILER_EXPORT bool ShInitialize();
// //
// Driver should call this at shutdown. // Driver should call this at shutdown.
// If the function succeeds, the return value is nonzero, else zero. // If the function succeeds, the return value is true, else false.
// //
COMPILER_EXPORT int ShFinalize(); COMPILER_EXPORT bool ShFinalize();
// The 64 bits hash function. The first parameter is the input string; the // The 64 bits hash function. The first parameter is the input string; the
// second parameter is the string length. // second parameter is the string length.
...@@ -273,7 +261,7 @@ typedef struct ...@@ -273,7 +261,7 @@ typedef struct
// Parameters: // Parameters:
// resources: The object to initialize. Will be comparable with memcmp. // resources: The object to initialize. Will be comparable with memcmp.
// //
COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources); COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources *resources);
// //
// ShHandle held by but opaque to the driver. It is allocated, // ShHandle held by but opaque to the driver. It is allocated,
...@@ -282,18 +270,15 @@ COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources); ...@@ -282,18 +270,15 @@ COMPILER_EXPORT void ShInitBuiltInResources(ShBuiltInResources* resources);
// //
// If handle creation fails, 0 will be returned. // If handle creation fails, 0 will be returned.
// //
typedef void* ShHandle; typedef void *ShHandle;
// //
// Returns the a concatenated list of the items in ShBuiltInResources as a string. // Returns the a concatenated list of the items in ShBuiltInResources as a
// null-terminated string.
// This function must be updated whenever ShBuiltInResources is changed. // This function must be updated whenever ShBuiltInResources is changed.
// Parameters: // Parameters:
// handle: Specifies the handle of the compiler to be used. // handle: Specifies the handle of the compiler to be used.
// outStringLen: Specifies the size of the buffer, in number of characters. The size COMPILER_EXPORT const std::string &ShGetBuiltInResourcesString(const ShHandle handle);
// of the buffer required to store the resources string can be obtained
// by calling ShGetInfo with SH_RESOURCES_STRING_LENGTH.
// outStr: Returns a null-terminated string representing all the built-in resources.
COMPILER_EXPORT void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, char *outStr);
// //
// Driver calls these to create and destroy compiler objects. // Driver calls these to create and destroy compiler objects.
...@@ -311,12 +296,12 @@ COMPILER_EXPORT ShHandle ShConstructCompiler( ...@@ -311,12 +296,12 @@ COMPILER_EXPORT ShHandle ShConstructCompiler(
sh::GLenum type, sh::GLenum type,
ShShaderSpec spec, ShShaderSpec spec,
ShShaderOutput output, ShShaderOutput output,
const ShBuiltInResources* resources); const ShBuiltInResources *resources);
COMPILER_EXPORT void ShDestruct(ShHandle handle); COMPILER_EXPORT void ShDestruct(ShHandle handle);
// //
// Compiles the given shader source. // Compiles the given shader source.
// If the function succeeds, the return value is nonzero, else zero. // If the function succeeds, the return value is true, else false.
// Parameters: // Parameters:
// handle: Specifies the handle of compiler to be used. // handle: Specifies the handle of compiler to be used.
// shaderStrings: Specifies an array of pointers to null-terminated strings // shaderStrings: Specifies an array of pointers to null-terminated strings
...@@ -338,74 +323,36 @@ COMPILER_EXPORT void ShDestruct(ShHandle handle); ...@@ -338,74 +323,36 @@ COMPILER_EXPORT void ShDestruct(ShHandle handle);
// SH_VARIABLES: Extracts attributes, uniforms, and varyings. // SH_VARIABLES: Extracts attributes, uniforms, and varyings.
// Can be queried by calling ShGetVariableInfo(). // Can be queried by calling ShGetVariableInfo().
// //
COMPILER_EXPORT int ShCompile( COMPILER_EXPORT bool ShCompile(
const ShHandle handle, const ShHandle handle,
const char* const shaderStrings[], const char * const shaderStrings[],
size_t numStrings, size_t numStrings,
int compileOptions int compileOptions);
);
// Returns a parameter from a compiled shader. // Return the version of the shader language.
// Parameters: COMPILER_EXPORT int ShGetShaderVersion(const ShHandle handle);
// handle: Specifies the compiler
// pname: Specifies the parameter to query. // Return the currently set language output type.
// The following parameters are defined: COMPILER_EXPORT ShShaderOutput ShGetShaderOutputType(
// SH_INFO_LOG_LENGTH: the number of characters in the information log const ShHandle handle);
// including the null termination character.
// SH_OBJECT_CODE_LENGTH: the number of characters in the object code
// including the null termination character.
// SH_MAPPED_NAME_MAX_LENGTH: the length of the mapped variable name including
// the null termination character.
// SH_NAME_MAX_LENGTH: the max length of a user-defined name including the
// null termination character.
// SH_HASHED_NAME_MAX_LENGTH: the max length of a hashed name including the
// null termination character.
// SH_HASHED_NAMES_COUNT: the number of hashed names from the latest compile.
// SH_SHADER_VERSION: the version of the shader language
// SH_OUTPUT_TYPE: the currently set language output type
//
// params: Requested parameter
COMPILER_EXPORT void ShGetInfo(const ShHandle handle,
ShShaderInfo pname,
size_t* params);
// Returns nul-terminated information log for a compiled shader. // Returns null-terminated information log for a compiled shader.
// Parameters: // Parameters:
// handle: Specifies the compiler // handle: Specifies the compiler
// infoLog: Specifies an array of characters that is used to return COMPILER_EXPORT const std::string &ShGetInfoLog(const ShHandle handle);
// 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.
COMPILER_EXPORT void ShGetInfoLog(const ShHandle handle, char* infoLog);
// Returns null-terminated object code for a compiled shader. // Returns null-terminated object code for a compiled shader.
// Parameters: // Parameters:
// handle: Specifies the compiler // handle: Specifies the compiler
// infoLog: Specifies an array of characters that is used to return COMPILER_EXPORT const std::string &ShGetObjectCode(const ShHandle handle);
// the object code. It is assumed that infoLog has enough memory to
// accomodate the object code. The size of the buffer required to // Returns a (original_name, hash) map containing all the user defined
// store the returned object code can be obtained by calling // names in the shader, including variable names, function names, struct
// ShGetInfo with SH_OBJECT_CODE_LENGTH. // names, and struct field names.
COMPILER_EXPORT void ShGetObjectCode(const ShHandle handle, char* objCode);
// Returns information about a name hashing entry from the latest compile.
// Parameters: // Parameters:
// handle: Specifies the compiler // handle: Specifies the compiler
// index: Specifies the index of the name hashing entry to be queried. COMPILER_EXPORT const std::map<std::string, std::string> *ShGetNameHashingMap(
// name: Returns a null terminated string containing the user defined name. const ShHandle handle);
// It is assumed that name has enough memory to accomodate the name.
// The size of the buffer required to store the user defined name can
// be obtained by calling ShGetInfo with SH_NAME_MAX_LENGTH.
// hashedName: Returns a null terminated string containing the hashed name of
// the uniform variable, It is assumed that hashedName has enough
// memory to accomodate the name. The size of the buffer required
// to store the name can be obtained by calling ShGetInfo with
// SH_HASHED_NAME_MAX_LENGTH.
COMPILER_EXPORT void ShGetNameHashingEntry(const ShHandle handle,
int index,
char* name,
char* hashedName);
// Shader variable inspection. // Shader variable inspection.
// Returns a pointer to a list of variables of the designated type. // Returns a pointer to a list of variables of the designated type.
...@@ -425,17 +372,17 @@ typedef struct ...@@ -425,17 +372,17 @@ typedef struct
int size; int size;
} ShVariableInfo; } ShVariableInfo;
// Returns 1 if the passed in variables pack in maxVectors following // Returns true if the passed in variables pack in maxVectors following
// the packing rules from the GLSL 1.017 spec, Appendix A, section 7. // the packing rules from the GLSL 1.017 spec, Appendix A, section 7.
// Returns 0 otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS // Returns false otherwise. Also look at the SH_ENFORCE_PACKING_RESTRICTIONS
// flag above. // flag above.
// Parameters: // Parameters:
// maxVectors: the available rows of registers. // maxVectors: the available rows of registers.
// varInfoArray: an array of variable info (types and sizes). // varInfoArray: an array of variable info (types and sizes).
// varInfoArraySize: the size of the variable array. // varInfoArraySize: the size of the variable array.
COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits( COMPILER_EXPORT bool ShCheckVariablesWithinPackingLimits(
int maxVectors, int maxVectors,
ShVariableInfo* varInfoArray, ShVariableInfo *varInfoArray,
size_t varInfoArraySize); size_t varInfoArraySize);
// Gives the compiler-assigned register for an interface block. // Gives the compiler-assigned register for an interface block.
...@@ -446,7 +393,7 @@ COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits( ...@@ -446,7 +393,7 @@ COMPILER_EXPORT int ShCheckVariablesWithinPackingLimits(
// interfaceBlockName: Specifies the interface block // interfaceBlockName: Specifies the interface block
// indexOut: output variable that stores the assigned register // indexOut: output variable that stores the assigned register
COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle, COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle,
const char *interfaceBlockName, const std::string &interfaceBlockName,
unsigned int *indexOut); unsigned int *indexOut);
// Gives the compiler-assigned register for uniforms in the default // Gives the compiler-assigned register for uniforms in the default
...@@ -458,11 +405,7 @@ COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle, ...@@ -458,11 +405,7 @@ COMPILER_EXPORT bool ShGetInterfaceBlockRegister(const ShHandle handle,
// interfaceBlockName: Specifies the uniform // interfaceBlockName: Specifies the uniform
// indexOut: output variable that stores the assigned register // indexOut: output variable that stores the assigned register
COMPILER_EXPORT bool ShGetUniformRegister(const ShHandle handle, COMPILER_EXPORT bool ShGetUniformRegister(const ShHandle handle,
const char *uniformName, const std::string &uniformName,
unsigned int *indexOut); unsigned int *indexOut);
#ifdef __cplusplus
}
#endif
#endif // _COMPILER_INTERFACE_INCLUDED_ #endif // _COMPILER_INTERFACE_INCLUDED_
...@@ -80,7 +80,7 @@ class TCompiler : public TShHandleBase ...@@ -80,7 +80,7 @@ class TCompiler : public TShHandleBase
TSymbolTable& getSymbolTable() { return symbolTable; } TSymbolTable& getSymbolTable() { return symbolTable; }
ShShaderSpec getShaderSpec() const { return shaderSpec; } ShShaderSpec getShaderSpec() const { return shaderSpec; }
ShShaderOutput getOutputType() const { return outputType; } ShShaderOutput getOutputType() const { return outputType; }
std::string getBuiltInResourcesString() const { return builtInResourcesString; } const std::string &getBuiltInResourcesString() const { return builtInResourcesString; }
// Get the resources set by InitBuiltInSymbolTable // Get the resources set by InitBuiltInSymbolTable
const ShBuiltInResources& getResources() const; const ShBuiltInResources& getResources() const;
......
...@@ -84,32 +84,48 @@ const std::vector<VarT> *GetShaderVariables(const ShHandle handle, ShaderVariabl ...@@ -84,32 +84,48 @@ const std::vector<VarT> *GetShaderVariables(const ShHandle handle, ShaderVariabl
return GetVariableList<VarT>(compiler, variableType); return GetVariableList<VarT>(compiler, variableType);
} }
TCompiler *GetCompilerFromHandle(ShHandle handle)
{
if (!handle)
return NULL;
TShHandleBase *base = static_cast<TShHandleBase *>(handle);
return base->getAsCompiler();
} }
TranslatorHLSL *GetTranslatorHLSLFromHandle(ShHandle handle)
{
if (!handle)
return NULL;
TShHandleBase *base = static_cast<TShHandleBase *>(handle);
return base->getAsTranslatorHLSL();
}
} // namespace anonymous
// //
// Driver must call this first, once, before doing any other compiler operations. // Driver must call this first, once, before doing any other compiler operations.
// Subsequent calls to this function are no-op. // Subsequent calls to this function are no-op.
// //
int ShInitialize() bool ShInitialize()
{ {
if (!isInitialized) if (!isInitialized)
{ {
isInitialized = InitProcess(); isInitialized = InitProcess();
} }
return isInitialized ? 1 : 0; return isInitialized;
} }
// //
// Cleanup symbol tables // Cleanup symbol tables
// //
int ShFinalize() bool ShFinalize()
{ {
if (isInitialized) if (isInitialized)
{ {
DetachProcess(); DetachProcess();
isInitialized = false; isInitialized = false;
} }
return 1; return true;
} }
// //
...@@ -190,23 +206,13 @@ void ShDestruct(ShHandle handle) ...@@ -190,23 +206,13 @@ void ShDestruct(ShHandle handle)
DeleteCompiler(base->getAsCompiler()); DeleteCompiler(base->getAsCompiler());
} }
void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, char *outString) const std::string &ShGetBuiltInResourcesString(const ShHandle handle)
{ {
if (!handle || !outString) TCompiler *compiler = GetCompilerFromHandle(handle);
{ ASSERT(compiler);
return; return compiler->getBuiltInResourcesString();
}
TShHandleBase *base = static_cast<TShHandleBase*>(handle);
TCompiler *compiler = base->getAsCompiler();
if (!compiler)
{
return;
}
strncpy(outString, compiler->getBuiltInResourcesString().c_str(), outStringLen);
outString[outStringLen - 1] = '\0';
} }
// //
// Do an actual compile on the given strings. The result is left // Do an actual compile on the given strings. The result is left
// in the given compile object. // in the given compile object.
...@@ -214,149 +220,62 @@ void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, cha ...@@ -214,149 +220,62 @@ void ShGetBuiltInResourcesString(const ShHandle handle, size_t outStringLen, cha
// Return: The return value of ShCompile is really boolean, indicating // Return: The return value of ShCompile is really boolean, indicating
// success or failure. // success or failure.
// //
int ShCompile( bool ShCompile(
const ShHandle handle, const ShHandle handle,
const char* const shaderStrings[], const char *const shaderStrings[],
size_t numStrings, size_t numStrings,
int compileOptions) int compileOptions)
{ {
if (handle == 0) TCompiler *compiler = GetCompilerFromHandle(handle);
return 0; ASSERT(compiler);
TShHandleBase* base = reinterpret_cast<TShHandleBase*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (compiler == 0)
return 0;
bool success = compiler->compile(shaderStrings, numStrings, compileOptions); return compiler->compile(shaderStrings, numStrings, compileOptions);
return success ? 1 : 0;
} }
void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params) int ShGetShaderVersion(const ShHandle handle)
{ {
if (!handle || !params) TCompiler* compiler = GetCompilerFromHandle(handle);
return; ASSERT(compiler);
return compiler->getShaderVersion();
TShHandleBase* base = static_cast<TShHandleBase*>(handle); }
TCompiler* compiler = base->getAsCompiler();
if (!compiler) return;
switch(pname) ShShaderOutput ShGetShaderOutputType(const ShHandle handle)
{ {
case SH_INFO_LOG_LENGTH: TCompiler* compiler = GetCompilerFromHandle(handle);
*params = compiler->getInfoSink().info.size() + 1; ASSERT(compiler);
break; return compiler->getOutputType();
case SH_OBJECT_CODE_LENGTH:
*params = compiler->getInfoSink().obj.size() + 1;
break;
case SH_MAPPED_NAME_MAX_LENGTH:
// Use longer length than MAX_SHORTENED_IDENTIFIER_SIZE to
// handle array and struct dereferences.
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
break;
case SH_NAME_MAX_LENGTH:
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
break;
case SH_HASHED_NAME_MAX_LENGTH:
if (compiler->getHashFunction() == NULL) {
*params = 0;
} else {
// 64 bits hashing output requires 16 bytes for hex
// representation.
const char HashedNamePrefix[] = HASHED_NAME_PREFIX;
(void)HashedNamePrefix;
*params = 16 + sizeof(HashedNamePrefix);
}
break;
case SH_HASHED_NAMES_COUNT:
*params = compiler->getNameMap().size();
break;
case SH_SHADER_VERSION:
*params = compiler->getShaderVersion();
break;
case SH_RESOURCES_STRING_LENGTH:
*params = compiler->getBuiltInResourcesString().length() + 1;
break;
case SH_OUTPUT_TYPE:
*params = compiler->getOutputType();
break;
default: UNREACHABLE();
}
} }
// //
// Return any compiler log of messages for the application. // Return any compiler log of messages for the application.
// //
void ShGetInfoLog(const ShHandle handle, char* infoLog) const std::string &ShGetInfoLog(const ShHandle handle)
{ {
if (!handle || !infoLog) TCompiler *compiler = GetCompilerFromHandle(handle);
return; ASSERT(compiler);
TShHandleBase* base = static_cast<TShHandleBase*>(handle); TInfoSink &infoSink = compiler->getInfoSink();
TCompiler* compiler = base->getAsCompiler(); return infoSink.info.str();
if (!compiler) return;
TInfoSink& infoSink = compiler->getInfoSink();
strcpy(infoLog, infoSink.info.c_str());
} }
// //
// Return any object code. // Return any object code.
// //
void ShGetObjectCode(const ShHandle handle, char* objCode) const std::string &ShGetObjectCode(const ShHandle handle)
{ {
if (!handle || !objCode) TCompiler *compiler = GetCompilerFromHandle(handle);
return; ASSERT(compiler);
TShHandleBase* base = static_cast<TShHandleBase*>(handle); TInfoSink &infoSink = compiler->getInfoSink();
TCompiler* compiler = base->getAsCompiler(); return infoSink.obj.str();
if (!compiler) return;
TInfoSink& infoSink = compiler->getInfoSink();
strcpy(objCode, infoSink.obj.c_str());
} }
void ShGetNameHashingEntry(const ShHandle handle, const std::map<std::string, std::string> *ShGetNameHashingMap(
int index, const ShHandle handle)
char* name,
char* hashedName)
{ {
if (!handle || !name || !hashedName || index < 0) TCompiler *compiler = GetCompilerFromHandle(handle);
return; ASSERT(compiler);
return &(compiler->getNameMap());
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
TCompiler* compiler = base->getAsCompiler();
if (!compiler) return;
const NameMap& nameMap = compiler->getNameMap();
if (index >= static_cast<int>(nameMap.size()))
return;
NameMap::const_iterator it = nameMap.begin();
for (int i = 0; i < index; ++i)
++it;
size_t len = it->first.length() + 1;
size_t max_len = 0;
ShGetInfo(handle, SH_NAME_MAX_LENGTH, &max_len);
if (len > max_len) {
ASSERT(false);
len = max_len;
}
strncpy(name, it->first.c_str(), len);
// To be on the safe side in case the source is longer than expected.
name[len - 1] = '\0';
len = it->second.length() + 1;
max_len = 0;
ShGetInfo(handle, SH_HASHED_NAME_MAX_LENGTH, &max_len);
if (len > max_len) {
ASSERT(false);
len = max_len;
}
strncpy(hashedName, it->second.c_str(), len);
// To be on the safe side in case the source is longer than expected.
hashedName[len - 1] = '\0';
} }
const std::vector<sh::Uniform> *ShGetUniforms(const ShHandle handle) const std::vector<sh::Uniform> *ShGetUniforms(const ShHandle handle)
...@@ -384,11 +303,11 @@ const std::vector<sh::InterfaceBlock> *ShGetInterfaceBlocks(const ShHandle handl ...@@ -384,11 +303,11 @@ const std::vector<sh::InterfaceBlock> *ShGetInterfaceBlocks(const ShHandle handl
return GetShaderVariables<sh::InterfaceBlock>(handle, SHADERVAR_INTERFACEBLOCK); return GetShaderVariables<sh::InterfaceBlock>(handle, SHADERVAR_INTERFACEBLOCK);
} }
int ShCheckVariablesWithinPackingLimits( bool ShCheckVariablesWithinPackingLimits(
int maxVectors, ShVariableInfo* varInfoArray, size_t varInfoArraySize) int maxVectors, ShVariableInfo *varInfoArray, size_t varInfoArraySize)
{ {
if (varInfoArraySize == 0) if (varInfoArraySize == 0)
return 1; return true;
ASSERT(varInfoArray); ASSERT(varInfoArray);
std::vector<sh::ShaderVariable> variables; std::vector<sh::ShaderVariable> variables;
for (size_t ii = 0; ii < varInfoArraySize; ++ii) for (size_t ii = 0; ii < varInfoArraySize; ++ii)
...@@ -397,24 +316,17 @@ int ShCheckVariablesWithinPackingLimits( ...@@ -397,24 +316,17 @@ int ShCheckVariablesWithinPackingLimits(
variables.push_back(var); variables.push_back(var);
} }
VariablePacker packer; VariablePacker packer;
return packer.CheckVariablesWithinPackingLimits(maxVectors, variables) ? 1 : 0; return packer.CheckVariablesWithinPackingLimits(maxVectors, variables);
} }
bool ShGetInterfaceBlockRegister(const ShHandle handle, bool ShGetInterfaceBlockRegister(const ShHandle handle,
const char *interfaceBlockName, const std::string &interfaceBlockName,
unsigned int *indexOut) unsigned int *indexOut)
{ {
if (!handle || !interfaceBlockName || !indexOut) ASSERT(indexOut);
{
return false;
}
TShHandleBase* base = static_cast<TShHandleBase*>(handle); TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
TranslatorHLSL* translator = base->getAsTranslatorHLSL(); ASSERT(translator);
if (!translator)
{
return false;
}
if (!translator->hasInterfaceBlock(interfaceBlockName)) if (!translator->hasInterfaceBlock(interfaceBlockName))
{ {
...@@ -426,20 +338,12 @@ bool ShGetInterfaceBlockRegister(const ShHandle handle, ...@@ -426,20 +338,12 @@ bool ShGetInterfaceBlockRegister(const ShHandle handle,
} }
bool ShGetUniformRegister(const ShHandle handle, bool ShGetUniformRegister(const ShHandle handle,
const char *uniformName, const std::string &uniformName,
unsigned int *indexOut) unsigned int *indexOut)
{ {
if (!handle || !uniformName || !indexOut) ASSERT(indexOut);
{ TranslatorHLSL *translator = GetTranslatorHLSLFromHandle(handle);
return false; ASSERT(translator);
}
TShHandleBase* base = static_cast<TShHandleBase*>(handle);
TranslatorHLSL* translator = base->getAsTranslatorHLSL();
if (!translator)
{
return false;
}
if (!translator->hasUniform(uniformName)) if (!translator->hasUniform(uniformName))
{ {
......
...@@ -102,7 +102,7 @@ void ShaderD3D::initializeCompiler() ...@@ -102,7 +102,7 @@ void ShaderD3D::initializeCompiler()
{ {
if (!mFragmentCompiler) if (!mFragmentCompiler)
{ {
int result = ShInitialize(); bool result = ShInitialize();
if (result) if (result)
{ {
...@@ -252,23 +252,16 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source) ...@@ -252,23 +252,16 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
result = ShCompile(compiler, sourceStrings, ArraySize(sourceStrings), compileOptions | SH_SOURCE_PATH); result = ShCompile(compiler, sourceStrings, ArraySize(sourceStrings), compileOptions | SH_SOURCE_PATH);
} }
size_t shaderVersion = 100; mShaderVersion = ShGetShaderVersion(compiler);
ShGetInfo(compiler, SH_SHADER_VERSION, &shaderVersion);
mShaderVersion = static_cast<int>(shaderVersion); if (mShaderVersion == 300 && mRenderer->getCurrentClientVersion() < 3)
if (shaderVersion == 300 && mRenderer->getCurrentClientVersion() < 3)
{ {
mInfoLog = "GLSL ES 3.00 is not supported by OpenGL ES 2.0 contexts"; mInfoLog = "GLSL ES 3.00 is not supported by OpenGL ES 2.0 contexts";
TRACE("\n%s", mInfoLog.c_str()); TRACE("\n%s", mInfoLog.c_str());
} }
else if (result) else if (result)
{ {
size_t objCodeLen = 0; mHlsl = ShGetObjectCode(compiler);
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen);
std::vector<char> outputHLSL(objCodeLen);
ShGetObjectCode(compiler, outputHLSL.data());
#ifdef _DEBUG #ifdef _DEBUG
// Prefix hlsl shader with commented out glsl shader // Prefix hlsl shader with commented out glsl shader
...@@ -288,10 +281,8 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source) ...@@ -288,10 +281,8 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1); curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1);
} }
hlslStream << "\n\n"; hlslStream << "\n\n";
hlslStream << outputHLSL.data(); hlslStream << mHlsl;
mHlsl = hlslStream.str(); mHlsl = hlslStream.str();
#else
mHlsl = outputHLSL.data();
#endif #endif
mUniforms = *GetShaderVariables(ShGetUniforms(compiler)); mUniforms = *GetShaderVariables(ShGetUniforms(compiler));
...@@ -303,7 +294,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source) ...@@ -303,7 +294,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
if (uniform.staticUse) if (uniform.staticUse)
{ {
unsigned int index = -1; unsigned int index = -1;
bool result = ShGetUniformRegister(compiler, uniform.name.c_str(), &index); bool result = ShGetUniformRegister(compiler, uniform.name, &index);
UNUSED_ASSERTION_VARIABLE(result); UNUSED_ASSERTION_VARIABLE(result);
ASSERT(result); ASSERT(result);
...@@ -320,7 +311,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source) ...@@ -320,7 +311,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
if (interfaceBlock.staticUse) if (interfaceBlock.staticUse)
{ {
unsigned int index = -1; unsigned int index = -1;
bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name.c_str(), &index); bool result = ShGetInterfaceBlockRegister(compiler, interfaceBlock.name, &index);
UNUSED_ASSERTION_VARIABLE(result); UNUSED_ASSERTION_VARIABLE(result);
ASSERT(result); ASSERT(result);
...@@ -330,14 +321,9 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source) ...@@ -330,14 +321,9 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
} }
else else
{ {
size_t infoLogLen = 0; mInfoLog = ShGetInfoLog(compiler);
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &infoLogLen);
std::vector<char> infoLog(infoLogLen); TRACE("\n%s", mInfoLog.c_str());
ShGetInfoLog(compiler, infoLog.data());
mInfoLog = infoLog.data();
TRACE("\n%s", infoLog.data());
} }
} }
...@@ -419,10 +405,7 @@ ShShaderOutput ShaderD3D::getCompilerOutputType(GLenum shader) ...@@ -419,10 +405,7 @@ ShShaderOutput ShaderD3D::getCompilerOutputType(GLenum shader)
default: UNREACHABLE(); return SH_HLSL9_OUTPUT; default: UNREACHABLE(); return SH_HLSL9_OUTPUT;
} }
size_t outputType = 0; return ShGetShaderOutputType(compiler);
ShGetInfo(compiler, SH_OUTPUT_TYPE, &outputType);
return static_cast<ShShaderOutput>(outputType);
} }
bool ShaderD3D::compile(const std::string &source) bool ShaderD3D::compile(const std::string &source)
......
...@@ -144,19 +144,18 @@ protected: ...@@ -144,19 +144,18 @@ protected:
// substring in the error log. This way we know the error is specific // substring in the error log. This way we know the error is specific
// to the issue we are testing. // to the issue we are testing.
bool CheckShaderCompilation(ShHandle compiler, bool CheckShaderCompilation(ShHandle compiler,
const char* source, const char *source,
int compileOptions, int compileOptions,
const char* expected_error) { const char *expected_error)
{
bool success = ShCompile(compiler, &source, 1, compileOptions) != 0; bool success = ShCompile(compiler, &source, 1, compileOptions) != 0;
if (success) { if (success)
{
success = !expected_error; success = !expected_error;
} else { }
size_t bufferLen = 0; else
ShGetInfo(compiler, SH_INFO_LOG_LENGTH, &bufferLen); {
char* buffer(new char [bufferLen]); std::string log = ShGetInfoLog(compiler);
ShGetInfoLog(compiler, buffer);
std::string log(buffer, buffer + bufferLen);
delete [] buffer;
if (expected_error) if (expected_error)
success = log.find(expected_error) != std::string::npos; success = log.find(expected_error) != std::string::npos;
......
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