summaryrefslogtreecommitdiffstats
path: root/third_party/rust/gpu-alloc/src/config.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/rust/gpu-alloc/src/config.rs
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/gpu-alloc/src/config.rs')
-rw-r--r--third_party/rust/gpu-alloc/src/config.rs72
1 files changed, 72 insertions, 0 deletions
diff --git a/third_party/rust/gpu-alloc/src/config.rs b/third_party/rust/gpu-alloc/src/config.rs
new file mode 100644
index 0000000000..84442a9fef
--- /dev/null
+++ b/third_party/rust/gpu-alloc/src/config.rs
@@ -0,0 +1,72 @@
+/// Configuration for [`GpuAllocator`]
+///
+/// [`GpuAllocator`]: type.GpuAllocator
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct Config {
+ /// Size in bytes of request that will be served by dedicated memory object.
+ /// This value should be large enough to not exhaust memory object limit
+ /// and not use slow memory object allocation when it is not necessary.
+ pub dedicated_treshold: u64,
+
+ /// Size in bytes of request that will be served by dedicated memory object if preferred.
+ /// This value should be large enough to not exhaust memory object limit
+ /// and not use slow memory object allocation when it is not necessary.
+ ///
+ /// This won't make much sense if this value is larger than `dedicated_treshold`.
+ pub preferred_dedicated_treshold: u64,
+
+ /// Size in bytes of transient memory request that will be served by dedicated memory object.
+ /// This value should be large enough to not exhaust memory object limit
+ /// and not use slow memory object allocation when it is not necessary.
+ ///
+ /// This won't make much sense if this value is lesser than `dedicated_treshold`.
+ pub transient_dedicated_treshold: u64,
+
+ /// Size in bytes for chunks for linear allocator.
+ pub linear_chunk: u64,
+
+ /// Minimal size for buddy allocator.
+ pub minimal_buddy_size: u64,
+
+ /// Initial memory object size for buddy allocator.
+ /// If less than `minimal_buddy_size` then `minimal_buddy_size` is used instead.
+ pub initial_buddy_dedicated_size: u64,
+}
+
+impl Config {
+ /// Returns default configuration.
+ ///
+ /// This is not `Default` implementation to discourage usage outside of
+ /// prototyping.
+ ///
+ /// Proper configuration should depend on hardware and intended usage.\
+ /// But those values can be used as starting point.\
+ /// Note that they can simply not work for some platforms with lesser
+ /// memory capacity than today's "modern" GPU (year 2020).
+ pub fn i_am_prototyping() -> Self {
+ // Assume that today's modern GPU is made of 1024 potatoes.
+ let potato = Config::i_am_potato();
+
+ Config {
+ dedicated_treshold: potato.dedicated_treshold * 1024,
+ preferred_dedicated_treshold: potato.preferred_dedicated_treshold * 1024,
+ transient_dedicated_treshold: potato.transient_dedicated_treshold * 1024,
+ linear_chunk: potato.linear_chunk * 1024,
+ minimal_buddy_size: potato.minimal_buddy_size * 1024,
+ initial_buddy_dedicated_size: potato.initial_buddy_dedicated_size * 1024,
+ }
+ }
+
+ /// Returns default configuration for average sized potato.
+ pub fn i_am_potato() -> Self {
+ Config {
+ dedicated_treshold: 32 * 1024,
+ preferred_dedicated_treshold: 1024,
+ transient_dedicated_treshold: 128 * 1024,
+ linear_chunk: 128 * 1024,
+ minimal_buddy_size: 1,
+ initial_buddy_dedicated_size: 8 * 1024,
+ }
+ }
+}