Commit Graph
5 Commits
Author SHA1 Message Date
Anees Iqbal 4b564766ec Sample extended-range textures through Metal's bicubic filter
A sample of a BGR10_XR, BGRA10_XR or RGB10A8_2P_XR10 texture (or an sRGB twin) through a constexpr
bicubic sampler, or through a runtime sampler whose bound word states Cubic, was refused
(NotImplemented(SamplerBicubicFilter) in the lowering, NotImplemented(Format) in the binder). It is
now Metal's bicubic filter of the decoded texels, measured on an Apple M3 Max (macOS 26.7) through
the owned fixture xr_bicubic: random codes of each of the six formats at 16x16, 7x5, 3x3, 2x6 and
1x1, 2,304 coordinates each (every texel's centre, then random ones up to 0.15 of the texture past
its edges), through 12 kernels (a runtime Cubic sampler with float and half results; constexpr
samplers under clamp to edge with float and half results, repeat, mirrored repeat, clamp to zero,
the opaque-white and opaque-black borders, pixel coordinates, and an offset under clamp to edge and
repeat): 3,317,760 lanes.

What Metal does, and what the lowering now does: the footprint, weights, addressing, a mirrored
axis and a level below four texels are the other formats' bicubic filter's, each tap the decoded
texel or the border texel through the format's channels; a level below four texels sums as the
extended-range linear filter (terms truncated); otherwise each tap's step is weighed by the
product of Metal's weights and summed exactly (no term truncated, unlike the linear filter), the
step rounded half up, clamped into the steps of the codes 0 and 1023 (a color lane's (0-384)/510
and (1023-384)/510, an sRGB twin's table steps, alpha [0, 1]), and divided by the grid exactly; a
half result rounds as the linear filter's does. The clamp is applied to the rounded result, which
equals clamping the step because each rounding is monotonic. Every lane but 4,050 matches that
model; each of the 4,050 is one step from Metal's (1/8160 a color lane, 1/8192 an sRGB color lane,
1/4080 alpha), its exact sum within 0.014 of a step of a rounding tie that Metal rounds the other
way. No model of Metal's datapath tried closes that residue, so the sample records
PrecisionNote::BicubicFilterArithmetic, and docs/FAST-PATHS.md and docs/API.md say so. A bfloat or
padded form's bicubic sample, a swizzled texture's and a gather through a bicubic sampler were not
measured and are refused.

How: select_extended takes the bicubic state of a constexpr sampler or of the slot's cubic-sampler
variant (LoweringInputs::cubic_samplers) and plans Metal's bicubic filter; the extended sampler emits
it through bicubic::filter with Texels::Extended, which fetches each tap's raw texel and decodes it,
through the exact routines alone, then clamps. The binder takes a cubic word at an extended-range
slot as the cubic-sampler variant's, and gives such a slot the neutral BicubicTexels value in the
plan of the pipeline as compiled, which binds the neutral there (it refused the format before
naming the variant: the device lane found that). SEMANTICS_VERSION 1693; RUNTIME_VERSION 1184, as
a run of an existing artifact with a cubic sampler at an extended-range slot is no longer refused;
the runtime-sources hash re-pinned.

The table: xr_bicubic.tsv (2,067 samples of the probe's, per texture and kernel the middle
texel's centre, four random coordinates, the first sample with a lane at a clamp bound and the
first with a lane at a tie), shared through metal2vulkan_devtools::xr_bicubic with the probe's
texture generator.

Verified on homelab-gem10 (debug builds):
- tests::engine_extended_range::bicubic, on the CPU interpreter on the lavapipe and MoltenVK-M3
  profiles: every lane of the table through the same 12 kernels, compiled under the six forms'
  variants (the runtime ones under the cubic-sampler word the binder plans), is Metal's bits but
  the 136 lanes the table marks, each one step away; each compile validates and its estimate
  bounds it. A padded or bfloat form's bicubic sample, a swizzled texture's and a gather are
  refused as above (a two-plane gather as Format, under any sampler); on every committed profile
  the pipeline as compiled plans the variants with the XR texture and a Cubic sampler bound, and
  the variant's pipeline plans the same key.
- runtime_lane::extended_range_bicubic (new): the 8,268 lanes on the Radeon 780M (RADV), the RTX
  3090 and lavapipe, textures written as the probe wrote them: 0 differ from Metal (136 at a tie,
  one step away), and the state announces bicubic-filter-arithmetic. The extended_range_samples,
  two_plane_samples and two_plane_copies lanes, whose helpers this shares, pass on all three.
- Release build, 12 kernels x 6 forms x 5 profiles (lavapipe, 780M, RTX 5080 Laptop, Arc ANV,
  MoltenVK-M3): 360 translations, mean 1.31 ms, slowest 1.97 ms (xrb_runtime, BGRA10_XR sRGB,
  780M), budget ledger peak at most 935 KiB, process peak RSS 15.6 MB; the linear XR kernels
  take 0.81 ms on average.
- clippy -D warnings (workspace, all features, all targets; validation also under m2v_gpu),
  rustdoc -D warnings and the doctests pass. Suites: metal2vulkan, -air, -runtime and -devtools
  4,566 of 4,567, validation 1,293 of 1,293. The one failure is tests::golden_hashes, whose 380
  stale cells are the two new fixtures' alone (smw_writers 7 and xr_bicubic 12 entries x 20
  profiles), left to be blessed on development.
2026-10-13 17:04:18 +03:00
Anees Iqbal 61a2efc7d3 Fix the GPU test failures seen on the 3090, 5080, XTX, 780M and M3
What and why, per failure (all release, --cfg m2v_gpu):

AMD RADV, Ubuntu Mesa 26.0.8 (RX 7900 XTX, Radeon 780M):
- generated_executions faulted the GPU (amdgpu gfxhub page fault, ring
  reset): RADV before 26.2 skips re-emitting a compute pipeline it thinks
  is bound, so the second execution's implicit preprocess ran our kernel.
  New RuntimeDriverDefect::ImplicitPreprocessAfterExecutionSet (RADV at
  every identity but the measured clean 780M at 26.2.4): the runtime
  preprocesses every execution of a range explicitly, then a barrier, then
  runs them preprocessed. RUNTIME_VERSION 1183.
- The validation executor's generated-commands replay had the same fault;
  it now preprocesses apart on the same defect (runtime's
  generated_commands::preprocess_apart, now public).
- float_denormals under fast math: the test checked a / b, smoothstep and
  (a / b) * c bit for bit, but without VK_KHR_shader_fma (26.0.8) the fast
  reciprocal is the device's OpFDiv(1, y), within 2.5 ulp. Those words are
  now checked at Metal's edges there, in full elsewhere.

NVIDIA 615.71.09 (RTX 3090, RTX 5080 Laptop):
- render_commands_and_render_states_run_as_the_executor_compiles_them: the
  executor used Vulkan device addresses as Metal addresses, and NVIDIA's lie
  below 2^32, where a record's address names no buffer. An addressed
  allocation's guest address is now its device address read signed (RADV's
  are sign-extended) plus 2^47 + 2^32, one translation for every allocation.
- the_runtime_probe_measures_the_test_device_consistently: two driver
  answers Vulkan does not allow (3090: a buffer read after a linear-image
  copy over the same memory in one submission reads stale bytes; both: an
  explicit linear pitch the driver does not lay out is moved, not refused)
  are listed with their evidence in the test; the runtime records neither.
- exits (5 tests): vkDestroyDevice takes ~55 ms alone and up to 2 s beside
  other processes' GPU work on the 3090, so the exit-timing tests run alone
  (.config/nextest.toml); the 1.5 s limit is unchanged.
- pipeline_records (5080): the test assumed the driver finds a pipeline only
  in byte-identical records, but NVIDIA's bytes vary per compile and the two
  formats share entry keys. It now copies a compute pipeline's record over
  the render state's records, which no driver can hit.
- compile_worker (5080, under load): a worker faster than the 1 ms sampler
  left no peak RSS. Each worker now reports its own peak (VmHWM on Linux,
  ru_maxrss on macOS) and the parent takes the larger.
- tests::completion (both, under load): slow rounds were the GPU starting
  late behind another process's ~200 ms busy kernel, or NVIDIA's
  vkQueueSubmit returning up to 64 ms late; the completion was seen within
  1 ms of the moment it could be. A command buffer is now judged from the
  later of its GPU end and its submission's return where the device
  calibrates timestamps (from the commit elsewhere, as before).
- first_use::new_resources_wait_for_no_gpu_work (both, under load): the
  busy kernel's rate came from one wall-clock run, which collapsed under
  load (3 of 28 calibrations), so the busy work lasted milliseconds. The
  rate is now the fastest of every run at every size by GPU time, for all
  four lanes that share it (gpu_times::read_kinds predicts the notice a GPU
  time read emits, for the neutrals test).

Apple M3 Max, MoltenVK 1.4.1:
- heap_textures allows the shadowed-texture route for depth on drivers that
  lay heap depth textures apart.
- The argument-buffer intersection-table test states Metal's own metadata.
- The indirect lane classifies the deferred pipeline-making failure as
  compile-failed alike and keeps only the failed pipeline's error; Apple's
  33-bit closed-form compiler crash is a known gap in docs/FAST-PATHS.md.

Docs: CONTRIBUTING.md and docs/VALIDATION.md say the golden tables and the
compile census are re-blessed on development.

ENGINE_EXECUTOR_ABI is vulkan-engine-v181 (the RADV replay and the Metal
addresses change what the executor submits): every recorded candidate row
and the authored compile census go stale and need re-recording
(scripts/rerecord-venue per venue, rerecord-commit, corpus-status --c3,
corpus-triage --audit authored-compile --bless).

Still open: M3 frees_in_flight, XTX bfloat clears, 780M half NaN blur and
the 5080's one 2 s rebind_bytes_no_copy did not reproduce; the wall-clock
busy calibrations of framebuffer_fetch/storage_forms.rs and queue_storms
remain.

Verified:
- um780 full suites at the AMD fixes (before the executor and NVIDIA
  commits): XTX 3535/3535, 780M 3535/3535, no amdgpu kernel lines.
- Each fix's focused tests before and after on its GPUs (in the agents'
  commits: e.g. generated/indirect 178/178 on XTX and 780M at 26.0.8 and
  26.2.4; candidate 229/229 on 3090, 780M and Iris Xe; the worker peak 0
  of 1440 under 24-way load on the 5080).
- The combined tip: fmt, clippy (with and without --cfg m2v_gpu) and
  rustdoc on ms01; clippy of the validation crate on macOS; a focused run
  on the 3090 was stopped at 333 of 334 passed, none failed. No full suite
  ran on the combined tip.
- The completion and first_use fixes: 3090 load set 1 of 4 runs failed
  before, 4 of 4 passed after (completion) and 12 runs with no first_use
  failure (84 calibrations, 10.19M-11.24M loads); 5080 6 of 6 and 12 of
  12. fmt and clippy (no cfg, m2v_gpu, m2v_cpu_icd) on ms01.
2026-10-13 01:15:18 +03:00
Anees Iqbal ecb80e019d Place heap textures needing up to 256 KiB alignment instead of refusing them
A heap's memory started at a multiple of 64 KiB of the runtime's block, and a
heap texture whose image needed a coarser alignment was refused
NotImplemented(HeapTextureAlignment), by heapTextureSizeAndAlign and
newTexture alike. On an RX 7900 XTX that refused nearly every depth texture a
program puts in a heap: four runtime-lane tests failed there on every run,
each with `alignment: 131072`, while the Radeon 780M in the same machine,
under the same driver, passed them.

Measured with a raw Vulkan probe on homelab-um780 (vkGetImageMemoryRequirements,
optimal tiling, attachment|sampled|transfer usage, 11 formats, sides 1 to
16384, 1/2/4/8 samples, one level or full mips), RADV under Mesa 26.0.8:
- RX 7900 XTX: 128 KiB for D16, D32F and D32FS8 images of 8 x 8 texels or
  more; 256 KiB for multisample depth, stencil and color images from about
  128 x 128 texels; single-sample color, storage and BC1 images at most
  64 KiB. Nothing past 256 KiB.
- Radeon 780M: at most 64 KiB for every shape.

The base is now 256 KiB (HEAP_BASE_ALIGNMENT), the largest alignment measured.
The check moves into check_heap_base, which a GPU-free test can reach, and the
typed refusal stays for anything past the base. A heap over host pages
already starts at offset 0 of its own import, which meets any alignment.

Whole units of the base would have pushed the largest heaps past one
allocation: heap_size admits a heap up to maxMemoryAllocationSize in whole
16 KiB, and where that limit is no whole number of 256 KiB the largest heaps
asked more than the device allocates. RADV (4 GiB less 4 bytes) asked a 4 GiB
allocation for every heap from 4 GiB less 240 KiB, with a block's buffer of
addresses past maxBufferSize; MoltenVK (41,747,087,360 on the M3 Max,
9,534,832,640 on the M4, multiples of 128 KiB but not 256 KiB) would have
asked 128 KiB past the limit for its largest 128 KiB of sizes. So a buffer
past half a pooled block (32 MiB) now keeps its own size (buffer.rs's
`placed`). Such a buffer always takes a block of its own, where nothing
follows it; whole units exist only so the next placement in a pooled block
starts where the last ends. Buffers up to half a block still take whole
units, and half a block is a whole number of 256 KiB.

Cost: a heap of up to 32 MiB now starts at a multiple of 256 KiB of its pooled
block and takes whole 256 KiB units of it, up from 64 KiB units, so a small
heap can hold up to 240 KiB more of its block, on every device. A heap or
buffer past 32 MiB takes exactly its size, no longer rounded up. Programs see
no change where their images need 64 KiB or less. On the 7900 XTX the shapes
past 64 KiB now answer 128 or 256 KiB, are placed, and announce
heap-texture-larger-than-metal.

RUNTIME_VERSION 1179 -> 1181: heapTextureSizeAndAlign and newTexture answer
and refuse differently on such devices, heap buffers lie at other offsets in
the runtime's blocks, and every buffer and heap past half a pooled block
allocates its own size (WorkCounts::device_memory_allocated answers it).
runtime-sources.sha256 is re-pinned. docs/REFUSALS.md is regenerated, and the
reach mark's text says 256 KiB.

Tests:
- tests::heap::every_image_alignment_measured_fits_a_heap_s_base (GPU-free):
  the measured alignments fit the base, and one past it is refused typed.
  With the constant back at 64 KiB it fails (Err(NotImplemented(
  HeapTextureAlignment { alignment: 131072 }))).
- tests::heap::the_largest_heap_asks_one_allocation_of_its_device (GPU-free):
  every committed profile's largest heap asks at most one allocation and one
  buffer. With `placed` rounding every size it fails on amd-780m-radv
  (4,294,950,912 bytes asking 4294967296).
- runtime_lane::heaps::the_largest_heap_lies_in_one_allocation: where the
  largest heap is at most 4 GiB, making it grows the runtime's memory by at
  least its size and at most one allocation, with no validation message.
  Without the size fix it failed on the 7900 XTX ("the largest heap,
  4294950912 bytes, took 4294967296 bytes, past one allocation of
  4294967292"). It reserves the memory without touching it: on Iris Xe a 4 GiB
  heap took 0.04 s and a 53 MiB peak RSS; on lavapipe (debug) a 2 GiB heap
  took 127 MiB.

Verified (release, --cfg m2v_gpu, one GPU pinned):
- The heap set (`test(/heap/) | test(/rebind/) | test(/no_copy/) |
  test(/alias/)`, metal2vulkan-validation and metal2vulkan-runtime), before ->
  after: RX 7900 XTX (RADV, Mesa 26.0.8) 176/180 -> 183/183 (the four
  refusals pass); Radeon 780M (same host and Mesa), RTX 3090 and RTX 5080
  Laptop (NVIDIA 615.71.09) and Iris Xe RPL-P (ANV, Mesa 26.2.4) 180/180 ->
  183/183; lavapipe (--cfg m2v_cpu_icd, debug) 134/134. No kernel GPU
  messages.
- Apple M3 Max (MoltenVK 1.4.1): the heap set plus `test(/buffer/)`. Every
  failure fails identically at the base: heap_textures_answer_and_place_as_
  metal_s_do, argument_buffer_intersection_table_is_encoded_at_reflected_field,
  frees_while_the_gpu_is_busy_fail_no_command_buffer and
  every_case_of_buffers_alone_runs_from_a_command_as_its_dispatch_2.
- Full GPU suites: RX 7900 XTX 3528/3531 and RTX 3090 3526/3531. Every
  failure fails at the base or passes on rerun: on the XTX,
  float_denormals_read_as_metal_reads_them and the two generated_executions
  tests, which fail on the 780M too; on the 3090,
  render_commands_and_render_states_run_as_the_executor_compiles_them and
  the_runtime_probe_measures_the_test_device_consistently fail at the base,
  and three timing tests pass on rerun.
- On the 7900 XTX, the heap lane's output shows answers and placements at
  0x20000 and 0x40000 alignment and no HeapTextureAlignment.
- The runtime crate's GPU-free suite: 856/856. Clippy (workspace, all
  targets, all features, and --cfg m2v_gpu) and rustdoc are clean,
  refusal_surface.py --check passes, and the runtime-sources guard passes.
2026-10-12 20:57:59 +03:00
Anees Iqbal 11715e2a3f Import no-copy memory a driver refuses from the caller's dma-bufs
RADV imports host pointers through amdgpu userptr with ANONONLY, so it
refuses MAP_SHARED memfd pages (QEMU's memory-backend-memfd guest RAM and
views of it): every no-copy buffer, heap and rebind over them was refused,
and a macOS guest could not boot on AMD. NVIDIA imports the same pages.

What:
- The five no-copy entry points (new_buffer_with_bytes_no_copy, both
  new_heap_with_bytes_no_copy calls, Buffer and Heap rebind_bytes_no_copy)
  take a HostMemory; HostMemory::with_dma_buf adds a retained DmaBufSource.
- Where the pointer import is refused, and only there, on any device that
  lists VK_KHR_external_memory_fd and VK_EXT_external_memory_dma_buf, the
  runtime asks the source for dma-bufs of the window's pages (chunks cut at
  the device's sparse granule, sized by the caller within udmabuf's default
  limits) and binds one buffer over them: plain for one chunk, sparse for
  several (vkQueueBindSparse signalling queue 0's timeline; later work waits
  on it, no host wait). Every path that imported before is unchanged.
- Textures over such pages get a dedicated DRM_FORMAT_MOD_LINEAR image import
  of their own pages where the driver takes the plane offset and row pitch
  (multiples of 256 on RADV), with 64-bit modifier features; elsewhere, or on
  a source error, the existing shadow path.
- The extensions are enabled outside the compile profile: no device's enable
  set, fingerprint or ARTIFACT_FORMAT_VERSION changes. The translator crate is
  unchanged.
- Imports free inside exit-guard sections; the source is never called with a
  runtime lock held. WorkCounts gains dma_buf_imports, dma_buf_sparse_buffers,
  dma_buf_images and dma_buf_image_fallbacks.

Verified:
- Product suites 4553/4553, validation suite 1289/1289, clippy in every
  configuration, rustdoc -D warnings, scripts/api-docs.
- runtime_lane::dma_buf_imports and rebinds on RADV Mesa 26.2.4 (validation
  layer clean), the RTX 3090 and lavapipe (pointer imported, source never
  called), and dma_buf_imports on RADV Mesa 26.0.8.
- reims-vgpu on the Radeon 780M (RADV 26.0.8, udmabuf at its defaults): a
  macOS 26 guest cold-boots to the desktop and runs Safari; 5,119 dma-buf
  requests, none refused.
- 64 MiB on RADV 26.2.4, release: pointer import 187 us; one chunk 665 us;
  16 chunks 16.9 ms, about half of it the refused pointer attempt. The old
  host-fence bind waited 1.26 s behind queue-0 work on RADV 26.0.8.
2026-10-12 11:33:41 +03:00
Anees Iqbal 13b279df1b Squash 11203 commits of translator, runtime, and validation work
Rolls up everything since 43c46ac8 into a single commit. Its tree is
identical to the tree of private master at
b3c77f2d2b20a432be10591a2129547c10b1c24b.

- A Cargo workspace of five crates under crates/: metal2vulkan (the
  translator and the metal2vulkan command), metal2vulkan-runtime (the
  Metal API on Vulkan), metal2vulkan-air (the AIR front end),
  metal2vulkan-validation and metal2vulkan-devtools.
- Dual license: GPL-2.0-or-later OR LGPL-3.0-or-later.
- docs/: API, architecture, fast paths, how-to, Metal coverage,
  refusals, runtime porting and validation guides.

Private-Commit: b3c77f2d2b20a432be10591a2129547c10b1c24b
2026-10-11 20:09:13 +03:00