mirror of
https://gitlab.winehq.org/wine/vkd3d.git
synced 2025-04-13 05:43:18 -07:00
vkd3d: Update the descriptor next
index before getting a reference for writing.
Fixes a race condition where the descriptor is modified between getting its object and resetting the `next` index. The new object would never be written. While it is invalid for the app to write descriptors used by a command list which has been submitted to a queue, unused descriptors may be written. This change also supports writing descriptors in a worker thread.
This commit is contained in:
committed by
Alexandre Julliard
parent
21491d1bbb
commit
70962ae7d8
Notes:
Alexandre Julliard
2023-12-14 23:31:17 +01:00
Approved-by: Giovanni Mascellani (@giomasce) Approved-by: Henri Verbeet (@hverbeet) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/vkd3d/-/merge_requests/292
@@ -2632,20 +2632,18 @@ void d3d12_desc_flush_vk_heap_updates_locked(struct d3d12_descriptor_heap *descr
|
|||||||
for (; i != UINT_MAX; i = next)
|
for (; i != UINT_MAX; i = next)
|
||||||
{
|
{
|
||||||
src = &descriptors[i];
|
src = &descriptors[i];
|
||||||
next = (int)src->next >> 1;
|
next = vkd3d_atomic_exchange(&src->next, 0);
|
||||||
|
next = (int)next >> 1;
|
||||||
|
|
||||||
|
/* A race exists here between updating src->next and getting the current object. The best
|
||||||
|
* we can do is get the object last, which may result in a harmless rewrite later. */
|
||||||
u.object = d3d12_desc_get_object_ref(src, device);
|
u.object = d3d12_desc_get_object_ref(src, device);
|
||||||
|
|
||||||
if (!u.object)
|
if (!u.object)
|
||||||
{
|
|
||||||
vkd3d_atomic_exchange(&src->next, 0);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
writes.held_refs[writes.held_ref_count++] = u.object;
|
writes.held_refs[writes.held_ref_count++] = u.object;
|
||||||
d3d12_desc_write_vk_heap(descriptor_heap, i, &writes, u.object, device);
|
d3d12_desc_write_vk_heap(descriptor_heap, i, &writes, u.object, device);
|
||||||
|
|
||||||
vkd3d_atomic_exchange(&src->next, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Avoid thunk calls wherever possible. */
|
/* Avoid thunk calls wherever possible. */
|
||||||
|
Reference in New Issue
Block a user