Mesa (main): radeonsi: add an option to use CPU storage uploads for threaded context

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Oct 19 17:44:52 UTC 2021


Module: Mesa
Branch: main
Commit: 9f2a97e9df7453807ae74d825bdd1a7eac6da8dc
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9f2a97e9df7453807ae74d825bdd1a7eac6da8dc

Author: Marek Olšák <marek.olsak at amd.com>
Date:   Sun Oct 17 17:17:14 2021 -0400

radeonsi: add an option to use CPU storage uploads for threaded context

It's only enabled for viewperf for now.

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

---

 src/gallium/drivers/radeonsi/driinfo_radeonsi.h |  1 +
 src/gallium/drivers/radeonsi/si_buffer.c        | 14 +++++++++-----
 src/gallium/drivers/radeonsi/si_debug_options.h |  2 ++
 src/gallium/drivers/radeonsi/si_pipe.c          |  2 ++
 src/gallium/drivers/radeonsi/si_pipe.h          |  1 +
 src/gallium/drivers/radeonsi/si_texture.c       |  2 ++
 src/util/00-mesa-defaults.conf                  |  1 +
 7 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/radeonsi/driinfo_radeonsi.h b/src/gallium/drivers/radeonsi/driinfo_radeonsi.h
index 1e1ca86c2d4..3957f9288a2 100644
--- a/src/gallium/drivers/radeonsi/driinfo_radeonsi.h
+++ b/src/gallium/drivers/radeonsi/driinfo_radeonsi.h
@@ -8,6 +8,7 @@ DRI_CONF_SECTION_END
 
 DRI_CONF_SECTION_DEBUG
 #define OPT_BOOL(name, dflt, description) DRI_CONF_OPT_B(radeonsi_##name, dflt, description)
+#define OPT_INT(name, dflt, description) DRI_CONF_OPT_I(radeonsi_##name, dflt, INT_MIN, INT_MAX, description)
 
 #include "radeonsi/si_debug_options.h"
 DRI_CONF_SECTION_END
diff --git a/src/gallium/drivers/radeonsi/si_buffer.c b/src/gallium/drivers/radeonsi/si_buffer.c
index 9977588132f..0867c98f59a 100644
--- a/src/gallium/drivers/radeonsi/si_buffer.c
+++ b/src/gallium/drivers/radeonsi/si_buffer.c
@@ -154,6 +154,7 @@ void si_init_resource_fields(struct si_screen *sscreen, struct si_resource *res,
        */
       if (!sscreen->info.smart_access_memory &&
           sscreen->info.has_dedicated_vram &&
+          !res->b.cpu_storage && /* TODO: The CPU storage breaks this. */
           size >= SI_MAX_VRAM_MAP_SIZE)
          res->b.b.flags |= PIPE_RESOURCE_FLAG_DONT_MAP_DIRECTLY;
    }
@@ -555,7 +556,8 @@ static void si_buffer_subdata(struct pipe_context *ctx, struct pipe_resource *bu
 }
 
 static struct si_resource *si_alloc_buffer_struct(struct pipe_screen *screen,
-                                                  const struct pipe_resource *templ)
+                                                  const struct pipe_resource *templ,
+                                                  bool allow_cpu_storage)
 {
    struct si_resource *buf = MALLOC_STRUCT_CL(si_resource);
 
@@ -564,7 +566,7 @@ static struct si_resource *si_alloc_buffer_struct(struct pipe_screen *screen,
    pipe_reference_init(&buf->b.b.reference, 1);
    buf->b.b.screen = screen;
 
-   threaded_resource_init(&buf->b.b, false, 0);
+   threaded_resource_init(&buf->b.b, allow_cpu_storage, SI_MAP_BUFFER_ALIGNMENT);
 
    buf->buf = NULL;
    buf->bind_history = 0;
@@ -577,7 +579,9 @@ static struct pipe_resource *si_buffer_create(struct pipe_screen *screen,
                                               const struct pipe_resource *templ, unsigned alignment)
 {
    struct si_screen *sscreen = (struct si_screen *)screen;
-   struct si_resource *buf = si_alloc_buffer_struct(screen, templ);
+   struct si_resource *buf =
+      si_alloc_buffer_struct(screen, templ,
+                             templ->width0 <= sscreen->options.tc_max_cpu_storage_size);
 
    if (templ->flags & PIPE_RESOURCE_FLAG_SPARSE)
       buf->b.b.flags |= SI_RESOURCE_FLAG_UNMAPPABLE;
@@ -627,7 +631,7 @@ static struct pipe_resource *si_buffer_from_user_memory(struct pipe_screen *scre
 {
    struct si_screen *sscreen = (struct si_screen *)screen;
    struct radeon_winsys *ws = sscreen->ws;
-   struct si_resource *buf = si_alloc_buffer_struct(screen, templ);
+   struct si_resource *buf = si_alloc_buffer_struct(screen, templ, false);
 
    buf->domains = RADEON_DOMAIN_GTT;
    buf->flags = 0;
@@ -655,7 +659,7 @@ struct pipe_resource *si_buffer_from_winsys_buffer(struct pipe_screen *screen,
                                                    bool dedicated)
 {
    struct si_screen *sscreen = (struct si_screen *)screen;
-   struct si_resource *res = si_alloc_buffer_struct(screen, templ);
+   struct si_resource *res = si_alloc_buffer_struct(screen, templ, false);
 
    if (!res)
       return 0;
diff --git a/src/gallium/drivers/radeonsi/si_debug_options.h b/src/gallium/drivers/radeonsi/si_debug_options.h
index 3ad4a9dcef0..9f8302f7f4e 100644
--- a/src/gallium/drivers/radeonsi/si_debug_options.h
+++ b/src/gallium/drivers/radeonsi/si_debug_options.h
@@ -14,5 +14,7 @@ OPT_BOOL(vrs2x2, false, "Enable 2x2 coarse shading for non-GUI elements")
 OPT_BOOL(enable_sam, false, "Enable Smart Access Memory with Above 4G Decoding for unvalidated platforms.")
 OPT_BOOL(disable_sam, false, "Disable Smart Access Memory.")
 OPT_BOOL(fp16, false, "Enable FP16 for mediump.")
+OPT_INT(tc_max_cpu_storage_size, 0, "Enable the CPU storage for pipelined buffer uploads in TC.")
 
 #undef OPT_BOOL
+#undef OPT_INT
diff --git a/src/gallium/drivers/radeonsi/si_pipe.c b/src/gallium/drivers/radeonsi/si_pipe.c
index 525c6b705dd..4abbd928818 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.c
+++ b/src/gallium/drivers/radeonsi/si_pipe.c
@@ -1073,6 +1073,8 @@ static struct pipe_screen *radeonsi_screen_create_impl(struct radeon_winsys *ws,
    {
 #define OPT_BOOL(name, dflt, description)                                                          \
    sscreen->options.name = driQueryOptionb(config->options, "radeonsi_" #name);
+#define OPT_INT(name, dflt, description)                                                           \
+   sscreen->options.name = driQueryOptioni(config->options, "radeonsi_" #name);
 #include "si_debug_options.h"
    }
 
diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h
index e297378578d..7a38acc9af3 100644
--- a/src/gallium/drivers/radeonsi/si_pipe.h
+++ b/src/gallium/drivers/radeonsi/si_pipe.h
@@ -556,6 +556,7 @@ struct si_screen {
 
    struct {
 #define OPT_BOOL(name, dflt, description) bool name : 1;
+#define OPT_INT(name, dflt, description) int name;
 #include "si_debug_options.h"
    } options;
 
diff --git a/src/gallium/drivers/radeonsi/si_texture.c b/src/gallium/drivers/radeonsi/si_texture.c
index 06b14129e3b..388743ccf6a 100644
--- a/src/gallium/drivers/radeonsi/si_texture.c
+++ b/src/gallium/drivers/radeonsi/si_texture.c
@@ -733,6 +733,8 @@ static bool si_texture_get_handle(struct pipe_screen *screen, struct pipe_contex
 
       modifier = tex->surface.modifier;
    } else {
+      tc_buffer_disable_cpu_storage(&res->b.b);
+
       /* Buffer exports are for the OpenCL interop. */
       /* Move a suballocated buffer into a non-suballocated allocation. */
       if (sscreen->ws->buffer_is_suballocated(res->buf) ||
diff --git a/src/util/00-mesa-defaults.conf b/src/util/00-mesa-defaults.conf
index aeb36509007..a10e0d8b491 100644
--- a/src/util/00-mesa-defaults.conf
+++ b/src/util/00-mesa-defaults.conf
@@ -769,6 +769,7 @@ TODO: document the other workarounds.
             <option name="radeonsi_sync_compile" value="true" />
             <option name="radeonsi_clamp_div_by_zero" value="true" />
             <option name="radeonsi_inline_uniforms" value="true" />
+            <option name="radeonsi_tc_max_cpu_storage_size" value="1000" />
         </application>
         <application name="Road Redemption" executable="RoadRedemption.x86_64">
             <option name="radeonsi_clamp_div_by_zero" value="true" />



More information about the mesa-commit mailing list