• 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_VulkanTypes_DEFINED
9 #define skgpu_VulkanTypes_DEFINED
10 
11 #include "include/core/SkTypes.h"
12 #include "include/private/gpu/vk/SkiaVulkan.h"
13 
14 #include <functional>
15 
16 #ifndef VK_VERSION_1_1
17 #error Skia requires the use of Vulkan 1.1 headers
18 #endif
19 
20 namespace skgpu {
21 
22 using VulkanGetProc = std::function<PFN_vkVoidFunction(
23         const char*, // function name
24         VkInstance,  // instance or VK_NULL_HANDLE
25         VkDevice     // device or VK_NULL_HANDLE
26         )>;
27 
28 typedef intptr_t VulkanBackendMemory;
29 
30 /**
31  * Types for interacting with Vulkan resources created externally to Skia.
32  */
33 struct VulkanAlloc {
34     // can be VK_NULL_HANDLE iff is an RT and is borrowed
35     VkDeviceMemory      fMemory = VK_NULL_HANDLE;
36     VkDeviceSize        fOffset = 0;
37     VkDeviceSize        fSize = 0;  // this can be indeterminate iff Tex uses borrow semantics
38     uint32_t            fFlags = 0;
39     // handle to memory allocated via skgpu::VulkanMemoryAllocator.
40     VulkanBackendMemory fBackendMemory = 0;
41 
42     enum Flag {
43         kNoncoherent_Flag     = 0x1,   // memory must be flushed to device after mapping
44         kMappable_Flag        = 0x2,   // memory is able to be mapped.
45         kLazilyAllocated_Flag = 0x4,   // memory was created with lazy allocation
46     };
47 
48     bool operator==(const VulkanAlloc& that) const {
49         return fMemory == that.fMemory && fOffset == that.fOffset && fSize == that.fSize &&
50                fFlags == that.fFlags && fUsesSystemHeap == that.fUsesSystemHeap;
51     }
52 
53 private:
54     bool fUsesSystemHeap = false;
55 };
56 
57 } // namespace skgpu
58 
59 #endif // skgpu_VulkanTypes_DEFINED
60