diff options
-rw-r--r-- | .SRCINFO | 16 | ||||
-rw-r--r-- | 0001-wined3d-Initial-implementation-of-a-persistent-mappe.patch | 806 | ||||
-rw-r--r-- | 0002-wined3d-Add-support-for-backing-dynamic-wined3d_buff.patch | 682 | ||||
-rw-r--r-- | 0003-wined3d-Use-ARB_multi_bind-to-speed-up-UBO-updates.patch | 121 | ||||
-rw-r--r-- | 0004-wined3d-Use-GL_CLIENT_STORAGE_BIT-for-persistent-map.patch | 26 | ||||
-rw-r--r-- | 0005-wined3d-Experimental-support-for-persistent-buffer-t.patch | 180 | ||||
-rw-r--r-- | PKGBUILD | 28 |
7 files changed, 15 insertions, 1844 deletions
@@ -1,7 +1,7 @@ pkgbase = wine-staging-pba - pkgdesc = A compatibility layer for running Windows programs - Staging branch + pkgdesc = A compatibility layer for running Windows programs - Staging branch with PBA patches pkgver = 3.3 - pkgrel = 1 + pkgrel = 2 url = http://www.wine-staging.com install = wine.install arch = x86_64 @@ -147,11 +147,7 @@ pkgbase = wine-staging-pba source = harmony-fix.diff source = 30-win32-aliases.conf source = wine-binfmt.conf - source = 0001-wined3d-Initial-implementation-of-a-persistent-mappe.patch - source = 0002-wined3d-Add-support-for-backing-dynamic-wined3d_buff.patch - source = 0003-wined3d-Use-ARB_multi_bind-to-speed-up-UBO-updates.patch - source = 0004-wined3d-Use-GL_CLIENT_STORAGE_BIT-for-persistent-map.patch - source = 0005-wined3d-Experimental-support-for-persistent-buffer-t.patch + source = pba-patches::git+https://github.com/acomminos/wine-pba.git validpgpkeys = 5AC1A08B03BD7A313E0A955AF5E6E9EEB9461DD7 validpgpkeys = DA23579A74D4AD9AF9D3F945CEFAC8EAAF17519D sha512sums = c9e4c75e94d745837208bf877b19c4e4e46df1e78082d21e716f52c9f9d93eaabbec8bf34783cda68e4275f53e37929b81ac128e5b8a13c1e5035223b2621d6a @@ -160,11 +156,7 @@ pkgbase = wine-staging-pba sha512sums = b86edf07bfc560f403fdfd5a71f97930ee2a4c3f76c92cc1a0dbb2e107be9db3bed3a727a0430d8a049583c63dd11f5d4567fb7aa69b193997c6da241acc4f2e sha512sums = 6e54ece7ec7022b3c9d94ad64bdf1017338da16c618966e8baf398e6f18f80f7b0576edf1d1da47ed77b96d577e4cbb2bb0156b0b11c183a0accf22654b0a2bb sha512sums = bdde7ae015d8a98ba55e84b86dc05aca1d4f8de85be7e4bd6187054bfe4ac83b5a20538945b63fb073caab78022141e9545685e4e3698c97ff173cf30859e285 - sha512sums = b68f09aa0688ba52e40dd9a22c99699d28b3e1a7028d1c39e5705cad345e17535d9b1066babf6881668be23ab43ca7ed0203aa5a287ed343ec4383b58358f6ab - sha512sums = e7a1ab3ea00dc257de3dfdeab61df4dcd1ba3b448d3d323a5c7fed7da0b9a0ddb0b00eb6bc3f72b1fc1b10c61e181e8fe4f413a64b59d740371b2852686ce0c8 - sha512sums = 643b7575bd3e5a080c98e4435747942d39a072a662d26aefacec512263889dfda1fa154b77c6323d0cb69b5cab357258906cf17ad5013af09eda3d255706b5fe - sha512sums = 095ad54ea35f2e8317ab42a24fb92cbc214c6c3b53be165a6ddec9ef31f97b989befac4a3b51a1fcfbf5ead11b0ab3ca57ac34ad41621e81fdaa96aed17815cb - sha512sums = a58ae6201bfab1ddbda4d789054ce384434d4eb5e3d5845e995caa81b41c2814bb625216ce09c0e4bae92e3e6a45771d28ee4ef09b7c587cd56ec17d577a37a8 + sha512sums = SKIP pkgname = wine-staging-pba diff --git a/0001-wined3d-Initial-implementation-of-a-persistent-mappe.patch b/0001-wined3d-Initial-implementation-of-a-persistent-mappe.patch deleted file mode 100644 index 365dd861d14f..000000000000 --- a/0001-wined3d-Initial-implementation-of-a-persistent-mappe.patch +++ /dev/null @@ -1,806 +0,0 @@ -From 1f69076549bf2351eb6d8d885b35a46b4dc69813 Mon Sep 17 00:00:00 2001 -From: Andrew Comminos <andrew@comminos.com> -Date: Mon, 5 Mar 2018 15:38:35 -0800 -Subject: [PATCH 1/5] wined3d: Initial implementation of a persistent mapped - buffer allocator. - ---- - dlls/wined3d-csmt/Makefile.in | 1 + - dlls/wined3d/Makefile.in | 1 + - dlls/wined3d/buffer_heap.c | 508 +++++++++++++++++++++++++++++++++++++++++ - dlls/wined3d/cs.c | 9 + - dlls/wined3d/device.c | 52 +++++ - dlls/wined3d/directx.c | 3 + - dlls/wined3d/query.c | 2 +- - dlls/wined3d/wined3d_gl.h | 1 + - dlls/wined3d/wined3d_private.h | 68 +++++- - 9 files changed, 641 insertions(+), 4 deletions(-) - create mode 100644 dlls/wined3d/buffer_heap.c - -diff --git a/dlls/wined3d-csmt/Makefile.in b/dlls/wined3d-csmt/Makefile.in -index 1d0458eb46..cb3a5484c6 100644 ---- a/dlls/wined3d-csmt/Makefile.in -+++ b/dlls/wined3d-csmt/Makefile.in -@@ -8,6 +8,7 @@ C_SRCS = \ - arb_program_shader.c \ - ati_fragment_shader.c \ - buffer.c \ -+ buffer_heap.c \ - context.c \ - cs.c \ - device.c \ -diff --git a/dlls/wined3d/Makefile.in b/dlls/wined3d/Makefile.in -index b850ba6872..52ef8666fb 100644 ---- a/dlls/wined3d/Makefile.in -+++ b/dlls/wined3d/Makefile.in -@@ -6,6 +6,7 @@ C_SRCS = \ - arb_program_shader.c \ - ati_fragment_shader.c \ - buffer.c \ -+ buffer_heap.c \ - context.c \ - cs.c \ - device.c \ -diff --git a/dlls/wined3d/buffer_heap.c b/dlls/wined3d/buffer_heap.c -new file mode 100644 -index 0000000000..b133bd6893 ---- /dev/null -+++ b/dlls/wined3d/buffer_heap.c -@@ -0,0 +1,508 @@ -+/* -+ * Copyright 2018 Andrew Comminos -+ * -+ * This library is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU Lesser General Public -+ * License as published by the Free Software Foundation; either -+ * version 2.1 of the License, or (at your option) any later version. -+ * -+ * This library is distributed in the hope that it will be useful, -+ * but WITHOUT ANY WARRANTY; without even the implied warranty of -+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -+ * Lesser General Public License for more details. -+ * -+ * You should have received a copy of the GNU Lesser General Public -+ * License along with this library; if not, write to the Free Software -+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA -+ * -+ */ -+ -+#include "config.h" -+#include "wine/port.h" -+#include "wine/rbtree.h" -+#include "wined3d_private.h" -+ -+WINE_DEFAULT_DEBUG_CHANNEL(d3d); -+WINE_DECLARE_DEBUG_CHANNEL(d3d_perf); -+ -+struct wined3d_buffer_heap_element -+{ -+ struct wined3d_map_range range; -+ -+ // rbtree data -+ struct wine_rb_entry entry; -+ -+ // Binned free list positions -+ struct wined3d_buffer_heap_element *next; -+ struct wined3d_buffer_heap_element *prev; -+}; -+ -+struct wined3d_buffer_heap_fenced_element -+{ -+ struct wined3d_buffer_heap_bin_set free_list; -+ struct wined3d_fence *fence; -+ -+ struct wined3d_buffer_heap_fenced_element *next; -+}; -+ -+static struct wined3d_buffer_heap_element* element_new(GLsizei offset, GLsizei size) -+{ -+ struct wined3d_buffer_heap_element* elem; -+ elem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wined3d_buffer_heap_element)); -+ if (!elem) -+ return NULL; -+ elem->range.offset = offset; -+ elem->range.size = size; -+ return elem; -+} -+ -+static inline int bitwise_log2_floor(GLsizei size) -+{ -+ // XXX(acomminos): I hope this gets unrolled. -+ for (int i = 8 * sizeof(GLsizei) - 1; i >= 0; i--) -+ { -+ if ((size >> i) & 1) { -+ return i; -+ } -+ } -+ return 0; -+} -+ -+static inline int bitwise_log2_ceil(GLsizei size) -+{ -+ // Add one to the floor of size if size isn't a power of two. -+ return bitwise_log2_floor(size) + !!(size & (size - 1)); -+} -+ -+static int element_bin(struct wined3d_buffer_heap_element *elem) -+{ -+ return min(WINED3D_BUFFER_HEAP_BINS - 1, bitwise_log2_floor(elem->range.size)); -+} -+ -+// Inserts an element into the appropriate free list bin. -+static void element_insert_free_bin(struct wined3d_buffer_heap *heap, struct wined3d_buffer_heap_element *elem) -+{ -+ int bin = element_bin(elem); -+ -+ elem->prev = NULL; -+ elem->next = heap->free_list.bins[bin].head; -+ if (heap->free_list.bins[bin].head) -+ heap->free_list.bins[bin].head->prev = elem; -+ heap->free_list.bins[bin].head = elem; -+ -+ if (!heap->free_list.bins[bin].tail) -+ heap->free_list.bins[bin].tail = elem; -+ -+ TRACE("Inserted allocation at %p of size %lld into bin %d\n", elem->range.offset, elem->range.size, bin); -+} -+ -+// Removes an element from the free tree, its bin, and the coalesce list. -+static void element_remove_free(struct wined3d_buffer_heap *heap, struct wined3d_buffer_heap_element *elem) -+{ -+ int bin = element_bin(elem); -+ -+ if (elem->prev) -+ elem->prev->next = elem->next; -+ -+ if (elem->next) -+ elem->next->prev = elem->prev; -+ -+ if (elem == heap->free_list.bins[bin].head) -+ heap->free_list.bins[bin].head = elem->next; -+ -+ if (elem == heap->free_list.bins[bin].tail) -+ heap->free_list.bins[bin].tail = elem->prev; -+ -+ elem->prev = NULL; -+ elem->next = NULL; -+ -+ TRACE("Freed allocation at %p of size %lld from bin %d\n", elem->range.offset, elem->range.size, bin); -+} -+ -+static struct wined3d_buffer_heap_fenced_element* fenced_element_new(struct wined3d_buffer_heap_bin_set bins, struct wined3d_fence* fence) -+{ -+ struct wined3d_buffer_heap_fenced_element* elem; -+ elem = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct wined3d_buffer_heap_fenced_element)); -+ if (!elem) -+ return NULL; -+ elem->free_list = bins; -+ elem->fence = fence; -+ elem->next = NULL; -+ return elem; -+} -+ -+static int free_tree_compare(const void *key, const struct wine_rb_entry *entry) -+{ -+ const GLsizei offset = *(const GLsizei*) key; -+ struct wined3d_buffer_heap_element *elem = WINE_RB_ENTRY_VALUE(entry, struct wined3d_buffer_heap_element, entry); -+ -+ if (offset < elem->range.offset) -+ return -1; -+ if (offset > elem->range.offset) -+ return 1; -+ return 0; -+} -+ -+/* Context activation is done by the caller. */ -+HRESULT wined3d_buffer_heap_create(struct wined3d_context *context, GLsizeiptr size, GLsizeiptr alignment, BOOL write_only, struct wined3d_buffer_heap **buffer_heap) -+{ -+ const struct wined3d_gl_info *gl_info = context->gl_info; -+ const GLenum buffer_target = GL_ARRAY_BUFFER; -+ GLbitfield access_flags; -+ GLbitfield storage_flags; -+ struct wined3d_buffer_heap_element *initial_elem; -+ -+ struct wined3d_buffer_heap *object; -+ -+ if ((alignment & (alignment - 1)) != 0) -+ { -+ return E_FAIL; -+ } -+ -+ if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)))) -+ { -+ return E_OUTOFMEMORY; -+ } -+ -+ access_flags = GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT | GL_MAP_WRITE_BIT; -+ if (!write_only) -+ { -+ access_flags |= GL_MAP_READ_BIT; -+ } -+ storage_flags = access_flags; -+ -+ // TODO(acomminos): where should we be checking for errors here? -+ GL_EXTCALL(glGenBuffers(1, &object->buffer_object)); -+ -+ context_bind_bo(context, buffer_target, object->buffer_object); -+ -+ // TODO(acomminos): assert glBufferStorage supported? -+ GL_EXTCALL(glBufferStorage(buffer_target, size, NULL, storage_flags)); -+ -+ if (!(object->map_ptr = GL_EXTCALL(glMapBufferRange(buffer_target, 0, size, access_flags)))) -+ { -+ ERR("Couldn't map persistent buffer.\n"); -+ return -1; // FIXME(acomminos): proper error code, cleanup -+ } -+ context_bind_bo(context, buffer_target, 0); -+ -+ object->fenced_head = object->fenced_tail = NULL; -+ object->alignment = alignment; -+ InitializeCriticalSection(&object->temp_lock); -+ -+ initial_elem = element_new(0, size); -+ // Don't bother adding the initial allocation to the coalescing tree. -+ element_insert_free_bin(object, initial_elem); -+ -+ *buffer_heap = object; -+ -+ return WINED3D_OK; -+} -+ -+/* Context activation is done by the caller. */ -+HRESULT wined3d_buffer_heap_destroy(struct wined3d_buffer_heap *heap, struct wined3d_context *context) -+{ -+ FIXME("Unimplemented, leaking buffer"); -+ return WINED3D_OK; -+} -+ -+HRESULT wined3d_buffer_heap_alloc(struct wined3d_buffer_heap *heap, GLsizeiptr size, struct wined3d_map_range *out_range) -+{ -+ int initial_bin; -+ int initial_size = size; -+ -+ EnterCriticalSection(&heap->temp_lock); -+ -+ // After alignment, reduce fragmentation by rounding to next power of two. -+ // If the alignment is a power of two (which it should be), this should be -+ // no problem. -+ size = 1 << bitwise_log2_ceil(size); -+ -+ // Align size values where possible. -+ if (heap->alignment && (size % heap->alignment != 0)) -+ size += heap->alignment - (size % heap->alignment); -+ -+ initial_bin = min(WINED3D_BUFFER_HEAP_BINS - 1, bitwise_log2_ceil(size)); -+ -+ for (int i = initial_bin; i < WINED3D_BUFFER_HEAP_BINS; i++) -+ { -+ struct wined3d_buffer_heap_element *elem = heap->free_list.bins[i].head; -+ if (elem) -+ { -+ struct wined3d_map_range remaining_range; -+ remaining_range.offset = elem->range.offset + size; -+ remaining_range.size = elem->range.size - size; -+ -+ out_range->offset = elem->range.offset; -+ out_range->size = size; -+ -+ TRACE_(d3d_perf)("Allocated %d (requested %d) at %p from bin %d (initial %d)\n", size, initial_size, elem->range.offset, i, initial_bin); -+ -+ // Remove the element from its current free bin to move it to the correct list. -+ element_remove_free(heap, elem); -+ -+ if (remaining_range.size > 0) -+ { -+ TRACE_(d3d_perf)("Imperfect fit allocated, fragmenting remainder of %lld at %p.\n", remaining_range.size, remaining_range.offset); -+ -+ elem->range = remaining_range; -+ element_insert_free_bin(heap, elem); -+ } -+ else -+ { -+ HeapFree(GetProcessHeap(), 0, elem); -+ } -+ -+ LeaveCriticalSection(&heap->temp_lock); -+ return WINED3D_OK; -+ } -+ } -+ -+ LeaveCriticalSection(&heap->temp_lock); -+ -+ FIXME_(d3d_perf)("Forcing coalesce, not enough free space in buffer heap.\n"); -+ int num_coalesced; -+ if (SUCCEEDED(wined3d_buffer_heap_deferred_coalesce(heap, &num_coalesced))) -+ { -+ if (num_coalesced > 0) -+ return wined3d_buffer_heap_alloc(heap, size, out_range); -+ } -+ -+ FIXME_(d3d_perf)("Coalescing did not create new blocks, failing.\n"); -+ -+ return WINED3DERR_OUTOFVIDEOMEMORY; -+} -+ -+HRESULT wined3d_buffer_heap_free(struct wined3d_buffer_heap *heap, struct wined3d_map_range range) -+{ -+ struct wined3d_buffer_heap_element *elem = element_new(range.offset, range.size); -+ -+ if (!elem) -+ return E_OUTOFMEMORY; -+ -+ EnterCriticalSection(&heap->temp_lock); -+ -+ // Only insert the element into a free bin, coalescing will occur later. -+ element_insert_free_bin(heap, elem); -+ -+ LeaveCriticalSection(&heap->temp_lock); -+ -+ return WINED3D_OK; -+} -+ -+HRESULT wined3d_buffer_heap_free_fenced(struct wined3d_buffer_heap *heap, struct wined3d_device *device, struct wined3d_map_range range) -+{ -+ struct wined3d_buffer_heap_element *elem = element_new(range.offset, range.size); -+ int bin_index = element_bin(elem); -+ struct wined3d_buffer_heap_bin *bin = &heap->pending_fenced_bins.bins[bin_index]; -+ -+ if (bin->tail) -+ { -+ bin->tail->next = elem; -+ elem->prev = bin->tail; -+ bin->tail = elem; -+ } -+ else -+ { -+ bin->head = elem; -+ bin->tail = elem; -+ } -+ -+ return WINED3D_OK; -+} -+ -+HRESULT wined3d_buffer_heap_cs_fence_issue(struct wined3d_buffer_heap *heap, struct wined3d_device *device) -+{ -+ struct wined3d_buffer_heap_fenced_element *fenced_elem; -+ struct wined3d_fence *fence; -+ HRESULT hr; -+ -+ if (heap->fenced_head) -+ { -+ // XXX(acomminos): double or triple buffer this? -+ wined3d_buffer_heap_cs_fence_wait(heap, device); -+ } -+ -+ if (FAILED(hr = wined3d_fence_create(device, &fence))) -+ { -+ ERR("Failed to create fence.\n"); -+ return hr; -+ } -+ -+ fenced_elem = fenced_element_new(heap->pending_fenced_bins, fence); -+ if (!fenced_elem) -+ return E_OUTOFMEMORY; -+ -+ TRACE_(d3d_perf)("Dispatching fenced buffer set.\n"); -+ memset(&heap->pending_fenced_bins, 0, sizeof(heap->pending_fenced_bins)); -+ -+ // Append to end of fenced list, which works well if you assume that buffers -+ // are freed in some ascending draw call ordering. -+ if (!heap->fenced_head) -+ { -+ heap->fenced_head = fenced_elem; -+ heap->fenced_tail = fenced_elem; -+ } -+ else -+ { -+ heap->fenced_tail->next = fenced_elem; -+ heap->fenced_tail = fenced_elem; -+ } -+ -+ wined3d_fence_issue(fence, device); -+ return WINED3D_OK; -+} -+ -+HRESULT wined3d_buffer_heap_cs_fence_wait(struct wined3d_buffer_heap *heap, struct wined3d_device *device) -+{ -+ enum wined3d_fence_result res; -+ struct wined3d_buffer_heap_fenced_element *elem = heap->fenced_head; -+ if (!elem) -+ return WINED3D_OK; -+ -+ res = wined3d_fence_wait(elem->fence, device); -+ switch (res) -+ { -+ case WINED3D_FENCE_OK: -+ case WINED3D_FENCE_NOT_STARTED: -+ { -+ TRACE_(d3d_perf)("Freed fence group.\n"); -+ -+ EnterCriticalSection(&heap->temp_lock); -+ for (int i = 0; i < WINED3D_BUFFER_HEAP_BINS; i++) -+ { -+ struct wined3d_buffer_heap_bin *elem_bin = &elem->free_list.bins[i]; -+ if (!elem_bin->tail) -+ continue; -+ -+ struct wined3d_buffer_heap_bin *heap_bin = &heap->free_list.bins[i]; -+ if (heap_bin->head) -+ { -+ // Insert to front. -+ elem_bin->tail->next = heap_bin->head; -+ heap_bin->head->prev = elem_bin->tail; -+ -+ elem_bin->head->prev = NULL; -+ heap_bin->head = elem_bin->head; -+ } -+ else -+ { -+ elem_bin->head->prev = NULL; -+ heap_bin->head = elem_bin->head; -+ elem_bin->tail->next = NULL; -+ heap_bin->tail = elem_bin->tail; -+ } -+ } -+ LeaveCriticalSection(&heap->temp_lock); -+ -+ wined3d_fence_destroy(elem->fence); -+ -+ heap->fenced_head = elem->next; -+ HeapFree(GetProcessHeap(), 0, elem); -+ // TODO(acomminos): bother to null out fenced_tail? -+ break; -+ } -+ default: -+ return WINED3D_OK; -+ } -+ -+ return WINED3D_OK; -+} -+ -+HRESULT wined3d_buffer_heap_deferred_coalesce(struct wined3d_buffer_heap *heap, int *coalesced_count) -+{ -+ struct wined3d_buffer_heap_element *elem = NULL; -+ struct wined3d_buffer_heap_element *next = NULL; -+ struct wine_rb_entry *entry; -+ struct wined3d_map_range coalesced_range; -+ -+ struct wine_rb_tree free_tree; -+ int num_coalesced = 0; -+ -+ wine_rb_init(&free_tree, free_tree_compare); -+ -+ EnterCriticalSection(&heap->temp_lock); -+ -+ // TODO(acomminos): on one hand, if there's a lot of elements in the list, -+ // it's highly fragmented. on the other, we can potentially waste a decent -+ // sum of time checking for uncoalesced bins. -+ for (int i = 0; i < WINED3D_BUFFER_HEAP_BINS; i++) -+ { -+ elem = heap->free_list.bins[i].head; -+ while (elem) -+ { -+ // Insert a sentry. FIXME(acomminos): can skip this with traversal. -+ if (wine_rb_put(&free_tree, &elem->range.offset, &elem->entry) == -1) -+ { -+ ERR("Failed to insert key %x in tree.\n", elem->range.offset); -+ elem = elem->next; -+ continue; -+ } -+ -+ coalesced_range = elem->range; -+ -+ // Coalesce right. -+ entry = wine_rb_next(&elem->entry); -+ if (entry) -+ { -+ TRACE("Coalesced right.\n"); -+ struct wined3d_buffer_heap_element *right_elem = WINE_RB_ENTRY_VALUE(entry, struct wined3d_buffer_heap_element, entry); -+ if (elem->range.offset + elem->range.size == right_elem->range.offset) -+ { -+ coalesced_range.size += right_elem->range.size; -+ -+ wine_rb_remove(&free_tree, entry); -+ element_remove_free(heap, right_elem); -+ HeapFree(GetProcessHeap(), 0, right_elem); -+ -+ num_coalesced++; -+ } -+ } -+ -+ // Coalesce left. -+ entry = wine_rb_prev(&elem->entry); -+ if (entry) -+ { -+ TRACE("Coalesced left.\n"); -+ struct wined3d_buffer_heap_element *left_elem = WINE_RB_ENTRY_VALUE(entry, struct wined3d_buffer_heap_element, entry); -+ if (left_elem->range.offset + left_elem->range.size == coalesced_range.offset) -+ { -+ coalesced_range.offset = left_elem->range.offset; -+ coalesced_range.size += left_elem->range.size; -+ -+ wine_rb_remove(&free_tree, entry); -+ element_remove_free(heap, left_elem); -+ HeapFree(GetProcessHeap(), 0, left_elem); -+ -+ num_coalesced++; -+ } -+ } -+ -+ next = elem->next; -+ -+ if (elem->range.size != coalesced_range.size) -+ { -+ FIXME_(d3d_perf)("Coalesced range from (%p, %ld) to (%p, %ld)\n", elem->range.offset, elem->range.size, coalesced_range.offset, coalesced_range.size); -+ -+ wine_rb_remove(&free_tree, &elem->entry); -+ -+ // Move to the correct free bin. -+ element_remove_free(heap, elem); -+ elem->range = coalesced_range; -+ element_insert_free_bin(heap, elem); -+ -+ wine_rb_put(&free_tree, &elem->range.offset, &elem->entry); -+ } -+ -+ elem = next; -+ } -+ } -+ -+ LeaveCriticalSection(&heap->temp_lock); -+ -+ FIXME_(d3d_perf)("Performed %d coalesces.\n", num_coalesced); -+ if (coalesced_count) -+ *coalesced_count = num_coalesced; -+ -+ return WINED3D_OK; -+} -diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c -index 3a7c95ddd8..50a4d041cd 100644 ---- a/dlls/wined3d/cs.c -+++ b/dlls/wined3d/cs.c -@@ -472,6 +472,15 @@ static void wined3d_cs_exec_present(struct wined3d_cs *cs, const void *data) - } - - InterlockedDecrement(&cs->pending_presents); -+ -+ // FIXME(acomminos): is this the right place to put double-buffered frame -+ // timing based logic? -+ // FIXME(acomminos): this conditional sucks, replace with fancier feature check -+ if (cs->device->wo_buffer_heap && cs->device->cb_buffer_heap) -+ { -+ wined3d_buffer_heap_cs_fence_issue(cs->device->wo_buffer_heap, cs->device); -+ wined3d_buffer_heap_cs_fence_issue(cs->device->cb_buffer_heap, cs->device); -+ } - } - - void wined3d_cs_emit_present(struct wined3d_cs *cs, struct wined3d_swapchain *swapchain, -diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c -index e2b27e0cf4..785841a062 100644 ---- a/dlls/wined3d/device.c -+++ b/dlls/wined3d/device.c -@@ -833,6 +833,53 @@ static void destroy_default_samplers(struct wined3d_device *device, struct wined - device->null_sampler = NULL; - } - -+/* Context activation is done by the caller. */ -+static void create_buffer_heap(struct wined3d_device *device, struct wined3d_context *context) -+{ -+ const struct wined3d_gl_info *gl_info = &device->adapter->gl_info; -+ // TODO(acomminos): kill this magic number. perhaps base on vram. -+ GLsizeiptr geo_heap_size = 512 * 1024 * 1024; -+ // We choose a constant buffer size of 128MB, the same as NVIDIA claims to -+ // use in their Direct3D driver for discarded constant buffers. -+ GLsizeiptr cb_heap_size = 128 * 1024 * 1024; -+ GLint ub_alignment; -+ HRESULT hr; -+ -+ if (gl_info->supported[ARB_BUFFER_STORAGE]) -+ { -+ gl_info->gl_ops.gl.p_glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &ub_alignment); -+ -+ // Align constant buffer heap size, in case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT isn't a power of two (for some reason). -+ cb_heap_size -= cb_heap_size % ub_alignment; -+ -+ if (FAILED(hr = wined3d_buffer_heap_create(context, geo_heap_size, 0, TRUE, &device->wo_buffer_heap))) -+ { -+ ERR("Failed to create write-only persistent buffer heap, hr %#x.\n", hr); -+ } -+ -+ if (FAILED(hr = wined3d_buffer_heap_create(context, cb_heap_size, ub_alignment, TRUE, &device->cb_buffer_heap))) -+ { -+ ERR("Failed to create persistent buffer heap for constant buffers, hr %#x.\n", hr); -+ } -+ -+ FIXME("Initialized PBA (geo_heap_size: %ld, cb_heap_size: %ld, ub_align: %d)\n", geo_heap_size, cb_heap_size, ub_alignment); -+ } -+ else -+ { -+ FIXME("Not using PBA, ARB_buffer_storage unsupported.\n"); -+ } -+} -+ -+/* Context activation is done by the caller. */ -+static void destroy_buffer_heap(struct wined3d_device *device, struct wined3d_context *context) -+{ -+ if (device->wo_buffer_heap) -+ wined3d_buffer_heap_destroy(device->wo_buffer_heap, context); -+ -+ if (device->cb_buffer_heap) -+ wined3d_buffer_heap_destroy(device->cb_buffer_heap, context); -+} -+ - static LONG fullscreen_style(LONG style) - { - /* Make sure the window is managed, otherwise we won't get keyboard input. */ -@@ -997,6 +1044,8 @@ static void wined3d_device_delete_opengl_contexts_cs(void *object) - device->shader_backend->shader_free_private(device); - destroy_dummy_textures(device, context); - destroy_default_samplers(device, context); -+ destroy_buffer_heap(device, context); -+ - context_release(context); - - while (device->context_count) -@@ -1045,6 +1094,9 @@ static void wined3d_device_create_primary_opengl_context_cs(void *object) - context = context_acquire(device, target, 0); - create_dummy_textures(device, context); - create_default_samplers(device, context); -+ -+ create_buffer_heap(device, context); -+ - context_release(context); - } - -diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c -index 8720fc7ad6..46c6a59536 100644 ---- a/dlls/wined3d/directx.c -+++ b/dlls/wined3d/directx.c -@@ -111,6 +111,7 @@ static const struct wined3d_extension_map gl_extension_map[] = - /* ARB */ - {"GL_ARB_base_instance", ARB_BASE_INSTANCE }, - {"GL_ARB_blend_func_extended", ARB_BLEND_FUNC_EXTENDED }, -+ {"GL_ARB_buffer_storage", ARB_BUFFER_STORAGE }, - {"GL_ARB_clear_buffer_object", ARB_CLEAR_BUFFER_OBJECT }, - {"GL_ARB_clear_texture", ARB_CLEAR_TEXTURE }, - {"GL_ARB_clip_control", ARB_CLIP_CONTROL }, -@@ -2714,6 +2715,8 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info) - /* GL_ARB_blend_func_extended */ - USE_GL_FUNC(glBindFragDataLocationIndexed) - USE_GL_FUNC(glGetFragDataIndex) -+ /* GL_ARB_buffer_storage */ -+ USE_GL_FUNC(glBufferStorage) - /* GL_ARB_clear_buffer_object */ - USE_GL_FUNC(glClearBufferData) - USE_GL_FUNC(glClearBufferSubData) -diff --git a/dlls/wined3d/query.c b/dlls/wined3d/query.c -index 5ea79b6e4a..f3ca1630e5 100644 ---- a/dlls/wined3d/query.c -+++ b/dlls/wined3d/query.c -@@ -88,7 +88,7 @@ static BOOL wined3d_fence_supported(const struct wined3d_gl_info *gl_info) - return gl_info->supported[ARB_SYNC] || gl_info->supported[NV_FENCE] || gl_info->supported[APPLE_FENCE]; - } - --static enum wined3d_fence_result wined3d_fence_test(const struct wined3d_fence *fence, -+enum wined3d_fence_result wined3d_fence_test(const struct wined3d_fence *fence, - const struct wined3d_device *device, DWORD flags) - { - const struct wined3d_gl_info *gl_info; -diff --git a/dlls/wined3d/wined3d_gl.h b/dlls/wined3d/wined3d_gl.h -index 87283c850e..7626864ef2 100644 ---- a/dlls/wined3d/wined3d_gl.h -+++ b/dlls/wined3d/wined3d_gl.h -@@ -44,6 +44,7 @@ enum wined3d_gl_extension - /* ARB */ - ARB_BASE_INSTANCE, - ARB_BLEND_FUNC_EXTENDED, -+ ARB_BUFFER_STORAGE, - ARB_CLEAR_BUFFER_OBJECT, - ARB_CLEAR_TEXTURE, - ARB_CLIP_CONTROL, -diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h -index 8aa61d811f..3d535f4e17 100644 ---- a/dlls/wined3d/wined3d_private.h -+++ b/dlls/wined3d/wined3d_private.h -@@ -1712,6 +1712,9 @@ void wined3d_fence_destroy(struct wined3d_fence *fence) DECLSPEC_HIDDEN; - void wined3d_fence_issue(struct wined3d_fence *fence, const struct wined3d_device *device) DECLSPEC_HIDDEN; - enum wined3d_fence_result wined3d_fence_wait(const struct wined3d_fence *fence, - const struct wined3d_device *device) DECLSPEC_HIDDEN; -+// XXX(acomminos): really expose this? -+enum wined3d_fence_result wined3d_fence_test(const struct wined3d_fence *fence, -+ const struct wined3d_device *device, DWORD flags) DECLSPEC_HIDDEN; - - /* Direct3D terminology with little modifications. We do not have an issued - * state because only the driver knows about it, but we have a created state -@@ -2993,6 +2996,10 @@ struct wined3d_device - /* Context management */ - struct wined3d_context **contexts; - UINT context_count; -+ -+ /* Dynamic buffer heap */ -+ struct wined3d_buffer_heap *wo_buffer_heap; -+ struct wined3d_buffer_heap *cb_buffer_heap; - }; - - void device_clear_render_targets(struct wined3d_device *device, UINT rt_count, const struct wined3d_fb_state *fb, -@@ -3513,6 +3520,12 @@ void state_init(struct wined3d_state *state, struct wined3d_fb_state *fb, - DWORD flags) DECLSPEC_HIDDEN; - void state_unbind_resources(struct wined3d_state *state) DECLSPEC_HIDDEN; - -+struct wined3d_map_range -+{ -+ GLintptr offset; -+ GLsizeiptr size; -+}; -+ - enum wined3d_cs_queue_id - { - WINED3D_CS_QUEUE_DEFAULT = 0, -@@ -3692,12 +3705,61 @@ enum wined3d_buffer_conversion_type - CONV_POSITIONT, - }; - --struct wined3d_map_range -+struct wined3d_buffer_heap_element; -+struct wined3d_buffer_heap_fenced_element; -+ -+// Number of power-of-two buckets to populate. -+#define WINED3D_BUFFER_HEAP_BINS 32 -+ -+struct wined3d_buffer_heap_bin - { -- UINT offset; -- UINT size; -+ struct wined3d_buffer_heap_element *head; -+ struct wined3d_buffer_heap_element *tail; -+}; -+ -+struct wined3d_buffer_heap_bin_set -+{ -+ struct wined3d_buffer_heap_bin bins[WINED3D_BUFFER_HEAP_BINS]; - }; - -+// A heap that manages allocations with a single GL buffer. -+struct wined3d_buffer_heap -+{ -+ GLuint buffer_object; -+ void *map_ptr; -+ GLsizeiptr alignment; -+ CRITICAL_SECTION temp_lock; // Temporary lock while we implement the fenced free list. -+ -+ struct wined3d_buffer_heap_bin_set free_list; -+ -+ // Elements that need to be fenced, but haven't reached the required size. -+ struct wined3d_buffer_heap_bin_set pending_fenced_bins; -+ -+ // List of sets of buffers behind a common fence, in FIFO order. -+ struct wined3d_buffer_heap_fenced_element *fenced_head; -+ struct wined3d_buffer_heap_fenced_element *fenced_tail; -+}; -+ -+HRESULT wined3d_buffer_heap_create(struct wined3d_context *context, GLsizeiptr size, GLsizeiptr alignment, BOOL write_only, struct wined3d_buffer_heap **heap) DECLSPEC_HIDDEN; -+HRESULT wined3d_buffer_heap_destroy(struct wined3d_buffer_heap *heap, struct wined3d_context *context) DECLSPEC_HIDDEN; -+// Fetches a buffer from the heap of at least the given size. -+// Attempts to coalesce blocks under memory pressure. -+HRESULT wined3d_buffer_heap_alloc(struct wined3d_buffer_heap *heap, GLsizeiptr size, struct wined3d_map_range* out_range) DECLSPEC_HIDDEN; -+// Immediately frees a heap-allocated buffer segment. -+HRESULT wined3d_buffer_heap_free(struct wined3d_buffer_heap *heap, struct wined3d_map_range range) DECLSPEC_HIDDEN; -+// Enqueues a buffer segment to return to the heap once its fence has been signaled. -+HRESULT wined3d_buffer_heap_free_fenced(struct wined3d_buffer_heap *heap, struct wined3d_device *device, struct wined3d_map_range range) DECLSPEC_HIDDEN; -+// Issues a fence for the current set of pending fenced buffers. -+// Double-buffered: if the last fence issued has not yet been triggered, waits -+// on it. -+HRESULT wined3d_buffer_heap_cs_fence_issue(struct wined3d_buffer_heap *heap, struct wined3d_device *device) DECLSPEC_HIDDEN; -+// Waits on the next issued fence in FIFO order. Frees the fenced buffers after -+// the fence has been triggered. -+HRESULT wined3d_buffer_heap_cs_fence_wait(struct wined3d_buffer_heap *heap, struct wined3d_device *device) DECLSPEC_HIDDEN; -+// Performs deferred coalescing of buffers. To be called under memory pressure. -+// Outputs the number of coalesced regions in `num_coalesced`. -+HRESULT wined3d_buffer_heap_deferred_coalesce(struct wined3d_buffer_heap *heap, int *num_coalesced) DECLSPEC_HIDDEN; -+ - struct wined3d_buffer - { - struct wined3d_resource resource; --- -2.16.2 - diff --git a/0002-wined3d-Add-support-for-backing-dynamic-wined3d_buff.patch b/0002-wined3d-Add-support-for-backing-dynamic-wined3d_buff.patch deleted file mode 100644 index cb910a25df4b..000000000000 --- a/0002-wined3d-Add-support-for-backing-dynamic-wined3d_buff.patch +++ /dev/null @@ -1,682 +0,0 @@ -From 6d2e04a5aeab1e3dc238b548a3f90986da4b5e1e Mon Sep 17 00:00:00 2001 -From: Andrew Comminos <andrew@comminos.com> -Date: Mon, 5 Mar 2018 15:39:11 -0800 -Subject: [PATCH 2/5] wined3d: Add support for backing dynamic wined3d_buffer - objects by a persistent map. - ---- - dlls/wined3d/buffer.c | 220 ++++++++++++++++++++++++++++++++++++++++- - dlls/wined3d/context.c | 6 +- - dlls/wined3d/cs.c | 60 ++++++++++- - dlls/wined3d/resource.c | 18 +++- - dlls/wined3d/state.c | 17 +++- - dlls/wined3d/texture.c | 13 +++ - dlls/wined3d/utils.c | 1 + - dlls/wined3d/wined3d_private.h | 11 +++ - 8 files changed, 336 insertions(+), 10 deletions(-) - -diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c -index cae7ef8788..ad057b7fba 100644 ---- a/dlls/wined3d/buffer.c -+++ b/dlls/wined3d/buffer.c -@@ -28,12 +28,14 @@ - #include "wined3d_private.h" - - WINE_DEFAULT_DEBUG_CHANNEL(d3d); -+WINE_DECLARE_DEBUG_CHANNEL(d3d_perf); - - #define WINED3D_BUFFER_HASDESC 0x01 /* A vertex description has been found. */ - #define WINED3D_BUFFER_USE_BO 0x02 /* Use a buffer object for this buffer. */ - #define WINED3D_BUFFER_PIN_SYSMEM 0x04 /* Keep a system memory copy for this buffer. */ - #define WINED3D_BUFFER_DISCARD 0x08 /* A DISCARD lock has occurred since the last preload. */ - #define WINED3D_BUFFER_APPLESYNC 0x10 /* Using sync as in GL_APPLE_flush_buffer_range. */ -+#define WINED3D_BUFFER_PERSISTENT 0x20 /* Uses a persistent-mapped buffer via ARB_buffer_storage. */ - - #define VB_MAXDECLCHANGES 100 /* After that number of decl changes we stop converting */ - #define VB_RESETDECLCHANGE 1000 /* Reset the decl changecount after that number of draws */ -@@ -269,6 +271,52 @@ fail: - return FALSE; - } - -+/* Context activation is done by the caller. */ -+static BOOL buffer_alloc_persistent_map(struct wined3d_buffer *buffer, struct wined3d_context *context) -+{ -+ struct wined3d_device *device = buffer->resource.device; -+ struct wined3d_buffer_heap *heap; -+ struct wined3d_map_range map_range; -+ HRESULT hr; -+ -+ if (buffer->bind_flags & WINED3D_BIND_CONSTANT_BUFFER) -+ { -+ // Use a heap aligned to constant buffer offset requirements. -+ heap = device->cb_buffer_heap; -+ } -+ else -+ { -+ if (!(buffer->resource.usage & WINED3DUSAGE_WRITEONLY)) -+ FIXME("Using a write-only persistent buffer for %p without WINED3DUSAGE_WRITEONLY.\n", buffer); -+ heap = device->wo_buffer_heap; -+ } -+ -+ buffer->buffer_heap = heap; -+ if (FAILED(hr = wined3d_buffer_heap_alloc(heap, buffer->resource.size, &map_range))) -+ { -+ goto fail; -+ } -+ buffer->cs_persistent_map = map_range; -+ buffer->mt_persistent_map = map_range; -+ return TRUE; -+ -+fail: -+ // FIXME(acomminos): fall back to standalone BO here? -+ ERR("Failed to create persistent map for buffer %p, hr=%x\n", buffer, hr); -+ buffer->buffer_heap = NULL; -+ return FALSE; -+} -+ -+static void buffer_free_persistent_map(struct wined3d_buffer *buffer) -+{ -+ if (!buffer->buffer_heap) -+ return; -+ -+ // TODO(acomminos): get the CS thread to free pending main thread buffers. -+ wined3d_buffer_heap_free(buffer->buffer_heap, buffer->cs_persistent_map); -+ buffer->buffer_heap = NULL; -+} -+ - static BOOL buffer_process_converted_attribute(struct wined3d_buffer *buffer, - const enum wined3d_buffer_conversion_type conversion_type, - const struct wined3d_stream_info_element *attrib, DWORD *stride_this_run) -@@ -631,6 +679,16 @@ static BOOL wined3d_buffer_prepare_location(struct wined3d_buffer *buffer, - return FALSE; - } - return buffer_create_buffer_object(buffer, context); -+ case WINED3D_LOCATION_PERSISTENT_MAP: -+ if (buffer->buffer_heap) -+ return TRUE; -+ -+ if (!(buffer->flags & WINED3D_BUFFER_PERSISTENT)) -+ { -+ WARN("Trying to map a persistent region for buffer %p without WINED3D_BUFFER_PERSISTENT.\n", buffer); -+ return FALSE; -+ } -+ return buffer_alloc_persistent_map(buffer, context); - - default: - ERR("Invalid location %s.\n", wined3d_debug_location(location)); -@@ -689,16 +747,32 @@ BOOL wined3d_buffer_load_location(struct wined3d_buffer *buffer, - buffer_conversion_upload(buffer, context); - break; - -+ case WINED3D_LOCATION_PERSISTENT_MAP: -+ // TODO(acomminos): are we guaranteed location_sysmem to be kept? -+ // no. -+ if (buffer->conversion_map) -+ FIXME("Attempting to use conversion map with persistent mapping.\n"); -+ memcpy(buffer->buffer_heap->map_ptr + -+ buffer->cs_persistent_map.offset, -+ buffer->resource.heap_memory, buffer->resource.size); -+ break; -+ - default: - ERR("Invalid location %s.\n", wined3d_debug_location(location)); - return FALSE; - } - - wined3d_buffer_validate_location(buffer, location); -- if (buffer->resource.heap_memory && location == WINED3D_LOCATION_BUFFER -+ if (buffer->resource.heap_memory -+ && location & WINED3D_LOCATION_BUFFER - && !(buffer->resource.usage & WINED3DUSAGE_DYNAMIC)) - wined3d_buffer_evict_sysmem(buffer); - -+ // FIXME(acomminos) -+ if (buffer->resource.heap_memory -+ && location & WINED3D_LOCATION_PERSISTENT_MAP) -+ wined3d_buffer_evict_sysmem(buffer); -+ - return TRUE; - } - -@@ -720,12 +794,25 @@ DWORD wined3d_buffer_get_memory(struct wined3d_buffer *buffer, - { - data->buffer_object = buffer->buffer_object; - data->addr = NULL; -+ data->length = buffer->resource.size; - return WINED3D_LOCATION_BUFFER; - } -+ if (locations & WINED3D_LOCATION_PERSISTENT_MAP) -+ { -+ // FIXME(acomminos): should we expose a buffer object we don't wholly own here? -+ data->buffer_object = buffer->buffer_heap->buffer_object; -+ data->addr = buffer->cs_persistent_map.offset; -+ // Note that the size of the underlying buffer allocation may be larger -+ // than the buffer knows about. In this case, we've rounded it up to be -+ // aligned (e.g. for uniform buffer offsets). -+ data->length = buffer->cs_persistent_map.size; -+ return WINED3D_LOCATION_PERSISTENT_MAP; -+ } - if (locations & WINED3D_LOCATION_SYSMEM) - { - data->buffer_object = 0; - data->addr = buffer->resource.heap_memory; -+ data->length = buffer->resource.size; - return WINED3D_LOCATION_SYSMEM; - } - -@@ -761,6 +848,8 @@ static void buffer_unload(struct wined3d_resource *resource) - buffer->flags &= ~WINED3D_BUFFER_HASDESC; - } - -+ buffer_free_persistent_map(buffer); -+ - resource_unload(resource); - } - -@@ -784,6 +873,8 @@ static void wined3d_buffer_destroy_object(void *object) - heap_free(buffer->conversion_map); - } - -+ buffer_free_persistent_map(buffer); -+ - heap_free(buffer->maps); - heap_free(buffer); - } -@@ -900,6 +991,16 @@ void wined3d_buffer_load(struct wined3d_buffer *buffer, struct wined3d_context * - - buffer_mark_used(buffer); - -+ if (buffer->flags & WINED3D_BUFFER_PERSISTENT) -+ { -+ if (wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_PERSISTENT_MAP)) -+ return; -+ -+ ERR("Failed to preload persistent mapping for %p, falling back to BO.\n", buffer); -+ buffer->flags |= WINED3D_BUFFER_USE_BO; -+ buffer->flags &= ~WINED3D_BUFFER_PERSISTENT; -+ } -+ - /* TODO: Make converting independent from VBOs */ - if (!(buffer->flags & WINED3D_BUFFER_USE_BO)) - { -@@ -1010,6 +1111,25 @@ static HRESULT wined3d_buffer_map(struct wined3d_buffer *buffer, UINT offset, UI - - count = ++buffer->resource.map_count; - -+ if (buffer->locations & WINED3D_LOCATION_PERSISTENT_MAP) -+ { -+ const struct wined3d_gl_info *gl_info; -+ context = context_acquire(device, NULL, 0); -+ -+ FIXME_(d3d_perf)("Fences not used for persistent buffer maps on CS thread, using glFinish.\n"); -+ -+ gl_info = context->gl_info; -+ gl_info->gl_ops.gl.p_glFinish(); -+ -+ base = buffer->buffer_heap->map_ptr -+ + buffer->cs_persistent_map.offset; -+ *data = base + offset; -+ -+ context_release(context); -+ -+ return WINED3D_OK; -+ } -+ - if (buffer->buffer_object) - { - unsigned int dirty_offset = offset, dirty_size = size; -@@ -1152,6 +1272,12 @@ static void wined3d_buffer_unmap(struct wined3d_buffer *buffer) - return; - } - -+ if (buffer->flags & WINED3D_BUFFER_PERSISTENT) -+ { -+ TRACE("Persistent buffer, ignore unmap.\n"); -+ return; -+ } -+ - if (buffer->map_ptr) - { - struct wined3d_device *device = buffer->resource.device; -@@ -1256,6 +1382,64 @@ static void buffer_resource_preload(struct wined3d_resource *resource) - - static HRESULT buffer_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx, - struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags) -+{ -+ struct wined3d_buffer *buffer = buffer_from_resource(resource); -+ UINT offset = box ? box->left : 0; -+ -+ if (sub_resource_idx) -+ { -+ WARN("Invalid sub_resource_idx %u.\n", sub_resource_idx); -+ return E_INVALIDARG; -+ } -+ -+ // Support immediate mapping of persistent buffers off the command thread, -+ // which require no GL calls to interface with. -+ if (buffer->locations & WINED3D_LOCATION_PERSISTENT_MAP) -+ { -+ map_desc->row_pitch = map_desc->slice_pitch = buffer->desc.byte_width; -+ if (flags & WINED3D_MAP_DISCARD) -+ { -+ HRESULT hr; -+ struct wined3d_map_range map_range; -+ if (FAILED(hr = wined3d_buffer_heap_alloc(buffer->buffer_heap, resource->size, &map_range))) -+ { -+ FIXME_(d3d_perf)("Failed to allocate new buffer, falling back to sync path.\n"); -+ return hr; -+ } -+ map_desc->data = buffer->buffer_heap->map_ptr + map_range.offset + offset; -+ resource->map_count++; -+ -+ buffer->mt_persistent_map = map_range; -+ -+ // Discard handler on CSMT thread is responsible for returning the -+ // currently used buffer to the free pool, along with the fence that -+ // must be called before the buffer can be reused. -+ wined3d_cs_emit_discard_buffer(resource->device->cs, buffer, map_range); -+ return WINED3D_OK; -+ } -+ else if (flags & WINED3D_MAP_NOOVERWRITE) -+ { -+ // Allow immediate access for persistent buffers without a fence. -+ // Always use the latest buffer in this case in case the latest -+ // DISCARDed one hasn't reached the command stream yet. -+ struct wined3d_map_range map_range = buffer->mt_persistent_map; -+ map_desc->data = buffer->buffer_heap->map_ptr + map_range.offset + offset; -+ resource->map_count++; -+ return WINED3D_OK; -+ } -+ else -+ { -+ // TODO(acomminos): Should check mapped ranges to see if the region is writeable even though NOOVERWRITE is specified. -+ WARN_(d3d_perf)("Mapping persistent buffer %p in sync with CS thread.\n", buffer); -+ // XXX(acomminos): kill this early return. they're the worst. -+ } -+ } -+ -+ return E_NOTIMPL; -+} -+ -+static HRESULT buffer_resource_sub_resource_map_cs(struct wined3d_resource *resource, unsigned int sub_resource_idx, -+ struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags) - { - struct wined3d_buffer *buffer = buffer_from_resource(resource); - UINT offset, size; -@@ -1299,6 +1483,18 @@ static HRESULT buffer_resource_sub_resource_map_info(struct wined3d_resource *re - } - - static HRESULT buffer_resource_sub_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx) -+{ -+ struct wined3d_buffer *buffer = buffer_from_resource(resource); -+ if (buffer->locations & WINED3D_LOCATION_PERSISTENT_MAP) -+ { -+ // Nothing to be done to unmap a region of a persistent buffer. -+ resource->map_count--; -+ return WINED3D_OK; -+ } -+ return E_NOTIMPL; -+} -+ -+static HRESULT buffer_resource_sub_resource_unmap_cs(struct wined3d_resource *resource, unsigned int sub_resource_idx) - { - if (sub_resource_idx) - { -@@ -1318,7 +1514,9 @@ static const struct wined3d_resource_ops buffer_resource_ops = - buffer_unload, - buffer_resource_sub_resource_map, - buffer_resource_sub_resource_map_info, -+ buffer_resource_sub_resource_map_cs, - buffer_resource_sub_resource_unmap, -+ buffer_resource_sub_resource_unmap_cs, - }; - - static GLenum buffer_type_hint_from_bind_flags(const struct wined3d_gl_info *gl_info, -@@ -1394,12 +1592,30 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device - buffer->flags |= WINED3D_BUFFER_PIN_SYSMEM; - } - -+ if (buffer->resource.usage & WINED3DUSAGE_DYNAMIC) -+ { -+ if (!gl_info->supported[ARB_BUFFER_STORAGE]) -+ { -+ WARN_(d3d_perf)("Not creating a persistent mapping for a dynamic buffer because ARB_buffer_storage is unsupported.\n"); -+ } -+ else -+ { -+ // If supported, use persistent mapped buffers instead of a -+ // standalone BO for dynamic buffers. -+ buffer->flags |= WINED3D_BUFFER_PERSISTENT; -+ } -+ } -+ - /* Observations show that draw_primitive_immediate_mode() is faster on - * dynamic vertex buffers than converting + draw_primitive_arrays(). - * (Half-Life 2 and others.) */ - dynamic_buffer_ok = gl_info->supported[APPLE_FLUSH_BUFFER_RANGE] || gl_info->supported[ARB_MAP_BUFFER_RANGE]; - -- if (!gl_info->supported[ARB_VERTEX_BUFFER_OBJECT]) -+ if (buffer->flags & WINED3D_BUFFER_PERSISTENT) -+ { -+ TRACE("Not creating a BO because a persistent mapped buffer will be used.\n"); -+ } -+ else if (!gl_info->supported[ARB_VERTEX_BUFFER_OBJECT]) - { - TRACE("Not creating a BO because GL_ARB_vertex_buffer is not supported.\n"); - } -diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c -index 0e2e68b4b0..eae2c3a79d 100644 ---- a/dlls/wined3d/context.c -+++ b/dlls/wined3d/context.c -@@ -5005,7 +5005,11 @@ void draw_primitive(struct wined3d_device *device, const struct wined3d_state *s - if (parameters->indexed) - { - struct wined3d_buffer *index_buffer = state->index_buffer; -- if (!index_buffer->buffer_object || !stream_info->all_vbo) -+ if (index_buffer->locations & WINED3D_LOCATION_PERSISTENT_MAP) -+ { -+ idx_data = index_buffer->cs_persistent_map.offset; -+ } -+ else if (!index_buffer->buffer_object || !stream_info->all_vbo) - { - idx_data = index_buffer->resource.heap_memory; - } -diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c -index 50a4d041cd..e61b8dedbb 100644 ---- a/dlls/wined3d/cs.c -+++ b/dlls/wined3d/cs.c -@@ -73,6 +73,7 @@ enum wined3d_cs_op - WINED3D_CS_OP_CLEAR_UNORDERED_ACCESS_VIEW, - WINED3D_CS_OP_COPY_UAV_COUNTER, - WINED3D_CS_OP_GENERATE_MIPMAPS, -+ WINED3D_CS_OP_DISCARD_BUFFER, - WINED3D_CS_OP_STOP, - }; - -@@ -439,6 +440,13 @@ struct wined3d_cs_generate_mipmaps - struct wined3d_shader_resource_view *view; - }; - -+struct wined3d_cs_discard_buffer -+{ -+ enum wined3d_cs_op opcode; -+ struct wined3d_buffer *buffer; -+ struct wined3d_map_range map_range; -+}; -+ - struct wined3d_cs_stop - { - enum wined3d_cs_op opcode; -@@ -2002,7 +2010,7 @@ static void wined3d_cs_exec_map(struct wined3d_cs *cs, const void *data) - const struct wined3d_cs_map *op = data; - struct wined3d_resource *resource = op->resource; - -- *op->hr = resource->resource_ops->resource_sub_resource_map(resource, -+ *op->hr = resource->resource_ops->resource_sub_resource_map_cs(resource, - op->sub_resource_idx, op->map_desc, op->box, op->flags); - } - -@@ -2036,7 +2044,7 @@ static void wined3d_cs_exec_unmap(struct wined3d_cs *cs, const void *data) - const struct wined3d_cs_unmap *op = data; - struct wined3d_resource *resource = op->resource; - -- *op->hr = resource->resource_ops->resource_sub_resource_unmap(resource, op->sub_resource_idx); -+ *op->hr = resource->resource_ops->resource_sub_resource_unmap_cs(resource, op->sub_resource_idx); - } - - HRESULT wined3d_cs_unmap(struct wined3d_cs *cs, struct wined3d_resource *resource, unsigned int sub_resource_idx) -@@ -2455,6 +2463,53 @@ void wined3d_cs_emit_generate_mipmaps(struct wined3d_cs *cs, struct wined3d_shad - cs->ops->submit(cs, WINED3D_CS_QUEUE_DEFAULT); - } - -+static void wined3d_cs_exec_discard_buffer(struct wined3d_cs *cs, const void *data) -+{ -+ const struct wined3d_cs_discard_buffer *op = data; -+ struct wined3d_buffer *buffer = op->buffer; -+ HRESULT hr; -+ -+ // TODO(acomminos): should call into buffer.c here instead. -+ if (FAILED(hr = wined3d_buffer_heap_free_fenced(buffer->buffer_heap, cs->device, buffer->cs_persistent_map))) -+ { -+ ERR("Failed to do a fenced free on discarded buffer %p, hr %x\n. Freeing anyway.", buffer, hr); -+ wined3d_buffer_heap_free(buffer->buffer_heap, buffer->cs_persistent_map); -+ } -+ -+ buffer->cs_persistent_map = op->map_range; -+ -+ // TODO(acomminos): merge this logic with buffer.c functions for standalone BOs -+ if (buffer->bind_flags & WINED3D_BIND_VERTEX_BUFFER) -+ device_invalidate_state(cs->device, STATE_STREAMSRC); -+ if (buffer->bind_flags & WINED3D_BIND_INDEX_BUFFER) -+ device_invalidate_state(cs->device, STATE_INDEXBUFFER); -+ if (buffer->bind_flags & WINED3D_BIND_CONSTANT_BUFFER) -+ { -+ device_invalidate_state(cs->device, STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX)); -+ device_invalidate_state(cs->device, STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL)); -+ device_invalidate_state(cs->device, STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN)); -+ device_invalidate_state(cs->device, STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY)); -+ device_invalidate_state(cs->device, STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL)); -+ device_invalidate_state(cs->device, STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE)); -+ } -+ -+ wined3d_resource_release(&op->buffer->resource); -+} -+ -+void wined3d_cs_emit_discard_buffer(struct wined3d_cs *cs, struct wined3d_buffer *buffer, struct wined3d_map_range map_range) -+{ -+ struct wined3d_cs_discard_buffer *op; -+ -+ op = cs->ops->require_space(cs, sizeof(*op), WINED3D_CS_QUEUE_DEFAULT); -+ op->opcode = WINED3D_CS_OP_DISCARD_BUFFER; -+ op->buffer = buffer; -+ op->map_range = map_range; -+ -+ wined3d_resource_acquire(&buffer->resource); -+ -+ cs->ops->submit(cs, WINED3D_CS_QUEUE_DEFAULT); -+} -+ - static void wined3d_cs_emit_stop(struct wined3d_cs *cs) - { - struct wined3d_cs_stop *op; -@@ -2515,6 +2570,7 @@ static void (* const wined3d_cs_op_handlers[])(struct wined3d_cs *cs, const void - /* WINED3D_CS_OP_CLEAR_UNORDERED_ACCESS_VIEW */ wined3d_cs_exec_clear_unordered_access_view, - /* WINED3D_CS_OP_COPY_UAV_COUNTER */ wined3d_cs_exec_copy_uav_counter, - /* WINED3D_CS_OP_GENERATE_MIPMAPS */ wined3d_cs_exec_generate_mipmaps, -+ /* WINED3D_CS_OP_DISCARD_BUFFER */ wined3d_cs_exec_discard_buffer, - }; - - #if defined(STAGING_CSMT) -diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c -index 8b7f17bb6b..02d469bc20 100644 ---- a/dlls/wined3d/resource.c -+++ b/dlls/wined3d/resource.c -@@ -344,6 +344,7 @@ static DWORD wined3d_resource_sanitise_map_flags(const struct wined3d_resource * - HRESULT CDECL wined3d_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx, - struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags) - { -+ HRESULT hr; - TRACE("resource %p, sub_resource_idx %u, map_desc %p, box %s, flags %#x.\n", - resource, sub_resource_idx, map_desc, debug_box(box), flags); - -@@ -366,9 +367,14 @@ HRESULT CDECL wined3d_resource_map(struct wined3d_resource *resource, unsigned i - } - - flags = wined3d_resource_sanitise_map_flags(resource, flags); -- wined3d_resource_wait_idle(resource); -+ if (FAILED(hr = resource->resource_ops->resource_sub_resource_map(resource, sub_resource_idx, map_desc, box, flags))) -+ { -+ TRACE_(d3d_perf)("Mapping resource %p on the command stream.\n", resource); -+ wined3d_resource_wait_idle(resource); -+ hr = wined3d_cs_map(resource->device->cs, resource, sub_resource_idx, map_desc, box, flags); -+ } - -- return wined3d_cs_map(resource->device->cs, resource, sub_resource_idx, map_desc, box, flags); -+ return hr; - } - - HRESULT CDECL wined3d_resource_map_info(struct wined3d_resource *resource, unsigned int sub_resource_idx, -@@ -381,9 +387,15 @@ HRESULT CDECL wined3d_resource_map_info(struct wined3d_resource *resource, unsig - - HRESULT CDECL wined3d_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx) - { -+ HRESULT hr; - TRACE("resource %p, sub_resource_idx %u.\n", resource, sub_resource_idx); - -- return wined3d_cs_unmap(resource->device->cs, resource, sub_resource_idx); -+ if (FAILED(hr = resource->resource_ops->resource_sub_resource_unmap(resource, sub_resource_idx))) -+ { -+ TRACE_(d3d_perf)("Unmapping resource %p on the command stream.\n", resource); -+ hr = wined3d_cs_unmap(resource->device->cs, resource, sub_resource_idx); -+ } -+ return hr; - } - - UINT CDECL wined3d_resource_update_info(struct wined3d_resource *resource, unsigned int sub_resource_idx, -diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c -index 2f506c36d1..6f7805b8bd 100644 ---- a/dlls/wined3d/state.c -+++ b/dlls/wined3d/state.c -@@ -4934,7 +4934,11 @@ static void indexbuffer(struct wined3d_context *context, const struct wined3d_st - else - { - struct wined3d_buffer *ib = state->index_buffer; -- GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib->buffer_object)); -+ // FIXME(acomminos): disasterous. -+ if (ib->locations & WINED3D_LOCATION_PERSISTENT_MAP) -+ GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib->buffer_heap->buffer_object)); -+ else -+ GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib->buffer_object)); - } - } - -@@ -5000,6 +5004,7 @@ static void state_cb(struct wined3d_context *context, const struct wined3d_state - enum wined3d_shader_type shader_type; - struct wined3d_buffer *buffer; - unsigned int i, base, count; -+ struct wined3d_bo_address bo_addr; - - TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id); - -@@ -5012,7 +5017,15 @@ static void state_cb(struct wined3d_context *context, const struct wined3d_state - for (i = 0; i < count; ++i) - { - buffer = state->cb[shader_type][i]; -- GL_EXTCALL(glBindBufferBase(GL_UNIFORM_BUFFER, base + i, buffer ? buffer->buffer_object : 0)); -+ if (buffer) -+ { -+ wined3d_buffer_get_memory(buffer, &bo_addr, buffer->locations); -+ GL_EXTCALL(glBindBufferRange(GL_UNIFORM_BUFFER, base + i, bo_addr.buffer_object, bo_addr.addr, bo_addr.length)); -+ } -+ else -+ { -+ GL_EXTCALL(glBindBufferBase(GL_UNIFORM_BUFFER, base + i, 0)); -+ } - } - checkGLcall("bind constant buffers"); - } -diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c -index e6af0c7508..8ca1ee7158 100644 ---- a/dlls/wined3d/texture.c -+++ b/dlls/wined3d/texture.c -@@ -2301,6 +2301,12 @@ static void wined3d_texture_unload(struct wined3d_resource *resource) - - static HRESULT texture_resource_sub_resource_map(struct wined3d_resource *resource, unsigned int sub_resource_idx, - struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags) -+{ -+ return E_NOTIMPL; -+} -+ -+static HRESULT texture_resource_sub_resource_map_cs(struct wined3d_resource *resource, unsigned int sub_resource_idx, -+ struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags) - { - const struct wined3d_format *format = resource->format; - struct wined3d_texture_sub_resource *sub_resource; -@@ -2461,6 +2467,11 @@ static HRESULT texture_resource_sub_resource_map_info(struct wined3d_resource *r - } - - static HRESULT texture_resource_sub_resource_unmap(struct wined3d_resource *resource, unsigned int sub_resource_idx) -+{ -+ return E_NOTIMPL; -+} -+ -+static HRESULT texture_resource_sub_resource_unmap_cs(struct wined3d_resource *resource, unsigned int sub_resource_idx) - { - struct wined3d_texture_sub_resource *sub_resource; - struct wined3d_device *device = resource->device; -@@ -2512,7 +2523,9 @@ static const struct wined3d_resource_ops texture_resource_ops = - wined3d_texture_unload, - texture_resource_sub_resource_map, - texture_resource_sub_resource_map_info, -+ texture_resource_sub_resource_map_cs, - texture_resource_sub_resource_unmap, -+ texture_resource_sub_resource_unmap_cs, - }; - - static HRESULT texture1d_init(struct wined3d_texture *texture, const struct wined3d_resource_desc *desc, -diff --git a/dlls/wined3d/utils.c b/dlls/wined3d/utils.c -index b8b7880501..62758ae056 100644 ---- a/dlls/wined3d/utils.c -+++ b/dlls/wined3d/utils.c -@@ -6404,6 +6404,7 @@ const char *wined3d_debug_location(DWORD location) - LOCATION_TO_STR(WINED3D_LOCATION_DRAWABLE); - LOCATION_TO_STR(WINED3D_LOCATION_RB_MULTISAMPLE); - LOCATION_TO_STR(WINED3D_LOCATION_RB_RESOLVED); -+ LOCATION_TO_STR(WINED3D_LOCATION_PERSISTENT_MAP); - #undef LOCATION_TO_STR - if (location) - FIXME("Unrecognized location flag(s) %#x.\n", location); -diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h -index 3d535f4e17..6d32a368a2 100644 ---- a/dlls/wined3d/wined3d_private.h -+++ b/dlls/wined3d/wined3d_private.h -@@ -1470,6 +1470,7 @@ struct wined3d_bo_address - { - GLuint buffer_object; - BYTE *addr; -+ GLsizeiptr length; - }; - - struct wined3d_const_bo_address -@@ -3046,7 +3047,10 @@ struct wined3d_resource_ops - struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags); - HRESULT (*resource_map_info)(struct wined3d_resource *resource, unsigned int sub_resource_idx, - struct wined3d_map_info *info, DWORD flags); -+ HRESULT (*resource_sub_resource_map_cs)(struct wined3d_resource *resource, unsigned int sub_resource_idx, -+ struct wined3d_map_desc *map_desc, const struct wined3d_box *box, DWORD flags); - HRESULT (*resource_sub_resource_unmap)(struct wined3d_resource *resource, unsigned int sub_resource_idx); -+ HRESULT (*resource_sub_resource_unmap_cs)(struct wined3d_resource *resource, unsigned int sub_resource_idx); - }; - - struct wined3d_resource -@@ -3325,6 +3329,7 @@ void wined3d_texture_validate_location(struct wined3d_texture *texture, - #define WINED3D_LOCATION_DRAWABLE 0x00000040 - #define WINED3D_LOCATION_RB_MULTISAMPLE 0x00000080 - #define WINED3D_LOCATION_RB_RESOLVED 0x00000100 -+#define WINED3D_LOCATION_PERSISTENT_MAP 0x00000200 - - const char *wined3d_debug_location(DWORD location) DECLSPEC_HIDDEN; - -@@ -3672,6 +3677,7 @@ void wined3d_cs_emit_unload_resource(struct wined3d_cs *cs, struct wined3d_resou - void wined3d_cs_emit_update_sub_resource(struct wined3d_cs *cs, struct wined3d_resource *resource, - unsigned int sub_resource_idx, const struct wined3d_box *box, const void *data, unsigned int row_pitch, - unsigned int slice_pitch) DECLSPEC_HIDDEN; -+void wined3d_cs_emit_discard_buffer(struct wined3d_cs *cs, struct wined3d_buffer *buffer, struct wined3d_map_range map_range) DECLSPEC_HIDDEN; - void wined3d_cs_init_object(struct wined3d_cs *cs, - void (*callback)(void *object), void *object) DECLSPEC_HIDDEN; - HRESULT wined3d_cs_map(struct wined3d_cs *cs, struct wined3d_resource *resource, unsigned int sub_resource_idx, -@@ -3784,6 +3790,11 @@ struct wined3d_buffer - UINT stride; /* 0 if no conversion */ - enum wined3d_buffer_conversion_type *conversion_map; /* NULL if no conversion */ - UINT conversion_stride; /* 0 if no shifted conversion */ -+ -+ /* persistent mapped buffer */ -+ struct wined3d_buffer_heap *buffer_heap; -+ struct wined3d_map_range cs_persistent_map; -+ struct wined3d_map_range mt_persistent_map; // TODO: make struct list? - }; - - static inline struct wined3d_buffer *buffer_from_resource(struct wined3d_resource *resource) --- -2.16.2 - diff --git a/0003-wined3d-Use-ARB_multi_bind-to-speed-up-UBO-updates.patch b/0003-wined3d-Use-ARB_multi_bind-to-speed-up-UBO-updates.patch deleted file mode 100644 index b0de3a7183e1..000000000000 --- a/0003-wined3d-Use-ARB_multi_bind-to-speed-up-UBO-updates.patch +++ /dev/null @@ -1,121 +0,0 @@ -From d64aafc0ede047d1eff93ee7aa77411c0d27aa21 Mon Sep 17 00:00:00 2001 -From: Andrew Comminos <andrew@comminos.com> -Date: Mon, 5 Mar 2018 20:28:34 -0800 -Subject: [PATCH 3/5] wined3d: Use ARB_multi_bind to speed up UBO updates. - -More frequent UBO remaps as a result of the persistent buffer allocator -causes glBindBufferRange to be a bottleneck. Using ARB_multi_bind -massively reduces state change overhead. ---- - dlls/wined3d/directx.c | 4 ++++ - dlls/wined3d/state.c | 46 +++++++++++++++++++++++++++++++++++++++------- - dlls/wined3d/wined3d_gl.h | 1 + - 3 files changed, 44 insertions(+), 7 deletions(-) - -diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c -index 46c6a59536..8789a501ec 100644 ---- a/dlls/wined3d/directx.c -+++ b/dlls/wined3d/directx.c -@@ -149,6 +149,7 @@ static const struct wined3d_extension_map gl_extension_map[] = - {"GL_ARB_internalformat_query2", ARB_INTERNALFORMAT_QUERY2 }, - {"GL_ARB_map_buffer_alignment", ARB_MAP_BUFFER_ALIGNMENT }, - {"GL_ARB_map_buffer_range", ARB_MAP_BUFFER_RANGE }, -+ {"GL_ARB_multi_bind", ARB_MULTI_BIND }, - {"GL_ARB_multisample", ARB_MULTISAMPLE }, - {"GL_ARB_multitexture", ARB_MULTITEXTURE }, - {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY }, -@@ -2796,6 +2797,8 @@ static void load_gl_funcs(struct wined3d_gl_info *gl_info) - /* GL_ARB_map_buffer_range */ - USE_GL_FUNC(glFlushMappedBufferRange) - USE_GL_FUNC(glMapBufferRange) -+ /* GL_ARB_multi_bind */ -+ USE_GL_FUNC(glBindBuffersRange) - /* GL_ARB_multisample */ - USE_GL_FUNC(glSampleCoverageARB) - /* GL_ARB_multitexture */ -@@ -3973,6 +3976,7 @@ static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter, - {ARB_TEXTURE_VIEW, MAKEDWORD_VERSION(4, 3)}, - - {ARB_CLEAR_TEXTURE, MAKEDWORD_VERSION(4, 4)}, -+ {ARB_MULTI_BIND, MAKEDWORD_VERSION(4, 4)}, - - {ARB_CLIP_CONTROL, MAKEDWORD_VERSION(4, 5)}, - {ARB_CULL_DISTANCE, MAKEDWORD_VERSION(4, 5)}, -diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c -index 6f7805b8bd..4d0718514f 100644 ---- a/dlls/wined3d/state.c -+++ b/dlls/wined3d/state.c -@@ -5014,19 +5014,51 @@ static void state_cb(struct wined3d_context *context, const struct wined3d_state - shader_type = WINED3D_SHADER_TYPE_COMPUTE; - - wined3d_gl_limits_get_uniform_block_range(&gl_info->limits, shader_type, &base, &count); -- for (i = 0; i < count; ++i) -+ -+ if (gl_info->supported[ARB_MULTI_BIND]) - { -- buffer = state->cb[shader_type][i]; -- if (buffer) -+ GLuint buffer_objects[count]; -+ GLsizeiptr buffer_offsets[count]; -+ GLsizeiptr buffer_sizes[count]; -+ -+ for (i = 0; i < count; ++i) - { -- wined3d_buffer_get_memory(buffer, &bo_addr, buffer->locations); -- GL_EXTCALL(glBindBufferRange(GL_UNIFORM_BUFFER, base + i, bo_addr.buffer_object, bo_addr.addr, bo_addr.length)); -+ buffer = state->cb[shader_type][i]; -+ if (buffer) -+ { -+ wined3d_buffer_get_memory(buffer, &bo_addr, buffer->locations); -+ buffer_objects[i] = bo_addr.buffer_object; -+ buffer_offsets[i] = bo_addr.addr; -+ buffer_sizes[i] = bo_addr.length; -+ } -+ else -+ { -+ buffer_objects[i] = buffer_offsets[i] = 0; -+ // The ARB_multi_bind spec states that an error may be thrown if -+ // `size` is less than or equal to zero, Thus, we specify a size for -+ // unused buffers anyway. -+ buffer_sizes[i] = 1; -+ } - } -- else -+ GL_EXTCALL(glBindBuffersRange(GL_UNIFORM_BUFFER, base, count, buffer_objects, buffer_offsets, buffer_sizes)); -+ } -+ else -+ { -+ for (i = 0; i < count; ++i) - { -- GL_EXTCALL(glBindBufferBase(GL_UNIFORM_BUFFER, base + i, 0)); -+ buffer = state->cb[shader_type][i]; -+ if (buffer) -+ { -+ wined3d_buffer_get_memory(buffer, &bo_addr, buffer->locations); -+ GL_EXTCALL(glBindBufferRange(GL_UNIFORM_BUFFER, base + i, bo_addr.buffer_object, bo_addr.addr, bo_addr.length)); -+ } -+ else -+ { -+ GL_EXTCALL(glBindBufferBase(GL_UNIFORM_BUFFER, base + i, 0)); -+ } - } - } -+ - checkGLcall("bind constant buffers"); - } - -diff --git a/dlls/wined3d/wined3d_gl.h b/dlls/wined3d/wined3d_gl.h -index 7626864ef2..25c3301c94 100644 ---- a/dlls/wined3d/wined3d_gl.h -+++ b/dlls/wined3d/wined3d_gl.h -@@ -82,6 +82,7 @@ enum wined3d_gl_extension - ARB_INTERNALFORMAT_QUERY2, - ARB_MAP_BUFFER_ALIGNMENT, - ARB_MAP_BUFFER_RANGE, -+ ARB_MULTI_BIND, - ARB_MULTISAMPLE, - ARB_MULTITEXTURE, - ARB_OCCLUSION_QUERY, --- -2.16.2 - diff --git a/0004-wined3d-Use-GL_CLIENT_STORAGE_BIT-for-persistent-map.patch b/0004-wined3d-Use-GL_CLIENT_STORAGE_BIT-for-persistent-map.patch deleted file mode 100644 index 45c7ada812c6..000000000000 --- a/0004-wined3d-Use-GL_CLIENT_STORAGE_BIT-for-persistent-map.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 780cb020b7064eac55b1394aa6dbef2f11f2488a Mon Sep 17 00:00:00 2001 -From: Andrew Comminos <andrew@comminos.com> -Date: Tue, 6 Mar 2018 02:07:31 -0800 -Subject: [PATCH 4/5] wined3d: Use GL_CLIENT_STORAGE_BIT for persistent - mappings. - ---- - dlls/wined3d/buffer_heap.c | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/dlls/wined3d/buffer_heap.c b/dlls/wined3d/buffer_heap.c -index b133bd6893..75f84b0088 100644 ---- a/dlls/wined3d/buffer_heap.c -+++ b/dlls/wined3d/buffer_heap.c -@@ -169,7 +169,7 @@ HRESULT wined3d_buffer_heap_create(struct wined3d_context *context, GLsizeiptr s - { - access_flags |= GL_MAP_READ_BIT; - } -- storage_flags = access_flags; -+ storage_flags = GL_CLIENT_STORAGE_BIT | access_flags; - - // TODO(acomminos): where should we be checking for errors here? - GL_EXTCALL(glGenBuffers(1, &object->buffer_object)); --- -2.16.2 - diff --git a/0005-wined3d-Experimental-support-for-persistent-buffer-t.patch b/0005-wined3d-Experimental-support-for-persistent-buffer-t.patch deleted file mode 100644 index a039c7e622c8..000000000000 --- a/0005-wined3d-Experimental-support-for-persistent-buffer-t.patch +++ /dev/null @@ -1,180 +0,0 @@ -From 1e4c2e45a18a6eb445c507745f1c7b568c22aca6 Mon Sep 17 00:00:00 2001 -From: Andrew Comminos <andrew@comminos.com> -Date: Tue, 6 Mar 2018 15:58:05 -0800 -Subject: [PATCH 5/5] wined3d: Experimental support for persistent buffer - textures. - -Fixes missing models in Overwatch. ---- - dlls/wined3d/cs.c | 6 ++++ - dlls/wined3d/view.c | 79 +++++++++++++++++++++++++++++++++-------------------- - 2 files changed, 55 insertions(+), 30 deletions(-) - -diff --git a/dlls/wined3d/cs.c b/dlls/wined3d/cs.c -index e61b8dedbb..63cdb74e02 100644 ---- a/dlls/wined3d/cs.c -+++ b/dlls/wined3d/cs.c -@@ -2493,6 +2493,12 @@ static void wined3d_cs_exec_discard_buffer(struct wined3d_cs *cs, const void *da - device_invalidate_state(cs->device, STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE)); - } - -+ if (buffer->bind_flags & WINED3D_BIND_SHADER_RESOURCE) -+ { -+ device_invalidate_state(cs->device, STATE_GRAPHICS_SHADER_RESOURCE_BINDING); -+ device_invalidate_state(cs->device, STATE_COMPUTE_SHADER_RESOURCE_BINDING); -+ } -+ - wined3d_resource_release(&op->buffer->resource); - } - -diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c -index bed39dbc5f..100b3e34d8 100644 ---- a/dlls/wined3d/view.c -+++ b/dlls/wined3d/view.c -@@ -227,9 +227,7 @@ static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target - context_release(context); - } - --static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_context *context, -- struct wined3d_buffer *buffer, const struct wined3d_format *view_format, -- unsigned int offset, unsigned int size) -+static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_context *context) - { - const struct wined3d_gl_info *gl_info = context->gl_info; - -@@ -239,34 +237,58 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c - return; - } - -- if ((offset & (gl_info->limits.texture_buffer_offset_alignment - 1))) -+ view->target = GL_TEXTURE_BUFFER; -+ gl_info->gl_ops.gl.p_glGenTextures(1, &view->name); -+ -+ context_invalidate_compute_state(context, STATE_COMPUTE_SHADER_RESOURCE_BINDING); -+ context_invalidate_state(context, STATE_GRAPHICS_SHADER_RESOURCE_BINDING); -+} -+ -+static void bind_buffer_texture(struct wined3d_gl_view *view, struct wined3d_context *context, -+ struct wined3d_buffer *buffer, const struct wined3d_format *view_format, -+ unsigned int offset, unsigned int size) -+{ -+ const struct wined3d_gl_info *gl_info = context->gl_info; -+ struct wined3d_bo_address bo_addr; -+ unsigned int addr_offset; -+ -+ if (!wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER) && -+ !wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_PERSISTENT_MAP)) - { -- FIXME("Buffer offset %u is not %u byte aligned.\n", -- offset, gl_info->limits.texture_buffer_offset_alignment); -+ ERR("Failed to load a supported buffer location for %p.\n", buffer); - return; - } - -- wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER); - -- view->target = GL_TEXTURE_BUFFER; -- gl_info->gl_ops.gl.p_glGenTextures(1, &view->name); -+ if (FAILED(wined3d_buffer_get_memory(buffer, &bo_addr, buffer->locations))) -+ { -+ ERR("Failed to get buffer memory to create a buffer texture.\n"); -+ return; -+ } -+ -+ // TODO(acomminos): use a special heap for texture buffer alignment? -+ addr_offset = offset + bo_addr.addr; -+ -+ if ((addr_offset & (gl_info->limits.texture_buffer_offset_alignment - 1))) -+ { -+ FIXME("Buffer offset %u is not %u byte aligned.\n", -+ offset, gl_info->limits.texture_buffer_offset_alignment); -+ return; -+ } - -- context_bind_texture(context, GL_TEXTURE_BUFFER, view->name); - if (gl_info->supported[ARB_TEXTURE_BUFFER_RANGE]) - { - GL_EXTCALL(glTexBufferRange(GL_TEXTURE_BUFFER, view_format->glInternal, -- buffer->buffer_object, offset, size)); -+ bo_addr.buffer_object, addr_offset, size)); - } - else - { -- if (offset || size != buffer->resource.size) -+ if (addr_offset || size != buffer->resource.size) - FIXME("OpenGL implementation does not support ARB_texture_buffer_range.\n"); -- GL_EXTCALL(glTexBuffer(GL_TEXTURE_BUFFER, view_format->glInternal, buffer->buffer_object)); -+ GL_EXTCALL(glTexBuffer(GL_TEXTURE_BUFFER, view_format->glInternal, bo_addr.buffer_object)); - } -- checkGLcall("Create buffer texture"); -+ checkGLcall("Bind buffer texture"); - -- context_invalidate_compute_state(context, STATE_COMPUTE_SHADER_RESOURCE_BINDING); -- context_invalidate_state(context, STATE_GRAPHICS_SHADER_RESOURCE_BINDING); - } - - static void get_buffer_view_range(const struct wined3d_buffer *buffer, -@@ -285,16 +307,6 @@ static void get_buffer_view_range(const struct wined3d_buffer *buffer, - } - } - --static void create_buffer_view(struct wined3d_gl_view *view, struct wined3d_context *context, -- const struct wined3d_view_desc *desc, struct wined3d_buffer *buffer, -- const struct wined3d_format *view_format) --{ -- unsigned int offset, size; -- -- get_buffer_view_range(buffer, desc, view_format, &offset, &size); -- create_buffer_texture(view, context, buffer, view_format, offset, size); --} -- - static void wined3d_view_invalidate_location(struct wined3d_resource *resource, - const struct wined3d_view_desc *desc, DWORD location) - { -@@ -711,11 +723,10 @@ static void wined3d_shader_resource_view_cs_init(void *object) - - if (resource->type == WINED3D_RTYPE_BUFFER) - { -- struct wined3d_buffer *buffer = buffer_from_resource(resource); - struct wined3d_context *context; - - context = context_acquire(resource->device, NULL, 0); -- create_buffer_view(&view->gl_view, context, desc, buffer, view_format); -+ create_buffer_texture(&view->gl_view, context); - context_release(context); - } - else -@@ -814,7 +825,16 @@ void wined3d_shader_resource_view_bind(struct wined3d_shader_resource_view *view - - if (view->gl_view.name) - { -+ // XXX(acomminos): only rebind buffer texture range when needed (i.e. on discards) - context_bind_texture(context, view->gl_view.target, view->gl_view.name); -+ if (view->resource->type == WINED3D_RTYPE_BUFFER) -+ { -+ unsigned int offset, size; -+ struct wined3d_buffer *buffer = buffer_from_resource(view->resource); -+ get_buffer_view_range(buffer, &view->desc, view->format, &offset, &size); -+ bind_buffer_texture(&view->gl_view, context, buffer_from_resource(view->resource), view->format, offset, size); -+ } -+ - wined3d_sampler_bind(sampler, unit, NULL, context); - return; - } -@@ -1092,12 +1112,11 @@ static void wined3d_unordered_access_view_cs_init(void *object) - - if (resource->type == WINED3D_RTYPE_BUFFER) - { -- struct wined3d_buffer *buffer = buffer_from_resource(resource); - struct wined3d_context *context; - - context = context_acquire(resource->device, NULL, 0); - gl_info = context->gl_info; -- create_buffer_view(&view->gl_view, context, desc, buffer, view->format); -+ create_buffer_texture(&view->gl_view, context); - if (desc->flags & (WINED3D_VIEW_BUFFER_COUNTER | WINED3D_VIEW_BUFFER_APPEND)) - { - static const GLuint initial_value = 0; --- -2.16.2 - @@ -8,7 +8,7 @@ pkgname=wine-staging-pba pkgver=3.3 -pkgrel=1 +pkgrel=2 _pkgbasever=${pkgver/rc/-rc} @@ -17,26 +17,18 @@ source=(https://dl.winehq.org/wine/source/3.x/wine-$_pkgbasever.tar.xz{,.sign} harmony-fix.diff 30-win32-aliases.conf wine-binfmt.conf - 0001-wined3d-Initial-implementation-of-a-persistent-mappe.patch - 0002-wined3d-Add-support-for-backing-dynamic-wined3d_buff.patch - 0003-wined3d-Use-ARB_multi_bind-to-speed-up-UBO-updates.patch - 0004-wined3d-Use-GL_CLIENT_STORAGE_BIT-for-persistent-map.patch - 0005-wined3d-Experimental-support-for-persistent-buffer-t.patch) + "pba-patches::git+https://github.com/acomminos/wine-pba.git") sha512sums=('c9e4c75e94d745837208bf877b19c4e4e46df1e78082d21e716f52c9f9d93eaabbec8bf34783cda68e4275f53e37929b81ac128e5b8a13c1e5035223b2621d6a' 'SKIP' '02d48a9c403b93d01ca37b74af5dc81f86e49c72d67f194c71ccebd4556fa72c473728a1b1f9d5325c6f85f4e41bb7072a1183a2d81cafa8888e00dc53d12166' 'b86edf07bfc560f403fdfd5a71f97930ee2a4c3f76c92cc1a0dbb2e107be9db3bed3a727a0430d8a049583c63dd11f5d4567fb7aa69b193997c6da241acc4f2e' '6e54ece7ec7022b3c9d94ad64bdf1017338da16c618966e8baf398e6f18f80f7b0576edf1d1da47ed77b96d577e4cbb2bb0156b0b11c183a0accf22654b0a2bb' 'bdde7ae015d8a98ba55e84b86dc05aca1d4f8de85be7e4bd6187054bfe4ac83b5a20538945b63fb073caab78022141e9545685e4e3698c97ff173cf30859e285' - 'b68f09aa0688ba52e40dd9a22c99699d28b3e1a7028d1c39e5705cad345e17535d9b1066babf6881668be23ab43ca7ed0203aa5a287ed343ec4383b58358f6ab' - 'e7a1ab3ea00dc257de3dfdeab61df4dcd1ba3b448d3d323a5c7fed7da0b9a0ddb0b00eb6bc3f72b1fc1b10c61e181e8fe4f413a64b59d740371b2852686ce0c8' - '643b7575bd3e5a080c98e4435747942d39a072a662d26aefacec512263889dfda1fa154b77c6323d0cb69b5cab357258906cf17ad5013af09eda3d255706b5fe' - '095ad54ea35f2e8317ab42a24fb92cbc214c6c3b53be165a6ddec9ef31f97b989befac4a3b51a1fcfbf5ead11b0ab3ca57ac34ad41621e81fdaa96aed17815cb' - 'a58ae6201bfab1ddbda4d789054ce384434d4eb5e3d5845e995caa81b41c2814bb625216ce09c0e4bae92e3e6a45771d28ee4ef09b7c587cd56ec17d577a37a8') + 'SKIP') validpgpkeys=(5AC1A08B03BD7A313E0A955AF5E6E9EEB9461DD7 DA23579A74D4AD9AF9D3F945CEFAC8EAAF17519D) -pkgdesc="A compatibility layer for running Windows programs - Staging branch" +pkgdesc="A compatibility layer for running Windows programs - Staging branch with PBA patches" url="http://www.wine-staging.com" arch=(x86_64) options=(staticlibs) @@ -134,11 +126,13 @@ prepare() { patch -d $pkgname -Np1 < harmony-fix.diff - patch -d $pkgname -Np1 < 0001-wined3d-Initial-implementation-of-a-persistent-mappe.patch - patch -d $pkgname -Np1 < 0002-wined3d-Add-support-for-backing-dynamic-wined3d_buff.patch - patch -d $pkgname -Np1 < 0003-wined3d-Use-ARB_multi_bind-to-speed-up-UBO-updates.patch - patch -d $pkgname -Np1 < 0004-wined3d-Use-GL_CLIENT_STORAGE_BIT-for-persistent-map.patch - patch -d $pkgname -Np1 < 0005-wined3d-Experimental-support-for-persistent-buffer-t.patch + pushd pba-patches + git checkout 4b64220635c9eb0aeee34c451421085d1a71bb6b + popd + + for f in $(ls pba-patches/patches); do + patch -d $pkgname -Np1 < "pba-patches/patches/${f}" + done sed 's|OpenCL/opencl.h|CL/opencl.h|g' -i $pkgname/configure* |