*/
#include "wsi_common_private.h"
-#include "drm_fourcc.h"
+#include "drm-uapi/drm_fourcc.h"
#include "util/macros.h"
+#include "util/xmlconfig.h"
#include "vk_util.h"
+#include <time.h>
#include <unistd.h>
#include <xf86drm.h>
+#include <stdlib.h>
+#include <stdio.h>
VkResult
wsi_device_init(struct wsi_device *wsi,
VkPhysicalDevice pdevice,
WSI_FN_GetPhysicalDeviceProcAddr proc_addr,
const VkAllocationCallbacks *alloc,
- int display_fd)
+ int display_fd,
+ const struct driOptionCache *dri_options)
{
+ const char *present_mode;
VkResult result;
memset(wsi, 0, sizeof(*wsi));
};
GetPhysicalDeviceProperties2(pdevice, &pdp2);
+ wsi->maxImageDimension2D = pdp2.properties.limits.maxImageDimension2D;
+ wsi->override_present_mode = VK_PRESENT_MODE_MAX_ENUM_KHR;
+
GetPhysicalDeviceMemoryProperties(pdevice, &wsi->memory_props);
GetPhysicalDeviceQueueFamilyProperties(pdevice, &wsi->queue_family_count, NULL);
#undef WSI_GET_CB
#ifdef VK_USE_PLATFORM_XCB_KHR
- result = wsi_x11_init_wsi(wsi, alloc);
+ result = wsi_x11_init_wsi(wsi, alloc, dri_options);
if (result != VK_SUCCESS)
goto fail;
#endif
goto fail;
#endif
+ present_mode = getenv("MESA_VK_WSI_PRESENT_MODE");
+ if (present_mode) {
+ if (!strcmp(present_mode, "fifo")) {
+ wsi->override_present_mode = VK_PRESENT_MODE_FIFO_KHR;
+ } else if (!strcmp(present_mode, "mailbox")) {
+ wsi->override_present_mode = VK_PRESENT_MODE_MAILBOX_KHR;
+ } else if (!strcmp(present_mode, "immediate")) {
+ wsi->override_present_mode = VK_PRESENT_MODE_IMMEDIATE_KHR;
+ } else {
+ fprintf(stderr, "Invalid MESA_VK_WSI_PRESENT_MODE value!\n");
+ }
+ }
+
+ if (dri_options) {
+ if (driCheckOption(dri_options, "adaptive_sync", DRI_BOOL))
+ wsi->enable_adaptive_sync = driQueryOptionb(dri_options,
+ "adaptive_sync");
+
+ if (driCheckOption(dri_options, "vk_wsi_force_bgra8_unorm_first", DRI_BOOL)) {
+ wsi->force_bgra8_unorm_first =
+ driQueryOptionb(dri_options, "vk_wsi_force_bgra8_unorm_first");
+ }
+ }
+
return VK_SUCCESS;
fail:
return result;
}
+static bool
+wsi_swapchain_is_present_mode_supported(struct wsi_device *wsi,
+ const VkSwapchainCreateInfoKHR *pCreateInfo,
+ VkPresentModeKHR mode)
+{
+ ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, pCreateInfo->surface);
+ struct wsi_interface *iface = wsi->wsi[surface->platform];
+ VkPresentModeKHR *present_modes;
+ uint32_t present_mode_count;
+ bool supported = false;
+ VkResult result;
+
+ result = iface->get_present_modes(surface, &present_mode_count, NULL);
+ if (result != VK_SUCCESS)
+ return supported;
+
+ present_modes = malloc(present_mode_count * sizeof(*present_modes));
+ if (!present_modes)
+ return supported;
+
+ result = iface->get_present_modes(surface, &present_mode_count,
+ present_modes);
+ if (result != VK_SUCCESS)
+ goto fail;
+
+ for (uint32_t i = 0; i < present_mode_count; i++) {
+ if (present_modes[i] == mode) {
+ supported = true;
+ break;
+ }
+ }
+
+fail:
+ free(present_modes);
+ return supported;
+}
+
+enum VkPresentModeKHR
+wsi_swapchain_get_present_mode(struct wsi_device *wsi,
+ const VkSwapchainCreateInfoKHR *pCreateInfo)
+{
+ if (wsi->override_present_mode == VK_PRESENT_MODE_MAX_ENUM_KHR)
+ return pCreateInfo->presentMode;
+
+ if (!wsi_swapchain_is_present_mode_supported(wsi, pCreateInfo,
+ wsi->override_present_mode)) {
+ fprintf(stderr, "Unsupported MESA_VK_WSI_PRESENT_MODE value!\n");
+ return pCreateInfo->presentMode;
+ }
+
+ return wsi->override_present_mode;
+}
+
void
wsi_swapchain_finish(struct wsi_swapchain *chain)
{
- for (unsigned i = 0; i < ARRAY_SIZE(chain->fences); i++)
- chain->wsi->DestroyFence(chain->device, chain->fences[i], &chain->alloc);
+ if (chain->fences) {
+ for (unsigned i = 0; i < chain->image_count; i++)
+ chain->wsi->DestroyFence(chain->device, chain->fences[i], &chain->alloc);
+
+ vk_free(&chain->alloc, chain->fences);
+ }
for (uint32_t i = 0; i < chain->wsi->queue_family_count; i++) {
chain->wsi->DestroyCommandPool(chain->device, chain->cmd_pools[i],
.pNext = NULL,
};
+ VkImageCreateInfo image_info = {
+ .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
+ .flags = 0,
+ .imageType = VK_IMAGE_TYPE_2D,
+ .format = pCreateInfo->imageFormat,
+ .extent = {
+ .width = pCreateInfo->imageExtent.width,
+ .height = pCreateInfo->imageExtent.height,
+ .depth = 1,
+ },
+ .mipLevels = 1,
+ .arrayLayers = 1,
+ .samples = VK_SAMPLE_COUNT_1_BIT,
+ .tiling = VK_IMAGE_TILING_OPTIMAL,
+ .usage = pCreateInfo->imageUsage,
+ .sharingMode = pCreateInfo->imageSharingMode,
+ .queueFamilyIndexCount = pCreateInfo->queueFamilyIndexCount,
+ .pQueueFamilyIndices = pCreateInfo->pQueueFamilyIndices,
+ .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
+ };
+
+ __vk_append_struct(&image_info, &image_wsi_info);
+
uint32_t image_modifier_count = 0, modifier_prop_count = 0;
struct wsi_format_modifier_properties *modifier_props = NULL;
uint64_t *image_modifiers = NULL;
.sType = VK_STRUCTURE_TYPE_WSI_FORMAT_MODIFIER_PROPERTIES_LIST_MESA,
.pNext = NULL,
};
- VkFormatProperties2KHR format_props = {
- .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2_KHR,
+ VkFormatProperties2 format_props = {
+ .sType = VK_STRUCTURE_TYPE_FORMAT_PROPERTIES_2,
.pNext = &modifier_props_list,
};
wsi->GetPhysicalDeviceFormatProperties2KHR(wsi->pdevice,
}
}
- const VkImageCreateInfo image_info = {
- .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
- .pNext = &image_wsi_info,
- .flags = 0,
- .imageType = VK_IMAGE_TYPE_2D,
- .format = pCreateInfo->imageFormat,
- .extent = {
- .width = pCreateInfo->imageExtent.width,
- .height = pCreateInfo->imageExtent.height,
- .depth = 1,
- },
- .mipLevels = 1,
- .arrayLayers = 1,
- .samples = VK_SAMPLE_COUNT_1_BIT,
- .tiling = VK_IMAGE_TILING_OPTIMAL,
- .usage = pCreateInfo->imageUsage,
- .sharingMode = pCreateInfo->imageSharingMode,
- .queueFamilyIndexCount = pCreateInfo->queueFamilyIndexCount,
- .pQueueFamilyIndices = pCreateInfo->pQueueFamilyIndices,
- .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
- };
result = wsi->CreateImage(chain->device, &image_info,
&chain->alloc, &image->image);
if (result != VK_SUCCESS)
.pNext = NULL,
.implicit_sync = true,
};
- const VkExportMemoryAllocateInfoKHR memory_export_info = {
- .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR,
+ const VkExportMemoryAllocateInfo memory_export_info = {
+ .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO,
.pNext = &memory_wsi_info,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
};
- const VkMemoryDedicatedAllocateInfoKHR memory_dedicated_info = {
- .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR,
+ const VkMemoryDedicatedAllocateInfo memory_dedicated_info = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
.pNext = &memory_export_info,
.image = image->image,
.buffer = VK_NULL_HANDLE,
for (uint32_t p = 0; p < image->num_planes; p++) {
const VkImageSubresource image_subresource = {
- .aspectMask = VK_IMAGE_ASPECT_PLANE_0_BIT_KHR << p,
+ .aspectMask = VK_IMAGE_ASPECT_PLANE_0_BIT << p,
.mipLevel = 0,
.arrayLayer = 0,
};
uint32_t linear_size = linear_stride * pCreateInfo->imageExtent.height;
linear_size = align_u32(linear_size, 4096);
- const VkExternalMemoryBufferCreateInfoKHR prime_buffer_external_info = {
- .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO_KHR,
+ const VkExternalMemoryBufferCreateInfo prime_buffer_external_info = {
+ .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO,
.pNext = NULL,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
};
.pNext = NULL,
.implicit_sync = true,
};
- const VkExportMemoryAllocateInfoKHR prime_memory_export_info = {
- .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR,
+ const VkExportMemoryAllocateInfo prime_memory_export_info = {
+ .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO,
.pNext = &memory_wsi_info,
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_DMA_BUF_BIT_EXT,
};
- const VkMemoryDedicatedAllocateInfoKHR prime_memory_dedicated_info = {
- .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR,
+ const VkMemoryDedicatedAllocateInfo prime_memory_dedicated_info = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
.pNext = &prime_memory_export_info,
.image = VK_NULL_HANDLE,
.buffer = image->prime.buffer,
wsi->GetImageMemoryRequirements(chain->device, image->image, &reqs);
- const VkMemoryDedicatedAllocateInfoKHR memory_dedicated_info = {
- .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR,
+ const VkMemoryDedicatedAllocateInfo memory_dedicated_info = {
+ .sType = VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO,
.pNext = NULL,
.image = image->image,
.buffer = VK_NULL_HANDLE,
.sType = VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR,
};
- VkResult result = iface->get_capabilities2(surface, NULL, &caps2);
+ VkResult result = iface->get_capabilities2(surface, wsi_device, NULL, &caps2);
if (result == VK_SUCCESS)
*pSurfaceCapabilities = caps2.surfaceCapabilities;
ICD_FROM_HANDLE(VkIcdSurfaceBase, surface, pSurfaceInfo->surface);
struct wsi_interface *iface = wsi_device->wsi[surface->platform];
- return iface->get_capabilities2(surface, pSurfaceInfo->pNext,
+ return iface->get_capabilities2(surface, wsi_device, pSurfaceInfo->pNext,
pSurfaceCapabilities);
}
.pNext = &counters,
};
- VkResult result = iface->get_capabilities2(surface, NULL, &caps2);
+ VkResult result = iface->get_capabilities2(surface, wsi_device, NULL, &caps2);
if (result == VK_SUCCESS) {
VkSurfaceCapabilities2EXT *ext_caps = pSurfaceCapabilities;
if (result != VK_SUCCESS)
return result;
+ swapchain->fences = vk_zalloc(pAllocator,
+ sizeof (*swapchain->fences) * swapchain->image_count,
+ sizeof (*swapchain->fences),
+ VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
+ if (!swapchain->fences) {
+ swapchain->destroy(swapchain, pAllocator);
+ return VK_ERROR_OUT_OF_HOST_MEMORY;
+ }
+
*pSwapchain = wsi_swapchain_to_handle(swapchain);
return VK_SUCCESS;
{
WSI_FROM_HANDLE(wsi_swapchain, swapchain, pAcquireInfo->swapchain);
- return swapchain->acquire_next_image(swapchain, pAcquireInfo, pImageIndex);
+ VkResult result = swapchain->acquire_next_image(swapchain, pAcquireInfo,
+ pImageIndex);
+ if (result != VK_SUCCESS)
+ return result;
+
+ if (pAcquireInfo->semaphore != VK_NULL_HANDLE &&
+ wsi->signal_semaphore_for_memory != NULL) {
+ struct wsi_image *image =
+ swapchain->get_wsi_image(swapchain, *pImageIndex);
+ wsi->signal_semaphore_for_memory(device, pAcquireInfo->semaphore,
+ image->memory);
+ }
+
+ if (pAcquireInfo->fence != VK_NULL_HANDLE &&
+ wsi->signal_fence_for_memory != NULL) {
+ struct wsi_image *image =
+ swapchain->get_wsi_image(swapchain, *pImageIndex);
+ wsi->signal_fence_for_memory(device, pAcquireInfo->fence,
+ image->memory);
+ }
+
+ return VK_SUCCESS;
}
VkResult
for (uint32_t i = 0; i < pPresentInfo->swapchainCount; i++) {
WSI_FROM_HANDLE(wsi_swapchain, swapchain, pPresentInfo->pSwapchains[i]);
+ uint32_t image_index = pPresentInfo->pImageIndices[i];
VkResult result;
- if (swapchain->fences[0] == VK_NULL_HANDLE) {
+ if (swapchain->fences[image_index] == VK_NULL_HANDLE) {
const VkFenceCreateInfo fence_info = {
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
.pNext = NULL,
};
result = wsi->CreateFence(device, &fence_info,
&swapchain->alloc,
- &swapchain->fences[0]);
+ &swapchain->fences[image_index]);
if (result != VK_SUCCESS)
goto fail_present;
} else {
- wsi->ResetFences(device, 1, &swapchain->fences[0]);
+ result =
+ wsi->WaitForFences(device, 1, &swapchain->fences[image_index],
+ true, ~0ull);
+ if (result != VK_SUCCESS)
+ goto fail_present;
+
+ result =
+ wsi->ResetFences(device, 1, &swapchain->fences[image_index]);
+ if (result != VK_SUCCESS)
+ goto fail_present;
}
+ struct wsi_image *image =
+ swapchain->get_wsi_image(swapchain, image_index);
+
+ struct wsi_memory_signal_submit_info mem_signal = {
+ .sType = VK_STRUCTURE_TYPE_WSI_MEMORY_SIGNAL_SUBMIT_INFO_MESA,
+ .pNext = NULL,
+ .memory = image->memory,
+ };
+
VkSubmitInfo submit_info = {
.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO,
- .pNext = NULL,
+ .pNext = &mem_signal,
};
VkPipelineStageFlags *stage_flags = NULL;
/* If we are using prime blits, we need to perform the blit now. The
* command buffer is attached to the image.
*/
- struct wsi_image *image =
- swapchain->get_wsi_image(swapchain, pPresentInfo->pImageIndices[i]);
submit_info.commandBufferCount = 1;
submit_info.pCommandBuffers =
&image->prime.blit_cmd_buffers[queue_family_index];
+ mem_signal.memory = image->prime.memory;
}
- result = wsi->QueueSubmit(queue, 1, &submit_info, swapchain->fences[0]);
+ result = wsi->QueueSubmit(queue, 1, &submit_info, swapchain->fences[image_index]);
vk_free(&swapchain->alloc, stage_flags);
if (result != VK_SUCCESS)
goto fail_present;
if (regions && regions->pRegions)
region = ®ions->pRegions[i];
- result = swapchain->queue_present(swapchain,
- pPresentInfo->pImageIndices[i],
- region);
+ result = swapchain->queue_present(swapchain, image_index, region);
if (result != VK_SUCCESS)
goto fail_present;
- VkFence last = swapchain->fences[2];
- swapchain->fences[2] = swapchain->fences[1];
- swapchain->fences[1] = swapchain->fences[0];
- swapchain->fences[0] = last;
-
- if (last != VK_NULL_HANDLE) {
- wsi->WaitForFences(device, 1, &last, true, 1);
- }
-
fail_present:
if (pPresentInfo->pResults != NULL)
pPresentInfo->pResults[i] = result;
return final_result;
}
+
+uint64_t
+wsi_common_get_current_time(void)
+{
+ struct timespec current;
+ clock_gettime(CLOCK_MONOTONIC, ¤t);
+ return current.tv_nsec + current.tv_sec * 1000000000ull;
+}