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