Commit df412bd5 authored by Geoff Lang's avatar Geoff Lang Committed by Commit Bot

Lazily create shader translators and implement glReleaseShaderCompiler

ANGLE's shader translators hold a significant amount of memory for the
builtin symbols.  By lazily creating the shader translator, it may never
be intialized at all if all compiles hit the program binary cache.

BUG=695135

CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.win:win_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel

Change-Id: I095dd2efa33e111726db893cd14c3c3574bdd6ce
Reviewed-on: https://chromium-review.googlesource.com/570540Reviewed-by: default avatarKenneth Russell <kbr@chromium.org>
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488317}
parent 8599312a
......@@ -684,6 +684,7 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient {
// Initialize or re-initialize the shader translator.
bool InitializeShaderTranslator();
void DestroyShaderTranslator();
void UpdateCapabilities();
......@@ -1750,7 +1751,7 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient {
GLuint renderbuffer, GLenum format);
// Wrapper for glReleaseShaderCompiler.
void DoReleaseShaderCompiler() { }
void DoReleaseShaderCompiler();
// Wrappers for glSamplerParameter functions.
void DoSamplerParameterf(GLuint client_id, GLenum pname, GLfloat param);
......@@ -2371,6 +2372,7 @@ class GLES2DecoderImpl : public GLES2Decoder, public ErrorStateClient {
// if not returning an error.
error::Error current_decoder_error_;
bool has_fragment_precision_high_ = false;
scoped_refptr<ShaderTranslatorInterface> vertex_translator_;
scoped_refptr<ShaderTranslatorInterface> fragment_translator_;
......@@ -3536,9 +3538,12 @@ bool GLES2DecoderImpl::Initialize(
features().khr_robustness ||
features().ext_robustness;
if (!InitializeShaderTranslator()) {
return false;
}
GLint range[2] = {0, 0};
GLint precision = 0;
QueryShaderPrecisionFormat(gl_version_info(), GL_FRAGMENT_SHADER,
GL_HIGH_FLOAT, range, &precision);
has_fragment_precision_high_ =
PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision);
GLint viewport_params[4] = { 0 };
glGetIntegerv(GL_MAX_VIEWPORT_DIMS, viewport_params);
......@@ -3894,6 +3899,10 @@ bool GLES2DecoderImpl::InitializeShaderTranslator() {
if (feature_info_->disable_shader_translator()) {
return true;
}
if (vertex_translator_ || fragment_translator_) {
DCHECK(vertex_translator_ && fragment_translator_);
return true;
}
ShBuiltInResources resources;
sh::InitBuiltInResources(&resources);
resources.MaxVertexAttribs = group_->max_vertex_attribs();
......@@ -3920,12 +3929,7 @@ bool GLES2DecoderImpl::InitializeShaderTranslator() {
resources.MinProgramTexelOffset = group_->min_program_texel_offset();
}
GLint range[2] = { 0, 0 };
GLint precision = 0;
QueryShaderPrecisionFormat(gl_version_info(), GL_FRAGMENT_SHADER,
GL_HIGH_FLOAT, range, &precision);
resources.FragmentPrecisionHigh =
PrecisionMeetsSpecForHighpFloat(range[0], range[1], precision);
resources.FragmentPrecisionHigh = has_fragment_precision_high_;
ShShaderSpec shader_spec;
switch (feature_info_->context_type()) {
......@@ -4044,6 +4048,11 @@ bool GLES2DecoderImpl::InitializeShaderTranslator() {
return true;
}
void GLES2DecoderImpl::DestroyShaderTranslator() {
vertex_translator_ = nullptr;
fragment_translator_ = nullptr;
}
bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) {
for (GLsizei ii = 0; ii < n; ++ii) {
if (GetBuffer(client_ids[ii])) {
......@@ -4905,8 +4914,7 @@ void GLES2DecoderImpl::Destroy(bool have_context) {
// Need to release these before releasing |group_| which may own the
// ShaderTranslatorCache.
fragment_translator_ = NULL;
vertex_translator_ = NULL;
DestroyShaderTranslator();
// Destroy the GPU Tracer which may own some in process GPU Timings.
if (gpu_tracer_) {
......@@ -8723,6 +8731,10 @@ bool GLES2DecoderImpl::VerifyMultisampleRenderbufferIntegrity(
pixel[2] == 0xFF);
}
void GLES2DecoderImpl::DoReleaseShaderCompiler() {
DestroyShaderTranslator();
}
void GLES2DecoderImpl::DoRenderbufferStorage(
GLenum target, GLenum internalformat, GLsizei width, GLsizei height) {
Renderbuffer* renderbuffer =
......@@ -10552,6 +10564,9 @@ void GLES2DecoderImpl::DoTransformFeedbackVaryings(
scoped_refptr<ShaderTranslatorInterface> GLES2DecoderImpl::GetTranslator(
GLenum type) {
if (!InitializeShaderTranslator()) {
return nullptr;
}
return type == GL_VERTEX_SHADER ? vertex_translator_ : fragment_translator_;
}
......@@ -15825,7 +15840,7 @@ error::Error GLES2DecoderImpl::HandleRequestExtensionCHROMIUM(
frag_depth_explicitly_enabled_ |= desire_frag_depth;
draw_buffers_explicitly_enabled_ |= desire_draw_buffers;
shader_texture_lod_explicitly_enabled_ |= desire_shader_texture_lod;
InitializeShaderTranslator();
DestroyShaderTranslator();
}
if (feature_str.find("GL_CHROMIUM_color_buffer_float_rgba ") !=
......
......@@ -121,6 +121,8 @@ void Shader::DoCompile() {
<< "\n--translated-shader--\n" << source_for_driver
<< "\n--info-log--\n" << log_info_;
}
translator_ = nullptr;
}
void Shader::RefreshTranslatedShaderSource() {
......
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