[PATCH 4/5] wined3d: Use GL_ARB_buffer_storage if available.

Henri Verbeet hverbeet at codeweavers.com
Mon Nov 30 08:41:24 CST 2020


From: Matteo Bruni <mbruni at codeweavers.com>

Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/wined3d/buffer.c          |  4 +++-
 dlls/wined3d/context_gl.c      | 11 +++++++----
 dlls/wined3d/resource.c        | 15 +++++++++++++++
 dlls/wined3d/texture.c         |  4 ++--
 dlls/wined3d/view.c            |  4 ++--
 dlls/wined3d/wined3d_private.h |  5 +++--
 6 files changed, 32 insertions(+), 11 deletions(-)

diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index 285ae7231ec..61e35dc1e45 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -201,6 +201,7 @@ static BOOL wined3d_buffer_gl_create_buffer_object(struct wined3d_buffer_gl *buf
 {
     const struct wined3d_gl_info *gl_info = context_gl->gl_info;
     GLenum usage = GL_STATIC_DRAW;
+    GLbitfield gl_storage_flags;
     struct wined3d_bo_gl *bo;
     bool coherent = true;
     GLsizeiptr size;
@@ -216,8 +217,9 @@ static BOOL wined3d_buffer_gl_create_buffer_object(struct wined3d_buffer_gl *buf
         usage = GL_STREAM_DRAW_ARB;
         coherent = false;
     }
+    gl_storage_flags = wined3d_resource_gl_storage_flags(&buffer_gl->b.resource);
     bo = &buffer_gl->bo;
-    if (!wined3d_context_gl_create_bo(context_gl, size, binding, usage, coherent, bo))
+    if (!wined3d_context_gl_create_bo(context_gl, size, binding, usage, coherent, gl_storage_flags, bo))
     {
         ERR("Failed to create OpenGL buffer object.\n");
         buffer_gl->b.flags &= ~WINED3D_BUFFER_USE_BO;
diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c
index 567d6ba56b7..12e5e088713 100644
--- a/dlls/wined3d/context_gl.c
+++ b/dlls/wined3d/context_gl.c
@@ -2694,13 +2694,13 @@ void wined3d_context_gl_destroy_bo(struct wined3d_context_gl *context_gl, struct
 }
 
 bool wined3d_context_gl_create_bo(struct wined3d_context_gl *context_gl, GLsizeiptr size,
-        GLenum binding, GLenum usage, bool coherent, struct wined3d_bo_gl *bo)
+        GLenum binding, GLenum usage, bool coherent, GLbitfield flags, struct wined3d_bo_gl *bo)
 {
     const struct wined3d_gl_info *gl_info = context_gl->gl_info;
     GLuint id = 0;
 
-    TRACE("context_gl %p, size %lu, binding %#x, usage %#x, coherent %#x, bo %p.\n",
-            context_gl, size, binding, usage, coherent, bo);
+    TRACE("context_gl %p, size %lu, binding %#x, usage %#x, coherent %#x, flags %#x, bo %p.\n",
+            context_gl, size, binding, usage, coherent, flags, bo);
 
     GL_EXTCALL(glGenBuffers(1, &id));
     if (!id)
@@ -2716,7 +2716,10 @@ bool wined3d_context_gl_create_bo(struct wined3d_context_gl *context_gl, GLsizei
         GL_EXTCALL(glBufferParameteriAPPLE(binding, GL_BUFFER_SERIALIZED_MODIFY_APPLE, GL_FALSE));
     }
 
-    GL_EXTCALL(glBufferData(binding, size, NULL, usage));
+    if (gl_info->supported[ARB_BUFFER_STORAGE])
+        GL_EXTCALL(glBufferStorage(binding, size, NULL, flags | GL_DYNAMIC_STORAGE_BIT));
+    else
+        GL_EXTCALL(glBufferData(binding, size, NULL, usage));
 
     wined3d_context_gl_bind_bo(context_gl, binding, 0);
     checkGLcall("buffer object creation");
diff --git a/dlls/wined3d/resource.c b/dlls/wined3d/resource.c
index c8d5fecf9d9..97b8b68374d 100644
--- a/dlls/wined3d/resource.c
+++ b/dlls/wined3d/resource.c
@@ -428,6 +428,21 @@ void wined3d_resource_free_sysmem(struct wined3d_resource *resource)
     resource->heap_memory = NULL;
 }
 
+GLbitfield wined3d_resource_gl_storage_flags(const struct wined3d_resource *resource)
+{
+    uint32_t access = resource->access;
+    GLbitfield flags = 0;
+
+    if (resource->usage & WINED3DUSAGE_DYNAMIC)
+        flags |= GL_CLIENT_STORAGE_BIT;
+    if (access & WINED3D_RESOURCE_ACCESS_MAP_W)
+        flags |= GL_MAP_WRITE_BIT;
+    if (access & WINED3D_RESOURCE_ACCESS_MAP_R)
+        flags |= GL_MAP_READ_BIT;
+
+    return flags;
+}
+
 GLbitfield wined3d_resource_gl_map_flags(DWORD d3d_flags)
 {
     GLbitfield ret = 0;
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index b311df0f896..b84b68c592b 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -1924,8 +1924,8 @@ static void wined3d_texture_gl_prepare_buffer_object(struct wined3d_texture_gl *
     if (bo->id)
         return;
 
-    if (!wined3d_context_gl_create_bo(context_gl, sub_resource->size,
-            GL_PIXEL_UNPACK_BUFFER, GL_STREAM_DRAW, true, bo))
+    if (!wined3d_context_gl_create_bo(context_gl, sub_resource->size, GL_PIXEL_UNPACK_BUFFER,
+            GL_STREAM_DRAW, true, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_CLIENT_STORAGE_BIT, bo))
         return;
 
     TRACE("Created buffer object %u for texture %p, sub-resource %u.\n", bo->id, texture_gl, sub_resource_idx);
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index 1d77b0e44fb..4c85e2fefe4 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -1415,8 +1415,8 @@ static void wined3d_unordered_access_view_gl_cs_init(void *object)
             struct wined3d_bo_gl *bo = &view_gl->counter_bo;
 
             view_gl->v.counter_bo = (uintptr_t)bo;
-            wined3d_context_gl_create_bo(context_gl, sizeof(uint32_t),
-                    GL_ATOMIC_COUNTER_BUFFER, GL_STATIC_DRAW, true, bo);
+            wined3d_context_gl_create_bo(context_gl, sizeof(uint32_t), GL_ATOMIC_COUNTER_BUFFER,
+                    GL_STATIC_DRAW, true, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_CLIENT_STORAGE_BIT, bo);
             wined3d_unordered_access_view_set_counter(&view_gl->v, 0);
         }
         context_release(&context_gl->c);
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 9b12295ec52..3dcd3e26846 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2256,8 +2256,8 @@ void wined3d_context_gl_bind_texture(struct wined3d_context_gl *context_gl,
 void wined3d_context_gl_check_fbo_status(const struct wined3d_context_gl *context_gl, GLenum target) DECLSPEC_HIDDEN;
 void wined3d_context_gl_copy_bo_address(struct wined3d_context_gl *context_gl,
         const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src, size_t size) DECLSPEC_HIDDEN;
-bool wined3d_context_gl_create_bo(struct wined3d_context_gl *context_gl, GLsizeiptr size,
-        GLenum binding, GLenum usage, bool coherent, struct wined3d_bo_gl *bo) DECLSPEC_HIDDEN;
+bool wined3d_context_gl_create_bo(struct wined3d_context_gl *context_gl, GLsizeiptr size, GLenum binding,
+        GLenum usage, bool coherent, GLbitfield flags, struct wined3d_bo_gl *bo) DECLSPEC_HIDDEN;
 void wined3d_context_gl_destroy(struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
 void wined3d_context_gl_destroy_bo(struct wined3d_context_gl *context_gl, struct wined3d_bo_gl *bo) DECLSPEC_HIDDEN;
 void wined3d_context_gl_draw_shaded_quad(struct wined3d_context_gl *context_gl, struct wined3d_texture_gl *texture_gl,
@@ -4049,6 +4049,7 @@ const struct wined3d_format *wined3d_resource_get_decompress_format(
 unsigned int wined3d_resource_get_sample_count(const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
 GLbitfield wined3d_resource_gl_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN;
 GLenum wined3d_resource_gl_legacy_map_flags(DWORD d3d_flags) DECLSPEC_HIDDEN;
+GLbitfield wined3d_resource_gl_storage_flags(const struct wined3d_resource *resource) DECLSPEC_HIDDEN;
 BOOL wined3d_resource_is_offscreen(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
 BOOL wined3d_resource_prepare_sysmem(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
 void wined3d_resource_update_draw_binding(struct wined3d_resource *resource) DECLSPEC_HIDDEN;
-- 
2.20.1




More information about the wine-devel mailing list