Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix virtual swapchain #2685

Merged
merged 2 commits into from
Mar 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 37 additions & 30 deletions core/vulkan/vk_virtual_swapchain/cc/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,30 +321,31 @@ static const VkLayerProperties global_layer_properties[] = {{
"Virtual Swapchain Layer",
}};

VkResult get_layer_properties(uint32_t *pCount,
VkResult get_layer_properties(uint32_t *pPropertyCount,
VkLayerProperties *pProperties) {
if (pProperties == NULL) {
*pCount = 1;
*pPropertyCount = 1;
return VK_SUCCESS;
}

if (pCount == 0) {
if (pPropertyCount == 0) {
return VK_INCOMPLETE;
}
*pCount = 1;
*pPropertyCount = 1;
memcpy(pProperties, global_layer_properties, sizeof(global_layer_properties));
return VK_SUCCESS;
}

VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkEnumerateInstanceLayerProperties(uint32_t *pCount,
vkEnumerateInstanceLayerProperties(uint32_t *pPropertyCount,
VkLayerProperties *pProperties) {
return get_layer_properties(pCount, pProperties);
return get_layer_properties(pPropertyCount, pProperties);
}

VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
VkPhysicalDevice, uint32_t *pCount, VkLayerProperties *pProperties) {
return get_layer_properties(pCount, pProperties);
VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkEnumerateDeviceLayerProperties(VkPhysicalDevice, uint32_t *pPropertyCount,
VkLayerProperties *pProperties) {
return get_layer_properties(pPropertyCount, pProperties);
}

// Overload EnumeratePhysicalDevices, this is entirely for
Expand Down Expand Up @@ -414,6 +415,15 @@ VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceExtensionProperties(
physicalDevice, pLayerName, pPropertyCount, pProperties);
}

// Overload vkEnumerateInstanceExtensionProperties
VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkEnumerateInstanceExtensionProperties(
const char * /*pLayerName*/, uint32_t *pPropertyCount,
VkExtensionProperties * /*pProperties*/) {
*pPropertyCount = 0;
return VK_SUCCESS;
}

VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(
VkDevice device, VkCommandPool commandPool, uint32_t commandBufferCount,
const VkCommandBuffer *pCommandBuffers) {
Expand All @@ -425,14 +435,6 @@ VKAPI_ATTR void VKAPI_CALL vkFreeCommandBuffers(
device, commandPool, commandBufferCount, pCommandBuffers);
}

VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkEnumerateInstanceExtensionProperties(
const char * /*pLayerName*/, uint32_t *pCount,
VkExtensionProperties * /*pProperties*/) {
*pCount = 0;
return VK_SUCCESS;
}

// Overload GetInstanceProcAddr.
// It also provides the overloaded function for vkCreateDevice. This way we can
// also hook vkGetDeviceProcAddr.
Expand All @@ -444,13 +446,15 @@ vkGetInstanceProcAddr(VkInstance instance, const char *funcName) {
return reinterpret_cast<PFN_vkVoidFunction>(func)

INTERCEPT(vkGetInstanceProcAddr);

INTERCEPT(vkCreateDevice);
INTERCEPT(vkCreateInstance);
INTERCEPT(vkDestroyInstance);
INTERCEPT(vkEnumeratePhysicalDevices);
INTERCEPT(vkEnumerateDeviceExtensionProperties);
INTERCEPT(vkEnumerateInstanceLayerProperties);
INTERCEPT(vkEnumerateDeviceLayerProperties);
INTERCEPT(vkEnumerateInstanceExtensionProperties);
INTERCEPT(vkEnumerateInstanceLayerProperties);
INTERCEPT(vkEnumeratePhysicalDevices);

// From here on down these are what is needed for
// swapchain/surface support.
Expand Down Expand Up @@ -556,39 +560,42 @@ VK_LAYER_EXPORT VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL LAYER_NAME_FUNCTION(
}

// Documentation is sparse for Android, looking at libvulkan.so
// These 4 function must be defined in order for this to even
// These 4 functions must be defined in order for this to even
// be considered for loading.
#if defined(__ANDROID__)
VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkEnumerateInstanceLayerProperties(uint32_t *pCount,
vkEnumerateInstanceLayerProperties(uint32_t *pPropertyCount,
VkLayerProperties *pProperties) {
return swapchain::vkEnumerateInstanceLayerProperties(pCount, pProperties);
return swapchain::vkEnumerateInstanceLayerProperties(pPropertyCount,
pProperties);
}

// On Android this must also be defined, even if we have 0
// layers to expose.
VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkEnumerateInstanceExtensionProperties(const char *pLayerName, uint32_t *pCount,
vkEnumerateInstanceExtensionProperties(const char *pLayerName,
uint32_t *pPropertyCount,
VkExtensionProperties *pProperties) {
return swapchain::vkEnumerateInstanceExtensionProperties(pLayerName, pCount,
pProperties);
return swapchain::vkEnumerateInstanceExtensionProperties(
pLayerName, pPropertyCount, pProperties);
}

VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkEnumerateDeviceLayerProperties(
VkPhysicalDevice physicalDevice, uint32_t *pCount,
VkPhysicalDevice physicalDevice, uint32_t *pPropertyCount,
VkLayerProperties *pProperties) {
return swapchain::vkEnumerateDeviceLayerProperties(physicalDevice, pCount,
pProperties);
return swapchain::vkEnumerateDeviceLayerProperties(
physicalDevice, pPropertyCount, pProperties);
}

// On Android this must also be defined, even if we have 0
// layers to expose.
VK_LAYER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL
vkEnumerateDeviceExtensionProperties(VkPhysicalDevice physicalDevice,
const char *pLayerName, uint32_t *pCount,
const char *pLayerName,
uint32_t *pPropertyCount,
VkExtensionProperties *pProperties) {
return swapchain::vkEnumerateDeviceExtensionProperties(
physicalDevice, pLayerName, pCount, pProperties);
physicalDevice, pLayerName, pPropertyCount, pProperties);
}
#endif
}