gl::Error CompilerD3D::release() { if (mFragmentCompiler) { ShDestruct(mFragmentCompiler); mFragmentCompiler = NULL; ASSERT(activeCompilerHandles > 0); activeCompilerHandles--; } if (mVertexCompiler) { ShDestruct(mVertexCompiler); mVertexCompiler = NULL; ASSERT(activeCompilerHandles > 0); activeCompilerHandles--; } if (activeCompilerHandles == 0) { ShFinalize(); } return gl::Error(GL_NO_ERROR); }
ANGLEWebKitBridge::~ANGLEWebKitBridge() { if (builtCompilers) { ShDestruct(m_fragmentCompiler); ShDestruct(m_vertexCompiler); } }
Error Compiler::release() { if (mFragmentCompiler) { ShDestruct(mFragmentCompiler); mFragmentCompiler = nullptr; ASSERT(activeCompilerHandles > 0); activeCompilerHandles--; } if (mVertexCompiler) { ShDestruct(mVertexCompiler); mVertexCompiler = nullptr; ASSERT(activeCompilerHandles > 0); activeCompilerHandles--; } if (activeCompilerHandles == 0) { ShFinalize(); } mImplementation->release(); return gl::Error(GL_NO_ERROR); }
void Shader::releaseCompiler() { ShDestruct(mFragmentCompiler); ShDestruct(mVertexCompiler); mFragmentCompiler = NULL; mVertexCompiler = NULL; }
void ShaderD3D::releaseCompiler() { ShDestruct(mFragmentCompiler); ShDestruct(mVertexCompiler); mFragmentCompiler = NULL; mVertexCompiler = NULL; ShFinalize(); }
void ANGLEWebKitBridge::cleanupCompilers() { if (m_fragmentCompiler) ShDestruct(m_fragmentCompiler); m_fragmentCompiler = nullptr; if (m_vertexCompiler) ShDestruct(m_vertexCompiler); m_vertexCompiler = nullptr; builtCompilers = false; }
void ANGLEPlatformBridge::cleanupCompilers() { if (m_fragmentCompiler) ShDestruct(m_fragmentCompiler); m_fragmentCompiler = 0; if (m_vertexCompiler) ShDestruct(m_vertexCompiler); m_vertexCompiler = 0; builtCompilers = false; }
osgToy::GlslLint::~GlslLint() { while( !_compilerList.empty() ) { ShHandle compiler = _compilerList.back(); _compilerList.pop_back(); ShDestruct( compiler ); } if( _linker) ShDestruct( _linker ); if( _uniformMap ) ShDestruct( _uniformMap ); }
void DestroyCompiler() { if (mCompiler) { ShDestruct(mCompiler); mCompiler = nullptr; } }
void DestroyCompiler() { if (mCompiler) { ShDestruct(mCompiler); mCompiler = NULL; } }
// // Driver calls these to create and destroy compiler objects. // ShHandle ShConstructCompiler(ShShaderType type, ShShaderSpec spec, ShShaderOutput output, const ShBuiltInResources* resources) { TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(type, spec, output)); 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); }
// // Thread entry point, for non-linking asynchronous mode. // // Return 0 for failure, 1 for success. // unsigned int CompileShaders(void*) { glslang::TWorkItem* workItem; while (Worklist.remove(workItem)) { ShHandle compiler = ShConstructCompiler(FindLanguage(workItem->name), Options); if (compiler == 0) return 0; CompileFile(workItem->name.c_str(), compiler); if (! (Options & EOptionSuppressInfolog)) workItem->results = ShGetInfoLog(compiler); ShDestruct(compiler); } return 0; }
// // Driver calls these to create and destroy compiler objects. // ShHandle ShConstructCompiler(EShLanguage language, EShSpec spec, const TBuiltInResource* resources) { if (!InitThread()) return 0; TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(language, spec)); TCompiler* compiler = base->getAsCompiler(); if (compiler == 0) return 0; // Generate built-in symbol table. if (!GenerateBuiltInSymbolTable(language, spec, *resources, compiler->getInfoSink(), compiler->getSymbolTable())) { ShDestruct(base); return 0; } return reinterpret_cast<void*>(base); }
// Test that using invariant varyings doesn't trigger a double delete. TEST(ShaderVariableTest, InvariantDoubleDeleteBug) { ShBuiltInResources resources; ShInitBuiltInResources(&resources); ShHandle compiler = ShConstructCompiler(GL_VERTEX_SHADER, SH_GLES2_SPEC, SH_GLSL_COMPATIBILITY_OUTPUT, &resources); EXPECT_NE(static_cast<ShHandle>(0), compiler); const char *program[] = { "attribute vec4 position;\n" "varying float v;\n" "invariant v;\n" "void main() {\n" " v = 1.0;\n" " gl_Position = position;\n" "}" }; EXPECT_TRUE(ShCompile(compiler, program, 1, SH_OBJECT_CODE)); EXPECT_TRUE(ShCompile(compiler, program, 1, SH_OBJECT_CODE)); ShDestruct(compiler); }
int main(int argc, char* argv[]) { TFailCode failCode = ESuccess; int compileOptions = 0; int numCompiles = 0; ShHandle vertexCompiler = 0; ShHandle fragmentCompiler = 0; char* buffer = 0; int bufferLen = 0; int numAttribs = 0, numUniforms = 0; ShShaderSpec spec = SH_GLES2_SPEC; ShShaderOutput output = SH_ESSL_OUTPUT; ShInitialize(); ShBuiltInResources resources; GenerateResources(&resources); argc--; argv++; for (; (argc >= 1) && (failCode == ESuccess); argc--, argv++) { if (argv[0][0] == '-') { switch (argv[0][1]) { case 'i': compileOptions |= SH_INTERMEDIATE_TREE; break; case 'm': compileOptions |= SH_MAP_LONG_VARIABLE_NAMES; break; case 'o': compileOptions |= SH_OBJECT_CODE; break; case 'u': compileOptions |= SH_ATTRIBUTES_UNIFORMS; break; case 'l': compileOptions |= SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX; break; case 'e': compileOptions |= SH_EMULATE_BUILT_IN_FUNCTIONS; break; case 'd': compileOptions |= SH_DEPENDENCY_GRAPH; break; case 't': compileOptions |= SH_TIMING_RESTRICTIONS; break; case 's': if (argv[0][2] == '=') { switch (argv[0][3]) { case 'e': spec = SH_GLES2_SPEC; break; case 'w': spec = SH_WEBGL_SPEC; break; case 'c': spec = SH_CSS_SHADERS_SPEC; break; default: failCode = EFailUsage; } } else { failCode = EFailUsage; } break; case 'b': if (argv[0][2] == '=') { switch (argv[0][3]) { case 'e': output = SH_ESSL_OUTPUT; break; case 'g': output = SH_GLSL_OUTPUT; break; case 'h': output = SH_HLSL_OUTPUT; break; default: failCode = EFailUsage; } } else { failCode = EFailUsage; } break; case 'x': if (argv[0][2] == '=') { switch (argv[0][3]) { case 'i': resources.OES_EGL_image_external = 1; break; case 'd': resources.OES_standard_derivatives = 1; break; case 'r': resources.ARB_texture_rectangle = 1; break; default: failCode = EFailUsage; } } else { failCode = EFailUsage; } break; default: failCode = EFailUsage; } } else { ShHandle compiler = 0; switch (FindShaderType(argv[0])) { case SH_VERTEX_SHADER: if (vertexCompiler == 0) vertexCompiler = ShConstructCompiler( SH_VERTEX_SHADER, spec, output, &resources); compiler = vertexCompiler; break; case SH_FRAGMENT_SHADER: if (fragmentCompiler == 0) fragmentCompiler = ShConstructCompiler( SH_FRAGMENT_SHADER, spec, output, &resources); compiler = fragmentCompiler; break; default: break; } if (compiler) { bool compiled = CompileFile(argv[0], compiler, compileOptions); LogMsg("BEGIN", "COMPILER", numCompiles, "INFO LOG"); 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"); printf("\n\n"); if (compiled && (compileOptions & SH_OBJECT_CODE)) { LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE"); 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"); printf("\n\n"); } if (compiled && (compileOptions & SH_ATTRIBUTES_UNIFORMS)) { LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE ATTRIBS"); PrintActiveVariables(compiler, SH_ACTIVE_ATTRIBUTES, (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) != 0); LogMsg("END", "COMPILER", numCompiles, "ACTIVE ATTRIBS"); printf("\n\n"); LogMsg("BEGIN", "COMPILER", numCompiles, "ACTIVE UNIFORMS"); PrintActiveVariables(compiler, SH_ACTIVE_UNIFORMS, (compileOptions & SH_MAP_LONG_VARIABLE_NAMES) != 0); LogMsg("END", "COMPILER", numCompiles, "ACTIVE UNIFORMS"); printf("\n\n"); } if (!compiled) failCode = EFailCompile; ++numCompiles; } else { failCode = EFailCompilerCreate; } } } if ((vertexCompiler == 0) && (fragmentCompiler == 0)) failCode = EFailUsage; if (failCode == EFailUsage) usage(); if (vertexCompiler) ShDestruct(vertexCompiler); if (fragmentCompiler) ShDestruct(fragmentCompiler); if (buffer) free(buffer); ShFinalize(); return failCode; }
ShaderValidator::~ShaderValidator() { ShDestruct(mHandle); }
int main(int argc, char *argv[]) { TFailCode failCode = ESuccess; int compileOptions = 0; int numCompiles = 0; ShHandle vertexCompiler = 0; ShHandle fragmentCompiler = 0; ShShaderSpec spec = SH_GLES2_SPEC; ShShaderOutput output = SH_ESSL_OUTPUT; ShInitialize(); ShBuiltInResources resources; GenerateResources(&resources); argc--; argv++; for (; (argc >= 1) && (failCode == ESuccess); argc--, argv++) { if (argv[0][0] == '-') { switch (argv[0][1]) { case 'i': compileOptions |= SH_INTERMEDIATE_TREE; break; case 'o': compileOptions |= SH_OBJECT_CODE; break; case 'u': compileOptions |= SH_VARIABLES; break; case 'l': compileOptions |= SH_UNROLL_FOR_LOOP_WITH_INTEGER_INDEX; break; case 'e': compileOptions |= SH_EMULATE_BUILT_IN_FUNCTIONS; break; case 'd': compileOptions |= SH_DEPENDENCY_GRAPH; break; case 't': compileOptions |= SH_TIMING_RESTRICTIONS; break; case 'p': resources.WEBGL_debug_shader_precision = 1; break; case 's': if (argv[0][2] == '=') { switch (argv[0][3]) { case 'e': if (argv[0][4] == '3') { spec = SH_GLES3_SPEC; } else { spec = SH_GLES2_SPEC; } break; case 'w': if (argv[0][4] == '2') { spec = SH_WEBGL2_SPEC; } else { spec = SH_WEBGL_SPEC; } break; case 'c': spec = SH_CSS_SHADERS_SPEC; break; default: failCode = EFailUsage; } } else { failCode = EFailUsage; } break; case 'b': if (argv[0][2] == '=') { switch (argv[0][3]) { case 'e': output = SH_ESSL_OUTPUT; break; case 'g': output = SH_GLSL_OUTPUT; break; case 'h': if (argv[0][4] == '1' && argv[0][5] == '1') { output = SH_HLSL11_OUTPUT; } else { output = SH_HLSL9_OUTPUT; } break; default: failCode = EFailUsage; } } else { failCode = EFailUsage; } break; case 'x': if (argv[0][2] == '=') { switch (argv[0][3]) { case 'i': resources.OES_EGL_image_external = 1; break; case 'd': resources.OES_standard_derivatives = 1; break; case 'r': resources.ARB_texture_rectangle = 1; break; case 'l': resources.EXT_shader_texture_lod = 1; break; case 'f': resources.EXT_shader_framebuffer_fetch = 1; break; case 'n': resources.NV_shader_framebuffer_fetch = 1; break; case 'a': resources.ARM_shader_framebuffer_fetch = 1; break; default: failCode = EFailUsage; } } else { failCode = EFailUsage; } break; default: failCode = EFailUsage; } } else { ShHandle compiler = 0; switch (FindShaderType(argv[0])) { case GL_VERTEX_SHADER: if (vertexCompiler == 0) { vertexCompiler = ShConstructCompiler( GL_VERTEX_SHADER, spec, output, &resources); } compiler = vertexCompiler; break; case GL_FRAGMENT_SHADER: if (fragmentCompiler == 0) { fragmentCompiler = ShConstructCompiler( GL_FRAGMENT_SHADER, spec, output, &resources); } compiler = fragmentCompiler; break; default: break; } if (compiler) { bool compiled = CompileFile(argv[0], compiler, compileOptions); LogMsg("BEGIN", "COMPILER", numCompiles, "INFO LOG"); std::string log = ShGetInfoLog(compiler); puts(log.c_str()); LogMsg("END", "COMPILER", numCompiles, "INFO LOG"); printf("\n\n"); if (compiled && (compileOptions & SH_OBJECT_CODE)) { LogMsg("BEGIN", "COMPILER", numCompiles, "OBJ CODE"); std::string code = ShGetObjectCode(compiler); puts(code.c_str()); LogMsg("END", "COMPILER", numCompiles, "OBJ CODE"); printf("\n\n"); } if (compiled && (compileOptions & SH_VARIABLES)) { LogMsg("BEGIN", "COMPILER", numCompiles, "VARIABLES"); PrintActiveVariables(compiler); LogMsg("END", "COMPILER", numCompiles, "VARIABLES"); printf("\n\n"); } if (!compiled) failCode = EFailCompile; ++numCompiles; } else { failCode = EFailCompilerCreate; } } } if ((vertexCompiler == 0) && (fragmentCompiler == 0)) failCode = EFailUsage; if (failCode == EFailUsage) usage(); if (vertexCompiler) ShDestruct(vertexCompiler); if (fragmentCompiler) ShDestruct(fragmentCompiler); ShFinalize(); return failCode; }