• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef skgpu_graphite_VulkanSharedContext_DEFINED
9 #define skgpu_graphite_VulkanSharedContext_DEFINED
10 
11 #include "include/private/base/SkMutex.h"
12 #include "src/gpu/graphite/SharedContext.h"
13 
14 #include "include/gpu/vk/VulkanTypes.h"
15 #include "src/gpu/graphite/vk/VulkanCaps.h"
16 
17 namespace skgpu {
18 struct VulkanBackendContext;
19 struct VulkanInterface;
20 class VulkanMemoryAllocator;
21 }
22 
23 namespace skgpu::graphite {
24 
25 struct ContextOptions;
26 class VulkanCaps;
27 
28 class VulkanSharedContext final : public SharedContext {
29 public:
30     static sk_sp<SharedContext> Make(const VulkanBackendContext&, const ContextOptions&);
31     ~VulkanSharedContext() override;
32 
vulkanCaps()33     const VulkanCaps& vulkanCaps() const { return static_cast<const VulkanCaps&>(*this->caps()); }
34 
interface()35     const skgpu::VulkanInterface* interface() const { return fInterface.get(); }
36 
memoryAllocator()37     skgpu::VulkanMemoryAllocator* memoryAllocator() const { return fMemoryAllocator.get(); }
38 
device()39     VkDevice device() const { return fDevice; }
queueIndex()40     uint32_t  queueIndex() const { return fQueueIndex; }
41 
42     std::unique_ptr<ResourceProvider> makeResourceProvider(SingleOwner*,
43                                                            uint32_t recorderID,
44                                                            size_t resourceBudget) override;
45 
46     bool checkVkResult(VkResult result) const;
47 
isDeviceLost()48     bool isDeviceLost() const override {
49         SkAutoMutexExclusive lock(fDeviceIsLostMutex);
50         return fDeviceIsLost;
51     }
52 
53 private:
54     VulkanSharedContext(const VulkanBackendContext&,
55                         sk_sp<const skgpu::VulkanInterface> interface,
56                         sk_sp<skgpu::VulkanMemoryAllocator> memoryAllocator,
57                         std::unique_ptr<const VulkanCaps> caps);
58 
59     sk_sp<const skgpu::VulkanInterface> fInterface;
60     sk_sp<skgpu::VulkanMemoryAllocator> fMemoryAllocator;
61 
62     VkDevice fDevice;
63     uint32_t fQueueIndex;
64 
65     mutable SkMutex fDeviceIsLostMutex;
66     // TODO(b/322207523): consider refactoring to remove the mutable keyword from fDeviceIsLost.
67     mutable bool fDeviceIsLost SK_GUARDED_BY(fDeviceIsLostMutex) = false;
68     skgpu::VulkanDeviceLostContext fDeviceLostContext;
69     skgpu::VulkanDeviceLostProc fDeviceLostProc;
70 };
71 
72 } // namespace skgpu::graphite
73 
74 #endif // skgpu_graphite_VulkanSharedContext_DEFINED
75