[PATCH 1/5] wined3d: Introduce a structure for OpenGL buffer objects.

Henri Verbeet hverbeet at codeweavers.com
Tue Apr 21 13:07:09 CDT 2020


Analogous to the wined3d_bo_vk structure for Vulkan.

Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/wined3d/adapter_gl.c      | 12 +++--
 dlls/wined3d/buffer.c          | 16 +++----
 dlls/wined3d/context_gl.c      | 84 +++++++++++++++++++---------------
 dlls/wined3d/state.c           |  6 +--
 dlls/wined3d/surface.c         |  2 +-
 dlls/wined3d/texture.c         | 61 ++++++++++++------------
 dlls/wined3d/view.c            | 39 ++++++++--------
 dlls/wined3d/wined3d_private.h | 20 +++++++-
 8 files changed, 135 insertions(+), 105 deletions(-)

diff --git a/dlls/wined3d/adapter_gl.c b/dlls/wined3d/adapter_gl.c
index a1170fa12db..49b9c7bcd97 100644
--- a/dlls/wined3d/adapter_gl.c
+++ b/dlls/wined3d/adapter_gl.c
@@ -4825,7 +4825,7 @@ struct wined3d_view_gl_destroy_ctx
 {
     struct wined3d_device *device;
     const struct wined3d_gl_view *gl_view;
-    GLuint *counter_bo;
+    struct wined3d_bo_gl *counter_bo;
     void *object;
     struct wined3d_view_gl_destroy_ctx *free;
 };
@@ -4836,10 +4836,12 @@ static void wined3d_view_gl_destroy_object(void *object)
     const struct wined3d_gl_info *gl_info;
     struct wined3d_context *context;
     struct wined3d_device *device;
+    GLuint counter_id;
 
     device = ctx->device;
 
-    if (ctx->gl_view->name || ctx->counter_bo)
+    counter_id = ctx->counter_bo ? ctx->counter_bo->id : 0;
+    if (ctx->gl_view->name || counter_id)
     {
         context = context_acquire(device, NULL, 0);
         gl_info = wined3d_context_gl(context)->gl_info;
@@ -4848,8 +4850,8 @@ static void wined3d_view_gl_destroy_object(void *object)
             context_gl_resource_released(device, ctx->gl_view->name, FALSE);
             gl_info->gl_ops.gl.p_glDeleteTextures(1, &ctx->gl_view->name);
         }
-        if (ctx->counter_bo)
-            GL_EXTCALL(glDeleteBuffers(1, ctx->counter_bo));
+        if (counter_id)
+            GL_EXTCALL(glDeleteBuffers(1, &counter_id));
         checkGLcall("delete resources");
         context_release(context);
     }
@@ -4859,7 +4861,7 @@ static void wined3d_view_gl_destroy_object(void *object)
 }
 
 static void wined3d_view_gl_destroy(struct wined3d_device *device,
-        const struct wined3d_gl_view *gl_view, GLuint *counter_bo, void *object)
+        const struct wined3d_gl_view *gl_view, struct wined3d_bo_gl *counter_bo, void *object)
 {
     struct wined3d_view_gl_destroy_ctx *ctx, c;
 
diff --git a/dlls/wined3d/buffer.c b/dlls/wined3d/buffer.c
index 8c4ca425451..b7ba2be16d1 100644
--- a/dlls/wined3d/buffer.c
+++ b/dlls/wined3d/buffer.c
@@ -135,7 +135,7 @@ void wined3d_buffer_invalidate_location(struct wined3d_buffer *buffer, DWORD loc
 /* Context activation is done by the caller. */
 static void wined3d_buffer_gl_bind(struct wined3d_buffer_gl *buffer_gl, struct wined3d_context_gl *context_gl)
 {
-    wined3d_context_gl_bind_bo(context_gl, buffer_gl->buffer_type_hint, buffer_gl->b.buffer_object);
+    wined3d_context_gl_bind_bo(context_gl, buffer_gl->buffer_type_hint, buffer_gl->bo.id);
 }
 
 /* Context activation is done by the caller. */
@@ -146,7 +146,6 @@ static void wined3d_buffer_gl_destroy_buffer_object(struct wined3d_buffer_gl *bu
     struct wined3d_resource *resource = &buffer_gl->b.resource;
     struct wined3d_buffer *buffer = &buffer_gl->b;
     struct wined3d_cs *cs = resource->device->cs;
-    GLuint bo;
 
     if (!buffer_gl->b.buffer_object)
         return;
@@ -186,10 +185,10 @@ static void wined3d_buffer_gl_destroy_buffer_object(struct wined3d_buffer_gl *bu
         }
     }
 
-    bo = buffer_gl->b.buffer_object;
-    GL_EXTCALL(glDeleteBuffers(1, &bo));
+    GL_EXTCALL(glDeleteBuffers(1, &buffer_gl->bo.id));
     checkGLcall("glDeleteBuffers");
     buffer_gl->b.buffer_object = 0;
+    buffer_gl->bo.id = 0;
 
     if (buffer_gl->b.fence)
     {
@@ -205,8 +204,8 @@ 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 gl_usage = GL_STATIC_DRAW;
+    struct wined3d_bo_gl *bo;
     GLenum error;
-    GLuint bo;
 
     TRACE("Creating an OpenGL buffer object for wined3d buffer %p with usage %s.\n",
             buffer_gl, debug_d3dusage(buffer_gl->b.resource.usage));
@@ -224,10 +223,11 @@ static BOOL wined3d_buffer_gl_create_buffer_object(struct wined3d_buffer_gl *buf
      * to be verified to check if the rhw and color values are in the correct
      * format. */
 
-    GL_EXTCALL(glGenBuffers(1, &bo));
-    buffer_gl->b.buffer_object = bo;
+    bo = &buffer_gl->bo;
+    GL_EXTCALL(glGenBuffers(1, &bo->id));
+    buffer_gl->b.buffer_object = (uintptr_t)bo;
     error = gl_info->gl_ops.gl.p_glGetError();
-    if (!buffer_gl->b.buffer_object || error != GL_NO_ERROR)
+    if (!bo->id || error != GL_NO_ERROR)
     {
         ERR("Failed to create a BO with error %s (%#x).\n", debug_glerror(error), error);
         goto fail;
diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c
index 9dbd0346ff3..f435c7e7607 100644
--- a/dlls/wined3d/context_gl.c
+++ b/dlls/wined3d/context_gl.c
@@ -2528,13 +2528,14 @@ void *wined3d_context_gl_map_bo_address(struct wined3d_context_gl *context_gl,
         const struct wined3d_bo_address *data, size_t size, GLenum binding, DWORD flags)
 {
     const struct wined3d_gl_info *gl_info;
+    struct wined3d_bo_gl *bo;
     BYTE *memory;
 
-    if (!data->buffer_object)
+    if (!(bo = (struct wined3d_bo_gl *)data->buffer_object))
         return data->addr;
 
     gl_info = context_gl->gl_info;
-    wined3d_context_gl_bind_bo(context_gl, binding, data->buffer_object);
+    wined3d_context_gl_bind_bo(context_gl, binding, bo->id);
 
     if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
     {
@@ -2557,13 +2558,14 @@ void wined3d_context_gl_unmap_bo_address(struct wined3d_context_gl *context_gl,
         GLenum binding, unsigned int range_count, const struct wined3d_range *ranges)
 {
     const struct wined3d_gl_info *gl_info;
+    struct wined3d_bo_gl *bo;
     unsigned int i;
 
-    if (!data->buffer_object)
+    if (!(bo = (struct wined3d_bo_gl *)data->buffer_object))
         return;
 
     gl_info = context_gl->gl_info;
-    wined3d_context_gl_bind_bo(context_gl, binding, data->buffer_object);
+    wined3d_context_gl_bind_bo(context_gl, binding, bo->id);
 
     if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
     {
@@ -2583,17 +2585,20 @@ void wined3d_context_gl_copy_bo_address(struct wined3d_context_gl *context_gl,
         const struct wined3d_bo_address *src, GLenum src_binding, size_t size)
 {
     const struct wined3d_gl_info *gl_info;
+    struct wined3d_bo_gl *src_bo, *dst_bo;
     struct wined3d_range range;
     BYTE *dst_ptr, *src_ptr;
 
     gl_info = context_gl->gl_info;
+    src_bo = (struct wined3d_bo_gl *)src->buffer_object;
+    dst_bo = (struct wined3d_bo_gl *)dst->buffer_object;
 
-    if (dst->buffer_object && src->buffer_object)
+    if (dst_bo && src_bo)
     {
         if (gl_info->supported[ARB_COPY_BUFFER])
         {
-            GL_EXTCALL(glBindBuffer(GL_COPY_READ_BUFFER, src->buffer_object));
-            GL_EXTCALL(glBindBuffer(GL_COPY_WRITE_BUFFER, dst->buffer_object));
+            GL_EXTCALL(glBindBuffer(GL_COPY_READ_BUFFER, src_bo->id));
+            GL_EXTCALL(glBindBuffer(GL_COPY_WRITE_BUFFER, dst_bo->id));
             GL_EXTCALL(glCopyBufferSubData(GL_COPY_READ_BUFFER, GL_COPY_WRITE_BUFFER,
                     (GLintptr)src->addr, (GLintptr)dst->addr, size));
             checkGLcall("direct buffer copy");
@@ -2611,15 +2616,15 @@ void wined3d_context_gl_copy_bo_address(struct wined3d_context_gl *context_gl,
             wined3d_context_gl_unmap_bo_address(context_gl, src, src_binding, 0, NULL);
         }
     }
-    else if (!dst->buffer_object && src->buffer_object)
+    else if (!dst_bo && src_bo)
     {
-        wined3d_context_gl_bind_bo(context_gl, src_binding, src->buffer_object);
+        wined3d_context_gl_bind_bo(context_gl, src_binding, src_bo->id);
         GL_EXTCALL(glGetBufferSubData(src_binding, (GLintptr)src->addr, size, dst->addr));
         checkGLcall("buffer download");
     }
-    else if (dst->buffer_object && !src->buffer_object)
+    else if (dst_bo && !src_bo)
     {
-        wined3d_context_gl_bind_bo(context_gl, dst_binding, dst->buffer_object);
+        wined3d_context_gl_bind_bo(context_gl, dst_binding, dst_bo->id);
         GL_EXTCALL(glBufferSubData(dst_binding, (GLintptr)dst->addr, size, src->addr));
         checkGLcall("buffer upload");
     }
@@ -3489,8 +3494,8 @@ static void wined3d_context_gl_bind_unordered_access_views(struct wined3d_contex
         GL_EXTCALL(glBindImageTexture(i, texture_name, level, GL_TRUE, 0, GL_READ_WRITE,
                 format_gl->internal));
 
-        if (view_gl->counter_bo)
-            GL_EXTCALL(glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, i, view_gl->counter_bo));
+        if (view_gl->counter_bo.id)
+            GL_EXTCALL(glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, i, view_gl->counter_bo.id));
     }
     checkGLcall("Bind unordered access views");
 }
@@ -3908,9 +3913,9 @@ void dispatch_compute(struct wined3d_device *device, const struct wined3d_state
     if (parameters->indirect)
     {
         const struct wined3d_indirect_dispatch_parameters *indirect = &parameters->u.indirect;
-        struct wined3d_buffer *buffer = indirect->buffer;
+        struct wined3d_buffer_gl *buffer_gl = wined3d_buffer_gl(indirect->buffer);
 
-        GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, buffer->buffer_object));
+        GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, buffer_gl->bo.id));
         GL_EXTCALL(glDispatchComputeIndirect((GLintptr)indirect->offset));
         GL_EXTCALL(glBindBuffer(GL_DISPATCH_INDIRECT_BUFFER, 0));
     }
@@ -4303,7 +4308,7 @@ static void wined3d_context_gl_draw_indirect(struct wined3d_context_gl *context_
         return;
     }
 
-    GL_EXTCALL(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buffer->buffer_object));
+    GL_EXTCALL(glBindBuffer(GL_DRAW_INDIRECT_BUFFER, wined3d_buffer_gl(buffer)->bo.id));
 
     offset = (void *)(GLintptr)parameters->offset;
     if (idx_size)
@@ -4662,6 +4667,7 @@ void wined3d_context_gl_load_tex_coords(const struct wined3d_context_gl *context
     const struct wined3d_format_gl *format_gl;
     unsigned int mapped_stage = 0;
     unsigned int texture_idx;
+    GLuint bo;
 
     for (texture_idx = 0; texture_idx < context_gl->c.d3d_info->limits.ffp_blend_stages; ++texture_idx)
     {
@@ -4683,11 +4689,12 @@ void wined3d_context_gl_load_tex_coords(const struct wined3d_context_gl *context
             TRACE("Setting up texture %u, idx %u, coord_idx %u, data %s.\n",
                     texture_idx, mapped_stage, coord_idx, debug_bo_address(&e->data));
 
-            if (*current_bo != e->data.buffer_object)
+            bo = wined3d_bo_gl_id(e->data.buffer_object);
+            if (*current_bo != bo)
             {
-                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
+                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
                 checkGLcall("glBindBuffer");
-                *current_bo = e->data.buffer_object;
+                *current_bo = bo;
             }
 
             GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
@@ -4738,7 +4745,7 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte
     const struct wined3d_gl_info *gl_info = context_gl->gl_info;
     const struct wined3d_stream_info_element *e;
     const struct wined3d_format_gl *format_gl;
-    GLuint current_bo;
+    GLuint current_bo, bo;
 
     TRACE("context_gl %p, si %p, state %p.\n", context_gl, si, state);
 
@@ -4770,11 +4777,12 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte
         e = &si->elements[WINED3D_FFP_POSITION];
         format_gl = wined3d_format_gl(e->format);
 
-        if (current_bo != e->data.buffer_object)
+        bo = wined3d_bo_gl_id(e->data.buffer_object);
+        if (current_bo != bo)
         {
-            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
+            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
             checkGLcall("glBindBuffer");
-            current_bo = e->data.buffer_object;
+            current_bo = bo;
         }
 
         TRACE("glVertexPointer(%#x, %#x, %#x, %p);\n",
@@ -4793,11 +4801,12 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte
         e = &si->elements[WINED3D_FFP_NORMAL];
         format_gl = wined3d_format_gl(e->format);
 
-        if (current_bo != e->data.buffer_object)
+        bo = wined3d_bo_gl_id(e->data.buffer_object);
+        if (current_bo != bo)
         {
-            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
+            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
             checkGLcall("glBindBuffer");
-            current_bo = e->data.buffer_object;
+            current_bo = bo;
         }
 
         TRACE("glNormalPointer(%#x, %#x, %p);\n", format_gl->vtx_type, e->stride,
@@ -4821,11 +4830,12 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte
         e = &si->elements[WINED3D_FFP_DIFFUSE];
         format_gl = wined3d_format_gl(e->format);
 
-        if (current_bo != e->data.buffer_object)
+        bo = wined3d_bo_gl_id(e->data.buffer_object);
+        if (current_bo != bo)
         {
-            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
+            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
             checkGLcall("glBindBuffer");
-            current_bo = e->data.buffer_object;
+            current_bo = bo;
         }
 
         TRACE("glColorPointer(%#x, %#x %#x, %p);\n",
@@ -4860,11 +4870,12 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte
             type = format_gl->vtx_type;
             format = format_gl->vtx_format;
 
-            if (current_bo != e->data.buffer_object)
+            bo = wined3d_bo_gl_id(e->data.buffer_object);
+            if (current_bo != bo)
             {
-                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, e->data.buffer_object));
+                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
                 checkGLcall("glBindBuffer");
-                current_bo = e->data.buffer_object;
+                current_bo = bo;
             }
 
             if (format != 4 || (gl_info->quirks & WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA))
@@ -4957,7 +4968,7 @@ static void wined3d_context_gl_load_numbered_arrays(struct wined3d_context_gl *c
     struct wined3d_context *context = &context_gl->c;
     const struct wined3d_shader *vs = state->shader[WINED3D_SHADER_TYPE_VERTEX];
     const struct wined3d_gl_info *gl_info = context_gl->gl_info;
-    GLuint current_bo;
+    GLuint current_bo, bo;
     unsigned int i;
 
     /* Default to no instancing. */
@@ -5021,11 +5032,12 @@ static void wined3d_context_gl_load_numbered_arrays(struct wined3d_context_gl *c
         {
             DWORD format_flags = format_gl->f.flags[WINED3D_GL_RES_TYPE_BUFFER];
 
-            if (current_bo != element->data.buffer_object)
+            bo = wined3d_bo_gl_id(element->data.buffer_object);
+            if (current_bo != bo)
             {
-                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, element->data.buffer_object));
+                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
                 checkGLcall("glBindBuffer");
-                current_bo = element->data.buffer_object;
+                current_bo = bo;
             }
             /* Use the VBO to find out if a vertex buffer exists, not the vb
              * pointer. vb can point to a user pointer data blob. In that case
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index 1cb9f222eab..b37554cdb01 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -4388,7 +4388,7 @@ static void indexbuffer(struct wined3d_context *context, const struct wined3d_st
     if (!ib || !stream_info->all_vbo)
         GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
     else
-        GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ib->buffer_object));
+        GL_EXTCALL(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, wined3d_buffer_gl_const(ib)->bo.id));
 }
 
 static void depth_clip(const struct wined3d_rasterizer_state *r, const struct wined3d_gl_info *gl_info)
@@ -4495,7 +4495,7 @@ 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));
+        GL_EXTCALL(glBindBufferBase(GL_UNIFORM_BUFFER, base + i, buffer ? wined3d_buffer_gl(buffer)->bo.id : 0));
     }
     checkGLcall("bind constant buffers");
 }
@@ -4567,7 +4567,7 @@ static void state_so(struct wined3d_context *context, const struct wined3d_state
             offset = 0;
         }
         size = buffer->resource.size - offset;
-        GL_EXTCALL(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i, buffer->buffer_object, offset, size));
+        GL_EXTCALL(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i, wined3d_buffer_gl(buffer)->bo.id, offset, size));
     }
     checkGLcall("bind transform feedback buffers");
 }
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index e965203950e..366dcb90061 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -742,7 +742,7 @@ void texture2d_read_from_framebuffer(struct wined3d_texture *texture, unsigned i
 
     if (data.buffer_object)
     {
-        GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data.buffer_object));
+        GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, ((struct wined3d_bo_gl *)data.buffer_object)->id));
         checkGLcall("glBindBuffer");
     }
 
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 89d7096f3c1..e41c0f3999b 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -361,6 +361,7 @@ static BOOL wined3d_texture_copy_sysmem_location(struct wined3d_texture *texture
     unsigned int size = texture->sub_resources[sub_resource_idx].size;
     struct wined3d_device *device = texture->resource.device;
     const struct wined3d_gl_info *gl_info;
+    struct wined3d_bo_gl *src_bo, *dst_bo;
     struct wined3d_bo_address dst, src;
 
     if (!wined3d_texture_prepare_location(texture, sub_resource_idx, context, location))
@@ -370,11 +371,11 @@ static BOOL wined3d_texture_copy_sysmem_location(struct wined3d_texture *texture
     wined3d_texture_get_memory(texture, sub_resource_idx, &src,
             texture->sub_resources[sub_resource_idx].locations);
 
-    if (dst.buffer_object)
+    if ((dst_bo = (struct wined3d_bo_gl *)dst.buffer_object))
     {
         context = context_acquire(device, NULL, 0);
         gl_info = wined3d_context_gl(context)->gl_info;
-        GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, dst.buffer_object));
+        GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, dst_bo->id));
         GL_EXTCALL(glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, size, src.addr));
         GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
         checkGLcall("PBO upload");
@@ -382,11 +383,11 @@ static BOOL wined3d_texture_copy_sysmem_location(struct wined3d_texture *texture
         return TRUE;
     }
 
-    if (src.buffer_object)
+    if ((src_bo = (struct wined3d_bo_gl *)src.buffer_object))
     {
         context = context_acquire(device, NULL, 0);
         gl_info = wined3d_context_gl(context)->gl_info;
-        GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, src.buffer_object));
+        GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, src_bo->id));
         GL_EXTCALL(glGetBufferSubData(GL_PIXEL_PACK_BUFFER, 0, size, dst.addr));
         GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
         checkGLcall("PBO download");
@@ -466,7 +467,7 @@ void wined3d_texture_get_memory(struct wined3d_texture *texture, unsigned int su
     if (locations & WINED3D_LOCATION_BUFFER)
     {
         data->addr = NULL;
-        data->buffer_object = sub_resource->buffer_object;
+        data->buffer_object = (uintptr_t)&sub_resource->bo;
         return;
     }
     if (locations & WINED3D_LOCATION_USER_MEMORY)
@@ -492,18 +493,16 @@ void wined3d_texture_get_memory(struct wined3d_texture *texture, unsigned int su
 static void wined3d_texture_remove_buffer_object(struct wined3d_texture *texture,
         unsigned int sub_resource_idx, const struct wined3d_gl_info *gl_info)
 {
-    uintptr_t *buffer_object = &texture->sub_resources[sub_resource_idx].buffer_object;
-    GLuint bo;
+    struct wined3d_bo_gl *bo = &texture->sub_resources[sub_resource_idx].bo;
 
-    bo = *buffer_object;
-    GL_EXTCALL(glDeleteBuffers(1, &bo));
+    GL_EXTCALL(glDeleteBuffers(1, &bo->id));
     checkGLcall("glDeleteBuffers");
 
     TRACE("Deleted buffer object %u for texture %p, sub-resource %u.\n",
-            bo, texture, sub_resource_idx);
+            bo->id, texture, sub_resource_idx);
 
     wined3d_texture_invalidate_location(texture, sub_resource_idx, WINED3D_LOCATION_BUFFER);
-    *buffer_object = 0;
+    bo->id = 0;
 }
 
 static void wined3d_texture_update_map_binding(struct wined3d_texture *texture)
@@ -1631,20 +1630,20 @@ static void wined3d_texture_prepare_buffer_object(struct wined3d_texture *textur
         unsigned int sub_resource_idx, const struct wined3d_gl_info *gl_info)
 {
     struct wined3d_texture_sub_resource *sub_resource;
-    GLuint bo;
+    struct wined3d_bo_gl *bo;
 
     sub_resource = &texture->sub_resources[sub_resource_idx];
-    if (sub_resource->buffer_object)
+    bo = &sub_resource->bo;
+    if (bo->id)
         return;
 
-    GL_EXTCALL(glGenBuffers(1, &bo));
-    GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bo));
+    GL_EXTCALL(glGenBuffers(1, &bo->id));
+    GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bo->id));
     GL_EXTCALL(glBufferData(GL_PIXEL_UNPACK_BUFFER, sub_resource->size, NULL, GL_STREAM_DRAW));
     GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0));
     checkGLcall("Create buffer object");
 
-    sub_resource->buffer_object = bo;
-    TRACE("Created buffer object %u for texture %p, sub-resource %u.\n", bo, texture, sub_resource_idx);
+    TRACE("Created buffer object %u for texture %p, sub-resource %u.\n", bo->id, texture, sub_resource_idx);
 }
 
 static void wined3d_texture_force_reload(struct wined3d_texture *texture)
@@ -2186,7 +2185,7 @@ static void wined3d_texture_gl_upload_data(struct wined3d_context *context,
     {
         if (bo.buffer_object)
         {
-            GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, bo.buffer_object));
+            GL_EXTCALL(glBindBuffer(GL_PIXEL_UNPACK_BUFFER, ((struct wined3d_bo_gl *)bo.buffer_object)->id));
             checkGLcall("glBindBuffer");
         }
 
@@ -2215,6 +2214,7 @@ static void wined3d_texture_gl_upload_data(struct wined3d_context *context,
 static void wined3d_texture_gl_download_data_slow_path(struct wined3d_texture_gl *texture_gl,
         unsigned int sub_resource_idx, struct wined3d_context_gl *context_gl, const struct wined3d_bo_address *data)
 {
+    const struct wined3d_bo_gl *bo = (const struct wined3d_bo_gl *)data->buffer_object;
     const struct wined3d_gl_info *gl_info = context_gl->gl_info;
     struct wined3d_texture_sub_resource *sub_resource;
     unsigned int dst_row_pitch, dst_slice_pitch;
@@ -2280,7 +2280,7 @@ static void wined3d_texture_gl_download_data_slow_path(struct wined3d_texture_gl
             return;
         }
 
-        if (data->buffer_object)
+        if (bo)
             ERR("NP2 emulated texture uses PBO unexpectedly.\n");
         if (texture_gl->t.resource.format_flags & WINED3DFMT_FLAG_COMPRESSED)
             ERR("Unexpected compressed format for NP2 emulated texture.\n");
@@ -2290,7 +2290,7 @@ static void wined3d_texture_gl_download_data_slow_path(struct wined3d_texture_gl
     {
         struct wined3d_format f;
 
-        if (data->buffer_object)
+        if (bo)
             ERR("Converted texture %p uses PBO unexpectedly.\n", texture_gl);
 
         WARN_(d3d_perf)("Downloading converted texture %p, %u with format %s.\n",
@@ -2315,9 +2315,9 @@ static void wined3d_texture_gl_download_data_slow_path(struct wined3d_texture_gl
     {
         mem = temporary_mem;
     }
-    else if (data->buffer_object)
+    else if (bo)
     {
-        GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data->buffer_object));
+        GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, bo->id));
         checkGLcall("glBindBuffer");
         mem = data->addr;
     }
@@ -2418,9 +2418,9 @@ static void wined3d_texture_gl_download_data_slow_path(struct wined3d_texture_gl
     {
         unsigned int layer = sub_resource_idx / texture_gl->t.level_count;
         void *src_data = temporary_mem + layer * sub_resource->size;
-        if (data->buffer_object)
+        if (bo)
         {
-            GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, data->buffer_object));
+            GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, bo->id));
             checkGLcall("glBindBuffer");
             GL_EXTCALL(glBufferSubData(GL_PIXEL_PACK_BUFFER, 0, sub_resource->size, src_data));
             checkGLcall("glBufferSubData");
@@ -2431,7 +2431,7 @@ static void wined3d_texture_gl_download_data_slow_path(struct wined3d_texture_gl
         }
     }
 
-    if (data->buffer_object)
+    if (bo)
     {
         GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
         checkGLcall("glBindBuffer");
@@ -2452,6 +2452,7 @@ static void wined3d_texture_gl_download_data(struct wined3d_context *context,
     unsigned int src_level, src_width, src_height, src_depth;
     unsigned int src_row_pitch, src_slice_pitch;
     const struct wined3d_format_gl *format_gl;
+    struct wined3d_bo_gl *dst_bo;
     BOOL srgb = FALSE;
     GLenum target;
 
@@ -2526,9 +2527,9 @@ static void wined3d_texture_gl_download_data(struct wined3d_context *context,
         return;
     }
 
-    if (dst_bo_addr->buffer_object)
+    if ((dst_bo = (struct wined3d_bo_gl *)dst_bo_addr->buffer_object))
     {
-        GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, dst_bo_addr->buffer_object));
+        GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, dst_bo->id));
         checkGLcall("glBindBuffer");
     }
 
@@ -2549,7 +2550,7 @@ static void wined3d_texture_gl_download_data(struct wined3d_context *context,
         checkGLcall("glGetTexImage");
     }
 
-    if (dst_bo_addr->buffer_object)
+    if (dst_bo)
     {
         GL_EXTCALL(glBindBuffer(GL_PIXEL_PACK_BUFFER, 0));
         checkGLcall("glBindBuffer");
@@ -2793,7 +2794,7 @@ static BOOL wined3d_texture_gl_load_texture(struct wined3d_texture_gl *texture_g
     /* Don't use PBOs for converted surfaces. During PBO conversion we look at
      * WINED3D_TEXTURE_CONVERTED but it isn't set (yet) in all cases it is
      * getting called. */
-    if (conversion && sub_resource->buffer_object)
+    if (conversion && sub_resource->bo.id)
     {
         TRACE("Removing the pbo attached to texture %p, %u.\n", texture_gl, sub_resource_idx);
 
@@ -2936,7 +2937,7 @@ static void wined3d_texture_gl_unload_location(struct wined3d_texture *texture,
             sub_count = texture->level_count * texture->layer_count;
             for (i = 0; i < sub_count; ++i)
             {
-                if (texture_gl->t.sub_resources[i].buffer_object)
+                if (texture_gl->t.sub_resources[i].bo.id)
                     wined3d_texture_remove_buffer_object(&texture_gl->t, i, context_gl->gl_info);
             }
             break;
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index eeca7c868bf..19339424682 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -246,13 +246,11 @@ 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,
+static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_context_gl *context_gl,
+        struct wined3d_buffer_gl *buffer_gl, const struct wined3d_format_gl *view_format_gl,
         unsigned int offset, unsigned int size)
 {
-    struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
     const struct wined3d_gl_info *gl_info = context_gl->gl_info;
-    const struct wined3d_format_gl *view_format_gl;
 
     if (!gl_info->supported[ARB_TEXTURE_BUFFER_OBJECT])
     {
@@ -267,8 +265,7 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c
         return;
     }
 
-    view_format_gl = wined3d_format_gl(view_format);
-    wined3d_buffer_load_location(buffer, context, WINED3D_LOCATION_BUFFER);
+    wined3d_buffer_load_location(&buffer_gl->b, &context_gl->c, WINED3D_LOCATION_BUFFER);
 
     view->target = GL_TEXTURE_BUFFER;
     gl_info->gl_ops.gl.p_glGenTextures(1, &view->name);
@@ -276,19 +273,18 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c
     wined3d_context_gl_bind_texture(context_gl, GL_TEXTURE_BUFFER, view->name);
     if (gl_info->supported[ARB_TEXTURE_BUFFER_RANGE])
     {
-        GL_EXTCALL(glTexBufferRange(GL_TEXTURE_BUFFER, view_format_gl->internal,
-                buffer->buffer_object, offset, size));
+        GL_EXTCALL(glTexBufferRange(GL_TEXTURE_BUFFER, view_format_gl->internal, buffer_gl->bo.id, offset, size));
     }
     else
     {
-        if (offset || size != buffer->resource.size)
+        if (offset || size != buffer_gl->b.resource.size)
             FIXME("OpenGL implementation does not support ARB_texture_buffer_range.\n");
-        GL_EXTCALL(glTexBuffer(GL_TEXTURE_BUFFER, view_format_gl->internal, buffer->buffer_object));
+        GL_EXTCALL(glTexBuffer(GL_TEXTURE_BUFFER, view_format_gl->internal, buffer_gl->bo.id));
     }
     checkGLcall("Create buffer texture");
 
-    context_invalidate_compute_state(context, STATE_COMPUTE_SHADER_RESOURCE_BINDING);
-    context_invalidate_state(context, STATE_GRAPHICS_SHADER_RESOURCE_BINDING);
+    context_invalidate_compute_state(&context_gl->c, STATE_COMPUTE_SHADER_RESOURCE_BINDING);
+    context_invalidate_state(&context_gl->c, STATE_GRAPHICS_SHADER_RESOURCE_BINDING);
 }
 
 static void get_buffer_view_range(const struct wined3d_buffer *buffer,
@@ -314,7 +310,8 @@ static void create_buffer_view(struct wined3d_gl_view *view, struct wined3d_cont
     unsigned int offset, size;
 
     get_buffer_view_range(buffer, desc, view_format, &offset, &size);
-    create_buffer_texture(view, context, buffer, view_format, offset, size);
+    create_buffer_texture(view, wined3d_context_gl(context),
+            wined3d_buffer_gl(buffer), wined3d_format_gl(view_format), offset, size);
 }
 
 static void wined3d_view_invalidate_location(struct wined3d_resource *resource,
@@ -1035,7 +1032,7 @@ void wined3d_unordered_access_view_gl_clear_uint(struct wined3d_unordered_access
     wined3d_unordered_access_view_invalidate_location(&view_gl->v, ~WINED3D_LOCATION_BUFFER);
 
     get_buffer_view_range(&buffer_gl->b, &view_gl->v.desc, &format->f, &offset, &size);
-    wined3d_context_gl_bind_bo(context_gl, buffer_gl->buffer_type_hint, buffer_gl->b.buffer_object);
+    wined3d_context_gl_bind_bo(context_gl, buffer_gl->buffer_type_hint, buffer_gl->bo.id);
     GL_EXTCALL(glClearBufferSubData(buffer_gl->buffer_type_hint, format->internal,
             offset, size, format->format, format->type, clear_value));
     checkGLcall("clear unordered access view");
@@ -1048,12 +1045,12 @@ void wined3d_unordered_access_view_set_counter(struct wined3d_unordered_access_v
     const struct wined3d_gl_info *gl_info;
     struct wined3d_context *context;
 
-    if (!view_gl->counter_bo)
+    if (!view_gl->counter_bo.id)
         return;
 
     context = context_acquire(view_gl->v.resource->device, NULL, 0);
     gl_info = wined3d_context_gl(context)->gl_info;
-    GL_EXTCALL(glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, view_gl->counter_bo));
+    GL_EXTCALL(glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, view_gl->counter_bo.id));
     GL_EXTCALL(glBufferSubData(GL_ATOMIC_COUNTER_BUFFER, 0, sizeof(value), &value));
     checkGLcall("set atomic counter");
     context_release(context);
@@ -1067,13 +1064,13 @@ void wined3d_unordered_access_view_copy_counter(struct wined3d_unordered_access_
     struct wined3d_bo_address dst, src;
     DWORD dst_location;
 
-    if (!view_gl->counter_bo)
+    if (!view_gl->counter_bo.id)
         return;
 
     dst_location = wined3d_buffer_get_memory(buffer, &dst, buffer->locations);
     dst.addr += offset;
 
-    src.buffer_object = view_gl->counter_bo;
+    src.buffer_object = (uintptr_t)&view_gl->counter_bo;
     src.addr = NULL;
 
     wined3d_context_gl_copy_bo_address(context_gl, &dst, wined3d_buffer_gl(buffer)->buffer_type_hint,
@@ -1101,9 +1098,11 @@ static void wined3d_unordered_access_view_gl_cs_init(void *object)
         create_buffer_view(&view_gl->gl_view, context, desc, buffer, view_gl->v.format);
         if (desc->flags & (WINED3D_VIEW_BUFFER_COUNTER | WINED3D_VIEW_BUFFER_APPEND))
         {
+            struct wined3d_bo_gl *bo = &view_gl->counter_bo;
             static const GLuint initial_value = 0;
-            GL_EXTCALL(glGenBuffers(1, &view_gl->counter_bo));
-            GL_EXTCALL(glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, view_gl->counter_bo));
+
+            GL_EXTCALL(glGenBuffers(1, &bo->id));
+            GL_EXTCALL(glBindBuffer(GL_ATOMIC_COUNTER_BUFFER, bo->id));
             GL_EXTCALL(glBufferData(GL_ATOMIC_COUNTER_BUFFER,
                     sizeof(initial_value), &initial_value, GL_STATIC_DRAW));
             checkGLcall("create atomic counter buffer");
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 244c320734c..8b7f518b4d9 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -1519,6 +1519,16 @@ do {                                                                \
 #define checkGLcall(A) do {} while(0)
 #endif
 
+struct wined3d_bo_gl
+{
+    GLuint id;
+};
+
+static inline GLuint wined3d_bo_gl_id(uintptr_t bo)
+{
+    return bo ? ((struct wined3d_bo_gl *)bo)->id : 0;
+}
+
 struct wined3d_bo_vk
 {
     VkBuffer vk_buffer;
@@ -3800,7 +3810,7 @@ struct wined3d_texture
         unsigned int map_count;
         uint32_t map_flags;
         DWORD locations;
-        uintptr_t buffer_object;
+        struct wined3d_bo_gl bo;
     } *sub_resources;
 };
 
@@ -4410,6 +4420,7 @@ struct wined3d_buffer_gl
 {
     struct wined3d_buffer b;
 
+    struct wined3d_bo_gl bo;
     GLenum buffer_object_usage;
     GLenum buffer_type_hint;
 };
@@ -4419,6 +4430,11 @@ static inline struct wined3d_buffer_gl *wined3d_buffer_gl(struct wined3d_buffer
     return CONTAINING_RECORD(buffer, struct wined3d_buffer_gl, b);
 }
 
+static inline const struct wined3d_buffer_gl *wined3d_buffer_gl_const(const struct wined3d_buffer *buffer)
+{
+    return CONTAINING_RECORD(buffer, struct wined3d_buffer_gl, b);
+}
+
 GLenum wined3d_buffer_gl_binding_from_bind_flags(const struct wined3d_gl_info *gl_info,
         uint32_t bind_flags) DECLSPEC_HIDDEN;
 HRESULT wined3d_buffer_gl_init(struct wined3d_buffer_gl *buffer_gl, struct wined3d_device *device,
@@ -4581,7 +4597,7 @@ struct wined3d_unordered_access_view_gl
 {
     struct wined3d_unordered_access_view v;
     struct wined3d_gl_view gl_view;
-    GLuint counter_bo;
+    struct wined3d_bo_gl counter_bo;
 };
 
 static inline struct wined3d_unordered_access_view_gl *wined3d_unordered_access_view_gl(
-- 
2.20.1




More information about the wine-devel mailing list