| 43 | GlShader::~GlShader() { Invalidate(); } |
| 44 | |
| 45 | Status GlShader::CompileShader(GLenum shader_type, |
| 46 | const std::string& shader_source, |
| 47 | GlShader* gl_shader) { |
| 48 | // NOTE: code compilation can fail due to gl errors happened before |
| 49 | GLuint shader_id; |
| 50 | RETURN_IF_ERROR(TFLITE_GPU_CALL_GL(glCreateShader, &shader_id, shader_type)); |
| 51 | GlShader shader(shader_id); |
| 52 | |
| 53 | const char* src = shader_source.c_str(); |
| 54 | RETURN_IF_ERROR( |
| 55 | TFLITE_GPU_CALL_GL(glShaderSource, shader.id(), 1, &src, nullptr)); |
| 56 | |
| 57 | glCompileShader(shader.id()); |
| 58 | // Didn't check for opengl errors here because we want to get better logs |
| 59 | // if it didn't compile. |
| 60 | GLint compiled = GL_FALSE; |
| 61 | glGetShaderiv(shader.id(), GL_COMPILE_STATUS, &compiled); |
| 62 | if (!compiled) { |
| 63 | GLint info_log_len = 0; |
| 64 | glGetShaderiv(shader.id(), GL_INFO_LOG_LENGTH, &info_log_len); |
| 65 | std::string errors(info_log_len, 0); |
| 66 | glGetShaderInfoLog(shader.id(), info_log_len, nullptr, &errors[0]); |
| 67 | return InternalError("Shader compilation failed: " + errors + |
| 68 | "\nProblem shader is:\n" + shader_source); |
| 69 | } |
| 70 | |
| 71 | *gl_shader = std::move(shader); |
| 72 | return OkStatus(); |
| 73 | } |
| 74 | |
| 75 | } // namespace gl |
| 76 | } // namespace gpu |
nothing calls this directly
no test coverage detected