From: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@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)))
From: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/context_gl.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c index d00c1ae2b0c..b1d5c1ff9ed 100644 --- a/dlls/wined3d/context_gl.c +++ b/dlls/wined3d/context_gl.c @@ -4935,10 +4935,12 @@ 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) + struct wined3d_bo *bo = index_buffer->buffer_object; + + if (!bo || !stream_info->all_vbo) idx_data = index_buffer->resource.heap_memory; else - idx_data = NULL; + idx_data = (void *)bo->memory_offset; idx_data = (const BYTE *)idx_data + state->index_offset;
if (state->index_format == WINED3DFMT_R16_UINT)
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/state.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 21b5ba1d032..25733bbb50c 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -4651,6 +4651,7 @@ static void state_so(struct wined3d_context *context, const struct wined3d_state const struct wined3d_gl_info *gl_info = context_gl->gl_info; struct wined3d_buffer *buffer; unsigned int offset, size, i; + struct wined3d_bo_gl *bo_gl;
TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
@@ -4666,6 +4667,7 @@ static void state_so(struct wined3d_context *context, const struct wined3d_state
buffer = state->stream_output[i].buffer; offset = state->stream_output[i].offset; + bo_gl = wined3d_bo_gl(buffer->buffer_object); if (offset == ~0u) { FIXME("Appending to stream output buffers not implemented.\n"); @@ -4673,7 +4675,7 @@ static void state_so(struct wined3d_context *context, const struct wined3d_state } size = buffer->resource.size - offset; GL_EXTCALL(glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, i, - wined3d_bo_gl(buffer->buffer_object)->id, offset, size)); + bo_gl->id, bo_gl->b.memory_offset + offset, size)); buffer->bo_user.valid = true; } checkGLcall("bind transform feedback buffers");
From: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/state.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c index 25733bbb50c..d291bc15757 100644 --- a/dlls/wined3d/state.c +++ b/dlls/wined3d/state.c @@ -4577,6 +4577,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_gl *bo_gl;
TRACE("context %p, state %p, state_id %#x.\n", context, state, state_id);
@@ -4597,8 +4598,9 @@ static void state_cb(struct wined3d_context *context, const struct wined3d_state }
buffer = buffer_state->buffer; + bo_gl = wined3d_bo_gl(buffer->buffer_object); GL_EXTCALL(glBindBufferRange(GL_UNIFORM_BUFFER, base + i, - wined3d_bo_gl(buffer->buffer_object)->id, buffer_state->offset, buffer_state->size)); + bo_gl->id, bo_gl->b.memory_offset + buffer_state->offset, buffer_state->size)); buffer->bo_user.valid = true; } checkGLcall("bind constant buffers");
From: Henri Verbeet hverbeet@codeweavers.com
Signed-off-by: Zebediah Figura zfigura@codeweavers.com --- dlls/wined3d/context_gl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/dlls/wined3d/context_gl.c b/dlls/wined3d/context_gl.c index b1d5c1ff9ed..ad18a87aab6 100644 --- a/dlls/wined3d/context_gl.c +++ b/dlls/wined3d/context_gl.c @@ -3814,7 +3814,8 @@ static void wined3d_context_gl_bind_unordered_access_views(struct wined3d_contex format_gl->internal));
if (view_gl->counter_bo.id) - GL_EXTCALL(glBindBufferBase(GL_ATOMIC_COUNTER_BUFFER, i, view_gl->counter_bo.id)); + GL_EXTCALL(glBindBufferRange(GL_ATOMIC_COUNTER_BUFFER, i, view_gl->counter_bo.id, + view_gl->counter_bo.b.memory_offset, view_gl->counter_bo.size)); } checkGLcall("Bind unordered access views"); }
On Thu, 18 Nov 2021 at 01:09, Zebediah Figura zfigura@codeweavers.com wrote:
@@ -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) {
I think "e->data.buffer_object" can be NULL here.
@@ -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);
I think it's a little unfortunate to use "memory_offset" here. (And I don't think the original version of these patches did that.) The "memory_offset" field contains the offset from the start of the underlying memory allocation (i.e., VkDeviceMemory in Vulkan), while "buffer_offset" is the offset from the start of the buffer object (i.e., VkBuffer in Vulkan). We're addressing relative to the buffer object here.
Of course, in OpenGL, these are generally the same. (But, note that GL_EXT_memory_object exists.) For clarity though, it seems preferable to use these in a consistent way between the Vulkan and GL backends.