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
...@@ -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;
......
...@@ -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