Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
GraphiteVulkanTestContext.cpp
Go to the documentation of this file.
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
9
18
19extern bool gCreateProtectedContext;
20
21namespace skiatest::graphite {
22
23std::unique_ptr<GraphiteTestContext> VulkanTestContext::Make() {
24 skgpu::VulkanBackendContext backendContext;
25 skgpu::VulkanExtensions* extensions;
27 VkDebugReportCallbackEXT debugCallback = VK_NULL_HANDLE;
28 PFN_vkDestroyDebugReportCallbackEXT destroyCallback = nullptr;
29
31 if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
32 return nullptr;
33 }
34
35 extensions = new skgpu::VulkanExtensions();
36 features = new VkPhysicalDeviceFeatures2;
37 memset(features, 0, sizeof(VkPhysicalDeviceFeatures2));
38 if (!sk_gpu_test::CreateVkBackendContext(instProc, &backendContext, extensions,
39 features, &debugCallback,
40 nullptr, sk_gpu_test::CanPresentFn(),
42 sk_gpu_test::FreeVulkanFeaturesStructs(features);
43 delete features;
44 delete extensions;
45 return nullptr;
46 }
47 if (debugCallback != VK_NULL_HANDLE) {
48 destroyCallback = (PFN_vkDestroyDebugReportCallbackEXT) instProc(
49 backendContext.fInstance, "vkDestroyDebugReportCallbackEXT");
50 }
51
52 return std::unique_ptr<GraphiteTestContext>(new VulkanTestContext(backendContext,
53 extensions,
54 features,
55 debugCallback,
56 destroyCallback));
57}
58
59#define ACQUIRE_VK_PROC_LOCAL(name, inst) \
60 PFN_vk##name localVk##name = \
61 reinterpret_cast<PFN_vk##name>(fVulkan.fGetProc("vk" #name, inst, nullptr)); \
62 do { \
63 if (localVk##name == nullptr) { \
64 SkDebugf("Function ptr for vk%s could not be acquired\n", #name); \
65 return; \
66 } \
67 } while (0)
68
70 fVulkan.fMemoryAllocator.reset();
71 ACQUIRE_VK_PROC_LOCAL(DeviceWaitIdle, fVulkan.fInstance);
72 ACQUIRE_VK_PROC_LOCAL(DestroyDevice, fVulkan.fInstance);
73 ACQUIRE_VK_PROC_LOCAL(DestroyInstance, fVulkan.fInstance);
74 localVkDeviceWaitIdle(fVulkan.fDevice);
75 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 (void)fDebugCallback;
83 (void)fDestroyDebugReportCallbackEXT;
84#endif
85 localVkDestroyInstance(fVulkan.fInstance, nullptr);
86 delete fExtensions;
87
88 sk_gpu_test::FreeVulkanFeaturesStructs(fFeatures);
89 delete fFeatures;
90}
91
93 return skgpu::ContextType::kVulkan;
94}
95
96std::unique_ptr<skgpu::graphite::Context> VulkanTestContext::makeContext(
97 const TestOptions& options) {
98 SkASSERT(!options.fNeverYieldToWebGPU);
99 skgpu::graphite::ContextOptions revisedContextOptions(options.fContextOptions);
100 skgpu::graphite::ContextOptionsPriv contextOptionsPriv;
101 if (!options.fContextOptions.fOptionsPriv) {
102 revisedContextOptions.fOptionsPriv = &contextOptionsPriv;
103 }
104 // Needed to make synchronous readPixels work
105 revisedContextOptions.fOptionsPriv->fStoreContextRefInRecorder = true;
106
107 return skgpu::graphite::ContextFactory::MakeVulkan(fVulkan, revisedContextOptions);
108}
109
110} // namespace skiatest::graphite
const char * options
bool gCreateProtectedContext
#define ACQUIRE_VK_PROC_LOCAL(name, inst)
bool gCreateProtectedContext
#define SkASSERT(cond)
Definition SkAssert.h:116
std::unique_ptr< skgpu::graphite::Context > makeContext(const TestOptions &) override
static std::unique_ptr< GraphiteTestContext > Make()
SK_API std::unique_ptr< Context > MakeVulkan(const VulkanBackendContext &, const ContextOptions &)
sk_sp< VulkanMemoryAllocator > fMemoryAllocator
ContextOptionsPriv * fOptionsPriv
void(VKAPI_PTR * PFN_vkDestroyDebugReportCallbackEXT)(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks *pAllocator)
#define VK_NULL_HANDLE
Definition vulkan_core.h:46
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)