• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2021 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // entry_points_cl_utils.cpp: These helpers are used in CL entry point routines.
7 
8 #include "libGLESv2/entry_points_cl_utils.h"
9 
10 #include "libGLESv2/cl_dispatch_table.h"
11 
12 #include "libANGLE/CLPlatform.h"
13 #ifdef ANGLE_ENABLE_CL_PASSTHROUGH
14 #    include "libANGLE/renderer/cl/CLPlatformCL.h"
15 #endif
16 #ifdef ANGLE_ENABLE_VULKAN
17 #    include "libANGLE/renderer/vulkan/CLPlatformVk.h"
18 #endif
19 
20 #include "anglebase/no_destructor.h"
21 
22 #include <mutex>
23 
24 namespace cl
25 {
26 
InitBackEnds(bool isIcd)27 void InitBackEnds(bool isIcd)
28 {
29     enum struct State
30     {
31         Uninitialized,
32         Initializing,
33         Initialized
34     };
35     static State sState = State::Uninitialized;
36 
37     // Fast thread-unsafe check first
38     if (sState == State::Initialized)
39     {
40         return;
41     }
42 
43     static angle::base::NoDestructor<std::recursive_mutex> sMutex;
44     std::lock_guard<std::recursive_mutex> lock(*sMutex);
45 
46     // Thread-safe check, return if initialized
47     // or if already initializing (re-entry from CL pass-through back end)
48     if (sState != State::Uninitialized)
49     {
50         return;
51     }
52 
53     sState = State::Initializing;
54 
55     rx::CLPlatformImpl::CreateFuncs createFuncs;
56 #ifdef ANGLE_ENABLE_CL_PASSTHROUGH
57     rx::CLPlatformCL::Initialize(createFuncs, isIcd);
58 #endif
59 #ifdef ANGLE_ENABLE_VULKAN
60     rx::CLPlatformVk::Initialize(createFuncs);
61 #endif
62     Platform::Initialize(gCLIcdDispatchTable, std::move(createFuncs));
63 
64     sState = State::Initialized;
65 }
66 
67 }  // namespace cl
68