In vulkan tests, use vkGetInstanceProcAddr to get vkGetDeviceProcAddr.
We've run into drivers a few times now that have bugs where they only expose vkGetInstaneProcAddr and not vkGetDeviceProcAddr. The latest being swiftshader (which is getting fixed). To avoid this issue in the future we can just have our tests use vkGetInstanceProcAddr to get vkGetDeviceProcAddr. Change-Id: I6d73abde507519c145b873042393f50ce6c4527c Reviewed-on: https://skia-review.googlesource.com/c/skia/+/494822 Reviewed-by: Jim Van Verth <jvanverth@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
parent
f260a297c6
commit
6658fd1584
@ -508,17 +508,9 @@ private:
|
||||
|
||||
bool VulkanTestHelper::init(skiatest::Reporter* reporter) {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
|
||||
return false;
|
||||
}
|
||||
auto getProc = [&instProc, &devProc](const char* proc_name,
|
||||
VkInstance instance, VkDevice device) {
|
||||
if (device != VK_NULL_HANDLE) {
|
||||
return devProc(device, proc_name);
|
||||
}
|
||||
return instProc(instance, proc_name);
|
||||
};
|
||||
|
||||
fExtensions = new GrVkExtensions();
|
||||
fFeatures = new VkPhysicalDeviceFeatures2;
|
||||
@ -529,11 +521,12 @@ bool VulkanTestHelper::init(skiatest::Reporter* reporter) {
|
||||
fBackendContext.fInstance = VK_NULL_HANDLE;
|
||||
fBackendContext.fDevice = VK_NULL_HANDLE;
|
||||
|
||||
if (!sk_gpu_test::CreateVkBackendContext(getProc, &fBackendContext, fExtensions,
|
||||
if (!sk_gpu_test::CreateVkBackendContext(instProc, &fBackendContext, fExtensions,
|
||||
fFeatures, &fDebugCallback)) {
|
||||
return false;
|
||||
}
|
||||
fDevice = fBackendContext.fDevice;
|
||||
auto getProc = fBackendContext.fGetProc;
|
||||
|
||||
if (fDebugCallback != VK_NULL_HANDLE) {
|
||||
fDestroyDebugCallback = (PFN_vkDestroyDebugReportCallbackEXT) instProc(
|
||||
|
@ -14,34 +14,35 @@
|
||||
#include "tests/Test.h"
|
||||
#include "tools/gpu/vk/VkTestUtils.h"
|
||||
|
||||
#define ACQUIRE_VK_PROC_NOCHECK(name, instance, device) \
|
||||
PFN_vk##name grVk##name = reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, device))
|
||||
|
||||
#define ACQUIRE_VK_PROC(name, instance, device) \
|
||||
#define ACQUIRE_VK_PROC_NOCHECK(name, instance) \
|
||||
PFN_vk##name grVk##name = \
|
||||
reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, device)); \
|
||||
reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, VK_NULL_HANDLE))
|
||||
|
||||
#define ACQUIRE_VK_PROC(name, instance) \
|
||||
PFN_vk##name grVk##name = \
|
||||
reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, VK_NULL_HANDLE)); \
|
||||
do { \
|
||||
if (grVk##name == nullptr) { \
|
||||
if (device != VK_NULL_HANDLE) { \
|
||||
destroy_instance(getProc, inst); \
|
||||
if (instance != VK_NULL_HANDLE) { \
|
||||
destroy_instance(getProc, instance); \
|
||||
} \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ACQUIRE_VK_PROC_LOCAL(name, instance, device) \
|
||||
#define ACQUIRE_VK_PROC_LOCAL(name, instance) \
|
||||
PFN_vk##name grVk##name = \
|
||||
reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, device)); \
|
||||
reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, VK_NULL_HANDLE)); \
|
||||
do { \
|
||||
if (grVk##name == nullptr) { \
|
||||
return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define GET_PROC_LOCAL(F, inst, device) PFN_vk ## F F = (PFN_vk ## F) getProc("vk" #F, inst, device)
|
||||
#define GET_PROC_LOCAL(F, inst) PFN_vk ## F F = (PFN_vk ## F) getProc("vk" #F, inst, VK_NULL_HANDLE)
|
||||
|
||||
static void destroy_instance(GrVkGetProc getProc, VkInstance inst) {
|
||||
ACQUIRE_VK_PROC_LOCAL(DestroyInstance, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC_LOCAL(DestroyInstance, inst);
|
||||
grVkDestroyInstance(inst, nullptr);
|
||||
}
|
||||
|
||||
@ -50,21 +51,17 @@ static void destroy_instance(GrVkGetProc getProc, VkInstance inst) {
|
||||
// doesn't crash.
|
||||
DEF_GPUTEST(VulkanPriorityExtension, reporter, options) {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
|
||||
return;
|
||||
}
|
||||
auto getProc = [instProc, devProc](const char* proc_name,
|
||||
VkInstance instance, VkDevice device) {
|
||||
if (device != VK_NULL_HANDLE) {
|
||||
return devProc(device, proc_name);
|
||||
}
|
||||
// This isn't the most effecient but we just use the instProc to get all ptrs.
|
||||
auto getProc = [instProc](const char* proc_name, VkInstance instance, VkDevice) {
|
||||
return instProc(instance, proc_name);
|
||||
};
|
||||
|
||||
VkResult err;
|
||||
|
||||
ACQUIRE_VK_PROC_NOCHECK(EnumerateInstanceVersion, VK_NULL_HANDLE, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC_NOCHECK(EnumerateInstanceVersion, VK_NULL_HANDLE);
|
||||
uint32_t instanceVersion = 0;
|
||||
if (!grVkEnumerateInstanceVersion) {
|
||||
instanceVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
@ -112,21 +109,21 @@ DEF_GPUTEST(VulkanPriorityExtension, reporter, options) {
|
||||
nullptr, // ppEnabledExtensionNames
|
||||
};
|
||||
|
||||
ACQUIRE_VK_PROC(CreateInstance, VK_NULL_HANDLE, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC(CreateInstance, VK_NULL_HANDLE);
|
||||
err = grVkCreateInstance(&instance_create, nullptr, &inst);
|
||||
if (err < 0) {
|
||||
ERRORF(reporter, "Failed to create VkInstance");
|
||||
return;
|
||||
}
|
||||
|
||||
ACQUIRE_VK_PROC(EnumeratePhysicalDevices, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC(GetPhysicalDeviceProperties, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC(GetPhysicalDeviceQueueFamilyProperties, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC(GetPhysicalDeviceFeatures, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC(CreateDevice, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC(GetDeviceQueue, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC(DeviceWaitIdle, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC(DestroyDevice, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_PROC(EnumeratePhysicalDevices, inst);
|
||||
ACQUIRE_VK_PROC(GetPhysicalDeviceProperties, inst);
|
||||
ACQUIRE_VK_PROC(GetPhysicalDeviceQueueFamilyProperties, inst);
|
||||
ACQUIRE_VK_PROC(GetPhysicalDeviceFeatures, inst);
|
||||
ACQUIRE_VK_PROC(CreateDevice, inst);
|
||||
ACQUIRE_VK_PROC(GetDeviceQueue, inst);
|
||||
ACQUIRE_VK_PROC(DeviceWaitIdle, inst);
|
||||
ACQUIRE_VK_PROC(DestroyDevice, inst);
|
||||
|
||||
uint32_t gpuCount;
|
||||
err = grVkEnumeratePhysicalDevices(inst, &gpuCount, nullptr);
|
||||
@ -180,8 +177,8 @@ DEF_GPUTEST(VulkanPriorityExtension, reporter, options) {
|
||||
return;
|
||||
}
|
||||
|
||||
GET_PROC_LOCAL(EnumerateDeviceExtensionProperties, inst, VK_NULL_HANDLE);
|
||||
GET_PROC_LOCAL(EnumerateDeviceLayerProperties, inst, VK_NULL_HANDLE);
|
||||
GET_PROC_LOCAL(EnumerateDeviceExtensionProperties, inst);
|
||||
GET_PROC_LOCAL(EnumerateDeviceLayerProperties, inst);
|
||||
|
||||
if (!EnumerateDeviceExtensionProperties ||
|
||||
!EnumerateDeviceLayerProperties) {
|
||||
|
@ -37,21 +37,14 @@ public:
|
||||
ownsContext = false;
|
||||
} else {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
|
||||
return nullptr;
|
||||
}
|
||||
auto getProc = [instProc, devProc](const char* proc_name,
|
||||
VkInstance instance, VkDevice device) {
|
||||
if (device != VK_NULL_HANDLE) {
|
||||
return devProc(device, proc_name);
|
||||
}
|
||||
return instProc(instance, proc_name);
|
||||
};
|
||||
|
||||
extensions = new GrVkExtensions();
|
||||
features = new VkPhysicalDeviceFeatures2;
|
||||
memset(features, 0, sizeof(VkPhysicalDeviceFeatures2));
|
||||
if (!sk_gpu_test::CreateVkBackendContext(getProc, &backendContext, extensions,
|
||||
if (!sk_gpu_test::CreateVkBackendContext(instProc, &backendContext, extensions,
|
||||
features, &debugCallback)) {
|
||||
sk_gpu_test::FreeVulkanFeaturesStructs(features);
|
||||
delete features;
|
||||
|
@ -14,15 +14,14 @@
|
||||
#include "tools/gpu/vk/VkTestUtils.h"
|
||||
|
||||
#define ACQUIRE_INST_VK_PROC(name) \
|
||||
fVk##name = reinterpret_cast<PFN_vk##name>(getProc("vk" #name, fBackendContext.fInstance,\
|
||||
VK_NULL_HANDLE)); \
|
||||
fVk##name = reinterpret_cast<PFN_vk##name>(instProc(fBackendContext.fInstance, "vk" #name)); \
|
||||
if (fVk##name == nullptr) { \
|
||||
SkDebugf("Function ptr for vk%s could not be acquired\n", #name); \
|
||||
return false; \
|
||||
}
|
||||
|
||||
#define ACQUIRE_DEVICE_VK_PROC(name) \
|
||||
fVk##name = reinterpret_cast<PFN_vk##name>(getProc("vk" #name, VK_NULL_HANDLE, fDevice)); \
|
||||
fVk##name = reinterpret_cast<PFN_vk##name>(fVkGetDeviceProcAddr(fDevice, "vk" #name)); \
|
||||
if (fVk##name == nullptr) { \
|
||||
SkDebugf("Function ptr for vk%s could not be acquired\n", #name); \
|
||||
return false; \
|
||||
@ -30,17 +29,9 @@
|
||||
|
||||
bool VkTestHelper::init() {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
|
||||
return false;
|
||||
}
|
||||
auto getProc = [&instProc, &devProc](const char* proc_name,
|
||||
VkInstance instance, VkDevice device) {
|
||||
if (device != VK_NULL_HANDLE) {
|
||||
return devProc(device, proc_name);
|
||||
}
|
||||
return instProc(instance, proc_name);
|
||||
};
|
||||
|
||||
fFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
|
||||
fFeatures.pNext = nullptr;
|
||||
@ -48,7 +39,7 @@ bool VkTestHelper::init() {
|
||||
fBackendContext.fInstance = VK_NULL_HANDLE;
|
||||
fBackendContext.fDevice = VK_NULL_HANDLE;
|
||||
|
||||
if (!sk_gpu_test::CreateVkBackendContext(getProc, &fBackendContext, &fExtensions,
|
||||
if (!sk_gpu_test::CreateVkBackendContext(instProc, &fBackendContext, &fExtensions,
|
||||
&fFeatures, &fDebugCallback, nullptr,
|
||||
sk_gpu_test::CanPresentFn(), fIsProtected)) {
|
||||
return false;
|
||||
@ -66,6 +57,8 @@ bool VkTestHelper::init() {
|
||||
ACQUIRE_INST_VK_PROC(GetPhysicalDeviceFormatProperties)
|
||||
ACQUIRE_INST_VK_PROC(GetPhysicalDeviceMemoryProperties)
|
||||
|
||||
ACQUIRE_INST_VK_PROC(GetDeviceProcAddr)
|
||||
|
||||
ACQUIRE_DEVICE_VK_PROC(CreateImage)
|
||||
ACQUIRE_DEVICE_VK_PROC(DestroyImage)
|
||||
ACQUIRE_DEVICE_VK_PROC(GetImageMemoryRequirements)
|
||||
|
@ -39,6 +39,7 @@ private:
|
||||
DECLARE_VK_PROC(DestroyInstance);
|
||||
DECLARE_VK_PROC(DeviceWaitIdle);
|
||||
DECLARE_VK_PROC(DestroyDevice);
|
||||
DECLARE_VK_PROC(GetDeviceProcAddr);
|
||||
|
||||
DECLARE_VK_PROC(GetPhysicalDeviceFormatProperties);
|
||||
DECLARE_VK_PROC(GetPhysicalDeviceMemoryProperties);
|
||||
|
@ -33,11 +33,9 @@
|
||||
|
||||
namespace sk_gpu_test {
|
||||
|
||||
bool LoadVkLibraryAndGetProcAddrFuncs(PFN_vkGetInstanceProcAddr* instProc,
|
||||
PFN_vkGetDeviceProcAddr* devProc) {
|
||||
bool LoadVkLibraryAndGetProcAddrFuncs(PFN_vkGetInstanceProcAddr* instProc) {
|
||||
static void* vkLib = nullptr;
|
||||
static PFN_vkGetInstanceProcAddr localInstProc = nullptr;
|
||||
static PFN_vkGetDeviceProcAddr localDevProc = nullptr;
|
||||
if (!vkLib) {
|
||||
vkLib = SkLoadDynamicLibrary(SK_GPU_TOOLS_VK_LIBRARY_NAME);
|
||||
if (!vkLib) {
|
||||
@ -45,14 +43,11 @@ bool LoadVkLibraryAndGetProcAddrFuncs(PFN_vkGetInstanceProcAddr* instProc,
|
||||
}
|
||||
localInstProc = (PFN_vkGetInstanceProcAddr) SkGetProcedureAddress(vkLib,
|
||||
"vkGetInstanceProcAddr");
|
||||
localDevProc = (PFN_vkGetDeviceProcAddr) SkGetProcedureAddress(vkLib,
|
||||
"vkGetDeviceProcAddr");
|
||||
}
|
||||
if (!localInstProc || !localDevProc) {
|
||||
if (!localInstProc) {
|
||||
return false;
|
||||
}
|
||||
*instProc = localInstProc;
|
||||
*devProc = localDevProc;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -139,34 +134,37 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugReportCallback(
|
||||
}
|
||||
#endif
|
||||
|
||||
#define GET_PROC_LOCAL(F, inst, device) PFN_vk ## F F = (PFN_vk ## F) getProc("vk" #F, inst, device)
|
||||
#define ACQUIRE_VK_INST_PROC_LOCAL(name, instance) \
|
||||
PFN_vk##name grVk##name = \
|
||||
reinterpret_cast<PFN_vk##name>(getInstProc(instance, "vk" #name)); \
|
||||
do { \
|
||||
if (grVk##name == nullptr) { \
|
||||
SkDebugf("Function ptr for vk%s could not be acquired\n", #name); \
|
||||
return false; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static bool init_instance_extensions_and_layers(GrVkGetProc getProc,
|
||||
static bool init_instance_extensions_and_layers(PFN_vkGetInstanceProcAddr getInstProc,
|
||||
uint32_t specVersion,
|
||||
SkTArray<VkExtensionProperties>* instanceExtensions,
|
||||
SkTArray<VkLayerProperties>* instanceLayers) {
|
||||
if (getProc == nullptr) {
|
||||
if (getInstProc == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GET_PROC_LOCAL(EnumerateInstanceExtensionProperties, VK_NULL_HANDLE, VK_NULL_HANDLE);
|
||||
GET_PROC_LOCAL(EnumerateInstanceLayerProperties, VK_NULL_HANDLE, VK_NULL_HANDLE);
|
||||
|
||||
if (!EnumerateInstanceExtensionProperties ||
|
||||
!EnumerateInstanceLayerProperties) {
|
||||
return false;
|
||||
}
|
||||
ACQUIRE_VK_INST_PROC_LOCAL(EnumerateInstanceExtensionProperties, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_INST_PROC_LOCAL(EnumerateInstanceLayerProperties, VK_NULL_HANDLE);
|
||||
|
||||
VkResult res;
|
||||
uint32_t layerCount = 0;
|
||||
#ifdef SK_ENABLE_VK_LAYERS
|
||||
// instance layers
|
||||
res = EnumerateInstanceLayerProperties(&layerCount, nullptr);
|
||||
res = grVkEnumerateInstanceLayerProperties(&layerCount, nullptr);
|
||||
if (VK_SUCCESS != res) {
|
||||
return false;
|
||||
}
|
||||
VkLayerProperties* layers = new VkLayerProperties[layerCount];
|
||||
res = EnumerateInstanceLayerProperties(&layerCount, layers);
|
||||
res = grVkEnumerateInstanceLayerProperties(&layerCount, layers);
|
||||
if (VK_SUCCESS != res) {
|
||||
delete[] layers;
|
||||
return false;
|
||||
@ -187,12 +185,12 @@ static bool init_instance_extensions_and_layers(GrVkGetProc getProc,
|
||||
// via Vulkan implementation and implicitly enabled layers
|
||||
{
|
||||
uint32_t extensionCount = 0;
|
||||
res = EnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
|
||||
res = grVkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
|
||||
if (VK_SUCCESS != res) {
|
||||
return false;
|
||||
}
|
||||
VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount];
|
||||
res = EnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions);
|
||||
res = grVkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions);
|
||||
if (VK_SUCCESS != res) {
|
||||
delete[] extensions;
|
||||
return false;
|
||||
@ -207,13 +205,13 @@ static bool init_instance_extensions_and_layers(GrVkGetProc getProc,
|
||||
layerCount = instanceLayers->count();
|
||||
for (uint32_t layerIndex = 0; layerIndex < layerCount; ++layerIndex) {
|
||||
uint32_t extensionCount = 0;
|
||||
res = EnumerateInstanceExtensionProperties((*instanceLayers)[layerIndex].layerName,
|
||||
res = grVkEnumerateInstanceExtensionProperties((*instanceLayers)[layerIndex].layerName,
|
||||
&extensionCount, nullptr);
|
||||
if (VK_SUCCESS != res) {
|
||||
return false;
|
||||
}
|
||||
VkExtensionProperties* extensions = new VkExtensionProperties[extensionCount];
|
||||
res = EnumerateInstanceExtensionProperties((*instanceLayers)[layerIndex].layerName,
|
||||
res = grVkEnumerateInstanceExtensionProperties((*instanceLayers)[layerIndex].layerName,
|
||||
&extensionCount, extensions);
|
||||
if (VK_SUCCESS != res) {
|
||||
delete[] extensions;
|
||||
@ -228,6 +226,8 @@ static bool init_instance_extensions_and_layers(GrVkGetProc getProc,
|
||||
return true;
|
||||
}
|
||||
|
||||
#define GET_PROC_LOCAL(F, inst, device) PFN_vk ## F F = (PFN_vk ## F) getProc("vk" #F, inst, device)
|
||||
|
||||
static bool init_device_extensions_and_layers(GrVkGetProc getProc, uint32_t specVersion,
|
||||
VkInstance inst, VkPhysicalDevice physDev,
|
||||
SkTArray<VkExtensionProperties>* deviceExtensions,
|
||||
@ -317,6 +317,22 @@ static bool init_device_extensions_and_layers(GrVkGetProc getProc, uint32_t spec
|
||||
return true;
|
||||
}
|
||||
|
||||
#define ACQUIRE_VK_INST_PROC_NOCHECK(name, instance) \
|
||||
PFN_vk##name grVk##name = reinterpret_cast<PFN_vk##name>(getInstProc(instance, "vk" #name))
|
||||
|
||||
#define ACQUIRE_VK_INST_PROC(name, instance) \
|
||||
PFN_vk##name grVk##name = \
|
||||
reinterpret_cast<PFN_vk##name>(getInstProc(instance, "vk" #name)); \
|
||||
do { \
|
||||
if (grVk##name == nullptr) { \
|
||||
SkDebugf("Function ptr for vk%s could not be acquired\n", #name); \
|
||||
if (inst != VK_NULL_HANDLE) { \
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension); \
|
||||
} \
|
||||
return false; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ACQUIRE_VK_PROC_NOCHECK(name, instance, device) \
|
||||
PFN_vk##name grVk##name = reinterpret_cast<PFN_vk##name>(getProc("vk" #name, instance, device))
|
||||
|
||||
@ -326,8 +342,8 @@ static bool init_device_extensions_and_layers(GrVkGetProc getProc, uint32_t spec
|
||||
do { \
|
||||
if (grVk##name == nullptr) { \
|
||||
SkDebugf("Function ptr for vk%s could not be acquired\n", #name); \
|
||||
if (device != VK_NULL_HANDLE) { \
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension); \
|
||||
if (inst != VK_NULL_HANDLE) { \
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension); \
|
||||
} \
|
||||
return false; \
|
||||
} \
|
||||
@ -343,15 +359,15 @@ static bool init_device_extensions_and_layers(GrVkGetProc getProc, uint32_t spec
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static bool destroy_instance(GrVkGetProc getProc, VkInstance inst,
|
||||
static bool destroy_instance(PFN_vkGetInstanceProcAddr getInstProc, VkInstance inst,
|
||||
VkDebugReportCallbackEXT* debugCallback,
|
||||
bool hasDebugExtension) {
|
||||
if (hasDebugExtension && *debugCallback != VK_NULL_HANDLE) {
|
||||
ACQUIRE_VK_PROC_LOCAL(DestroyDebugReportCallbackEXT, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_INST_PROC_LOCAL(DestroyDebugReportCallbackEXT, inst);
|
||||
grVkDestroyDebugReportCallbackEXT(inst, *debugCallback, nullptr);
|
||||
*debugCallback = VK_NULL_HANDLE;
|
||||
}
|
||||
ACQUIRE_VK_PROC_LOCAL(DestroyInstance, inst, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_INST_PROC_LOCAL(DestroyInstance, inst);
|
||||
grVkDestroyInstance(inst, nullptr);
|
||||
return true;
|
||||
}
|
||||
@ -420,7 +436,7 @@ static bool setup_features(GrVkGetProc getProc, VkInstance inst, VkPhysicalDevic
|
||||
// If we want to disable any extension features do so here.
|
||||
}
|
||||
|
||||
bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
bool CreateVkBackendContext(PFN_vkGetInstanceProcAddr getInstProc,
|
||||
GrVkBackendContext* ctx,
|
||||
GrVkExtensions* extensions,
|
||||
VkPhysicalDeviceFeatures2* features,
|
||||
@ -430,7 +446,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
bool isProtected) {
|
||||
VkResult err;
|
||||
|
||||
ACQUIRE_VK_PROC_NOCHECK(EnumerateInstanceVersion, VK_NULL_HANDLE, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_INST_PROC_NOCHECK(EnumerateInstanceVersion, VK_NULL_HANDLE);
|
||||
uint32_t instanceVersion = 0;
|
||||
if (!grVkEnumerateInstanceVersion) {
|
||||
instanceVersion = VK_MAKE_VERSION(1, 0, 0);
|
||||
@ -460,7 +476,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
|
||||
VkPhysicalDevice physDev;
|
||||
VkDevice device;
|
||||
VkInstance inst;
|
||||
VkInstance inst = VK_NULL_HANDLE;
|
||||
|
||||
const VkApplicationInfo app_info = {
|
||||
VK_STRUCTURE_TYPE_APPLICATION_INFO, // sType
|
||||
@ -475,7 +491,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
SkTArray<VkLayerProperties> instanceLayers;
|
||||
SkTArray<VkExtensionProperties> instanceExtensions;
|
||||
|
||||
if (!init_instance_extensions_and_layers(getProc, instanceVersion,
|
||||
if (!init_instance_extensions_and_layers(getInstProc, instanceVersion,
|
||||
&instanceExtensions,
|
||||
&instanceLayers)) {
|
||||
return false;
|
||||
@ -505,13 +521,22 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
|
||||
bool hasDebugExtension = false;
|
||||
|
||||
ACQUIRE_VK_PROC(CreateInstance, VK_NULL_HANDLE, VK_NULL_HANDLE);
|
||||
ACQUIRE_VK_INST_PROC(CreateInstance, VK_NULL_HANDLE);
|
||||
err = grVkCreateInstance(&instance_create, nullptr, &inst);
|
||||
if (err < 0) {
|
||||
SkDebugf("vkCreateInstance failed: %d\n", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
ACQUIRE_VK_INST_PROC(GetDeviceProcAddr, inst);
|
||||
auto getProc = [getInstProc, grVkGetDeviceProcAddr](const char* proc_name,
|
||||
VkInstance instance, VkDevice device) {
|
||||
if (device != VK_NULL_HANDLE) {
|
||||
return grVkGetDeviceProcAddr(device, proc_name);
|
||||
}
|
||||
return getInstProc(instance, proc_name);
|
||||
};
|
||||
|
||||
#ifdef SK_ENABLE_VK_LAYERS
|
||||
*debugCallback = VK_NULL_HANDLE;
|
||||
for (int i = 0; i < instanceExtensionNames.count() && !hasDebugExtension; ++i) {
|
||||
@ -551,12 +576,12 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
err = grVkEnumeratePhysicalDevices(inst, &gpuCount, nullptr);
|
||||
if (err) {
|
||||
SkDebugf("vkEnumeratePhysicalDevices failed: %d\n", err);
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension);
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension);
|
||||
return false;
|
||||
}
|
||||
if (!gpuCount) {
|
||||
SkDebugf("vkEnumeratePhysicalDevices returned no supported devices.\n");
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension);
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension);
|
||||
return false;
|
||||
}
|
||||
// Just returning the first physical device instead of getting the whole array.
|
||||
@ -566,7 +591,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
// VK_INCOMPLETE is returned when the count we provide is less than the total device count.
|
||||
if (err && VK_INCOMPLETE != err) {
|
||||
SkDebugf("vkEnumeratePhysicalDevices failed: %d\n", err);
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension);
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -576,7 +601,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
|
||||
if (isProtected && physDeviceVersion < VK_MAKE_VERSION(1, 1, 0)) {
|
||||
SkDebugf("protected requires vk physical device version 1.1\n");
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension);
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -585,7 +610,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
grVkGetPhysicalDeviceQueueFamilyProperties(physDev, &queueCount, nullptr);
|
||||
if (!queueCount) {
|
||||
SkDebugf("vkGetPhysicalDeviceQueueFamilyProperties returned no queues.\n");
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension);
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -605,7 +630,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
}
|
||||
if (graphicsQueueIndex == queueCount) {
|
||||
SkDebugf("Could not find any supported graphics queues.\n");
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension);
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -620,7 +645,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
}
|
||||
if (presentQueueIndex == queueCount) {
|
||||
SkDebugf("Could not find any supported present queues.\n");
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension);
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension);
|
||||
return false;
|
||||
}
|
||||
*presentQueueIndexPtr = presentQueueIndex;
|
||||
@ -636,7 +661,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
inst, physDev,
|
||||
&deviceExtensions,
|
||||
&deviceLayers)) {
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension);
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -696,7 +721,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
extensions->hasExtension(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, 1)) {
|
||||
if (!setup_features(getProc, inst, physDev, physDeviceVersion, extensions, features,
|
||||
isProtected)) {
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension);
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -758,7 +783,7 @@ bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
}
|
||||
if (err) {
|
||||
SkDebugf("CreateDevice failed: %d\n", err);
|
||||
destroy_instance(getProc, inst, debugCallback, hasDebugExtension);
|
||||
destroy_instance(getInstProc, inst, debugCallback, hasDebugExtension);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -21,12 +21,12 @@ class GrVkExtensions;
|
||||
struct GrVkBackendContext;
|
||||
|
||||
namespace sk_gpu_test {
|
||||
bool LoadVkLibraryAndGetProcAddrFuncs(PFN_vkGetInstanceProcAddr*, PFN_vkGetDeviceProcAddr*);
|
||||
bool LoadVkLibraryAndGetProcAddrFuncs(PFN_vkGetInstanceProcAddr*);
|
||||
|
||||
using CanPresentFn = std::function<bool(VkInstance, VkPhysicalDevice,
|
||||
uint32_t queueFamilyIndex)>;
|
||||
|
||||
bool CreateVkBackendContext(GrVkGetProc getProc,
|
||||
bool CreateVkBackendContext(PFN_vkGetInstanceProcAddr getInstProc,
|
||||
GrVkBackendContext* ctx,
|
||||
GrVkExtensions*,
|
||||
VkPhysicalDeviceFeatures2*,
|
||||
|
@ -24,16 +24,17 @@
|
||||
#undef CreateSemaphore
|
||||
#endif
|
||||
|
||||
#define GET_PROC(F) f ## F = (PFN_vk ## F) fGetInstanceProcAddr(fInstance, "vk" #F)
|
||||
#define GET_DEV_PROC(F) f ## F = (PFN_vk ## F) fGetDeviceProcAddr(fDevice, "vk" #F)
|
||||
#define GET_PROC(F) f ## F = \
|
||||
(PFN_vk ## F) backendContext.fGetProc("vk" #F, fInstance, VK_NULL_HANDLE)
|
||||
#define GET_DEV_PROC(F) f ## F = \
|
||||
(PFN_vk ## F) backendContext.fGetProc("vk" #F, VK_NULL_HANDLE, fDevice)
|
||||
|
||||
namespace sk_app {
|
||||
|
||||
VulkanWindowContext::VulkanWindowContext(const DisplayParams& params,
|
||||
CreateVkSurfaceFn createVkSurface,
|
||||
CanPresentFn canPresent,
|
||||
PFN_vkGetInstanceProcAddr instProc,
|
||||
PFN_vkGetDeviceProcAddr devProc)
|
||||
PFN_vkGetInstanceProcAddr instProc)
|
||||
: WindowContext(params)
|
||||
, fCreateVkSurfaceFn(createVkSurface)
|
||||
, fCanPresentFn(canPresent)
|
||||
@ -44,7 +45,6 @@ VulkanWindowContext::VulkanWindowContext(const DisplayParams& params,
|
||||
, fSurfaces(nullptr)
|
||||
, fBackbuffers(nullptr) {
|
||||
fGetInstanceProcAddr = instProc;
|
||||
fGetDeviceProcAddr = devProc;
|
||||
this->initializeContext();
|
||||
}
|
||||
|
||||
@ -53,19 +53,12 @@ void VulkanWindowContext::initializeContext() {
|
||||
// any config code here (particularly for msaa)?
|
||||
|
||||
PFN_vkGetInstanceProcAddr getInstanceProc = fGetInstanceProcAddr;
|
||||
PFN_vkGetDeviceProcAddr getDeviceProc = fGetDeviceProcAddr;
|
||||
auto getProc = [getInstanceProc, getDeviceProc](const char* proc_name,
|
||||
VkInstance instance, VkDevice device) {
|
||||
if (device != VK_NULL_HANDLE) {
|
||||
return getDeviceProc(device, proc_name);
|
||||
}
|
||||
return getInstanceProc(instance, proc_name);
|
||||
};
|
||||
GrVkBackendContext backendContext;
|
||||
GrVkExtensions extensions;
|
||||
VkPhysicalDeviceFeatures2 features;
|
||||
if (!sk_gpu_test::CreateVkBackendContext(getProc, &backendContext, &extensions, &features,
|
||||
&fDebugCallback, &fPresentQueueIndex, fCanPresentFn)) {
|
||||
if (!sk_gpu_test::CreateVkBackendContext(getInstanceProc, &backendContext, &extensions,
|
||||
&features, &fDebugCallback, &fPresentQueueIndex,
|
||||
fCanPresentFn)) {
|
||||
sk_gpu_test::FreeVulkanFeaturesStructs(&features);
|
||||
return;
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
using CanPresentFn = sk_gpu_test::CanPresentFn;
|
||||
|
||||
VulkanWindowContext(const DisplayParams&, CreateVkSurfaceFn, CanPresentFn,
|
||||
PFN_vkGetInstanceProcAddr, PFN_vkGetDeviceProcAddr);
|
||||
PFN_vkGetInstanceProcAddr);
|
||||
|
||||
private:
|
||||
void initializeContext();
|
||||
@ -73,9 +73,7 @@ private:
|
||||
CreateVkSurfaceFn fCreateVkSurfaceFn;
|
||||
CanPresentFn fCanPresentFn;
|
||||
|
||||
// Vulkan GetProcAddr functions
|
||||
PFN_vkGetInstanceProcAddr fGetInstanceProcAddr = nullptr;
|
||||
PFN_vkGetDeviceProcAddr fGetDeviceProcAddr = nullptr;
|
||||
|
||||
// WSI interface functions
|
||||
PFN_vkDestroySurfaceKHR fDestroySurfaceKHR = nullptr;
|
||||
|
@ -21,8 +21,7 @@ namespace window_context_factory {
|
||||
std::unique_ptr<WindowContext> MakeVulkanForAndroid(ANativeWindow* window,
|
||||
const DisplayParams& params) {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -50,7 +49,7 @@ std::unique_ptr<WindowContext> MakeVulkanForAndroid(ANativeWindow* window,
|
||||
auto canPresent = [](VkInstance, VkPhysicalDevice, uint32_t) { return true; };
|
||||
|
||||
std::unique_ptr<WindowContext> ctx(
|
||||
new VulkanWindowContext(params, createVkSurface, canPresent, instProc, devProc));
|
||||
new VulkanWindowContext(params, createVkSurface, canPresent, instProc));
|
||||
if (!ctx->isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ namespace window_context_factory {
|
||||
std::unique_ptr<WindowContext> MakeVulkanForXlib(const XlibWindowInfo& info,
|
||||
const DisplayParams& displayParams) {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -75,7 +74,7 @@ std::unique_ptr<WindowContext> MakeVulkanForXlib(const XlibWindowInfo& info,
|
||||
return (VK_FALSE != check);
|
||||
};
|
||||
std::unique_ptr<WindowContext> ctx(
|
||||
new VulkanWindowContext(displayParams, createVkSurface, canPresent, instProc, devProc));
|
||||
new VulkanWindowContext(displayParams, createVkSurface, canPresent, instProc));
|
||||
if (!ctx->isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ namespace window_context_factory {
|
||||
|
||||
std::unique_ptr<WindowContext> MakeVulkanForWin(HWND hwnd, const DisplayParams& params) {
|
||||
PFN_vkGetInstanceProcAddr instProc;
|
||||
PFN_vkGetDeviceProcAddr devProc;
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc, &devProc)) {
|
||||
if (!sk_gpu_test::LoadVkLibraryAndGetProcAddrFuncs(&instProc)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@ -70,7 +69,7 @@ std::unique_ptr<WindowContext> MakeVulkanForWin(HWND hwnd, const DisplayParams&
|
||||
};
|
||||
|
||||
std::unique_ptr<WindowContext> ctx(
|
||||
new VulkanWindowContext(params, createVkSurface, canPresent, instProc, devProc));
|
||||
new VulkanWindowContext(params, createVkSurface, canPresent, instProc));
|
||||
if (!ctx->isValid()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user