Edit

kc3-lang/angle/src/libGLESv2/global_state.h

Branch :

  • Show log

    Commit

  • Author : Jamie Madill
    Date : 2018-09-23 17:28:55
    Hash : 77db6f4a
    Message : Use global Context lookup in single-threaded cases. In single-threaded cases we don't need to use a TLS lookup for the current Context. Assume a global context has 3 states: unset, set, and multi-threaded: * global context unset -> set the global context * global context set, matches TLS context -> set the global context * global context set, doesn't match TLS -> set multi-threaded * global context multi-threaded -> leave it This also inlines the global context/TLS check into global_state.h. Increases performance of the binding perf overhead test by up to 25% and the draw call perf test by up to 3%. Bug: angleproject:2824 Change-Id: Ib95953ca918f2408fe72ca83061f4e2d1bd1adad Reviewed-on: https://chromium-review.googlesource.com/1231993 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Yuly Novikov <ynovikov@chromium.org>

  • src/libGLESv2/global_state.h
  • //
    // Copyright(c) 2014 The ANGLE Project Authors. All rights reserved.
    // Use of this source code is governed by a BSD-style license that can be
    // found in the LICENSE file.
    //
    
    // global_state.h : Defines functions for querying the thread-local GL and EGL state.
    
    #ifndef LIBGLESV2_GLOBALSTATE_H_
    #define LIBGLESV2_GLOBALSTATE_H_
    
    #include "libANGLE/Context.h"
    #include "libANGLE/Debug.h"
    #include "libANGLE/Thread.h"
    #include "libANGLE/features.h"
    
    #include <mutex>
    
    namespace egl
    {
    class Debug;
    class Thread;
    
    Thread *GetCurrentThread();
    Debug *GetDebug();
    void SetContextCurrent(Thread *thread, gl::Context *context);
    }  // namespace egl
    
    namespace gl
    {
    extern Context *gSingleThreadedContext;
    
    ANGLE_INLINE Context *GetGlobalContext()
    {
        if (gSingleThreadedContext)
        {
            return gSingleThreadedContext;
        }
    
        egl::Thread *thread = egl::GetCurrentThread();
        return thread->getContext();
    }
    
    ANGLE_INLINE Context *GetValidGlobalContext()
    {
        if (gSingleThreadedContext && !gSingleThreadedContext->isContextLost())
        {
            return gSingleThreadedContext;
        }
    
        egl::Thread *thread = egl::GetCurrentThread();
        return thread->getValidContext();
    }
    
    }  // namespace gl
    
    #if ANGLE_FORCE_THREAD_SAFETY == ANGLE_ENABLED
    namespace angle
    {
    std::mutex &GetGlobalMutex();
    }  // namespace angle
    
    #define ANGLE_SCOPED_GLOBAL_LOCK() \
        std::lock_guard<std::mutex> globalMutexLock(angle::GetGlobalMutex())
    #else
    #define ANGLE_SCOPED_GLOBAL_LOCK()
    #endif
    
    #endif  // LIBGLESV2_GLOBALSTATE_H_