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 non-sorted surface indexing #890

Merged
merged 1 commit into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions loader/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -5928,6 +5928,7 @@ VkResult setup_loader_term_phys_devs(struct loader_instance *inst) {
}
inst->total_gpu_count += icd_phys_dev_array[icd_idx].device_count;
icd_phys_dev_array[icd_idx].icd_term = icd_term;
icd_phys_dev_array[icd_idx].icd_index = icd_idx;
icd_term = icd_term->next;
++icd_idx;
}
Expand Down
24 changes: 10 additions & 14 deletions loader/wsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceSupportKH
abort(); /* Intentionally fail so user can correct issue. */
}
disp = loader_get_instance_layer_dispatch(physicalDevice);
VkResult res = disp->GetPhysicalDeviceSurfaceSupportKHR(unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
return res;
return disp->GetPhysicalDeviceSurfaceSupportKHR(unwrapped_phys_dev, queueFamilyIndex, surface, pSupported);
}

// This is the instance chain terminator function for
Expand Down Expand Up @@ -277,8 +276,7 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceCapabilit
abort(); /* Intentionally fail so user can correct issue. */
}
disp = loader_get_instance_layer_dispatch(physicalDevice);
VkResult res = disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(unwrapped_phys_dev, surface, pSurfaceCapabilities);
return res;
return disp->GetPhysicalDeviceSurfaceCapabilitiesKHR(unwrapped_phys_dev, surface, pSurfaceCapabilities);
}

// This is the instance chain terminator function for
Expand Down Expand Up @@ -331,8 +329,7 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfaceFormatsKH
abort(); /* Intentionally fail so user can correct issue. */
}
disp = loader_get_instance_layer_dispatch(physicalDevice);
VkResult res = disp->GetPhysicalDeviceSurfaceFormatsKHR(unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
return res;
return disp->GetPhysicalDeviceSurfaceFormatsKHR(unwrapped_phys_dev, surface, pSurfaceFormatCount, pSurfaceFormats);
}

// This is the instance chain terminator function for
Expand Down Expand Up @@ -387,8 +384,7 @@ LOADER_EXPORT VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceSurfacePresentMo
abort(); /* Intentionally fail so user can correct issue. */
}
disp = loader_get_instance_layer_dispatch(physicalDevice);
VkResult res = disp->GetPhysicalDeviceSurfacePresentModesKHR(unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
return res;
return disp->GetPhysicalDeviceSurfacePresentModesKHR(unwrapped_phys_dev, surface, pPresentModeCount, pPresentModes);
}

// This is the instance chain terminator function for
Expand All @@ -414,7 +410,7 @@ VKAPI_ATTR VkResult VKAPI_CALL terminator_GetPhysicalDeviceSurfacePresentModesKH

if (NULL == icd_term->dispatch.GetPhysicalDeviceSurfacePresentModesKHR) {
loader_log(loader_inst, VULKAN_LOADER_ERROR_BIT, 0,
"ICD for selected physical device does not exportvkGetPhysicalDeviceSurfacePresentModesKHR!\n");
"ICD for selected physical device does not export vkGetPhysicalDeviceSurfacePresentModesKHR!\n");
abort();
}

Expand Down Expand Up @@ -771,7 +767,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceWaylandPresentationSu

if (NULL == icd_term->dispatch.GetPhysicalDeviceWaylandPresentationSupportKHR) {
loader_log(loader_inst, VULKAN_LOADER_ERROR_BIT, 0,
"ICD for selected physical device does not exportvkGetPhysicalDeviceWaylandPresentationSupportKHR!\n");
"ICD for selected physical device does not export vkGetPhysicalDeviceWaylandPresentationSupportKHR!\n");
abort();
}

Expand Down Expand Up @@ -893,7 +889,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceXcbPresentationSuppor

if (NULL == icd_term->dispatch.GetPhysicalDeviceXcbPresentationSupportKHR) {
loader_log(loader_inst, VULKAN_LOADER_ERROR_BIT, 0,
"ICD for selected physical device does not exportvkGetPhysicalDeviceXcbPresentationSupportKHR!\n");
"ICD for selected physical device does not export vkGetPhysicalDeviceXcbPresentationSupportKHR!\n");
abort();
}

Expand Down Expand Up @@ -1014,7 +1010,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceXlibPresentationSuppo

if (NULL == icd_term->dispatch.GetPhysicalDeviceXlibPresentationSupportKHR) {
loader_log(loader_inst, VULKAN_LOADER_ERROR_BIT, 0,
"ICD for selected physical device does not exportvkGetPhysicalDeviceXlibPresentationSupportKHR!\n");
"ICD for selected physical device does not export vkGetPhysicalDeviceXlibPresentationSupportKHR!\n");
abort();
}

Expand Down Expand Up @@ -1138,7 +1134,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceDirectFBPresentationS

if (NULL == icd_term->dispatch.GetPhysicalDeviceDirectFBPresentationSupportEXT) {
loader_log(loader_inst, VULKAN_LOADER_ERROR_BIT, 0,
"ICD for selected physical device does not exportvkGetPhysicalDeviceDirectFBPresentationSupportEXT!\n");
"ICD for selected physical device does not export vkGetPhysicalDeviceDirectFBPresentationSupportEXT!\n");
abort();
}

Expand Down Expand Up @@ -1653,7 +1649,7 @@ VKAPI_ATTR VkBool32 VKAPI_CALL terminator_GetPhysicalDeviceScreenPresentationSup

if (NULL == icd_term->dispatch.GetPhysicalDeviceScreenPresentationSupportQNX) {
loader_log(loader_inst, VULKAN_LOADER_ERROR_BIT, 0,
"ICD for selected physical device does not exportvkGetPhysicalDeviceScreenPresentationSupportQNX!\n");
"ICD for selected physical device does not export vkGetPhysicalDeviceScreenPresentationSupportQNX!\n");
abort();
}

Expand Down
52 changes: 52 additions & 0 deletions tests/framework/icd/test_icd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,22 @@ VKAPI_ATTR VkBool32 VKAPI_CALL test_vkGetPhysicalDeviceScreenPresentationSupport
}
#endif // VK_USE_PLATFORM_SCREEN_QNX

VKAPI_ATTR VkResult VKAPI_CALL test_vkCreateHeadlessSurfaceEXT(VkInstance instance,
const VkHeadlessSurfaceCreateInfoEXT* pCreateInfo,
const VkAllocationCallbacks* pAllocator, VkSurfaceKHR* pSurface) {
if (nullptr != pSurface) {
uint64_t fake_surf_handle = reinterpret_cast<uint64_t>(new uint8_t);
icd.surface_handles.push_back(fake_surf_handle);
#if defined(__LP64__) || defined(_WIN64) || (defined(__x86_64__) && !defined(__ILP32__)) || defined(_M_X64) || defined(__ia64) || \
defined(_M_IA64) || defined(__aarch64__) || defined(__powerpc64__)
*pSurface = reinterpret_cast<VkSurfaceKHR>(fake_surf_handle);
#else
*pSurface = fake_surf_handle;
#endif
}
return VK_SUCCESS;
}

VKAPI_ATTR void VKAPI_CALL test_vkDestroySurfaceKHR(VkInstance instance, VkSurfaceKHR surface,
const VkAllocationCallbacks* pAllocator) {
if (surface != VK_NULL_HANDLE) {
Expand Down Expand Up @@ -665,13 +681,29 @@ VKAPI_ATTR void VKAPI_CALL test_vkDestroySwapchainKHR(VkDevice device, VkSwapcha
// VK_KHR_surface
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceSupportKHR(VkPhysicalDevice physicalDevice, uint32_t queueFamilyIndex,
VkSurfaceKHR surface, VkBool32* pSupported) {
if (surface != VK_NULL_HANDLE) {
uint64_t fake_surf_handle = (uint64_t)(surface);
auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
if (found_iter == icd.surface_handles.end()) {
assert(false && "Surface not found during GetPhysicalDeviceSurfaceSupportKHR query!");
return VK_ERROR_UNKNOWN;
}
}
if (nullptr != pSupported) {
*pSupported = icd.GetPhysDevice(physicalDevice).queue_family_properties.at(queueFamilyIndex).support_present;
}
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
VkSurfaceCapabilitiesKHR* pSurfaceCapabilities) {
if (surface != VK_NULL_HANDLE) {
uint64_t fake_surf_handle = (uint64_t)(surface);
auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
if (found_iter == icd.surface_handles.end()) {
assert(false && "Surface not found during GetPhysicalDeviceSurfaceCapabilitiesKHR query!");
return VK_ERROR_UNKNOWN;
}
}
if (nullptr != pSurfaceCapabilities) {
*pSurfaceCapabilities = icd.GetPhysDevice(physicalDevice).surface_capabilities;
}
Expand All @@ -680,12 +712,28 @@ VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceCapabilitiesKHR(Vk
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
uint32_t* pSurfaceFormatCount,
VkSurfaceFormatKHR* pSurfaceFormats) {
if (surface != VK_NULL_HANDLE) {
uint64_t fake_surf_handle = (uint64_t)(surface);
auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
if (found_iter == icd.surface_handles.end()) {
assert(false && "Surface not found during GetPhysicalDeviceSurfaceFormatsKHR query!");
return VK_ERROR_UNKNOWN;
}
}
FillCountPtr(icd.GetPhysDevice(physicalDevice).surface_formats, pSurfaceFormatCount, pSurfaceFormats);
return VK_SUCCESS;
}
VKAPI_ATTR VkResult VKAPI_CALL test_vkGetPhysicalDeviceSurfacePresentModesKHR(VkPhysicalDevice physicalDevice, VkSurfaceKHR surface,
uint32_t* pPresentModeCount,
VkPresentModeKHR* pPresentModes) {
if (surface != VK_NULL_HANDLE) {
uint64_t fake_surf_handle = (uint64_t)(surface);
auto found_iter = std::find(icd.surface_handles.begin(), icd.surface_handles.end(), fake_surf_handle);
if (found_iter == icd.surface_handles.end()) {
assert(false && "Surface not found during GetPhysicalDeviceSurfacePresentModesKHR query!");
return VK_ERROR_UNKNOWN;
}
}
FillCountPtr(icd.GetPhysDevice(physicalDevice).surface_present_modes, pPresentModeCount, pPresentModes);
return VK_SUCCESS;
}
Expand Down Expand Up @@ -1140,6 +1188,10 @@ PFN_vkVoidFunction get_instance_func_wsi(VkInstance instance, const char* pName)
}
#endif // VK_USE_PLATFORM_SCREEN_QNX

if (string_eq(pName, "vkCreateHeadlessSurfaceEXT")) {
return to_vkVoidFunction(test_vkCreateHeadlessSurfaceEXT);
}

if (string_eq(pName, "vkDestroySurfaceKHR")) {
icd.is_using_icd_wsi = UsingICDProvidedWSI::is_using;
return to_vkVoidFunction(test_vkDestroySurfaceKHR);
Expand Down
18 changes: 14 additions & 4 deletions tests/loader_phys_dev_inst_ext_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2727,8 +2727,11 @@ TEST(LoaderInstPhysDevExts, PhysDevSurfaceCaps2KHRInstanceAndICDSupport) {
Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME};
Extension second_ext{VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME};
Extension third_ext{VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME};
env.get_test_icd(0).add_instance_extensions({first_ext, second_ext, third_ext});
env.get_test_icd(0).physical_devices.push_back({});
auto& cur_icd = env.get_test_icd(0);
cur_icd.add_instance_extensions({first_ext, second_ext, third_ext});
cur_icd.physical_devices.push_back({});
cur_icd.min_icd_interface_version = 3;
cur_icd.enable_icd_wsi = true;
FillInRandomSurfaceCapsData(env.get_test_icd(0).physical_devices.back().surface_capabilities);

InstWrapper instance(env.vulkan_functions);
Expand Down Expand Up @@ -2795,6 +2798,8 @@ TEST(LoaderInstPhysDevExts, PhysDevSurfaceCaps2KHRMixed) {
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_6));
auto& cur_icd = env.get_test_icd(icd);
cur_icd.icd_api_version = VK_API_VERSION_1_0;
cur_icd.min_icd_interface_version = 3;
cur_icd.enable_icd_wsi = true;
cur_icd.add_instance_extensions({first_ext, third_ext});

// ICD 1 should not have 1.1
Expand Down Expand Up @@ -2928,8 +2933,11 @@ TEST(LoaderInstPhysDevExts, PhysDevSurfaceFormats2KHRInstanceAndICDSupport) {
Extension first_ext{VK_KHR_SURFACE_EXTENSION_NAME};
Extension second_ext{VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME};
Extension third_ext{VK_EXT_HEADLESS_SURFACE_EXTENSION_NAME};
env.get_test_icd(0).add_instance_extensions({first_ext, second_ext, third_ext});
env.get_test_icd(0).physical_devices.push_back({});
auto& cur_icd = env.get_test_icd(0);
cur_icd.add_instance_extensions({first_ext, second_ext, third_ext});
cur_icd.physical_devices.push_back({});
cur_icd.min_icd_interface_version = 3;
cur_icd.enable_icd_wsi = true;
FillInRandomSurfaceFormatsData(env.get_test_icd(0).physical_devices.back().surface_formats);

InstWrapper instance(env.vulkan_functions);
Expand Down Expand Up @@ -3005,6 +3013,8 @@ TEST(LoaderInstPhysDevExts, PhysDevSurfaceFormats2KHRMixed) {
env.add_icd(TestICDDetails(TEST_ICD_PATH_VERSION_6));
auto& cur_icd = env.get_test_icd(icd);
cur_icd.icd_api_version = VK_API_VERSION_1_0;
cur_icd.enable_icd_wsi = true;
cur_icd.min_icd_interface_version = 3;
cur_icd.add_instance_extensions({first_ext, third_ext});

// ICD 1 should not have 1.1
Expand Down
Loading