wined3d: Implement a copy-on-write scheme for whole buffer uploads.
commitc6b9aa7a7c44a97fccc5b5270e90786dfac1eb83
authorZebediah Figura <zfigura@codeweavers.com>
Tue, 18 Jul 2023 05:31:02 +0000 (18 00:31 -0500)
committerAlexandre Julliard <julliard@winehq.org>
Thu, 10 Aug 2023 00:53:17 +0000 (10 09:53 +0900)
treeac862fc1249dbb6273588fb936238e9a9bbbc92d
parentde7164910243c2114545d1c263c1bafa22b1bff3
wined3d: Implement a copy-on-write scheme for whole buffer uploads.

For discard maps on deferred contexts, we currently blit from the upload buffer
to the resource. This is necessary because command lists can be reused and
submitted multiple times—we cannot simply have the buffer take ownership, as for
discard maps on immediate contexts.

However, it is very common for applications to use command lists only once
before throwing them away—in essence taking advantage of the feature only for
the multithreading advantages it allows.

Therefore we take advantage of this pattern by trying to rename the buffer
anyway. In order to do this we introduce a refcount for BO pointers. When
writing to a buffer BO, we first check whether the buffer "owns" the BO—i.e.
whether it has a refcount of 1—and if not, we create a new BO for the buffer and
copy the contents of the old BO to the new BO. That is, we perform
mostly-transparent copy-on-write.

This improves performance, and reduces CPU usage, in Assassin's Creed: Unity.
dlls/wined3d/buffer.c
dlls/wined3d/context_gl.c
dlls/wined3d/context_vk.c
dlls/wined3d/cs.c
dlls/wined3d/device.c
dlls/wined3d/view.c
dlls/wined3d/wined3d_private.h