On a host whose GPU shares the CPU's memory, rt makes a texture in place over
a cached surface's pages by copying the bytes under it out and back around the
image's first layout move. A guest write to those bytes inside that span was
lost (the two tests of the commit before), where a Mac keeps it. The make now
runs rt's RestoreFence around the span, which keeps its writers out:
- The guest's read-write locks. A new device feature, FEATURES_EXT bit 1
(SURFACE_HOLD), is taken in a new register, DRIVER_FEATURES_EXT (0x05c).
Where the driver took it, the host raises a hold word in the cached block's
header (offset 8) before the copy out, rereads the surface's CPU generation
after a full fence, and refuses the make as "unsettled" where a lock moved
it. A lock that finds the word raised sets WAITED and waits. The host lowers
the word once the bytes are back and, where a lock waited, posts
SURFACE_HOLD_LOWERED (0x413), whose vector wakes it.
- The device's own writers. The make is refused as "busy" where a command
buffer that uses the cache is begun and not ended, or a copy into its pages
or a fill from them is in flight. Otherwise the block is marked made, and a
begin that uses it waits for the span's end, at most 100 ms.
- The thread that made a texture over a buffer of its own pages. Where the
driver took the hold, the host answers each TEXTURE_FROM_BUFFER and
LINEAR_TEXTURE_FROM_BUFFER over a BUFFER_OVER_PAGES buffer with a COMPLETE
once carried out, so the thread's writes after its create follow the span.
This is a device-wide rule (A), not a per-block flag (A'): on Linux, whether
a block's make restores (its import by address, not as dma-bufs) depends on
the views' folds at their budget and on rt's refusals, which come after the
pages are answered, so no answer can carry it exactly. The rule only waits
more, and its waits are counted (rt-pages-texture-creates-answered, -ns).
A driver that does not take the hold, as the kexts before this change, gets no
make that would copy the bytes out and back: it is declined as no-lock-hold,
and the shape takes the platform's own image. That is decided up front where
every import of pages lies in host memory (a Mac, Windows), and per block on
Linux once a make over the block's import ran the fence.
What the hold does not cover: a guest thread writing those bytes with no lock,
or another device's DMA, inside the span; and a read under a read-only lock
then may see other bytes. docs/known-issues.md says so, with the hosts.
The two red tests pass. New tests cover a lock ahead of the hold, a command
buffer and a copy in flight, a begin inside the span, the device's register
and event, and the answered creates. Each writer kind's tests fail with its
check switched off (job m3-max-82923).