From 389c0fdc7c71c634ca35cef6cb4d0c018358f974 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Fri, 12 May 2023 08:13:22 -0400 Subject: [PATCH] asahi: Add ASAHI_MESA_DEBUG=nowc flag Add a debug flag to disable write-combining as a performance hack. This may help diagnose slowness with glReadPixels() heavy workloads like screen capture. Signed-off-by: Alyssa Rosenzweig Part-of: --- docs/envvars.rst | 4 ++++ src/asahi/lib/agx_device.h | 1 + src/gallium/drivers/asahi/agx_pipe.c | 6 ++++++ 3 files changed, 11 insertions(+) diff --git a/docs/envvars.rst b/docs/envvars.rst index 5b7352113a1..98233c67b6e 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -1633,6 +1633,10 @@ Asahi driver environment variables possible) or added in the Mesa-wide driconf (if closed source). ``dirty`` In debug builds only: disable dirty tracking optimizations. + ``nowc`` + Disable write-combining (force all allocations to be write-through). This + may be useful for diagnosing certain performance issues. Note imported + buffers may still be write-combined. .. envvar:: AGX_MESA_DEBUG diff --git a/src/asahi/lib/agx_device.h b/src/asahi/lib/agx_device.h index 424d10e93b2..c8c121bcb4a 100644 --- a/src/asahi/lib/agx_device.h +++ b/src/asahi/lib/agx_device.h @@ -25,6 +25,7 @@ enum agx_dbg { AGX_DBG_STATS = BITFIELD_BIT(9), AGX_DBG_RESOURCE = BITFIELD_BIT(10), AGX_DBG_BATCH = BITFIELD_BIT(11), + AGX_DBG_NOWC = BITFIELD_BIT(12), }; /* Dummy partial declarations, pending real UAPI */ diff --git a/src/gallium/drivers/asahi/agx_pipe.c b/src/gallium/drivers/asahi/agx_pipe.c index d92e26a0d51..3def67dc2d9 100644 --- a/src/gallium/drivers/asahi/agx_pipe.c +++ b/src/gallium/drivers/asahi/agx_pipe.c @@ -69,6 +69,7 @@ static const struct debug_named_value agx_debug_options[] = { {"stats", AGX_DBG_STATS, "Show command execution statistics"}, {"resource", AGX_DBG_RESOURCE, "Log resource operations"}, {"batch", AGX_DBG_BATCH, "Log batches"}, + {"nowc", AGX_DBG_NOWC, "Disable write-combining"}, DEBUG_NAMED_VALUE_END }; /* clang-format on */ @@ -557,6 +558,11 @@ agx_resource_create_with_modifiers(struct pipe_screen *screen, create_flags |= AGX_BO_WRITEBACK; } + /* Allow disabling write-combine to debug performance issues */ + if (dev->debug & AGX_DBG_NOWC) { + create_flags |= AGX_BO_WRITEBACK; + } + /* Create buffers that might be shared with the SHAREABLE flag */ if (bind & (PIPE_BIND_SCANOUT | PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SHARED)) create_flags |= AGX_BO_SHAREABLE;