/src/skia/tools/graphite/vk/GraphiteVulkanTestContext.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | #include "tools/graphite/vk/GraphiteVulkanTestContext.h" |
9 | | |
10 | | #include "include/gpu/graphite/Context.h" |
11 | | #include "include/gpu/graphite/ContextOptions.h" |
12 | | #include "include/gpu/graphite/vk/VulkanGraphiteUtils.h" |
13 | | #include "include/gpu/vk/VulkanExtensions.h" |
14 | | #include "include/gpu/vk/VulkanMemoryAllocator.h" |
15 | | #include "src/gpu/graphite/ContextOptionsPriv.h" |
16 | | #include "tools/gpu/ContextType.h" |
17 | | #include "tools/gpu/vk/VkTestUtils.h" |
18 | | #include "tools/graphite/TestOptions.h" |
19 | | |
20 | | extern bool gCreateProtectedContext; |
21 | | |
22 | | namespace skiatest::graphite { |
23 | | |
24 | 24 | std::unique_ptr<GraphiteTestContext> VulkanTestContext::Make() { |
25 | 24 | skgpu::VulkanBackendContext backendContext; |
26 | 24 | skgpu::VulkanExtensions* extensions; |
27 | 24 | VkPhysicalDeviceFeatures2* features; |
28 | 24 | VkDebugReportCallbackEXT debugCallback = VK_NULL_HANDLE; |
29 | 24 | PFN_vkDestroyDebugReportCallbackEXT destroyCallback = nullptr; |
30 | | |
31 | 24 | PFN_vkGetInstanceProcAddr instProc; |
32 | 24 | if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) { |
33 | 24 | return nullptr; |
34 | 24 | } |
35 | | |
36 | 0 | extensions = new skgpu::VulkanExtensions(); |
37 | 0 | features = new VkPhysicalDeviceFeatures2; |
38 | 0 | memset(features, 0, sizeof(VkPhysicalDeviceFeatures2)); |
39 | 0 | if (!sk_gpu_test::CreateVkBackendContext(instProc, &backendContext, extensions, |
40 | 0 | features, &debugCallback, |
41 | 0 | nullptr, sk_gpu_test::CanPresentFn(), |
42 | 0 | gCreateProtectedContext)) { |
43 | 0 | sk_gpu_test::FreeVulkanFeaturesStructs(features); |
44 | 0 | delete features; |
45 | 0 | delete extensions; |
46 | 0 | return nullptr; |
47 | 0 | } |
48 | 0 | if (debugCallback != VK_NULL_HANDLE) { |
49 | 0 | destroyCallback = (PFN_vkDestroyDebugReportCallbackEXT) instProc( |
50 | 0 | backendContext.fInstance, "vkDestroyDebugReportCallbackEXT"); |
51 | 0 | } |
52 | |
|
53 | 0 | return std::unique_ptr<GraphiteTestContext>(new VulkanTestContext(backendContext, |
54 | 0 | extensions, |
55 | 0 | features, |
56 | 0 | debugCallback, |
57 | 0 | destroyCallback)); |
58 | 0 | } |
59 | | |
60 | | #define ACQUIRE_VK_PROC_LOCAL(name, inst) \ |
61 | 0 | PFN_vk##name localVk##name = \ |
62 | 0 | reinterpret_cast<PFN_vk##name>(fVulkan.fGetProc("vk" #name, inst, nullptr)); \ |
63 | 0 | do { \ |
64 | 0 | if (localVk##name == nullptr) { \ |
65 | 0 | SkDebugf("Function ptr for vk%s could not be acquired\n", #name); \ |
66 | 0 | return; \ |
67 | 0 | } \ |
68 | 0 | } while (0) |
69 | | |
70 | 0 | VulkanTestContext::~VulkanTestContext() { |
71 | 0 | fVulkan.fMemoryAllocator.reset(); |
72 | 0 | ACQUIRE_VK_PROC_LOCAL(DeviceWaitIdle, fVulkan.fInstance); |
73 | 0 | ACQUIRE_VK_PROC_LOCAL(DestroyDevice, fVulkan.fInstance); |
74 | 0 | ACQUIRE_VK_PROC_LOCAL(DestroyInstance, fVulkan.fInstance); |
75 | 0 | localVkDeviceWaitIdle(fVulkan.fDevice); |
76 | 0 | localVkDestroyDevice(fVulkan.fDevice, nullptr); |
77 | | #ifdef SK_ENABLE_VK_LAYERS |
78 | | if (fDebugCallback != VK_NULL_HANDLE) { |
79 | | fDestroyDebugReportCallbackEXT(fVulkan.fInstance, fDebugCallback, nullptr); |
80 | | } |
81 | | #else |
82 | | // Surpress unused private member variable warning |
83 | 0 | (void)fDebugCallback; |
84 | 0 | (void)fDestroyDebugReportCallbackEXT; |
85 | 0 | #endif |
86 | 0 | localVkDestroyInstance(fVulkan.fInstance, nullptr); |
87 | 0 | delete fExtensions; |
88 | |
|
89 | 0 | sk_gpu_test::FreeVulkanFeaturesStructs(fFeatures); |
90 | 0 | delete fFeatures; |
91 | 0 | } |
92 | | |
93 | 0 | skgpu::ContextType VulkanTestContext::contextType() { |
94 | 0 | return skgpu::ContextType::kVulkan; |
95 | 0 | } |
96 | | |
97 | | std::unique_ptr<skgpu::graphite::Context> VulkanTestContext::makeContext( |
98 | 0 | const TestOptions& options) { |
99 | 0 | SkASSERT(!options.hasDawnOptions()); |
100 | 0 | skgpu::graphite::ContextOptions revisedContextOptions(options.fContextOptions); |
101 | 0 | skgpu::graphite::ContextOptionsPriv contextOptionsPriv; |
102 | 0 | if (!options.fContextOptions.fOptionsPriv) { |
103 | 0 | revisedContextOptions.fOptionsPriv = &contextOptionsPriv; |
104 | 0 | } |
105 | | // Needed to make synchronous readPixels work |
106 | 0 | revisedContextOptions.fOptionsPriv->fStoreContextRefInRecorder = true; |
107 | 0 | SkASSERT(fVulkan.fMemoryAllocator); |
108 | 0 | return skgpu::graphite::ContextFactory::MakeVulkan(fVulkan, revisedContextOptions); |
109 | 0 | } Unexecuted instantiation: skiatest::graphite::VulkanTestContext::makeContext(skiatest::graphite::TestOptions const&) Unexecuted instantiation: skiatest::graphite::VulkanTestContext::makeContext(skiatest::graphite::TestOptions const&) |
110 | | |
111 | | } // namespace skiatest::graphite |