[PATCH 1/5] wined3d: Respect the BO memory offset for vertex buffers.

Zebediah Figura zfigura at codeweavers.com
Wed Nov 17 18:09:28 CST 2021


From: Henri Verbeet <hverbeet at codeweavers.com>

Signed-off-by: Zebediah Figura <zfigura at codeweavers.com>
---
 dlls/wined3d/context_gl.c | 89 ++++++++++++++++++++-------------------
 1 file changed, 46 insertions(+), 43 deletions(-)

diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c
index 686cd7dc548..d00c1ae2b0c 100644
--- a/dlls/wined3d/context_gl.c
+++ b/dlls/wined3d/context_gl.c
@@ -5100,8 +5100,8 @@ void wined3d_context_gl_load_tex_coords(const struct wined3d_context_gl *context
     const struct wined3d_gl_info *gl_info = context_gl->gl_info;
     const struct wined3d_format_gl *format_gl;
     unsigned int mapped_stage = 0;
+    struct wined3d_bo_gl *bo_gl;
     unsigned int texture_idx;
-    GLuint bo;
 
     for (texture_idx = 0; texture_idx < context_gl->c.d3d_info->limits.ffp_blend_stages; ++texture_idx)
     {
@@ -5123,12 +5123,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));
 
-            bo = wined3d_bo_gl_id(e->data.buffer_object);
-            if (*current_bo != bo)
+            bo_gl = wined3d_bo_gl(e->data.buffer_object);
+            if (*current_bo != bo_gl->id)
             {
-                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
+                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo_gl->id));
                 checkGLcall("glBindBuffer");
-                *current_bo = bo;
+                *current_bo = bo_gl->id;
             }
 
             GL_EXTCALL(glClientActiveTextureARB(GL_TEXTURE0_ARB + mapped_stage));
@@ -5137,7 +5137,7 @@ void wined3d_context_gl_load_tex_coords(const struct wined3d_context_gl *context
             /* The coords to supply depend completely on the fvf/vertex shader. */
             format_gl = wined3d_format_gl(e->format);
             gl_info->gl_ops.gl.p_glTexCoordPointer(format_gl->vtx_format, format_gl->vtx_type, e->stride,
-                    e->data.addr + state->load_base_vertex_index * e->stride);
+                    bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride);
             gl_info->gl_ops.gl.p_glEnableClientState(GL_TEXTURE_COORD_ARRAY);
             state->streams[e->stream_idx].buffer->bo_user.valid = true;
         }
@@ -5180,7 +5180,8 @@ 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, bo;
+    struct wined3d_bo_gl *bo_gl;
+    GLuint current_bo;
 
     TRACE("context_gl %p, si %p, state %p.\n", context_gl, si, state);
 
@@ -5212,19 +5213,19 @@ 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);
 
-        bo = wined3d_bo_gl_id(e->data.buffer_object);
-        if (current_bo != bo)
+        bo_gl = wined3d_bo_gl(e->data.buffer_object);
+        if (current_bo != bo_gl->id)
         {
-            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
+            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo_gl->id));
             checkGLcall("glBindBuffer");
-            current_bo = bo;
+            current_bo = bo_gl->id;
         }
 
         TRACE("glVertexPointer(%#x, %#x, %#x, %p);\n",
                 format_gl->vtx_format, format_gl->vtx_type, e->stride,
-                e->data.addr + state->load_base_vertex_index * e->stride);
+                bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride);
         gl_info->gl_ops.gl.p_glVertexPointer(format_gl->vtx_format, format_gl->vtx_type, e->stride,
-                e->data.addr + state->load_base_vertex_index * e->stride);
+                bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride);
         checkGLcall("glVertexPointer(...)");
         gl_info->gl_ops.gl.p_glEnableClientState(GL_VERTEX_ARRAY);
         checkGLcall("glEnableClientState(GL_VERTEX_ARRAY)");
@@ -5237,18 +5238,18 @@ 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);
 
-        bo = wined3d_bo_gl_id(e->data.buffer_object);
-        if (current_bo != bo)
+        bo_gl = wined3d_bo_gl(e->data.buffer_object);
+        if (current_bo != bo_gl->id)
         {
-            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
+            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo_gl->id));
             checkGLcall("glBindBuffer");
-            current_bo = bo;
+            current_bo = bo_gl->id;
         }
 
         TRACE("glNormalPointer(%#x, %#x, %p);\n", format_gl->vtx_type, e->stride,
-                e->data.addr + state->load_base_vertex_index * e->stride);
+                bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride);
         gl_info->gl_ops.gl.p_glNormalPointer(format_gl->vtx_type, e->stride,
-                e->data.addr + state->load_base_vertex_index * e->stride);
+                bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride);
         checkGLcall("glNormalPointer(...)");
         gl_info->gl_ops.gl.p_glEnableClientState(GL_NORMAL_ARRAY);
         checkGLcall("glEnableClientState(GL_NORMAL_ARRAY)");
@@ -5266,19 +5267,19 @@ 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);
 
-        bo = wined3d_bo_gl_id(e->data.buffer_object);
-        if (current_bo != bo)
+        bo_gl = wined3d_bo_gl(e->data.buffer_object);
+        if (current_bo != bo_gl->id)
         {
-            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
+            GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo_gl->id));
             checkGLcall("glBindBuffer");
-            current_bo = bo;
+            current_bo = bo_gl->id;
         }
 
         TRACE("glColorPointer(%#x, %#x %#x, %p);\n",
                 format_gl->vtx_format, format_gl->vtx_type, e->stride,
-                e->data.addr + state->load_base_vertex_index * e->stride);
+                bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride);
         gl_info->gl_ops.gl.p_glColorPointer(format_gl->vtx_format, format_gl->vtx_type, e->stride,
-                e->data.addr + state->load_base_vertex_index * e->stride);
+                bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride);
         checkGLcall("glColorPointer(4, GL_UNSIGNED_BYTE, ...)");
         gl_info->gl_ops.gl.p_glEnableClientState(GL_COLOR_ARRAY);
         checkGLcall("glEnableClientState(GL_COLOR_ARRAY)");
@@ -5306,12 +5307,12 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte
             type = format_gl->vtx_type;
             format = format_gl->vtx_format;
 
-            bo = wined3d_bo_gl_id(e->data.buffer_object);
-            if (current_bo != bo)
+            bo_gl = wined3d_bo_gl(e->data.buffer_object);
+            if (current_bo != bo_gl->id)
             {
-                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
+                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo_gl->id));
                 checkGLcall("glBindBuffer");
-                current_bo = bo;
+                current_bo = bo_gl->id;
             }
 
             if (format != 4 || (gl_info->quirks & WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA))
@@ -5322,9 +5323,9 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte
                  * 4 component secondary colors use it
                  */
                 TRACE("glSecondaryColorPointer(%#x, %#x, %#x, %p);\n", format, type, e->stride,
-                        e->data.addr + state->load_base_vertex_index * e->stride);
+                        bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride);
                 GL_EXTCALL(glSecondaryColorPointerEXT(format, type, e->stride,
-                        e->data.addr + state->load_base_vertex_index * e->stride));
+                        bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride));
                 checkGLcall("glSecondaryColorPointerEXT(format, type, ...)");
             }
             else
@@ -5333,9 +5334,9 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte
                 {
                     case GL_UNSIGNED_BYTE:
                         TRACE("glSecondaryColorPointer(3, GL_UNSIGNED_BYTE, %#x, %p);\n", e->stride,
-                                e->data.addr + state->load_base_vertex_index * e->stride);
+                                bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride);
                         GL_EXTCALL(glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, e->stride,
-                                e->data.addr + state->load_base_vertex_index * e->stride));
+                                bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride));
                         checkGLcall("glSecondaryColorPointerEXT(3, GL_UNSIGNED_BYTE, ...)");
                         break;
 
@@ -5343,9 +5344,9 @@ static void wined3d_context_gl_load_vertex_data(struct wined3d_context_gl *conte
                         FIXME("Add 4 component specular colour pointers for type %#x.\n", type);
                         /* Make sure that the right colour component is dropped. */
                         TRACE("glSecondaryColorPointer(3, %#x, %#x, %p);\n", type, e->stride,
-                                e->data.addr + state->load_base_vertex_index * e->stride);
+                                bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride);
                         GL_EXTCALL(glSecondaryColorPointerEXT(3, type, e->stride,
-                                e->data.addr + state->load_base_vertex_index * e->stride));
+                                bo_gl->b.memory_offset + e->data.addr + state->load_base_vertex_index * e->stride));
                         checkGLcall("glSecondaryColorPointerEXT(3, type, ...)");
                 }
             }
@@ -5405,7 +5406,8 @@ 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, bo;
+    struct wined3d_bo_gl *bo_gl;
+    GLuint current_bo;
     unsigned int i;
 
     /* Default to no instancing. */
@@ -5474,27 +5476,28 @@ 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];
 
-            bo = wined3d_bo_gl_id(element->data.buffer_object);
-            if (current_bo != bo)
+            bo_gl = wined3d_bo_gl(element->data.buffer_object);
+            if (current_bo != bo_gl->id)
             {
-                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo));
+                GL_EXTCALL(glBindBuffer(GL_ARRAY_BUFFER, bo_gl->id));
                 checkGLcall("glBindBuffer");
-                current_bo = bo;
+                current_bo = bo_gl->id;
             }
+
             /* 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
              * current_bo will be 0. If there is a vertex buffer but no vbo we
              * won't be load converted attributes anyway. */
             if (vs && vs->reg_maps.shader_version.major >= 4 && (format_flags & WINED3DFMT_FLAG_INTEGER))
             {
-                GL_EXTCALL(glVertexAttribIPointer(i, format_gl->vtx_format, format_gl->vtx_type,
-                        element->stride, element->data.addr + state->load_base_vertex_index * element->stride));
+                GL_EXTCALL(glVertexAttribIPointer(i, format_gl->vtx_format, format_gl->vtx_type, element->stride,
+                        bo_gl->b.memory_offset + element->data.addr + state->load_base_vertex_index * element->stride));
             }
             else
             {
                 GL_EXTCALL(glVertexAttribPointer(i, format_gl->vtx_format, format_gl->vtx_type,
                         !!(format_flags & WINED3DFMT_FLAG_NORMALISED), element->stride,
-                        element->data.addr + state->load_base_vertex_index * element->stride));
+                        bo_gl->b.memory_offset + element->data.addr + state->load_base_vertex_index * element->stride));
             }
 
             if (!(context->numbered_array_mask & (1u << i)))
-- 
2.33.0




More information about the wine-devel mailing list