• 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 
physDevice()39     VkPhysicalDevice physDevice() const { return fPhysDevice; }
device()40     VkDevice device() const { return fDevice; }
queueIndex()41     uint32_t  queueIndex() const { return fQueueIndex; }
42 
43     std::unique_ptr<ResourceProvider> makeResourceProvider(SingleOwner*,
44                                                            uint32_t recorderID,
45                                                            size_t resourceBudget) override;
46 
47     bool checkVkResult(VkResult result) const;
48 
isDeviceLost()49     bool isDeviceLost() const override {
50         SkAutoMutexExclusive lock(fDeviceIsLostMutex);
51         return fDeviceIsLost;
52     }
53 
54 private:
55     VulkanSharedContext(const VulkanBackendContext&,
56                         sk_sp<const skgpu::VulkanInterface> interface,
57                         sk_sp<skgpu::VulkanMemoryAllocator> memoryAllocator,
58                         std::unique_ptr<const VulkanCaps> caps,
59                         SkSpan<sk_sp<SkRuntimeEffect>> userDefinedKnownRuntimeEffects);
60 
61     sk_sp<const skgpu::VulkanInterface> fInterface;
62     sk_sp<skgpu::VulkanMemoryAllocator> fMemoryAllocator;
63 
64     VkPhysicalDevice fPhysDevice;
65     VkDevice fDevice;
66     uint32_t fQueueIndex;
67 
68     mutable SkMutex fDeviceIsLostMutex;
69     // TODO(b/322207523): consider refactoring to remove the mutable keyword from fDeviceIsLost.
70     mutable bool fDeviceIsLost SK_GUARDED_BY(fDeviceIsLostMutex) = false;
71     skgpu::VulkanDeviceLostContext fDeviceLostContext;
72     skgpu::VulkanDeviceLostProc fDeviceLostProc;
73 };
74 
75 } // namespace skgpu::graphite
76 
77 #endif // skgpu_graphite_VulkanSharedContext_DEFINED
78