gallium/u_threaded: disable forced staging upload at runtime
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Fri, 27 Nov 2020 14:14:07 +0000 (15:14 +0100)
committerPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Thu, 3 Dec 2020 09:40:23 +0000 (10:40 +0100)
If a conflict caused by the forced staging optimization is detected,
disable it.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7098>

src/gallium/auxiliary/util/u_threaded_context.c
src/gallium/auxiliary/util/u_threaded_context.h

index 0227be3..248c38f 100644 (file)
@@ -1504,6 +1504,7 @@ tc_improve_map_buffer_flags(struct threaded_context *tc,
        /* Try not to decrement the counter if it's not positive. Still racy,
         * but it makes it harder to wrap the counter from INT_MIN to INT_MAX. */
        tres->max_forced_staging_uploads > 0 &&
+       tc->use_forced_staging_uploads &&
        p_atomic_dec_return(&tres->max_forced_staging_uploads) >= 0) {
       usage &= ~(PIPE_MAP_DISCARD_WHOLE_RESOURCE |
                  PIPE_MAP_UNSYNCHRONIZED);
@@ -1639,6 +1640,7 @@ tc_transfer_map(struct pipe_context *_pipe,
           * written range(s).
           */
          usage &= ~PIPE_MAP_UNSYNCHRONIZED & ~TC_TRANSFER_MAP_THREADED_UNSYNC;
+         tc->use_forced_staging_uploads = false;
       }
    }
 
@@ -2958,6 +2960,8 @@ threaded_context_create(struct pipe_context *pipe,
    if (!tc->base.stream_uploader || !tc->base.const_uploader)
       goto fail;
 
+   tc->use_forced_staging_uploads = true;
+
    /* The queue size is the number of batches "waiting". Batches are removed
     * from the queue before being executed, so keep one tc_batch slot for that
     * execution. Also, keep one unused slot for an unflushed batch.
index 3adec8e..12cd653 100644 (file)
@@ -367,6 +367,8 @@ struct threaded_context {
    unsigned num_direct_slots;
    unsigned num_syncs;
 
+   bool use_forced_staging_uploads;
+
    /* Estimation of how much vram/gtt bytes are mmap'd in
     * the current tc_batch.
     */