Commit Graph
9 Commits
Author SHA1 Message Date
Anees Iqbal 62b3e5a250 rt: the render encoder's use_resource, and a draw after a declared write of a texture with no storage element is Gap::StorageElement
What: RenderCommandEncoder::use_resource is useResource:usage:stages:, its plural and their
deprecated forms without stages. The command buffer keeps the buffer or the texture until it
retires and nothing is recorded: every resource is resident to every function, and the pass's
barriers already order its draws. A usage that writes a texture (or a view of one) made for
shader writes with no storage element marks the encoder, and every later draw whose vertex or
fragment function may reach a texture through its storage image beyond its slots
(PipelineInterface::unbound_storage_textures: an argument buffer's write or read_write texture, a
resource ID) is Gap::StorageElement with no slot, as the compute encoder's dispatch already is.
Before this, such a draw ran and Vulkan dropped the writes Metal makes. The declaration
invalidates the encoder's held draw facts, so a draw of an unchanged state and bindings after it
is checked again.

Also: the three redundant explicit links in new_render_pipeline_state's docs (private rustdoc
-D warnings, from 3653240b57) are plain intra-doc links; Refusal::OtherDevice's doc names the
render encoder's calls; the README's storage-element known gap no longer waits for the render
encoder's useResource:, and the render encoder's section describes use_resource; coverage.tsv
marks the four MTLRenderCommandEncoder useResource rows implemented; REFUSALS.md,
METAL-COVERAGE.md, CONFORMANCE-COVERAGE.md and api_signatures.tsv regenerated.

Test: every_device_refuses_a_draw_after_a_declared_write_of_a_texture_with_no_storage_element
(storage_element.rs, device cfgs): an owned fragment function writes an argument buffer's
texture2d<float, write>; for RGBA8Unorm, RGBA8Unorm_sRGB, BGRA8Unorm_sRGB, A8Unorm and an sRGB
view of an RGBA8Unorm texture, a draw before the declaration draws, the same draw after
use_resource(WRITE) is Gap::StorageElement { slot: None, pixel_format } exactly where the texture
has no storage element, and a colored_fragment draw after the declaration draws; the fragment
function's write through its resource ID lands (1, 0, 1, 1). Without the Facts::find check the
refused cases draw and the test panics.
2026-11-20 22:08:11 -08:00
Anees Iqbal 9a1c8fe6dc metal2vulkan-rt takes the runtime's name: metal2vulkan-runtime, published
The cutover's last mechanical step. The old runtime is deleted, so its name is free: the crate
moves to crates/metal2vulkan-runtime, its package is metal2vulkan-runtime and its library
metal2vulkan_runtime, and every reference in the tree follows (sources, tests, scripts, CI,
generated tables and docs).

It is now a published crate, as AGENTS.md said it would be once it took the name: version 0.2.0
with the other two, the translator pinned exactly (=0.2.0, as the translator pins the AIR front
end), documentation, keywords and categories, and copies of the repository's four license files,
which the published-crates test now holds equal to the root's for three crates. CI packages it
with the others. Prose that said it was unpublished, or counted two published crates, says three.

AGENTS.md: facts only. The crate table row, the published-crates and version sentences, and the
paragraph on the old runtime, whose name the runtime now carries (listed for the owner).

Made by one script run on this tip. Verified by the job
named in the landing note.
2026-11-20 09:10:02 -08:00
Anees Iqbal a9acc24aa0 Coverage map: rows rt and the translator answer through their own calls, per-row sizes, refusals by rt's names
The fast switch to metal2vulkan-rt marked missing every runtime row whose old counterpart rt
does not hold under the same name. rt's and the translator's Rustdoc answer more of them:
- 28 runtime rows are implemented: the 9-argument texture and buffer-to-texture copies and the
  options form with no option, `enqueue`, `commandBufferWithUnretainedReferences` (the same call
  as `commandBuffer`), every `withRange:` setter of both encoders (a loop of the single setter),
  `useResources:count:usage:` and `useHeaps:count:`, both encoders' memory barriers,
  `newBufferWithBytesNoCopy` (Device::import_host_memory and a buffer in its block),
  `MTLCreateSystemDefaultDevice` (Device::new), `MTLCopyAllDevices`
  (Instance::physical_devices), a texture's `storageMode` through its descriptor, and
  `renderPassDescriptor` (RenderPassDescriptor's Default);
- 23 translator rows are implemented: MTLLibrary and MTLFunction by the translator's Library
  and Function (from_metallib, function, functions, library_type, install_name, properties,
  function_constants_dictionary, reflection), and MTLFunctionDescriptor by FunctionDescriptor;
- maxBufferLength and a texture descriptor's resourceOptions are the consumer's;
- 53 missing rows take their own size and note: encoder calls (S for loops of existing calls and
  store action options, M for stride binds and indirect draws, L for vertex amplification),
  render pass fields, a texture buffer's descriptor and alignment, function options;
- refusals are named by rt's types: Gap::IndirectCommandBuffers, Gap::KernelInput and
  Gap::DrawInput for function tables, RenderPipelineKind::VertexAmplification and Tessellation,
  RenderPassKind::TextureType and NoAttachment, Gap::TextureBuffer;
- 629 notes no longer name the old runtime's items (RuntimeGap's variants, FeatureRow's rows,
  its compiled_reflection, function_handle, allocated_size, new_library_with_source and
  BlitOption).
coverage.py's group names follow (buffers, encoder calls, command buffer options, function
options). docs/METAL-COVERAGE.md and docs/CONFORMANCE-COVERAGE.md regenerated: implemented
593, missing 1118, out of scope 424.

Verified: every implemented row resolves by the test's own rules in its crate's sources (a
script run of them: runtime 237, translator 356, none missing); every `Type::name` a note names
is held by rt or the translator (14 checked; the same check over the table before this commit
finds 26 it does not hold). The compile job is named in the hand-off.
2026-11-20 06:02:37 -08:00
Anees Iqbal 220473aafd Coverage map: the runtime's counterparts are metal2vulkan-rt's, and the test reads rt's sources
The old runtime is being deleted, and the coverage map's 649 runtime rows named its items. Every
runtime row now names metal2vulkan-rt's counterpart or none:
- 180 rows whose counterpart rt holds under the same name keep it;
- 29 take rt's name for it: DeviceProperties fields that are Device methods, the heap placements
  that are Device::new_heap_buffer and Device::new_heap_texture, the lod-clamp and stencil
  setters, the dispatch type taken by CommandBuffer::compute_command_encoder, and a texture's
  getters through Texture::descriptor;
- 73 are out of scope as rt's README gives them to its consumer: labels, MTLHeap and its
  descriptor, MTLBinaryArchive and every descriptor's binaryArchives, a resource's options, a
  texture's parent and shareable getters, a library's and a function's device;
- 367 are missing, each with a group, a size and a note: indirect command buffers (71), function
  tables, handles and dynamic libraries (38), mesh (33) and tile (26) pipelines and their calls,
  encoder calls (59), argument encoders (24), libraries and functions as runtime objects (25),
  and smaller groups. Their sizes are the group's, to be refined.

coverage.py names metal2vulkan-rt as the runtime and gains the new groups;
metal_coverage.rs reads crates/metal2vulkan-rt/src. docs/METAL-COVERAGE.md and
docs/CONFORMANCE-COVERAGE.md regenerated from the table (implemented 542, missing 1171, out of
scope 422).

Verified: every implemented runtime row resolves in rt's sources by the test's own rules (a
script run of them over the tree: 209 of 209); the compile job is named in the hand-off.
2026-11-20 05:28:07 -08:00
Anees Iqbal 2b0b59061a Runtime sampler descriptor: lod_bias, read as an Apple9 GPU reads it
SamplerDescriptor gains `lod_bias: f32` (MTLSamplerDescriptor.lodBias,
default 0, serde default), so a guest's bias is carried rather than
having no field to land in.

What Metal does with it, measured on the M3 Max (Apple9, macOS 27.0.1
26A434) with a throwaway Swift probe of runtime-compiled MSL (jobs
m3-max-19665/19666): level L of a 7-level texture held L, so every
sample read its own level of detail. Across 136 row groups no sample
changed with the sampler's bias: fragment implicit, shader bias(),
level(), gradient2d(), min_lod_clamp() and bias+min_lod_clamp; kernel
default, level, gradient and bias; linear and nearest mip filters on
float textures, both on uint ones; a NotMipmapped sampler's min/mag
choice; clamps [1,3], [1.5,MAX], [0,2]; biases -1000 to 1000, 15.99,
16, 16.5, 17, NaN, +-inf. The probe saw levels move with the shader
bias, the clamps, explicit levels and the NotMipmapped filter switch.
With MTL_DEBUG_LAYER=1 every value made a sampler with no assertion and
read back as set. Apple's tables list the bias under Apple10, which no
runtime device claims.

So the Vulkan sampler's mipLodBias stays 0 whatever the descriptor
holds: no bias is past maxSamplerLodBias, and none needs a portability
subset's samplerMipLodBias. The binding shape and the sampler word do
not carry it either. The runtime's state key does: on the M3 (job
m3-max-19683, with and without validation) biases 0 and 1, 1 and
1.0001, and 20 and 30 gave two states each, while 0 and -0, and two
NaNs of one encoding, gave one. The key takes the bits of `bias + 0.0`.

The Apple10 family row stays a gap, its reason now that the biased
level of Apple10 is not built. The conformance suite's SamplerSpec
states the bias too (tag 8, a word only where it is not 0, so no
recording's fingerprint moves), and both legs set it. METAL-COVERAGE
lists lodBias as implemented; CONFORMANCE-COVERAGE and the API
signature table are regenerated.

Tests: metal::sampler::a_lod_bias_makes_the_unbiased_sampler covers
every committed profile, every mip filter, three filter pairs and four
uses plus the unnormalized one, and 15 biases: the Vulkan sampler and
the binding shape are the zero bias's. That includes MoltenVK, which
withholds samplerMipLodBias, and biases past every device's limit.
runtime_lane::lod_bias::a_sampler_s_lod_bias_reads_the_unbiased_level
runs a kernel's biased samples through runtime sampler states of ten
biases, under linear and nearest mip filters, and compares them bit for
bit with the unbiased state's. It also checks the state-sharing rule.
2026-11-12 00:51:28 -08:00
Anees Iqbal 5e51dc6023 METAL-COVERAGE names the macOS 27.2 SDK its table was checked against
coverage.py's SDK line still said the macOS 27.0 SDK (Xcode 27.0, 27A266a),
while the M3 has Xcode 27.2 (27B52) and its MacOSX27.2.sdk; the generated
enum tables already name 27.2. The table needed no row change: on the M3,
coverage.py --sdk against MacOSX27.2.sdk answered 'coverage.tsv names every
SDK item (2135)', rc 0 (potluck job m3-max-13567). docs/METAL-COVERAGE.md
regenerated (coverage.py), coverage.py --check current.

(cherry picked from commit ca8424427caaa8636587eb5593e7b91b68afe9b1)
2026-11-10 04:15:05 -08:00
Anees Iqbal 61a9508e92 Build visibilityResultType: Accumulate takes a pass's results into the buffer's words
RenderPassDescriptor gains visibility_result_type (MTLVisibilityResultType: Reset, the default
and today's behaviour, and Accumulate). Under Accumulate no query result is copied over its
offset's word: every query of an offset, the first one too, is copied into the upload region the
continuations already use, and the crate-owned combine takes them into the word as the buffer
holds it. The combine already loaded the destination word as its accumulator, so Accumulate is
the first query becoming one more source. A `Boolean` word ORs the device's results in; a
`Counting` word is summed in through a new table mode of the combine, into the word's low 32 bits
alone, wrapping there, its high 32 bits kept (ContinuedResult::low_half / in_low_half). That last
part is what the M3 Max answered when recorded: 0xffff_fff8 plus 16 samples writes 8, and
0xffff_ffff_ffff_fff8 plus 16 writes 0xffff_ffff_0000_0008. A plain 64-bit sum was divergent there.
An offset set with no draw after it keeps its word, because a query with no draw adds 0. Where a
no-copy buffer's bytes start off a multiple of 8, so the results land in an upload region, the
words are now copied into that region before the combine (Landing::inward). Reset records exactly
what it did before.

Conformance: RenderPass gains visibility_type (typed()), and words() appends it only where it is
not Reset, so existing fingerprints read as before. Both sides set it. There are four new
visibility cases, recorded on the M3 Max (macOS 27.0.1): visibility-counting-accumulate (two
command buffers; words 100/5/7/0xffff_fff8/u64::MAX-7), visibility-counting-accumulate-one-command-buffer
(two passes in one command buffer, read once), visibility-counting-accumulate-revisit, and
visibility-boolean-accumulate (words 0/2/3 under covering and non-covering draws, an offset set
with no draw, then a second command buffer). The family's acts key states the type, and a joined
shape adds a command-buffer input. Cost and timing records for the new cases are not written here.

Lane tests (runtime_lane): accumulated_counts_add_to_the_words,
accumulated_booleans_or_into_the_words, and
host_bytes::accumulated_visibility_results_land_where_their_bytes_lie. Unit tests: the combine's
accumulated_counts_are_summed_into_the_low_half, its plan's table mode, and the type's raw values.

Coverage: coverage.tsv marks MTLRenderPassDescriptor.visibilityResultType implemented (its unused
"visibility" group is removed), and METAL-COVERAGE.md is regenerated. MTLVisibilityResultType joins
the enum table, so metal_enumerators.tsv and CONFORMANCE-COVERAGE.md are regenerated. The API
signatures are re-blessed. REFUSALS.md is regenerated: VisibilityResultType::from_raw is one more
UndefinedValue site. The regeneration also picks up two bind/graphics.rs sites the committed file
was missing. The degrade docs (landed results, Boolean) state Accumulate.

Verified on the M3 Max under MoltenVK 1.4.2:
- The 52 visibility-touching lane tests pass: visibility, host_bytes, depth_never, amplified_draws,
  degrade_notices and the framebuffer_fetch split pass.
- The visibility family's replay is all announced (no divergence), after the low-half change.
- Negative control with Accumulate forced to Reset: all three Accumulate lane tests fail, and all
  four new cases replay divergent.
- Negative control with no inward copy: the landing test fails at 4 bytes past a page (2 read 0,
  100 read 16).
- Before the low-half change, visibility-counting-accumulate replayed divergent at words 3 and 4.
- The combine's low-half test fails on the interpreter without the high-half select ([8, 1] for
  [8, 0]).
clippy (plain and --cfg m2v_gpu), rustdoc and scripts/api-docs are clean.

SEMANTICS_VERSION: no translated shader changes, but the owned combine module's words do
(main's call). RUNTIME_VERSION and the runtime-sources pin are not touched here.

(cherry picked from commit 1c172968ad6492cebcae2a568fc99e90565d4d11)
(cherry picked from commit 9f47ebcf006920f7561a16a77f77e422de7201c1)
2026-11-03 11:08:01 -08:00
Anees Iqbal 0175289314 Batch the development-fast round: tessellation without tessellationShader, primitive ids, mesh tooling, color groups, the vk12 floor, runtime timing and teardown fixes
One commit of the 247 on development-fast (720ef1ce9a..9f46fdf80d), squashed at the user's request.

Translator:
- Tessellation on a device without tessellationShader: Metal's tessellator emitted as SPIR-V, a
  one-workgroup scan placing each patch's triangles in Metal's order, and the post-tessellation
  function as a plain vertex stage (EmulatedTessellationDraws; SEMANTICS 1739, ARTIFACT_FORMAT 419).
- [[primitive_id]] on a device without geometry or tessellation shaders, as a flat varying the
  vertex function writes; indexed lists, lines and points drawn de-indexed (RuntimeGap::PrimitiveIdIndices).
- Fragment functions of more colors than the device draws at once, compiled in color groups
  (PrecisionNote::ColorAttachmentGroups).
- Object functions' threadgroup memory from the render encoder; a kernel's mesh draws from an
  indirect command buffer; mesh payload sizing.
- The Vulkan 1.2 floor profile (vk12-floor) and the gates it needs; Metal 27.0.1 answers as the M3 Max.
- Overflow tests in the runtime-built modules by the product's high word (NVIDIA's compiler fails
  the division form), guarded crate-wide by tests::owned_divisions.

Runtime:
- Color-group passes replayed per group over twin depth/stencil; snapshot and copy-back cost cuts.
- Command buffers finish on the queue waiter that saw them; the waiter holds no device handle, so
  a program's drop after its wait is the device's last.
- Every object an encoder was handed held until its command buffer completes; deallocator order
  and announcements.
- Driver defects recorded and announced: ANV counts a visibility sample once per color output
  (visibility-count-per-color); MoltenVK fails pending work when memory that held a device-address
  buffer is freed, so freed memory waits for the work in flight (host-deallocator-delayed).
- RenderCommandEncoder::set_object_threadgroup_memory_length; Visibility::counting().

Validation: mesh tooling (object, mesh and ICB-mesh cases on both executors), the authoring
census closed, the queue storm judged in Metal's unit, load-robust exits and indirect-census
bounds, and the golden hashes, printouts, fixture inventory and authored compile census blessed.

Docs: FAST-PATHS.md trimmed to a ledger of what is true now; API.md's catalogue and accepted
differences, REFUSALS.md and METAL-COVERAGE.md current.

Verified on development-fast before the squash: the full suites on the RTX 5080, RTX 3090,
RX 7900 XTX, Radeon 780M, Iris Xe, lavapipe and the M3 (MoltenVK and the Metal oracle), lint in
every configuration, rustdoc, doc tests, packaging and public case qualification; the timing and
teardown lanes x5 on every venue; the authoring-capability census 16656/16656 with 0 unresolved,
the vk12-floor translation census at 6139 translated with the slowest row 794 ms and peak 126 MiB.
The tree is development-fast's at 9f46fdf80d.
2026-10-16 11:12:03 +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