mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-30 21:22:15 +09:00
69 lines
3.7 KiB
C++
69 lines
3.7 KiB
C++
// MobileGL - MobileGL/MG_Remote/Client/GpuWritePending.cpp
|
|
// Copyright (c) 2025-2026 MobileGL-Dev
|
|
// Licensed under the GNU Lesser General Public License v3.0:
|
|
// https://www.gnu.org/licenses/gpl-3.0.txt
|
|
// https://www.gnu.org/licenses/lgpl-3.0.txt
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
// End of Source File Header
|
|
|
|
#include "GpuWritePending.h"
|
|
|
|
#include "ClientSession.h"
|
|
// RunsAsTheServerRole: declared beside the wire emitters that need the same predicate, so this
|
|
// TU does not pull a server header in for it.
|
|
#include "WireTables.h"
|
|
|
|
namespace MobileGL::MG_Remote::Client {
|
|
|
|
SizeT BufferWritebackSliceBytes() {
|
|
ClientSession* session = ClientSession::Active();
|
|
if (session == nullptr) return 0;
|
|
// A quarter of the ring, not the MaxRecordBytes half: the record carries its own
|
|
// header and the 32-byte EventBufferWritebackHead beside the payload, and the ring
|
|
// may still hold a few small events (gpu-written, gl-error) posted earlier in the
|
|
// same verb's apply. Each slice round-trips with its own barrier + drain, so the
|
|
// ring never holds more than one slice's bytes.
|
|
const Uint64 slice = session->EventRingCapacityBytes() / 4;
|
|
// A floor so a pathologically small operator-supplied ring cannot make the slicing
|
|
// loop in SyncGpuWrites spin at zero width; such a ring is broken anyway, and the
|
|
// producer's Fatal{EventRingOverflow} names it on the first post.
|
|
return static_cast<SizeT>(slice < 4096 ? 4096 : slice);
|
|
}
|
|
|
|
SizeT MGPipeStageChunkBytesFor(Uint64 stageCapacityBytes) {
|
|
if (stageCapacityBytes == 0) return 0;
|
|
// A quarter of the arena, not all of it, for the readback slice's reason one ring over
|
|
// (above): the pieces of one range are staged one after another, an allocation is only
|
|
// reclaimable once the record carrying it has retired, and the allocator skips a
|
|
// remainder it cannot fill contiguously. A quarter leaves room for the pieces still in
|
|
// flight, so an ordinary whole-buffer upload never waits on a retirement it could have
|
|
// avoided.
|
|
const Uint64 quarter = stageCapacityBytes / 4;
|
|
// A floor so a pathologically small operator-supplied segment cannot make the piece
|
|
// width zero, which the walk reads as "refuse" (MGPipeForEachSubDataRecordRange); such a segment
|
|
// is broken anyway, and the producer's Fatal{RingOverrun} names it on the first stage.
|
|
const Uint64 chunk = quarter < 4096 ? 4096 : quarter;
|
|
return static_cast<SizeT>(chunk > stageCapacityBytes ? stageCapacityBytes : chunk);
|
|
}
|
|
|
|
SizeT MGPipeStageChunkBytes() {
|
|
// The server role's own uploads run the monolith adapter (RunsAsTheServerRole's comment
|
|
// in WireTables.h): cutting them would change how many calls the server's own backend
|
|
// sees for one application call, which is a monolith behavior change on the apply
|
|
// thread and not this emitter's to make.
|
|
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return 0;
|
|
if (RunsAsTheServerRole()) return 0;
|
|
ClientSession* session = ClientSession::Active();
|
|
// No session: the emission WAS the application (every unit gate, and a monolith-shaped
|
|
// lane in a split build), so there is no arena to fit and the record's own bound stands.
|
|
if (session == nullptr) return 0;
|
|
return MGPipeStageChunkBytesFor(session->StageCapacityBytes());
|
|
}
|
|
|
|
Uint64 GpuWriteOrderSeq() {
|
|
ClientSession* session = ClientSession::Active();
|
|
return session == nullptr ? 0 : session->LastPublishedSeq();
|
|
}
|
|
|
|
} // namespace MobileGL::MG_Remote::Client
|