From: Marek Olšák Date: Tue, 21 Jan 2020 02:35:54 +0000 (-0500) Subject: mesa: import PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET handling X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f89ee44ab0300b72ab957c3135858ff46187dfb5;p=mesa.git mesa: import PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET handling This should decrease overhead in st_update_array. Reviewed-by: Pierre-Eric Pelloux-Prayer Part-of: --- diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index afe35615789..41276dbac89 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -4150,6 +4150,9 @@ struct gl_constants /** Wether or not glBitmap uses red textures rather than alpha */ bool BitmapUsesRed; + /** Whether the vertex buffer offset is a signed 32-bit integer. */ + bool VertexBufferOffsetIsInt32; + /** GL_ARB_gl_spirv */ struct spirv_supported_capabilities SpirVCapabilities; diff --git a/src/mesa/main/varray.c b/src/mesa/main/varray.c index 048e836b60c..bea3e8945ab 100644 --- a/src/mesa/main/varray.c +++ b/src/mesa/main/varray.c @@ -199,6 +199,20 @@ _mesa_bind_vertex_buffer(struct gl_context *ctx, assert(!vao->SharedAndImmutable); struct gl_vertex_buffer_binding *binding = &vao->BufferBinding[index]; + if (ctx->Const.VertexBufferOffsetIsInt32 && (int)offset < 0 && + _mesa_is_bufferobj(vbo)) { + /* The offset will be interpreted as a signed int, so make sure + * the user supplied offset is not negative (driver limitation). + */ + _mesa_warning(ctx, "Received negative int32 vertex buffer offset. " + "(driver limitation)\n"); + + /* We can't disable this binding, so use a non-negative offset value + * instead. + */ + offset = 0; + } + if (binding->BufferObj != vbo || binding->Offset != offset || binding->Stride != stride) { diff --git a/src/mesa/state_tracker/st_atom_array.c b/src/mesa/state_tracker/st_atom_array.c index d08e0986ab9..7913e3512b9 100644 --- a/src/mesa/state_tracker/st_atom_array.c +++ b/src/mesa/state_tracker/st_atom_array.c @@ -390,21 +390,10 @@ st_setup_arrays(struct st_context *st, if (_mesa_is_bufferobj(binding->BufferObj)) { /* Set the binding */ struct st_buffer_object *stobj = st_buffer_object(binding->BufferObj); + vbuffer[bufidx].buffer.resource = stobj ? stobj->buffer : NULL; vbuffer[bufidx].is_user_buffer = false; vbuffer[bufidx].buffer_offset = _mesa_draw_binding_offset(binding); - if (st->has_signed_vertex_buffer_offset) { - /* 'buffer_offset' will be interpreted as an signed int, so make sure - * the user supplied offset is not negative (application bug). - */ - if ((int) vbuffer[bufidx].buffer_offset < 0) { - assert ((int) vbuffer[bufidx].buffer_offset >= 0); - /* Fallback if assert are disabled: we can't disable this attribute - * since other parts expects it (e.g: velements, vp_variant), so - * use a non-buggy offset value instead */ - vbuffer[bufidx].buffer_offset = 0; - } - } } else { /* Set the binding */ const void *ptr = (const void *)_mesa_draw_binding_offset(binding); diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index e6a5b65dc22..5aec2f5bb23 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -680,8 +680,6 @@ st_create_context_priv(struct gl_context *ctx, struct pipe_context *pipe, screen->get_param(screen, PIPE_CAP_INDEP_BLEND_FUNC); st->needs_rgb_dst_alpha_override = screen->get_param(screen, PIPE_CAP_RGB_OVERRIDE_DST_ALPHA_BLEND); - st->has_signed_vertex_buffer_offset = - screen->get_param(screen, PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET); st->lower_flatshade = !screen->get_param(screen, PIPE_CAP_FLATSHADE); st->lower_alpha_test = diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h index 68708818fdf..853a1895825 100644 --- a/src/mesa/state_tracker/st_context.h +++ b/src/mesa/state_tracker/st_context.h @@ -147,7 +147,6 @@ struct st_context boolean has_indep_blend_func; boolean needs_rgb_dst_alpha_override; boolean can_bind_const_buffer_as_vertex; - boolean has_signed_vertex_buffer_offset; boolean lower_flatshade; boolean lower_alpha_test; boolean lower_point_size; diff --git a/src/mesa/state_tracker/st_extensions.c b/src/mesa/state_tracker/st_extensions.c index 91f429513fe..3c598fef2bd 100644 --- a/src/mesa/state_tracker/st_extensions.c +++ b/src/mesa/state_tracker/st_extensions.c @@ -559,6 +559,9 @@ void st_init_limits(struct pipe_screen *screen, temp = screen->get_param(screen, PIPE_CAP_MAX_COMBINED_SHADER_OUTPUT_RESOURCES); if (temp > 0 && c->MaxCombinedShaderOutputResources > temp) c->MaxCombinedShaderOutputResources = temp; + + c->VertexBufferOffsetIsInt32 = + screen->get_param(screen, PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET); }