24#if defined(SK_GRAPHITE)
30#define ACQUIRE_INST_VK_PROC(name) \
31 fVk##name = reinterpret_cast<PFN_vk##name>(instProc(fBackendContext.fInstance, "vk" #name)); \
32 if (fVk##name == nullptr) { \
33 SkDebugf("Function ptr for vk%s could not be acquired\n", #name); \
37#define ACQUIRE_DEVICE_VK_PROC(name) \
38 fVk##name = reinterpret_cast<PFN_vk##name>(fVkGetDeviceProcAddr(fDevice, "vk" #name)); \
39 if (fVk##name == nullptr) { \
40 SkDebugf("Function ptr for vk%s could not be acquired\n", #name); \
46class GaneshVkTestHelper :
public VkTestHelper {
48 GaneshVkTestHelper(
bool isProtected) : VkTestHelper(isProtected) {}
50 ~GaneshVkTestHelper()
override {
57 fDirectContext.reset();
60 bool isValid()
const override {
return fDirectContext !=
nullptr; }
67 textureable, isProtected,
71 void submitAndWaitForCompletion(
bool* completionMarker)
override {
72 fDirectContext->submit();
73 while (!*completionMarker) {
74 fDirectContext->checkAsyncWorkCompletion();
78 GrDirectContext* directContext()
override {
return fDirectContext.get(); }
81 bool init()
override {
82 if (!this->setupBackendContext()) {
87 sk_gpu_test::ConvertBackendContext(fBackendContext, &gr);
89 if (!fDirectContext) {
93 SkASSERT(fDirectContext->supportsProtectedContent() == fIsProtected);
103#if defined(SK_GRAPHITE)
105class GraphiteVkTestHelper :
public VkTestHelper {
107 GraphiteVkTestHelper(
bool isProtected) : VkTestHelper(isProtected) {}
109 ~GraphiteVkTestHelper()
override {
113 std::unique_ptr<skgpu::graphite::Recording> recording;
115 recording = fRecorder->snap();
119 fContext->insertRecording({ recording.get() });
128 bool isValid()
const override {
return fContext !=
nullptr && fRecorder !=
nullptr; }
132 bool isProtected)
override {
137 void submitAndWaitForCompletion(
bool* completionMarker)
override {
139 while (!*completionMarker) {
140 fContext->checkAsyncWorkCompletion();
147 bool init()
override {
148 if (!this->setupBackendContext()) {
165 fRecorder =
fContext->makeRecorder();
174 std::unique_ptr<skgpu::graphite::Context>
fContext;
175 std::unique_ptr<skgpu::graphite::Recorder> fRecorder;
182 std::unique_ptr<VkTestHelper> helper;
185#if defined(SK_GANESH)
187 helper = std::make_unique<GaneshVkTestHelper>(isProtected);
190#if defined(SK_GRAPHITE)
192 helper = std::make_unique<GraphiteVkTestHelper>(isProtected);
198 if (!helper->init()) {
205bool VkTestHelper::setupBackendContext() {
207 if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
212 fFeatures.pNext =
nullptr;
217 if (!sk_gpu_test::CreateVkBackendContext(instProc, &fBackendContext, &fExtensions,
218 &fFeatures, &fDebugCallback,
nullptr,
219 sk_gpu_test::CanPresentFn(), fIsProtected)) {
222 fDevice = fBackendContext.fDevice;
226 instProc(fBackendContext.fInstance,
"vkDestroyDebugReportCallbackEXT"));
237 ACQUIRE_DEVICE_VK_PROC(CreateImage)
238 ACQUIRE_DEVICE_VK_PROC(DestroyImage)
239 ACQUIRE_DEVICE_VK_PROC(GetImageMemoryRequirements)
240 ACQUIRE_DEVICE_VK_PROC(AllocateMemory)
241 ACQUIRE_DEVICE_VK_PROC(FreeMemory)
242 ACQUIRE_DEVICE_VK_PROC(BindImageMemory)
243 ACQUIRE_DEVICE_VK_PROC(MapMemory)
244 ACQUIRE_DEVICE_VK_PROC(UnmapMemory)
245 ACQUIRE_DEVICE_VK_PROC(FlushMappedMemoryRanges)
246 ACQUIRE_DEVICE_VK_PROC(GetImageSubresourceLayout)
250VkTestHelper::~VkTestHelper() {
251 fBackendContext.fMemoryAllocator.reset();
253 fVkDeviceWaitIdle(fDevice);
254 fVkDestroyDevice(fDevice,
nullptr);
258 fDestroyDebugCallback(fBackendContext.fInstance, fDebugCallback,
nullptr);
262 fVkDestroyInstance(fBackendContext.fInstance,
nullptr);
266 sk_gpu_test::FreeVulkanFeaturesStructs(&fFeatures);
@ kUnknown_SkPixelGeometry
#define ACQUIRE_INST_VK_PROC(name)
SK_API sk_sp< GrDirectContext > MakeVulkan(const GrVkBackendContext &, const GrContextOptions &)
sk_sp< SkSurface > CreateProtectedSkSurface(GrDirectContext *dContext, SkISize size, bool textureable, bool isProtected, const SkSurfaceProps *surfaceProps)
SK_API std::unique_ptr< Context > MakeVulkan(const VulkanBackendContext &, const ContextOptions &)
bool fStoreContextRefInRecorder
ContextOptionsPriv * fOptionsPriv
void(VKAPI_PTR * PFN_vkDestroyDebugReportCallbackEXT)(VkInstance instance, VkDebugReportCallbackEXT callback, const VkAllocationCallbacks *pAllocator)
PFN_vkVoidFunction(VKAPI_PTR * PFN_vkGetInstanceProcAddr)(VkInstance instance, const char *pName)
@ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2