Commit 0ee1586a authored by zmo's avatar zmo Committed by Commit bot

Distinguish ES2/ES3 contexts in GPU command buffer

BUG=463675
TEST=bots, WebGL2 demos
R=kbr@chromium.org,bajones@chromium.org

Review URL: https://codereview.chromium.org/978593003

Cr-Commit-Position: refs/heads/master@{#319016}
parent 6e37f17a
......@@ -1183,6 +1183,8 @@ void WebGraphicsContext3DImpl::ConvertAttributes(
output_attribs->fail_if_major_perf_caveat =
attributes.failIfMajorPerformanceCaveat;
output_attribs->bind_generates_resource = false;
output_attribs->es3_context_required =
(attributes.webGL && attributes.webGLVersion == 2);
}
} // namespace gpu_blink
......@@ -894,6 +894,7 @@ const int32 kBufferDestroyed = 0x3095; // EGL_BUFFER_DESTROYED
const int32 kBindGeneratesResource = 0x10000;
const int32 kFailIfMajorPerfCaveat = 0x10001;
const int32 kLoseContextWhenOutOfMemory = 0x10002;
const int32 kES3ContextRequired = 0x10003;
} // namespace
......@@ -909,7 +910,8 @@ ContextCreationAttribHelper::ContextCreationAttribHelper()
buffer_preserved(true),
bind_generates_resource(true),
fail_if_major_perf_caveat(false),
lose_context_when_out_of_memory(false) {}
lose_context_when_out_of_memory(false),
es3_context_required(false) {}
void ContextCreationAttribHelper::Serialize(std::vector<int32>* attribs) const {
if (alpha_size != -1) {
......@@ -952,6 +954,8 @@ void ContextCreationAttribHelper::Serialize(std::vector<int32>* attribs) const {
attribs->push_back(fail_if_major_perf_caveat ? 1 : 0);
attribs->push_back(kLoseContextWhenOutOfMemory);
attribs->push_back(lose_context_when_out_of_memory ? 1 : 0);
attribs->push_back(kES3ContextRequired);
attribs->push_back(es3_context_required ? 1 : 0);
attribs->push_back(kNone);
}
......@@ -1006,6 +1010,9 @@ bool ContextCreationAttribHelper::Parse(const std::vector<int32>& attribs) {
case kLoseContextWhenOutOfMemory:
lose_context_when_out_of_memory = value != 0;
break;
case kES3ContextRequired:
es3_context_required = value != 0;
break;
case kNone:
// Terminate list, even if more attributes.
return true;
......
......@@ -223,6 +223,7 @@ struct GLES2_UTILS_EXPORT ContextCreationAttribHelper {
bool bind_generates_resource;
bool fail_if_major_perf_caveat;
bool lose_context_when_out_of_memory;
bool es3_context_required;
};
} // namespace gles2
......
......@@ -2441,6 +2441,10 @@ bool GLES2DecoderImpl::Initialize(
DCHECK(context->IsCurrent(surface.get()));
DCHECK(!context_.get());
ContextCreationAttribHelper attrib_parser;
if (!attrib_parser.Parse(attribs))
return false;
surfaceless_ = surface->IsSurfaceless() && !offscreen;
set_initialized();
......@@ -2457,7 +2461,10 @@ bool GLES2DecoderImpl::Initialize(
}
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableUnsafeES3APIs)) {
switches::kEnableUnsafeES3APIs) &&
attrib_parser.es3_context_required) {
// TODO(zmo): We need to implement capabilities check to ensure we can
// actually create ES3 contexts.
set_unsafe_es3_apis_enabled(true);
}
......@@ -2470,10 +2477,6 @@ bool GLES2DecoderImpl::Initialize(
context_ = context;
surface_ = surface;
ContextCreationAttribHelper attrib_parser;
if (!attrib_parser.Parse(attribs))
return false;
// Create GPU Tracer for timing values.
gpu_tracer_.reset(new GPUTracer(this));
......@@ -2956,9 +2959,15 @@ bool GLES2DecoderImpl::InitializeShaderTranslator() {
features().nv_draw_buffers ? 1 : 0;
}
ShShaderSpec shader_spec = force_webgl_glsl_validation_ ? SH_WEBGL_SPEC
: SH_GLES2_SPEC;
if (shader_spec == SH_WEBGL_SPEC && features().enable_shader_name_hashing)
ShShaderSpec shader_spec;
if (force_webgl_glsl_validation_) {
shader_spec = unsafe_es3_apis_enabled() ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC;
} else {
shader_spec = unsafe_es3_apis_enabled() ? SH_GLES3_SPEC : SH_GLES2_SPEC;
}
if ((shader_spec == SH_WEBGL_SPEC || shader_spec == SH_WEBGL2_SPEC) &&
features().enable_shader_name_hashing)
resources.HashFunction = &CityHash64;
else
resources.HashFunction = NULL;
......
......@@ -110,13 +110,19 @@ bool ShaderTranslator::Init(
// Make sure Init is called only once.
DCHECK(compiler_ == NULL);
DCHECK(shader_type == GL_FRAGMENT_SHADER || shader_type == GL_VERTEX_SHADER);
DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC);
DCHECK(shader_spec == SH_GLES2_SPEC || shader_spec == SH_WEBGL_SPEC ||
shader_spec == SH_GLES3_SPEC || shader_spec == SH_WEBGL2_SPEC);
DCHECK(resources != NULL);
g_translator_initializer.Get();
ShShaderOutput shader_output =
(glsl_implementation_type == kGlslES ? SH_ESSL_OUTPUT : SH_GLSL_OUTPUT);
ShShaderOutput shader_output;
if (glsl_implementation_type == kGlslES) {
shader_output = SH_ESSL_OUTPUT;
} else {
shader_output = (shader_spec == SH_WEBGL2_SPEC) ? SH_GLSL_CORE_OUTPUT :
SH_GLSL_COMPATIBILITY_OUTPUT;
}
{
TRACE_EVENT0("gpu", "ShConstructCompiler");
......
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