Debian Codegraph @

tools/gpu/vk/VkTestHelper.h

raw
1 /*
2 * Copyright 2020 Google Inc.
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 VkTestHelper_DEFINED
9 #define VkTestHelper_DEFINED
10
11 #include "include/core/SkTypes.h"
12
13 #ifdef SK_VULKAN
14
15 #include "include/core/SkRefCnt.h"
16 #include "include/gpu/vk/VulkanBackendContext.h"
17 #include "include/gpu/vk/VulkanExtensions.h"
18
19 #include "tools/gpu/vk/VkTestUtils.h"
20
21 class GrDirectContext;
22 class SkSurface;
23 struct SkISize;
24
25 namespace skiatest {
26 enum class TestType : uint8_t;
27 }
28
29 namespace skgpu::graphite {
30 class Context;
31 class Recorder;
32 }
33
34 #define DECLARE_VK_PROC(name) PFN_vk##name fVk##name
35
36 class VkTestHelper {
37 public:
38 static std::unique_ptr<VkTestHelper> Make(skiatest::TestType, bool isProtected);
39
40 virtual ~VkTestHelper();
41
42 virtual bool isValid() const = 0;
43
44 virtual sk_sp<SkSurface> createSurface(SkISize, bool textureable, bool isProtected) = 0;
45 virtual void submitAndWaitForCompletion(bool* completionMarker) = 0;
46
47 virtual GrDirectContext* directContext() { return nullptr; }
48 virtual skgpu::graphite::Recorder* recorder() { return nullptr; }
49 virtual skgpu::graphite::Context* context() { return nullptr; }
50
51 protected:
52 explicit VkTestHelper(bool isProtected) : fIsProtected(isProtected) {}
53
54 bool setupBackendContext();
55 virtual bool init() = 0;
56
57 DECLARE_VK_PROC(DestroyInstance);
58 DECLARE_VK_PROC(DeviceWaitIdle);
59 DECLARE_VK_PROC(DestroyDevice);
60 DECLARE_VK_PROC(GetDeviceProcAddr);
61
62 DECLARE_VK_PROC(GetPhysicalDeviceFormatProperties);
63 DECLARE_VK_PROC(GetPhysicalDeviceMemoryProperties);
64
65 DECLARE_VK_PROC(CreateImage);
66 DECLARE_VK_PROC(DestroyImage);
67 DECLARE_VK_PROC(GetImageMemoryRequirements);
68 DECLARE_VK_PROC(AllocateMemory);
69 DECLARE_VK_PROC(FreeMemory);
70 DECLARE_VK_PROC(BindImageMemory);
71 DECLARE_VK_PROC(MapMemory);
72 DECLARE_VK_PROC(UnmapMemory);
73 DECLARE_VK_PROC(FlushMappedMemoryRanges);
74 DECLARE_VK_PROC(GetImageSubresourceLayout);
75
76 bool fIsProtected = false;
77 VkDevice fDevice = VK_NULL_HANDLE;
78
79 skgpu::VulkanExtensions fExtensions = {};
80 sk_gpu_test::TestVkFeatures fFeatures = {};
81 VkDebugUtilsMessengerEXT fDebugMessenger = VK_NULL_HANDLE;
82 PFN_vkDestroyDebugUtilsMessengerEXT fDestroyDebugCallback = nullptr;
83 skgpu::VulkanBackendContext fBackendContext;
84 };
85
86 #undef DECLARE_VK_PROC
87
88 #endif // SK_VULKAN
89 #endif // VkTestHelper_DEFINED