A device cache on a GPU that shares the CPU's memory exists because textures
over the surface's pages cannot lie in place. A 3662x2038 desktop's surface
is one of them: 14648 bytes of texels in rows 14848 apart. metal2vulkan then
made each texture over the cache a shadow, as an image at that pitch holds the
bytes between rows, and Vulkan lets layout moves and a render pass's load and
store write them. On the 780M that cost about 1 G texels/s of copies in a
Finder drag (pad boot m3-max-7495: 169 shadowed textures, drag 36 fps).
A laid-out cache's copies into the pages already take the texels alone
(d48b1fe76), and nothing else reads those bytes, so the cache's buffer now says
so. GpuDevice::new_buffer_of_length_padding_unobserved is a buffer as
newBufferWithLength:options: makes one. The Vulkan platform makes it with
metal2vulkan's BufferDescriptor::with_padding_unobserved, and the default
makes it as any other buffer. SurfaceCaches::new_cache makes a laid-out cache
so. An exportable cache, a deferred one and one with no layout are made as
before: only a GPU of its own memory exports or defers caches, and only a GPU
that shares the CPU's memory lays them out.
What changes for the guest: a texture over such a cache is an image over the
cache's memory, which may change the bytes between rows there. No copy carries
them into the pages, so what the guest's CPU reads of the surface is
unchanged. The host does fewer copies.
Measured on the 780M (cold boots of macOS 26.7.2 on um870 and um790, each
against development without this commit on the same runtime, 0 fatal): 12 or 13
textures a boot lie over laid-out caches of small padded surfaces, where each
was a shadow (unobserved_padding_aliases), all as Safari's, Finder's and
TextEdit's windows open; 5 to 12 fewer shadowed textures, and the shadows'
copies back over the session fall from 23.5-28.8M texels to 12.2-12.8M, as
those textures' writes land in the cache. Copies in and the frame rate (60)
are unchanged. The desktop's surface, 3648 wide since 7638d2ea0, is not
padded and lies in place in every run.
Tests:
- Over a buffer with the declaration, a texture lies over the buffer's memory
(unobserved_padding_aliases +1, no shadow). This holds where the device lays
its linear images' rows at multiples of an alignment past Metal's 16 bytes
(RADV's 256). Over a buffer without the declaration, the texture is a
shadow.
- A laid-out cache's buffer is made by the new call, and one with no layout by
newBufferWithLength:options:.