Implement Vulkan API for reading the display's size
Implement the Vulkan API --
vkGetPhysicalDeviceSurfacePresentModesKHR() -- in terms of the Magma
public API.
Note that the vkcube demo already uses that Vulkan API, so it will
start using the actual display size (rather than a default) after this
change.
This is a reland of 3fa9877324791bdeb56bcf3d4e0cb8a57ec2e0e7 now that
the bad interaction between vkCreateMagmaSurfaceKHR() and
vulkan_loader_and_validation_layers has been fixed by other changes.
MA-214
Change-Id: Ic0431ac8a1193b110768ef33bee378885cf6e7ad
diff --git a/include/vulkan/vk_icd.h b/include/vulkan/vk_icd.h
index f06610b..a06e7c8 100644
--- a/include/vulkan/vk_icd.h
+++ b/include/vulkan/vk_icd.h
@@ -86,6 +86,7 @@
#ifdef VK_USE_PLATFORM_MAGMA_KHR
typedef struct _VkIcdSurfaceMagma {
VkIcdSurfaceBase base;
+ VkExtent2D display_size;
} VkIcdSurfaceMagma;
#endif // VK_USE_PLATFORM_MAGMA_KHR
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index bb96c76..911f096 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -67,6 +67,7 @@
fd = open(path, O_RDONLY);
if (fd < 0)
return vk_error(VK_ERROR_INCOMPATIBLE_DRIVER);
+ device->device_fd = fd;
device->_loader_data.loaderMagic = ICD_LOADER_MAGIC;
device->instance = instance;
@@ -186,7 +187,6 @@
/* XXX: Actually detect bit6 swizzling */
isl_device_init(&device->isl_dev, &device->info, swizzled);
- close(fd);
return VK_SUCCESS;
fail:
@@ -199,6 +199,8 @@
{
anv_finish_wsi(device);
ralloc_free(device->compiler);
+ int result = close(device->device_fd);
+ assert(result == 0);
}
static const VkExtensionProperties global_extensions[] = {
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index 173dcf3..bd9965c 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -493,6 +493,7 @@
struct anv_instance * instance;
uint32_t chipset_id;
char path[64];
+ int device_fd;
const char * name;
struct gen_device_info info;
uint64_t aperture_size;
diff --git a/src/intel/vulkan/anv_wsi_magma.cc b/src/intel/vulkan/anv_wsi_magma.cc
index bef5467..8aa4bae 100644
--- a/src/intel/vulkan/anv_wsi_magma.cc
+++ b/src/intel/vulkan/anv_wsi_magma.cc
@@ -26,6 +26,10 @@
assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_MAGMA_SURFACE_CREATE_INFO_KHR);
+ magma_display_size display_size;
+ if (magma_display_get_size(instance->physicalDevice.device_fd, &display_size) != MAGMA_STATUS_OK)
+ return VK_ERROR_INITIALIZATION_FAILED;
+
if (!pAllocator)
pAllocator = &instance->alloc;
@@ -35,6 +39,8 @@
return VK_ERROR_OUT_OF_HOST_MEMORY;
surface->base.platform = VK_ICD_WSI_PLATFORM_MAGMA;
+ surface->display_size.width = display_size.width;
+ surface->display_size.height = display_size.height;
*pSurface = _VkIcdSurfaceBase_to_handle(&surface->base);
diff --git a/src/vulkan/wsi/wsi_common_magma.cc b/src/vulkan/wsi/wsi_common_magma.cc
index a22f28a..bfd1fb1 100644
--- a/src/vulkan/wsi/wsi_common_magma.cc
+++ b/src/vulkan/wsi/wsi_common_magma.cc
@@ -333,11 +333,11 @@
{
DLOG("magma_surface_get_capabilities");
- VkExtent2D any_extent = {0xFFFFFFFF, 0xFFFFFFFF};
+ auto* magma_surface = reinterpret_cast<VkIcdSurfaceMagma*>(icd_surface);
caps->minImageExtent = {1, 1};
- caps->maxImageExtent = any_extent;
- caps->currentExtent = any_extent;
+ caps->maxImageExtent = magma_surface->display_size;
+ caps->currentExtent = magma_surface->display_size;
caps->supportedCompositeAlpha =
VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR | VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;