Commit Graph
6766 Commits
Author SHA1 Message Date
Anees Iqbal ec7984da43 replay: the rt backend's heap storage mode reads with explicit precedence 2026-11-17 19:50:26 -08:00
Anees Iqbal 4b92cec28a replay: the player's backend over the new runtime, what it does not build yet skipped and counted; command-replay --runtime old|rt 2026-11-17 19:50:25 -08:00
Anees Iqbal 45b5778d03 conformance: the empty command buffer probe records what it measured on the M3
Job m3-max-43955 (M3 Max, macOS 27.0.1, five runs per case, plain and under the
validation layer): every case Completed with no error and nonzero GPU times;
handlers in commit order; an empty or fence-only command buffer after a busy one
reports equal start and end just after the busy one's end; an empty-kernel
dispatch ran on the GPU beside the busy one, its handler still after the busy
one's.
2026-11-17 19:47:36 -08:00
Anees Iqbal 11229c6989 conformance: a probe of what Metal reports for a command buffer that does no work
Its GPU start and end times, when its completed handler runs against the
command buffer committed before it on the same queue, and its status and error:
an empty command buffer, one with a compute encoder that only waits on and
updates a fence, and one dispatching an empty kernel, each alone and after a
busy command buffer.
2026-11-17 19:46:22 -08:00
Anees Iqbal bef6f4bb2b rt tests: the cross-queue counts are read before any busy command buffer completes, and a commit's lock wait is at least half the 20 ms hold 2026-11-17 19:40:19 -08:00
Anees Iqbal 3a0f6abca1 api signatures: the queue counters' Metrics fields 2026-11-17 19:40:19 -08:00
Anees Iqbal e1d2df75e4 rt: counters of what a second Metal queue adds: commit-lock waits, groups beside another queue, lone submissions across queues, forced flushes
Replay counted two Metal queues in flight at once in 99% of gb's frames, and every Metal queue
submits to the device's one VkQueue. These metrics measure what that costs on rt's own side, per
frame as differences of two reads:
- commit_lock_wait_nanos and commit_lock_wait_max_nanos: how long commits waited to take the
  submission lock, which every queue's commits and the submit thread take;
- groups_beside_another_queue: groups opened while another queue held one (each queue groups
  its own command buffers, so one queue would not have opened them);
- lone_submissions_across_queues: submissions sent with fewer than IN_FLIGHT of their own
  queue's in flight while the device had IN_FLIGHT or more across queues, which one queue would
  have held in a group;
- forced_flushes_across_queues: groups sent with no reason of their own queue's. No path sends
  one, so it stays 0; it is counted to show that.

Tests: every_device_counts_what_a_second_queue_adds (two lone submissions and one group beside
another queue, no forced flush, checked once the busy work outlasted the held commits),
every_device_counts_a_commits_wait_for_the_submission_lock (a commit behind a 20 ms hold waits at
least 20 ms).
2026-11-17 19:40:19 -08:00
Anees Iqbal 671ba2e958 rt tests: the view test grants the indices of every texture it makes
The test made textures at 4112 to 4114 with only 4096 to 4111 granted, so every
device refused the first (legs 43825-43827); the views, their bytes and the
refusals before it had passed.
2026-11-17 19:35:26 -08:00
Anees Iqbal 1874c8272d rt: a view of a Managed texture names the parent's bytes of its levels and slices
A view of a Managed texture had no named bytes, so replace_region and get_bytes
through it reached the image while the parent's reached its named bytes: a write
through the view was lost to the parent's getBytes, and a synchronize of the view
copied nothing. The view now takes the parent's buffer and the places of its own
levels and slices, in the view's level-major order, so both reach the same bytes
as Metal's do.

Test: every_device_views_a_managed_texture_s_named_bytes writes level 0 of a 2D
view of level 1, slice 1 of a Managed 2D array and reads it back through the
parent and from the named place.
2026-11-17 19:35:26 -08:00
Anees Iqbal 36cbf6e44c rt tests: the view test's cases take their types from their use
Clippy's type_complexity stopped lint m3-max-43764 under both device cfgs on the cases array's
annotation; the element types follow from the calls and comparisons that take them.
2026-11-17 19:35:26 -08:00
Anees Iqbal 9b427f7cf7 harness: a description's texture-view, a view of an earlier texture's slices
`texture-view PARENT TYPE SLICE SLICES` makes the next texture as
newTextureViewWithPixelFormat:textureType:levels:slices: of texture PARENT: its
format, extent, usage and storage, its one level, SLICES slices from SLICE, of
raw MTLTextureType TYPE (TextureSource::View). A parent not made before it, and
slices empty or past the parent's (Metal's validation stops both), are refused
with the line's number, as is a view of a type the harness does not make. The
run makes views from their made parents through ComputeDevice::new_texture_view:
the old runtime's new_texture_view_with_levels_slices and the new one's
new_texture_view, placed at an index as a texture is.

The described test gains workload `viewed`: a 2D view of slice 1 of a 2D array
read by texels_out, checked against the slice's bytes; tests.rs gains five
refusals.
2026-11-17 19:35:26 -08:00
Anees Iqbal 0a39715cf8 rt: texture views, a texture over levels and slices of its parent's image with image views of its own
Texture::new_texture_view(pixel_format, texture_type, levels, slices, index) is
newTextureViewWithPixelFormat:textureType:levels:slices: (and, with the
texture's own type and every level and slice, newTextureViewWithPixelFormat:).
A view is a TextureInner over its parent's image: its own sampled and storage
image views of the subresource range, its own index and elements of set 1, no
image, memory or copy. It keeps its first parent (a view of a view composes
the ranges), shares the parent's resource id so hazards between them are one
texture's, and reports Metal's view descriptor: the extent of its first level,
its levels and slices (probe texture_view_rules.m, job m3-max-43677: width 4
for levels 1..3 of an 8-wide texture, arrayLength 2 for slices 1..3).
place() takes the texture's base level and layer, so blit copies,
replace_region and get_bytes through a view reach the parent's levels and
slices under it. The view's image views go to the reaper (Free::Views) when it
drops; Gauges::textures counts views until then.

Built, from replay's compute-bound views (gb 18, b2 19): the parent's own
pixel format over every slice in its type, a slice subrange of a 1D or 2D
array, one slice of a 2D array as a 2D texture, each over any level
subrange. Refused as Metal's validation stops them (job m3-max-43677):
Refusal::TextureViewRange (empty or past ranges) and
Refusal::TextureViewFormat (another format without PixelFormatView usage).
Not built: Gap::TextureView naming the kind (TextureViewKind: PixelFormat,
TextureType, Slices, Swizzle).

Test (device cfgs): tests::view::every_device_views_levels_and_slices_of_a_texture:
six views and a view of a view report Metal's descriptor and read Metal's
bytes (the probe's FNV-1a 64 of each view's level 0 copied out), each view
costs 0 submissions, 0 blocks and 0 bytes copied; the three range refusals,
the format refusal and four gap kinds; views outlive their parents' handles
and every gauge falls to zero. The blit tests' Side carries the base.
README, REFUSALS.md and the signatures table updated.
2026-11-17 19:35:25 -08:00
Anees Iqbal 00288ca6dc replay: a placement heap's placements are a named type (clippy type_complexity, job m3-max-43774) 2026-11-17 19:22:14 -08:00
Anees Iqbal 647c186ec8 replay: placement heaps laid out for the runtime's sizes and alignments
A stream's heap offsets and heap sizes are the recording device's answers. On another device a
texture can be larger: b2 on an NVIDIA GPU stopped at a heap texture whose image the old runtime
makes 7.47 MB in a 5.9 MB heap. A live program lays its heap out by the device's
heapTextureSizeAndAlignWithDescriptor: and heapBufferSizeAndAlignWithLength:options:, so the player
now does the same: before it plays, it reads every placement in each placement heap ahead, asks the
backend the size and alignment of each (a texture's of its descriptor as its making call and setters
left it), and moves each offset up until the resources below it end and it is aligned, growing the
heap to hold them. Resources at one offset still share it; where every answer fits the stream's
layout, nothing moves. The report says what moved (`relaid HEAPS moved OFFSETS grown BYTES`).

The backend gains heap_size_and_align; the old runtime's answers through its own queries, with the
texture descriptor's making and setters shared with its play of those calls.

Verified: not yet built; a unit test on the keeping backend covers a texture larger than its room
(the buffer above it moves, the heap grows), a texture made again at its offset, a heap where every
answer fits, and the descriptor calls the backend is asked with.
2026-11-17 19:22:14 -08:00
Anees Iqbal b6368b040b translator tests: the builder's pointer and Workgroup-block tests follow the implicit-only Workgroup rule
pointer_classes_admit_only_their_layouts now checks a Workgroup pointer or
variable refuses an explicitly laid-out type, Block or not; the test of
member pointers into a Workgroup block goes with the blocks.
2026-11-17 19:17:15 -08:00
Anees Iqbal 4c3b32e481 rt: the floor's comment says threadgroup memory is implicitly laid out
Comment only: the arena is a word array and the typed shared objects are
typed variables, both implicitly laid out, so "addressed by byte offset"
described only the arena.
2026-11-17 19:17:15 -08:00
Anees Iqbal 54b39b4ea9 translator: Workgroup memory is implicitly laid out; the explicit layout's requirement path goes
Every Workgroup variable the translator declares is a plain array or
scalar, so the requirement walk's explicit-layout branch (the capability,
SPV_KHR_workgroup_memory_explicit_layout and its four features), the
entry interface's mixed-layout rule and the scalar Workgroup layout
feature were reached only by builder tests. ModuleBuilder::plain_global
and the pointer type rule now refuse an explicitly laid-out Workgroup
variable or pointee, Block or not, so the path cannot be reached, and it
goes with GlobalRule::MixedWorkgroupLayout and spirv-val's
--workgroup-scalar-block-layout option in the test validator. The
families_stage test checks the refusal; the workgroup layout census
checks no translated module declares the capabilities or requires the
extension or its features.
2026-11-17 19:17:15 -08:00
Anees Iqbal 61fa23a414 rt: the floor no longer requires VK_KHR_workgroup_memory_explicit_layout or its four features
The translator declares every Workgroup variable as a plain array or scalar
(the threadgroup arena, typed shared objects, SIMD-group scratch, mesh and
object state, the bind prepasses' lists), never an explicitly laid-out
Block, so no module it writes declares WorkgroupMemoryExplicitLayoutKHR or
its 8- and 16-bit access capabilities. The census over the fixtures, the
authored cases and the recorded kernels found none. The extension, its
feature structure in floor::Features, the four required features, the
README's floor rows and the floor tests' cases go; a device that lacks the
extension is no longer below the floor.
2026-11-17 19:17:15 -08:00
Anees Iqbal 56e7f3770f tests: the workgroup layout census also checks each module's requirements name neither the explicit layout's extension nor its four features
The floor's extension and features are needed only if a module requires
them, which the requirement set states beside the declared capabilities:
a layout rule can ask for workgroupMemoryExplicitLayoutScalarBlockLayout
without a capability of its own.
2026-11-17 19:17:15 -08:00
Anees Iqbal 4022e00dc0 tests: the workgroup layout census counts the modules whose threadgroup arena is sized at run time apart from those with fixed-size Workgroup variables
A module whose [[threadgroup(n)]] regions the binder sizes from the encoder's
threadgroup memory lengths declares its arena as a Workgroup array whose
length is a specialization constant. The census now reports those modules
apart from the ones with only fixed-size Workgroup variables, so the claim
that no module needs the explicit layout's capabilities is shown on the
modules that use threadgroup memory sized at run time.
2026-11-17 19:17:15 -08:00
Anees Iqbal 8ae23a2281 tests: no module the translator writes declares the explicit workgroup layout's capabilities 2026-11-17 19:17:15 -08:00
Anees Iqbal ff4c6835aa rt tests: a synchronize of a texture without named bytes leaves the segment's end barrier alone
Legs 43734/43735/43736 at ae67a08163 measured one barrier, not none, for a command buffer whose
blit encoder only synchronizes a texture without named bytes, on all seven devices: the
command buffer's segment end, which every command buffer of an encoder records. The
synchronize itself records none; the test now expects the end alone.
2026-11-17 19:08:49 -08:00
Anees Iqbal e438446cdd rt tests: the blit tests open each count once the pool holds a ready block of each class
Core's legs at 03677fd352 (um870 43664) saw two submissions in every_device_copies_between_textures
on the 3090 where the test counts one, and one on the rerun (43687). A submission the runtime
counts outside command buffers is the block-maker thread's zero fill of a Private block it makes
after one is taken (fill.rs); the test's textures take the ready one just before the window. Each
blit test now waits, before each count it asserts, until the pool holds a ready block of each
class again, as the pacing tests wait for theirs; the runtime adds no submission to a blit.
2026-11-17 19:08:49 -08:00
Anees Iqbal d70cb2baec rt tests: the synchronize test makes its texture before the command buffers it measures
Legs 43678/43679 failed every_device_synchronizes_a_managed_buffer on every device: the texture
made just before the measured command buffer was moved home by that command buffer's upload, two
barriers the synchronize did not record. The texture is now made before the first command
buffer, whose upload moves it home; the synchronize of it still records no barrier.
2026-11-17 19:08:49 -08:00
Anees Iqbal 552fb45223 conformance: a probe of which texture views Metal makes, what a view reports, and the bytes it reads
Eleven cases, one per process under Metal's validation layer: whole views, level subranges, a 2D
view of one slice of a 2D array, a slice subrange of the array, ranges past the parent or empty,
and a view of another pixel format with and without PixelFormatView usage. A view that is made
reports its extent, level and slice counts, type and parent-relative level and slice, and the
FNV-1a 64 of its level 0 copied out by a blit: what rt's views must answer.
2026-11-17 19:08:49 -08:00
Anees Iqbal 9771d45fdb rt: a blit encoder synchronizes a Managed texture, each level and slice of its image into its named bytes
synchronize_resource of a Managed texture with named bytes
(Device::new_managed_texture, on every device) records one
vkCmdCopyImageToBuffer of each level and slice of its image into its place in
the named buffer, between one pair of a buffer copy's barriers, and marks the
segment so its end barrier reaches the host. A texture without named bytes
still records nothing; every call is counted in Metrics::synchronizations.

texture.rs gains one read hook, Texture::named_bytes (the named buffer and its
per-level/slice places), which main agreed to. The blit encoder's buffer copy
now records through record_buffer_copies, which takes a list of checked copies
and puts each copy's level and slice in the same two barriers; one copy
records exactly as before. new_managed_texture's doc names the synchronize.

Test (device cfgs): every_device_synchronizes_a_managed_texture_into_its_named_bytes:
a 2-level 4x4 RGBA8Unorm Managed texture with places 256-byte rows apart;
copies into its image alone leave the named bytes zero; the synchronize puts
level 0 at offset 0 and level 1 at 1024, the bytes between the rows kept, at 1
submission, 3 barriers, 0 bytes copied, 1 synchronization, 1 host reach.
Level 0 is plain Metal's: probe blit_synchronize_rules.m, job m3-max-43667,
getBytes of a Managed texture copied into then synchronized hashes
a918a78fc82cbba5 (the managed-buffer case still 5d28bc84b408472d).
2026-11-17 19:08:49 -08:00
Anees Iqbal b025e83119 conformance: the synchronize probe writes its Managed texture by a copy and hashes getBytes after the synchronize
The two Managed texture cases now copy the 64 bytes the buffer cases start from into the 4x4
RGBA8Unorm texture with copyFromBuffer: before the synchronize, and hash getBytes: (rows 16
bytes apart) once the command buffer completes: the bytes a synchronized Managed texture gives
the host.
2026-11-17 19:08:49 -08:00
Anees Iqbal 3398f59995 harness: a description's synchronize, synchronizeResource: of a managed buffer before a dispatch
The directive `synchronize BUFFER` records synchronizeResource: in the blit
encoder before its dispatch, as the other blits do. A buffer not made before it
and one that is not managed (Metal's validation stops a synchronize of it) are
refused with the line's number. The old runtime's synchronize_resource and the
new one's back the trait method; the new runtime's harness keeps a managed
buffer as a Private one, so the call records nothing there.

The described test gains workload `synced` (a managed buffer filled, then
synchronized, then stepped by lcg_step and checked); tests.rs gains the three
refusals.
2026-11-17 19:08:48 -08:00
Anees Iqbal b37339a609 rt: a blit encoder synchronizes a Managed buffer, one copy of its device copy into the consumer's bytes
BlitCommandEncoder::synchronize_resource is synchronizeResource:. Of a Managed
buffer with a device copy (Shared memory not device-local) it records one
vkCmdCopyBuffer of the copy into the consumer's bytes between the two barriers a
fill records, and marks the segment so its end barrier reaches the host: the
host reads the GPU's writes before the call once the command buffer completes or
it sees an event signaled after it. A buffer without a device copy is read by
the host where shaders write it, and a texture has no bytes the host reads
apart from its image (no texture has named bytes on development yet): for
those the call records nothing. Every call is counted in the new
Metrics::synchronizations and is no submission of its own.

Metal's validation stops a synchronize of a Shared or Private buffer or
texture (probe blit_synchronize_rules.m, job m3-max-43632: "synchronizeResource:
only applies when ... == MTLResourceStorageModeManaged"); rt keeps no storage
mode for those and records nothing, as the old runtime does. The probe's
Managed buffer, filled 4..12 with 0xab and synchronized, hashes
5d28bc84b408472d, the bytes the test asserts.

The barrier after a blit's write into a buffer is one helper now (fill, buffer
copy, synchronize); a buffer copy's source stage widens from COPY to
ALL_TRANSFER.

Tests (device cfgs): every_device_synchronizes_a_managed_buffer (a fill alone
leaves the host's bytes where the buffer has a device copy; fill + synchronize
gives Metal's bytes at 1 submission, 5 barriers with a device copy and 3
without, 0 bytes copied, 1 synchronization, 1 host reach; a texture's
synchronize records no barrier) and
every_device_reaches_the_host_only_after_a_blit_writes_shared_memory (the
wrote_host invariant for blit encoders: fills and copies into Private memory
or a texture reach no host, into a Shared buffer they do). README,
REFUSALS.md and the signatures table updated; the README drops the line that
said synchronizeResource comes with blit encoders, and names
synchronizeTexture:slice:level: as not built (no recorded stream calls it).
2026-11-17 19:08:48 -08:00
Anees Iqbal 8239a53a35 conformance: a probe of which resources Metal's synchronize takes, and the bytes after one
Seven cases, one per process under Metal's validation layer: synchronizeResource: of a Managed,
Shared and Private buffer after a fill in the same encoder (the host's bytes hashed where it
reaches them), of a Managed, Shared and Private texture, and synchronizeTexture:slice:level: of a
Managed one. It tells which calls rt may refuse and which must do nothing.
2026-11-17 19:08:48 -08:00
Anees Iqbal 594b86d1f2 rt: the floor asks the created device for support of the runtime's set layouts
vkGetDescriptorSetLayoutSupport is Vulkan's answer to whether a set layout can be made; the
limits the floor checks do not promise it. MoltenVK 1.4.2 on an M3 Max reports set 1's layout
(65,536 sampled images, 4,096 storage images, three arrays of 4,000 samplers, update after bind)
unsupported, and the validation layer then names VUID-vkCreateDescriptorSetLayout-support-09582
at device creation (probe job m3-max-43634).

Arrays::make asks it for the empty set 0 and for set 1 before making either; an unsupported one
refuses the device with Error::BelowFloor and the new Missing::SetLayout { set }. Vulkan answers
it only for a created device, so PhysicalDevice::check cannot. Set 1's layout is built in one
place, with_arrays_layout, for the query and the creation.

Tests: every_device_supports_the_runtimes_set_layouts (each device of the cfg's kind supports
both), a_set_layout_the_device_does_not_support_is_named. README floor section, REFUSALS.md and
api_signatures.tsv regenerated.
2026-11-17 18:52:30 -08:00
Anees Iqbal 088f8bb61c rt, harness: the device tests and the harness's test session follow the shared kernel
Fixes forward the kernel-map commit (a010c3090d). That commit's checks (m3-max-43671) failed in
three places:
- The device-cfg tests in rt's tests/translate.rs still read the emulated and whole modules
  on the state. They now read them on its compiled kernel.
- The harness's test session still took a buffer length in Session::create. It now takes Makes.
- The harness's run.rs doc linked STATE_CREATIONS with an explicit target that rustdoc reports
  as redundant.

Verified: formatted only. The checks run on this commit next.
2026-11-17 18:51:28 -08:00
Anees Iqbal b431b1cca9 rt: states of one compute pipeline content share one compiled kernel
Before this, each compute pipeline state lowered its own kernel. It made its own VkShaderModule
and its own VkPipelines, so 1,000 states of one content cost 1,000 translations, or 1,000 reads
of the cache directory where one was set. Now the device keeps a map from content to compiled
kernel. A state of a content the map holds takes that kernel: it lowers nothing and makes no
module or pipeline. The VkPipelines live in the shared kernel, one per variant (workgroup size,
threadgroup memory lengths, tiles), so states of one content share them too.

The key is the translator's compute_pipeline_key(descriptor) plus
required_threads_per_threadgroup. The pipeline key does not cover that field, but rt reads it
into each module's interface (Kernel::new's max_total_threads). One entry holds the content's
whole kernel: the whole module, the partial-threadgroups module where the translator made one,
and the emulated-SIMD-group module the reaper lowers. The module kind therefore lives inside the
entry, not in the key.

What stays per state, checked against every field a state reads:
- The numbered samplers. Each state keeps the sampler indices the consumer gave
  (sampler_ids, pushed by every dispatch), plus its hold on the constexpr sampler elements at
  those indices. Two states of one content may number them differently, so they stay with the
  state (Numbered).
- support_indirect_command_buffers is refused before the lookup.
- No other descriptor field reaches the module, its interface or a variant. The emulated
  module's sampler check needs only the kernel's constexprs (covers), which come from the
  content.

The map holds at most 1,024 entries and forgets the least recently used past that. It bounds
what it holds, not what lives: a state keeps its kernel, so eviction only forgets the entry, and
the kernel goes with its last state. Two new gauges, kernels and kernel_entries, count live
kernels and map entries. Both read 0 once the device is gone, because the device's teardown
clears the map after the queue halts. The map's kernels hold the core, and clearing the map
breaks that cycle.

Tests (rt src/tests/kernel_map.rs):
- the map filled past its cap, on the host;
- on every device of the cfg: two states of one content share one translation, one module and
  one VkPipeline per variant, for a tiling kernel and for one that observes its threadgroups;
- other constant values and other linked functions compile apart;
- a cap of 2 filled with 3 contents holds 2, frees a forgotten kernel with its last state, and
  compiles a forgotten content again.

The harness gains create_state. It times the first creation of a content the device has not
seen ("first"), then 1,000 creations of a content it has, against the old runtime too, with
the gauges at 100 and 200.

The README's compute pipeline states section and the counters' docs say "per kernel" where they
said "per state". api_signatures.tsv is reblessed for the two gauges.

Verified: formatted only. The checks run on this commit next (clippy x3, rustdoc, the touched
tests, and rt's lavapipe device tests).
2026-11-17 18:51:27 -08:00
Anees Iqbal 75bfbbb062 harness: a buffer copy's whole-texel check uses is_multiple_of
Clippy's manual_is_multiple_of stopped the harness (lint m3-max-43622) on the two remainder
tests of BufferCopy::problem; is_multiple_of says the same.
2026-11-17 18:37:19 -08:00
Anees Iqbal b00be4734d rt: the blit refusals' doc lines fit in 100 columns
Three doc lines of TextureBytes, FloatDepthUpload and FillAlignment ran past 100 columns; they
are reflowed with no word changed. docs/REFUSALS.md regenerates unchanged.
2026-11-17 18:37:18 -08:00
Anees Iqbal 9576102404 harness: the run names the plan's blits
a172c73d93 matched on Blit in run.rs without importing it, so the harness did not build
(lint m3-max-43611, E0433 four times). The import joins the plan's others.
2026-11-17 18:37:18 -08:00
Anees Iqbal e9f43bb855 rt: blit buffer copies and fills reach a buffer through its device range, and keep the buffer
Development's Managed buffers (ee7c4a5173) replaced held_block with held and device_range: a
Managed buffer's GPU side is its device copy where the Shared type is not device-local. A blit copy
or fill now records against device_range's VkBuffer and offset (alignment checked from that
offset) and keeps the buffer through Building::keep, which keeps a device copy too; is_shared
answers false for a buffer with a device copy, so only a copy or fill into the bytes the host
reads marks the segment. The lint of a172c73d93 (m3-max-43607) was cancelled before it compiled:
held_block no longer exists. Docs say 'the bytes shaders reach' where they said the block.
2026-11-17 18:37:18 -08:00
Anees Iqbal f4b7e606cc harness: a description's buffer copies and fills, in the blit encoder before a dispatch
A dispatch carries the blit commands before it (plan::Blit: a texture copy, a copy from a buffer
into a texture or back, or a fill), recorded in order in one blit encoder between the compute
encoders; the field is blits, not copies. The BlitCommandEncoder trait gains copy_from_buffer,
copy_from_texture_to_buffer and fill_buffer, and both runtimes implement them (the old runtime's
copy_from_buffer_to_texture, copy_from_texture_to_buffer and fill_buffer with BlitOption::None;
rt's copy_from_buffer, copy_from_texture_to_buffer and fill_buffer).

A description names them with
  copy-buffer-to-texture BUFFER OFFSET ROW-BYTES IMAGE-BYTES WIDTH HEIGHT TEXTURE SLICE X Y
  copy-texture-to-buffer TEXTURE SLICE X Y WIDTH HEIGHT BUFFER OFFSET ROW-BYTES IMAGE-BYTES
  fill-buffer BUFFER OFFSET LENGTH VALUE
before the next dispatch's set lines. Refused with the line's number, as Metal's validation stops
them (probes blit_buffer_copy_rules.m and blit_fill_rules.m): a buffer or texture no line before it
makes, a slice or region outside the texture, an empty region, an offset or row stride of no whole
texels or rows closer than the region's, a region or fill past the buffer's end, an empty fill. The
messages for a blit after the set lines or after the last dispatch now say blit.

The rt README's segment paragraph names a blit copy or fill into a Shared buffer among the writes
that make a segment's end barrier reach the host.

Tests: each new refusal in the faulty-description test; the described device test gains 'staged':
a Private texture written whole from a buffer, a fill of buffer 2, a region of the texture read
into buffer 2 at padded rows, then texels_out of the texture, checked against its CPU model and
between the runtimes.
2026-11-17 18:37:18 -08:00
Anees Iqbal 2cb7ea189d rt: a blit encoder fills a range of a buffer, one vkCmdFillBuffer between two barriers
fill_buffer (fillBuffer:range:value:) records vkCmdFillBuffer of the byte four times over in each
word against the buffer's own range of its block, between the two barriers a copy records (the
second from every transfer stage's writes to every later command), and a fill of a Shared buffer
marks the segment so its end barrier reaches the host.

Probe blit_fill_rules.m on an Apple M3 Max, macOS 27.0.1: Metal's validation stops an empty range
and one past the buffer's end (job m3-max-43573), Refusal::FillRange; it takes ranges of no whole
words (job m3-max-43571), which vkCmdFillBuffer cannot write: Gap::FillAlignment until a replay
stream makes one.

Tests: the range checks (offset from the buffer's place in its block, empty, past the end,
reversed, unaligned start, length or block offset); a device test filling 4..12 of a 64-byte
Shared buffer with 0xab, its bytes plain Metal's FNV-1a 64 (job m3-max-43571), at one submission,
three barriers, no byte of the runtime's own.
2026-11-17 18:37:18 -08:00
Anees Iqbal 8603abbad3 conformance: the fill probe asks about a range past the buffer's end and an empty one 2026-11-17 18:36:53 -08:00
Anees Iqbal 41fcf99168 conformance: a probe of which ranges Metal's buffer fill takes, and the bytes it leaves
Whole words, an offset or a length of no whole word, both, and a Private buffer, one case per
process under the validation layer; each Shared buffer's FNV-1a 64 after the fill. The rt blit
fill (next) takes its rules and its bytes from it.
2026-11-17 18:36:53 -08:00
Anees Iqbal 8e39e812e5 rt: a blit encoder copies between a buffer and a texture, one copy command an image of the region
copy_from_buffer (copyFromBuffer:sourceOffset:sourceBytesPerRow:sourceBytesPerImage:sourceSize:
toTexture:destinationSlice:destinationLevel:destinationOrigin:) and copy_from_texture_to_buffer
(copyFromTexture:sourceSlice:sourceLevel:sourceOrigin:sourceSize:toBuffer:destinationOffset:
destinationBytesPerRow:destinationBytesPerImage:) record vkCmdCopyBufferToImage or
vkCmdCopyImageToBuffer against the buffer's own range of its block, nothing staged, between the
two barriers a texture copy records. One region per image of the region, each at its own offset
(offset + image x bytesPerImage), so an image stride of no whole number of rows copies too;
bufferRowLength is bytesPerRow in texels, 0 for one row. The second barrier also makes a buffer
write visible to every later command, and a write into a Shared buffer marks the segment, whose
end barrier reaches the host. BufferLayout carries the offset and the two strides.

Refusals follow probe blit_buffer_copy_rules.m on an Apple M3 Max, macOS 27.0.1 (jobs
m3-max-43541, m3-max-43545): Metal's validation stops an offset or a row stride of no whole
texels, rows or images closer than the region's and a region past the buffer's end
(Refusal::BufferCopyLayout); it takes an R8Unorm offset of 2, a row stride of 0 for one row, image
strides of no whole rows, and bytesPerImage on 2D and 1D-array copies. Where Metal takes bytes a
copy command cannot address (a depth or stencil offset not a multiple of 4, as a 16-bit depth at
2; a compressed offset or row stride of no whole blocks, as BC1 rows 20 apart, which Metal takes)
it is Gap::BufferCopyAlignment. TextureBytes and FloatDepthUpload now name the blit copies too.

Tests: pure checks of the regions (padded rows, one row, a 3D region's images at their own
offsets, a 1D array slice, BC1 blocks) and of each refusal and gap; a device test copying into a
mipmap level, out of an array slice and a 3D region at padded strides, into a 1D array slice and
BC1 blocks, each result held to plain Metal's FNV-1a 64 (probe blit_copy_layouts.m, job
m3-max-43555, plain and under the validation layer), and one copy into a Shared buffer alone at
one submission, three barriers, no byte of the runtime's own.
2026-11-17 18:36:53 -08:00
Anees Iqbal 4664a6f276 conformance: the blit copy probe copies between Shared buffers and textures
Five copies the rt device test makes too: into a mipmap level at an offset with padded rows, out
of an array slice with padded rows, out of a 3D region with an image stride of no whole number
of rows, into a 1D array slice with an image stride, and BC1 blocks from a buffer; each
destination's length and FNV-1a 64 printed.
2026-11-17 18:36:28 -08:00
Anees Iqbal d90d36def9 rt: a Private allocation spills to the next memory type on its own out-of-device-memory error, and reports it
As the plan decided for reims's first need (Metal never fails a Managed
resource for want of video memory): a Private allocation takes the device-local
Private type and, where that allocation itself fails with
VK_ERROR_OUT_OF_DEVICE_MEMORY (never a budget poll), the next memory type the
resource allows, in the device's order (memory::allocate_spilling).

Reporting: BlockInfo::device_local is false for a spilled block (and, for a
Shared block, says whether the Shared type is device-local);
Gauges::spilled_bytes counts the bytes of spilled blocks and of textures' own
spilled allocations until they are freed.

Where it applies:
- blocks, pooled and dedicated (memory::make); a spilled pooled block is freed
  when given back, so the pool's next block tries device-local memory again;
- texture blocks and copy blocks never hold a place in a spilled block
  (Places::place gives it back and answers the out-of-memory error): a texture
  then takes an allocation of its own, which spills the same way where the
  image allows another type;
- a Managed buffer whose device copy finds no device-local room is its Shared
  range for its life, as on a unified device: no second copy in system memory.

The device tests stand in for a full device with Core::fail_private (test
builds only), which fails the Private type's allocations before the driver is
called.

Test: tests::spill::every_device_spills_private_memory_out_of_device_memory.
2026-11-17 18:33:50 -08:00
Anees Iqbal 25602502e3 rt: the translator's description enables the portability subset and its floor features where the device lists it
Device creation enables VK_KHR_portability_subset and the three portability features the floor
asks for where a device lists the subset, but shader_enables named neither to the translator.
DeviceDescription::with_enabled then refuses a description that does not enable a listed
portability subset, so Device::new failed on MoltenVK with 'the translator made no pipeline:
invalid descriptor: does not enable KhrPortabilitySubset, which the device lists' (M3 probe job
m3-max-43626, with the probe admitting MoltenVK past the two floor items it lacks).

shader_extension maps the subset to VkExtension::KhrPortabilitySubset, the PORTABILITY features
carry their translator names, and shader_enables reads them: false, so not named, where the
subset is not listed. Test: the_translator_sees_the_portability_subset_device_creation_enables
(fails without the fix: the extension is not in the enable set).
2026-11-17 18:27:16 -08:00
Anees Iqbal 2105fa114e rt: heap textures, bound at the consumer's offsets in a heap's range of a Private block
A heap is a range of a Private block the consumer took at the heap's creation
(HeapRange: block, offset, length), as the plan decided: one Private range per
heap, resources at the offsets the guest's first-fit allocator picks.

Device::heap_texture_size_and_align answers heapTextureSizeAndAlignWithDescriptor:
with this device's image requirements (vkGetDeviceImageMemoryRequirements of the
same create info new_texture uses), never Metal's: the size rounded up to and
the alignment raised to bufferImageGranularity, so a buffer placed by the same
answers never shares a granularity page with the image. Replay showed why: one
vendor's image for a recorded heap texture is larger than the recording
device's (7.47 MB in a 5.9 MB heap), so the guest places by this answer.

Device::new_heap_texture binds the image at the heap offset: no allocation and
no texture block, bytes not zeroed (as Metal's heap textures), aliasing allowed.
A placement past the heap's end, an offset in the block off the image's
alignment, or a heap range past its block is Refusal::HeapTexturePlace at
creation; the image is never bound outside its heap. A Shared block, or an image
that requires an allocation of its own or does not take the Private type, is
Gap::HeapTexture (every optimal image measured takes the Private type). The
image holds the block, so a released block returns to the pool only once its
heap textures' images are gone.

new_texture's checks move into Device::prepare, shared with the size query, and
the image's create info into image_info. README: heap textures leave the
not-built line; REFUSALS.md and the signatures table updated.

Test: tests::heap::every_device_places_heap_textures_at_the_consumer_s_offsets
(answer equals the image's own size rounded to granularity; first-fit
placements allocate nothing and keep their own bytes; an alias; refusals for
past the end, off the alignment, a heap past its block, and a Shared block).
2026-11-17 18:26:07 -08:00
Anees Iqbal c96072be85 rt tests: once the reads drain the staging ring, the next copy's span starts at the region's start
The planner ruled that the staging ring restarts at its start whenever nothing
is pending in it. Ring::take already does that: since the region became its own
allocation, the head is the end of the last live span, so an empty ring takes
at 0 (the ring unit test checks "empty starts at 0"). This adds the device-level
check: in the upload test, after get_bytes has waited for every copy, the next
replace_region's span is 0..len (Work::staging_spans, for the device tests).
A one-texel read then sends that copy so the test's later bounds start from
an empty upload.
2026-11-17 18:26:07 -08:00
Anees Iqbal 8fc4064da5 rt: Managed textures, an image and the consumer's named bytes, uploaded by a device copy
A Managed texture is a Private image plus a range the consumer names, on every
device. Device::new_managed_texture takes a Shared buffer and, per level and
slice, a BytesPlace (offset, bytes per row, bytes per image) laid out as the
consumer chooses; rt never picks the layout. Places that a buffer-to-image copy
cannot read in place (rows not whole texel blocks apart, images not whole rows
apart, a first byte off the block's bytes or off 4 for depth/stencil, a level
leaving the buffer, a wrong count, a buffer the host does not reach) are
refused with Refusal::ManagedTextureBytes.

Texture::upload_region(region, level, slice) records one vkCmdCopyBufferToImage
from the named place into the image in the upload, ahead of every command
buffer committed after the call on every queue, as did_modify_range copies a
Managed buffer: no CPU copy, no staging. On such a texture replace_region
writes the named bytes (Metal's CPU copy) and uploads them; get_bytes reads the
named bytes with no submission. The texture copy's record() now takes a buffer
and region, so staging and named copies share it.

README, the API.md accepted difference (the copy reads the bytes when the GPU
reaches it), REFUSALS.md and the signatures table updated.

Test: tests::managed::every_device_copies_a_managed_texture_s_named_regions
(whole-level uploads, a sub-region upload with an unmarked change outside it,
get_bytes reading the named bytes, replace_region writing them, six refusals).
2026-11-17 18:26:07 -08:00
Anees Iqbal 3da5c35785 rt tests: the floor's device test passes the runtime's instance reference as it is 2026-11-17 18:18:24 -08:00
Anees Iqbal 0ef45ca579 rt tests: the floor's device test checks through the runtime instance's loader 2026-11-17 18:18:24 -08:00