From 8af55b60fa87bb0fb21afd17e3467253b53e61a1 Mon Sep 17 00:00:00 2001 From: Andrew Comminos Date: Thu, 15 Mar 2018 21:07:21 -0700 Subject: [PATCH 8/9] wined3d: Add DISABLE_PBA envvar, some PBA cleanup. --- dlls/wined3d/buffer.c | 4 ++-- dlls/wined3d/buffer_heap.c | 34 ++++++++++++++++++++++++++-------- dlls/wined3d/device.c | 38 ++++++++++++++++++++++++++------------ dlls/wined3d/query.c | 2 +- dlls/wined3d/wined3d_private.h | 6 ++---- 5 files changed, 57 insertions(+), 27 deletions(-) diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c index 74b3ba8abd..651d9a4360 100644 --- a/dlls/wined3d/buffer.c +++ b/dlls/wined3d/buffer.c @@ -1603,9 +1603,9 @@ static HRESULT buffer_init(struct wined3d_buffer *buffer, struct wined3d_device if (buffer->resource.usage & WINED3DUSAGE_DYNAMIC) { - if (!gl_info->supported[ARB_BUFFER_STORAGE]) + if (!device->use_pba) { - WARN_(d3d_perf)("Not creating a persistent mapping for a dynamic buffer because ARB_buffer_storage is unsupported.\n"); + WARN_(d3d_perf)("Not creating a persistent mapping for dynamic buffer %p because the PBA is disabled.\n", buffer); } else if (bind_flags & WINED3D_BIND_SHADER_RESOURCE) { diff --git a/dlls/wined3d/buffer_heap.c b/dlls/wined3d/buffer_heap.c index 80670c515f..899aad9612 100644 --- a/dlls/wined3d/buffer_heap.c +++ b/dlls/wined3d/buffer_heap.c @@ -25,6 +25,9 @@ WINE_DEFAULT_DEBUG_CHANNEL(d3d); WINE_DECLARE_DEBUG_CHANNEL(d3d_perf); +// Arbitrary binding to use when binding the persistent buffer. +#define BIND_TARGET GL_ARRAY_BUFFER + struct wined3d_buffer_heap_fenced_element { struct wined3d_buffer_heap_bin_set free_list; @@ -140,7 +143,6 @@ static int free_tree_compare(const void *key, const struct wine_rb_entry *entry) 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; @@ -162,22 +164,23 @@ HRESULT wined3d_buffer_heap_create(struct wined3d_context *context, GLsizeiptr s { access_flags |= GL_MAP_READ_BIT; } + 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)); + checkGLcall("glGenBuffers"); - context_bind_bo(context, buffer_target, object->buffer_object); + context_bind_bo(context, BIND_TARGET, object->buffer_object); - // TODO(acomminos): assert glBufferStorage supported? - GL_EXTCALL(glBufferStorage(buffer_target, size, NULL, storage_flags)); + GL_EXTCALL(glBufferStorage(BIND_TARGET, size, NULL, storage_flags)); + checkGLcall("glBufferStorage"); - if (!(object->map_ptr = GL_EXTCALL(glMapBufferRange(buffer_target, 0, size, access_flags)))) + if (!(object->map_ptr = GL_EXTCALL(glMapBufferRange(BIND_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); + context_bind_bo(context, BIND_TARGET, 0); object->fenced_head = object->fenced_tail = NULL; object->alignment = alignment; @@ -195,7 +198,22 @@ HRESULT wined3d_buffer_heap_create(struct wined3d_context *context, GLsizeiptr s /* 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"); + const struct wined3d_gl_info *gl_info = context->gl_info; + + context_bind_bo(context, BIND_TARGET, heap->buffer_object); + GL_EXTCALL(glUnmapBuffer(BIND_TARGET)); + checkGLcall("glUnmapBuffer"); + context_bind_bo(context, BIND_TARGET, 0); + + GL_EXTCALL(glDeleteBuffers(1, &heap->buffer_object)); + checkGLcall("glDeleteBuffers"); + + DeleteCriticalSection(&heap->temp_lock); + + // TODO(acomminos): cleanup free lists, fenced list, etc. + + HeapFree(GetProcessHeap(), 0, heap); + return WINED3D_OK; } diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c index 785841a062..f4c9dc7bd6 100644 --- a/dlls/wined3d/device.c +++ b/dlls/wined3d/device.c @@ -837,16 +837,27 @@ static void destroy_default_samplers(struct wined3d_device *device, struct wined 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; + BOOL use_pba = FALSE; + char *env_pba_disable; - if (gl_info->supported[ARB_BUFFER_STORAGE]) + if (!gl_info->supported[ARB_BUFFER_STORAGE]) + { + FIXME("Not using PBA, ARB_buffer_storage unsupported.\n"); + } + else if ((env_pba_disable = getenv("PBA_DISABLE")) && *env_pba_disable != '0') { + FIXME("Not using PBA, envvar 'PBA_DISABLE' set.\n"); + } + else + { + // 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; + 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). @@ -855,19 +866,22 @@ static void create_buffer_heap(struct wined3d_device *device, struct wined3d_con 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); + goto fail; } 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); + goto fail; } FIXME("Initialized PBA (geo_heap_size: %ld, cb_heap_size: %ld, ub_align: %d)\n", geo_heap_size, cb_heap_size, ub_alignment); + + use_pba = TRUE; } - else - { - FIXME("Not using PBA, ARB_buffer_storage unsupported.\n"); - } + +fail: + device->use_pba = use_pba; } /* Context activation is done by the caller. */ diff --git a/dlls/wined3d/query.c b/dlls/wined3d/query.c index f3ca1630e5..5ea79b6e4a 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]; } -enum wined3d_fence_result wined3d_fence_test(const struct wined3d_fence *fence, +static 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_private.h b/dlls/wined3d/wined3d_private.h index 0114444943..63f004d57e 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -1713,9 +1713,6 @@ 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 @@ -2943,6 +2940,7 @@ BYTE inScene : 1; /* A flag to check for proper BeginScene / EndScene call pairs */ BYTE softwareVertexProcessing : 1; /* process vertex shaders using software or hardware */ BYTE filter_messages : 1; + BYTE use_pba : 1; /* A flag to use the persistent buffer allocator for dynamic buffers. */ BYTE padding : 3; unsigned char surface_alignment; /* Line Alignment of surfaces */ -- 2.16.2