Answer maxArgumentBufferSamplerCount from the set-1 sampler array and the sampler limit

What: `DeviceProperties::max_argument_buffer_sampler_count`, Metal's
`maxArgumentBufferSamplerCount`: one fewer than the smaller of a set-1
sampler array's elements and the device's maxSamplerAllocationCount
(element 0 of the array, and one of the device's samplers, are the
neutral sampler's; each state the array holds takes an element and a
sampler of its own). The array's elements are a new public translator
function, `pipeline::heap_sampler_capacity`: link's heap capacity for a
heap of one sampler array with set 0 counting no sampler, the least of
the handle table's 65536 entries (TABLE_CAPACITY) and the two
update-after-bind sampler limits, 0 where a function cannot read a set-1
sampler array (the layout's features or the module's non-uniform
sampled-image indexing). Link's heap_capacity now reads the same limit
table (`heap_limits`) and arithmetic (`room`), and heap_set the same
layout-feature check (`heap_layout_lacks`), so the sizing and the answer
cannot drift. The runtime's `Device::sampler_array` (each state's
creation-time check) now calls it too: it was the two update-after-bind
limits without the handle table's reach, 500000 on MoltenVK where link
makes 65536 elements, so a state past 65535 was not announced as it was
made. The device's SamplerCount and the answer read one value, the
identity's maxSamplerAllocationCount.

Why: the consumer computed it as the least of the two update-after-bind
sampler limits and maxSamplerAllocationCount; that misses the handle
table's reach (500000 against our 65535 on the M3) and the neutral's
element (32768 against 32767 on lavapipe, 4000 against 3999 on NVIDIA).

Metal on the M3 Max (macOS 27.0.1) answers 500000 (a Swift query of
MTLCreateSystemDefaultDevice, potluck job m3-max-2496), recorded in the
field's docs and docs/API.md's accepted differences.

Tests: engine_handles::an_argument_sampler_array_has_the_heap_sampler_capacity
(link's array equals the function on every committed profile, follows
lowered limits, 0 without the features); capabilities::
argument_buffer_samplers_are_one_fewer_than_the_array_and_the_sampler_limit
(every committed profile, pinned venue values); the device test
argument_sampler_count (the kernel's array, the device's count, the
driver's limit and the answer agree; elements-1 states unannounced, the
next announced). Verification follows in the branch's report.

(cherry picked from commit 7a2b84f15a1dde81e35cbc0b9367962e54d8332f)
This commit is contained in:
Anees Iqbal committed 2026-11-05 18:59:21 -08:00
1 parent 296723b362
commit 570df3cc95
18 files changed
+526 -108

No files matched your search

+9 -1
View File
@@ -903,7 +903,8 @@ for dependency in &pipeline.dependencies {
says whether Metal binds a buffer, a visible-function table or an intersection function table
there.
- The layout numbers set 0 densely, in `ResourceSlot` order. Set 1 holds the heap arrays (the
resources reached through argument buffers and resource IDs). Push constants carry the values the
resources reached through argument buffers and resource IDs); `pipeline::heap_sampler_capacity`
is the most elements a set-1 sampler array has on a profile. Push constants carry the values the
binder writes per command. A stage that writes the command buffer's `ExecutionStatus` (an absent
argument's read, a `seq_cst` fence, an argument buffer's cubic sampler) reaches it by device
address, a push hole, where the device addresses buffers (`bufferDeviceAddress` and
@@ -3883,6 +3884,13 @@ each item named states the rule in full.
- **The device counts the sampler IDs it holds** (`Device::sampler_ids_live`,
`Device::sampler_id_pool_size`), runtime extensions for a consumer that models Metal's sampler
heap.
- **`maxArgumentBufferSamplerCount` is the device's set-1 sampler array less its neutral**
(`DeviceProperties::max_argument_buffer_sampler_count`): one fewer than the smaller of the
array's elements (`pipeline::heap_sampler_capacity`: at most the handle table's 65536 entries
and the update-after-bind sampler limits) and `maxSamplerAllocationCount`. Metal answers 500000
on an M3 Max; MoltenVK there answers 65535. It counts every live sampler state, with or without
`supportArgumentBuffers`. A state past it reads the neutral sampler through an argument buffer
(`unlisted-argument-sampler`).
- **A texture can take no resource ID** (`IdPlacement::Outside`), for a consumer's helper textures
and its textures over its own images (`Device::new_texture_with_vk_image`), such as swapchain
images.