util/tc: add a util function for setting bytes_mapped_limit
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 14 Jul 2021 17:43:13 +0000 (13:43 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 20 Jul 2021 13:49:01 +0000 (13:49 +0000)
tc drivers set this based on os_get_total_physical_memory()/divisor,
which is going to be totally wrong for 32bit processes and explode
the address space

this util function can be used to handle per-platform clamping

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

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

index 543662f..8e98983 100644 (file)
@@ -4207,3 +4207,14 @@ fail:
    tc_destroy(&tc->base);
    return NULL;
 }
+
+void
+threaded_context_init_bytes_mapped_limit(struct threaded_context *tc, unsigned divisor)
+{
+   uint64_t total_ram;
+   if (os_get_total_physical_memory(&total_ram)) {
+      tc->bytes_mapped_limit = total_ram / divisor;
+      if (sizeof(void*) == 4)
+         tc->bytes_mapped_limit = MIN2(tc->bytes_mapped_limit, 512*1024*1024UL);
+   }
+}
index 952429d..0408816 100644 (file)
@@ -505,6 +505,9 @@ threaded_context_create(struct pipe_context *pipe,
                         struct threaded_context **out);
 
 void
+threaded_context_init_bytes_mapped_limit(struct threaded_context *tc, unsigned divisor);
+
+void
 threaded_context_flush(struct pipe_context *_pipe,
                        struct tc_unflushed_batch_token *token,
                        bool prefer_async);