anv: make semaphore helper work on a single object

Should have done that last time.

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9045>
This commit is contained in:
Lionel Landwerlin
2021-03-12 19:34:31 +02:00
committed by Marge Bot
parent ad9d95eee4
commit 8d9102bde2

View File

@@ -886,145 +886,132 @@ maybe_transfer_temporary_semaphore(struct anv_queue_submit *submit,
} }
static VkResult static VkResult
anv_queue_submit_add_in_semaphores(struct anv_queue_submit *submit, anv_queue_submit_add_in_semaphore(struct anv_queue_submit *submit,
struct anv_device *device, struct anv_device *device,
const VkSemaphore *in_semaphores, const VkSemaphore _semaphore,
const uint64_t *in_values, const uint64_t value)
uint32_t num_in_semaphores)
{ {
ANV_FROM_HANDLE(anv_semaphore, semaphore, _semaphore);
struct anv_semaphore_impl *impl;
VkResult result; VkResult result;
for (uint32_t i = 0; i < num_in_semaphores; i++) { result = maybe_transfer_temporary_semaphore(submit, semaphore, &impl);
ANV_FROM_HANDLE(anv_semaphore, semaphore, in_semaphores[i]); if (result != VK_SUCCESS)
struct anv_semaphore_impl *impl; return result;
result = maybe_transfer_temporary_semaphore(submit, semaphore, &impl); switch (impl->type) {
case ANV_SEMAPHORE_TYPE_WSI_BO:
/* When using a window-system buffer as a semaphore, always enable
* EXEC_OBJECT_WRITE. This gives us a WaR hazard with the display or
* compositor's read of the buffer and enforces that we don't start
* rendering until they are finished. This is exactly the
* synchronization we want with vkAcquireNextImage.
*/
result = anv_queue_submit_add_fence_bo(submit, impl->bo, true /* signal */);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
return result; return result;
break;
switch (impl->type) { case ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ:
case ANV_SEMAPHORE_TYPE_WSI_BO: result = anv_queue_submit_add_syncobj(submit, device,
/* When using a window-system buffer as a semaphore, always enable impl->syncobj,
* EXEC_OBJECT_WRITE. This gives us a WaR hazard with the display or I915_EXEC_FENCE_WAIT,
* compositor's read of the buffer and enforces that we don't start 0);
* rendering until they are finished. This is exactly the if (result != VK_SUCCESS)
* synchronization we want with vkAcquireNextImage. return result;
*/ break;
result = anv_queue_submit_add_fence_bo(submit, impl->bo, true /* signal */);
if (result != VK_SUCCESS)
return result;
break;
case ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ: { case ANV_SEMAPHORE_TYPE_TIMELINE:
result = anv_queue_submit_add_syncobj(submit, device, if (value == 0)
impl->syncobj,
I915_EXEC_FENCE_WAIT,
0);
if (result != VK_SUCCESS)
return result;
break; break;
} result = anv_queue_submit_add_timeline_wait(submit, device,
&impl->timeline,
value);
if (result != VK_SUCCESS)
return result;
break;
case ANV_SEMAPHORE_TYPE_TIMELINE: case ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ_TIMELINE:
assert(in_values); if (value == 0)
if (in_values[i] == 0)
break;
result = anv_queue_submit_add_timeline_wait(submit, device,
&impl->timeline,
in_values[i]);
if (result != VK_SUCCESS)
return result;
break; break;
result = anv_queue_submit_add_syncobj(submit, device,
impl->syncobj,
I915_EXEC_FENCE_WAIT,
value);
if (result != VK_SUCCESS)
return result;
break;
case ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ_TIMELINE: default:
assert(in_values); break;
if (in_values[i] == 0)
break;
result = anv_queue_submit_add_syncobj(submit, device,
impl->syncobj,
I915_EXEC_FENCE_WAIT,
in_values[i]);
if (result != VK_SUCCESS)
return result;
break;
default:
break;
}
} }
return VK_SUCCESS; return VK_SUCCESS;
} }
static VkResult static VkResult
anv_queue_submit_add_out_semaphores(struct anv_queue_submit *submit, anv_queue_submit_add_out_semaphore(struct anv_queue_submit *submit,
struct anv_device *device, struct anv_device *device,
const VkSemaphore *out_semaphores, const VkSemaphore _semaphore,
const uint64_t *out_values, const uint64_t value)
uint32_t num_out_semaphores)
{ {
ANV_FROM_HANDLE(anv_semaphore, semaphore, _semaphore);
VkResult result; VkResult result;
for (uint32_t i = 0; i < num_out_semaphores; i++) { /* Under most circumstances, out fences won't be temporary. However, the
ANV_FROM_HANDLE(anv_semaphore, semaphore, out_semaphores[i]); * spec does allow it for opaque_fd. From the Vulkan 1.0.53 spec:
*
* "If the import is temporary, the implementation must restore the
* semaphore to its prior permanent state after submitting the next
* semaphore wait operation."
*
* The spec says nothing whatsoever about signal operations on temporarily
* imported semaphores so it appears they are allowed. There are also CTS
* tests that require this to work.
*/
struct anv_semaphore_impl *impl =
semaphore->temporary.type != ANV_SEMAPHORE_TYPE_NONE ?
&semaphore->temporary : &semaphore->permanent;
/* Under most circumstances, out fences won't be temporary. However, switch (impl->type) {
* the spec does allow it for opaque_fd. From the Vulkan 1.0.53 spec: case ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ: {
* /*
* "If the import is temporary, the implementation must restore the * Reset the content of the syncobj so it doesn't contain a previously
* semaphore to its prior permanent state after submitting the next * signaled dma-fence, until one is added by EXECBUFFER by the
* semaphore wait operation." * submission thread.
*
* The spec says nothing whatsoever about signal operations on
* temporarily imported semaphores so it appears they are allowed.
* There are also CTS tests that require this to work.
*/ */
struct anv_semaphore_impl *impl = anv_gem_syncobj_reset(device, impl->syncobj);
semaphore->temporary.type != ANV_SEMAPHORE_TYPE_NONE ?
&semaphore->temporary : &semaphore->permanent;
switch (impl->type) { result = anv_queue_submit_add_syncobj(submit, device, impl->syncobj,
case ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ: { I915_EXEC_FENCE_SIGNAL,
/* 0);
* Reset the content of the syncobj so it doesn't contain a if (result != VK_SUCCESS)
* previously signaled dma-fence, until one is added by EXECBUFFER by return result;
* the submission thread. break;
*/ }
anv_gem_syncobj_reset(device, impl->syncobj);
result = anv_queue_submit_add_syncobj(submit, device, impl->syncobj, case ANV_SEMAPHORE_TYPE_TIMELINE:
I915_EXEC_FENCE_SIGNAL, if (value == 0)
0);
if (result != VK_SUCCESS)
return result;
break; break;
} result = anv_queue_submit_add_timeline_signal(submit, device,
&impl->timeline,
value);
if (result != VK_SUCCESS)
return result;
break;
case ANV_SEMAPHORE_TYPE_TIMELINE: case ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ_TIMELINE:
assert(out_values); if (value == 0)
if (out_values[i] == 0)
break;
result = anv_queue_submit_add_timeline_signal(submit, device,
&impl->timeline,
out_values[i]);
if (result != VK_SUCCESS)
return result;
break; break;
result = anv_queue_submit_add_syncobj(submit, device, impl->syncobj,
I915_EXEC_FENCE_SIGNAL,
value);
if (result != VK_SUCCESS)
return result;
break;
case ANV_SEMAPHORE_TYPE_DRM_SYNCOBJ_TIMELINE: default:
assert(out_values); break;
if (out_values[i] == 0)
break;
result = anv_queue_submit_add_syncobj(submit, device, impl->syncobj,
I915_EXEC_FENCE_SIGNAL,
out_values[i]);
if (result != VK_SUCCESS)
return result;
break;
default:
break;
}
} }
return VK_SUCCESS; return VK_SUCCESS;
@@ -1279,13 +1266,14 @@ VkResult anv_QueueSubmit(
} }
/* Wait semaphores */ /* Wait semaphores */
result = anv_queue_submit_add_in_semaphores(submit, for (uint32_t j = 0; j < pSubmits[i].waitSemaphoreCount; j++) {
device, result = anv_queue_submit_add_in_semaphore(submit,
pSubmits[i].pWaitSemaphores, device,
wait_values, pSubmits[i].pWaitSemaphores[j],
pSubmits[i].waitSemaphoreCount); wait_values ? wait_values[j] : 0);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
goto out; goto out;
}
/* Command buffers */ /* Command buffers */
for (uint32_t j = 0; j < pSubmits[i].commandBufferCount; j++) { for (uint32_t j = 0; j < pSubmits[i].commandBufferCount; j++) {
@@ -1310,13 +1298,14 @@ VkResult anv_QueueSubmit(
} }
/* Signal semaphores */ /* Signal semaphores */
result = anv_queue_submit_add_out_semaphores(submit, for (uint32_t j = 0; j < pSubmits[i].signalSemaphoreCount; j++) {
device, result = anv_queue_submit_add_out_semaphore(submit,
pSubmits[i].pSignalSemaphores, device,
signal_values, pSubmits[i].pSignalSemaphores[j],
pSubmits[i].signalSemaphoreCount); signal_values ? signal_values[j] : 0);
if (result != VK_SUCCESS) if (result != VK_SUCCESS)
goto out; goto out;
}
/* WSI BO */ /* WSI BO */
if (wsi_signal_bo) { if (wsi_signal_bo) {