xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/vulkan/CLPlatformVk.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 // CLPlatformVk.h: Defines the class interface for CLPlatformVk, implementing CLPlatformImpl.
7 
8 #ifndef LIBANGLE_RENDERER_VULKAN_CLPLATFORMVK_H_
9 #define LIBANGLE_RENDERER_VULKAN_CLPLATFORMVK_H_
10 
11 #include "common/MemoryBuffer.h"
12 #include "common/SimpleMutex.h"
13 #include "libANGLE/angletypes.h"
14 #include "libANGLE/renderer/CLPlatformImpl.h"
15 
16 #include "libANGLE/renderer/vulkan/vk_utils.h"
17 
18 #include "libANGLE/Display.h"
19 #include "libANGLE/SizedMRUCache.h"
20 
21 namespace rx
22 {
23 
24 class CLPlatformVk : public CLPlatformImpl, public vk::Context, public vk::GlobalOps
25 {
26   public:
27     using Ptr = std::unique_ptr<CLPlatformVk>;
28 
29     ~CLPlatformVk() override;
30 
31     Info createInfo() const override;
32     CLDeviceImpl::CreateDatas createDevices() const override;
33 
34     angle::Result createContext(cl::Context &context,
35                                 const cl::DevicePtrs &devices,
36                                 bool userSync,
37                                 CLContextImpl::Ptr *contextOut) override;
38 
39     angle::Result createContextFromType(cl::Context &context,
40                                         cl::DeviceType deviceType,
41                                         bool userSync,
42                                         CLContextImpl::Ptr *contextOut) override;
43 
44     angle::Result unloadCompiler() override;
45 
46     static void Initialize(CreateFuncs &createFuncs);
47 
48     static constexpr cl_version GetVersion();
49     static const std::string &GetVersionString();
50 
51     angle::Result initBackendRenderer();
52 
53     // vk::Context
54     void handleError(VkResult result,
55                      const char *file,
56                      const char *function,
57                      unsigned int line) override;
58 
59     // vk::GlobalOps
60     void putBlob(const angle::BlobCacheKey &key, const angle::MemoryBuffer &value) override;
61     bool getBlob(const angle::BlobCacheKey &key, angle::BlobCacheValue *valueOut) override;
62     std::shared_ptr<angle::WaitableEvent> postMultiThreadWorkerTask(
63         const std::shared_ptr<angle::Closure> &task) override;
64     void notifyDeviceLost() override;
65 
66   private:
67     explicit CLPlatformVk(const cl::Platform &platform);
68 
69     angle::NativeWindowSystem getWindowSystem();
70     const char *getWSIExtension();
getWSILayer()71     const char *getWSILayer() { return nullptr; }
72 
73     mutable angle::SimpleMutex mBlobCacheMutex;
74     angle::SizedMRUCache<angle::BlobCacheKey, angle::MemoryBuffer> mBlobCache;
75 };
76 
GetVersion()77 constexpr cl_version CLPlatformVk::GetVersion()
78 {
79     return CL_MAKE_VERSION(3, 0, 0);
80 }
81 
82 }  // namespace rx
83 
84 #endif  // LIBANGLE_RENDERER_VULKAN_CLPLATFORMVK_H_
85