Files
metal2vulkan/crates
Anees Iqbal 8a0ff9110f Bound max_buffer_length by three quarters of the device's largest device-local heap, as Metal does
The RTX 5080 Laptop GPU answered max_buffer_length 2^40 (its maxBufferSize; maxMemoryAllocationSize
is u64::MAX), a length no allocation of its 16 GiB can meet. Metal answers three quarters of
recommendedMaxWorkingSetSize, measured with MTLCopyAllDevices on the cluster's Macs:
- AMD Radeon Pro 5300M (4 GiB, macOS 26.7.1): maxBufferLength 3,208,642,560 of
  recommendedMaxWorkingSetSize 4,278,190,080, exactly three quarters;
- Apple M3 Max (64 GiB, macOS 27.0.1): 41,747,087,360 of 55,662,788,608, three quarters rounded
  down to 16 KiB.
(Intel UHD Graphics 630 on the same MacBook answers 2 GiB of a 1.5 GiB working set: outside the
rule, and no venue of ours.)

What: the runtime reads the size of the device's largest DEVICE_LOCAL heap as it queries the
physical device (DeviceIdentity::device_local_heap) and answers the compile layer's
max_buffer_length bound by working_set_buffer_bound(heap), three quarters of it to 16 KiB; the
runtime holds no working set size, so the heap stands for it. On MoltenVK the M3 Max's heap is
64 GiB (vulkaninfo), whose bound (48 GiB) lies above the compile layer's 41,747,087,360, Metal's
own, which stays. Buffers past the new length are refused nil as before, as Metal refuses them.
The compile layer's MetalDeviceProperties::max_buffer_length (what a shader can address) is
unchanged.

Tests: a runtime unit test of the rule on both Metal measurements and on heaps above, below and
at the limit; the lane's capability check takes the bound and prints both values.

Verified: compile and the 5080 and M3 runs follow in the lane proof run.
(cherry picked from commit 11f1133bd6f80f1917a4f93bb37b2c1402946a40)
2026-11-05 05:10:58 -08:00
..