[MG_Backend, MG_IntegrationTest] (P7): a uniform range that ends mid-word is copied, not refused

`uniform-buffer-byte-tail@P7` is retired. It was the live boundary the Redmi
Minecraft run reported (notes/p5f/magma-inproc-fix.md #5) and, since wave 0, a
named Fatal that took the session with it.

Only the SIZE of a uniform range can land off a word. glBindBufferRange already
forces the offset onto GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT and records
GL_INVALID_VALUE otherwise (GL_Buffer.cpp ValidateBufferRangeOffsetAndSize), and
every device reports that as a multiple of four - but GL 4.6 core 6.1.1 puts no
such rule on size, so a 19-byte bind is legal and 19 % 4 is not 0. The sub-word
start is only reachable protocol-side; the new arm handles it anyway rather than
leaving a second shape to trip over later.

CopyWireBufferSubWordRangeToSlice rounds the read of the APPLICATION's store OUT
to whole words, clamped to the store's end so the widened window can never touch
a byte the application does not own, and lands it in a transient staging slice.
Only the staging -> padded-block shift is sub-word, and that happens inside our
own arena; vkCmdCopyBuffer places no alignment rule on a region's offsets or size
(unlike vkCmdUpdateBuffer / vkCmdFillBuffer), so the shift is a plain legal copy.
The block still starts at the padded slice's own offset, which is what lets the
descriptor keep a minUniformBufferOffsetAlignment-aligned dynamic offset.

red-once (R-16), all three Magma two-process arms, before the backend half:

    DirectVulkan.Split.Buffers.F1WireScenario.SubWordUniformBufferRangePadsMissingBytes
    DirectVulkan.Spawn.Buffers.F1WireScenario.SubWordUniformBufferRangePadsMissingBytes
    DirectVulkan.Tcp.Buffers.F1WireScenario.SubWordUniformBufferRangePadsMissingBytes
        Subprocess aborted - MGPipe: Fatal{UnmigratedVerb, "Magma:uniform-buffer-byte-tail@P7"}

and green after it. The case is the sibling of
ShortUniformBufferRangePadsMissingBytes with a 19-byte range; the byte just past
the range is poisoned, so a rounding that leaks it reads tail.x as 0.5f and the
red channel comes back 127 instead of 0.

Lanes: integration-magma-split 74 (was 73), -spawn 53 (52), -tcp 55 (54),
integration-magma-buffers 20 (19), all green. fatal_census unchanged at 79 abort
sites / 43 family words - these refusals stopped being bare aborts in wave 0, so
a retirement moves no census number and needs no re-baseline. link_ratchet
unchanged at 186.
This commit is contained in:
2026-09-22 16:22:40 -04:00
parent cf7ca59fab
commit 450d30759e
5 changed files with 147 additions and 4 deletions
@@ -2391,15 +2391,30 @@ namespace MobileGL::MG_Backend::DirectVulkan {
// inside the GL binding range. A readback here could retire the command buffer
// whose value BindProgramUniformBuffers is currently holding.
const VkDeviceSize copied = std::min(available, blockSize);
if (bound && ((start & 3u) != 0 || ((source.offset + start) & 3u) != 0 || (copied & 3u) != 0))
WireDescriptorFatal("uniform-buffer-byte-tail@P7");
static thread_local Vector<Uint8> zero;
zero.assign(static_cast<SizeT>(blockSize), 0);
BufferSlice padded{};
if (!m_bufferManager->UploadTransient(BufferKind::Uniform, m_wireFrameIndex, zero.data(), blockSize,
std::max<VkDeviceSize>(4, m_minDynamicOffsetAlignment), padded) || !padded.IsValid()) return false;
if (bound && copied != 0 &&
!m_bufferManager->CopyWireBufferRangeToSlice(range.Res, start, copied, padded)) return false;
if (bound && copied != 0) {
// P7 A.1 retires `uniform-buffer-byte-tail@P7`. The window is word-aligned at both
// ends on nearly every bind - glBindBufferRange already forces the offset onto
// GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, and that is a multiple of four on every
// device - but GL 4.6 core 6.1.1 puts no such rule on the SIZE, so `copied` is free
// to end mid-word and the Redmi Minecraft run lands there
// (notes/p5f/magma-inproc-fix.md #5). An unaligned start is not reachable through
// the public API and only a protocol-level offset can produce one; the sub-word arm
// handles it anyway rather than leaving a second shape to trip over later. Both arms
// copy the same bytes to the same place: the sub-word one pays one extra transient
// slice and one extra region copy, and nothing outside [start, start + copied)
// reaches the block, which is what makes the padded zeros the visible tail.
const Bool wordWindow = ((start | copied) & 3u) == 0;
if (!(wordWindow
? m_bufferManager->CopyWireBufferRangeToSlice(range.Res, start, copied, padded)
: m_bufferManager->CopyWireBufferSubWordRangeToSlice(range.Res, start, copied,
m_wireFrameIndex, padded, 0)))
return false;
}
if (padded.offset > std::numeric_limits<Uint32>::max())
WireDescriptorFatal("uniform-buffer-dynamic-offset@P7");
out.directBindable = true;