Files
metal2vulkan/docs/RESOURCE-ID.md
T
Anees Iqbal 1c68dd10f4 Texture buffers: a read-write one is words where its format's own view reads none without a format
A texture buffer's form (rule 2's texture buffer formats, metal::format::texel_buffer_form) asked
three accesses of a format's own view: a uniform texel buffer, a storage texel buffer, and a storage
texel buffer written without a format. A function that reads a texture buffer through
access::read_write reads its storage element without a format, which Vulkan asks of the view's
format (VK_FORMAT_FEATURE_2_STORAGE_READ_WITHOUT_FORMAT_BIT, VUID-vkCmdDispatch-OpTypeImage-07030),
so on a device whose own view of a format lacks that bit the runtime refused the draw or dispatch
(Gap::StorageElement, ReadWithoutFormat). ANV on the Iris Xe (RPL-P) lacks it for BGRA8Unorm,
B5G6R5Unorm, BGR5A1Unorm and BGR10A2Unorm (jobs m3-max-81883, m3-max-82116); its committed profile
(intel-irisxe-rplp-anv) answers the same for RG11B10Float, RGB10A2Unorm and RGB10A2Uint, and so do
intel-irisxe-anv and intel-uhd770-rpls-anv for all seven (job m3-max-82025). Holding those formats
as words for every texture buffer would cost one made to be read 31.6% and 31.7% on that Iris
(texel_buffer_bgra8_read and texel_buffer_b5g6r5_read, job m3-max-82136).

The form now asks a fourth access, the storage read without a format, only of a texture buffer
whose usage, fixed at its making, holds both MTLTextureUsageShaderRead and
MTLTextureUsageShaderWrite, or is MTLTextureUsageUnknown (metal::format::texel_buffer_read_write):
Metal lets a function reach a texture buffer through access::read_write only where its usage holds
both. texel_buffer_form(pf, usage, profile) is one answer per format and usage per device; one made
to be read or written alone keeps the three-access answer. On the three ANV profiles the seven
formats move to words for such a texture buffer and nowhere else. AGENTS.md's rule 2 says so in
the same commit: the three accesses, plus the storage read without a format for a texture buffer
made with both usages, one answer per format and usage per device; it is still one query-chosen
form, and the count of fourteen is unchanged.

The word says the usage, as it says the format, so a shader that meets a texture buffer through a
handle, as one at a slot, tells which answer holds: bit 11 of a texture buffer word of a format
with a word layout, TextureWord::TEXEL_BUFFER_READ_WRITE, is set where it was made both to be read
and to be written. It lies within the 14 low bits an argument buffer's handle carries
(HANDLE_WORD), and the word stays the same on every device. The translator holds the codes a
profile holds as words per usage (WordCodes: alone, read_write); the words twin's held test tests
bit 11 beside the code only where some format is words for the one usage and not the other
(read_write & !alone), and where the two sets are equal the test and the module are what they
were. The runtime asks texel_form of the texture's usage at its making, and
Device::minimum_texture_buffer_alignment, Metal's query of a format alone, answers the larger of
the two forms' alignments: on the three ANV profiles (uniform offset alignment 1, storage 16, a
single texel enough for both) B5G6R5Unorm and BGR5A1Unorm go from 2 to 4 bytes (a word against a
2-byte texel), and BGRA8Unorm, BGR10A2Unorm, RG11B10Float, RGB10A2Unorm and RGB10A2Uint stay 4;
every other profile's two forms are equal, so its answer is unchanged (computed from the committed
profiles' limits, not measured apart).

Public contract, in this commit: TextureWord::of_texture_buffer(pixel_format, width, usage),
texel_buffer_form(pf, usage, profile), the new texel_buffer_read_write and
TextureWord::TEXEL_BUFFER_READ_WRITE (api_surface, api_signatures.tsv); docs/RESOURCE-ID.md's bit 11
row, its texture buffer word section and its test vectors: tests/resource_words.tsv gains a usage
column, each format with a word at read (1) and read-write (3) usage with its widths, and at write
(2) and unknown (0) at width 1. Consumer search: reims-vgpu at 4f46e27e3b (main's) and at its
current e447795571 (mine): no guest computation of words; of_texture_buffer, texel_buffer_form,
TEXEL_BUFFER_ and resource_words have no hit, and TextureWord's one hit is link-order.txt, a symbol
order list naming TextureWord::of. The runtime README's known gap now says the read is served for a
texture buffer made with both usages, and keeps the measured words' cost scoped to those; its form,
alignment and words-cost paragraphs, docs/API.md and docs/REPLAY-STREAM.md name the usage.

The zero for amd-rdna2-apu-radv, intel-arl-anv and nvidia-pascal-linux is unaudited: those
committed profiles report all 39 word formats as words, so no format can move there by this rule
(main opens a row to re-record them).

SEMANTICS_VERSION 2339 (development holds 2338): the words twin's module on the three ANV profiles
and the form's answers move. RUNTIME_VERSION 2558: a texture buffer's form, its word and the
alignment the runtime answers move. runtime-sources.sha256 re-pinned (metal/format/texel_words.rs
and metal/format/mod.rs are runtime inputs). docs/REFUSALS.md does not move (refusal_surface.py
--check passed).

Verified at 0cbe4dfc70, a commit of this same tree on a try branch (tree dd16b6a2f7):
- red: the test before this one (rebased here as 5900eb8642), at ed24bac82a, job m3-max-83041 on
  the Iris Xe (RPL-P, Mesa 26.2.6): every_device_runs_texture_buffers_made_to_be_read_and_written_at_every_slot
  failed with B5G6R5Unorm, BGR5A1Unorm and BGR10A2Unorm "not dispatched", the read-written slot's
  ReadWithoutFormat refusal;
- the Iris Xe (RPL-P, Mesa 26.2.6), the runtime's texture buffer tests (--cfg m2v_gpu, filter
  test(texture_buffer)), job m3-max-83121: 12 run, 12 passed; the new test alone, job m3-max-83127,
  passed, every one of the 15 formats answering the CPU's at every slot. It asserts, per texture
  buffer made, that the words gauge (Gauges::word_texture_buffers) moved exactly where the form
  answers words for its usage, and that the words twin ran once per dispatch where one bound is
  words; every_device_reads_and_writes_texture_buffers_of_formats_held_as_words printed
  B5G6R5Unorm, BGR5A1Unorm and BGR10A2Unorm "own view; made to be read and written, words: every
  answer the CPU's", where they were refused before;
- the Iris Xe, rt_replay's texture_buffers_play_with_their_recorded_ids_and_the_cpu_s_texels
  (--cfg m2v_gpu), job m3-max-83115 (at 9eb68e9c2c, which differs from this tree by a test
  helper's name in the runtime's texture_buffer_words.rs alone): BGRA8Unorm and B5G6R5Unorm play
  as "own view, read_write words" with the recorded IDs (each word with bit 11 where made to be
  read and written), the CPU's texels and values, where the play ended in the refusal before;
- the Intel UHD 630 (Windows driver 101.2145, validation layer 1.4.363.0), job m3-max-83145 (the
  win-cross build m3-max-83134): the runtime's whole suite, 985 run: 984 passed, 1 failed, 4
  skipped; every_device_runs_texture_buffers_made_to_be_read_and_written_at_every_slot and
  every_device_reads_and_writes_texture_buffers_of_formats_held_as_words passed. The one failure,
  half_simd_reductions' every_device_sums_and_multiplies_half_simdgroups_as_metal, fails the same
  way at pin Q (m3-max-82853) and at 2e9f9866be (m3-max-83061) and is outside this change;
- job m3-max-83128 (Linux): the runtime's, devtools' and harness's suites 280 run, 280 passed, 2
  skipped; validation 1323 run, 1323 passed, 3 skipped; conformance 1052 run, 1052 passed;
  doctests; on lavapipe (--cfg m2v_cpu_icd) the runtime's texture buffer tests 12 run, 12 passed,
  and rt_replay's texture buffer play passed, every format the same form for both usages there;
- the Linux gate, job m3-max-83122: cargo fmt --check, signatures --check, refusal_surface.py
  --check, clippy -D warnings (plain, --cfg m2v_gpu, --cfg m2v_cpu_icd) and rustdoc all clean;
  the translator's and AIR suites 3459 run: 3458 passed, 1 failed, 22 skipped, the one failure
  golden_hashes_match_the_table, a bless due of 80 cells under 2339 (the 78 below and
  development's own 2); the runtime guard (the_runtime_sources_are_the_committed_ones) passed;
- golden cells (job m3-max-83165: the golden test's every changed cell at this tree and at
  development's 401d9d5949, the same build, listed in full): 26 cells move on each of
  intel-irisxe-anv, intel-irisxe-rplp-anv and intel-uhd770-rpls-anv (every fixture that reaches a
  texture buffer: a8r_buffers, abt_descriptor_sets, hlf_half_buffer, hsw_storage_writes,
  kernel_read_through, ob1_texel_buffer, rlm_runtime_limits, tb_word_formats, texture_ops'
  texel_buffers, tob_renders, trh_forward, unk_size_queries,
  kernel_texture_variant_leftovers, kernel_write_one_dimensional_textures), and 0 on each of the
  other twelve committed profiles (amd-780m-hawkpoint-radv, amd-780m-radv, amd-rdna2-apu-radv,
  gate-lavapipe, gate-lavapipe-x86_64, intel-arl-anv, lavapipe, moltenvk-m3, nvidia-pascal-linux,
  nvidia-rtx50-linux, nvidia-rtx5080-laptop, runtime-floor): there the two code sets are equal and
  the module is what it was. Development's own two due cells (runtime-floor's a8r_buffer_read_write
  and tb_word_formats) are the same at both. The .air.ll rows need macOS's metal-as and were not
  compared. The table is re-blessed on development;
- the authored compile census (jobs m3-max-83117 at 9eb68e9c2c and m3-max-83118 at
  401d9d5949, checks; m3-max-83148, a bless in its own workspace at this tree, diffed): 0
  differences and 0 failures at both, 21321 cells; 14 artifact digests move, every one on
  intel-irisxe-rplp-anv (a C3 venue), 0 on gate-lavapipe and amd-780m-radv, against 0 at
  401d9d5949;
- the bit test's cost where nothing moves, on the Iris Xe (exclusive, job m3-max-83168): the
  release harness of 401d9d5949 (before, and a copy of it, before2) against this tree's (after),
  built by job m3-max-83124, 8 rounds of 500 runs each, the arms' order rotating: the read-only
  own views texel_buffer_bgra8_read and texel_buffer_b5g6r5_read take a GPU p50 (median of the 8
  rounds) of 9009.0 us and 9215.8 us after against 9009.0 us and 9215.6 us before, +0.00% each,
  before2 against before -0.01% and 0.00%; every run matched its CPU reference.
2026-12-03 03:22:23 -08:00

236 lines
16 KiB
Markdown

# Resource IDs
A Metal texture's or sampler's `gpuResourceID` is a 64-bit value that a shader reads from an
argument buffer or a buffer of its own and then samples, reads or writes through. Under the
translator's identity binding domains the ID is computed on the guest's side, with no round trip
to the runtime, from the index the consumer grants and the object's Metal descriptor:
```text
gpuResourceID = index | word << 32
```
The low 32 bits are the index into the pipeline's heap arrays (set 1, [API.md](API.md) section 5);
the high 32 bits are the word, which carries what a shader reads of the object beyond its
descriptor. Both are pure functions of what the guest already holds, so the same program produces
the same IDs on every run, and a replay reproduces them.
## Index classes
| Class | Index | Object | Arrays it is valid in |
|---|---|---|---|
| nil | 0 | nil (the ID 0) | none |
| texture | 1 to 65,535 | a texture of any usage a shader reaches: `MTLTextureUsageShaderRead`, `MTLTextureUsageShaderWrite`, `MTLTextureUsageUnknown`, or `MTLTextureUsageRenderTarget` of a colour pixel format, which a fragment function reads through its attachment | the sampled-image array and the storage-image array |
| sampler | 1 to 3,999 | a sampler | the sampler arrays |
A texture of any usage may be placed at any index of the texture class. A texture with a storage
element (shader-write or unknown usage, of a format the device stores through a storage image
declared without a format) writes the element of both image arrays at its index; any other
texture writes its sampled-image element and leaves its storage-image element null. A colour
render target made for neither shader reads nor writes leaves both null; a draw that reads it as an
attachment of its own pass (`[[color(n)]]`) reads the runtime's second element at its index plus
65,536, which no resource ID reaches. A texture no shader reaches, a depth or stencil target made
for neither, has no index. A texture view takes its own index of the texture class, and so does
a texture buffer, whose elements are the texel-buffer arrays' (below).
A slot reaches its texture's elements only where the texture's usage holds what the function's
access there asks: `ShaderRead` for a `sample` or `read` slot, a size query alone included,
`ShaderWrite` for a `write` or `read_write` slot, and both for a `read_write` slot the function
reads (Metal's unknown usage takes every access; a view's usage is its texture's). Metal's
validation asks the same, but asks both at every `read_write` slot, by the declared access, one
the function only writes included. A runtime refuses a dispatch or draw
whose function uses a slot whose texture lacks it (the runtime's
`Refusal::TextureUsageAtSlot`): such a slot would read element 0's or a null element's zeros and
drop its writes, where plain Metal reads and writes the texture.
An index has one owner, the object placed there last, as Metal's later texture at a resource ID
takes the ID. A texture or a sampler placed at an index another object holds, a live one or one
the program released that work in flight still holds, writes its elements and owns the index at
once; where the earlier texture had a storage element and the later has none, the later one
writes that element null, so nothing stale answers there. The earlier object's release, and its
teardown once its work retires, touch neither the index nor its elements; the owner's empties
them. Vulkan does not define that write where work in flight uses the element. Keeping it away is
the consumer's duty, not the program's: Metal hands a released ID out again at once (seen on a
Radeon Pro 5300M), so a consumer keeps a released ID back from the program until every command
buffer committed before the release has retired. The runtime does not check it, and does not refuse
the placement: between that retirement and the index's vacate the placement is defined, and the
displaced form is for that window.
## The arrays
Under the identity domains set 1 has one layout for every pipeline: binding 0 is the sampled-image
array of 65,536 elements, binding 1 the storage-image array of 65,536, bindings 2, 3 and 4 the
sampler arrays of 4,000 elements each, and bindings 5 and 6 the uniform and the storage
texel-buffer arrays of 65,536 elements each, every one partially bound, updated after binding and
while unused elements are pending, and seen by every stage. Shaders declare the arrays unsized, so
a consumer's layout may hold more elements than these; the runtime's sampler arrays hold 8,000,
the last 4,000 for sampler states bound with LOD clamps of their own, which no ID a program
writes reaches, and its storage-image array 131,072, the last 65,536 the level elements: 4,096
runs of 16, each the single-level storage views of one texture's levels in order from its first,
which a slot written or read at a level other than the constant 0 indexes. The slot pushes the
run's first element (`PushField::TextureLevelBase`) beside the texture's level count
(`PushField::TextureLevels`), and an access at level `l` takes element
`first + min(l, max(count, 1) - 1)` only where `l < count`; a texture of one level pushes its own
index, and nil 0 with count 0. No ID reaches a level element. Element `i` of each image array is the
texture whose ID holds index `i`, and element `i` of each texel-buffer array the texture buffer
whose ID holds it (a read texture buffer is a uniform texel buffer, a written one a storage texel
buffer), so the consumer writes an element once, as it makes the texture, for every pipeline; a
texture's texel-buffer elements and a texture buffer's image elements are null. Element 0 is a null
descriptor (`nullDescriptor`, which the floor requires): a nil texture sizes 0, reads and samples
zero, and drops a store, as Metal answers for a nil texture, with no code in the shader. So is every
image and texel-buffer element no texture owns: the runtime writes every element at device
creation, a null descriptor in each image and texel-buffer array and a default sampler (nearest,
clamped to the edge, every level reached: `maxLod` is `VK_LOD_CLAMP_NONE`; the comparison array's
compares with `NEVER`) in each sampler array, as Vulkan has no null sampler, and writes an element back to that once its owner goes. An index
nobody owns, nil, freed or stale, reads as nil and cannot reach a destroyed view or sampler. Each
texture class a shader declares (its shape, numeric type and depth
comparison, sampled, or storage without a format, or storage of `R32Uint` or `R32Sint` for a
texture atomic or of `RG32Uint` for a `ulong` texture's reads and writes; a texture buffer's of
the same, a texel buffer) is a variable of its descriptor type's binding.
A shader takes a texture slot's ID from the slot's push field (`PushField::SlotGuestBase`), and an
argument buffer's texture's ID from the member's 8 bytes, with no table between. It indexes the
arrays with the low word, answers `is_null_texture` by whether the index is 0, and,
where it checks a `read` itself (a device without `robustImageAccess2`), takes an out-of-bounds
alpha of 1 from bit 12 of the word. A texture buffer whose word names a format the device holds
as words takes its format, its texels per word, whether a texel is two words and its padding from
bits 0-10 of its word, and the shader learns that the device holds it as words from its code and,
where the device's answer for its format differs with the usage, bit 11. A slot's `read` through a sampler (MSL 4.1) takes the border
texel an index outside the level reads on a border axis from bits 0-11 of the word, for the
sampler's border color; a texture buffer's whose word has bit 13 set, from the border texels of
the format its code names, as an argument buffer's texture buffer held as words does from the code
its handle carries. The runtime writes a slot's ID, so its index is an element;
the program writes an argument buffer's, so the shader masks its index to its low 16 bits: a bad
ID reads the element at `index & 0xFFFF`, never one outside the arrays.
Element `i` of each sampler array is a device sampler made of the sampler whose ID holds index `i`,
one per use, which the shader picks by the instruction and the texture's numeric type: binding 2
for a plain sample, 3 for a depth comparison, and 4 for a texture of an integer format, every
filter nearest. The consumer makes each from the descriptor (its reduction mode and anisotropy
included); it makes none of a descriptor whose min or mag filter is cubic. A shader takes a
runtime sampler slot's ID from the slot's push field, samples through the element its low word
indexes, and reads the word's fields where a sample depends on them (pixel coordinates, a nearest
pixel sampler).
A sampled cube's or cube array's element is its cube view, whose texels no fetch addresses, so a
`read` of it by face (`read(coord, face, lod)`, and with the cube index for a cube array) samples
that view through element 0 of binding 2, or of binding 4 for an integer texture, which no ID
reaches: the default sampler, nearest with every level reached. It samples at the direction of
the texel's centre on the face and at the read's level as an explicit level, which reads exactly
that texel; the shader tests the coordinate against the level's extent, the face against 6, the
cube index against the cube count and the level against the level count itself, and reads
Metal's out-of-bounds texel (its alpha from the word) outside them. A consumer that lays the
arrays out itself places that default sampler at element 0 of both.
A constexpr sampler has no ID: the consumer places a device sampler of it (the function's
`PushField::ConstexprSampler` names it and its use, and `CombinedSampler::constexpr_sampler`
describes it) at an index of the use's array and pushes that index as a `u32`. Its coordinates
are normalized; the shader scales a pixel sampler's coordinate itself. It samples with its own
address modes. A shader takes an argument buffer's sampler's ID from the member's 8 bytes,
samples through the element of its use's array that its low word indexes, and reads the word's
fields as a runtime sampler slot's. The program writes the ID, so the shader compares its index
with the arrays' length: an index of 4,000 or more reads element 0, the default sampler, never one
outside the arrays. The runtime makes no sampler of a cubic filter, so no live ID's word carries
bit 30, and the shader does not test it.
## The texture word
`metal2vulkan::metal::resource_word::TextureWord::of(pixelFormat, swizzle)`:
| Bits | Field |
|---|---|
| 0-11 | the border texels: bit `3c + b` is set where channel `c` (0 red, 1 green, 2 blue, 3 alpha) reads 1 rather than 0 outside the level for border color `b` (`MTLSamplerBorderColor`'s raw value) |
| 12 | the format has no alpha, so an out-of-bounds `read` reads alpha 1 |
| 13-15 | 0 |
| 16-31 | the `MTLPixelFormat` raw value |
The border texels are taken after the swizzle. A color format's channels are its own, a missing
red, green or blue reads 0 and a missing alpha reads 1; `A8Unorm`'s alpha is the color's red; a
format held rotated (`ARGB8Unorm`) reads red from the color's green, green from its blue, blue from
its alpha and alpha from its red; a depth or stencil format reads as red, green and blue, alpha 1.
Every pixel format's raw value is above 0, so a texture's word is never 0. The placeholders
(`Invalid`, `Unspecialized`) and the formats the translator holds no texture of or only copies have
no word.
## The texture buffer word
`metal2vulkan::metal::resource_word::TextureWord::of_texture_buffer(pixelFormat, width, usage)`:
the texture word of its format under each channel's own swizzle. Where the format has a word layout,
bit 13 is set and bits 0-11 hold the layout's fields in place of the border texels; a read
through a sampler of such a texture buffer takes its format's border texels from its code. Every
other texture buffer's word is its texture word, border texels included:
| Bits | A format with a word layout | Any other format |
|---|---|---|
| 0-1 | the texels the last word holds past `width`, 0 to 3 | the border texels |
| 2-7 | its code, 1 to 39 (below) | the border texels |
| 8-9 | the base-2 logarithm of the texels one word holds, 0, 1 or 2 | the border texels |
| 10 | a texel is two words, the low word first | the border texels |
| 11 | it was made both to be read and to be written: `usage` holds `MTLTextureUsageShaderRead` and `MTLTextureUsageShaderWrite`, or is `MTLTextureUsageUnknown` (`metal::format::texel_buffer_read_write`) | the border texels |
| 12 | the format has no alpha | the format has no alpha |
| 13 | 1 | 0 |
| 14-15 | 0 | 0 |
| 16-31 | the `MTLPixelFormat` raw value | the `MTLPixelFormat` raw value |
A format has a word layout where it is a colour format whose Vulkan format Vulkan does not
require as a storage texel buffer (its mandatory format tables), or that has no Vulkan format of
its own, and the word carries its fields on every device (`metal::format::texel_buffer_words`),
so the word is the same on every device. A device holds a texture buffer of such a format as words
where it lacks the format's own Vulkan format, held directly, as a uniform texel buffer, a storage
texel buffer or a storage texel buffer written without a format, and, for a texture buffer made
both to be read and to be written (bit 11), as a storage texel buffer read without a format
(`metal::format::texel_buffer_form`): one answer per format and usage. A module holds those answers
for the profile it is compiled for, and tests a word's bit 13 and code, and its bit 11 where the two
answers differ for some format, only where its stage's `SpecKey::TexelBufferWords` is set (the
runtime's words twin). The view is then of `R32_UINT`, its
texels packed in the buffer's bytes as Metal lays them out: a texel of `b` bytes, `w` texels wide,
views `⌈w · b / 4⌉` words, and its width is the words times its texels per word, halved where a
texel is two words, less its padding. Elsewhere the view is of the format's own Vulkan format,
`w` texels, and the shader reads its width from it. The codes, from 1:
`A8Unorm`, `R8Unorm`, `R8Unorm_sRGB`, `R8Snorm`, `R8Uint`, `R8Sint`, `R16Unorm`, `R16Snorm`,
`R16Uint`, `R16Sint`, `R16Float`, `RG8Unorm`, `RG8Unorm_sRGB`, `RG8Snorm`, `RG8Uint`, `RG8Sint`,
`B5G6R5Unorm`, `A1BGR5Unorm`, `ABGR4Unorm`, `BGR5A1Unorm`, `RG16Unorm`, `RG16Snorm`, `RG16Uint`,
`RG16Sint`, `RG16Float`, `RGBA8Unorm_sRGB`, `BGRA8Unorm`, `BGRA8Unorm_sRGB`, `RGB10A2Unorm`,
`RGB10A2Uint`, `BGR10A2Unorm`, `RG11B10Float`, `RGB9E5Float`, `RGBA16Unorm`, `RGBA16Snorm`,
`BGR10_XR`, `BGR10_XR_sRGB`, `BGRA10_XR` and `BGRA10_XR_sRGB` (`metal::format::WORD_FORMATS`). A
format keeps its code. A texture buffer whose words overflow a `u32` has no word.
## The sampler word
`metal2vulkan::metal::sampler::SamplerWord::of(descriptor)`. Each field holds its
`MTLSamplerDescriptor` value's raw Metal value, so the default descriptor's word is 0:
| Bits | Field |
|---|---|
| 0 | `normalizedCoordinates` is false |
| 1 | `minFilter` is `Linear` |
| 2 | `magFilter` is `Linear` |
| 3-4 | `mipFilter` |
| 5-7, 8-10, 11-13 | `sAddressMode`, `tAddressMode`, `rAddressMode` |
| 14-15 | `borderColor` |
| 16-18 | `compareFunction` |
| 19-20 | `reductionMode` |
| 21 | `maxAnisotropy` is above 1 |
| 22-25 | the level a nearest mip filter reads at `lodMinClamp` |
| 26-29 | 15 less the level a nearest mip filter reads at `lodMaxClamp` |
| 30 | `minFilter` or `magFilter` is `Cubic` |
| 31 | 0 |
The level a nearest mip filter reads at a clamp `c`: take `c` below 0 as 0, and below 64 truncate
it onto sixty-fourths of a level; if the result is 15 or more the level is 15; otherwise, with `L`
its whole levels and `q` its fraction, the level is `L + 1` where `q` is above one half, else `L`.
The LOD clamps themselves, `lodAverage` and the anisotropy's degree are not in the word: the
Vulkan sampler applies them.
## Test vectors
[`crates/metal2vulkan/tests/resource_words.tsv`](../crates/metal2vulkan/tests/resource_words.tsv)
holds one descriptor per line with its word, in tab-separated raw Metal values; its header names
the columns. A texture line is a pixel format and its four swizzle sources; a texture buffer line a
pixel format, a width and a usage (`MTLTextureUsage`'s raw value); a sampler line is every
`MTLSamplerDescriptor` field above, with `lodMinClamp` and `lodMaxClamp` as the float's IEEE-754
bits. Words are hexadecimal.
The translator's tests (`tests/resource_words.rs`) recompute every line's word and hold the file
equal to what the word functions generate, so a changed word changes the file. A guest's own
computation of the words checks itself against the same file.