mesa: import PIPE_CAP_SIGNED_VERTEX_BUFFER_OFFSET handling
authorMarek Olšák <marek.olsak@amd.com>
Tue, 21 Jan 2020 02:35:54 +0000 (21:35 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 11 Feb 2020 00:34:57 +0000 (00:34 +0000)
This should decrease overhead in st_update_array.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3766>

src/mesa/main/mtypes.h
src/mesa/main/varray.c
src/mesa/state_tracker/st_atom_array.c
src/mesa/state_tracker/st_context.c
src/mesa/state_tracker/st_context.h
src/mesa/state_tracker/st_extensions.c

index afe35615789764714350fdbb2ed8d3cc8de3e59e..41276dbac89ba0fd7dd9df606403afa0c075ee60 100644 (file)
@@ -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;
 
index 048e836b60cef7534236248737b458e831f10574..bea3e8945abf2d8119db6f75575b122d5b02b67a 100644 (file)
@@ -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) {
index d08e0986ab940039110277fc21dad63147970373..7913e3512b943c963bda31fec897b3c6b96db09a 100644 (file)
@@ -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);
index e6a5b65dc22ea94fd9d0ea1575a6d647b4f1b631..5aec2f5bb23819099f78ee141b2cac3f053d7802 100644 (file)
@@ -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 =
index 68708818fdf0e3c5b3046aeec96eef55d2e4bb96..853a1895825cdf555db408312a5d9a1d0d0e833a 100644 (file)
@@ -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;
index 91f429513fe1086156cf845c37d1d7e5f01c0059..3c598fef2bdd3fbcf0c72350511bc6012422d4c6 100644 (file)
@@ -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);
 }