Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(820)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder.cc

Issue 1273693002: command_buffer: Use GLSL core version that matches the OpenGL version (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // Return the union of |rect1| and |rect2| if they share an edge. 211 // Return the union of |rect1| and |rect2| if they share an edge.
212 if (rect1.SharesEdgeWith(rect2)) { 212 if (rect1.SharesEdgeWith(rect2)) {
213 *result = gfx::UnionRects(rect1, rect2); 213 *result = gfx::UnionRects(rect1, rect2);
214 return true; 214 return true;
215 } 215 }
216 216
217 // Return false if it's not possible to combine |rect1| and |rect2|. 217 // Return false if it's not possible to combine |rect1| and |rect2|.
218 return false; 218 return false;
219 } 219 }
220 220
221 ShShaderOutput GetShaderOutputLanguageForContext(
Ken Russell (switch to Gerrit) 2015/08/05 18:29:37 Please figure out some way to test this code. Perh
Kimmo Kinnunen 2015/08/10 08:36:34 I struggled a bit adding the return type (ShShader
222 const gfx::GLVersionInfo& version_info) {
223 if (version_info.is_es) {
224 return SH_ESSL_OUTPUT;
225 }
226
227 // Determine the GLSL version based on OpenGL specification.
228
229 unsigned context_version =
230 version_info.major_version * 100 + version_info.minor_version * 10;
231 if (context_version >= 450) {
232 // OpenGL specs from 4.2 on specify that the core profile is "also
233 // guaranteed to support all previous versions of the OpenGL Shading
234 // Language back to version 1.40". For simplicity, we assume future
235 // specs do not unspecify this. If they did, they could unspecify
236 // glGetStringi(GL_SHADING_LANGUAGE_VERSION, k), too.
237 // Since current context >= 4.5, use GLSL 4.50 core.
238 return SH_GLSL_450_CORE_OUTPUT;
239 } else if (context_version == 440) {
240 return SH_GLSL_440_CORE_OUTPUT;
241 } else if (context_version == 430) {
242 return SH_GLSL_430_CORE_OUTPUT;
243 } else if (context_version == 420) {
244 return SH_GLSL_420_CORE_OUTPUT;
245 } else if (context_version == 410) {
246 return SH_GLSL_410_CORE_OUTPUT;
247 } else if (context_version == 400) {
248 return SH_GLSL_400_CORE_OUTPUT;
249 } else if (context_version == 330) {
250 return SH_GLSL_330_CORE_OUTPUT;
251 } else if (context_version == 320) {
252 return SH_GLSL_150_CORE_OUTPUT;
253 } else if (context_version == 310) {
254 return SH_GLSL_140_OUTPUT;
255 } else if (context_version == 300) {
256 return SH_GLSL_130_OUTPUT;
257 }
258
259 // Before OpenGL 3.0 we use compatibility profile. Also for future
260 // specs between OpenGL 3.3 and OpenGL 4.0, at the time of writing,
261 // we use compatibility profile.
262 return SH_GLSL_COMPATIBILITY_OUTPUT;
263 }
264
221 } // namespace 265 } // namespace
222 266
223 class GLES2DecoderImpl; 267 class GLES2DecoderImpl;
224 268
225 // Local versions of the SET_GL_ERROR macros 269 // Local versions of the SET_GL_ERROR macros
226 #define LOCAL_SET_GL_ERROR(error, function_name, msg) \ 270 #define LOCAL_SET_GL_ERROR(error, function_name, msg) \
227 ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg) 271 ERRORSTATE_SET_GL_ERROR(state_.GetErrorState(), error, function_name, msg)
228 #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \ 272 #define LOCAL_SET_GL_ERROR_INVALID_ENUM(function_name, value, label) \
229 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \ 273 ERRORSTATE_SET_GL_ERROR_INVALID_ENUM(state_.GetErrorState(), \
230 function_name, value, label) 274 function_name, value, label)
(...skipping 3001 matching lines...) Expand 10 before | Expand all | Expand 10 after
3232 shader_spec = webgl_version_ == 2 ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC; 3276 shader_spec = webgl_version_ == 2 ? SH_WEBGL2_SPEC : SH_WEBGL_SPEC;
3233 } else { 3277 } else {
3234 shader_spec = unsafe_es3_apis_enabled() ? SH_GLES3_SPEC : SH_GLES2_SPEC; 3278 shader_spec = unsafe_es3_apis_enabled() ? SH_GLES3_SPEC : SH_GLES2_SPEC;
3235 } 3279 }
3236 3280
3237 if ((shader_spec == SH_WEBGL_SPEC || shader_spec == SH_WEBGL2_SPEC) && 3281 if ((shader_spec == SH_WEBGL_SPEC || shader_spec == SH_WEBGL2_SPEC) &&
3238 features().enable_shader_name_hashing) 3282 features().enable_shader_name_hashing)
3239 resources.HashFunction = &CityHash64; 3283 resources.HashFunction = &CityHash64;
3240 else 3284 else
3241 resources.HashFunction = NULL; 3285 resources.HashFunction = NULL;
3242 ShaderTranslatorInterface::GlslImplementationType implementation_type = 3286
3243 gfx::GetGLImplementation() == gfx::kGLImplementationEGLGLES2 ? 3287 ShShaderOutput shader_output_language =
3244 ShaderTranslatorInterface::kGlslES : ShaderTranslatorInterface::kGlsl; 3288 GetShaderOutputLanguageForContext(feature_info_->gl_version_info());
3289
3245 int driver_bug_workarounds = 0; 3290 int driver_bug_workarounds = 0;
3246 if (workarounds().needs_glsl_built_in_function_emulation) 3291 if (workarounds().needs_glsl_built_in_function_emulation)
3247 driver_bug_workarounds |= SH_EMULATE_BUILT_IN_FUNCTIONS; 3292 driver_bug_workarounds |= SH_EMULATE_BUILT_IN_FUNCTIONS;
3248 if (workarounds().init_gl_position_in_vertex_shader) 3293 if (workarounds().init_gl_position_in_vertex_shader)
3249 driver_bug_workarounds |= SH_INIT_GL_POSITION; 3294 driver_bug_workarounds |= SH_INIT_GL_POSITION;
3250 if (workarounds().unfold_short_circuit_as_ternary_operation) 3295 if (workarounds().unfold_short_circuit_as_ternary_operation)
3251 driver_bug_workarounds |= SH_UNFOLD_SHORT_CIRCUIT; 3296 driver_bug_workarounds |= SH_UNFOLD_SHORT_CIRCUIT;
3252 if (workarounds().init_varyings_without_static_use) 3297 if (workarounds().init_varyings_without_static_use)
3253 driver_bug_workarounds |= SH_INIT_VARYINGS_WITHOUT_STATIC_USE; 3298 driver_bug_workarounds |= SH_INIT_VARYINGS_WITHOUT_STATIC_USE;
3254 if (workarounds().unroll_for_loop_with_sampler_array_index) 3299 if (workarounds().unroll_for_loop_with_sampler_array_index)
3255 driver_bug_workarounds |= SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX; 3300 driver_bug_workarounds |= SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX;
3256 if (workarounds().scalarize_vec_and_mat_constructor_args) 3301 if (workarounds().scalarize_vec_and_mat_constructor_args)
3257 driver_bug_workarounds |= SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS; 3302 driver_bug_workarounds |= SH_SCALARIZE_VEC_AND_MAT_CONSTRUCTOR_ARGS;
3258 if (workarounds().regenerate_struct_names) 3303 if (workarounds().regenerate_struct_names)
3259 driver_bug_workarounds |= SH_REGENERATE_STRUCT_NAMES; 3304 driver_bug_workarounds |= SH_REGENERATE_STRUCT_NAMES;
3260 if (workarounds().remove_pow_with_constant_exponent) 3305 if (workarounds().remove_pow_with_constant_exponent)
3261 driver_bug_workarounds |= SH_REMOVE_POW_WITH_CONSTANT_EXPONENT; 3306 driver_bug_workarounds |= SH_REMOVE_POW_WITH_CONSTANT_EXPONENT;
3262 3307
3263 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 3308 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
3264 switches::kEmulateShaderPrecision)) 3309 switches::kEmulateShaderPrecision))
3265 resources.WEBGL_debug_shader_precision = true; 3310 resources.WEBGL_debug_shader_precision = true;
3266 3311
3267 vertex_translator_ = shader_translator_cache()->GetTranslator( 3312 vertex_translator_ = shader_translator_cache()->GetTranslator(
3268 GL_VERTEX_SHADER, 3313 GL_VERTEX_SHADER, shader_spec, &resources, shader_output_language,
3269 shader_spec,
3270 &resources,
3271 implementation_type,
3272 static_cast<ShCompileOptions>(driver_bug_workarounds)); 3314 static_cast<ShCompileOptions>(driver_bug_workarounds));
3273 if (!vertex_translator_.get()) { 3315 if (!vertex_translator_.get()) {
3274 LOG(ERROR) << "Could not initialize vertex shader translator."; 3316 LOG(ERROR) << "Could not initialize vertex shader translator.";
3275 Destroy(true); 3317 Destroy(true);
3276 return false; 3318 return false;
3277 } 3319 }
3278 3320
3279 fragment_translator_ = shader_translator_cache()->GetTranslator( 3321 fragment_translator_ = shader_translator_cache()->GetTranslator(
3280 GL_FRAGMENT_SHADER, 3322 GL_FRAGMENT_SHADER, shader_spec, &resources, shader_output_language,
3281 shader_spec,
3282 &resources,
3283 implementation_type,
3284 static_cast<ShCompileOptions>(driver_bug_workarounds)); 3323 static_cast<ShCompileOptions>(driver_bug_workarounds));
3285 if (!fragment_translator_.get()) { 3324 if (!fragment_translator_.get()) {
3286 LOG(ERROR) << "Could not initialize fragment shader translator."; 3325 LOG(ERROR) << "Could not initialize fragment shader translator.";
3287 Destroy(true); 3326 Destroy(true);
3288 return false; 3327 return false;
3289 } 3328 }
3290 return true; 3329 return true;
3291 } 3330 }
3292 3331
3293 bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) { 3332 bool GLES2DecoderImpl::GenBuffersHelper(GLsizei n, const GLuint* client_ids) {
(...skipping 11126 matching lines...) Expand 10 before | Expand all | Expand 10 after
14420 return error::kNoError; 14459 return error::kNoError;
14421 } 14460 }
14422 14461
14423 // Include the auto-generated part of this file. We split this because it means 14462 // Include the auto-generated part of this file. We split this because it means
14424 // we can easily edit the non-auto generated parts right here in this file 14463 // we can easily edit the non-auto generated parts right here in this file
14425 // instead of having to edit some template or the code generator. 14464 // instead of having to edit some template or the code generator.
14426 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 14465 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
14427 14466
14428 } // namespace gles2 14467 } // namespace gles2
14429 } // namespace gpu 14468 } // namespace gpu
OLDNEW
« no previous file with comments | « no previous file | gpu/command_buffer/service/mocks.h » ('j') | gpu/command_buffer/service/shader_translator_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698