From ea6c57cfcbca4cfd5f18cbb00de196f524106184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=C3=A1n=20de=20B=C3=BArca?= Date: Thu, 27 Mar 2025 10:00:18 -0700 Subject: [PATCH] rusticl: cap max alloc size to i32 to avoid overflowing gallium v2: remove stray comment Reviewed-by: Karol Herbst Cc: stable Part-of: --- src/gallium/frontends/rusticl/core/device.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/gallium/frontends/rusticl/core/device.rs b/src/gallium/frontends/rusticl/core/device.rs index 2230d57fffa..3eada9bbbc6 100644 --- a/src/gallium/frontends/rusticl/core/device.rs +++ b/src/gallium/frontends/rusticl/core/device.rs @@ -1025,9 +1025,18 @@ impl Device { self.screen.compute_caps().grid_dimension } + /// Returns the maximum size in bytes of a memory allocation for this + /// device. pub fn max_mem_alloc(&self) -> cl_ulong { - // TODO: at the moment gallium doesn't support bigger buffers - min(self.screen.compute_caps().max_mem_alloc_size, 0x80000000) + // The returned value must always be less than or equal to `isize::MAX`, + // as this method may be used for bounds checking on allocations. + // TODO: Add support for larger allocations. gallium doesn't support + // buffers larger than `i32::MAX` due to constraints in the buffer + // mapping API. + min( + self.screen.compute_caps().max_mem_alloc_size, + i32::MAX as cl_ulong, + ) } pub fn max_samplers(&self) -> cl_uint {