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

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

Issue 217813004: Make ShaderTranslatorCache thread safe (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: protect ShFinalize Created 6 years, 8 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 | Annotate | Revision Log
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 <list> 10 #include <list>
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 573
574 // Overridden from AsyncAPIInterface. 574 // Overridden from AsyncAPIInterface.
575 virtual Error DoCommand(unsigned int command, 575 virtual Error DoCommand(unsigned int command,
576 unsigned int arg_count, 576 unsigned int arg_count,
577 const void* args) OVERRIDE; 577 const void* args) OVERRIDE;
578 578
579 // Overridden from AsyncAPIInterface. 579 // Overridden from AsyncAPIInterface.
580 virtual const char* GetCommandName(unsigned int command_id) const OVERRIDE; 580 virtual const char* GetCommandName(unsigned int command_id) const OVERRIDE;
581 581
582 // Overridden from GLES2Decoder. 582 // Overridden from GLES2Decoder.
583 virtual bool Initialize(const scoped_refptr<gfx::GLSurface>& surface, 583 virtual bool Initialize(
584 const scoped_refptr<gfx::GLContext>& context, 584 const scoped_refptr<gfx::GLSurface>& surface,
585 bool offscreen, 585 const scoped_refptr<gfx::GLContext>& context,
586 const gfx::Size& size, 586 const scoped_refptr<ShaderTranslatorCache>& shader_translator_cache,
587 const DisallowedFeatures& disallowed_features, 587 bool offscreen,
588 const std::vector<int32>& attribs) OVERRIDE; 588 const gfx::Size& size,
589 const DisallowedFeatures& disallowed_features,
590 const std::vector<int32>& attribs) OVERRIDE;
589 virtual void Destroy(bool have_context) OVERRIDE; 591 virtual void Destroy(bool have_context) OVERRIDE;
590 virtual void SetSurface( 592 virtual void SetSurface(
591 const scoped_refptr<gfx::GLSurface>& surface) OVERRIDE; 593 const scoped_refptr<gfx::GLSurface>& surface) OVERRIDE;
592 virtual void ProduceFrontBuffer(const Mailbox& mailbox) OVERRIDE; 594 virtual void ProduceFrontBuffer(const Mailbox& mailbox) OVERRIDE;
593 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size) OVERRIDE; 595 virtual bool ResizeOffscreenFrameBuffer(const gfx::Size& size) OVERRIDE;
594 void UpdateParentTextureInfo(); 596 void UpdateParentTextureInfo();
595 virtual bool MakeCurrent() OVERRIDE; 597 virtual bool MakeCurrent() OVERRIDE;
596 virtual GLES2Util* GetGLES2Util() OVERRIDE { return &util_; } 598 virtual GLES2Util* GetGLES2Util() OVERRIDE { return &util_; }
597 virtual gfx::GLContext* GetGLContext() OVERRIDE { return context_.get(); } 599 virtual gfx::GLContext* GetGLContext() OVERRIDE { return context_.get(); }
598 virtual ContextGroup* GetContextGroup() OVERRIDE { return group_.get(); } 600 virtual ContextGroup* GetContextGroup() OVERRIDE { return group_.get(); }
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1717 bool back_buffer_has_depth_; 1719 bool back_buffer_has_depth_;
1718 bool back_buffer_has_stencil_; 1720 bool back_buffer_has_stencil_;
1719 1721
1720 // Backbuffer attachments that are currently undefined. 1722 // Backbuffer attachments that are currently undefined.
1721 uint32 backbuffer_needs_clear_bits_; 1723 uint32 backbuffer_needs_clear_bits_;
1722 1724
1723 // The current decoder error. 1725 // The current decoder error.
1724 error::Error current_decoder_error_; 1726 error::Error current_decoder_error_;
1725 1727
1726 bool use_shader_translator_; 1728 bool use_shader_translator_;
1729 scoped_refptr<ShaderTranslatorCache> shader_translator_cache_;
1727 scoped_refptr<ShaderTranslator> vertex_translator_; 1730 scoped_refptr<ShaderTranslator> vertex_translator_;
1728 scoped_refptr<ShaderTranslator> fragment_translator_; 1731 scoped_refptr<ShaderTranslator> fragment_translator_;
1729 1732
1730 DisallowedFeatures disallowed_features_; 1733 DisallowedFeatures disallowed_features_;
1731 1734
1732 // Cached from ContextGroup 1735 // Cached from ContextGroup
1733 const Validators* validators_; 1736 const Validators* validators_;
1734 scoped_refptr<FeatureInfo> feature_info_; 1737 scoped_refptr<FeatureInfo> feature_info_;
1735 1738
1736 int frame_number_; 1739 int frame_number_;
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after
2278 use_shader_translator_ = false; 2281 use_shader_translator_ = false;
2279 } 2282 }
2280 } 2283 }
2281 2284
2282 GLES2DecoderImpl::~GLES2DecoderImpl() { 2285 GLES2DecoderImpl::~GLES2DecoderImpl() {
2283 } 2286 }
2284 2287
2285 bool GLES2DecoderImpl::Initialize( 2288 bool GLES2DecoderImpl::Initialize(
2286 const scoped_refptr<gfx::GLSurface>& surface, 2289 const scoped_refptr<gfx::GLSurface>& surface,
2287 const scoped_refptr<gfx::GLContext>& context, 2290 const scoped_refptr<gfx::GLContext>& context,
2291 const scoped_refptr<ShaderTranslatorCache>& shader_translator_cache,
2288 bool offscreen, 2292 bool offscreen,
2289 const gfx::Size& size, 2293 const gfx::Size& size,
2290 const DisallowedFeatures& disallowed_features, 2294 const DisallowedFeatures& disallowed_features,
2291 const std::vector<int32>& attribs) { 2295 const std::vector<int32>& attribs) {
2292 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize"); 2296 TRACE_EVENT0("gpu", "GLES2DecoderImpl::Initialize");
2293 DCHECK(context->IsCurrent(surface.get())); 2297 DCHECK(context->IsCurrent(surface.get()));
2294 DCHECK(!context_.get()); 2298 DCHECK(!context_.get());
2295 2299
2296 set_initialized(); 2300 set_initialized();
2297 gpu_tracer_ = GPUTracer::Create(this); 2301 gpu_tracer_ = GPUTracer::Create(this);
(...skipping 14 matching lines...) Expand all
2312 2316
2313 compile_shader_always_succeeds_ = CommandLine::ForCurrentProcess()->HasSwitch( 2317 compile_shader_always_succeeds_ = CommandLine::ForCurrentProcess()->HasSwitch(
2314 switches::kCompileShaderAlwaysSucceeds); 2318 switches::kCompileShaderAlwaysSucceeds);
2315 2319
2316 2320
2317 // Take ownership of the context and surface. The surface can be replaced with 2321 // Take ownership of the context and surface. The surface can be replaced with
2318 // SetSurface. 2322 // SetSurface.
2319 context_ = context; 2323 context_ = context;
2320 surface_ = surface; 2324 surface_ = surface;
2321 2325
2326 shader_translator_cache_ = shader_translator_cache;
2327
2322 ContextCreationAttribHelper attrib_parser; 2328 ContextCreationAttribHelper attrib_parser;
2323 if (!attrib_parser.Parse(attribs)) 2329 if (!attrib_parser.Parse(attribs))
2324 return false; 2330 return false;
2325 2331
2326 // If the failIfMajorPerformanceCaveat context creation attribute was true 2332 // If the failIfMajorPerformanceCaveat context creation attribute was true
2327 // and we are using a software renderer, fail. 2333 // and we are using a software renderer, fail.
2328 if (attrib_parser.fail_if_major_perf_caveat_ && 2334 if (attrib_parser.fail_if_major_perf_caveat_ &&
2329 feature_info_->feature_flags().is_swiftshader) { 2335 feature_info_->feature_flags().is_swiftshader) {
2330 group_ = NULL; // Must not destroy ContextGroup if it is not initialized. 2336 group_ = NULL; // Must not destroy ContextGroup if it is not initialized.
2331 Destroy(true); 2337 Destroy(true);
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
2743 driver_bug_workarounds |= SH_EMULATE_BUILT_IN_FUNCTIONS; 2749 driver_bug_workarounds |= SH_EMULATE_BUILT_IN_FUNCTIONS;
2744 if (workarounds().init_gl_position_in_vertex_shader) 2750 if (workarounds().init_gl_position_in_vertex_shader)
2745 driver_bug_workarounds |= SH_INIT_GL_POSITION; 2751 driver_bug_workarounds |= SH_INIT_GL_POSITION;
2746 if (workarounds().unfold_short_circuit_as_ternary_operation) 2752 if (workarounds().unfold_short_circuit_as_ternary_operation)
2747 driver_bug_workarounds |= SH_UNFOLD_SHORT_CIRCUIT; 2753 driver_bug_workarounds |= SH_UNFOLD_SHORT_CIRCUIT;
2748 if (workarounds().init_varyings_without_static_use) 2754 if (workarounds().init_varyings_without_static_use)
2749 driver_bug_workarounds |= SH_INIT_VARYINGS_WITHOUT_STATIC_USE; 2755 driver_bug_workarounds |= SH_INIT_VARYINGS_WITHOUT_STATIC_USE;
2750 if (workarounds().unroll_for_loop_with_sampler_array_index) 2756 if (workarounds().unroll_for_loop_with_sampler_array_index)
2751 driver_bug_workarounds |= SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX; 2757 driver_bug_workarounds |= SH_UNROLL_FOR_LOOP_WITH_SAMPLER_ARRAY_INDEX;
2752 2758
2753 ShaderTranslatorCache* cache = ShaderTranslatorCache::GetInstance(); 2759 vertex_translator_ = shader_translator_cache_->GetTranslator(
2754 vertex_translator_ = cache->GetTranslator(
2755 SH_VERTEX_SHADER, shader_spec, &resources, 2760 SH_VERTEX_SHADER, shader_spec, &resources,
2756 implementation_type, 2761 implementation_type,
2757 static_cast<ShCompileOptions>(driver_bug_workarounds)); 2762 static_cast<ShCompileOptions>(driver_bug_workarounds));
2758 if (!vertex_translator_.get()) { 2763 if (!vertex_translator_.get()) {
2759 LOG(ERROR) << "Could not initialize vertex shader translator."; 2764 LOG(ERROR) << "Could not initialize vertex shader translator.";
2760 Destroy(true); 2765 Destroy(true);
2761 return false; 2766 return false;
2762 } 2767 }
2763 2768
2764 fragment_translator_ = cache->GetTranslator( 2769 fragment_translator_ = shader_translator_cache_->GetTranslator(
2765 SH_FRAGMENT_SHADER, shader_spec, &resources, 2770 SH_FRAGMENT_SHADER, shader_spec, &resources,
2766 implementation_type, 2771 implementation_type,
2767 static_cast<ShCompileOptions>(driver_bug_workarounds)); 2772 static_cast<ShCompileOptions>(driver_bug_workarounds));
2768 if (!fragment_translator_.get()) { 2773 if (!fragment_translator_.get()) {
2769 LOG(ERROR) << "Could not initialize fragment shader translator."; 2774 LOG(ERROR) << "Could not initialize fragment shader translator.";
2770 Destroy(true); 2775 Destroy(true);
2771 return false; 2776 return false;
2772 } 2777 }
2773 return true; 2778 return true;
2774 } 2779 }
(...skipping 7884 matching lines...) Expand 10 before | Expand all | Expand 10 after
10659 DoDidUseTexImageIfNeeded(texture, texture->target()); 10664 DoDidUseTexImageIfNeeded(texture, texture->target());
10660 } 10665 }
10661 10666
10662 // Include the auto-generated part of this file. We split this because it means 10667 // Include the auto-generated part of this file. We split this because it means
10663 // we can easily edit the non-auto generated parts right here in this file 10668 // we can easily edit the non-auto generated parts right here in this file
10664 // instead of having to edit some template or the code generator. 10669 // instead of having to edit some template or the code generator.
10665 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h" 10670 #include "gpu/command_buffer/service/gles2_cmd_decoder_autogen.h"
10666 10671
10667 } // namespace gles2 10672 } // namespace gles2
10668 } // namespace gpu 10673 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698