radv: clean up fence syncobj code

Since RADV requires DRM 3.35+, this code can be simplified.

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9953>
This commit is contained in:
Samuel Pitoiset 2021-03-31 15:43:06 +02:00 committed by Marge Bot
parent 4b0fc025f3
commit 9745a6f9a3
2 changed files with 18 additions and 112 deletions

View File

@ -4096,15 +4096,8 @@ static VkResult radv_alloc_sem_counts(struct radv_device *device,
} }
} }
if (_fence != VK_NULL_HANDLE) { if (_fence != VK_NULL_HANDLE)
RADV_FROM_HANDLE(radv_fence, fence, _fence); counts->syncobj_count++;
struct radv_fence_part *part =
fence->temporary.kind != RADV_FENCE_NONE ?
&fence->temporary : &fence->permanent;
if (part->kind == RADV_FENCE_SYNCOBJ)
counts->syncobj_count++;
}
if (counts->syncobj_count || counts->timeline_syncobj_count) { if (counts->syncobj_count || counts->timeline_syncobj_count) {
counts->points = (uint64_t *)malloc( counts->points = (uint64_t *)malloc(
@ -4159,8 +4152,7 @@ static VkResult radv_alloc_sem_counts(struct radv_device *device,
struct radv_fence_part *part = struct radv_fence_part *part =
fence->temporary.kind != RADV_FENCE_NONE ? fence->temporary.kind != RADV_FENCE_NONE ?
&fence->temporary : &fence->permanent; &fence->temporary : &fence->permanent;
if (part->kind == RADV_FENCE_SYNCOBJ) counts->syncobj[non_reset_idx++] = part->syncobj;
counts->syncobj[non_reset_idx++] = part->syncobj;
} }
assert(MAX2(syncobj_idx, non_reset_idx) <= counts->syncobj_count); assert(MAX2(syncobj_idx, non_reset_idx) <= counts->syncobj_count);
@ -5747,16 +5739,8 @@ static void
radv_destroy_fence_part(struct radv_device *device, radv_destroy_fence_part(struct radv_device *device,
struct radv_fence_part *part) struct radv_fence_part *part)
{ {
switch (part->kind) { if (part->kind != RADV_FENCE_NONE)
case RADV_FENCE_NONE:
break;
case RADV_FENCE_SYNCOBJ:
device->ws->destroy_syncobj(device->ws, part->syncobj); device->ws->destroy_syncobj(device->ws, part->syncobj);
break;
default:
unreachable("Invalid fence type");
}
part->kind = RADV_FENCE_NONE; part->kind = RADV_FENCE_NONE;
} }
@ -5822,20 +5806,6 @@ void radv_DestroyFence(
radv_destroy_fence(device, pAllocator, fence); radv_destroy_fence(device, pAllocator, fence);
} }
static bool radv_all_fences_syncobj(uint32_t fenceCount, const VkFence *pFences)
{
for (uint32_t i = 0; i < fenceCount; ++i) {
RADV_FROM_HANDLE(radv_fence, fence, pFences[i]);
struct radv_fence_part *part =
fence->temporary.kind != RADV_FENCE_NONE ?
&fence->temporary : &fence->permanent;
if (part->kind != RADV_FENCE_SYNCOBJ)
return false;
}
return true;
}
VkResult radv_WaitForFences( VkResult radv_WaitForFences(
VkDevice _device, VkDevice _device,
uint32_t fenceCount, uint32_t fenceCount,
@ -5844,44 +5814,16 @@ VkResult radv_WaitForFences(
uint64_t timeout) uint64_t timeout)
{ {
RADV_FROM_HANDLE(radv_device, device, _device); RADV_FROM_HANDLE(radv_device, device, _device);
uint32_t *handles;
if (radv_device_is_lost(device)) if (radv_device_is_lost(device))
return VK_ERROR_DEVICE_LOST; return VK_ERROR_DEVICE_LOST;
timeout = radv_get_absolute_timeout(timeout); timeout = radv_get_absolute_timeout(timeout);
if (radv_all_fences_syncobj(fenceCount, pFences)) handles = malloc(sizeof(uint32_t) * fenceCount);
{ if (!handles)
uint32_t *handles = malloc(sizeof(uint32_t) * fenceCount); return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
if (!handles)
return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
for (uint32_t i = 0; i < fenceCount; ++i) {
RADV_FROM_HANDLE(radv_fence, fence, pFences[i]);
struct radv_fence_part *part =
fence->temporary.kind != RADV_FENCE_NONE ?
&fence->temporary : &fence->permanent;
assert(part->kind == RADV_FENCE_SYNCOBJ);
handles[i] = part->syncobj;
}
bool success = device->ws->wait_syncobj(device->ws, handles, fenceCount, waitAll, timeout);
free(handles);
return success ? VK_SUCCESS : VK_TIMEOUT;
}
if (!waitAll && fenceCount > 1) {
while(radv_get_current_time() <= timeout) {
for (uint32_t i = 0; i < fenceCount; ++i) {
if (radv_GetFenceStatus(_device, pFences[i]) == VK_SUCCESS)
return VK_SUCCESS;
}
}
return VK_TIMEOUT;
}
for (uint32_t i = 0; i < fenceCount; ++i) { for (uint32_t i = 0; i < fenceCount; ++i) {
RADV_FROM_HANDLE(radv_fence, fence, pFences[i]); RADV_FROM_HANDLE(radv_fence, fence, pFences[i]);
@ -5890,21 +5832,13 @@ VkResult radv_WaitForFences(
fence->temporary.kind != RADV_FENCE_NONE ? fence->temporary.kind != RADV_FENCE_NONE ?
&fence->temporary : &fence->permanent; &fence->temporary : &fence->permanent;
switch (part->kind) { assert(part->kind == RADV_FENCE_SYNCOBJ);
case RADV_FENCE_NONE: handles[i] = part->syncobj;
break;
case RADV_FENCE_SYNCOBJ:
if (!device->ws->wait_syncobj(device->ws,
&part->syncobj, 1, true,
timeout))
return VK_TIMEOUT;
break;
default:
unreachable("Invalid fence type");
}
} }
return VK_SUCCESS; bool success = device->ws->wait_syncobj(device->ws, handles, fenceCount, waitAll, timeout);
free(handles);
return success ? VK_SUCCESS : VK_TIMEOUT;
} }
VkResult radv_ResetFences(VkDevice _device, VkResult radv_ResetFences(VkDevice _device,
@ -5927,15 +5861,7 @@ VkResult radv_ResetFences(VkDevice _device,
if (fence->temporary.kind != RADV_FENCE_NONE) if (fence->temporary.kind != RADV_FENCE_NONE)
radv_destroy_fence_part(device, &fence->temporary); radv_destroy_fence_part(device, &fence->temporary);
struct radv_fence_part *part = &fence->permanent; device->ws->reset_syncobj(device->ws, fence->permanent.syncobj);
switch (part->kind) {
case RADV_FENCE_SYNCOBJ:
device->ws->reset_syncobj(device->ws, part->syncobj);
break;
default:
unreachable("Invalid fence type");
}
} }
return VK_SUCCESS; return VK_SUCCESS;
@ -5953,21 +5879,9 @@ VkResult radv_GetFenceStatus(VkDevice _device, VkFence _fence)
if (radv_device_is_lost(device)) if (radv_device_is_lost(device))
return VK_ERROR_DEVICE_LOST; return VK_ERROR_DEVICE_LOST;
switch (part->kind) { bool success = device->ws->wait_syncobj(device->ws,
case RADV_FENCE_NONE: &part->syncobj, 1, true, 0);
break; return success ? VK_SUCCESS : VK_NOT_READY;
case RADV_FENCE_SYNCOBJ: {
bool success = device->ws->wait_syncobj(device->ws,
&part->syncobj, 1, true, 0);
if (!success)
return VK_NOT_READY;
break;
}
default:
unreachable("Invalid fence type");
}
return VK_SUCCESS;
} }

View File

@ -265,15 +265,7 @@ VkResult radv_AcquireNextImage2KHR(
fence->temporary.kind != RADV_FENCE_NONE ? fence->temporary.kind != RADV_FENCE_NONE ?
&fence->temporary : &fence->permanent; &fence->temporary : &fence->permanent;
switch (part->kind) { device->ws->signal_syncobj(device->ws, part->syncobj, 0);
case RADV_FENCE_NONE:
break;
case RADV_FENCE_SYNCOBJ:
device->ws->signal_syncobj(device->ws, part->syncobj, 0);
break;
default:
unreachable("Invalid WSI fence type");
}
} }
if (semaphore) { if (semaphore) {
struct radv_semaphore_part *part = struct radv_semaphore_part *part =