turnip: Porting to common vulkan implementation for synchronization.

This patch ports to common code for VkSemaphore, VkFence and relevant
APIs like vkCreate(Destroy)Semaphore/Fence, vkGetSemaphoreFdKHR, etc.

Accordingly, starts using common vkQueueSubmit with implementing
driver-specific hook.

Also remove all timeline semaphore codes so that we could use common
code in the following patches. This way we could easily see what's
modified in the following patch.

Note that kgsl is not ported in this patch.

Signed-off-by: Hyunjun Ko <zzoon@igalia.com>
Reviewed-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14105>
This commit is contained in:
Hyunjun Ko 2022-01-12 02:11:13 +00:00 committed by Marge Bot
parent 58aa920706
commit 479a1c405e
6 changed files with 156 additions and 1135 deletions

View File

@ -159,7 +159,7 @@ get_device_extensions(const struct tu_physical_device *device,
.KHR_buffer_device_address = true,
.KHR_shader_integer_dot_product = true,
#ifndef TU_USE_KGSL
.KHR_timeline_semaphore = true,
.KHR_timeline_semaphore = false,
#endif
#ifdef VK_USE_PLATFORM_DISPLAY_KHR
/* This extension is supported by common code across drivers, but it is
@ -562,7 +562,7 @@ tu_get_physical_device_features_1_2(struct tu_physical_device *pdevice,
features->shaderSubgroupExtendedTypes = true;
features->separateDepthStencilLayouts = true;
features->hostQueryReset = true;
features->timelineSemaphore = true;
features->timelineSemaphore = false;
features->bufferDeviceAddress = true;
features->bufferDeviceAddressCaptureReplay = false;
features->bufferDeviceAddressMultiDevice = false;
@ -757,7 +757,7 @@ tu_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice,
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES: {
VkPhysicalDeviceTimelineSemaphoreFeaturesKHR *features =
(VkPhysicalDeviceTimelineSemaphoreFeaturesKHR *) ext;
features->timelineSemaphore = true;
features->timelineSemaphore = false;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT: {
@ -1328,8 +1328,9 @@ tu_queue_init(struct tu_device *device,
return result;
queue->device = device;
list_inithead(&queue->queued_submits);
#ifndef TU_USE_KGSL
queue->vk.driver_submit = tu_queue_submit;
#endif
int ret = tu_drm_submitqueue_new(device, 0, &queue->msm_queue_id);
if (ret)
@ -1573,6 +1574,10 @@ tu_CreateDevice(VkPhysicalDevice physicalDevice,
mtx_init(&device->bo_mutex, mtx_plain);
pthread_mutex_init(&device->submit_mutex, NULL);
#ifndef TU_USE_KGSL
vk_device_set_drm_fd(&device->vk, device->fd);
#endif
for (unsigned i = 0; i < pCreateInfo->queueCreateInfoCount; i++) {
const VkDeviceQueueCreateInfo *queue_create =
&pCreateInfo->pQueueCreateInfos[i];
@ -1871,6 +1876,8 @@ tu_EnumerateInstanceLayerProperties(uint32_t *pPropertyCount,
return VK_SUCCESS;
}
/* Only used for kgsl since drm started using common implementation */
#ifdef TU_USE_KGSL
VKAPI_ATTR VkResult VKAPI_CALL
tu_QueueWaitIdle(VkQueue _queue)
{
@ -1882,20 +1889,6 @@ tu_QueueWaitIdle(VkQueue _queue)
if (queue->fence < 0)
return VK_SUCCESS;
pthread_mutex_lock(&queue->device->submit_mutex);
do {
tu_device_submit_deferred_locked(queue->device);
if (list_is_empty(&queue->queued_submits))
break;
pthread_cond_wait(&queue->device->timeline_cond,
&queue->device->submit_mutex);
} while (!list_is_empty(&queue->queued_submits));
pthread_mutex_unlock(&queue->device->submit_mutex);
struct pollfd fds = { .fd = queue->fence, .events = POLLIN };
int ret;
do {
@ -1909,6 +1902,7 @@ tu_QueueWaitIdle(VkQueue _queue)
queue->fence = -1;
return VK_SUCCESS;
}
#endif
VKAPI_ATTR VkResult VKAPI_CALL
tu_EnumerateInstanceExtensionProperties(const char *pLayerName,

File diff suppressed because it is too large Load Diff

View File

@ -635,27 +635,20 @@ tu_GetFenceStatus(VkDevice _device, VkFence _fence)
}
int
tu_signal_fences(struct tu_device *device, struct tu_syncobj *fence1, struct tu_syncobj *fence2)
tu_signal_syncs(struct tu_device *device,
struct vk_sync *sync1, struct vk_sync *sync2)
{
tu_finishme("tu_signal_fences");
tu_finishme("tu_signal_syncs");
return 0;
}
int
tu_syncobj_to_fd(struct tu_device *device, struct tu_syncobj *sync)
tu_syncobj_to_fd(struct tu_device *device, struct vk_sync *sync)
{
tu_finishme("tu_syncobj_to_fd");
return -1;
}
VkResult
tu_device_submit_deferred_locked(struct tu_device *dev)
{
tu_finishme("tu_device_submit_deferred_locked");
return VK_SUCCESS;
}
VkResult
tu_device_wait_u_trace(struct tu_device *dev, struct tu_u_trace_syncobj *syncobj)
{

View File

@ -97,6 +97,11 @@ typedef uint32_t xcb_window_t;
#include "vk_image.h"
#include "vk_command_buffer.h"
#include "vk_queue.h"
#include "vk_object.h"
#include "vk_sync.h"
#include "vk_fence.h"
#include "vk_semaphore.h"
#include "vk_drm_syncobj.h"
#define MAX_VBS 32
#define MAX_VERTEX_ATTRIBS 32
@ -225,6 +230,9 @@ struct tu_physical_device
struct disk_cache *disk_cache;
struct tu_memory_heap heap;
struct vk_sync_type syncobj_type;
const struct vk_sync_type *sync_types[3];
};
enum tu_debug_flags
@ -298,7 +306,10 @@ struct tu_pipeline_key
#define TU_MAX_QUEUE_FAMILIES 1
/* Keep tu_syncobj until porting to common code for kgsl too */
#ifdef TU_USE_KGSL
struct tu_syncobj;
#endif
struct tu_u_trace_syncobj;
struct tu_queue
@ -309,9 +320,6 @@ struct tu_queue
uint32_t msm_queue_id;
int fence;
/* Queue containing deferred submits */
struct list_head queued_submits;
};
struct tu_bo
@ -1707,11 +1715,13 @@ void
tu_drm_submitqueue_close(const struct tu_device *dev, uint32_t queue_id);
int
tu_signal_fences(struct tu_device *device, struct tu_syncobj *fence1, struct tu_syncobj *fence2);
tu_signal_syncs(struct tu_device *device, struct vk_sync *sync1, struct vk_sync *sync2);
int
tu_syncobj_to_fd(struct tu_device *device, struct tu_syncobj *sync);
tu_syncobj_to_fd(struct tu_device *device, struct vk_sync *sync);
VkResult
tu_queue_submit(struct vk_queue *vk_queue, struct vk_queue_submit *submit);
void
tu_copy_timestamp_buffer(struct u_trace_context *utctx, void *cmdstream,

View File

@ -71,8 +71,8 @@ tu_AcquireNextImage2KHR(VkDevice _device,
uint32_t *pImageIndex)
{
TU_FROM_HANDLE(tu_device, device, _device);
TU_FROM_HANDLE(tu_syncobj, fence, pAcquireInfo->fence);
TU_FROM_HANDLE(tu_syncobj, semaphore, pAcquireInfo->semaphore);
VK_FROM_HANDLE(vk_fence, fence, pAcquireInfo->fence);
VK_FROM_HANDLE(vk_semaphore, semaphore, pAcquireInfo->semaphore);
struct tu_physical_device *pdevice = device->physical_device;
@ -80,7 +80,9 @@ tu_AcquireNextImage2KHR(VkDevice _device,
&pdevice->wsi_device, _device, pAcquireInfo, pImageIndex);
/* signal fence/semaphore - image is available immediately */
tu_signal_fences(device, fence, semaphore);
tu_signal_syncs(device,
fence ? vk_fence_get_active_sync(fence) : NULL,
semaphore ? vk_semaphore_get_active_sync(semaphore) : NULL);
return result;
}

View File

@ -33,6 +33,7 @@
#include "vk_format.h"
#include "util/debug.h"
#include "wsi_common_display.h"
#include "vulkan/runtime/vk_common_entrypoints.h"
/* VK_EXT_display_control */
@ -46,13 +47,13 @@ tu_RegisterDeviceEventEXT(VkDevice _device,
VkResult ret;
VkFence _fence;
ret = tu_CreateFence(_device, &(VkFenceCreateInfo) {}, allocator, &_fence);
ret = vk_common_CreateFence(_device, &(VkFenceCreateInfo) {}, allocator, &_fence);
if (ret != VK_SUCCESS)
return ret;
TU_FROM_HANDLE(tu_syncobj, fence, _fence);
VK_FROM_HANDLE(vk_fence, fence, _fence);
int sync_fd = tu_syncobj_to_fd(device, fence);
int sync_fd = tu_syncobj_to_fd(device, vk_fence_get_active_sync(fence));
if (sync_fd >= 0) {
ret = wsi_register_device_event(_device,
&device->physical_device->wsi_device,
@ -67,7 +68,7 @@ tu_RegisterDeviceEventEXT(VkDevice _device,
}
if (ret != VK_SUCCESS)
tu_DestroyFence(_device, _fence, allocator);
vk_common_DestroyFence(_device, _fence, allocator);
else
*out_fence = _fence;
@ -84,13 +85,14 @@ tu_RegisterDisplayEventEXT(VkDevice _device,
TU_FROM_HANDLE(tu_device, device, _device);
VkResult ret;
ret = tu_CreateFence(_device, &(VkFenceCreateInfo) {}, allocator, _fence);
ret = vk_common_CreateFence(_device, &(VkFenceCreateInfo) {}, allocator, _fence);
if (ret != VK_SUCCESS)
return ret;
TU_FROM_HANDLE(tu_syncobj, fence, *_fence);
VK_FROM_HANDLE(vk_fence, fence, *_fence);
int sync_fd = tu_syncobj_to_fd(device, vk_fence_get_active_sync(fence));
int sync_fd = tu_syncobj_to_fd(device, fence);
if (sync_fd >= 0) {
ret = wsi_register_display_event(_device,
&device->physical_device->wsi_device,
@ -106,7 +108,7 @@ tu_RegisterDisplayEventEXT(VkDevice _device,
}
if (ret != VK_SUCCESS)
tu_DestroyFence(_device, *_fence, allocator);
vk_common_DestroyFence(_device, *_fence, allocator);
return ret;
}