reims's recorder (descwire) now writes three keys at the end of each
newRenderPipelineStateWithDescriptor:error: map, always:
- `tessellation`, a map of the seven tessellation properties as Metal's raw
values;
- `maxVertexCallStackDepth`;
- `maxFragmentCallStackDepth`.
The players refused any key they did not know, so every pipeline of such a
stream would have been refused. A stream without the keys means Metal's
defaults (0, 16, false, 0, 0, 0, 0; depths 1 and 1): the device built those
before the recorder carried them. There is no header bit, and the host's
short display map is unchanged.
Both players (translator::render_pipeline) now accept the keys:
- The depths always go to the descriptor.
- The tessellation state goes to it only where it differs from Metal's
defaults and the vertex function is a post-tessellation one (patchType not
None). Any other vertex function ignores the state, as Metal does, so a
plain pipeline is never handed tessellation state the new runtime would
refuse.
docs/REPLAY-STREAM.md section 9 states the keys, their defaults and the
names that differ from Metal's.
Test: a unit test parses the recorder's pinned record (partition 3, factor
32, scale on, half, uint32 indices, per-patch, counter-clockwise; depths 2 and
3) to those values, a record without the keys to the defaults, and refuses an
unknown key at the top and inside the tessellation map. Verified by the lane
check named in the hand-over.
A per-gap play counts the gaps, but a compute pipeline state that the runtime
answered with a typed gap, or that the translator refused, stopped the new
runtime's play at once. glbench-3090-r2 stopped at frame 0 on an
IdentityDomains refusal, and nothing after it was counted.
Compute pipeline states are now skipped and counted the way render pipeline
states are (c027cc2cfa): by the runtime's gap, or `Translation` for the
translator's refusal, together with the first state's object and the runtime's
answer. They appear as `skipped_compute_states` and the report line
`skipped compute states GAP N, the first #ID: WHY`. A dispatch of a skipped
state is skipped and counted (`skipped_dispatches`), and the play goes on. Any
other error still stops it. Render and compute share the counting
(Skips::skipped_state). docs/REPLAY-STREAM.md section 10 says so.
Test: a device test plays a state made for indirect command buffers. The
runtime refuses it as IndirectCommandBuffers; the test expects it counted,
its dispatch skipped and the play ended normally. The rt_replay library
helper takes any of the runtime examples' functions, a kernel among them.
Verified by the lane check named in the hand-over.
The SPI newLinearTextureWithDescriptor:offset:bytesPerRow:bytesPerImage:
stopped the new runtime's play of webdiv-780m-2 at frame 0 ("not played on a
buffer"): the stream makes one such texture, a 2D one over a no-copy buffer.
Neither player knew the selector.
The old runtime measured the SPI as newTextureWithDescriptor:offset:bytesPerRow:
for a 2D descriptor, plus 2D arrays whose slices Metal lays out itself
(bytesPerImage ignored; Buffer::new_linear_texture). The old player now calls
that. The new runtime has no form of the array layout, so its player plays a
2D descriptor as the public texture over the buffer (its resource index
included) and refuses any other type, "a linear texture of a type other than
2D". docs/REPLAY-STREAM.md section 5 names the selector.
Test: a device test plays a 2D linear texture with nothing skipped and gets
the refusal for a 2D array. Verified by the lane check named in the hand-over.
The report gave one line for every skipped render pipeline state, its
total and the first one's answer, so a stream's states refused for a
depth attachment, for framebuffer fetch or by the translator read as one
number. The planner's census of what the new runtime refuses needs the
count of each kind per stream.
The backend now keeps the skipped states by the gap as Rust prints it
for debugging (Translation where the translator refused), with the
first one's object and answer, and the report gives a
"skipped render states GAP N, the first #ID: WHY" line for each, as it
does for render commands; skipped_render_states is their sum.
docs/REPLAY-STREAM.md describes the line.
Verified: see the check job (a new rt_replay device test: a state with
a Depth32Float depth attachment is counted under
RenderPipeline { kind: DepthAttachment }).
A known-bad tail cost a ring timeout on a shared card and a wrongly
bounded play. The player now ends every play at the recording range by
default:
- the stream's sidecar, NAME.range beside NAME.0000.m2vr, one line:
"last-frame F" or "whole";
- else the player's table RECORDED_RANGES for the streams recorded
before sidecars, found by the first segment's file name and byte
length: u2 1128, u3 1178, r3 1137, r4 1099, b3 whole;
- else the whole stream (the 3D streams until their ranges are stated).
--past-range yes plays past it; without it --until-frame F stops at the
earlier of F and the range. Every report says which range the play
used, where it came from and whether the play ends there, on a range
line after the completion mark; a sidecar of neither form is a harness
error (exit 2). docs/REPLAY-STREAM.md: section 1 names the sidecar,
section 10 the default, the flag and the report line.
Tests: replay::tests a_recording_range_comes_from_the_sidecar_then_the_table
(sidecar over table, table row by name and length, no row, bad sidecar);
integration replay_range runs the binary over a synthetic stream with no
sidecar, a last-frame sidecar, the flag and a bad sidecar (no device
opens); replay_completion_mark now expects the range line second.
The recorder's completion fix marks a stream with header flag bit 1,
FLAG_COMPLETION_BYTES_RECORDED (value 2): at each command buffer's
completion the stream holds every chunk the buffer's work could store to
as the GPU left it, before any later CPU write, on all four late routes
(signalled event, final status read, refused hook, released command
buffer). Fixed streams read flags 3; every stream recorded so far reads 1.
- The reader takes bit 1 (it refused any bit but 0 before), so a fixed
stream plays.
- command-replay play writes "recorded before the recorder's completion
fix: the stream may differ from what the program did" by itself as the
first line of report.txt for every stream without bit 1, so no table
relayed from a report loses it. The stream is now read before the
device type is parsed, so even a report that stops there carries it.
- docs/REPLAY-STREAM.md: section 1 names the bit, section 6 replaces the
rule that described a stream without completion writes as allowed with
the completion invariant and what a stream without the bit may miss,
and section 10 names the line and its place in report.txt.
Tests: replay_completion_mark (integration) runs the player binary on a
one-call stream with flags 1 (the report begins with the line) and flags
3 (it does not), with a device type no device has so no device opens;
the header flags test now reads flags 3 and refuses bit 2.
The new runtime's backend skipped m2v.copyToGuestRam and counted it, so
every play's verdict ended at the first one (u2 frame 97, u3 frame 99),
though nothing in a play reads that RAM. The planner ruled it does not
end the played range, and that work the recording host did live plays
as the runtime's, cost included.
It now plays as the old backend's does: each run copied by the blit
encoder, in its order, into a Shared place of the play's own that
nothing reads, each run widened to the whole words it touches within
the buffer (a buffer copy takes whole 4-byte words). The place is given
back at the command buffer's commit, as a copy from the guest's RAM
gives back its staging. The report counts the bytes
(copied_back_guest_ram_bytes); skipped_guest_ram_reads is gone.
Verified: see the check job (a new rt_replay device test: nothing
skipped, the widened bytes counted, the buffer's bytes kept).
The backend packed buffers first fit at Metal's 256-byte alignment, so a program's write past
a buffer's end landed in the next buffer. A recorded stream's program did that: an append
list of 4000 records took about 870 more on one play, and the overrun went 17340 bytes into
twelve 4-byte counters and the start of a 48000-byte buffer that the player had packed behind
it. The recording had given each of those buffers its own 32 KiB-granular range, so the same
overrun landed in the list's own slack there. The clobbered counters then feed the next
rounds; a 780M page fault past a 64 MB buffer and a hang on a 3090 follow them (expected, the proof plays pending).
Each buffer's place now spans its length rounded up to its recorded granule: the largest
power of two that divides its recorded gpuAddress, from 256 bytes to 64 KiB, and 256 bytes
where the stream records no address (the player's own staging included). Both copies of a
two-copy Managed buffer take it. A buffer past the class's block length takes a block of its
own of the rounded span. The backend's new "places by recorded granule" line counts the
places by granule and gives the most bytes of slack held at once.
Test: rt_replay's buffers_keep_the_slack_of_their_recorded_granule plays two 4-byte buffers
recorded at addresses of 32 KiB and 64 KiB granules and reads back their relocated addresses
from a third: they lie apart by at least the lower one's granule (256 bytes apart before).
docs/REPLAY-STREAM.md says how the backend places buffers.
u3 stopped at player frame 259: the placement of a sampler state at index 16 waited for commit
1614 (#20713), which rt held at Committed because it waits for event #35 to reach 309, which only
command buffer #20439 signals, encoded 20 records later. The program had released #10401 (index 16,
bound directly by #20713) and made #20822 with the same descriptor the next call; Metal gave it ID
16 again. Nothing changed for the work in flight, and the original run did not wait (it could not:
#20713's signal was not yet encoded).
- A sampler state whose recorded descriptor is the one placed last at its index takes the index
without waiting, counted on the indices line; the index stays owed for another sampler state.
- The player tells the backend, at each look for command buffers to wait for, the committed ones
no record played so far lets complete (Backend::held: their unmet event waits, or a held one
ahead on their queue). A placement owing its index to one of those stops with PlayError::Held
naming the chain, instead of waiting for ever.
- docs/REPLAY-STREAM.md says what record order does not promise (a committed buffer may wait on a
later record's signal) and what the indices line and the stop say.
Tests: a unit test of the equal rule in Indices; rt_replay device tests of our own sequence: an
equal sampler state at an index a held commit owes plays through without a wait; another
descriptor there stops with Held naming #6 and its unmet wait. Check follows.
The comparison point takes the GPU's bytes at a completion only for 4 KiB chunks wholly inside
GPU-only ranges, and a recorder may record what a command buffer's GPU work stored in memory the
CPU shares as writes after its commit: which chunks are compared, the Managed rule, why the
player's waits make them change nothing, and the restore they let a stream carry. The planner's
text, verbatim, for the recorder change that lands with it.
Doc only; no test reads this section.
The counter (74fe5e67ca) asked the translator for each pipeline state's reflection to learn its
used buffer arguments. From a Function source that reflection decodes and specializes the
kernel's AIR a second time, inside the backend call the player books as pipeline cost, so every
play paid it: on b3 on the 780M, pipeline time 11.9 s against 1.5 s at f0df30b6ba with the same
403 translations (exclusive A/B, 47329). Its follow-up is dropped, so the count, its report line,
its per-frame counter, its test and its paragraph in REPLAY-STREAM.md go.
Verified: see the exclusive A/B in the hand-over (b3, 780M, development's tip against this).
Under the owner rule the runtime gives a held index to the newer object, so a placement while
an earlier holder's work runs takes the element from under that work, which Metal leaves the
program never to do (docs/RESOURCE-ID.md); the program's own timing kept that duty, and the
player, the runtime's consumer here, now keeps it. Each index is owed to the last commit that
named an object holding it, live or released (a released one's uncommitted users owe it at their
commit; a command buffer released uncommitted owes nothing), and a placement there, named, lowest
or highest, first waits for that commit. The `indices named` line counts the waits and their
time.
A commit counts done once its completed handler has run: the runtime sets a command buffer's
status before it drops what the command buffer held, and runs the handlers after, so the status
alone could find the work done while the runtime still held the old holder.
Verified: the ledger's unit test an_index_is_owed_to_the_commits_that_named_its_holders (to run
in the lane's check). The device test that holds work in flight comes after the reruns.
A read of an unbound buffer argument is undefined in Metal; under the new runtime a draw that
makes one reads address 0 and loses the device. Whether release programs make such reads is a
count the player can take: each pipeline state's used buffer arguments come from the
translator's reflection of its descriptor (isUsed), and each encoder's bound indices from its
setBuffer, setBuffers and setBytes calls per stage (a nil buffer unsets one) until endEncoding.
The backend reports an `unbound buffer reads N: ...` line (the states, the unreflected ones, the
first eight by position and frame) and `unbound_buffer_reads` per frame.
Verified: the unit test a_draw_reading_a_buffer_argument_nothing_is_bound_to_is_counted (to run
in the lane's check).
A run that played every frame but whose objects' gpuResourceID differ from
the recording's exited 1 with an 'error ids' line, the status of a run that
stopped: two clean plays read as crashes. It now ends 'ids: played to the
end; ...' and exits 3; docs/REPLAY-STREAM.md says so.
A constexpr sampler's numbering is a placement like any other. Where a sampler state took the
index from it, a later pipeline state that numbers the constexpr sampler there took nothing back:
it sampled through the program's sampler. Now it places the constexpr sampler there again with
every element it holds (Arrays::hold_samplers: under the grants' lock, the owner's additions where
it still owns the index, else a placement), and the constexpr sampler keeps its elements' samplers
to write them. The consumer chooses constexpr indices and keeps them from the program's sampler
states while a state numbering one lives; rt does not check it (rt README, compute pipeline
docs).
An object the program released while a command buffer that used it is pending is displaced like
a live one: a placement at its index takes it at once, and its teardown once the command buffer
retires touches nothing it no longer owns (one owner compare for both). Nothing empties an
element at the program's release: a committed command buffer still reads the object through its
index, which Metal allows. The owner's teardown nulls it. RESOURCE-ID.md states the duty (no work
in flight reads a displaced or released object through its ID) and what an element no object owns
holds: every element is written at device creation, a null descriptor (nullDescriptor, on the
floor) or the array's default sampler, and written back to that when its owner goes.
The replay player gave constexpr samplers the lowest free sampler index, the range the stream's
named sampler IDs come from, so a program's sampler state could take a constexpr sampler's index.
It now gives them the highest free one, outside that sequence (Indices::highest; REPLAY-STREAM.md).
Tests:
- sampling::every_device_gives_a_constexpr_sampler_s_index_to_the_object_placed_there_last: a
nearest sampler state over sample_up's linear constexpr sampler reads nearest; a later state
numbering it takes the index back (linear, for both states); the sampler state's going touches
nothing; the slot gauge counts the index once.
- sampling::every_device_gives_a_released_object_s_index_to_the_next_at_once: a command buffer
samples A through SA, signals and waits on the host; A and SA are released and B and SB made at
their indices while it is pending (asserted); another queue reads B through SB; after the first
command buffer retires, and A and SA with it, the index still reads B through SB. The writes are
valid under UPDATE_UNUSED_WHILE_PENDING with PARTIALLY_BOUND (vkspec: "as long as they are not
dynamically used by any shader invocations"): A's dispatch completed before its signal.
- replay a_constexpr_sampler_takes_no_index_of_the_sequence.
The consumer's program places a texture at an index a live texture of its own still holds, and
releases the older one later (179 placements in one recorded stream, 92 in another). Metal takes
it: the later texture takes the ID. rt refused it (IndexInUse).
Now Grants keeps one owner word per held index (a HashMap per class, the word given at placement
and never again on the device; no list of holders, no refcount, no second bitset). A placement at
a granted index always succeeds and makes the placed object the owner; a release vacates the index
and empties its elements only where the releaser still owns it, so a displaced object's going
touches nothing. Placement and element writes happen under the grants lock in one step
(Arrays::place_texture, place_samplers, add_samplers, vacate_texture, vacate_samplers), so the
elements always belong to the owner. Where a placement displaces another object, a texture with
no storage view writes its storage element null and a sampler writes the arrays it does not use
back to their defaults, so nothing stale answers. The descriptor-slot gauge counts held indices:
a displacing placement adds none.
The same occupancy serves textures, sampler states and constexpr samplers. Constexpr samplers are
kept by (index, state words), each with its owner word; a later pipeline state of the same words
adds its arrays where the constexpr sampler still owns the index. Refusal::IndexInUse is deleted:
nothing Metal refuses remains. A texture now takes its index after its image and views are made,
so an index not granted is refused after the image is made and freed at once.
The duty: no work in flight reads a displaced object through its ID, as Metal's. rt does not
check it. RESOURCE-ID.md and the rt README state the rule and the duty.
The harness takes the next index round each class's range (its workloads make far fewer objects
than a range holds). The replay player keeps the object placed last per index: a named index an
object holds is taken, and the earlier object's release leaves it; with no index free for a
constexpr sampler it answers IndicesNotGranted past the range.
Tests: grants' an_index_has_one_owner_the_object_placed_there_last (both classes);
sampling::every_device_gives_an_index_to_the_texture_placed_there_last (a storage-capable D at 3,
a sampled-only A over it, whose placement empties D's storage element: a write through 3 is
dropped and D keeps its texels; B storage-capable over A, A dropped; sampling through 3 reads B,
writing through 3 writes B; B dropped, sampling through D's ID reads zero; the slot gauge counts
3 once); the sampler states' test places a state over a live one; replay's indices test.
REFUSALS.md regenerated, api_signatures loses IndexInUse.
The live system zeroes a heap's memory once when it is made, so a buffer
placed there reads zero where nothing wrote it. The runtime's take_block
leaves a block's bytes undefined, and a block it takes again holds a
released block's bytes: placed buffers read them where the program read
zeros, a resource ID among them. zero_block zeroes [from, len) of a new
block through buffers zeroed from their start; from is the extent the
runtime zeroed itself, none yet. The device test writes a placed buffer,
releases it and its block, and reads zeros from a buffer placed in a block
of the same length; the bytes zeroed show both blocks went through it.
new_managed_buffer(bytes, copy, length, copied) takes both placements from the consumer: the
bytes as (block, offset) in a block the host maps, and on a device that keeps a device copy
(has_unified_memory false) the copy as (block, offset) in a Private block the consumer holds, at
any byte offset; gpu_address is that block's address plus the offset. rt chooses no layout any
more: its copy blocks, COPY_ALIGN, the first fit and the device's copies place list are deleted,
and so is the Private block of the copy's own that the copy took where device-local memory had
no room. Placement, and so the slack past a buffer's length, is the consumer's: rt writes the
copy's length and no byte past it.
New typed refusals: ManagedCopyMissing (no copy where the device keeps one),
ManagedCopyOnUnified (a copy where it keeps none) and ManagedCopyNotPrivate (a copy in a block
that is not Private); a copy range past its block is BufferPastBlock, as for any buffer.
managed_spilled_bytes is now per buffer: a copy the consumer placed in a spilled Private block
counts its length while the buffer lives. new_buffer shares the range check (placed).
The harness places a Managed buffer's device copy as it places a Private buffer of its length
and frees both with the buffer. The player places the GPU copy through its places at their
current rule, as a Private buffer of the buffer's length: a buffer in a place of its own keeps
the copy's place beside its own and gives both back with the same users; a buffer in a stream's
block or heap holds the copy's place as its one place. REPLAY-STREAM.md says so.
Tests: the two-copy rule places its device copy 4 KiB into a Private block the consumer takes
and checks gpu_address there (and, under the spill test, in a consumer take that spills, counted
in managed_spilled_bytes); a new device test places the copy at byte 4099 of a Private block
filled with 0xA5 and checks the whole block after the copy's creation and after a copy-in of the
whole buffer: the copy's bytes at 4099..5099 alone, the consumer's slack write at 5100..5200 and
every other byte unchanged; and the four refusals. Every other Managed test places its copy at
the start of a Private block of its own (tests::managed::on_device::new_managed).
Regenerated docs/REFUSALS.md (scripts/refusal-surface); api_signatures.tsv by hand.
The recorder now keeps an announce invariant (its header flag bit 0, FLAG_ANNOUNCED_BYTES_RECORDED;
the version stays 2): at each didModifyRange: of a Managed buffer, the last m2v.write before it
that carries each 4 KiB chunk of the range holds the bytes the program's CPU copy held there, the
GPU's that a synchronizeResource: read back included. A player that also plays the read-back into
its CPU copy pushes the GPU's bytes where the program put its own back without the stream writing
them again, which is how r3's appender lost its count reset at call 4319503 and overran its list.
The reader takes the flags, refusing a segment with another bit or with flags unlike the first
segment's, and the writer writes them (StreamWriter::with_flags). The player tells the backend
before the first call (Backend::announced_bytes_recorded). On a marked stream a
synchronizeResource: of a buffer played with two copies leaves the CPU's copy as the stream's
writes made it: the new runtime's backend copies the GPU's copy into an aside buffer of its own
(one per buffer, in a Shared place, given back at the buffer's release), which a check of the
buffer reads from the read-back to its next didModifyRange:; the old runtime's backend moves
nothing, and its checks read the GPU's copy as before. An unmarked stream plays as before. Each
backend's report says which rule played on its "announced bytes" line, with the read-backs it
kept out. docs/REPLAY-STREAM.md takes the flags (section 1), the invariant (section 6) and the
player's rule (section 10).
Tests: a unit test of the flags (read alike in every segment, refused otherwise); rt_replay
device tests of one stream played marked and unmarked: a write of 5s announced, a fill of 9s
read back (a check sees the 9s), an announcement with no write after it, then a copy of the
buffer and checks: marked, the GPU's copy and the CPU's hold the stream's 5s; unmarked, the 9s
read back (the marked test fails on a player that ignores the flag). Check follows.
The new runtime leaves texture and sampler indices to its consumer. The backend now gives
each object the index the stream names where the runtime takes it: a descriptor's or a
view's resource index, else the index of the ID the program saw of the object (its first
gpuResourceID record, read ahead by the player and handed over before the call that makes
it). Otherwise it gives the lowest index of the object's class that no live object holds
and the program did not reserve, as Metal's pool hands out a sampler state's ID. A reserved
index (reserveResourceIndicesForResourceType:indices:indexCount:) is taken only where the
stream names it. Where the runtime refuses a named index (an object of the play holds it, or
it lies outside the class), the object takes the lowest free one and the report counts it on
the backend's "indices named" line. Released objects give their index back.
Before this, a play of a recorded stream on the new runtime reported tens of objects whose
gpuResourceID differed from the recording's.
Tests: unit tests of the index bookkeeping (Indices), and rt_replay device tests: sampler
states made and released past the class's 3,999 indices reuse the released ones; a reserved
index is taken only where named; a state takes the ID the program saw. docs/REPLAY-STREAM.md
says how the new runtime's backend places textures and sampler states.
The same change, on an older base, passed clippy, the replay unit tests and the four rt_replay
device tests on lavapipe (m3-max-45671, m3-max-45775). The rebased tree's check follows.
The rt backend ended a play at the first render command the runtime answers with a typed gap: r3
stopped at frame 111 on a draw that reads its pass's own target, so nothing past it could be
measured. Such a command is now skipped and counted, as a render state the runtime does not build
is: `skipped_render_commands`, and a report line for each gap with its count and the frame and
call of the first. A dispatch is still skipped only where it names a skipped object.
So that a skip can never pass as a result, the player notes where the backend first skipped
anything (`Backend::skips`, told the frame and stream position of each call through
`Backend::locate`), and `Report::first_skip` holds it. Where it is set, command-replay's skipped
line and its last line (`ok` or `error ...`) end `; not a verdict past frame F, call C`.
Tests: a player unit test on a backend that skips draws (the first skip's frame and call, the
verdict note, none without a skip), and an rt device test where a draw of points after a covering
triangle is skipped, counted, named on its line, and the check still matches.
A stream may record more than one device: reims's one-copy recording on the 780M also holds the
host window's device on the display GPU, which is not unified. Each segment opens with one identity
record per live device in id order, and the player passed every record to the backend, so the last
one decided how every Managed buffer was kept, whichever device the guest used.
The player now reads ahead which recorded device the guest makes its objects on (the one that most
calls making an object have as their receiver, the lowest id of a tie) and takes the Managed form
from that device's identity record only. The report names the other devices on a
`devices apart from the guest's` line.
Test: a unit test with two devices, one unified and one not, the guest on each in turn.
What: where device-local memory has no room for a copy block, a Managed buffer's device copy is
now a Private block of its own, taken through the pool, so it spills to whatever memory type has
room like any Private block; where no type has room, new_managed_buffer returns the allocation's
out-of-device-memory error (Metal: nil). Before, such a buffer was its Shared range, one copy,
on a device whose has_unified_memory is false. Gauges::managed_spilled_bytes counts the bytes of
Managed buffers whose device copy is not device-local, while they live; the replay player
reports it beside spilled_bytes. The rt README states the cost: on a full discrete card a
Managed kernel reads its copy across the host link.
Why: the planner's ruling. Metal keeps a Managed buffer's two copies on a discrete Mac: a
kernel's write stays in the GPU's copy until a synchronize, and didModifyRange sends the CPU's
bytes over it. With one copy, a kernel's write reached the consumer's bytes, and a range named
with no CPU write left the kernel's value in place: a program could observe the difference.
Tests: tests::managed::every_device_keeps_metal_s_two_copy_rule_for_a_managed_buffer (every
device): a kernel takes each word x to 2x+1, the range is named with no host write, a second
kernel reads it. Where has_unified_memory is false the consumer's bytes keep the host's words
and the reader reads them, and the buffer's address is not its Shared range's; on a unified
device the reader reads the kernel's write. tests::spill: the same rule with the Private type's
allocations made to fail (the test seam core.fail_private) and the pool's Private blocks
spilled; on a device that is not unified the gauge counts the buffer's 256 bytes while it lives
and reads 0 after. The api signature table gains the gauge field.
A render pipeline state the runtime answers with a typed gap or the translator
refuses is skipped and counted, and nothing said which one or why: the replay
device test's draw was skipped on every device (legs 45244, 45245, 45246) with
skipped_render_states=1 and no reason. The backend now keeps the first such
state's object id and the runtime's answer, and its lines print
`skipped render states N, the first #ID: WHY`. The device test prints the
backend's lines after the player's.
REPLAY-STREAM.md names the line.
Verified: the next job builds the validation crate in every cfg and runs the
replay test on lavapipe.
The new runtime builds draws (its render encoder, render pipeline and
depth-stencil states), so the player's rt backend stops skipping render
encoders whole. It plays, on rt's API:
- newRenderPipelineStateWithDescriptor:error:, its constexpr samplers numbered
as a compute pipeline state's are (one helper, `numbered`, for both);
newDepthStencilStateWithDescriptor:; MTLRenderPassDescriptor.new and
.renderPassDescriptor with their m2v.setPass, m2v.setColorAttachment,
m2v.setDepthAttachment and m2v.setStencilAttachment setter records;
- renderCommandEncoderWithDescriptor: and the render encoder's calls the old
runtime's backend plays, with the vertex stage's textures and samplers, both
stages' bytes, cull mode, winding, blend color, and the draws' instance,
base-vertex and base-instance forms.
What rt does not build stays skipped and counted, honestly: a render pipeline
state rt answers with a typed gap or the translator refuses
(skipped_render_states); a parallel render encoder, or a render encoder of a
pass that holds what rt's descriptor does not (resolve textures, depth planes,
store action options, a visibility result buffer, layered or tile rendering, a
skipped texture) or that rt answers with a typed gap (skipped_encoders); and a
draw whose pipeline state, bound buffer or texture, or index buffer is a
skipped object (skipped_draws).
The render pipeline, depth-stencil and pass-key parsing moves from the old
backend's descriptors.rs to replay/translator.rs, shared by both backends, as
the sampler's is. docs/REPLAY-STREAM.md says what the rt backend plays and
counts.
Verified: lint of the validation crate (clippy in every cfg, the replay
tests, rustdoc); the device test that follows plays a draw on every device.
The new runtime's backend skips render pipeline and depth-stencil states, so nothing in its play reads their IDs; b3's play counted 8,082 of them as differing. It now counts them (skipped_resource_ids) and command-replay leaves them out of differing_ids, as it leaves the compute pipeline states' typed gap. The id lines stay.
Whether rt must capture a Managed texture's bytes at replaceRegion (rather than when the GPU copy
is next used) turns on how often a program writes one while a command buffer that used it may
still be running. The report now says.
- The player keeps, from the stream alone (replay/texwrites.rs): the textures and each view's
texture; each encoder's command buffer; the textures each command buffer used (an encoder call
naming the texture or a view of it, or an encoder made with an MTL...Descriptor object, or one
made on such an object, that names one); each texture's latest committed user per queue; and the
completions the stream records, which are only the program's CPU waits (waitUntilCompleted of a
command buffer or a later one of its queue, waitUntilSignaledValue:timeoutMS: reaching a value
one of its queue's command buffers signals). The play itself waits at each commit, so this is the
recording's order, not the play's.
- At each call on a texture that carries bytes (replaceRegion:...), blobs resolved, it asks the
backend whether the texture is Managed (Backend::managed_texture, default None; the rt backend
answers from the texture's descriptor) and counts the write, and where a committed user has no
recorded completion, counts it by the presents since that user's commit (0, 1, 2, 3+) and names
the first eight.
- Report::texture_writes (TextureWrites) carries the counts and the report's texture_writes line
says them, with the writes into textures whose storage the backend does not tell.
REPLAY-STREAM.md section 10 documents the line.
Verified: a replay test (Kept backend) writes a Managed texture used through a view by a committed
command buffer, before and after a present, writes a texture that is not Managed, and writes again
after the CPU waited: 3 writes, 2 with the user not seen complete (one per present bucket), the
first two named; clippy and the plays in the check job.
Metal's useHeap: names a heap the encoder's work may reach. rt had no such call, so the player
skipped and counted each one. ComputeCommandEncoder::use_heap takes the heap's block number (a
HeapRange's block, or the block a placement heap's buffers sit in) and keeps that block in the
command buffer until it retires, exactly as use_resource keeps a buffer's block (keep and the new
keep_block share one list). Metal states no retention for useHeap:, so keeping is the safe
reading. The call declares no access: a kernel that reaches a heap's resources through addresses
outside its slots already orders against every write since the last barrier. A number no handle
names answers Error::NoSuchBlock, as new_buffer's does.
The player's compute encoders now call use_heap with the heap's block, and still skip and count
a useHeap: of a skipped object. REPLAY-STREAM.md's skip list and the rt README say so.
Test: heap::every_device_holds_a_used_heap_until_its_command_buffer_retires takes a Private
block, uses it twice in one encoder (the command buffer holds it once), releases it while the
encoder is open (the command buffer still holds it, and a new use of its number answers
NoSuchBlock), commits, and waits for the block's last holder to go once the command buffer
retires. api_signatures.tsv regenerated (one new method); REFUSALS.md unchanged.
A play that hangs (gb's fault at frame 1095, b2's at 312) wrote no report: report.txt got its frame
and end lines only at the play's end, so every hung play left 0 frames in its timing table, and the
cold and warm plays of the frames before each fault could not be read.
- Player::until_frame(F) stops after frame F's present (frames counted from 0 as Report::frames
counts them), completes the work committed so far and reports as at the stream's end;
command-replay's --until-frame F sets it and says `until-frame F`.
- Player::with_frame_lines(out) writes each frame's lines (Report::frame_lines: its frame and end
lines) to out as the frame ends, flushed; command-replay passes its open report.txt and writes
the rest at the end (Report::lines_but_frames). Report::lines keeps every line, the completed
groups' first.
- The rt backend's report gets an `unwritten N` line: the Shared buffers made without bytes that a
compute encoder bound or used and whose command buffer committed before any recorded write,
upload or GPU pass reached their bytes since their making, with the first few named and the
command buffer that read each. It is where a recording that missed the program's writes shows
(b2's uniform ring #58725 had no recorded byte in its life). What reaches a buffer: an m2v.write
into it, into its block over it or into another buffer of the block over it; a blit or render
encoder call naming it or such a buffer (skipped encoders included); the commit of a dispatch
binding it. It counts and stops nothing (new_runtime/unwritten.rs, hooks in the make paths,
write, release, the encoder calls and the commit).
REPLAY-STREAM.md section 10 documents --until-frame, the per-frame lines and the unwritten line.
Verified: replay tests for the frame stop and the per-frame lines (Kept backend) and for the
unwritten count (the tracker alone: block writes, a blit naming, a write before the commit, a
release, a later commit, an alias made later); clippy and the device plays in the check job.
The pool handed a take of up to a block length a whole pooled block and kept one ready block per
class, which the block-maker thread made again as soon as a take used it. A 16-byte Shared buffer
took the ready block, and the 16 MiB allocation that followed held the consumer's next pipeline
creation for its whole length on NVIDIA's driver.
Now each block is a range of one of its class's allocations, with its own VkBuffer:
- A take is a kept block of its length, else the first free range that fits, else the start of an
allocation made in the call: 16 MiB, or the block's own length where that is longer. Lengths
round up to 64 KiB (or bufferImageGranularity); a block starts at its length rounded up to a
power of two, up to 2 MiB.
- Device::new makes one 16 MiB allocation per class. After that, the block-maker thread makes
another only while the class's free bytes are under 8 MiB. A take never waits on it for memory.
- A take that no free range fits, while the class keeps blocks of other lengths, allocates at once.
It also asks the block-maker thread to give those blocks' bytes back, after the consumer's hook.
Only when its own allocation fails does it wait for those bytes, then look for a free range once
more.
- An allocation holding no live block is idle. A class keeps its idle allocations while their
bytes plus those of its allocations in use stay at or under the most bytes it had in use over the
last 10 seconds, and within an eighth of its memory type's heap. Past that it frees the oldest,
except the reserve that keeps 8 MiB free. The rule runs at takes and give-backs on an injectable
clock; there is no timer.
- Removed: the dedicated path, fits-and-fills-half, the 256 and 128 MiB idle bounds and the 64 MiB
Private block.
- Metrics: blocks_reused replaces dedicated_blocks_reused. New metrics: block_bytes_made, and the
vkAllocateMemory time on the consumer's threads (count, total, longest) apart from the
block-maker thread's.
Tests:
- Unit: rounding, base alignment, and the window and surplus rule.
- On device:
- the first allocations, and the trigger at 8 MiB free;
- kept blocks taken again with their number, address and mapping;
- an allocation beside kept blocks of other lengths, with their bytes given back;
- the failed-allocation path, at an answered maxMemoryAllocationCount;
- idle allocations following the window down, the reserve kept;
- a seeded 300-step stress of mixed takes and releases across both classes, each step under a
one-minute timeout.
- Tests that took a block of 1 byte and used more of it now take what they use.
- The replay's rt counters read the new metrics.
Verified: cargo fmt; api_signatures blessed; REFUSALS.md regenerated. Clippy, the suites and the
device legs follow as potluck jobs.
How a Managed buffer behaves depends on the recording device's hasUnifiedMemory: one copy where
it is true (a CPU write needs no didModifyRange), a GPU copy made at the buffer's making and
changed only by didModifyRange where it is false. The stream did not say which, and the rt backend
always made the runtime's Managed buffer: gb, recorded on a discrete GPU, wrote its no-copy
Managed buffers (#368205, #368202, #368214) once before first use with no didModifyRange, so their
GPU copies never got the bytes; b2, recorded with unified memory, relies on such writes legitimately.
The player now takes the form from the stream's new m2v.deviceIdentity record (it plays as nothing
and tells the backend hasUnifiedMemory through Backend::recorded_unified_memory), or for a stream
without one from command-replay's --managed one-copy|two-copy. One copy: every Managed buffer plays
as a Shared one. Two copies: the runtime's Managed buffer, its GPU copy from the bytes it was made
with: a copied buffer's, or the new create-time bytes a no-copy one's making now carries
(newBufferWithBytesNoCopy's first argument, a no-copy descriptor's contents). A stream with no
identity record gives none, so a no-copy buffer's GPU copy takes the writes recorded before its
first use (the commit of a command buffer whose encoder names it). With neither the record nor the
setting a Managed buffer stops the play with an error saying so. The report's managed line names
the form and its source, counts the Managed buffers and the no-copy ones with contents from first
use, not from create, and notes a two-copy recording played on a unified-memory device.
REPLAY-STREAM.md documents the identity record, the create-time bytes and the player's rule.
Verified: a replay test plays an identity record as nothing and sees the backend told
hasUnifiedMemory; the rt paths need a device play (gb on the 3090 next).
Both recordings' guest-RAM copies (gb 106 before frame 1095, b2 14 before frame 312) land in
Private buffers, and the rt backend skipped them, so the bytes and addresses they carry never
reached the GPU. A buffer-to-buffer copy now plays as rt's copy_from_buffer_to_buffer. A copy from
the guest's RAM, the recording's plumbing, plays as its pieces' bytes in a Shared staging place of
the backend's own, then a buffer copy into the target in the same blit encoder, so the GPU's order
holds. A buffer copy takes whole 4-byte words at 4-byte offsets: a piece's edge bytes up to whole
words come from the target's mapping where it has one; a piece with such edges into a buffer
with none is skipped and counted. The staging place is given back at the command buffer's commit
and is free once it completes, so the staging stays bounded by the work in flight
(staged_guest_ram_bytes counts it). The player times these copies in a column of its own
(`upload`), the recording's share and not the runtime's.
The rt backend skipped every texture over a buffer, every texture view and every IOSurface
texture, and with them each dispatch and blit that bound one: words in the program's memory
then named textures the play never made. Textures over a buffer now play as the runtime's
(Buffer::new_texture) and views as its views (Texture::new_texture_view). An IOSurface texture,
a tiled texture over a buffer, and a texture or view the runtime answers with a typed gap become
an ordinary texture of the same descriptor, counted as a substitution (the recording's artefact,
not the runtime's). optimizeContentsForGPUAccess plays as nothing; the blits still not built are
counted by kind: buffer copies, guest-RAM copies in and out, texture syncs and mipmaps.
The report's second line says how far relocation reached: words relocated, words left at 4
past 8, address arguments, writes into objects with no recorded range, and the objects whose ID
differs from the recording's, which now make the play an error.
The relocation tests assert the writes of no address are counted.
A spike frame's wall time needs a split by cause before two runtimes can be compared on it. The
player now times, on its own thread, each kind of work: reading and decoding the stream and its
blobs, writing bytes into the runtime's memory, reading back, waiting for command buffers, the
calls that make or release resources (with the longest one), the calls that make libraries,
functions and pipeline states (with the longest one), every other runtime call, and reading the
runtime's counters; what is left is the player's own work. Beside them, a frame's GPU busy time
is the union of the GPU intervals of the command buffers it waited for, which a new Backend
method gives: both runtimes' GPUStartTime and GPUEndTime. The end line carries them, and the old
runtime's counters add its vkCreate*Pipelines and shader-cache nanoseconds.
A test plays three command buffers, two of them overlapping on the GPU, and checks the frame's
GPU busy time counts the overlap once and the end line holds the times.
A timing table must never come from a snapshotting play unnoticed: the device line reads
device NAME runtime old|rt snapshots yes|no for both runtimes.
Verified: cargo fmt only; clippy, replay tests and the release build next.
Old's play of gb on the 3090 with snapshots read 0.54 of 1.9 GB of stream in about 5 minutes
(m3-max-44322, cancelled before its 15-minute limit): the player's own splits and readbacks around
12,000 dispatches dominate it, and rt declines them, so their frame times and memory would not
compare. Player::without_snapshots takes none on any backend.
Verified: cargo fmt only; clippy, replay tests and the release build next.
The planner asks whether NVIDIA's first-pipeline cost is paid once per process or once per
kernel: each state's making's wall time, in order, with whether another specialization of its
kernel (a library's function by name) was made before. Backend::lines carries the backend's own
report lines; command-replay prints them after the player's.
Verified: cargo fmt only; build, clippy and replay tests next.
- The rt backend dropped a released m2v block or heap without Device::release_block, so every
block gb made and released stayed allocated; the 3090 play stopped at frame 1074 on
vkAllocateMemory (m3-max-44161).
- The old backend skips a library from source (no device here compiles Metal source), what is
made of a skipped object, and the draws of a render encoder whose pipeline state is one, all
counted; it takes MTLRenderPassDescriptor.renderPassDescriptor and the copyFromBuffer:...
toTexture: form without options. Those were the scratch player's alone, so old could not play
gb from development.
- Each frame's end line: wall nanoseconds, VmRSS, and the backend's gauges as they stand (rt's
live blocks, buffers, textures, pipelines, kernels, command buffers, spilled bytes and the bytes
of the blocks the backend holds by class; old's live, empty and dedicated memory blocks). Old's
counters add device memory allocated and pooled blocks made and freed. The skipped and gaps
lines are printed for both backends, before ok or error as documented.
Verified: cargo fmt only so far; build, clippy and the replay tests run next on msi.
A pooled block's length is now per memory class, MemoryClass::block_len: 16 MiB Shared and
64 MiB Private on every device. It replaces the one 256 MiB BLOCK_LEN. take_block gives a
pooled block up to the class's length and a dedicated one past it. Textures are placed in
texture blocks up to the Private length. The harness and the replay player's places take
blocks of the class's length.
Why: a driver may hold the device's other calls for the whole of a block's
vkAllocateMemory, and the hold grows with the bytes, so the length sets how long one hold
lasts. On an RTX 3090 (NVIDIA's Linux driver, probe at 70d7cae48e, jobs 44050 and 44053
with the RTX 2080), a pipeline creation beside a Shared block's making took 40-45 ms at
256 MiB and 6-8 ms at 16 MiB (3-4 ms settled). 16 MiB is the largest piece a guest's
allocator takes. Private holds less: 3.4-4.6 ms beside a 64 MiB block, at most 1 ms more
than beside a 32 MiB one. At 64 MiB, a texture or a Managed buffer's device copy of 32 MiB
takes a pooled block.
Tests: every_device_pools_16_mib_shared_and_64_mib_private_blocks covers the lengths, the
dedicated block past each, and a 32 MiB texture placed in a texture block. The memory,
command, places, spill and upload tests use the class's length. The memory test reads a
Private block back a Shared block's length at a time. API table re-blessed (the BLOCK_LEN
const goes, MemoryClass::block_len comes).
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.