mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-19 16:01:57 +09:00
Compare commits
57
Commits
85362a856d
...
3c13fa4b4a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c13fa4b4a | ||
|
|
d8b9848003 | ||
|
|
b4789e8ed4 | ||
|
|
5c777b49e8 | ||
|
|
dd89951062 | ||
|
|
53b83469e6 | ||
|
|
98ea16042a | ||
|
|
7c6f6886ff | ||
|
|
3cc4e1eca2 | ||
|
|
6662176733 | ||
|
|
44f91c7405 | ||
|
|
e7a66d2f24 | ||
|
|
cae68992b0 | ||
|
|
db2196fb08 | ||
|
|
30e385812d | ||
|
|
5b226f16ae | ||
|
|
e0f69e8791 | ||
|
|
4d1499ef7e | ||
|
|
ca1beb6958 | ||
|
|
48b2f56ef8 | ||
|
|
1c8727102c | ||
|
|
6ee4c0979b | ||
|
|
b004e5dcbb | ||
|
|
bbfd4fef81 | ||
|
|
99211a4807 | ||
|
|
aa38f0a05b | ||
|
|
c5491ca675 | ||
|
|
112c1d8dfc | ||
|
|
4fc93c1ab9 | ||
|
|
a04cf05c93 | ||
|
|
fcd7c5c87a | ||
|
|
1ebe6abeb2 | ||
|
|
f4675d1ac0 | ||
|
|
a08b337975 | ||
|
|
6c37c20f59 | ||
|
|
859590901a | ||
|
|
6e6b86e592 | ||
|
|
a3466e6f4c | ||
|
|
72e7902080 | ||
|
|
3012d52e2b | ||
|
|
39d0677616 | ||
|
|
f6cfcbd36b | ||
|
|
367e473416 | ||
|
|
11cbf4b688 | ||
|
|
a513c53ee3 | ||
|
|
b4cf9b0527 | ||
|
|
c06878ef73 | ||
|
|
0117d15725 | ||
|
|
287bade924 | ||
|
|
0d54de62e2 | ||
|
|
69a278549b | ||
|
|
f40a57cc96 | ||
|
|
5ef4701294 | ||
|
|
e99796d6ec | ||
|
|
7568161eb4 | ||
|
|
2fde70341d | ||
|
|
1f8de61be1 |
+90
-21
@@ -1187,11 +1187,24 @@ jobs:
|
||||
MOBILEGL_IPC_STRICT_ERRORS: "1"
|
||||
run: ctest --output-on-failure -L unit --no-tests=error -j "$(nproc)"
|
||||
|
||||
# The expected-red half: every integration-split entry aborts on its first BARRIER-PULLED
|
||||
# read under strict. The run is EXPECTED to fail; what the step gates on is that the
|
||||
# failure is the strict Fatal and nothing else. A scenario that PASSED would mean strict
|
||||
# never armed, and one whose private log lacks the marker failed for another reason.
|
||||
- name: Integration-split aborts under strict with the strict marker
|
||||
# ---- P5e (ra), MG_Remote/CONTRACT-P5E.md §7: ONE STEP, TWO ARMS, AND THE TREE PICKS ----
|
||||
#
|
||||
# This lane was written as an EXPECTED-RED control: under strict every integration-split
|
||||
# entry aborts on its first BARRIER-PULLED read, so the step gated on the run failing and
|
||||
# on the strict marker being the reason. P5e turns it into a HARD GREEN GATE - once the
|
||||
# client runs ahead, an unbarriered record's pull is a Fatal whatever this knob says
|
||||
# (§3.3), so what strict adds is only the BARRIERED rows' pulls, and those are a short,
|
||||
# named list. A revert of any handle arm in vi/sb/pg/tx2/fb then goes red HERE, by field
|
||||
# and verb, instead of in a picture nobody diffs.
|
||||
#
|
||||
# THE ARM IS CHOSEN BY THE TREE, NOT BY A SECOND EDIT. kMGPipeP5eRunAheadReady in
|
||||
# MG_Backend/Init.cpp is the one constant the integration commit flips, and it is exactly
|
||||
# the fact this lane's expectation depends on: with it false no server publishes
|
||||
# kCapRunAheadApply, every record is barriered, every scenario still aborts on its first
|
||||
# pull and the expected-red control is the honest gate. Reading it here means the lane
|
||||
# changes meaning in the same commit the runtime does - a lane whose flip is a separate
|
||||
# human step is a lane that is wrong for as long as that step is outstanding.
|
||||
- name: Integration-split under strict - expected-red before the P5e flip, hard green after
|
||||
working-directory: build-split
|
||||
env:
|
||||
MOBILEGL_ITEST_REQUIRE_GPU: "1"
|
||||
@@ -1199,27 +1212,83 @@ jobs:
|
||||
MOBILEGL_TRANSPORT: "inproc"
|
||||
run: |
|
||||
ulimit -c unlimited
|
||||
ready=$(grep -oE 'kMGPipeP5eRunAheadReady = (true|false)' "${GITHUB_WORKSPACE}/MobileGL/MG_Backend/Init.cpp" | head -1 | awk '{print $3}')
|
||||
echo "kMGPipeP5eRunAheadReady = ${ready}"
|
||||
rc=0
|
||||
ctest -L integration-split --no-tests=error -j 4 > "${RUNNER_TEMP}/strict-split.txt" 2>&1 || rc=$?
|
||||
cat "${RUNNER_TEMP}/strict-split.txt" | tail -5
|
||||
if [ "${rc}" -eq 0 ]; then
|
||||
echo "::error::integration-split under MOBILEGL_IPC_STRICT_ERRORS=1 went GREEN - the object-class residual pulls (P3b/P4b/P7) are still pinned, so strict must abort every drawing scenario. If the object-class rows have just retired, rewrite this step as the green lane it then becomes."
|
||||
exit 1
|
||||
fi
|
||||
failed=$(grep -cE '^ *[0-9]+ - .* \(.*(Failed|Subprocess aborted).*\)' "${RUNNER_TEMP}/strict-split.txt" || true)
|
||||
# Every entry that RAN (did not skip) must have failed; entries skipped by a missing
|
||||
# GPU or an unmet pre-flight are reported, not counted.
|
||||
ran=$(grep -cE 'tests passed, [0-9]+ tests failed out of [0-9]+' "${RUNNER_TEMP}/strict-split.txt" || true)
|
||||
tail -5 "${RUNNER_TEMP}/strict-split.txt"
|
||||
echo "strict run: rc=${rc}"
|
||||
# The strict marker, from the split entries' own private logs: the run's red must be
|
||||
# the strict Fatal and not a bring-up defect.
|
||||
marker='BARRIER-PULLED, MOBILEGL_IPC_STRICT_ERRORS=1'
|
||||
hits=$(grep -rl "${marker}" MobileGL/MG_IntegrationTest/split-logs/ 2>/dev/null | wc -l)
|
||||
if [ "${hits}" -lt 1 ]; then
|
||||
echo "::error::no split entry's private log carries the strict marker '${marker}' - the lane went red without the strict Fatal firing, which is a defect, not the control"
|
||||
|
||||
if [ "${ready}" != "true" ]; then
|
||||
# ---- the pre-flip arm, unchanged from P5c ----
|
||||
if [ "${rc}" -eq 0 ]; then
|
||||
echo "::error::integration-split under MOBILEGL_IPC_STRICT_ERRORS=1 went GREEN while kMGPipeP5eRunAheadReady is false - the object-class residual pulls (P3b/P4b/P7) are still pinned, so strict must abort every drawing scenario. If P5e has just landed, flip that constant in the same commit."
|
||||
exit 1
|
||||
fi
|
||||
marker='BARRIER-PULLED, MOBILEGL_IPC_STRICT_ERRORS=1'
|
||||
hits=$(grep -rl "${marker}" MobileGL/MG_IntegrationTest/split-logs/ 2>/dev/null | wc -l)
|
||||
if [ "${hits}" -lt 1 ]; then
|
||||
echo "::error::no split entry's private log carries the strict marker '${marker}' - the lane went red without the strict Fatal firing, which is a defect, not the control"
|
||||
exit 1
|
||||
fi
|
||||
echo "integration-split under strict is red by design; ${hits} private log(s) carry the strict marker"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# ---- the post-flip arm: HARD GREEN, with §7's allowlist ----
|
||||
#
|
||||
# EVERY ENTRY MUST COMPLETE. An abort here is either an unbarriered pull (§3.3's
|
||||
# unconditional Fatal, which is a missed migration) or a barriered row that is not on
|
||||
# the list below, and both are the lane's job to catch.
|
||||
if [ "${rc}" -ne 0 ]; then
|
||||
echo "::error::integration-split under MOBILEGL_IPC_STRICT_ERRORS=1 is RED on a run-ahead server. CONTRACT-P5E §7 makes this lane a hard green gate: an unbarriered record's pull aborts whatever the knob says, so a red here names a field and a verb in the failing entry's private log."
|
||||
grep -hoE 'Fatal\{UnmigratedPipeInput, "[^"]*"\}' MobileGL/MG_IntegrationTest/split-logs/*.log 2>/dev/null | sort | uniq -c | sort -rn | head -20
|
||||
exit 1
|
||||
fi
|
||||
echo "integration-split under strict is red by design; ${hits} private log(s) carry the strict marker"
|
||||
|
||||
# THE ADMITTED MARKERS, `<field>@<verb>`, AND NOTHING ELSE. These are the barriered
|
||||
# rows of §2.2 - the ones whose apply still pulls a row, and whose legality is the
|
||||
# client's own wait (ruling 4). Each line names the package that retires it; a row
|
||||
# that leaves this list leaves it by deletion, never by widening.
|
||||
# readbacks / the pack PBO ......... P8/P9 (read_pixels, get_texture_image)
|
||||
# CopyTex endpoint ................. tx2's trailing item
|
||||
# GenerateMipmap ................... tx2, until the VerbMipRes arm lands
|
||||
# set_storage_block_binding ........ pg's trailing item (by MGPStorageBlockBinding::ShaderCso)
|
||||
# XFB ............................... P3b/P4b/P9 (escalation (i) keeps the span lockstep)
|
||||
# resource_copy_region's names ..... the declared P5b debt
|
||||
printf '%s\n' \
|
||||
'GetTextureUnitObject@ReadPixels' \
|
||||
'GetTextureUnitObject@GetTextureImage' \
|
||||
'GetTextureUnitObject@CopyTexImage2D' \
|
||||
'GetTextureUnitObject@GenerateMipmap' \
|
||||
'GetBufferBindingSlot@ReadPixels' \
|
||||
'GetBufferBindingSlot@GetTextureImage' \
|
||||
'GetProgramObject@ShaderStorageBlockBinding' \
|
||||
'ValidateProgramName@ShaderStorageBlockBinding' \
|
||||
'GetTextureObject@CopyImageSubData' \
|
||||
'GetTransformFeedbackProgram@BeginTransformFeedback' \
|
||||
'GetTransformFeedbackProgram@EndTransformFeedback' \
|
||||
'GetBufferBindingPoint@BeginTransformFeedback' \
|
||||
'GetBufferBindingPoint@EndTransformFeedback' \
|
||||
> "${RUNNER_TEMP}/allowed.txt"
|
||||
|
||||
grep -rhoE '\[BARRIER-PULLED[^]]*\]' MobileGL/MG_IntegrationTest/split-logs/ 2>/dev/null > "${RUNNER_TEMP}/markers-raw.txt" || true
|
||||
grep -rhoE 'Fatal\{UnmigratedPipeInput, "[^"]*"\}' MobileGL/MG_IntegrationTest/split-logs/ 2>/dev/null \
|
||||
| sed -E 's/.*"([^"]*)".*/\1/' | sort -u > "${RUNNER_TEMP}/markers.txt" || true
|
||||
bad=$(comm -23 "${RUNNER_TEMP}/markers.txt" <(sort -u "${RUNNER_TEMP}/allowed.txt") || true)
|
||||
if [ -n "${bad}" ]; then
|
||||
echo "::error::a BARRIER-PULLED marker outside CONTRACT-P5E §7's allowlist appeared on a run-ahead server. Each one is a field an apply still reads out of client memory:"
|
||||
echo "${bad}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# `rsp` = 0 ON UNBARRIERED RECORDS, in every summary that printed it. A non-zero count
|
||||
# would be an abort that did not fire, which is the one failure §3.3's unconditional
|
||||
# arm cannot report by itself.
|
||||
if grep -rhoE 'rsp=[0-9]+' MobileGL/MG_IntegrationTest/split-logs/ 2>/dev/null | grep -qvE 'rsp=0$'; then
|
||||
echo "::warning::a scenario summary reports a non-zero rsp; under P5e every remaining pull is a BARRIERED row on the allowlist above, and the count belongs in the trailing inventory rather than in this lane"
|
||||
fi
|
||||
echo "integration-split under strict is GREEN with only the §7 allowlist admitted ($(wc -l < "${RUNNER_TEMP}/markers.txt") distinct marker(s))"
|
||||
|
||||
- name: Upload strict lane logs
|
||||
if: always()
|
||||
|
||||
+32
-3
@@ -322,9 +322,9 @@ namespace MobileGL::MG_Config {
|
||||
// 0 - the only shipped value until the migration lands - is "pull everything",
|
||||
// i.e. exactly today's behaviour, and is the default of a PULL build, where the
|
||||
// knob is meaningless anyway. A PUSH build defaults to every subsystem migrated so
|
||||
// far (MG_Pipe::kMGPipeSubsystemsMigratedAtP4a), so MOBILEGL_PIPE_PUSH=0 in the
|
||||
// environment is the all-pull control and 0x1ff (kMGPipeSubsystemsMigratedAtP3a) is
|
||||
// the "everything before P4a" control P4a's A/B is run against - each phase's
|
||||
// far (MG_Pipe::kMGPipeSubsystemsMigratedAtP5e = 0x3fff), so MOBILEGL_PIPE_PUSH=0 in
|
||||
// the environment is the all-pull control and 0x1fff (kMGPipeSubsystemsMigratedAtP4a)
|
||||
// is the "everything before P5e" control P5e's A/B is run against - each phase's
|
||||
// constant survives as the next phase's control, which is why none of them is ever
|
||||
// edited. Accepts decimal or 0x-prefixed hex, and operators pass it as hex, so the
|
||||
// bits are listed here (MG_Pipe/MGPipe.h owns them):
|
||||
@@ -342,6 +342,9 @@ namespace MobileGL::MG_Config {
|
||||
// 0x800 samplers (sampler CSO, sampler view, set_sampler_views /
|
||||
// bind_sampler_states / set_shader_images) - requires 0x400
|
||||
// 0x1000 programs (shader CSO, set_draw/dispatch_program, global constants)
|
||||
// 0x2000 buffer binding points (set_shader_buffers, the three indexed binding-point
|
||||
// classes and the dirty bits 15/16/17) - requires 0x80
|
||||
// (every MGPBufferRange::Res names a Buffer handle; P5e)
|
||||
// A dependency that is not met is REFUSED with one ERROR naming both bits and the
|
||||
// family runs its legacy arm; it is never half-run.
|
||||
// 1<<63 NOT a subsystem, a BEHAVIOUR: turn OFF client-side content addressing of
|
||||
@@ -502,6 +505,32 @@ namespace MobileGL::MG_Config {
|
||||
// GLContext by the client's residual fill and a free-running queue lets the server
|
||||
// read a FUTURE value of them.
|
||||
Uint32 VerbBarrier = 1;
|
||||
// MOBILEGL_IPC_RUN_AHEAD (P5e, MG_Remote/CONTRACT-P5E.md §1): 1 = after publishing an
|
||||
// UNBARRIERED record the client returns immediately instead of waiting for its apply.
|
||||
// It is one half of a conjunction and never a switch on its own - the client arms
|
||||
// run-ahead only when the server also publishes kCapRunAheadApply, so on Magma, and on
|
||||
// Espryt before the P5e integration commit, 1 means exactly what 0 means and logs once
|
||||
// saying so.
|
||||
//
|
||||
// 0 IS THE A/B CONTROL AND NOT A NEGATIVE ONE: the server code, the fill decision and
|
||||
// every record are identical on both arms, and the only difference is whether the
|
||||
// client waits. That is what makes "is the picture the same" a question about the wait
|
||||
// rule alone. MOBILEGL_IPC_VERB_BARRIER=0 keeps its own meaning and stays the
|
||||
// lockstep arm's negative control; under run-ahead it is the one that must go red, at
|
||||
// the first barriered row's stale pull.
|
||||
//
|
||||
// Forced to 0 by MOBILEGL_PIPE_VERIFY, beside BatchWaits: the comparator needs a
|
||||
// client-filled gPipeInputs block for every verb, and run-ahead is precisely the
|
||||
// arm that stops filling it.
|
||||
Uint32 RunAhead = 1;
|
||||
// MOBILEGL_IPC_PRESENT_CREDIT (P5e, ruling 4 / ID-92): how many presents the client may
|
||||
// have in flight before it waits for a swap to come back. 1 = the client publishes
|
||||
// frame N+1's records while the server applies and swaps frame N - one frame of
|
||||
// overlap, at most one frame of added latency - and the CREDIT, never the ring's bytes,
|
||||
// is what paces a run-ahead client. 2 is a device MEASUREMENT arm: it buys no CPU on a
|
||||
// client that is already CPU-bound and costs a frame of latency, which is why the
|
||||
// default is 1 and not "as deep as the ring".
|
||||
Uint32 PresentCredit = 1;
|
||||
// MOBILEGL_IPC_STRICT_ERRORS: promote a BARRIER-PULLED field read - and, in a split
|
||||
// build, the seven sticky forwards that are otherwise exempt - from "count it in
|
||||
// rsp" to Fatal (R-7.3).
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "Config.h"
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// For kMGPipeSubsystemsMigratedAtP4a, the push build's PipePush default (the P2 and P3a
|
||||
// For kMGPipeSubsystemsMigratedAtP5e, the push build's PipePush default (the P2, P3a and P4a
|
||||
// constants beside it are the phase-by-phase controls, not the default). Push-only, so the
|
||||
// pull build's translation unit is unchanged.
|
||||
#include <MG_Pipe/MGPipe.h>
|
||||
@@ -263,7 +263,7 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
// environment is the all-subsystems-pull control that reproduces P1 exactly, and
|
||||
// kMGPipeSubsystemsMigratedAtP3a (0x1ff) is the phase-by-phase control - P4a's four
|
||||
// subsystems off, everything P3a landed still on.
|
||||
features.PipePush = QueryEnvUint64("MOBILEGL_PIPE_PUSH", MG_Pipe::kMGPipeSubsystemsMigratedAtP4a);
|
||||
features.PipePush = QueryEnvUint64("MOBILEGL_PIPE_PUSH", MG_Pipe::kMGPipeSubsystemsMigratedAtP5e);
|
||||
#else
|
||||
// Meaningless in a pull build: there is nothing to push. Config.h documents 0 as
|
||||
// "pull everything" and that stays literally true.
|
||||
@@ -379,6 +379,17 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
// point of use, which is where the "P11" in the message belongs.
|
||||
ipc.AdoptTier = QueryEnvUint32("MOBILEGL_IPC_ADOPT_TIER", 2, 0, 2);
|
||||
ipc.VerbBarrier = QueryEnvUint32("MOBILEGL_IPC_VERB_BARRIER", 1, 0, 1);
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §1). The wait rule's A/B, parsed here like every
|
||||
// other IPC knob and armed only where the server publishes kCapRunAheadApply.
|
||||
ipc.RunAhead = QueryEnvUint32("MOBILEGL_IPC_RUN_AHEAD", 1, 0, 1);
|
||||
// ... and forced OFF by the verify harness for BatchWaits' reason, one step further:
|
||||
// run-ahead's whole point is that the client stops filling gPipeInputs for an
|
||||
// unbarriered record, and the comparator has nothing left to compare when it does.
|
||||
if (MG_Config::Features.PipeVerify) ipc.RunAhead = 0;
|
||||
// The present credit (ruling 4). 1 is one frame of overlap; 8 is the ceiling because a
|
||||
// deeper queue buys nothing on a CPU-bound client and pays for it in latency. 0 is NOT
|
||||
// admitted: a credit of zero would mean "publish no present at all".
|
||||
ipc.PresentCredit = QueryEnvUint32("MOBILEGL_IPC_PRESENT_CREDIT", 1, 1, 8);
|
||||
ipc.StrictErrors = QueryEnvFlag("MOBILEGL_IPC_STRICT_ERRORS");
|
||||
ipc.Audit = QueryEnvFlag("MOBILEGL_IPC_AUDIT");
|
||||
QueryEnvVariable("MOBILEGL_IPC_SERVER_AFFINITY", ipc.ServerAffinity, "auto");
|
||||
@@ -387,9 +398,11 @@ namespace MobileGL::MG_ConfigLoader {
|
||||
// One line, on the arm where these numbers decide behaviour, because every one of
|
||||
// them is a number a bug report has to quote.
|
||||
MGLOG_I("Config: IPC ring=%uMiB stage=%uMiB spin=%uus persistent-block=%uKiB "
|
||||
"adopt-tier=%u verb-barrier=%u strict=%d audit=%d affinity='%s'",
|
||||
"adopt-tier=%u verb-barrier=%u run-ahead=%u present-credit=%u strict=%d "
|
||||
"audit=%d affinity='%s'",
|
||||
ipc.RingMb, ipc.StageMb, ipc.SpinUs, ipc.PersistentBlockKb, ipc.AdoptTier,
|
||||
ipc.VerbBarrier, static_cast<int>(ipc.StrictErrors), static_cast<int>(ipc.Audit),
|
||||
ipc.VerbBarrier, ipc.RunAhead, ipc.PresentCredit,
|
||||
static_cast<int>(ipc.StrictErrors), static_cast<int>(ipc.Audit),
|
||||
ipc.ServerAffinity.c_str());
|
||||
if (ipc.VerbBarrier == 0) {
|
||||
MGLOG_W("Config: MOBILEGL_IPC_VERB_BARRIER=0 is the R-1 NEGATIVE CONTROL and is "
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -467,10 +467,15 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return m_slotTable.LiveGenAt(slot);
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5c (hd): the two halves of SlotTables.h's state note, forwarded. A caller holding
|
||||
// both the record's handle and the frontend object (the record-driven sync) notes the
|
||||
// object so a later handle-only resolution can reach it without the client allocator.
|
||||
//
|
||||
// P5e (id): under MOBILEGL_PIPE_PUSH rather than MOBILEGL_BUILD_DISAGGREGATED, because
|
||||
// the re-typed ForEachLive's caller resolves its object through StateForHandle in the
|
||||
// push-monolith build too. Each half is a named Fatal from an unbarriered apply
|
||||
// (SlotTables.h); on the legacy arm there is no note and StateForHandle answers null,
|
||||
// which is the answer the legacy walk's own weak_ptr test already gives.
|
||||
void NoteStateForHandle(MG_Pipe::MGPipeHandle handle, const StatePtr& stateObj) {
|
||||
if (EsprytSlotTablesEnabled()) {
|
||||
m_slotTable.NoteStateForHandle(handle, stateObj);
|
||||
@@ -482,7 +487,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
// NO ReleaseByHandle HERE THROUGH P5, AND THAT WAS A DECISION (review M-4). The death
|
||||
// half of GetOrCreateByHandle existed only for a kind whose announcement is its own
|
||||
@@ -527,23 +531,21 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return false;
|
||||
}
|
||||
|
||||
// fn(const StatePtr& state, const BackendPtr& twin) over every live entry. The legacy
|
||||
// begin()/end() handed out the map key, i.e. the raw frontend address - exactly the
|
||||
// identity the backend must stop reading - and handed it out for entries whose state
|
||||
// object had already died, so the one caller had to test stateRef.expired() itself
|
||||
// before dereferencing it. Here the state object arrives as a strong reference.
|
||||
// P5e (id), CONTRACT-P5E §4.1: fn(MGPipeHandle, const BackendPtr& twin) over every live
|
||||
// entry of the HANDLE ARM, and of that arm only.
|
||||
//
|
||||
// IT NO LONGER SERVES THE LEGACY ARM, and that is a narrowing rather than a loss. The
|
||||
// legacy map is keyed by the raw frontend address and has no handle to hand over - a
|
||||
// synthesised null one would be a lie the callee could not tell from a real answer -
|
||||
// and its one caller (ScopedDetachedTextureFramebufferAttachments) has always had its
|
||||
// own `#if MOBILEGL_PIPE_LEGACY_MEMOS` begin()/end() walk beside the call, because the
|
||||
// legacy entry needs its stateRef.expired() test done by hand. So the arm check here
|
||||
// was answering a question no caller asked, and leaving it would have meant inventing a
|
||||
// second signature for a walk the P5e rule exists to delete.
|
||||
template <typename Fn>
|
||||
void ForEachLive(Fn&& fn) const {
|
||||
if (EsprytSlotTablesEnabled()) {
|
||||
m_slotTable.ForEachLive(fn);
|
||||
return;
|
||||
}
|
||||
for (const auto& [stateKey, entry] : m_entries) {
|
||||
(void)stateKey;
|
||||
if (!entry.backend) continue;
|
||||
const StatePtr state = entry.stateRef.lock();
|
||||
if (!state) continue;
|
||||
fn(state, entry.backend);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -694,6 +696,26 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (pg), CONTRACT-P5E.md §5.8 / ruling 1 (ID-81): THE HANDLE ARM'S SELECTOR for the
|
||||
// program family. Transport AND the family bit, in that order and both required:
|
||||
//
|
||||
// * `Transport != Monolith` because the push-MONOLITH build keeps its frontend arms token
|
||||
// for token - the verify comparator needs them, and it is what makes
|
||||
// MOBILEGL_IPC_RUN_AHEAD=0 a pure wait-rule A/B on identical server code rather than a
|
||||
// comparison of two different backends;
|
||||
// * the family bit because the A/B that switches this family off has to switch off the
|
||||
// arm too, not only the emission - a server reading records nobody sends would draw
|
||||
// with no program at all.
|
||||
//
|
||||
// NOT LATCHED, unlike the four above: Transport is configuration read once at bring-up and
|
||||
// ProgramSubsystemEnabled() already latches, so this is one load and one test, and a latch
|
||||
// here would only hide which half answered.
|
||||
inline Bool ProgramHandleArm() {
|
||||
return MG_Config::Transport != MG_Config::TransportMode::Monolith && ProgramSubsystemEnabled();
|
||||
}
|
||||
#endif
|
||||
|
||||
// ---- P4a: what the twins read INSTEAD of the frontend object ----
|
||||
//
|
||||
// One reader per record kind, all const, all null-on-miss, and all bounds-checked against
|
||||
@@ -722,6 +744,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// composite: this reader hides the split behind one lookup, exactly as the wire does.
|
||||
const MG_Pipe::MGPipeShaderCsoRecord* PipeShaderCsoRecordForHandle(MG_Pipe::MGPipeHandle cso);
|
||||
|
||||
// P5e (fb): the texture's own TARGET, from its descriptor. The image-unit bind needs it
|
||||
// (glBindImageTexture's layered/format rules are per target) and MGPImageView has no room
|
||||
// for it - 24 bytes, no pad - so it is read off the resource record instead of being added
|
||||
// to the wire. TextureTarget::Unknown when the handle names no live texture record, which
|
||||
// every caller treats as "decline", never as a default.
|
||||
MobileGL::TextureTarget PipeTextureTargetForHandle(MG_Pipe::MGPipeHandle res);
|
||||
|
||||
// The pending-upload entry the applier accumulated for this (uploadTarget, level) of this
|
||||
// texture record, or null (D-D5). SERVER-SIDE STATE, and that is the whole point: the
|
||||
// client clears its own dirty flags at EMISSION for the levels the applier accepted, while
|
||||
@@ -787,6 +816,52 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// AcquirePersistentMap or (FLUSH_EXPLICIT) publish only via FlushMappedRange.
|
||||
Uint64 CurrentBufferMutationEpoch();
|
||||
void BumpBufferMutationEpoch();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5e (vi), CONTRACT-P5E §5.1's first pin: how many bumps came from a thread other than
|
||||
// the apply thread WHILE an apply thread was running, under a live transport. The
|
||||
// record arm's clean gate stamps this counter and skips its probes while the stamp
|
||||
// holds, so "who may move it" is a question the phase has to answer with a number
|
||||
// rather than with a reading of the call graph. Expected 0 for any session; the bump
|
||||
// itself is Fatal on that path under the strict lane, and the answer at this head is
|
||||
// that the only non-apply-thread bump in the tree happens at bring-up, BEFORE the apply
|
||||
// thread exists (BackendObject_DirectGLES::Initialize's RegisterBufferBackendOps), and
|
||||
// is therefore not counted here.
|
||||
Uint64 BufferMutationEpochBumpsOffTheApplyThread();
|
||||
|
||||
// ---- P5e (vi): THE TWO SOURCE DECISIONS OF THE DRAW'S BUFFER SYNC ------------------
|
||||
//
|
||||
// CONTRACT-P5E §5.1 is, for this family, two substitutions and nothing else: the
|
||||
// attribute walk's buffer set comes from st.VertexBuffers[Start..+Count) instead of the
|
||||
// frontend VAO's GetAllAttributes(), and the index buffer comes from st.IndexBuffer.Res
|
||||
// + IndexBufferSerial instead of the VAO's element slot. Both are lifted out of
|
||||
// SyncNeccessaryBuffers' arms and given names HERE, and the reason is the red-once:
|
||||
// these take the applier state AND NOTHING ELSE, so the only way to revert the
|
||||
// substitution is to put a frontend read back inside one of them, and
|
||||
// MG_Test/SanityTest.cpp drives exactly these two with a frontend VAO deliberately
|
||||
// pointing somewhere else. A test that drove a copy of the decision instead would stay
|
||||
// green through that revert, which is the fake-green ID-102 names.
|
||||
//
|
||||
// The ensure, the memo and the clean probe stay where they are: they need an ES context
|
||||
// and are the integration lane's to exercise.
|
||||
struct DrawVertexBufferRequest {
|
||||
MG_Pipe::MGPipeHandle Res = MG_Pipe::kMGPipeNullHandle;
|
||||
// MGPVertexBuffer::BindingIndex, carried for the memo's diagnostics only.
|
||||
Uint32 BindingIndex = 0;
|
||||
};
|
||||
// The DISTINCT buffers the draw's enabled attributes fetch from, deduped on {slot, gen}.
|
||||
// A null Res is skipped: it is a disabled slot below the window's high-water mark, or a
|
||||
// client-memory array whose bytes have no store to ensure (P8 stages those).
|
||||
Uint ResolveDrawVertexBuffersFromRecord(const MG_Pipe::MGPipeApplierState& st,
|
||||
DrawVertexBufferRequest* out, Uint capacity);
|
||||
|
||||
struct DrawIndexBufferRequest {
|
||||
MG_Pipe::MGPipeHandle Res = MG_Pipe::kMGPipeNullHandle;
|
||||
// IndexBufferSerial, which joins the identity compare because this arm has no live
|
||||
// frontend slot to re-read - see ResolvedDrawBuffers::iboSerial.
|
||||
Uint64 Serial = 0;
|
||||
};
|
||||
DrawIndexBufferRequest ResolveDrawIndexBufferFromRecord(const MG_Pipe::MGPipeApplierState& st);
|
||||
#endif
|
||||
|
||||
// The DirectGLES storage behind one frontend buffer. Owned (refcounted) by
|
||||
// the frontend BufferObject; immediate BufferBackendOps keep it current, so
|
||||
@@ -1019,6 +1094,38 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Uint CurrentBufferContextGeneration();
|
||||
#endif
|
||||
|
||||
// P5e (vi), CONTRACT-P5E §5.1 + §5.8 (ruling 1 / ID-81): THE ARM SELECTOR for this
|
||||
// family, and it is a conjunction on purpose.
|
||||
//
|
||||
// Transport != Monolith the record arm exists because there is no frontend VAO on
|
||||
// this side of a real split. Under Transport=monolith the
|
||||
// push build keeps its frontend arms token for token - that
|
||||
// is what the verify comparator compares against, and what
|
||||
// makes MOBILEGL_IPC_RUN_AHEAD=0 a pure wait-rule A/B on
|
||||
// identical server code rather than an arm swap.
|
||||
// the family bit `0x0ff` (bit 7 on, bit 8 off) is a supported A/B and must
|
||||
// keep running the legacy vertex-input walk; the bit is
|
||||
// already the gate the rest of this family reads.
|
||||
//
|
||||
// It is NOT gated on run-ahead. The records carry the whole family either way, so a
|
||||
// lockstep split session reads them too and the wait rule changes nothing here - which
|
||||
// is the only reason ra can flip one constant at the end of the phase and change no
|
||||
// backend code at all.
|
||||
//
|
||||
// P5e (mv): it lives in the HEADER rather than in DirectGLES.cpp because the multi-draw
|
||||
// path is a second translation unit that has to select the SAME arm - and the addendum's
|
||||
// rule is that a site states the transport test it relies on, which a copy of the
|
||||
// conjunction in MultiDraw.cpp would satisfy in letter while giving the family two
|
||||
// selectors that can drift apart. One definition, spelled at every site that reads it.
|
||||
inline Bool VertexInputReadsRecords() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
return MG_Config::Transport != MG_Config::TransportMode::Monolith &&
|
||||
VertexInputSubsystemEnabled();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Registered as the frontend's BufferBackendOps at backend init and on
|
||||
// every MakeCurrent (the ES context can be destroyed and recreated, e.g.
|
||||
// by the trace replayer's probe context).
|
||||
@@ -1201,6 +1308,16 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BackendVertexArrayObject();
|
||||
~BackendVertexArrayObject();
|
||||
void SyncToBackend(const SharedPtr<MG_State::GLState::VertexArrayObject>& stateVAOObject);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// PUBLIC AS OF P5e (vi), and the move is the point rather than a convenience: with
|
||||
// a live transport there is no frontend VAO on this side to hand to the overload
|
||||
// above, so VertexArrayImpl::SyncCurrentVAOFromRecords calls this ENTRY directly
|
||||
// instead of passing a null SharedPtr into a function whose signature promises one.
|
||||
// CONTRACT-P5E §4.1's rule ("the object parameter is deleted from the transport
|
||||
// overload, not defaulted to null") is what this obeys. The body is unchanged and
|
||||
// was already record-only - it is this family's existence proof (scout S1 §2).
|
||||
void SyncToBackendFromApplier();
|
||||
#endif
|
||||
void SyncClientSideAttributesForDrawArrays(
|
||||
const SharedPtr<MG_State::GLState::VertexArrayObject>& stateVAOObject, GLint first, GLsizei count);
|
||||
Uint GetBackendVertexArrayId() const { return m_backendVAOId; }
|
||||
@@ -1220,6 +1337,15 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// and is not covered by the config version).
|
||||
struct ResolvedDrawBuffers {
|
||||
struct Entry {
|
||||
// MONOLITH GLUE AFTER P5e (vi), CONTRACT-P5E §5.1: the RECORD arm
|
||||
// (SyncVaoAttributeBuffersByRecord) never writes this and never reads it -
|
||||
// it stores nullptr and hands nullptr to IsBufferDrawCleanByHandle, whose
|
||||
// frontend question is itself monolith-only (Managers.cpp's
|
||||
// askTheObjectWhetherItIsMapped). It stays DECLARED because the legacy arm
|
||||
// and the push-monolith arm still key on it and because moving it would
|
||||
// move sizeof(ResolvedDrawBuffers) in the pull build (G1). That also
|
||||
// retires, on the split arm, the dangling-pointer hazard the note below
|
||||
// has to state.
|
||||
MG_State::GLState::BufferObject* frontend = nullptr;
|
||||
// A RAW TWIN POINTER, AND IT MAY DANGLE - the invariant that makes that safe
|
||||
// is stated here rather than left in the two callers (espryt-v3 §8, m8).
|
||||
@@ -1238,6 +1364,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// owning a reference from a per-draw memo - is what keeps a dead driver
|
||||
// buffer alive, which is the leak class P2's death notice exists to remove.
|
||||
BufferImpl::GLESBufferResource* resource = nullptr;
|
||||
// P5e (vi): on the record arm this is the BINDING index the applier's
|
||||
// vertex-buffer entry carried (MGPVertexBuffer::BindingIndex, which for
|
||||
// Espryt's resolved attributes IS the attribute index) and it is kept for
|
||||
// DIAGNOSTICS only - that arm's repair re-ensures by `handle`, never by
|
||||
// walking back into a frontend attribute slot.
|
||||
Uint8 attribIndex = 0;
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P3a re-key: the entry's identity on the handle arm. A {slot, gen} cannot
|
||||
@@ -1264,6 +1395,18 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Uint64 elementsSerial = 0;
|
||||
Uint64 buffersSerial = 0;
|
||||
MG_Pipe::MGPipeHandle iboHandle = MG_Pipe::kMGPipeNullHandle;
|
||||
// P5e (vi), CONTRACT-P5E §5.1: the index slot's own server-owned serial, and
|
||||
// the reason it has to join the identity compare is the one D5 gives for the
|
||||
// slot version - the ELEMENT BUFFER IS NOT PART OF THE CONFIGURATION. The
|
||||
// legacy and push-monolith arms re-read the frontend slot on every indexed
|
||||
// draw and so notice a rebind for free; the record arm reads nothing, so
|
||||
// "the applier was told about this index buffer again" has to be a value in
|
||||
// the key. A rebind of the SAME handle still moves IndexBufferSerial
|
||||
// (MGPipeApplySetIndexBuffer bumps unconditionally), which is exactly the
|
||||
// case an identity-only compare would call a hit: a client that respecified
|
||||
// the store behind an unchanged {slot, gen} re-emits set_index_buffer and
|
||||
// this is what re-opens the ensure.
|
||||
Uint64 iboSerial = 0;
|
||||
#endif
|
||||
// Buffer-mutation epoch (BufferImpl::CurrentBufferMutationEpoch) at which
|
||||
// the LAST probe pass found every entry / the IBO clean; 0 = not stamped
|
||||
@@ -1288,6 +1431,18 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Uint32 configVersion = 0;
|
||||
Uint32 activeMask = 0;
|
||||
Uint32 pendingMask = 0;
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (vi), CONTRACT-P5E §5.1: the record arm's half of the key. It replaces
|
||||
// the frontend VAO's configuration version with the bound vertex-elements CSO's
|
||||
// identity and its server-owned content serial, and the substitution is
|
||||
// STRICTLY STRONGER rather than merely equivalent: GetConfigVersion() is a
|
||||
// wrapping Uint16-derived counter shared by every VAO, while every
|
||||
// configuration change re-creates the record on the same handle and ++s
|
||||
// ContentSerial (PipeApply.h's MGPipeVertexElementsRecord), and a DIFFERENT VAO
|
||||
// is a different {slot, gen} rather than another value of the same counter.
|
||||
MG_Pipe::MGPipeHandle elementsHandle = MG_Pipe::kMGPipeNullHandle;
|
||||
Uint64 elementsSerial = 0;
|
||||
#endif
|
||||
};
|
||||
PendingAttribValueMask& GetPendingAttribValueMaskMemo() { return m_pendingAttribValueMask; }
|
||||
|
||||
@@ -1310,8 +1465,8 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// the applier's records - the bound CSO's two views, the vertex-buffer set, the
|
||||
// index buffer and the resolved fetch base instance - so it takes no argument at
|
||||
// all and touches no frontend type. The legacy arm above it is unchanged and both
|
||||
// compile in every push build (ARCHITECTURE.md 9.6).
|
||||
void SyncToBackendFromApplier();
|
||||
// compile in every push build (ARCHITECTURE.md 9.6). DECLARED IN THE PUBLIC SECTION
|
||||
// as of P5e (vi) - see the note there.
|
||||
// Same narrowing, same memo, same Adreno disable; the source bytes are the shadow
|
||||
// base the resource call carried and the memo key is the buffer's {slot, gen}.
|
||||
Bool SyncFloat64AttributeAsFloat32ByHandle(Uint attribIndex, const MGPVertexAttribWire& attrib,
|
||||
@@ -1423,6 +1578,24 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
extern TwinRegistry<MG_State::GLState::VertexArrayObject, BackendVertexArrayObject, MG_Pipe::MGPipeKind::VertexElementsCso>
|
||||
g_backendVertexArrayObjects;
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (id), CONTRACT-P5E §4.1 / §4.2: THE VAO TWIN, RESOLVED BY THE HANDLE THE RECORD
|
||||
// CARRIED - `MGPipeApplierState::BoundVertexElements` at a draw, never
|
||||
// `Find(vao.get())`. One of the three resolvers the identity package lands so the
|
||||
// per-family packages have a by-handle door from day one; SamplerImpl's
|
||||
// ResolveSamplerCsoTwin is the shape all four share.
|
||||
//
|
||||
// WHAT IT DOES AND, AS IMPORTANTLY, WHAT IT DOES NOT. Record first (a handle with no
|
||||
// applier record is a seam defect, and adopting a slot for it would leave a twin that
|
||||
// syncs nothing), then AdoptTwinByHandle, then a twin if the slot is empty. It never
|
||||
// touches a frontend object and never probes the client's slot allocator - those two
|
||||
// absences ARE the deliverable - and it does not SYNC: which serials gate a VAO sync,
|
||||
// and what the sync reads, is the vi package's, and a resolver that synced would have
|
||||
// to know. Null, loudly, for a handle with no record or a generation behind the live
|
||||
// twin's; null silently for the null handle.
|
||||
BackendVertexArrayObject* ResolveVaoTwin(MG_Pipe::MGPipeHandle elements);
|
||||
#endif
|
||||
|
||||
// Shadowed glBindVertexArray: every backend VAO bind goes through here so a
|
||||
// draw's second bind of the same VAO (SyncToBackend, then PrepareForDraw's
|
||||
// re-bind) reaches the driver once. Invalidate whenever the ES context is
|
||||
@@ -1466,6 +1639,22 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// the attribute-offset emulation must stay out of the way. Applied to whatever the
|
||||
// applier stored, so the answer is the same whichever side resolved it first.
|
||||
Bool BackendUsesNativeBaseInstance();
|
||||
|
||||
// ---- P5e SEAM (MG_Remote/CONTRACT-P5E.md §4.2; declared by c0e, bodied by id/vi) ----
|
||||
//
|
||||
// THE VAO TWIN, RESOLVED FROM THE HANDLE THE RECORD CARRIED - MGPipeApplierState::
|
||||
// BoundVertexElements - instead of from the frontend VertexArrayObject the draw's
|
||||
// BARRIER_PULLED row hands over. The frontend overload above it stays as the
|
||||
// monolith-glue half, in the shape ResolveSamplerCsoTwin already established for the
|
||||
// sampler CSO family: two overloads, not an #if inside one body, so which arm a caller
|
||||
// is on is visible at the call site.
|
||||
//
|
||||
// It is declared HERE, with a body that aborts by name, because the packages that fill
|
||||
// it in land in parallel worktrees: id rekeys the registry under it, vi moves
|
||||
// PrepareForDraw's call onto it, and neither may edit the other's file. A missing
|
||||
// declaration would make that a merge conflict; a declaration with a quiet body would
|
||||
// make it a null twin and a blank draw.
|
||||
BackendVertexArrayObject* ResolveVaoTwin(MG_Pipe::MGPipeHandle vertexElements);
|
||||
#endif
|
||||
} // namespace VertexArrayImpl
|
||||
|
||||
@@ -1590,6 +1779,14 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BackendTextureObject(const BackendTextureObject&) = delete;
|
||||
BackendTextureObject& operator=(const BackendTextureObject&) = delete;
|
||||
void SyncMipmapsToBackend(const SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e SEAM (declared by c0e, bodied by tx2): the same storage sync keyed on the
|
||||
// texture HANDLE, reading the applier's resource record and the server's staged
|
||||
// store instead of the frontend object's levels and pending uploads. fb's
|
||||
// attachment sync and the image sweep both call it, which is why it is declared
|
||||
// once here rather than twice in two packages' worktrees.
|
||||
void SyncMipmapsToBackendByHandle(MG_Pipe::MGPipeHandle texture);
|
||||
#endif
|
||||
// The storage half of the sync for a texture created by glTextureView. Instead of
|
||||
// allocating storage and replaying uploads, it makes this object's ES name BE a view
|
||||
// of the storage texture's ES name (EXT/OES_texture_view), which is what gives the
|
||||
@@ -1597,6 +1794,26 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// parameter and sampler halves are unchanged and run on this name as on any other.
|
||||
void SyncTextureViewToBackend(const SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject);
|
||||
void StampViewSyncKeys(const SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5e (tx2). THE VIEW ARM UNDER A TRANSPORT, and what it can and cannot answer.
|
||||
//
|
||||
// `Desc.ViewOf` names the storage owner BY HANDLE, so the STEADY question - "is my ES
|
||||
// name still a view of the same storage name" - is answered entirely server-side: sync
|
||||
// the storage twin by handle, compare its id against m_viewSourceBackendTextureId,
|
||||
// stamp the record's Serial. That is the per-draw cost of every already-synced view
|
||||
// and it reads nothing from the client.
|
||||
//
|
||||
// The CREATION of the view is the gap and it is named rather than papered over: the
|
||||
// glTextureView call needs (minLevel, numLevels, minLayer, numLayers) and MGPResourceDesc
|
||||
// carries none of the four - `ViewOf` is the only view field on the wire. So a view whose
|
||||
// ES name has not been made a view YET, or whose storage was re-minted underneath it,
|
||||
// still needs the frontend object and takes it when one is reachable; with no object it
|
||||
// declines LOUDLY and the view samples its own (empty) name. Listed as trailing in the
|
||||
// tx2 report with the wire fields it needs.
|
||||
void SyncTextureViewToBackendByRecord(
|
||||
MG_Pipe::MGPipeHandle res, const MG_Pipe::MGPipeResourceRecord& record,
|
||||
const SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject);
|
||||
#endif
|
||||
// The storage half of the sync for a texture created by glTextureView. Instead of
|
||||
// allocating storage and replaying uploads, it makes this object's ES name BE a view
|
||||
// of the storage texture's ES name (EXT/OES_texture_view), which is what gives the
|
||||
@@ -1610,6 +1827,24 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// re-mint allocates fresh storage and only replays what the shadow still calls dirty.
|
||||
void RequireImageBindableStorage(
|
||||
const SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (tx2), CONTRACT-P5E §5.2 / G-S2-5. THE SAME TRANSITION WITH NO FRONTEND
|
||||
// ARGUMENT, and with the re-dirty NAMED AT THE ENTRY instead of three frames deep.
|
||||
//
|
||||
// The frontend overload's whole second half is the re-dirty: it walks the CLIENT's
|
||||
// level shadows to re-arm every level the widened carrier owes. A server has no
|
||||
// client address space to walk, so under a transport that half is not "not migrated
|
||||
// yet", it is not expressible - ImageBindableHint is the prevention (a texture that
|
||||
// has ever been image-bound is allocated in the carrier from the start) and P9 owns
|
||||
// the pull. The refusal is raised here, at the entry, where the reason can still be
|
||||
// stated, rather than at the MarkStorageDirty guard the loop would reach.
|
||||
//
|
||||
// A texture arriving here with NO backend storage yet pulls nothing - it is simply
|
||||
// allocated image-bindable up front - so that case is not refused, it is the whole
|
||||
// point of the hint.
|
||||
void RequireImageBindableStorageByHandle(MG_Pipe::MGPipeHandle res,
|
||||
const MG_Pipe::MGPipeResourceRecord& record);
|
||||
#endif
|
||||
// Whether this texture's ES storage was minted in an image carrier rather than in the
|
||||
// frontend format's own layout - the readback has to ask, because for a NORMALIZED
|
||||
// carrier the storage is an integer texture holding codes and glGetTexImage still owes
|
||||
@@ -1658,6 +1893,39 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return t->GetStorageType() == TextureStorageType::Mipmap;
|
||||
}
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (tx2), CONTRACT-P5E §5.2. THE SAME AGGREGATE GATE WITH NO FRONTEND OBJECT IN
|
||||
// IT, and it is EXACTLY the conjunction of the three handle-arm prologues' own
|
||||
// early-outs - the relation IsDrawSyncClean states above for the frontend versions,
|
||||
// restated over the server's serials:
|
||||
//
|
||||
// SyncMipmapsToBackend m_isInitialized && m_syncedResourceSerial == Serial
|
||||
// && PendingUploads.empty()
|
||||
// SyncTextureParamsToBackend m_syncedParamsSerial == ParamsSerial
|
||||
// && !Params.ForceResync && !m_forceTextureParamsResync
|
||||
// SyncBuiltinSamplerToBackend m_syncedBuiltinSampler == Params.BuiltinSampler
|
||||
// && m_syncedBuiltinSamplerSerial == that CSO's Serial
|
||||
// && !Params.SamplerResync && !m_forceSamplerResync
|
||||
//
|
||||
// plus the storage-kind restriction the frontend gate carries, answered from
|
||||
// Desc.StorageKind. No new member and no new wire field: every input already
|
||||
// exists, which is the whole reason the memo-HIT path can stop being frontend-bound.
|
||||
//
|
||||
// BOTH SIDES OF THE RESYNC PAIR ARE READ AND NEITHER CLEARS THE OTHER'S (D-E2, now
|
||||
// load-bearing for a GATE rather than only for a push, scout R4). `Params.ForceResync`
|
||||
// and `Params.SamplerResync` are the CLIENT's bits: the server reads them, acts on
|
||||
// them and never writes them back. `m_forceTextureParamsResync`/`m_forceSamplerResync`
|
||||
// are the SERVER's: set by RecreateBackendTexture / RequireImageBindableStorage and
|
||||
// cleared only by the prologue that consumed them. A gate that read one side would
|
||||
// skip the sync the other side is asking for, which for the sampler half is not
|
||||
// mis-filtering but an INCOMPLETE texture sampling (0,0,0,1).
|
||||
//
|
||||
// The contextId / samplingGeneration arguments are GONE: the applier's ContextSerial
|
||||
// and TextureShutterSerial are what the caller's keys already carry.
|
||||
Bool IsDrawSyncCleanByRecord(MG_Pipe::MGPipeHandle res,
|
||||
const MG_Pipe::MGPipeResourceRecord& record) const;
|
||||
#endif
|
||||
|
||||
private:
|
||||
void RecreateBackendTexture();
|
||||
|
||||
@@ -1767,8 +2035,17 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// over, and quietly re-reading the object would hide a missing record behind a
|
||||
// picture that still looks right - which is precisely what the subsystem A/B exists
|
||||
// to expose (MarkBufferGpuWritten's note, P3a).
|
||||
//
|
||||
// P5e (tx2): the HANDLE comes from m_pushedSyncHandle when the caller adopted this
|
||||
// twin by handle, and only then from the client allocator - which is what retires
|
||||
// the two `HandleOf` probes this pair used to make on every feature path. The record
|
||||
// is resolved once by ResolveOwnRecord below and passed to the sampler half rather
|
||||
// than looked up twice.
|
||||
const MG_Pipe::MGPipeResourceRecord* ResolveOwnRecord(
|
||||
const SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject) const;
|
||||
const SamplerParameters* ResolvePushedBuiltinSampler(
|
||||
const SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject);
|
||||
const SharedPtr<MG_State::GLState::ITextureObject>& stateTextureObject,
|
||||
const MG_Pipe::MGPipeResourceRecord* record);
|
||||
// Hands back the whole RECORD rather than its Params, because the parameter push
|
||||
// reads two things from beside them: Desc.InternalFormat, which decides the two
|
||||
// channel-widening swizzle compositions, and Params.BuiltinSampler, which is where
|
||||
@@ -1810,6 +2087,28 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// (two textures sharing one CSO, then one of them diverging).
|
||||
Uint64 m_syncedBuiltinSamplerSerial = 0;
|
||||
MG_Pipe::MGPipeHandle m_syncedBuiltinSampler = MG_Pipe::kMGPipeNullHandle;
|
||||
|
||||
// P5e (tx2), CONTRACT-P5E §4.1's `m_handle` (the m_pushedSyncHandle pattern the
|
||||
// framebuffer twin already carries). THE HANDLE THIS TWIN WAS ADOPTED FOR.
|
||||
//
|
||||
// It is what replaces `g_backendTextureObjects.HandleOf(stateTextureObject.get())`
|
||||
// in the three sync prologues: the by-handle entry point knows the handle before it
|
||||
// knows anything else, so the prologues stop probing the client allocator to
|
||||
// re-derive an answer the caller already had. It is ALSO the arm selector - a twin
|
||||
// with a handle noted syncs from the record and tolerates a null frontend object,
|
||||
// one without it is the monolith-glue half and reads the object as it always did.
|
||||
//
|
||||
// Stamped by SyncTextureToBackendByHandle and SyncMipmapsToBackendByHandle - the two
|
||||
// entries that HAVE a handle - and never cleared afterwards:
|
||||
// a slot recycled to {s, g+1} RESETS the twin (SlotTables.h's forward-Gen rule), so
|
||||
// a stale handle cannot outlive the object it names.
|
||||
MG_Pipe::MGPipeHandle m_pushedSyncHandle = MG_Pipe::kMGPipeNullHandle;
|
||||
|
||||
public:
|
||||
void NotePushedSyncHandle(MG_Pipe::MGPipeHandle res) { m_pushedSyncHandle = res; }
|
||||
MG_Pipe::MGPipeHandle PushedSyncHandle() const { return m_pushedSyncHandle; }
|
||||
|
||||
private:
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1817,9 +2116,42 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
void UnbindTexture(Uint unit, GLenum target);
|
||||
extern TwinRegistry<MG_State::GLState::ITextureObject, BackendTextureObject, MG_Pipe::MGPipeKind::Texture>
|
||||
g_backendTextureObjects;
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (id), CONTRACT-P5E §4.1 / §4.2: THE TEXTURE TWIN BY HANDLE - the handle a record
|
||||
// carried (`BoundSamplerViews[u].Texture`, `BoundShaderImages[u].Res`, a framebuffer
|
||||
// record's `MGPSurface::Res`, `VerbMipRes`, `VerbCopyTexDst`, `MGPCopyImage`'s two
|
||||
// endpoints), never `Find(textureObject.get())`. Same shape and the same three
|
||||
// absences as VertexArrayImpl::ResolveVaoTwin: record first, no frontend touch, no
|
||||
// allocator probe, and NO SYNC - the three texture syncs and the clean condition that
|
||||
// gates them are the tx2 package's.
|
||||
//
|
||||
// The by-value twin copy plus second Find that SyncTextureObjectToBackend pays today
|
||||
// (the registry's Find could relocate its own return) is not reproduced here: the slot
|
||||
// table's answer is an array element and only a GetOrCreate that GROWS the table moves
|
||||
// it, which this function has already done by the time it returns.
|
||||
BackendTextureObject* ResolveTextureTwin(MG_Pipe::MGPipeHandle res);
|
||||
#endif
|
||||
SharedPtr<BackendTextureObject>& SyncTextureObjectToBackend(
|
||||
const SharedPtr<MG_State::GLState::ITextureObject>& textureObject,
|
||||
Bool imageBindableStorageRequired = false);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// ---- P5e SEAM (MG_Remote/CONTRACT-P5E.md §4.2, §5.2; declared by c0e, bodied by
|
||||
// id/tx2) --------------------------------------------------------------------------
|
||||
//
|
||||
// EVERY DRAW-PATH TEXTURE ENTRY, BY HANDLE. The caller holds a Texture handle - a
|
||||
// sampler view's Texture, an image unit's Res, a framebuffer surface's Res, VerbMipRes,
|
||||
// VerbCopyTexDst, a copy-image endpoint - and the sync resolves the RECORD first and the
|
||||
// twin by GetOrCreateByHandle, so nothing on the apply thread dereferences a frontend
|
||||
// ITextureObject. The frontend overload above stays as the monolith-glue half.
|
||||
//
|
||||
// ResolveTextureTwin is the lookup without the sync, for the callers that need the twin
|
||||
// to answer a shape question (an image bind's target and storage format come off the
|
||||
// twin, not off a new wire field) after tx2's sync has already run this frame.
|
||||
SharedPtr<BackendTextureObject>& SyncTextureToBackendByHandle(
|
||||
MG_Pipe::MGPipeHandle texture, Bool imageBindableStorageRequired = false);
|
||||
BackendTextureObject* ResolveTextureTwin(MG_Pipe::MGPipeHandle texture);
|
||||
#endif
|
||||
// Brings every texture the next draw reads - the touched units' bindings and the draw
|
||||
// FBO's texture attachments - onto the backend, through the two borrowed-pair memos
|
||||
// documented at their definitions. Declared here so tests can drive those memos directly.
|
||||
@@ -1844,10 +2176,26 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BackendFramebufferObject& operator=(const BackendFramebufferObject&) = delete;
|
||||
void SyncToBackend(const SharedPtr<MG_State::GLState::FramebufferObject>& stateFBOObject,
|
||||
FramebufferTarget asTarget);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e SEAM (MG_Remote/CONTRACT-P5E.md §5.4; declared by c0e, bodied by fb): the same
|
||||
// sync keyed on the framebuffer HANDLE. The record's eleven surfaces ARE the point
|
||||
// set - the emitter refuses a point at or above the wire width - so the attachment
|
||||
// walk needs no frontend FramebufferObject and no m_pushedSyncHandle handshake: the
|
||||
// handle is the argument. An OVERLOAD rather than a changed signature, so the
|
||||
// monolith arm and the pull build see no token move.
|
||||
void SyncToBackendByHandle(MG_Pipe::MGPipeHandle fbo, FramebufferTarget asTarget);
|
||||
#endif
|
||||
// Apply only this FBO's read buffer (glReadBuffer) to the backend. Split out so it can
|
||||
// still run when SyncCurrentFBO skips the READ-target sync because the same GL FBO is
|
||||
// bound as both draw and read (otherwise glReadBuffer changes would be silently dropped).
|
||||
void SyncReadBufferToBackend(const SharedPtr<MG_State::GLState::FramebufferObject>& stateFBOObject);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (fb, §5.4): the same read-buffer push keyed on the handle, for the one path
|
||||
// that applies a read buffer without doing the rest of the sync - SyncCurrentFBO's
|
||||
// "one object is bound to BOTH bindings" skip, where the DRAW pass already did the
|
||||
// attachment work and only glReadBuffer is READ-target-specific.
|
||||
void SyncReadBufferToBackendByHandle(MG_Pipe::MGPipeHandle fbo);
|
||||
#endif
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5c (hd, CONTRACT-P5C §3.2): the framebuffer handle the CURRENT sync is keyed on.
|
||||
// A caller applying a record sets it before SyncToBackend / SyncReadBufferToBackend,
|
||||
@@ -1937,6 +2285,11 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// did. 0 is never a live hash (a computed 0 is remapped to 1 by the client's
|
||||
// suppressor), so a zeroed memo is a guaranteed miss.
|
||||
Array<Uint64, SizeT(FramebufferTarget::FramebufferTargetCount)> m_syncedRecordHashes = {0};
|
||||
// P5e (fb): the read-buffer decision, taken from the record alone. Both
|
||||
// SyncReadBufferToBackend overloads funnel through it, so the rule lives in one
|
||||
// place and the object form is visibly the half that only finds the handle.
|
||||
// glNameForDiag is 0 on the handle arm, which reads as "the record did not say".
|
||||
void ApplyReadBufferFromRecord(const MG_Pipe::MGPFramebufferState& record, Uint glNameForDiag);
|
||||
#endif
|
||||
};
|
||||
|
||||
@@ -1968,6 +2321,34 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// describes an object without claiming any binding for it, so asking the record would
|
||||
// give the wrong answer by construction.
|
||||
Bool PushedFramebufferIsBoundTo(FramebufferTarget target, MG_Pipe::MGPipeHandle fbo);
|
||||
|
||||
// ---- P5e (fb, CONTRACT-P5E.md §5.4): the reverse index, texture -> framebuffers ------
|
||||
//
|
||||
// "Which framebuffers currently have this texture attached." The detach walk
|
||||
// (ScopedDetachedTextureFramebufferAttachments) used to answer it by iterating every
|
||||
// live twin and reading each one's FRONTEND attachment array, which is the last place
|
||||
// the server held a frontend framebuffer across records - id re-typed ForEachLive and
|
||||
// named this package as the one that replaces the read. The relation is maintained
|
||||
// where the record is consumed (SyncToBackendByHandle's attachment walk), because the
|
||||
// record's eleven surfaces already say it.
|
||||
//
|
||||
// The index answers about a TEXTURE SLOT and returns whole FRAMEBUFFER handles, so a
|
||||
// recycled framebuffer slot never answers for its predecessor. See the definition for
|
||||
// why nothing prunes a dead row.
|
||||
void NoteFramebufferTextureAttachments(MG_Pipe::MGPipeHandle fbo,
|
||||
const MG_Pipe::MGPFramebufferState& record);
|
||||
Vector<MG_Pipe::MGPipeHandle> FramebuffersAttachingTexture(MG_Pipe::MGPipeHandle texture);
|
||||
|
||||
// The record's surface for an attachment POINT, or null when this record does not
|
||||
// describe that point at all (Color8..Color31, and the default framebuffer's FRONT/BACK
|
||||
// tokens). MGPFramebufferState carries Color[8] + Depth + Stencil, which is every point
|
||||
// a framebuffer can hold on the handle arm - D-C3 refuses bit 9 outright on a driver
|
||||
// reporting more than 8 colour attachments. P5e (fb) exports it: the twin's attachment
|
||||
// walk, the named blit's aspect plan and the detach walk all ask the same question of
|
||||
// the same record, and a second copy of the Color/Depth/Stencil dispatch beside each of
|
||||
// them is how one of them ends up describing a point differently from the others.
|
||||
const MG_Pipe::MGPSurface* PushedSurfaceForAttachment(const MG_Pipe::MGPFramebufferState& record,
|
||||
FramebufferAttachmentType point);
|
||||
#endif
|
||||
// True when the read buffer names a fixed-point (norm/snorm) attachment that the
|
||||
// backend actually stores in a floating-point format. GL clamps a read from a
|
||||
@@ -2256,6 +2637,173 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// Defined further down, next to CollectImageFormatBakeInputs; only referenced here.
|
||||
struct ImageFormatBakeInputs;
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// ---- P5e (pg), CONTRACT-P5E.md §5.5: THE ONE SOURCE A PROGRAM BUILD READS ----------
|
||||
//
|
||||
// WHY THIS TYPE EXISTS AT ALL. Building a driver program asks the frontend
|
||||
// ProgramObject sixteen distinct questions and asks its reflection tables thousands of
|
||||
// times, and EVERY ONE OF THEM used to be a read of client-owned memory on the apply
|
||||
// thread. Under run-ahead that is not a race to be careful about, it is wrong by
|
||||
// construction: ProgramObject::Link() REPLACES m_artifacts and m_spirv in place, and by
|
||||
// the time the server builds, the client may be several links past the one the record
|
||||
// describes. So the build reads THIS instead, and the two arms differ only in where it
|
||||
// points.
|
||||
//
|
||||
// AND IT IS DELIBERATELY NOT A SECOND ProgramObject. Nothing here constructs a frontend
|
||||
// object on the apply thread - ID-102's lesson, learned by id: a ProgramObject's own
|
||||
// constructor mints a lifetime id, so an "object" built server-side would trip the very
|
||||
// guards this phase installs and would make a red-once falsely green.
|
||||
//
|
||||
// THE OVERLAY IS THE OTHER HALF. Three reflection fields - the block-to-point map, the
|
||||
// sampler unit per uniform LOCATION and the name-keyed storage-block override set - are
|
||||
// members of LinkArtifacts that glUniformBlockBinding, glUniform1i and
|
||||
// glShaderStorageBlockBinding move AFTER the link that produced the archive, without
|
||||
// relinking. On the handle arm the record's set_program_bindings tails are the whole
|
||||
// truth for all three (whole-set replacement, not a merge) and the archive's link-time
|
||||
// values are shadowed; on the monolith arm there is no overlay because the "archive"
|
||||
// IS the frontend's live table.
|
||||
//
|
||||
// THE ACCESSORS BELOW MIRROR ProgramObject's, one for one, and that duplication is
|
||||
// deliberate rather than lazy: MG_Backend includes nothing from MG_State's program
|
||||
// internals beyond the archive structs themselves, and ProgramObject's own forms are
|
||||
// non-static members over Artifacts(). The three that ARE already static over
|
||||
// LinkArtifacts (IsValidUniformLocation, UniformAtIn, GetUniformArraySizeByTIndex) are
|
||||
// called rather than copied, which is where the boundary sits.
|
||||
struct ProgramArchiveSource {
|
||||
using LinkArtifacts = MG_State::GLState::LinkArtifacts;
|
||||
using SpirvArtifacts = MG_State::GLState::SpirvArtifacts;
|
||||
using UniformReflection = MG_State::GLState::ResourceReflection;
|
||||
using TypeFacts = MG_State::GLState::TypeFacts;
|
||||
using XfbVarying = MG_State::GLState::XfbVarying;
|
||||
|
||||
// Both are non-null for the whole lifetime of a source; a source is a local of the
|
||||
// build that made it and never outlives the record or the object it points into.
|
||||
const LinkArtifacts* Link = nullptr;
|
||||
const SpirvArtifacts* Spirv = nullptr;
|
||||
|
||||
// WHAT A LOG LINE NAMES. The frontend's GL program name on the monolith arm; the
|
||||
// ShaderCso slot on the handle arm, because the server does not know GL names and
|
||||
// must not learn them (the handle is the identity the whole phase speaks in).
|
||||
Uint Identity = 0;
|
||||
// True when Identity is a handle slot rather than a GL name, so a message can say
|
||||
// which it printed instead of leaving a reader to guess.
|
||||
Bool IdentityIsHandleSlot = false;
|
||||
|
||||
Bool Linked = false;
|
||||
Bool SpirvUsable = false;
|
||||
Bool SpirvValidationEnabled = false;
|
||||
Bool PointSizeWasDemoted = false;
|
||||
Uint GlobalUboSize = 0;
|
||||
|
||||
// One entry per Spirv->generatedSpirv module, at the same index. Owned rather than
|
||||
// referenced because the monolith arm builds it (GetLinkedShaderStages() returns by
|
||||
// value) and the handle arm converts the frame's Uint32 words.
|
||||
Vector<ShaderStage> LinkedStages;
|
||||
|
||||
// The post-link overlay. Governs iff OverlayGoverns; see the type comment.
|
||||
Bool OverlayGoverns = false;
|
||||
const Vector<Int32>* BlockBindingOverlay = nullptr;
|
||||
const Vector<MG_Pipe::MGPProgramSamplerUnit>* SamplerUnitOverlay = nullptr;
|
||||
// Built once per build from whichever side owns it, because TranspileSpirvToEssl
|
||||
// takes the map by const reference and the record carries a vector.
|
||||
UnorderedMap<String, Int> StorageOverrides;
|
||||
// The client's commutative hash on the handle arm, ComputeShaderStorageBlockBinding-
|
||||
// Signature's on the monolith one. Same function, computed on whichever side owns
|
||||
// the map (MG_Impl/Pipe/ProgramEmit.h names its twin).
|
||||
Uint64 StorageOverrideSignature = 0;
|
||||
|
||||
// ---- the archive's own answers ----
|
||||
//
|
||||
// EVERY NAME HERE IS ProgramObject's NAME, and that is load-bearing rather than
|
||||
// tidy: the build body below is written once against `src`, whose TYPE is the
|
||||
// build's (ProgramBuildSource), so the pull build compiles the very same text
|
||||
// against a ProgramObject and G1's byte identity survives.
|
||||
Uint GetExternalIndex() const { return Identity; }
|
||||
Bool GetLinkStatus() const { return Linked; }
|
||||
Bool GetSpirvStatus() const { return SpirvUsable; }
|
||||
Bool GetSpirvValidationEnabled() const { return SpirvValidationEnabled; }
|
||||
Bool PointSizeDemoted() const { return PointSizeWasDemoted; }
|
||||
Uint GetUBOSize() const { return GlobalUboSize; }
|
||||
const Vector<ShaderStage>& GetLinkedShaderStages() const { return LinkedStages; }
|
||||
const UnorderedMap<String, Int>& GetShaderStorageBlockBindingOverrides() const {
|
||||
return StorageOverrides;
|
||||
}
|
||||
// THE DEBUG LOG IS DELETED ON THIS ARM (CONTRACT-P5E §5.5). The snapshot is
|
||||
// GL-thread-owned ShaderObject SharedPtrs - the exact shape rule C forbids an
|
||||
// applier entry point to reach - and its one consumer in the build is an MGLOG_D
|
||||
// dump of each stage's original GLSL, which the server does not have and does not
|
||||
// need. An empty list makes that loop a no-op rather than a special case.
|
||||
const Vector<MG_State::GLState::ProgramObject::LinkedShaderRef>& GetLinkedShaderSnapshot() const {
|
||||
static const Vector<MG_State::GLState::ProgramObject::LinkedShaderRef> kNone;
|
||||
return kNone;
|
||||
}
|
||||
|
||||
Uint GetMaxUniformLocation() const { return Link->maxUniformLocation; }
|
||||
Bool IsValidUniformLocation(Int location) const {
|
||||
return MG_State::GLState::ProgramObject::IsValidUniformLocation(*Link, location);
|
||||
}
|
||||
const UniformReflection& UniformAt(Int tIndex) const {
|
||||
return MG_State::GLState::ProgramObject::UniformAtIn(*Link, tIndex);
|
||||
}
|
||||
// Bounds-checked, exactly as ProgramObject::GetUniformName is not: the frontend's
|
||||
// form indexes uniformIndexInTProgram raw because every caller there has already
|
||||
// walked a legal location, and this one is reached from a handle arm where the
|
||||
// location space comes off a record.
|
||||
const String& GetUniformName(Uint location) const {
|
||||
static const String kEmpty;
|
||||
if (location >= Link->uniformIndexInTProgram.size()) return kEmpty;
|
||||
return UniformAt(Link->uniformIndexInTProgram[location]).name;
|
||||
}
|
||||
GLenum GetUniformType(Uint location) const {
|
||||
if (location >= Link->uniformIndexInTProgram.size()) return 0;
|
||||
return UniformAt(Link->uniformIndexInTProgram[location]).glDefineType;
|
||||
}
|
||||
const TypeFacts& GetUniformTypeFacts(Uint location) const {
|
||||
static const TypeFacts kEmpty{};
|
||||
if (location >= Link->uniformIndexInTProgram.size()) return kEmpty;
|
||||
return UniformAt(Link->uniformIndexInTProgram[location]).type;
|
||||
}
|
||||
Bool UniformLocationsAliasSameUniform(Int a, Int b) const {
|
||||
if (!IsValidUniformLocation(a) || !IsValidUniformLocation(b)) return false;
|
||||
return Link->uniformIndexInTProgram[a] == Link->uniformIndexInTProgram[b];
|
||||
}
|
||||
// ProgramObject::GetUniformLocation, reproduced over the archive. The array rules
|
||||
// are the whole body: reflection keys an array under "arr[0]" at its base location,
|
||||
// a bare "arr" resolves to that, an "arr[k]" resolves to base + k, and an array of
|
||||
// arrays is keyed by its full "[0]"-terminated spelling - which is why the
|
||||
// suffixed lookup is tried before the trailing subscript is read as an index.
|
||||
Int GetUniformLocation(const String& name) const;
|
||||
Int GetActiveUniformBlocksCount() const {
|
||||
return static_cast<Int>(Link->glBlockIndexToTProgram.size());
|
||||
}
|
||||
const String& GetUniformBlockName(Uint index) const;
|
||||
|
||||
GLenum GetTransformFeedbackBufferMode() const { return Link->xfbBufferMode; }
|
||||
SizeT GetTransformFeedbackVaryingCount() const { return Link->xfbVaryings.size(); }
|
||||
const Vector<XfbVarying>& GetTransformFeedbackVaryings() const { return Link->xfbVaryings; }
|
||||
const Vector<Vector<unsigned>>& GetGeneratedSpirv() const { return Spirv->generatedSpirv; }
|
||||
|
||||
// ---- the three the overlay governs ----
|
||||
Uint GetUniformBlockBinding(Uint index) const;
|
||||
Int GetUniformSamplerOrImageUnitIndex(Uint location) const;
|
||||
|
||||
// The monolith-glue constructor: the archive IS the frontend's live tables, so
|
||||
// there is no overlay and the three mutable fields answer from them directly.
|
||||
static ProgramArchiveSource FromFrontend(const MG_State::GLState::ProgramObject& program);
|
||||
// The handle arm: the record's own archive, with its three tails overlaid.
|
||||
static ProgramArchiveSource FromRecord(MG_Pipe::MGPipeHandle cso,
|
||||
const MG_Pipe::MGPipeShaderCsoRecord& record);
|
||||
};
|
||||
|
||||
// THE BUILD'S SOURCE TYPE, per build. This alias is what lets the program build have one
|
||||
// body: in a push build it is the record-or-frontend view above, in a pull build it is
|
||||
// the frontend object the body always read, spelled through the same name so the text
|
||||
// does not move (G1).
|
||||
using ProgramBuildSource = ProgramArchiveSource;
|
||||
#else
|
||||
using ProgramBuildSource = MG_State::GLState::ProgramObject;
|
||||
#endif
|
||||
|
||||
class BackendProgramObjectImpl {
|
||||
public:
|
||||
// Per-link cache of a sampler-style uniform's backend location: built once in
|
||||
@@ -2315,6 +2863,14 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BackendProgramObjectImpl();
|
||||
~BackendProgramObjectImpl();
|
||||
void SyncToBackend(const SharedPtr<MG_State::GLState::ProgramObject>& stateProgramObject);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (pg), CONTRACT-P5E.md §5.5: the same sync keyed on the ShaderCso HANDLE and
|
||||
// answered from the record - the archive the create carries and the three binding
|
||||
// tails set_program_bindings carries. It is an OVERLOAD beside the frontend one,
|
||||
// which stays as the monolith-glue half, so the pull build's mangled names do not
|
||||
// move (ruling 1 / ID-81: two overloads, not an #if inside one body).
|
||||
void SyncToBackendByHandle(MG_Pipe::MGPipeHandle cso);
|
||||
#endif
|
||||
void Use();
|
||||
void SetBaseInstance(Uint32 baseInstance) const;
|
||||
void SetBaseInstanceWordIndex(Int32 wordIndex) const;
|
||||
@@ -2413,6 +2969,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// parameters - are all still specialised at the verb, from state this backend holds.
|
||||
// 0 means "never stamped", which is a guaranteed miss (applier serials start at 1).
|
||||
Uint64 GetSyncedShaderCsoSerial() const { return m_syncedShaderCsoSerial; }
|
||||
// P5e (pg): the SECOND server-owned key, and it replaces GetImageUnitVersion() on
|
||||
// the handle arm rather than duplicating the one above. A glUniform1i on an IMAGE
|
||||
// uniform is BAKED into the generated ESSL (ES forbids the call outright), so the
|
||||
// record that carries the new unit has to force a rebuild; BindingsSerial moves on
|
||||
// every applied set_program_bindings, which is exactly when one can have changed.
|
||||
// 0 means "never stamped", a guaranteed miss, because applier serials start at 1.
|
||||
Uint64 GetSyncedBindingsSerial() const { return m_syncedBindingsSerial; }
|
||||
#endif
|
||||
// Whether the (unit, bound format) pairs this program's FORMAT-LESS image uniforms
|
||||
// resolve to are still the ones its ESSL was generated against.
|
||||
@@ -2438,7 +3001,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Uint64 ComputeImageUnitFormatSignature() const;
|
||||
|
||||
private:
|
||||
void CacheResourceLocations(const SharedPtr<MG_State::GLState::ProgramObject>& stateProgramObject);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// The one body both public heads feed; see its definition for why it is a worker in
|
||||
// a push build and IS SyncToBackend in a pull build.
|
||||
void SyncToBackendFromSource(const ProgramBuildSource& src);
|
||||
#endif
|
||||
void CacheResourceLocations(const ProgramBuildSource& src);
|
||||
|
||||
// Builds, compiles and attaches the pass-through tessellation control stage GL 4.6
|
||||
// core 11.2.2 describes, for a program that has an evaluation stage and none of its
|
||||
@@ -2446,7 +3014,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// stage has been attached and before the link; see the definition for why it cannot
|
||||
// regress a program that works today.
|
||||
void AttachPassthroughTessControlStage(
|
||||
const MG_State::GLState::ProgramObject& stateProgramObject, Int tessEvalShaderIndex,
|
||||
const ProgramBuildSource& src, Int tessEvalShaderIndex,
|
||||
const Vector<Vector<unsigned int>>& shaderSpirvs, const String& vertexStageEssl,
|
||||
const String& tessEvalStageEssl);
|
||||
|
||||
@@ -2517,6 +3085,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// P4a's replacement for the two above on the handle arm; see GetSyncedShaderCsoSerial.
|
||||
// Push-only, so the pull build's object is byte-for-byte the pre-P4a one (D-P).
|
||||
Uint64 m_syncedShaderCsoSerial = 0;
|
||||
Uint64 m_syncedBindingsSerial = 0;
|
||||
#endif
|
||||
// Image units addressed by the program's FORMAT-LESS image uniforms, and the digest
|
||||
// of the (unit, format) pairs the generated ESSL baked. Empty/0 for every program
|
||||
@@ -2540,6 +3109,23 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
extern TwinRegistry<MG_State::GLState::ProgramObject, BackendProgramObjectImpl, MG_Pipe::MGPipeKind::ShaderCso>
|
||||
g_backendProgramObjects;
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (id), CONTRACT-P5E §4.1 / §4.2: THE PROGRAM TWIN BY HANDLE - `st.DrawProgram` at
|
||||
// a draw, `st.DispatchProgram` at a dispatch, `st.BoundShaderCso` at a bind - never
|
||||
// `Find(currentProgram.get())` and never the raw-pointer stash. Same shape and the same
|
||||
// three absences as the VAO and texture resolvers beside it: record first, no frontend
|
||||
// touch, no allocator probe, no sync (the nine-clause clean condition and what feeds it
|
||||
// are the pg package's).
|
||||
//
|
||||
// THE BAND IS WHY THIS ONE MATTERS MOST. A program-pipeline composite's ShaderCso slot
|
||||
// is >= kMGPipeShaderCsoCompositeSlotBase, and before P5e the by-handle path would have
|
||||
// grown g_backendProgramObjects to ~983k entries to reach it. SlotTables.h's m_band
|
||||
// lands in this package for exactly that reason - the rekey makes the composite the
|
||||
// ordinary path, so the band is a prerequisite and not a follow-up. The record reader
|
||||
// (PipeShaderCsoRecordForHandle) has been band-aware since P4a.
|
||||
BackendProgramObjectImpl* ResolveProgramTwin(MG_Pipe::MGPipeHandle cso);
|
||||
#endif
|
||||
|
||||
// Points one shader storage block of an ALREADY-LINKED backend program at
|
||||
// `binding`. `blockName` is the frontend interface-query spelling; the real
|
||||
// driver's own index for it is looked up here, because the transpiled ESSL's
|
||||
@@ -2558,15 +3144,20 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// program that was just built - best effort, on the same "only where the driver has
|
||||
// the entry point" terms as ApplyShaderStorageBlockBinding above. Mirrors
|
||||
// DirectVulkan's reseed-on-rebuild in BuildProgramResourceCache.
|
||||
void ReseedShaderStorageBlockBindings(Uint backendProgramId,
|
||||
const MG_State::GLState::ProgramObject& stateProgramObject);
|
||||
void ReseedShaderStorageBlockBindings(Uint backendProgramId, const ProgramBuildSource& src);
|
||||
// Order-independent digest of the program's glShaderStorageBlockBinding overrides.
|
||||
// The generated ESSL carries them (ES has no way to move a storage block's binding
|
||||
// after link), so a program built against a different set is stale and the draw path
|
||||
// has to rebuild it. Computed from the values, so re-setting a block to the binding it
|
||||
// already has costs nothing. 0 when nothing was ever rebound.
|
||||
Uint64 ComputeShaderStorageBlockBindingSignature(
|
||||
const MG_State::GLState::ProgramObject& stateProgramObject);
|
||||
Uint64 ComputeShaderStorageBlockBindingSignature(const ProgramBuildSource& src);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (pg): the computation itself, for the monolith arm - the source constructor seeds
|
||||
// itself with it and the monolith draw path asks it per draw. Push-only: in a pull build
|
||||
// the overload above IS this body, so no name is added there.
|
||||
Uint64 ComputeShaderStorageBlockBindingSignatureOf(
|
||||
const MG_State::GLState::ProgramObject& program);
|
||||
#endif
|
||||
|
||||
// Everything the image-format bake needs from one walk of a program's uniform
|
||||
// reflection. GLSL ES requires a format layout qualifier on every image uniform;
|
||||
@@ -2607,8 +3198,36 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// keeps the module it already had.
|
||||
Bool declaresWidenableImageFormat = false;
|
||||
};
|
||||
ImageFormatBakeInputs CollectImageFormatBakeInputs(
|
||||
const MG_State::GLState::ProgramObject& stateProgramObject);
|
||||
ImageFormatBakeInputs CollectImageFormatBakeInputs(const ProgramBuildSource& src);
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// ---- P5e SEAM (MG_Remote/CONTRACT-P5E.md §4.2, §5.5; declared by c0e, bodied by
|
||||
// id/pg) ---------------------------------------------------------------------------
|
||||
//
|
||||
// THE PROGRAM TWIN, RESOLVED FROM MGPipeApplierState::DrawProgram / DispatchProgram /
|
||||
// BoundShaderCso instead of from GetProgramForDraw()'s frontend SharedPtr - the second
|
||||
// unconditional pointer read of every draw, and one of the two rows whose retirement is
|
||||
// what P5e is for. Composite pipeline programs resolve through the same call: their
|
||||
// slots come out of the allocator's composite band, which the server's slot table gains
|
||||
// a band for so the ordinary table does not grow to a million entries.
|
||||
//
|
||||
// Null, loudly, when the handle names no record or cannot be adopted - the shape
|
||||
// ResolveSamplerCsoTwin set - and null silently for the null handle, which is the legal
|
||||
// "nothing bound".
|
||||
BackendProgramObjectImpl* ResolveProgramTwin(MG_Pipe::MGPipeHandle cso);
|
||||
|
||||
// P5e (pg): the two PER-DRAW reads of set_program_bindings' tails, as free functions
|
||||
// rather than through a ProgramArchiveSource - building a source per draw would copy the
|
||||
// override map for a question that is one indexed read. Both answer exactly what their
|
||||
// frontend twins do when the record carries no bindings yet: the archive's own link-time
|
||||
// value, which for an untouched program IS the right answer.
|
||||
//
|
||||
// The block binding is dense in the BLOCK index space; the sampler unit is sparse and
|
||||
// ascending by LOCATION, so it is a binary search (a program has thousands of locations
|
||||
// and a handful of samplers, and a linear scan per sampler would be quadratic).
|
||||
Uint ProgramBlockBindingFromRecord(const MG_Pipe::MGPipeShaderCsoRecord& record, Int blockIndex);
|
||||
Int ProgramSamplerUnitFromRecord(const MG_Pipe::MGPipeShaderCsoRecord& record, Uint location);
|
||||
#endif
|
||||
} // namespace PrgramImpl
|
||||
|
||||
namespace SamplerImpl {
|
||||
@@ -2789,6 +3408,16 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BackendRenderbufferObject(const BackendRenderbufferObject&) = delete;
|
||||
BackendRenderbufferObject& operator=(const BackendRenderbufferObject&) = delete;
|
||||
void SyncToBackend(const SharedPtr<MG_State::GLState::RenderbufferObject>& stateRBOObject);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e SEAM (declared by c0e, bodied by fb): the renderbuffer twin of the
|
||||
// framebuffer overload above. MGPSurface::Res names the renderbuffer and the
|
||||
// resource record already carries its format, extent and sample count (P4a), so the
|
||||
// attachment sync needs no frontend RenderbufferObject - which is what deletes the
|
||||
// one live identity probe left in the attachment path (Managers.cpp's renderbuffer
|
||||
// cross-check, the sibling that never got the Transport == Monolith gate its
|
||||
// texture counterpart has).
|
||||
void SyncToBackendByHandle(MG_Pipe::MGPipeHandle renderbuffer);
|
||||
#endif
|
||||
Uint GetBackendRenderbufferId() const { return m_backendRBOId; }
|
||||
void Bind() const;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <MG_State/GLState/Core.h>
|
||||
#include <MG_Pipe/PipeInputsSwitch.h>
|
||||
#include <MG_Util/Metrics/PipeStats.h>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
|
||||
@@ -91,11 +92,151 @@ namespace MobileGL::MG_Backend::DirectGLES::MultiDrawImpl {
|
||||
return resource ? resource->id : 0;
|
||||
}
|
||||
|
||||
const SharedPtr<MG_State::GLState::BufferObject>& BoundIndexBuffer() {
|
||||
static const SharedPtr<MG_State::GLState::BufferObject> none;
|
||||
// ---------------------------------------------------------------------------
|
||||
// The bound index buffer, and WHICH SIDE ANSWERS FOR IT
|
||||
//
|
||||
// P5e (mv), CONTRACT-P5E §5.1 + §5.8 (ruling ID-81): this file asks the bound element
|
||||
// array buffer exactly three questions - "is one bound at all", "what GL name did
|
||||
// PrepareForDraw leave on GL_ELEMENT_ARRAY_BUFFER (and how big is its store)", and
|
||||
// "give me its bytes on the CPU" - and until now it asked all three of the FRONTEND
|
||||
// VAO, on the apply thread, once per indexed multi-draw. That was the last unguarded
|
||||
// `MGB_CTX->GetBoundVertexArray()` in the backend: package vi retired the ordinary
|
||||
// draw path's copy (DirectGLES.cpp's SyncCurrentVertexAttributeValues / PrepareForDraw)
|
||||
// and this one survived only because these batches used to die earlier, on the
|
||||
// framebuffer row fb has since retired.
|
||||
//
|
||||
// THE ARM IS STATED, NEVER INFERRED. BufferImpl::VertexInputReadsRecords() is the
|
||||
// family's own selector and reduces to `Transport != Monolith && the vertex-input bit`;
|
||||
// it is the same conjunction RefuseElementArrayBufferFromTheFrontend guards the
|
||||
// single-draw path with. Nothing below decides an arm by noticing that a handle or a
|
||||
// pointer happens to be null - conflating "a handle was noted" with "the record arm is
|
||||
// selected" is what ID-107 cost this phase 137 scenarios.
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// How much of the index buffer a caller needs. DELIBERATELY not nested levels: each
|
||||
// value is exactly the work its original call site did, in its original order, so the
|
||||
// monolith arm makes the same calls in the same sequence it made before this package.
|
||||
enum class IndexBufferQuestion {
|
||||
Presence, // is an element array buffer bound at all
|
||||
DriverName, // + the GL name currently bound to GL_ELEMENT_ARRAY_BUFFER
|
||||
DriverNameAndSize,// + the store's size in bytes (the compute tier's source)
|
||||
HostBytes, // a CPU-readable copy of the whole store, and its size
|
||||
};
|
||||
|
||||
struct BoundIndexBufferView {
|
||||
Bool Present = false;
|
||||
Uint Id = 0; // DriverName*: 0 when there is no backend store yet
|
||||
SizeT Size = 0; // DriverNameAndSize / HostBytes
|
||||
const Uint8* HostBytes = nullptr; // HostBytes: null when there is no CPU copy
|
||||
};
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// A missing record on the handle arm is a NAMED refusal and never a quiet fall-back to
|
||||
// the frontend (TASK-mv requirement 2; the shape is Managers.cpp's
|
||||
// RefuseNullFrontendTextureOffTheHandleArm). The frontend element slot is not a second
|
||||
// opinion on this side: it answers for whatever the CLIENT has bound NOW, which is a
|
||||
// later draw than the one being applied. Drawing a batch from it would be a silently
|
||||
// wrong picture, which is precisely what MultiDrawScenario's batch-matches-unrolled
|
||||
// assertions exist to catch and what a fall-back would hide from them.
|
||||
[[noreturn]] void RefuseMissingIndexBufferRecord(const char* entry, MG_Pipe::MGPipeHandle res,
|
||||
const char* missing) {
|
||||
MGLOG_F("MGPipe: Fatal{RoleViolation, \"multidraw-index-buffer-arm\"} - %s found no %s for "
|
||||
"the index buffer {%u, %u} this batch's record named. The index buffer of this "
|
||||
"family is MGPipeApplier().IndexBuffer.Res (CONTRACT-P5E §5.1) and the arm is "
|
||||
"selected by Transport != Monolith AND the vertex-input subsystem bit (§5.8, "
|
||||
"ID-81); falling back to the frontend VAO's element slot here would draw this "
|
||||
"multi-draw from whatever the CLIENT has bound now",
|
||||
entry, missing, res.Slot, res.Gen);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// Does the applier's record say the application SUPPLIED this store's content? The M-3
|
||||
// rule ScopedRestartIndexSubstitution spells: for a supplied store a coverage gap in the
|
||||
// server shadow is a missing record and Fatal by name; for one the application ORPHANED
|
||||
// the gap is its own undefined content, and reading the shadow's zero-fill is exactly
|
||||
// what the monolith arm's MappedData() hands back.
|
||||
Bool IndexBufferRecordHasDefinedContent(const MG_Pipe::MGPipeApplierState& st,
|
||||
MG_Pipe::MGPipeHandle res) {
|
||||
if (res.Slot >= st.Resources.size()) return false;
|
||||
const auto& candidate = st.Resources[res.Slot];
|
||||
if (!candidate.Live || candidate.Gen != res.Gen) return false;
|
||||
return candidate.Desc.HasDefinedContent != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
BoundIndexBufferView ResolveBoundIndexBuffer(IndexBufferQuestion question, const char* entry) {
|
||||
BoundIndexBufferView view;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (BufferImpl::VertexInputReadsRecords()) {
|
||||
const auto& st = MG_Pipe::MGPipeApplier();
|
||||
const MG_Pipe::MGPipeHandle res = BufferImpl::ResolveDrawIndexBufferFromRecord(st).Res;
|
||||
// A null Res is "no element array buffer bound", exactly as a null frontend slot
|
||||
// is on the arm below - the batch's indices are a client array, and every caller
|
||||
// already has an arm for that. It is NOT the arm test; the arm was decided above.
|
||||
if (MG_Pipe::MGPipeHandleIsNull(res)) return view;
|
||||
view.Present = true;
|
||||
if (question == IndexBufferQuestion::Presence) return view;
|
||||
|
||||
if (question == IndexBufferQuestion::HostBytes) {
|
||||
// No Sync* pair here and none is missing: on this side the applier has
|
||||
// already consumed the persistent-map blocks and the shader writebacks for
|
||||
// this resource before the draw verb replayed, so the server's staged shadow
|
||||
// IS the synced copy. That is also why this arm cannot be expressed as "find
|
||||
// the object and run the monolith body".
|
||||
auto* resource = BufferImpl::FindBufferResourceForHandle(res);
|
||||
if (resource == nullptr) RefuseMissingIndexBufferRecord(entry, res, "backend resource");
|
||||
view.Size = BufferImpl::ResourceWidthForHandle(res);
|
||||
view.HostBytes = resource->hostBytes;
|
||||
if (view.HostBytes != nullptr && IndexBufferRecordHasDefinedContent(st, res)) {
|
||||
BufferImpl::RequireStagedCoverage(*resource, view.HostBytes, 0, view.Size,
|
||||
"multidraw_index_rebase");
|
||||
}
|
||||
// A null HostBytes is not a refusal: MappedData() on the monolith arm is
|
||||
// equally allowed to be null (an adopted coherent map keeps its bytes
|
||||
// elsewhere), and the one caller that asks declines the tier for it.
|
||||
return view;
|
||||
}
|
||||
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(nullptr, res);
|
||||
if (resource == nullptr) RefuseMissingIndexBufferRecord(entry, res, "backend resource");
|
||||
view.Id = resource->id;
|
||||
if (question == IndexBufferQuestion::DriverNameAndSize) {
|
||||
view.Size = BufferImpl::ResourceWidthForHandle(res);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
#endif
|
||||
// MONOLITH GLUE from here down, token for token what each call site did before.
|
||||
const auto& vao = MGB_CTX->GetBoundVertexArray();
|
||||
if (!vao) return none;
|
||||
return vao->GetIndexBufferBindingSlot().GetBoundObject();
|
||||
if (!vao) return view;
|
||||
const auto& ibo = vao->GetIndexBufferBindingSlot().GetBoundObject();
|
||||
if (!ibo) return view;
|
||||
view.Present = true;
|
||||
switch (question) {
|
||||
case IndexBufferQuestion::Presence:
|
||||
break;
|
||||
case IndexBufferQuestion::DriverName: {
|
||||
const auto* resource = BufferImpl::EnsureBufferResource(ibo);
|
||||
view.Id = resource ? resource->id : 0;
|
||||
break;
|
||||
}
|
||||
case IndexBufferQuestion::DriverNameAndSize: {
|
||||
const auto* resource = BufferImpl::EnsureBufferResource(ibo);
|
||||
view.Id = resource ? resource->id : 0;
|
||||
view.Size = ibo->GetSize();
|
||||
break;
|
||||
}
|
||||
case IndexBufferQuestion::HostBytes:
|
||||
// The shadow is the source of truth for CPU reads, but a persistent map or
|
||||
// a shader write may have moved past it since the last sync.
|
||||
ibo->SyncPersistentMappedRange();
|
||||
ibo->SyncGpuWrites();
|
||||
view.HostBytes = ibo->MappedData();
|
||||
view.Size = ibo->GetSize();
|
||||
break;
|
||||
}
|
||||
(void)entry;
|
||||
return view;
|
||||
}
|
||||
|
||||
// The GL name PrepareForDraw left on GL_ELEMENT_ARRAY_BUFFER, i.e. what a tier
|
||||
@@ -103,10 +244,7 @@ namespace MobileGL::MG_Backend::DirectGLES::MultiDrawImpl {
|
||||
// matters beyond tidiness: the VAO twin memoises that it already synced this
|
||||
// index binding and will not re-issue it on the next draw.
|
||||
Uint BoundIndexBufferId() {
|
||||
const auto& ibo = BoundIndexBuffer();
|
||||
if (!ibo) return 0;
|
||||
const auto* resource = BufferImpl::EnsureBufferResource(ibo);
|
||||
return resource ? resource->id : 0;
|
||||
return ResolveBoundIndexBuffer(IndexBufferQuestion::DriverName, "BoundIndexBufferId").Id;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -361,13 +499,18 @@ namespace MobileGL::MG_Backend::DirectGLES::MultiDrawImpl {
|
||||
}
|
||||
}
|
||||
|
||||
// CPU-readable bytes of one sub-draw's indices, from the frontend shadow of the
|
||||
// bound index buffer or straight from the client array. Null when the sub-draw
|
||||
// would read outside the buffer.
|
||||
const Uint8* ResolveSubDrawIndices(const SharedPtr<MG_State::GLState::BufferObject>& indexBuffer,
|
||||
const Uint8* indexBufferBytes, SizeT indexBufferSize, const void* indices,
|
||||
SizeT indexCount, SizeT indexSize) {
|
||||
if (!indexBuffer) {
|
||||
// CPU-readable bytes of one sub-draw's indices, from the CPU copy of the bound index
|
||||
// buffer (the frontend shadow on the monolith arm, the server's staged shadow on the
|
||||
// record arm) or straight from the client array. Null when the sub-draw would read
|
||||
// outside the buffer.
|
||||
//
|
||||
// P5e (mv): `hasIndexBuffer` is a Bool and not the frontend object it used to be,
|
||||
// because presence is the only thing this function ever asked of it - and on the record
|
||||
// arm there is no such object on this side to hand it.
|
||||
const Uint8* ResolveSubDrawIndices(Bool hasIndexBuffer, const Uint8* indexBufferBytes,
|
||||
SizeT indexBufferSize, const void* indices, SizeT indexCount,
|
||||
SizeT indexSize) {
|
||||
if (!hasIndexBuffer) {
|
||||
return static_cast<const Uint8*>(indices);
|
||||
}
|
||||
if (!indexBufferBytes) return nullptr;
|
||||
@@ -410,8 +553,7 @@ namespace MobileGL::MG_Backend::DirectGLES::MultiDrawImpl {
|
||||
if (indexSize == 0) return false;
|
||||
// Indirect commands address indices as an element offset into the bound element
|
||||
// array buffer, and an indirect draw is not defined without one.
|
||||
const auto& indexBuffer = BoundIndexBuffer();
|
||||
if (!indexBuffer) return false;
|
||||
if (!ResolveBoundIndexBuffer(IndexBufferQuestion::Presence, "RunIndirect").Present) return false;
|
||||
|
||||
g_commandStaging.resize(static_cast<SizeT>(drawcount));
|
||||
for (GLsizei i = 0; i < drawcount; ++i) {
|
||||
@@ -502,17 +644,10 @@ namespace MobileGL::MG_Backend::DirectGLES::MultiDrawImpl {
|
||||
if (total == 0) return true;
|
||||
if (total > kMaxFlattenedIndices) return false;
|
||||
|
||||
const auto& indexBuffer = BoundIndexBuffer();
|
||||
const Uint8* indexBufferBytes = nullptr;
|
||||
SizeT indexBufferSize = 0;
|
||||
if (indexBuffer) {
|
||||
// The shadow is the source of truth for CPU reads, but a persistent map or
|
||||
// a shader write may have moved past it since the last sync.
|
||||
indexBuffer->SyncPersistentMappedRange();
|
||||
indexBuffer->SyncGpuWrites();
|
||||
indexBufferBytes = indexBuffer->MappedData();
|
||||
indexBufferSize = indexBuffer->GetSize();
|
||||
}
|
||||
const BoundIndexBufferView indexBuffer =
|
||||
ResolveBoundIndexBuffer(IndexBufferQuestion::HostBytes, "RunRebasedDrawElements");
|
||||
const Uint8* const indexBufferBytes = indexBuffer.HostBytes;
|
||||
const SizeT indexBufferSize = indexBuffer.Size;
|
||||
|
||||
const Bool restartActive = RestartActive();
|
||||
const Uint32 restartSentinel = RestartSentinelFor(type);
|
||||
@@ -531,8 +666,8 @@ namespace MobileGL::MG_Backend::DirectGLES::MultiDrawImpl {
|
||||
for (GLsizei i = 0; i < drawcount; ++i) {
|
||||
if (count[i] <= 0) continue;
|
||||
const SizeT subDrawCount = static_cast<SizeT>(count[i]);
|
||||
const Uint8* source = ResolveSubDrawIndices(indexBuffer, indexBufferBytes, indexBufferSize, indices[i],
|
||||
subDrawCount, indexSize);
|
||||
const Uint8* source = ResolveSubDrawIndices(indexBuffer.Present, indexBufferBytes, indexBufferSize,
|
||||
indices[i], subDrawCount, indexSize);
|
||||
if (!source) {
|
||||
MGLOG_E_ONCE("DirectGLES multi-draw (drawelements tier): sub-draw %d reads outside the bound index "
|
||||
"buffer; skipping the batch",
|
||||
@@ -714,16 +849,18 @@ void main() {
|
||||
|
||||
// The shader reads the source indices as a storage buffer, so there has to be
|
||||
// a real buffer to read - a client-memory index array has none.
|
||||
const auto& indexBuffer = BoundIndexBuffer();
|
||||
if (!indexBuffer) return;
|
||||
if (!ResolveBoundIndexBuffer(IndexBufferQuestion::Presence, "FlattenWithCompute").Present) return;
|
||||
|
||||
// A dispatch inside an open capture span is not legal, and the span would also
|
||||
// observe one merged draw rather than the batch it asked for.
|
||||
if (XfbImpl::IsCaptureSpanOpen()) return;
|
||||
|
||||
auto* sourceResource = BufferImpl::EnsureBufferResource(indexBuffer);
|
||||
if (!sourceResource || sourceResource->id == 0) return;
|
||||
const SizeT sourceSize = indexBuffer->GetSize();
|
||||
// Asked a second time, and one question later: the ensure below may do GL work, so
|
||||
// it stays BEHIND the capture-span check exactly as it was before P5e (mv).
|
||||
const BoundIndexBufferView source =
|
||||
ResolveBoundIndexBuffer(IndexBufferQuestion::DriverNameAndSize, "FlattenWithCompute");
|
||||
if (source.Id == 0) return;
|
||||
const SizeT sourceSize = source.Size;
|
||||
// std430 addresses the source as uint[]; a tail shorter than a word is not
|
||||
// reachable, so a narrow index type needs a word-multiple buffer.
|
||||
if (indexSize < 4 && (sourceSize % 4) != 0) return;
|
||||
@@ -762,7 +899,7 @@ void main() {
|
||||
return;
|
||||
}
|
||||
|
||||
BufferImpl::BindBufferBaseCached(GL_SHADER_STORAGE_BUFFER, 0, sourceResource->id);
|
||||
BufferImpl::BindBufferBaseCached(GL_SHADER_STORAGE_BUFFER, 0, source.Id);
|
||||
BufferImpl::BindBufferBaseCached(GL_SHADER_STORAGE_BUFFER, 1, g_drawInfo.id);
|
||||
BufferImpl::BindBufferBaseCached(GL_SHADER_STORAGE_BUFFER, 2, g_flattenedIndices.id);
|
||||
|
||||
@@ -906,7 +1043,8 @@ void main() {
|
||||
const Bool arbitraryRestart = restartKind == RestartSubstitutionKind::RewriteIndices;
|
||||
const ScopedSuppressedPrimitiveRestart restartCapOverride(restartKind);
|
||||
|
||||
const Bool hasIndexBuffer = BoundIndexBuffer() != nullptr;
|
||||
const Bool hasIndexBuffer =
|
||||
ResolveBoundIndexBuffer(IndexBufferQuestion::Presence, "DrawElementsBatch").Present;
|
||||
|
||||
// The compute tier dispatches BEFORE the draw state is established: doing it
|
||||
// afterwards would mean unpicking the program, SSBO and index bindings
|
||||
|
||||
@@ -58,14 +58,20 @@
|
||||
// of the six kinds has exactly one table type in this backend. Magma's subsystem-4 table mints
|
||||
// out of its own per-renderer allocator, not MGPipeSlots(), so it is not a holder here.)
|
||||
//
|
||||
// The weak_ptr per entry survives for exactly one reason: ForEachLive() hands the callee a
|
||||
// STRONG reference to the frontend object, which the one direct-iteration site
|
||||
// (ScopedDetachedTextureFramebufferAttachments) needs. It is never an identity test - that is
|
||||
// what Gen is for - and it is never read to decide whether an entry is dead: a destructor that
|
||||
// runs after exit() has begun has its notice dropped by InProcessTeardown(), and that twin is
|
||||
// then a DELIBERATE leak (the process is exiting, the driver reclaims the object, and a twin
|
||||
// destructor must not call into a driver that may already be unloaded), not something to be
|
||||
// collected later.
|
||||
// The weak_ptr per entry survives as the MONOLITH-GLUE half of the table's identity: the
|
||||
// minting GetOrCreate stores it, NoteStateForHandle/StateForHandle read it, and the legacy
|
||||
// death notice walks it. It is never an identity test - that is what Gen is for - and it is
|
||||
// never read to decide whether an entry is dead: a destructor that runs after exit() has begun
|
||||
// has its notice dropped by InProcessTeardown(), and that twin is then a DELIBERATE leak (the
|
||||
// process is exiting, the driver reclaims the object, and a twin destructor must not call into
|
||||
// a driver that may already be unloaded), not something to be collected later.
|
||||
//
|
||||
// P5e (id, CONTRACT-P5E §4.1): ForEachLive() NO LONGER HANDS IT OUT. It answers
|
||||
// fn(MGPipeHandle, const BackendPtr&), because a walk that produced a frontend SharedPtr out
|
||||
// of server memory was the last place the server could hold one across records - and a caller
|
||||
// that still needs the object (the detach walk) asks StateForHandle for it BY HANDLE, inside
|
||||
// the scope that names the debt, so the read is one greppable site rather than a property of
|
||||
// the iteration.
|
||||
//
|
||||
// P3+ DEBT, recorded rather than hidden: this header is under MG_Backend/ and it MINTS
|
||||
// handles (MGPipeSlots().Acquire below) off a frontend SharedPtr's GetLifetimeId().
|
||||
@@ -81,6 +87,20 @@
|
||||
// Fatal{RoleViolation, "MGPipeSlots"} when reached from the apply thread (the same check the
|
||||
// allocator's own three entries carry, repeated here so the refusal names this surface), and
|
||||
// the split paths resolve through GetOrCreate(handle) / ReleaseByHandle instead.
|
||||
//
|
||||
// P5e (id, CONTRACT-P5E §4.1 / §5.8) SETTLES WHAT HAPPENS TO THE FRONTEND-KEYED HALF: it is
|
||||
// NOT deleted. The push build under Transport=monolith keeps its frontend arms token for token
|
||||
// (ruling 1), which is what the MOBILEGL_PIPE_VERIFY comparator needs and what makes
|
||||
// MOBILEGL_IPC_RUN_AHEAD=0 a pure wait-rule A/B on identical server code. So
|
||||
// GetOrCreate(StatePtr), Find(StateObject*), HandleOf, NoteStateForHandle/StateForHandle,
|
||||
// Entry::stateRef and the resolution memo all survive - as MONOLITH GLUE, each of them a NAMED
|
||||
// FATAL the moment it is reached from an apply thread that is applying an UNBARRIERED record
|
||||
// (§4.4: the client's wait is the only thing that makes such a read stable, and an unbarriered
|
||||
// record has none). The refusal is raised either by the allocator guard, for the three members
|
||||
// that call the allocator, or by MGPipeRefuseFrontendKeyedRegistryFromUnbarrieredApply for the
|
||||
// three that do not. There is no silent path: the phase's claim is that the twin is resolved
|
||||
// from the handle the record carried, and a surface that quietly answered from a frontend
|
||||
// pointer instead would make that claim untestable.
|
||||
namespace MobileGL::MG_Backend::DirectGLES {
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
@@ -153,12 +173,34 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// is letting a corrupt 32-bit slot decide a vector resize. See GetOrCreate(MGPipeHandle).
|
||||
static constexpr Uint32 kMaxHandleSlot = 1u << 20;
|
||||
|
||||
// P5e (id), CONTRACT-P5E §4.3: THE COMPOSITE BAND, and it is a P5e PREREQUISITE rather
|
||||
// than a follow-up. ShaderCso's top 1/16 of slot space (from
|
||||
// kMGPipeShaderCsoCompositeSlotBase = 983040) is the program-pipeline composites'
|
||||
// (MGPipeHandles.h); EntryAt below indexes m_slots BY SLOT and resizes to it, so a
|
||||
// single composite used to grow g_backendProgramObjects to ~983k entries of ~40 B -
|
||||
// ~40 MB for one program pipeline. Today that is reachable only through
|
||||
// GetOrCreate(StatePtr) for a composite program; after the rekey the by-handle
|
||||
// resolution IS the ordinary path, so every composite bind would pay it.
|
||||
//
|
||||
// A SECOND VECTOR RATHER THAN MORE OF THE FIRST, exactly as the allocator
|
||||
// (SlotAllocator.h's KindState::BandSlots) and the applier (PipeApply.h's
|
||||
// CompositeShaderCsos) already do, and for the same reason: both spaces stay dense
|
||||
// against their own high-water mark, which is the property that lets the server index
|
||||
// rather than hash. The band is EMPTY for every kind but ShaderCso and costs those
|
||||
// kinds one empty Vector per table.
|
||||
static constexpr Bool kHasCompositeBand = (kKind == MG_Pipe::MGPipeKind::ShaderCso);
|
||||
static constexpr SizeT kMaxBandSlots =
|
||||
MG_Pipe::kMGPipeShaderCsoSlotLimit - MG_Pipe::kMGPipeShaderCsoCompositeSlotBase;
|
||||
|
||||
struct Entry {
|
||||
BackendPtr backend;
|
||||
// LIVENESS ONLY, and only for ForEachLive(), which locks it so the callee holds a
|
||||
// strong ref. Never compared against another object to decide identity - that is
|
||||
// what Gen is for - never dereferenced for its address, and never read to decide
|
||||
// whether the slot is dead: death is announced, not discovered.
|
||||
// THE MONOLITH-GLUE HALF of the entry (P5e, CONTRACT-P5E §4.1): written by the
|
||||
// minting GetOrCreate and by NoteStateForHandle, read only by StateForHandle and
|
||||
// the legacy death notice. Never compared against another object to decide identity
|
||||
// - that is what Gen is for - never dereferenced for its address, and never read to
|
||||
// decide whether the slot is dead: death is announced, not discovered. ForEachLive
|
||||
// stopped reading it at P5e: a walk that handed a frontend SharedPtr out of server
|
||||
// memory on every step was the last place the server could hold one across records.
|
||||
StateWeakPtr stateRef;
|
||||
// The generation this entry's twin was built for. An entry whose Gen no longer
|
||||
// matches the allocator's is a twin of the slot's PREVIOUS owner.
|
||||
@@ -173,6 +215,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BackendSlotTable() { LinkHolder(); }
|
||||
BackendSlotTable(const BackendSlotTable& other):
|
||||
m_slots(other.m_slots),
|
||||
m_band(other.m_band),
|
||||
m_nullTwin(other.m_nullTwin),
|
||||
m_memoLifetimeId(other.m_memoLifetimeId),
|
||||
m_memoHandle(other.m_memoHandle) {
|
||||
@@ -180,16 +223,19 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
BackendSlotTable(BackendSlotTable&& other) noexcept:
|
||||
m_slots(std::move(other.m_slots)),
|
||||
m_band(std::move(other.m_band)),
|
||||
m_nullTwin(std::move(other.m_nullTwin)),
|
||||
m_memoLifetimeId(other.m_memoLifetimeId),
|
||||
m_memoHandle(other.m_memoHandle) {
|
||||
other.m_slots.clear();
|
||||
other.m_band.clear();
|
||||
other.ForgetHandle();
|
||||
LinkHolder();
|
||||
}
|
||||
BackendSlotTable& operator=(const BackendSlotTable& other) {
|
||||
if (this != &other) {
|
||||
m_slots = other.m_slots;
|
||||
m_band = other.m_band;
|
||||
m_nullTwin = other.m_nullTwin;
|
||||
m_memoLifetimeId = other.m_memoLifetimeId;
|
||||
m_memoHandle = other.m_memoHandle;
|
||||
@@ -199,10 +245,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BackendSlotTable& operator=(BackendSlotTable&& other) noexcept {
|
||||
if (this != &other) {
|
||||
m_slots = std::move(other.m_slots);
|
||||
m_band = std::move(other.m_band);
|
||||
m_nullTwin = std::move(other.m_nullTwin);
|
||||
m_memoLifetimeId = other.m_memoLifetimeId;
|
||||
m_memoHandle = other.m_memoHandle;
|
||||
other.m_slots.clear();
|
||||
other.m_band.clear();
|
||||
other.ForgetHandle();
|
||||
}
|
||||
return *this;
|
||||
@@ -241,6 +289,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// overload below. (The check also lives at the allocator's own three entries; it
|
||||
// is repeated at this entry so the refusal names this surface even if the entry
|
||||
// set changes.)
|
||||
//
|
||||
// P5e (id, §4.4): that one call is also this member's unbarriered-apply refusal.
|
||||
// The guard exempts a probe only inside a named scope AND while the record being
|
||||
// applied is barriered, so reaching a MINT from an unbarriered apply aborts here
|
||||
// whatever scope is open - which is what "kept only as monolith glue" has to mean
|
||||
// if it is to be checkable.
|
||||
MG_Pipe::MGPipeRefuseAllocatorFromApplyThread("GetOrCreate(StatePtr)");
|
||||
#endif
|
||||
|
||||
@@ -279,10 +333,13 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// so the twin at it describes driver ids the new resource never made) and hand back
|
||||
// the twin pointer. FindByHandle beside it is the same shape and already existed.
|
||||
//
|
||||
// No StatePtr, therefore no Entry::stateRef: the weak pointer is liveness for
|
||||
// ForEachLive() and a handle-keyed entry has no frontend object to weakly hold. Such
|
||||
// an entry is therefore invisible to ForEachLive, which is correct - the one direct
|
||||
// iteration site walks texture twins, and it is not one of these tables.
|
||||
// No StatePtr, therefore no Entry::stateRef unless a caller that holds the object notes
|
||||
// it (NoteStateForHandle): a handle-keyed entry has no frontend object to weakly hold
|
||||
// by itself. P5e (§4.1) makes that stop mattering for the iteration - ForEachLive keys
|
||||
// on Live && backend, so such an entry is VISIBLE to the walk and it is StateForHandle,
|
||||
// asked by the one caller that needs the object, that answers null for it. Which is the
|
||||
// same set the old stateRef-locking walk produced, decided at one site instead of in
|
||||
// the loop.
|
||||
//
|
||||
// Death stays ANNOUNCED, as it is on the other overload: for a handle-keyed kind the
|
||||
// announcement is the family's own destroy call, not the shared death notice, and the
|
||||
@@ -345,38 +402,48 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// holds no live entry. It exists so a caller can DIAGNOSE - in a release build, where
|
||||
// MOBILEGL_ASSERT is inert - the refusal GetOrCreate(handle) above performs silently.
|
||||
Uint32 LiveGenAt(Uint32 slot) const {
|
||||
if (slot >= m_slots.size()) return 0;
|
||||
const Entry& entry = m_slots[slot];
|
||||
return entry.Live ? entry.Gen : 0;
|
||||
const Entry* const entry = EntryOrNull(slot);
|
||||
if (entry == nullptr) return 0;
|
||||
return entry->Live ? entry->Gen : 0;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5c (hd): remember the frontend object a HANDLE-keyed twin was synced from. The
|
||||
// minting overload sets stateRef itself; the handle overload cannot (no object
|
||||
// crosses), so a caller that legitimately holds the object - the record-driven sync,
|
||||
// which arrived holding it through the object-class barrier-pulled rows - notes it
|
||||
// here. It is what lets a later handle-only resolution (P5c's named blit) reach the
|
||||
// frontend object the twin's sync body still walks, without probing the client's slot
|
||||
// allocator (T2). Same liveness rules as the minted stateRef: never an identity test,
|
||||
// never read to decide the slot is dead.
|
||||
// here. It is what lets a later handle-only resolution (P5c's named blit, and P5e's
|
||||
// re-typed ForEachLive) reach the frontend object the twin's sync body still walks,
|
||||
// without probing the client's slot allocator (T2). Same liveness rules as the minted
|
||||
// stateRef: never an identity test, never read to decide the slot is dead.
|
||||
//
|
||||
// P5e (id): the pair is now compiled under MOBILEGL_PIPE_PUSH rather than
|
||||
// MOBILEGL_BUILD_DISAGGREGATED, because ForEachLive's caller needs it in the
|
||||
// push-monolith build too, where the note is simply always present. And each half is a
|
||||
// NAMED FATAL from an unbarriered apply (§4.4): they answer from a frontend SharedPtr
|
||||
// that only the client's wait pins, so without that wait the object they hand back may
|
||||
// already be the client's next one. Neither touches the allocator, so the allocator
|
||||
// guard never sees them - this is their own refusal.
|
||||
void NoteStateForHandle(MG_Pipe::MGPipeHandle handle, const StatePtr& stateObj) {
|
||||
if (MG_Pipe::MGPipeHandleIsNull(handle) || handle.Slot >= m_slots.size()) return;
|
||||
Entry& entry = m_slots[handle.Slot];
|
||||
if (!entry.Live || entry.Gen != handle.Gen) return;
|
||||
entry.stateRef = stateObj;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MG_Pipe::MGPipeRefuseFrontendKeyedRegistryFromUnbarrieredApply("NoteStateForHandle");
|
||||
#endif
|
||||
if (MG_Pipe::MGPipeHandleIsNull(handle)) return;
|
||||
Entry* const entry = EntryOrNull(handle.Slot);
|
||||
if (entry == nullptr || !entry->Live || entry->Gen != handle.Gen) return;
|
||||
entry->stateRef = stateObj;
|
||||
}
|
||||
|
||||
// The frontend object noted for this handle, or null. The handle answers identity;
|
||||
// this answers only "which object was this twin last synced from".
|
||||
StatePtr StateForHandle(MG_Pipe::MGPipeHandle handle) const {
|
||||
if (MG_Pipe::MGPipeHandleIsNull(handle) || handle.Slot >= m_slots.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
const Entry& entry = m_slots[handle.Slot];
|
||||
if (!entry.Live || entry.Gen != handle.Gen) return nullptr;
|
||||
return entry.stateRef.lock();
|
||||
}
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MG_Pipe::MGPipeRefuseFrontendKeyedRegistryFromUnbarrieredApply("StateForHandle");
|
||||
#endif
|
||||
if (MG_Pipe::MGPipeHandleIsNull(handle)) return nullptr;
|
||||
const Entry* const entry = EntryOrNull(handle.Slot);
|
||||
if (entry == nullptr || !entry->Live || entry->Gen != handle.Gen) return nullptr;
|
||||
return entry->stateRef.lock();
|
||||
}
|
||||
|
||||
// P3a: the death half of the overload above, for a kind whose announcement is its own
|
||||
// destroy CALL rather than the shared death notice (D-L). Hands the twin OUT rather
|
||||
@@ -394,13 +461,12 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BackendPtr ReleaseByHandle(MG_Pipe::MGPipeHandle handle) {
|
||||
if (MG_Pipe::MGPipeHandleIsNull(handle)) return BackendPtr{};
|
||||
if (m_memoHandle.Slot == handle.Slot) ForgetHandle();
|
||||
if (handle.Slot >= m_slots.size()) return BackendPtr{};
|
||||
Entry& entry = m_slots[handle.Slot];
|
||||
if (!entry.Live || entry.Gen != handle.Gen) return BackendPtr{};
|
||||
BackendPtr dead = std::move(entry.backend);
|
||||
entry.backend.reset();
|
||||
entry.stateRef.reset();
|
||||
entry.Live = false;
|
||||
Entry* const entry = EntryOrNull(handle.Slot);
|
||||
if (entry == nullptr || !entry->Live || entry->Gen != handle.Gen) return BackendPtr{};
|
||||
BackendPtr dead = std::move(entry->backend);
|
||||
entry->backend.reset();
|
||||
entry->stateRef.reset();
|
||||
entry->Live = false;
|
||||
return dead;
|
||||
}
|
||||
|
||||
@@ -419,10 +485,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
|
||||
BackendPtr* FindByHandle(MG_Pipe::MGPipeHandle handle) {
|
||||
if (MG_Pipe::MGPipeHandleIsNull(handle)) return nullptr;
|
||||
if (handle.Slot >= m_slots.size()) return nullptr;
|
||||
Entry& entry = m_slots[handle.Slot];
|
||||
if (!entry.Live || entry.Gen != handle.Gen) return nullptr;
|
||||
return &entry.backend;
|
||||
Entry* const entry = EntryOrNull(handle.Slot);
|
||||
if (entry == nullptr || !entry->Live || entry->Gen != handle.Gen) return nullptr;
|
||||
return &entry->backend;
|
||||
}
|
||||
|
||||
// The handle this object's twin is keyed on, or the null handle. This is what a backend
|
||||
@@ -438,6 +503,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5c (hd): same guard as the minting overload - a lifetime-id probe from the
|
||||
// apply thread is Fatal{RoleViolation, "MGPipeSlots"} with an active transport.
|
||||
// P5e (id, §4.4): and now also whenever the record being applied is UNBARRIERED,
|
||||
// scope or no scope. This member and Find(StateObject*) below it are the two the
|
||||
// per-family packages retire by passing the handle the record carried instead.
|
||||
MG_Pipe::MGPipeRefuseAllocatorFromApplyThread("HandleOf");
|
||||
#endif
|
||||
const Uint64 lifetimeId = stateObj->GetLifetimeId();
|
||||
@@ -517,11 +585,23 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return count;
|
||||
}
|
||||
|
||||
// fn(const StatePtr& state, const BackendPtr& twin) over every live, still-owned entry.
|
||||
// Replaces the registry's begin()/end(), whose iterator exposed the raw frontend
|
||||
// address as the map key - the one place the backend read an identity it must not have.
|
||||
// The state object is handed over as a STRONG reference, so the callee cannot be handed
|
||||
// a dangling key the way the old iteration could.
|
||||
// P5e (id), CONTRACT-P5E §4.1: fn(MGPipeHandle, const BackendPtr& twin) over every
|
||||
// live, twinned entry. Replaces the registry's begin()/end(), whose iterator exposed
|
||||
// the raw frontend address as the map key - the one place the backend read an identity
|
||||
// it must not have - and replaces P3a's own fn(StatePtr, BackendPtr), which handed a
|
||||
// frontend SharedPtr OUT OF SERVER MEMORY on every step.
|
||||
//
|
||||
// WHAT THE CALLER LOST AND HOW IT GETS IT BACK, because the two are not the same thing.
|
||||
// The walk no longer locks Entry::stateRef, so a caller that needs the frontend object
|
||||
// asks StateForHandle(handle) for it - which is the same weak reference, read at one
|
||||
// named site inside the scope that owns the debt, instead of at every step of an
|
||||
// iteration. Coverage is UNCHANGED by construction: an entry ForEachLive used to skip
|
||||
// because its stateRef did not lock is one whose StateForHandle answers null, and the
|
||||
// caller skips it there instead.
|
||||
//
|
||||
// The handle is the entry's own {slot, gen}, band-aware: a composite ShaderCso's slot
|
||||
// is reported as kMGPipeShaderCsoCompositeSlotBase + its band index, i.e. the slot the
|
||||
// client minted, never the index into m_band.
|
||||
template <typename Fn>
|
||||
void ForEachLive(Fn&& fn) const {
|
||||
// Index loop and a COPIED twin, not a range-for over references: fn is arbitrary
|
||||
@@ -529,13 +609,20 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// invalidate both the iterator and any reference into the vector that outlives the
|
||||
// call. The one caller today happens not to insert; that is not a property the
|
||||
// walk should depend on.
|
||||
for (SizeT slot = 0; slot < m_slots.size(); ++slot) {
|
||||
const Entry& entry = m_slots[slot];
|
||||
for (SizeT index = 0; index < m_slots.size(); ++index) {
|
||||
const Entry& entry = m_slots[index];
|
||||
if (!entry.Live || !entry.backend) continue;
|
||||
const StatePtr state = entry.stateRef.lock();
|
||||
if (!state) continue;
|
||||
const BackendPtr twin = entry.backend;
|
||||
fn(state, twin);
|
||||
fn(MG_Pipe::MGPipeHandle{static_cast<Uint32>(index), entry.Gen}, twin);
|
||||
}
|
||||
for (SizeT index = 0; index < m_band.size(); ++index) {
|
||||
const Entry& entry = m_band[index];
|
||||
if (!entry.Live || !entry.backend) continue;
|
||||
const BackendPtr twin = entry.backend;
|
||||
fn(MG_Pipe::MGPipeHandle{
|
||||
static_cast<Uint32>(index) + MG_Pipe::kMGPipeShaderCsoCompositeSlotBase,
|
||||
entry.Gen},
|
||||
twin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,9 +631,29 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
for (const Entry& entry : m_slots) {
|
||||
if (entry.Live) ++count;
|
||||
}
|
||||
for (const Entry& entry : m_band) {
|
||||
if (entry.Live) ++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// The band's own live count, so a case can tell "the composite is twinned" from "the
|
||||
// ordinary table grew to reach it" - which is the whole assertion the band exists for
|
||||
// and is untestable from LiveCount alone.
|
||||
Uint32 CompositeLiveCount() const {
|
||||
Uint32 count = 0;
|
||||
for (const Entry& entry : m_band) {
|
||||
if (entry.Live) ++count;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// How many entries each space has ALLOCATED, live or not. A leak case asserts on these
|
||||
// rather than on LiveCount: growth is what the band prevents, and a dense table that
|
||||
// never shrinks is invisible to a liveness count.
|
||||
SizeT OrdinaryCapacityForTest() const { return m_slots.size(); }
|
||||
SizeT CompositeCapacityForTest() const { return m_band.size(); }
|
||||
|
||||
private:
|
||||
// Drop the twin at `handle` if THIS table holds it. Frees nothing: the slot belongs to
|
||||
// the kind, not to the table, and OnFrontendObjectDestroyed returns it once, after
|
||||
@@ -556,31 +663,61 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// there: a memo can be a handle learned from the allocator for an object another
|
||||
// holder twinned, and it must not survive the slot's next handout.
|
||||
if (m_memoHandle.Slot == handle.Slot) ForgetHandle();
|
||||
if (handle.Slot >= m_slots.size()) return false;
|
||||
// The twin's destructor is a driver call and could, in principle, re-enter
|
||||
// GetOrCreate on this table and resize m_slots. So NOTHING that outlives the
|
||||
// destructor may be a reference into m_slots: the twin is moved out into a local,
|
||||
// the entry is finished with, and only then is the local released.
|
||||
BackendPtr dead;
|
||||
{
|
||||
Entry& entry = m_slots[handle.Slot];
|
||||
if (!entry.Live || entry.Gen != handle.Gen) return false;
|
||||
dead = std::move(entry.backend);
|
||||
entry.backend.reset();
|
||||
entry.stateRef.reset();
|
||||
entry.Live = false;
|
||||
Entry* const entry = EntryOrNull(handle.Slot);
|
||||
if (entry == nullptr || !entry->Live || entry->Gen != handle.Gen) return false;
|
||||
dead = std::move(entry->backend);
|
||||
entry->backend.reset();
|
||||
entry->stateRef.reset();
|
||||
entry->Live = false;
|
||||
}
|
||||
dead.reset();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Grows the table to hold `slot`. Every caller bounds `slot` first - the minting
|
||||
// ---- P5e (id): the two slot spaces, resolved in ONE place ---------------------------
|
||||
//
|
||||
// Every reader and writer below goes through these three, so a caller that forgot the
|
||||
// band cannot exist - the shape MGPipeSlotAllocator::EntryOf already uses one level
|
||||
// out. kHasCompositeBand folds to `false` at compile time for the five non-ShaderCso
|
||||
// instantiations, so their band is dead code and an empty Vector.
|
||||
static constexpr Bool SlotIsBanded(Uint32 slot) {
|
||||
return kHasCompositeBand && MG_Pipe::MGPipeIsCompositeShaderSlot(slot);
|
||||
}
|
||||
static constexpr SizeT IndexOfSlot(Uint32 slot) {
|
||||
return SlotIsBanded(slot)
|
||||
? static_cast<SizeT>(slot - MG_Pipe::kMGPipeShaderCsoCompositeSlotBase)
|
||||
: static_cast<SizeT>(slot);
|
||||
}
|
||||
|
||||
// The entry a slot names, or null when its space has never grown that far. NEVER grows:
|
||||
// a lookup that resized would turn every miss into an allocation, which is the hazard
|
||||
// Find documents.
|
||||
Entry* EntryOrNull(Uint32 slot) {
|
||||
Vector<Entry>& table = SlotIsBanded(slot) ? m_band : m_slots;
|
||||
const SizeT index = IndexOfSlot(slot);
|
||||
if (index >= table.size()) return nullptr;
|
||||
return &table[index];
|
||||
}
|
||||
const Entry* EntryOrNull(Uint32 slot) const {
|
||||
return const_cast<BackendSlotTable*>(this)->EntryOrNull(slot);
|
||||
}
|
||||
|
||||
// Grows the right space to hold `slot`. Every caller bounds `slot` first - the minting
|
||||
// overload because the allocator produced it, the handle overload against
|
||||
// kMaxHandleSlot - because this is the one place a client-supplied number decides an
|
||||
// allocation size.
|
||||
// allocation size. A composite slot grows m_band by (slot - base) + 1, so the ordinary
|
||||
// table never learns the band exists.
|
||||
Entry& EntryAt(Uint32 slot) {
|
||||
if (slot >= m_slots.size()) m_slots.resize(static_cast<SizeT>(slot) + 1);
|
||||
return m_slots[slot];
|
||||
Vector<Entry>& table = SlotIsBanded(slot) ? m_band : m_slots;
|
||||
const SizeT index = IndexOfSlot(slot);
|
||||
if (index >= table.size()) table.resize(index + 1);
|
||||
return table[index];
|
||||
}
|
||||
|
||||
void RememberHandle(Uint64 lifetimeId, MG_Pipe::MGPipeHandle handle) const {
|
||||
@@ -621,6 +758,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
|
||||
// Indexed by MGPipeHandle::Slot; [0] is the reserved slot and is never live.
|
||||
Vector<Entry> m_slots;
|
||||
// P5e (id): the ShaderCso COMPOSITE band, indexed by (slot -
|
||||
// kMGPipeShaderCsoCompositeSlotBase) and EMPTY for every other kind. See
|
||||
// kHasCompositeBand above for why it is a second vector and not more of the first.
|
||||
Vector<Entry> m_band;
|
||||
// Handed back by GetOrCreate for a null state object. Never live, never handed a handle.
|
||||
BackendPtr m_nullTwin;
|
||||
|
||||
|
||||
@@ -4551,7 +4551,12 @@ void main() {
|
||||
// delete, so the scope admits the probe as named debt rather than letting the guard
|
||||
// Fatal at server teardown. P7 gives these resources storage that is not a frontend
|
||||
// object.
|
||||
const MG_Pipe::MGPipeFrontendKeyedRegistryScope frontendKeyedRegistry;
|
||||
//
|
||||
// P5e (id), ruling 12: one of Magma's FOUR apply-thread allocator debts, and the scope
|
||||
// is now named after that debt rather than after the frontend-keyed registry - Espryt's
|
||||
// half of which P5e is retiring, while this one waits for P7. The exemption is keyed on
|
||||
// a DirectVulkan server, which is what this file always is.
|
||||
const MG_Pipe::MagmaP7AllocatorDebtScope magmaP7AllocatorDebt;
|
||||
#endif
|
||||
m_blitResources = {};
|
||||
}
|
||||
@@ -4630,8 +4635,9 @@ void main() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// Same shape as ShutdownBlitResources above: the hidden depth-mipmap program is a
|
||||
// frontend object created and destroyed by the server backend on the apply thread, and
|
||||
// its destructor's lifetime-id probe is admitted here as named debt.
|
||||
const MG_Pipe::MGPipeFrontendKeyedRegistryScope frontendKeyedRegistry;
|
||||
// its destructor's lifetime-id probe is admitted here as named debt - Magma's, P7's to
|
||||
// retire, which is what the scope's P5e name says (ruling 12).
|
||||
const MG_Pipe::MagmaP7AllocatorDebtScope magmaP7AllocatorDebt;
|
||||
#endif
|
||||
m_depthMipmapResources = {};
|
||||
}
|
||||
@@ -8974,8 +8980,11 @@ void main() {
|
||||
// the resolution here is frontend-keyed - the handle was minted over the frontend
|
||||
// object's lifetime id, and the two probes below (the client allocator's slot entry
|
||||
// and the frontend context's framebuffer pool) are named debt inside the scope, the
|
||||
// same shape as Espryt's StateForHandle arm: P3b/P4b retire it by carrying the object
|
||||
// identity in the record.
|
||||
// same shape as Espryt's StateForHandle arm: P7 retires it by carrying the object
|
||||
// identity in the record. P5e (id), ruling 12: the third of Magma's four debts, so the
|
||||
// scope it rides in is MagmaP7AllocatorDebtScope. Magma stays lockstep for the whole of
|
||||
// P5e (CONTRACT-P5E §6.1), so the record being applied here is always barriered and the
|
||||
// exemption still holds.
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
auto& applierState = MG_Pipe::MGPipeApplier();
|
||||
const MG_Pipe::MGPipeHandle readHandle = applierState.VerbBlitReadFbo;
|
||||
@@ -8983,7 +8992,7 @@ void main() {
|
||||
if (!MG_Pipe::MGPipeHandleIsNull(readHandle) || !MG_Pipe::MGPipeHandleIsNull(drawHandle)) {
|
||||
const auto resolveEndpoint = [](MG_Pipe::MGPipeHandle handle)
|
||||
-> SharedPtr<MG_State::GLState::FramebufferObject> {
|
||||
const MG_Pipe::MGPipeFrontendKeyedRegistryScope frontendKeyedRegistry;
|
||||
const MG_Pipe::MagmaP7AllocatorDebtScope magmaP7AllocatorDebt;
|
||||
if (handle == MG_Pipe::kMGPipeDefaultFramebuffer) {
|
||||
return MG_State::pGLContext ? MG_State::pGLContext->GetFramebufferObject(0) : nullptr;
|
||||
}
|
||||
|
||||
@@ -81,9 +81,37 @@ namespace MobileGL::MG_Backend {
|
||||
// DirectVulkan registers NO resource ops - MGPipeSetResourceOps has exactly one caller
|
||||
// in the whole tree and it is Managers.cpp:2594 - so bit 7 is CLEAR for it, which is
|
||||
// the same fact ObjectSubsystemControlScenario already pins from the client side.
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §6.2). THE ONE CONSTANT THE WHOLE PHASE HANGS ON.
|
||||
//
|
||||
// kCapRunAheadApply says "this server applies an unbarriered record without reading
|
||||
// client memory". That is only true once EVERY per-draw family reads records instead
|
||||
// of the frontend - vi, sb, pg, tx2 and fb all land before it is - so the caps arm
|
||||
// below is gated on this constant, which the P5e INTEGRATION COMMIT flips to true
|
||||
// after the last of them. Until then every P5e package lands with the wait rule, the
|
||||
// static WaitClass column and the barriered predicate compiled and INERT: the client
|
||||
// never latches RunAheadArmed, so it runs today's lockstep path byte for byte.
|
||||
//
|
||||
// It is a constant and not a knob on purpose. An operator cannot turn a half-migrated
|
||||
// server into a run-ahead one, because the failure mode is not a slow frame - it is
|
||||
// the apply thread reading client memory that has already moved, which renders wrong
|
||||
// rather than aborting.
|
||||
constexpr Bool kMGPipeP5eRunAheadReady = false;
|
||||
|
||||
// P5e (sb, ID-106). DirectGLES GAINS BIT 13 - the indexed buffer binding points - and
|
||||
// Magma deliberately does not. c0e landed the phase constant and the dirty-bit map with
|
||||
// this row still reading P4a's mask, because withholding a consumer bit is the safe
|
||||
// direction while no emitter exists: the client's R-8 gate then keeps the whole family
|
||||
// on the legacy pull path. The moment ShaderBufferEmit.h's wired constant leaves 0 the
|
||||
// two have to move together, so they are one commit.
|
||||
//
|
||||
// DIRECTVULKAN STAYS ON P4a's MASK. The bit says "this server reads set_shader_buffers
|
||||
// instead of walking the client's binding-point table", and Magma's UniformManager does
|
||||
// no such thing - it has no binding-point records at all, and P5e leaves it lockstep
|
||||
// (CONTRACT-P5E.md §6). Claiming the bit there would make the client emit a family
|
||||
// nothing consumes, which is ID-39's failure with a different family's name on it.
|
||||
Uint64 ConsumedSubsystemsFor(BackendType type) {
|
||||
switch (type) {
|
||||
case BackendType::DirectGLES: return MG_Pipe::kMGPipeSubsystemsMigratedAtP4a;
|
||||
case BackendType::DirectGLES: return MG_Pipe::kMGPipeSubsystemsMigratedAtP5e;
|
||||
case BackendType::DirectVulkan:
|
||||
return MG_Pipe::kMGPipeSubsystemsMigratedAtP4a & ~MG_Pipe::kMGPipeSubsystemResources;
|
||||
default: return 0;
|
||||
@@ -166,6 +194,21 @@ namespace MobileGL::MG_Backend {
|
||||
serverBackend->GetBackendFunctions().GL.EndTransformFeedback != nullptr) {
|
||||
capBits |= MG_Pipe::kCapBackendOwnsXfbCapture;
|
||||
}
|
||||
// P5e (CONTRACT-P5E.md §1, §6): kCapRunAheadApply, THE DIRECTGLES ARM AND ONLY IT.
|
||||
//
|
||||
// Magma is deliberately absent and is not an omission: it keeps the lockstep for
|
||||
// the whole of P5e, its four apply-thread allocator sites are real debt P7 retires,
|
||||
// and MGPipeApplierCurrentRecordIsBarriered() answers true for every record on a
|
||||
// server that does not publish this bit - which is exactly what keeps those probes
|
||||
// and its BARRIER_PULLED reads inside P5C's semantics and its rsp accounting
|
||||
// honest. Publishing the bit here for DirectVulkan would turn accounted pulls into
|
||||
// torn ones, so MagmaPipeIdentityTest pins its absence.
|
||||
//
|
||||
// The Espryt arm is gated on kMGPipeP5eRunAheadReady, which is false until the
|
||||
// integration commit: the bit is what ARMS the client, so every package before it
|
||||
// lands inert.
|
||||
capBits |= MG_Pipe::MGPipeRunAheadCapBitsFor(MG_Config::ActiveBackendType,
|
||||
kMGPipeP5eRunAheadReady);
|
||||
session.SetCapabilityBits(capBits);
|
||||
session.SetBackend(loop.Backend());
|
||||
|
||||
|
||||
@@ -58,22 +58,50 @@ namespace MobileGL::MG_Pipe {
|
||||
// existing filter on Fatal{UnmigratedPipeInput still matches, plus the class and the
|
||||
// phase that retires it - a strict abort that did not say which phase owes the answer
|
||||
// would leave the reader exactly where the gate found them.
|
||||
[[noreturn]] void StrictBarrierPullFatal(MGPipeInputField field, MGPipeVerb verb) {
|
||||
// P5e (ra): `why` is the second half of the marker, because the lane's allowlist step
|
||||
// reads this line and the two reasons mean different things to it. "MOBILEGL_IPC_
|
||||
// STRICT_ERRORS=1" is the operator asking for a real, ordered value to be loud;
|
||||
// "UNBARRIERED" is the value not existing (§3.3). The `<field>@<verb>` prefix and the
|
||||
// Fatal{UnmigratedPipeInput tag are unchanged, so every filter written since P5c still
|
||||
// matches.
|
||||
[[noreturn]] void StrictBarrierPullFatal(MGPipeInputField field, MGPipeVerb verb,
|
||||
const char* why) {
|
||||
const SizeT index = static_cast<SizeT>(field);
|
||||
MGLOG_F("MGPipe: Fatal{UnmigratedPipeInput, \"%s@%s\"} [BARRIER-PULLED, "
|
||||
"MOBILEGL_IPC_STRICT_ERRORS=1, retires in %s]",
|
||||
kMGPipeInputFieldNames[index], MGPipeVerbName(verb), kMGPipeFieldRetiringPhase[index]);
|
||||
MGLOG_F("MGPipe: Fatal{UnmigratedPipeInput, \"%s@%s\"} [BARRIER-PULLED, %s, "
|
||||
"retires in %s]",
|
||||
kMGPipeInputFieldNames[index], MGPipeVerbName(verb), why,
|
||||
kMGPipeFieldRetiringPhase[index]);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// One place decides what a BARRIER-PULLED read does, so the field accessors and the
|
||||
// seven sticky forwards cannot drift apart on it.
|
||||
//
|
||||
// ---- P5e (ra), CONTRACT-P5E §3.3: THE DETECTOR IS UNCONDITIONAL UNDER AN UNBARRIERED
|
||||
// RECORD, AND THAT IS WHAT MAKES THE STRICT LANE A GATE -------------------------------
|
||||
//
|
||||
// The knob exists because under LOCKSTEP a pulled row is a real, ordered, fresh value:
|
||||
// the client filled it and then parked, so "count it and carry on" is an honest
|
||||
// measurement of remaining debt and MOBILEGL_IPC_STRICT_ERRORS is the operator asking
|
||||
// for the debt to be loud instead. None of that survives run-ahead. With the client
|
||||
// running ahead of this apply, the row was either never filled for this verb (§3.1
|
||||
// skips the fill) or is being overwritten by a verb two frames later - so the value is
|
||||
// torn or stale BY CONSTRUCTION and there is nothing for a counter to count. A
|
||||
// "count it" arm here would be a wrong picture with a number beside it.
|
||||
//
|
||||
// rsp is therefore 0 on unbarriered records in every scenario summary (§7's pin): a
|
||||
// non-zero count would be an abort that did not fire.
|
||||
void CountBarrierPull(MGPipeInputField field, MGPipeVerb verb) {
|
||||
if (!MGPipeApplierCurrentRecordIsBarriered()) {
|
||||
StrictBarrierPullFatal(field, verb, "UNBARRIERED, the client did not fill it");
|
||||
}
|
||||
++g_residualPulls;
|
||||
if (MG_Util::PipeStats::Enabled()) {
|
||||
MG_Util::PipeStats::AddCalls(MG_Util::PipeStats::CallClass::ResidualPulls, 1);
|
||||
}
|
||||
if (MG_Config::Ipc.StrictErrors) StrictBarrierPullFatal(field, verb);
|
||||
if (MG_Config::Ipc.StrictErrors) {
|
||||
StrictBarrierPullFatal(field, verb, "MOBILEGL_IPC_STRICT_ERRORS=1");
|
||||
}
|
||||
}
|
||||
|
||||
// The verb's OWN may-read table (FillPoints.def, kMGPipeClassFieldMask). The stamp
|
||||
@@ -87,6 +115,58 @@ namespace MobileGL::MG_Pipe {
|
||||
const MGPipeVerbClass verbClass = kMGPipeVerbClass[verbIndex];
|
||||
return MGPipeFieldMaskHas(kMGPipeClassFieldMask[static_cast<SizeT>(verbClass)], field);
|
||||
}
|
||||
|
||||
// ---- the same verdict, per verb CLASS, as a constant (P5d round 3, package C) ----
|
||||
//
|
||||
// THE STAMP's ANSWER IS A CONSTANT OF THE VERB CLASS AND OF NOTHING ELSE. Both halves of
|
||||
// `answerable` below read constexpr tables only - kMGPipeFieldOwnership, kMGPipeVerbClass
|
||||
// and kMGPipeClassFieldMask - so the 63-field loop was recomputing, at every verb on the
|
||||
// apply thread, a table the compiler can build once. The 2026-09-17 inproc profile put
|
||||
// MGPipeServerStampVerbBoundary at 1.1% self of the apply thread (Minecraft 26.3-rc-3,
|
||||
// ~852 draws/frame), and every cycle taken there is a cycle the lockstep client waits for.
|
||||
//
|
||||
// IT IS A MASK, NOT A BOOL ARRAY, so the stamp loop's body stays a shift and a store with
|
||||
// no branch: FilledGen[i] = serial & -bit, which is `serial` for an answerable field and
|
||||
// the WITHDRAWAL 0 for every other. The verdict itself is unchanged, and it is still
|
||||
// computed by the one expression argued at the stamp - it just runs at compile time.
|
||||
constexpr MGPipeFieldMask AnswerableMaskForClass(MGPipeVerbClass verbClass) {
|
||||
MGPipeFieldMask mask{};
|
||||
for (SizeT i = 0; i < kMGPipeInputFieldCount; ++i) {
|
||||
const auto field = static_cast<MGPipeInputField>(i);
|
||||
const MGPipeFieldOwnership ownership = kMGPipeFieldOwnership[i];
|
||||
const Bool answerable = (ownership == MGPipeFieldOwnership::kRecordSupplied ||
|
||||
ownership == MGPipeFieldOwnership::kApplierDerived) &&
|
||||
MGPipeFieldMaskHas(
|
||||
kMGPipeClassFieldMask[static_cast<SizeT>(verbClass)], field);
|
||||
if (answerable) mask.Words[i / 64] |= (Uint64{1} << (i % 64));
|
||||
}
|
||||
return mask;
|
||||
}
|
||||
|
||||
struct AnswerableMaskTable {
|
||||
MGPipeFieldMask ByClass[kMGPipeVerbClassCount];
|
||||
};
|
||||
|
||||
constexpr AnswerableMaskTable MakeAnswerableMaskTable() {
|
||||
AnswerableMaskTable table{};
|
||||
for (SizeT i = 0; i < kMGPipeVerbClassCount; ++i) {
|
||||
table.ByClass[i] = AnswerableMaskForClass(static_cast<MGPipeVerbClass>(i));
|
||||
}
|
||||
return table;
|
||||
}
|
||||
|
||||
constexpr AnswerableMaskTable kAnswerableByClass = MakeAnswerableMaskTable();
|
||||
|
||||
// A verb id outside the table answers NOTHING, which is exactly what FieldIsInVerbClass
|
||||
// said for it (`verbIndex >= kMGPipeVerbCount` -> false for every field) and therefore
|
||||
// what the stamp said: all 63 withdrawn, every read the poison Fatal.
|
||||
constexpr MGPipeFieldMask kNoFieldIsAnswerable{};
|
||||
|
||||
const MGPipeFieldMask& AnswerableMaskForVerb(MGPipeVerb verb) {
|
||||
const SizeT verbIndex = static_cast<SizeT>(verb);
|
||||
if (verbIndex >= kMGPipeVerbCount) return kNoFieldIsAnswerable;
|
||||
return kAnswerableByClass.ByClass[static_cast<SizeT>(kMGPipeVerbClass[verbIndex])];
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// The third door into the storage (see PipeInputs.h). It exists because neither of the
|
||||
@@ -108,23 +188,25 @@ namespace MobileGL::MG_Pipe {
|
||||
// BOTH branches of MGPipeInputFieldIsFresh, so the zeroing below is a real withdrawal
|
||||
// rather than a stamp that happens to be old.
|
||||
++filled.CurrentVerbSerial;
|
||||
// STAMPED: in this verb's class AND answerable out of the records the applier has
|
||||
// already applied. WITHDRAWN (0): everything else - which is BARRIER-PULLED, FATAL,
|
||||
// and anything the verb's own may-read table says this verb does not read.
|
||||
//
|
||||
// The withdrawal is the load-bearing half of the rule: the client's residual fill
|
||||
// stamped all 63 fields at its own verb boundary, so without it every field would
|
||||
// read fresh on the server, `rsp` would be identically 0 and the exit gate would be
|
||||
// decoration. It also cancels the sticky exemption for free - generated/
|
||||
// PipeFilled.inc tests "never filled" BEFORE it tests sticky, so 0 wins over
|
||||
// kMGPipeInputFieldSticky without a line of the generated file changing.
|
||||
//
|
||||
// THE VERDICT IS THE SAME EXPRESSION; it is just precomputed per verb class
|
||||
// (AnswerableMaskForClass above) instead of re-derived 63 times per verb, so what is
|
||||
// left here is a table lookup and a branch-free fill.
|
||||
const MGPipeFieldMask& answerable = AnswerableMaskForVerb(verb);
|
||||
const Uint64 serial = filled.CurrentVerbSerial;
|
||||
for (SizeT i = 0; i < kMGPipeInputFieldCount; ++i) {
|
||||
const auto field = static_cast<MGPipeInputField>(i);
|
||||
const MGPipeFieldOwnership ownership = kMGPipeFieldOwnership[i];
|
||||
// STAMPED: in this verb's class AND answerable out of the records the applier has
|
||||
// already applied. WITHDRAWN (0): everything else - which is BARRIER-PULLED, FATAL,
|
||||
// and anything the verb's own may-read table says this verb does not read.
|
||||
//
|
||||
// The withdrawal is the load-bearing half of the rule: the client's residual fill
|
||||
// stamped all 63 fields at its own verb boundary, so without it every field would
|
||||
// read fresh on the server, `rsp` would be identically 0 and the exit gate would be
|
||||
// decoration. It also cancels the sticky exemption for free - generated/
|
||||
// PipeFilled.inc tests "never filled" BEFORE it tests sticky, so 0 wins over
|
||||
// kMGPipeInputFieldSticky without a line of the generated file changing.
|
||||
const Bool answerable = (ownership == MGPipeFieldOwnership::kRecordSupplied ||
|
||||
ownership == MGPipeFieldOwnership::kApplierDerived) &&
|
||||
FieldIsInVerbClass(field, verb);
|
||||
filled.FilledGen[i] = answerable ? filled.CurrentVerbSerial : 0;
|
||||
const Uint64 bit = (answerable.Words[i / 64] >> (i % 64)) & Uint64{1};
|
||||
filled.FilledGen[i] = serial & (Uint64{0} - bit);
|
||||
}
|
||||
MGPipeStampAccess::SetServerStamped(inputs, true);
|
||||
}
|
||||
|
||||
@@ -1497,6 +1497,20 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return;
|
||||
}
|
||||
MG_State::pGLContext->TouchBufferBindingPoint(bufferTarget, pointIndex);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (sb, CONTRACT-P5E.md §5.6). THE BIND-POINT GENERATION, and it is bumped HERE -
|
||||
// before the writes below and after every refusal above - rather than inside
|
||||
// BindingSlotRange1D, for two reasons. The slot has no back-pointer to the state
|
||||
// container that owns it, which is the same reason every other aggregate is bumped from
|
||||
// the entry point; and a bump on a bind that is about to be REJECTED by
|
||||
// ValidateBufferName is an over-fire the set-hash suppressor absorbs, while a bump
|
||||
// placed after the writes would be skipped by the `buffer == 0` early return below -
|
||||
// which is an unbind, the one case a shutter may least afford to miss.
|
||||
//
|
||||
// The dirty bits this feeds are 15/16/17 (Tracker.h); before P5e they shuttered on the
|
||||
// buffer CONTENT aggregate, which no bind has ever moved.
|
||||
MG_State::pGLContext->NoteBufferBindPointChanged(bufferTarget);
|
||||
#endif
|
||||
|
||||
auto& point = MG_State::pGLContext->GetBufferBindingPoint(bufferTarget, pointIndex);
|
||||
SharedPtr<MG_State::GLState::BufferObject> bufferObject;
|
||||
@@ -1620,6 +1634,13 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
return;
|
||||
}
|
||||
MG_State::pGLContext->TouchBufferBindingPoint(bufferTarget, index);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (sb): the other half of BindBufferBase_State's bump - same generation, same
|
||||
// placement, same reason. A glBindBufferRange moves the point's EXTENT as well as what
|
||||
// is bound to it, and the record carries the resolved Offset/Size, so a range change
|
||||
// with no object change still has to reach the emitter.
|
||||
MG_State::pGLContext->NoteBufferBindPointChanged(bufferTarget);
|
||||
#endif
|
||||
|
||||
auto& point = MG_State::pGLContext->GetBufferBindingPoint(bufferTarget, index);
|
||||
SharedPtr<MG_State::GLState::BufferObject> bufferObject;
|
||||
|
||||
@@ -108,7 +108,18 @@ DECLARE_GL_FUNCTION_HEAD(void, DrawArrays, GLenum mode, GLint first, GLsizei cou
|
||||
DECLARE_GL_FUNCTION_HEAD(void, DrawElements, GLenum mode, GLsizei count, GLenum type, const void* indices) DECLARE_GL_FUNCTION_END_NO_RETURN(void, DrawElements, mode, count, type, indices)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, Enable, GLenum cap) DECLARE_GL_FUNCTION_END_NO_RETURN(void, Enable, cap)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, EnableVertexAttribArray, GLuint index) DECLARE_GL_FUNCTION_END_NO_RETURN(void, EnableVertexAttribArray, index)
|
||||
MOBILEGL_GL_API void glFinish() { MGLOG_D("Implementing function: %s(...)", __FUNCTION__); }
|
||||
// P5e (ra), CONTRACT-P5E §2.5. STILL NOTHING ON THE WIRE - Flush and Finish have no record
|
||||
// (ARCHITECTURE §11) and this stays a no-op on every monolith build. What it is not any more
|
||||
// is a no-op on a RUN-AHEAD client: "the commands issued so far have completed" is a promise a
|
||||
// queue the client never waits on can break, and this is the only place an application can ask
|
||||
// for it. Under lockstep the client had already waited out every command it issued, so the
|
||||
// call really did have nothing to do; MGPipeClientFinish answers false-cheap there too.
|
||||
MOBILEGL_GL_API void glFinish() {
|
||||
MGLOG_D("Implementing function: %s(...)", __FUNCTION__);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
MobileGL::MG_Pipe::MGPipeClientFinish();
|
||||
#endif
|
||||
}
|
||||
MOBILEGL_GL_API void glFlush() { MGLOG_D("Implementing function: %s(...)", __FUNCTION__); }
|
||||
DECLARE_GL_FUNCTION_HEAD(void, FramebufferRenderbuffer, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) DECLARE_GL_FUNCTION_END_NO_RETURN(void, FramebufferRenderbuffer, target, attachment, renderbuffertarget, renderbuffer)
|
||||
DECLARE_GL_FUNCTION_HEAD(void, FramebufferTexture2D, GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level) DECLARE_GL_FUNCTION_END_NO_RETURN(void, FramebufferTexture2D, target, attachment, textarget, texture, level)
|
||||
|
||||
@@ -6745,6 +6745,16 @@ namespace MobileGL::MG_Impl::GLImpl {
|
||||
MG_State::pGLContext->GetImageTextureBinding(static_cast<Int>(unit))
|
||||
.Bind(textureObject, level, layered, layer, access, format);
|
||||
MG_State::pGLContext->NoteTextureUnitTouched(static_cast<Int>(unit));
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// AND THE IMAGE-UNIT MARK BESIDE IT. The line above moves the TEXTURE-unit high-water
|
||||
// mark, which is a different array: a reader that needs "the highest image unit ever
|
||||
// bound" cannot take it from there without either over-walking (a texture bind at unit
|
||||
// 31 with no image bound anywhere) or, worse, under-walking if that line ever moves. The
|
||||
// split client's per-draw writable-image sweep is that reader
|
||||
// (MG_Remote/Client/GpuWritePending.cpp). Push builds only, so the pull build's bytes do
|
||||
// not move (G1).
|
||||
MG_State::pGLContext->NoteImageUnitTouched(static_cast<Int>(unit));
|
||||
#endif
|
||||
MGP_FILL(BindImageTexture);
|
||||
bindImageTexture(unit, texture, level, layered, layer, access, format);
|
||||
}
|
||||
|
||||
@@ -48,6 +48,31 @@
|
||||
|
||||
namespace MobileGL::MG_Pipe {
|
||||
|
||||
// GL_READ_ONLY / GL_WRITE_ONLY / GL_READ_WRITE folded into the one byte the wire carries.
|
||||
// A value the enum does not name would otherwise truncate silently into a Uint8, which is
|
||||
// the class of bug the descriptors exist to close.
|
||||
//
|
||||
// P5e (CONTRACT-P5E.md §1, ruling 16) MOVED THE NUMBERS OUT FROM UNDER THIS FUNCTION and
|
||||
// left the GLenum half here, where the GLenum is. The three values are
|
||||
// MGPipeValueTypes.h's MGPipeImageAccess, which the server decodes through, so the encode
|
||||
// and the decode are one table instead of two literals that happened to agree. It is also
|
||||
// why the function is a free function now rather than a private static: the unit case that
|
||||
// pins the three constants has to reach BOTH halves (MG_Test/Pipe/ImageEmitTest.cpp).
|
||||
inline Uint32 MGPipeEncodeImageAccess(GLenum access) {
|
||||
switch (access) {
|
||||
case GL_READ_ONLY:
|
||||
return kMGPipeImageAccessReadOnly;
|
||||
case GL_WRITE_ONLY:
|
||||
return kMGPipeImageAccessWriteOnly;
|
||||
case GL_READ_WRITE:
|
||||
return kMGPipeImageAccessReadWrite;
|
||||
default:
|
||||
MOBILEGL_ASSERT(false, "glBindImageTexture access 0x%x is not one of the three GL names",
|
||||
static_cast<Uint>(access));
|
||||
return kMGPipeImageAccessReadOnly;
|
||||
}
|
||||
}
|
||||
|
||||
// D-G3. Over the tail with Start and Count mixed in, the same shape the two sampler sets
|
||||
// use - and it covers InternalFormat and Access because those are live glBindImageTexture
|
||||
// state that the format-less image bake keys on, not decoration.
|
||||
@@ -64,12 +89,20 @@ namespace MobileGL::MG_Pipe {
|
||||
|
||||
// set_shader_images. Start is 0 and Count is the image-unit window described below.
|
||||
//
|
||||
// WHERE THE HIGH-WATER MARK COMES FROM, because the frontend has none and this is the
|
||||
// one place a reader will look for it. DirectGLES keeps g_imageUnitHighWaterMark, but
|
||||
// that is written from inside its own per-unit sync and lives on the far side of the
|
||||
// boundary; TextureState::NoteUnitTouched is the TEXTURE-unit path and
|
||||
// glBindImageTexture does not reach it. Adding a counter to TextureState would edit
|
||||
// another package's file and resize the pull build's object, which G1 forbids outright.
|
||||
// WHERE THE HIGH-WATER MARK COMES FROM, because this is the one place a reader will look
|
||||
// for it. DirectGLES keeps g_imageUnitHighWaterMark, but that is written from inside its
|
||||
// own per-unit sync and lives on the far side of the boundary.
|
||||
//
|
||||
// AND IT IS STILL NOT TextureState's MARK, EVEN THOUGH ONE NOW EXISTS. P5d round 3
|
||||
// (package C) added TextureState::NoteImageUnitTouched - a push-build-only image-unit
|
||||
// high-water mark, fed by glBindImageTexture - for the split client's per-draw
|
||||
// GPU-write sweep. That mark answers "which units could hold a binding"; the window
|
||||
// below answers the strictly narrower "which units could a SHADER READ", which is what
|
||||
// makes the zero early-out fire for an application that binds an image no shader names.
|
||||
// Swapping one for the other would widen this emitter for no record's benefit, and the
|
||||
// paragraph that used to stand here - "adding a counter to TextureState would resize the
|
||||
// pull build's object, which G1 forbids outright" - is answered by that mark being
|
||||
// compiled only into push builds, where the object is already a different size.
|
||||
//
|
||||
// So the window is derived instead, from the one thing that decides whether an image
|
||||
// unit can matter at all: the highest image unit the CURRENT PROGRAM names, memoised
|
||||
@@ -149,24 +182,6 @@ namespace MobileGL::MG_Pipe {
|
||||
Uint32 Window() const { return m_window; }
|
||||
|
||||
private:
|
||||
// GL_READ_ONLY / GL_WRITE_ONLY / GL_READ_WRITE folded into the one byte the wire
|
||||
// carries. A value the enum does not name would otherwise truncate silently into a
|
||||
// Uint8, which is the class of bug the descriptors exist to close.
|
||||
static Uint32 MGPipeEncodeImageAccess(GLenum access) {
|
||||
switch (access) {
|
||||
case GL_READ_ONLY:
|
||||
return 0;
|
||||
case GL_WRITE_ONLY:
|
||||
return 1;
|
||||
case GL_READ_WRITE:
|
||||
return 2;
|
||||
default:
|
||||
MOBILEGL_ASSERT(false, "glBindImageTexture access 0x%x is not one of the three GL names",
|
||||
static_cast<Uint>(access));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
Array<MGPImageView, kMGPipeMaxImageUnits> m_entries{};
|
||||
MGPShaderImages m_lastImages{};
|
||||
Uint32 m_window = 0;
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <MG_Impl/Pipe/ResourceTracker.h>
|
||||
#include <MG_Impl/Pipe/SamplerEmit.h>
|
||||
#include <MG_Impl/Pipe/SetHashSuppressor.h>
|
||||
#include <MG_Impl/Pipe/ShaderBufferEmit.h>
|
||||
#include <MG_Impl/Pipe/TextureEmit.h>
|
||||
#include <MG_Impl/Pipe/Tracker.h>
|
||||
#include <MG_Impl/Pipe/VertexInputEmit.h>
|
||||
@@ -85,6 +86,20 @@ namespace MobileGL::MG_Pipe {
|
||||
return inputs.m_currentVertexAttribute;
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5e (ra, CONTRACT-P5E §2.3). THE FOUR O-CLASS ROWS, AND ONLY THEY: these are the only
|
||||
// members of this block that own a frontend object rather than point into one, so they
|
||||
// are the only ones through which the apply thread can become a last owner. The raw
|
||||
// pointer rows (the binding-slot bases) are borrowed from a live GLContext and own
|
||||
// nothing, so releasing them would buy no lifetime and lose the monolith's arms.
|
||||
static void ReleaseObjectPins(PipeInputs& inputs) {
|
||||
inputs.m_boundVertexArray.reset();
|
||||
inputs.m_programForDispatch.reset();
|
||||
inputs.m_programForDraw.reset();
|
||||
inputs.m_transformFeedbackProgram.reset();
|
||||
}
|
||||
#endif
|
||||
|
||||
static void CopyField(PipeInputs& dst, GLContext& ctx, MGPipeInputField field) {
|
||||
using F = MGPipeInputField;
|
||||
using MG_State::GLState::BufferBindPointTargets;
|
||||
@@ -330,6 +345,72 @@ namespace MobileGL::MG_Pipe {
|
||||
namespace {
|
||||
GLContext* LiveContext() { return MG_State::pGLContext.get(); }
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// ---- P5e (ra): the fill decision (CONTRACT-P5E §3.1) -----------------------------
|
||||
//
|
||||
// Is this process a run-ahead CLIENT right now? Three questions, cheapest first, and
|
||||
// the last one is the latch ClientSession took at its first caps adoption - so this is
|
||||
// one pointer test and one bool load on the verb path once the first two are constant.
|
||||
Bool ClientRunsAhead() {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return false;
|
||||
if (MG_Remote::Client::RunsAsTheServerRole()) return false;
|
||||
const MG_Remote::Client::ClientSession* session = MG_Remote::Client::ClientSession::Active();
|
||||
return session != nullptr && session->RunAheadArmed();
|
||||
}
|
||||
|
||||
// THE WIRE OP A VERB BOUNDARY BECOMES, which is the join MGPipeVerbForWireOp draws in
|
||||
// the other direction. Built by walking the op space once at compile time rather than
|
||||
// written out, because a second hand-written table is a second thing to forget a row
|
||||
// in - and the generator already refuses a verb-shaped op with no row.
|
||||
constexpr MGPWireOp WireOpForVerb(MGPipeVerb verb) {
|
||||
for (SizeT i = 0; i < static_cast<SizeT>(MGPWireOp::kOpCount); ++i) {
|
||||
const auto op = static_cast<MGPWireOp>(i);
|
||||
if (MGPipeVerbForWireOp(op) == verb) return op;
|
||||
}
|
||||
return MGPWireOp::kOpCount;
|
||||
}
|
||||
|
||||
// CONTRACT-P5E §2.1's predicate, ASKED AT THE VALIDATE POINT - which is before the
|
||||
// record exists, so it is asked of the verb and the live context rather than of the
|
||||
// payload. The two halves must agree with MGPipeBarriered(op, payload, applierState),
|
||||
// which is what the server computes, so each clause is the same clause:
|
||||
//
|
||||
// 1. the static WaitClass column - the same generated table, same op;
|
||||
// 2. kCtxVerb inside an open XFB span - ctx.IsTransformFeedbackActive() here,
|
||||
// the applied MGPContextValues mirror there, and set_context_values precedes the
|
||||
// verb on the ring, so the two read the same value (§2.1);
|
||||
// 3. a draw carrying kDrawClientArrays - NOT asked here, because under run-ahead
|
||||
// such a draw never reaches a record at all: vi refuses it on this very thread in
|
||||
// EmitDrawRecord's array arm (§5.1, ruling 2). Asking it here would be a second
|
||||
// spelling of vi's "does any enabled attribute lack a buffer" walk, and two
|
||||
// spellings of an escalation is precisely what ruling 3 replaced.
|
||||
//
|
||||
// AN OP WITH NO VERB ROW ANSWERS BARRIERED. A verb the join does not know is one this
|
||||
// file cannot reason about, and the safe answer - fill it, wait for it - is also the
|
||||
// pre-P5e answer.
|
||||
// `ctx` MAY BE NULL, and that is not a convenience: the validate point asks this
|
||||
// question BEFORE it has decided whether there is anything to fill, so that the answer
|
||||
// is about the RECORD and not about the state of the block. A null context has no open
|
||||
// transform-feedback span, so clause 2 is false for it - and the verb is a no-op below
|
||||
// either way.
|
||||
Bool ClientVerbIsBarriered(MGPipeVerb verb, GLContext* ctx) {
|
||||
const MGPWireOp op = WireOpForVerb(verb);
|
||||
if (op == MGPWireOp::kOpCount) return true;
|
||||
if (MGPipeWaitClassFor(op) != kWaitNone) return true;
|
||||
if (MGPipeCallClassFor(op) == kCtxVerb && ctx != nullptr &&
|
||||
ctx->IsTransformFeedbackActive()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Whether the LAST fill actually happened, i.e. whether the rows in the block describe
|
||||
// the verb in flight. Read by MGPipeNoteFrontendMutation, which refreshes one field of
|
||||
// that fill: with no fill behind it there is nothing to refresh and the write would be
|
||||
// the role violation §3.5 names.
|
||||
Bool g_lastFillWasBarriered = true;
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
const SharedPtr<T>& NullShared() {
|
||||
static const SharedPtr<T> null;
|
||||
@@ -361,7 +442,16 @@ namespace MobileGL::MG_Pipe {
|
||||
// An empty value never clears an omission a test armed through MGPipeSetPoisonOmission.
|
||||
void ParsePoisonOmissionKnob() {
|
||||
const String& knob = MG_Config::Features.PipePoisonOmit;
|
||||
if (g_omissionKnobParsed && knob == g_omissionKnobValue) return;
|
||||
// THE UNSET KNOB IS TWO LENGTH LOADS AND A BRANCH, inline, and that is the whole
|
||||
// change (P5d r3, package C): this runs at every verb - 852 draws a frame on the
|
||||
// profiled workload - and `knob == g_omissionKnobValue` is an out-of-line String
|
||||
// compare even when both sides are empty, which is every shipping configuration.
|
||||
// Sizes first, contents only when a non-empty value is involved; the re-parse
|
||||
// condition is unchanged (the value differing from what the last parse latched).
|
||||
if (g_omissionKnobParsed && knob.size() == g_omissionKnobValue.size() &&
|
||||
(knob.empty() || knob == g_omissionKnobValue)) {
|
||||
return;
|
||||
}
|
||||
g_omissionKnobParsed = true;
|
||||
g_omissionKnobValue = knob;
|
||||
if (knob.empty()) return;
|
||||
@@ -537,10 +627,18 @@ namespace MobileGL::MG_Pipe {
|
||||
void MGPipeNoteFrontendMutation(MGPipeInputField field) {
|
||||
PipeInputs& inputs = gPipeInputs;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5e (ra, CONTRACT-P5E §3.1): THIS REFRESHES ONE FIELD OF THE LAST FILL, so with no
|
||||
// fill behind it there is nothing to refresh. Under run-ahead the last verb may have
|
||||
// been unbarriered, in which case the block describes an older verb the server is no
|
||||
// longer being asked about and a write here would be a GL-thread touch of server-role
|
||||
// memory. It returns instead - the same answer, one line earlier, as the class-mask
|
||||
// test below gives for a field the verb never pushed.
|
||||
if (!g_lastFillWasBarriered) return;
|
||||
// P5c (gt, layer 2): the single-field refresh is a client write into gPipeInputs too -
|
||||
// same gate as the fill.
|
||||
// same gate as the fill, and it makes the same claim the fill made: the rows it is
|
||||
// touching belong to a record this thread is parked behind (or will park behind).
|
||||
MG_Remote::Client::ClientSession::RefusePipeInputsTouchWhileApplierOwnsIt(
|
||||
"MGPipeNoteFrontendMutation");
|
||||
"MGPipeNoteFrontendMutation", /*isBarrieredFill=*/true);
|
||||
#endif
|
||||
auto* ctx = LiveContext();
|
||||
if (ctx == nullptr) return;
|
||||
@@ -990,6 +1088,29 @@ namespace MobileGL::MG_Pipe {
|
||||
Bool MGPipeDeferDestroyAndFreeIfOnApplyThread(MGPipeKind kind, Uint64 lifetimeId) {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return false;
|
||||
if (!MG_Remote::Client::RunsAsTheServerRole()) return false;
|
||||
// P5e (ra), CONTRACT-P5E §2.7 / ruling 13. The queue stays - a BARRIERED record's apply
|
||||
// may still pin a frontend object (its fill's O-class rows, XFB's targets), so the
|
||||
// apply thread can still be a last owner and this is still the belt that keeps that
|
||||
// death off the client's allocator. But an enqueue from an UNBARRIERED record is a
|
||||
// FINDING, not a service: rule F says such an apply names no client memory at all, so
|
||||
// a SharedPtr it could be the last owner of means some site is still pinning a
|
||||
// frontend object across a record and the migration this phase believes it finished is
|
||||
// not finished. Named once with the kind so the site is findable, and Fatal under
|
||||
// strict so the lane owns the red rather than a log nobody reads.
|
||||
if (!MG_Pipe::MGPipeApplierCurrentRecordIsBarriered()) {
|
||||
if (MG_Config::Ipc.StrictErrors) {
|
||||
MGLOG_F("MGPipe: Fatal{RoleViolation, \"deferred-destroy\"} - an UNBARRIERED "
|
||||
"apply was the last owner of a frontend object of kind %u (lifetime "
|
||||
"%llu). CONTRACT-P5E rule F says an unbarriered apply reads no client "
|
||||
"memory, so nothing it touched should have been a SharedPtr at all",
|
||||
static_cast<unsigned>(kind), static_cast<unsigned long long>(lifetimeId));
|
||||
std::abort();
|
||||
}
|
||||
MGLOG_E_ONCE("MGPipe: an UNBARRIERED apply deferred the destruction of a frontend "
|
||||
"object of kind %u - CONTRACT-P5E §2.7's finding: some apply-thread "
|
||||
"site still holds a frontend SharedPtr across a record",
|
||||
static_cast<unsigned>(kind));
|
||||
}
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(g_deferredDestroyMutex);
|
||||
g_deferredDestroys.push_back(MGPipeDeferredDestroy{kind, lifetimeId});
|
||||
@@ -998,6 +1119,30 @@ namespace MobileGL::MG_Pipe {
|
||||
return true;
|
||||
}
|
||||
|
||||
// P5e (ra), CONTRACT-P5E §2.3. Declared in PipeMutation.h, where its WHY is argued.
|
||||
//
|
||||
// NO GUARD ON THE CALLER'S BEHALF: ClientSession calls this only after a barriered apply
|
||||
// has returned on a run-ahead session, and adding a second "is run-ahead armed" test here
|
||||
// would be a copy of a decision that belongs on the other side. What this side owns is
|
||||
// WHICH rows go, and that answer is ReleaseObjectPins' four.
|
||||
//
|
||||
// THE STAMPS ARE LEFT ALONE, deliberately. A released row reads back as null, and a
|
||||
// BARRIERED verb's fill re-copies it before that verb's apply can pull it (§3.1 skips the
|
||||
// fill only for UNBARRIERED records); an unbarriered apply may not read it at all, and
|
||||
// §3.3's detector is what says so by name. Clearing the stamps as well would trade that
|
||||
// named abort for the poison Fatal, which names the field but not the rule it broke.
|
||||
void MGPipeReleaseResidualFillPins() { MGPipeFillAccess::ReleaseObjectPins(gPipeInputs); }
|
||||
|
||||
// P5e (ra), CONTRACT-P5E §2.5. Declared in PipeMutation.h; see there for why it is not a
|
||||
// ClientSession call at the GL entry point.
|
||||
void MGPipeClientFinish() {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
if (MG_Remote::Client::RunsAsTheServerRole()) return;
|
||||
if (MG_Remote::Client::ClientSession* session = MG_Remote::Client::ClientSession::Active()) {
|
||||
session->Finish();
|
||||
}
|
||||
}
|
||||
|
||||
void MGPipeDrainDeferredDestroys() {
|
||||
if (g_deferredDestroyCount.load(std::memory_order_acquire) == 0) return;
|
||||
Vector<MGPipeDeferredDestroy> drained;
|
||||
@@ -1310,11 +1455,41 @@ namespace MobileGL::MG_Pipe {
|
||||
// the commit that gives the emitter its body - so a client path that lands before its
|
||||
// emitter does is inert by construction rather than by everyone remembering to check; the
|
||||
// third is P4aFamilyHasItsConsumer above and the fourth is P4aFamilyDependenciesAreSet.
|
||||
// P5e (sb, ID-106 and CONTRACT-P5E.md §1). THE BINDING-POINT FAMILY's TWO EXTRA
|
||||
// CONJUNCTS, kept beside P4a's rather than folded into them, because it asks a
|
||||
// DIFFERENT consumer question. P4a's four families all ride the resource family's one
|
||||
// signal (P4aFamilyHasItsConsumer says why); bit 13's consumer question is bit 13's
|
||||
// own - MG_Backend/Init.cpp publishes it in the same commit that sets
|
||||
// ShaderBufferEmit.h's wired constant, and a server that does not publish it is a
|
||||
// server whose four binding-point walks still read the frontend, so a record sent to it
|
||||
// would be stored and never looked at while the client latched its suppressor.
|
||||
//
|
||||
// AND BIT 13 REQUIRES BIT 7, for bit 11's reason one family over: every
|
||||
// MGPBufferRange::Res names a Buffer handle and only bit 7 puts one in the resource
|
||||
// slot table, so without it every EnsureBufferResourceForHandle on the server would
|
||||
// mint a twin with no record behind it. Withholding the whole family is the safe
|
||||
// direction - the legacy frontend walk runs untouched on both sides.
|
||||
Bool P5eFamilyIsLive(Uint64 subsystem, Uint64 pushMask) {
|
||||
if ((subsystem & kMGPipeSubsystemBufferBindings) == 0) return true;
|
||||
if ((pushMask & kMGPipeSubsystemResources) == 0) return false;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (MG_Config::Transport != MG_Config::TransportMode::Monolith) {
|
||||
return MG_Remote::Client::CapsMirrorInstance().ServerConsumes(
|
||||
kMGPipeSubsystemBufferBindings);
|
||||
}
|
||||
#endif
|
||||
// Under monolith the "consumer" is the backend that registered the resource op
|
||||
// table, exactly as it is for P4a's four: there is no caps snapshot to ask and the
|
||||
// binding-point walks live in the same DirectGLES that registers it.
|
||||
return MGPipeGetResourceOps() != nullptr;
|
||||
}
|
||||
|
||||
Bool FamilyIsLive(Uint64 subsystem, Uint64 wired) {
|
||||
const Uint64 pushMask = MG_Config::Features.PipePush;
|
||||
return (pushMask & subsystem) != 0 && (wired & subsystem) != 0 &&
|
||||
P4aFamilyHasItsConsumer(subsystem) &&
|
||||
P4aFamilyDependenciesAreSet(subsystem, pushMask);
|
||||
P4aFamilyDependenciesAreSet(subsystem, pushMask) &&
|
||||
P5eFamilyIsLive(subsystem, pushMask);
|
||||
}
|
||||
|
||||
// ---- THE FAMILY SEAM ----
|
||||
@@ -1946,9 +2121,20 @@ namespace MobileGL::MG_Pipe {
|
||||
void MGPipeLeaveVerb() {
|
||||
PipeInputs& inputs = gPipeInputs;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// Same layer-2 gate as the fill: the serial bump and the verb reset below are writes
|
||||
// into gPipeInputs (gt).
|
||||
MG_Remote::Client::ClientSession::RefusePipeInputsTouchWhileApplierOwnsIt("MGPipeLeaveVerb");
|
||||
// P5e (ra, §3.1): a verb whose fill was skipped has no stamps of this thread's to
|
||||
// retire, and the bump below would move a serial the SERVER's stamp owns. Leave
|
||||
// returns, and the tracker's base-instance clear - which is frontend state, not block
|
||||
// state - still runs at the bottom.
|
||||
if (g_lastFillWasBarriered) {
|
||||
// Same layer-2 gate as the fill: the serial bump and the verb reset below are
|
||||
// writes into gPipeInputs (gt).
|
||||
MG_Remote::Client::ClientSession::RefusePipeInputsTouchWhileApplierOwnsIt(
|
||||
"MGPipeLeaveVerb", /*isBarrieredFill=*/true);
|
||||
}
|
||||
if (!g_lastFillWasBarriered) {
|
||||
MGPipeTrackerInstance().ClearPendingBaseInstance();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if MOBILEGL_PIPE_POISON
|
||||
// Same bump the next fill would make, without a verb to fill from: no field is
|
||||
@@ -2014,6 +2200,15 @@ namespace MobileGL::MG_Pipe {
|
||||
// emission gate is the subsystem bit plus the whole-record hash and nothing else.
|
||||
case MGPipeFieldEmitter::SetContextValues:
|
||||
return kMGPipeSubsystemResidualValues;
|
||||
// P5e's one emitted row (MG_Remote/CONTRACT-P5E.md §5.6): the indexed buffer
|
||||
// binding points. Written HERE at the contract commit, with the Coverage.def row
|
||||
// and EmittedCallSuppliesTheWholeField's arm beside it, for the reason
|
||||
// kMGPipeWiredSubsystems' block states one paragraph down - this file belongs to
|
||||
// the contract package for the whole phase, and an emitter enumerator whose
|
||||
// dispatch arm lived in the family's own worktree is the merge trap that block
|
||||
// exists to close. It is inert until that family's wired constant leaves 0.
|
||||
case MGPipeFieldEmitter::SetShaderBuffers:
|
||||
return kMGPipeSubsystemBufferBindings;
|
||||
case MGPipeFieldEmitter::kNone:
|
||||
break;
|
||||
}
|
||||
@@ -2082,6 +2277,15 @@ namespace MobileGL::MG_Pipe {
|
||||
MG_State::GLState::VertexArrayObject::MAX_VERTEX_ATTRIBS,
|
||||
"the MGPipe vertex-attribute capacity and the frontend's have drifted");
|
||||
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §1, ruling 10), pinned here for the same reason and in
|
||||
// the same place: this translation unit sees the frontend constant and the MG_Pipe one,
|
||||
// and nothing else does. 84 is what the emitter may describe and what the wire carries;
|
||||
// the BACKEND clamps to the device's real GL_MAX_UNIFORM_BUFFER_BINDINGS, as it does
|
||||
// today, because a client-side clamp would read a device capability from the wrong side.
|
||||
static_assert(kMGPipeMaxBufferBindingPoints ==
|
||||
MG_State::GLState::BufferBindingPointCount,
|
||||
"the MGPipe buffer-binding-point capacity and the frontend's have drifted");
|
||||
|
||||
// ---- P4a's SEVEN pairings, and EVERY ONE OF THEM COMPARES AGAINST
|
||||
// SubsystemForEmitter RATHER THAN AGAINST A CONSTANT. That is the lesson written out
|
||||
// twenty lines above and it is not a style preference: naming the subsystem constant
|
||||
@@ -2119,6 +2323,23 @@ namespace MobileGL::MG_Pipe {
|
||||
SubsystemForEmitter(MGPipeFieldEmitter::SetDispatchProgram),
|
||||
"set_draw_program and set_dispatch_program are one family and one A/B");
|
||||
|
||||
// P5e's pairing, in the same shape and for the same reason as P4a's seven: the two maps
|
||||
// answer different questions - one takes a field's EMITTER, the other a dirty BIT - and
|
||||
// the emission is gated on one while the residual-fill skip is gated on the other, so a
|
||||
// divergence would push a call whose field is still pulled, or skip a field whose call
|
||||
// was never emitted. Compared against SubsystemForEmitter rather than against the
|
||||
// constant, because pinning the two MAPS to each other is the statement that cannot
|
||||
// drift.
|
||||
static_assert(MGPipeSubsystemForDirty(MGPipeDirty::NewShaderBuffers) ==
|
||||
SubsystemForEmitter(MGPipeFieldEmitter::SetShaderBuffers),
|
||||
"set_shader_buffers and NEW_SHADER_BUFFERS must name one subsystem");
|
||||
static_assert(MGPipeSubsystemForDirty(MGPipeDirty::NewConstBuffers) ==
|
||||
MGPipeSubsystemForDirty(MGPipeDirty::NewShaderBuffers),
|
||||
"the three binding-point bits are one family and one A/B");
|
||||
static_assert(MGPipeSubsystemForDirty(MGPipeDirty::NewSoTargets) ==
|
||||
MGPipeSubsystemForDirty(MGPipeDirty::NewShaderBuffers),
|
||||
"the three binding-point bits are one family and one A/B");
|
||||
|
||||
// THE TEXTURE-RESOURCE SUBSYSTEM HAS NO DIRTY BIT, and that has to be asserted rather
|
||||
// than left as an absence: its calls are dispatched from the GL entry points that
|
||||
// cause them, so a bit that started naming it would gate the emission twice - once at
|
||||
@@ -2204,7 +2425,14 @@ namespace MobileGL::MG_Pipe {
|
||||
kMGPipeWiredFramebufferSubsystem |
|
||||
kMGPipeWiredTextureSubsystem |
|
||||
kMGPipeWiredSamplerSubsystem |
|
||||
kMGPipeWiredProgramSubsystem;
|
||||
kMGPipeWiredProgramSubsystem |
|
||||
// P5e (sb): the indexed buffer binding
|
||||
// points, by the same rule and from the same
|
||||
// kind of header. ID-106 pins the other half
|
||||
// of the switch: MG_Backend/Init.cpp's
|
||||
// consumer mask gains bit 13 in the same
|
||||
// commit, or R-8 withholds the whole family.
|
||||
kMGPipeWiredBufferBindingSubsystem;
|
||||
// Each family constant is either 0 or its own subsystem bit and nothing else. Without
|
||||
// this a header that set the wrong constant - the sampler bit in the program header,
|
||||
// say - would switch the wrong family on and every gate would still pass.
|
||||
@@ -2220,6 +2448,9 @@ namespace MobileGL::MG_Pipe {
|
||||
static_assert(kMGPipeWiredProgramSubsystem == 0 ||
|
||||
kMGPipeWiredProgramSubsystem == kMGPipeSubsystemPrograms,
|
||||
"ProgramEmit.h's wired constant must be 0 or the program bit");
|
||||
static_assert(kMGPipeWiredBufferBindingSubsystem == 0 ||
|
||||
kMGPipeWiredBufferBindingSubsystem == kMGPipeSubsystemBufferBindings,
|
||||
"ShaderBufferEmit.h's wired constant must be 0 or the binding-point bit");
|
||||
|
||||
// A field an emitted call supplies COMPLETELY, so the residual fill may stop pulling
|
||||
// it. Two rows of Coverage.def's emitted list do not qualify and each has its reason
|
||||
@@ -2274,6 +2505,13 @@ namespace MobileGL::MG_Pipe {
|
||||
case MGPipeInputField::GetTextureUnitObject:
|
||||
case MGPipeInputField::GetProgramForDraw:
|
||||
case MGPipeInputField::GetProgramForDispatch:
|
||||
// P5e (CONTRACT-P5E.md §5.6): the same answer for the same reason. The field is
|
||||
// four raw bases into the frontend's binding-point table and set_shader_buffers
|
||||
// carries resolved {handle, offset, size} ranges; the applier cannot produce a
|
||||
// pointer, so skipping the pull would leave the mirror null on every draw of every
|
||||
// push build. What retires it is the four Espryt consumers reading the applier's
|
||||
// BoundShaderBuffers, not this row.
|
||||
case MGPipeInputField::GetBufferBindingPoint:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
@@ -2355,6 +2593,168 @@ namespace MobileGL::MG_Pipe {
|
||||
return answer;
|
||||
}
|
||||
|
||||
// ---- the residual fill's SUPPLIED SET, computed once per environment (P5d r3, C) ----
|
||||
//
|
||||
// WHY THIS CACHE EXISTS, AND WHAT IT DOES NOT CHANGE. Step 4 of the validate point asks,
|
||||
// for every one of the 63 fields and at EVERY verb, whether an emitted call already
|
||||
// supplied it. The question is the seven-term conjunction spelled below - and it is still
|
||||
// spelled exactly once, so there is ONE copy of it: five of its terms are constants of the
|
||||
// FIELD, and the other two are facts about the PROCESS - which subsystems the operator's
|
||||
// mask carries, and whether the backend consumes the P4a families - that move a handful of
|
||||
// times in a process's life and never inside a verb. So the conjunction is evaluated per
|
||||
// field once per distinct environment and read back as a bit. Nothing about WHICH fields
|
||||
// are copied moves: same expression, same inputs, same answer.
|
||||
//
|
||||
// AND THE PROFILE IS WHY IT IS WORTH A CACHE AT ALL. The 2026-09-17 inproc profile
|
||||
// (Minecraft 26.3-rc-3, view distance 12, ~852 draws/frame) put MGPipeValidateForVerb at
|
||||
// 4.11% self / 10.9% inclusive of the GL thread, of which MGPipeTracker::Update is 1.46
|
||||
// and CopyField 2.54; most of the rest is this walk's per-field predicate.
|
||||
// P4aFamilyHasItsConsumer alone is a CapsMirror read under split, and it was taken 63
|
||||
// times per verb for an answer that is the same 63 times.
|
||||
//
|
||||
// THE KEY IS THE WHOLE OF WHAT THE EXPRESSION READS BESIDE THE FIELD ID, which is what
|
||||
// makes this a memo rather than a latch that goes stale:
|
||||
// - the push mask (MG_Config::Features.PipePush), which the per-subsystem A/B lanes move;
|
||||
// - ApplierDerivesRenderStateFields(), a one-shot probe - in the key anyway, so that a
|
||||
// build where it ever stopped being one-shot cannot keep a stale answer silently;
|
||||
// - contextValuesWireLive, which flips when a session starts, stops, or tears its tables
|
||||
// down (P5c rv, CONTRACT-P5C.md 5.3) - the half that must never disagree with the
|
||||
// emission's half at the validate point, which is why it is PASSED IN rather than
|
||||
// re-read here;
|
||||
// - P4aFamilyHasItsConsumer, which flips when the caps mirror adopts a snapshot (R-12: a
|
||||
// second arrival IS the invalidation) or a backend registers its resource op table.
|
||||
// ALL FOUR FAMILIES RIDE THE ONE SIGNAL - that is P4aFamilyHasItsConsumer's own rule,
|
||||
// argued where it is defined - so asking it once for the whole family mask is asking
|
||||
// it for every family at once, and the rebuild re-asks it per subsystem from the same
|
||||
// unchanged mirror. It is also the one key input that CANNOT MOVE AN ANSWER TODAY,
|
||||
// and the static_assert below is that fact's trip wire rather than a claim in prose.
|
||||
//
|
||||
// NOT THREAD-LOCAL, AND THAT IS THIS FILE'S EXISTING RULE RATHER THAN A NEW ONE:
|
||||
// g_residualDue, g_omission and the verify latches beside it are file-scope too, and what
|
||||
// keeps a single writer on them is the verb barrier (ROADMAP.md's G1 row states it for
|
||||
// gPipeInputs itself). A validate that runs on the apply thread is inside that barrier by
|
||||
// construction.
|
||||
//
|
||||
// BUT THE ANSWER IS HANDED OUT BY VALUE, WHICH IS NOT THE SAME ARGUMENT (P5d r3 package C
|
||||
// review, minor 1). Those latches are single BITS: a reader cannot observe one
|
||||
// half-written. A 2x64-bit mask can, so the rebuild below fills a LOCAL and publishes it
|
||||
// into the memo in one assignment, and the caller gets a copy rather than a reference into
|
||||
// storage the next rebuild would zero under it. Sixteen bytes is cheaper at the use site
|
||||
// than the indirection was anyway - the walk reads the copy 63 times.
|
||||
|
||||
// AND THE FOURTH KEY INPUT CANNOT MOVE AN ANSWER TODAY, WHICH IS A FACT WITH A TRIP WIRE
|
||||
// RATHER THAN A COMMENT (P5d r3 package C review, the major).
|
||||
//
|
||||
// The consumer conjunct sits in the expression because the expression reads it, and the
|
||||
// key carries it because a key that omits an input the expression reads is how a memo
|
||||
// goes stale. But every field whose emitter belongs to a P4a family - the five of them:
|
||||
// GetFramebufferBindingSlot, GetImageTextureBinding, GetTextureUnitObject,
|
||||
// GetProgramForDraw, GetProgramForDispatch - is ALSO a field
|
||||
// EmittedCallSuppliesTheWholeField() answers `false` for: their storage
|
||||
// is a frontend heap reference (a BindingSlot, an ImageTextureBinding, a TextureUnit,
|
||||
// two SharedPtr<ProgramObject>) that a payload cannot carry, so the fill pulls them
|
||||
// whatever the consumer says. The consumer conjunct is therefore DOMINATED: no motion of
|
||||
// the caps mirror or of MGPipeGetResourceOps() can change one bit of the mask, and no
|
||||
// unit case can distinguish a key that carries it from one that does not.
|
||||
//
|
||||
// WHEN THIS FIRES, that stopped being true - P3b/P4b/P7/P8 gave one of those rows a twin
|
||||
// the applier can write - and the consumer signal became observable through
|
||||
// MGPipeResidualFillSuppliesField. At that point the memo's key needs the same
|
||||
// move-it-and-read-it-back pair steps 1-3 of
|
||||
// FieldOwnershipTest.TheResidualFillsSuppliedMemoReKeysOnEveryInputThatMovesAnAnswer
|
||||
// give the other three inputs, and that case's step 4 (which today pins the domination
|
||||
// instead) has to become it. Do that rather than deleting this line.
|
||||
constexpr Bool NoP4aFamilyFieldIsWhollySupplied() {
|
||||
for (SizeT i = 0; i < kMGPipeInputFieldCount; ++i) {
|
||||
const auto field = static_cast<MGPipeInputField>(i);
|
||||
const Uint64 subsystem = SubsystemForEmitter(kMGPipeFieldEmittedBy[i]);
|
||||
if ((subsystem & kMGPipeP4aFamilySubsystems) != 0 &&
|
||||
EmittedCallSuppliesTheWholeField(field)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static_assert(NoP4aFamilyFieldIsWhollySupplied(),
|
||||
"a P4a-family field became whole-supplied: the residual fill's supplied-set "
|
||||
"memo can now answer differently for the consumer signal, so that key input "
|
||||
"needs the unit case the paragraph above names");
|
||||
|
||||
struct ResidualFillPlan {
|
||||
Bool Valid = false;
|
||||
Uint64 PushMask = 0;
|
||||
Bool ApplierDerives = false;
|
||||
Bool ContextValuesWireLive = false;
|
||||
Bool P4aConsumer = false;
|
||||
// One bit per FIELD - not per verb class. The class mask is applied at the walk
|
||||
// exactly as it always was, so "does this verb read this field" stays the walk's
|
||||
// business and this stays a statement about EMISSION alone.
|
||||
MGPipeFieldMask Supplied{};
|
||||
};
|
||||
ResidualFillPlan g_fillPlan;
|
||||
|
||||
MGPipeFieldMask SuppliedFieldMask(Uint64 pushMask, Bool applierDerives,
|
||||
Bool contextValuesWireLive) {
|
||||
// THE CONSUMER SIGNAL IS READ ONLY WHERE THE WALK BELOW COULD REACH IT, and that
|
||||
// guard is not a micro-optimisation - it is what keeps R-8's DIAGNOSTIC COUNTERS
|
||||
// where they were (P5d r3 package C review, minor 2). In the conjunction below
|
||||
// P4aFamilyHasItsConsumer sits AFTER `(pushMask & subsystem) != 0`, and it answers a
|
||||
// constant `true` for every subsystem outside the P4a families - so at a mask that
|
||||
// carries no P4a bit NO field reaches the caps mirror at all. Asking it here anyway
|
||||
// would have moved CapsMirror::ServerConsumes' refusal count and its one-shot
|
||||
// MGLOG_W at exactly the hand-picked A/B lanes (and the bring-up window, CallMask 0)
|
||||
// where the baseline never touched the mirror, which is the opposite direction from
|
||||
// the one this change is supposed to move them in. The key stays COMPLETE because
|
||||
// pushMask is itself in the key: a mask that gains a P4a bit re-keys on the mask.
|
||||
const Bool p4aConsumer = (pushMask & kMGPipeP4aFamilySubsystems) != 0 &&
|
||||
P4aFamilyHasItsConsumer(kMGPipeP4aFamilySubsystems);
|
||||
if (g_fillPlan.Valid && g_fillPlan.PushMask == pushMask &&
|
||||
g_fillPlan.ApplierDerives == applierDerives &&
|
||||
g_fillPlan.ContextValuesWireLive == contextValuesWireLive &&
|
||||
g_fillPlan.P4aConsumer == p4aConsumer) {
|
||||
return g_fillPlan.Supplied;
|
||||
}
|
||||
MGPipeFieldMask built{};
|
||||
for (SizeT i = 0; i < kMGPipeInputFieldCount; ++i) {
|
||||
const auto field = static_cast<MGPipeInputField>(i);
|
||||
// A field a P2 call now supplies is not pulled again - that second pull is exactly
|
||||
// the cost P2 exists to remove. THE STAMP IS UNCHANGED either way: a stamp says
|
||||
// "this verb published this field", which is as true of an emitted field as of a
|
||||
// copied one, and withholding it would abort every backend read of the very fields
|
||||
// the migration just took over. The stamp is still written at the walk; only the
|
||||
// QUESTION moved up here.
|
||||
const MGPipeFieldEmitter emitter = kMGPipeFieldEmittedBy[i];
|
||||
const Uint64 subsystem = SubsystemForEmitter(emitter);
|
||||
// P4aFamilyHasItsConsumer and P4aFamilyDependenciesAreSet are in this conjunction
|
||||
// for the reason they are in `wants()`: "supplied" means A CALL WENT OUT CARRYING
|
||||
// THIS FIELD, and on a backend with no consumer - or at a mask that leaves one of
|
||||
// the family's D-K2 dependency bits clear - no P4a call went out at all, so
|
||||
// withholding the pull here would leave the field unfilled at the very verb that
|
||||
// reads it.
|
||||
//
|
||||
// AND THE LAST CONJUNCT IS P5c rv's (CONTRACT-P5C.md 5.3): set_context_values has
|
||||
// NO PRODUCER without a live wire (its emission is transport-gated at the validate
|
||||
// point), so its eight fields keep being pulled under monolith - G1's byte-for-byte
|
||||
// rule - and are skipped only when the record really crosses.
|
||||
const Bool supplied = subsystem != 0 && (subsystem & kMGPipeWiredSubsystems) != 0 &&
|
||||
(pushMask & subsystem) != 0 &&
|
||||
P4aFamilyHasItsConsumer(subsystem) &&
|
||||
P4aFamilyDependenciesAreSet(subsystem, pushMask) &&
|
||||
EmittedCallSuppliesTheWholeField(field) &&
|
||||
(applierDerives || AppliedWithoutDerivation(field)) &&
|
||||
(emitter != MGPipeFieldEmitter::SetContextValues ||
|
||||
contextValuesWireLive);
|
||||
if (supplied) built.Words[i / 64] |= (Uint64{1} << (i % 64));
|
||||
}
|
||||
// PUBLISHED IN ONE ASSIGNMENT, after the walk - see the paragraph above the struct.
|
||||
g_fillPlan.Valid = true;
|
||||
g_fillPlan.PushMask = pushMask;
|
||||
g_fillPlan.ApplierDerives = applierDerives;
|
||||
g_fillPlan.ContextValuesWireLive = contextValuesWireLive;
|
||||
g_fillPlan.P4aConsumer = p4aConsumer;
|
||||
g_fillPlan.Supplied = built;
|
||||
return built;
|
||||
}
|
||||
|
||||
// set_pixel_pack_state. PACK only, deliberately: nothing on the far side of the
|
||||
// boundary reads unpack state, and the staged-repack upload path does not even issue
|
||||
@@ -2473,6 +2873,18 @@ namespace MobileGL::MG_Pipe {
|
||||
// Did the applier reproduce it? Byte for byte, over the attributes this call
|
||||
// named - anything less would be a mirror that disagrees with the frontend in a
|
||||
// window no gate looks at.
|
||||
//
|
||||
// P5e (ra, CONTRACT-P5E §3.4): NOT UNDER RUN-AHEAD. The mirror is the APPLIER's
|
||||
// copy of this record, and set_vertex_attrib_defaults is a kWaitNone row - so
|
||||
// under run-ahead this thread has not waited for the apply and the read races it,
|
||||
// and the repair below (a CopyField straight into the block) is precisely the
|
||||
// GL-thread write §3.5 refuses. The client's own authority is `resolved` and
|
||||
// `g_attribDefaultLastHeader`, which is what it just published; there is nothing
|
||||
// the mirror could add that the wire does not already carry. A build that ever
|
||||
// needs the repair arm again has to earn it with a barriered row.
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
if (ClientRunsAhead()) return sizeof(MGPVertexAttribDefaults) + header.Count * sizeof(MGPAttribValue);
|
||||
#endif
|
||||
const auto* mirror = MGPipeFillAccess::VertexAttribDefaultsOf(gPipeInputs);
|
||||
Bool reproduced = true;
|
||||
for (SizeT i = 0; i < kAttribs && reproduced; ++i) {
|
||||
@@ -2772,22 +3184,55 @@ namespace MobileGL::MG_Pipe {
|
||||
Uint64 DrainTextureSubData(GLContext& ctx) {
|
||||
return MGPipeTextureEmitterInstance().DrainTextureSubData(ctx);
|
||||
}
|
||||
|
||||
// ---- P5e's two, and they are TWO adapters over THREE records (sb, §5.6) ----
|
||||
//
|
||||
// The split is the DIRTY BITS' and not the classes': bit 15 is the uniform binding
|
||||
// points and bit 16 is the two writable classes, which share a shutter because a
|
||||
// storage bind and a counter bind are the same event to every reader of the record.
|
||||
// Bit 17's family (set_stream_output_targets) has no adapter at all - XFB stays
|
||||
// lockstep for the whole of P5e (§5.7) - and that absence is the catalogue's split,
|
||||
// not an omission.
|
||||
Uint64 EmitConstBuffers(GLContext& ctx) {
|
||||
return MGPipeShaderBufferEmitterInstance().EmitConstBuffers(ctx);
|
||||
}
|
||||
|
||||
Uint64 EmitShaderBuffers(GLContext& ctx) {
|
||||
return MGPipeShaderBufferEmitterInstance().EmitShaderBuffers(ctx);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Uint64 MGPipeVertexAttribDefaultRepairCount() { return g_attribDefaultRepairs; }
|
||||
MGPVertexAttribDefaults MGPipeVertexAttribDefaultsLastHeader() { return g_attribDefaultLastHeader; }
|
||||
|
||||
// The unit gate's door onto step 4's predicate (PipeFill.h says why it needs one). It
|
||||
// returns the memo's answer rather than a second copy of the expression, so a case that
|
||||
// moves one input and reads the answer back is a statement about the MEMO and not about a
|
||||
// re-implementation of it.
|
||||
Bool MGPipeResidualFillSuppliesField(MGPipeInputField field, Uint64 pushMask, Bool applierDerives,
|
||||
Bool contextValuesWireLive) {
|
||||
return MGPipeFieldMaskHas(SuppliedFieldMask(pushMask, applierDerives, contextValuesWireLive),
|
||||
field);
|
||||
}
|
||||
|
||||
// ---- the validate point (P2 brief D1) ----
|
||||
void MGPipeValidateForVerb(MGPipeVerb verb) {
|
||||
PipeInputs& inputs = gPipeInputs;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5c (gt, CONTRACT-P5C §6 layer 2): the residual fill is THE client-side write into
|
||||
// gPipeInputs, and it is legal only because it runs before the record is published -
|
||||
// under an armed barrier the apply thread's in-applier flag is provably down here. If
|
||||
// that ever stops being true this is the check that says so, rather than the applier
|
||||
// reading a half-written fill.
|
||||
MG_Remote::Client::ClientSession::RefusePipeInputsTouchWhileApplierOwnsIt(
|
||||
"MGPipeValidateForVerb");
|
||||
// ---- P5e (ra), CONTRACT-P5E §3: WHO OWNS gPipeInputs FOR THIS VERB ----------------
|
||||
//
|
||||
// Under run-ahead the block is SERVER-ROLE MEMORY for an unbarriered record: the
|
||||
// client does not fill it, does not stamp it and does not withdraw the server's stamp,
|
||||
// because it will not be parked while the apply runs and every one of those writes
|
||||
// would race the applier's own reads. What still runs, unchanged, is the tracker walk
|
||||
// and the emitters (steps 2 and 3): those PRODUCE RECORDS, which is the whole of what
|
||||
// an unbarriered verb is allowed to hand the server.
|
||||
//
|
||||
// `fillOwed` is deliberately a separate name from `barriered`, and that is what makes
|
||||
// the red-once one line: setting it to `true` restores the old behaviour (a fill for
|
||||
// every verb) and the guard below then fires Fatal{RoleViolation, "gPipeInputs"} on
|
||||
// the first unbarriered verb, by name.
|
||||
const Bool runAhead = ClientRunsAhead();
|
||||
#endif
|
||||
ParsePoisonOmissionKnob();
|
||||
#if MOBILEGL_PIPE_VERIFY
|
||||
@@ -2800,24 +3245,63 @@ namespace MobileGL::MG_Pipe {
|
||||
"(configure with -DMOBILEGL_PIPE_VERIFY=ON)");
|
||||
}
|
||||
#endif
|
||||
auto* ctx = LiveContext();
|
||||
// THE IDENTITY / LIVENESS PAIR IS WRITTEN ON EVERY VERB, run-ahead or not, and that is
|
||||
// a NAMED DEVIATION from CONTRACT-P5E §3.1's list (see the report): `m_live` and
|
||||
// `m_contextIdentity` are not FIELDS of the residual model - no FieldOwnership.def row
|
||||
// owns them, no applier record carries them, and no server stamp can answer them -
|
||||
// they are "does this process still have a GL context", which every null-context guard
|
||||
// in the backend reads and which only this thread can know. Two stores, no freshness
|
||||
// and no stamp, so an unbarriered apply reading them reads a fact about the client's
|
||||
// process rather than a value the wire owes it.
|
||||
MGPipeFillAccess::SetIdentity(inputs, ctx);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// §2.1's predicate, client-side (see ClientVerbIsBarriered).
|
||||
const Bool barriered = !runAhead || ClientVerbIsBarriered(verb, ctx);
|
||||
// THE ONE LINE THE RED-ONCE FLIPS: `= true` here is "fill for every verb", the
|
||||
// pre-P5e behaviour, and it turns the guard below into the abort §3.5 names.
|
||||
const Bool fillOwed = barriered;
|
||||
g_lastFillWasBarriered = fillOwed;
|
||||
if (fillOwed) {
|
||||
// P5c (gt, CONTRACT-P5C §6 layer 2) / P5e §3.5: the residual fill is THE
|
||||
// client-side write into gPipeInputs. Under lockstep it is legal because it runs
|
||||
// before the record is published - the apply thread's in-applier flag is provably
|
||||
// down here. Under run-ahead it is legal because this record is BARRIERED: this
|
||||
// thread is about to park behind it. The second argument is which of the two
|
||||
// claims the caller is making, and a fill that made the second one falsely is the
|
||||
// named abort.
|
||||
MG_Remote::Client::ClientSession::RefusePipeInputsTouchWhileApplierOwnsIt(
|
||||
"MGPipeValidateForVerb", /*isBarrieredFill=*/barriered);
|
||||
}
|
||||
#else
|
||||
constexpr Bool fillOwed = true;
|
||||
#endif
|
||||
if (fillOwed) {
|
||||
#if MOBILEGL_PIPE_POISON
|
||||
MGPipeFilledState& filled = MGPipeFillAccess::Filled(inputs);
|
||||
// Starts at 1: FilledGen == 0 is "never filled", and MGPipeInputFieldIsFresh refuses
|
||||
// it on both branches, so a read before this first bump is
|
||||
// Fatal{UnmigratedPipeInput, "<Field>@<none>"} rather than default storage.
|
||||
++filled.CurrentVerbSerial;
|
||||
// Starts at 1: FilledGen == 0 is "never filled", and MGPipeInputFieldIsFresh
|
||||
// refuses it on both branches, so a read before this first bump is
|
||||
// Fatal{UnmigratedPipeInput, "<Field>@<none>"} rather than default storage.
|
||||
++MGPipeFillAccess::Filled(inputs).CurrentVerbSerial;
|
||||
#endif
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The client is filling, so whatever the server stamped at its last verb boundary is
|
||||
// withdrawn: the stamps below are the CLIENT's again and a stale read is a defect, not
|
||||
// a residual pull. Disarming here rather than at the end of the applier's work is what
|
||||
// makes the arming flag say "the current stamps are the server's" no matter which of
|
||||
// the two roles ran last.
|
||||
MGPipeServerClearVerbBoundary();
|
||||
// The client is filling, so whatever the server stamped at its last verb boundary
|
||||
// is withdrawn: the stamps below are the CLIENT's again and a stale read is a
|
||||
// defect, not a residual pull. Disarming here rather than at the end of the
|
||||
// applier's work is what makes the arming flag say "the current stamps are the
|
||||
// server's" no matter which of the two roles ran last.
|
||||
//
|
||||
// P5e (§3.2): under run-ahead this runs only inside a barriered fill, which is the
|
||||
// whole of the E note's hazard (b.4) - a GL thread withdrawing the SERVER's stamp
|
||||
// while the apply thread is inside a record that depends on it. For an unbarriered
|
||||
// verb the stamp is not touched at all, and the applier's own LeaveApplier is then
|
||||
// its only writer.
|
||||
MGPipeServerClearVerbBoundary();
|
||||
#endif
|
||||
MGPipeFillAccess::SetVerb(inputs, verb);
|
||||
}
|
||||
#if MOBILEGL_PIPE_POISON
|
||||
MGPipeFilledState& filled = MGPipeFillAccess::Filled(inputs);
|
||||
#endif
|
||||
MGPipeFillAccess::SetVerb(inputs, verb);
|
||||
auto* ctx = LiveContext();
|
||||
MGPipeFillAccess::SetIdentity(inputs, ctx);
|
||||
if (ctx == nullptr) {
|
||||
// The pending base instance belongs to THIS verb, and this exit skips step 3's
|
||||
// clear, so it has to make the same promise here: a base-instanced draw with no
|
||||
@@ -2882,12 +3366,17 @@ namespace MobileGL::MG_Pipe {
|
||||
#else
|
||||
constexpr Bool contextValuesWireLive = false;
|
||||
#endif
|
||||
// AND THE SEVENTH IS P5eFamilyIsLive (ID-106), which is the same sentence for the
|
||||
// binding-point family and asks bit 13's OWN consumer bit rather than the resource
|
||||
// family's. It answers true for every subsystem but bit 13, so nothing that emitted
|
||||
// before P5e changes.
|
||||
const auto wants = [&](MGPipeDirty bit) {
|
||||
const Uint64 subsystem = MGPipeSubsystemForDirty(bit);
|
||||
return subsystem != 0 && (pushMask & subsystem) != 0 &&
|
||||
(kMGPipeWiredSubsystems & subsystem) != 0 &&
|
||||
P4aFamilyHasItsConsumer(subsystem) &&
|
||||
P4aFamilyDependenciesAreSet(subsystem, pushMask) &&
|
||||
P5eFamilyIsLive(subsystem, pushMask) &&
|
||||
(dirty & MGPipeDirtyBit(bit)) != 0;
|
||||
};
|
||||
Uint64 payloadBytes = 0;
|
||||
@@ -2959,6 +3448,13 @@ namespace MobileGL::MG_Pipe {
|
||||
MGPipeSamplerEmitterInstance().Reset();
|
||||
MGPipeImageEmitterInstance().Reset();
|
||||
MGPipeProgramEmitterInstance().Reset();
|
||||
// P5e (sb): and the binding-point emitter's mirrors. MGPipeApplierReset clears all
|
||||
// three of the applier's windows and ADVANCES ShaderBuffersSerial, so the emitter's
|
||||
// latch has to reset with it - the three suppressor slots are already cleared by
|
||||
// InvalidateAll() above, and without that the first emission after a make-current
|
||||
// would be suppressed as unchanged and the server would draw against a window it
|
||||
// had just been told to empty.
|
||||
MGPipeShaderBufferEmitterInstance().Reset();
|
||||
g_residualDue = true;
|
||||
}
|
||||
|
||||
@@ -3008,6 +3504,24 @@ namespace MobileGL::MG_Pipe {
|
||||
payloadBytes += EmitGlobalConstants(*ctx);
|
||||
}
|
||||
|
||||
// P5e's segment (sb, §5.6): the indexed buffer binding points, AFTER the program
|
||||
// segment for the same "code organisation, not a contract" reason ARCHITECTURE.md 5.4
|
||||
// gives for P4a's order - all of a verb's set_*/bind_* complete before the verb, and
|
||||
// the server resolves a point against its own descriptor at its sync point. It reads
|
||||
// better here because the uniform window is what the program's block bindings INDEX
|
||||
// (DirectGLES.cpp's UBO loop), so the two records that describe a draw's uniform
|
||||
// buffers stand together.
|
||||
//
|
||||
// NOTHING FOR BIT 17: set_stream_output_targets stays unemitted for the whole of P5e
|
||||
// (§5.7). The bit is still computed, counted and mapped onto this subsystem, so an
|
||||
// operator clearing bit 13 gets the whole family's frontend walk back.
|
||||
if (wants(MGPipeDirty::NewConstBuffers)) {
|
||||
payloadBytes += EmitConstBuffers(*ctx);
|
||||
}
|
||||
if (wants(MGPipeDirty::NewShaderBuffers)) {
|
||||
payloadBytes += EmitShaderBuffers(*ctx);
|
||||
}
|
||||
|
||||
if (wants(MGPipeDirty::NewPipelineState) || wants(MGPipeDirty::NewRenderState)) {
|
||||
payloadBytes += EmitRenderState(*ctx, dirty, tracker.FreshlyPrimed());
|
||||
}
|
||||
@@ -3057,8 +3571,26 @@ namespace MobileGL::MG_Pipe {
|
||||
tracker.ClearPendingBaseInstance();
|
||||
|
||||
// ---- step 4: the residual fill, for what an emitted call did NOT supply ----
|
||||
// THE SUPPLIED QUESTION IS ASKED ONCE PER ENVIRONMENT, NOT ONCE PER FIELD PER VERB
|
||||
// (SuppliedFieldMask above, P5d r3 package C): the conjunction it used to spell inline
|
||||
// here reads nothing about the verb, so it is a memo keyed on the four process facts it
|
||||
// does read. The two halves of P5c rv's gate still read the ONE `contextValuesWireLive`
|
||||
// computed at the top of this function - it is the memo's key AND its argument - so they
|
||||
// cannot disagree about who supplies the eight value-class fields.
|
||||
//
|
||||
// P5e (ra, §3.1): AND IT DOES NOT RUN AT ALL FOR AN UNBARRIERED RECORD. Every write
|
||||
// below - the CopyField and the FilledGen stamp alike - is a GL-thread write into a
|
||||
// block the apply thread is about to read without this thread being parked, which is
|
||||
// exactly what rule F forbids. The server does not go without an answer: it stamps its
|
||||
// own boundary and §3.3's detector turns any field it still needs from here into
|
||||
// Fatal{UnmigratedPipeInput, "<field>@<verb>"} by name, which is what makes the strict
|
||||
// lane a gate rather than a count.
|
||||
const Bool applierDerives = ApplierDerivesRenderStateFields();
|
||||
for (SizeT i = 0; i < kMGPipeInputFieldCount; ++i) {
|
||||
// BY VALUE, NOT BY REFERENCE: the memo's storage is rebuilt in place when the key moves,
|
||||
// and the walk below holds this across 63 iterations.
|
||||
const MGPipeFieldMask supplied =
|
||||
SuppliedFieldMask(pushMask, applierDerives, contextValuesWireLive);
|
||||
for (SizeT i = 0; fillOwed && i < kMGPipeInputFieldCount; ++i) {
|
||||
const auto field = static_cast<MGPipeInputField>(i);
|
||||
if (!MGPipeFieldMaskHas(mask, field)) continue;
|
||||
#if MOBILEGL_PIPE_POISON
|
||||
@@ -3071,33 +3603,7 @@ namespace MobileGL::MG_Pipe {
|
||||
#else
|
||||
if (kMGPipeInputFieldSticky[i]) continue;
|
||||
#endif
|
||||
// A field a P2 call now supplies is not pulled again - that second pull is
|
||||
// exactly the cost P2 exists to remove. THE STAMP IS UNCHANGED either way: a
|
||||
// stamp says "this verb published this field", which is as true of an emitted
|
||||
// field as of a copied one, and withholding it would abort every backend read of
|
||||
// the very fields the migration just took over.
|
||||
const MGPipeFieldEmitter emitter = kMGPipeFieldEmittedBy[i];
|
||||
const Uint64 subsystem = SubsystemForEmitter(emitter);
|
||||
// P4aFamilyHasItsConsumer and P4aFamilyDependenciesAreSet are in this conjunction for
|
||||
// the reason they are in `wants()`: "supplied" means A CALL WENT OUT CARRYING THIS
|
||||
// FIELD, and on a backend with no consumer - or at a mask that leaves one of the
|
||||
// family's D-K2 dependency bits clear - no P4a call went out at all, so withholding
|
||||
// the pull here would leave the field unfilled at the very verb that reads it.
|
||||
//
|
||||
// AND THE LAST CONJUNCT IS P5c rv's (CONTRACT-P5C.md §5.3): set_context_values has
|
||||
// NO PRODUCER without a live wire (its emission is transport-gated, above), so its
|
||||
// eight fields keep being pulled under monolith - G1's byte-for-byte rule - and are
|
||||
// skipped only when the record really crosses. The two sides read the ONE answer
|
||||
// computed at the top of this function, so they cannot disagree.
|
||||
const Bool supplied = subsystem != 0 && (subsystem & kMGPipeWiredSubsystems) != 0 &&
|
||||
(pushMask & subsystem) != 0 &&
|
||||
P4aFamilyHasItsConsumer(subsystem) &&
|
||||
P4aFamilyDependenciesAreSet(subsystem, pushMask) &&
|
||||
EmittedCallSuppliesTheWholeField(field) &&
|
||||
(applierDerives || AppliedWithoutDerivation(field)) &&
|
||||
(emitter != MGPipeFieldEmitter::SetContextValues ||
|
||||
contextValuesWireLive);
|
||||
if (!supplied) MGPipeFillAccess::CopyField(inputs, *ctx, field);
|
||||
if (!MGPipeFieldMaskHas(supplied, field)) MGPipeFillAccess::CopyField(inputs, *ctx, field);
|
||||
#if MOBILEGL_PIPE_POISON
|
||||
// The value is copied either way; only the stamp is withheld for the omitted pair.
|
||||
if (!IsOmitted(verb, field)) filled.FilledGen[i] = filled.CurrentVerbSerial;
|
||||
|
||||
@@ -70,6 +70,29 @@ namespace MobileGL::MG_Pipe {
|
||||
// through it, and this returns that same expression rather than a second copy of it.
|
||||
Bool MGPipeP4aFamilyEmits(Uint64 subsystem, Uint64 wired);
|
||||
|
||||
// PipeFill.cpp. DOES AN EMITTED CALL SUPPLY THIS FIELD at the environment named, i.e. would
|
||||
// the validate point's residual fill SKIP it? This is step 4's own predicate, which P5d
|
||||
// round 3 (package C) turned from a per-field-per-verb conjunction into a memo keyed on the
|
||||
// three arguments plus the P4a consumer signal it reads for itself - the profile had it at
|
||||
// 63 CapsMirror reads per verb for one answer.
|
||||
//
|
||||
// IT IS EXPORTED FOR THE UNIT GATE AND FOR NO OTHER CALLER, for MGPipeP4aFamilyEmits'
|
||||
// reason and one of its own: which fields the fill copies has NO other observable, because
|
||||
// in a push build every emission this predicate asks about is routed straight into the
|
||||
// applier, which writes the same storage the fill would have written. So the only way to
|
||||
// state "the memo's key is complete" - the one thing a memo can get wrong that the
|
||||
// expression it replaced could not - is to ask it directly. A call re-keys the memo, which
|
||||
// is exactly what the case is for.
|
||||
//
|
||||
// AND A STALE ANSWER IS SILENT, WHICH IS WHY THAT CASE IS THE ONLY GUARD. It is tempting to
|
||||
// say a wrongly-skipped field aborts as Fatal{UnmigratedPipeInput}; it does not. The walk
|
||||
// stamps FilledGen from the verb serial whether or not it copied (PipeFill.cpp, step 4), so
|
||||
// a field the fill skips reads FRESH with the PREVIOUS verb's value - a stale binding slot
|
||||
// rendered without a word, caught only by the verify lane's comparison. Poison catches an
|
||||
// UNSTAMPED read, not a stamped-but-uncopied one.
|
||||
Bool MGPipeResidualFillSuppliesField(MGPipeInputField field, Uint64 pushMask, Bool applierDerives,
|
||||
Bool contextValuesWireLive);
|
||||
|
||||
// PipeFill.cpp. P3a D-H2.1: the DRAW's raw vertex-fetch base instance, which
|
||||
// set_vertex_buffers now carries as an explicit field.
|
||||
//
|
||||
|
||||
@@ -79,6 +79,25 @@ namespace MobileGL::MG_Pipe {
|
||||
// would describe a program that does not exist yet. GetLinkedShaderStages() is also what
|
||||
// indexes GetGeneratedSpirv(), so the two halves of this descriptor are guaranteed to agree
|
||||
// by construction rather than by care.
|
||||
// P5e (pg). ONE ENTRY OF THE STORAGE-OVERRIDE SIGNATURE, and it is a VERBATIM copy of the
|
||||
// mix in `MG_Backend/DirectGLES/Managers.cpp`'s ComputeShaderStorageBlockBindingSignature -
|
||||
// the function whose answer this record replaces on the handle arm. The two halves cannot
|
||||
// share one definition today because MG_Backend includes nothing from MG_Impl (checked at
|
||||
// this head), so they are twins with a named pointer at each other and a unit case in
|
||||
// ProgramEmitTest that pins the number. Order-independent by construction: the source is an
|
||||
// UnorderedMap, the combine is commutative, and the entry mixes name and binding so two
|
||||
// entries cannot trade halves and cancel out.
|
||||
//
|
||||
// OVER THE VALUES, NOT OVER A CHANGE COUNTER, which is the property the pipeline composite's
|
||||
// uniform mirror depends on: it re-sets every override every draw, and re-setting a block to
|
||||
// the binding it already carries must produce the same signature and force no rebuild.
|
||||
inline Uint64 MGPipeStorageOverrideSignatureEntry(const String& blockName, Int binding) {
|
||||
Uint64 entry = std::hash<String>{}(blockName);
|
||||
entry ^= (static_cast<Uint64>(static_cast<Uint32>(binding)) + 0x9e3779b97f4a7c15ull +
|
||||
(entry << 6) + (entry >> 2));
|
||||
return entry;
|
||||
}
|
||||
|
||||
inline Uint32 MGPipeStageMaskOf(const MG_State::GLState::ProgramObject& program) {
|
||||
Uint32 mask = 0;
|
||||
for (const ShaderStage stage : program.GetLinkedShaderStages()) {
|
||||
@@ -109,6 +128,17 @@ namespace MobileGL::MG_Pipe {
|
||||
|
||||
const MGPipeHandle drawCso =
|
||||
drawProgram ? AcquireShaderCso(*drawProgram, bytes) : kMGPipeNullHandle;
|
||||
// P5e (pg): AFTER the create and never before it. The draft note on
|
||||
// MGPProgramBindings said "emitted BEFORE create_shader_state at the same validate
|
||||
// point", and that ordering is wrong against the applier the same contract
|
||||
// specifies: a re-issued create CLEARS all three tails, for the reason it clears
|
||||
// GlobalConstants (a relink replaces the archive the tails index into), so bindings
|
||||
// published ahead of it are wiped by the create that follows. What the draft was
|
||||
// protecting - "a rebuild inside the verb must already see the bindings" - is
|
||||
// satisfied by both records going out at the SAME validate point, ahead of the verb,
|
||||
// which is what this ordering does. See MG_Remote/CONTRACT-P5E.md §5.5 and the
|
||||
// record's own comment in PipeApply.h.
|
||||
if (drawProgram) bytes += EmitProgramBindings(*drawProgram, drawCso);
|
||||
// THE COMPOSITE'S SECOND RELEASE PATH is spoken here, not in a destructor: when the
|
||||
// bound pipeline's draw-program signature moves, the resolver releases the slot the
|
||||
// previous composite held. Whichever of the two paths runs second - this one or the
|
||||
@@ -130,6 +160,9 @@ namespace MobileGL::MG_Pipe {
|
||||
dispatchProgram ? (dispatchProgram == drawProgram ? drawCso
|
||||
: AcquireShaderCso(*dispatchProgram, bytes))
|
||||
: kMGPipeNullHandle;
|
||||
if (dispatchProgram && dispatchProgram != drawProgram) {
|
||||
bytes += EmitProgramBindings(*dispatchProgram, dispatchCso);
|
||||
}
|
||||
|
||||
// THE BOUND CSO IS THE DRAW ONE WHEN THERE IS ONE. bind_shader_state names what
|
||||
// glUseProgram selected, and when a program pipeline is bound instead that is the
|
||||
@@ -208,6 +241,136 @@ namespace MobileGL::MG_Pipe {
|
||||
return bytes + sizeof(MGPGlobalConstants) + size;
|
||||
}
|
||||
|
||||
// ---- P5e (pg): set_program_bindings, opcode 80 -----------------------------------
|
||||
//
|
||||
// THE THREE POST-LINK MUTABLE REFLECTION FIELDS, and why an archive alone is not an
|
||||
// answer. `uniformBlockBinding[i]`, `uniformSamplerOrImageUnitIndex[loc]` and the
|
||||
// name-keyed `shaderStorageBlockBinding` map are all MEMBERS OF LinkArtifacts - so the
|
||||
// archive create_shader_state carries does hold them - but glUniformBlockBinding,
|
||||
// glUniform1i on a sampler uniform and glShaderStorageBlockBinding all move them AFTER
|
||||
// the link that produced that archive, without relinking. A server answering a draw
|
||||
// from the archive alone would bind the uniform blocks the program was LINKED with
|
||||
// rather than the ones it is BOUND with. This record is the delta carrier; the applier
|
||||
// overlays it on the archive, and a re-issued create drops it because the indices no
|
||||
// longer mean anything.
|
||||
//
|
||||
// LATCHED ON THE TWO COUNTERS THAT MOVE WHEN ANY OF THE THREE DOES, plus the handle:
|
||||
// m_backendStateVersion (glUniformBlockBinding and glUniform1i both bump it) and
|
||||
// m_blockBindingVersion (glUniformBlockBinding and glShaderStorageBlockBinding both
|
||||
// bump it, and the storage setter deliberately bumps ONLY it). Neither setter moves a
|
||||
// counter on an unchanged value - both have an equality bail-out - so an application
|
||||
// that re-sets the same bindings every frame emits nothing, which is what the pipeline
|
||||
// composite's uniform mirror needs (it replays every override per draw).
|
||||
Uint64 EmitProgramBindings(const ProgramObject& program, MGPipeHandle cso) {
|
||||
if (MGPipeHandleIsNull(cso)) return 0;
|
||||
const Uint32 backendStateVersion = program.GetBackendStateVersion();
|
||||
const Uint32 blockBindingVersion = program.GetBlockBindingVersion();
|
||||
Latch& latch = LatchFor(cso);
|
||||
if (latch.BindingsLive && latch.BindingsGen == cso.Gen &&
|
||||
latch.BindingsBackendStateVersion == backendStateVersion &&
|
||||
latch.BindingsBlockBindingVersion == blockBindingVersion) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_blockBindings.clear();
|
||||
m_samplerUnits.clear();
|
||||
m_storageOverrides.clear();
|
||||
m_storageOverrideNames.clear();
|
||||
|
||||
// TAIL 1: dense, in BLOCK index order - the space GetActiveUniformBlocksCount(),
|
||||
// GetUniformBlockName(i) and GetUniformBlockBinding(i) all speak, which is exactly
|
||||
// the space the server's CacheResourceLocations walks. Dense because the server
|
||||
// indexes it by i and a sparse form would need a second index space on the wire.
|
||||
const Int blockCount = program.GetActiveUniformBlocksCount();
|
||||
if (static_cast<Uint32>(std::max(blockCount, 0)) > kMGPipeMaxProgramBlockBindings) {
|
||||
// A COUNTED REFUSAL AND NOT A TRUNCATION (D-J3): a program with more uniform
|
||||
// blocks than the record can name would have the tail of its block set bound
|
||||
// to whatever the archive's link-time snapshot said, silently. The counter is
|
||||
// what makes that visible; the record is not emitted at all, so the server
|
||||
// keeps the archive's values for every block rather than for some of them.
|
||||
++m_bindingRefusals;
|
||||
return 0;
|
||||
}
|
||||
m_blockBindings.reserve(static_cast<SizeT>(std::max(blockCount, 0)));
|
||||
for (Int i = 0; i < blockCount; ++i) {
|
||||
m_blockBindings.push_back(static_cast<Int32>(program.GetUniformBlockBinding(static_cast<Uint>(i))));
|
||||
}
|
||||
|
||||
// TAIL 2: sparse, ascending by LOCATION, because the frontend's array is indexed by
|
||||
// uniform location and maxUniformLocation runs into the thousands while the
|
||||
// sampler count is a handful. -1 is "never assigned" and is what the server's own
|
||||
// default already is, so it is not worth a wire entry.
|
||||
const Uint maxUniformLoc = program.GetMaxUniformLocation();
|
||||
for (Uint loc = 0; loc <= maxUniformLoc; ++loc) {
|
||||
// The same guard CacheResourceLocations uses one level down: a location with no
|
||||
// uniform behind it has an empty name and must not index the type tables.
|
||||
if (program.GetUniformName(loc).empty()) continue;
|
||||
const Int unit = program.GetUniformSamplerOrImageUnitIndex(loc);
|
||||
if (unit < 0) continue;
|
||||
if (m_samplerUnits.size() >= kMGPipeMaxProgramSamplerUnits) {
|
||||
++m_bindingRefusals;
|
||||
return 0;
|
||||
}
|
||||
MGPProgramSamplerUnit entry{};
|
||||
entry.Location = loc;
|
||||
entry.Unit = static_cast<Int32>(unit);
|
||||
m_samplerUnits.push_back(entry);
|
||||
}
|
||||
|
||||
// TAIL 3: name-keyed BY DESIGN. A shader storage block has three index spaces - the
|
||||
// frontend interface query, DirectVulkan's descriptor order and the real driver's -
|
||||
// and the name is the only coordinate all three agree on (ProgramObject.h says so
|
||||
// over the setter). Empty for the overwhelming majority of programs, which is why
|
||||
// the signature below exists: the server compares one Uint64 and touches the names
|
||||
// only on a rebuild.
|
||||
const auto& overrides = program.GetShaderStorageBlockBindingOverrides();
|
||||
if (overrides.size() > kMGPipeMaxProgramStorageOverrides) {
|
||||
++m_bindingRefusals;
|
||||
return 0;
|
||||
}
|
||||
Uint64 signature = 0;
|
||||
m_storageOverrides.reserve(overrides.size());
|
||||
m_storageOverrideNames.reserve(overrides.size());
|
||||
for (const auto& [blockName, binding] : overrides) {
|
||||
if (binding < 0) continue; // never rebound; the declared qualifier still stands
|
||||
MGPProgramStorageOverride entry{};
|
||||
entry.Binding = binding;
|
||||
m_storageOverrides.push_back(entry);
|
||||
m_storageOverrideNames.push_back(blockName);
|
||||
signature += MGPipeStorageOverrideSignatureEntry(blockName, binding);
|
||||
}
|
||||
m_storageOverrides.resize(m_storageOverrideNames.size());
|
||||
|
||||
m_lastBindings = MGPProgramBindings{};
|
||||
m_lastBindings.Cso = cso;
|
||||
m_lastBindings.Signature = signature;
|
||||
m_lastBindings.BlockBindingCount = static_cast<Uint32>(m_blockBindings.size());
|
||||
m_lastBindings.SamplerUnitCount = static_cast<Uint32>(m_samplerUnits.size());
|
||||
m_lastBindings.StorageOverrideCount = static_cast<Uint32>(m_storageOverrides.size());
|
||||
|
||||
// The name POINTERS, index-aligned with the override tail. Built here rather than
|
||||
// inside the loop because push_back on m_storageOverrideNames may reallocate and
|
||||
// every c_str() taken before that would dangle.
|
||||
m_storageOverrideNamePtrs.clear();
|
||||
m_storageOverrideNamePtrs.reserve(m_storageOverrideNames.size());
|
||||
for (const String& name : m_storageOverrideNames) m_storageOverrideNamePtrs.push_back(name.c_str());
|
||||
|
||||
MGPipeRouteSetProgramBindings(
|
||||
m_lastBindings, m_blockBindings.empty() ? nullptr : m_blockBindings.data(),
|
||||
m_samplerUnits.empty() ? nullptr : m_samplerUnits.data(),
|
||||
m_storageOverrides.empty() ? nullptr : m_storageOverrides.data(),
|
||||
m_storageOverrideNamePtrs.empty() ? nullptr : m_storageOverrideNamePtrs.data());
|
||||
++m_bindingSets;
|
||||
|
||||
latch.BindingsLive = true;
|
||||
latch.BindingsGen = cso.Gen;
|
||||
latch.BindingsBackendStateVersion = backendStateVersion;
|
||||
latch.BindingsBlockBindingVersion = blockBindingVersion;
|
||||
return sizeof(MGPProgramBindings) + m_blockBindings.size() * sizeof(Int32) +
|
||||
m_samplerUnits.size() * sizeof(MGPProgramSamplerUnit) +
|
||||
m_storageOverrides.size() * sizeof(MGPProgramStorageOverride);
|
||||
}
|
||||
|
||||
// D-H4's re-issue rule, and it is the CreateVertexElements shape one for one: the
|
||||
// record goes out again on the SAME handle whenever the link version moves, which is
|
||||
// legal because MGPipeHandle::Gen increments only on slot reuse and never on a
|
||||
@@ -232,6 +395,21 @@ namespace MobileGL::MG_Pipe {
|
||||
m_lastDesc.GlobalUboSize = static_cast<Uint32>(program.GetUBOSize());
|
||||
m_lastDesc.ReservedNumSamplesOffset = static_cast<Uint32>(spirv.reservedNumSamplesOffset);
|
||||
m_lastDesc.SpirvStatus = spirv.spirvStatus ? 1 : 0;
|
||||
// P5e (pg), ID-88 / ruling 9: THE FAILED RELINK OF A BOUND PROGRAM, and the ruling
|
||||
// asked this package to verify the frontend's actual behaviour rather than assume
|
||||
// it. VERIFIED, at ProgramObject.cpp:510-531: `Link()`'s PROLOGUE bumps
|
||||
// m_linkVersion and then assigns `m_artifacts = {}` - "the complete not-linked
|
||||
// state" in its own words - before the link body runs, and every failure arm of
|
||||
// ProgramLinkTask leaves `linkStatus = false`. So a failed relink reports UNLINKED
|
||||
// through GetLinkStatus(), the re-issue this latch triggers is the one the ruling
|
||||
// names, and it carries LinkStatus = 0.
|
||||
//
|
||||
// AND NEVER AN object_death: the program object is alive, its handle is alive, and
|
||||
// its twin must stay alive to be rebuilt by the next successful link. What the
|
||||
// server does with LinkStatus = 0 is exactly what the monolith arm already does
|
||||
// with GetLinkStatus() == false - glUseProgram(0), a visible no-op draw - which is
|
||||
// also what GL requires, since MobileGL's frontend withdraws LINK_STATUS here.
|
||||
m_lastDesc.LinkStatus = program.GetLinkStatus() ? 1 : 0;
|
||||
m_lastDesc.NativeFloat64 = spirv.nativeFloat64 ? 1 : 0;
|
||||
m_lastDesc.PointSizeDemoted = spirv.pointSizeDemoted ? 1 : 0;
|
||||
m_lastDesc.EnableSpirvValidation = spirv.enableSpirvValidation ? 1 : 0;
|
||||
@@ -260,7 +438,20 @@ namespace MobileGL::MG_Pipe {
|
||||
m_lastDesc.Reflection.Offset = reinterpret_cast<Uint64>(&link);
|
||||
m_lastDesc.Reflection.Size = 0;
|
||||
|
||||
MGPipeRouteCreateShaderState(m_lastDesc, &link, &spirv);
|
||||
// P5e (pg): THE STAGE OF EACH MODULE, beside the modules and not folded into
|
||||
// StageMask. StageMask is a bit SET and GL lets two shader objects of one stage be
|
||||
// attached to a program, so a list rebuilt from it can be SHORTER than
|
||||
// generatedSpirv - and the server pairs the two by one running index. The client
|
||||
// arm frames this in front of the archive; the monolith arm discards it and reads
|
||||
// the snapshot off the object it is handed. Taken from the same accessor
|
||||
// MGPipeStageMaskOf walks, so the mask and the list cannot disagree.
|
||||
m_linkedStageWords.clear();
|
||||
for (const ShaderStage stage : program.GetLinkedShaderStages()) {
|
||||
m_linkedStageWords.push_back(static_cast<Uint32>(stage));
|
||||
}
|
||||
|
||||
MGPipeRouteCreateShaderState(m_lastDesc, &link, &spirv, m_linkedStageWords.data(),
|
||||
static_cast<Uint32>(m_linkedStageWords.size()));
|
||||
// THE CREATE WENT OUT, so the publication latch is taken here and nowhere else
|
||||
// (contract-v2 §3.1). MGPipeEmitShaderCsoDestroyAndFree reads it, and without it
|
||||
// delete_shader_state can never go out - for an ordinary program or for a
|
||||
@@ -283,6 +474,14 @@ namespace MobileGL::MG_Pipe {
|
||||
m_constantsVersion = kMGPipeGlobalConstantsNeverUploaded;
|
||||
}
|
||||
|
||||
// P5e (pg): THE BINDINGS LATCH GOES WITH THE GLOBAL-CONSTANTS ONE, and for the same
|
||||
// reason stated one branch up. The applier clears all three binding tails on a
|
||||
// re-issued create (the indices point into an archive that has just been replaced),
|
||||
// so a latch that survived it would suppress the very record that has to re-establish
|
||||
// them and the server would draw the whole program off the archive's link-time
|
||||
// snapshot. Invalidated rather than emitted here: EmitShaderState sends the bindings
|
||||
// immediately after this returns, which is also the ONLY order that works.
|
||||
latch.BindingsLive = false;
|
||||
latch.RecordLive = true;
|
||||
latch.RecordGen = handle.Gen;
|
||||
latch.LinkVersion = linkVersion;
|
||||
@@ -304,7 +503,13 @@ namespace MobileGL::MG_Pipe {
|
||||
// validate-point emission and has no payload budget to report into.
|
||||
void EmitShaderCso(ProgramObject& program) {
|
||||
Uint64 bytes = 0;
|
||||
AcquireShaderCso(program, bytes);
|
||||
const MGPipeHandle cso = AcquireShaderCso(program, bytes);
|
||||
// P5e (pg): the birth hook publishes the bindings too, for the same reason the
|
||||
// validate point does. A program born here and drawn before the next validate point
|
||||
// would otherwise reach the server with its archive's LINK-TIME snapshot and no
|
||||
// delta, which is right only for a program nothing has rebound since - and this
|
||||
// hook is exactly where a program that WAS rebound at creation time arrives.
|
||||
EmitProgramBindings(program, cso);
|
||||
}
|
||||
|
||||
// The emitter's OWN record memo - "have I already published a create_shader_state at
|
||||
@@ -378,6 +583,7 @@ namespace MobileGL::MG_Pipe {
|
||||
void ResetCounters() {
|
||||
m_creates = m_binds = m_drawSets = m_dispatchSets = m_constantSets = 0;
|
||||
m_moduleTruncations = 0;
|
||||
m_bindingSets = m_bindingRefusals = 0;
|
||||
}
|
||||
|
||||
// ---- what a unit case reads ----
|
||||
@@ -399,6 +605,15 @@ namespace MobileGL::MG_Pipe {
|
||||
Uint64 DrawProgramSetCount() const { return m_drawSets; }
|
||||
Uint64 DispatchProgramSetCount() const { return m_dispatchSets; }
|
||||
Uint64 GlobalConstantsSetCount() const { return m_constantSets; }
|
||||
// P5e (pg). The record a case reads back, and the two counters D-J3's rule asks for:
|
||||
// how many set_program_bindings went out, and how many programs were REFUSED because
|
||||
// one of their three sets is larger than the record can name. A refusal leaves the
|
||||
// server on the archive's link-time snapshot for that program - correct for anything
|
||||
// that was never rebound after the link, wrong for anything that was, and countable
|
||||
// either way, which is the whole point of not truncating.
|
||||
const MGPProgramBindings& LastProgramBindings() const { return m_lastBindings; }
|
||||
Uint64 ProgramBindingsSetCount() const { return m_bindingSets; }
|
||||
Uint64 ProgramBindingsRefusalCount() const { return m_bindingRefusals; }
|
||||
|
||||
private:
|
||||
// THE ONE PLACE THE BAND CAN ENTER. An ordinary program's slot comes from the ordinary
|
||||
@@ -426,6 +641,15 @@ namespace MobileGL::MG_Pipe {
|
||||
Bool RecordLive = false;
|
||||
Uint32 RecordGen = 0;
|
||||
Uint32 LinkVersion = 0;
|
||||
// P5e (pg): set_program_bindings' own key, in the SAME latch because it is keyed on
|
||||
// the same handle and a slot recycle has to invalidate both at once. Kept separate
|
||||
// from RecordLive because the two records have different triggers - a create fires
|
||||
// on a link-version move, the bindings fire on a binding move without a relink, and
|
||||
// most frames have neither.
|
||||
Bool BindingsLive = false;
|
||||
Uint32 BindingsGen = 0;
|
||||
Uint32 BindingsBackendStateVersion = 0;
|
||||
Uint32 BindingsBlockBindingVersion = 0;
|
||||
};
|
||||
|
||||
// TWO TABLES, NOT A WIDER ONE, and it is the allocator's own reason repeated where it
|
||||
@@ -461,6 +685,19 @@ namespace MobileGL::MG_Pipe {
|
||||
|
||||
MGPProgramDesc m_lastDesc{};
|
||||
MGPGlobalConstants m_lastConstants{};
|
||||
// P5e (pg): the three tails and their names, MEMBERS rather than locals so the steady
|
||||
// frame allocates nothing - the same reason every other emitter in this directory keeps
|
||||
// its scratch. Cleared and refilled per emission; none of them outlives the route call
|
||||
// except as the record's own copy on the far side (rule C).
|
||||
MGPProgramBindings m_lastBindings{};
|
||||
Vector<Int32> m_blockBindings;
|
||||
Vector<MGPProgramSamplerUnit> m_samplerUnits;
|
||||
Vector<MGPProgramStorageOverride> m_storageOverrides;
|
||||
Vector<String> m_storageOverrideNames;
|
||||
Vector<const char*> m_storageOverrideNamePtrs;
|
||||
// The stage of each module of the descriptor being built, index-aligned with
|
||||
// GetGeneratedSpirv(); the client arm frames it in front of the archive.
|
||||
Vector<Uint32> m_linkedStageWords;
|
||||
|
||||
Vector<Latch> m_latch;
|
||||
Vector<Latch> m_compositeLatch;
|
||||
@@ -476,6 +713,8 @@ namespace MobileGL::MG_Pipe {
|
||||
Uint64 m_dispatchSets = 0;
|
||||
Uint64 m_constantSets = 0;
|
||||
Uint64 m_moduleTruncations = 0;
|
||||
Uint64 m_bindingSets = 0;
|
||||
Uint64 m_bindingRefusals = 0;
|
||||
};
|
||||
|
||||
inline MGPipeProgramEmitter& MGPipeProgramEmitterInstance() {
|
||||
|
||||
@@ -717,10 +717,15 @@ namespace MobileGL::MG_Pipe {
|
||||
const MGPipeHandle res = [&]() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// CONTRACT-P5C §3.1's named exemption, Magma's half: the binding records that
|
||||
// would carry this buffer's handle are P4b's to emit and Magma's server-side
|
||||
// would carry this buffer's handle are sb's to emit and Magma's server-side
|
||||
// binding table is P7's, so until then the probe runs inside the scope - the
|
||||
// debt's named, greppable form rather than a silent guard removal.
|
||||
const MGPipeReverseAnnouncementScope reverseAnnouncement;
|
||||
//
|
||||
// P5e (id), ruling 12: the FOURTH of Magma's apply-thread allocator debts and the
|
||||
// last user of the scope P5e renamed. Espryt never reaches this arm under a
|
||||
// transport - MarkBufferGpuWrittenByHandle carries the handle from the record side
|
||||
// (sb/fb) - so the DirectVulkan key on the exemption costs it nothing.
|
||||
const MagmaP7AllocatorDebtScope magmaP7AllocatorDebt;
|
||||
#endif
|
||||
return MGPipeSlots().FindByLifetimeId(MGPipeKind::Buffer, bufferObject->GetLifetimeId());
|
||||
}();
|
||||
|
||||
@@ -62,8 +62,23 @@ namespace MobileGL::MG_Pipe {
|
||||
SetSamplerViews, // P4a - wired (backend debounce deletion: P3b/P4b)
|
||||
BindSamplerStates, // P4a - wired (backend debounce deletion: P3b/P4b)
|
||||
SetShaderImages, // P4a - wired (backend debounce deletion: P3b/P4b)
|
||||
SetShaderBuffers, // P4b
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §1, ruling 11): THREE SLOTS, ONE PER CLASS, not one
|
||||
// for the call. set_shader_buffers is emitted per Class (Uniform / ShaderStorage /
|
||||
// AtomicCounter) because the record's own Class field says which binding-point array
|
||||
// it describes - so a single slot would make every emission of one class cancel the
|
||||
// previous emission of another, and the shader-storage set would be suppressed as
|
||||
// "unchanged" by a uniform set that happened to hash the same way. Three slots also
|
||||
// keep the per-family fire tally and the A/B meaningful, which one keyed on
|
||||
// (slot, Class) would not.
|
||||
SetShaderBuffersUniform, // P5e (sb)
|
||||
SetShaderBuffersShaderStorage, // P5e (sb)
|
||||
SetShaderBuffersAtomicCounter, // P5e (sb)
|
||||
SetStreamOutputTargets, // P4b
|
||||
// P5e (CONTRACT-P5E.md §1): set_program_bindings, the post-link binding record. Not
|
||||
// kVarTail-only - it has three tails - but the same rule applies: the emitter latches
|
||||
// on (Cso, backendStateVersion, blockBindingVersion) and the whole-record hash is what
|
||||
// says "nothing moved".
|
||||
SetProgramBindings, // P5e (pg)
|
||||
SetVertexAttribDefaults, // P2 - the one consumer that is wired
|
||||
SetFramebufferState, // P4a - wired
|
||||
// P5c rv (CONTRACT-P5C.md §5.3). NOT kVarTail either - the same shape as
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
// MobileGL - MobileGL/MG_Impl/Pipe/ShaderBufferEmit.h
|
||||
// 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
|
||||
|
||||
#pragma once
|
||||
#include <Includes.h>
|
||||
|
||||
// The CLIENT side of set_shader_buffers - the INDEXED BUFFER BINDING POINTS (P5e package sb,
|
||||
// MG_Remote/CONTRACT-P5E.md §5.6, rulings 10 and 11). The call has been in the catalogue since
|
||||
// P4a with no emitter, no route and no applier; this file is the emitter half.
|
||||
//
|
||||
// ONE RECORD PER CLASS, THREE CLASSES. MGPShaderBuffers::Class names which binding-point array
|
||||
// the record describes - Uniform=0, ShaderStorage=1, AtomicCounter=2 - so the three are three
|
||||
// emissions through one route and one applier, not one record with three tails. That is also
|
||||
// why the suppressor has THREE SLOTS (ruling 11): a single slot would let a uniform set cancel
|
||||
// the previous storage set, and the shader-storage bindings would be suppressed as "unchanged"
|
||||
// by a record that described something else entirely.
|
||||
//
|
||||
// XFB IS NOT ONE OF THEM (§5.7). The transform-feedback capture points are span-scoped state
|
||||
// latched at glBeginTransformFeedback, and set_stream_output_targets carries a Generation this
|
||||
// payload has no field for - so the catalogue's split between the two rows stays, XFB keeps its
|
||||
// lockstep escalation, and dirty bit 17 fires for a family that emits nothing this phase.
|
||||
//
|
||||
// TWO INVARIANTS THAT MUST SURVIVE INTO THE BODY:
|
||||
// 1. THE HIGH-WATER-ZERO EARLY-OUT. A class whose touched high-water mark is 0 emits nothing,
|
||||
// BEFORE any hash and before any walk. Minecraft's touched SSBO and atomic-counter counts
|
||||
// are both 0, so the whole family costs one integer read per class per validate point on
|
||||
// the workload this phase exists for.
|
||||
// 2. A BASE BINDING TRAVELS AS kMGPipeWholeBuffer AND NEVER AS A RESOLVED EXTENT (§5.6,
|
||||
// table 0). glBindBufferBase does not freeze anything: GL resolves the range against the
|
||||
// object's size at every USE, and BindingSlotRange1D::GetRange() reproduces that by asking
|
||||
// the bound object. Resolving it HERE would freeze the size as of the emission, and under
|
||||
// run-ahead a glBufferData issued between the emission and the apply would then bind the
|
||||
// OLD extent - silently, with the right handle. So Offset/Size are copied only for an
|
||||
// EXPLICIT range (glBindBufferRange), and a base binding says "whole buffer" and lets the
|
||||
// server re-resolve against its own descriptor.
|
||||
//
|
||||
// THE WINDOW IS THE TOUCHED HIGH-WATER MARK (ruling 10), the same value the backend's own walk
|
||||
// has used since P2 and the same value MGPContextValues already carries. A program-derived
|
||||
// window would be narrower for the uniform class - Minecraft reaches UBOs through the program's
|
||||
// block bindings, so a program binding block 0 at GL point 83 pays a 84-entry record - but that
|
||||
// is a NARROWING and this package is a correctness landing; BRIEF-P5E §5 lists it as trailing.
|
||||
//
|
||||
// HEADER-ONLY, and the wired constant below is what switches the family on, for the ownership
|
||||
// reason PipeFill.cpp states in full: that file belongs to the contract package for the whole
|
||||
// phase, so the bit that turns an emitter on is a constant in the emitter's OWN header.
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
#include <MG_Impl/Pipe/ResourceTracker.h>
|
||||
#include <MG_Impl/Pipe/SetHashSuppressor.h>
|
||||
#include <MG_Impl/Pipe/SlotAllocator.h>
|
||||
#include <MG_Impl/Pipe/Tracker.h> // MGPipeMixShutter, the one shutter-mixing function
|
||||
#include <MG_Pipe/MGPipe.h>
|
||||
#include <MG_Pipe/MGPipeTypes.h>
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#include <MG_Pipe/PipeRoute.h>
|
||||
#include <MG_State/GLState/BufferState/BufferState.h>
|
||||
#include <MG_State/GLState/Core.h>
|
||||
|
||||
#include <xxhash.h>
|
||||
|
||||
namespace MobileGL::MG_Pipe {
|
||||
|
||||
// WHICH SUBSYSTEM BIT THIS BUILD ACTUALLY EMITS FOR. PipeFill.cpp ORs the per-family
|
||||
// constants into kMGPipeWiredSubsystems, so the bit is added by the commit that gives this
|
||||
// emitter its body and no file is touched twice.
|
||||
//
|
||||
// IT MUST MOVE WITH MG_Backend/Init.cpp's CONSUMER BIT (ID-106). c0e deliberately withheld
|
||||
// bit 13 from ConsumedSubsystemsFor because no emitter existed and withholding is the safe
|
||||
// direction; the client's R-8 liveness gate (PipeFill.cpp's P5eFamilyIsLive) asks the server
|
||||
// for THIS bit in particular, so a build that set the constant here and left the server's
|
||||
// mask alone would emit nothing at all and look exactly like a build that had not landed.
|
||||
//
|
||||
// TURNING IT ON DOES NOT RETIRE A PULL. GetBufferBindingPoint is the family's Coverage.def
|
||||
// emitted row and PipeFill.cpp's EmittedCallSuppliesTheWholeField answers FALSE for it: the
|
||||
// field is four raw bases into the frontend's binding-point table and the record carries
|
||||
// resolved {handle, offset, size} triples, so the residual fill keeps writing the mirror and
|
||||
// the verify comparator keeps proving it. What retires the pull is the four Espryt consumers
|
||||
// reading the applier's window instead, which is the other half of this package.
|
||||
inline constexpr Uint64 kMGPipeWiredBufferBindingSubsystem = kMGPipeSubsystemBufferBindings;
|
||||
|
||||
// The BufferTarget each wire class names. One table, because the class is a wire value and
|
||||
// the target is a frontend enum, and a switch written at each of the four call sites is four
|
||||
// chances to pair Uniform with ShaderStorage.
|
||||
inline constexpr BufferTarget MGPipeBufferTargetForShaderBufferClass(Uint32 cls) {
|
||||
switch (cls) {
|
||||
case kMGPipeShaderBufferClassShaderStorage: return BufferTarget::ShaderStorage;
|
||||
case kMGPipeShaderBufferClassAtomicCounter: return BufferTarget::AtomicCounter;
|
||||
default: return BufferTarget::Uniform;
|
||||
}
|
||||
}
|
||||
|
||||
// And the suppressor slot, for ruling 11's reason - one per class.
|
||||
inline constexpr MGPipeSuppressorSlot MGPipeSuppressorSlotForShaderBufferClass(Uint32 cls) {
|
||||
switch (cls) {
|
||||
case kMGPipeShaderBufferClassShaderStorage:
|
||||
return MGPipeSuppressorSlot::SetShaderBuffersShaderStorage;
|
||||
case kMGPipeShaderBufferClassAtomicCounter:
|
||||
return MGPipeSuppressorSlot::SetShaderBuffersAtomicCounter;
|
||||
default: return MGPipeSuppressorSlot::SetShaderBuffersUniform;
|
||||
}
|
||||
}
|
||||
|
||||
// D-G3's shape, the same one the three unit sets use: XXH64 over the tail with the header's
|
||||
// own discriminators mixed in. Class is mixed BECAUSE the three classes share nothing but
|
||||
// this function - two classes whose windows happen to hold the same ranges must not hash the
|
||||
// same, or the per-class A/B tallies would be reading each other's traffic - and the mask
|
||||
// words are mixed because they are a FIELD of the record that the entries alone do not
|
||||
// determine (a uniform range and a storage range with the same handle differ only there).
|
||||
inline Uint64 MGPipeShaderBufferSetContentHash(const MGPBufferRange* entries, Uint32 cls,
|
||||
Uint32 start, Uint32 count,
|
||||
const Uint32* writableMask) {
|
||||
Uint64 hash = XXH64(entries, static_cast<SizeT>(count) * sizeof(MGPBufferRange), 0);
|
||||
hash = MGPipeMixShutter(hash, cls);
|
||||
hash = MGPipeMixShutter(hash, start);
|
||||
hash = MGPipeMixShutter(hash, count);
|
||||
for (Uint32 w = 0; w < kMGPipeShaderBufferWritableMaskWords; ++w) {
|
||||
hash = MGPipeMixShutter(hash, writableMask[w]);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
class MGPipeShaderBufferEmitter {
|
||||
public:
|
||||
using GLContext = MG_State::GLState::GLContext;
|
||||
|
||||
// Dirty bit 15 (NEW_CONST_BUFFERS) -> the uniform binding points.
|
||||
Uint64 EmitConstBuffers(GLContext& ctx) {
|
||||
return EmitClass(ctx, kMGPipeShaderBufferClassUniform);
|
||||
}
|
||||
|
||||
// Dirty bit 16 (NEW_SHADER_BUFFERS) -> the two WRITABLE classes, which share a bit
|
||||
// because they share a shutter: a storage bind and a counter bind are both "the
|
||||
// shader's writable binding points moved", and a workload that touches one without the
|
||||
// other pays one suppressed record rather than a second dirty bit.
|
||||
Uint64 EmitShaderBuffers(GLContext& ctx) {
|
||||
return EmitClass(ctx, kMGPipeShaderBufferClassShaderStorage) +
|
||||
EmitClass(ctx, kMGPipeShaderBufferClassAtomicCounter);
|
||||
}
|
||||
|
||||
// The validate point's FreshlyPrimed arm. A fresh context is a fresh set of binding
|
||||
// points AND a fresh applier window (MGPipeApplierReset clears all three), so the
|
||||
// emitter's mirrors go with them. The suppressor slots are invalidated beside this call
|
||||
// by InvalidateAll(); without that the first emission after a make-current would be
|
||||
// suppressed as unchanged and the server would draw against a cleared window.
|
||||
void Reset() {
|
||||
for (Uint32 cls = 0; cls < kMGPipeShaderBufferClassCount; ++cls) {
|
||||
m_last[cls] = MGPShaderBuffers{};
|
||||
}
|
||||
}
|
||||
|
||||
void ResetCounters() {
|
||||
for (Uint32 cls = 0; cls < kMGPipeShaderBufferClassCount; ++cls) m_emissions[cls] = 0;
|
||||
}
|
||||
|
||||
// What a unit case reads. The emitter hands m_entries straight to the route, so "what
|
||||
// was emitted" costs no copy at all - VertexInputEmit.h's G6/G7 property.
|
||||
const MGPShaderBuffers& LastHeader(Uint32 cls) const {
|
||||
return m_last[cls < kMGPipeShaderBufferClassCount ? cls : 0];
|
||||
}
|
||||
const Array<MGPBufferRange, kMGPipeMaxBufferBindingPoints>& LastRanges() const {
|
||||
return m_entries;
|
||||
}
|
||||
Uint64 EmissionCount(Uint32 cls) const {
|
||||
return m_emissions[cls < kMGPipeShaderBufferClassCount ? cls : 0];
|
||||
}
|
||||
|
||||
private:
|
||||
Uint64 EmitClass(GLContext& ctx, Uint32 cls) {
|
||||
const BufferTarget target = MGPipeBufferTargetForShaderBufferClass(cls);
|
||||
// INVARIANT 1, and it is one integer read on every draw of every application that
|
||||
// never binds an indexed buffer of this class.
|
||||
const SizeT touched = ctx.GetTouchedBufferBindingPointCount(target);
|
||||
if (touched == 0) return 0;
|
||||
const Uint32 count = touched < kMGPipeMaxBufferBindingPoints
|
||||
? static_cast<Uint32>(touched)
|
||||
: kMGPipeMaxBufferBindingPoints;
|
||||
// NO CLIENT-SIDE CLAMP TO THE DEVICE's LIMIT (ruling 10). MobileGL advertises the
|
||||
// GL 4.5 minimum of 84 uniform binding points while ES 3.2's is 72, and which of
|
||||
// them the driver can actually hold is a SERVER question: the backend clamps to
|
||||
// GL_MAX_UNIFORM_BUFFER_BINDINGS exactly as it does today, because a client reading
|
||||
// a device capability would be answering it from the wrong side of the wire.
|
||||
|
||||
// The writable mask is rebuilt from scratch for every emission: it is a property of
|
||||
// the window as it stands now, not an accumulation, and a sticky one would keep
|
||||
// claiming a point that has since been unbound.
|
||||
Uint32 writableMask[kMGPipeShaderBufferWritableMaskWords] = {};
|
||||
const Bool classIsWritable = cls != kMGPipeShaderBufferClassUniform;
|
||||
|
||||
for (Uint32 i = 0; i < count; ++i) {
|
||||
const auto& point = ctx.GetBufferBindingPoint(target, i);
|
||||
const auto& object = point.GetBoundObject();
|
||||
MGPBufferRange& entry = m_entries[i];
|
||||
entry = MGPBufferRange{};
|
||||
if (!object) {
|
||||
// A null handle is "nothing bound at that point", which is what the server
|
||||
// binds 0 for. Spelled by clearing the entry rather than by shortening the
|
||||
// window: the window is the touched high-water mark and a hole in the
|
||||
// middle of it is ordinary.
|
||||
entry.Res = kMGPipeNullHandle;
|
||||
continue;
|
||||
}
|
||||
entry.Res = MGPipeSlots().Acquire(MGPipeKind::Buffer, object->GetLifetimeId());
|
||||
// D-A3's sticky bind mask, ORed HERE for the reason VertexInputEmit.h ORs it at
|
||||
// every draw: a buffer given its storage through glNamedBufferData and only ever
|
||||
// bound with glBindBufferBase is bound to NOTHING at its resource emission, so
|
||||
// the mask sampled there would never carry its UNIFORM / SHADER_STORAGE /
|
||||
// ATOMIC_COUNTER bit. This is the resolution site, and it is sticky, so one
|
||||
// validate point is enough for the rest of the buffer's life.
|
||||
MGPipeResourceTrackerInstance().NoteBoundAs(entry.Res, target);
|
||||
// INVARIANT 2. HasExplicitRange() is exactly "this point was bound with
|
||||
// glBindBufferRange": BindingSlotRange1D keeps the flag precisely so GetRange()
|
||||
// can re-resolve a BASE binding against the object every time it is asked, and
|
||||
// that re-resolution is what must happen on the SERVER rather than here.
|
||||
if (point.HasExplicitRange()) {
|
||||
const auto range = point.GetRange();
|
||||
entry.Offset = static_cast<Uint64>(range.start);
|
||||
entry.Size = static_cast<Uint64>(range.end - range.start);
|
||||
} else {
|
||||
entry.Offset = 0;
|
||||
entry.Size = kMGPipeWholeBuffer;
|
||||
}
|
||||
// WHAT REPLACES THE BACKEND's GPU-WRITE WALK. Every bound storage-buffer and
|
||||
// atomic-counter point is marked writable, which is exactly the set
|
||||
// MarkShaderStorageBuffersGpuWritten and SyncAtomicCounterBuffers used to walk
|
||||
// the frontend for - conservative in the same direction and for the same reason
|
||||
// (GpuWritePending.h: an over-approximate set costs a readback, an under-
|
||||
// approximate one reads a stale shadow and says nothing). The uniform class
|
||||
// never sets a bit: a UBO is read-only to the shader by definition.
|
||||
if (classIsWritable) MGPipeShaderBufferMaskSet(writableMask, i);
|
||||
}
|
||||
|
||||
const Uint64 hash =
|
||||
MGPipeShaderBufferSetContentHash(m_entries.data(), cls, 0, count, writableMask);
|
||||
if (!MGPipeSetHashSuppressorInstance().ShouldEmit(
|
||||
MGPipeSuppressorSlotForShaderBufferClass(cls), hash)) {
|
||||
return 0;
|
||||
}
|
||||
MGPShaderBuffers& header = m_last[cls];
|
||||
header = MGPShaderBuffers{};
|
||||
header.Class = cls;
|
||||
header.Start = 0;
|
||||
header.Count = count;
|
||||
for (Uint32 w = 0; w < kMGPipeShaderBufferWritableMaskWords; ++w) {
|
||||
header.WritableMask[w] = writableMask[w];
|
||||
}
|
||||
// HostSpanCount IS 0 ALWAYS on Espryt, and that is a ruling rather than an omission:
|
||||
// the second var-tail exists for kCapNeedsHostUboBytes (Magma's named-UBO ring) and
|
||||
// that bit is 0 for the whole of P5 (CONTRACT-P5.md table 0). The codec's host-span
|
||||
// honesty pass is the guard that says so out loud if a backend ever publishes it.
|
||||
header.HostSpanCount = 0;
|
||||
header.ContentHash = hash;
|
||||
MGPipeRouteSetShaderBuffers(header, m_entries.data());
|
||||
++m_emissions[cls];
|
||||
return sizeof(MGPShaderBuffers) + static_cast<Uint64>(count) * sizeof(MGPBufferRange);
|
||||
}
|
||||
|
||||
// ONE entry buffer for all three classes, not three. A class is built and routed before
|
||||
// the next one is built (EmitShaderBuffers above calls EmitClass twice in sequence and
|
||||
// the route copies or stages the tail synchronously in both arms), so three would be
|
||||
// three times 84 * 24 bytes of resident staging for no reader.
|
||||
Array<MGPBufferRange, kMGPipeMaxBufferBindingPoints> m_entries{};
|
||||
MGPShaderBuffers m_last[kMGPipeShaderBufferClassCount]{};
|
||||
Uint64 m_emissions[kMGPipeShaderBufferClassCount] = {0, 0, 0};
|
||||
};
|
||||
|
||||
inline MGPipeShaderBufferEmitter& MGPipeShaderBufferEmitterInstance() {
|
||||
// NEVER DESTROYED, for MGPipeTrackerInstance()' reason; heap-constructed and
|
||||
// intentionally leaked at exit, like every other MGPipe process singleton.
|
||||
static MGPipeShaderBufferEmitter* emitter = new MGPipeShaderBufferEmitter();
|
||||
return *emitter;
|
||||
}
|
||||
} // namespace MobileGL::MG_Pipe
|
||||
#endif // MOBILEGL_PIPE_PUSH
|
||||
@@ -11,6 +11,10 @@
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
#include <Config.h>
|
||||
// P5e (id): the guard's exemption is keyed on whether the record being applied is BARRIERED
|
||||
// (CONTRACT-P5E §4.4), and MGPipeApplierCurrentRecordIsBarriered() is where ApplyOne stamps
|
||||
// that. Declarations only - this file names no applier state.
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#include <MG_Remote/Server/ServerLoop.h>
|
||||
#include <MG_Util/Debug/Log.h>
|
||||
|
||||
@@ -19,53 +23,136 @@
|
||||
|
||||
namespace MobileGL::MG_Pipe {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
Bool MGPipeApplierIsUnbarrieredApply() {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return false;
|
||||
if (!MG_Remote::Server::ServerLoop::OnApplyThread()) return false;
|
||||
return !MGPipeApplierCurrentRecordIsBarriered();
|
||||
}
|
||||
|
||||
void MGPipeRefuseAllocatorFromApplyThread(const char* entry) {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
if (!MG_Remote::Server::ServerLoop::OnApplyThread()) return;
|
||||
// The named exemption of CONTRACT-P5C §3.1: the sites whose handle-carrying records
|
||||
// are not emitted yet (P4b/P7) probe read-only inside the scope. The G6
|
||||
// frontend-keyed registry family (P3b/P4b) does the same inside its own scope.
|
||||
if (MGPipeReverseAnnouncementScope::Active()) return;
|
||||
if (MGPipeFrontendKeyedRegistryScope::Active()) return;
|
||||
// CONTRACT-P5E §4.4 AMENDS CONTRACT-P5C §3.1 HERE, AND IT IS THE WHOLE OF WHAT id
|
||||
// CHANGES ABOUT THIS FUNCTION: a named exemption is a debt the CLIENT'S WAIT pays for.
|
||||
// Behind a barriered record the client is parked in WaitForApplied and its allocator
|
||||
// is not moving, so a read-only probe is stale-free; behind an unbarriered one it is
|
||||
// running ahead, and the same probe reads a free list and a lifetimeId -> slot map the
|
||||
// client is concurrently mutating. So the two scopes below exempt nothing at all once
|
||||
// the record is unbarriered - regardless of MOBILEGL_IPC_STRICT_ERRORS, because the
|
||||
// value would be wrong by construction and there is no "count it" arm for that
|
||||
// (CONTRACT-P5E, rule F).
|
||||
//
|
||||
// Every record is barriered until ra lands the wait rule, so this reads exactly as it
|
||||
// did at 2fde7034 for the whole of this phase.
|
||||
if (MGPipeApplierCurrentRecordIsBarriered()) {
|
||||
// Ruling 12: Magma's four P7 debts, and ONLY on a DirectVulkan server. The key is
|
||||
// on the backend kind rather than on the site because the scope is a class anyone
|
||||
// can construct, and an Espryt probe borrowing Magma's exemption is exactly the
|
||||
// hole P5e is closing.
|
||||
if (MagmaP7AllocatorDebtScope::ActiveOnApplyThread() &&
|
||||
MG_Config::ActiveBackendType == BackendType::DirectVulkan) {
|
||||
return;
|
||||
}
|
||||
// The G6 frontend-keyed registry family: the barriered-row sites the per-family
|
||||
// packages have not carried a handle to yet (CONTRACT-P5E §4.4).
|
||||
if (MGPipeFrontendKeyedRegistryScope::ActiveOnApplyThread()) return;
|
||||
}
|
||||
MGLOG_F("MGPipe: Fatal{RoleViolation, \"MGPipeSlots\"} - the apply thread called "
|
||||
"MGPipeSlots().%s. With an active transport the client slot allocator is "
|
||||
"client-only memory (CONTRACT-P5C §3.1, rule E): a handle arrives already "
|
||||
"minted in a record, and a server that resolves or mints one off a frontend "
|
||||
"object's lifetime id is reading memory that will not exist on its side of a "
|
||||
"real split",
|
||||
"client-only memory (CONTRACT-P5C §3.1, rule E; CONTRACT-P5E §4.4): a handle "
|
||||
"arrives already minted in a record, and a server that resolves or mints one "
|
||||
"off a frontend object's lifetime id is reading memory that will not exist on "
|
||||
"its side of a real split. A named exemption scope admits it only while the "
|
||||
"record being applied is BARRIERED (barriered=%d) and, for Magma's P7 debt, "
|
||||
"only on a DirectVulkan server",
|
||||
entry, MGPipeApplierCurrentRecordIsBarriered() ? 1 : 0);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// P5e (id): the non-allocator half of the same rule. SlotTables.h's state note, its reader
|
||||
// and ForEachLive's weak-reference walk read server memory KEYED BY FRONTEND IDENTITY and
|
||||
// hand a frontend SharedPtr back, which is the same violation one step removed - no
|
||||
// allocator call, so the guard above never sees it.
|
||||
void MGPipeRefuseFrontendKeyedRegistryFromUnbarrieredApply(const char* entry) {
|
||||
if (!MGPipeApplierIsUnbarrieredApply()) return;
|
||||
MGLOG_F("MGPipe: Fatal{RoleViolation, \"MGPipeSlots\"} - the apply thread reached "
|
||||
"BackendSlotTable::%s while applying an UNBARRIERED record. The frontend-keyed "
|
||||
"half of the twin table is monolith glue (CONTRACT-P5E §4.1, §5.8): it answers "
|
||||
"from a frontend object the server has no wait pinning, so the SharedPtr it "
|
||||
"would hand back may already be the client's next object. Resolve the twin "
|
||||
"from the handle the record carried instead",
|
||||
entry);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
namespace {
|
||||
thread_local Uint32 g_reverseAnnouncementScopeDepth = 0;
|
||||
// NOT thread_local any more, and not atomic either (P5d round 3, package D).
|
||||
//
|
||||
// WHY THERE IS NO DATA RACE. Both depths have exactly ONE reader in the whole tree:
|
||||
// MGPipeRefuseAllocatorFromApplyThread above, whose first two lines return unless the
|
||||
// transport is active AND ServerLoop::OnApplyThread() is true. So the only thread whose
|
||||
// depth could ever change an answer is the apply thread - and the four scope bodies
|
||||
// below now increment and decrement ONLY when OnApplyThread() says so. That makes the
|
||||
// apply thread the single writer and the single reader of both counters; no other
|
||||
// thread touches them, and a monolith process never even reads them (the guard's first
|
||||
// line returns on TransportMode::Monolith and there is no apply thread to make the
|
||||
// second true). Single-writer-single-reader on one thread needs no lock, no atomic and
|
||||
// no TLS.
|
||||
//
|
||||
// WHY IT WAS WORTH DOING. A shared-library thread_local costs an __emutls_get_address
|
||||
// call per access. On the MONOLITH's GL thread that symbol is the TOP entry of the
|
||||
// profile at 7.7%, and these two scopes' ctor/dtor are 32.7% of its samples
|
||||
// (MGPipeFrontendKeyedRegistryScope 18.75 ctor + 13.95 dtor, the scope P5e renamed
|
||||
// MagmaP7AllocatorDebtScope 8.4); on the split's apply thread emutls is 7.4%. The
|
||||
// measurement predates the rename and the numbers are quoted as measured. The scope is
|
||||
// constructed at ~20
|
||||
// sites in DirectGLES.cpp, several inside StateBackendObjectRegistry::HandleOf, which
|
||||
// is per-draw. The cost on the GL thread is now one inlined predicate per end.
|
||||
//
|
||||
// The query's meaning ON THE APPLY THREAD is unchanged, which is the only meaning
|
||||
// the guard reads. Off it the answer is now always false, and the query is named
|
||||
// ActiveOnApplyThread() rather than Active() so that a reader who needs the other
|
||||
// meaning cannot ask for it by accident: whoever wants "is a scope open on THIS
|
||||
// thread" has to add it, and move the counting back, rather than read a false that
|
||||
// looks like an answer.
|
||||
Uint32 g_magmaP7AllocatorDebtScopeDepth = 0;
|
||||
}
|
||||
|
||||
MGPipeReverseAnnouncementScope::MGPipeReverseAnnouncementScope() {
|
||||
++g_reverseAnnouncementScopeDepth;
|
||||
MagmaP7AllocatorDebtScope::MagmaP7AllocatorDebtScope()
|
||||
// Decided ONCE and remembered: the destructor must undo exactly what the constructor
|
||||
// did, and re-asking the predicate would leak a count across a scope that straddled
|
||||
// the apply thread's exit block.
|
||||
: m_counted(MG_Remote::Server::ServerLoop::OnApplyThread()) {
|
||||
if (m_counted) ++g_magmaP7AllocatorDebtScopeDepth;
|
||||
}
|
||||
|
||||
MGPipeReverseAnnouncementScope::~MGPipeReverseAnnouncementScope() {
|
||||
--g_reverseAnnouncementScopeDepth;
|
||||
MagmaP7AllocatorDebtScope::~MagmaP7AllocatorDebtScope() {
|
||||
if (m_counted) --g_magmaP7AllocatorDebtScopeDepth;
|
||||
}
|
||||
|
||||
Bool MGPipeReverseAnnouncementScope::Active() {
|
||||
return g_reverseAnnouncementScopeDepth != 0;
|
||||
// The DEPTH is not backend-keyed and deliberately so: the backend kind is read by the
|
||||
// GUARD, once, at the moment it decides. Counting only on DirectVulkan would make the
|
||||
// depth's meaning depend on a global that a test can move between the constructor and the
|
||||
// destructor, which is the m_counted bug one level out.
|
||||
Bool MagmaP7AllocatorDebtScope::ActiveOnApplyThread() {
|
||||
return g_magmaP7AllocatorDebtScopeDepth != 0;
|
||||
}
|
||||
|
||||
namespace {
|
||||
thread_local Uint32 g_frontendKeyedRegistryScopeDepth = 0;
|
||||
// Same counter, same argument, same single reader - see the block above.
|
||||
Uint32 g_frontendKeyedRegistryScopeDepth = 0;
|
||||
}
|
||||
|
||||
MGPipeFrontendKeyedRegistryScope::MGPipeFrontendKeyedRegistryScope() {
|
||||
++g_frontendKeyedRegistryScopeDepth;
|
||||
MGPipeFrontendKeyedRegistryScope::MGPipeFrontendKeyedRegistryScope()
|
||||
: m_counted(MG_Remote::Server::ServerLoop::OnApplyThread()) {
|
||||
if (m_counted) ++g_frontendKeyedRegistryScopeDepth;
|
||||
}
|
||||
|
||||
MGPipeFrontendKeyedRegistryScope::~MGPipeFrontendKeyedRegistryScope() {
|
||||
--g_frontendKeyedRegistryScopeDepth;
|
||||
if (m_counted) --g_frontendKeyedRegistryScopeDepth;
|
||||
}
|
||||
|
||||
Bool MGPipeFrontendKeyedRegistryScope::Active() {
|
||||
Bool MGPipeFrontendKeyedRegistryScope::ActiveOnApplyThread() {
|
||||
return g_frontendKeyedRegistryScopeDepth != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -173,37 +173,112 @@ namespace MobileGL::MG_Pipe {
|
||||
// pull build's bytes do not move (G1).
|
||||
void MGPipeRefuseAllocatorFromApplyThread(const char* entry);
|
||||
|
||||
// The NAMED EXEMPTION to the rule above (CONTRACT-P5C §3.1): the family of sites whose
|
||||
// handle-carrying records the client does not EMIT yet. set_shader_buffers and
|
||||
// set_stream_output_targets exist in the catalogue but are P4b's to emit
|
||||
// (SetHashSuppressor.h says so), so the buffer binding-point ensures and the GPU-written
|
||||
// announcement they feed have no record handle to resolve from today. Inside this scope
|
||||
// ONE read-only lifetime-id probe stays legal; the scope is the debt's measurable,
|
||||
// greppable form, and it retires with P4b's emission (Espryt) and P7's server-side
|
||||
// binding table (Magma). Every other apply-thread allocator access stays Fatal.
|
||||
class MGPipeReverseAnnouncementScope {
|
||||
// ---- P5e (id, CONTRACT-P5E §4.4): THE CONDITION UNDER WHICH A NAMED SCOPE EXEMPTS -----
|
||||
//
|
||||
// "This thread is applying a record the client is NOT parked behind." Both scopes below
|
||||
// exempt a probe only while it is FALSE, because the client's wait is the whole of what
|
||||
// makes a frontend read from the apply thread safe: behind a barriered record the client
|
||||
// is blocked in WaitForApplied and its memory is stable; behind an unbarriered one it is
|
||||
// running ahead and the same read is torn or stale BY CONSTRUCTION, which is why rule F
|
||||
// has no "count it" arm and this answer does not consult MOBILEGL_IPC_STRICT_ERRORS.
|
||||
//
|
||||
// False in a monolith process and on any thread but the apply thread, so a GL-thread
|
||||
// caller is never refused by it.
|
||||
Bool MGPipeApplierIsUnbarrieredApply();
|
||||
|
||||
// The refusal for the frontend-keyed surfaces that do NOT touch the allocator and so are
|
||||
// not covered by MGPipeRefuseAllocatorFromApplyThread: the state note, its reader, and
|
||||
// ForEachLive's weak-reference walk (SlotTables.h). They survive P5e as MONOLITH GLUE
|
||||
// (CONTRACT-P5E §5.8) and this is what keeps that claim honest - reaching one of them from
|
||||
// an unbarriered apply is Fatal{RoleViolation, "MGPipeSlots"} naming the member, not a
|
||||
// silently stale SharedPtr. Same name in the refusal as the allocator guard's on purpose:
|
||||
// it is one surface, "server memory keyed by frontend identity", and a reader chasing the
|
||||
// abort should land on the same rule either way.
|
||||
void MGPipeRefuseFrontendKeyedRegistryFromUnbarrieredApply(const char* entry);
|
||||
|
||||
// The NAMED EXEMPTION to the rule above (CONTRACT-P5C §3.1, as amended by CONTRACT-P5E
|
||||
// §4.4): the family of sites whose handle-carrying records the client does not EMIT yet.
|
||||
// set_shader_buffers and set_stream_output_targets exist in the catalogue but are P4b/sb's
|
||||
// to emit (SetHashSuppressor.h says so), so the buffer binding-point ensures and the
|
||||
// GPU-written announcement they feed have no record handle to resolve from today. Inside
|
||||
// this scope ONE read-only lifetime-id probe stays legal WHILE THE CURRENT RECORD IS
|
||||
// BARRIERED; the scope is the debt's measurable, greppable form, and it retires with P7's
|
||||
// server-side binding table. Every other apply-thread allocator access stays Fatal.
|
||||
//
|
||||
// THE DEPTH IS COUNTED ONLY ON THE APPLY THREAD (P5d round 3, package D). The counter's
|
||||
// only reader is MGPipeRefuseAllocatorFromApplyThread, which returns before it looks unless
|
||||
// ServerLoop::OnApplyThread() is true, so a depth kept on any OTHER thread could never
|
||||
// change an answer - it was pure cost. The query is called ActiveOnApplyThread() and not
|
||||
// Active() BECAUSE OF THAT (review round 3): a name that promised "is a scope open" would
|
||||
// now be quietly answering "is a scope open ON THE APPLY THREAD", and the next reader to
|
||||
// come along - a P4b/P7 probe deciding on the GL thread whether to emit a record - would
|
||||
// read a truthful-looking false and take the wrong branch with nothing to warn it. The name
|
||||
// carries the precondition so a second reader has to notice it. m_counted remembers what the constructor decided so
|
||||
// the destructor undoes exactly what the constructor did; asking the predicate twice would
|
||||
// leak a count for a scope that outlived the apply thread. On the GL thread (and in every
|
||||
// monolith process) both ends are now one inlined predicate and a branch instead of an
|
||||
// emutls call, which is where 32.7% of the monolith GL thread's __emutls_get_address - its
|
||||
// top symbol at 7.7% - was going.
|
||||
//
|
||||
// P5e (id), ruling 12: RENAMED FROM MGPipeReverseAnnouncementScope AND KEYED ON THE
|
||||
// BACKEND KIND. The rename is the finding: what is left inside it after P5e is not "the
|
||||
// reverse announcement" - Espryt's half of that moved to the frontend-keyed scope with the
|
||||
// rest of the registry debt - it is MAGMA'S FOUR APPLY-THREAD ALLOCATOR TOUCHES, which P7
|
||||
// retires (VulkanRenderer.cpp's two hidden-resource shutdowns and its named-blit endpoint
|
||||
// resolve, plus MGPipeAnnounceBufferGpuWritten in ResourceTracker.h). Naming the scope
|
||||
// after the debt rather than after one of its sites is what makes "has P7 landed yet" a
|
||||
// grep; naming it after Magma is what stops a new Espryt site being wrapped in it.
|
||||
//
|
||||
// THE EXEMPTION IS REFUSED WHEN THE SERVER BACKEND IS NOT DirectVulkan, and that is the
|
||||
// point of the key rather than a safety belt. Magma stays lockstep for the whole of P5e
|
||||
// (§6.1: the DirectVulkan arm never publishes kCapRunAheadApply, so every record there is
|
||||
// barriered and every probe inside this scope keeps P5C's semantics). Espryt is what P5e
|
||||
// is retiring the lockstep for, so an Espryt probe must not be able to borrow Magma's
|
||||
// exemption - even by wrapping itself in Magma's scope.
|
||||
class MagmaP7AllocatorDebtScope {
|
||||
public:
|
||||
MGPipeReverseAnnouncementScope();
|
||||
~MGPipeReverseAnnouncementScope();
|
||||
MGPipeReverseAnnouncementScope(const MGPipeReverseAnnouncementScope&) = delete;
|
||||
MGPipeReverseAnnouncementScope& operator=(const MGPipeReverseAnnouncementScope&) = delete;
|
||||
static Bool Active();
|
||||
MagmaP7AllocatorDebtScope();
|
||||
~MagmaP7AllocatorDebtScope();
|
||||
MagmaP7AllocatorDebtScope(const MagmaP7AllocatorDebtScope&) = delete;
|
||||
MagmaP7AllocatorDebtScope& operator=(const MagmaP7AllocatorDebtScope&) = delete;
|
||||
static Bool ActiveOnApplyThread();
|
||||
|
||||
private:
|
||||
Bool m_counted;
|
||||
};
|
||||
|
||||
// The SECOND named exemption family (CONTRACT-P5C §5.4): the frontend-keyed twin
|
||||
// registry (audit row G6). The texture / sampler-view / FBO-legacy HandleOf probes are
|
||||
// how the server answers "which twin is this frontend object" while the registry is
|
||||
// keyed by frontend identity - server-PRIVATE state whose rekey onto handles is
|
||||
// P3b/P4b's, not P5c's. A probe inside this scope stays a read-only, barrier-held debt;
|
||||
// wrapping a NEW site in it is the greppable act of naming that debt, and an unwrapped
|
||||
// P5e's per-family packages', not P5c's. A probe inside this scope stays a read-only,
|
||||
// BARRIER-HELD debt - and P5e (id) makes the "barrier-held" half literal rather than
|
||||
// documentary: the exemption now holds only while MGPipeApplierCurrentRecordIsBarriered()
|
||||
// (§4.4), i.e. only while the client is actually parked behind the record being applied.
|
||||
// Wrapping a NEW site in it is the greppable act of naming that debt, and an unwrapped
|
||||
// probe from the apply thread is still Fatal{RoleViolation, "MGPipeSlots"}.
|
||||
//
|
||||
// WHAT THE CLASS IS FOR NOW, since P5e deletes most of its sites: vi/sb/pg/tx2/fb delete
|
||||
// their ~20 draw-path constructions with the probes they wrap, and what survives is the
|
||||
// set of BARRIERED-ROW sites (CONTRACT-P5E §4.4: DirectGLES.cpp's CopyTex / GetTexImage /
|
||||
// mipmap-shape / set_storage_block_binding / detach-walk sites, the two verify arms, and -
|
||||
// until vi/sb carry the handle - BufferImpl::HandleOfBuffer). Those keep P5C's semantics
|
||||
// because their records are barriered and their client IS parked.
|
||||
//
|
||||
// Apply-thread-only depth, and m_counted, for MagmaP7AllocatorDebtScope's reasons
|
||||
// above. This is the scope that pays: it is constructed at ~20 sites in DirectGLES.cpp,
|
||||
// several of them inside StateBackendObjectRegistry::HandleOf on the per-draw path, and
|
||||
// its ctor/dtor alone were 18.75% + 13.95% of the monolith GL thread's emutls samples.
|
||||
class MGPipeFrontendKeyedRegistryScope {
|
||||
public:
|
||||
MGPipeFrontendKeyedRegistryScope();
|
||||
~MGPipeFrontendKeyedRegistryScope();
|
||||
MGPipeFrontendKeyedRegistryScope(const MGPipeFrontendKeyedRegistryScope&) = delete;
|
||||
MGPipeFrontendKeyedRegistryScope& operator=(const MGPipeFrontendKeyedRegistryScope&) = delete;
|
||||
static Bool Active();
|
||||
static Bool ActiveOnApplyThread();
|
||||
|
||||
private:
|
||||
Bool m_counted;
|
||||
};
|
||||
#endif
|
||||
} // namespace MobileGL::MG_Pipe
|
||||
|
||||
@@ -136,6 +136,19 @@ namespace MobileGL::MG_Pipe {
|
||||
MGPipeDirtyBit(MGPipeDirty::NewFramebuffer) | MGPipeDirtyBit(MGPipeDirty::NewSamplerViews) |
|
||||
MGPipeDirtyBit(MGPipeDirty::NewSamplers) | MGPipeDirtyBit(MGPipeDirty::NewShaderImages);
|
||||
|
||||
// The THREE P5e adds, all one subsystem (kMGPipeSubsystemBufferBindings): the indexed
|
||||
// buffer binding points, whose three bits have been computed and counted since P2 and have
|
||||
// named no subsystem since. Added rather than edited in, for the reason above.
|
||||
//
|
||||
// NewSoTargets rides the same bit even though set_stream_output_targets stays UNEMITTED
|
||||
// for the whole of P5e (XFB is lockstep by escalation, CONTRACT-P5E.md §5.7): the bit is
|
||||
// "which A/B switch owns this family's legacy arm", and an operator clearing bit 13 has to
|
||||
// get the whole binding-point family's frontend walk back rather than two thirds of it -
|
||||
// the rule P3a's three and P4a's two triples already state.
|
||||
inline constexpr Uint32 kMGPipeDirtyEmittedAtP5e =
|
||||
kMGPipeDirtyEmittedAtP4a | MGPipeDirtyBit(MGPipeDirty::NewConstBuffers) |
|
||||
MGPipeDirtyBit(MGPipeDirty::NewShaderBuffers) | MGPipeDirtyBit(MGPipeDirty::NewSoTargets);
|
||||
|
||||
inline constexpr const char* kMGPipeDirtyNames[kMGPipeDirtyCount] = {
|
||||
"NEW_RENDER_STATE",
|
||||
"NEW_PIPELINE_STATE",
|
||||
@@ -198,6 +211,22 @@ namespace MobileGL::MG_Pipe {
|
||||
case MGPipeDirty::NewSamplers:
|
||||
case MGPipeDirty::NewShaderImages:
|
||||
return kMGPipeSubsystemSamplers;
|
||||
// P5e's three, one subsystem (MG_Remote/CONTRACT-P5E.md §1): the indexed buffer
|
||||
// binding points. Bits 15/16/17 have been computed and counted since P2 and have named
|
||||
// no subsystem since - "the remaining bits have no call of their own until P4b", which
|
||||
// the default arm below used to say for them. set_shader_buffers is the call, and
|
||||
// set_stream_output_targets stays unemitted while riding the same A/B bit, for the
|
||||
// reason kMGPipeDirtyEmittedAtP5e states.
|
||||
//
|
||||
// NAMING THE SUBSYSTEM IS NOT THE SAME AS EMITTING. The emission gate is five
|
||||
// conjuncts (PipeFill.cpp's `wants()`), one of which is kMGPipeWiredSubsystems - and
|
||||
// the buffer-binding family's wired constant is 0 until the package that gives the
|
||||
// emitter its body sets it, exactly as P4a's four families were. So this map moves
|
||||
// here, inert, and nothing is emitted and no field is skipped on its account yet.
|
||||
case MGPipeDirty::NewConstBuffers:
|
||||
case MGPipeDirty::NewShaderBuffers:
|
||||
case MGPipeDirty::NewSoTargets:
|
||||
return kMGPipeSubsystemBufferBindings;
|
||||
// NO BIT NAMES kMGPipeSubsystemTextureResources, and that is deliberate rather than an
|
||||
// omission: the texture and renderbuffer resource_* calls and set_texture_params are
|
||||
// dispatched from the GL entry points that cause them - a constructor, a storage
|
||||
@@ -205,8 +234,8 @@ namespace MobileGL::MG_Pipe {
|
||||
// is. Bit 10 gates those dispatch sites; there is no dirty bit to map onto it and
|
||||
// there must not be one, or the emission would be gated twice and disagree with itself.
|
||||
default:
|
||||
// The remaining bits have no call of their own until P4b, so there is no
|
||||
// subsystem to switch and the residual fill keeps supplying their fields.
|
||||
// Every dirty bit now names a subsystem; the arm stays because the switch is over
|
||||
// a value cast from an index and a future bit must not fall off the end.
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -522,7 +551,11 @@ namespace MobileGL::MG_Pipe {
|
||||
// ---- the object-class bits 9..17 ----
|
||||
const Uint64 textureContent = ctx.GetAnyTextureContentGeneration();
|
||||
const Uint64 textureParams = ctx.GetAnyTextureParamsGeneration();
|
||||
const Uint64 buffers = ctx.GetAnyBufferChangeGeneration();
|
||||
// P5e (sb): the buffer CONTENT aggregate is no longer read here at all. It was
|
||||
// bits 15/16/17's whole shutter and it answered the wrong question for every one of
|
||||
// them (see those bits below); the aggregate itself stays, because
|
||||
// MGPipeAggregate::BufferChange is still one of the six the walk reports and a
|
||||
// counter with no reader is a different removal from a shutter with a better input.
|
||||
|
||||
// Bit 9. The VAO attribute aggregate mixed with the bound VAO's identity is
|
||||
// already exact for the SET - it is bumped by all three Bump*Version functions,
|
||||
@@ -633,10 +666,50 @@ namespace MobileGL::MG_Pipe {
|
||||
now[Index(MGPipeDirty::NewShaderImages)] = MGPipeMixShutter(
|
||||
MGPipeMixShutter(MGPipeMixShutter(textureContent, textureParams), programImages),
|
||||
ctx.GetTextureBindGeneration());
|
||||
now[Index(MGPipeDirty::NewConstBuffers)] = buffers;
|
||||
now[Index(MGPipeDirty::NewShaderBuffers)] = buffers;
|
||||
now[Index(MGPipeDirty::NewSoTargets)] =
|
||||
MGPipeMixShutter(buffers, ctx.GetTransformFeedbackGeneration());
|
||||
// ---- bits 15/16/17, REWRITTEN AT P5e (sb, MG_Remote/CONTRACT-P5E.md §5.6) ----
|
||||
//
|
||||
// ALL THREE USED TO READ `buffers` - the buffer CONTENT aggregate - AND THAT WAS
|
||||
// WRONG IN BOTH DIRECTIONS AT ONCE. Over: any glBufferSubData anywhere fired all
|
||||
// three, which is the same width bit 10 was narrowed out of at P3a. Under, and this
|
||||
// is the half that mattered: glBindBufferBase / glBindBufferRange mutate a binding
|
||||
// point through a returned reference, which moves the slot's own Uint16 version and
|
||||
// NOTHING the content aggregate reads - so
|
||||
// `glBindBufferBase(UNIFORM,1,A); draw; glBindBufferBase(UNIFORM,1,B); draw` fired
|
||||
// no bit at all. Harmless while nothing was emitted for these three; an
|
||||
// under-fire the moment set_shader_buffers is, and under-firing renders stale,
|
||||
// which this file's own rule calls the dangerous direction. Same defect class as
|
||||
// P4a's glBindSampler hole (c0d), closed the same way: the shutter reads the
|
||||
// generation the mutator actually moves (BufferState::NoteBindPointChanged).
|
||||
//
|
||||
// THE CONTENT AGGREGATE LEAVES ALL THREE and is not replaced by anything: whether
|
||||
// the BYTES behind a bound buffer moved is the resource family's question, answered
|
||||
// server-side by the resource record's own Serial, and the record these bits emit
|
||||
// carries {handle, offset, size} - none of which a glBufferSubData changes. A base
|
||||
// binding's extent is the one thing that could, and it does not travel resolved:
|
||||
// Size is kMGPipeWholeBuffer and the server re-resolves it at use (§5.6).
|
||||
//
|
||||
// BIT 15 MIXES THE PROGRAM IDENTITY IN, for bit 12's and bit 14's reason one family
|
||||
// over (fable seams F-1/F-2): the uniform window is resolved FOR THE PROGRAM IN USE
|
||||
// - the UBO loop indexes it by the program's own block bindings - so a glUseProgram
|
||||
// alone must re-open it. `shader` is that identity in both arms (lifetime id x link
|
||||
// version, or stageLinks under a pipeline).
|
||||
//
|
||||
// BIT 16 IS TWO TARGETS, one bit: a storage-buffer bind and an atomic-counter bind
|
||||
// are both "the shader's writable binding points moved", they are emitted together
|
||||
// at the same validate point, and splitting them would buy one suppressed record on
|
||||
// a workload that binds one without the other.
|
||||
//
|
||||
// BIT 17 KEEPS THE TRANSFORM-FEEDBACK GENERATION beside the new bind-point one:
|
||||
// the capture points are span-scoped state latched at Begin, so when a span opens
|
||||
// matters as much as what is bound. Nothing is emitted for it this phase (§5.7).
|
||||
now[Index(MGPipeDirty::NewConstBuffers)] = MGPipeMixShutter(
|
||||
ctx.GetBufferBindPointGeneration(BufferTarget::Uniform), shader);
|
||||
now[Index(MGPipeDirty::NewShaderBuffers)] = MGPipeMixShutter(
|
||||
ctx.GetBufferBindPointGeneration(BufferTarget::ShaderStorage),
|
||||
ctx.GetBufferBindPointGeneration(BufferTarget::AtomicCounter));
|
||||
now[Index(MGPipeDirty::NewSoTargets)] = MGPipeMixShutter(
|
||||
ctx.GetBufferBindPointGeneration(BufferTarget::TransformFeedback),
|
||||
ctx.GetTransformFeedbackGeneration());
|
||||
|
||||
Uint32 dirty = 0;
|
||||
for (SizeT i = 0; i < kMGPipeDirtyCount; ++i) {
|
||||
|
||||
@@ -72,11 +72,13 @@ add_executable(MobileGLIntegrationTest
|
||||
Scenarios/SampledSetStalenessScenario.cpp
|
||||
Scenarios/ThreeChannelAttachmentScenario.cpp
|
||||
Scenarios/SnormAttachmentScenario.cpp
|
||||
Scenarios/MonolithAttachmentClearScenario.cpp
|
||||
Scenarios/PipelineFailureScenario.cpp
|
||||
Scenarios/AdvertisedLimitsScenario.cpp
|
||||
Scenarios/PixelStoreSweepScenario.cpp
|
||||
Scenarios/PrimitiveRestartScenario.cpp
|
||||
Scenarios/FragCoordOriginScenario.cpp
|
||||
Scenarios/ClientVertexArrayScenario.cpp
|
||||
Scenarios/ClearThenReadPixelsScenario.cpp
|
||||
Scenarios/SampleVariablesScenario.cpp
|
||||
Scenarios/DepthStencilReadbackScenario.cpp
|
||||
@@ -1937,6 +1939,45 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
ENVIRONMENT "${MGL_ITEST_GLES_SPLIT_ENVIRONMENT}"
|
||||
)
|
||||
|
||||
# ---- P5e fix1: THE PUSH-MONOLITH ARM, INSIDE THE GATED SET (ID-107) ----------------------
|
||||
#
|
||||
# WHY A MONOLITH LANE CARRIES THE `integration-split` LABEL. That label does not mean "runs
|
||||
# inproc" - it means "the set the disaggregation gate runs", which is exactly why it is
|
||||
# registered inside this `if (MOBILEGL_BUILD_DISAGGREGATED)` and why the block above argues
|
||||
# that a build without the option must match NOTHING under it. ID-81 gives the push build TWO
|
||||
# server arms, selected at runtime by MG_Config::Transport, and until now only one of them had
|
||||
# a gated entry: every Split block above exports MOBILEGL_TRANSPORT=inproc, and every
|
||||
# split-only scenario skips itself the moment the runtime is not split (SplitRuntimeSkipReason
|
||||
# in their SetUp), so the ambient monolith registration of those files runs zero cases. The
|
||||
# arm the phone actually ships on was therefore ungated, and P5e landed a null dereference on
|
||||
# it under 2250 green unit entries and 113 green split entries (ID-107: the game died in
|
||||
# Lightmap.<init> -> clearColorTexture -> glClear). A second arm needs a second lane, in the
|
||||
# same set, or "the gate is green" keeps meaning "one of the two arms is green".
|
||||
#
|
||||
# MOBILEGL_TRANSPORT=monolith IS NAMED, for review finding N-6's reason exactly as the
|
||||
# PersistentMapArm pair above names it: a ctest ENVIRONMENT property overrides the job
|
||||
# environment, and without it a gate-level `MOBILEGL_TRANSPORT=inproc` export would quietly
|
||||
# turn this block into a fourth copy of the split lane - the one failure mode a lane whose
|
||||
# whole purpose is to be the OTHER arm cannot survive.
|
||||
#
|
||||
# The scenario is registered ambiently as well (its source is in the list above), so
|
||||
# `DirectGLES.MonolithAttachmentClearScenario.*` and `DirectVulkan.…` still exist in
|
||||
# integration-gpu; this block is the copy the gate can see, under a prefix that says which arm
|
||||
# it pins.
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_PUSH_MONOLITH_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=monolith"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectGLES.PushMonolithArm."
|
||||
TEST_LIST MGL_PUSH_MONOLITH_ATTACHMENT_TESTS
|
||||
TEST_FILTER "MonolithAttachmentClearScenario.*"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES
|
||||
LABELS "integration-gpu\;integration-split"
|
||||
TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
ENVIRONMENT "${MGL_ITEST_GLES_PUSH_MONOLITH_ENVIRONMENT}"
|
||||
)
|
||||
|
||||
# ---- P5b d1: the indexed / instanced / multi-draw / indirect draw family under inproc ----
|
||||
#
|
||||
# One block per scenario, the precedent above. IndexedDrawFamilyScenario is d1's own lane
|
||||
@@ -1973,6 +2014,79 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# ---- P5e mv: THE MULTI-DRAW TIERS, INSIDE THE GATED SET (ID-109's rule, one level down) --
|
||||
#
|
||||
# WHY FIVE MORE LANES FOR ONE FILE. MultiDrawImpl asks the bound index buffer three questions
|
||||
# and P5e (mv) moved all three onto the applier's record. Five of this driver's six tiers ask
|
||||
# them from a DIFFERENT place in the batch - `RunIndirect` before any GL work, the rebased
|
||||
# tier from the CPU shadow, `FlattenWithCompute` before PrepareForDraw has even run - and the
|
||||
# resolved tier is ONE process-wide read of MOBILEGL_ESPRYT_MULTIDRAW_MODE (MultiDraw.cpp's
|
||||
# ResolveTierOnce). The d1 block above leaves it at `auto`, and on every driver this gate has
|
||||
# run against, `auto` lands on `ext` - a real multi-draw entry point that asks the index
|
||||
# buffer nothing at all. Three of the five migrated sites therefore had no gated entry.
|
||||
#
|
||||
# That is ID-107's shape exactly one level down: code on a real arm, with no entry in the set
|
||||
# the gate runs. The phase already paid 137 SEGFAULTs across 38 scenarios for the version of
|
||||
# this that lived at the transport level, and the lesson ID-109 drew - "the gate runs the SET,
|
||||
# so put the second arm in the set" - does not stop being true because the selector is an env
|
||||
# knob rather than MG_Config::Transport. A manual sweep run once by one package decays to
|
||||
# nothing by the next one.
|
||||
#
|
||||
# MOBILEGL_ESPRYT_MULTIDRAW_MODE IS A ctest ENVIRONMENT PROPERTY, not a job-level export, for
|
||||
# review finding N-6's reason and the PushMonolithArm block's: the property overrides the job
|
||||
# environment, so a gate that exported a mode of its own could not silently collapse these
|
||||
# five lanes into five more copies of the `auto` one - the single failure mode a lane whose
|
||||
# whole purpose is to pin a tier cannot survive.
|
||||
#
|
||||
# `ext` IS NOT REGISTERED HERE, deliberately: it is what `auto` already resolves to, so the
|
||||
# d1 block above IS the ext lane and a sixth block would only run it twice. Every other tier
|
||||
# was confirmed to resolve to ITSELF on this driver rather than falling back
|
||||
# (`ResolveTier`'s "MOBILEGL_ESPRYT_MULTIDRAW_MODE=<x> -> <x> (driver supports: ext,
|
||||
# basevertex, multiindirect, indirect, drawelements, compute (opt-in))"); a tier the driver
|
||||
# refuses would resolve to `ext` and register an entry that quietly proves nothing, so if this
|
||||
# list ever runs somewhere poorer, drop the refused tier rather than keeping a green that
|
||||
# means "ext again".
|
||||
#
|
||||
# THE FILTER IS THE TIER-SENSITIVE WORKLOAD and nothing else, which is this file's own rule
|
||||
# for an armed Split entry: MultiDrawScenario (its whole point is that a batch matches the
|
||||
# unrolled draws, which is precisely what a wrong index buffer breaks quietly) and
|
||||
# IndexedDrawFamilyScenario's three MultiDraw cases. The client-side-indices case keeps the
|
||||
# d1 block's exclusion - it is refused by name under split before any tier is chosen.
|
||||
#
|
||||
# NOTE FOR THE STRICT-MARKER CENSUS (PREAMBLE-ADDENDUM-WAVE3 §4): these entries carry a THIRD
|
||||
# name segment, so `strict_census2.sh` re-derives their gtest filter from the last two
|
||||
# components and re-runs them WITHOUT the mode this block pins - which for these lanes is the
|
||||
# whole point of the entry. They join Ct. / F1. / SmallRing. / PersistentMapArm. / NamedBlit.
|
||||
# in that blind spot, so SplitLogPaths.cmake.in gives each of them a private log path: read
|
||||
# the marker out of `build-split/MobileGL/MG_IntegrationTest/split-logs/<entry>.log`, which
|
||||
# the LANE wrote under its own pin, instead of out of a re-run that lost it.
|
||||
set(MGL_SPLIT_MULTIDRAW_TIERS basevertex multiindirect indirect drawelements compute)
|
||||
set(MGL_SPLIT_MULTIDRAW_TIER_PREFIX_basevertex "BaseVertex")
|
||||
set(MGL_SPLIT_MULTIDRAW_TIER_PREFIX_multiindirect "MultiIndirect")
|
||||
set(MGL_SPLIT_MULTIDRAW_TIER_PREFIX_indirect "Indirect")
|
||||
set(MGL_SPLIT_MULTIDRAW_TIER_PREFIX_drawelements "DrawElements")
|
||||
set(MGL_SPLIT_MULTIDRAW_TIER_PREFIX_compute "Compute")
|
||||
set(MGL_SPLIT_MULTIDRAW_TIER_FILTER
|
||||
"MultiDrawScenario.*:IndexedDrawFamilyScenario.MultiDraw*-MultiDrawScenario.ClientSideIndicesBatchMatchesUnrolledDraws")
|
||||
foreach(mglItestMultiDrawTier IN LISTS MGL_SPLIT_MULTIDRAW_TIERS)
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_SPLIT_MULTIDRAW_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc"
|
||||
"MOBILEGL_IPC_SERVER_PATH=${MGL_ITEST_SPLIT_SERVER_PATH}" "MGITEST_SPLIT_LANE=1"
|
||||
"MOBILEGL_ESPRYT_MULTIDRAW_MODE=${mglItestMultiDrawTier}"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX
|
||||
"DirectGLES.Split.MultiDrawTier${MGL_SPLIT_MULTIDRAW_TIER_PREFIX_${mglItestMultiDrawTier}}."
|
||||
TEST_LIST "MGL_SPLIT_MULTIDRAW_${mglItestMultiDrawTier}_TESTS"
|
||||
TEST_FILTER "${MGL_SPLIT_MULTIDRAW_TIER_FILTER}"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES
|
||||
LABELS "integration-gpu\;integration-split"
|
||||
TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
ENVIRONMENT "${MGL_ITEST_GLES_SPLIT_MULTIDRAW_ENVIRONMENT}"
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# ---- P5b package i1 (MG_Remote/CONTRACT-P5B.md §2 i1) --------------------------------
|
||||
#
|
||||
# THE LANE CASE THAT PROVES THE RECORDS CROSSED, and it is a RESULT and not a probe (R-16:
|
||||
@@ -2069,6 +2183,26 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
ENVIRONMENT "${MGL_ITEST_GLES_SPLIT_ENVIRONMENT}"
|
||||
)
|
||||
|
||||
# ---- P5e package vi (MG_Remote/CONTRACT-P5E.md §5.1, ID-82 / ruling 2) --------------------
|
||||
#
|
||||
# THE LANE ENTRY THAT DID NOT EXIST, and its absence was the brief's open item (a). Nothing
|
||||
# else registered here draws from a vertex array in the APPLICATION's own memory: every
|
||||
# other scenario binds GL_ARRAY_BUFFER first, so its glVertexAttribPointer argument is a
|
||||
# byte offset. This is the one draw shape whose bytes have no wire form - the server uploads
|
||||
# them by dereferencing a client pointer per draw - and it is therefore both the positive
|
||||
# control for vi's decision to KEEP that arm alive under lockstep and the only entry that
|
||||
# can reach the run-ahead refusal when ra publishes the caps bit.
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectGLES.Split."
|
||||
TEST_LIST MGL_SPLIT_VI_CLIENT_ARRAY_TESTS
|
||||
TEST_FILTER "ClientVertexArrayScenario.*"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES
|
||||
LABELS "integration-gpu\;integration-split"
|
||||
TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
ENVIRONMENT "${MGL_ITEST_GLES_SPLIT_ENVIRONMENT}"
|
||||
)
|
||||
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectGLES.Split."
|
||||
TEST_LIST MGL_SPLIT_SYNC_TESTS
|
||||
@@ -2142,6 +2276,59 @@ if (MOBILEGL_BUILD_DISAGGREGATED)
|
||||
ENVIRONMENT "${MGL_ITEST_GLES_SPLIT_SMALL_RING_ENVIRONMENT}"
|
||||
)
|
||||
endforeach()
|
||||
|
||||
# ---- P5e package pa: THE STRICT LANE GETS ENTRIES OF ITS OWN ------------------------------
|
||||
#
|
||||
# pa retired the two per-draw program rows - Fatal{UnmigratedPipeInput,
|
||||
# "GetProgramForDraw@DrawArrays"} and "...GetProgramForDispatch@DispatchCompute", 69 of the
|
||||
# 109 entries the strict lane was red on. NOTHING GATED THEM. MOBILEGL_IPC_STRICT_ERRORS=1 is
|
||||
# a knob the phase's gate driver sets by hand, no REGISTERED entry exports it, and package
|
||||
# pg's declared red-once for this exact marker never landed - so the row could come back and
|
||||
# every gate would stay green. That is ID-109's finding in miniature: the gap was never a
|
||||
# missing test case, it was a missing gated ENTRY for a whole reading.
|
||||
#
|
||||
# WHICH SCENARIOS MAY JOIN is decided by the knob itself: under it every BARRIER-PULLED read
|
||||
# is Fatal, and most split scenarios end in a readback, whose GetFramebufferBindingSlot@ReadPixels
|
||||
# is an allowlisted row that only P7 retires. So a scenario is eligible exactly when it
|
||||
# reaches PrepareForDraw / PrepareForCompute and then does NOT read pixels back. Two do, one
|
||||
# per half of pa, and both were red with pa's own marker before it landed:
|
||||
# * MultiDrawScenario.BaseVertexDrawsRejectMalformedArguments - the DRAW half; it prepares a
|
||||
# draw and then asserts on GL errors rather than on pixels.
|
||||
# * AtomicCounterScenario.* - the DISPATCH half, and all three cases were
|
||||
# GetProgramForDispatch@DispatchCompute entries.
|
||||
#
|
||||
# LABELS IS integration-split ALONE, deliberately, and it is not the hole ID-109 names. That
|
||||
# hole was a runtime ARM with no entry anywhere; here the monolith arm of these same scenarios
|
||||
# is registered under DirectGLES. already and this knob is a no-op on it - a monolith client
|
||||
# fills and stamps all 63 fields at every verb, so no read is unfresh and nothing can trip.
|
||||
# An entry that cannot fail for the reason it exists is worse than none (R-16), so this lane
|
||||
# names the arm it is for in its own prefix. The F1. lane sets the same precedent.
|
||||
mgl_itest_join_environment(MGL_ITEST_GLES_SPLIT_STRICT_ENVIRONMENT
|
||||
"MOBILEGL_BACKEND_TYPE=DirectGLES" "MOBILEGL_TRANSPORT=inproc"
|
||||
"MOBILEGL_IPC_SERVER_PATH=${MGL_ITEST_SPLIT_SERVER_PATH}" "MGITEST_SPLIT_LANE=1"
|
||||
"MOBILEGL_IPC_STRICT_ERRORS=1"
|
||||
${MGL_ITEST_CAPABILITY_ENV} ${MGL_ITEST_COMMON_ENV})
|
||||
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectGLES.Split.StrictProgramArm."
|
||||
TEST_LIST MGL_SPLIT_PA_STRICT_DRAW_TESTS
|
||||
TEST_FILTER "MultiDrawScenario.BaseVertexDrawsRejectMalformedArguments"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES
|
||||
LABELS "integration-split"
|
||||
TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
ENVIRONMENT "${MGL_ITEST_GLES_SPLIT_STRICT_ENVIRONMENT}"
|
||||
)
|
||||
gtest_discover_tests(MobileGLIntegrationTest
|
||||
TEST_PREFIX "DirectGLES.Split.StrictProgramArm."
|
||||
TEST_LIST MGL_SPLIT_PA_STRICT_DISPATCH_TESTS
|
||||
TEST_FILTER "AtomicCounterScenario.*"
|
||||
DISCOVERY_TIMEOUT 30
|
||||
PROPERTIES
|
||||
LABELS "integration-split"
|
||||
TIMEOUT ${MGL_ITEST_TIMEOUT}
|
||||
ENVIRONMENT "${MGL_ITEST_GLES_SPLIT_STRICT_ENVIRONMENT}"
|
||||
)
|
||||
# Apply per-entry paths after GoogleTest discovery has populated the TEST_LISTs.
|
||||
configure_file(Harness/SplitLogPaths.cmake.in SplitLogPaths.cmake @ONLY)
|
||||
set_property(DIRECTORY APPEND PROPERTY TEST_INCLUDE_FILES
|
||||
|
||||
@@ -3,8 +3,15 @@
|
||||
file(MAKE_DIRECTORY "@CMAKE_CURRENT_BINARY_DIR@/split-logs")
|
||||
# P5b t2's two lanes ride the same rule: one private log path per entry, or
|
||||
# SplitLogPaths.PrivateAndDistinct is red for them (ID-53).
|
||||
# P5e vi's client-array lane joins the same list for the same reason: its two entries are the
|
||||
# only ones that can reach Fatal{UnmigratedVerb, "DrawArrays+CLIENT_ARRAYS"} once ra publishes
|
||||
# the caps bit, and a shared log file is a marker nobody can attribute.
|
||||
# P5e pa's strict lane joins it for the same reason as vi's: its four entries exist to CARRY a
|
||||
# Fatal marker (the two program rows), and a shared log file is a marker nobody can attribute.
|
||||
foreach(entry IN LISTS MGL_SPLIT_CLEAR_TESTS MGL_SPLIT_TRIANGLE_TESTS MGL_SPLIT_PMAP_TESTS
|
||||
MGL_SPLIT_T2_TESS_TESTS MGL_SPLIT_T2_XFB_TESTS MGL_SPLIT_SYNC_TESTS)
|
||||
MGL_SPLIT_T2_TESS_TESTS MGL_SPLIT_T2_XFB_TESTS MGL_SPLIT_SYNC_TESTS
|
||||
MGL_SPLIT_VI_CLIENT_ARRAY_TESTS
|
||||
MGL_SPLIT_PA_STRICT_DRAW_TESTS MGL_SPLIT_PA_STRICT_DISPATCH_TESTS)
|
||||
set_tests_properties("${entry}" PROPERTIES ENVIRONMENT
|
||||
"MOBILEGL_LOG_FILE_PATH=@CMAKE_CURRENT_BINARY_DIR@/split-logs/${entry}.log")
|
||||
endforeach()
|
||||
@@ -22,6 +29,17 @@ foreach(scenario @MGL_SPLIT_D1_SCENARIOS@)
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
# P5e mv's five tier-pinned lanes, the same rule for the same reason - and here it also repairs
|
||||
# the addendum §4 blind spot for them: these entries carry a third name segment, so the strict
|
||||
# census cannot re-derive their MOBILEGL_ESPRYT_MULTIDRAW_MODE, but a private log per entry means
|
||||
# its marker can be read where the LANE wrote it instead of from a re-run that lost the pin.
|
||||
foreach(tier @MGL_SPLIT_MULTIDRAW_TIERS@)
|
||||
foreach(entry IN LISTS MGL_SPLIT_MULTIDRAW_${tier}_TESTS)
|
||||
set_tests_properties("${entry}" PROPERTIES ENVIRONMENT
|
||||
"MOBILEGL_LOG_FILE_PATH=@CMAKE_CURRENT_BINARY_DIR@/split-logs/${entry}.log")
|
||||
endforeach()
|
||||
endforeach()
|
||||
|
||||
# P5b package i1's four scenarios, the same shape as the small-ring loop above: every
|
||||
# DirectGLES.Split. entry owns exactly one absolute log path and shares it with nobody, which
|
||||
# is what SplitLogPaths.PrivateAndDistinct checks over the discovered set.
|
||||
|
||||
@@ -0,0 +1,189 @@
|
||||
// MobileGL - MobileGL/MG_IntegrationTest/Scenarios/ClientVertexArrayScenario.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
|
||||
//
|
||||
// Scenario - A VERTEX ARRAY THAT LIVES IN THE APPLICATION'S OWN MEMORY, DRAWN OVER THE WIRE.
|
||||
//
|
||||
// WHY THIS FILE EXISTS AT ALL (P5e vi, ID-82 / BRIEF-P5E §6 open item (a)). The brief asked
|
||||
// whether any existing scenario exercises a client-memory vertex array under split, and named
|
||||
// DoublePrecisionScenario as the candidate. IT DOES NOT, and nothing else does either: every
|
||||
// glVertexAttribPointer in this directory is issued with a buffer bound to GL_ARRAY_BUFFER, so
|
||||
// its last argument is a byte OFFSET and not a host pointer (DoublePrecisionScenario uses the
|
||||
// binding-model calls against real buffer objects, DoublePrecisionScenario.cpp:944-959). So the
|
||||
// one draw shape whose bytes have no wire form was, until this file, never drawn over the wire
|
||||
// in any lane.
|
||||
//
|
||||
// WHAT IT PINS, in the two arms it can be in:
|
||||
//
|
||||
// TODAY (lockstep, and the monolith control) the draw is NOT refused - ruling 4: the client
|
||||
// is parked in WaitForApplied for exactly this record, so the server's per-draw upload of the
|
||||
// application's bytes (Managers.cpp's SyncClientSideAttributesForDrawArrays, the kimi audit's
|
||||
// row 14) reads memory that is not moving. The assertion is therefore about PIXELS: the quad
|
||||
// has to arrive. That is what makes vi's "monolith-only would have been wrong here" concrete
|
||||
// rather than an argument in a report - delete the split arm of the upload and this goes red.
|
||||
//
|
||||
// UNDER RUN-AHEAD it is REFUSED BY NAME on the GL thread, Fatal{UnmigratedVerb,
|
||||
// "DrawArrays+CLIENT_ARRAYS"} (CONTRACT-P5E §5.1), because the client is a frame ahead and
|
||||
// those bytes are moving under the reader. This file is the red-once for that refusal: it is
|
||||
// the only lane entry that can reach it. Staging the bytes as a per-attribute {BindingIndex,
|
||||
// MGHostSpan} tail - the shape kDrawHasUserIndices already has for client INDICES - is P8's,
|
||||
// and retires the refusal along with this scenario's second half.
|
||||
//
|
||||
// Both draw entry points that carry the upload are driven, because they are two arms and not
|
||||
// one: DrawArrays uploads the single range, MultiDrawArrays uploads one range per sub-draw.
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../Harness/HeadlessGL.h"
|
||||
#include "../Harness/ScenarioFixture.h"
|
||||
|
||||
#ifdef GLAPI
|
||||
#undef GLAPI
|
||||
#endif
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glcorearb.h>
|
||||
#undef GL_GLEXT_PROTOTYPES
|
||||
|
||||
namespace MGITest {
|
||||
namespace {
|
||||
|
||||
constexpr const char* kVS = R"(#version 330 core
|
||||
in vec2 aPos;
|
||||
void main() { gl_Position = vec4(aPos, 0.0, 1.0); }
|
||||
)";
|
||||
|
||||
constexpr const char* kFS = R"(#version 330 core
|
||||
out vec4 o_color;
|
||||
void main() { o_color = vec4(0.0, 1.0, 0.0, 1.0); }
|
||||
)";
|
||||
|
||||
class ClientVertexArrayScenario : public ScenarioTest {};
|
||||
|
||||
// THE WHOLE POINT IS THE ABSENCE OF A BUFFER. glBindBuffer(GL_ARRAY_BUFFER, 0) before
|
||||
// glVertexAttribPointer makes the last argument a HOST POINTER rather than an offset,
|
||||
// which is the one vertex source EmitVertexBuffers publishes as Res ==
|
||||
// kMGPipeNullHandle - "not a hole: it is exactly how the server learns this attribute
|
||||
// is client-sourced, upload it yourself" (VertexInputEmit.h).
|
||||
//
|
||||
// A VAO is still bound, because ES core requires one and because the server's upload
|
||||
// hangs off the VAO's twin.
|
||||
struct ClientArrayQuad {
|
||||
GLuint vao = 0;
|
||||
const float* vertices = nullptr;
|
||||
|
||||
void Bind(const float* quad) {
|
||||
vertices = quad;
|
||||
glGenVertexArrays(1, &vao);
|
||||
glBindVertexArray(vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), vertices);
|
||||
}
|
||||
void Release() {
|
||||
glBindVertexArray(0);
|
||||
if (vao != 0) glDeleteVertexArrays(1, &vao);
|
||||
vao = 0;
|
||||
}
|
||||
};
|
||||
|
||||
// Full-viewport strip, so "did the draw arrive" is one pixel read rather than a shape
|
||||
// comparison - the claim is about the vertex SOURCE, not about rasterisation.
|
||||
const float kQuad[] = {-1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f};
|
||||
|
||||
Rgba8 CentreAfter(int width, int height) {
|
||||
const Image image = ReadPixelsRect(0, 0, width, height);
|
||||
return image.At(width / 2, height / 2);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_F(ClientVertexArrayScenario, AClientMemoryVertexArrayReachesTheDrawItFeeds) {
|
||||
if (!Ready()) return;
|
||||
HeadlessGL& gl = Gl();
|
||||
const int width = gl.Width();
|
||||
const int height = gl.Height();
|
||||
|
||||
std::string error;
|
||||
const unsigned int program = CompileProgram(kVS, kFS, &error);
|
||||
ASSERT_NE(program, 0u) << error;
|
||||
|
||||
BindDefaultFramebuffer();
|
||||
glViewport(0, 0, width, height);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
ClearTo(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
|
||||
ClientArrayQuad quad;
|
||||
quad.Bind(kQuad);
|
||||
glUseProgram(program);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
|
||||
const Rgba8 centre = CentreAfter(width, height);
|
||||
EXPECT_GT(static_cast<int>(centre.g), 200)
|
||||
<< "the client-memory vertex array never reached the draw: the centre is " << centre
|
||||
<< ", i.e. still the clear colour. Under split this means the per-draw upload of "
|
||||
"the application's own bytes did not run - the arm CONTRACT-P5E §5.1 keeps alive "
|
||||
"for lockstep, and refuses only under run-ahead";
|
||||
EXPECT_LT(static_cast<int>(centre.b), 60)
|
||||
<< "the quad drew, but the clear colour is still showing through: " << centre;
|
||||
|
||||
quad.Release();
|
||||
glUseProgram(0);
|
||||
glDeleteProgram(program);
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
}
|
||||
|
||||
TEST_F(ClientVertexArrayScenario, EverySubDrawOfAMultiDrawArraysGetsItsOwnClientRange) {
|
||||
if (!Ready()) return;
|
||||
HeadlessGL& gl = Gl();
|
||||
const int width = gl.Width();
|
||||
const int height = gl.Height();
|
||||
|
||||
std::string error;
|
||||
const unsigned int program = CompileProgram(kVS, kFS, &error);
|
||||
ASSERT_NE(program, 0u) << error;
|
||||
|
||||
BindDefaultFramebuffer();
|
||||
glViewport(0, 0, width, height);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
ClearTo(0.0f, 0.0f, 1.0f, 1.0f);
|
||||
|
||||
// Two strips out of one client array: the left half and the right half, so a
|
||||
// MultiDrawArrays that uploaded only the FIRST sub-draw's range leaves one side blue.
|
||||
static const float kTwoHalves[] = {
|
||||
-1.0f, -1.0f, 0.0f, -1.0f, -1.0f, 1.0f, 0.0f, 1.0f,
|
||||
0.0f, -1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
|
||||
};
|
||||
ClientArrayQuad quad;
|
||||
quad.Bind(kTwoHalves);
|
||||
glUseProgram(program);
|
||||
|
||||
const GLint firsts[2] = {0, 4};
|
||||
const GLsizei counts[2] = {4, 4};
|
||||
glMultiDrawArrays(GL_TRIANGLE_STRIP, firsts, counts, 2);
|
||||
|
||||
const Image image = ReadPixelsRect(0, 0, width, height);
|
||||
const Rgba8 left = image.At(width / 4, height / 2);
|
||||
const Rgba8 right = image.At((3 * width) / 4, height / 2);
|
||||
EXPECT_GT(static_cast<int>(left.g), 200)
|
||||
<< "the FIRST sub-draw's client range did not reach the draw: " << left;
|
||||
EXPECT_GT(static_cast<int>(right.g), 200)
|
||||
<< "the SECOND sub-draw's client range did not reach the draw (" << right
|
||||
<< "): an upload that ran once for the whole call instead of once per sub-draw "
|
||||
"leaves exactly this half unpainted";
|
||||
|
||||
quad.Release();
|
||||
glUseProgram(0);
|
||||
glDeleteProgram(program);
|
||||
EXPECT_EQ(FirstGLError(), 0u);
|
||||
}
|
||||
|
||||
} // namespace MGITest
|
||||
@@ -143,6 +143,13 @@ namespace {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
const MobileGL::Uint64 deathsBefore = ServerVerbs().ObjectDeaths();
|
||||
glDeleteTextures(1, &texture);
|
||||
// THE FENCE, the framebuffer case's exactly (MOBILEGL_IPC_BATCH_WAITS, default on):
|
||||
// object_death is a kCtxObject value-class record, published WITHOUT waiting for its
|
||||
// own apply, and the server-side tally only moves at apply time. Without a wait
|
||||
// boundary this read races the apply thread - it passed by timing until P5d round 3's
|
||||
// clock-free spin changed that timing, then failed 1 in 5. A clear is kCtxVerb and
|
||||
// still waits, and its wait covers the death.
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
EXPECT_GT(ServerVerbs().ObjectDeaths(), deathsBefore)
|
||||
<< "the texture's death produced no object_death record; the server's twin was "
|
||||
"never told to let go";
|
||||
|
||||
@@ -0,0 +1,180 @@
|
||||
// MobileGL - MobileGL/MG_IntegrationTest/Scenarios/MonolithAttachmentClearScenario.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
|
||||
//
|
||||
// Scenario - CLEARING A FRAMEBUFFER THAT HOLDS AN ATTACHMENT, ON THE PUSH-MONOLITH ARM.
|
||||
//
|
||||
// THE HOLE THIS CLOSES (INTEGRATOR-DECISIONS-P5E ID-107). P5e landed with 2250 unit entries and
|
||||
// 113 `integration-split` entries green, and the game then died at startup under
|
||||
// MOBILEGL_TRANSPORT=monolith inside Lightmap.<init> -> clearColorTexture -> glClear:
|
||||
// SyncCurrentFBO -> BackendFramebufferObject::SyncToBackend(frontend FBO) ->
|
||||
// SyncAttachmentSurface -> SyncMipmapsToBackend(null SharedPtr) -> SIGSEGV. Neither gated lane
|
||||
// could see it, for two reasons that are one reason:
|
||||
//
|
||||
// * the gate runs `-L unit` and `-L integration-split`, and EVERY split entry sets
|
||||
// MOBILEGL_TRANSPORT=inproc, which selects the by-handle framebuffer arm
|
||||
// (FramebufferRecordArmIsMandatory) - the arm that never reaches the frontend overload at
|
||||
// all; and
|
||||
// * every P5-era scenario that DOES clear a texture-attached framebuffer is split-only by
|
||||
// construction (F1WireScenario and friends call SplitRuntimeSkipReason() in SetUp and skip
|
||||
// the moment the runtime is not split), so the ambient monolith registration of those files
|
||||
// runs zero cases.
|
||||
//
|
||||
// So the arm the phone ships on - MOBILEGL_PIPE_PUSH compiled, transport monolith, framebuffer
|
||||
// records produced and applied IN PROCESS (P4a D-C2), attachments resolved from those records -
|
||||
// had no gated entry that attached anything to a framebuffer and cleared it. This file is that
|
||||
// entry, and its registration block (MG_IntegrationTest/CMakeLists.txt, the
|
||||
// `DirectGLES.PushMonolithArm.` prefix) pins the transport with a ctest ENVIRONMENT property for
|
||||
// review finding N-6's reason: a job-level MOBILEGL_TRANSPORT=inproc must not be able to turn
|
||||
// this lane into a second copy of the split one.
|
||||
//
|
||||
// WHAT EACH CASE IS FOR. The three attachment KINDS are the three arms of
|
||||
// FramebufferImpl::SyncAttachmentSurface, and on the monolith arm each must drive its storage
|
||||
// from the frontend object the walk is holding rather than from a by-handle seam whose record
|
||||
// arm is selected by `Transport != Monolith` (CONTRACT-P5E §5.8 / ID-81):
|
||||
//
|
||||
// * a MUTABLE 2D texture (glTexImage2D, the Lightmap shape) - the texture arm, whose storage
|
||||
// sync is the one that crashed;
|
||||
// * an IMMUTABLE 2D texture (glTexStorage2D) - the same arm with the levels already allocated,
|
||||
// so a regression that only shows up while levels are still being defined cannot hide the
|
||||
// other half;
|
||||
// * a RENDERBUFFER - the sibling arm, whose by-handle form does not dereference anything but
|
||||
// does drop the application-visible GL_OUT_OF_MEMORY report, so it is arm-selected too.
|
||||
//
|
||||
// The assertion is the PIXEL, not "it did not crash": a clear that reaches a driver framebuffer
|
||||
// with no attachment raises GL_INVALID_FRAMEBUFFER_OPERATION and writes nothing, which is the
|
||||
// silent half of the same defect and is what an attach that was refused rather than crashed
|
||||
// would produce. Both are failures here.
|
||||
//
|
||||
// Backend-agnostic on purpose. Nothing below is a DirectGLES fallback: "a clear of a complete
|
||||
// framebuffer reaches its own attachment" is a property of GL, so both ambient registrations
|
||||
// assert it and the scenario fails wherever it stops being true.
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
#include "../Harness/HeadlessGL.h"
|
||||
#include "../Harness/ScenarioFixture.h"
|
||||
|
||||
#ifdef GLAPI
|
||||
#undef GLAPI
|
||||
#endif
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glcorearb.h>
|
||||
#undef GL_GLEXT_PROTOTYPES
|
||||
|
||||
namespace MGITest {
|
||||
namespace {
|
||||
|
||||
constexpr int kSize = 8;
|
||||
|
||||
// 0.25 / 0.5 / 0.75 / 1.0 - the F1 lane's own clear values, so a reader comparing the two
|
||||
// arms is comparing the same numbers. None of them is 0 or 1, so neither a cleared-to-zero
|
||||
// texture nor an untouched one can pass by accident.
|
||||
constexpr float kClearR = 0.25f;
|
||||
constexpr float kClearG = 0.5f;
|
||||
constexpr float kClearB = 0.75f;
|
||||
constexpr GLubyte kExpected[4] = {64, 128, 191, 255};
|
||||
|
||||
class MonolithAttachmentClearScenario : public ScenarioTest {
|
||||
protected:
|
||||
GLuint fbo = 0;
|
||||
GLuint texture = 0;
|
||||
GLuint renderbuffer = 0;
|
||||
|
||||
void SetUp() override {
|
||||
ScenarioTest::SetUp();
|
||||
if (!Ready()) return;
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
glDisable(GL_SCISSOR_TEST);
|
||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||
glViewport(0, 0, kSize, kSize);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
if (!Ready()) return;
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
if (texture) glDeleteTextures(1, &texture);
|
||||
if (renderbuffer) glDeleteRenderbuffers(1, &renderbuffer);
|
||||
if (fbo) glDeleteFramebuffers(1, &fbo);
|
||||
ScenarioTest::TearDown();
|
||||
}
|
||||
|
||||
// Clear the bound framebuffer and read back the pixel the F1 lane reads. Separated
|
||||
// from the attach so that a failure says which half broke.
|
||||
void ClearAndExpectThePixel(const char* what) {
|
||||
ASSERT_EQ(glCheckFramebufferStatus(GL_FRAMEBUFFER), GLenum(GL_FRAMEBUFFER_COMPLETE))
|
||||
<< what << ": the framebuffer never came up, so the clear below would prove nothing";
|
||||
glClearColor(kClearR, kClearG, kClearB, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
GLubyte pixel[4] = {0, 0, 0, 0};
|
||||
glReadPixels(2, 3, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
|
||||
// A clear issued against a driver framebuffer whose attachment point was never
|
||||
// filled in raises this and writes nothing - the silent form of the defect.
|
||||
EXPECT_EQ(FirstGLError(), 0u) << what << ": " << GLErrorName(FirstGLError());
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
EXPECT_NEAR(pixel[i], kExpected[i], 1)
|
||||
<< what << ": channel " << i << " of the attachment did not receive the clear";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// THE DEVICE'S OWN SHAPE: a mutable texture whose level 0 is defined by glTexImage2D and
|
||||
// then attached, which is what Lightmap.<init> does before its clearColorTexture. The
|
||||
// storage sync behind the attachment is the call that took the null frontend object.
|
||||
TEST_F(MonolithAttachmentClearScenario, AClearOfAMutableTextureAttachmentReachesItsPixels) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
std::vector<GLubyte> zeros(static_cast<std::size_t>(kSize) * kSize * 4, 0);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, zeros.data());
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
||||
|
||||
ClearAndExpectThePixel("mutable 2D texture attachment");
|
||||
}
|
||||
|
||||
// The same arm with immutable storage: the levels are allocated before the attach, so a
|
||||
// sync that only misbehaves while a level is still being defined cannot account for a
|
||||
// green here.
|
||||
TEST_F(MonolithAttachmentClearScenario, AClearOfAnImmutableTextureAttachmentReachesItsPixels) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
|
||||
glGenTextures(1, &texture);
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, kSize, kSize);
|
||||
ASSERT_EQ(FirstGLError(), 0u) << "the driver refused the immutable storage itself";
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
||||
|
||||
ClearAndExpectThePixel("immutable 2D texture attachment");
|
||||
}
|
||||
|
||||
// The renderbuffer arm of the same function. It cannot crash the way the texture arm did
|
||||
// - the by-handle allocation dereferences no frontend object - but it IS the other half of
|
||||
// the arm selection, and a regression that routes it back through the by-handle form on
|
||||
// the monolith arm silently drops the application's GL_OUT_OF_MEMORY report.
|
||||
TEST_F(MonolithAttachmentClearScenario, AClearOfARenderbufferAttachmentReachesItsPixels) {
|
||||
if (!Ready() || IsSkipped()) return;
|
||||
|
||||
glGenRenderbuffers(1, &renderbuffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, kSize, kSize);
|
||||
ASSERT_EQ(FirstGLError(), 0u) << "the driver refused the renderbuffer storage itself";
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
|
||||
|
||||
ClearAndExpectThePixel("renderbuffer attachment");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace MGITest
|
||||
@@ -236,6 +236,23 @@
|
||||
// And GetTextureObject / GetProgramObject are STICKY (see MGP_COVERAGE_STICKY_LIST): they are
|
||||
// keyed by GL name, they are object lookups rather than verb state, and a forwarded field has
|
||||
// no storage for an emitted call to supply.
|
||||
//
|
||||
// P5e ADDS ONE ROW, GetBufferBindingPoint -> SetShaderBuffers (MG_Remote/CONTRACT-P5E.md §5.6),
|
||||
// and it is SHAPE-ONLY like P3a's and P4a's six: the field's storage is four raw bases into the
|
||||
// frontend's Array<Array<BindingSlotRange1D, 84>, 4>, and set_shader_buffers carries RESOLVED
|
||||
// {handle, offset, size} ranges per class. The applier has no way to produce a pointer and P5e
|
||||
// deliberately does not give it one, so the row lands in PipeFill.cpp's
|
||||
// EmittedCallSuppliesTheWholeField FALSE arm and the decision is taken THERE. What retires the
|
||||
// pull is not a better applier, it is the four Espryt consumers reading the applier's
|
||||
// BoundShaderBuffers instead of the frontend's binding points - at which point the
|
||||
// FieldOwnership.def row flips to RECORD_SUPPLIED.
|
||||
//
|
||||
// THE ROW IS INERT AT THIS COMMIT for GetBoundVertexArray's reason one phase on: the emission
|
||||
// and the fill skip both test kMGPipeWiredSubsystems, and the buffer-binding family's wired
|
||||
// constant is 0 until the package that gives MG_Impl/Pipe/ShaderBufferEmit.h its body sets it.
|
||||
// It lands here, with its two PipeFill.cpp switch arms, because this file and that one belong
|
||||
// to the contract package for the whole phase - a family package that had to add an enumerator
|
||||
// AND the arm that dispatches on it would be editing the one file the merge trap lives in.
|
||||
#define MGP_COVERAGE_EMITTED_LIST(X) \
|
||||
X(GetActiveTextureUnit, SetContextValues) \
|
||||
X(GetBlendColor, SetDynamicState) \
|
||||
@@ -243,6 +260,7 @@
|
||||
X(GetBlendFuncIndexed, CreateRenderState) \
|
||||
X(GetBoundTransformFeedbackLifetimeId, SetContextValues) \
|
||||
X(GetBoundVertexArray, BindVertexElements) \
|
||||
X(GetBufferBindingPoint, SetShaderBuffers) \
|
||||
X(GetClampReadColor, SetDynamicState) \
|
||||
X(GetClearColor, SetDynamicState) \
|
||||
X(GetClearDepth, SetDynamicState) \
|
||||
|
||||
@@ -284,16 +284,37 @@
|
||||
/* which is the window no shutter and no pull can cover, and the reason those sites */ \
|
||||
/* had to come inside this gate rather than stay a recorded blind spot. */ \
|
||||
X(NoteUnitTouched, kPulledPartialShutter|NEW_SAMPLER_VIEWS) \
|
||||
/* NOT NEW_SO_TARGETS, and this one was false on EVERY path: GLContext::SetNamed */ \
|
||||
/* TransformFeedbackBinding either binds a BufferState binding point (index == the */ \
|
||||
/* bound XFB object) or writes a saved-bindings entry, and NEW_SO_TARGETS mixes the */ \
|
||||
/* buffer-CONTENT aggregate with the transform-feedback generation - the first moves */ \
|
||||
/* only at BufferObject.cpp's content sites, the second only in BeginTransformFeedback. */ \
|
||||
/* A binding moves neither. It reaches the backend the same way every other buffer */ \
|
||||
/* binding point does, through GetBufferBindingPoint in the verb class's may-read mask, */ \
|
||||
/* so the honest answer is the pull. Narrowing it is P3b's, when it takes the subsystem */ \
|
||||
/* over and the binding points get a generation of their own. */ \
|
||||
X(SetNamedTransformFeedbackBinding, kPulledEveryVerb) \
|
||||
/* P5e (sb) REWRITES THIS ROW, AND THE OLD ONE ENDED WITH ITS OWN CONDITION: "narrowing */ \
|
||||
/* it is P3b's, when it takes the subsystem over and the binding points get a */ \
|
||||
/* generation of their own". They have one now (BufferState::NoteBindPointChanged), bit */ \
|
||||
/* 17's shutter reads it, and this function bumps it - so the paragraph that said */ \
|
||||
/* NEW_SO_TARGETS was "false on EVERY path" is withdrawn, because what made it false */ \
|
||||
/* was that the bit mixed the buffer-CONTENT aggregate, which no binding has ever moved.*/ \
|
||||
/* */ \
|
||||
/* kPulledPartialShutter AND NOT A BARE BIT, because the function has two arms: with */ \
|
||||
/* `index == m_boundTransformFeedback` it binds a real BufferState binding point and */ \
|
||||
/* bumps, and otherwise it writes the NAMED object's saved-bindings entry, which is not */ \
|
||||
/* a binding point at all and deliberately bumps nothing. So the bit fires on some of */ \
|
||||
/* the paths that mutate and not all, which is exactly what this answer is for; what */ \
|
||||
/* holds on every mutating path is still the pull through GetBufferBindingPoint. */ \
|
||||
X(SetNamedTransformFeedbackBinding, kPulledPartialShutter|NEW_SO_TARGETS) \
|
||||
/* P5e (sb), THE ONE NAME THE `Touch` PREFIX SURFACES, on two call sites - GL_Buffer.cpp's*/ \
|
||||
/* BindBufferBase_State and BindBufferRange_State. It moves the per-target high-water */ \
|
||||
/* mark that bounds every indexed-binding-point walk there is: the backend's, the */ \
|
||||
/* client's GPU-write sweep's, and set_shader_buffers' emitted window. */ \
|
||||
/* */ \
|
||||
/* kPulledEveryVerb, in GetMaxTouchedTextureUnit's exact words one family over: the */ \
|
||||
/* field it writes (GetTouchedBufferBindingPointCount) has no shutter of its own and */ \
|
||||
/* needs none - it is in kDraw's, kDispatch's and kXfbSpan's may-read masks, so the */ \
|
||||
/* residual fill copies it at every verb of those classes, and since P5c rv */ \
|
||||
/* set_context_values carries it as a value whose gate is the whole-record hash. */ \
|
||||
/* */ \
|
||||
/* IT NAMES NO BIT, AND THAT IS NOT THE SAME AS THE MUTATION GOING UNPUBLISHED. Both */ \
|
||||
/* call sites bump the bind-point generation on the line below this call, so bits 15/16/ */ \
|
||||
/* 17 fire for the bind - but they fire for the BINDING, through a different member, and */ \
|
||||
/* a row here that named them would claim this mutator moves a shutter it does not touch */ \
|
||||
/* (the derivation refutes exactly that, which is how the claim was tested). */ \
|
||||
X(TouchBufferBindingPoint, kPulledEveryVerb) \
|
||||
/* ---- P4a, THE FOUR THE WIDENED PREFIX SET SURFACES. Every one of them moves a field */ \
|
||||
/* P3a or P4a pushes and none of them was visible to the scan before, because none */ \
|
||||
/* begins with one of the ten words the pattern matched. */ \
|
||||
@@ -415,10 +436,23 @@
|
||||
//
|
||||
// The ten mutators that reach a tainted body (--check prints the count) all carry a prose
|
||||
// answer, which no derivation checks; these two mutators are the first that carry a bit answer.
|
||||
//
|
||||
// P5e (sb) ADDS A THIRD, for the same property of the scanner and a third unplaceable write:
|
||||
//
|
||||
// SetNamedTransformFeedbackBinding
|
||||
// -> MGPipeSlots().Acquire() calls GetLifetimeId() through its reference
|
||||
// parameter `buffer`, which the analysis cannot root in a member
|
||||
//
|
||||
// The claim it marks is plain: the bound arm of this function bumps the transform-feedback
|
||||
// target's bind-point generation (BufferState::NoteBindPointChanged), which is exactly what
|
||||
// bit 17's shutter reads since P5e. The mark is on the BIT the kPulledPartialShutter row
|
||||
// names, not on the pull, so what this list suspends is the narrowing claim and never the
|
||||
// answer that holds on every path.
|
||||
#define MGP_DIRTY_SURFACE_UNDECIDED_LIST(X) \
|
||||
X(UseProgram, NEW_SHADER) \
|
||||
X(UseProgram, NEW_SAMPLER_VIEWS) \
|
||||
X(UseProgram, NEW_SHADER_IMAGES) \
|
||||
X(BindVertexArray, NEW_VERTEX_ELEMENTS)
|
||||
X(BindVertexArray, NEW_VERTEX_ELEMENTS) \
|
||||
X(SetNamedTransformFeedbackBinding, NEW_SO_TARGETS)
|
||||
|
||||
// clang-format on
|
||||
|
||||
@@ -69,7 +69,7 @@
|
||||
/* no record fallback, and PipeFill.cpp:1902-1905 says outright that what retires the pull */ \
|
||||
/* is P8, not a better applier: the storage is a SharedPtr<VertexArrayObject> and */ \
|
||||
/* bind_vertex_elements carries an eight-byte {slot, gen}. */ \
|
||||
X(GetBoundVertexArray, BARRIER_PULLED, "P8", \
|
||||
X(GetBoundVertexArray, BARRIER_PULLED, "P5e (Espryt unbarriered), P7 (Magma)", \
|
||||
"frontend heap reference; the record carries a handle, the mirror is a pointer") \
|
||||
/* 18 Espryt sites + 11 Magma. Coverage.def:37-70 splits the 15 BufferTargets across three */ \
|
||||
/* calls and leaves SEVEN with no carrier at all (CopyRead, CopyWrite, PixelPack, */ \
|
||||
@@ -77,19 +77,19 @@
|
||||
/* though eight targets are covered. */ \
|
||||
X(GetBufferBindingSlot, BARRIER_PULLED, "P8 (indirect), P9 (readback), P13 (transfer)", \
|
||||
"7 of 15 BufferTargets have no call; the field is one array over all 15") \
|
||||
X(GetBufferBindingPoint, BARRIER_PULLED, "P3b/P4b, P7", \
|
||||
X(GetBufferBindingPoint, BARRIER_PULLED, "P5e (Espryt unbarriered), P7 (Magma)", \
|
||||
"frontend BindingSlotRange1D pointer") \
|
||||
/* 8 Espryt sites through GetFramebufferBindingSlotChecked + 13 Magma. SyncCurrentFBO */ \
|
||||
/* (:2995) is SELF-DECLARED monolith glue (DirectGLES.cpp:2961-2965) while BindCurrentFBO */ \
|
||||
/* (:4303-4353) is already split-clean - the bind is migrated, the sync is not. */ \
|
||||
X(GetFramebufferBindingSlot, BARRIER_PULLED, "P3b/P4b (Espryt), P7 (Magma)", \
|
||||
X(GetFramebufferBindingSlot, BARRIER_PULLED, "P5e (Espryt unbarriered), P7 (Magma)", \
|
||||
"frontend BindingSlot<FramebufferObject> pointer") \
|
||||
X(GetImageTextureBinding, BARRIER_PULLED, "P3b/P4b, P7", \
|
||||
X(GetImageTextureBinding, BARRIER_PULLED, "P5e (Espryt unbarriered), P7 (Magma)", \
|
||||
"frontend ImageTextureBinding base pointer") \
|
||||
X(GetTextureUnitObject, BARRIER_PULLED, "P3b/P4b, P7", \
|
||||
X(GetTextureUnitObject, BARRIER_PULLED, "P5e (Espryt unbarriered), P7 (Magma)", \
|
||||
"frontend TextureUnit base pointer; 13 Espryt + 8 Magma sites") \
|
||||
/* DirectGLES.cpp:4497, PrepareForDraw, the second unconditional pointer read of every draw. */ \
|
||||
X(GetProgramForDraw, BARRIER_PULLED, "P8 (Espryt), P7 (Magma)", \
|
||||
X(GetProgramForDraw, BARRIER_PULLED, "P5e (Espryt unbarriered), P7 (Magma)", \
|
||||
"frontend SharedPtr<ProgramObject>; the record carries a handle") \
|
||||
/* P5b package i1 (CONTRACT-P5B.md §6.9, the one row the contract grants a package). This */ \
|
||||
/* was FATAL "reachable only from kDispatch; there is no compute on the reduced path" - and */ \
|
||||
@@ -97,7 +97,7 @@
|
||||
/* PrepareForCompute pulls this inside it (DirectGLES.cpp:5779, VulkanRenderer.cpp:7327). */ \
|
||||
/* It is GetProgramForDraw's twin in every respect, so it takes its class and its retiring */ \
|
||||
/* phases. Overturned by: nothing in P5b; P7/P8 retire both rows together. */ \
|
||||
X(GetProgramForDispatch, BARRIER_PULLED, "P7 (Magma), P8 (Espryt)", \
|
||||
X(GetProgramForDispatch, BARRIER_PULLED, "P5e (Espryt unbarriered), P7 (Magma)", \
|
||||
"frontend SharedPtr<ProgramObject>; the record carries a handle") \
|
||||
/* The XFB family's one OBJECT row. XFB itself is off the reduced path, but kDraw's */ \
|
||||
/* may-read mask carries it and the draw walk reads it regardless - which is exactly the */ \
|
||||
|
||||
@@ -54,6 +54,30 @@ namespace MobileGL::MG_Pipe {
|
||||
kOptional = 1u << 5,
|
||||
};
|
||||
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §2.2). THE FIFTH COLUMN OF PipeCalls.def: what the client
|
||||
// does after publishing a record of this call, on a server that publishes
|
||||
// kCapRunAheadApply. Unscoped for MGPipeCallClass's reason - PipeCalls.def spells these as
|
||||
// bare tokens so the same file can be read by the C++ preprocessor and by
|
||||
// scripts/gen_pipe.py, which generates MGPipeWaitClassFor(op) from it.
|
||||
//
|
||||
// IT IS A VALUE, NOT AN OPCODE AND NOT A FLAG. The wire carries the opcode and both roles
|
||||
// recover the class from it, exactly as they recover the flags - which is the whole reason
|
||||
// MGPipeBarriered(op, payload, applierState) can be one function computed identically by
|
||||
// the emit table and by the sink instead of two copies that agree until they do not.
|
||||
//
|
||||
// kWaitNone is 0 so that an uninitialised read is the SAFE direction in exactly one sense
|
||||
// and the dangerous one in the other, which is why nothing reads this table without an
|
||||
// opcode that came out of the catalogue: MGPipeWaitClassFor answers kWaitClassCount for an
|
||||
// opcode it does not know, and a caller holding bytes off a stream must reach its own
|
||||
// Fatal{ProtocolCorruption} rather than a wait decision.
|
||||
enum MGPipeWaitClass : Uint8 {
|
||||
kWaitNone = 0,
|
||||
kWaitApplied,
|
||||
kWaitReply,
|
||||
kWaitPresent,
|
||||
kWaitClassCount,
|
||||
};
|
||||
|
||||
// The pipeline/dynamic split of RenderStateParameters, defined exactly once (section
|
||||
// 4.5.2): MG_Pipe/MGPipeRenderStateSpans.{h,cpp}, which landed with P2 and computes
|
||||
// every chunk boundary with offsetof. Include that header to use it; what stays here
|
||||
@@ -106,7 +130,17 @@ namespace MobileGL::MG_Pipe {
|
||||
// the three unit sets
|
||||
inline constexpr Uint64 kMGPipeSubsystemPrograms = 1ull << 12; // shader CSO, draw/dispatch
|
||||
// program, global constants
|
||||
// bits 13..62 reserved for the later phases, allocated in ROADMAP order.
|
||||
// P5e's one (MG_Remote/CONTRACT-P5E.md §1). The INDEXED BUFFER BINDING POINTS: the three
|
||||
// dirty bits NewConstBuffers / NewShaderBuffers / NewSoTargets, the set_shader_buffers
|
||||
// emitter, and the backend's four binding-point walks. It is its own bit and not part of
|
||||
// bit 7's resource family for the reason every other split here has: a UBO/SSBO binding
|
||||
// path that regressed and a buffer path that regressed are different findings, and
|
||||
// clearing one must not disarm the other.
|
||||
//
|
||||
// BIT 13 REQUIRES BIT 7, and for bit 11's reason: every MGPBufferRange::Res names a Buffer
|
||||
// handle, and only bit 7 puts one in the slot table.
|
||||
inline constexpr Uint64 kMGPipeSubsystemBufferBindings = 1ull << 13;
|
||||
// bits 14..62 reserved for the later phases, allocated in ROADMAP order.
|
||||
// NOT a subsystem, a BEHAVIOUR: turn OFF client-side content addressing of CSOs, so
|
||||
// every pipeline-version change mints a fresh CSO and the map is never probed. This is
|
||||
// the negative control the whole CSO design is measured against (ROADMAP.md P2).
|
||||
@@ -124,6 +158,13 @@ namespace MobileGL::MG_Pipe {
|
||||
kMGPipeSubsystemTextureResources | kMGPipeSubsystemSamplers |
|
||||
kMGPipeSubsystemPrograms),
|
||||
"the P4a phase constant and P4a's four subsystem bits have drifted");
|
||||
// P5e's, and P4a's is NOT edited: 0x1fff stays P5e's "everything P4a had and nothing of
|
||||
// mine" control, exactly as 0x1ff was P4a's and 0x7f was P3a's. The push default becomes
|
||||
// 0x3fff, so the A/B that reproduces today's picture is one bit cleared.
|
||||
inline constexpr Uint64 kMGPipeSubsystemsMigratedAtP5e = 0x3fffull; // bits 0..13
|
||||
static_assert(kMGPipeSubsystemsMigratedAtP5e ==
|
||||
(kMGPipeSubsystemsMigratedAtP4a | kMGPipeSubsystemBufferBindings),
|
||||
"the P5e phase constant and P5e's subsystem bit have drifted");
|
||||
|
||||
// The catalogue itself. Only macros, so it is safe to expand inside the namespace, and
|
||||
// consumers (the unit test, later the transport) get MGP_CALL_LIST from this header.
|
||||
|
||||
@@ -133,8 +133,38 @@ namespace MobileGL::MG_Pipe {
|
||||
// buffer. So the answer is the SERVER's table, published as a bit and read through
|
||||
// MGL_BACKEND_SLOT_CAP. The first of the "XFB span family" bits SlotCaps.h predicted.
|
||||
kCapBackendOwnsXfbCapture = 1ull << 9,
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §1, §6). THE SERVER APPLIES AN UNBARRIERED RECORD
|
||||
// WITHOUT READING CLIENT MEMORY: every object it needs is resolved from a handle the
|
||||
// record or the applier state carries, so the client may publish and move on instead
|
||||
// of waiting for appliedSeq at every verb (rule F).
|
||||
//
|
||||
// It is set in the DirectGLES arm of the server's CallMask and NEVER in the
|
||||
// DirectVulkan one - Magma keeps the lockstep for the whole of P5e (§6), its
|
||||
// apply-thread allocator debt is real, and a bit published there would turn that debt
|
||||
// into torn reads rather than into the accounted pulls it is today. On Espryt the arm
|
||||
// is gated on kMGPipeP5eRunAheadReady (MG_Backend/Init.cpp), false until the P5e
|
||||
// integration commit, so every package lands with the wait rule inert.
|
||||
//
|
||||
// The client latches RunAheadArmed() = m_barrierArmed && Ipc.RunAhead &&
|
||||
// Caps().HasCap(kCapRunAheadApply) at the first caps adoption after Start; a later
|
||||
// snapshot may only turn it OFF, because a caps re-run must not be able to make a
|
||||
// lockstep server run-ahead in the middle of a frame.
|
||||
kCapRunAheadApply = 1ull << 10,
|
||||
};
|
||||
|
||||
// THE RUN-AHEAD ARM, AS A PURE FUNCTION, so that "Magma never" is something a unit case can
|
||||
// hold rather than a line inside MG_Backend/Init.cpp's InitSplitRoles that only a live
|
||||
// split session reaches. `ready` is Init.cpp's kMGPipeP5eRunAheadReady - false until the
|
||||
// P5e integration commit - and the BACKEND TYPE is the half that must not depend on it:
|
||||
// whatever `ready` says, a DirectVulkan server publishes no bit 10, because Magma keeps the
|
||||
// lockstep for the whole of P5e (CONTRACT-P5E.md §6) and its apply thread really does read
|
||||
// client memory inside MagmaP7AllocatorDebtScope. MG_Test/Pipe/MagmaPipeIdentityTest.cpp
|
||||
// pins both halves; reverting the type test there is the phase's named red.
|
||||
inline constexpr Uint64 MGPipeRunAheadCapBitsFor(BackendType type, Bool ready) {
|
||||
return (ready && type == BackendType::DirectGLES) ? static_cast<Uint64>(kCapRunAheadApply)
|
||||
: static_cast<Uint64>(kCapNone);
|
||||
}
|
||||
|
||||
struct MGPCaps {
|
||||
// The ~90 flat scalars the backends already publish, by inclusion rather than by
|
||||
// restatement: a caps field added there must not need a second edit here. This is
|
||||
@@ -591,10 +621,26 @@ namespace MobileGL::MG_Pipe {
|
||||
Uint8 NativeFloat64;
|
||||
Uint8 PointSizeDemoted;
|
||||
Uint8 EnableSpirvValidation;
|
||||
// P5e (CONTRACT-P5E.md §1). 1 = the link this record describes SUCCEEDED. Today
|
||||
// "linked" is only implied by the create existing, which is not the same statement:
|
||||
// create_shader_state is re-issued on the same handle at every link that moves
|
||||
// GetLinkVersion, and a FAILED relink of a bound program moves it too. The server's
|
||||
// clean condition needs the difference spelled, because a draw on a program the
|
||||
// frontend reports unlinked DECLINES (the frontend raises INVALID_OPERATION) and a
|
||||
// record that cannot say so leaves the twin rebuilding from empty artefacts.
|
||||
//
|
||||
// THE DESCRIPTOR GREW 192 -> 200 AND THE DRAFT'S "in the descriptor's existing pad"
|
||||
// WAS WRONG: the four bytes above end at offset 24 and MGPBlobRef is 8-aligned, so
|
||||
// there is no spare byte and a fifth one costs the alignment slack below. It is paid
|
||||
// once, on a record that fires at most once per link, and it is confined to the push
|
||||
// build (this payload is only ever instantiated under MOBILEGL_PIPE_PUSH), which is
|
||||
// why G1 does not see it. PipeCatalogueTest pins the new size.
|
||||
Uint8 LinkStatus;
|
||||
Uint8 Pad0[7];
|
||||
MGPBlobRef Spirv[6]; // per stage
|
||||
MGPBlobRef Reflection;
|
||||
};
|
||||
MGP_ASSERT_POD(MGPProgramDesc, 192);
|
||||
MGP_ASSERT_POD(MGPProgramDesc, 200);
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// set_*
|
||||
@@ -802,6 +848,17 @@ namespace MobileGL::MG_Pipe {
|
||||
inline constexpr Uint32 kMGPipeMaxTextureUnits = 192;
|
||||
inline constexpr Uint32 kMGPipeMaxImageUnits = 192;
|
||||
|
||||
// P5e (CONTRACT-P5E.md §1, ruling 10). How many INDEXED BUFFER BINDING POINTS one
|
||||
// set_shader_buffers record may describe per class. 84 is the frontend's capacity
|
||||
// (MG_State/GLState/BufferState/BufferState.h's BufferBindingPointCount, itself the GL 4.5
|
||||
// core minimum for GL_MAX_UNIFORM_BUFFER_BINDINGS) and it is what travels: the BACKEND
|
||||
// clamps to the device's real ceiling, as it does today, because a client-side clamp would
|
||||
// read a device capability from the wrong side of the wire.
|
||||
//
|
||||
// Pinned against the frontend constant in MG_Impl/Pipe/PipeFill.cpp, the one translation
|
||||
// unit that sees both, exactly as the two above are.
|
||||
inline constexpr Uint32 kMGPipeMaxBufferBindingPoints = 84;
|
||||
|
||||
struct MGPVertexBuffer {
|
||||
MGPipeHandle Res;
|
||||
Uint64 Offset;
|
||||
@@ -907,16 +964,71 @@ namespace MobileGL::MG_Pipe {
|
||||
// Var-tail header: MGPBufferRange[Count], then MGHostSpan[HostSpanCount]. HostSpanCount is
|
||||
// 0, or Count for the Uniform class under kCapNeedsHostUboBytes (a range with nothing to
|
||||
// ship carries an empty span, so the two arrays stay index-aligned).
|
||||
// MGPShaderBuffers::Class's three values, and the ONLY spelling of them (P5e,
|
||||
// MG_Remote/CONTRACT-P5E.md §1). The payload's comment has named them since P4a and
|
||||
// nothing numbered them, so the emitter and the applier were one literal each away from
|
||||
// disagreeing. Uniform is 0 so a zeroed record describes the uniform binding points, which
|
||||
// is the class every workload has.
|
||||
//
|
||||
// XFB IS NOT ONE OF THEM: set_stream_output_targets carries a Generation this payload has
|
||||
// no field for and its capture points are span-scoped state latched at Begin, so the
|
||||
// catalogue's split between the two rows stays (§5.7).
|
||||
inline constexpr Uint32 kMGPipeShaderBufferClassUniform = 0;
|
||||
inline constexpr Uint32 kMGPipeShaderBufferClassShaderStorage = 1;
|
||||
inline constexpr Uint32 kMGPipeShaderBufferClassAtomicCounter = 2;
|
||||
inline constexpr Uint32 kMGPipeShaderBufferClassCount = 3;
|
||||
|
||||
// P5e, ID-104. HOW MANY Uint32 WORDS THE WRITABLE MASK NEEDS TO COVER THE WINDOW IT IS
|
||||
// ATTACHED TO, and it is a derived number rather than a literal because the two used to
|
||||
// disagree: WritableMask was ONE Uint32 while the window has been 84 points since P4a, so
|
||||
// the mask could only ever describe the first 32 of them and a shader-storage buffer bound
|
||||
// at point 32 or above was silently unwritable as far as the record was concerned.
|
||||
//
|
||||
// THE RULING WIDENS THE FIELD RATHER THAN NARROWING THE WINDOW (ID-104): narrowing to 32
|
||||
// would change what an application can bind, which is an observable, while the POD growing
|
||||
// 32 -> 40 bytes is paid by a record that fires at most once per class per change and is
|
||||
// confined to the push build. THREE Uint32 WORDS AND NOT A Uint64+Uint32 PAIR: 96 >= 84
|
||||
// either way, but one word type means one shift width, so the set and the test below are a
|
||||
// single expression each instead of a low half and a high half that have to agree.
|
||||
inline constexpr Uint32 kMGPipeShaderBufferWritableMaskWords = 3;
|
||||
|
||||
struct MGPShaderBuffers {
|
||||
Uint32 Class; // Uniform | ShaderStorage | AtomicCounter
|
||||
Uint32 Class; // MGPipeTypes.h's kMGPipeShaderBufferClass* - Uniform | ShaderStorage |
|
||||
// AtomicCounter
|
||||
Uint32 Start;
|
||||
Uint32 Count;
|
||||
Uint32 WritableMask;
|
||||
// Bit i (LSB-first within word i/32) = "the shader may WRITE through binding point i",
|
||||
// for classes 1 and 2. Always read and written through the two helpers below, never by
|
||||
// hand: an open-coded shift is how the emitter and the four consumers come to disagree
|
||||
// about which word a point lives in.
|
||||
Uint32 WritableMask[kMGPipeShaderBufferWritableMaskWords];
|
||||
Uint32 HostSpanCount; // 0, or Count when the kHostSpan tail is present (D-B8)
|
||||
Uint32 Pad0;
|
||||
Uint64 ContentHash;
|
||||
};
|
||||
MGP_ASSERT_POD(MGPShaderBuffers, 32);
|
||||
MGP_ASSERT_POD(MGPShaderBuffers, 40);
|
||||
|
||||
// THE ONE SPELLING OF THE MASK, for the reason kMGPipeShaderBufferClass* is the one
|
||||
// spelling of the class: the emitter sets these bits on the client and four backend sites
|
||||
// read them on the server, and a mask indexed by hand in five places is five chances to
|
||||
// pick the wrong word. Both take the words rather than the record so the APPLIER's copy of
|
||||
// the mask - which is per class and lives in MGPipeApplierState, not in a payload - goes
|
||||
// through exactly the same arithmetic.
|
||||
//
|
||||
// OUT OF RANGE IS "NOT WRITABLE" AND "WRITE NOTHING", never an out-of-bounds word: the
|
||||
// capacity is the wire's bound and the codec refuses a record past it, so this is the
|
||||
// second belt rather than the first.
|
||||
inline constexpr Bool MGPipeShaderBufferMaskHas(const Uint32* words, Uint32 index) {
|
||||
if (index >= kMGPipeMaxBufferBindingPoints) return false;
|
||||
return (words[index >> 5] & (Uint32{1} << (index & 31u))) != 0;
|
||||
}
|
||||
inline constexpr void MGPipeShaderBufferMaskSet(Uint32* words, Uint32 index) {
|
||||
if (index >= kMGPipeMaxBufferBindingPoints) return;
|
||||
words[index >> 5] |= Uint32{1} << (index & 31u);
|
||||
}
|
||||
static_assert(kMGPipeShaderBufferWritableMaskWords * 32u >= kMGPipeMaxBufferBindingPoints,
|
||||
"the writable mask no longer covers the binding-point window it describes "
|
||||
"(ID-104: widen the mask, never narrow the window)");
|
||||
|
||||
// Var-tail header: MGPBufferRange[Count] then Uint32 offsets[Count].
|
||||
struct MGPStreamOutputTargets {
|
||||
@@ -927,6 +1039,60 @@ namespace MobileGL::MG_Pipe {
|
||||
};
|
||||
MGP_ASSERT_POD(MGPStreamOutputTargets, 24);
|
||||
|
||||
// ---- set_program_bindings (P5e, opcode 80; CONTRACT-P5E.md §1 and §5.5) --------------
|
||||
//
|
||||
// THE THREE POST-LINK MUTABLE REFLECTION FIELDS. create_shader_state carries the archive
|
||||
// as LINKED; glUniformBlockBinding, glUniform1i on a sampler and glShaderStorageBlockBinding
|
||||
// all move a binding AFTER the link, inside the frontend's LinkArtifacts, so an archive
|
||||
// snapshot alone is wrong and the server would answer a draw with the bindings the program
|
||||
// was linked with rather than the ones it is bound with.
|
||||
//
|
||||
// Three tails, in this order, because the three live in three different index spaces:
|
||||
// Int32 BlockBindings[BlockBindingCount] dense, GL uniform-block index
|
||||
// MGPProgramSamplerUnit SamplerUnits[SamplerUnitCount] sparse, ascending Location
|
||||
// MGPProgramStorageOverride StorageOverrides[StorageOverrideCount]
|
||||
// The storage-override map is NAME-keyed BY DESIGN (ProgramObject.h: three index spaces,
|
||||
// one coordinate), so its key travels as a host span staged whole, exactly as
|
||||
// set_storage_block_binding's single name does.
|
||||
//
|
||||
// Emitted BEFORE create_shader_state at the same validate point: a rebuild inside the verb
|
||||
// must already see the bindings. A re-issued create CLEARS all three tails, for the reason
|
||||
// GlobalConstants is cleared - a relink replaces the archive the tails index into.
|
||||
struct MGPProgramSamplerUnit {
|
||||
Uint32 Location; // the frontend uniform location
|
||||
Int32 Unit; // the texture image unit glUniform1i put there
|
||||
};
|
||||
MGP_ASSERT_POD(MGPProgramSamplerUnit, 8);
|
||||
|
||||
struct MGPProgramStorageOverride {
|
||||
MGHostSpan Name; // the block name, NUL included, staged whole
|
||||
Int32 Binding;
|
||||
Uint32 Pad0;
|
||||
};
|
||||
MGP_ASSERT_POD(MGPProgramStorageOverride, 40);
|
||||
|
||||
// The three declared bounds. A program that exceeds one is a COUNTED REFUSAL and never a
|
||||
// truncation: a sampler array larger than 256 locations is a program this record cannot
|
||||
// describe, and silently describing 256 of them is the class of bug the descriptors exist
|
||||
// to close. The codec raises Fatal{ProtocolCorruption, "SetProgramBindings.<field>"}.
|
||||
inline constexpr Uint32 kMGPipeMaxProgramBlockBindings = 64;
|
||||
inline constexpr Uint32 kMGPipeMaxProgramSamplerUnits = 256;
|
||||
inline constexpr Uint32 kMGPipeMaxProgramStorageOverrides = 64;
|
||||
|
||||
struct MGPProgramBindings {
|
||||
MGPipeHandle Cso;
|
||||
// The client's commutative hash of the override MAP, the same function the backend
|
||||
// computes today (Managers.cpp's ComputeShaderStorageBlockBindingSignature), so the
|
||||
// server's "do I have to rebuild" clause is one Uint64 compare and the name tail is
|
||||
// touched only on a rebuild.
|
||||
Uint64 Signature;
|
||||
Uint32 BlockBindingCount;
|
||||
Uint32 SamplerUnitCount;
|
||||
Uint32 StorageOverrideCount;
|
||||
Uint32 Pad0;
|
||||
};
|
||||
MGP_ASSERT_POD(MGPProgramBindings, 32);
|
||||
|
||||
// Covers the DEFAULT UNIFORM BLOCK only (D6).
|
||||
struct MGPGlobalConstants {
|
||||
MGPipeHandle ShaderCso;
|
||||
@@ -1413,6 +1579,18 @@ namespace MobileGL::MG_Pipe {
|
||||
// server never reads the indirect buffer to learn a count and the client never sends
|
||||
// ranges it does not have.
|
||||
kDrawIsIndirect = 1u << 5,
|
||||
// P5e (CONTRACT-P5E.md §1, §5.1, ruling 2). AT LEAST ONE ENABLED ATTRIBUTE OF THE
|
||||
// BOUND VAO HAS NO BUFFER: the draw's vertex bytes live in client memory and the
|
||||
// server uploads them today by dereferencing the raw client pointer the record's
|
||||
// Offset carries (Managers.cpp's SyncClientSideAttributesForDrawArrays). That is
|
||||
// exactly the read rule F forbids, and it is NOT refused under split at this head -
|
||||
// only client INDEX arrays are. So the flag exists to make the case VISIBLE on the
|
||||
// wire: the barriered predicate escalates on it, and under run-ahead the client
|
||||
// refuses the draw by name (Fatal{UnmigratedVerb, "DrawArrays+CLIENT_ARRAYS"}) rather
|
||||
// than publishing bytes that may move before they are read. The staged form - a
|
||||
// per-attribute {BindingIndex, MGHostSpan} tail, shaped like kDrawHasUserIndices - is
|
||||
// P8's; the lockstep arm is unchanged.
|
||||
kDrawClientArrays = 1u << 6,
|
||||
};
|
||||
|
||||
// = pipe_draw_info. Today's twenty draw entry points collapse onto this one call, with
|
||||
|
||||
@@ -599,6 +599,55 @@ namespace MobileGL {
|
||||
Uint32 Divisor; // 12
|
||||
};
|
||||
|
||||
// ---- MGPImageView::Access, P5e (CONTRACT-P5E.md §1, ruling 16) -----------------------
|
||||
//
|
||||
// ONE TABLE, BOTH ROLES. The CLIENT has encoded this byte since P4a
|
||||
// (MG_Impl/Pipe/ImageEmit.h's MGPipeEncodeImageAccess, which folds the three GL names into
|
||||
// 0/1/2 and asserts on anything else); the SERVER open-coded the reverse mapping at its one
|
||||
// reader and carried a comment saying the encoding "does not exist", which was stale. The
|
||||
// numbers now live HERE, in the value header both sides already include, so the encode and
|
||||
// the decode cannot drift - the client emitter names these enumerators instead of literals
|
||||
// and the backend decodes through the function below.
|
||||
//
|
||||
// The enum is NOT the GLenum: this header is pure (no MG_State, MG_Impl, MG_Backend or
|
||||
// MG_Remote - scripts/check_include_closure.py probe "value-header") and a GL token is a
|
||||
// frontend spelling. The GLenum <-> enumerator half stays at the one client site that has
|
||||
// a GLenum in its hand.
|
||||
enum class MGPipeImageAccess : Uint8 {
|
||||
ReadOnly = 0, // GL_READ_ONLY
|
||||
WriteOnly = 1, // GL_WRITE_ONLY
|
||||
ReadWrite = 2, // GL_READ_WRITE
|
||||
Count = 3,
|
||||
};
|
||||
|
||||
// 0 IS READ-ONLY AND THAT IS WHY THE ORDER IS THIS ONE, not the low byte of the GL tokens:
|
||||
// a zeroed MGPImageView must decode to the most restrictive access, so a record that forgot
|
||||
// to set the field can only ever lose a write, never invent one.
|
||||
inline constexpr Uint8 kMGPipeImageAccessReadOnly = static_cast<Uint8>(MGPipeImageAccess::ReadOnly);
|
||||
inline constexpr Uint8 kMGPipeImageAccessWriteOnly = static_cast<Uint8>(MGPipeImageAccess::WriteOnly);
|
||||
inline constexpr Uint8 kMGPipeImageAccessReadWrite = static_cast<Uint8>(MGPipeImageAccess::ReadWrite);
|
||||
|
||||
// The decoder's own precondition. Any other value is Fatal{ProtocolCorruption,
|
||||
// "ImageView.Access"} at the READER - this header may not log, so it answers the question
|
||||
// and the caller owns the refusal.
|
||||
inline constexpr Bool MGPipeImageAccessIsValid(Uint8 encoded) {
|
||||
return encoded < static_cast<Uint8>(MGPipeImageAccess::Count);
|
||||
}
|
||||
|
||||
inline constexpr MGPipeImageAccess MGPipeDecodeImageAccess(Uint8 encoded) {
|
||||
return static_cast<MGPipeImageAccess>(encoded);
|
||||
}
|
||||
|
||||
// "May the shader read / write through this binding." Stated here rather than at each
|
||||
// reader because the image sweep's writable set and the backend's barrier plan ask the
|
||||
// same question of the same three values.
|
||||
inline constexpr Bool MGPipeImageAccessReads(MGPipeImageAccess access) {
|
||||
return access == MGPipeImageAccess::ReadOnly || access == MGPipeImageAccess::ReadWrite;
|
||||
}
|
||||
inline constexpr Bool MGPipeImageAccessWrites(MGPipeImageAccess access) {
|
||||
return access == MGPipeImageAccess::WriteOnly || access == MGPipeImageAccess::ReadWrite;
|
||||
}
|
||||
|
||||
// ---- trip wires (P0.5). Sizes are what every ABI MobileGL ships on produces: every
|
||||
// member is a fixed-width scalar, an enum of one, or an array of those - no pointer, no
|
||||
// SizeT - except the vertex types, which carry SharedPtr<BufferObject> by design and are
|
||||
|
||||
@@ -1239,6 +1239,22 @@ namespace MobileGL::MG_Pipe {
|
||||
++g_applier.RefusedNoConsumer;
|
||||
return true;
|
||||
}
|
||||
|
||||
// P5e (sb, CONTRACT-P5E.md §5.6): the three binding-point windows, cleared in one
|
||||
// place because BOTH resets clear them and the two used to drift on exactly this kind
|
||||
// of member (the framebuffer family's four). The SERIAL is deliberately NOT touched
|
||||
// here - each caller advances it beside its own siblings, where the "advance, never
|
||||
// zero" rule is written out.
|
||||
void ClearShaderBufferWindows() {
|
||||
for (Uint32 cls = 0; cls < kMGPipeShaderBufferClassCount; ++cls) {
|
||||
g_applier.BoundShaderBuffers[cls] = {};
|
||||
g_applier.ShaderBufferStart[cls] = 0;
|
||||
g_applier.ShaderBufferCount[cls] = 0;
|
||||
for (Uint32 w = 0; w < kMGPipeShaderBufferWritableMaskWords; ++w) {
|
||||
g_applier.ShaderBufferWritableMask[cls][w] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void MGPipeApplierReset() {
|
||||
@@ -1363,11 +1379,22 @@ namespace MobileGL::MG_Pipe {
|
||||
g_applier.DrawProgram = kMGPipeNullHandle;
|
||||
g_applier.DispatchProgram = kMGPipeNullHandle;
|
||||
g_applier.BoundShaderCso = kMGPipeNullHandle;
|
||||
// P5e (sb, CONTRACT-P5E.md §5.6): the three binding-point windows are per-context
|
||||
// WORKING state and go with the rest of it - a returning context has its own
|
||||
// glBindBufferBase history and may not inherit the one this applier was left holding.
|
||||
// The SERIAL advances rather than restarting, for the reason written out above: the
|
||||
// clearing is itself a change every backend memo has to hear about, and a counter that
|
||||
// restarts walks back through values already stamped into a memo that outlived the
|
||||
// switch. The EMITTER's latch resets with it (PipeFill.cpp's FreshlyPrimed arm
|
||||
// invalidates the three suppressor slots), or the first emission after a make-current
|
||||
// would be suppressed as unchanged and the server would draw with a cleared window.
|
||||
ClearShaderBufferWindows();
|
||||
++g_applier.FramebufferSerial;
|
||||
++g_applier.SamplerViewsSerial;
|
||||
++g_applier.SamplerStatesSerial;
|
||||
++g_applier.ShaderImagesSerial;
|
||||
++g_applier.ProgramBindingSerial;
|
||||
++g_applier.ShaderBuffersSerial;
|
||||
}
|
||||
|
||||
void MGPipeApplierReleaseObjectRecords() {
|
||||
@@ -1424,11 +1451,18 @@ namespace MobileGL::MG_Pipe {
|
||||
g_applier.BoundShaderImages = {};
|
||||
g_applier.ShaderImageStart = 0;
|
||||
g_applier.ShaderImageCount = 0;
|
||||
// P5e (sb): and the three binding-point windows, for the paragraph above's reason in
|
||||
// its own words - every MGPBufferRange::Res names a resource record this function has
|
||||
// just dropped, so a window left populated here is a set of handles into an empty
|
||||
// table, which the next resolve either refuses or answers with somebody else's record
|
||||
// on a slot the next context re-mints.
|
||||
ClearShaderBufferWindows();
|
||||
++g_applier.FramebufferSerial;
|
||||
++g_applier.SamplerViewsSerial;
|
||||
++g_applier.SamplerStatesSerial;
|
||||
++g_applier.ShaderImagesSerial;
|
||||
++g_applier.ProgramBindingSerial;
|
||||
++g_applier.ShaderBuffersSerial;
|
||||
}
|
||||
|
||||
void MGPipeApplyCreateRenderState(const MGPRenderStateDesc& desc, const void* chunkBytes) {
|
||||
@@ -1537,6 +1571,13 @@ namespace MobileGL::MG_Pipe {
|
||||
PipeInputs::kBufferTargetCount,
|
||||
"the record's per-target array and PipeInputs' have drifted");
|
||||
MGPipeApplyAccess::SetContextValues(gPipeInputs, values);
|
||||
// P5e (CONTRACT-P5E.md §2.1, escalation (i)): mirror the XFB-active flag into the
|
||||
// applier state as well. The barriered predicate has to be computable on the SERVER
|
||||
// from applier state alone - gPipeInputs is the block the run-ahead client stops
|
||||
// filling, so a predicate that read the answer out of THERE would be reading the very
|
||||
// memory the rule exists to stop it reading. One store, inert until the caps bit is
|
||||
// published, and it is what makes the two roles' third clause the same clause.
|
||||
g_applier.IsTransformFeedbackActive = values.IsTransformFeedbackActive != 0;
|
||||
}
|
||||
|
||||
void MGPipeApplySetPatchState(const MGPPatchState& patch) {
|
||||
@@ -2822,6 +2863,182 @@ namespace MobileGL::MG_Pipe {
|
||||
MGPipeApplierNoteTextureStateMoved();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// P5e's two entry points, DECLARED BY c0e (MG_Remote/CONTRACT-P5E.md §1)
|
||||
// ---------------------------------------------------------------------------------
|
||||
//
|
||||
// set_shader_buffers HAS ITS BODY (package sb); set_program_bindings still refuses by name
|
||||
// until package pg writes its own. A record that reached an unbodied one would be a binding
|
||||
// set the server accepted and dropped, so the answer there is a named abort rather than a
|
||||
// quiet return: the picture would be wrong and the lane would be green, which is the one
|
||||
// failure mode this campaign spends its refusals on.
|
||||
|
||||
// set_shader_buffers, ONE RECORD PER CLASS (CONTRACT-P5E.md §5.6, rulings 10/11). The whole
|
||||
// body is "validate the window, copy the tail into that class's array, take the mask, move
|
||||
// the serial" - the binding points are WORKING STATE and the objects they name are resolved
|
||||
// by the backend at its own sync point, from the handle each range carries.
|
||||
//
|
||||
// IT DOES NOT GO THROUGH ApplyUnitWindow, and the reason is worth a line rather than a
|
||||
// diff: that helper's refusal message names "the merged texture-unit space" and the three
|
||||
// unit sets share one capacity, while this row has THREE windows keyed by Class and two
|
||||
// refusals of its own that the contract names by string ("SetShaderBuffers.Class" /
|
||||
// ".Count"). A shared helper that had to grow a class parameter and a message parameter
|
||||
// would be the same code with more ways to pass the wrong one.
|
||||
//
|
||||
// AND THERE IS NO NoP4aConsumer BELT HERE, deliberately. P4a's belt exists because a client
|
||||
// clears a per-level dirty flag on ACCEPTANCE, so accepting on a backend that consumes
|
||||
// nothing loses uploads (ID-39). This family's liveness gate is the client's own
|
||||
// P5eFamilyIsLive (PipeFill.cpp), which asks R-8 for bit 13 in particular - a server that
|
||||
// does not publish bit 13 never receives one of these records at all - and storing a window
|
||||
// no backend reads costs nothing and loses nothing, because the emitter's only latch is the
|
||||
// set-hash suppressor and the record it latched did cross.
|
||||
void MGPipeApplySetShaderBuffers(const MGPShaderBuffers& hdr, const MGPBufferRange* tail) {
|
||||
if (hdr.Class >= kMGPipeShaderBufferClassCount) {
|
||||
MGP_TRIP_WIRE_REPORT("MGPipe: " MGP_TRIP_WIRE_TAG("ProtocolCorruption")
|
||||
" SetShaderBuffers.Class - class %u names no binding-point "
|
||||
"array; the three are Uniform=0, ShaderStorage=1, "
|
||||
"AtomicCounter=2",
|
||||
hdr.Class);
|
||||
return;
|
||||
}
|
||||
const Uint64 end = Uint64{hdr.Start} + Uint64{hdr.Count};
|
||||
if (end > kMGPipeMaxBufferBindingPoints || (hdr.Count != 0 && tail == nullptr)) {
|
||||
MGP_TRIP_WIRE_REPORT("MGPipe: " MGP_TRIP_WIRE_TAG("ProtocolCorruption")
|
||||
" SetShaderBuffers.Count {class=%u, start=%u, count=%u}: the "
|
||||
"window runs past the %u binding points the wire carries, or a "
|
||||
"non-empty set carries no ranges",
|
||||
hdr.Class, hdr.Start, hdr.Count,
|
||||
static_cast<unsigned>(kMGPipeMaxBufferBindingPoints));
|
||||
return;
|
||||
}
|
||||
// THE WINDOW IS THE BOUND AND ENTRIES OUTSIDE IT ARE NOT CLEARED, exactly as the three
|
||||
// unit sets and set_vertex_buffers work: the record is "the last set as received", and
|
||||
// a binding at or above Count means "nothing bound" to every reader (the frontend
|
||||
// array's default says the same thing, which is what makes the two pictures agree).
|
||||
auto& destination = g_applier.BoundShaderBuffers[hdr.Class];
|
||||
for (Uint32 i = 0; i < hdr.Count; ++i) destination[hdr.Start + i] = tail[i];
|
||||
g_applier.ShaderBufferStart[hdr.Class] = hdr.Start;
|
||||
g_applier.ShaderBufferCount[hdr.Class] = hdr.Count;
|
||||
for (Uint32 w = 0; w < kMGPipeShaderBufferWritableMaskWords; ++w) {
|
||||
g_applier.ShaderBufferWritableMask[hdr.Class][w] = hdr.WritableMask[w];
|
||||
}
|
||||
// ONE SERIAL FOR ALL THREE CLASSES, and it moves on EVERY applied record - a backend
|
||||
// memo that asks "have the binding points moved since I last bound them" must hear
|
||||
// about a uniform set exactly as it hears about a storage set, and splitting the serial
|
||||
// per class would make each of the four consumers pick which one to read.
|
||||
++g_applier.ShaderBuffersSerial;
|
||||
}
|
||||
|
||||
// P5e (pg) WRITES THE SECOND BODY. The three post-link mutable reflection fields -
|
||||
// glUniformBlockBinding's block-to-point map, glUniform1i's sampler unit per uniform
|
||||
// LOCATION, and glShaderStorageBlockBinding's name-keyed override set - all live INSIDE
|
||||
// the frontend's LinkArtifacts and all move after the link that produced it. An archive
|
||||
// snapshot alone therefore answers the wrong question: a twin built from it would bind the
|
||||
// uniform blocks the program was LINKED with rather than the ones it is BOUND with.
|
||||
void MGPipeApplySetProgramBindings(const MGPProgramBindings& hdr, const Int32* blockBindings,
|
||||
const MGPProgramSamplerUnit* samplerUnits,
|
||||
const MGPProgramStorageOverride* storageOverrides,
|
||||
const char* const* storageOverrideNames) {
|
||||
// THE BOUNDS ARE THE DECODER'S AND ARE RE-ASSERTED HERE, because the monolith adapter
|
||||
// reaches this entry point without passing the decoder at all: under monolith the only
|
||||
// validation a record ever gets is the one the applier does itself, which is the rule
|
||||
// every sibling in this file already keeps.
|
||||
const char* fault = nullptr;
|
||||
if (hdr.BlockBindingCount > kMGPipeMaxProgramBlockBindings) fault = "BlockBindingCount";
|
||||
else if (hdr.SamplerUnitCount > kMGPipeMaxProgramSamplerUnits) fault = "SamplerUnitCount";
|
||||
else if (hdr.StorageOverrideCount > kMGPipeMaxProgramStorageOverrides) fault = "StorageOverrideCount";
|
||||
else if (hdr.BlockBindingCount != 0 && blockBindings == nullptr) fault = "BlockBindings";
|
||||
else if (hdr.SamplerUnitCount != 0 && samplerUnits == nullptr) fault = "SamplerUnits";
|
||||
else if (hdr.StorageOverrideCount != 0 &&
|
||||
(storageOverrides == nullptr || storageOverrideNames == nullptr)) {
|
||||
fault = "StorageOverrides";
|
||||
}
|
||||
if (fault != nullptr) {
|
||||
MGP_TRIP_WIRE_REPORT("MGPipe: " MGP_TRIP_WIRE_TAG("ProtocolCorruption")
|
||||
" set_program_bindings {slot=%u, gen=%u}: %s is out of range or "
|
||||
"its tail is absent (%u/%u/%u declared)",
|
||||
hdr.Cso.Slot, hdr.Cso.Gen, fault, hdr.BlockBindingCount,
|
||||
hdr.SamplerUnitCount, hdr.StorageOverrideCount);
|
||||
return;
|
||||
}
|
||||
// P4a's belt, for MGPipeApplyBindShaderState's reason: with no consumer this applier
|
||||
// holds no shader CSO record at all, so the resolution below would report the designed
|
||||
// state as RefusedObjectCalls.
|
||||
if (NoP4aConsumer()) return;
|
||||
|
||||
MGPipeShaderCsoRecord* record = ResolveShaderCso("set_program_bindings", hdr.Cso);
|
||||
if (record == nullptr) return;
|
||||
|
||||
// WHOLE-SET REPLACEMENT, NOT A MERGE, in all three tails. Each one describes the
|
||||
// program's complete state for its index space as the client observed it at emit; a
|
||||
// merge would leave a block binding the application has since reset to its declared
|
||||
// default sitting on top of the archive's value for ever, and there is no per-entry
|
||||
// "cleared" token on the wire that could say otherwise.
|
||||
record->BlockBindings.assign(blockBindings, blockBindings + hdr.BlockBindingCount);
|
||||
record->SamplerUnits.assign(samplerUnits, samplerUnits + hdr.SamplerUnitCount);
|
||||
record->StorageOverrides.clear();
|
||||
record->StorageOverrides.reserve(hdr.StorageOverrideCount);
|
||||
for (Uint32 i = 0; i < hdr.StorageOverrideCount; ++i) {
|
||||
MGPipeProgramStorageOverride entry;
|
||||
// COPIED, NOT POINTED AT (rule C). The name rides SEG_STAGE and the staged run
|
||||
// retires with the record that named it; the rebuild that reads this may be a
|
||||
// frame later, and by then those bytes are somebody else's.
|
||||
entry.Name = storageOverrideNames[i] != nullptr ? String(storageOverrideNames[i]) : String();
|
||||
entry.Binding = storageOverrides[i].Binding;
|
||||
record->StorageOverrides.push_back(Move(entry));
|
||||
}
|
||||
record->Signature = hdr.Signature;
|
||||
// ADVANCED, NEVER RETURNED TO A VALUE IT HAS HANDED OUT - VertexBuffersSerial's rule.
|
||||
// Both texture-unit memos and the program twin's clean condition key on it (ruling 6),
|
||||
// so a serial that went backwards would make a memo match state it has never seen.
|
||||
++record->BindingsSerial;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// P5e: the barriered predicate and the applier's current-record flag (§2.1, §4.4)
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
||||
Bool MGPipeBarriered(MGPWireOp op, const void* payload, const MGPipeApplierState& st) {
|
||||
// 1. The static column. Every reply row, present, and the rows whose apply still pulls
|
||||
// a BARRIER_PULLED field or probes the client allocator.
|
||||
if (MGPipeWaitClassFor(op) != kWaitNone) return true;
|
||||
// 2. Escalation (i): an open transform-feedback span makes every verb inside it
|
||||
// barriered. XFB is not migrated by P5e - StartPendingTransformFeedback holds
|
||||
// frontend SharedPtrs across two verbs, which rule C forbids an applier entry point
|
||||
// outright - so the span keeps P5C's semantics and the cost on the steady Espryt
|
||||
// path is one bool test per draw.
|
||||
if (MGPipeCallClassFor(op) == kCtxVerb && st.IsTransformFeedbackActive) return true;
|
||||
// 3. Escalation (ii): a draw whose enabled attributes include a client-memory array.
|
||||
// The server uploads those bytes by dereferencing a raw client pointer, so the draw
|
||||
// cannot run ahead. Under run-ahead the client refuses it before it is published
|
||||
// (§5.1), so this clause is what the LOCKSTEP arm - where the draw is legal - uses.
|
||||
if (op == MGPWireOp::DrawVbo && payload != nullptr) {
|
||||
const auto& draw = *static_cast<const MGPDrawInfo*>(payload);
|
||||
if ((draw.Flags & static_cast<Uint8>(kDrawClientArrays)) != 0) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Server-private and deliberately NOT a member of MGPipeApplierState: it is not per-context
|
||||
// state the applier owns, it is "which record is the apply thread inside right now", and a
|
||||
// reader (the allocator guard) that had to find the right context's applier first would be
|
||||
// asking a harder question than the one it needs answered.
|
||||
//
|
||||
// TRUE IS THE DEFAULT AND THE LOCKSTEP ANSWER. On a server that does not publish
|
||||
// kCapRunAheadApply every record is barriered, the client is parked in its own wait for
|
||||
// each of them, and the two named exemption scopes of CONTRACT-P5C §3.1 keep working
|
||||
// exactly as they do today. Nothing writes this until package id sets it from
|
||||
// MGPipeBarriered in the sink's ApplyOne.
|
||||
namespace {
|
||||
thread_local Bool g_currentRecordBarriered = true;
|
||||
} // namespace
|
||||
|
||||
Bool MGPipeApplierCurrentRecordIsBarriered() { return g_currentRecordBarriered; }
|
||||
|
||||
void MGPipeApplierSetCurrentRecordBarriered(Bool barriered) {
|
||||
g_currentRecordBarriered = barriered;
|
||||
}
|
||||
|
||||
// ================================================================================
|
||||
// w3: the shader CSO, the two program bindings and the default uniform block
|
||||
//
|
||||
@@ -2841,7 +3058,8 @@ namespace MobileGL::MG_Pipe {
|
||||
|
||||
void MGPipeApplyCreateShaderState(const MGPProgramDesc& desc,
|
||||
const MG_State::GLState::LinkArtifacts* link,
|
||||
const MG_State::GLState::SpirvArtifacts* spirv) {
|
||||
const MG_State::GLState::SpirvArtifacts* spirv,
|
||||
SharedPtr<const MG_State::GLState::ProgramArchive> archive) {
|
||||
MOBILEGL_ASSERT(desc.Cso.Slot >= kMGPipeFirstAllocatableSlot,
|
||||
"create_shader_state named the reserved slot 0");
|
||||
if (desc.Cso.Slot < kMGPipeFirstAllocatableSlot) return;
|
||||
@@ -2914,6 +3132,31 @@ namespace MobileGL::MG_Pipe {
|
||||
// deserialised archive is attached to. Either way the applier owns identity, extent and
|
||||
// order, and never content.
|
||||
record.Desc = desc;
|
||||
// P5e (pg), gap G-A: "under split the descriptor is what the deserialised archive is
|
||||
// attached to" is now literally true, and this is the attachment. ADOPTED
|
||||
// UNCONDITIONALLY, INCLUDING A NULL: a monolith create must CLEAR an archive a
|
||||
// previous split-arm create left behind, because the record outlives a transport
|
||||
// change (MGPipeApplierReset keeps the CSO table - a program lives in a share group)
|
||||
// and a stale archive is worse than none.
|
||||
//
|
||||
// AFTER Desc, so a reader that sees the new descriptor sees the artefacts it describes;
|
||||
// the apply thread is the only writer and the only reader, so ordering here is about
|
||||
// reading this function rather than about memory visibility.
|
||||
record.Archive = Move(archive);
|
||||
// THE RE-ISSUE CLEARS THE THREE BINDING TAILS for the reason it clears GlobalConstants
|
||||
// one branch up: they are indices INTO the archive that has just been replaced, so a
|
||||
// surviving tail would name block indices and uniform locations of a program that no
|
||||
// longer exists. Unconditional rather than inside the else-branch above, because a
|
||||
// recycled slot must not inherit its predecessor's bindings either - and a fresh record
|
||||
// has empty tails, so the clear costs a live program nothing. The client re-emits
|
||||
// set_program_bindings immediately after this create (ProgramEmit.h), which is the
|
||||
// ordering the applier relies on: emitting them BEFORE would put them where this line
|
||||
// wipes them.
|
||||
record.BlockBindings.clear();
|
||||
record.SamplerUnits.clear();
|
||||
record.StorageOverrides.clear();
|
||||
record.Signature = 0;
|
||||
++record.BindingsSerial;
|
||||
}
|
||||
|
||||
void MGPipeApplyBindShaderState(const MGPHandleOnly& handle) {
|
||||
|
||||
@@ -11,6 +11,10 @@
|
||||
|
||||
#include "MGPipeRenderStateSpans.h"
|
||||
#include "MGPipeTypes.h"
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §2.1): MGPipeBarriered takes an MGPWireOp and reads the
|
||||
// generated wait-class and call-class tables, all of which live in MGPipe.h. It is a sibling
|
||||
// header in the same layer - MG_Pipe includes MG_Pipe - so the closure does not move.
|
||||
#include "MGPipe.h"
|
||||
|
||||
// The in-process applier: the SERVER half of the calls P2 emits. Under split this file is
|
||||
// MG_Remote/Server/PipeApplier (ARCHITECTURE.md 8.3); in the monolith it writes
|
||||
@@ -34,9 +38,16 @@
|
||||
// this header needs their NAMES and never their definitions; the forward declaration is the
|
||||
// whole coupling and the closure gate is what keeps it one. The verify build is the only
|
||||
// place the codec runs, and it runs from PipeApply.cpp.
|
||||
// P5e (pg) ADDS A THIRD NAME AND KEEPS THE RULE: ProgramArchive is what a SPLIT create carries
|
||||
// - the record's OWN copy of both structs plus the stage of each module - and the record holds
|
||||
// it through a SharedPtr, which needs no definition either (the deleter is captured where the
|
||||
// archive is constructed, in the decoder's TU). So the coupling is still three names and no
|
||||
// closure change, and MG_Backend, which does need the definition, includes
|
||||
// ProgramArtifactsCodec.h for it.
|
||||
namespace MobileGL::MG_State::GLState {
|
||||
struct LinkArtifacts;
|
||||
struct SpirvArtifacts;
|
||||
struct ProgramArchive;
|
||||
} // namespace MobileGL::MG_State::GLState
|
||||
|
||||
namespace MobileGL::MG_Pipe {
|
||||
@@ -367,6 +378,16 @@ namespace MobileGL::MG_Pipe {
|
||||
// GlobalConstants is the one allocation P4a adds per program, it is bounded by
|
||||
// Desc.GlobalUboSize, and it is NOT on the hot path: set_global_constants is
|
||||
// (ShaderCso, Version) keyed and fires at most once per program per frame.
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §1): one entry of set_program_bindings' third tail as the
|
||||
// RECORD owns it. The wire carries the block name as an MGHostSpan into SEG_STAGE, which
|
||||
// retires with the record that named it (rule C), so the applier copies the bytes here
|
||||
// rather than keeping the span: a rebuild happens at the next bind, which may be a frame
|
||||
// later, and by then the staged run is somebody else's.
|
||||
struct MGPipeProgramStorageOverride {
|
||||
String Name;
|
||||
Int32 Binding = 0;
|
||||
};
|
||||
|
||||
struct MGPipeShaderCsoRecord {
|
||||
Uint32 Gen = 0;
|
||||
Bool Live = false;
|
||||
@@ -377,6 +398,53 @@ namespace MobileGL::MG_Pipe {
|
||||
Vector<Uint8> GlobalConstants;
|
||||
Uint64 GlobalConstantsSerial = 0;
|
||||
Uint64 Serial = 0;
|
||||
|
||||
// ---- P5e's server-owned archive (CONTRACT-P5E.md §5.5, gap G-A) --------------------
|
||||
//
|
||||
// FILLED BY PACKAGE pg, AND ONLY UNDER A TRANSPORT. This is the whole of rule F for
|
||||
// this family: before P5e the record stored the DESCRIPTOR and the artefacts rode
|
||||
// beside it as two companion pointers into the frontend's own ProgramObject, so every
|
||||
// reflection question the program twin asked - forty accessors in SyncToBackend alone -
|
||||
// was a read of client memory that `ProgramObject::Link()` REPLACES IN PLACE. Under
|
||||
// run-ahead the client is already several records past the create, so those reads are
|
||||
// torn or stale by construction and no amount of care at the read site can fix it.
|
||||
//
|
||||
// The client encodes the archive once per link (ProgramEmit.h -> SEG_STAGE), the
|
||||
// decoder frames and deserialises it, and the record ADOPTS it here - a SharedPtr and
|
||||
// not a Vector, because a program-pipeline composite and its stage programs are three
|
||||
// records over one link's artefacts, and because the twin holds the pointer across the
|
||||
// build it is running. It retires with the record, which is rule C: the staged run the
|
||||
// bytes arrived in belongs to somebody else by the next frame.
|
||||
//
|
||||
// NULL UNDER MONOLITH, and that is the arm selection and not an omission (ruling 1):
|
||||
// the push-monolith build keeps its frontend arms token for token, so its twin reads
|
||||
// the frontend's archive as it always has and this pointer is never consulted.
|
||||
SharedPtr<const MG_State::GLState::ProgramArchive> Archive;
|
||||
|
||||
// ---- P5e's set_program_bindings tails (CONTRACT-P5E.md §1, §5.5) -------------------
|
||||
//
|
||||
// DECLARED BY c0e, FILLED BY PACKAGE pg. THE THREE POST-LINK MUTABLE REFLECTION FIELDS
|
||||
// the archive cannot answer: glUniformBlockBinding, glUniform1i on a sampler uniform and
|
||||
// glShaderStorageBlockBinding all move a binding INSIDE the frontend's LinkArtifacts
|
||||
// after the link, so a twin that answered a draw from the archive alone would bind the
|
||||
// uniform blocks the program was LINKED with rather than the ones it is BOUND with.
|
||||
//
|
||||
// A RE-ISSUED create_shader_state CLEARS ALL OF THEM, for the reason it clears
|
||||
// GlobalConstants: a relink replaces the archive these index into, so a surviving tail
|
||||
// would name block indices and uniform locations of a program that no longer exists.
|
||||
// The client re-emits set_program_bindings before the create that describes the relink.
|
||||
Vector<Int32> BlockBindings; // dense, GL uniform-block index order
|
||||
Vector<MGPProgramSamplerUnit> SamplerUnits; // sparse, ascending Location
|
||||
Vector<MGPipeProgramStorageOverride> StorageOverrides; // name-keyed by design
|
||||
// The client's commutative hash of the override MAP, so the twin's "must I rebuild the
|
||||
// storage-block bindings" clause is one Uint64 compare and the name tail is touched only
|
||||
// on a rebuild. 0 is "no overrides", which is what an untouched program has.
|
||||
Uint64 Signature = 0;
|
||||
// Server-owned MGGen, ++ on every applied set_program_bindings for this record. It is
|
||||
// what the program twin's clean condition and both texture-unit memos key on (ruling 6),
|
||||
// so it obeys VertexBuffersSerial's rule: ADVANCED, never returned to a value it has
|
||||
// already handed out.
|
||||
Uint64 BindingsSerial = 0;
|
||||
};
|
||||
|
||||
// The vertex-elements CSO as the applier holds it: the unpacked blob, both views, plus
|
||||
@@ -693,6 +761,49 @@ namespace MobileGL::MG_Pipe {
|
||||
MGPipeHandle BoundShaderCso = kMGPipeNullHandle;
|
||||
Uint64 ProgramBindingSerial = 0;
|
||||
|
||||
// ---- P5e: THE INDEXED BUFFER BINDING POINTS (CONTRACT-P5E.md §5.6, rulings 10/11) ---
|
||||
//
|
||||
// DECLARED BY c0e, FILLED BY PACKAGE sb. One window per CLASS, because the record is
|
||||
// per class - a set_shader_buffers names Uniform, ShaderStorage or AtomicCounter and
|
||||
// describes THAT target's array. XFB does NOT ride this state: its targets are span-
|
||||
// scoped and carry a Generation this payload has no field for, so set_stream_output_
|
||||
// targets keeps its own row and XFB stays lockstep (§5.7).
|
||||
//
|
||||
// THE VAR-TAIL WINDOW IS THE BOUND, exactly as it is for the three unit sets above:
|
||||
// Start is 0 by contract, Count is the touched high-water mark, and a binding at or
|
||||
// above Count means "nothing bound" - which is what the frontend array's default says
|
||||
// too, so the server does not have to clear entries outside the window to be right.
|
||||
Array<MGPBufferRange, kMGPipeMaxBufferBindingPoints>
|
||||
BoundShaderBuffers[kMGPipeShaderBufferClassCount]{};
|
||||
Uint32 ShaderBufferStart[kMGPipeShaderBufferClassCount] = {0, 0, 0};
|
||||
Uint32 ShaderBufferCount[kMGPipeShaderBufferClassCount] = {0, 0, 0};
|
||||
// Which entries of classes 1 and 2 the shader may WRITE through. It is what replaces
|
||||
// the backend's own GPU-write marking walk (DirectGLES.cpp's three MarkBufferGpuWritten
|
||||
// sites), which sb deletes under a transport because the client already owns the
|
||||
// GPU-write set and the server's walk is over client memory.
|
||||
//
|
||||
// THREE WORDS PER CLASS, NOT ONE (P5e, ID-104): the window is 84 points and c0e's
|
||||
// single Uint32 could describe only the first 32 of them, so a storage buffer bound at
|
||||
// point 32 or above read as read-only here while the record said nothing was wrong.
|
||||
// Always through MGPipeShaderBufferMaskHas / ...Set (MGPipeTypes.h), which is the same
|
||||
// arithmetic the payload's own mask goes through - one table, both sides.
|
||||
Uint32 ShaderBufferWritableMask[kMGPipeShaderBufferClassCount]
|
||||
[kMGPipeShaderBufferWritableMaskWords] = {};
|
||||
// ONE serial for all three classes, ++ on every applied record and ADVANCED (never
|
||||
// zeroed) by MGPipeApplierReset, for VertexBuffersSerial's reason - and the emitter's
|
||||
// latch resets with it, or the first emission after a make-current is suppressed as
|
||||
// unchanged.
|
||||
Uint64 ShaderBuffersSerial = 0;
|
||||
|
||||
// ---- P5e: the applied value the barriered predicate's XFB escalation reads ---------
|
||||
//
|
||||
// MGPContextValues::IsTransformFeedbackActive as set_context_values last delivered it.
|
||||
// It is mirrored HERE, beside the applier's other working state, and not only written
|
||||
// into gPipeInputs, because MGPipeBarriered must be computable on the SERVER from
|
||||
// applier state alone: the record that carries it precedes the verb on the ring, so
|
||||
// both roles evaluate the same predicate over the same value (§2.1, escalation (i)).
|
||||
Bool IsTransformFeedbackActive = false;
|
||||
|
||||
// ---- P5c (rv, CONTRACT-P5C.md §5.3): the server-side answer for the three texture
|
||||
// SHUTTERS. FieldOwnership.def moves GetSamplingResolutionGeneration /
|
||||
// GetTextureBindGeneration / GetTextureContextId to APPLIER_DERIVED - "a shutter, not
|
||||
@@ -744,6 +855,14 @@ namespace MobileGL::MG_Pipe {
|
||||
// dispatch_indirect's command buffer (MGPGridInfo::IndirectBuffer).
|
||||
MGPipeHandle VerbDispatchIndirectBuffer = kMGPipeNullHandle;
|
||||
|
||||
// P5e: "is the record being applied barriered?" is NOT a member of this struct. It is
|
||||
// thread_local beside MGPipeApplierCurrentRecordIsBarriered() in PipeApply.cpp, because
|
||||
// it describes which record THIS THREAD is inside rather than per-context state the
|
||||
// applier owns - and because a reader (the allocator guard) that had to find the right
|
||||
// context's applier first would be asking a harder question than the one it needs
|
||||
// answered. The integrator resolved the two packages' duplicate here (ID-103).
|
||||
|
||||
|
||||
// Every verb's writer calls this FIRST and then sets its own fields, so no field ever
|
||||
// outlives the verb that wrote it and a reader can treat non-null as "this verb's".
|
||||
void ClearVerbHandles() {
|
||||
@@ -782,6 +901,73 @@ namespace MobileGL::MG_Pipe {
|
||||
// The monolith's single applier. Under split there is one per served context.
|
||||
MGPipeApplierState& MGPipeApplier();
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// P5e: THE BARRIERED PREDICATE (MG_Remote/CONTRACT-P5E.md §2.1, ruling 3)
|
||||
// ---------------------------------------------------------------------------------
|
||||
//
|
||||
// ONE FUNCTION, TWO CALLERS, AND THAT IS THE WHOLE POINT. The client calls it at the emit
|
||||
// table to decide whether to wait after publishing; the sink calls it in ApplyOne to decide
|
||||
// whether the record it is about to apply may read client memory. If the two answers ever
|
||||
// differ the failure is silent: the client runs on while the server reads a value that has
|
||||
// already moved. So it is a PURE FUNCTION OF WIRE-VISIBLE DATA - the static wait-class
|
||||
// column, the record's own payload, and applier state that a record earlier on the ring put
|
||||
// there - and both roles evaluate the same three clauses:
|
||||
//
|
||||
// 1. MGPipeWaitClassFor(op) != kWaitNone the static column (§2.2)
|
||||
// 2. kCtxVerb with an open transform-feedback span escalation (i): XFB stays lockstep
|
||||
// 3. draw_vbo carrying kDrawClientArrays escalation (ii): client vertex arrays
|
||||
//
|
||||
// NO OTHER RUNTIME ESCALATION EXISTS. Adding one is an integrator ruling and a row in the
|
||||
// contract, not a condition somebody adds at a call site - because a fourth clause that only
|
||||
// one side computes is the same silent failure one level down.
|
||||
//
|
||||
// Escalation (ii) is a REFUSAL under run-ahead (§5.1), so on a run-ahead server it never
|
||||
// reaches the sink at all; it is here so the predicate is TOTAL and so the lockstep arm,
|
||||
// where such a draw is legal, gets the barrier it needs.
|
||||
//
|
||||
// `payload` may be null, which answers "the fixed payload is not available here" and makes
|
||||
// clause 3 fall through - a caller that has an opcode but no bytes (the emit table before it
|
||||
// has built the record) must not be told a draw is unbarriered on that account, so DrawVbo
|
||||
// with a null payload is treated as carrying no client arrays and the emit site passes the
|
||||
// real MGPDrawInfo it is about to publish.
|
||||
Bool MGPipeBarriered(MGPWireOp op, const void* payload, const MGPipeApplierState& st);
|
||||
|
||||
// Whether the record the apply thread is INSIDE is a barriered one. Server-private: written
|
||||
// by the sink's ApplyOne from MGPipeBarriered before it dispatches, read by
|
||||
// MGPipeRefuseAllocatorFromApplyThread (§4.4) to decide whether a frontend-keyed registry
|
||||
// probe is a named, accounted debt or a role violation.
|
||||
//
|
||||
// IT ANSWERS `true` BY DEFAULT AND THAT IS THE LANDED LOCKSTEP ANSWER, not a stub: on a
|
||||
// server that does not publish kCapRunAheadApply - Magma always, and Espryt until the
|
||||
// integration commit - EVERY record is barriered, the client is parked in its own wait for
|
||||
// each of them, and P5C's semantics hold unchanged. An asserting body here would abort the
|
||||
// monolith and the lockstep split alike, which is why this one seam is implemented rather
|
||||
// than declared: the safe answer and the correct answer are the same answer.
|
||||
Bool MGPipeApplierCurrentRecordIsBarriered();
|
||||
// The one writer, called by the sink at the top of every record's dispatch. Package id owns
|
||||
// the call site (it is the line ra rebases onto); c0e owns the storage so both compile.
|
||||
void MGPipeApplierSetCurrentRecordBarriered(Bool barriered);
|
||||
|
||||
// THE CLIENT'S HALF OF THE WAIT RULE IS NOT LANDED YET, AND THIS CONSTANT IS THAT FACT.
|
||||
// MGPipeBarriered above describes what the client WILL do; until package ra changes
|
||||
// EmitAndWaitTails the client still blocks after every record, so the answer the server
|
||||
// must stamp is `true` whatever the wire says - the two named exemption scopes (§4.4) are
|
||||
// legal exactly while the client is parked, and it is parked behind all of them today.
|
||||
// IT FLIPS WITH kMGPipeP5eRunAheadReady, IN THE INTEGRATION COMMIT, AND NOT WHEN ra LANDS
|
||||
// (ra's amendment to ID-103's wording, which said "the same commit that lands the wait
|
||||
// rule"). The argument ID-103 makes is about whether the CLIENT is parked, not about
|
||||
// whether ra's code exists: RunAheadArmed() is a conjunction whose third term is the
|
||||
// server's caps bit, so between ra landing and the caps bit being published the client
|
||||
// still blocks after every record - and stamping `false` there would withdraw §4.4's
|
||||
// exemptions from probes that client's own wait still makes safe, which is exactly the
|
||||
// "refusal with no defect behind it" ID-103 refused. The two constants are therefore ONE
|
||||
// switch with two spellings, and the integration commit throws both.
|
||||
//
|
||||
// Computing the predicate anyway (PipeApplier::ApplyOne) is deliberate: it keeps the
|
||||
// function exercised on every record for the whole phase rather than first run on the day
|
||||
// it starts deciding.
|
||||
inline constexpr Bool kMGPipeP5eClientWaitRuleLanded = false;
|
||||
|
||||
// P5c (rv): the two serials the PipeInputs texture-shutter accessors answer with under a
|
||||
// server-stamped verb (FieldOwnership.def, APPLIER_DERIVED). Free functions rather than
|
||||
// member reads so PipeInputs.h needs this header's DECLARATIONS only... and because the
|
||||
@@ -793,6 +979,7 @@ namespace MobileGL::MG_Pipe {
|
||||
// this, so the bump rule lives in exactly one place.
|
||||
void MGPipeApplierNoteTextureStateMoved();
|
||||
|
||||
|
||||
// A MAKE-CURRENT, NOT A TEARDOWN - and the distinction is the whole of this function's
|
||||
// contract. It runs on every change of the current GLContext (MGPipeTracker::Update resets
|
||||
// the tracker whenever the context pointer moves, and the emitter calls this from the
|
||||
@@ -1145,6 +1332,37 @@ namespace MobileGL::MG_Pipe {
|
||||
void MGPipeApplyBindSamplerStates(const MGPSamplerStates& hdr, const MGPipeHandle* tail);
|
||||
void MGPipeApplySetShaderImages(const MGPShaderImages& hdr, const MGPImageView* tail);
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// P5e's two entry points: DECLARED BY c0e, BODIED BY sb AND pg
|
||||
// ---------------------------------------------------------------------------------
|
||||
//
|
||||
// Both are declared here, with bodies in PipeApply.cpp that ABORT BY NAME, so that every
|
||||
// P5e package compiles and links against the same signatures from day one and the family
|
||||
// that lands one of them changes a body rather than adding a symbol. An abort and not a
|
||||
// silent no-op: a record that reached an unimplemented applier and returned quietly is a
|
||||
// dropped binding set, which renders wrong rather than stopping - the exact failure mode
|
||||
// ID-39's sixty-six lost uploads had. Nothing routes either opcode until its package lands
|
||||
// (PipeCatalogueTest pins both table slots null), so the abort is unreachable today.
|
||||
|
||||
// set_shader_buffers, per Class. `tail` is hdr.Count MGPBufferRanges starting at hdr.Start;
|
||||
// Class >= kMGPipeShaderBufferClassCount and Start + Count above the capacity are
|
||||
// Fatal{ProtocolCorruption, "SetShaderBuffers.Class"} / "SetShaderBuffers.Count". Entries
|
||||
// outside the declared window are NOT cleared - the record is "the last set as received",
|
||||
// exactly as set_vertex_buffers is.
|
||||
void MGPipeApplySetShaderBuffers(const MGPShaderBuffers& hdr, const MGPBufferRange* tail);
|
||||
|
||||
// set_program_bindings. The three tails in the order the record declares them, plus the
|
||||
// RESOLVED block names for the override tail: the names ride SEG_STAGE as host spans and
|
||||
// SEG_STAGE retires with the record that named them, so the applier must copy them into the
|
||||
// record before this call returns (rule C) and the decoder hands over pointers that are
|
||||
// valid only for the duration of the call. `storageOverrideNames[i]` belongs to
|
||||
// `storageOverrides[i]`, NUL-terminated, exactly as set_storage_block_binding's single name
|
||||
// is. Any of the four pointers may be null when its count is 0.
|
||||
void MGPipeApplySetProgramBindings(const MGPProgramBindings& hdr, const Int32* blockBindings,
|
||||
const MGPProgramSamplerUnit* samplerUnits,
|
||||
const MGPProgramStorageOverride* storageOverrides,
|
||||
const char* const* storageOverrideNames);
|
||||
|
||||
// create_shader_state. THE ARTEFACTS TRAVEL BESIDE THE RECORD, by pointer: all seven of
|
||||
// desc.Spirv[] and desc.Reflection are declared with Size 0 ("this record does not declare
|
||||
// its blob"), which is what a monolith emission is, and the codec is NOT called - zero
|
||||
@@ -1152,9 +1370,20 @@ namespace MobileGL::MG_Pipe {
|
||||
// field-compares before storing, and a mismatch is Fatal{PipeVerifyDiffer, "program-archive"}.
|
||||
// Splitting this record for a transport whose ring caps one record at half its capacity is
|
||||
// P5's problem, not this entry point's.
|
||||
//
|
||||
// P5e (pg) ADDS THE FOURTH ARGUMENT AND DID NOT DEFAULT IT, for the reason PipeRoute.h
|
||||
// gives about the three byte counts it also refused to default: a caller that HAS the
|
||||
// archive and forgets to pass it would compile, and the failure would be a program twin
|
||||
// reading the frontend's artefacts on the apply thread - silent, and exactly what this
|
||||
// package exists to end. `archive` is null under monolith (the two companion pointers are
|
||||
// the frontend's own and the handle arm is not taken there) and non-null under a
|
||||
// transport, where `link` and `spirv` point INTO it: the record adopts it, so every later
|
||||
// reflection read is of memory the server owns. A non-null archive whose Link/Spirv are
|
||||
// not the two pointers passed beside it is a caller bug this entry point asserts on.
|
||||
void MGPipeApplyCreateShaderState(const MGPProgramDesc& desc,
|
||||
const MG_State::GLState::LinkArtifacts* link,
|
||||
const MG_State::GLState::SpirvArtifacts* spirv);
|
||||
const MG_State::GLState::SpirvArtifacts* spirv,
|
||||
SharedPtr<const MG_State::GLState::ProgramArchive> archive);
|
||||
void MGPipeApplyBindShaderState(const MGPHandleOnly& handle);
|
||||
void MGPipeApplyDeleteShaderState(const MGPHandleOnly& handle);
|
||||
void MGPipeApplySetDrawProgram(const MGPHandleOnly& handle);
|
||||
|
||||
+136
-84
@@ -11,11 +11,42 @@
|
||||
// (scripts/gen_pipe.py -> MG_Pipe/generated/*.inc) and one unit test
|
||||
// (MG_Test/Pipe/PipeCatalogueTest.cpp) pins the arithmetic.
|
||||
//
|
||||
// X(Name, PayloadStruct, Class, Flags)
|
||||
// X(Name, PayloadStruct, Class, Flags, WaitClass)
|
||||
// Class : kScreen | kCtxCso | kCtxState | kCtxObject | kCtxVerb | kCtxQuery
|
||||
// kScreen lands in struct MGPipeScreen, every other class in struct
|
||||
// MGPipeContext (plan section 4.3).
|
||||
// Flags : kNone | kNeedsAck | kHasBlob | kVarTail | kHostSpan | kReplySlot | kOptional
|
||||
// WaitClass : kWaitNone | kWaitApplied | kWaitReply | kWaitPresent
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md section 2.2). WHAT THE CLIENT DOES AFTER IT HAS
|
||||
// PUBLISHED A RECORD OF THIS CALL, on a server that publishes kCapRunAheadApply.
|
||||
// It is A VALUE AND NOT A NEW OP: the opcode order and the flag column are
|
||||
// untouched, and gen_pipe.py emits the column beside kMGPipeCallFlags as
|
||||
// MGPipeWaitClassFor(op) in generated/PipeWire.inc, so the emit table and the
|
||||
// sink compute the barriered predicate from one table instead of two copies.
|
||||
//
|
||||
// kWaitReply the answer is not derivable and the client acts on it (R-5), so
|
||||
// it blocks on the reply slot. EVERY kReplySlot ROW CARRIES IT and
|
||||
// gen_pipe.py refuses a row where the two disagree - a reply-slot
|
||||
// row that did not wait would be a waiter that hangs, and a waiting
|
||||
// row with no slot would block on an answer nobody posts.
|
||||
// resource_subdata is here because the row OWNS a slot; the buffer
|
||||
// half's wantReply=false is a per-record ROUTE decision one level
|
||||
// down (CONTRACT-P5E.md section 2.5), not a second wait class.
|
||||
// kWaitPresent present, whose pacing is the present CREDIT taken BEFORE the
|
||||
// encode rather than a wait after the publish (section 2.4).
|
||||
// kWaitApplied the record's apply still reads a BARRIER_PULLED row or probes the
|
||||
// client allocator, so the client parks in its own wait and the row
|
||||
// keeps CONTRACT-P5C's semantics exactly: its pulls count into rsp
|
||||
// and its probes are legal inside a scope. This column is the
|
||||
// static half of MGPipeBarriered(op, payload, applierState); the
|
||||
// other two escalations (an open XFB span, a draw with client
|
||||
// vertex arrays) are payload-derived and live in that function.
|
||||
// kWaitNone rule F holds for this row's sink: its apply names no client
|
||||
// memory at all, so the client publishes and moves on.
|
||||
//
|
||||
// THE COLUMN IS INERT UNTIL THE INTEGRATION COMMIT publishes kCapRunAheadApply
|
||||
// (MG_Backend/Init.cpp's kMGPipeP5eRunAheadReady): with the bit unpublished the
|
||||
// client runs today's lockstep path and never reads the table.
|
||||
// kNeedsAck on a call means records of this call MAY require an ack; a
|
||||
// per-record predicate decides. resource_respecify carries it for
|
||||
// glBufferStorage - a real synchronous allocation, and the only entry point
|
||||
@@ -45,15 +76,15 @@
|
||||
// appended server-side fence wait 1 and P5c's applier_reset 1
|
||||
// kCtxQuery 8 query object namespace 6, plus the appended timestamp pair 2
|
||||
// kCtxCso 13 CSO create/bind/delete
|
||||
// kCtxState 18 16 of the 18 set_* calls + the temporary set_residual_value_state
|
||||
// + P5c rv's set_context_values
|
||||
// kCtxState 19 16 of the 18 set_* calls + the temporary set_residual_value_state
|
||||
// + P5c rv's set_context_values + P5e's set_program_bindings
|
||||
// kCtxObject 10 set_texture_params (the 17th set_*) + 8 object-scoped transfers, plus
|
||||
// P5c's object_death 1
|
||||
// kCtxVerb 18 3 context-reading transfer calls + the 10 commands, plus the five
|
||||
// P5b-appended verbs (bind_shader_image, patch_parameter,
|
||||
// bind_stream_output, set_storage_block_binding,
|
||||
// copy_framebuffer_to_texture - MG_Remote/CONTRACT-P5B.md)
|
||||
// total 79
|
||||
// total 80
|
||||
//
|
||||
// Reconciliation with the plan's headline numbers (section 4.4 / appendix A), because they
|
||||
// do not add up to a set of UNIQUE records and this file has to hold unique records:
|
||||
@@ -101,9 +132,17 @@
|
||||
// routed through gMGPipeContext like its seventeen siblings, and under monolith it has no
|
||||
// producer at all - the fields keep coming through the residual fill, byte for byte as
|
||||
// before (G1). 79 unique records.
|
||||
// - P5e (MG_Remote/CONTRACT-P5E.md section 1) appended ONE more (opcode 80):
|
||||
// set_program_bindings, the three POST-LINK mutable reflection fields - the uniform-block
|
||||
// bindings, the sampler uniform units and the name-keyed storage-block override map. They
|
||||
// live inside the LinkArtifacts the reflection archive snapshots, and all three move AFTER
|
||||
// the link, so no existing row can carry them: create_shader_state describes the link and
|
||||
// this one describes what happened to it since. It lands with a NULL ROUTE and a sink that
|
||||
// refuses it by name until package pg wires the emitter, exactly as set_shader_buffers has
|
||||
// sat catalogued-and-dead since P4a. 80 unique records.
|
||||
// ---------------------------------------------------------------------------------------
|
||||
|
||||
#define MGP_CALL_LIST_DOCUMENTED_COUNT 79
|
||||
#define MGP_CALL_LIST_DOCUMENTED_COUNT 80
|
||||
|
||||
// clang-format off
|
||||
#define MGP_CALL_LIST(X) \
|
||||
@@ -112,7 +151,7 @@
|
||||
/* RendererInfo (MGPipeTypes.h). It carried none until P5 R-13.1; the flag is a */ \
|
||||
/* property of the payload, so its absence was simply wrong. Adding a flag does not */ \
|
||||
/* move an opcode: the opcode is this line's 1-based position. */ \
|
||||
X(GetCaps, MGPCaps, kScreen, kReplySlot|kHasBlob) \
|
||||
X(GetCaps, MGPCaps, kScreen, kReplySlot|kHasBlob, kWaitReply) \
|
||||
/* THE FOUR ACCEPTANCE ROWS (P5 R-5, R-16). These four and map_persistent are the only */ \
|
||||
/* applier entry points that RETURN something the client acts on destructively - clearing */ \
|
||||
/* per-level dirty flags, latching parameters, advancing its own bookkeeping - so the */ \
|
||||
@@ -120,7 +159,7 @@
|
||||
/* until P5, because in monolith the answer is the return value of a direct call and there */ \
|
||||
/* was nothing to declare. kMGPipeCallFlags is now what sizes the reply pool and what the */ \
|
||||
/* decoder posts against, so a row that answers without the flag is a waiter that hangs. */ \
|
||||
X(ResourceCreate, MGPResourceDesc, kScreen, kReplySlot) \
|
||||
X(ResourceCreate, MGPResourceDesc, kScreen, kReplySlot, kWaitReply) \
|
||||
/* NO kHasBlob, BY RULING (P5 R-13.3; CONTRACT-P5.md table 1 row 19). MGPResourceDesc */ \
|
||||
/* owns no MGPBlobRef and gains none: under split `initialBytes` is always nullptr and */ \
|
||||
/* the initial content of a glBufferData(size, data) / glTexImage*(..., data) arrives */ \
|
||||
@@ -129,65 +168,65 @@
|
||||
/* cost is one extra record. NOTE the SECOND uncarried companion on this call, the */ \
|
||||
/* MGPRespecifiedLevel* scope (PipeApply.h:792) - it is NOT bytes and NOT covered by */ \
|
||||
/* this ruling; table 1 row 19 gives it the two pad fields of MGPResourceDesc. */ \
|
||||
X(ResourceRespecify, MGPResourceDesc, kScreen, kNeedsAck|kReplySlot) \
|
||||
X(ResourceDestroy, MGPHandleOnly, kScreen, kNone) \
|
||||
X(MapPersistent, MGPHandleOnly, kScreen, kReplySlot|kOptional) \
|
||||
X(UnmapPersistent, MGPHandleOnly, kScreen, kOptional) \
|
||||
X(FenceCreate, MGPHandleOnly, kScreen, kNone) \
|
||||
X(FenceStatus, MGPHandleOnly, kScreen, kReplySlot) \
|
||||
X(FenceWait, MGPFenceWait, kScreen, kReplySlot) \
|
||||
X(FenceDestroy, MGPHandleOnly, kScreen, kNone) \
|
||||
X(ResourceRespecify, MGPResourceDesc, kScreen, kNeedsAck|kReplySlot, kWaitReply) \
|
||||
X(ResourceDestroy, MGPHandleOnly, kScreen, kNone, kWaitNone) \
|
||||
X(MapPersistent, MGPHandleOnly, kScreen, kReplySlot|kOptional, kWaitReply) \
|
||||
X(UnmapPersistent, MGPHandleOnly, kScreen, kOptional, kWaitNone) \
|
||||
X(FenceCreate, MGPHandleOnly, kScreen, kNone, kWaitNone) \
|
||||
X(FenceStatus, MGPHandleOnly, kScreen, kReplySlot, kWaitReply) \
|
||||
X(FenceWait, MGPFenceWait, kScreen, kReplySlot, kWaitReply) \
|
||||
X(FenceDestroy, MGPHandleOnly, kScreen, kNone, kWaitNone) \
|
||||
/* ---- context: query objects (plan 4.3 gives the namespace to the context) ---- */ \
|
||||
X(QueryCreate, MGPQueryDesc, kCtxQuery, kNone) \
|
||||
X(QueryBegin, MGPQueryDesc, kCtxQuery, kNone) \
|
||||
X(QueryEnd, MGPQueryDesc, kCtxQuery, kNone) \
|
||||
X(QueryAvailable, MGPHandleOnly, kCtxQuery, kReplySlot) \
|
||||
X(QueryResult, MGPQueryResultRequest, kCtxQuery, kReplySlot) \
|
||||
X(QueryDestroy, MGPHandleOnly, kCtxQuery, kNone) \
|
||||
X(QueryCreate, MGPQueryDesc, kCtxQuery, kNone, kWaitNone) \
|
||||
X(QueryBegin, MGPQueryDesc, kCtxQuery, kNone, kWaitNone) \
|
||||
X(QueryEnd, MGPQueryDesc, kCtxQuery, kNone, kWaitNone) \
|
||||
X(QueryAvailable, MGPHandleOnly, kCtxQuery, kReplySlot, kWaitReply) \
|
||||
X(QueryResult, MGPQueryResultRequest, kCtxQuery, kReplySlot, kWaitReply) \
|
||||
X(QueryDestroy, MGPHandleOnly, kCtxQuery, kNone, kWaitNone) \
|
||||
/* ---- context: CSO create/bind/delete (plan 4.4.2, 4.5.2-4.5.5) ---- */ \
|
||||
X(CreateRenderState, MGPRenderStateDesc, kCtxCso, kHasBlob) \
|
||||
X(BindRenderState, MGPBindRenderState, kCtxCso, kNone) \
|
||||
X(DeleteRenderState, MGPHandleOnly, kCtxCso, kNone) \
|
||||
X(CreateVertexElements, MGPVertexElements, kCtxCso, kHasBlob) \
|
||||
X(BindVertexElements, MGPHandleOnly, kCtxCso, kNone) \
|
||||
X(DeleteVertexElements, MGPHandleOnly, kCtxCso, kNone) \
|
||||
X(CreateRenderState, MGPRenderStateDesc, kCtxCso, kHasBlob, kWaitNone) \
|
||||
X(BindRenderState, MGPBindRenderState, kCtxCso, kNone, kWaitNone) \
|
||||
X(DeleteRenderState, MGPHandleOnly, kCtxCso, kNone, kWaitNone) \
|
||||
X(CreateVertexElements, MGPVertexElements, kCtxCso, kHasBlob, kWaitNone) \
|
||||
X(BindVertexElements, MGPHandleOnly, kCtxCso, kNone, kWaitNone) \
|
||||
X(DeleteVertexElements, MGPHandleOnly, kCtxCso, kNone, kWaitNone) \
|
||||
/* kHasBlob because MGPSamplerDesc owns an MGPBlobRef member, `Parameters` - the */ \
|
||||
/* SamplerParameters POD byte for byte, borderColorForm included (P5 R-13.1). The */ \
|
||||
/* companion pointer beside the record today is a TYPED frontend pointer */ \
|
||||
/* (const SamplerParameters*), which is exactly what split may not carry. */ \
|
||||
X(CreateSamplerState, MGPSamplerDesc, kCtxCso, kHasBlob) \
|
||||
X(DeleteSamplerState, MGPHandleOnly, kCtxCso, kNone) \
|
||||
X(CreateSamplerView, MGPSamplerView, kCtxCso, kNone) \
|
||||
X(DeleteSamplerView, MGPHandleOnly, kCtxCso, kNone) \
|
||||
X(CreateShaderState, MGPProgramDesc, kCtxCso, kHasBlob) \
|
||||
X(BindShaderState, MGPHandleOnly, kCtxCso, kNone) \
|
||||
X(DeleteShaderState, MGPHandleOnly, kCtxCso, kNone) \
|
||||
X(CreateSamplerState, MGPSamplerDesc, kCtxCso, kHasBlob, kWaitNone) \
|
||||
X(DeleteSamplerState, MGPHandleOnly, kCtxCso, kNone, kWaitNone) \
|
||||
X(CreateSamplerView, MGPSamplerView, kCtxCso, kNone, kWaitNone) \
|
||||
X(DeleteSamplerView, MGPHandleOnly, kCtxCso, kNone, kWaitNone) \
|
||||
X(CreateShaderState, MGPProgramDesc, kCtxCso, kHasBlob, kWaitNone) \
|
||||
X(BindShaderState, MGPHandleOnly, kCtxCso, kNone, kWaitNone) \
|
||||
X(DeleteShaderState, MGPHandleOnly, kCtxCso, kNone, kWaitNone) \
|
||||
/* ---- context: set_* (plan 4.4.3) ---- */ \
|
||||
X(SetDynamicState, MGPDynamicState, kCtxState, kHasBlob) \
|
||||
X(SetFramebufferState, MGPFramebufferState, kCtxState, kNone) \
|
||||
X(SetVertexBuffers, MGPVertexBuffers, kCtxState, kVarTail) \
|
||||
X(SetIndexBuffer, MGPIndexBuffer, kCtxState, kNone) \
|
||||
X(SetIndirectBuffers, MGPIndirectBuffers, kCtxState, kNone) \
|
||||
X(SetSamplerViews, MGPSamplerViews, kCtxState, kVarTail) \
|
||||
X(BindSamplerStates, MGPSamplerStates, kCtxState, kVarTail) \
|
||||
X(SetShaderImages, MGPShaderImages, kCtxState, kVarTail) \
|
||||
X(SetShaderBuffers, MGPShaderBuffers, kCtxState, kVarTail|kHostSpan) \
|
||||
X(SetStreamOutputTargets, MGPStreamOutputTargets, kCtxState, kVarTail) \
|
||||
X(SetGlobalConstants, MGPGlobalConstants, kCtxState, kHasBlob) \
|
||||
X(SetVertexAttribDefaults, MGPVertexAttribDefaults, kCtxState, kVarTail) \
|
||||
X(SetPixelPackState, MGPPixelPackState, kCtxState, kNone) \
|
||||
X(SetPatchState, MGPPatchState, kCtxState, kNone) \
|
||||
X(SetDrawProgram, MGPHandleOnly, kCtxState, kNone) \
|
||||
X(SetDispatchProgram, MGPHandleOnly, kCtxState, kNone) \
|
||||
X(SetDynamicState, MGPDynamicState, kCtxState, kHasBlob, kWaitNone) \
|
||||
X(SetFramebufferState, MGPFramebufferState, kCtxState, kNone, kWaitNone) \
|
||||
X(SetVertexBuffers, MGPVertexBuffers, kCtxState, kVarTail, kWaitNone) \
|
||||
X(SetIndexBuffer, MGPIndexBuffer, kCtxState, kNone, kWaitNone) \
|
||||
X(SetIndirectBuffers, MGPIndirectBuffers, kCtxState, kNone, kWaitNone) \
|
||||
X(SetSamplerViews, MGPSamplerViews, kCtxState, kVarTail, kWaitNone) \
|
||||
X(BindSamplerStates, MGPSamplerStates, kCtxState, kVarTail, kWaitNone) \
|
||||
X(SetShaderImages, MGPShaderImages, kCtxState, kVarTail, kWaitNone) \
|
||||
X(SetShaderBuffers, MGPShaderBuffers, kCtxState, kVarTail|kHostSpan, kWaitNone) \
|
||||
X(SetStreamOutputTargets, MGPStreamOutputTargets, kCtxState, kVarTail, kWaitNone) \
|
||||
X(SetGlobalConstants, MGPGlobalConstants, kCtxState, kHasBlob, kWaitNone) \
|
||||
X(SetVertexAttribDefaults, MGPVertexAttribDefaults, kCtxState, kVarTail, kWaitNone) \
|
||||
X(SetPixelPackState, MGPPixelPackState, kCtxState, kNone, kWaitNone) \
|
||||
X(SetPatchState, MGPPatchState, kCtxState, kNone, kWaitNone) \
|
||||
X(SetDrawProgram, MGPHandleOnly, kCtxState, kNone, kWaitNone) \
|
||||
X(SetDispatchProgram, MGPHandleOnly, kCtxState, kNone, kWaitNone) \
|
||||
/* Migration-only carrier for Track V, retired field by field across P2..P13. Its */ \
|
||||
/* retirement is a compile error: MGL_RESIDUAL_BLOCK_SIZE only ever goes DOWN and the */ \
|
||||
/* final step asserts sizeof(ResidualValueBlock) == 0 (plan 6.3). */ \
|
||||
X(SetResidualValueState, MGPResidualValueState, kCtxState, kHasBlob) \
|
||||
X(SetResidualValueState, MGPResidualValueState, kCtxState, kHasBlob, kWaitNone) \
|
||||
/* ---- context: per-object state and transfer (plan 4.4.3 set_texture_params, 4.4.4) ---- */ \
|
||||
X(SetTextureParams, MGPTextureParams, kCtxObject, kReplySlot) \
|
||||
X(ResourceSubData, MGPSubData, kCtxObject, kHasBlob|kVarTail|kReplySlot) \
|
||||
X(BufferSubDataResident, MGPSubData, kCtxObject, kHasBlob|kOptional) \
|
||||
X(ResourceSubDataComplete, MGPSubDataComplete, kCtxObject, kNone) \
|
||||
X(SetTextureParams, MGPTextureParams, kCtxObject, kReplySlot, kWaitReply) \
|
||||
X(ResourceSubData, MGPSubData, kCtxObject, kHasBlob|kVarTail|kReplySlot, kWaitReply) \
|
||||
X(BufferSubDataResident, MGPSubData, kCtxObject, kHasBlob|kOptional, kWaitNone) \
|
||||
X(ResourceSubDataComplete, MGPSubDataComplete, kCtxObject, kNone, kWaitNone) \
|
||||
/* NO kHasBlob AND NO MGPBlobRef, BY RULING (P5 R-13.2; CONTRACT-P5.md table 1 row 21). */ \
|
||||
/* It takes a content pointer today, but under split it CARRIES NO BYTES AT ALL: it is */ \
|
||||
/* a {range, AccessFlags} control record, and the bytes of [Offset, Offset+Size) arrive */ \
|
||||
@@ -195,36 +234,36 @@
|
||||
/* drives rewrites its range "from the authoritative shadow" (Managers.cpp:1047-1076), */ \
|
||||
/* and under split the authoritative shadow is server-owned (R-11), so subdata is the */ \
|
||||
/* only way bytes reach it - a blobref here would be a SECOND way to say the same thing. */ \
|
||||
X(ResourceFlushRange, MGPFlushRange, kCtxObject, kNone) \
|
||||
X(ResourceReadback, MGPReadback, kCtxObject, kReplySlot) \
|
||||
X(ResourceCopyRegion, MGPCopyRegion, kCtxObject, kNone) \
|
||||
X(GenerateMipmap, MGPMipPlan, kCtxObject, kNone) \
|
||||
X(GetTextureImage, MGPReadbackInfo, kCtxObject, kReplySlot) \
|
||||
X(ResourceFlushRange, MGPFlushRange, kCtxObject, kNone, kWaitNone) \
|
||||
X(ResourceReadback, MGPReadback, kCtxObject, kReplySlot, kWaitReply) \
|
||||
X(ResourceCopyRegion, MGPCopyRegion, kCtxObject, kNone, kWaitNone) \
|
||||
X(GenerateMipmap, MGPMipPlan, kCtxObject, kNone, kWaitApplied) \
|
||||
X(GetTextureImage, MGPReadbackInfo, kCtxObject, kReplySlot, kWaitReply) \
|
||||
/* ---- context: transfer calls that read whole-context state, and the commands ---- */ \
|
||||
X(Blit, MGPBlit, kCtxVerb, kNone) \
|
||||
X(Clear, MGPClear, kCtxVerb, kNone) \
|
||||
X(ReadPixels, MGPReadbackInfo, kCtxVerb, kReplySlot) \
|
||||
X(DrawVbo, MGPDrawInfo, kCtxVerb, kHostSpan|kVarTail) \
|
||||
X(LaunchGrid, MGPGridInfo, kCtxVerb, kNone) \
|
||||
X(MemoryBarrier, MGPMemoryBarrier, kCtxVerb, kNone) \
|
||||
X(BeginStreamOutput, MGPStreamOutputBegin, kCtxVerb, kNone) \
|
||||
X(EndStreamOutput, MGPXfbAccounting, kCtxVerb, kNone) \
|
||||
X(PauseStreamOutput, MGPStreamOutputControl, kCtxVerb, kNone) \
|
||||
X(ResumeStreamOutput, MGPStreamOutputControl, kCtxVerb, kNone) \
|
||||
X(Flush, MGPFlush, kCtxVerb, kNone) \
|
||||
X(Present, MGPPresent, kCtxVerb, kNone) \
|
||||
X(SetSwapInterval, MGPSwapInterval, kCtxVerb, kOptional) \
|
||||
X(Blit, MGPBlit, kCtxVerb, kNone, kWaitNone) \
|
||||
X(Clear, MGPClear, kCtxVerb, kNone, kWaitNone) \
|
||||
X(ReadPixels, MGPReadbackInfo, kCtxVerb, kReplySlot, kWaitReply) \
|
||||
X(DrawVbo, MGPDrawInfo, kCtxVerb, kHostSpan|kVarTail, kWaitNone) \
|
||||
X(LaunchGrid, MGPGridInfo, kCtxVerb, kNone, kWaitNone) \
|
||||
X(MemoryBarrier, MGPMemoryBarrier, kCtxVerb, kNone, kWaitNone) \
|
||||
X(BeginStreamOutput, MGPStreamOutputBegin, kCtxVerb, kNone, kWaitApplied) \
|
||||
X(EndStreamOutput, MGPXfbAccounting, kCtxVerb, kNone, kWaitApplied) \
|
||||
X(PauseStreamOutput, MGPStreamOutputControl, kCtxVerb, kNone, kWaitApplied) \
|
||||
X(ResumeStreamOutput, MGPStreamOutputControl, kCtxVerb, kNone, kWaitApplied) \
|
||||
X(Flush, MGPFlush, kCtxVerb, kNone, kWaitNone) \
|
||||
X(Present, MGPPresent, kCtxVerb, kNone, kWaitPresent) \
|
||||
X(SetSwapInterval, MGPSwapInterval, kCtxVerb, kOptional, kWaitNone) \
|
||||
/* ---- APPENDED. Opcodes are positional, so a late arrival goes at the END, never into ---- */ \
|
||||
/* ---- its group: three live GLFunctionsTable entries the catalogue had no carrier for. ---- */ \
|
||||
/* glGetInteger64v(GL_TIMESTAMP) - GetGpuTimestampNs, a synchronous server answer, which */ \
|
||||
/* the reply slot carries. The query namespace is the context's (plan 4.3). */ \
|
||||
X(QueryTimestamp, MGPTimestampRequest, kCtxQuery, kReplySlot) \
|
||||
X(QueryTimestamp, MGPTimestampRequest, kCtxQuery, kReplySlot, kWaitReply) \
|
||||
/* glQueryCounter(GL_TIMESTAMP) - QueryCounterTimestamp, a one-shot stamp into a query */ \
|
||||
/* object, NOT a begin/end pair. Kind carries GL_TIMESTAMP. */ \
|
||||
X(QueryCounter, MGPQueryDesc, kCtxQuery, kNone) \
|
||||
X(QueryCounter, MGPQueryDesc, kCtxQuery, kNone, kWaitNone) \
|
||||
/* glWaitSync - WaitSync, the GPU-side wait, distinct from FenceWait's client-side one. */ \
|
||||
/* TimeoutNs is GL_TIMEOUT_IGNORED by contract. */ \
|
||||
X(FenceWaitServer, MGPFenceWait, kScreen, kNone) \
|
||||
X(FenceWaitServer, MGPFenceWait, kScreen, kNone, kWaitNone) \
|
||||
/* ---- APPENDED BY P5b (MG_Remote/CONTRACT-P5B.md): five GLFunctionsTable verbs the ---- */ \
|
||||
/* ---- class-C census measured as first blockers and that no existing row could carry. ---- */ \
|
||||
/* ---- Opcodes 72..76. Every one reaches WireVerbSink, none has an MGPipeApply* entry ---- */ \
|
||||
@@ -232,18 +271,18 @@
|
||||
/* ---- directly, as today. The payload comments in MGPipeTypes.h say why each exists. ---- */ \
|
||||
/* glBindImageTexture - Espryt syncs the unit's binding to the driver AT THE CALL */ \
|
||||
/* (SyncImageTextureBinding), so the validate-time set_shader_images cannot stand in. */ \
|
||||
X(BindShaderImage, MGPImageBind, kCtxVerb, kNone) \
|
||||
X(BindShaderImage, MGPImageBind, kCtxVerb, kNone, kWaitNone) \
|
||||
/* glPatchParameteri(GL_PATCH_VERTICES) - Espryt pushes glPatchParameteri at the call. */ \
|
||||
X(PatchParameter, MGPPatchParameter, kCtxVerb, kNone) \
|
||||
X(PatchParameter, MGPPatchParameter, kCtxVerb, kNone, kWaitNone) \
|
||||
/* glBindTransformFeedback - the driver object rebind and the capture-binding shadow */ \
|
||||
/* invalidation happen at the call; the XFB namespace has no wire lifetime. */ \
|
||||
X(BindStreamOutput, MGPStreamOutputBind, kCtxVerb, kNone) \
|
||||
X(BindStreamOutput, MGPStreamOutputBind, kCtxVerb, kNone, kWaitApplied) \
|
||||
/* glShaderStorageBlockBinding - the block NAME is the coordinate all three sides share */ \
|
||||
/* (BackendObject.h), and a name is bytes: kHasBlob, staged whole in SEG_STAGE, NUL included. */ \
|
||||
X(SetStorageBlockBinding, MGPStorageBlockBinding, kCtxVerb, kHasBlob) \
|
||||
X(SetStorageBlockBinding, MGPStorageBlockBinding, kCtxVerb, kHasBlob, kWaitApplied) \
|
||||
/* glCopyTexImage2D / glCopyTexSubImage2D - a copy whose SOURCE is the read framebuffer, */ \
|
||||
/* which resource_copy_region (resource -> resource) cannot express. */ \
|
||||
X(CopyFramebufferToTexture, MGPCopyFromFramebuffer, kCtxVerb, kNone) \
|
||||
X(CopyFramebufferToTexture, MGPCopyFromFramebuffer, kCtxVerb, kNone, kWaitApplied) \
|
||||
/* ---- APPENDED BY P5c (MG_Remote/CONTRACT-P5C.md §5): the two control records. Opcodes ---- */ \
|
||||
/* ---- 77..78. Neither has an MGPipeApply* entry point and neither gains one: both reach ---- */ \
|
||||
/* ---- WireVerbSink, and under monolith neither has a producer - the reset is a direct ---- */ \
|
||||
@@ -255,14 +294,14 @@
|
||||
/* against every verb that follows. ContextSerial is the client context's make-current */ \
|
||||
/* serial at the edge - ASSERTED against the session's, never dispatched on (P5c: one */ \
|
||||
/* context per session). */ \
|
||||
X(ApplierReset, MGPApplierReset, kScreen, kNone) \
|
||||
X(ApplierReset, MGPApplierReset, kScreen, kNone, kWaitApplied) \
|
||||
/* A frontend state object died. The record carries the HANDLE (and kind) the client's own */ \
|
||||
/* allocator resolves for it - nothing is emitted for an object that never crossed (the */ \
|
||||
/* server never saw it, so there is no twin to kill) - and the sink releases the kind's */ \
|
||||
/* twin table by handle. The framebuffer family's FIRST wire delete opcode: its death used */ \
|
||||
/* to hop to the apply thread through a stack-struct mailbox and a lifetime-id probe of */ \
|
||||
/* the client's allocator, both rule-E surfaces. */ \
|
||||
X(ObjectDeath, MGPHandleOnly, kCtxObject, kNone) \
|
||||
X(ObjectDeath, MGPHandleOnly, kCtxObject, kNone, kWaitNone) \
|
||||
/* ---- P5c rv (CONTRACT-P5C.md §5.3), opcode 79: the residual-value record. One POD that ---- */ \
|
||||
/* ---- carries every value-class BARRIER_PULLED field left after the set_* catalogue: the ---- */ \
|
||||
/* ---- two texture-unit counters, the 15 per-target touched-buffer-binding counts and the ---- */ \
|
||||
@@ -270,7 +309,20 @@
|
||||
/* ---- (whole-record hash suppression, D11's shape), ACTIVE ONLY with an active transport ---- */ \
|
||||
/* ---- (PipeFill.cpp gates both the emission and the residual-fill skip on it): under ---- */ \
|
||||
/* ---- monolith there is no producer and the fields keep being pulled, byte for byte (G1). ---- */ \
|
||||
X(SetContextValues, MGPContextValues, kCtxState, kNone)
|
||||
X(SetContextValues, MGPContextValues, kCtxState, kNone, kWaitNone) \
|
||||
/* ---- P5e (MG_Remote/CONTRACT-P5E.md §1), opcode 80: the post-link binding record. ------ */ \
|
||||
/* ---- THREE POST-LINK MUTABLE REFLECTION FIELDS LIVE INSIDE THE FRONTEND'S LinkArtifacts ---- */ \
|
||||
/* ---- and therefore inside the archive create_shader_state carries - but glUniformBlock- ---- */ \
|
||||
/* ---- Binding, glUniform1i on a sampler and glShaderStorageBlockBinding all move one ---- */ \
|
||||
/* ---- AFTER the link. So an archive snapshot alone answers a draw with the bindings the ---- */ \
|
||||
/* ---- program was LINKED with rather than the ones it is BOUND with, and the server's ---- */ \
|
||||
/* ---- twin rebuilds against the wrong uniform-block points. Three tails, three index ---- */ \
|
||||
/* ---- spaces (dense block index, sparse uniform location, and a NAME span for the storage ---- */ \
|
||||
/* ---- override map, which is name-keyed by design). Emitted BEFORE create_shader_state at ---- */ \
|
||||
/* ---- the same validate point: a rebuild inside the verb must already see the bindings. ---- */ \
|
||||
/* ---- kWaitNone: nothing about it is read back, and under run-ahead a kCtxState row that ---- */ \
|
||||
/* ---- names only handles and values is exactly what rule F admits. ---- */ \
|
||||
X(SetProgramBindings, MGPProgramBindings, kCtxState, kVarTail|kHostSpan, kWaitNone)
|
||||
// clang-format on
|
||||
|
||||
// Explicitly NOT migrated (plan 4.4.6 / appendix A "explicit deletions"):
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
|
||||
#define MGP_FIELDS_MGPProgramDesc(F) \
|
||||
F(Cso) F(StageMask) F(GlobalUboSize) F(ReservedNumSamplesOffset) F(SpirvStatus) F(NativeFloat64) \
|
||||
F(PointSizeDemoted) F(EnableSpirvValidation) F(Spirv) F(Reflection)
|
||||
F(PointSizeDemoted) F(EnableSpirvValidation) F(LinkStatus) F(Spirv) F(Reflection)
|
||||
|
||||
// P4a, ID-12 / esprytobj DV-5: Pad0 became Uint16 TextureTarget. Same trip wire as
|
||||
// MGPFramebufferState's Target below - PADDING_MEMBER_RE only excludes a member still NAMED
|
||||
@@ -145,6 +145,19 @@
|
||||
#define MGP_FIELDS_MGPStreamOutputTargets(F) \
|
||||
F(Count) F(Generation) F(ContentHash)
|
||||
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §1): set_program_bindings and its two tail element types. The
|
||||
// third tail's element embeds an MGHostSpan, which has a list of its own below, so the
|
||||
// comparator sees the NAME SPAN's four members rather than memcmp'ing a struct with a pointer
|
||||
// and a pad word in it - the exact false-difference MGPSamplerDesc's blob used to produce.
|
||||
#define MGP_FIELDS_MGPProgramBindings(F) \
|
||||
F(Cso) F(Signature) F(BlockBindingCount) F(SamplerUnitCount) F(StorageOverrideCount)
|
||||
|
||||
#define MGP_FIELDS_MGPProgramSamplerUnit(F) \
|
||||
F(Location) F(Unit)
|
||||
|
||||
#define MGP_FIELDS_MGPProgramStorageOverride(F) \
|
||||
F(Name) F(Binding)
|
||||
|
||||
#define MGP_FIELDS_MGPGlobalConstants(F) \
|
||||
F(ShaderCso) F(Version) F(Blob)
|
||||
|
||||
@@ -394,6 +407,7 @@
|
||||
P(MGPImageBind) P(MGPPatchParameter) P(MGPStreamOutputBind) P(MGPStorageBlockBinding) \
|
||||
P(MGPCopyFromFramebuffer) \
|
||||
P(MGPApplierReset) P(MGPContextValues) \
|
||||
P(MGPProgramBindings) P(MGPProgramSamplerUnit) P(MGPProgramStorageOverride) \
|
||||
P(RenderStateParameters) P(PixelStoreParameters) P(SamplerParameters) P(PerBufferBlendState) \
|
||||
P(StencilFaceState) \
|
||||
P(DynamicBackendParameters) P(MGHostSpan) \
|
||||
|
||||
@@ -231,8 +231,38 @@ namespace MobileGL::MG_Pipe {
|
||||
// BeforeReadOnlyVerb) through MGPipeDrainDeferredDestroys. A delayed free is safe:
|
||||
// slots are plentiful, reuse is delayed rather than corrupted, and the replay runs the
|
||||
// helper itself, so every helper's own three-step order is untouched.
|
||||
// P5e (ra), CONTRACT-P5E §2.7 / ruling 13 (ID-91): THE QUEUE STAYS LIVE, AND AN
|
||||
// UNBARRIERED ENQUEUE IS A FINDING. After the family packages land, an unbarriered apply
|
||||
// holds no frontend SharedPtr at all - every object is resolved from a handle - so the
|
||||
// only apply thread that can still be a last owner is one inside a BARRIERED record (a
|
||||
// fill's O-class rows, XFB's pinned targets). An enqueue from an unbarriered record
|
||||
// therefore means some site still pins a frontend object across a record, which is a
|
||||
// migration this phase believes it finished: it logs once with the kind, and is Fatal
|
||||
// under MOBILEGL_IPC_STRICT_ERRORS so the strict lane owns the red. The queue itself is
|
||||
// NOT removed - it is the belt that keeps the barriered case from corrupting the
|
||||
// allocator while the finding is being read.
|
||||
Bool MGPipeDeferDestroyAndFreeIfOnApplyThread(MGPipeKind kind, Uint64 lifetimeId);
|
||||
void MGPipeDrainDeferredDestroys();
|
||||
|
||||
// P5e (ra), CONTRACT-P5E §2.3: drop the four O-class SharedPtr rows the residual fill left
|
||||
// in gPipeInputs (the bound VAO and the three programs, PipeInputs.h's O block). Called by
|
||||
// ClientSession on the GL thread once a BARRIERED apply has returned - the one instant
|
||||
// under run-ahead at which the applier is provably idle and this block has no other
|
||||
// reader. Under lockstep nothing calls it: the next verb's fill overwrites those rows
|
||||
// within a verb, and dropping them early would only cost a re-pin.
|
||||
//
|
||||
// It is HERE rather than in ClientSession because the rows are PipeInputs' private storage
|
||||
// and MGPipeFillAccess - the client-side door to it - lives in MG_Impl (PipeFill.cpp).
|
||||
// MG_Remote says when; MG_Impl says what.
|
||||
void MGPipeReleaseResidualFillPins();
|
||||
|
||||
// P5e (ra), CONTRACT-P5E §2.5: glFinish's whole body under a transport. Declared here
|
||||
// rather than on ClientSession so that MG_Impl's GL entry points - which are BELOW
|
||||
// MG_Remote - can reach it without learning that a session exists; the implementation in
|
||||
// PipeFill.cpp is one forward to ClientSession::Finish. A no-op with no live session, on a
|
||||
// monolith transport, and on a lockstep one (there the client waited out every command it
|
||||
// issued before it could reach the call).
|
||||
void MGPipeClientFinish();
|
||||
#endif
|
||||
|
||||
void MGPipeEmitResourceCreate(MG_State::GLState::BufferObject& buffer);
|
||||
|
||||
@@ -225,6 +225,11 @@ namespace MobileGL::MG_Pipe {
|
||||
MGP_MONO_TAIL(SetSamplerViews, MGPSamplerViews, MGPBoundView)
|
||||
MGP_MONO_TAIL(BindSamplerStates, MGPSamplerStates, MGPipeHandle)
|
||||
MGP_MONO_TAIL(SetShaderImages, MGPShaderImages, MGPImageView)
|
||||
// P5e (sb, CONTRACT-P5E.md §5.6). Catalogued since P4a with no producer and no
|
||||
// consumer; the adapter lands with the applier's body. The generic tail shape fits
|
||||
// because the SECOND tail is absent on every Espryt configuration (HostSpanCount is 0
|
||||
// while kCapNeedsHostUboBytes is 0, which is the whole of P5).
|
||||
MGP_MONO_TAIL(SetShaderBuffers, MGPShaderBuffers, MGPBufferRange)
|
||||
MGP_MONO_TAIL(SetVertexAttribDefaults, MGPVertexAttribDefaults, MGPAttribValue)
|
||||
|
||||
#undef MGP_MONO_PLAIN
|
||||
@@ -310,8 +315,33 @@ namespace MobileGL::MG_Pipe {
|
||||
|
||||
void Mono_Escape_CreateShaderState(const MGPProgramDesc* desc,
|
||||
const MG_State::GLState::LinkArtifacts* link,
|
||||
const MG_State::GLState::SpirvArtifacts* spirv) {
|
||||
MGPipeApplyCreateShaderState(*desc, link, spirv);
|
||||
const MG_State::GLState::SpirvArtifacts* spirv,
|
||||
const Uint32* linkedStages, Uint32 linkedStageCount) {
|
||||
// The stage list is the CLIENT ARM's framing input and this arm has no use for it:
|
||||
// the monolith twin reads GetLinkedShaderStages() off the frontend object it is
|
||||
// handed. Named and discarded rather than left out of the signature, so the two
|
||||
// arms stay one row.
|
||||
(void)linkedStages;
|
||||
(void)linkedStageCount;
|
||||
// P5e (pg): NO ARCHIVE ON THIS ARM, and the null is the arm selection rather than a
|
||||
// hole. Under monolith the two companion pointers ARE the frontend's own archive,
|
||||
// the backend twin reads it through its frontend overload (ruling 1 keeps that arm
|
||||
// token for token), and serialising here to deserialise into the record would put
|
||||
// EncodeProgramArtifacts on the monolith path - which PipeRoute.h's escape note
|
||||
// and PipeApply.h both promise it is not.
|
||||
MGPipeApplyCreateShaderState(*desc, link, spirv, nullptr);
|
||||
}
|
||||
|
||||
// P5e (pg), the fifth escape. A pass-through like the four above: the caller already
|
||||
// holds the three tails and the parallel name array, and under monolith there is no
|
||||
// segment to resolve - the names ARE the frontend's own String::c_str()s, alive for
|
||||
// the duration of the call, which is exactly the lifetime the applier's copy-in needs.
|
||||
void Mono_Escape_SetProgramBindings(const MGPProgramBindings* hdr, const Int32* blockBindings,
|
||||
const MGPProgramSamplerUnit* samplerUnits,
|
||||
const MGPProgramStorageOverride* storageOverrides,
|
||||
const char* const* storageOverrideNames) {
|
||||
MGPipeApplySetProgramBindings(*hdr, blockBindings, samplerUnits, storageOverrides,
|
||||
storageOverrideNames);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -342,6 +372,7 @@ namespace MobileGL::MG_Pipe {
|
||||
gMGPipeContext.SetSamplerViews = &Mono_SetSamplerViews;
|
||||
gMGPipeContext.BindSamplerStates = &Mono_BindSamplerStates;
|
||||
gMGPipeContext.SetShaderImages = &Mono_SetShaderImages;
|
||||
gMGPipeContext.SetShaderBuffers = &Mono_SetShaderBuffers;
|
||||
gMGPipeContext.SetGlobalConstants = &Mono_SetGlobalConstants;
|
||||
gMGPipeContext.SetVertexAttribDefaults = &Mono_SetVertexAttribDefaults;
|
||||
gMGPipeContext.SetPixelPackState = &Mono_SetPixelPackState;
|
||||
@@ -357,6 +388,7 @@ namespace MobileGL::MG_Pipe {
|
||||
gMGPipeRouteEscapes.ResourceFlushRange = &Mono_Escape_ResourceFlushRange;
|
||||
gMGPipeRouteEscapes.MapPersistent = &Mono_Escape_MapPersistent;
|
||||
gMGPipeRouteEscapes.CreateShaderState = &Mono_Escape_CreateShaderState;
|
||||
gMGPipeRouteEscapes.SetProgramBindings = &Mono_Escape_SetProgramBindings;
|
||||
|
||||
// KEPT, not merely installed. The client arm overwrites the three tables above; these
|
||||
// three copies are what it forwards to when it finds itself on the server's own thread.
|
||||
|
||||
@@ -144,6 +144,16 @@ namespace MobileGL::MG_Pipe {
|
||||
// `EncodeProgramArtifacts` on the monolith path, which `PipeApply.h`
|
||||
// explicitly promises it is not ("zero serialisation cost on the
|
||||
// monolith path").
|
||||
// SetProgramBindings THREE tails in three index spaces plus a PARALLEL NAME ARRAY
|
||||
// (P5e, MG_Remote/CONTRACT-P5E.md §1/§5.5). One `varTail` +
|
||||
// `varTailCount` pair cannot express three runs at all, and the
|
||||
// fourth argument is not a run: the storage-override key is a
|
||||
// `MGHostSpan` on the wire and a plain `const char*` under monolith,
|
||||
// so the applier takes the resolved names beside the tail rather
|
||||
// than resolving segments itself (rule C - a span retires with the
|
||||
// record that named it, and the applier copies the bytes it keeps).
|
||||
// The generated `gMGPipeContext.SetProgramBindings` row therefore
|
||||
// STAYS NULL, which is what PipeCatalogueTest already pins.
|
||||
//
|
||||
// OVERTURN CONDITIONS, one per row: give `MGPResourceDesc` and `MGPFlushRange` a blobref
|
||||
// (overturns R-13.2/R-13.3, and c0 owns `MGPipeTypes.h`); give `MGPHandleOnly` a size
|
||||
@@ -154,9 +164,19 @@ namespace MobileGL::MG_Pipe {
|
||||
const MGPRespecifiedLevel* level);
|
||||
void (*ResourceFlushRange)(const MGPFlushRange* record, const void* bytes);
|
||||
void* (*MapPersistent)(const MGPHandleOnly* handle, Uint64 size, const void* seedBytes);
|
||||
// P5e (pg) grew this row by the STAGE LIST, and it belongs on the route rather than in
|
||||
// the two structs: `SpirvArtifacts::generatedSpirv` is one module per shader object and
|
||||
// the stage of each lives in `ProgramObject::m_linkedShaderSnapshot`, which is GL-thread
|
||||
// state and not an artifact. The client arm frames it in front of the archive; the
|
||||
// monolith arm ignores it, because its twin reads the snapshot directly.
|
||||
void (*CreateShaderState)(const MGPProgramDesc* desc,
|
||||
const MG_State::GLState::LinkArtifacts* link,
|
||||
const MG_State::GLState::SpirvArtifacts* spirv);
|
||||
const MG_State::GLState::SpirvArtifacts* spirv,
|
||||
const Uint32* linkedStages, Uint32 linkedStageCount);
|
||||
void (*SetProgramBindings)(const MGPProgramBindings* hdr, const Int32* blockBindings,
|
||||
const MGPProgramSamplerUnit* samplerUnits,
|
||||
const MGPProgramStorageOverride* storageOverrides,
|
||||
const char* const* storageOverrideNames);
|
||||
};
|
||||
inline MGPipeRouteEscapes gMGPipeRouteEscapes{};
|
||||
|
||||
@@ -267,12 +287,41 @@ namespace MobileGL::MG_Pipe {
|
||||
}
|
||||
|
||||
// ---- resources ---------------------------------------------------------------------
|
||||
|
||||
// P5e (ra), CONTRACT-P5E §2.5 / ruling 15 (ID-93): DOES THIS SUB-DATA RECORD WANT ITS
|
||||
// ANSWER? One predicate, two callers - this route and the wire emit table - because the
|
||||
// route cannot pass a flag through the thunk (the call table's signature is the
|
||||
// catalogue's) and two hand-written copies of "is this the buffer half" is exactly the
|
||||
// drift that would make the client wait for an answer the emitter told the server not to
|
||||
// bother with, or read a slot that was never posted.
|
||||
//
|
||||
// THE BUFFER HALF DOES NOT: its Bool is discarded at the only call site there is
|
||||
// (MGPipeEmitResourceSubData), and because the row carries kReplySlot the client used to
|
||||
// wait for it anyway - one full round trip per 64 KB persistent-map block, whose answer
|
||||
// nobody looked at. THE TEXTURE HALF DOES: DrainTextureSubData clears the level's dirty
|
||||
// flag on an ACCEPTED reply, so its answer is load-bearing (D-D5; making that half
|
||||
// fire-and-forget is a trailing item, not this package's).
|
||||
//
|
||||
// The test is MGPSubData::Target == kMGPipeResourceTargetBuffer, whole field, which is the
|
||||
// invariant MGPipeTypes.h asserts beside the packer and which the applier's own
|
||||
// SubDataNamesABuffer already reads.
|
||||
inline Bool MGPipeSubDataWantsItsReply(const MGPSubData& record) {
|
||||
return record.Target != kMGPipeResourceTargetBuffer;
|
||||
}
|
||||
|
||||
inline Bool MGPipeRouteResourceSubData(const MGPSubData& record, const void* bytes,
|
||||
Uint64 byteCount,
|
||||
const MGPSubRegion* regions = nullptr) {
|
||||
// THE SLOT IS STILL MINTED AND STILL TAKEN, even for the buffer half. The row keeps
|
||||
// kReplySlot on the wire, the server still posts, and the mailbox's "every minted slot
|
||||
// is taken" rule is what the next row's ReplyOverrun Fatal is looking for - so the
|
||||
// half that does not WAIT still has to collect. What changes is that under run-ahead
|
||||
// the emit table publishes and returns, and the answer it collects is the emitter's
|
||||
// accept-by-construction rather than the server's.
|
||||
MGPReplySlot reply = MGPipeMintReplySlot();
|
||||
MGP_ResourceSubData(&record, bytes, byteCount, regions, record.RegionCount, &reply);
|
||||
return MGPipeTakeReplyBool(reply, "resource_subdata");
|
||||
const Bool accepted = MGPipeTakeReplyBool(reply, "resource_subdata");
|
||||
return MGPipeSubDataWantsItsReply(record) ? accepted : true;
|
||||
}
|
||||
inline void MGPipeRouteBufferSubDataResident(const MGPSubData& record, const void* bytes,
|
||||
Uint64 byteCount) {
|
||||
@@ -381,11 +430,24 @@ namespace MobileGL::MG_Pipe {
|
||||
MGP_SetShaderImages(&hdr, tail, hdr.Count);
|
||||
}
|
||||
|
||||
// ---- indexed buffer binding points (P5e, sb) ----------------------------------------
|
||||
//
|
||||
// ONE ROUTE FOR THREE RECORDS: the class is a FIELD, not an opcode, so Uniform,
|
||||
// ShaderStorage and AtomicCounter all come through here and the applier keys on hdr.Class.
|
||||
// The second var-tail (MGHostSpan[HostSpanCount], D-B8) is never present on Espryt -
|
||||
// kCapNeedsHostUboBytes is 0 for the whole of P5 - so this wrapper states one tail, and the
|
||||
// codec's honesty pass is the guard that says so out loud if a backend ever asks for the
|
||||
// other one.
|
||||
inline void MGPipeRouteSetShaderBuffers(const MGPShaderBuffers& hdr, const MGPBufferRange* tail) {
|
||||
MGP_SetShaderBuffers(&hdr, tail, hdr.Count);
|
||||
}
|
||||
|
||||
// ---- programs ----------------------------------------------------------------------
|
||||
inline void MGPipeRouteCreateShaderState(const MGPProgramDesc& desc,
|
||||
const MG_State::GLState::LinkArtifacts* link,
|
||||
const MG_State::GLState::SpirvArtifacts* spirv) {
|
||||
gMGPipeRouteEscapes.CreateShaderState(&desc, link, spirv);
|
||||
const MG_State::GLState::SpirvArtifacts* spirv,
|
||||
const Uint32* linkedStages, Uint32 linkedStageCount) {
|
||||
gMGPipeRouteEscapes.CreateShaderState(&desc, link, spirv, linkedStages, linkedStageCount);
|
||||
}
|
||||
inline void MGPipeRouteBindShaderState(const MGPHandleOnly& handle) {
|
||||
MGP_BindShaderState(&handle);
|
||||
@@ -403,6 +465,18 @@ namespace MobileGL::MG_Pipe {
|
||||
Uint64 byteCount) {
|
||||
MGP_SetGlobalConstants(&record, bytes, byteCount);
|
||||
}
|
||||
// P5e (pg), opcode 80. The fifth escape; see MGPipeRouteEscapes above for why this row has
|
||||
// no generated shape. `storageOverrideNames` is index-aligned with `storageOverrides` and
|
||||
// is what the applier copies into the record - the MGHostSpan inside each override element
|
||||
// describes where the name lives on the WIRE and is resolved by the decoder, never here.
|
||||
inline void MGPipeRouteSetProgramBindings(const MGPProgramBindings& hdr,
|
||||
const Int32* blockBindings,
|
||||
const MGPProgramSamplerUnit* samplerUnits,
|
||||
const MGPProgramStorageOverride* storageOverrides,
|
||||
const char* const* storageOverrideNames) {
|
||||
gMGPipeRouteEscapes.SetProgramBindings(&hdr, blockBindings, samplerUnits, storageOverrides,
|
||||
storageOverrideNames);
|
||||
}
|
||||
|
||||
} // namespace MobileGL::MG_Pipe
|
||||
|
||||
|
||||
@@ -106,9 +106,9 @@ inline constexpr const char* kMGPipeFieldRetiringPhase[kMGPipeInputFieldCount] =
|
||||
"-", // GetBlendEquationIndexed
|
||||
"-", // GetBlendFuncIndexed
|
||||
"-", // GetBoundTransformFeedbackName
|
||||
"P8", // GetBoundVertexArray
|
||||
"P5e (Espryt unbarriered), P7 (Magma)", // GetBoundVertexArray
|
||||
"P8 (indirect), P9 (readback), P13 (transfer)", // GetBufferBindingSlot
|
||||
"P3b/P4b, P7", // GetBufferBindingPoint
|
||||
"P5e (Espryt unbarriered), P7 (Magma)", // GetBufferBindingPoint
|
||||
"P7/P13", // GetBufferBindingPointCount
|
||||
"-", // GetTouchedBufferBindingPointCount
|
||||
"-", // GetClampReadColor
|
||||
@@ -121,8 +121,8 @@ inline constexpr const char* kMGPipeFieldRetiringPhase[kMGPipeInputFieldCount] =
|
||||
"-", // GetDepthFunc
|
||||
"-", // GetDepthMask
|
||||
"-", // GetDepthRangeIndexed
|
||||
"P3b/P4b (Espryt), P7 (Magma)", // GetFramebufferBindingSlot
|
||||
"P3b/P4b, P7", // GetImageTextureBinding
|
||||
"P5e (Espryt unbarriered), P7 (Magma)", // GetFramebufferBindingSlot
|
||||
"P5e (Espryt unbarriered), P7 (Magma)", // GetImageTextureBinding
|
||||
"-", // GetLineWidth
|
||||
"-", // GetLogicOp
|
||||
"-", // GetMaxTouchedTextureUnit
|
||||
@@ -136,8 +136,8 @@ inline constexpr const char* kMGPipeFieldRetiringPhase[kMGPipeInputFieldCount] =
|
||||
"-", // GetPolygonOffsetFactor
|
||||
"-", // GetPolygonOffsetUnits
|
||||
"-", // GetPrimitiveRestartIndex
|
||||
"P7 (Magma), P8 (Espryt)", // GetProgramForDispatch
|
||||
"P8 (Espryt), P7 (Magma)", // GetProgramForDraw
|
||||
"P5e (Espryt unbarriered), P7 (Magma)", // GetProgramForDispatch
|
||||
"P5e (Espryt unbarriered), P7 (Magma)", // GetProgramForDraw
|
||||
"P9", // GetProgramObject
|
||||
"-", // GetProvokingVertexMode
|
||||
"-", // GetRenderStateParameters
|
||||
@@ -148,7 +148,7 @@ inline constexpr const char* kMGPipeFieldRetiringPhase[kMGPipeInputFieldCount] =
|
||||
"-", // GetTextureBindGeneration
|
||||
"-", // GetTextureContextId
|
||||
"P7", // GetTextureObject
|
||||
"P3b/P4b, P7", // GetTextureUnitObject
|
||||
"P5e (Espryt unbarriered), P7 (Magma)", // GetTextureUnitObject
|
||||
"-", // GetTransformFeedbackCapturedVertices
|
||||
"-", // GetTransformFeedbackGeneration
|
||||
"-", // GetTransformFeedbackPausedPrimitiveCounter
|
||||
|
||||
@@ -315,6 +315,7 @@ enum class MGPipeFieldEmitter : Uint8 {
|
||||
SetFramebufferState,
|
||||
SetPatchState,
|
||||
SetSamplerViews,
|
||||
SetShaderBuffers,
|
||||
SetShaderImages,
|
||||
SetVertexAttribDefaults,
|
||||
};
|
||||
@@ -331,6 +332,7 @@ inline constexpr const char* kMGPipeFieldEmitterNames[] = {
|
||||
"SetFramebufferState",
|
||||
"SetPatchState",
|
||||
"SetSamplerViews",
|
||||
"SetShaderBuffers",
|
||||
"SetShaderImages",
|
||||
"SetVertexAttribDefaults",
|
||||
};
|
||||
@@ -343,7 +345,7 @@ inline constexpr MGPipeFieldEmitter kMGPipeFieldEmittedBy[kMGPipeInputFieldCount
|
||||
MGPipeFieldEmitter::kNone, // GetBoundTransformFeedbackName
|
||||
MGPipeFieldEmitter::BindVertexElements, // GetBoundVertexArray
|
||||
MGPipeFieldEmitter::kNone, // GetBufferBindingSlot
|
||||
MGPipeFieldEmitter::kNone, // GetBufferBindingPoint
|
||||
MGPipeFieldEmitter::SetShaderBuffers, // GetBufferBindingPoint
|
||||
MGPipeFieldEmitter::kNone, // GetBufferBindingPointCount
|
||||
MGPipeFieldEmitter::SetContextValues, // GetTouchedBufferBindingPointCount
|
||||
MGPipeFieldEmitter::SetDynamicState, // GetClampReadColor
|
||||
@@ -400,7 +402,7 @@ inline constexpr MGPipeFieldEmitter kMGPipeFieldEmittedBy[kMGPipeInputFieldCount
|
||||
MGPipeFieldEmitter::SetContextValues, // GetBoundTransformFeedbackLifetimeId
|
||||
MGPipeFieldEmitter::kNone, // HasOpenTransformFeedbackSpan
|
||||
};
|
||||
inline constexpr SizeT kMGPipeEmittedFieldCount = 47;
|
||||
inline constexpr SizeT kMGPipeEmittedFieldCount = 48;
|
||||
|
||||
struct MGPipeFilledState {
|
||||
Uint64 CurrentVerbSerial;
|
||||
|
||||
@@ -29,7 +29,7 @@ struct MGPipeScreen {
|
||||
void (*ApplierReset)(const MGPApplierReset* payload);
|
||||
};
|
||||
|
||||
// context: 67 calls. A null entry means the backend does not implement this
|
||||
// context: 68 calls. A null entry means the backend does not implement this
|
||||
// call and the frontend keeps its own path (plan B section 4.1).
|
||||
struct MGPipeContext {
|
||||
void (*QueryCreate)(const MGPQueryDesc* payload);
|
||||
@@ -99,11 +99,12 @@ struct MGPipeContext {
|
||||
void (*CopyFramebufferToTexture)(const MGPCopyFromFramebuffer* payload);
|
||||
void (*ObjectDeath)(const MGPHandleOnly* payload);
|
||||
void (*SetContextValues)(const MGPContextValues* payload);
|
||||
void (*SetProgramBindings)(const MGPProgramBindings* payload, const void* varTail, Uint32 varTailCount);
|
||||
};
|
||||
|
||||
inline constexpr SizeT kMGPipeScreenCallCount = 12;
|
||||
inline constexpr SizeT kMGPipeContextCallCount = 67;
|
||||
inline constexpr SizeT kMGPipeCallCount = 79;
|
||||
inline constexpr SizeT kMGPipeContextCallCount = 68;
|
||||
inline constexpr SizeT kMGPipeCallCount = 80;
|
||||
|
||||
// A table that is not exactly its call count of function pointers has grown a
|
||||
// member that no generator knows about.
|
||||
|
||||
@@ -332,3 +332,7 @@ inline void MGP_ObjectDeath(const MGPHandleOnly* payload) {
|
||||
inline void MGP_SetContextValues(const MGPContextValues* payload) {
|
||||
gMGPipeContext.SetContextValues(payload);
|
||||
}
|
||||
|
||||
inline void MGP_SetProgramBindings(const MGPProgramBindings* payload, const void* varTail, Uint32 varTailCount) {
|
||||
gMGPipeContext.SetProgramBindings(payload, varTail, varTailCount);
|
||||
}
|
||||
|
||||
@@ -114,6 +114,9 @@ inline Bool MGPipeVerify(const MGPStorageBlockBinding& a, const MGPStorageBlockB
|
||||
inline Bool MGPipeVerify(const MGPCopyFromFramebuffer& a, const MGPCopyFromFramebuffer& b, const char** outField);
|
||||
inline Bool MGPipeVerify(const MGPApplierReset& a, const MGPApplierReset& b, const char** outField);
|
||||
inline Bool MGPipeVerify(const MGPContextValues& a, const MGPContextValues& b, const char** outField);
|
||||
inline Bool MGPipeVerify(const MGPProgramBindings& a, const MGPProgramBindings& b, const char** outField);
|
||||
inline Bool MGPipeVerify(const MGPProgramSamplerUnit& a, const MGPProgramSamplerUnit& b, const char** outField);
|
||||
inline Bool MGPipeVerify(const MGPProgramStorageOverride& a, const MGPProgramStorageOverride& b, const char** outField);
|
||||
inline Bool MGPipeVerify(const RenderStateParameters& a, const RenderStateParameters& b, const char** outField);
|
||||
inline Bool MGPipeVerify(const PixelStoreParameters& a, const PixelStoreParameters& b, const char** outField);
|
||||
inline Bool MGPipeVerify(const SamplerParameters& a, const SamplerParameters& b, const char** outField);
|
||||
@@ -265,6 +268,12 @@ struct MGPipeHasFieldVerifier<MGPApplierReset> : std::true_type {};
|
||||
template <>
|
||||
struct MGPipeHasFieldVerifier<MGPContextValues> : std::true_type {};
|
||||
template <>
|
||||
struct MGPipeHasFieldVerifier<MGPProgramBindings> : std::true_type {};
|
||||
template <>
|
||||
struct MGPipeHasFieldVerifier<MGPProgramSamplerUnit> : std::true_type {};
|
||||
template <>
|
||||
struct MGPipeHasFieldVerifier<MGPProgramStorageOverride> : std::true_type {};
|
||||
template <>
|
||||
struct MGPipeHasFieldVerifier<RenderStateParameters> : std::true_type {};
|
||||
template <>
|
||||
struct MGPipeHasFieldVerifier<PixelStoreParameters> : std::true_type {};
|
||||
@@ -678,6 +687,21 @@ inline Bool MGPipeVerify(const MGPContextValues& a, const MGPContextValues& b, c
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Bool MGPipeVerify(const MGPProgramBindings& a, const MGPProgramBindings& b, const char** outField) {
|
||||
MGP_FIELDS_MGPProgramBindings(MGP_VERIFY_FIELD)
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Bool MGPipeVerify(const MGPProgramSamplerUnit& a, const MGPProgramSamplerUnit& b, const char** outField) {
|
||||
MGP_FIELDS_MGPProgramSamplerUnit(MGP_VERIFY_FIELD)
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Bool MGPipeVerify(const MGPProgramStorageOverride& a, const MGPProgramStorageOverride& b, const char** outField) {
|
||||
MGP_FIELDS_MGPProgramStorageOverride(MGP_VERIFY_FIELD)
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Bool MGPipeVerify(const RenderStateParameters& a, const RenderStateParameters& b, const char** outField) {
|
||||
MGP_FIELDS_RenderStateParameters(MGP_VERIFY_FIELD)
|
||||
return true;
|
||||
@@ -725,4 +749,4 @@ inline Bool MGPipeVerify(const MGPVertexBindingPointWire& a, const MGPVertexBind
|
||||
|
||||
#undef MGP_VERIFY_FIELD
|
||||
|
||||
inline constexpr SizeT kMGPipeVerifiedPayloadCount = 79;
|
||||
inline constexpr SizeT kMGPipeVerifiedPayloadCount = 82;
|
||||
|
||||
@@ -149,7 +149,8 @@ enum class MGPWireOp : Uint16 {
|
||||
ApplierReset = 77,
|
||||
ObjectDeath = 78,
|
||||
SetContextValues = 79,
|
||||
kOpCount = 80,
|
||||
SetProgramBindings = 80,
|
||||
kOpCount = 81,
|
||||
};
|
||||
|
||||
// THE FLAGS, EXPORTED ONCE, INDEXED BY OPCODE (P5 R-13.4). MGPWireRecHeader::Flags is
|
||||
@@ -250,6 +251,7 @@ inline constexpr Uint32 kMGPipeCallFlags[static_cast<SizeT>(MGPWireOp::kOpCount)
|
||||
/* 77 ApplierReset */ static_cast<Uint32>(kNone),
|
||||
/* 78 ObjectDeath */ static_cast<Uint32>(kNone),
|
||||
/* 79 SetContextValues */ static_cast<Uint32>(kNone),
|
||||
/* 80 SetProgramBindings */ static_cast<Uint32>(kVarTail | kHostSpan),
|
||||
};
|
||||
static_assert(sizeof(kMGPipeCallFlags) / sizeof(kMGPipeCallFlags[0]) ==
|
||||
static_cast<SizeT>(MGPWireOp::kOpCount),
|
||||
@@ -349,6 +351,7 @@ inline constexpr Uint8 kMGPipeCallClasses[static_cast<SizeT>(MGPWireOp::kOpCount
|
||||
/* 77 ApplierReset */ static_cast<Uint8>(kScreen),
|
||||
/* 78 ObjectDeath */ static_cast<Uint8>(kCtxObject),
|
||||
/* 79 SetContextValues */ static_cast<Uint8>(kCtxState),
|
||||
/* 80 SetProgramBindings */ static_cast<Uint8>(kCtxState),
|
||||
};
|
||||
static_assert(sizeof(kMGPipeCallClasses) / sizeof(kMGPipeCallClasses[0]) ==
|
||||
static_cast<SizeT>(MGPWireOp::kOpCount),
|
||||
@@ -361,6 +364,126 @@ inline constexpr MGPipeCallClass MGPipeCallClassFor(MGPWireOp op) {
|
||||
: kCallClassCount;
|
||||
}
|
||||
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md 2.2): THE WAIT CLASS OF EVERY OPCODE, indexed the same way.
|
||||
// Index 0 is kWaitClassCount - never a real class - for the flags table's reason: the one
|
||||
// caller that can pass an opcode this catalogue never produced is a decoder holding bytes off
|
||||
// a stream, and it must reach its own Fatal{ProtocolCorruption} rather than a wait decision.
|
||||
//
|
||||
// This is the STATIC HALF of MGPipeBarriered(op, payload, applierState), the predicate the emit
|
||||
// table and the sink compute identically. The other half is payload-derived (an open
|
||||
// transform-feedback span, a draw carrying client vertex arrays) and lives in that function,
|
||||
// because it depends on state a table indexed by opcode cannot see.
|
||||
inline constexpr Uint8 kMGPipeWaitClasses[static_cast<SizeT>(MGPWireOp::kOpCount)] = {
|
||||
/* 0 */ static_cast<Uint8>(kWaitClassCount),
|
||||
|
||||
/* 1 GetCaps */ static_cast<Uint8>(kWaitReply),
|
||||
/* 2 ResourceCreate */ static_cast<Uint8>(kWaitReply),
|
||||
/* 3 ResourceRespecify */ static_cast<Uint8>(kWaitReply),
|
||||
/* 4 ResourceDestroy */ static_cast<Uint8>(kWaitNone),
|
||||
/* 5 MapPersistent */ static_cast<Uint8>(kWaitReply),
|
||||
/* 6 UnmapPersistent */ static_cast<Uint8>(kWaitNone),
|
||||
/* 7 FenceCreate */ static_cast<Uint8>(kWaitNone),
|
||||
/* 8 FenceStatus */ static_cast<Uint8>(kWaitReply),
|
||||
/* 9 FenceWait */ static_cast<Uint8>(kWaitReply),
|
||||
/* 10 FenceDestroy */ static_cast<Uint8>(kWaitNone),
|
||||
/* 11 QueryCreate */ static_cast<Uint8>(kWaitNone),
|
||||
/* 12 QueryBegin */ static_cast<Uint8>(kWaitNone),
|
||||
/* 13 QueryEnd */ static_cast<Uint8>(kWaitNone),
|
||||
/* 14 QueryAvailable */ static_cast<Uint8>(kWaitReply),
|
||||
/* 15 QueryResult */ static_cast<Uint8>(kWaitReply),
|
||||
/* 16 QueryDestroy */ static_cast<Uint8>(kWaitNone),
|
||||
/* 17 CreateRenderState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 18 BindRenderState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 19 DeleteRenderState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 20 CreateVertexElements */ static_cast<Uint8>(kWaitNone),
|
||||
/* 21 BindVertexElements */ static_cast<Uint8>(kWaitNone),
|
||||
/* 22 DeleteVertexElements */ static_cast<Uint8>(kWaitNone),
|
||||
/* 23 CreateSamplerState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 24 DeleteSamplerState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 25 CreateSamplerView */ static_cast<Uint8>(kWaitNone),
|
||||
/* 26 DeleteSamplerView */ static_cast<Uint8>(kWaitNone),
|
||||
/* 27 CreateShaderState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 28 BindShaderState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 29 DeleteShaderState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 30 SetDynamicState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 31 SetFramebufferState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 32 SetVertexBuffers */ static_cast<Uint8>(kWaitNone),
|
||||
/* 33 SetIndexBuffer */ static_cast<Uint8>(kWaitNone),
|
||||
/* 34 SetIndirectBuffers */ static_cast<Uint8>(kWaitNone),
|
||||
/* 35 SetSamplerViews */ static_cast<Uint8>(kWaitNone),
|
||||
/* 36 BindSamplerStates */ static_cast<Uint8>(kWaitNone),
|
||||
/* 37 SetShaderImages */ static_cast<Uint8>(kWaitNone),
|
||||
/* 38 SetShaderBuffers */ static_cast<Uint8>(kWaitNone),
|
||||
/* 39 SetStreamOutputTargets */ static_cast<Uint8>(kWaitNone),
|
||||
/* 40 SetGlobalConstants */ static_cast<Uint8>(kWaitNone),
|
||||
/* 41 SetVertexAttribDefaults */ static_cast<Uint8>(kWaitNone),
|
||||
/* 42 SetPixelPackState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 43 SetPatchState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 44 SetDrawProgram */ static_cast<Uint8>(kWaitNone),
|
||||
/* 45 SetDispatchProgram */ static_cast<Uint8>(kWaitNone),
|
||||
/* 46 SetResidualValueState */ static_cast<Uint8>(kWaitNone),
|
||||
/* 47 SetTextureParams */ static_cast<Uint8>(kWaitReply),
|
||||
/* 48 ResourceSubData */ static_cast<Uint8>(kWaitReply),
|
||||
/* 49 BufferSubDataResident */ static_cast<Uint8>(kWaitNone),
|
||||
/* 50 ResourceSubDataComplete */ static_cast<Uint8>(kWaitNone),
|
||||
/* 51 ResourceFlushRange */ static_cast<Uint8>(kWaitNone),
|
||||
/* 52 ResourceReadback */ static_cast<Uint8>(kWaitReply),
|
||||
/* 53 ResourceCopyRegion */ static_cast<Uint8>(kWaitNone),
|
||||
/* 54 GenerateMipmap */ static_cast<Uint8>(kWaitApplied),
|
||||
/* 55 GetTextureImage */ static_cast<Uint8>(kWaitReply),
|
||||
/* 56 Blit */ static_cast<Uint8>(kWaitNone),
|
||||
/* 57 Clear */ static_cast<Uint8>(kWaitNone),
|
||||
/* 58 ReadPixels */ static_cast<Uint8>(kWaitReply),
|
||||
/* 59 DrawVbo */ static_cast<Uint8>(kWaitNone),
|
||||
/* 60 LaunchGrid */ static_cast<Uint8>(kWaitNone),
|
||||
/* 61 MemoryBarrier */ static_cast<Uint8>(kWaitNone),
|
||||
/* 62 BeginStreamOutput */ static_cast<Uint8>(kWaitApplied),
|
||||
/* 63 EndStreamOutput */ static_cast<Uint8>(kWaitApplied),
|
||||
/* 64 PauseStreamOutput */ static_cast<Uint8>(kWaitApplied),
|
||||
/* 65 ResumeStreamOutput */ static_cast<Uint8>(kWaitApplied),
|
||||
/* 66 Flush */ static_cast<Uint8>(kWaitNone),
|
||||
/* 67 Present */ static_cast<Uint8>(kWaitPresent),
|
||||
/* 68 SetSwapInterval */ static_cast<Uint8>(kWaitNone),
|
||||
/* 69 QueryTimestamp */ static_cast<Uint8>(kWaitReply),
|
||||
/* 70 QueryCounter */ static_cast<Uint8>(kWaitNone),
|
||||
/* 71 FenceWaitServer */ static_cast<Uint8>(kWaitNone),
|
||||
/* 72 BindShaderImage */ static_cast<Uint8>(kWaitNone),
|
||||
/* 73 PatchParameter */ static_cast<Uint8>(kWaitNone),
|
||||
/* 74 BindStreamOutput */ static_cast<Uint8>(kWaitApplied),
|
||||
/* 75 SetStorageBlockBinding */ static_cast<Uint8>(kWaitApplied),
|
||||
/* 76 CopyFramebufferToTexture*/ static_cast<Uint8>(kWaitApplied),
|
||||
/* 77 ApplierReset */ static_cast<Uint8>(kWaitApplied),
|
||||
/* 78 ObjectDeath */ static_cast<Uint8>(kWaitNone),
|
||||
/* 79 SetContextValues */ static_cast<Uint8>(kWaitNone),
|
||||
/* 80 SetProgramBindings */ static_cast<Uint8>(kWaitNone),
|
||||
};
|
||||
static_assert(sizeof(kMGPipeWaitClasses) / sizeof(kMGPipeWaitClasses[0]) ==
|
||||
static_cast<SizeT>(MGPWireOp::kOpCount),
|
||||
"the wait-class table and the opcode space disagree");
|
||||
|
||||
inline constexpr MGPipeWaitClass MGPipeWaitClassFor(MGPWireOp op) {
|
||||
const SizeT index = static_cast<SizeT>(op);
|
||||
return index < static_cast<SizeT>(MGPWireOp::kOpCount)
|
||||
? static_cast<MGPipeWaitClass>(kMGPipeWaitClasses[index])
|
||||
: kWaitClassCount;
|
||||
}
|
||||
|
||||
// THE COLUMN'S OWN INVARIANT, stated in C++ as well as in the generator: a reply-slot row
|
||||
// waits for its reply and a waiting row owns a slot. gen_pipe.py refuses a catalogue where the
|
||||
// two disagree, and this is the same statement where a reader of the generated table will look
|
||||
// for it - a kReplySlot row that did not wait would run on and read a slot nobody had posted
|
||||
// into, and a kWaitReply row with no slot would block on an answer nobody posts.
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::kInvalid) == kWaitClassCount,
|
||||
"opcode 0 is not a call and has no wait class");
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::Present) == kWaitPresent,
|
||||
"present is paced by the credit, not by a wait after the publish");
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::DrawVbo) == kWaitNone,
|
||||
"the steady draw path is what P5e exists to stop waiting on");
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::ApplierReset) == kWaitApplied,
|
||||
"a make-current is a fresh server and every verb after it must see the reset");
|
||||
static_assert(MGPipeWaitClassFor(MGPWireOp::ReadPixels) == kWaitReply,
|
||||
"a readback's answer is not derivable (R-5)");
|
||||
|
||||
// Spot checks the generator states about its own output, so that a catalogue edit that
|
||||
// silently drops a flag is a build break here and not a wrong decode six packages away.
|
||||
static_assert(MGPipeCallFlagsFor(MGPWireOp::kInvalid) == static_cast<Uint32>(kNone),
|
||||
@@ -1031,6 +1154,14 @@ static_assert(sizeof(MGPWireRec_SetContextValues) ==
|
||||
((sizeof(MGPWireRecHeader) + sizeof(MGPContextValues) + 7u) & ~SizeT(7u)),
|
||||
"MGPWireRec_SetContextValues gained padding; the wire format moved");
|
||||
|
||||
struct alignas(8) MGPWireRec_SetProgramBindings {
|
||||
MGPWireRecHeader Header;
|
||||
MGPProgramBindings Payload;
|
||||
};
|
||||
static_assert(sizeof(MGPWireRec_SetProgramBindings) ==
|
||||
((sizeof(MGPWireRecHeader) + sizeof(MGPProgramBindings) + 7u) & ~SizeT(7u)),
|
||||
"MGPWireRec_SetProgramBindings gained padding; the wire format moved");
|
||||
|
||||
[[noreturn]] inline void MGPipeWireProtocolFatal(const char* call, Uint64 size, Uint64 remaining) {
|
||||
MGLOG_F("MGPipe: protocol corruption applying %s: size=%llu remaining=%llu", call,
|
||||
static_cast<unsigned long long>(size), static_cast<unsigned long long>(remaining));
|
||||
@@ -1317,6 +1448,9 @@ inline Bool MGPipeApplyWireRecord(MGPWireOp op, const void* record, Uint64 size,
|
||||
case MGPWireOp::SetContextValues:
|
||||
MGP_WIRE_CHECK_BOUNDS(MGPWireRec_SetContextValues, "SetContextValues");
|
||||
break;
|
||||
case MGPWireOp::SetProgramBindings:
|
||||
MGP_WIRE_CHECK_BOUNDS(MGPWireRec_SetProgramBindings, "SetProgramBindings");
|
||||
break;
|
||||
case MGPWireOp::kInvalid:
|
||||
case MGPWireOp::kOpCount:
|
||||
default:
|
||||
|
||||
@@ -352,7 +352,7 @@ make-current and teardown do to it — the column `ARCHITECTURE.md` does not hav
|
||||
|
||||
1. client publishes and waits for the server to drain and acknowledge;
|
||||
2. **`Doorbell::Kill()`** — *the only thing that can wake an apply thread parked on
|
||||
`kWaitForever`* (`Doorbell.h:211-221`; the shape is already pinned by
|
||||
`kWaitForever`* (`CondVarDoorbell::Kill` in `Doorbell.h`; the shape is already pinned by
|
||||
`InProcessTransportTest.cpp:344`);
|
||||
3. **join**, bounded (that test uses 5 s) so a regression is a red test and not a hung CI job;
|
||||
4. only then may the client free anything an emitter owns — a tail still referenced by an
|
||||
|
||||
@@ -0,0 +1,566 @@
|
||||
# CONTRACT-P5E — the client runs ahead of apply on the Espryt draw path
|
||||
|
||||
Authority: this file, beside `CONTRACT-P5.md` (table 0, byte carriers, field ownership, R-1…R-17),
|
||||
`CONTRACT-P5B.md` (the class-C slots) and `CONTRACT-P5C.md` (rule E, the two named exemptions,
|
||||
SEG_EVENT, the guards). Where it disagrees with any of them this file is newer and wins; §8 lists
|
||||
every such place. Base: `feat/disaggregated @ 2fde7034` (code head `1f8de61b`). Every `file:line`
|
||||
was read at that commit and re-resolved at c0e's head; paths are under `MobileGL/` unless they
|
||||
start with `docs/`.
|
||||
|
||||
**How to change it.** Package c0e's file, edited by the integrator first. A P5e package (id / vi /
|
||||
sb / pg / tx2 / fb / ra) that needs a row changed goes through the integrator; the packages compile
|
||||
against the rows below from day one.
|
||||
|
||||
**What c0e actually landed, where it differs from the plan this file was written as.** Four places,
|
||||
each argued where it sits: `MGPProgramDesc` GREW 192 → 200 bytes because it has no spare byte (§1);
|
||||
the applier's per-class binding-point windows are spelled `ShaderBufferStart/Count/WritableMask`
|
||||
rather than bare `Start/Count/WritableMask` (§5.6); the suppressor's three slots are named
|
||||
`SetShaderBuffersUniform/ShaderStorage/AtomicCounter` (§1); and the wire codec's record layout now
|
||||
carries THREE tails rather than two, because `set_program_bindings` has three (§1). Everything else
|
||||
below is the plan as written, and the nineteen rulings of §9 are as the integrator decided them
|
||||
(ID-80…98).
|
||||
|
||||
---
|
||||
|
||||
## §0 What P5e is, and the rule above every row
|
||||
|
||||
P5d made `inproc` CPU-bound on the client thread with the frame still `client work + (per draw)
|
||||
wait for apply + handoff` (R-1, `MG_Remote/Client/ClientSession.cpp:932-959`). The wait exists
|
||||
because the apply of a draw still dereferences client-owned memory: the object-class BARRIER_PULLED
|
||||
rows of `MG_Pipe/FieldOwnership.def:72-106` and the frontend-keyed twin registries
|
||||
(`MG_Backend/DirectGLES/SlotTables.h:411-449`) inside the two P5C §3.1 exemption scopes. **P5e
|
||||
retires the lockstep for every op on the Espryt draw path: the client publishes and moves on; the
|
||||
server resolves every object from a handle a record carried, and the only client memory it may read
|
||||
is the residual fill of a record the client is provably blocked behind.**
|
||||
|
||||
Rules A–E bind unchanged. P5e adds one definition and one rule:
|
||||
|
||||
**Definition — a BARRIERED record.** A record is barriered iff `MGPipeBarriered(op, payload,
|
||||
applierState)` is true, a pure function of wire-visible data computed identically by the emit
|
||||
table and by the sink (§2.1). The client blocks in `WaitForApplied(seq)` after publishing a
|
||||
barriered record; it never blocks after an unbarriered one.
|
||||
|
||||
**Rule F — an unbarriered record's apply names no client memory.** With a live wire on a
|
||||
run-ahead server (§6), the apply of an unbarriered record reads NOTHING from client-owned memory:
|
||||
no frontend object dereference, no `gPipeInputs` BARRIER_PULLED row, no `MGPipeSlots()` probe or
|
||||
mint, no `SharedPtr` to a frontend object taken or held. Every object is resolved from a handle the
|
||||
record or the applier state carries, through a handle-keyed twin table (§4). A violation is
|
||||
`Fatal{UnmigratedPipeInput, "<field>@<verb>"}` (a pulled row, §3.3), `Fatal{RoleViolation,
|
||||
"MGPipeSlots"}` (an allocator probe, §4.4) or `Fatal{RoleViolation, "<surface>"}` (P5C §6 layer 1),
|
||||
**regardless of `MOBILEGL_IPC_STRICT_ERRORS`** — the value would be torn or stale by construction,
|
||||
so there is no "count it" arm. A barriered record's apply keeps P5C's rules exactly: its pulls count
|
||||
into `rsp`, its probes are legal inside a scope, and the client's wait is what makes them legal.
|
||||
|
||||
Refusal vocabulary is P5C's, plus: `Fatal{UnmigratedVerb, "DrawArrays+CLIENT_ARRAYS"}` (§5.1),
|
||||
`Fatal{UnmigratedVerb, "set_global_constants"}` (§5.5), `Fatal{UnmigratedEmulation,
|
||||
"image-bindable-redirty"}` (§5.2), `Fatal{ProtocolCorruption, "SetSamplerViews.Count"}` /
|
||||
`"BindSamplerStates.Count"` / `"SetShaderBuffers.Class"` / `"SetShaderBuffers.Count"` /
|
||||
`"SetProgramBindings.<field>"` / `"Present.FrameSerial"` / `"ImageView.Access"` (§1, §5),
|
||||
`Fatal{PresentCreditTimeout}` (§2.4), `Fatal{RoleViolation, "gPipeInputs"}` (§3.5).
|
||||
`Fatal{EventRingOverflow}` is RETIRED on a run-ahead server (§2.6).
|
||||
|
||||
---
|
||||
|
||||
## §1 Table 0 additions — encodings the P5e rows introduce
|
||||
|
||||
| field | the ruling | zero means | who reads it |
|
||||
|---|---|---|---|
|
||||
| **`MGPCapBit::kCapRunAheadApply = 1ull << 10`** (`MGPipeTypes.h`, bits 0..9 used) | Set in the DirectGLES arm of the server's `CallMask` (`MG_Backend/Init.cpp`), NEVER in the DirectVulkan arm. THE ARM IS A PURE FUNCTION, `MGPipeRunAheadCapBitsFor(backendType, ready)` in `MGPipeTypes.h`, so "Magma never" is a unit case (`MG_Test/Pipe/MagmaPipeIdentityTest.cpp`) rather than a line only a live split session reaches; `ready` is `MG_Backend/Init.cpp`'s `kMGPipeP5eRunAheadReady`. It says "this server applies unbarriered records without reading client memory". The client latches `RunAheadArmed()` = `m_barrierArmed && Ipc.RunAhead && Caps().HasCap(kCapRunAheadApply)` at the first caps adoption after `Start`; a later snapshot may only turn it OFF. | absent = lockstep (Magma; and Espryt until the integration commit flips `kMGPipeP5eRunAheadReady`, §6.2) | `ClientSession::RunAheadArmed`, `MGPipeBarriered` on both sides |
|
||||
| **`MGPipeWaitClass`** — a FIFTH column of `PipeCalls.def`'s X-macro (`MGPipe.h`'s enum, spelled as a bare token like the class column), generated beside `kMGPipeCallFlags` into `generated/PipeWire.inc` as `MGPipeWaitClassFor(op)` | `kWaitReply` (every `kReplySlot` row), `kWaitPresent` (`Present`), `kWaitApplied` (the static barriered rows of §2.2), `kWaitNone` (everything else). Opcode order and the flag column are untouched: the column is a value, not a new op. `gen_pipe.py` refuses a token that is not an `MGPipeWaitClass` enumerator AND a row where the flag column and this one disagree in either direction — a `kReplySlot` row that did not wait is a waiter that hangs, a `kWaitReply` row with no slot blocks on an answer nobody posts. Three negative controls in `--self-test` (twelve now, up from nine). | — | `EmitAndWaitTails`, `ServerVerbSink::ApplyOne`, `MGPipeBarriered` |
|
||||
| **`MGPDrawInfo::Flags` gains `kDrawClientArrays`** = `1u << 6`, the next free bit beside `kDrawIsIndirect` (`MGPipeTypes.h`'s `MGPDrawFlagBit`; `MGPDrawInfo` stays 56 bytes, the flag byte had two bits left) | Set by the client emit arm when any ENABLED attribute of the bound VAO has no buffer. §2.1 escalation (ii). `PipeCatalogueTest` pins the bit's value and its disjointness from the five before it. | no client array in this draw | `MGPipeBarriered`; `EmitDrawRecord`'s refusal (§5.1) |
|
||||
| **`MGPPresent::FrameSerial`** | Minted by the CLIENT, `++m_presentsSent`, 1-based — no longer 0 (`EmitTables.cpp:1040`). The sink calls `ServerSession::ReturnPresentCredit(FrameSerial)` after `table->Present()` returns (today `ReturnPresentCredit` has no production caller, `ServerSession.cpp:677-682`), one credit per swap. | 0 arriving on a run-ahead server is `Fatal{ProtocolCorruption, "Present.FrameSerial"}` | `OnPresent`, `WaitForPresentAck` |
|
||||
| **`MGPShaderBuffers` + `MGPBufferRange[]`** (`MGPipeTypes.h`, wire op 38, catalogued since P4a, no route/sink/emitter today) | One record per **Class** ∈ {Uniform=0, ShaderStorage=1, AtomicCounter=2} — the three values are `kMGPipeShaderBufferClassUniform/ShaderStorage/AtomicCounter` in `MGPipeTypes.h`, which is the ONLY spelling of them: the payload's comment had named them since P4a and nothing numbered them, so the emitter and the applier were one literal each away from disagreeing. `Start = 0` always; `Count = TouchedBufferBindingPointCount[target]` (the rv value already carried) clamped to `kMGPipeMaxBufferBindingPoints = 84` (pinned against `BufferState.h:29` in `PipeFill.cpp`); per entry `Res` = the buffer handle or null, `Offset/Size` from the point's range, **`Size = kMGPipeWholeBuffer` (`MGPipeTypes.h:406`) for a base binding** so the server re-resolves the extent against ITS descriptor at use (a `glBufferData` between emit and apply then binds the new extent, as GL does); `WritableMask` bit per entry for classes 1/2. `HostSpanCount = 0` on Espryt for the whole of P5e (`kCapNeedsHostUboBytes` is 0, `CONTRACT-P5.md:64`); the codec's honesty pass (`PipeWireCodec.cpp:1783-1799`) is the guard. `Class >= 3` → `Fatal{ProtocolCorruption, "SetShaderBuffers.Class"}`; `Start + Count > 84` → `"SetShaderBuffers.Count"`. XFB targets do NOT ride this record (`set_stream_output_targets` keeps its row, still unemitted: XFB stays lockstep, §5.7). | `Res` null = nothing bound at that point | `MGPipeApplySetShaderBuffers`, `SyncBufferBindingPointsByRecord`, the UBO loop, `SyncAtomicCounterBuffers` |
|
||||
| **`set_program_bindings` — opcode 80, appended.** `X(SetProgramBindings, MGPProgramBindings, kCtxState, kVarTail\|kHostSpan, kWaitNone)` | Head `MGPProgramBindings { MGPipeHandle Cso; Uint64 Signature; Uint32 BlockBindingCount, SamplerUnitCount, StorageOverrideCount, Pad0; }` (32 B, `MGP_ASSERT_POD`); three tails in order: `Int32 BlockBindings[BlockBindingCount]` (dense, GL uniform-block index order), `MGPProgramSamplerUnit {Uint32 Location; Int32 Unit;}[SamplerUnitCount]` (8 B, sparse, ascending Location), `MGPProgramStorageOverride {MGHostSpan Name; Int32 Binding; Uint32 Pad0;}[StorageOverrideCount]` (40 B; the storage-block override map is name-keyed BY DESIGN, `ProgramObject.h:1030-1034`; the name travels as a host span staged whole). `Signature` = the client's commutative hash of the override map, the same function as `Managers.cpp:10832-10841`, so the server's rebuild clause is one `Uint64` compare. Bounds: `kMGPipeMaxProgramBlockBindings` 64, `kMGPipeMaxProgramSamplerUnits` 256, `kMGPipeMaxProgramStorageOverrides` 64, else `Fatal{ProtocolCorruption, "SetProgramBindings.<field>"}` — a larger sampler array is a counted refusal, not a truncation. **THE RECORD ALWAYS DECLARES THREE TAILS**, empty ones included: the tails are positional and the third one's offset is derived from the first two, so a record that declared "one tail" when only the block bindings were present would put the same bytes at a different offset than one that declared three, and the two halves of the wire would disagree about where the overrides start. The wire codec's `WireRecordLayout` grew from two tails to three for it (`MG_Remote/Wire/PipeWireCodec.h`), and the override names are walked through `CheckHostSpanIsHonest` in the decode arm rather than by the encoder's blanket second-tail pass — they are MEMBERS of a 40-byte element, and reading that tail as bare spans would see one span and a quarter of garbage. Emitted BEFORE `create_shader_state` at the same validate point (a rebuild inside the verb must already see the bindings). Dirty rule: bit `NewShaderBindings` (`Tracker.h:364-371, 419-448`) already mixes the three counters; the emitter latches on `(Cso, backendStateVersion, blockBindingVersion)`. A re-issued create clears the record's tails (`GlobalConstants`' rule, `PipeApply.cpp:2903-2909`). | all three counts 0 = "defaults" | `MGPipeApplySetProgramBindings`, the program twin's sync and memo keys |
|
||||
| **`MGPProgramDesc::LinkStatus`** (a `Uint8`; **the descriptor grows 192 → 200**, `PipeCatalogueTest` pins the new size) | **THE DRAFT SAID "in the descriptor's existing pad, size unchanged" AND THAT WAS WRONG.** `MGPProgramDesc`'s four trailing `Uint8`s end at offset 24 and `MGPBlobRef` is 8-aligned, so the fixed head is exactly full and a fifth byte costs the alignment slack behind it: 20 bytes of handle and counters + 5 bytes of flags, padded to 32, plus 168 of blob refs. It is paid once, on a record that fires at most once per link, and it is confined to the push build — this payload is only ever instantiated under `MOBILEGL_PIPE_PUSH` (`PipeApply.cpp`, `PipeRoute.cpp` and the emitters are all push-only sources), which is why G1 does not see it. 1 = the link the archive describes succeeded. `create_shader_state` is re-issued on the same handle at every link that changes `GetLinkVersion` (today's rule) and the record's `Serial` moves with it; a failed link re-issues with `LinkStatus = 0` and empty blobs IFF the frontend reports the program unlinked afterwards (§9 ruling 9 pins which). A draw on a `LinkStatus == 0` program DECLINES on the server, as the frontend raises `INVALID_OPERATION`. | not linked | the program twin (`SyncCurrentProgram`) |
|
||||
| **`MGPProgramDesc::Spirv[6]` / `Reflection` blobs are NON-EMPTY** on a live wire | The client encodes the link artefacts once per link with `ProgramArtifactsCodec` into `SEG_STAGE`; the applier decodes into RECORD-OWNED `LinkArtifacts`/`SpirvArtifacts` and the companion pointers (`ProgramEmit.h:230-260`) are deleted under a transport. `Size 0` with no companion is the existing trip wire `Fatal{ProtocolCorruption}` (`PipeApply.cpp:2858-2871`). A `SharedPtr` pin of the client's artefacts was considered and REFUSED: rule B, and `Link()` replaces them in place (`ProgramObject.cpp:348-356`). | — | the program twin's rebuild |
|
||||
| **`MGPImageView::Access`** | 0 = `GL_READ_ONLY`, 1 = `GL_WRITE_ONLY`, 2 = `GL_READ_WRITE` — the encoding `MGPipeEncodeImageAccess` already writes (`MG_Impl/Pipe/ImageEmit.h`). The NUMBERS move to `MG_Pipe/MGPipeValueTypes.h` as `enum class MGPipeImageAccess : Uint8` with `MGPipeDecodeImageAccess` / `MGPipeImageAccessIsValid` / `MGPipeImageAccessReads` / `MGPipeImageAccessWrites` beside them, and the client encode NAMES those enumerators instead of literal 0/1/2 — one table, both roles, moved rather than duplicated. The encode also stops being a private static so the unit case can reach both halves. The server comment at `DirectGLES.cpp:2662-2669` is deleted as stale (fb). Any other value is `Fatal{ProtocolCorruption, "ImageView.Access"}` AT THE READER: the value header may not log, so it answers the question and the caller owns the refusal. | read-only | `SyncImageTextureBinding` |
|
||||
| **`kMGPipeSubsystemBufferBindings = 1ull << 13`** (`MG_Pipe/MGPipe.h`, bits 14..62 now reserved) | Owns dirty bits 15/16/17 (`NewConstBuffers/NewShaderBuffers/NewSoTargets`, `Tracker.h:97-99`) and the `SetShaderBuffers` emitter. Caps-required under a transport like bits 7–12; the default push mask becomes `kMGPipeSubsystemsMigratedAtP5e` = `0x3fff`, and `0x1fff` survives as P5e's "everything P4a had and nothing of mine" control. Bit 13 requires bit 7 (a range names a Buffer handle). `NewSoTargets` rides the bit even though `set_stream_output_targets` stays unemitted for the whole of P5e: the bit answers "which A/B switch owns this family's legacy arm", and an operator clearing it has to get the whole binding-point family's frontend walk back rather than two thirds of it. `TrackerTest.cpp` is rewritten, not deleted, and now also pins that the phase constant is the WHOLE dirty-bit set — after P5e every bit names a subsystem. | bit clear = the frontend walk (monolith / A/B only) | `MGPipeSubsystemForDirty`, `SubsystemForEmitter` |
|
||||
| **`SetHashSuppressor` slots** (`MG_Impl/Pipe/SetHashSuppressor.h`) | `SetShaderBuffers` becomes THREE slots (`SetShaderBuffersUniform` / `SetShaderBuffersShaderStorage` / `SetShaderBuffersAtomicCounter`) — one per Class, so an emission of one class never cancels another's; `SetProgramBindings` gets one. `SetStreamOutputTargets` stays "P4b" (unemitted). | — | the emitters |
|
||||
| **`IpcTable::RunAhead`** = `MOBILEGL_IPC_RUN_AHEAD` (default 1, range 0..1); **`IpcTable::PresentCredit`** = `MOBILEGL_IPC_PRESENT_CREDIT` (default **1**, range 1..8) | Parsed unconditionally like every IPC knob (`ConfigLoader.cpp:356-403`), and both are in the IPC log line, because a knob that silently means nothing on one arm of an A/B is how an A/B stops being one. `PipeVerify` forces `RunAhead = 0` beside `BatchWaits = 0`. `RunAhead=1` on a server without the caps bit logs once "run-ahead requested, server does not publish kCapRunAheadApply" and runs lockstep. The stats line gains `credit-waits`. | `RunAhead=0` is the A/B control: identical server code, only the client's wait differs | `RunAheadArmed`, `EmitPresent` |
|
||||
| **`BufferState` bind-point generations** (client-only, `#if MOBILEGL_PIPE_PUSH`) | One `Uint64` per `BufferBindPointTargets` entry beside `NoteBufferChanged` (`BufferState.h:69-75`), bumped by `glBindBufferBase/Range` (`GL_Buffer.cpp:1501-1520, 1624-1650`) and `SetNamedTransformFeedbackBinding`. Not a wire field; listed because it is the emit rule's input and the pull build's object must not resize (the licence `TextureState::NoteImageUnitTouched` took at P5d r3). | — | bits 15/16/17's shutters |
|
||||
|
||||
---
|
||||
|
||||
## §2 ra — the wait rule
|
||||
|
||||
### 2.1 The barriered predicate (one function, two callers)
|
||||
|
||||
```
|
||||
MGPipeBarriered(op, payload, st) =
|
||||
MGPipeWaitClassFor(op) != kWaitNone // static column, §2.2
|
||||
|| (MGPipeCallClassFor(op) == kCtxVerb && st.IsTransformFeedbackActive) // (i) XFB stays lockstep
|
||||
|| (op == DrawVbo && (payload.Flags & kDrawClientArrays)) // (ii) client arrays
|
||||
```
|
||||
`st.IsTransformFeedbackActive` is `MGPContextValues`' value (`MGPipeTypes.h:1698`): on the client
|
||||
it is `ctx.IsTransformFeedbackActive()` at emit, on the server the applied value — `set_context_values`
|
||||
precedes the verb on the ring, so the two agree. **c0e LANDED THE FUNCTION, all three clauses, in
|
||||
`MG_Pipe/PipeApply.cpp`**, and gave `MGPipeApplierState` its own `IsTransformFeedbackActive` mirror
|
||||
written by `MGPipeApplySetContextValues`: the predicate has to be computable on the server from
|
||||
APPLIER state, and `gPipeInputs` is the block a run-ahead client stops filling, so reading the
|
||||
answer out of there would be reading the very memory rule F exists to stop it reading. `payload`
|
||||
may be null, which makes clause 3 fall through — a caller holding an opcode but not yet the bytes
|
||||
must not be told a draw is unbarriered on that account. Escalation (ii) is a refusal under run-ahead
|
||||
(§5.1), so on a run-ahead server it never reaches the sink; it is listed so the predicate is total.
|
||||
**No other runtime escalation exists**; adding one is an integrator ruling and a row here.
|
||||
|
||||
### 2.2 The static column, row by row
|
||||
|
||||
| class | rows | why |
|
||||
|---|---|---|
|
||||
| `kWaitReply` | every `kReplySlot` row (`PipeCalls.def:115-202, 206, 221`): GetCaps, ResourceCreate/Respecify, MapPersistent, FenceStatus/Wait, QueryAvailable/Result/Timestamp, SetTextureParams, ResourceSubData (texture half, §2.5), ResourceReadback, GetTextureImage, ReadPixels | the answer is not derivable (R-5) |
|
||||
| `kWaitPresent` | `Present` | the credit, §2.4 |
|
||||
| `kWaitApplied` | `ApplierReset`; `GenerateMipmap` (`kCtxObject`, waits today for the reason at `ClientSession.cpp:900-914` — until tx2 lands its `VerbMipRes` arm, then `kWaitNone`); `SetStorageBlockBinding` (`kCtxVerb`, resolves through `GetProgramObject(GlName)`, `PipeApplier.cpp:805-808`; trailing: pg resolves through `MGPStorageBlockBinding::ShaderCso` and flips it); `BeginStreamOutput`, `EndStreamOutput`, `PauseStreamOutput`, `ResumeStreamOutput`, `BindStreamOutput` (§5.7); `CopyFramebufferToTexture` (the CopyTex endpoint still syncs the frontend texture, `DirectGLES.cpp:9714-9735`; trailing, tx2) | each still pulls a row or probes; the wait keeps P5C's semantics for it |
|
||||
| `kWaitNone` | `DrawVbo`, `LaunchGrid`, `Clear`, `Blit`, `MemoryBarrier`, `Flush`, `SetSwapInterval`, `BindShaderImage`, `PatchParameter`; every `kCtxState` / `kCtxCso` / `kCtxObject` row without a reply (incl. `ObjectDeath`, `ResourceSubData` buffer half); `ResourceDestroy`, `UnmapPersistent`, `FenceCreate/Destroy`, `FenceWaitServer`; `QueryCreate/Begin/End/Destroy/Counter` | rule F holds for their sinks after §4/§5 |
|
||||
|
||||
The column is inert until the integration commit publishes the caps bit (§6.2), after vi/sb/pg/tx2/fb.
|
||||
|
||||
### 2.3 `EmitAndWaitTails` after `PublishAndNotify` (`ClientSession.cpp:877`)
|
||||
|
||||
```
|
||||
if (ownsReplySlot) -> WaitForAppliedBudget + DrainEventRing + ReadReply (unchanged)
|
||||
else if (RunAheadArmed())
|
||||
switch (class) kWaitNone: return seq;
|
||||
kWaitApplied: WaitForAppliedBudget + DrainEventRing + ReleaseFillPins(); return seq;
|
||||
kWaitPresent: return seq; // the credit wait ran BEFORE encode, §2.4
|
||||
else -> today's :915-959 shape, byte for byte (lockstep, Magma, verify)
|
||||
```
|
||||
`ReleaseFillPins()` clears the four O-class `SharedPtr` rows of `gPipeInputs` (`PipeInputs.h:801-809`)
|
||||
on the GL thread once the barriered apply returned — under run-ahead the next fill may be a frame
|
||||
away and a pinned VAO/program must not make the apply thread its last owner. `VerbBarrier==0`
|
||||
keeps its lockstep meaning (nothing but reply rows waits); under run-ahead it removes the
|
||||
`kWaitApplied` waits too and is the run-ahead NEGATIVE CONTROL: expected red is
|
||||
`Fatal{UnmigratedPipeInput, ...}` at the first barriered row's stale pull.
|
||||
|
||||
### 2.4 Present pacing
|
||||
|
||||
`EmitPresent` (`EmitTables.cpp:977-1053`): `BeforeReadOnlyVerb(); if (m_presentsSent >= PresentCredit)
|
||||
WaitForPresentAck(m_presentsSent + 1 - PresentCredit, 30 s)` — `ShutDown` returns, `TimedOut` is
|
||||
`Fatal{PresentCreditTimeout}`; then `DrainEventRing`, encode, publish, `PumpControlPlane`. Credit 1
|
||||
= the client publishes frame N+1 while the server applies and swaps frame N: one frame of overlap,
|
||||
at most one frame of added latency. Budget at ~850 draws + ~0.36 MB pmap/frame: SEG_CMD ~70 KB +
|
||||
set/CSO records per frame against 8 MiB, SEG_STAGE ~1 MB/frame against 32 MiB, SEG_REPLY unchanged.
|
||||
The credit, never the bytes, is the steady-state backpressure; `WaitForCmdSpace` and the stage bell
|
||||
(`PipeWireCodec.cpp:836`) are the safety net and both drain events on exit (§2.6).
|
||||
|
||||
### 2.5 Drains and forced waits
|
||||
|
||||
Drain points: every wait exit in `ClientSession` (reply, applied, present-ack, cmd-space, stage
|
||||
bell), the four EGL RPC returns (`BackendObject_Remote.cpp:200-245`), `Stop`. Forced waits:
|
||||
`MapBuffer(READ)` / `GetBufferSubData` / a `CopyBufferSubData` source → `SyncGpuWrites` (reply
|
||||
row, unchanged); `glFinish` → `WaitForApplied(LastPublishedSeq)` + drain (a new client `Finish`
|
||||
slot; `Flush`/`Finish` stay no-ops on the wire, ARCHITECTURE:415); every `Server*` EGL forwarder
|
||||
waits `WaitForApplied(LastPublishedSeq)` BEFORE the RPC (the mailbox is pumped between drain
|
||||
batches, `ServerLoop.cpp:385-390`, so a make-current would otherwise land between two run-ahead
|
||||
records); `ServerSwapEGLBuffers` is not on that list — present is the swap. **`glGetError`
|
||||
relaxation:** a run-ahead verb's `kEventGlError` is observed at the next drain point, i.e. at most
|
||||
one present credit later than the call after it; P5C §4.2 already assigns ordering to P9 and P5e
|
||||
names the window. **`resource_subdata`:** the BUFFER half passes `wantReply = false` through
|
||||
`MGPipeRouteResourceSubData` (the Bool is discarded today, `PipeFill.cpp:839`; the server still
|
||||
posts, the slot is never read — legal, `ReplySlot.h:16, 105`), which is what makes the persistent-map
|
||||
push (`PersistentMapTracker.cpp:735, 850`) fire-and-forget; the TEXTURE half keeps its wait because
|
||||
`DrainTextureSubData` clears the level's dirty flag on the accepted reply (D-D5; trailing).
|
||||
|
||||
### 2.6 Event-ring flow control (ARCHITECTURE §11.7 made real)
|
||||
|
||||
On a run-ahead server `Reserve == nullptr` is NOT `Fatal{EventRingOverflow}`: the producer latches
|
||||
`eventRingFull` (exists, `EventRing.h:135-143`), publishes, rings, and `ApplyThreadMain` parks at
|
||||
the record boundary with `eventRingFull == 0` added to `ready` (`ServerLoop.cpp:380-383`). The
|
||||
client re-checks `m_events.RingIsFull()` at every park exit and drains before re-parking. Deadlock
|
||||
argument: the server blocks only on the event ring; the client blocks only on watermarks the
|
||||
server advances; every client wait drains; so at most one side is parked at any instant. The
|
||||
lockstep arm keeps the Fatal (P5C §4.4).
|
||||
|
||||
### 2.7 Object lifetime under run-ahead
|
||||
|
||||
The client frees a slot only after its death record went out (`PipeFill.cpp:1623-1626`), the ring
|
||||
is in order, every record naming `{s,g}` precedes `destroy{s,g}` which precedes `create{s,g+1}`,
|
||||
and every server twin table Gen-checks (§4.3). **No wait is added at any delete.** Persistent maps:
|
||||
`Forget()` (`PersistentMapTracker.cpp:599-606`) drops tracker state only; pushed bytes were copied
|
||||
into SEG_STAGE at `StageOptional` and reclaim waits on `retiredSeq`, so a map released with blocks
|
||||
in flight is safe. The P5d deferred-destroy queue (`PipeMutation.h:216-236`) STAYS LIVE: a
|
||||
barriered record's apply may still pin a frontend object (its fill's `SharedPtr` rows, XFB
|
||||
`targets`), so the apply thread can still be a last owner. Under `RunAheadArmed` an enqueue from an
|
||||
UNBARRIERED apply is a finding: `MGLOG_E_ONCE` with the kind, Fatal under strict.
|
||||
|
||||
---
|
||||
|
||||
## §3 `gPipeInputs` — server-role memory for unbarriered records
|
||||
|
||||
1. **The client fills only for barriered records.** In `MGPipeValidateForVerb`
|
||||
(`PipeFill.cpp:2962-3306`), when `RunAheadArmed()` and `!MGPipeBarriered(...)`: step 2 (tracker
|
||||
walk) and step 3 (emitters) run unchanged; `:2989` (`++CurrentVerbSerial`), `:2999-3001`
|
||||
(`SetVerb/SetIdentity`), step 4 (`:3252-3270`, `CopyField` + `FilledGen`) and `MGPipeLeaveVerb`'s
|
||||
writes are SKIPPED; `MGPipeNoteFrontendMutation` returns at `:554`. The residual-value trip
|
||||
wire (`:3284-3294`) still emits — it compares on the server against the applier mirror.
|
||||
`RunAhead=0` on a caps-publishing server uses the SAME fill decision (the A/B changes one
|
||||
variable: the wait). `PipeVerify` forces lockstep, a fill for every verb, and every record
|
||||
barriered (both roles read the in-process flag; the comparator `:3304` is inproc-only).
|
||||
2. **The server's stamp is server-private.** `MGPipeServerStampVerbBoundary` writes
|
||||
`m_filled/m_currentVerb/m_serverStampedVerb` into applier-owned storage, never into the shared
|
||||
block; `MGPipeServerClearVerbBoundary()` from the GL thread (`:2997`) is DELETED under a
|
||||
transport. For a barriered record the server reads the client's fill (the client is parked) and
|
||||
its own stamp; for an unbarriered one it does not touch the block. `SetIdentity` (`:3001`) moves
|
||||
to `ApplyOne`, once per session. This removes the E note's hazard (b.4).
|
||||
3. **The detector.** `MGPipeInputUnfreshRead` (`PipeInputs.cpp:191-224`) under an unbarriered
|
||||
record takes `StrictBarrierPullFatal` (`:60-66`) regardless of `StrictErrors`; the seven sticky
|
||||
forwards (`MGPipeStickyForwardPull`, `:251-257`) the same; `CountBarrierPull` stays for barriered
|
||||
records. This is what turns `integration-split-strict` into a hard green lane (§7).
|
||||
4. `VertexAttribDefaultsOf` (`PipeFill.cpp:84-86`) diffs against the emitter's own last header
|
||||
(`g_attribDefaultLastHeader`, `:2949`), never against the block.
|
||||
5. `RefusePipeInputsTouchWhileApplierOwnsIt` (`ClientSession.cpp:1015-1056`) is re-derived: the
|
||||
`BatchWaits` early return at `:1037` goes; under `RunAheadArmed` any GL-thread write to the block
|
||||
outside a barriered fill is `Fatal{RoleViolation, "gPipeInputs"}` by name.
|
||||
`Fatal{BarrierViolation}` (`:840`) stays for `BatchWaits==0 && !RunAhead`.
|
||||
|
||||
---
|
||||
|
||||
## §4 id — handle-keyed twins
|
||||
|
||||
### 4.1 The rule
|
||||
With a live wire, every twin on the apply thread is resolved BY THE HANDLE the applier state or
|
||||
the record carries, never by a frontend object: `GetOrCreate(MGPipeHandle)` (`SlotTables.h:294-342`),
|
||||
`FindByHandle` (`:420-426`), `ReleaseByHandle` (`:394-408`). `HandleOf(stateObj)`,
|
||||
`Find(StateObject*)`, `GetOrCreate(const StatePtr&)`, `NoteStateForHandle/StateForHandle` and
|
||||
`Entry::stateRef` survive as the MONOLITH-GLUE half (§5.8) and are unreachable from an
|
||||
unbarriered apply. The twin sync bodies take `(MGPipeHandle, const <Record>&)` and store
|
||||
`m_handle` (the `m_pushedSyncHandle` pattern, `Managers.h:1857`); the object parameter is deleted
|
||||
from the transport overload, not defaulted to null. The E note's "content-addressed VAO CSO" is
|
||||
corrected: every kind mints its slot off the object's own lifetime id (`VertexInputEmit.h:170-172`,
|
||||
`TextureEmit.h:422`, `FramebufferEmit.h:257`, `ProgramEmit.h:411-422`), so the rekey is a
|
||||
replacement of the lookup ARGUMENT, not of the table.
|
||||
|
||||
### 4.2 Per kind
|
||||
| kind / table | key on the server | the record that names the handle before any verb reads it | twin created | twin dies |
|
||||
|---|---|---|---|---|
|
||||
| Buffer `g_backendBufferResources` (already handle-keyed) | `Res` from `VertexBuffers[]`, `IndexBuffer`, `BoundShaderBuffers[c][i]`, `Desc.BufferForTexBuffer`, `VerbIndirect*` | `resource_create/respecify` | `EnsureBufferResourceForHandle(nullptr, h)` | `resource_destroy` |
|
||||
| VAO `g_backendVertexArrayObjects` | `st.BoundVertexElements` (`PipeApply.h:594`; one CSO per VAO, re-created on the same handle when the config moves) | `create/bind_vertex_elements` | first `ResolveVaoTwin(handle)` at a draw | `object_death{VertexElementsCso}` / `delete_vertex_elements` |
|
||||
| Texture `g_backendTextureObjects` | `BoundSamplerViews[u].Texture`, `BoundShaderImages[u].Res`, `FramebufferRecords[h].State.{Color[i],Depth,Stencil}.Res`, `VerbMipRes`, `VerbCopyTexDst`, `MGPCopyImage` src/dst | `resource_create/respecify` (Texture) | first `SyncTextureToBackendByHandle(h)` | `object_death{Texture}` / `resource_destroy` |
|
||||
| Renderbuffer `g_backendRenderbufferObjects` | `MGPSurface.Res` with `Kind == Renderbuffer` | `resource_create/respecify` (Renderbuffer) | first attach sync | `object_death{Renderbuffer}` |
|
||||
| Framebuffer `g_backendFramebufferObjects` | `st.BoundFramebuffer[t]`, `record.Fbo`, `VerbBlitReadFbo/DrawFbo`; `kMGPipeDefaultFramebuffer` is never a twin | `set_framebuffer_state` | `GetOrCreateByHandle(record.Fbo)` (already, `DirectGLES.cpp:3197`) | `object_death{Framebuffer}` |
|
||||
| Program `g_backendProgramObjects` | `st.DrawProgram` / `DispatchProgram` / `BoundShaderCso`; composites at the band | `create_shader_state` (+ `set_program_bindings`) | first `SyncCurrentProgram(handle)` | `object_death{ShaderCso}` / `delete_shader_state` |
|
||||
| Sampler `g_backendSamplerObjects` | the CSO family ONLY: `st.BoundSamplerStates[u]` or `TextureResources[h].Params.BuiltinSampler` | `create_sampler_state` | `ResolveSamplerCsoTwin` (already, `Managers.cpp:13457-13486`) | `object_death{SamplerCso}` |
|
||||
| SamplerView `g_backendSamplerViews` | `BoundSamplerViews[u].View` (no draw-path resolver today; unchanged) | `create_sampler_view` | — | `object_death{SamplerViewCso}` |
|
||||
|
||||
The identity family of samplers (`ResolveUnitSamplerBackend` `DirectGLES.cpp:4985-5026`, the mint
|
||||
at `:5623-5630`, `Managers.cpp:13264-13280`) is deleted under a transport; a unit whose
|
||||
`BoundSamplerStates[u]` is null while the frontend held a sampler is a missing record and §5.3's
|
||||
window rule makes it unrepresentable. The creation moment is LAZY everywhere (no twin at
|
||||
`create_*`); the applier's Gen check refuses a bind or verb naming an unknown or stale handle
|
||||
(`PipeApply.cpp:2266, 2549, 2625, 2683, 2896`), so a twin is never minted for an object the ring has
|
||||
not introduced. `applier_reset` touches neither twins nor object records (`PipeApply.h:800-832`).
|
||||
|
||||
### 4.3 ABA
|
||||
`Gen` moves only on reuse (`SlotAllocator.cpp:176-189`, and `:240-258` for the composite band —
|
||||
"the one place Gen may move", in the file's own words). At the server every record naming `{s,g}`
|
||||
is applied before `object_death{s,g}`, which is applied before `create{s,g+1}`. `GetOrCreate({s,g+1})`
|
||||
on a live `{s,g}` entry resets it (`SlotTables.h:338`); `FindByHandle({s,g})` after the recycle
|
||||
answers null (`:424`); a backward `{s,g-1}` is refused (`:331`). Even with a death skipped (an
|
||||
object that never crossed emits none, `WireTables.cpp:595-596`) the forward-Gen reset answers.
|
||||
Twin memos key on `{slot,gen}` plus server serials, never on a pointer. `BackendSlotTable` gains
|
||||
the composite band (`m_band`, indexed `slot - base`, as `SlotAllocator.h:144` / `PipeApply.h:511`)
|
||||
so a pipeline program (slot >= 983040) does not grow the ordinary table to `kMaxHandleSlot` entries
|
||||
— a P5e prerequisite, not a follow-up, because the rekey makes it the ordinary path.
|
||||
|
||||
### 4.4 The scopes and the guard
|
||||
`MGPipeRefuseAllocatorFromApplyThread` (`SlotAllocator.cpp:22-38`) exempts a probe iff a scope is
|
||||
active AND `MGPipeApplierCurrentRecordIsBarriered()` (server-private, set by `ApplyOne` from
|
||||
§2.1; `true` for every record on a non-run-ahead server, §6). **c0e landed the storage and the
|
||||
writer** (`MGPipeApplierSetCurrentRecordBarriered`, `MG_Pipe/PipeApply.cpp`) with `true` as the
|
||||
default — the only seam in this phase whose body is implemented rather than aborting, because
|
||||
there the safe answer and the landed lockstep answer are the same answer, and an abort would take
|
||||
down the monolith and the lockstep split alike. id owns the `ApplyOne` call site. **`MGPipeFrontendKeyedRegistryScope`
|
||||
is deleted at its draw-path sites** — `DirectGLES.cpp:1609, 1734, 2588, 3303, 4236, 4329, 4585, 4926,
|
||||
4993, 5328, 5689, 6729, 6775, 9695` and `Managers.cpp:256, 2938 (draw-path callers), 4544, 5882,
|
||||
7087, 8481, 8717, 9256, 9310, 9709, 12949, 13273, 13570` — with the frontend probes they wrap; the
|
||||
class survives only around the barriered-row sites (`DirectGLES.cpp:6166, 8837, 9161, 9216, 10029,
|
||||
11884`, the verify arms `Managers.cpp:10382, 10403`) with their P8/P9 phases re-annotated.
|
||||
`MGPipeReverseAnnouncementScope` is renamed `MagmaP7AllocatorDebtScope`, compiled for the Magma
|
||||
sites only (`VulkanRenderer.cpp:4554, 4634, 8986`, `ResourceTracker.h:723`), exempting only when
|
||||
the server backend is DirectVulkan. The renderbuffer cross-check `Managers.cpp:9709-9720` (not
|
||||
transport-gated today, unlike `:9628-9632`) is deleted by the rekey, not gated. The NoSession
|
||||
server-only fixture hop (`Managers.cpp:224-246`) is deleted; such a fixture's twins die at Stop.
|
||||
|
||||
---
|
||||
|
||||
## §5 Per family — the clean gate, the records, the windows
|
||||
|
||||
### 5.1 VAO / vertex input / index (vi)
|
||||
Twin from `st.BoundVertexElements`; memo key `{BoundVertexElements, rec->ContentSerial,
|
||||
VertexBuffersSerial, IndexBufferSerial}` (all server-owned); the buffer walk is over
|
||||
`st.VertexBuffers[Start..+Count).Res` (dedupe on `{slot,gen}`) with
|
||||
`EnsureBufferResourceForHandle(nullptr, Res)` and `IsBufferDrawCleanByHandle(h, res, nullptr)`;
|
||||
`ResolvedDrawBuffers::Entry::frontend` leaves the split arm; the IBO arm reads `st.IndexBuffer.Res`
|
||||
+ `IndexBufferSerial` (also for the restart substitution, `DirectGLES.cpp:6447-6461`);
|
||||
`SyncCurrentVertexAttributeValues` keys on `{elementsHandle, ContentSerial, activeMask}` and reads
|
||||
`rec->Attributes[i].Enabled`; the dead `GetConfigVersion` read at `:4775` is deleted. **Client-memory
|
||||
vertex arrays are NOT refused under split today** (only `CLIENT_INDICES/CLIENT_COMMANDS/
|
||||
UNBOUND_PARAMETER`, `EmitTables.cpp:651-685`; the server dereferences `attrib.Offset` as a raw
|
||||
pointer, `Managers.cpp:5382`): under `RunAheadArmed` a draw with `kDrawClientArrays` is
|
||||
`Fatal{UnmigratedVerb, "DrawArrays+CLIENT_ARRAYS"}` raised on the GL thread in `EmitDrawRecord`'s
|
||||
array arm; the lockstep arm is unchanged; the staged form (a per-attribute `{BindingIndex,
|
||||
MGHostSpan}` tail like `kDrawHasUserIndices`) is P8's. Two pins by test: `CurrentBufferMutationEpoch()`
|
||||
(`Managers.cpp:794`) is apply-thread-only under a transport; the VAO twin key is 1:1 only while the
|
||||
vertex-elements CSO stays identity-addressed.
|
||||
|
||||
### 5.2 Textures (tx2)
|
||||
Every draw-path entry is `SyncTextureToBackendByHandle(h, imageBindable)`: record first, twin by
|
||||
`GetOrCreateByHandle`, three syncs `(h, *rec)`; the by-value twin copy + second `Find`
|
||||
(`DirectGLES.cpp:1745-1755, 1781-1805`) go with the map arm. Clean = `m_isInitialized &&
|
||||
m_syncedResourceSerial == rec->Serial && rec->PendingUploads.empty() && m_syncedParamsSerial ==
|
||||
rec->ParamsSerial && !rec->Params.ForceResync && !m_forceTextureParamsResync &&
|
||||
m_syncedBuiltinSampler == rec->Params.BuiltinSampler && m_syncedBuiltinSamplerSerial ==
|
||||
SamplerCso(rec->Params.BuiltinSampler)->Serial && !rec->Params.SamplerResync && !m_forceSamplerResync
|
||||
&& rec->Desc.StorageKind == Mipmap` — no new state. The four in-body live reads (`GetTarget` at
|
||||
`Managers.cpp:8876-8877, 8620-8621`; `IsTextureView` `:7060`; the TexBuffer backing `:8223-8231`)
|
||||
read `Desc.Target / Desc.ViewOf / Desc.BufferForTexBuffer`; `GetExternalIndex` in logs becomes
|
||||
`Desc.GlNameForDiag`. The unit work list is `{Res, backend}` keyed `(ContextSerial,
|
||||
SamplerViewsSerial, SamplerViewStart, SamplerViewCount, g_backendContextGeneration)`;
|
||||
`PairingsIntact` is deleted; `ResolveAndBindUnitTextures` is one pass over the window with the
|
||||
target from `SamplerViewCsos[View].View.Target`, then an unbind of every target the window did not
|
||||
claim driven by `g_boundTexturesCache`; the alias arbiter dies (the client arbitrated,
|
||||
`SamplerEmit.h:751-757`). **Named delta (P5e-5):** the unit list syncs the program-resolved texture
|
||||
per unit, not every slot of every touched unit; coverage is unchanged (views ∪ image units ∪
|
||||
attachment lists ∪ the waited texture ops). `RequireImageBindableStorage`'s re-dirty arm
|
||||
(`Managers.cpp:5930-5962`, already aborting three frames deep) becomes a NAMED refusal at its
|
||||
entry under a transport, `Fatal{UnmigratedEmulation, "image-bindable-redirty"}`; `ImageBindableHint`
|
||||
is the prevention, P9 owns the pull. `GenerateMipmap(target)` under a transport resolves the
|
||||
texture from `VerbMipRes` (as `EnsureGenerateMipmapStorageAllocated` already does, `DirectGLES.cpp:8736`),
|
||||
never the active unit (`:9563-9566`), and its row flips to `kWaitNone`. `m_force*Resync` are
|
||||
server-set and never cleared by the wire; the wire bits are never cleared by the server (D-E2, now
|
||||
load-bearing for a gate). The pinned guard list (`MipmapStorage.cpp:39-51`, `RemoteClientTest.cpp:1938-1978`)
|
||||
gains the six shape accessors it exempts today plus `GetSamplerObject/GetTextureParamsVersion/GetContentVersion`.
|
||||
|
||||
### 5.3 Samplers and the two unit windows (tx2; the rule binds the emitters)
|
||||
The effective sampler of unit u is `st.BoundSamplerStates[u]` if non-null else
|
||||
`TextureResources[view.Texture].Params.BuiltinSampler`; its values are the CSO record's
|
||||
(`MGPipeValueTypes.h:462-486`); the raw-depth-fetch substitution stays on the server
|
||||
(ARCHITECTURE §5.5); `texture2D->GetFormat()` becomes `SamplerViewCsos[View].View.InternalFormat`.
|
||||
**Window rule (A8 closed):** `set_sampler_views` and `bind_sampler_states` MUST carry `Start == 0`
|
||||
and `Count >= MaxTouchedTextureUnit + 1` (0 when none touched), as `SamplerEmit.h:733-737` emits
|
||||
today; at every draw/dispatch apply the sink checks the two counts against the applied
|
||||
`MGPContextValues::MaxTouchedTextureUnit` and a narrower window is `Fatal{ProtocolCorruption,
|
||||
"SetSamplerViews.Count"}` / `"BindSamplerStates.Count"` — a server-side re-derivation is refused.
|
||||
The `BindCurrentTextures` memo key is `{DrawProgram.{Slot,Gen}, ShaderCso.Serial, BindingsSerial,
|
||||
SamplerViewsSerial}` (ruling 6). The decline arms `DirectGLES.cpp:5152-5169` and `:2073-2098` become
|
||||
named refusals under a live wire; `CaptureUnitBindings/UnitBindingsUnchanged/g_observedUnitBindings`
|
||||
(`:1867-1957`) are monolith-only text.
|
||||
|
||||
### 5.4 Framebuffers, attachments, images (fb)
|
||||
`SyncCurrentFBO` is `SyncCurrentFBOByRecord` only; a decline under a transport is
|
||||
`Fatal{UnmigratedPipeInput, "GetFramebufferBindingSlot@<verb>"}`; `FramebufferRecordMatchesBinding`
|
||||
(`:3017-3033`) is monolith-only. `BackendFramebufferObject::SyncToBackend(record, target)`: the
|
||||
attachment walk is over `Color[0..7] + Depth + Stencil` (`Color[0]` alone when `IsDefault`) — the
|
||||
record's 11 surfaces ARE the point set (the emitter refuses a point at or above the wire width,
|
||||
`FramebufferEmit.h:489-501`; FRONT/BACK tokens exist only on the default framebuffer); the empty
|
||||
point is `Kind == None || Res null` for the detach (`Managers.cpp:10310`) and the N-6 refusal
|
||||
(`:9601-9606`) alike; `m_syncedFrontendAttachmentVersions` is replaced by the record hash;
|
||||
`g_attachmentBackendIdGeneration` stays. `SyncAttachmentSurface(target, surface, attachment)` takes
|
||||
no object; storage through `SyncMipmapsToBackendByHandle` / RBO `SyncToBackendByHandle(surface.Res)`.
|
||||
The two attachment texture lists key `(record.Fbo, ContentHash, ContextSerial,
|
||||
g_backendContextGeneration)` with entries `{Res, backend}` and `PairingsIntact` = `entry.Res ==
|
||||
surface.Res`. `ForceBindCurrentFBO` is handle-only and stamps nothing frontend (the stamps at
|
||||
`:4734-4738` and the legacy memo are skipped together under the transport test). The named blit
|
||||
takes two `const MGPFramebufferState&` (draw buffers, `ReadSurface`, `Kind`, layer/level/layered/
|
||||
format from the surface, `Samples` from the record, `kMGPipeDefaultFramebuffer` for the default)
|
||||
and retires `StateForHandle`; the bound arm reads `FramebufferRecordFor(st.BoundFramebuffer[t])`.
|
||||
`ScopedDetachedTextureFramebufferAttachments` walks a reverse index texture → FBO slots maintained
|
||||
at `set_framebuffer_state` apply. `MGPFramebufferState::Complete` is never a "may I draw" gate.
|
||||
`SyncReadFramebufferTextureAttachments` is not gated on the framebuffer bit (`:2227-2230`), so its
|
||||
retirement moves the object A/B baseline in BOTH arms (re-baselined, not a regression).
|
||||
**Default-framebuffer resize:** the surface-changed consumer's `AllocateStorage` (`ClientSession.cpp:210-221`)
|
||||
reaches `MGP_NOTE_AGGREGATE(FramebufferAttachment)` (`TextureObject.cpp:84-102`), so bit
|
||||
`NewFramebuffer` (`Tracker.h:594`) re-emits the record — verified at this head, pinned by a test in fb.
|
||||
Images: `SyncImageTextureBinding(const MGPImageView&)`: twin by `FindByHandle(Res)`, `Access`
|
||||
decoded, target and storage format off the TWIN (no new wire field; `MGPImageView` is 24 B, no
|
||||
pad); `ResolveShaderImageRecord`'s identity test and I5 seam log go. The sweep gate is
|
||||
`(ShaderImagesSerial, TextureShutterSerial, ContextSerial, g_backendContextGeneration)` — never a
|
||||
backend re-mint counter, so the "re-minted inside the sweep" property (`:2890-2901`) holds; the walk
|
||||
stays the UNION of the record window and `g_imageUnitHighWaterMark` (`:2811-2821`), never narrowed
|
||||
to the window. `MarkWritableImageBufferTexturesGpuWritten` is DELETED under a transport (the client
|
||||
owns the GPU-write set, `GpuWritePending.h:9-55`, `:83-115`); `WritableMask` survives as the record
|
||||
of which points P9's narrowing will name.
|
||||
|
||||
### 5.5 Programs (pg)
|
||||
Twin from the ShaderCso handle; `SyncToBackend(h, const MGPipeShaderCsoRecord&)` answers every
|
||||
reflection question from the record-owned archive and the bindings tails (`GetLinkedShaderSnapshot`
|
||||
`:12049` is a debug log, deleted on this arm). The nine-clause clean condition (`DirectGLES.cpp:4437-4507`)
|
||||
keeps its clause count and moves its inputs: `record.Serial` vs `m_syncedShaderCsoSerial` (exists,
|
||||
stamped at `Managers.cpp:12944-12966`, unread today — P5e is its first reader), `BindingsSerial`,
|
||||
`record.Signature`, `Desc.SpirvStatus`, `Desc.LinkStatus`; `ImageUnitFormatsStillMatch` and the
|
||||
patch clauses are fb's / value rows. The stash `g_currentDrawFrontendProgram` (`:4097-4098`)
|
||||
becomes `{MGPipeHandle, twin*}` compared against `st.DrawProgram`; `PrepareForCompute` reads
|
||||
`st.DispatchProgram`. The sampler-pass memo (`:5522`) keys on `BindingsSerial`;
|
||||
`sampledTargetForUnit` reads the sampler-unit tail and the archive's uniform types. **`MapUBO()`
|
||||
has no run-ahead answer:** when `ResolveGlobalConstantsRecord` declines under a transport it is
|
||||
`Fatal{UnmigratedVerb, "set_global_constants"}`, not a torn upload. `GetProgramObject/
|
||||
ValidateProgramName` keep their P9 rows: `GetBackendProgramId(name)` (`:6151`) is a monolith entry;
|
||||
`ShaderStorageBlockBinding` (`:10020`) is reached from the barriered `set_storage_block_binding`
|
||||
(§2.2) until pg's trailing item resolves it by `MGPStorageBlockBinding::ShaderCso`. Codec
|
||||
completeness: `ProgramArtifactsCodec.cpp:242`'s skipped member is named and either encoded or
|
||||
proven unread by the twin before pg claims "every reflection question is answered".
|
||||
|
||||
### 5.6 Buffer binding points (sb)
|
||||
Applier: `BoundShaderBuffers[3][84]`, `ShaderBufferStart[3]` / `ShaderBufferCount[3]` /
|
||||
`ShaderBufferWritableMask[3]` (the draft said bare `Start/Count/WritableMask`; they sit in
|
||||
`MGPipeApplierState` beside `SamplerViewStart`/`SamplerViewCount` and take the same shape), ONE
|
||||
`ShaderBuffersSerial` advanced on every applied record and ADVANCED (never zeroed) by
|
||||
`MGPipeApplierReset` (`VertexBuffersSerial`'s rule, `PipeApply.h`); the emitter's latch resets with
|
||||
it (`PipeFill.cpp:3129-3143`'s list). c0e declares all of it, with
|
||||
`MGPipeApplySetShaderBuffers` declared and aborting by name until sb writes the body.
|
||||
**`WritableMask` IS A `Uint32` AND THE WINDOW IS 84** (`MGPShaderBuffers::WritableMask`, unchanged
|
||||
since P4a): the mask can only describe the first 32 points of a class, so sb either narrows the
|
||||
window it sets bits for, widens the field, or states the bound — an integrator ruling sb must ask
|
||||
for rather than pick, because the field is on the wire. `SyncBufferBindingPointsByRecord(Class, glTarget)`: per entry
|
||||
`EnsureBufferResourceForHandle(nullptr, Res)`; whole-vs-range is `Offset == 0 && Size ==
|
||||
kMGPipeWholeBuffer`; clean = `resource->syncedChangeSerial` vs the resource record's `Serial`
|
||||
(`Managers.cpp:3151`) plus `ShaderBuffersSerial`; no twin key is introduced (a point names an object,
|
||||
it is not one). The UBO loop (`DirectGLES.cpp:5447-5497`) reads `BoundShaderBuffers[Uniform][binding]`
|
||||
where `binding` is the program's block binding (pg's tail); `binding >= Count` = nothing bound;
|
||||
`GetBufferResource(obj)` `:5472` becomes `FindBufferResourceForHandle`. `SyncAtomicCounterBuffers`
|
||||
reads `Count[AtomicCounter]`; `GetBufferBindingPointCount`'s sticky forward becomes FATAL under
|
||||
split (`InvalidateCompileEnv`'s shape, `FieldOwnership.def:163-165`). The three backend GPU-write
|
||||
marks (`DirectGLES.cpp:606, 658, 2775`) are deleted under a transport in ONE edit with fb's.
|
||||
**Client shutter (the P4b hole, verified: bits 15/16/17 read the content aggregate, `Tracker.h:525,
|
||||
636-639`, and `glBindBufferBase` moves only `BindingSlot::m_version`):** bit 15 =
|
||||
`Mix(bindPointGen[Uniform], programIdentity)`, bit 16 = `Mix(gen[ShaderStorage], gen[AtomicCounter])`,
|
||||
bit 17 = `Mix(gen[TransformFeedback], TransformFeedbackGeneration)`; the content aggregate leaves all
|
||||
three. `Touch` joins `gen_pipe_dirty_surface.py`'s `MUTATOR_PREFIXES` (`:87-90`) and `DirtySurface.def`
|
||||
gains the rows the generator then demands. `Coverage.def`'s EMITTED list gains `GetBufferBindingPoint
|
||||
→ SetShaderBuffers` as SHAPE-ONLY — **landed by c0e, with BOTH of its `PipeFill.cpp` switch arms
|
||||
(`SubsystemForEmitter` and `EmittedCallSuppliesTheWholeField`) and the pairing `static_assert`s**,
|
||||
because that file belongs to the contract package for the whole phase and an emitter enumerator
|
||||
whose dispatch arm lived in the family's own worktree is exactly the merge trap the file's own
|
||||
comment was written about. It is inert until the family's wired constant leaves 0.
|
||||
`FieldOwnership.def:80-81` flips to RECORD_SUPPLIED when the four Espryt consumers are gone. `GetBufferBindingSlot`'s 15-pointer copy (`PipeFill.cpp:116-124`) needs no
|
||||
special case: an unbarriered record has no fill at all.
|
||||
|
||||
### 5.7 XFB — stays lockstep
|
||||
`StartPendingTransformFeedback` (`:1381-1510`), `SyncTransformFeedbackBindingPoints` (`:562-592`),
|
||||
`ReadbackCapturedRanges` (`:1118-1160`) and the `xfb.targets` pins are not migrated
|
||||
(`GetTransformFeedbackProgram` is an object row no package retires; the targets hold `SharedPtr`s
|
||||
across two verbs, which rule C forbids an applier entry to do without a barrier). Escalation (i)
|
||||
makes every verb inside an active span barriered; the cost on the Espryt steady path is one bool
|
||||
test per draw (`:1386`).
|
||||
|
||||
### 5.8 Monolith / G1 / the push build under `Transport=monolith` (ruling 1)
|
||||
Every server-side handle arm is selected by `MG_Config::Transport != Monolith` (the idiom at
|
||||
`DirectGLES.cpp:3226, 4725, 6534`, `Managers.cpp:9629`) AND the family bit; it runs under ANY
|
||||
active transport, lockstep or run-ahead, so `RUN_AHEAD=0` is a pure wait-rule A/B on identical
|
||||
server code. The push build under `Transport=monolith` keeps its frontend arms token for token
|
||||
(behaviour and bytes), which the verify comparator needs; the pull build compiles none of it (every
|
||||
new symbol sits under `MOBILEGL_PIPE_PUSH` / `MOBILEGL_BUILD_DISAGGREGATED`; the `TwinRegistry`
|
||||
alias keeps its mangled name, `Managers.h:626-640`; `BackendTextureObject`'s pull-build layout does
|
||||
not move — the admitted-resize set stays empty). Two overloads, not an `#if` inside one body — the
|
||||
frontend one is visibly the monolith-glue half, as `GetOrCreate(const StatePtr&)` is
|
||||
(`SlotTables.h:236-244`). G1 0/0/0/0, G2/G14 name-set rules kept; the new public names are listed in
|
||||
BRIEF-P5E per package. `MOBILEGL_PIPE_VERIFY` forces lockstep (`ConfigLoader.cpp:377`, confirmed).
|
||||
|
||||
---
|
||||
|
||||
## §6 Magma keeps the lockstep
|
||||
|
||||
1. The DirectVulkan arm of `CallMask` never sets `kCapRunAheadApply`; `RunAheadArmed()` is false;
|
||||
the client runs today's `:915-959` path; `MGPipeApplierCurrentRecordIsBarriered()` answers `true`
|
||||
for every record on a server that does not publish the bit, so Magma's probes inside
|
||||
`MagmaP7AllocatorDebtScope` and its BARRIER_PULLED reads keep P5C's semantics and `rsp`
|
||||
accounting. P7 retires them.
|
||||
2. On Espryt the bit is published by `Init.cpp`'s DirectGLES arm gated on one constant
|
||||
(`kMGPipeP5eRunAheadReady`, false until the integration commit), so every package lands with the
|
||||
column inert and nothing changes behaviour until the integrator flips it.
|
||||
3. Negative controls: `MOBILEGL_IPC_RUN_AHEAD=1` on Magma logs once and runs lockstep;
|
||||
`MagmaPipeIdentityTest`/`ServerLoopTest` pin that a DirectVulkan `CallMask` has no bit 10.
|
||||
|
||||
---
|
||||
|
||||
## §7 The strict gate
|
||||
|
||||
`integration-split-strict` (`.github/workflows/test.yml:1140-1206`) becomes a HARD GREEN lane for
|
||||
the Espryt run-ahead server: with `MOBILEGL_IPC_STRICT_ERRORS=1` and the caps bit published, every
|
||||
scenario must complete and every `[BARRIER-PULLED, ...]` marker in a private log is red. Because
|
||||
§3.3 aborts on an unbarriered pull regardless of the knob, strict adds only the barriered rows'
|
||||
pulls (readbacks, GenerateMipmap until tx2, XFB, CopyTex, set_storage_block_binding) — the lane's
|
||||
step lists those rows as the ONLY admitted markers (an allowlist by `<field>@<verb>`) and fails on
|
||||
any other. A revert of any handle arm in vi/sb/pg/tx2/fb goes red HERE, by field and verb, not in
|
||||
a picture. Magma keeps the expected-red step. `rsp` on unbarriered records is 0 in every scenario
|
||||
summary (pinned: a non-zero count would be a Fatal that did not fire). The `PipeSlotPeek` harness
|
||||
asserts zero scope entries per frame on the draw path.
|
||||
|
||||
---
|
||||
|
||||
## §8 Amendments to CONTRACT-P5C (the complete list)
|
||||
|
||||
1. **§3.1's two named exemptions** are superseded by §4.4: the registry scope is deleted at every
|
||||
draw-path site and exempts only a barriered record elsewhere; the announcement scope is Magma's.
|
||||
2. **§4.4 overflow**: lossless stays, but a run-ahead server parks on `Reserve == nullptr` (§2.6).
|
||||
3. **§5.2 `object_death`**: the ring keeps the ordering; the row is `kWaitNone`.
|
||||
4. **§5.1 `applier_reset`** is `kWaitApplied`; its `ContextSerial` assertion stands.
|
||||
5. **§6 CI lane**: the two-sided lane becomes one-sided green for Espryt (§7).
|
||||
6. **§6 layer 2** gains `Fatal{RoleViolation, "gPipeInputs"}` (§3.5); `InBarrierWait()` is
|
||||
re-derived as `MGPipeBarriered`. 7. **§3.3's state note** is retired by fb (§5.4).
|
||||
8. **`FieldOwnership.def`**: `GetBoundVertexArray`, `GetTextureUnitObject`, `GetImageTextureBinding`,
|
||||
`GetFramebufferBindingSlot`, `GetProgramForDraw/Dispatch`, `GetBufferBindingPoint` gain retiring
|
||||
phase "P5e (Espryt unbarriered), P7 (Magma)"; `GetBufferBindingPointCount`'s forward → FATAL under
|
||||
split; `GetTransformFeedbackProgram`, `GetProgramObject`, `GetTextureObject`, `ValidateProgramName`,
|
||||
`HasOpenTransformFeedbackSpan`, `RecordError` keep their rows (barriered-only readers).
|
||||
9. **Table 1** gains `set_program_bindings` (80), appended; `set_shader_buffers` (38) gains its
|
||||
route, sink and emitter (`PipeCatalogueTest.cpp:170-171, 242-243` invert). **Table 0** gains §1's
|
||||
thirteen rows. **Table 3** gains `IpcTable::RunAhead/PresentCredit`.
|
||||
10. **P5C §6's `rsp` paragraph**: the measured object-class pulls (948.5/frame on bsl) go to 0 on
|
||||
unbarriered records; what remains is the barriered allowlist of §7.
|
||||
|
||||
## §9 The rulings, as made (ID-80…98; BRIEF-P5E §6 has the conflicts they resolve)
|
||||
|
||||
All nineteen are ACCEPTED AS WRITTEN. They are restated here rather than referenced, because a
|
||||
package reads this file and not the brief.
|
||||
|
||||
1. Monolith arm selection: transport check + family bit, frontend arms kept for monolith (§5.8) —
|
||||
NOT S7's "handle arm under monolith too" (it would make the monolith push build depend on the
|
||||
new emissions and lose the verify comparator's frontend arm).
|
||||
2. Client vertex arrays: refuse under run-ahead (§5.1), stage in P8; wait-escalation rejected (it
|
||||
would need `Find(vao)` on the apply thread, which §4.4 forbids for a draw).
|
||||
3. XFB / atomic dispatch waits: the wire-derived predicate (§2.1); atomic-counter dispatch needs no
|
||||
escalation because sb lands 4.5.
|
||||
4. Present credit default 1, range 1..8; credit 2 is a measurement arm only.
|
||||
5. `resource_subdata`: buffer half `kWaitNone`, texture half keeps the reply (trailing D-D5).
|
||||
6. `BindCurrentTextures` memo key: both S2's and S4's rows (§5.3).
|
||||
7. Image sweep gate: applier serials, never a backend counter (§5.4); keep the union walk.
|
||||
8. Program archive: encode per link into SEG_STAGE (§1), measured on MC + a shader pack before pg
|
||||
is sized; the `SharedPtr` pin is refused; lazy encode at first bind is the fallback.
|
||||
9. Failed relink: re-issue with `LinkStatus = 0` iff the frontend reports the program unlinked
|
||||
afterwards; pg verifies which at `ProgramObject.cpp:348-356, 518-522`. Never an `object_death`.
|
||||
10. `set_shader_buffers` window: the touched high-water count per target; capacity 84 on the wire,
|
||||
the backend clamps (`DirectGLES.cpp:500-504`). 11. Suppressor: three class slots.
|
||||
12. Magma scope: one renamed scope, backend-kind-keyed exemption (§4.4).
|
||||
13. Deferred-destroy queue: stays live (§2.7). 14. `ResolvedDrawBuffers`: measured after vi.
|
||||
15. `Blit`'s `kWaitNone` is fb's landing, not a separate package; `Clear`'s is tx2+fb.
|
||||
|
||||
---
|
||||
|
||||
## §10 What c0e landed, by name — the surface every other package compiles against
|
||||
|
||||
Inert by construction: the caps bit is not published (`kMGPipeP5eRunAheadReady` is `false`), the
|
||||
new opcode has no route, the new subsystem bit is not in `kMGPipeWiredSubsystems`, and every new
|
||||
applier entry point and by-handle backend signature has a body that aborts by name. Unit,
|
||||
`integration-split` and the generator gates are green with all of it in the tree.
|
||||
|
||||
| where | the names |
|
||||
|---|---|
|
||||
| `MG_Pipe/MGPipeTypes.h` | `kCapRunAheadApply`, `MGPipeRunAheadCapBitsFor(BackendType, Bool)`, `kMGPipeMaxBufferBindingPoints`, `kMGPipeShaderBufferClass{Uniform,ShaderStorage,AtomicCounter,Count}`, `MGPProgramBindings`, `MGPProgramSamplerUnit`, `MGPProgramStorageOverride`, `kMGPipeMaxProgram{BlockBindings,SamplerUnits,StorageOverrides}`, `MGPProgramDesc::LinkStatus`, `kDrawClientArrays` |
|
||||
| `MG_Pipe/MGPipeValueTypes.h` | `MGPipeImageAccess`, `kMGPipeImageAccess{ReadOnly,WriteOnly,ReadWrite}`, `MGPipeImageAccessIsValid`, `MGPipeDecodeImageAccess`, `MGPipeImageAccessReads/Writes` |
|
||||
| `MG_Pipe/MGPipe.h` | `MGPipeWaitClass` (`kWaitNone/kWaitApplied/kWaitReply/kWaitPresent/kWaitClassCount`), `kMGPipeSubsystemBufferBindings`, `kMGPipeSubsystemsMigratedAtP5e` |
|
||||
| `MG_Pipe/generated/PipeWire.inc` | `MGPWireOp::SetProgramBindings` (80), `kMGPipeWaitClasses[]`, `MGPipeWaitClassFor(op)` |
|
||||
| `MG_Pipe/PipeApply.h` | `MGPipeBarriered(op, payload, st)` (implemented), `MGPipeApplierCurrentRecordIsBarriered()` / `MGPipeApplierSetCurrentRecordBarriered()` (implemented, default `true`), `MGPipeApplySetShaderBuffers` and `MGPipeApplySetProgramBindings` (declared, aborting), `MGPipeApplierState::{BoundShaderBuffers, ShaderBufferStart, ShaderBufferCount, ShaderBufferWritableMask, ShaderBuffersSerial, IsTransformFeedbackActive}`, `MGPipeShaderCsoRecord::{BlockBindings, SamplerUnits, StorageOverrides, Signature, BindingsSerial}`, `MGPipeProgramStorageOverride` |
|
||||
| `MG_Impl/Pipe/SetHashSuppressor.h` | `MGPipeSuppressorSlot::{SetShaderBuffersUniform, SetShaderBuffersShaderStorage, SetShaderBuffersAtomicCounter, SetProgramBindings}` |
|
||||
| `MG_Impl/Pipe/Tracker.h` | `kMGPipeDirtyEmittedAtP5e`; bits 15/16/17 mapped onto bit 13 |
|
||||
| `MG_Impl/Pipe/ImageEmit.h` | `MGPipeEncodeImageAccess` promoted to a free function over the shared table |
|
||||
| `MG_Backend/DirectGLES/Managers.h` | `VertexArrayImpl::ResolveVaoTwin(handle)`, `TextureImpl::SyncTextureToBackendByHandle`, `TextureImpl::ResolveTextureTwin`, `BackendTextureObject::SyncMipmapsToBackendByHandle`, `BackendFramebufferObject::SyncToBackendByHandle`, `BackendRenderbufferObject::SyncToBackendByHandle`, `BackendProgramObjectImpl::SyncToBackendByHandle`, `PrgramImpl::ResolveProgramTwin` — all declared, all aborting by name, one block at the end of `Managers.cpp` |
|
||||
| `Config.h` / `ConfigLoader.cpp` | `IpcTable::RunAhead`, `IpcTable::PresentCredit`; the push default is `kMGPipeSubsystemsMigratedAtP5e` |
|
||||
| `MG_Backend/Init.cpp` | `kMGPipeP5eRunAheadReady` (`false`) and the caps arm through `MGPipeRunAheadCapBitsFor` |
|
||||
|
||||
**The three red-onces c0e ran, and what they name.** (1) flipping one row's `WaitClass` without
|
||||
regenerating → `gen_pipe: OUT OF DATE: MobileGL/MG_Pipe/generated/PipeWire.inc`, rc 1; with the
|
||||
regeneration, `PipeCatalogue.EveryRowCarriesTheWaitClassTheContractGivesIt` fails naming
|
||||
`GenerateMipmap`. (2) `sizeof(MGPProgramBindings)` 32 → 40 →
|
||||
`PipeCatalogue.LateArrivalsAreAppendedWithoutRenumbering` fails "Which is: 40 / 32". (3) making
|
||||
the caps arm ignore the backend type →
|
||||
`MagmaPipeIdentityTest.AMagmaServerNeverPublishesTheRunAheadCapBit` fails "Which is: 1024 / 0".
|
||||
@@ -60,6 +60,10 @@ namespace MobileGL::MG_Remote {
|
||||
// assertion that turns "room to P8" from a comment into a build break.
|
||||
static_assert(MG_Pipe::kMGPipeSubsystemsMigratedAtP4a <= 0xFFFFull,
|
||||
"the subsystem mask no longer fits CallMask's sixteen consumer bits");
|
||||
// P5e (sb): and the phase constant that is actually published now, so the assertion tracks
|
||||
// the highest allocated bit rather than the highest bit at the time it was written.
|
||||
static_assert(MG_Pipe::kMGPipeSubsystemsMigratedAtP5e <= 0xFFFFull,
|
||||
"the subsystem mask no longer fits CallMask's sixteen consumer bits");
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -172,6 +172,27 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return CapsMirrorInstance().Backend();
|
||||
}
|
||||
|
||||
namespace {
|
||||
// P5e (ra), CONTRACT-P5E §2.5: THE WAIT BEFORE EVERY `Server*` EGL FORWARDER.
|
||||
//
|
||||
// These calls do not travel on SEG_CMD. They go through ServerLoop's control mailbox,
|
||||
// which is pumped BETWEEN drain batches (ServerLoop.cpp's PumpControlRequest, above
|
||||
// DrainRing) - so a make-current, a surface creation or a resize can land between two
|
||||
// records the client published and never waited for. Under lockstep that was
|
||||
// impossible: the client had waited out every record it issued before it could reach
|
||||
// this line. Under run-ahead it is one queued frame wide, and a context switch applied
|
||||
// in the middle of another context's draws is not a wrong pixel, it is a wrong
|
||||
// everything.
|
||||
//
|
||||
// ServerSwapEGLBuffers is deliberately NOT on this list, and its own virtual says why:
|
||||
// present IS the swap and it travels as a record, in order, with its own credit.
|
||||
void WaitForApplyBeforeEglForwarder(const char* forwarder) {
|
||||
if (ClientSession* session = ClientSession::Active()) {
|
||||
session->WaitForApplyToCatchUp(forwarder);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// ---- the nine EGL lifecycle virtuals ---------------------------------------------------
|
||||
//
|
||||
// FORWARD FIRST, THEN RUN THE BASE. The server has to own the context before the client's
|
||||
@@ -180,6 +201,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// InitCapabilities has run.
|
||||
|
||||
Bool BackendObject_Remote::InitializeEGLDisplay(EGLDisplay dpy, EGLint* major, EGLint* minor) {
|
||||
WaitForApplyBeforeEglForwarder("InitializeEGLDisplay");
|
||||
if (!Server::ServerInitializeEGLDisplay(dpy, major, minor)) return false;
|
||||
return MG_Backend::BackendObject::InitializeEGLDisplay(dpy, major, minor);
|
||||
}
|
||||
@@ -188,6 +210,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
const MG_Backend::WindowHandle& handle) {
|
||||
// The handle first: the server's backend has to know which window it is about to make
|
||||
// a surface for, and ServerSetWindowHandle is the only way to tell it.
|
||||
WaitForApplyBeforeEglForwarder("CreateEGLWindowSurface");
|
||||
Server::ServerSetWindowHandle(handle);
|
||||
if (!Server::ServerCreateEGLWindowSurface(surface, handle)) return false;
|
||||
// The server's surface init published the default framebuffer's shape as a
|
||||
@@ -202,6 +225,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
}
|
||||
|
||||
Bool BackendObject_Remote::ResizeEGLWindowSurface(EGLSurface surface, Uint32 width, Uint32 height) {
|
||||
WaitForApplyBeforeEglForwarder("ResizeEGLWindowSurface");
|
||||
if (!Server::ServerResizeEGLWindowSurface(surface, width, height)) return false;
|
||||
// A resize re-creates the server's swapchain, which re-posts the surface-changed
|
||||
// event - same drain, same reason as CreateEGLWindowSurface.
|
||||
@@ -210,6 +234,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
}
|
||||
|
||||
Bool BackendObject_Remote::CreateEGLPbufferSurface(EGLSurface surface, EGLint width, EGLint height) {
|
||||
WaitForApplyBeforeEglForwarder("CreateEGLPbufferSurface");
|
||||
if (!Server::ServerCreateEGLPbufferSurface(surface, width, height)) return false;
|
||||
// Same drain as the window surface: InitPbufferSurface publishes the default
|
||||
// framebuffer's depth/stencil format on SEG_EVENT from inside this very RPC.
|
||||
@@ -223,6 +248,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// class latches "the surface is initialised" and calls InitCapabilities, because
|
||||
// InitCapabilities' answer comes from a snapshot the server can only publish once its
|
||||
// own InitCapabilities has run - and ServerMakeEGLCurrent is what publishes it.
|
||||
WaitForApplyBeforeEglForwarder("MakeEGLCurrent");
|
||||
if (!Server::ServerMakeEGLCurrent(dpy, draw, read, ctx)) return false;
|
||||
if (!MG_Backend::BackendObject::MakeEGLCurrent(dpy, draw, read, ctx)) return false;
|
||||
|
||||
|
||||
@@ -139,7 +139,12 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return timeoutNs / 1000000 + (timeoutNs % 1000000 != 0) + kBarrierTimeoutMs;
|
||||
}
|
||||
|
||||
// Defined below; declared here because the applied wait has to be able to drain
|
||||
// SEG_EVENT while it is parked (P5e §2.6).
|
||||
Uint32 DrainEventRing(Transport::EventRingConsumer& events);
|
||||
|
||||
Transport::SessionWait WaitForAppliedBudget(Transport::SessionProducer& producer,
|
||||
Transport::EventRingConsumer& events,
|
||||
Uint64 seq, Uint64 remainingMs) {
|
||||
// The transport takes Uint32 milliseconds with UINT32_MAX meaning forever.
|
||||
// Keep even the largest GL timeout finite, using bounded chunks and preserving
|
||||
@@ -148,7 +153,23 @@ namespace MobileGL::MG_Remote::Client {
|
||||
for (;;) {
|
||||
const Uint32 chunkMs = remainingMs > kMaxFiniteWaitMs
|
||||
? kMaxFiniteWaitMs : static_cast<Uint32>(remainingMs);
|
||||
const auto wait = producer.WaitForApplied(seq, chunkMs);
|
||||
// P5e (ra, CONTRACT-P5E §2.6): THE PARK BREAKS ON TWO THINGS. A server that
|
||||
// ran out of SEG_EVENT stops producing and therefore stops applying, so a
|
||||
// waiter that could only be woken by appliedSeq would wait for a watermark
|
||||
// nothing is going to move - and it is holding the only drain there is. The
|
||||
// second exit is that case: drain, clear the latch, ring the server, park
|
||||
// again. `remainingMs` is deliberately NOT charged for it; a wake that did
|
||||
// the queue's work is not the caller's budget being spent.
|
||||
const auto wait = producer.WaitForAppliedOrEventBacklog(seq, chunkMs);
|
||||
if (wait == Transport::SessionWait::Reached) {
|
||||
Transport::RingControl* control = producer.Control();
|
||||
if (control == nullptr ||
|
||||
Transport::Watermark::Reached(control->appliedSeq, seq)) {
|
||||
return wait;
|
||||
}
|
||||
DrainEventRing(events);
|
||||
continue;
|
||||
}
|
||||
if (wait != Transport::SessionWait::TimedOut || remainingMs <= chunkMs) return wait;
|
||||
remainingMs -= chunkMs;
|
||||
}
|
||||
@@ -592,6 +613,9 @@ namespace MobileGL::MG_Remote::Client {
|
||||
m_events = Transport::EventRingConsumer(m_shm.EventControl(), control,
|
||||
m_shm.EventRingBase(), m_shm.EventRingCapacity(),
|
||||
m_shm.EventSegmentBase());
|
||||
// P5e (ra, §2.6): the drain's other half. A server parked on a full SEG_EVENT is woken
|
||||
// by the drain that emptied it, not by the next thing this client happens to publish.
|
||||
m_events.SetServerDoorbell(&m_clientTransport->PeerDoorbell());
|
||||
if (!m_replies.Valid() || !m_events.Valid()) {
|
||||
Stop();
|
||||
return MOBILEGL_ERR_INVALID_ARGUMENT;
|
||||
@@ -629,6 +653,10 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// half-wired shape this session exists not to have.
|
||||
m_encoder = Wire::PipeWireEncoder(control, &m_cmd, nullptr, &m_segments);
|
||||
m_encoder.SetStageRetirementDoorbell(m_producer.SelfDoorbell());
|
||||
// P5e (ra, §2.6): the stage bell is a client wait and every client wait drains. The
|
||||
// encoder owns the park; the session owns SEG_EVENT, so the session lends it a drain.
|
||||
m_encoder.SetStageWaitHook(
|
||||
+[](void* self) { DrainEventRing(static_cast<ClientSession*>(self)->Events()); }, this);
|
||||
|
||||
// ---- 7. the first CapsSnapshot, if the server had a backend to publish one from.
|
||||
// ONE DRAIN, ONE ADOPTER (c1): PumpControlPlane below is the only thing in the client
|
||||
@@ -748,7 +776,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
}
|
||||
|
||||
// 2. Doorbell::Kill(). THE ONLY thing that can wake an apply thread parked on
|
||||
// kWaitForever (Doorbell.h:211-221): a Notify is consumed by one Park, after which
|
||||
// kWaitForever (CondVarDoorbell::Kill): a Notify is consumed by one Park, after which
|
||||
// Doorbell::Wait re-tests a condition nothing published, finds the bell alive and
|
||||
// parks again, forever. InProcessChannel::Close kills both bells.
|
||||
if (m_transport != nullptr) {
|
||||
@@ -774,6 +802,14 @@ namespace MobileGL::MG_Remote::Client {
|
||||
m_serverTransport.reset();
|
||||
m_transport = nullptr;
|
||||
m_started = false;
|
||||
// P5e (ra, §1): the LATCH GOES DOWN WITH THE SESSION. It is "what the first caps
|
||||
// adoption of THIS session said", and a session that starts again - the same singleton,
|
||||
// a second Start - must take it again from that session's own first snapshot rather
|
||||
// than inherit a verdict about a server that is gone. The present serial goes with it
|
||||
// for the same reason: the credit's id space belongs to the session that paces on it.
|
||||
m_runAheadArmed = false;
|
||||
m_runAheadLatched = false;
|
||||
m_presentsSent = 0;
|
||||
if (g_active == this) {
|
||||
g_active = nullptr;
|
||||
}
|
||||
@@ -814,7 +850,8 @@ namespace MobileGL::MG_Remote::Client {
|
||||
Uint64 ClientSession::EmitAndWaitTails(MG_Pipe::MGPWireOp op, const void* payload,
|
||||
Uint64 payloadBytes, const Wire::WireTail* tails,
|
||||
Uint32 tailCount, void* replyOut, Uint64 replyBytes,
|
||||
Int32* statusOut, Uint64* replySizeOut) {
|
||||
Int32* statusOut, Uint64* replySizeOut,
|
||||
Bool wantReply) {
|
||||
Uint64 varTailBytes = 0;
|
||||
for (Uint32 i = 0; i < tailCount; ++i) varTailBytes += tails[i].Size;
|
||||
if (statusOut != nullptr) *statusOut = Wire::ReplySink::kStatusError;
|
||||
@@ -863,6 +900,12 @@ namespace MobileGL::MG_Remote::Client {
|
||||
wait == Transport::SessionWait::ShutDown ? "shutdown" : "timeout");
|
||||
std::abort();
|
||||
}
|
||||
// P5e (ra, §2.6): EVERY WAIT EXIT DRAINS. The cmd-space wait is one of the two
|
||||
// safety nets under run-ahead (the stage bell is the other), and a client parked
|
||||
// here without draining is the other half of the flow-control deadlock: the server
|
||||
// stops applying on a full event ring, so retiredSeq stops moving, so this wait
|
||||
// never completes. One drain on the way out closes it.
|
||||
DrainEventRing(m_events);
|
||||
seq = m_encoder.EncodeRecord(op, payload, payloadBytes, tails, tailCount);
|
||||
if (seq == Wire::kInvalidSeq) {
|
||||
MGLOG_F("MGPipe: Fatal{RingOverrun, \"SEG_CMD\"} - %s refused after sufficient "
|
||||
@@ -880,8 +923,63 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// (R-16 / ID-31) - fourteen rows now, because the four Bool acceptance entry points
|
||||
// gained the flag. Asking the catalogue rather than the caller is what stops a caller
|
||||
// that forgot to pass a buffer from silently turning an answer into a guess.
|
||||
const Bool ownsReplySlot =
|
||||
//
|
||||
// P5e (ra) ADDS ONE CALLER-SIDE CONJUNCT AND NO SECOND SOURCE OF TRUTH: `wantReply`.
|
||||
// The catalogue still says which rows CARRY a slot; a caller that passes false says it
|
||||
// will not read this one (resource_subdata's buffer half, §2.5 - the only such caller).
|
||||
// The server posts either way, so the wire is unchanged and the row keeps its flag.
|
||||
const Bool rowCarriesReplySlot =
|
||||
(MG_Pipe::MGPipeCallFlagsFor(op) & static_cast<Uint32>(MG_Pipe::kReplySlot)) != 0;
|
||||
const Bool ownsReplySlot = rowCarriesReplySlot && wantReply;
|
||||
|
||||
// ---- THE P5e WAIT RULE (CONTRACT-P5E §2.3) ---------------------------------------
|
||||
//
|
||||
// IT STANDS BEFORE THE BATCH SKIP AND REPLACES IT WHOLE, rather than adding a clause to
|
||||
// it. The batch skip is a rule about CALL CLASSES ("a set/CSO/object record carries its
|
||||
// whole value in the payload"); the wait class is a rule about WHAT AN APPLY READS, and
|
||||
// it is generated from the same PipeCalls.def row the class comes from
|
||||
// (MGPipeWaitClassFor, c0e). Two rules layered would mean a row could be skipped by the
|
||||
// class rule and waited by the column, and the column is the one the SERVER's
|
||||
// MGPipeBarriered reads - so the two halves of the wire would disagree about whether
|
||||
// the client is parked behind this record, which is the single fact §4.4's exemptions
|
||||
// and §3.3's detector both rest on.
|
||||
//
|
||||
// WITH RUN-AHEAD DISARMED NOTHING BELOW RUNS and the file's original shape continues -
|
||||
// Magma, a monolith transport, MOBILEGL_IPC_RUN_AHEAD=0 and every build before the
|
||||
// integration commit take the old path byte for byte, which is what makes RUN_AHEAD=0
|
||||
// a pure wait-rule A/B on identical server code (§5.8).
|
||||
if (RunAheadArmed() && !ownsReplySlot) {
|
||||
MG_Pipe::MGPipeWaitClass waitClass = MG_Pipe::MGPipeWaitClassFor(op);
|
||||
// §2.5's named relaxation, and the ONLY place a static column answer is overridden:
|
||||
// a kWaitReply row whose caller does not want the answer has nothing to wait FOR.
|
||||
// It is spelled here rather than in the column because the column is per-op and
|
||||
// this is per-call - the texture half of the same row still waits.
|
||||
if (!wantReply && waitClass == MG_Pipe::kWaitReply) waitClass = MG_Pipe::kWaitNone;
|
||||
switch (waitClass) {
|
||||
case MG_Pipe::kWaitNone:
|
||||
// Published and gone. Rule F is what makes this legal: the apply of an
|
||||
// unbarriered record names no client memory at all (§3, §4, §5).
|
||||
return seq;
|
||||
case MG_Pipe::kWaitPresent:
|
||||
// The credit wait already ran, in EmitPresent, BEFORE the encode (§2.4). There
|
||||
// is nothing left to do here and waiting would turn the credit into a barrier.
|
||||
return seq;
|
||||
case MG_Pipe::kWaitApplied:
|
||||
// §2.2's barriered rows: applier_reset, generate_mipmap (until tx2 lands its
|
||||
// VerbMipRes arm), set_storage_block_binding, the five XFB span verbs and the
|
||||
// CopyTex endpoint. Each still pulls a row or probes a registry, and the
|
||||
// client's wait is exactly what keeps P5C's semantics legal for it (ruling 4).
|
||||
// Falls through to the wait below.
|
||||
break;
|
||||
case MG_Pipe::kWaitReply:
|
||||
case MG_Pipe::kWaitClassCount:
|
||||
// Unreachable: `ownsReplySlot` is false here, and gen_pipe refuses a kWaitReply
|
||||
// row without a slot and a kReplySlot row that does not wait (c0e's three
|
||||
// negative controls). Treated as a wait rather than as a skip, because the
|
||||
// wrong answer to "does this hang" is the recoverable one.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// MOBILEGL_IPC_BATCH_WAITS (default 1): a value-class record is published WITHOUT
|
||||
// waiting for its own apply. The barrier's one load-bearing reader is the backend
|
||||
@@ -896,7 +994,30 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// the number of round trips between them changes. Set / CSO / object records carry
|
||||
// their whole value in the payload and are consumed at the next (waited) sync, which
|
||||
// the in-order ring guarantees precedes that sync's apply.
|
||||
if (!ownsReplySlot && MG_Config::Ipc.BatchWaits != 0) {
|
||||
//
|
||||
// WITH ONE NAMED EXCEPTION, FOUND BY ITS OWN FATAL (P5d round 3): generate_mipmap is
|
||||
// catalogued kCtxObject, but its sink is the backend's GenerateMipmap, which reads
|
||||
// MGB_CTX->GetActiveTextureUnit() and the unit's binding slot - residual inputs whose
|
||||
// freshness is the CLIENT's verb serial. Published without a wait, the record sits in
|
||||
// the ring while this thread runs the next verb's MGPipeValidateForVerb, which moves
|
||||
// that serial and withdraws the server stamp; the apply thread then reads the unit
|
||||
// stale and aborts Fatal{UnmigratedPipeInput, "GetActiveTextureUnit@<next verb>"}
|
||||
// (F1WireScenario.GenerateMipmap*Pixels, reproduced on the gate tree once the round-3
|
||||
// spin no longer read the clock). So it waits, exactly as the four stamping verbs
|
||||
// do. The rule this encodes: a record may skip its wait only if its apply reads
|
||||
// nothing the residual fill writes - the value carried in the payload is the whole
|
||||
// input. No other kCtxObject row has a backend body behind it that reads MGB_CTX
|
||||
// (set_texture_params, resource_subdata, resource_readback and get_texture_image
|
||||
// own reply slots and wait anyway; the resource_* transfers and object_death resolve
|
||||
// by handle).
|
||||
//
|
||||
// AND IT IS DISARMED WHOLE UNDER RUN-AHEAD (P5e §2.3): the wait class above is the
|
||||
// rule there, and a second skip rule reading a different column is how the two halves
|
||||
// of the wire end up disagreeing about whether the client is parked. Written as a
|
||||
// conjunct here rather than left to "the classes happen not to overlap", because the
|
||||
// classes overlapping is one PipeCalls.def row away at any time.
|
||||
if (!ownsReplySlot && !RunAheadArmed() && MG_Config::Ipc.BatchWaits != 0 &&
|
||||
op != MG_Pipe::MGPWireOp::GenerateMipmap) {
|
||||
const MG_Pipe::MGPipeCallClass callClass = MG_Pipe::MGPipeCallClassFor(op);
|
||||
if (callClass == MG_Pipe::kCtxState || callClass == MG_Pipe::kCtxCso ||
|
||||
callClass == MG_Pipe::kCtxObject) {
|
||||
@@ -914,7 +1035,8 @@ namespace MobileGL::MG_Remote::Client {
|
||||
|
||||
const BarrierWaitScope waiting;
|
||||
const Uint64 waitBudgetMs = AppliedWaitBudgetMs(op, payload);
|
||||
const Transport::SessionWait wait = WaitForAppliedBudget(m_producer, seq, waitBudgetMs);
|
||||
const Transport::SessionWait wait =
|
||||
WaitForAppliedBudget(m_producer, m_events, seq, waitBudgetMs);
|
||||
if (wait == Transport::SessionWait::ShutDown) {
|
||||
// The doorbell died: the server went away. The only thing that returns from a
|
||||
// kWaitForever park, and therefore the only way a client blocked in the barrier
|
||||
@@ -948,7 +1070,17 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// clears when the writeback lands, and the writeback lands on this ring.
|
||||
DrainEventRing(m_events);
|
||||
|
||||
if (!ownsReplySlot) return seq;
|
||||
if (!ownsReplySlot) {
|
||||
// P5e (ra, §2.3). A barriered record's apply has returned and this thread is the
|
||||
// only runnable one, so the four O-class SharedPtr rows the last fill left in
|
||||
// gPipeInputs can go. Under lockstep they were harmless - the next verb's fill
|
||||
// overwrote them - but under run-ahead the next fill may be a frame away, and a
|
||||
// frontend VAO or program whose LAST owner is that block is one the apply thread
|
||||
// can end up destroying (§2.7's deferred-destroy hazard). Released here rather
|
||||
// than at the fill, because here is where the applier is provably idle.
|
||||
if (RunAheadArmed()) ReleaseFillPins();
|
||||
return seq;
|
||||
}
|
||||
|
||||
// THE SAME WAIT, NOT A SECOND ONE. appliedSeq >= seq already means the server wrote
|
||||
// this record's answer, because it writes the slot before it advances the watermark.
|
||||
@@ -983,6 +1115,166 @@ namespace MobileGL::MG_Remote::Client {
|
||||
|
||||
Bool ClientSession::BarrierArmed() const { return m_barrierArmed; }
|
||||
|
||||
// ---- P5e (ra): the run-ahead latch and the waits it leaves behind ---------------------
|
||||
|
||||
Bool ClientSession::RunAheadArmed() const { return m_runAheadArmed; }
|
||||
// THE PRODUCER'S NUMBER, NOT A SECOND ONE. SessionProducer records it inside
|
||||
// PublishAndNotify, which is the only place a record becomes published at all; a copy kept
|
||||
// here would be a second thing to forget to write on a path that publishes without waiting
|
||||
// - which, after P5e, is most of them.
|
||||
Uint64 ClientSession::LastPublishedSeq() const { return m_producer.LastPublishedSeq(); }
|
||||
Uint64 ClientSession::PresentCreditWaits() const { return m_presentCreditWaits; }
|
||||
|
||||
void ClientSession::LatchRunAheadFromCaps() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// THE CONJUNCTION, IN THE CONTRACT'S OWN ORDER (§1). The caps read is last because it
|
||||
// is the only one that costs a mirror load, and because it is the only one whose answer
|
||||
// can change: the other two are process configuration.
|
||||
const Bool armed = m_barrierArmed && MG_Config::Ipc.RunAhead != 0 &&
|
||||
Caps().HasCap(MG_Pipe::kCapRunAheadApply);
|
||||
if (!m_runAheadLatched) {
|
||||
m_runAheadLatched = true;
|
||||
m_runAheadArmed = armed;
|
||||
if (armed) {
|
||||
MGLOG_I("MG_Remote client: run-ahead ARMED - the server publishes "
|
||||
"kCapRunAheadApply, so an unbarriered record is published and not "
|
||||
"waited for (CONTRACT-P5E §2.3), paced by a present credit of %u",
|
||||
MG_Config::Ipc.PresentCredit);
|
||||
} else if (MG_Config::Ipc.RunAhead != 0 && m_barrierArmed) {
|
||||
// THE KNOB IS NOT A SWITCH ON ITS OWN, and an operator who set it has to be
|
||||
// told that, or an A/B arm that measured nothing looks like an A/B arm that
|
||||
// measured no difference (Config.h's own argument for parsing it everywhere).
|
||||
MGLOG_W_ONCE("MG_Remote client: run-ahead requested, server does not publish "
|
||||
"kCapRunAheadApply - running lockstep. This is Magma always, and "
|
||||
"Espryt until the P5e integration commit flips "
|
||||
"kMGPipeP5eRunAheadReady");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// A LATER SNAPSHOT MAY ONLY TURN IT OFF. Promotion would mean the records already
|
||||
// published without a wait were published against a rule this server never agreed to,
|
||||
// and nothing can un-publish them; demotion only adds waits, so it is safe and is
|
||||
// exactly what a server that lost its run-ahead backend needs.
|
||||
if (!armed && m_runAheadArmed) {
|
||||
m_runAheadArmed = false;
|
||||
MGLOG_W("MG_Remote client: run-ahead DISARMED by a later caps snapshot - every "
|
||||
"record from here waits as it did before P5e");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClientSession::ReleaseFillPins() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The block's own door: PipeInputs' O-class rows are private and MG_Remote has no
|
||||
// business knowing which four they are. MG_Impl owns the fill, so MG_Impl owns the
|
||||
// un-fill (PipeFill.cpp), and this side only says WHEN.
|
||||
MG_Pipe::MGPipeReleaseResidualFillPins();
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClientSession::WaitForApplyToCatchUp(const char* why) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// A NO-OP WITHOUT RUN-AHEAD, and that is not an optimisation: under lockstep the
|
||||
// client already waited for every record it published, so appliedSeq is at
|
||||
// LastPublishedSeq by construction and a second wait would only add a park on a
|
||||
// watermark that is already reached.
|
||||
if (!m_runAheadArmed || !m_started) return;
|
||||
const Uint64 target = m_producer.LastPublishedSeq();
|
||||
if (target == 0) return;
|
||||
const BarrierWaitScope waiting;
|
||||
const Transport::SessionWait wait =
|
||||
WaitForAppliedBudget(m_producer, m_events, target, kBarrierTimeoutMs);
|
||||
if (wait == Transport::SessionWait::ShutDown) {
|
||||
// The doorbell died: teardown, not a fault - the same answer EmitAndWaitTails
|
||||
// gives, and for the same reason.
|
||||
MGLOG_E("MG_Remote client: the forced wait for %s woke on a dead doorbell; the "
|
||||
"server is gone", why);
|
||||
return;
|
||||
}
|
||||
if (wait != Transport::SessionWait::Reached) {
|
||||
MGLOG_F("MGPipe: Fatal{BarrierTimeout, \"%s\"} - a forced run-ahead wait did not "
|
||||
"reach appliedSeq %llu within %u ms. The forced waits of CONTRACT-P5E §2.5 "
|
||||
"are the points at which the client must be in step again, so a wedge here "
|
||||
"is a wedge in the queue and not a slow frame",
|
||||
why, static_cast<unsigned long long>(target), kBarrierTimeoutMs);
|
||||
std::abort();
|
||||
}
|
||||
// EVERY WAIT EXIT DRAINS (§2.6). It is what the flow-control deadlock argument rests
|
||||
// on: the server blocks only on a full event ring, the client blocks only on
|
||||
// watermarks the server advances, and every client wait drains - so at most one side
|
||||
// is parked at any instant.
|
||||
DrainEventRing(m_events);
|
||||
ReleaseFillPins();
|
||||
#else
|
||||
(void)why;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ClientSession::Finish() {
|
||||
// glFinish. Nothing goes on the wire - Flush and Finish have no record (ARCHITECTURE
|
||||
// §11) - and under lockstep there was nothing to do, because the client had already
|
||||
// waited out every command it issued. Under run-ahead "the commands issued so far have
|
||||
// completed" is a promise the queue can break, so this is where it is kept.
|
||||
WaitForApplyToCatchUp("glFinish");
|
||||
}
|
||||
|
||||
Uint64 ClientSession::AcquirePresentCredit() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// MINTED CLIENT-SIDE AND 1-BASED (§1). Before P5e the client sent 0 and the server
|
||||
// stamped its own frame count, which was honest while nothing paced on it; a credit
|
||||
// needs an id space only the payer can advance, and that is this one.
|
||||
const Uint64 serial = m_presentsSent + 1;
|
||||
if (!m_runAheadArmed) {
|
||||
// Lockstep: the present record's own barrier IS the pacing, one frame deep by
|
||||
// construction. The serial is still minted so that both arms carry the same field
|
||||
// and the server's ReturnPresentCredit is fed on both - an A/B whose two arms
|
||||
// disagree about a wire field is not an A/B (Config.h's rule for the knobs).
|
||||
m_presentsSent = serial;
|
||||
return serial;
|
||||
}
|
||||
const Uint32 credit = MG_Config::Ipc.PresentCredit;
|
||||
if (m_presentsSent >= credit) {
|
||||
// Wait for swap number (serial - credit) to have come back. With credit 1 that is
|
||||
// the previous frame: the client publishes frame N+1's records while the server
|
||||
// applies and swaps frame N, and blocks here until swap N returned - one frame of
|
||||
// overlap and at most one frame of added latency (ruling 4 / ID-92).
|
||||
const Uint64 awaited = serial - credit;
|
||||
++m_presentCreditWaits;
|
||||
const BarrierWaitScope waiting;
|
||||
Transport::SessionWait wait = Transport::SessionWait::TimedOut;
|
||||
for (;;) {
|
||||
// §2.6 again: the credit park breaks on a full SEG_EVENT too, for the same
|
||||
// reason the applied park does - a server that stopped producing stopped
|
||||
// swapping, and this waiter holds the only drain.
|
||||
wait = m_producer.WaitForPresentAckOrEventBacklog(awaited, kBarrierTimeoutMs);
|
||||
if (wait != Transport::SessionWait::Reached) break;
|
||||
Transport::RingControl* control = m_producer.Control();
|
||||
if (control == nullptr ||
|
||||
Transport::Watermark::Reached(control->presentAckSerial, awaited)) {
|
||||
break;
|
||||
}
|
||||
DrainEventRing(m_events);
|
||||
}
|
||||
if (wait == Transport::SessionWait::TimedOut) {
|
||||
MGLOG_F("MGPipe: Fatal{PresentCreditTimeout} - present %llu waited %u ms for "
|
||||
"swap %llu to come back with a credit of %u. The credit, never the "
|
||||
"ring's bytes, is what paces a run-ahead client (CONTRACT-P5E §2.4), "
|
||||
"so a credit that never returns is a server that stopped swapping",
|
||||
static_cast<unsigned long long>(serial), kBarrierTimeoutMs,
|
||||
static_cast<unsigned long long>(awaited), credit);
|
||||
std::abort();
|
||||
}
|
||||
// ShutDown is teardown and returns: the present did not happen, the same answer
|
||||
// the barrier gives on a dead doorbell.
|
||||
if (wait == Transport::SessionWait::Reached) DrainEventRing(m_events);
|
||||
}
|
||||
m_presentsSent = serial;
|
||||
return serial;
|
||||
#else
|
||||
return ++m_presentsSent;
|
||||
#endif
|
||||
}
|
||||
|
||||
// R-1's mutual-exclusion invariant, as two probes that answer honestly.
|
||||
//
|
||||
// THE CLIENT'S FLAG IS THREAD-LOCAL AND THE SERVER'S IS NOT, and the asymmetry is the
|
||||
@@ -995,14 +1287,45 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return g_applyThreadInsideApplier.load(std::memory_order_acquire);
|
||||
}
|
||||
|
||||
void ClientSession::RefusePipeInputsTouchWhileApplierOwnsIt(const char* surface) {
|
||||
if (Server::ServerLoop::OnApplyThread()) return; // the applier owns the block inside a verb
|
||||
void ClientSession::RefusePipeInputsTouchWhileApplierOwnsIt(const char* surface,
|
||||
Bool isBarrieredFill) {
|
||||
// THE CHAIN IS A CONJUNCTION, SO ITS ORDER IS FREE - AND IT IS ORDERED CHEAPEST-FIRST
|
||||
// (P5d round 3, package D). Every line below is a pure predicate whose only effect is
|
||||
// "no violation, go home"; the Fatal fires on the AND of all of them, so reordering
|
||||
// cannot change which touches abort. It changes only what a touch that does NOT abort
|
||||
// pays, and this guard sits on the per-verb fill path (PipeFill.cpp:542, :1951, :2789
|
||||
// - MGPipeValidateForVerb is 4.11% self / 10.9% inclusive of the client thread), so
|
||||
// "what it costs to answer no" is the whole of its cost in a healthy process.
|
||||
//
|
||||
// The two config reads come first because they are the two answers that are constant
|
||||
// for the life of the process and true for nearly every process that runs this code:
|
||||
// a monolith build never has a role split at all, and MOBILEGL_IPC_BATCH_WAITS
|
||||
// defaults to 1, which retires this guard by design (see its note below). Only after
|
||||
// both miss do we pay for a role probe, two singleton reads, a shared atomic and the
|
||||
// thread_local at the end.
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
if (!ClientSessionInstance().Started()) return; // the bring-up window pre-dates the roles
|
||||
// MOBILEGL_IPC_VERB_BARRIER=0 is R-1's NEGATIVE CONTROL: the single-writer rule is off
|
||||
// by the operator's own hand there, and EmitAndWait's Fatal{BarrierViolation} owns the
|
||||
// red. Firing here instead would pre-empt the control's evidence line.
|
||||
if (!ClientSessionInstance().BarrierArmed()) return;
|
||||
// ---- P5e (ra), CONTRACT-P5E §3.5: THE RUN-AHEAD RULE IS A DIFFERENT RULE -----------
|
||||
//
|
||||
// It is first, before the BatchWaits return, because BatchWaits' argument does not
|
||||
// survive run-ahead: "the pull-verbs' own wait keeps their pulled reads fenced" is a
|
||||
// statement about a client that waits at every verb, and this one does not. Under
|
||||
// run-ahead the block is SERVER-ROLE memory (§3) and the single legal GL-thread write
|
||||
// is the residual fill of a BARRIERED record - the one the client is about to park
|
||||
// behind. Every other touch races the applier by construction, so there is no
|
||||
// in-applier flag to consult and no "count it" arm: the value would be torn.
|
||||
//
|
||||
// This is where a fill left standing for an unbarriered record lands, by name.
|
||||
if (ClientSessionInstance().RunAheadArmed()) {
|
||||
if (isBarrieredFill) return;
|
||||
if (Server::ServerLoop::OnApplyThread()) return; // the applier owns the block
|
||||
MGLOG_F("MGPipe: Fatal{RoleViolation, \"gPipeInputs\"} - the GL thread touched "
|
||||
"gPipeInputs (%s) on a RUN-AHEAD session outside a barriered fill. With "
|
||||
"the client running ahead the block is the server's to read for as long "
|
||||
"as an unbarriered record is in flight (CONTRACT-P5E §3), and this thread "
|
||||
"has no wait that would make the touch quiescent",
|
||||
surface);
|
||||
std::abort();
|
||||
}
|
||||
// MOBILEGL_IPC_BATCH_WAITS=1 makes "the fill runs while the apply thread applies an
|
||||
// earlier value record" the INTENDED shape: the fill writes only fields no record
|
||||
// supplies (the wire-live skips are the same answer the emitters use), the applier
|
||||
@@ -1010,7 +1333,16 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// pulled reads fenced. This guard exists for the model where that is not true, so
|
||||
// it stands only while the batch is off.
|
||||
if (MG_Config::Ipc.BatchWaits != 0) return;
|
||||
if (Server::ServerLoop::OnApplyThread()) return; // the applier owns the block inside a verb
|
||||
if (!ClientSessionInstance().Started()) return; // the bring-up window pre-dates the roles
|
||||
// MOBILEGL_IPC_VERB_BARRIER=0 is R-1's NEGATIVE CONTROL: the single-writer rule is off
|
||||
// by the operator's own hand there, and EmitAndWait's Fatal{BarrierViolation} owns the
|
||||
// red. Firing here instead would pre-empt the control's evidence line.
|
||||
if (!ClientSessionInstance().BarrierArmed()) return;
|
||||
if (!ApplyThreadIsInsideApplier()) return;
|
||||
// LAST, because it is the only thread_local left in the chain: an emutls call per
|
||||
// access in a shared library, and it must stay thread-local (see InBarrierWait's note
|
||||
// above - a second GL thread would otherwise read the first one's wait as its own).
|
||||
if (InBarrierWait()) return;
|
||||
MGLOG_F("MGPipe: Fatal{RoleViolation, \"gPipeInputs\"} - the GL thread touched gPipeInputs "
|
||||
"(%s) while the apply thread was inside the applier and this thread was not in a "
|
||||
@@ -1056,6 +1388,14 @@ namespace MobileGL::MG_Remote::Client {
|
||||
}
|
||||
if (AdoptCapsSnapshot(envelope->msg_as_CapsSnapshot())) ++adopted;
|
||||
}
|
||||
// P5e (ra, §1): the run-ahead latch rides R-12's invalidation edge, because "the first
|
||||
// caps adoption after Start" and "the one place a CapsSnapshot becomes a mirror
|
||||
// generation" are the same instant, and a latch taken anywhere else would be reading a
|
||||
// mirror whose generation nobody had adopted yet. Called even when `adopted` is 0: the
|
||||
// first call in Start() is what takes the latch, and a pump that adopted nothing still
|
||||
// has to leave it taken (a handshake with no snapshot latches "not armed", which is
|
||||
// the honest answer for a server that never said what it consumes).
|
||||
if (adopted != 0 || !m_runAheadLatched) LatchRunAheadFromCaps();
|
||||
return adopted;
|
||||
}
|
||||
|
||||
@@ -1133,8 +1473,9 @@ namespace MobileGL::MG_Remote::Client {
|
||||
MGLOG_I("MG_Remote client: wire ledger: maxrec=%llu maxrecop=%s cap=%llu (%llu.%llu%% of "
|
||||
"RingProducer::MaxRecordBytes, half of a %llu byte SEG_CMD) cmdbytes=%llu "
|
||||
"ringwraps=%llu ringpads=%llu "
|
||||
"ringwaits=%llu emitseq=%llu - R-10's proof obligation and R-9's producer "
|
||||
"readings, published from the session that produced them",
|
||||
"ringwaits=%llu emitseq=%llu cliwait=%llu clipark=%llu credit-waits=%llu - "
|
||||
"R-10's proof obligation, R-9's producer readings, P5d round 3's client wait "
|
||||
"pair and P5e's present credit, published from the session that produced them",
|
||||
static_cast<unsigned long long>(maxRecord), m_encoder.MaxRecordOpName(),
|
||||
static_cast<unsigned long long>(cap),
|
||||
static_cast<unsigned long long>(permille / 10),
|
||||
@@ -1144,7 +1485,19 @@ namespace MobileGL::MG_Remote::Client {
|
||||
static_cast<unsigned long long>(m_encoder.CmdWraps()),
|
||||
static_cast<unsigned long long>(m_encoder.CmdWrapPads()),
|
||||
static_cast<unsigned long long>(m_encoder.StageReclaimWaits()),
|
||||
static_cast<unsigned long long>(m_encoder.EmitSeq()));
|
||||
static_cast<unsigned long long>(m_encoder.EmitSeq()),
|
||||
// The same pair the summary line's wait[] carries, on the channel that exists
|
||||
// in EVERY split private log rather than in the two counting lanes: the round-3
|
||||
// profile runs did not set MOBILEGL_PIPE_STATS either, and "did the barrier spin
|
||||
// or did it park" is the question their logs have to be able to answer.
|
||||
static_cast<unsigned long long>(m_producer.Waits()),
|
||||
static_cast<unsigned long long>(m_producer.Parks()),
|
||||
// P5e (ra, §2.4). The number the device exit reads to say whether the present
|
||||
// credit is what paces this workload: 0 with credit 1 means the server is
|
||||
// never the frame's critical path, and a count near the frame count means it
|
||||
// always is. It is on this line rather than only on the stats line for
|
||||
// LogWireLedger's own reason - a trace replay never reaches a stats summary.
|
||||
static_cast<unsigned long long>(m_presentCreditWaits));
|
||||
}
|
||||
|
||||
#undef MGP5_C0_STUB
|
||||
|
||||
@@ -84,7 +84,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
|
||||
// Teardown order matters and is table 3's fourth column: publish and let the server
|
||||
// drain, Doorbell::Kill() (the ONLY thing that wakes an apply thread parked on
|
||||
// kWaitForever, Doorbell.h:211-221), then join, and only then release anything an
|
||||
// kWaitForever, CondVarDoorbell::Kill), then join, and only then release anything an
|
||||
// emitter owns - a tail still referenced by an unapplied record is a use-after-free
|
||||
// the join is what prevents.
|
||||
void Stop();
|
||||
@@ -103,7 +103,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// this and refuses `replySize != DstSize` by name rather than trust the copy.
|
||||
//
|
||||
// Waiting is spin(MOBILEGL_IPC_SPIN_US) then park, through Doorbell::Wait, with
|
||||
// producerParked set before blocking - the shape Doorbell.h:121 already implements.
|
||||
// producerParked set before blocking - the shape Doorbell::Wait already implements.
|
||||
Uint64 EmitAndWait(MG_Pipe::MGPWireOp op, const void* payload, Uint64 payloadBytes,
|
||||
const void* varTail, Uint64 varTailBytes, void* replyOut,
|
||||
Uint64 replyBytes, Int32* statusOut, Uint64* replySizeOut = nullptr);
|
||||
@@ -112,15 +112,79 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// or its MGPDrawIndirect block behind the range array). The one-tail form above is this
|
||||
// one with a single WireTail; the barrier policy lives in exactly one body. A distinct
|
||||
// name rather than an overload, because `nullptr, 0` would match both.
|
||||
// P5e (ra, CONTRACT-P5E §2.5): `wantReply` is the ONE caller-side relaxation of the
|
||||
// catalogue's reply rule, and it exists for exactly one row - resource_subdata's
|
||||
// BUFFER half, whose Bool the only caller discards (PipeFill.cpp's
|
||||
// MGPipeEmitResourceSubData). The row keeps kReplySlot on the wire (the server still
|
||||
// posts; an unread slot is harmless, ReplySlot.h:16, 105), so nothing about the
|
||||
// protocol moves - what moves is that under run-ahead this client neither waits for
|
||||
// the answer nor reads it, which is what makes the 64 KB persistent-map push
|
||||
// fire-and-forget instead of a hidden round trip per block. It is NOT a licence to
|
||||
// skip an answer a caller uses: R-5 still forbids re-deriving one locally, and every
|
||||
// other kReplySlot row passes true (the default) and waits.
|
||||
Uint64 EmitAndWaitTails(MG_Pipe::MGPWireOp op, const void* payload, Uint64 payloadBytes,
|
||||
const Wire::WireTail* tails, Uint32 tailCount, void* replyOut,
|
||||
Uint64 replyBytes, Int32* statusOut,
|
||||
Uint64* replySizeOut = nullptr);
|
||||
Uint64* replySizeOut = nullptr, Bool wantReply = true);
|
||||
|
||||
// MOBILEGL_IPC_VERB_BARRIER. False is the R-1 negative control and is EXPECTED to be
|
||||
// red; it must be run once and the way it goes red recorded.
|
||||
Bool BarrierArmed() const;
|
||||
|
||||
// ---- P5e (ra): the wait rule (CONTRACT-P5E §1, §2.3, §2.4, §2.5) -------------------
|
||||
|
||||
// A CONJUNCTION OF THREE, LATCHED ONCE: `m_barrierArmed && Ipc.RunAhead &&
|
||||
// Caps().HasCap(kCapRunAheadApply)`. The third conjunct is the server's own statement
|
||||
// that it applies an unbarriered record without reading client memory, so run-ahead is
|
||||
// never something the client can turn on by itself - on Magma, and on Espryt until the
|
||||
// integration commit publishes bit 10, this answers false and EmitAndWaitTails runs
|
||||
// today's lockstep path byte for byte.
|
||||
//
|
||||
// LATCHED AT THE FIRST CAPS ADOPTION AFTER Start, AND A LATER SNAPSHOT MAY ONLY TURN IT
|
||||
// OFF. A caps re-run cannot promote a lockstep server to a run-ahead one mid-frame:
|
||||
// records already published without a wait would have been published against the wrong
|
||||
// rule, and there is no way to un-publish them. Demotion is safe in the other
|
||||
// direction - it only adds waits - so it is allowed.
|
||||
Bool RunAheadArmed() const;
|
||||
|
||||
// §2.3: the four O-class SharedPtr rows of gPipeInputs (PipeInputs.h:801-809 - the
|
||||
// bound VAO and the three programs), dropped on the GL thread once a barriered apply
|
||||
// has returned. Under lockstep the next fill overwrites them within a verb; under
|
||||
// run-ahead the next fill may be a frame away, and a pinned VAO whose last owner ends
|
||||
// up being the apply thread is exactly the deferred-destroy hazard §2.7 keeps a queue
|
||||
// for. Releasing them at the one instant the applier is provably idle costs four
|
||||
// refcount drops per barriered record and removes the pin entirely.
|
||||
void ReleaseFillPins();
|
||||
|
||||
// §2.5's forced wait, as one named entry point: publish nothing, wait for the apply
|
||||
// thread to reach LastPublishedSeq, drain the reverse channel. `why` names the caller
|
||||
// in the timeout Fatal, because "which forced wait wedged" is the whole diagnostic.
|
||||
// A no-op when run-ahead is not armed (the client is already in step by construction).
|
||||
void WaitForApplyToCatchUp(const char* why);
|
||||
|
||||
// glFinish. Flush and Finish stay no-ops ON THE WIRE (ARCHITECTURE §11, :415) - there
|
||||
// is no record to emit - but "the GL commands issued so far have completed" cannot be
|
||||
// true while a run-ahead queue still holds them, so under run-ahead glFinish becomes
|
||||
// exactly WaitForApplyToCatchUp + the drain that comes with it.
|
||||
void Finish();
|
||||
|
||||
// The last seq this session published, whether or not it waited for it. The forced
|
||||
// waits above are defined against it.
|
||||
Uint64 LastPublishedSeq() const;
|
||||
|
||||
// §2.4's counter, published on the stats line as `credit-waits`: how often the client
|
||||
// actually blocked for a swap to come back. Zero with a credit of 1 means the server
|
||||
// is never the frame's critical path; a number close to the frame count means the
|
||||
// credit is what paces this workload, which is what the device exit measures.
|
||||
Uint64 PresentCreditWaits() const;
|
||||
|
||||
// §2.4, called by EmitPresent immediately before it encodes: pay the credit (parking
|
||||
// if this client already has `MOBILEGL_IPC_PRESENT_CREDIT` presents in flight), then
|
||||
// mint and return this frame's 1-based MGPPresent::FrameSerial. The credit wait is
|
||||
// BEFORE the encode on purpose: a client that encoded first would hold a SEG_CMD
|
||||
// reservation across the park.
|
||||
Uint64 AcquirePresentCredit();
|
||||
|
||||
// R-1's invariant made checkable rather than only written down: true while this
|
||||
// thread is inside a barrier wait. The apply thread sets its own flag on entry to the
|
||||
// applier; a debug/verify build asserts the two are never both true, and that the
|
||||
@@ -140,7 +204,17 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// split session is live, when the caller IS the apply thread, and when the barrier is
|
||||
// disarmed - MOBILEGL_IPC_VERB_BARRIER=0 is R-1's negative control and its red belongs
|
||||
// to Fatal{BarrierViolation}, not to this check.
|
||||
static void RefusePipeInputsTouchWhileApplierOwnsIt(const char* surface);
|
||||
//
|
||||
// P5e (ra, CONTRACT-P5E §3.5) RE-DERIVES IT UNDER RUN-AHEAD, and `isBarrieredFill` is
|
||||
// what the caller says about ITSELF: "this touch is the residual fill of a record this
|
||||
// thread is about to park behind". With run-ahead armed the block is server-role
|
||||
// memory for every other touch, so the rule stops being "not while the applier is
|
||||
// inside" - which is unanswerable when the client never waits - and becomes "not at
|
||||
// all, unless you are that fill". The MOBILEGL_IPC_BATCH_WAITS early return goes with
|
||||
// it: batching is about how many round trips a lockstep client pays, and it says
|
||||
// nothing about a client that pays none.
|
||||
static void RefusePipeInputsTouchWhileApplierOwnsIt(const char* surface,
|
||||
Bool isBarrieredFill = false);
|
||||
|
||||
// ---- c1's additions ---------------------------------------------------------------
|
||||
|
||||
@@ -250,9 +324,20 @@ namespace MobileGL::MG_Remote::Client {
|
||||
void LogWireLedger() const;
|
||||
|
||||
private:
|
||||
// P5e (ra): the latch, taken from PumpControlPlane after every adoption. Private
|
||||
// because "when may run-ahead start" is this class's own rule and not a caller's.
|
||||
void LatchRunAheadFromCaps();
|
||||
|
||||
Wire::PipeWireEncoder m_encoder;
|
||||
Wire::SegmentTable m_segments;
|
||||
Bool m_barrierArmed = true;
|
||||
// P5e (ra): the latch of RunAheadArmed() and the fact that it has been taken once.
|
||||
Bool m_runAheadArmed = false;
|
||||
Bool m_runAheadLatched = false;
|
||||
// §2.4: presents published (the 1-based FrameSerial space) and how often the credit
|
||||
// wait really blocked.
|
||||
Uint64 m_presentsSent = 0;
|
||||
Uint64 m_presentCreditWaits = 0;
|
||||
|
||||
std::unique_ptr<Transport::InProcessTransport> m_clientTransport;
|
||||
std::unique_ptr<Transport::InProcessTransport> m_serverTransport;
|
||||
|
||||
@@ -382,8 +382,39 @@ namespace MobileGL::MG_Remote::Client {
|
||||
nullptr, 0, nullptr, 0, nullptr);
|
||||
}
|
||||
|
||||
// P5e (vi), ID-82: declared here because the REDUCED DrawArrays path below predates the
|
||||
// nineteen-slot block that defines them, and it needs the same two answers. One
|
||||
// definition each, further down, beside the rest of the draw plan.
|
||||
[[noreturn]] void RefuseDrawByName(const char* slot, const char* qualifier);
|
||||
Bool RunAheadWouldSkipTheWait(ClientSession& session);
|
||||
|
||||
// Does the bound VAO fetch any ENABLED attribute out of the application's own memory.
|
||||
// The test is EmitVertexBuffers' own (`attrib.Enabled && !attrib.Buffer` is exactly what
|
||||
// it publishes as Res == kMGPipeNullHandle), so the flag on the wire and the record the
|
||||
// server applies agree by construction.
|
||||
Bool BoundVaoHasClientVertexArrays(MG_State::GLState::GLContext* ctx) {
|
||||
if (ctx == nullptr) return false;
|
||||
const auto& vao = ctx->GetBoundVertexArray();
|
||||
if (!vao) return false;
|
||||
const auto& attributes = vao->GetAllAttributes();
|
||||
for (SizeT i = 0; i < attributes.size(); ++i) {
|
||||
if (attributes[i].Enabled && !attributes[i].Buffer) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void EmitDrawArrays(GLenum mode, GLint first, GLsizei count) {
|
||||
ClientSession& session = RequireSession("DrawArrays");
|
||||
|
||||
// P5e (vi): the same refusal the nineteen-slot block raises in EmitDrawRecord, and
|
||||
// this is the entry point the contract names by name - "DrawArrays+CLIENT_ARRAYS".
|
||||
// The probe runs only on this path's own draw, before the hooks, and it is inert
|
||||
// under lockstep (see RunAheadWouldSkipTheWait).
|
||||
const Bool clientArrays = BoundVaoHasClientVertexArrays(MG_State::pGLContext.get());
|
||||
if (clientArrays && RunAheadWouldSkipTheWait(session)) {
|
||||
RefuseDrawByName("DrawArrays", "CLIENT_ARRAYS");
|
||||
}
|
||||
|
||||
BeforeDrawVerb();
|
||||
|
||||
if (g_dropDrawEmission) {
|
||||
@@ -399,7 +430,10 @@ namespace MobileGL::MG_Remote::Client {
|
||||
MG_Pipe::MGPDrawInfo info{};
|
||||
info.Mode = static_cast<Uint32>(mode);
|
||||
info.IndexSize = 0; // arrays
|
||||
info.Flags = 0; // NO kDrawHasUserIndices: the reduced path draws from a VBO
|
||||
// NO kDrawHasUserIndices: the reduced path draws from a VBO. kDrawClientArrays IS
|
||||
// set when one is present, because the wait rule is computed from the record on
|
||||
// both sides and this path publishes its own record rather than PlanDrawInfo's.
|
||||
info.Flags = clientArrays ? static_cast<Uint8>(MG_Pipe::kDrawClientArrays) : 0;
|
||||
info.InstanceCount = 1;
|
||||
info.StartInstance = 0;
|
||||
info.RestartIndex = 0;
|
||||
@@ -446,6 +480,27 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// indices (or past 2^32 of them): the record spells Start in
|
||||
// indices, and rounding would draw from the wrong element.
|
||||
|
||||
// P5e (vi), ID-82 / CONTRACT-P5E §5.1: "would this session publish a draw and move on".
|
||||
//
|
||||
// IT IS THE CONJUNCTION MGPipeTypes.h STATES FOR RunAheadArmed(), spelled here rather
|
||||
// than called, and that is a SEAM, not a duplication: ClientSession::RunAheadArmed() is
|
||||
// package ra's to land (it latches the same three at the first caps adoption after Start
|
||||
// and may afterwards only turn OFF). Until it exists this is the same answer computed
|
||||
// from the same three inputs, and it is inert for the whole phase because the third one
|
||||
// - the server's kCapRunAheadApply - is not published until the integration commit
|
||||
// (kMGPipeP5eRunAheadReady). WHEN ra LANDS, THIS BODY BECOMES `session.RunAheadArmed()`:
|
||||
// one latch, one answer, and no way for the refusal to disagree with the wait rule about
|
||||
// which arm the session is on.
|
||||
Bool RunAheadWouldSkipTheWait(ClientSession& session) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
return session.BarrierArmed() && MG_Config::Ipc.RunAhead != 0 &&
|
||||
session.Caps().HasCap(MG_Pipe::kCapRunAheadApply);
|
||||
#else
|
||||
(void)session;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
[[noreturn]] void RefuseDrawByName(const char* slot, const char* qualifier) {
|
||||
char name[96];
|
||||
std::snprintf(name, sizeof(name), "%s+%s", slot, qualifier);
|
||||
@@ -465,6 +520,19 @@ namespace MobileGL::MG_Remote::Client {
|
||||
b.ElementBufferBound = true;
|
||||
b.ElementBuffer = MG_Pipe::MGPipeResourceTrackerInstance().Find(*bound);
|
||||
}
|
||||
// P5e (vi): the client-array probe, in the SAME single read of the bindings the
|
||||
// rest of the plan is made from rather than in a second walk at the refusal -
|
||||
// this runs on the GL thread once per draw and the refusal must not add its own
|
||||
// frontend pass. The test is the emitter's own: EmitVertexBuffers publishes
|
||||
// Res == kMGPipeNullHandle for exactly `attrib.Enabled && !attrib.Buffer`, so
|
||||
// the flag and the record agree by construction instead of by inspection.
|
||||
const auto& attributes = vao->GetAllAttributes();
|
||||
for (SizeT i = 0; i < attributes.size(); ++i) {
|
||||
if (attributes[i].Enabled && !attributes[i].Buffer) {
|
||||
b.ClientVertexArrays = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (const auto& di = ctx->GetBufferBindingSlot(::MobileGL::BufferTarget::DrawIndirect).GetBoundObject()) {
|
||||
b.DrawIndirectBuffer = MG_Pipe::MGPipeResourceTrackerInstance().Find(*di);
|
||||
@@ -486,6 +554,24 @@ namespace MobileGL::MG_Remote::Client {
|
||||
const void* clientIndices, Uint64 clientIndexBytes,
|
||||
const MG_Pipe::MGPDrawIndirect* indirect) {
|
||||
ClientSession& session = RequireSession(slot);
|
||||
|
||||
// P5e (vi), ID-82 / ruling 2, BEFORE the pre-verb hooks and before the record: a
|
||||
// draw that fetches vertices out of the application's own memory has no wire form,
|
||||
// and under run-ahead the server would dereference a client pointer into memory
|
||||
// this thread is already past. It is refused BY NAME on the GL thread, in the
|
||||
// shape ID-57 gives every unmigrated draw shape, rather than rendered wrong (R-4).
|
||||
//
|
||||
// Under LOCKSTEP it is not refused and nothing here changes: the client is parked
|
||||
// in WaitForApplied for exactly this record, so the server's upload reads memory
|
||||
// that is not moving - which is ruling 4's "barriered records keep P5C's
|
||||
// semantics", and is why this is a run-ahead gate and not a transport gate.
|
||||
// Staging the bytes as a per-attribute {BindingIndex, MGHostSpan} tail, shaped like
|
||||
// kDrawHasUserIndices, is P8's and retires the refusal with it.
|
||||
if ((info.Flags & static_cast<Uint8>(MG_Pipe::kDrawClientArrays)) != 0 &&
|
||||
RunAheadWouldSkipTheWait(session)) {
|
||||
RefuseDrawByName(slot, "CLIENT_ARRAYS");
|
||||
}
|
||||
|
||||
BeforeDrawVerb();
|
||||
|
||||
if (g_dropDrawEmission) {
|
||||
@@ -1003,6 +1089,17 @@ namespace MobileGL::MG_Remote::Client {
|
||||
MG_Util::PipeStats::PublishGauge(Gauge::RingWrapPads, encoder.CmdWrapPads());
|
||||
MG_Util::PipeStats::PublishGauge(Gauge::RingWaits, encoder.StageReclaimWaits());
|
||||
|
||||
// P5d round 3's wait ledger, CLIENT HALF, and it rides this frame boundary for
|
||||
// the same two reasons the five above it do: the producer keeps both as run
|
||||
// totals, so it is two relaxed stores per frame rather than two per wait, and
|
||||
// publishing before the present record means the first summary line of a run
|
||||
// carries real numbers instead of two zeroes that mean "not published yet".
|
||||
// The SERVER half is published by the apply thread from its own loop - rule E
|
||||
// does not let this thread read ServerLoop's counters.
|
||||
const Transport::SessionProducer& producer = session.Producer();
|
||||
MG_Util::PipeStats::PublishGauge(Gauge::ClientWaits, producer.Waits());
|
||||
MG_Util::PipeStats::PublishGauge(Gauge::ClientParks, producer.Parks());
|
||||
|
||||
// AND THE ROW, WHENEVER THE MAXIMUM MOVES. The summary line can carry the
|
||||
// number but not the name - MG_Util is below MG_Remote and has no WireOpName -
|
||||
// and the name is the actionable half: R-10 makes the integrator choose between
|
||||
@@ -1023,10 +1120,20 @@ namespace MobileGL::MG_Remote::Client {
|
||||
}
|
||||
|
||||
MG_Pipe::MGPPresent record{};
|
||||
// FrameSerial 0 = "the server stamps its own". P5 has no client-side present credit
|
||||
// (MOBILEGL_IPC_PRESENT_CREDIT is P6's), so a client-minted serial would be a second
|
||||
// id space with no consumer.
|
||||
record.FrameSerial = 0;
|
||||
// P5e (ra, CONTRACT-P5E §1, §2.4). FrameSerial USED TO BE 0 - "the server stamps
|
||||
// its own" - and that was honest while nothing paced on it. It is now minted here,
|
||||
// 1-based, by AcquirePresentCredit, which also PAYS the credit: if this client
|
||||
// already has MOBILEGL_IPC_PRESENT_CREDIT presents in flight it parks until the
|
||||
// server's OnPresent returns one, and only then does it mint.
|
||||
//
|
||||
// THE CREDIT WAIT IS BEFORE THE ENCODE, WHICH IS NOT A DETAIL: EmitAndWait
|
||||
// reserves SEG_CMD bytes as its first act, so a client that encoded and then
|
||||
// parked would hold a ring reservation across a whole frame of server time. It
|
||||
// also drains SEG_EVENT on its way out, like every other wait (§2.6).
|
||||
//
|
||||
// With run-ahead disarmed this is a counter and nothing else, and the record below
|
||||
// travels exactly as it did - the present row's own barrier is the pacing there.
|
||||
record.FrameSerial = session.AcquirePresentCredit();
|
||||
session.EmitAndWait(MG_Pipe::MGPWireOp::Present, &record, sizeof(record), nullptr, 0,
|
||||
nullptr, 0, nullptr);
|
||||
|
||||
@@ -1842,6 +1949,13 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// on its side). kDrawHasUserIndices / kDrawIsIndirect are added by the emission itself,
|
||||
// kDrawHasIndexRange by the two DrawRangeElements* callers.
|
||||
info.Flags = bindings.PrimitiveRestart ? static_cast<Uint8>(MG_Pipe::kDrawPrimitiveRestart) : 0;
|
||||
// P5e (vi), CONTRACT-P5E §2.1 (ii) / §5.1. On the wire BECAUSE the server needs it: the
|
||||
// barriered predicate is computed identically by both roles from the record alone, and
|
||||
// "does this draw fetch from client memory" is not derivable from anything else in it -
|
||||
// a null Res inside the vertex-buffer window is also what a DISABLED attribute below
|
||||
// the high-water mark publishes. Set for every draw shape, not just the array ones: a
|
||||
// glDrawElements can fetch its VERTICES from client memory too.
|
||||
if (bindings.ClientVertexArrays) info.Flags |= static_cast<Uint8>(MG_Pipe::kDrawClientArrays);
|
||||
// A negative count has already been refused by the frontend (INVALID_VALUE); 0 crosses
|
||||
// as 0 and draws nothing, which is what the driver does with it.
|
||||
info.InstanceCount = instanceCount > 0 ? static_cast<Uint32>(instanceCount) : 0u;
|
||||
|
||||
@@ -187,6 +187,16 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// carried verbatim (informational in P5b: the backend reads its own barrier-pulled copy).
|
||||
Bool PrimitiveRestart = false;
|
||||
Uint32 RestartIndex = 0;
|
||||
// P5e (vi), ID-82 / CONTRACT-P5E §5.1: TRUE when the bound VAO has at least one ENABLED
|
||||
// attribute with no buffer object behind it, i.e. an array whose vertices live in the
|
||||
// application's own memory. The server has no such memory: today it dereferences
|
||||
// `attrib.Offset` as a raw client pointer from the apply thread
|
||||
// (Managers.cpp's SyncClientSideAttributesForDrawArrays), which is legal only while the
|
||||
// client is parked behind the record. It rides in MGPDrawInfo::Flags as kDrawClientArrays
|
||||
// so BOTH roles can decide from the wire - the client refuses such a draw under
|
||||
// run-ahead, and MGPipeBarriered's escalation (ii) keeps it barriered if one ever
|
||||
// arrives anyway. Staging the bytes is P8's.
|
||||
Bool ClientVertexArrays = false;
|
||||
};
|
||||
|
||||
// 1 / 2 / 4 for the three GL index types, 0 for anything else (the frontend has already
|
||||
|
||||
@@ -87,14 +87,29 @@ namespace MobileGL::MG_Remote::Client {
|
||||
if (!context) return;
|
||||
// The backend keeps a bitset of writable image-buffer units
|
||||
// (DirectGLES.cpp:2350-2352, maintained from its own SyncImageTextureBinding) and
|
||||
// the client has no equivalent, so it sweeps. The sweep is bounded by the array,
|
||||
// not by a device limit read: MaxImageUnits would be a backend read, and a stale
|
||||
// or absent backend object would silently shorten the walk - which is the one
|
||||
// direction this set may not fail in. The loop body is a null test on a
|
||||
// contiguous array until a unit is actually bound. P5 records cost and does not
|
||||
// gate on it (2026-09-08 rule); an image-unit high-water mark on GLContext is the
|
||||
// obvious narrowing and belongs with P8's binding-walk migration.
|
||||
for (Int unit = 0; unit < MG_State::GLState::TextureState::MAX_TEXTURE_IMAGE_UNITS; ++unit) {
|
||||
// the client has no equivalent, so it sweeps. The sweep is NOT bounded by a device
|
||||
// limit read: MaxImageUnits would be a backend read, and a stale or absent backend
|
||||
// object would silently shorten the walk - which is the one direction this set may
|
||||
// not fail in.
|
||||
//
|
||||
// IT IS BOUNDED BY THE FRONTEND's OWN IMAGE-UNIT HIGH-WATER MARK (P5d round 3,
|
||||
// package C). The paragraph that stood here said the narrowing "belongs with P8's
|
||||
// binding-walk migration"; the 2026-09-17 inproc profile moved it forward -
|
||||
// MarkWritableImageBufferTextures was 2.15% self / 3.59% inclusive of the GL thread
|
||||
// (GetImageTextureBinding 1.37 of it) at ~852 draws/frame, in a workload that never
|
||||
// binds an image at all, purely because the walk was MAX_TEXTURE_IMAGE_UNITS (192)
|
||||
// units wide unconditionally - 192 GetImageTextureBinding reads per draw for a
|
||||
// context that has never bound one.
|
||||
//
|
||||
// AND THE MARK IS SAFE IN THE ONLY DIRECTION THAT MATTERS. It is written by
|
||||
// glBindImageTexture itself (GL_Texture.cpp, TextureState::NoteImageUnitTouched) and
|
||||
// it only ever grows - an unbind, a delete-unbind, a context that stops using an
|
||||
// image unit all leave it where it was - so `unit <= mark` can only be WIDER than
|
||||
// the set of units that hold a binding, never narrower. -1 means no image unit has
|
||||
// ever been bound in this context, and then this is one compare.
|
||||
const Int highest = context->GetMaxTouchedImageUnit();
|
||||
for (Int unit = 0; unit <= highest && unit < MG_State::GLState::TextureState::MAX_TEXTURE_IMAGE_UNITS;
|
||||
++unit) {
|
||||
const auto& binding = context->GetImageTextureBinding(unit);
|
||||
if (!ImageUnitIsAWritableBufferTexture(binding)) continue;
|
||||
auto* textureBuffer = static_cast<MG_State::GLState::TextureObjectBuffer*>(binding.Texture.get());
|
||||
|
||||
@@ -62,6 +62,15 @@ namespace MobileGL::MG_Remote::Client {
|
||||
constexpr SizeT kMaxTrackedMaps = 64;
|
||||
constexpr SizeT kPageShift = 12;
|
||||
constexpr SizeT kPageBytes = 1u << kPageShift;
|
||||
// THE PAGE-GRANULAR SHADOW IS THE TRACKER'S PRECONDITION, NOT A COINCIDENCE. Every
|
||||
// shadow a split build hands out is SHADOW_ALLOCATION_ALIGNMENT-aligned AND sized to
|
||||
// a multiple of it (PipeResource.h, ShadowAllocationBytesFor), so a shadow owns every
|
||||
// byte of every page it touches; the outward alignment in TrackWriteMap rests on
|
||||
// that, and it is only true when the allocator's unit is a whole number of the
|
||||
// tracker's pages.
|
||||
static_assert(MG_State::GLState::SHADOW_ALLOCATION_ALIGNMENT % kPageBytes == 0,
|
||||
"the shadow allocator's granule must be a whole number of tracker pages, "
|
||||
"or a page-granular shadow could still end mid-page");
|
||||
// The bitmap is FIXED-CAPACITY and never reallocated: a handler mid-flight on
|
||||
// another thread can hold the pointer it loaded before a retire, so a grow-and-free
|
||||
// would be a use-after-free no memory ordering can close. 64 K pages = 256 MB per
|
||||
@@ -76,10 +85,16 @@ namespace MobileGL::MG_Remote::Client {
|
||||
TrackedWriteMap g_trackedMaps[kMaxTrackedMaps];
|
||||
struct sigaction g_prevSegvAction {};
|
||||
std::atomic<Bool> g_segvInstalled{false};
|
||||
// Bumped by the handler for every write fault it answers. PushDrawConsumers
|
||||
// compares it against the GL thread's last-walk value: an unmoved epoch proves
|
||||
// no interior byte of any tracked map changed, because interior dirtiness can
|
||||
// only ever arrive through a fault.
|
||||
// Bumped by the handler for every write fault it answers, and by TrackWriteMap
|
||||
// for every registration (a fresh slot has EVERY page marked, which is a fault of
|
||||
// every page as far as the push is concerned). PushDrawConsumers compares it
|
||||
// against the GL thread's last-walk value: an unmoved epoch proves no page of any
|
||||
// tracked map was marked since the last walk, because a mark can only ever arrive
|
||||
// through one of those two events - and the walk drains every marked page of
|
||||
// every tracked member, which is what makes the proof worth having. The bump is a
|
||||
// RELEASE and the walk's load an ACQUIRE, so the bit the handler set before it
|
||||
// bumped is visible to a walk that saw the bump; a chunk builder writing an arena
|
||||
// off the GL thread is the ordinary case, not a corner.
|
||||
std::atomic<Uint64> g_faultEpoch{0};
|
||||
|
||||
// THE OWNERSHIP TESTS. "Ours" is a NARROW claim, and every fault that fails any
|
||||
@@ -200,11 +215,13 @@ namespace MobileGL::MG_Remote::Client {
|
||||
void PersistentWriteFaultHandler(int sig, siginfo_t* info, void* ucontext) {
|
||||
if (info != nullptr && info->si_code == SEGV_ACCERR) {
|
||||
const uintptr_t address = reinterpret_cast<uintptr_t>(info->si_addr);
|
||||
// EVERY overlapping slot gets its bit, not just the first: two tracked
|
||||
// shadows can share an edge page (separate heap allocations, one page
|
||||
// granularity), and unprotecting after only the first mark would leave the
|
||||
// second buffer's block permanently un-pushed - the page is writable now,
|
||||
// so it never faults again.
|
||||
// EVERY overlapping slot gets its bit, not just the first: unprotecting
|
||||
// after only the first mark would leave a second owner's block permanently
|
||||
// un-pushed - the page is writable now, so it never faults again. With
|
||||
// page-granular shadows no two tracked ranges can share a page any more
|
||||
// (each protected page is one shadow's own), so the loop finds at most one
|
||||
// owner; it stays in this form because a fault is rare and the exhaustive
|
||||
// scan is what makes the claim checkable rather than assumed.
|
||||
Bool matched = false;
|
||||
Bool bitWasSet = false;
|
||||
for (SizeT i = 0; i < kMaxTrackedMaps; ++i) {
|
||||
@@ -227,8 +244,10 @@ namespace MobileGL::MG_Remote::Client {
|
||||
if (matched &&
|
||||
!RefaultOfANonWriteAccess(FaultPcFrom(ucontext), address, bitWasSet)) {
|
||||
// The epoch moves BEFORE the unprotect: a walk that starts the
|
||||
// moment the page becomes writable must still see this fault.
|
||||
g_faultEpoch.fetch_add(1, std::memory_order_relaxed);
|
||||
// moment the page becomes writable must still see this fault. And it
|
||||
// moves with RELEASE, after the bit: a walk that acquires the moved
|
||||
// epoch is guaranteed to see the bit that goes with it.
|
||||
g_faultEpoch.fetch_add(1, std::memory_order_release);
|
||||
// Un-arm is a raw syscall, deliberately not the libc wrapper's
|
||||
// bookkeeping: the handler's whole job is to get out of the way.
|
||||
mprotect(reinterpret_cast<void*>(address & ~(kPageBytes - 1)),
|
||||
@@ -239,7 +258,32 @@ namespace MobileGL::MG_Remote::Client {
|
||||
ChainToPreviousSegvHandler(sig, info, ucontext);
|
||||
}
|
||||
|
||||
// THE KERNEL'S PAGE MUST BE THE TRACKER'S PAGE. Every ownership argument here -
|
||||
// above all "a protected page holds only this shadow's bytes" - is made at
|
||||
// kPageBytes granularity, and mprotect protects at the KERNEL's. On a 16 KB-page
|
||||
// kernel (Android 15 admits them) a kPageBytes mprotect would silently cover
|
||||
// three neighbouring 4 KB quarters that may be foreign memory, which is exactly
|
||||
// the process-killer the page-granular shadow exists to keep out. So on such a
|
||||
// kernel the arm is not installed at all and every persistent write map takes
|
||||
// the hash arm: slower, never unsafe. Said once, not per map - and decided BEFORE
|
||||
// g_segvInstalled can read true to anyone: a function-static answers exactly once,
|
||||
// on whichever thread asks first, and every other asker waits on that answer, so
|
||||
// no caller can pass TrackWriteMap's installed gate while the page size is still
|
||||
// being checked.
|
||||
Bool KernelPageIsTheTrackerPage() {
|
||||
static const Bool answer = [] {
|
||||
const long kernelPage = sysconf(_SC_PAGESIZE);
|
||||
if (kernelPage == static_cast<long>(kPageBytes)) return true;
|
||||
MGLOG_W("MGPipe: persistent-map mprotect tracking unavailable (kernel page %ld "
|
||||
"is not the tracker's %zu); persistent write maps fall back to the hash scan",
|
||||
kernelPage, kPageBytes);
|
||||
return false;
|
||||
}();
|
||||
return answer;
|
||||
}
|
||||
|
||||
void InstallWriteFaultHandler() {
|
||||
if (!KernelPageIsTheTrackerPage()) return;
|
||||
Bool expected = false;
|
||||
if (!g_segvInstalled.compare_exchange_strong(expected, true)) return;
|
||||
struct sigaction action {};
|
||||
@@ -256,35 +300,81 @@ namespace MobileGL::MG_Remote::Client {
|
||||
|
||||
void UntrackWriteMap(Uint64 lifetimeId);
|
||||
|
||||
// `shadowExtent` is the shadow allocation's own size in bytes as its allocator
|
||||
// sized it (BufferObject::ShadowAllocationBytes), or 0 when the caller cannot vouch
|
||||
// for it; it is what decides between the two alignments below.
|
||||
Bool TrackWriteMap(Uint64 lifetimeId, const Uint8* shadow,
|
||||
SizeT rangeBegin, SizeT rangeEnd) {
|
||||
SizeT rangeBegin, SizeT rangeEnd, SizeT shadowExtent) {
|
||||
if (shadow == nullptr || rangeEnd <= rangeBegin) return false;
|
||||
InstallWriteFaultHandler();
|
||||
if (!g_segvInstalled.load()) return false;
|
||||
// INWARD alignment, and the reason is a process-killer: with OUTWARD
|
||||
// alignment the protected edge pages hold FOREIGN bytes (the shadow is a
|
||||
// heap allocation; malloc metadata and other allocations share its first
|
||||
// and last page). A foreign write to such a page is fine for a thread
|
||||
// that runs our handler - it is marked and unprotected - but driver and
|
||||
// runtime worker threads commonly block every signal, and a fault there
|
||||
// with SIGSEGV blocked ends the process on the spot, undebuggable.
|
||||
// Protecting only pages FULLY inside the mapped range means every byte of
|
||||
// a protected page is the shadow's own, and no other allocation can ever
|
||||
// be made to fault by us. The head/tail partial pages stay writable and
|
||||
// their blocks are pushed unconditionally at every push (at most two).
|
||||
const uintptr_t rawBegin = reinterpret_cast<uintptr_t>(shadow + rangeBegin);
|
||||
const uintptr_t rawEnd = reinterpret_cast<uintptr_t>(shadow + rangeEnd);
|
||||
uintptr_t base = (rawBegin + kPageBytes - 1) &
|
||||
~static_cast<uintptr_t>(kPageBytes - 1);
|
||||
uintptr_t end = rawEnd & ~static_cast<uintptr_t>(kPageBytes - 1);
|
||||
// A SUB-PAGE range is not refused; it is registered with an EMPTY interior
|
||||
// (no pages are protected, no bitmap is needed) and hasEdges set, so the
|
||||
// whole range is served by the two edge hashes - bounded at 8 KB per push -
|
||||
// instead of falling to the hash arm, where as an "untracked" member it
|
||||
// would veto the epoch skip for every tracked buffer in the process and
|
||||
// force the full binding walk at every draw (measured on device). end is
|
||||
// clamped up to base so the [base, end) arithmetic below never underflows.
|
||||
if (end < base) end = base;
|
||||
// WHICH WAY TO ALIGN IS A QUESTION OF OWNERSHIP, and the reason is a
|
||||
// process-killer: a protected page that holds FOREIGN bytes can be written by
|
||||
// a thread that does not run our handler - driver and runtime worker threads
|
||||
// commonly block every signal - and a fault there with SIGSEGV blocked ends the
|
||||
// process on the spot, undebuggable (the ctest-only SmallRing segfault of
|
||||
// cb06538c). So a page may be protected only when every byte of it is this
|
||||
// shadow's own, and the two alignments are the two ways of guaranteeing that:
|
||||
//
|
||||
// OUTWARD, when the shadow is PAGE-GRANULAR: its base is on a page boundary
|
||||
// and its allocation is a whole number of pages (PipeResource.h's allocator
|
||||
// promises both in a split build, and `shadowExtent` is what it promised).
|
||||
// Then every page that intersects the mapped range lies inside
|
||||
// [shadow, shadow + shadowExtent), and every byte of that span belongs to
|
||||
// this allocation and to no other - the heap handed it out as ONE block of
|
||||
// that size, and its own metadata lives before the block, never inside it.
|
||||
// The mapped range's containing pages are protected whole, there are NO
|
||||
// unprotected edge bytes, and a sub-page map is one protected page. The bytes
|
||||
// of a head/tail page that lie OUTSIDE the mapped range are still the
|
||||
// shadow's: only the client's own API paths write them (a SubData /
|
||||
// FlushMappedRange memcpy into the shadow, a readback writeback landing on
|
||||
// the client thread), on threads that run this handler, and such a fault is
|
||||
// answered like any interior one - the push then clamps to [begin, end), so
|
||||
// at worst one block ships redundantly, and the byte itself crossed by its own
|
||||
// record.
|
||||
//
|
||||
// INWARD, for anything else (an unaligned base, an extent the caller could not
|
||||
// vouch for, a range running past the extent it was told): only pages FULLY
|
||||
// inside the mapped range are protected, which are the shadow's own by
|
||||
// construction, and the head/tail partial pages stay writable. Nothing tells
|
||||
// us they changed, so they are hashed per push (the edge hashes) - which was
|
||||
// 8.5% of the client thread at VD12 on every draw for every live map, and
|
||||
// the reason the outward arm exists. A sub-page range still registers here
|
||||
// with an EMPTY interior and hasEdges set rather than falling to the hash
|
||||
// arm, where as an "untracked" member it would veto the epoch skip for every
|
||||
// tracked buffer in the process (measured on device); end is clamped up to
|
||||
// base so the [base, end) arithmetic never underflows.
|
||||
const uintptr_t shadowBase = reinterpret_cast<uintptr_t>(shadow);
|
||||
const uintptr_t rawBegin = shadowBase + rangeBegin;
|
||||
const uintptr_t rawEnd = shadowBase + rangeEnd;
|
||||
constexpr uintptr_t kPageMask = ~static_cast<uintptr_t>(kPageBytes - 1);
|
||||
const Bool pageGranular = (shadowBase & (kPageBytes - 1)) == 0 && shadowExtent != 0 &&
|
||||
(shadowExtent & (kPageBytes - 1)) == 0 && rangeEnd <= shadowExtent;
|
||||
uintptr_t base = 0;
|
||||
uintptr_t end = 0;
|
||||
Bool outward = pageGranular;
|
||||
if (outward) {
|
||||
base = rawBegin & kPageMask;
|
||||
end = (rawEnd + kPageBytes - 1) & kPageMask;
|
||||
// Already implied by rangeEnd <= shadowExtent and the extent's own page
|
||||
// granularity; the clamp is kept because it is the line the ownership
|
||||
// argument rests on, and it must not depend on a caller's arithmetic.
|
||||
if (end > shadowBase + shadowExtent) end = shadowBase + shadowExtent;
|
||||
// WIDENING NEVER DEMOTES A MAP THE INWARD ARM COULD HOLD. Outward covers up
|
||||
// to one page more than inward does for the same range (both ends rounded
|
||||
// away instead of towards), so a map sitting on the bitmap's capacity that
|
||||
// was tracked inward before this round would otherwise fall off the tracker
|
||||
// altogether - onto the hash arm, where as an untracked member it vetoes the
|
||||
// epoch skip for every buffer in the process. It keeps the inward arm and
|
||||
// its two hashed edges instead: the old cost, on the one ~256 MB map that
|
||||
// can pay it, and nothing else changes.
|
||||
if (((end - base) >> kPageShift) > kMaxTrackedPages) outward = false;
|
||||
}
|
||||
if (!outward) {
|
||||
base = (rawBegin + kPageBytes - 1) & kPageMask;
|
||||
end = rawEnd & kPageMask;
|
||||
if (end < base) end = base;
|
||||
}
|
||||
const SizeT pageCount = (end - base) >> kPageShift;
|
||||
if (pageCount > kMaxTrackedPages) {
|
||||
MGLOG_W("MGPipe: persistent write map of %zu pages exceeds the mprotect "
|
||||
@@ -309,7 +399,10 @@ namespace MobileGL::MG_Remote::Client {
|
||||
g_trackedMaps[i].lifetimeId = lifetimeId;
|
||||
g_trackedMaps[i].edgeHashHead = 0;
|
||||
g_trackedMaps[i].edgeHashTail = 0;
|
||||
g_trackedMaps[i].hasEdges = base != rawBegin || end != rawEnd;
|
||||
// Edges are UNPROTECTED mapped bytes: the range starts before the first
|
||||
// protected page or ends after the last. Outward alignment never leaves
|
||||
// any (base <= rawBegin, end >= rawEnd); inward leaves one per unaligned end.
|
||||
g_trackedMaps[i].hasEdges = base > rawBegin || end < rawEnd;
|
||||
// EVERY BIT SET, NOT ZEROED - the same "fresh state pushes everything
|
||||
// once" rule the hash arm keeps: the server has never seen these bytes,
|
||||
// so the first push must ship the whole interior, not just the pages the
|
||||
@@ -318,8 +411,9 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// does on a pre-first-push fault is answered once and unprotected -
|
||||
// harmless, and the invariant (bit set <=> writable) holds from the
|
||||
// first push onward. The last word is masked: a set bit past pageCount
|
||||
// would re-arm a page outside the interior - a foreign page, which is
|
||||
// the process-killer the inward alignment exists to keep out.
|
||||
// would re-arm a page outside the protected span - past the shadow's
|
||||
// extent, a foreign page, which is the process-killer both alignments
|
||||
// exist to keep out.
|
||||
const SizeT wordCount = (pageCount + 63) / 64;
|
||||
for (SizeT w = 0; w < wordCount; ++w) {
|
||||
const SizeT bitsInWord =
|
||||
@@ -337,6 +431,13 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// it can observe is only ever one whose end is already visible.
|
||||
g_trackedMaps[i].end.store(end, std::memory_order_release);
|
||||
g_trackedMaps[i].base.store(base, std::memory_order_release);
|
||||
// AND THE EPOCH MOVES, as it would for a fault of every page: the bits just
|
||||
// set are exactly what a fault leaves behind, and the epoch is the only thing
|
||||
// PushDrawConsumers reads before deciding it has nothing to drain. Without
|
||||
// this a member registered between two draws sits fully marked and fully
|
||||
// protected until something else faults - "first push ships everything
|
||||
// once" would then be true only of the read-only verbs' whole push.
|
||||
g_faultEpoch.fetch_add(1, std::memory_order_release);
|
||||
return true;
|
||||
}
|
||||
MGLOG_W("MGPipe: the mprotect tracker is full (%zu live persistent write maps); "
|
||||
@@ -395,6 +496,19 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Whether any page of a live slot is marked - faulted since its last push, or never
|
||||
// pushed since registration. Read on the GL thread by the consumer walk only (a
|
||||
// walk runs when the epoch moved, never per draw in steady state), and it costs
|
||||
// one word load per 64 pages: 40 loads for a 10 MB arena. A slot with an empty
|
||||
// interior (the inward fallback's sub-page case) has no words and no marks.
|
||||
Bool AnyPageMarked(const TrackedWriteMap& slot) {
|
||||
const SizeT words = (slot.pageCount + 63) / 64;
|
||||
for (SizeT w = 0; w < words; ++w) {
|
||||
if (slot.pageBits[w].load(std::memory_order_relaxed) != 0) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
PersistentMapTracker& PersistentMapTracker::Instance() {
|
||||
@@ -413,11 +527,23 @@ namespace MobileGL::MG_Remote::Client {
|
||||
return MG_Config::Transport != MG_Config::TransportMode::Monolith;
|
||||
}
|
||||
|
||||
// P5d round 3 (package D): the body this forwards to is now one relaxed load of the apply
|
||||
// thread's key and one thread-pointer compare (ServerLoop.h), instead of a function-static
|
||||
// guard, two acquire loads and an out-of-line thread::id comparison. It stays out of line
|
||||
// here for WireTables.cpp's reason beside RunsAsTheServerRole: inlining it would put a
|
||||
// server header inside PersistentMapTracker.h, which MG_State's BufferObject.cpp includes.
|
||||
Bool PersistentMapTracker::OnServerRole() { return Server::ServerLoop::OnApplyThread(); }
|
||||
|
||||
// SyncPersistentMappedRange's early-out chain (BufferObject.cpp:341-353), in its order,
|
||||
// read as a membership test. Every line here has a line there; if one of them moves, the
|
||||
// unit case that drives both against each other is what says so.
|
||||
//
|
||||
// THE ORDER IS THE CONTRACT, so package D did not touch it even though the first row is the
|
||||
// only guarded accessor in the chain (IsMapped -> RefuseLegacyBufferArmFromApplyThread) and
|
||||
// moving it last would have saved a guard on the members that fail rows 2-6. It would also
|
||||
// have stopped being the same chain as the one in BufferObject, which is the property this
|
||||
// predicate exists to have. Item 1 made that guard two loads instead, which is cheaper than
|
||||
// the reorder would have been and costs nothing in meaning.
|
||||
Bool PersistentMapTracker::IsLivePersistentMap(const BufferObject& buffer) {
|
||||
if (!buffer.IsMapped()) return false;
|
||||
// GPU-resident: the application already wrote into coherent GPU memory and there is
|
||||
@@ -445,17 +571,25 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// set must follow the arm the member actually runs on. Erase is a no-op for a
|
||||
// member that was never large-untracked.
|
||||
m_untrackedMembers.erase(key);
|
||||
m_edgedMembers.erase(key);
|
||||
if (IsLivePersistentMap(buffer)) {
|
||||
const auto range = buffer.GetMappedRange();
|
||||
// The mprotect arm registers beside the hash arm: tracked buffers are pushed
|
||||
// from the fault bitmap, everything else keeps the content scan. A failed
|
||||
// registration (handler unavailable, table full, unaligned zero range) quietly
|
||||
// leaves the buffer on the hash path.
|
||||
// leaves the buffer on the hash path. The shadow's own extent goes along so
|
||||
// the tracker can align outward (TrackWriteMap): a live member's MappedData()
|
||||
// IS the shadow vector's storage - the predicate's IsBackendPersistentMapped
|
||||
// row keeps every adopted store out - so the extent describes that pointer.
|
||||
TrackWriteMap(key, buffer.MappedData(), static_cast<SizeT>(range.start),
|
||||
static_cast<SizeT>(range.end));
|
||||
static_cast<SizeT>(range.end), buffer.ShadowAllocationBytes());
|
||||
TrackedWriteMap* slot = TrackedMapFor(key);
|
||||
m_livePersistentMaps[key] = MemberEntry{&buffer, slot};
|
||||
if (slot == nullptr) m_untrackedMembers[key] = 1;
|
||||
if (slot == nullptr) {
|
||||
m_untrackedMembers[key] = 1;
|
||||
} else if (slot->hasEdges) {
|
||||
m_edgedMembers[key] = 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
m_livePersistentMaps.erase(key);
|
||||
@@ -465,6 +599,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
void PersistentMapTracker::Forget(const BufferObject& buffer) {
|
||||
const Uint64 key = buffer.GetLifetimeId();
|
||||
m_untrackedMembers.erase(key);
|
||||
m_edgedMembers.erase(key);
|
||||
m_livePersistentMaps.erase(key);
|
||||
m_blockHashes.erase(key);
|
||||
UntrackWriteMap(key);
|
||||
@@ -474,11 +609,34 @@ namespace MobileGL::MG_Remote::Client {
|
||||
m_livePersistentMaps.clear();
|
||||
m_blockHashes.clear();
|
||||
m_untrackedMembers.clear();
|
||||
m_edgedMembers.clear();
|
||||
UntrackAllWriteMaps();
|
||||
m_lastFaultEpoch = 0;
|
||||
ResetCountersForTest();
|
||||
}
|
||||
|
||||
Bool PersistentMapTracker::MprotectArmAvailableForTest() {
|
||||
InstallWriteFaultHandler();
|
||||
return g_segvInstalled.load();
|
||||
}
|
||||
|
||||
const TrackedWriteMap* PersistentMapTracker::TrackedSlotForTest(const BufferObject& buffer) {
|
||||
return TrackedMapFor(buffer.GetLifetimeId());
|
||||
}
|
||||
|
||||
const TrackedWriteMap* PersistentMapTracker::TrackForTest(Uint64 lifetimeId, const Uint8* shadow,
|
||||
SizeT rangeBegin, SizeT rangeEnd,
|
||||
SizeT shadowExtent) {
|
||||
TrackWriteMap(lifetimeId, shadow, rangeBegin, rangeEnd, shadowExtent);
|
||||
return TrackedMapFor(lifetimeId);
|
||||
}
|
||||
|
||||
void PersistentMapTracker::UntrackForTest(Uint64 lifetimeId) { UntrackWriteMap(lifetimeId); }
|
||||
|
||||
Uint64 PersistentMapTracker::FaultEpochForTest() {
|
||||
return g_faultEpoch.load(std::memory_order_acquire);
|
||||
}
|
||||
|
||||
void PersistentMapTracker::PushBlocksFor(BufferObject& buffer) {
|
||||
if (!PushIsArmed()) return;
|
||||
if (OnServerRole()) {
|
||||
@@ -532,10 +690,12 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// 64 KB block per block that contains at least one faulted page, shipped with
|
||||
// the whole machinery of every other arm (serial bump, HasDefinedContent,
|
||||
// wire record), then the page is cleared and re-armed read-only. No scan, no
|
||||
// hash, no per-draw cost for buffers the application did not touch. The two
|
||||
// partial-page EDGE ranges beside the page-aligned interior (see TrackWriteMap's
|
||||
// inward alignment) are never protected, so nothing tells us they changed -
|
||||
// their blocks ride along on every push, at most two.
|
||||
// hash, no per-draw cost for buffers the application did not touch. A
|
||||
// page-granular shadow's protected span is the mapped range's containing pages
|
||||
// (TrackWriteMap's outward alignment), so it can start BEFORE `begin` and end
|
||||
// AFTER `end`, and the block clamp below is what keeps every push inside
|
||||
// [begin, end). Only the inward fallback has the two unprotected partial-page
|
||||
// EDGE ranges that nothing faults for; those are hashed per push, at most two.
|
||||
TrackedWriteMap* tracked = nullptr;
|
||||
if (const auto it = m_livePersistentMaps.find(buffer.GetLifetimeId());
|
||||
it != m_livePersistentMaps.end() && it->second.tracked != nullptr &&
|
||||
@@ -547,10 +707,11 @@ namespace MobileGL::MG_Remote::Client {
|
||||
const uintptr_t trackedEnd = tracked->end.load(std::memory_order_acquire);
|
||||
const uintptr_t shadowBase = reinterpret_cast<uintptr_t>(buffer.MappedData());
|
||||
if (trackedBase != 0 && trackedEnd > trackedBase && shadowBase != 0) {
|
||||
const Uint64 interiorBegin =
|
||||
static_cast<Uint64>(trackedBase - shadowBase); // >= begin
|
||||
const Uint64 interiorEnd =
|
||||
static_cast<Uint64>(trackedEnd - shadowBase); // <= end
|
||||
// The protected span in buffer offsets: <= begin / >= end when aligned
|
||||
// outward, >= begin / <= end when aligned inward. Both are read below only
|
||||
// to find the inward fallback's edges; the page loop never needs them.
|
||||
const Uint64 interiorBegin = static_cast<Uint64>(trackedBase - shadowBase);
|
||||
const Uint64 interiorEnd = static_cast<Uint64>(trackedEnd - shadowBase);
|
||||
// Pushes are made in ASCENDING offset order, and `pushedUpTo` trims each
|
||||
// span against the one before it: edge spans, duplicate pages inside one
|
||||
// 64 KB block and faulted blocks overlapping an edge all collapse to one
|
||||
@@ -561,7 +722,12 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// And an edge span ships ONLY when its bytes changed since the last push
|
||||
// (the struct comment says why unconditional was measured and rejected):
|
||||
// no faults happen on unprotected bytes, so the hash is the only change
|
||||
// detector there is for them.
|
||||
// detector there is for them. The two conditions below are self-gating:
|
||||
// under outward alignment interiorBegin <= begin and interiorEnd >= end,
|
||||
// so neither hash runs for a page-granular shadow - every shadow in steady
|
||||
// state - and that, not a flag, is what took the per-draw XXH3 off the
|
||||
// client thread. hasEdges is the same fact recorded at registration for
|
||||
// the epoch skip's benefit, not a second gate here.
|
||||
Uint64 pushedUpTo = begin;
|
||||
const auto pushSpan = [&](Uint64 spanBegin, Uint64 spanEnd) {
|
||||
if (spanBegin < pushedUpTo) spanBegin = pushedUpTo;
|
||||
@@ -609,11 +775,15 @@ namespace MobileGL::MG_Remote::Client {
|
||||
mprotect(reinterpret_cast<void*>(trackedBase + (pageIndex << kPageShift)),
|
||||
(runEnd - pageIndex) << kPageShift, PROT_READ);
|
||||
for (SizeT runPage = pageIndex; runPage < runEnd; ++runPage) {
|
||||
// The interior was page-aligned INSIDE the mapped range at
|
||||
// registration, so a faulted page's offset in buffer space is
|
||||
// never negative; its containing block can still start before
|
||||
// `begin` (a block is 64 KB, a page is 4 KB), and the clamp is
|
||||
// what keeps the push inside [begin, end).
|
||||
// A faulted page's offset in buffer space is never negative
|
||||
// (the span starts at or after the shadow base either way),
|
||||
// but under outward alignment the head page can start before
|
||||
// `begin` and the tail page runs past `end`; and a containing
|
||||
// block starts before `begin` in any case (a block is 64 KB, a
|
||||
// page is 4 KB). The clamp is what keeps the push inside
|
||||
// [begin, end): a write to the shadow's own bytes outside the
|
||||
// mapped range faults here too and ships, at worst, one block
|
||||
// of the range redundantly.
|
||||
const Uint64 pageOffset =
|
||||
(trackedBase + (runPage << kPageShift)) - shadowBase;
|
||||
const Uint64 blockFloor = (pageOffset / blockBytes) * blockBytes;
|
||||
@@ -709,46 +879,56 @@ namespace MobileGL::MG_Remote::Client {
|
||||
std::abort();
|
||||
}
|
||||
if (m_livePersistentMaps.empty()) return;
|
||||
// THE EPOCH SKIP. Interior dirtiness can only arrive as a write fault, and the
|
||||
// handler bumps the fault epoch for every one it answers before it unprotects;
|
||||
// an unmoved epoch therefore proves no interior byte of any tracked map changed
|
||||
// since the last walk. The skip still serves a tracked member's partial-page
|
||||
// edge spans right here, per member, with no binding state read at all - they
|
||||
// are never protected, so their two spans are hashed per push. An untracked
|
||||
// (hash-arm) member vetoes the skip outright: only the binding walk knows
|
||||
// whether this draw consumes it, and scanning every untracked member on faith
|
||||
// measured strictly worse than the walk (VD12, on device). With none present
|
||||
// and the epoch unmoved, nearly every draw in steady flight costs a handful of
|
||||
// 4 KB edge hashes.
|
||||
// THE EPOCH SKIP, AND WHAT IT RESTS ON. A page of a tracked map is marked by
|
||||
// exactly two events - the handler answering a write fault, and TrackWriteMap
|
||||
// setting every bit of a fresh slot - and both move the fault epoch after the
|
||||
// mark. An unmoved epoch therefore proves no page of any tracked map was marked
|
||||
// since the last walk. That is only the whole answer if the last walk DRAINED
|
||||
// every marked page there was, and it does: the walk below pushes every tracked
|
||||
// member with a marked page whether or not this draw consumes it (see there).
|
||||
// Before this round the skip's per-member edge service did that drain by
|
||||
// accident - it ran PushBlocksForChecked, bitmap walk included, on every member
|
||||
// with edges, and nearly every member had edges; with page-granular shadows no
|
||||
// member has, so the drain has to be where the argument says it is. With every
|
||||
// byte of every tracked map protected (TrackWriteMap's outward alignment) the
|
||||
// skip then costs one atomic load and two empties. The one exception is a
|
||||
// member on the inward fallback, whose unprotected edge spans are served right
|
||||
// here, per such member, with no binding state read at all - the m_edgedMembers
|
||||
// set is exactly those and is empty in steady state. An untracked (hash-arm)
|
||||
// member vetoes the skip outright: only the binding walk knows whether this draw
|
||||
// consumes it, and scanning every untracked member on faith measured strictly
|
||||
// worse than the walk (VD12, on device).
|
||||
const Uint64 epoch = g_faultEpoch.load(std::memory_order_acquire);
|
||||
if (m_untrackedMembers.empty() && epoch == m_lastFaultEpoch) {
|
||||
for (const auto& entry : m_livePersistentMaps) {
|
||||
BufferObject* member = entry.second.buffer;
|
||||
if (member == nullptr) continue;
|
||||
// The cached slot pointer, validated against the slot's own lifetimeId:
|
||||
// a slot retired since the cache was written fails the test, as does one
|
||||
// re-claimed by a different buffer.
|
||||
const TrackedWriteMap* tracked = entry.second.tracked;
|
||||
if (tracked != nullptr && tracked->lifetimeId == member->GetLifetimeId() &&
|
||||
tracked->hasEdges) {
|
||||
PushBlocksForChecked(*member);
|
||||
if (!m_edgedMembers.empty()) {
|
||||
// Keys copied out first: PushBlocksForChecked can Forget() a member that
|
||||
// stopped being one, and ska::flat_hash_map invalidates on erase.
|
||||
Vector<Uint64> edged;
|
||||
edged.reserve(m_edgedMembers.size());
|
||||
for (const auto& entry : m_edgedMembers) edged.push_back(entry.first);
|
||||
for (const Uint64 key : edged) {
|
||||
const auto it = m_livePersistentMaps.find(key);
|
||||
if (it == m_livePersistentMaps.end() || it->second.buffer == nullptr) continue;
|
||||
// The cached slot pointer, validated against the slot's own
|
||||
// lifetimeId: a slot retired since the cache was written fails the
|
||||
// test, as does one re-claimed by a different buffer.
|
||||
const TrackedWriteMap* tracked = it->second.tracked;
|
||||
if (tracked != nullptr && tracked->lifetimeId == key && tracked->hasEdges) {
|
||||
PushBlocksForChecked(*it->second.buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
// Taken BEFORE the drain, on purpose: a fault landing while the drain runs moves
|
||||
// the epoch past this value, and the next draw walks again for it.
|
||||
m_lastFaultEpoch = epoch;
|
||||
const auto& ctx = MG_State::pGLContext;
|
||||
if (ctx == nullptr) return;
|
||||
|
||||
// The buffers the upcoming draw or dispatch can read, and only those. Every one is
|
||||
// named by the frontend's own binding state, read on this (the GL) thread - VAO
|
||||
// attribute and element buffers, the indexed binding points of every indexed
|
||||
// target, and the indirect / parameter slots. Client-sourced attributes (no
|
||||
// BufferObject) live on this side already and need no push.
|
||||
// The buffers this walk pushes: every tracked member with a marked page, and the
|
||||
// buffers the upcoming draw or dispatch can read. One entry per buffer, not per
|
||||
// binding point: an arena bound to six attribute slots would otherwise get its
|
||||
// predicate re-check, bitmap walk and edge hashes run six times per draw.
|
||||
Vector<BufferObject*> consumers;
|
||||
// One entry per buffer, not per binding point: an arena bound to six attribute
|
||||
// slots would otherwise get its predicate re-check, bitmap walk and edge hashes
|
||||
// run six times per draw.
|
||||
const auto consume = [&consumers](BufferObject* buffer) {
|
||||
if (buffer == nullptr) return;
|
||||
for (const BufferObject* existing : consumers) {
|
||||
@@ -756,57 +936,91 @@ namespace MobileGL::MG_Remote::Client {
|
||||
}
|
||||
consumers.push_back(buffer);
|
||||
};
|
||||
if (const auto& vao = ctx->GetBoundVertexArray()) {
|
||||
for (Uint i = 0; i < MG_Pipe::kMGPipeMaxVertexAttribs; ++i) {
|
||||
const auto& attrib = vao->GetAttribute(i);
|
||||
if (attrib.Enabled && attrib.Buffer != nullptr) {
|
||||
consume(attrib.Buffer.get());
|
||||
}
|
||||
}
|
||||
if (const auto& element = vao->GetIndexBufferBindingSlot().GetBoundObject()) {
|
||||
consume(element.get());
|
||||
|
||||
// THE DRAIN THE SKIP RESTS ON: every tracked member with a marked page, whether
|
||||
// or not this draw consumes it. The epoch says "some page of some tracked map was
|
||||
// marked" and nothing about which; pushing only the consumers would advance the
|
||||
// watermark past a mark on a buffer the draw did not bind, and that buffer would
|
||||
// then never move the epoch again (its faulted page is writable, its bit is set,
|
||||
// nothing re-arms it) - the next draw that DOES consume it would skip, and the
|
||||
// server would draw stale bytes. Such a push is bitmap-driven, so it ships only
|
||||
// the faulted blocks, not the range: the cost the consumer filter exists to avoid
|
||||
// is the whole-range rescan of the hash arm, which no tracked member pays. The
|
||||
// cached slot pointer is validated against the slot's own lifetimeId: a slot
|
||||
// retired since the cache was written fails the test, as does one re-claimed by
|
||||
// a different buffer.
|
||||
for (const auto& entry : m_livePersistentMaps) {
|
||||
const TrackedWriteMap* tracked = entry.second.tracked;
|
||||
if (tracked != nullptr && tracked->lifetimeId == entry.first && AnyPageMarked(*tracked)) {
|
||||
consume(entry.second.buffer);
|
||||
}
|
||||
}
|
||||
static constexpr BufferTarget kIndexedTargets[] = {
|
||||
BufferTarget::Uniform, BufferTarget::ShaderStorage, BufferTarget::AtomicCounter,
|
||||
BufferTarget::TransformFeedback, BufferTarget::CopyRead, BufferTarget::CopyWrite,
|
||||
BufferTarget::Query, BufferTarget::Texture};
|
||||
for (const BufferTarget target : kIndexedTargets) {
|
||||
const SizeT count = ctx->GetBufferBindingPointCount(target);
|
||||
for (SizeT i = 0; i < count; ++i) {
|
||||
if (const auto& bound = ctx->GetBufferBindingPoint(target, i).GetBoundObject()) {
|
||||
|
||||
// The buffers the upcoming draw or dispatch can read, and only those. Every one is
|
||||
// named by the frontend's own binding state, read on this (the GL) thread - VAO
|
||||
// attribute and element buffers, the indexed binding points of every indexed
|
||||
// target, and the indirect / parameter slots. Client-sourced attributes (no
|
||||
// BufferObject) live on this side already and need no push. This is the half of
|
||||
// the walk that serves the hash-arm (untracked) members and the inward fallback's
|
||||
// edges: nothing but a binding can say whether this draw reads them.
|
||||
if (const auto& ctx = MG_State::pGLContext) {
|
||||
if (const auto& vao = ctx->GetBoundVertexArray()) {
|
||||
for (Uint i = 0; i < MG_Pipe::kMGPipeMaxVertexAttribs; ++i) {
|
||||
const auto& attrib = vao->GetAttribute(i);
|
||||
if (attrib.Enabled && attrib.Buffer != nullptr) {
|
||||
consume(attrib.Buffer.get());
|
||||
}
|
||||
}
|
||||
if (const auto& element = vao->GetIndexBufferBindingSlot().GetBoundObject()) {
|
||||
consume(element.get());
|
||||
}
|
||||
}
|
||||
static constexpr BufferTarget kIndexedTargets[] = {
|
||||
BufferTarget::Uniform, BufferTarget::ShaderStorage, BufferTarget::AtomicCounter,
|
||||
BufferTarget::TransformFeedback, BufferTarget::CopyRead, BufferTarget::CopyWrite,
|
||||
BufferTarget::Query, BufferTarget::Texture};
|
||||
for (const BufferTarget target : kIndexedTargets) {
|
||||
const SizeT count = ctx->GetBufferBindingPointCount(target);
|
||||
for (SizeT i = 0; i < count; ++i) {
|
||||
if (const auto& bound = ctx->GetBufferBindingPoint(target, i).GetBoundObject()) {
|
||||
consume(bound.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
static constexpr BufferTarget kSlotTargets[] = {BufferTarget::DrawIndirect,
|
||||
BufferTarget::DispatchIndirect,
|
||||
BufferTarget::Parameter};
|
||||
for (const BufferTarget target : kSlotTargets) {
|
||||
if (const auto& bound = ctx->GetBufferBindingSlot(target).GetBoundObject()) {
|
||||
consume(bound.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
static constexpr BufferTarget kSlotTargets[] = {BufferTarget::DrawIndirect,
|
||||
BufferTarget::DispatchIndirect,
|
||||
BufferTarget::Parameter};
|
||||
for (const BufferTarget target : kSlotTargets) {
|
||||
if (const auto& bound = ctx->GetBufferBindingSlot(target).GetBoundObject()) {
|
||||
consume(bound.get());
|
||||
}
|
||||
}
|
||||
// BUFFER TEXTURES (the cloud renderer's shape, and the gap the binding-point walk
|
||||
// cannot see): a texture attached to a buffer with glTexBuffer is read by the draw
|
||||
// through a texture unit, never through a buffer binding point. Walking the touched
|
||||
// units and following a buffer-backed texture to its backing buffer is the only way
|
||||
// those bytes earn their push - without this arm a persistent-mapped TexBuffer is
|
||||
// only refreshed by the read-only verbs' whole push (once per present), which is
|
||||
// exactly the per-frame-cadence cloud twitch this comment is written against.
|
||||
const Int maxUnit = ctx->GetMaxTouchedTextureUnit();
|
||||
for (Int unit = 0; unit <= maxUnit; ++unit) {
|
||||
const auto& texture =
|
||||
ctx->GetTextureUnitObject(unit).GetBindingSlot(TextureTarget::TextureBuffer).GetBoundObject();
|
||||
if (texture == nullptr || texture->GetStorageType() != TextureStorageType::Buffer) {
|
||||
continue;
|
||||
}
|
||||
auto* bufferTexture = static_cast<MG_State::GLState::TextureObjectBuffer*>(texture.get());
|
||||
if (const auto& backing = bufferTexture->GetBufferBindingSlot().GetBoundObject()) {
|
||||
consume(backing.get());
|
||||
// BUFFER TEXTURES (the cloud renderer's shape, and the gap the binding-point
|
||||
// walk cannot see): a texture attached to a buffer with glTexBuffer is read by
|
||||
// the draw through a texture unit, never through a buffer binding point.
|
||||
// Walking the touched units and following a buffer-backed texture to its
|
||||
// backing buffer is the only way those bytes earn their push - without this
|
||||
// arm a persistent-mapped TexBuffer is only refreshed by the read-only verbs'
|
||||
// whole push (once per present), which is exactly the per-frame-cadence cloud
|
||||
// twitch this comment is written against.
|
||||
const Int maxUnit = ctx->GetMaxTouchedTextureUnit();
|
||||
for (Int unit = 0; unit <= maxUnit; ++unit) {
|
||||
const auto& texture = ctx->GetTextureUnitObject(unit)
|
||||
.GetBindingSlot(TextureTarget::TextureBuffer)
|
||||
.GetBoundObject();
|
||||
if (texture == nullptr || texture->GetStorageType() != TextureStorageType::Buffer) {
|
||||
continue;
|
||||
}
|
||||
auto* bufferTexture = static_cast<MG_State::GLState::TextureObjectBuffer*>(texture.get());
|
||||
if (const auto& backing = bufferTexture->GetBufferBindingSlot().GetBoundObject()) {
|
||||
consume(backing.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (consumers.empty()) return;
|
||||
// The membership test is what keeps a bound non-member (an ordinary buffer, an
|
||||
// adopted store) out of PushBlocksForChecked; PushBlocksForChecked can Forget()
|
||||
// a member that stopped being one, which is why the list was copied out first.
|
||||
for (BufferObject* buffer : consumers) {
|
||||
if (buffer != nullptr && m_livePersistentMaps.count(buffer->GetLifetimeId()) != 0) {
|
||||
PushBlocksForChecked(*buffer);
|
||||
|
||||
@@ -74,16 +74,23 @@ namespace MobileGL::MG_Remote::Client {
|
||||
std::atomic<Uint64>* pageBits = nullptr; // allocated once, never freed or moved
|
||||
SizeT pageCount = 0; // GL thread only
|
||||
Uint64 lifetimeId = 0; // GL thread only
|
||||
// GL thread only. The two partial-page edge spans are never protected (see
|
||||
// TrackWriteMap's inward alignment), so nothing faults for them; pushing their
|
||||
// blocks unconditionally measured ~2 x 64 KB x every draw for a hot unaligned
|
||||
// buffer (112 MB/frame). They are hashed per push instead - 8 KB of XXH3 at
|
||||
// worst - and their containing block ships only on a change.
|
||||
// GL thread only, and only on the INWARD fallback (TrackWriteMap: a shadow that
|
||||
// failed the page-granular test). There the two partial-page edge spans are
|
||||
// never protected, so nothing faults for them; pushing their blocks
|
||||
// unconditionally measured ~2 x 64 KB x every draw for a hot unaligned buffer
|
||||
// (112 MB/frame). They are hashed per push instead - 8 KB of XXH3 at worst - and
|
||||
// their containing block ships only on a change. A page-granular shadow (every
|
||||
// shadow the allocator hands out in a split build) is aligned OUTWARD and has no
|
||||
// edges, so these are never read for it - that per-draw XXH3 was 8.5% of the
|
||||
// client thread at VD12 (P5d round 3), on nearly every live map.
|
||||
Uint64 edgeHashHead = 0;
|
||||
Uint64 edgeHashTail = 0;
|
||||
// GL thread only: whether the mapped range has partial-page edge spans at all.
|
||||
// Feeds the epoch skip's per-member edge service (PushDrawConsumers) - edge
|
||||
// bytes are never protected, so their dirtiness is invisible to the fault epoch.
|
||||
// GL thread only: whether the mapped range has UNPROTECTED partial-page edge spans
|
||||
// at all - true only on the inward fallback. Feeds the epoch skip's per-member edge
|
||||
// service (PushDrawConsumers, through m_edgedMembers) - edge bytes are never
|
||||
// protected, so their dirtiness is invisible to the fault epoch. The push itself
|
||||
// does not read it: its two edge hashes are gated by the span geometry, which
|
||||
// says the same thing.
|
||||
Bool hasEdges = false;
|
||||
};
|
||||
|
||||
@@ -151,6 +158,22 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// Unit tests only: clears the membership, the hash cache and the mprotect tracked
|
||||
// slots (restoring every tracked page writable first), and resets the counters.
|
||||
void ClearForTest();
|
||||
// Unit tests only: the mprotect arm's white-box surface, for the alignment cases
|
||||
// (SplitBufferTest) that the public GL surface cannot see - which pages a map
|
||||
// protected is not observable through any push count. MprotectArmAvailableForTest
|
||||
// is the arm's precondition (handler installable, kernel page == tracker page);
|
||||
// a case that needs the arm skips on it rather than going red on a host that has
|
||||
// no arm. TrackedSlotForTest reads a member's live slot (nullptr on the hash arm).
|
||||
// TrackForTest / UntrackForTest register an arbitrary range with an arbitrary
|
||||
// declared extent, which is the only way to reach the inward fallback on a build
|
||||
// whose allocator never hands out an unaligned shadow. FaultEpochForTest is the
|
||||
// handler's answered-fault counter, the one observable a protected page has.
|
||||
static Bool MprotectArmAvailableForTest();
|
||||
static const TrackedWriteMap* TrackedSlotForTest(const MG_State::GLState::BufferObject& buffer);
|
||||
static const TrackedWriteMap* TrackForTest(Uint64 lifetimeId, const Uint8* shadow, SizeT rangeBegin,
|
||||
SizeT rangeEnd, SizeT shadowExtent);
|
||||
static void UntrackForTest(Uint64 lifetimeId);
|
||||
static Uint64 FaultEpochForTest();
|
||||
|
||||
private:
|
||||
// One live member. tracked is the member's tracker slot when it is on the
|
||||
@@ -183,13 +206,22 @@ namespace MobileGL::MG_Remote::Client {
|
||||
Uint64 m_blocksPushed = 0;
|
||||
Uint64 m_bytesPushed = 0;
|
||||
// THE EPOCH SKIP's state (see PushDrawConsumers). m_lastFaultEpoch is the fault
|
||||
// counter's value at the last consumer walk. m_untrackedMembers holds EVERY
|
||||
// counter's value at the last walk - and the walk drains every tracked member
|
||||
// with a marked page, consumer or not, which is the only reason an unmoved
|
||||
// counter can stand for "nothing to push". m_untrackedMembers holds EVERY
|
||||
// live member that fell back to the hash arm, and any one of them vetoes the
|
||||
// skip: the walk is what tells an untracked member's consumption, and scanning
|
||||
// every untracked member unconditionally (the alternative, measured on device
|
||||
// at VD12) costs more than the walk it replaced.
|
||||
Uint64 m_lastFaultEpoch = 0;
|
||||
UnorderedMap<Uint64, Uint8> m_untrackedMembers;
|
||||
// The tracked members whose slot has UNPROTECTED edge spans (the inward fallback,
|
||||
// TrackedWriteMap::hasEdges): the epoch skip serves exactly these per draw and
|
||||
// nobody else, so it walks this set and not the membership. Empty in steady state
|
||||
// on a split build - every shadow is page-granular and aligns outward - which is
|
||||
// what makes the skip's common path a handful of loads with no per-member work.
|
||||
// Maintained beside m_untrackedMembers at the same three events.
|
||||
UnorderedMap<Uint64, Uint8> m_edgedMembers;
|
||||
// Everything of PushBlocksFor after the two role guards, for callers that already
|
||||
// ran them once (the two Members hooks) - the guard's thread-local read was a
|
||||
// measurable per-buffer-per-draw cost on the emutls path.
|
||||
|
||||
@@ -44,6 +44,9 @@
|
||||
#include <MG_Impl/Pipe/SlotAllocator.h>
|
||||
#include <MG_State/GLState/ProgramState/ProgramArtifactsCodec.h>
|
||||
#include <MG_Util/Debug/Log.h>
|
||||
// P5e (pg): ID-87 asks this package for bytes-per-link measured rather than argued, and the
|
||||
// archive's byte count exists exactly once - here, where it is serialised.
|
||||
#include <MG_Util/Metrics/PipeStats.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdlib>
|
||||
@@ -72,6 +75,15 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// NOT in the anonymous namespace, because M5 needs it from MG_Impl/Pipe/PipeFill.cpp too
|
||||
// (its split-only respecify/flush branches must not run on the apply thread). Declared in
|
||||
// WireTables.h.
|
||||
//
|
||||
// AND IT STAYS OUT OF LINE (P5d round 3, package D). OnApplyThread() became an inline
|
||||
// relaxed load plus a thread-pointer compare in ServerLoop.h, so the body this forwards to
|
||||
// is now smaller than the call that reaches it - but inlining THIS would mean including a
|
||||
// server header from WireTables.h, and the declaration above exists precisely so PipeFill
|
||||
// does not have to. One PLT hop per verb is the price of that boundary; the four-part
|
||||
// predicate behind it, which was the measured cost (2.66% self on the client thread at
|
||||
// head 56a77348), is gone either way. The "one atomic load" the paragraph above promised
|
||||
// is now literally what it costs.
|
||||
Bool RunsAsTheServerRole() { return Server::ServerLoop::OnApplyThread(); }
|
||||
|
||||
namespace {
|
||||
@@ -213,6 +225,11 @@ namespace MobileGL::MG_Remote::Client {
|
||||
MGP_WIRE_TAIL(SetSamplerViews, MGPSamplerViews, MGPBoundView)
|
||||
MGP_WIRE_TAIL(BindSamplerStates, MGPSamplerStates, MGPipeHandle)
|
||||
MGP_WIRE_TAIL(SetShaderImages, MGPShaderImages, MGPImageView)
|
||||
// P5e (sb, CONTRACT-P5E.md §5.6): the indexed buffer binding points, one record per
|
||||
// class. The generic tail wrapper carries the FIRST tail only, which is the whole of
|
||||
// the record on Espryt - the optional MGHostSpan tail exists for kCapNeedsHostUboBytes
|
||||
// and that bit is 0 for the whole of P5.
|
||||
MGP_WIRE_TAIL(SetShaderBuffers, MGPShaderBuffers, MGPBufferRange)
|
||||
MGP_WIRE_TAIL(SetVertexAttribDefaults, MGPVertexAttribDefaults, MGPAttribValue)
|
||||
|
||||
#undef MGP_WIRE_PLAIN
|
||||
@@ -331,15 +348,33 @@ namespace MobileGL::MG_Remote::Client {
|
||||
ClientSession& session = RequireSession("ResourceSubData");
|
||||
MG_Pipe::MGPSubData record = *payload;
|
||||
record.Blob = StageOptional(session, blobBytes, blobByteCount);
|
||||
// P5e (ra, CONTRACT-P5E §2.5 / ruling 15): the BUFFER half does not want its
|
||||
// answer, and MGPipeSubDataWantsItsReply is the one place that decides - the same
|
||||
// function the route reads, so the two halves of this call cannot disagree about
|
||||
// whether a wait is owed. Under run-ahead the record is published and this thread
|
||||
// returns; the persistent-map push (PersistentMapTracker's 64 KB blocks) stops
|
||||
// being a hidden round trip per block, which is the single biggest wait left on
|
||||
// the steady path that is not a draw.
|
||||
//
|
||||
// THE ANSWER IS ACCEPT-BY-CONSTRUCTION, AND THAT IS HONEST HERE AND NOWHERE ELSE:
|
||||
// the only caller discards it (PipeFill.cpp's MGPipeEmitResourceSubData), so
|
||||
// "accepted" is not a re-derivation of a server decision - it is the absence of a
|
||||
// question. The server still posts the real answer into the slot; nothing reads
|
||||
// it, which ReplySlot.h:16, 105 makes legal. A row whose acceptance a caller USES
|
||||
// may never take this path - R-5 has not moved.
|
||||
const Bool wantReply = MG_Pipe::MGPipeSubDataWantsItsReply(record);
|
||||
Int32 status = 0;
|
||||
const Uint64 seq = session.EmitAndWait(
|
||||
MGPWireOp::ResourceSubData, &record, sizeof(record), varTail,
|
||||
static_cast<Uint64>(varTailCount) * sizeof(MG_Pipe::MGPSubRegion), nullptr, 0,
|
||||
&status);
|
||||
const Wire::WireTail tail{varTail, static_cast<Uint64>(varTailCount) *
|
||||
sizeof(MG_Pipe::MGPSubRegion)};
|
||||
const Uint64 seq = session.EmitAndWaitTails(
|
||||
MGPWireOp::ResourceSubData, &record, sizeof(record),
|
||||
varTail != nullptr ? &tail : nullptr, varTail != nullptr ? 1u : 0u, nullptr, 0,
|
||||
&status, nullptr, wantReply);
|
||||
reply->Id = seq;
|
||||
MG_Pipe::MGPipePostReply(*reply, status, status == 0 ? 1u : 0u);
|
||||
MG_Pipe::MGPipePostReply(*reply, wantReply ? status : 0,
|
||||
(wantReply ? status == 0 : true) ? 1u : 0u);
|
||||
++g_emitted;
|
||||
if (status == 1) ++g_declined;
|
||||
if (wantReply && status == 1) ++g_declined;
|
||||
}
|
||||
|
||||
void Wire_BufferSubDataResident(const MG_Pipe::MGPSubData* payload, const void* blobBytes,
|
||||
@@ -478,9 +513,11 @@ namespace MobileGL::MG_Remote::Client {
|
||||
// Spirv[i] is Fatal on the far side rather than ignored.
|
||||
void Wire_Escape_CreateShaderState(const MG_Pipe::MGPProgramDesc* desc,
|
||||
const MG_State::GLState::LinkArtifacts* link,
|
||||
const MG_State::GLState::SpirvArtifacts* spirv) {
|
||||
const MG_State::GLState::SpirvArtifacts* spirv,
|
||||
const Uint32* linkedStages, Uint32 linkedStageCount) {
|
||||
if (RunsAsTheServerRole()) {
|
||||
MG_Pipe::MGPipeMonolithEscapes().CreateShaderState(desc, link, spirv);
|
||||
MG_Pipe::MGPipeMonolithEscapes().CreateShaderState(desc, link, spirv, linkedStages,
|
||||
linkedStageCount);
|
||||
return;
|
||||
}
|
||||
ClientSession& session = RequireSession("CreateShaderState");
|
||||
@@ -492,11 +529,23 @@ namespace MobileGL::MG_Remote::Client {
|
||||
"code");
|
||||
std::abort();
|
||||
}
|
||||
// EncodeProgramArtifacts APPENDS and never fails - everything it walks is owned
|
||||
// EncodeProgramArchive APPENDS and never fails - everything it walks is owned
|
||||
// plain data - so an empty archive means the two structs themselves were empty,
|
||||
// which is a linked program with no artefacts and is not a codec question.
|
||||
//
|
||||
// P5e (pg): THE FRAMED form, so the record's own copy on the far side can pair each
|
||||
// module with its stage. The bare EncodeProgramArtifacts is still what the verify
|
||||
// build's round-trip pin uses; this is the one that crosses.
|
||||
Vector<Uint8> archive;
|
||||
MG_State::GLState::EncodeProgramArtifacts(*link, *spirv, archive);
|
||||
Vector<Uint32> stages(linkedStages, linkedStages + linkedStageCount);
|
||||
MG_State::GLState::EncodeProgramArchive(*link, *spirv, stages, archive);
|
||||
if (MG_Util::PipeStats::Enabled()) {
|
||||
// ID-87's measurement, taken where the bytes actually exist rather than
|
||||
// estimated: one sample per link, so the steady-state cost is (links this
|
||||
// frame) x (bytes per link) and both halves are countable from the stats line.
|
||||
MG_Util::PipeStats::AddBytes(MG_Util::PipeStats::ByteClass::CsoBlobBytes,
|
||||
static_cast<Uint64>(archive.size()));
|
||||
}
|
||||
if (archive.empty()) {
|
||||
MGLOG_F("MGPipe: Fatal{ArchiveEmpty, \"create_shader_state\"} - the program's "
|
||||
"artefacts serialised to nothing");
|
||||
@@ -510,6 +559,71 @@ namespace MobileGL::MG_Remote::Client {
|
||||
++g_emitted;
|
||||
}
|
||||
|
||||
// set_program_bindings (P5e, pg). THE FIFTH ESCAPE, for PipeRoute.h's reason: three
|
||||
// tails in three index spaces plus a parallel name array, which no generated
|
||||
// (payload, varTail, varTailCount) row can express.
|
||||
//
|
||||
// THE NAMES ARE STAGED ONE BY ONE and each element's own MGHostSpan names its run, so
|
||||
// the third tail is self-describing the way set_storage_block_binding's single name
|
||||
// already is. Staged rather than packed into one run with offsets, because the honesty
|
||||
// pass the decoder runs is per span and a packed run would have to be re-split there
|
||||
// against arithmetic nothing on the wire declares.
|
||||
void Wire_Escape_SetProgramBindings(const MG_Pipe::MGPProgramBindings* hdr,
|
||||
const Int32* blockBindings,
|
||||
const MG_Pipe::MGPProgramSamplerUnit* samplerUnits,
|
||||
const MG_Pipe::MGPProgramStorageOverride* storageOverrides,
|
||||
const char* const* storageOverrideNames) {
|
||||
if (RunsAsTheServerRole()) {
|
||||
MG_Pipe::MGPipeMonolithEscapes().SetProgramBindings(hdr, blockBindings, samplerUnits,
|
||||
storageOverrides,
|
||||
storageOverrideNames);
|
||||
return;
|
||||
}
|
||||
ClientSession& session = RequireSession("SetProgramBindings");
|
||||
MG_Pipe::MGPProgramBindings record = *hdr;
|
||||
|
||||
// The override tail is COPIED before it is emitted, because the span is the one
|
||||
// field the client must write after the caller is done with it - the same reason
|
||||
// MGP_WIRE_BLOB copies its payload.
|
||||
Vector<MG_Pipe::MGPProgramStorageOverride> overrides;
|
||||
overrides.reserve(record.StorageOverrideCount);
|
||||
for (Uint32 i = 0; i < record.StorageOverrideCount; ++i) {
|
||||
MG_Pipe::MGPProgramStorageOverride entry = storageOverrides[i];
|
||||
const char* const name = storageOverrideNames[i];
|
||||
// Size = strlen + 1: THE NUL TRAVELS, exactly as set_storage_block_binding's
|
||||
// name does (contract table 0's block-name row), and the decoder refuses a run
|
||||
// whose last byte is not NUL.
|
||||
const Uint64 nameBytes = static_cast<Uint64>(std::strlen(name)) + 1ull;
|
||||
const MG_Pipe::MGPBlobRef staged = session.Encoder().StageBytes(name, nameBytes);
|
||||
// A HOST SPAN AND NOT A BLOBREF, which is what the row's kHostSpan flag means:
|
||||
// the same run, described in the shape the decoder's honesty pass reads. Ptr
|
||||
// stays null - rule B, "the encoder writes nullptr and names SEG_STAGE" - so
|
||||
// the name is unreachable on a second process except through the segment table,
|
||||
// which is the whole point of the flag.
|
||||
entry.Name = MG_Pipe::MGHostSpan{};
|
||||
entry.Name.Ptr = nullptr;
|
||||
entry.Name.Seg = staged.Seg;
|
||||
entry.Name.Offset = staged.Offset;
|
||||
entry.Name.Size = staged.Size;
|
||||
overrides.push_back(entry);
|
||||
}
|
||||
|
||||
const Wire::WireTail tails[3] = {
|
||||
{blockBindings, static_cast<Uint64>(record.BlockBindingCount) * sizeof(Int32)},
|
||||
{samplerUnits, static_cast<Uint64>(record.SamplerUnitCount) *
|
||||
sizeof(MG_Pipe::MGPProgramSamplerUnit)},
|
||||
{overrides.empty() ? nullptr : overrides.data(),
|
||||
static_cast<Uint64>(record.StorageOverrideCount) *
|
||||
sizeof(MG_Pipe::MGPProgramStorageOverride)},
|
||||
};
|
||||
// ALWAYS THREE, even when a count is 0 - the decoder derives the third tail's
|
||||
// offset from the first two, so declaring fewer would put the same bytes somewhere
|
||||
// else (PipeWireCodec.cpp's layout arm says this from the other side).
|
||||
session.EmitAndWaitTails(MGPWireOp::SetProgramBindings, &record, sizeof(record), tails, 3,
|
||||
nullptr, 0, nullptr);
|
||||
++g_emitted;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// =====================================================================================
|
||||
@@ -640,6 +754,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
gMGPipeContext.SetSamplerViews = &Wire_SetSamplerViews;
|
||||
gMGPipeContext.BindSamplerStates = &Wire_BindSamplerStates;
|
||||
gMGPipeContext.SetShaderImages = &Wire_SetShaderImages;
|
||||
gMGPipeContext.SetShaderBuffers = &Wire_SetShaderBuffers;
|
||||
gMGPipeContext.SetGlobalConstants = &Wire_SetGlobalConstants;
|
||||
gMGPipeContext.SetVertexAttribDefaults = &Wire_SetVertexAttribDefaults;
|
||||
gMGPipeContext.SetPixelPackState = &Wire_SetPixelPackState;
|
||||
@@ -655,6 +770,7 @@ namespace MobileGL::MG_Remote::Client {
|
||||
gMGPipeRouteEscapes.ResourceFlushRange = &Wire_Escape_ResourceFlushRange;
|
||||
gMGPipeRouteEscapes.MapPersistent = &Wire_Escape_MapPersistent;
|
||||
gMGPipeRouteEscapes.CreateShaderState = &Wire_Escape_CreateShaderState;
|
||||
gMGPipeRouteEscapes.SetProgramBindings = &Wire_Escape_SetProgramBindings;
|
||||
|
||||
MGPipeNoteInstalledArm(MGPipeRouteArm::kClientWire);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "PipeApplier.h"
|
||||
|
||||
#include "ServerSession.h"
|
||||
#include "../Transport/ReplySlot.h"
|
||||
|
||||
#include <Config.h>
|
||||
@@ -29,6 +30,20 @@
|
||||
|
||||
namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
namespace {
|
||||
// P5e (ra, CONTRACT-P5E §1 / §6): DOES THIS SERVER PUBLISH kCapRunAheadApply? The
|
||||
// question is asked of the server's OWN CallMask and not of a build constant, because
|
||||
// "the client may run ahead" is exactly what that bit says and Magma never sets it.
|
||||
// A session with no CallMask yet (the bring-up window, a fixture that never called
|
||||
// SetCapabilityBits) answers false: no client can have latched run-ahead against a
|
||||
// snapshot that was never published.
|
||||
Bool ServerPublishesRunAhead() {
|
||||
const ServerSession* session = ServerSession::Active();
|
||||
if (session == nullptr || !session->CallMaskIsSet()) return false;
|
||||
return (session->CallMask() & static_cast<Uint64>(MG_Pipe::kCapRunAheadApply)) != 0;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
ReplyPool::ReplyPool(void* base, Uint64 sizeBytes, Uint32 slotCount, Uint32 slotBytes)
|
||||
: m_base(static_cast<Uint8*>(base)), m_size(sizeBytes), m_slots(slotCount), m_slotBytes(slotBytes) {}
|
||||
|
||||
@@ -288,7 +303,30 @@ namespace MobileGL::MG_Remote::Server {
|
||||
++m_presents;
|
||||
// FrameSerial 0 means "the server stamps its own" (c1-v1 8.3): P5 has no client-side
|
||||
// present credit, so the client sends 0 and the frame count on this side IS the serial.
|
||||
//
|
||||
// P5e (ra, CONTRACT-P5E §1, §2.4): IT IS THE CLIENT'S NOW, 1-BASED AND MINTED BY THE
|
||||
// PAYER. A credit can only be paced in an id space the waiter advances, and the waiter
|
||||
// is the client (`WaitForPresentAck(m_presentsSent + 1 - credit)`), so a server-stamped
|
||||
// serial would be the server acknowledging its own count. The 0 arm survives for a
|
||||
// peer that has not been re-built - and on a server that PUBLISHES the run-ahead cap it
|
||||
// is a protocol fault, because such a client is pacing on this answer and a 0 would
|
||||
// acknowledge a frame nobody asked about.
|
||||
if (present.FrameSerial == 0 && ServerPublishesRunAhead()) {
|
||||
MGLOG_F("MGPipe: Fatal{ProtocolCorruption, \"Present.FrameSerial\"} - a run-ahead "
|
||||
"server was handed present serial 0. The client mints this 1-based and "
|
||||
"waits on it for its credit (CONTRACT-P5E §2.4); returning a credit for "
|
||||
"serial 0 would release a wait that is asking about frame N");
|
||||
std::abort();
|
||||
}
|
||||
m_lastPresentSerial = present.FrameSerial != 0 ? present.FrameSerial : m_presents;
|
||||
// §2.4's other half, and the reason ServerSession::ReturnPresentCredit has had no
|
||||
// production caller since v1 wrote it: ONE CREDIT PER SWAP, returned after Present()
|
||||
// has returned rather than before it, because what the client is waiting for is the
|
||||
// swap and not the record's apply. It advances presentAckSerial AND rings the client's
|
||||
// bell - a client parked in WaitForPresentAck(kWaitForever) needs the pair.
|
||||
if (ServerSession* session = ServerSession::Active()) {
|
||||
session->ReturnPresentCredit(m_lastPresentSerial);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -427,6 +465,66 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// with a span (the client refuses "MultiDrawElements+CLIENT_INDICES" first; P8's
|
||||
// HostResolve.cpp flattens it) and a multi-draw that claims instancing (no GL entry point
|
||||
// produces one; the client never sends it).
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
namespace {
|
||||
// P5e (tx2), CONTRACT-P5E §5.3 / ruling 19 (ID-95, A8 closed). THE TWO UNIT WINDOWS MUST
|
||||
// COVER [0, MaxTouchedTextureUnit], AND THIS IS WHERE THAT PROMISE IS CHECKED.
|
||||
//
|
||||
// Everything the texture and sampler families do per draw now reads
|
||||
// [SamplerViewStart, +SamplerViewCount) and [SamplerStateStart, +SamplerStateCount).
|
||||
// Under run-ahead a window NARROWER than the frontend's high-water mark silently drops a
|
||||
// sync of a texture the draw is about to sample, or leaves an earlier draw's sampler
|
||||
// object on a unit - and a decline is exactly what run-ahead cannot take, because the
|
||||
// client has already moved on and there is no wait in which to notice.
|
||||
//
|
||||
// A SERVER-SIDE RE-DERIVATION IS REFUSED, and that is the ruling's point: the client owns
|
||||
// the high-water mark (it is the `count` argument SamplerEmit.h passes, Start=0 /
|
||||
// Count=maxTouched+1) and the server's job is to check the promise, not to invent a
|
||||
// second authority for it. So this is a CHECK and its failure is corruption.
|
||||
//
|
||||
// WHERE THE MARK COMES FROM: MGPContextValues::MaxTouchedTextureUnit, applied by
|
||||
// set_context_values, which precedes the verb on the ring - the same ordering §2.1's
|
||||
// XFB clause leans on. It is RECORD_SUPPLIED, so reading it is reading what a record
|
||||
// put there and not client memory (rule F).
|
||||
//
|
||||
// WIDER IS FINE. A window larger than the mark costs a walk over provably-empty units;
|
||||
// only SMALLER is unrepresentable. An empty window on a draw that touches no unit at all
|
||||
// (mark 0 with nothing ever touched) is the correct and only possible emission, so a
|
||||
// count of 0 is admitted exactly while the applied counters say no unit was touched.
|
||||
//
|
||||
// THE ONE ADMITTED SILENCE, and it is the A/B rather than a hole: a client whose sampler
|
||||
// subsystem bit is CLEAR emits neither record, the backend then runs its pre-handle
|
||||
// frontend walk, and there is no window to check because there is no window. That is
|
||||
// "both counts are still 0", and it is distinguishable from the narrowing this refuses
|
||||
// (a narrowed window carries a non-zero count that is merely too small). The moment
|
||||
// either set has been received, the rule binds.
|
||||
void CheckUnitWindows(const MG_Pipe::MGPipeApplierState& st, const char* verb) {
|
||||
if (st.SamplerViewCount == 0 && st.SamplerStateCount == 0) return;
|
||||
const Int maxTouched = MG_Pipe::gPipeInputs.GetMaxTouchedTextureUnit();
|
||||
if (maxTouched < 0) return;
|
||||
const Uint32 required = static_cast<Uint32>(maxTouched) + 1u;
|
||||
if (st.SamplerViewStart != 0 || st.SamplerViewCount < required) {
|
||||
MGLOG_F("MGPipe: Fatal{ProtocolCorruption, \"SetSamplerViews.Count\"} - %s applies with "
|
||||
"units 0..%d touched, so set_sampler_views must carry Start=0 and Count >= %u "
|
||||
"(CONTRACT-P5E.md §5.3); the applied window is Start=%u Count=%u, which drops "
|
||||
"the sync of at least one texture this draw samples",
|
||||
verb, static_cast<int>(maxTouched), required, st.SamplerViewStart,
|
||||
st.SamplerViewCount);
|
||||
std::abort();
|
||||
}
|
||||
if (st.SamplerStateStart != 0 || st.SamplerStateCount < required) {
|
||||
MGLOG_F("MGPipe: Fatal{ProtocolCorruption, \"BindSamplerStates.Count\"} - %s applies with "
|
||||
"units 0..%d touched, so bind_sampler_states must carry Start=0 and Count >= %u "
|
||||
"(CONTRACT-P5E.md §5.3); the applied window is Start=%u Count=%u, which leaves "
|
||||
"an earlier draw's sampler object on at least one unit",
|
||||
verb, static_cast<int>(maxTouched), required, st.SamplerStateStart,
|
||||
st.SamplerStateCount);
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
#endif
|
||||
|
||||
Bool ServerVerbSink::OnDrawVbo(const MG_Pipe::MGPDrawInfo& info,
|
||||
const MG_Pipe::MGPDrawRange* ranges,
|
||||
const MG_Pipe::MGHostSpan* userIndices,
|
||||
@@ -449,6 +547,11 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
++m_drawRecords;
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// Ruling 19 / ID-95: the window promise, checked at every draw, before the backend is
|
||||
// asked to resolve anything out of the windows.
|
||||
CheckUnitWindows(MG_Pipe::MGPipeApplier(), "draw_vbo");
|
||||
#endif
|
||||
const MG_Backend::GlobalBackendFunctionsTable* table = Table("draw_vbo");
|
||||
if (table == nullptr) return false;
|
||||
const MG_Backend::GLFunctionsTable& gl = table->GL;
|
||||
@@ -668,15 +771,26 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// identical - and it is also the honest statement of the debt, which `rsp` counts.
|
||||
|
||||
Bool ServerVerbSink::OnLaunchGrid(const MG_Pipe::MGPGridInfo& grid) {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// Ruling 19 / ID-95: a dispatch samples through the same unit windows a draw does.
|
||||
CheckUnitWindows(MG_Pipe::MGPipeApplier(), "launch_grid");
|
||||
#endif
|
||||
const MG_Backend::GlobalBackendFunctionsTable* table = Table("launch_grid");
|
||||
if (table == nullptr) return false;
|
||||
const MG_Backend::GLFunctionsTable& gl = table->GL;
|
||||
// The compute program is NOT named by this record and must not be: it is
|
||||
// GetProgramForDispatch, GetProgramForDraw's twin, which the backend pulls inside its
|
||||
// own PrepareForCompute (DirectGLES.cpp:5779). i1 is what puts compute on the path, so
|
||||
// the field moves FATAL -> BARRIER_PULLED in FieldOwnership.def (contract §6.9, the
|
||||
// one row this package is granted). Block* are 0 on the wire for the same reason: the
|
||||
// local size is a link artifact the backend reads from its own program.
|
||||
// The compute program is NOT named by THIS record and must not be - but it IS named, by
|
||||
// the set_dispatch_program record that preceded it, and the backend's PrepareForCompute
|
||||
// reads MGPipeApplier().DispatchProgram from there.
|
||||
//
|
||||
// P5e (pa): that is what this comment used to get wrong. Until P5e the backend PULLED
|
||||
// GetProgramForDispatch - GetProgramForDraw's twin - inside PrepareForCompute, and the
|
||||
// field's FATAL -> BARRIER_PULLED move in FieldOwnership.def (contract §6.9, i1's one
|
||||
// granted row) is what made the pull legal. pg gave the sync and the link/SPIR-V gate a
|
||||
// handle arm and pa retired the pull itself, so on the handle arm the row is not read at
|
||||
// all; the BARRIER_PULLED class stays because the monolith arm still reads it (ID-81).
|
||||
// Block* are 0 on the wire for the unchanged reason: the local size is a link artifact
|
||||
// the backend reads from the program it resolved, which on that arm is the record's
|
||||
// archive.
|
||||
if (grid.IsIndirect != 0) {
|
||||
if (gl.DispatchComputeIndirect == nullptr) return false;
|
||||
// IndirectBuffer travels for P7's sake; the BINDING is server state, put there by
|
||||
@@ -1055,6 +1169,24 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// dropped before this function returns, and s1's SessionConsumer::ApplyOne publishes
|
||||
// appliedSeq only after that - so by the time the client is runnable the flag is down.
|
||||
const Client::ClientSession::ScopedApplierEntry insideApplier;
|
||||
// P5e (id), CONTRACT-P5E §2.1 / §4.4: STAMP WHETHER THE CLIENT IS PARKED BEHIND THIS
|
||||
// RECORD, before anything can ask. It is the input to the allocator guard's exemption
|
||||
// (SlotAllocator.cpp) and to every frontend-keyed twin member that survives as monolith
|
||||
// glue (SlotTables.h), and it has to be up before DecodeAndApply because the sinks those
|
||||
// reach are exactly the askers. MGPipeBarriered answers true for every record until ra
|
||||
// lands the wait rule, so this line changes nothing this phase and is the line ra
|
||||
// rebases onto rather than adds.
|
||||
//
|
||||
// AND THE STAMP IS `true` UNTIL ra LANDS THE CLIENT'S HALF (ID-103). The predicate
|
||||
// describes what the client WILL do once EmitAndWaitTails follows the wait classes;
|
||||
// today it still blocks after every record, so a `false` stamp here would withdraw the
|
||||
// §4.4 exemptions from a probe the client's own wait still makes safe - a refusal with
|
||||
// no defect behind it. The predicate is computed on every record all the same, so it is
|
||||
// exercised for the whole phase rather than first run on the day it starts deciding.
|
||||
const Bool wireSaysBarriered = MG_Pipe::MGPipeBarriered(
|
||||
static_cast<MG_Pipe::MGPWireOp>(record.kind), record.payload, MG_Pipe::MGPipeApplier());
|
||||
MG_Pipe::MGPipeApplierSetCurrentRecordBarriered(
|
||||
MG_Pipe::kMGPipeP5eClientWaitRuleLanded ? wireSaysBarriered : true);
|
||||
// ORDER IS THE CONTRACT'S: stamp, then apply. The stamp is what makes any server-side
|
||||
// read of gPipeInputs legal at all (PipeApplier.h's block 1), so a record applied
|
||||
// before it aborts on the FIRST field inside SyncRenderState.
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <Config.h>
|
||||
#include <MG_Backend/BackendObjects.h>
|
||||
#include <MG_Util/Debug/Log.h>
|
||||
#include <MG_Util/Metrics/PipeStats.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
@@ -211,6 +212,7 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// tally - and a developer running the binary directly gets the count CI sees.
|
||||
m_drained.store(0, std::memory_order_release);
|
||||
m_parks.store(0, std::memory_order_release);
|
||||
m_parkBlocks.store(0, std::memory_order_release);
|
||||
m_nativeBinds.store(0, std::memory_order_release);
|
||||
m_clientReleases.store(0, std::memory_order_release);
|
||||
m_makeCurrentRepublishes.store(0, std::memory_order_release);
|
||||
@@ -226,15 +228,17 @@ namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
Bool ServerLoop::Running() const { return m_running.load(std::memory_order_acquire); }
|
||||
|
||||
Bool ServerLoop::OnApplyThread() {
|
||||
ServerLoop& loop = ServerLoopInstance();
|
||||
return loop.m_running.load(std::memory_order_acquire) &&
|
||||
loop.m_applyThreadId.load(std::memory_order_acquire) == std::this_thread::get_id();
|
||||
}
|
||||
// OnApplyThread() is inline in the header now (P5d round 3, package D). Its whole body is
|
||||
// one relaxed load of Detail::g_applyThreadKey and one comparison against the caller's own
|
||||
// thread pointer; the two writes to that key are in ApplyThreadMain, below.
|
||||
|
||||
Uint64 ServerLoop::ResolvedAffinityMask() const { return m_affinityMask; }
|
||||
Uint64 ServerLoop::DrainedRecords() const { return m_drained.load(std::memory_order_acquire); }
|
||||
Uint64 ServerLoop::ParkCount() const { return m_parks.load(std::memory_order_acquire); }
|
||||
|
||||
Uint64 ServerLoop::ParkBlockCount() const {
|
||||
return m_parkBlocks.load(std::memory_order_relaxed);
|
||||
}
|
||||
Uint64 ServerLoop::NativeBindCount() const { return m_nativeBinds.load(std::memory_order_acquire); }
|
||||
Uint64 ServerLoop::ClientReleaseCount() const {
|
||||
return m_clientReleases.load(std::memory_order_acquire);
|
||||
@@ -325,7 +329,12 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
|
||||
void ServerLoop::ApplyThreadMain() {
|
||||
m_applyThreadId.store(std::this_thread::get_id(), std::memory_order_release);
|
||||
// THE IDENTITY IS PUBLISHED FIRST, BEFORE THE THREAD HAS A NAME OR AN AFFINITY. Every
|
||||
// role guard in the tree reads it, and the very first record this thread applies must
|
||||
// already answer "yes" to OnApplyThread() - otherwise the applier's own reads would
|
||||
// look like client reads to the guards. Relaxed for the reason stated beside the key's
|
||||
// declaration: it is an identity, not a handshake, and this thread is the only writer.
|
||||
Detail::g_applyThreadKey.store(Detail::CurrentThreadKey(), std::memory_order_relaxed);
|
||||
NameThisThread("mgl-srv-apply");
|
||||
|
||||
Bool recognised = true;
|
||||
@@ -368,20 +377,55 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// CondVarDoorbell::Kill() breaks that, and Kill is the CLIENT's teardown call, not
|
||||
// something an EGL make-current request may perform. So the predicate carries all
|
||||
// three arming conditions and the doorbell wakes the thread for any of them.
|
||||
// P5e (ra, CONTRACT-P5E §2.6) ADDS A FOURTH, AND IT IS THE ONE THAT SAYS "NOT NOW"
|
||||
// RATHER THAN "WAKE UP". A full SEG_EVENT means the apply thread has nowhere to put
|
||||
// the events the next record's apply would produce, so a waiting record is NOT work
|
||||
// yet: applying it would only park the producer half way through. Stop and Control
|
||||
// still win - a teardown may not be held up by a client that stopped draining - which
|
||||
// is why they are tested first and the ring test sits between them and the queue.
|
||||
//
|
||||
// The wake comes from EventRingConsumer::Drained(), which clears the latch AND rings
|
||||
// this bell (that pairing is the whole of the flow-control protocol; a cleared flag
|
||||
// with no bell is the lost wakeup the forward direction's publish-then-ring order
|
||||
// exists to prevent).
|
||||
const auto ready = [this, &control, &ring] {
|
||||
return control.cmdHead.load(std::memory_order_acquire) != ring.LocalTail() ||
|
||||
m_stopRequested.load(std::memory_order_acquire) || ControlIsPending();
|
||||
if (m_stopRequested.load(std::memory_order_acquire) || ControlIsPending()) return true;
|
||||
if (control.eventRingFull.load(std::memory_order_acquire) != 0) return false;
|
||||
return control.cmdHead.load(std::memory_order_acquire) != ring.LocalTail();
|
||||
};
|
||||
|
||||
for (;;) {
|
||||
PumpControlRequest();
|
||||
if (m_stopRequested.load(std::memory_order_acquire)) break;
|
||||
DrainRing();
|
||||
if (control.eventRingFull.load(std::memory_order_acquire) == 0) DrainRing();
|
||||
if (m_stopRequested.load(std::memory_order_acquire)) break;
|
||||
if (ready()) continue;
|
||||
|
||||
m_parks.fetch_add(1, std::memory_order_acq_rel);
|
||||
const bool woke = bell.Wait(control.consumerParked, ready, spinUs, Transport::kWaitForever);
|
||||
const Uint64 waits = m_parks.fetch_add(1, std::memory_order_acq_rel) + 1;
|
||||
// THE WAIT LEDGER'S SERVER HALF (P5d round 3, package T item 4). The client may not
|
||||
// name this counter - CONTRACT-P5C rule E, layer 2: a GL-thread read of
|
||||
// ServerLoop's memory is exactly the cross-role access P5c zeroed - so the server
|
||||
// publishes its own reading and MG_Util::PipeStats is the meeting point. Two
|
||||
// relaxed stores behind the stats latch, on the one path in this loop that is about
|
||||
// to spin or block anyway; with MOBILEGL_PIPE_STATS unset it is a global load and a
|
||||
// predicted branch.
|
||||
//
|
||||
// BOTH NUMBERS, because they answer different questions. `srv` is how often the
|
||||
// loop reached Doorbell::Wait at all (ParkCount()'s long-standing meaning: an
|
||||
// intention, counted on the way TOWARD a park - ServerLoopTest's C10 note); `srvpark`
|
||||
// is how often it really blocked. The ratio is what says whether the spin budget is
|
||||
// sized for this workload, and it is only readable as a ratio because the two
|
||||
// numbers count the same events: m_parkBlocks is THIS loop's tally, handed to the
|
||||
// Wait below, not the bell's own ParkEntries(). A bell counts every waiter on its
|
||||
// endpoint, so reading it here would have made `srvpark` a superset of `srv` the
|
||||
// moment anything else waited on the consumer bell.
|
||||
if (MG_Util::PipeStats::Enabled()) {
|
||||
using MG_Util::PipeStats::Gauge;
|
||||
MG_Util::PipeStats::PublishGauge(Gauge::ServerWaits, waits);
|
||||
MG_Util::PipeStats::PublishGauge(Gauge::ServerParks, ParkBlockCount());
|
||||
}
|
||||
const bool woke = bell.Wait(control.consumerParked, ready, spinUs,
|
||||
Transport::kWaitForever, &m_parkBlocks);
|
||||
if (!woke) {
|
||||
// Wait returns false only on a dead bell or an expired deadline, and this park
|
||||
// has no deadline. A dead bell IS the shutdown signal (table 3's teardown step
|
||||
@@ -393,7 +437,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
break;
|
||||
}
|
||||
MGLOG_E("MG_Remote server: Doorbell::Wait(kWaitForever) returned false on a live "
|
||||
"bell - that is impossible by Doorbell.h:139-178 and means the bell's "
|
||||
"bell - that is impossible by Doorbell::Wait's park loop (the only "
|
||||
"false returns are the Dead() arm and an expired deadline) and means "
|
||||
"the bell's "
|
||||
"Dead() answer moved under the waiter. Shutting the loop down rather "
|
||||
"than spinning");
|
||||
break;
|
||||
@@ -435,6 +481,10 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// NOT_INITIALIZED without publishing). There is no third order.
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(m_controlMutex);
|
||||
// The shadow dies with the mailbox it shadows, under the same lock and inside the
|
||||
// same critical section as the m_running clear: nothing will ever pump again, so a
|
||||
// `true` left here would be a claim no thread can retire.
|
||||
m_controlPosted.store(false, std::memory_order_release);
|
||||
if (m_controlPending) {
|
||||
m_controlPending = false;
|
||||
m_controlFinished = true;
|
||||
@@ -443,6 +493,30 @@ namespace MobileGL::MG_Remote::Server {
|
||||
"exited; it is answered NOT_INITIALIZED rather than left blocking");
|
||||
}
|
||||
m_running.store(false, std::memory_order_release);
|
||||
// THE IDENTITY DIES WITH m_running, IN THE SAME CRITICAL SECTION, because it IS
|
||||
// m_running as far as OnApplyThread() is concerned (P5d round 3, package D): the
|
||||
// old predicate was `m_running && id == mine`, so it stopped answering true at
|
||||
// exactly this store, and the key has to stop meaning "this thread" at exactly the
|
||||
// same store or the window would have moved. Everything that must still run as the
|
||||
// server role - the final PumpControlRequest/DrainRing, Applier().Detach(),
|
||||
// ~BackendObject_DirectGLES and the ReleaseEGLResources it posts back to itself -
|
||||
// is already above this block.
|
||||
//
|
||||
// DO NOT MOVE THIS STORE UP ON THE STRENGTH OF A GREEN ctest (review round 3). That
|
||||
// this line EXISTS is pinned below (ServerLoopTest's
|
||||
// AThreadCreatedAfterTheLoopStoppedIsNotMistakenForTheApplyThread: delete the store
|
||||
// and the key survives the join, and the next thread that inherits this one's TLS
|
||||
// block - hence its thread pointer - answers OnApplyThread() TRUE). That it sits
|
||||
// HERE rather than fifteen lines earlier is NOT pinned by any unit case and cannot
|
||||
// be: ServerLoopTest has no GL context, so CreateBackend is never called and the
|
||||
// ~BackendObject_DirectGLES -> ReleaseEGLResources self-post named above is never
|
||||
// built. Move the store above m_backend.reset() and that post misses
|
||||
// RunOnApplyThread's re-entrancy arm (ServerLoop.cpp: `if (OnApplyThread()) return
|
||||
// work(user);`) while m_running is still true, so it publishes into the one-slot
|
||||
// mailbox and waits on m_controlDone for an answer only THIS thread could ever
|
||||
// give. The integration lane - a real EGL teardown - is the only thing that would
|
||||
// catch that, and it would catch it as a hang, not as a failed assertion.
|
||||
Detail::g_applyThreadKey.store(0, std::memory_order_relaxed);
|
||||
}
|
||||
m_controlDone.notify_all();
|
||||
|
||||
@@ -450,18 +524,38 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
|
||||
Bool ServerLoop::ControlIsPending() const {
|
||||
const std::lock_guard<std::mutex> lock(const_cast<std::mutex&>(m_controlMutex));
|
||||
return m_controlPending;
|
||||
// ONE ACQUIRE LOAD, NO LOCK - see the header block on m_controlPosted. This is the
|
||||
// hottest call in the whole loop (the `ready` lambda runs it on every spin iteration of
|
||||
// every wait) and it used to be a mutex round trip.
|
||||
return m_controlPosted.load(std::memory_order_acquire);
|
||||
}
|
||||
|
||||
Bool ServerLoop::PumpControlRequest() {
|
||||
// THE IDLE POLL'S FAST NEGATIVE. The loop calls this once per iteration whether or not
|
||||
// anything was posted, and the common answer is "nothing". Taking m_controlMutex to
|
||||
// learn that was the other half of package T's finding; the shadow answers it with a
|
||||
// load, and everything below this line still runs under the lock exactly as before.
|
||||
if (!m_controlPosted.load(std::memory_order_acquire)) return false;
|
||||
|
||||
ControlWork work = nullptr;
|
||||
void* user = nullptr;
|
||||
{
|
||||
const std::lock_guard<std::mutex> lock(m_controlMutex);
|
||||
if (!m_controlPending) return false;
|
||||
if (!m_controlPending) {
|
||||
// The shadow outlived its request - it cannot happen through the poster's
|
||||
// path, but a `true` that nobody clears would make `ready` permanently true
|
||||
// and the loop would never park again, so it is cleared here rather than
|
||||
// trusted.
|
||||
m_controlPosted.store(false, std::memory_order_release);
|
||||
return false;
|
||||
}
|
||||
work = m_controlWork;
|
||||
user = m_controlUser;
|
||||
// CLEARED WHEN THE REQUEST IS TAKEN, not when it finishes. m_controlPending stays
|
||||
// true for the duration of `work` (the C2 exit block reads it), but the thread that
|
||||
// would act on the shadow is THIS one and it is busy running the request; leaving
|
||||
// the shadow set would only make the post-work iteration spin instead of park.
|
||||
m_controlPosted.store(false, std::memory_order_release);
|
||||
}
|
||||
const MobileGLResult result = work == nullptr ? MOBILEGL_ERR_INVALID_ARGUMENT : work(user);
|
||||
{
|
||||
@@ -475,6 +569,14 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
|
||||
Uint64 ServerLoop::DrainRing() {
|
||||
// THE EMPTY-RING ANSWER COSTS TWO LOADS AND NOTHING ELSE, and that was AUDITED rather
|
||||
// than assumed (P5d round 3, package T item 2): the idle poll calls this on every
|
||||
// iteration, so a lock or a clock read in here would be the same defect
|
||||
// PumpControlRequest had. The path is SessionConsumer::ApplyOne -> RingConsumer::Pop,
|
||||
// and Pop's first act on an empty ring is one acquire load of cmdHead compared against
|
||||
// the consumer's own m_localTail (Ring.cpp:222-232) - no mutex, no steady_clock, no
|
||||
// allocation; `applied == 0` then skips the retire block below entirely. Keep it that
|
||||
// way: anything added here runs ~900 times a frame doing nothing.
|
||||
ServerSession& session = *m_session;
|
||||
Transport::SessionConsumer& consumer = session.Consumer();
|
||||
PipeApplier& applier = session.Applier();
|
||||
@@ -584,7 +686,14 @@ namespace MobileGL::MG_Remote::Server {
|
||||
m_controlUser = user;
|
||||
m_controlPending = true;
|
||||
m_controlFinished = false;
|
||||
// Publish THEN ring, in that order and never the other (Doorbell.h:186-193). The bell
|
||||
// THE SHADOW IS PUBLISHED LAST OF THE FOUR AND WITH A RELEASE, inside this same
|
||||
// critical section: the apply thread's park predicate reads ONLY this word, so an
|
||||
// acquire load that returns true must also see the three fields above it. Storing it
|
||||
// first would let a pump that is already past its own fast-negative read a slot that
|
||||
// does not name the work yet.
|
||||
m_controlPosted.store(true, std::memory_order_release);
|
||||
// Publish THEN ring, in that order and never the other (Doorbell.h, NotifyIfParked's
|
||||
// PRECONDITION block: the fence only orders what precedes it). The bell
|
||||
// is rung unconditionally rather than through NotifyIfParked because this side does not
|
||||
// know whether the apply thread is parked or spinning, and CondVarDoorbell remembers a
|
||||
// wakeup that arrives while nobody is waiting. Held under m_controlMutex: wait() releases
|
||||
@@ -643,7 +752,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
MGLOG_F("MGPipe: Fatal{ApplyThreadJoinTimeout} - mgl-srv-apply did not exit within "
|
||||
"%u ms of Stop(). Stop() published m_stopRequested (in the park predicate) "
|
||||
"BEFORE it rang, so a plain Notify should already have un-parked the thread; "
|
||||
"Doorbell::Kill() (Doorbell.h:211-221, table 3 step 2) is the belt to that "
|
||||
"Doorbell::Kill() (Doorbell.h, CondVarDoorbell::Kill; table 3 step 2) is "
|
||||
"the belt to that "
|
||||
"Notify's braces. If the thread is still parked after both, the wakeup was "
|
||||
"lost, not slow. Aborting rather than detaching: a detached apply thread still "
|
||||
"owns the context and would read rings the client is about to unmap",
|
||||
@@ -651,7 +761,10 @@ namespace MobileGL::MG_Remote::Server {
|
||||
std::abort();
|
||||
}
|
||||
m_thread.join();
|
||||
m_applyThreadId.store(std::thread::id{}, std::memory_order_release);
|
||||
// The identity is NOT cleared here any more: the thread clears it itself, under
|
||||
// m_controlMutex, beside the m_running store it used to be paired with. Clearing it a
|
||||
// second time after the join would be harmless but would also be the second place a
|
||||
// reader has to check to know when the key stops meaning "the apply thread".
|
||||
m_running.store(false, std::memory_order_release);
|
||||
m_session = nullptr;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
// kWaitForever waiter, not one, and the difference is the whole of review m-4: for the STOP case a
|
||||
// plain Doorbell::Notify() is sufficient, because m_stopRequested is in the park predicate and
|
||||
// Stop() publishes it BEFORE it rings (Doorbell.h re-tests ready() after every Park return);
|
||||
// Doorbell::Kill() (Doorbell.h:211-221) is load-bearing only for a predicate that has NOTHING to
|
||||
// see, which is why the redcheck's park-predicate-loses-control entry - the one that drops the
|
||||
// Doorbell::Kill() (Doorbell.h, CondVarDoorbell::Kill) is load-bearing only for a predicate
|
||||
// that has NOTHING to see, which is why the redcheck's park-predicate-loses-control entry - the one that drops the
|
||||
// control flag FROM the predicate - is the case that actually times out. Kill BEFORE join; join
|
||||
// before the client frees any emitter-owned Vector; and the join must be bounded (that test uses
|
||||
// 5 s) so a regression is a red test and not a hung CI job.
|
||||
@@ -74,11 +74,118 @@
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <type_traits>
|
||||
|
||||
namespace MobileGL::MG_Remote::Server {
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
// THE APPLY-THREAD IDENTITY, AS ONE INTEGER (P5d round 3, package D)
|
||||
// ---------------------------------------------------------------------------------
|
||||
//
|
||||
// OnApplyThread() is the predicate under EVERY role guard on both hot paths -
|
||||
// RefuseLegacyBufferArmFromApplyThread in BufferObject's accessors, PersistentMapTracker::
|
||||
// OnServerRole, ClientSession::RefusePipeInputsTouchWhileApplierOwnsIt, RunsAsTheServerRole,
|
||||
// MGPipeRefuseAllocatorFromApplyThread, RefuseLegacyTextureArmFromApplyThread. simpleperf at
|
||||
// head 56a77348 (FCL + Minecraft, VD12, Adreno 830) measured it at 2.66% self / 3.64%
|
||||
// inclusive ON THE CLIENT THREAD, for an answer that is "no" every single time.
|
||||
//
|
||||
// The old body paid five times over for that "no": ServerLoopInstance()'s function-static
|
||||
// guard byte, an acquire load of m_running, an acquire load of an atomic<std::thread::id>,
|
||||
// std::this_thread::get_id(), and a thread::id comparison that is an out-of-line
|
||||
// pthread_equal through the PLT (@plt was 6.1% of the apply thread). None of it carries
|
||||
// information the guard needs. A live thread's identity is already sitting in a
|
||||
// register-cheap place - the thread pointer, TPIDR_EL0 on aarch64 - so the loop publishes
|
||||
// ITS identity as a plain integer here and every caller compares one relaxed load against
|
||||
// one register read, inline, with no call and no singleton.
|
||||
//
|
||||
// ZERO MEANS "NO APPLY THREAD IS RUNNING", which is exactly the answer m_running == false
|
||||
// used to give: the key is published as the apply thread's FIRST act (ApplyThreadMain) and
|
||||
// cleared in the same m_controlMutex critical section that clears m_running on the way out
|
||||
// (ApplyThreadMain's C2 exit block), so "key != 0" and "m_running" move together and the
|
||||
// window in which a live-but-exiting apply thread answers true is byte-for-byte the old
|
||||
// one. The ServerLoop object still OWNS the key - nothing but ApplyThreadMain writes it -
|
||||
// it simply no longer has to be reached through the singleton to be read.
|
||||
namespace Detail {
|
||||
// RELAXED ON BOTH SIDES, and that is a claim about recycling, not a shrug. The only
|
||||
// dangerous outcome would be a NEW thread that reuses the exited apply thread's TLS
|
||||
// block (hence its thread pointer) while still reading the pre-clear key. It cannot
|
||||
// happen: the clear is sequenced before the apply thread's exit, the exit releases the
|
||||
// TLS block under libc's own lock, and the thread that later receives that block takes
|
||||
// the same lock - so the clear happens-before any load the new thread performs, and
|
||||
// coherence forbids a relaxed load from reading a value that a happens-before store
|
||||
// overwrote. A stale ZERO is harmless in the other direction: a thread that is not the
|
||||
// apply thread wants "false" anyway, and the apply thread always reads its own store.
|
||||
//
|
||||
// No acquire is needed for a second reason: this is an IDENTITY, not a handshake. No
|
||||
// caller publishes data through it; the real ordering lives in the ring, the doorbell
|
||||
// and m_controlMutex.
|
||||
inline std::atomic<Uint64> g_applyThreadKey{0};
|
||||
|
||||
// The calling thread's identity as the same integer. aarch64 - the split's only
|
||||
// measured target - reads TPIDR_EL0 with a single instruction and no call. Everywhere
|
||||
// else falls back to std::this_thread::get_id() memcpy'd into the key: still one libc
|
||||
// call, but the atomic<thread::id> load and the out-of-line pthread_equal that
|
||||
// dominated the old body are gone either way. x86_64 is deliberately NOT on the
|
||||
// builtin path - __builtin_thread_pointer only grew x86 support in clang 17 / GCC 11
|
||||
// and older toolchains accept __has_builtin for it and then fail in codegen, which is
|
||||
// a build break on the desktop ctest lane for a target whose frame rate nobody
|
||||
// measures.
|
||||
//
|
||||
// A LIVE THREAD'S KEY IS NEVER 0 on either path (a thread pointer is a real TLS
|
||||
// address; std::this_thread::get_id() on a running thread is never the
|
||||
// default-constructed id, whose object representation is the all-zero one on every
|
||||
// library in scope), which is what lets 0 mean "nobody".
|
||||
//
|
||||
// THE SELECTOR IS A BUILD KNOB, NOT A HEADER SECRET (review round 3). This header is
|
||||
// pulled into MG_State, MG_Impl and MG_Test translation units now, so the name carries
|
||||
// the MOBILEGL_DETAIL_ prefix to read as internal, it is #ifndef-guarded so a toolchain
|
||||
// whose __has_builtin(__builtin_thread_pointer) answers 1 and then fails in codegen can
|
||||
// be steered off the path with -DMOBILEGL_DETAIL_APPLY_THREAD_POINTER=0 instead of a
|
||||
// header edit, and it is always DEFINED - to 0 when unavailable - and tested with #if
|
||||
// rather than #ifdef, so that a -D...=0 really disables it instead of being ignored.
|
||||
#ifndef MOBILEGL_DETAIL_APPLY_THREAD_POINTER
|
||||
#if defined(__aarch64__) && defined(__has_builtin)
|
||||
#if __has_builtin(__builtin_thread_pointer)
|
||||
#define MOBILEGL_DETAIL_APPLY_THREAD_POINTER 1
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifndef MOBILEGL_DETAIL_APPLY_THREAD_POINTER
|
||||
#define MOBILEGL_DETAIL_APPLY_THREAD_POINTER 0
|
||||
#endif
|
||||
inline Uint64 CurrentThreadKey() {
|
||||
#if MOBILEGL_DETAIL_APPLY_THREAD_POINTER
|
||||
return static_cast<Uint64>(reinterpret_cast<std::uintptr_t>(__builtin_thread_pointer()));
|
||||
#else
|
||||
const std::thread::id id = std::this_thread::get_id();
|
||||
static_assert(sizeof(std::thread::id) <= sizeof(Uint64),
|
||||
"std::thread::id does not fit the apply-thread key; this fallback has "
|
||||
"to hash rather than copy on that platform");
|
||||
// AND IT MUST HAVE NO PADDING (review round 3). Copying the OBJECT REPRESENTATION of
|
||||
// a type that has padding bytes would let two calls ON THE SAME THREAD return
|
||||
// different keys, and OnApplyThread() would then answer FALSE ON THE APPLY THREAD -
|
||||
// a role guard that has stopped guarding, which is the one direction CONTRACT-P5C
|
||||
// rule E says a guard may never fail in (RunOnApplyThread would also lose its
|
||||
// re-entrancy shortcut and the EGL teardown post would deadlock on m_controlDone).
|
||||
// Every library this fallback is built against today wraps a single scalar
|
||||
// (libstdc++ __gthread_t, libc++ __libcpp_thread_id, MSVC unsigned int) and
|
||||
// satisfies this; one that did not is a BUILD ERROR here rather than a silently
|
||||
// dead guard at run time.
|
||||
static_assert(std::has_unique_object_representations_v<std::thread::id>,
|
||||
"std::thread::id has padding on this platform: copying its object "
|
||||
"representation would make the apply-thread key unstable within one "
|
||||
"thread. Hash the id (std::hash<std::thread::id>) instead.");
|
||||
Uint64 key = 0;
|
||||
std::memcpy(&key, &id, sizeof(id));
|
||||
return key;
|
||||
#endif
|
||||
}
|
||||
} // namespace Detail
|
||||
|
||||
class ServerLoop {
|
||||
public:
|
||||
// Creates the apply thread, names it mgl-srv-apply, applies
|
||||
@@ -131,7 +238,18 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// True on the apply thread itself. RunOnApplyThread uses it to run inline rather than
|
||||
// deadlock when the apply thread posts to itself - which the EGL teardown path does,
|
||||
// because ~BackendObject_DirectGLES runs THERE and reaches ReleaseEGLResources.
|
||||
static Bool OnApplyThread();
|
||||
//
|
||||
// INLINE, AND THAT IS THE POINT (P5d round 3, package D): see the Detail block above.
|
||||
// Every role guard in MG_State, MG_Impl, MG_Pipe and MG_Remote/Client asks this once
|
||||
// or more per draw, so the call itself - a cross-library PLT hop - was a measurable
|
||||
// share of the cost of the answer.
|
||||
static Bool OnApplyThread() {
|
||||
const Uint64 key = Detail::g_applyThreadKey.load(std::memory_order_relaxed);
|
||||
// Short-circuit ON PURPOSE: with TransportMode::Monolith, and in every process
|
||||
// before Start() and after Stop(), the key is 0 and the caller pays one relaxed
|
||||
// load and one branch - it never even reads its own identity.
|
||||
return key != 0 && key == Detail::CurrentThreadKey();
|
||||
}
|
||||
|
||||
// The CPU mask MOBILEGL_IPC_SERVER_AFFINITY resolved to and sched_setaffinity accepted.
|
||||
// 0 means "no affinity was applied" - the honest answer for `off`, for a platform with
|
||||
@@ -146,6 +264,13 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// fail for its own reason.
|
||||
Uint64 DrainedRecords() const;
|
||||
Uint64 ParkCount() const;
|
||||
// How many of those waits ran out of spin budget and really blocked. ParkCount is an
|
||||
// INTENTION (counted on the way toward a park, C10's note); this is the outcome, and
|
||||
// the pair is what says whether MOBILEGL_IPC_SPIN_US is sized for the workload. It is
|
||||
// this loop's OWN tally rather than the consumer bell's ParkEntries() because a bell
|
||||
// belongs to an endpoint and counts every waiter on it; only a tally passed into the
|
||||
// one Wait this loop makes is guaranteed to stay a subset of ParkCount().
|
||||
Uint64 ParkBlockCount() const;
|
||||
// Scheduling perturbation only: the hook runs after application, before retirement.
|
||||
// Integration tests use it to observe real producer back-pressure from GL uploads.
|
||||
void SetBeforeRetireHookForTesting(void (*hook)()) {
|
||||
@@ -192,11 +317,35 @@ namespace MobileGL::MG_Remote::Server {
|
||||
void ForgetCurrentTuple();
|
||||
void ForgetCurrentTupleIfItNames(EGLSurface surface);
|
||||
|
||||
private:
|
||||
void ApplyThreadMain();
|
||||
// Part of the apply thread's park predicate: a posted control request must be able to
|
||||
// un-park a thread waiting on kWaitForever, which a Notify alone cannot do.
|
||||
//
|
||||
// IT READS ONE ATOMIC AND TAKES NO LOCK (P5d round 3, package T item 1). It used to
|
||||
// take m_controlMutex on every call, and the idle poll calls it on every iteration -
|
||||
// once inside the `ready` lambda and once more through PumpControlRequest - which
|
||||
// simpleperf at head 56a77348 measured as ~49% of the whole apply thread's cycles
|
||||
// (mutex::lock 12.4 + mutex::unlock 13.6 + the two pthread_* halves, 58-60% of them
|
||||
// with ApplyThreadMain as the DIRECT caller). An idle poll on an empty ring must cost
|
||||
// loads, not a futex-backed critical section. m_controlPosted is that load; the
|
||||
// mailbox's own fields stay under the mutex and the handshake below is unchanged.
|
||||
//
|
||||
// PUBLIC because ServerLoopTest reads it: the clear side of the shadow has a failure
|
||||
// mode - a shadow left set makes `ready` permanently true and the loop never parks
|
||||
// again - that no other public surface can see.
|
||||
//
|
||||
// READ THE PREDICATE LITERALLY: "a request is POSTED AND NOT YET TAKEN", which is
|
||||
// narrower than the name's "a control request is in flight". The shadow is cleared
|
||||
// when the pump takes the work, not when the work returns, so for the whole duration
|
||||
// of `work(user)` this answers false although m_controlPending is still true and the
|
||||
// poster is still blocked in RunOnApplyThread. That is deliberate - it is a PARK
|
||||
// PREDICATE, and the thread that would act on it is the one running the work - but it
|
||||
// means this is not a liveness query and must not be used as one. The only in-tree
|
||||
// reader outside the test is the apply thread's own `ready` lambda, which by
|
||||
// construction cannot be inside that window.
|
||||
Bool ControlIsPending() const;
|
||||
|
||||
private:
|
||||
void ApplyThreadMain();
|
||||
// Runs a posted control request, if there is one. Returns true if it ran one.
|
||||
Bool PumpControlRequest();
|
||||
// Pops and applies every record currently in the ring; returns how many it applied.
|
||||
@@ -207,7 +356,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
std::atomic<Bool> m_running{false};
|
||||
std::atomic<Bool> m_stopRequested{false};
|
||||
std::thread m_thread;
|
||||
std::atomic<std::thread::id> m_applyThreadId{};
|
||||
// The apply thread's identity used to live here as an atomic<std::thread::id>. It is
|
||||
// Detail::g_applyThreadKey now - see the block at the top of this header for why the
|
||||
// identity had to stop being a member reachable only through ServerLoopInstance().
|
||||
|
||||
// The private backend object. Destroyed ON the apply thread while it still owns the
|
||||
// context - see Stop().
|
||||
@@ -217,7 +368,19 @@ namespace MobileGL::MG_Remote::Server {
|
||||
// client thread runnable at a time; m_callerMutex serialises anything that is not.
|
||||
std::mutex m_callerMutex;
|
||||
std::mutex m_controlMutex;
|
||||
std::condition_variable m_controlPosted;
|
||||
// THE MAILBOX'S ONE-BIT SHADOW, and the only field of it the idle poll may read.
|
||||
// Written to `true` by the poster under m_controlMutex AFTER m_controlPending, and
|
||||
// back to `false` under the same lock by whoever TAKES the request (PumpControlRequest,
|
||||
// or ApplyThreadMain's exit block when it answers NOT_INITIALIZED). A reader that sees
|
||||
// `true` through the release/acquire pair therefore also sees m_controlPending; a
|
||||
// reader that sees `false` cannot be missing a request, because the store precedes the
|
||||
// poster's Notify and Doorbell::Wait re-tests its predicate after every Park return.
|
||||
// The mutex still owns every other field - this is a fast NEGATIVE answer, not a second
|
||||
// copy of the mailbox.
|
||||
//
|
||||
// It replaces a std::condition_variable of the same name that had no waiter and no
|
||||
// notifier anywhere in the tree (m_controlDone is the one that carries the handshake).
|
||||
std::atomic<Bool> m_controlPosted{false};
|
||||
std::condition_variable m_controlDone;
|
||||
ControlWork m_controlWork = nullptr;
|
||||
void* m_controlUser = nullptr;
|
||||
@@ -235,6 +398,9 @@ namespace MobileGL::MG_Remote::Server {
|
||||
Uint64 m_affinityMask = 0;
|
||||
std::atomic<Uint64> m_drained{0};
|
||||
std::atomic<Uint64> m_parks{0};
|
||||
// Incremented by Doorbell::Wait through its `parkTally` out-parameter, once per wait
|
||||
// that reached the blocking Park. Relaxed everywhere: it is a gauge.
|
||||
std::atomic<Uint64> m_parkBlocks{0};
|
||||
std::atomic<void (*)()> m_beforeRetireHook{nullptr};
|
||||
|
||||
// C7 / ID-54: the (dpy, draw, read, ctx) currently bound on the apply thread. Written and
|
||||
|
||||
@@ -180,6 +180,87 @@ namespace MobileGL::MG_Remote::Server {
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// ---- P5e (ra), CONTRACT-P5E §2.6: the ring stops being a Fatal and becomes a queue --
|
||||
//
|
||||
// THE FATAL'S PREMISE DIES WITH THE LOCKSTEP. "A full ring is a producer burst no
|
||||
// workload has" was true because the client drained at EVERY verb: the ring was empty
|
||||
// whenever the server started a record, so filling 256 KiB inside one apply meant a
|
||||
// defect. A run-ahead client drains at its waits, which on the steady path are one
|
||||
// present apart, so a full ring is now an ordinary backlog and aborting on it would
|
||||
// turn the reverse channel's capacity into a workload limit.
|
||||
//
|
||||
// SO THE PRODUCER BLOCKS. It publishes what is already in the ring and rings the
|
||||
// client (a client that has not yet noticed cannot drain), then parks on its own bell
|
||||
// until the client's Drained() clears the latch and rings back. The deadlock argument
|
||||
// is the contract's, and it needs BOTH halves: the server blocks only here, the client
|
||||
// blocks only on watermarks the server advances, and every client park breaks on
|
||||
// `eventRingFull` as well (SessionProducer::WaitFor*OrEventBacklog) - so a parked
|
||||
// client is always wakeable by the server that is waiting for it.
|
||||
//
|
||||
// TWO NAMED REFUSALS SURVIVE, and they are the impossible cases rather than the busy
|
||||
// ones: a single event larger than the ring can EVER hold (no amount of draining
|
||||
// helps), and a wait that ran out of patience (the peer is gone or wedged). A server
|
||||
// that does not publish kCapRunAheadApply keeps P5C's Fatal unchanged.
|
||||
Bool ServerPublishesRunAhead(const ServerSession& session) {
|
||||
if (!session.CallMaskIsSet()) return false;
|
||||
return (session.CallMask() & static_cast<Uint64>(MG_Pipe::kCapRunAheadApply)) != 0;
|
||||
}
|
||||
|
||||
constexpr Uint32 kEventBacklogWaitMs = 30000;
|
||||
|
||||
void* ReserveEventOrBlock(ServerSession& session, Transport::EventKind kind,
|
||||
const char* eventName, Uint64 payloadBytes) {
|
||||
void* slot = session.Events().Reserve(kind, payloadBytes);
|
||||
if (slot != nullptr) return slot;
|
||||
if (!ServerPublishesRunAhead(session)) FatalEventRingOverflow(eventName, payloadBytes);
|
||||
|
||||
// Impossible case one: the record does not fit an EMPTY ring. Reserve caps one
|
||||
// record at capacity/2 (Ring.h), so no drain can ever make room and blocking would
|
||||
// be a hang with a comment on it.
|
||||
const Uint64 cap = session.Events().Ring().MaxRecordBytes();
|
||||
if (payloadBytes + sizeof(Transport::RingRecordHeader) > cap) {
|
||||
MGLOG_F("MGPipe: Fatal{EventRingOverflow} - %s needs %llu bytes and SEG_EVENT "
|
||||
"caps ONE record at %llu (half its capacity). Flow control cannot help: "
|
||||
"no amount of draining makes a record fit a ring that is too small for "
|
||||
"it. Raise MOBILEGL_IPC_EVENT_KB or slice the event at its producer, as "
|
||||
"the writeback path already does",
|
||||
eventName, static_cast<unsigned long long>(payloadBytes),
|
||||
static_cast<unsigned long long>(cap));
|
||||
std::abort();
|
||||
}
|
||||
|
||||
Transport::RingControl& control = session.Control();
|
||||
Transport::Doorbell& bell = session.ConsumerDoorbell();
|
||||
const auto drained = [&control] {
|
||||
return control.eventRingFull.load(std::memory_order_acquire) == 0;
|
||||
};
|
||||
for (Uint32 round = 0; round < 2; ++round) {
|
||||
// PUBLISH AND RING FIRST. The client cannot drain a ring whose head it has not
|
||||
// been shown, and the latch Reserve just set is only useful to a client that
|
||||
// gets a bell with it.
|
||||
session.PublishEvents();
|
||||
if (!drained() && !bell.Wait(control.consumerParked, drained, /*spinUs=*/0,
|
||||
kEventBacklogWaitMs)) {
|
||||
MGLOG_F("MGPipe: Fatal{EventRingOverflow} - %s waited %u ms for the client "
|
||||
"to drain SEG_EVENT and it never did. Under run-ahead the apply "
|
||||
"thread parks on this ring (CONTRACT-P5E §2.6); a client that does "
|
||||
"not drain is one that is not running",
|
||||
eventName, kEventBacklogWaitMs);
|
||||
std::abort();
|
||||
}
|
||||
slot = session.Events().Reserve(kind, payloadBytes);
|
||||
if (slot != nullptr) return slot;
|
||||
}
|
||||
// Two full rounds against a ring the record provably fits: something else is
|
||||
// producing into it, which on this side is impossible (one producer, the apply
|
||||
// thread, by construction).
|
||||
MGLOG_F("MGPipe: Fatal{EventRingOverflow} - %s could not reserve %llu bytes on an "
|
||||
"emptied SEG_EVENT. The apply thread is SEG_EVENT's only producer, so a "
|
||||
"drained ring that still refuses a record it fits is a corrupt cursor set",
|
||||
eventName, static_cast<unsigned long long>(payloadBytes));
|
||||
std::abort();
|
||||
}
|
||||
|
||||
void ServerOnBufferWriteback(MG_Pipe::MGPipeHandle res, Uint64 offset,
|
||||
MG_Pipe::MGPBlobRef bytes) {
|
||||
if (bytes.Seg != MG_Pipe::kMGHostSpanSegNone) {
|
||||
@@ -195,10 +276,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
ServerSession& session = ServerSessionInstance();
|
||||
const Uint64 payloadBytes = sizeof(Transport::EventBufferWritebackHead) + bytes.Size;
|
||||
void* slot = session.Events().Reserve(Transport::kEventBufferWriteback, payloadBytes);
|
||||
if (slot == nullptr) {
|
||||
FatalEventRingOverflow("kEventBufferWriteback", payloadBytes);
|
||||
}
|
||||
void* slot = ReserveEventOrBlock(session, Transport::kEventBufferWriteback,
|
||||
"kEventBufferWriteback", payloadBytes);
|
||||
Transport::EventBufferWritebackHead head{};
|
||||
head.Resource = Transport::EventHandle{res.Slot, res.Gen};
|
||||
head.Offset = offset;
|
||||
@@ -217,10 +296,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
ServerSession& session = ServerSessionInstance();
|
||||
const Uint64 tailBytes = static_cast<Uint64>(rangeCount) * sizeof(Transport::EventRange);
|
||||
const Uint64 payloadBytes = sizeof(Transport::EventGpuWrittenHead) + tailBytes;
|
||||
void* slot = session.Events().Reserve(Transport::kEventGpuWritten, payloadBytes);
|
||||
if (slot == nullptr) {
|
||||
FatalEventRingOverflow("kEventGpuWritten", payloadBytes);
|
||||
}
|
||||
void* slot = ReserveEventOrBlock(session, Transport::kEventGpuWritten,
|
||||
"kEventGpuWritten", payloadBytes);
|
||||
Transport::EventGpuWrittenHead head{};
|
||||
head.Resource = Transport::EventHandle{res.Slot, res.Gen};
|
||||
head.RangeCount = static_cast<std::uint32_t>(rangeCount);
|
||||
@@ -237,10 +314,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
void ServerOnSurfaceChanged(const MG_Pipe::MGPSurfaceInfo* info) {
|
||||
ServerSession& session = ServerSessionInstance();
|
||||
constexpr Uint64 payloadBytes = sizeof(Transport::EventSurfaceChangedHead);
|
||||
void* slot = session.Events().Reserve(Transport::kEventSurfaceChanged, payloadBytes);
|
||||
if (slot == nullptr) {
|
||||
FatalEventRingOverflow("kEventSurfaceChanged", payloadBytes);
|
||||
}
|
||||
void* slot = ReserveEventOrBlock(session, Transport::kEventSurfaceChanged,
|
||||
"kEventSurfaceChanged", payloadBytes);
|
||||
Transport::EventSurfaceChangedHead head{};
|
||||
if (info != nullptr) {
|
||||
head.Width = info->Width;
|
||||
@@ -649,10 +724,8 @@ namespace MobileGL::MG_Remote::Server {
|
||||
}
|
||||
const Uint32 messageBytes = static_cast<Uint32>(length) + 1;
|
||||
const Uint64 payloadBytes = sizeof(Transport::EventGlErrorHead) + messageBytes;
|
||||
void* slot = m_events.Reserve(Transport::kEventGlError, payloadBytes);
|
||||
if (slot == nullptr) {
|
||||
FatalEventRingOverflow("kEventGlError", payloadBytes);
|
||||
}
|
||||
void* slot = ReserveEventOrBlock(*this, Transport::kEventGlError, "kEventGlError",
|
||||
payloadBytes);
|
||||
Transport::EventGlErrorHead head{};
|
||||
head.Code = code;
|
||||
head.MessageBytes = messageBytes;
|
||||
|
||||
@@ -28,6 +28,112 @@
|
||||
|
||||
namespace MobileGL::MG_Remote::Transport {
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// The spin calibration (Doorbell.h's SpinItersPerUs block has the argument)
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
namespace Detail {
|
||||
|
||||
std::atomic<std::uint32_t> g_spinItersPerUs{0};
|
||||
|
||||
namespace {
|
||||
|
||||
// The probe's length. Big enough that one steady_clock read at each end is
|
||||
// a rounding error against it (a few microseconds of loop), small enough
|
||||
// that a thread calibrating on its first wait does not visibly stall: at
|
||||
// any plausible rate this is 2-30 us.
|
||||
constexpr std::uint32_t kProbeIterations = 8192;
|
||||
|
||||
// The clamps. Neither is a guess about a device - they are the bounds
|
||||
// outside which the READING itself cannot be true. A real iteration is an
|
||||
// acquire load plus a yield/pause: below ~0.5 ns each (2000/us) no core
|
||||
// retires it, and above ~250 ns each (4/us) the probe was preempted or the
|
||||
// clock is lying. Clamping is what keeps a bad reading from turning a 50 us
|
||||
// hint into a millisecond spin or into no spin at all.
|
||||
constexpr std::uint32_t kMinSpinItersPerUs = 4;
|
||||
constexpr std::uint32_t kMaxSpinItersPerUs = 2000;
|
||||
|
||||
// What a platform with a clock too coarse to measure the probe gets. 200
|
||||
// iterations per microsecond is the middle of the plausible range (5 ns an
|
||||
// iteration); the fallback exists so that an unmeasurable clock produces a
|
||||
// spin of roughly the right order rather than none. It is NOT what a
|
||||
// measurably slow probe gets - see the clamp at the bottom of this
|
||||
// function, which keeps the two readings apart.
|
||||
constexpr std::uint32_t kFallbackSpinItersPerUs = 200;
|
||||
|
||||
} // namespace
|
||||
|
||||
std::uint32_t CalibrateSpinItersPerUs() {
|
||||
// The probe body is the spin loop's body with the caller's `ready()` replaced
|
||||
// by an atomic load the compiler may not hoist and may not fold: an atomic
|
||||
// the optimiser cannot prove constant is the only portable way to keep the
|
||||
// loop from vanishing, and it is also the closest thing to what a real
|
||||
// `ready()` costs.
|
||||
std::atomic<std::uint32_t> probe{0};
|
||||
|
||||
// TWO PASSES, AND THE FASTER ONE WINS. The first pass pays the i-cache miss,
|
||||
// the branch predictor's warm-up and - on a big.LITTLE phone - the tail of a
|
||||
// frequency ramp; the second is the reading. Taking the MAXIMUM rather than
|
||||
// the last value is the deliberate choice: a pass that was preempted reads
|
||||
// absurdly slow, and under-spinning costs a park (a syscall and a context
|
||||
// switch) while over-spinning costs cycles the thread had nothing else to do
|
||||
// with. Both directions stay inside the clamps.
|
||||
//
|
||||
// "Did any pass produce a number at all?" - which is a DIFFERENT question
|
||||
// from "was the number small?", and conflating them is how a starved machine
|
||||
// ends up with the largest spin in the table. See the clamp below.
|
||||
bool sawUsableClock = false;
|
||||
std::uint32_t best = 0;
|
||||
for (int pass = 0; pass < 2; ++pass) {
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
for (std::uint32_t i = 0; i < kProbeIterations; ++i) {
|
||||
if (probe.load(std::memory_order_acquire) != 0) {
|
||||
break;
|
||||
}
|
||||
CpuRelax();
|
||||
}
|
||||
const auto elapsedNs = std::chrono::duration_cast<std::chrono::nanoseconds>(
|
||||
std::chrono::steady_clock::now() - start)
|
||||
.count();
|
||||
if (elapsedNs <= 0) {
|
||||
continue; // clock too coarse to see this probe at all
|
||||
}
|
||||
sawUsableClock = true;
|
||||
const std::uint64_t perUs = (static_cast<std::uint64_t>(kProbeIterations) * 1000ull) /
|
||||
static_cast<std::uint64_t>(elapsedNs);
|
||||
const std::uint32_t clamped =
|
||||
perUs > kMaxSpinItersPerUs ? kMaxSpinItersPerUs : static_cast<std::uint32_t>(perUs);
|
||||
if (clamped > best) {
|
||||
best = clamped;
|
||||
}
|
||||
}
|
||||
// THE TWO READINGS THAT BOTH ARRIVE AS best == 0 ARE OPPOSITE, and the first
|
||||
// cut of this clamp answered them the same way. `perUs` is
|
||||
// kProbeIterations*1000/elapsedNs, so it truncates to zero as soon as a pass
|
||||
// takes longer than 8.192 ms - that is EXACTLY the heavily preempted probe on
|
||||
// an oversubscribed runner or a thermally throttled device, and handing it
|
||||
// kFallbackSpinItersPerUs would install 200 iters/us (50x the floor, ~10 ms of
|
||||
// busy spin per 50 us wait) on the one machine that can least afford it. A
|
||||
// probe that never saw a usable clock is the opposite case: nothing was
|
||||
// measured, the machine may be perfectly fast, and a mid-range guess is the
|
||||
// only sane answer. So: measured-but-slow clamps UP to the floor, unmeasurable
|
||||
// takes the fallback.
|
||||
if (best < kMinSpinItersPerUs) {
|
||||
best = sawUsableClock ? kMinSpinItersPerUs : kFallbackSpinItersPerUs;
|
||||
}
|
||||
// Relaxed, and a race here is not a bug: two threads that calibrate at the
|
||||
// same moment both store a legitimate budget, and the loser's is as usable as
|
||||
// the winner's. A once_flag would put a guard-variable load on every Wait,
|
||||
// which is the cost this whole change exists to remove.
|
||||
g_spinItersPerUs.store(best, std::memory_order_relaxed);
|
||||
MGLOG_D("MG_Remote doorbell: spin calibrated at %u iterations per microsecond "
|
||||
"(clock-free spin budget = that times MOBILEGL_IPC_SPIN_US)",
|
||||
static_cast<unsigned>(best));
|
||||
return best;
|
||||
}
|
||||
|
||||
} // namespace Detail
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// CondVarDoorbell
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
@@ -83,6 +83,62 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
#endif
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// THE SPIN BUDGET IS COUNTED IN ITERATIONS, NOT IN CLOCK READS.
|
||||
//
|
||||
// WHY IT CHANGED (P5d round 3, package T item 3). Wait() used to spin until
|
||||
// steady_clock passed `start + spinUs`, reading the clock once per 64 spins.
|
||||
// On the workload device a steady_clock read is a real syscall (no vDSO), and
|
||||
// simpleperf at head 56a77348 measured the GL thread paying
|
||||
// steady_clock::now() 2.34 self / 5.91 inclusive plus __kernel_clock_gettime
|
||||
// 2.37 and clock_gettime 1.94 - about 6.6% of the thread spent asking what
|
||||
// time it is, at 900+ waits per frame, for a duration that is a HINT. The
|
||||
// common case (WaitForApplied, server not yet there) paid at least two of
|
||||
// those reads per wait even when the spin succeeded on its second iteration.
|
||||
//
|
||||
// WHAT REPLACES IT. Once per process the loop measures itself: how many
|
||||
// `load(acquire)` + CpuRelax() iterations fit in a microsecond. Wait() then
|
||||
// spins `itersPerUs * spinUs` iterations and reads no clock at all; only the
|
||||
// park phase - which is about to block, so a syscall there is noise - computes
|
||||
// a deadline.
|
||||
//
|
||||
// THE OVERSHOOT BOUND, STATED HONESTLY. The old loop overshot by at most one
|
||||
// batch of 64 yields. This one overshoots by whatever the calibration was
|
||||
// wrong by, and the calibration is a single reading taken on one core at one
|
||||
// frequency:
|
||||
// - a later DVFS drop or a migration to a little core stretches the spin by
|
||||
// the frequency ratio (on the workload device's big/little spread that is
|
||||
// bounded by roughly 3-4x, so a 50 us budget can become ~200 us);
|
||||
// - a preemption inside the spin adds one scheduler slice, exactly as before;
|
||||
// - the calibration probe does not run the caller's `ready()`, which is one
|
||||
// or two acquire loads, so a real iteration is dearer than a probed one and
|
||||
// the spin ends EARLY rather than late by that factor;
|
||||
// - the clamps below cap the pathological directions: a probe that was
|
||||
// preempted cannot produce a budget smaller than kMinSpinItersPerUs, and a
|
||||
// probe that saw a broken clock cannot produce one larger than
|
||||
// kMaxSpinItersPerUs.
|
||||
// None of it is a correctness bound: `ready()` is re-tested every iteration
|
||||
// and the deadline, when there is one, is still measured against the real
|
||||
// clock in the park phase. The cost of being wrong is CPU burnt before a park
|
||||
// (too long) or a park that a few more spins would have avoided (too short).
|
||||
// -----------------------------------------------------------------------
|
||||
namespace Detail {
|
||||
// 0 until the first Wait calibrates it. Plain relaxed atomic rather than a
|
||||
// function-local static: a static's guard variable is a load and a branch on
|
||||
// EVERY Wait, and the whole point of this block is that the common path is a
|
||||
// load and a predicted branch.
|
||||
extern std::atomic<std::uint32_t> g_spinItersPerUs;
|
||||
// Measures, clamps, stores and returns. Two threads that race here both
|
||||
// store a legitimate reading and neither is wrong; there is nothing to
|
||||
// serialise, so nothing does.
|
||||
std::uint32_t CalibrateSpinItersPerUs();
|
||||
} // namespace Detail
|
||||
|
||||
inline std::uint32_t SpinItersPerUs() {
|
||||
const std::uint32_t cached = Detail::g_spinItersPerUs.load(std::memory_order_relaxed);
|
||||
return cached != 0 ? cached : Detail::CalibrateSpinItersPerUs();
|
||||
}
|
||||
|
||||
class Doorbell {
|
||||
public:
|
||||
virtual ~Doorbell() = default;
|
||||
@@ -115,34 +171,95 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
// bell that cannot die.
|
||||
virtual bool Dead() const { return false; }
|
||||
|
||||
// How many Wait() calls on this bell exhausted their spin budget and
|
||||
// really blocked. THE WAIT LEDGER'S RAW READING: the pair (waits, parks)
|
||||
// is what says whether the spin budget is sized for the workload, and it
|
||||
// is the one number a wait counter cannot give - a wait that spun and a
|
||||
// wait that blocked cost three orders of magnitude apart.
|
||||
//
|
||||
// ONCE PER Wait, NOT ONCE PER Park: a wait that blocks, wakes on a
|
||||
// remembered Notify, re-tests false and blocks again is ONE wait that
|
||||
// paid the park, and a `chunkMs == 0` Park is a poll that does not block
|
||||
// at all. Both are counted out at the site below, so parks <= waits holds
|
||||
// for a single waiter.
|
||||
//
|
||||
// PER BELL, THOUGH, NOT PER WAIT PATH. A bell belongs to an ENDPOINT and
|
||||
// every waiter on that endpoint shares it: the client's self bell carries
|
||||
// SessionProducer's barrier waits AND the encoder's SEG_STAGE retirement
|
||||
// wait (PipeWireCodec's m_stageRetirementBell, which is the same object).
|
||||
// A ledger that prints parks as the subset of ITS OWN waits must pass a
|
||||
// `parkTally` to Wait rather than read this; this counter answers "parks
|
||||
// on this bell", which is what a test on a private bell wants.
|
||||
//
|
||||
// Read from any thread; the counter is monotone and relaxed, so a reader
|
||||
// may see a value one behind, which is exactly what a per-frame gauge
|
||||
// wants.
|
||||
std::uint64_t ParkEntries() const { return m_parkEntries.load(std::memory_order_relaxed); }
|
||||
|
||||
// Spin `spinUs`, then park until `ready()` or the deadline.
|
||||
// `parked` is the RingControl flag the peer tests before ringing.
|
||||
//
|
||||
// `parkTally`, when given, is incremented alongside this bell's own park
|
||||
// counter - once, the first time THIS call really blocks. It is how a
|
||||
// caller gets parks that are a subset of its OWN waits off a bell it
|
||||
// shares with another subsystem; see ParkEntries() above.
|
||||
template <class Ready>
|
||||
bool Wait(std::atomic<std::uint32_t>& parked, Ready&& ready, std::uint32_t spinUs,
|
||||
std::uint32_t timeoutMs) {
|
||||
std::uint32_t timeoutMs, std::atomic<std::uint64_t>* parkTally = nullptr) {
|
||||
if (ready()) {
|
||||
return true;
|
||||
}
|
||||
const auto start = std::chrono::steady_clock::now();
|
||||
const auto deadline = timeoutMs == kWaitForever
|
||||
? std::chrono::steady_clock::time_point::max()
|
||||
: start + std::chrono::milliseconds(timeoutMs);
|
||||
|
||||
const auto spinEnd = start + std::chrono::microseconds(spinUs);
|
||||
// The clock is read once per 64 spins, not per spin: on the
|
||||
// workload device a steady_clock read is a REAL syscall (no vDSO),
|
||||
// and per-iteration reads made this loop the profile's top line
|
||||
// (~20% of the whole process at ~1000 waits per frame). The spin
|
||||
// duration is a hint, so the overshoot - one batch of yields at
|
||||
// most - costs nothing.
|
||||
std::uint32_t spinBatch = 0;
|
||||
while ((++spinBatch & 63) != 0 || std::chrono::steady_clock::now() < spinEnd) {
|
||||
// THE SPIN PHASE READS NO CLOCK AT ALL. It used to read one per 64
|
||||
// iterations plus one before the loop - see the SpinItersPerUs block
|
||||
// above for the measurement that made even that too dear, and for the
|
||||
// overshoot bound the iteration budget buys instead. The duration is
|
||||
// still a hint; what changed is that asking for it is free.
|
||||
//
|
||||
// spinUs == 0 NOW MEANS ZERO ITERATIONS, AND THAT IS A DELIBERATE CHANGE
|
||||
// rather than a side effect. The old batched loop tested
|
||||
// `(++spinBatch & 63) != 0 || now < spinEnd`, so a caller that asked for
|
||||
// no spin still ran 63 iterations before the first clock read could end
|
||||
// the loop. That was an artifact of the batch size, never a promise, and
|
||||
// multiplying a budget the caller deliberately set to zero would be the
|
||||
// wrong way to keep it. Two callers pass 0: PipeWireCodec's SEG_STAGE
|
||||
// retirement wait (rare, already slow, and it wants the park) and any
|
||||
// lane that sets MOBILEGL_IPC_SPIN_US=0 as a no-spin control, which now
|
||||
// really gets no spin - which is the point of such a control. The
|
||||
// short-circuit also keeps a zero-spin caller from paying the one-time
|
||||
// calibration probe for a reading it will never multiply by.
|
||||
const std::uint64_t budget =
|
||||
spinUs == 0 ? 0ull
|
||||
: static_cast<std::uint64_t>(SpinItersPerUs()) *
|
||||
static_cast<std::uint64_t>(spinUs);
|
||||
for (std::uint64_t spun = 0; spun < budget; ++spun) {
|
||||
if (ready()) {
|
||||
return true;
|
||||
}
|
||||
CpuRelax();
|
||||
}
|
||||
|
||||
// THE PARK PHASE, AND THE ONLY PLACE A DEADLINE IS COMPUTED. Reading
|
||||
// the clock here is free in the sense that matters: this side is about
|
||||
// to block on a condition variable or a poll(), which costs orders of
|
||||
// magnitude more than the syscall that sizes it. kWaitForever reads no
|
||||
// clock even here.
|
||||
//
|
||||
// THE DEADLINE STARTS NOW, NOT WHEN Wait WAS ENTERED. The spin the
|
||||
// caller asked for is no longer charged against its timeout, so the
|
||||
// total is bounded by `timeoutMs + the spin budget` rather than by
|
||||
// `timeoutMs`. spinUs is 50 by default and the timeouts that reach
|
||||
// here are milliseconds (the verb barrier's 30 s, the drain's bound),
|
||||
// so the drift is under a part in a thousand - and erring LONG is the
|
||||
// safe direction for a deadline whose expiry is reported as a timeout.
|
||||
const auto deadline = timeoutMs == kWaitForever
|
||||
? std::chrono::steady_clock::time_point::max()
|
||||
: std::chrono::steady_clock::now() +
|
||||
std::chrono::milliseconds(timeoutMs);
|
||||
|
||||
// ONE PARK PER Wait is what the ledger counts, and this loop may Park
|
||||
// many times for one Wait; see the counting site below.
|
||||
bool countedPark = false;
|
||||
for (;;) {
|
||||
// Announce, FENCE, then re-test. The fence is the mechanism -
|
||||
// see the file header - so setting the flag itself is relaxed.
|
||||
@@ -163,6 +280,34 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(deadline - now).count();
|
||||
chunkMs = remaining <= 0 ? 0 : static_cast<std::uint32_t>(remaining);
|
||||
}
|
||||
// COUNTED HERE, at the one place a waiter stops spinning and
|
||||
// really blocks (P5d round 3, package T item 4). Unconditional
|
||||
// rather than behind the stats latch: it is one relaxed add on a
|
||||
// path that is about to enter a condition variable or a poll(),
|
||||
// and a counter that only exists when MOBILEGL_PIPE_STATS is set
|
||||
// could not be read by a test that wants to prove the spin budget
|
||||
// avoided the park.
|
||||
//
|
||||
// TWO THINGS ARE COUNTED OUT, because this number is published as
|
||||
// the SUBSET of the waits that blocked, and a subset that can
|
||||
// exceed its own denominator is worse than no number at all:
|
||||
// - RE-PARKS. One Wait can traverse this loop many times: a
|
||||
// CondVarDoorbell remembers a Notify delivered while nobody
|
||||
// was waiting, so Park returns at once, `ready()` is still
|
||||
// false (the peer had already drained what it published) and
|
||||
// the wait parks again. That is one wait that paid a park, not
|
||||
// two, so only the first is counted.
|
||||
// - POLLS. `chunkMs == 0` is the last sub-millisecond of a
|
||||
// finite timeout rounding down; Park(0) does not block, and
|
||||
// counting it would charge a park per iteration of a tight
|
||||
// re-test loop that never left the CPU.
|
||||
if (chunkMs != 0 && !countedPark) {
|
||||
countedPark = true;
|
||||
m_parkEntries.fetch_add(1, std::memory_order_relaxed);
|
||||
if (parkTally != nullptr) {
|
||||
parkTally->fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
Park(chunkMs);
|
||||
// Clearing is relaxed on purpose: a notifier that reads a
|
||||
// stale 1 only rings a bell nobody is waiting on, which the
|
||||
@@ -188,6 +333,9 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
|
||||
protected:
|
||||
Doorbell() = default;
|
||||
|
||||
private:
|
||||
std::atomic<std::uint64_t> m_parkEntries{0};
|
||||
};
|
||||
|
||||
// Rings `bell` only when the peer said it is parked.
|
||||
|
||||
@@ -151,7 +151,7 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
}
|
||||
|
||||
// Publish, THEN ring - the same order as the forward direction, and for
|
||||
// the same reason (Doorbell.h:186-193: the fence only orders what
|
||||
// the same reason (NotifyIfParked's PRECONDITION: the fence only orders what
|
||||
// precedes it, so ringing first reopens the lost-wakeup window).
|
||||
void PublishAndNotify(Doorbell& clientBell, std::atomic<std::uint32_t>& producerParked) {
|
||||
m_producer.Publish();
|
||||
@@ -189,10 +189,26 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
void Drained() {
|
||||
m_consumer.PublishRetired();
|
||||
if (m_cmdControl != nullptr) {
|
||||
m_cmdControl->eventRingFull.store(0, std::memory_order_release);
|
||||
// P5e (ra, CONTRACT-P5E §2.6): CLEARING THE LATCH IS ONLY HALF OF IT. Under
|
||||
// flow control the server is PARKED on this flag - either inside a producer
|
||||
// that could not Reserve, or at a record boundary refusing to start the next
|
||||
// record - and a cleared flag with no bell is a wakeup lost exactly the way
|
||||
// the forward direction's publish-then-ring order exists to prevent. The
|
||||
// exchange is what makes the ring one-shot: only the drain that actually found
|
||||
// the flag up rings, so a steady stream of drains costs one relaxed RMW.
|
||||
const bool wasFull =
|
||||
m_cmdControl->eventRingFull.exchange(0, std::memory_order_acq_rel) != 0;
|
||||
if (wasFull && m_serverBell != nullptr) {
|
||||
NotifyIfParked(*m_serverBell, m_cmdControl->consumerParked);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The bell the SERVER parks on, lent by the session so that Drained() can ring it.
|
||||
// Null in every fixture that consumes a ring without a server behind it, and the
|
||||
// ring's clear then behaves exactly as it did before P5e.
|
||||
void SetServerDoorbell(Doorbell* bell) { m_serverBell = bell; }
|
||||
|
||||
// Byte offset of `payload` inside SEG_EVENT, which is what an
|
||||
// OnBufferWriteback MGPBlobRef must carry (Seg = kSegEvent, Offset =
|
||||
// this, Size = the head's Size). Never a host address - R-2's rule B.
|
||||
@@ -217,6 +233,8 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
RingControl* m_cmdControl = nullptr;
|
||||
RingConsumer m_consumer;
|
||||
const std::uint8_t* m_segmentBase = nullptr;
|
||||
// P5e (ra): the server's bell, rung by Drained() when it cleared a full latch.
|
||||
Doorbell* m_serverBell = nullptr;
|
||||
};
|
||||
|
||||
} // namespace MobileGL::MG_Remote::Transport
|
||||
|
||||
@@ -466,7 +466,15 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
if (!Valid() || m_selfBell == nullptr) {
|
||||
return SessionWait::TimedOut;
|
||||
}
|
||||
if (m_selfBell->Wait(m_control->producerParked, ready, m_spinUs, timeoutMs)) {
|
||||
// COUNTED BEFORE THE WAIT AND ONLY WHEN ONE REALLY HAPPENS - after the two refusals
|
||||
// above, which answer TimedOut without ever reaching the bell. See Waits()/Parks() in
|
||||
// the header for why the pair is the reading and either number alone is not.
|
||||
m_waits.fetch_add(1, std::memory_order_relaxed);
|
||||
// &m_parks is the OTHER half of the pair, and it is passed rather than read off the
|
||||
// bell: the bell is this endpoint's and the encoder waits on it too, so its own
|
||||
// ParkEntries() is not a subset of the waits counted one line above. See Parks() in
|
||||
// SessionRings.h.
|
||||
if (m_selfBell->Wait(m_control->producerParked, ready, m_spinUs, timeoutMs, &m_parks)) {
|
||||
return SessionWait::Reached;
|
||||
}
|
||||
// Wait == false && Dead() is "the session was shut down", and it is the
|
||||
@@ -493,6 +501,40 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
timeoutMs);
|
||||
}
|
||||
|
||||
// P5e (ra), CONTRACT-P5E §2.6. Two predicates, one OR each, and the caller decides which
|
||||
// of the two happened by reading the watermark it actually cares about.
|
||||
bool SessionProducer::EventRingIsFull() const {
|
||||
return m_control != nullptr && m_control->eventRingFull.load(std::memory_order_acquire) != 0;
|
||||
}
|
||||
|
||||
SessionWait SessionProducer::WaitForAppliedOrEventBacklog(std::uint64_t seq,
|
||||
std::uint32_t timeoutMs) {
|
||||
if (!Valid()) {
|
||||
return SessionWait::TimedOut;
|
||||
}
|
||||
RingControl* control = m_control;
|
||||
return Park(
|
||||
[control, seq] {
|
||||
return Watermark::Reached(control->appliedSeq, seq) ||
|
||||
control->eventRingFull.load(std::memory_order_acquire) != 0;
|
||||
},
|
||||
timeoutMs);
|
||||
}
|
||||
|
||||
SessionWait SessionProducer::WaitForPresentAckOrEventBacklog(std::uint64_t serial,
|
||||
std::uint32_t timeoutMs) {
|
||||
if (!Valid()) {
|
||||
return SessionWait::TimedOut;
|
||||
}
|
||||
RingControl* control = m_control;
|
||||
return Park(
|
||||
[control, serial] {
|
||||
return Watermark::Reached(control->presentAckSerial, serial) ||
|
||||
control->eventRingFull.load(std::memory_order_acquire) != 0;
|
||||
},
|
||||
timeoutMs);
|
||||
}
|
||||
|
||||
SessionWait SessionProducer::WaitForCmdSpace(std::uint64_t bytes, std::uint32_t timeoutMs) {
|
||||
if (!Valid()) {
|
||||
return SessionWait::TimedOut;
|
||||
|
||||
@@ -267,7 +267,7 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
enum class SessionWait : std::uint32_t {
|
||||
Reached = 0,
|
||||
// The doorbell died: the peer shut the session down. The ONLY thing that
|
||||
// can un-park a waiter on kWaitForever (Doorbell.h:211-221), and the
|
||||
// can un-park a waiter on kWaitForever (CondVarDoorbell::Kill), and the
|
||||
// reason a bounded join is possible at all.
|
||||
ShutDown = 1,
|
||||
TimedOut = 2,
|
||||
@@ -302,7 +302,7 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
bool Valid() const { return m_control != nullptr && m_cmd != nullptr; }
|
||||
|
||||
// Publish the command ring's head, record submittedSeq, THEN ring - in
|
||||
// that order and never any other. Doorbell.h:186-193: the fence only
|
||||
// that order and never any other. NotifyIfParked's PRECONDITION: the fence only
|
||||
// orders what precedes it, so ringing before publishing reopens the very
|
||||
// lost-wakeup window the fences exist to close. RingTest.cpp:446 pins the
|
||||
// call order; this is the one place production code performs it.
|
||||
@@ -325,6 +325,22 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
SessionWait WaitForApplied(std::uint64_t seq, std::uint32_t timeoutMs);
|
||||
// Present throttle.
|
||||
SessionWait WaitForPresentAck(std::uint64_t serial, std::uint32_t timeoutMs);
|
||||
|
||||
// ---- P5e (ra), CONTRACT-P5E §2.6: the same two waits, PLUS the event ring ---------
|
||||
//
|
||||
// A parked client must be wakeable by a server that ran out of SEG_EVENT, or the
|
||||
// flow-control deadlock is one burst wide: the server stops producing, so it stops
|
||||
// applying, so appliedSeq never reaches the seq this waiter is parked on, so the ring
|
||||
// is never drained. Both predicates therefore break on `eventRingFull` as well, and
|
||||
// the CALLER re-reads the watermark to find out which of the two woke it - a third
|
||||
// SessionWait value would have made every existing `== Reached` site a bug.
|
||||
//
|
||||
// The old entry points above are unchanged and keep their callers: teardown's
|
||||
// WaitForApplied has no ring to drain and must not learn about one.
|
||||
SessionWait WaitForAppliedOrEventBacklog(std::uint64_t seq, std::uint32_t timeoutMs);
|
||||
SessionWait WaitForPresentAckOrEventBacklog(std::uint64_t serial, std::uint32_t timeoutMs);
|
||||
// True when the peer latched "SEG_EVENT is full and I stopped producing".
|
||||
bool EventRingIsFull() const;
|
||||
// Back-pressure when Reserve returned nullptr. NEVER call this when
|
||||
// FreeBytes() is already >= the record: Ring.h:226-233 - a nullptr with
|
||||
// enough free bytes can only mean "too big, chunk", and waiting on it
|
||||
@@ -337,6 +353,29 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
Doorbell* SelfDoorbell() const { return m_selfBell; }
|
||||
std::uint32_t SpinUs() const { return m_spinUs; }
|
||||
|
||||
// THE WAIT LEDGER'S CLIENT HALF (P5d round 3, package T item 4), and it is a PAIR
|
||||
// because one number without the other says nothing. `Waits()` is every entry into
|
||||
// Park - the R-1 barrier's wait, the present throttle and the ring-space wait, which
|
||||
// simpleperf at head 56a77348 measured as WaitForApplied 27.9% self on the GL thread;
|
||||
// `Parks()` is how many of them ran out of spin budget and actually blocked. A high
|
||||
// wait count with near-zero parks is a thread spinning on a server that is nearly
|
||||
// there; a high park count is a server that is not. The two readings are what tell
|
||||
// those apart, and the split's whole frame budget turns on which one it is.
|
||||
//
|
||||
// Both counters are OURS, and the park one deliberately is not the bell's own
|
||||
// ParkEntries(). Doorbell::Wait is the only code that knows whether its spin budget
|
||||
// ran out, so it does the counting - but a bell belongs to an ENDPOINT, not to a wait
|
||||
// path, and this one is shared: ClientSession hands the very same object to the
|
||||
// encoder as its SEG_STAGE retirement bell (ClientSession::Start ->
|
||||
// PipeWireCodec::SetStageRetirementDoorbell), whose waits never pass through
|
||||
// SessionProducer::Park and so never reach m_waits. Reading ParkEntries() here would
|
||||
// fold that second subsystem's parks into a number this header, PipeStats and the
|
||||
// summary line all describe as the subset of OUR waits - and with the retirement
|
||||
// wait's spinUs of 0 it parks every time, so the subset could print larger than the
|
||||
// set it is a subset of. Wait's `parkTally` out-parameter exists for exactly this.
|
||||
std::uint64_t Waits() const { return m_waits.load(std::memory_order_relaxed); }
|
||||
std::uint64_t Parks() const { return m_parks.load(std::memory_order_relaxed); }
|
||||
|
||||
private:
|
||||
template <class Ready>
|
||||
SessionWait Park(Ready&& ready, std::uint32_t timeoutMs);
|
||||
@@ -347,6 +386,13 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
Doorbell* m_selfBell = nullptr;
|
||||
std::uint32_t m_spinUs = kDefaultSpinUs;
|
||||
std::uint64_t m_lastPublishedSeq = 0;
|
||||
// Relaxed atomics, not plain integers: the GL thread owns this producer, but
|
||||
// ClientSession::Stop's bounded drain waits through it from whichever thread is tearing
|
||||
// the session down, and a diagnostic is not worth a data race. Relaxed costs the same
|
||||
// as a plain add on both architectures the split runs on. m_parks is incremented by
|
||||
// Doorbell::Wait through the `parkTally` pointer, once per wait that really blocked.
|
||||
std::atomic<std::uint64_t> m_waits{0};
|
||||
std::atomic<std::uint64_t> m_parks{0};
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
@@ -449,7 +495,7 @@ namespace MobileGL::MG_Remote::Transport {
|
||||
|
||||
// Ring the client's bell, but only when it said it is parked: a store to
|
||||
// a shared cache line otherwise burns a big core for a whole frame on a
|
||||
// phone (Doorbell.h:13-22).
|
||||
// phone (Doorbell.h's file header, the bidirectional argument).
|
||||
void NotifyClient();
|
||||
|
||||
std::uint64_t AppliedSeq() const { return m_appliedSeq; }
|
||||
|
||||
@@ -242,7 +242,8 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
X(CopyFramebufferToTexture, MGPCopyFromFramebuffer) \
|
||||
X(ApplierReset, MGPApplierReset) \
|
||||
X(ObjectDeath, MGPHandleOnly) \
|
||||
X(SetContextValues, MGPContextValues)
|
||||
X(SetContextValues, MGPContextValues) \
|
||||
X(SetProgramBindings, MGPProgramBindings)
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -602,6 +603,7 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
// believed, and the bound is the header's own 32-bit Size field.
|
||||
Uint64 tail0 = 0;
|
||||
Uint64 tail1 = 0;
|
||||
Uint64 tail2 = 0; // P5e: set_program_bindings is the one three-tail row
|
||||
Uint32 tails = 0;
|
||||
switch (op) {
|
||||
case MGPWireOp::SetVertexBuffers: {
|
||||
@@ -650,6 +652,17 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
// (MGPipeTypes.h:820-823), because the two arrays stay index-aligned; a third
|
||||
// value would let a record describe spans for ranges it does not have.
|
||||
const auto& p = *static_cast<const MGPShaderBuffers*>(payload);
|
||||
// P5e (sb, CONTRACT-P5E.md §1): the class and the window, bounded HERE as well as
|
||||
// in the applier and for the reason SetShaderImages' Count is bounded here - this
|
||||
// is the arm that turns Count into a byte length, so a forged count has to be
|
||||
// refused before it is multiplied rather than after.
|
||||
if (p.Class >= kMGPipeShaderBufferClassCount) {
|
||||
WireProtocolFatalAt("SetShaderBuffers.Class", p.Class, kMGPipeShaderBufferClassCount);
|
||||
}
|
||||
if (static_cast<Uint64>(p.Start) + p.Count > kMGPipeMaxBufferBindingPoints) {
|
||||
WireProtocolFatalAt("SetShaderBuffers.Count", static_cast<Uint64>(p.Start) + p.Count,
|
||||
kMGPipeMaxBufferBindingPoints);
|
||||
}
|
||||
if (p.HostSpanCount != 0 && p.HostSpanCount != p.Count) {
|
||||
WireProtocolFatalAt("SetShaderBuffers.HostSpanCount", p.HostSpanCount, p.Count);
|
||||
}
|
||||
@@ -667,6 +680,47 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
tails = 2;
|
||||
break;
|
||||
}
|
||||
case MGPWireOp::SetProgramBindings: {
|
||||
// THREE TAILS, THREE COUNTS, THREE INDEX SPACES (P5e,
|
||||
// MG_Remote/CONTRACT-P5E.md §1): Int32[BlockBindingCount] in GL uniform-block index
|
||||
// order, MGPProgramSamplerUnit[SamplerUnitCount] ascending by Location, and
|
||||
// MGPProgramStorageOverride[StorageOverrideCount] whose Name is a host span staged
|
||||
// whole - the override map is name-keyed by design.
|
||||
//
|
||||
// EACH COUNT IS REFUSED AGAINST ITS DECLARED BOUND, never truncated: a sampler
|
||||
// array past 256 locations is a program this record cannot describe, and silently
|
||||
// describing 256 of them would put uniforms on the wrong units with no marker
|
||||
// anywhere. The counts come off the wire, so every one is bounded before it is
|
||||
// multiplied.
|
||||
const auto& p = *static_cast<const MGPProgramBindings*>(payload);
|
||||
if (p.BlockBindingCount > kMGPipeMaxProgramBlockBindings) {
|
||||
WireProtocolFatalAt("SetProgramBindings.BlockBindingCount", p.BlockBindingCount,
|
||||
kMGPipeMaxProgramBlockBindings);
|
||||
}
|
||||
if (p.SamplerUnitCount > kMGPipeMaxProgramSamplerUnits) {
|
||||
WireProtocolFatalAt("SetProgramBindings.SamplerUnitCount", p.SamplerUnitCount,
|
||||
kMGPipeMaxProgramSamplerUnits);
|
||||
}
|
||||
if (p.StorageOverrideCount > kMGPipeMaxProgramStorageOverrides) {
|
||||
WireProtocolFatalAt("SetProgramBindings.StorageOverrideCount",
|
||||
p.StorageOverrideCount, kMGPipeMaxProgramStorageOverrides);
|
||||
}
|
||||
tail0 = TailBytesFor(p.BlockBindingCount, sizeof(Int32));
|
||||
tail1 = TailBytesFor(p.SamplerUnitCount, sizeof(MGPProgramSamplerUnit));
|
||||
tail2 = TailBytesFor(p.StorageOverrideCount, sizeof(MGPProgramStorageOverride));
|
||||
// ALWAYS THREE, even when a count is 0. The tails are positional and the third one's
|
||||
// offset is derived from the first two, so a record that declared "one tail" when
|
||||
// only the block bindings were present would put the same bytes at a different
|
||||
// offset than a record that declared three - and the two halves of the wire would
|
||||
// disagree about where the overrides start. An empty tail is zero bytes at an
|
||||
// 8-aligned offset, which costs nothing.
|
||||
tails = 3;
|
||||
// NOT SecondTailIsHostSpans: the spans are MEMBERS of the third tail's elements,
|
||||
// not a bare MGHostSpan array, so the encoder's blanket honesty pass would read 40
|
||||
// bytes of {span, binding, pad} as one span and a quarter of garbage. The arm in
|
||||
// ApplyChecked walks the elements and checks each Name itself.
|
||||
break;
|
||||
}
|
||||
case MGPWireOp::SetVertexAttribDefaults: {
|
||||
// TWO DECLARANTS THAT MUST AGREE (contract table 1 row 15): Count and
|
||||
// popcount(Mask). Nothing checks this today; a disagreement is a wire fault that
|
||||
@@ -749,6 +803,15 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
out.TailBytes[1] = tail1;
|
||||
out.TotalBytes = out.TailOffset[1] + tail1;
|
||||
}
|
||||
// P5e: the third tail, realigned to 8 for the second one's reason - set_program_bindings'
|
||||
// first tail is Int32[] and its elements are four bytes, so the array behind it would
|
||||
// otherwise start at a 4-aligned offset and every MGHostSpan in the third would be
|
||||
// misaligned on a host that cares.
|
||||
if (tails >= 3) {
|
||||
out.TailOffset[2] = Align8(out.TailOffset[1] + tail1);
|
||||
out.TailBytes[2] = tail2;
|
||||
out.TotalBytes = out.TailOffset[2] + tail2;
|
||||
}
|
||||
out.TailCount = tails;
|
||||
out.TotalBytes = Align8(out.TotalBytes);
|
||||
if (out.TotalBytes > kMaxRecordBytesOnTheWire) {
|
||||
@@ -833,11 +896,19 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
// The allocation still cannot progress after reclamation. Count this
|
||||
// blocked allocation once, not each watermark poll or each reclaimed mark.
|
||||
if (!waited) { ++m_stageReclaimWaits; waited = true; }
|
||||
if (!m_stageRetirementBell->Wait(m_control->producerParked, ready, 0, 5000)) {
|
||||
// P5e (ra, CONTRACT-P5E §2.6): drain BEFORE parking and again after waking.
|
||||
// Before, because the ring may already be full and the server already stopped
|
||||
// - in which case retiredSeq will never move and there is nothing to wake us;
|
||||
// after, because the wake may have come from a server that is about to fill it
|
||||
// again. The hook is null in every standalone codec, which has no session and
|
||||
// therefore no reverse channel to drain.
|
||||
if (m_stageWaitHook != nullptr) m_stageWaitHook(m_stageWaitSelf);
|
||||
if (!ready() && !m_stageRetirementBell->Wait(m_control->producerParked, ready, 0, 5000)) {
|
||||
MGLOG_F("MGPipe: Fatal{RetirementWaitFailed, \"SEG_STAGE\"} producer wait "
|
||||
"ended before the pending allocation retired (shutdown or timeout)");
|
||||
std::abort();
|
||||
}
|
||||
if (m_stageWaitHook != nullptr) m_stageWaitHook(m_stageWaitSelf);
|
||||
}
|
||||
ReclaimStagedBytes();
|
||||
}
|
||||
@@ -1435,12 +1506,14 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
// record declaring Count = 4000 while carrying 8 bytes to its own arithmetic.
|
||||
if (size != layout.TotalBytes) {
|
||||
MGLOG_F("MGPipe: Fatal{ProtocolCorruption, \"%s\"} the record declares Size=%llu and "
|
||||
"its own count fields describe %llu bytes (fixed payload %llu + tails %llu/%llu)",
|
||||
"its own count fields describe %llu bytes (fixed payload %llu + tails "
|
||||
"%llu/%llu/%llu)",
|
||||
WireOpName(op), static_cast<unsigned long long>(size),
|
||||
static_cast<unsigned long long>(layout.TotalBytes),
|
||||
static_cast<unsigned long long>(layout.PayloadBytes),
|
||||
static_cast<unsigned long long>(layout.TailBytes[0]),
|
||||
static_cast<unsigned long long>(layout.TailBytes[1]));
|
||||
static_cast<unsigned long long>(layout.TailBytes[1]),
|
||||
static_cast<unsigned long long>(layout.TailBytes[2]));
|
||||
std::abort();
|
||||
}
|
||||
|
||||
@@ -1702,17 +1775,28 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
std::abort();
|
||||
}
|
||||
}
|
||||
const void* archive = ResolveOrFatal(op, desc.Reflection);
|
||||
MG_State::GLState::LinkArtifacts link;
|
||||
MG_State::GLState::SpirvArtifacts spirv;
|
||||
if (!MG_State::GLState::DecodeProgramArtifacts(static_cast<const Uint8*>(archive),
|
||||
static_cast<SizeT>(desc.Reflection.Size),
|
||||
link, spirv)) {
|
||||
const void* archiveBytes = ResolveOrFatal(op, desc.Reflection);
|
||||
// P5e (pg), gap G-A: DECODED ONTO THE HEAP AND HANDED TO THE RECORD, not onto this
|
||||
// stack. Before P5e these were two locals that died at the closing brace and the
|
||||
// applier kept only the descriptor, so every reflection question the program twin
|
||||
// later asked went back to the frontend's own ProgramObject - which Link() replaces
|
||||
// in place, and which a run-ahead client is several records past by then. The
|
||||
// record adopts the archive here and answers from it for the rest of its life.
|
||||
//
|
||||
// AND THE FRAME, not the bare codec stream: ProgramArchive carries the stage of
|
||||
// each module beside the modules, because SpirvArtifacts does not and StageMask
|
||||
// cannot stand in for it (two shader objects may share a stage). See
|
||||
// ProgramArtifactsCodec.h.
|
||||
auto archive = MakeShared<MG_State::GLState::ProgramArchive>();
|
||||
if (!MG_State::GLState::DecodeProgramArchive(static_cast<const Uint8*>(archiveBytes),
|
||||
static_cast<SizeT>(desc.Reflection.Size),
|
||||
*archive)) {
|
||||
WireProtocolFatal("CreateShaderState.Reflection",
|
||||
"DecodeProgramArtifacts refused the archive - a truncated "
|
||||
"stream, a codec version mismatch or a struct-size mismatch");
|
||||
"DecodeProgramArchive refused the archive - a truncated "
|
||||
"stream, a codec version mismatch, a struct-size mismatch, or "
|
||||
"a stage list that does not match the modules it frames");
|
||||
}
|
||||
MGPipeApplyCreateShaderState(desc, &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(desc, &archive->Link, &archive->Spirv, archive);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1776,16 +1860,17 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
return true;
|
||||
|
||||
case MGPWireOp::SetShaderBuffers: {
|
||||
// NO APPLIER ENTRY POINT EXISTS, and P5 does not invent one: the call is on
|
||||
// BRIEF §4's exclusion list, so a consumer written here would be a semantics
|
||||
// nobody can test this phase. What the record needs and cannot get later is its
|
||||
// TAIL ARITHMETIC, which MGPipeWireRecordLayout above has already run - including
|
||||
// the HostSpanCount-is-0-or-Count rule, the thing that keeps the two arrays
|
||||
// index-aligned.
|
||||
// P5e (sb, MG_Remote/CONTRACT-P5E.md §5.6): THE APPLIER ENTRY POINT EXISTS NOW and
|
||||
// this is the row's sink. The paragraph that stood here said "no applier entry
|
||||
// point exists, and P5 does not invent one: the call is on BRIEF §4's exclusion
|
||||
// list" - true for the whole of P5 through P5d, and withdrawn by the phase whose
|
||||
// entire point is that the server stops walking the client's binding-point table.
|
||||
//
|
||||
// kCapNeedsHostUboBytes is 0 for the whole of P5 (table 0), so the second tail is
|
||||
// always absent here; the honesty pass below is what says so out loud if it ever
|
||||
// is not.
|
||||
// THE HOST-SPAN PASS STILL RUNS FIRST, and it runs whether or not the record is
|
||||
// applied: kCapNeedsHostUboBytes is 0 for the whole of P5 (table 0), so the second
|
||||
// tail is always absent here, and this pass is what says so out loud if it ever is
|
||||
// not. A span that was going to be refused must be refused BEFORE the applier has
|
||||
// stored the window it rides with.
|
||||
if (layout.TailCount == 2 && layout.TailBytes[1] != 0) {
|
||||
const auto* spans = reinterpret_cast<const MGHostSpan*>(tailAt(1));
|
||||
const Uint64 count = layout.TailBytes[1] / sizeof(MGHostSpan);
|
||||
@@ -1799,13 +1884,75 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
CheckHostSpanIsHonest(span, *m_segments);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
MGPipeApplySetShaderBuffers(*static_cast<const MGPShaderBuffers*>(payload),
|
||||
reinterpret_cast<const MGPBufferRange*>(tailAt(0)));
|
||||
return true;
|
||||
}
|
||||
|
||||
case MGPWireOp::SetStreamOutputTargets:
|
||||
// Same as above: no applier, off the reduced path, both tails validated.
|
||||
// No applier entry point, off the reduced path, both tails validated. UNLIKE
|
||||
// set_shader_buffers above this row stays unemitted for the whole of P5e (§5.7):
|
||||
// XFB is lockstep, its capture points are span-scoped state latched at Begin, and
|
||||
// the payload carries a Generation that no applier state has a home for.
|
||||
return false;
|
||||
|
||||
case MGPWireOp::SetProgramBindings: {
|
||||
// P5e, opcode 80 (MG_Remote/CONTRACT-P5E.md §1). c0e wrote the shape check and left
|
||||
// the arm declining; PACKAGE pg COMPLETES IT. What the record needs before its
|
||||
// consumer sees it is its shape - the three declared counts against their bounds
|
||||
// and the three-tail arithmetic, both of which MGPipeWireRecordLayout above has
|
||||
// already run - plus the honesty of every name span it carries.
|
||||
//
|
||||
// THE SPANS ARE WALKED HERE RATHER THAN BY THE ENCODER'S BLANKET PASS because they
|
||||
// are MEMBERS of the third tail's 40-byte elements, not a bare MGHostSpan array:
|
||||
// SecondTailIsHostSpans reads a tail AS spans, and doing that to {span, binding,
|
||||
// pad} would read one span and a quarter of garbage. All four arms of
|
||||
// CheckHostSpanIsHonest run, the segment-range one included, so an override name
|
||||
// pointing outside SEG_STAGE is caught on the way in rather than at the rebuild.
|
||||
const auto& bindings = *static_cast<const MGPProgramBindings*>(payload);
|
||||
// RESOLVED HERE AND VALID ONLY FOR THIS CALL (rule C): the names live in the staged
|
||||
// run this record named, and the applier copies them into the record before it
|
||||
// returns. A Vector of resolved pointers rather than a second pass inside the
|
||||
// applier, because segment resolution is the decoder's job and the applier has no
|
||||
// segment table - it is reached by the monolith adapter too, where the names are
|
||||
// the frontend's own c_str()s and there is nothing to resolve.
|
||||
Vector<const char*> overrideNames;
|
||||
const MGPProgramStorageOverride* overrides = nullptr;
|
||||
if (layout.TailCount == 3 && layout.TailBytes[2] != 0 && m_segments != nullptr) {
|
||||
overrides = reinterpret_cast<const MGPProgramStorageOverride*>(tailAt(2));
|
||||
const Uint64 count = layout.TailBytes[2] / sizeof(MGPProgramStorageOverride);
|
||||
overrideNames.reserve(static_cast<SizeT>(count));
|
||||
for (Uint64 i = 0; i < count; ++i) {
|
||||
MGPProgramStorageOverride entry{};
|
||||
std::memcpy(&entry, reinterpret_cast<const Uint8*>(overrides) +
|
||||
i * sizeof(MGPProgramStorageOverride),
|
||||
sizeof(MGPProgramStorageOverride));
|
||||
CheckHostSpanIsHonest(entry.Name, *m_segments);
|
||||
// THE NUL IS THE CLIENT'S AND IS CHECKED, not assumed: the emitter stages
|
||||
// the name with its terminator (ProgramEmit.h), and a span whose last byte
|
||||
// is not 0 would make the applier's String(const char*) walk off the end of
|
||||
// SEG_STAGE. Honest-but-unterminated is the one shape CheckHostSpanIsHonest
|
||||
// cannot see.
|
||||
const auto* name = static_cast<const char*>(
|
||||
m_segments->Resolve(entry.Name.Seg, entry.Name.Offset, entry.Name.Size));
|
||||
if (entry.Name.Size == 0 || name == nullptr ||
|
||||
name[entry.Name.Size - 1] != '\0') {
|
||||
WireProtocolFatal("SetProgramBindings.StorageOverrides.Name",
|
||||
"an override name span is empty or is not "
|
||||
"NUL-terminated; the applier copies it as a C string");
|
||||
}
|
||||
overrideNames.push_back(name);
|
||||
}
|
||||
}
|
||||
MGPipeApplySetProgramBindings(
|
||||
bindings,
|
||||
layout.TailBytes[0] != 0 ? reinterpret_cast<const Int32*>(tailAt(0)) : nullptr,
|
||||
layout.TailBytes[1] != 0 ? reinterpret_cast<const MGPProgramSamplerUnit*>(tailAt(1))
|
||||
: nullptr,
|
||||
overrides, overrideNames.empty() ? nullptr : overrideNames.data());
|
||||
return true;
|
||||
}
|
||||
|
||||
case MGPWireOp::SetGlobalConstants: {
|
||||
const auto& rec = *static_cast<const MGPGlobalConstants*>(payload);
|
||||
// The length cross-check is the applier's (PipeApply.cpp:2784, against the
|
||||
|
||||
@@ -171,10 +171,19 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
// holds a pointer and two Uint64s. P5 emits no host span at all, so this rule costs
|
||||
// nothing now and is stated now because the phase that arms kDrawHasUserIndices would
|
||||
// otherwise have to discover it as a misaligned load on a device.
|
||||
// THREE TAILS AND NOT TWO SINCE P5e. set_program_bindings (opcode 80,
|
||||
// MG_Remote/CONTRACT-P5E.md §1) carries the uniform-block bindings, the sampler units and
|
||||
// the storage-override map as three arrays in three different index spaces, so the array
|
||||
// that used to be exactly "the two-tail rows plus draw_vbo's conditional second" grew by
|
||||
// one. Every loop over TailCount below already reads the count rather than the literal 2;
|
||||
// what changed is the storage and the assembly.
|
||||
inline constexpr Uint32 kMaxWireRecordTails = 3;
|
||||
|
||||
struct WireRecordLayout {
|
||||
Uint64 PayloadBytes = 0; // sizeof the op's payload struct
|
||||
Uint64 TailOffset[2] = {0, 0}; // from the START of the record, header included
|
||||
Uint64 TailBytes[2] = {0, 0};
|
||||
Uint64 TailOffset[kMaxWireRecordTails] = {0, 0, 0}; // from the START of the record,
|
||||
// header included
|
||||
Uint64 TailBytes[kMaxWireRecordTails] = {0, 0, 0};
|
||||
Uint32 TailCount = 0;
|
||||
Uint64 TotalBytes = 0; // header + payload + gaps + tails, rounded up to 8
|
||||
// P5b: WHAT THE SECOND TAIL IS. SetShaderBuffers' second tail is MGHostSpan[HostSpanCount]
|
||||
@@ -194,9 +203,9 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
// The catalogue's own spelling of an opcode, for a Fatal line. Out of range is "<opcode>".
|
||||
const char* WireOpName(MG_Pipe::MGPWireOp op);
|
||||
|
||||
// One tail array. Two of the 71 rows carry two (SetShaderBuffers, SetStreamOutputTargets)
|
||||
// and DrawVbo carries a conditional second one, which is why EncodeRecord's one-tail form
|
||||
// could not stay the only one.
|
||||
// One tail array. Two of the rows carry two (SetShaderBuffers, SetStreamOutputTargets),
|
||||
// DrawVbo carries a conditional second one and P5e's SetProgramBindings carries three,
|
||||
// which is why EncodeRecord's one-tail form could not stay the only one.
|
||||
struct WireTail {
|
||||
const void* Bytes = nullptr;
|
||||
Uint64 Size = 0;
|
||||
@@ -234,8 +243,10 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
Uint64 EncodeRecord(MG_Pipe::MGPWireOp op, const void* payload, Uint64 payloadBytes,
|
||||
const void* varTail = nullptr, Uint64 varTailBytes = 0);
|
||||
|
||||
// The same call for the three rows that carry TWO tails. The one-tail form above is
|
||||
// this one with tailCount <= 1; nothing is duplicated between them.
|
||||
// The same call for the rows that carry more than one tail - two for
|
||||
// set_shader_buffers, set_stream_output_targets and draw_vbo's conditional second,
|
||||
// three for P5e's set_program_bindings. The one-tail form above is this one with
|
||||
// tailCount <= 1; nothing is duplicated between them.
|
||||
//
|
||||
// The tails a caller hands over are CROSS-CHECKED against the layout the payload
|
||||
// itself declares (MGPipeWireRecordLayout): a caller whose Count says 4000 while its
|
||||
@@ -329,6 +340,20 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
// without a consumer cannot wait for retirement and retain the named refusal.
|
||||
void SetStageRetirementDoorbell(Transport::Doorbell* bell) { m_stageRetirementBell = bell; }
|
||||
|
||||
// P5e (ra, CONTRACT-P5E §2.6): THE STAGE BELL IS A CLIENT WAIT, so it has to drain the
|
||||
// reverse channel like every other one. The encoder cannot drain it itself - SEG_EVENT
|
||||
// and its consumers belong to the session - so the session installs a hook and this
|
||||
// layer only says WHEN. Without it the flow-control deadlock is one buffer upload
|
||||
// wide: the server stops applying on a full event ring, retiredSeq stops moving, and a
|
||||
// client parked here for staged bytes never drains the ring that would release it.
|
||||
// A raw function pointer rather than std::function: this header sits below MG_Impl and
|
||||
// the call is on a path that is already about to park.
|
||||
using StageWaitHook = void (*)(void* self);
|
||||
void SetStageWaitHook(StageWaitHook hook, void* self) {
|
||||
m_stageWaitHook = hook;
|
||||
m_stageWaitSelf = self;
|
||||
}
|
||||
|
||||
// Bytes this encoder has ever written into SEG_CMD, pad fillers included: the
|
||||
// producer's monotonic head cursor. It is the DENOMINATOR the wrap count only means
|
||||
// anything against - "0 wraps" is a defect when the run pushed more bytes than the ring
|
||||
@@ -372,6 +397,9 @@ namespace MobileGL::MG_Remote::Wire {
|
||||
Uint64 m_cmdWrapPads = 0;
|
||||
Uint64 m_stageReclaimWaits = 0;
|
||||
Transport::Doorbell* m_stageRetirementBell = nullptr;
|
||||
// P5e (ra): the session's event drain, called around the stage-bell park (§2.6).
|
||||
StageWaitHook m_stageWaitHook = nullptr;
|
||||
void* m_stageWaitSelf = nullptr;
|
||||
Vector<StageMark> m_stageMarks;
|
||||
SizeT m_stageMarkFront = 0;
|
||||
Uint8* m_stageBase = nullptr;
|
||||
|
||||
@@ -39,9 +39,12 @@ namespace MobileGL::MG_State::GLState {
|
||||
// the same shape as Fatal{PipeLegacyMemosDisabled} - so a cleared subsystem bit 7 no
|
||||
// longer leaves the arm silently readable. Client-thread callers (the GL thread's
|
||||
// own state) are unaffected.
|
||||
void RefuseLegacyBufferArmFromApplyThread(const char* accessor) {
|
||||
if (!MG_Remote::Client::PersistentMapTracker::PushIsArmed()) return;
|
||||
if (!MG_Remote::Client::PersistentMapTracker::OnServerRole()) return;
|
||||
// The refusal's BODY, split out from its two probes (P5d round 3, package D). A caller
|
||||
// that has already asked "am I the server role" for its own reasons -
|
||||
// SyncPersistentMappedRange does, one line later - calls this and pays for
|
||||
// ServerLoop::OnApplyThread() once instead of twice. It is a Fatal, so it never
|
||||
// returns; the probes live in RefuseLegacyBufferArmFromApplyThread below.
|
||||
[[noreturn]] void FatalLegacyBufferArmFromApplyThread(const char* accessor) {
|
||||
MGLOG_F("MGPipe: Fatal{RoleViolation, \"buffer-legacy-arm\"} - the apply thread "
|
||||
"called BufferObject::%s on a frontend object. With an active transport "
|
||||
"the server reads the applier's resource record and its own staged shadow; "
|
||||
@@ -50,6 +53,17 @@ namespace MobileGL::MG_State::GLState {
|
||||
accessor);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// The accessors' own guard: two loads and two branches on the client thread, which is
|
||||
// where MappedData/IsMapped/GetChangeSerial/HasDefinedContent are called from per draw
|
||||
// (IsLivePersistentMap reads two of them for every live map). PushIsArmed() is a read
|
||||
// of MG_Config::Transport and OnServerRole() is now one relaxed load of the apply
|
||||
// thread's key (ServerLoop.h), so the monolith answer costs a load each.
|
||||
void RefuseLegacyBufferArmFromApplyThread(const char* accessor) {
|
||||
if (!MG_Remote::Client::PersistentMapTracker::PushIsArmed()) return;
|
||||
if (!MG_Remote::Client::PersistentMapTracker::OnServerRole()) return;
|
||||
FatalLegacyBufferArmFromApplyThread(accessor);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -400,14 +414,27 @@ namespace MobileGL::MG_State::GLState {
|
||||
|
||||
void BufferObject::SyncPersistentMappedRange() {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// P5c (hd): the named refusal comes FIRST - the silent return below used to let a
|
||||
// P5c (hd): the named refusal comes FIRST - a silent return here used to let a
|
||||
// server-side caller slip through with one MGLOG_D's worth of evidence (B3).
|
||||
RefuseLegacyBufferArmFromApplyThread("SyncPersistentMappedRange");
|
||||
//
|
||||
// ONE ROLE PROBE, NOT TWO (P5d round 3, package D). This used to call
|
||||
// RefuseLegacyBufferArmFromApplyThread and then re-ask PushIsArmed()/OnServerRole()
|
||||
// for the early-out below - the same two questions, answered twice on the same line of
|
||||
// execution, on a function the draw path reaches per mapped buffer. The refusal's
|
||||
// condition and the early-out's condition were already IDENTICAL, which is why the
|
||||
// early-out's `return` was unreachable: with the push armed, the apply thread aborts
|
||||
// in the refusal and never gets there. Folding them keeps the refusal first and drops
|
||||
// the duplicate probe rather than the guard.
|
||||
//
|
||||
// Split's client pre-verb hook publishes these bytes. The retained backend sync
|
||||
// sites must do nothing on the apply thread: re-entering this producer there would
|
||||
// overwrite the server shadow through the monolith adapter without crossing the wire.
|
||||
// overwrite the server shadow through the monolith adapter without crossing the wire -
|
||||
// and "do nothing" is spelled Fatal, not `return`, because a server-side caller here
|
||||
// is a role violation and not a shape the design tolerates.
|
||||
if (MG_Remote::Client::PersistentMapTracker::PushIsArmed()) {
|
||||
if (MG_Remote::Client::PersistentMapTracker::OnServerRole()) return;
|
||||
if (MG_Remote::Client::PersistentMapTracker::OnServerRole()) {
|
||||
FatalLegacyBufferArmFromApplyThread("SyncPersistentMappedRange");
|
||||
}
|
||||
MG_Remote::Client::PersistentMapTracker::Instance().PushBlocksFor(*this);
|
||||
return;
|
||||
}
|
||||
@@ -967,6 +994,16 @@ namespace MobileGL::MG_State::GLState {
|
||||
return m_resource.Bytes();
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
SizeT BufferObject::ShadowAllocationBytes() const {
|
||||
// The extent of the very pointer MappedData() hands out, read by the same caller
|
||||
// (the tracker's registration) on the same thread: the same rule-E surface, the
|
||||
// same refusal.
|
||||
RefuseLegacyBufferArmFromApplyThread("ShadowAllocationBytes");
|
||||
return m_resource.ShadowAllocationBytes();
|
||||
}
|
||||
#endif
|
||||
|
||||
Bool BufferObject::IsBackendPersistentMapped() const {
|
||||
return m_resource.IsGpuResident();
|
||||
}
|
||||
|
||||
@@ -228,6 +228,16 @@ namespace MobileGL {
|
||||
// object can express that. Split-only so the pull build's layout and inlining do
|
||||
// not move (G1).
|
||||
Bool HasOutstandingGpuWrite() const { return m_gpuWritePending; }
|
||||
|
||||
// The shadow allocation's own extent in bytes - page-aligned base, page-granular
|
||||
// size, every byte this shadow's and nobody else's (PipeResource.h,
|
||||
// ShadowAllocationBytesFor). Read by the persistent-map tracker at registration
|
||||
// so it can protect the mapped range's containing pages OUTWARD and hash no
|
||||
// edges; zero for an adopted store, which the tracker never registers. Split-only
|
||||
// for G1's reason, like the rest of this block, and out of line because it is a
|
||||
// layer-1 read of client memory like MappedData (CONTRACT-P5C rule E) and carries
|
||||
// the same apply-thread refusal.
|
||||
SizeT ShadowAllocationBytes() const;
|
||||
#endif
|
||||
|
||||
Bool IsMapped() const;
|
||||
|
||||
@@ -71,11 +71,44 @@ namespace MobileGL::MG_State::GLState {
|
||||
// shutter on in P2 - five bits over one aggregate until P3b splits them.
|
||||
void NoteBufferChanged() { ++m_anyBufferChangeGeneration; }
|
||||
Uint64 GetAnyBufferChangeGeneration() const { return m_anyBufferChangeGeneration; }
|
||||
|
||||
// P5e (sb, MG_Remote/CONTRACT-P5E.md §1, §5.6). "DID ANY INDEXED BINDING POINT OF THIS
|
||||
// TARGET MOVE" - one counter per BufferBindPointTargets entry, and it is the P4b hole
|
||||
// closed rather than a new convenience.
|
||||
//
|
||||
// WHAT WAS WRONG. Dirty bits 15/16/17 shuttered on GetAnyBufferChangeGeneration() - the
|
||||
// CONTENT aggregate - while glBindBufferBase / glBindBufferRange mutate a binding point
|
||||
// through a returned reference (BindingSlotRange1D::Bind / SetRange), which moves the
|
||||
// slot's own Uint16 version and nothing the tracker reads. So
|
||||
// `glBindBufferBase(UNIFORM,1,A); draw; glBindBufferBase(UNIFORM,1,B); draw` fired no bit
|
||||
// at all: harmless while nothing was emitted for those bits, and an UNDER-FIRE the moment
|
||||
// set_shader_buffers is, because the server would go on binding A. It is the same defect
|
||||
// class as P4a's glBindSampler hole (c0d) and it is closed the same way - the shutter
|
||||
// reads the generation the mutator moves.
|
||||
//
|
||||
// A COUNTER AND NOT THE SLOT'S OWN VERSION: the slot version is a WRAPPING Uint16 per
|
||||
// point, and a shutter over 84 of them would have to observe all 84 through the widened
|
||||
// counter every draw. One monotone Uint64 per target answers "could this target's window
|
||||
// have moved" in one read, which is what a per-draw shutter can afford.
|
||||
//
|
||||
// #if MOBILEGL_PIPE_PUSH so the pull build's BufferState does not resize (G1) - the same
|
||||
// licence TextureState::NoteImageUnitTouched took at P5d r3.
|
||||
void NoteBindPointChanged(const BufferTarget target) {
|
||||
auto it = std::find(BufferBindPointTargets.begin(), BufferBindPointTargets.end(), target);
|
||||
if (it == BufferBindPointTargets.end()) return;
|
||||
++m_bindPointGeneration[std::distance(BufferBindPointTargets.begin(), it)];
|
||||
}
|
||||
Uint64 GetBindPointGeneration(const BufferTarget target) const {
|
||||
auto it = std::find(BufferBindPointTargets.begin(), BufferBindPointTargets.end(), target);
|
||||
if (it == BufferBindPointTargets.end()) return 0;
|
||||
return m_bindPointGeneration[std::distance(BufferBindPointTargets.begin(), it)];
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
Uint64 m_anyBufferChangeGeneration = 0;
|
||||
Array<Uint64, BufferBindPointTargets.size()> m_bindPointGeneration{};
|
||||
#endif
|
||||
UnorderedMap<Uint, SharedPtr<BufferObject>> m_bufferObjects;
|
||||
IndexGenerator<Uint> m_indexGenerator;
|
||||
|
||||
@@ -28,17 +28,39 @@ namespace MobileGL::MG_State::GLState {
|
||||
inline constexpr SizeT MIN_MAP_BUFFER_ALIGNMENT = 64;
|
||||
|
||||
// The shadow's ALLOCATION alignment is a full page, not the advertised 64: a
|
||||
// page-aligned shadow owns every byte of every page it occupies, which is what lets
|
||||
// the persistent-map mprotect tracker write-protect the mapped interior without ever
|
||||
// covering a neighbour allocation's byte (a foreign thread with signals blocked
|
||||
// faulting on a shared page is a process kill). GL_MIN_MAP_BUFFER_ALIGNMENT keeps
|
||||
// answering 64 - over-aligning an allocation is invisible to the application, and a
|
||||
// glMapBufferRange base that is page-aligned is 64-aligned. The cost is allocator
|
||||
// rounding on small buffers, paid so the tracker never has to make the unsafe choice.
|
||||
// page-aligned shadow (page-granular in SIZE as well, in a split build - see
|
||||
// ShadowAllocationBytesFor) owns every byte of every page it occupies, which is what
|
||||
// lets the persistent-map mprotect tracker write-protect the mapped range's containing
|
||||
// pages without ever covering a neighbour allocation's byte (a foreign thread with
|
||||
// signals blocked faulting on a shared page is a process kill).
|
||||
// GL_MIN_MAP_BUFFER_ALIGNMENT keeps answering 64 - over-aligning an allocation is
|
||||
// invisible to the application, and a glMapBufferRange base that is page-aligned is
|
||||
// 64-aligned. The cost is allocator rounding on small buffers, paid so the tracker
|
||||
// never has to make the unsafe choice.
|
||||
inline constexpr SizeT SHADOW_ALLOCATION_ALIGNMENT = 4096;
|
||||
|
||||
// Allocator that gives every allocation SHADOW_ALLOCATION_ALIGNMENT. Deliberately
|
||||
// minimal: the
|
||||
// The bytes one shadow allocation actually asks the heap for, from the count std::vector
|
||||
// asked the allocator for. In a split build the SIZE is rounded up to a whole number of
|
||||
// SHADOW_ALLOCATION_ALIGNMENT pages, not just the base: alignment alone puts the first
|
||||
// byte on a page boundary but lets the LAST page end mid-way, and whatever the heap
|
||||
// packs after it shares that page. The persistent-map tracker then had to align its
|
||||
// protected range inward and hash the partial-page edges on every draw (8.5% of the
|
||||
// client thread at VD12 in XXH3, on nearly every buffer - almost no mapped end is
|
||||
// page-aligned). With a page-granular size every byte of [base, base + this) is this
|
||||
// allocation's own, so the tracker can protect the mapped range's containing pages
|
||||
// outward and there are no edges to hash. ONE function for the allocator and for
|
||||
// PipeResource::ShadowAllocationBytes(), because the extent the tracker widens into may
|
||||
// never exceed what was allocated. The pull build keeps the exact count and does not
|
||||
// see this function at all: it has no tracker to spend the rounding on, and G1 holds
|
||||
// its symbol set and .text byte-identical only if allocate()'s own text does not move.
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
inline constexpr SizeT ShadowAllocationBytesFor(SizeT count) {
|
||||
return (count + SHADOW_ALLOCATION_ALIGNMENT - 1) & ~(SHADOW_ALLOCATION_ALIGNMENT - 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Allocator that gives every allocation SHADOW_ALLOCATION_ALIGNMENT (and, in a split
|
||||
// build, a page-granular size - see ShadowAllocationBytesFor). Deliberately minimal: the
|
||||
// vectors it backs hold raw bytes and are only ever sized, so allocate/deallocate plus the
|
||||
// rebinding and equality boilerplate std::vector requires is the whole interface.
|
||||
template <typename T>
|
||||
@@ -51,8 +73,13 @@ namespace MobileGL::MG_State::GLState {
|
||||
|
||||
T* allocate(SizeT count) {
|
||||
if (count == 0) return nullptr;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
return static_cast<T*>(::operator new(ShadowAllocationBytesFor(count * sizeof(T)),
|
||||
std::align_val_t{SHADOW_ALLOCATION_ALIGNMENT}));
|
||||
#else
|
||||
return static_cast<T*>(
|
||||
::operator new(count * sizeof(T), std::align_val_t{SHADOW_ALLOCATION_ALIGNMENT}));
|
||||
#endif
|
||||
}
|
||||
void deallocate(T* pointer, SizeT) noexcept {
|
||||
::operator delete(pointer, std::align_val_t{SHADOW_ALLOCATION_ALIGNMENT});
|
||||
@@ -111,14 +138,42 @@ namespace MobileGL::MG_State::GLState {
|
||||
// glBufferStorage before any persistent map). Mirrors the previous
|
||||
// power-of-two reserve + exact resize of the old m_dataPtr.
|
||||
void ResizeShadow(SizeT size) {
|
||||
m_shadow->reserve(std::bit_ceil(size == 0 ? SizeT{1} : size));
|
||||
const SizeT reserved = std::bit_ceil(size == 0 ? SizeT{1} : size);
|
||||
m_shadow->reserve(reserved);
|
||||
m_shadow->resize(size);
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// RECORDED HERE, NOT INFERRED FROM capacity(). `reserved` is the count this
|
||||
// call asked the allocator for, so ShadowAllocationBytesFor(reserved) is the
|
||||
// block the allocator handed back whenever this reserve reallocated - and when
|
||||
// it did not (the vector already held at least that much), the block behind
|
||||
// Bytes() is an earlier, LARGER reserve's, so the value recorded here is at
|
||||
// most the true extent either way. Reading capacity() back instead would tie
|
||||
// the ownership claim to a library's promise that capacity() never exceeds
|
||||
// the count it allocated - true of libc++, libstdc++ and MSVC today, pinned by
|
||||
// nothing - and an over-report there would protect a page this allocation
|
||||
// does not own, the very process-killer the extent exists to keep out. An
|
||||
// under-report costs nothing: the tracker still needs rangeEnd <= extent, and
|
||||
// size <= reserved always.
|
||||
m_shadowExtent = ShadowAllocationBytesFor(reserved);
|
||||
#endif
|
||||
}
|
||||
// Direct shadow access, used only by the backend's upload-from-shadow path,
|
||||
// which never runs for a GPU-resident (persistent) buffer.
|
||||
MapAlignedData& Shadow() { return *m_shadow; }
|
||||
const MapAlignedData& Shadow() const { return *m_shadow; }
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The extent of the shadow's heap allocation in bytes, as ResizeShadow asked for
|
||||
// it: every byte of [Bytes(), Bytes() + this) belongs to this shadow and to
|
||||
// nothing else, and the extent is a whole number of SHADOW_ALLOCATION_ALIGNMENT
|
||||
// pages. This is what lets the persistent-map tracker protect the mapped range's
|
||||
// containing pages OUTWARD without ever covering a byte it does not own (a
|
||||
// foreign thread with signals blocked faulting on a shared page is a process
|
||||
// kill). Zero for an adopted (GPU-resident) store, whose shadow was released, and
|
||||
// for a shadow that was never sized; the tracker excludes both.
|
||||
SizeT ShadowAllocationBytes() const { return m_gpuMapped != nullptr ? 0 : m_shadowExtent; }
|
||||
#endif
|
||||
|
||||
// Transition to persistent GPU residency: adopt the backend's coherent
|
||||
// mapped base as the source of truth and drop the CPU shadow. The caller
|
||||
// must have already seeded the GPU memory from the shadow (via the backend
|
||||
@@ -127,6 +182,10 @@ namespace MobileGL::MG_State::GLState {
|
||||
m_gpuMapped = mappedBase;
|
||||
m_shadow->clear();
|
||||
m_shadow->shrink_to_fit();
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// The block is gone with the shrink; the next ResizeShadow records the next one.
|
||||
m_shadowExtent = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Give the adoption back: the bytes resolve against the shadow again (which
|
||||
@@ -150,5 +209,9 @@ namespace MobileGL::MG_State::GLState {
|
||||
SharedPtr<MapAlignedData> m_shadow = MakeShared<MapAlignedData>();
|
||||
void* m_gpuMapped = nullptr;
|
||||
SharedPtr<BackendBufferResource> m_backend;
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
// See ShadowAllocationBytes. Split-only so the pull build's layout does not move (G1).
|
||||
SizeT m_shadowExtent = 0;
|
||||
#endif
|
||||
};
|
||||
} // namespace MobileGL::MG_State::GLState
|
||||
|
||||
@@ -1522,6 +1522,17 @@ namespace MobileGL::MG_State {
|
||||
Bool hasExplicitRange) {
|
||||
if (bufferIndex >= MAX_TRANSFORM_FEEDBACK_BUFFERS) return;
|
||||
if (index == m_boundTransformFeedback) {
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (sb): the THIRD writer of a transform-feedback binding point, and the one
|
||||
// a reader of GL_Buffer.cpp alone would miss - glTransformFeedbackBufferBase /
|
||||
// ...Range on the CURRENTLY BOUND object land here rather than in
|
||||
// BindBufferBase_State. Dirty bit 17 shutters on this generation, so a bump
|
||||
// left out here would make the DSA spelling of a capture-point bind invisible
|
||||
// while the non-DSA one was not. The saved-bindings arm below writes no binding
|
||||
// POINT at all (it writes the named object's own table) and deliberately bumps
|
||||
// nothing.
|
||||
NoteBufferBindPointChanged(BufferTarget::TransformFeedback);
|
||||
#endif
|
||||
auto& point = m_bufferState.GetBindingPoint(BufferTarget::TransformFeedback, bufferIndex);
|
||||
point.Bind(buffer);
|
||||
if (buffer && hasExplicitRange) {
|
||||
|
||||
@@ -140,6 +140,14 @@ namespace MobileGL {
|
||||
m_textureState.NoteUnitTouched(unit, bindingChanged);
|
||||
}
|
||||
Int GetMaxTouchedTextureUnit() const { return m_textureState.GetMaxTouchedUnit(); }
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// The IMAGE-unit high-water mark, which is a different namespace from the
|
||||
// texture-unit one above - see TextureState::NoteImageUnitTouched for why it is a
|
||||
// second mark and why it only grows. Push builds only, so the pull build's
|
||||
// GLContext is untouched (G1).
|
||||
void NoteImageUnitTouched(Int unit) { m_textureState.NoteImageUnitTouched(unit); }
|
||||
Int GetMaxTouchedImageUnit() const { return m_textureState.GetMaxTouchedImageUnit(); }
|
||||
#endif
|
||||
// Monotonic counter bumped whenever a texture bind/unbind/delete changes which
|
||||
// texture is bound at a unit; lets a backend skip re-resolving an unchanged
|
||||
// per-draw sampled-texture set.
|
||||
@@ -243,6 +251,15 @@ namespace MobileGL {
|
||||
Uint64 GetAnyBufferChangeGeneration() const {
|
||||
return m_bufferState.GetAnyBufferChangeGeneration();
|
||||
}
|
||||
// P5e (sb): the per-target INDEXED BINDING POINT generation, which is what dirty
|
||||
// bits 15/16/17 shutter on now. See BufferState::NoteBindPointChanged for why
|
||||
// the content aggregate above could not answer the question.
|
||||
void NoteBufferBindPointChanged(BufferTarget target) {
|
||||
m_bufferState.NoteBindPointChanged(target);
|
||||
}
|
||||
Uint64 GetBufferBindPointGeneration(BufferTarget target) const {
|
||||
return m_bufferState.GetBindPointGeneration(target);
|
||||
}
|
||||
// The sixth aggregate lives here rather than on a state container because
|
||||
// the values it guards do too (m_currentVertexAttributes).
|
||||
void NoteVertexAttribDefaultChanged() { ++m_anyVertexAttribDefaultGeneration; }
|
||||
|
||||
@@ -242,6 +242,14 @@ namespace MobileGL::MG_State::GLState {
|
||||
// (ProgramArtifacts.h's libc++ branch until the integrator fills it in) this is 0,
|
||||
// which still round-trips within one build - the echo compares what THIS build wrote
|
||||
// against what THIS build expects - and stops mattering the moment the pin lands.
|
||||
//
|
||||
// P5e (pg) READ THIS LINE AS THE CONTRACT ASKED (CONTRACT-P5E §5.5) and its verdict is
|
||||
// in ProgramArtifactsCodec.h's header comment: the caveat is about the ECHO WORD, not
|
||||
// about a member the codec skips - the one member VisitFields omits is
|
||||
// `LinkArtifacts::program`, and no backend twin reads it. A 0 echo is exact for an
|
||||
// in-process split, where the writer and the reader are one build, and becomes a real
|
||||
// cross-toolchain check when P6 puts a client and a server in different processes
|
||||
// built by different compilers.
|
||||
#ifdef MGL_LINKARTIFACTS_SIZE
|
||||
inline constexpr Uint64 kLinkArtifactsSizeEcho = MGL_LINKARTIFACTS_SIZE;
|
||||
#else
|
||||
@@ -300,4 +308,55 @@ namespace MobileGL::MG_State::GLState {
|
||||
link.program = nullptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- P5e (pg): the frame -------------------------------------------------------------
|
||||
//
|
||||
// ONE MORE LENGTH-PREFIXED RUN IN FRONT, and deliberately in front rather than behind:
|
||||
// DecodeProgramArtifacts refuses trailing bytes ("the format accounts for every byte it
|
||||
// writes"), which is a rule worth keeping, so the stage list is consumed BEFORE the
|
||||
// codec's own stream is handed the exact remainder. The version word inside that stream
|
||||
// still governs the archive proper; the frame has no version of its own because it is one
|
||||
// count and one run of Uint32 and there is nothing about it a future reader could
|
||||
// misinterpret without the count already disagreeing.
|
||||
void EncodeProgramArchive(const LinkArtifacts& link, const SpirvArtifacts& spirv,
|
||||
const Vector<Uint32>& linkedStages, Vector<Uint8>& out) {
|
||||
PutRaw(out, static_cast<Uint32>(linkedStages.size()));
|
||||
for (const Uint32 stage : linkedStages) PutRaw(out, stage);
|
||||
EncodeProgramArtifacts(link, spirv, out);
|
||||
}
|
||||
|
||||
Bool DecodeProgramArchive(const Uint8* bytes, SizeT size, ProgramArchive& out) {
|
||||
out = ProgramArchive{};
|
||||
if (bytes == nullptr) return false;
|
||||
if (size < sizeof(Uint32)) return false;
|
||||
|
||||
Uint32 stageCount = 0;
|
||||
std::memcpy(&stageCount, bytes, sizeof(stageCount));
|
||||
// BOUNDED BEFORE IT IS MULTIPLIED, the same rule the codec's own TakeCount keeps: a
|
||||
// corrupt count must not become a four-billion-element resize, and a count past the
|
||||
// declared maximum is a program this frame cannot describe rather than one to truncate.
|
||||
if (static_cast<SizeT>(stageCount) > kProgramArchiveMaxStages) return false;
|
||||
const SizeT framed = sizeof(Uint32) + static_cast<SizeT>(stageCount) * sizeof(Uint32);
|
||||
if (size < framed) return false;
|
||||
|
||||
out.LinkedStages.resize(stageCount);
|
||||
for (Uint32 i = 0; i < stageCount; ++i) {
|
||||
std::memcpy(&out.LinkedStages[i], bytes + sizeof(Uint32) + i * sizeof(Uint32),
|
||||
sizeof(Uint32));
|
||||
}
|
||||
if (!DecodeProgramArtifacts(bytes + framed, size - framed, out.Link, out.Spirv)) {
|
||||
out = ProgramArchive{};
|
||||
return false;
|
||||
}
|
||||
// THE TWO HALVES MUST AGREE, and this is the only place that can say so: the backend
|
||||
// pairs linkedStages[i] with generatedSpirv[i] and indexes both by one running index,
|
||||
// so a frame whose count disagrees with the decoded module count would read off the
|
||||
// end of one of them. The frontend builds both from one snapshot loop, so a mismatch
|
||||
// here is a wire fault and not a program shape.
|
||||
if (out.LinkedStages.size() != out.Spirv.generatedSpirv.size()) {
|
||||
out = ProgramArchive{};
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} // namespace MobileGL::MG_State::GLState
|
||||
|
||||
@@ -42,6 +42,26 @@
|
||||
// * and `LinkArtifacts::program` is NEVER visited. It is the live glslang TProgram, it is
|
||||
// null for every archived instance by construction, and VisitFields deliberately omits it
|
||||
// (57 of the 58 members). Decode leaves it null.
|
||||
//
|
||||
// P5e (pg), CONTRACT-P5E §5.5 "codec completeness": THE SKIPPED MEMBER IS NAMED, AND IT IS
|
||||
// `LinkArtifacts::program`. The contract asks this package either to carry it or to prove the
|
||||
// twin never reads it, and the proof is a closed grep rather than an argument: every read of
|
||||
// that member in the tree is inside `ProgramLinkTask.cpp` (`DoReflection`, which is the only
|
||||
// code that may dereference it at all) and the three sites that `reset()` it -
|
||||
// `ProgramLinkTask.cpp:678,764,877` and `ProgramObject::ResetLinkArtifacts`. `MG_Backend/`
|
||||
// contains NO read of it, in either backend; `ProgramTranslationCache` asserts it is null at
|
||||
// insert. So the archive answers every reflection question the program twin asks, and the one
|
||||
// member it does not carry is one no twin has ever asked for. It could not be carried in any
|
||||
// case: it points into a glslang arena that no archived instance owns.
|
||||
//
|
||||
// AND THE OTHER HALF OF THAT CONTRACT LINE - `ProgramArtifactsCodec.cpp`'s libc++ caveat - is
|
||||
// about the STRUCT-SIZE ECHO, not about a member: under a toolchain whose `MGL_LINKARTIFACTS_SIZE`
|
||||
// is not pinned yet (the NDK's libc++ branch of `ProgramArtifacts.h`, inert until the integrator
|
||||
// fills it in) the echo word is 0. That is SAFE FOR P5e AND NOT A GAP: the echo compares what
|
||||
// this build wrote against what this build expects, so a round trip within one build is exact,
|
||||
// and P5e is an in-process split where the writer and the reader ARE one build. It becomes a
|
||||
// real check the day a client and a server built by different toolchains share a wire, which is
|
||||
// P6's boundary and P6's problem - stated here so it cannot be discovered instead.
|
||||
namespace MobileGL::MG_State::GLState {
|
||||
|
||||
// Bumped whenever the byte format changes in a way a previous reader would misread. A
|
||||
@@ -60,6 +80,45 @@ namespace MobileGL::MG_State::GLState {
|
||||
Bool DecodeProgramArtifacts(const Uint8* bytes, SizeT size, LinkArtifacts& link,
|
||||
SpirvArtifacts& spirv);
|
||||
|
||||
// ---- P5e (pg): the archive as the SERVER OWNS it -------------------------------------
|
||||
//
|
||||
// WHAT THE TWO STRUCTS ABOVE DO NOT CARRY, and why a package that makes the server answer
|
||||
// every reflection question out of them had to notice: THE STAGE OF EACH MODULE.
|
||||
// `SpirvArtifacts::generatedSpirv` is one module per SHADER OBJECT the link consumed, in
|
||||
// snapshot order, and the stage of each lives in `ProgramObject::m_linkedShaderSnapshot` -
|
||||
// GL-thread state, not an artifact. `MGPProgramDesc::StageMask` cannot stand in for it: it
|
||||
// is a bit SET, and GL lets two shader objects of the same stage be attached to one
|
||||
// program, so a list rebuilt from the mask would be shorter than `generatedSpirv` and the
|
||||
// backend's "linked stages and modules must agree" refusal would fire on a perfectly good
|
||||
// program.
|
||||
//
|
||||
// So the frame is [stage count][stage words][the codec's own bytes], written and read by
|
||||
// this package on both sides, and `ProgramArchive` is what a decode produces: the record's
|
||||
// OWN copy, with the lifetime of the record rather than of the staged run that carried it
|
||||
// (rule C). Stages travel as Uint32 rather than as `ShaderStage` so this header keeps its
|
||||
// include closure - `ProgramArtifacts.h` beside it may not reach `ShaderStage.h`.
|
||||
struct ProgramArchive {
|
||||
LinkArtifacts Link;
|
||||
SpirvArtifacts Spirv;
|
||||
// ShaderStage, one per Spirv.generatedSpirv entry, at the same index.
|
||||
Vector<Uint32> LinkedStages;
|
||||
};
|
||||
|
||||
// The bound a decode refuses past: six is what MGPProgramDesc::Spirv[] can name and what
|
||||
// ProgramEmit.h's own truncation counter already watches, doubled so that a program this
|
||||
// stack can build is never refused here for a reason the emitter did not already count.
|
||||
inline constexpr SizeT kProgramArchiveMaxStages = 12;
|
||||
|
||||
// Appends the framed archive to `out` (not cleared, so a caller may frame it further).
|
||||
// `linkedStages` must be index-aligned with `spirv.generatedSpirv`.
|
||||
void EncodeProgramArchive(const LinkArtifacts& link, const SpirvArtifacts& spirv,
|
||||
const Vector<Uint32>& linkedStages, Vector<Uint8>& out);
|
||||
|
||||
// Replaces `out` with what `bytes` describes. Same refusal terms as
|
||||
// DecodeProgramArtifacts, plus: a stage count past kProgramArchiveMaxStages, and a stage
|
||||
// count that does not match the decoded module count.
|
||||
Bool DecodeProgramArchive(const Uint8* bytes, SizeT size, ProgramArchive& out);
|
||||
|
||||
// How many fields a type's VisitFields table actually visits. The codec walks exactly that
|
||||
// table, so this is what pins "the codec did not quietly grow an arm of its own" - most of
|
||||
// all for LinkArtifacts, whose 58th member is the live TProgram the table omits. It is a
|
||||
|
||||
@@ -36,12 +36,27 @@ namespace MobileGL {
|
||||
// The message names the TEXTURE-side method, not this storage's: the pinned
|
||||
// surface list (MG_Test/Wire/RemoteClientTest.cpp's RemoteGuards) is written
|
||||
// in TextureObjectMipmap's vocabulary.
|
||||
//
|
||||
// P5e (tx2): THE READ-ONLY SHAPE ACCESSORS JOIN THE LIST. P5c guarded the
|
||||
// MUTATORS and deliberately exempted the shape reads, with the reason written
|
||||
// into RemoteClientTest: "the per-draw binding walk reads them every draw", so
|
||||
// guarding them would have aborted a lane that was still correct. P5e is the
|
||||
// commit that makes that untrue - the unit work list, the clean gate and the
|
||||
// three sync bodies read the resource RECORD and the server's staged-texture
|
||||
// store, and nothing on the draw path asks the frontend object for a level count,
|
||||
// a level extent, a level byte size or a compressed level again. So the exemption
|
||||
// becomes a guard, and reverting any handle arm aborts here BY ACCESSOR NAME
|
||||
// instead of rendering from client memory.
|
||||
//
|
||||
// A client-thread caller is unaffected (this is the frontend's own state, and the
|
||||
// guard returns unless ServerLoop::OnApplyThread()); Magma's texture sync keeps
|
||||
// its named scope exemption; the pull build compiles none of it.
|
||||
void RefuseLegacyTextureArmFromApplyThread(const char* surface) {
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) return;
|
||||
if (!MG_Remote::Server::ServerLoop::OnApplyThread()) return;
|
||||
// The named exemption (MipmapStorage.h): Magma's texture sync is tx's
|
||||
// declared leftover and retires with P7.
|
||||
if (MGPipeTextureLegacyArmScope::Active()) return;
|
||||
if (MGPipeTextureLegacyArmScope::ActiveOnApplyThread()) return;
|
||||
MGLOG_F("MGPipe: Fatal{RoleViolation, \"texture-legacy-arm\"} - the apply thread "
|
||||
"called TextureObjectMipmap::%s on a frontend object. With an active "
|
||||
"transport the server reads the staged-texture store and the resource "
|
||||
@@ -50,6 +65,21 @@ namespace MobileGL {
|
||||
surface);
|
||||
std::abort();
|
||||
}
|
||||
|
||||
// P5e (tx2), ruling 12's shape (ID-90): THE NEW READ-ONLY ROWS ARE KEYED ON THE
|
||||
// BACKEND KIND, and that is not a softening - it is the same line §6 draws for
|
||||
// every other P5e guard. MAGMA KEEPS THE LOCKSTEP: a DirectVulkan server's
|
||||
// records are all barriered and its blit path still asks a frontend texture
|
||||
// whether it IsComplete() (VulkanRenderer's ResolveColorBlitBinding), which is a
|
||||
// P7 debt and legal under P5C's rules for a client parked in its own wait. What
|
||||
// P5e retires is ESPRYT's per-draw shape reads, so the new rows abort on a
|
||||
// DirectGLES server and are silent on a DirectVulkan one. The MUTATOR rows above
|
||||
// stay unconditional: no backend may write a frontend texture's storage from the
|
||||
// apply thread, and none does.
|
||||
void RefuseLegacyTextureShapeReadFromApplyThread(const char* surface) {
|
||||
if (MG_Config::ActiveBackendType != BackendType::DirectGLES) return;
|
||||
RefuseLegacyTextureArmFromApplyThread(surface);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Overlapping OR abutting ([lo, hi) intervals meeting edge-to-edge) in
|
||||
@@ -70,23 +100,36 @@ namespace MobileGL {
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
namespace {
|
||||
thread_local Uint32 g_textureLegacyArmScopeDepth = 0;
|
||||
// NOT thread_local (P5d round 3, package D), for hd's reason in
|
||||
// MG_Impl/Pipe/SlotAllocator.cpp: RefuseLegacyTextureArmFromApplyThread above
|
||||
// is this counter's ONLY reader in the tree and it returns before it looks
|
||||
// unless the transport is active and ServerLoop::OnApplyThread() is true, so
|
||||
// the apply thread is the only thread whose depth could change an answer. The
|
||||
// scope below therefore counts only there, which makes the apply thread the
|
||||
// single writer and the single reader - no race to defend, and no
|
||||
// __emutls_get_address call per access (7.4% of the apply thread, 7.7% and the
|
||||
// top symbol on the monolith's GL thread).
|
||||
Uint32 g_textureLegacyArmScopeDepth = 0;
|
||||
}
|
||||
|
||||
MGPipeTextureLegacyArmScope::MGPipeTextureLegacyArmScope() {
|
||||
++g_textureLegacyArmScopeDepth;
|
||||
MGPipeTextureLegacyArmScope::MGPipeTextureLegacyArmScope()
|
||||
: m_counted(MG_Remote::Server::ServerLoop::OnApplyThread()) {
|
||||
if (m_counted) ++g_textureLegacyArmScopeDepth;
|
||||
}
|
||||
|
||||
MGPipeTextureLegacyArmScope::~MGPipeTextureLegacyArmScope() {
|
||||
--g_textureLegacyArmScopeDepth;
|
||||
if (m_counted) --g_textureLegacyArmScopeDepth;
|
||||
}
|
||||
|
||||
Bool MGPipeTextureLegacyArmScope::Active() {
|
||||
Bool MGPipeTextureLegacyArmScope::ActiveOnApplyThread() {
|
||||
return g_textureLegacyArmScopeDepth != 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
SizeT MipmapStorage::GetLevelCount() const {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
RefuseLegacyTextureShapeReadFromApplyThread("GetMipmapLevelCount");
|
||||
#endif
|
||||
return m_data.size();
|
||||
}
|
||||
|
||||
@@ -161,16 +204,25 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
GLenum MipmapStorage::GetCompressedFormat(Uint level) const {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
RefuseLegacyTextureShapeReadFromApplyThread("GetCompressedFormat");
|
||||
#endif
|
||||
if (level >= m_compressedFormats.size()) return GL_NONE;
|
||||
return m_compressedFormats[level];
|
||||
}
|
||||
|
||||
SizeT MipmapStorage::GetCompressedByteSize(Uint level) const {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
RefuseLegacyTextureShapeReadFromApplyThread("GetCompressedByteSize");
|
||||
#endif
|
||||
if (level >= m_compressedData.size()) return 0;
|
||||
return m_compressedData[level].size();
|
||||
}
|
||||
|
||||
const void* MipmapStorage::MapCompressedData(Uint level) const {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
RefuseLegacyTextureShapeReadFromApplyThread("MapCompressedMipmapData");
|
||||
#endif
|
||||
if (level >= m_compressedData.size()) return nullptr;
|
||||
return m_compressedData[level].data();
|
||||
}
|
||||
@@ -181,6 +233,9 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
GLenum MipmapStorage::GetRequestedCompressedFormat(Uint level) const {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
RefuseLegacyTextureShapeReadFromApplyThread("GetRequestedCompressedFormat");
|
||||
#endif
|
||||
if (level >= m_requestedCompressedFormats.size()) return GL_NONE;
|
||||
return m_requestedCompressedFormats[level];
|
||||
}
|
||||
@@ -229,12 +284,18 @@ namespace MobileGL {
|
||||
}
|
||||
|
||||
IntVec3 MipmapStorage::GetTexelSize(Uint level) const {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
RefuseLegacyTextureShapeReadFromApplyThread("GetMipmapTexelSize");
|
||||
#endif
|
||||
auto& targetTexelSizes = m_texelSizes;
|
||||
if (level >= targetTexelSizes.size()) return {0, 0, 0};
|
||||
return targetTexelSizes[level];
|
||||
}
|
||||
|
||||
SizeT MipmapStorage::GetByteSize(Uint level) const {
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
RefuseLegacyTextureShapeReadFromApplyThread("GetMipmapByteSize");
|
||||
#endif
|
||||
if (level >= m_data.size()) return 0;
|
||||
return m_data[level].size();
|
||||
}
|
||||
|
||||
@@ -50,13 +50,27 @@ namespace MobileGL {
|
||||
// held, and greppable as exactly this name; retiring the scope is P7's server-side
|
||||
// Magma texture sync. Every OTHER apply-thread touch of a guarded surface is still
|
||||
// Fatal{RoleViolation, "texture-legacy-arm"}.
|
||||
//
|
||||
// The depth is counted ONLY on the apply thread (P5d round 3, package D), exactly
|
||||
// as hd's two scopes in MG_Impl/Pipe/SlotAllocator.h are: the guard above is the
|
||||
// counter's only reader and it returns before it looks unless
|
||||
// ServerLoop::OnApplyThread() is true, so a depth kept on any other thread could
|
||||
// never change an answer. m_counted remembers the constructor's decision so the
|
||||
// destructor undoes exactly what the constructor did. The query is spelled
|
||||
// ActiveOnApplyThread() rather than Active() because the precondition belongs in
|
||||
// the name: off the apply thread it now answers false however many scopes are
|
||||
// open, and a future second reader must be made to see that rather than trust a
|
||||
// bare Active().
|
||||
class MGPipeTextureLegacyArmScope {
|
||||
public:
|
||||
MGPipeTextureLegacyArmScope();
|
||||
~MGPipeTextureLegacyArmScope();
|
||||
MGPipeTextureLegacyArmScope(const MGPipeTextureLegacyArmScope&) = delete;
|
||||
MGPipeTextureLegacyArmScope& operator=(const MGPipeTextureLegacyArmScope&) = delete;
|
||||
static Bool Active();
|
||||
static Bool ActiveOnApplyThread();
|
||||
|
||||
private:
|
||||
Bool m_counted;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -108,6 +108,39 @@ namespace MobileGL::MG_State::GLState {
|
||||
}
|
||||
}
|
||||
Int GetMaxTouchedUnit() const { return m_maxTouchedUnit; }
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// High-water mark of IMAGE units ever bound by glBindImageTexture, and it is a SECOND
|
||||
// mark rather than a widening of the one above because the two index different
|
||||
// namespaces: GL 4.6 core 8.22's image units are their own array, and folding them
|
||||
// together would make a bind of image unit 7 push every per-draw TEXTURE-unit scan out
|
||||
// to eight slots for nothing - and a bind of the last advertised image unit push it out
|
||||
// to MAX_TEXTURE_IMAGE_UNITS (191), which is the whole array.
|
||||
//
|
||||
// WHAT IT IS FOR. The split client's per-draw GPU-write set swept ALL
|
||||
// MAX_TEXTURE_IMAGE_UNITS image units looking for a writable image-BUFFER texture
|
||||
// (MG_Remote/Client/GpuWritePending.cpp), because the frontend had no such mark - the
|
||||
// 2026-09-17 inproc profile measured that sweep at 2.15% self / 3.59% inclusive of the
|
||||
// GL thread in an application (Minecraft) that never binds an image at all. With the
|
||||
// mark that application's sweep is one compare against -1.
|
||||
//
|
||||
// IT ONLY EVER GROWS, which is NoteUnitTouched's rule one notch stronger and is the
|
||||
// whole safety argument: an unbind - glBindImageTexture(unit, 0, ...), or the
|
||||
// delete-unbind in MarkTextureObjectForDeletion - leaves the mark where it was, so a
|
||||
// scan bounded by it is an OVER-approximation. Over-approximating a GPU-write set costs
|
||||
// a readback the narrowing channel removes; under-approximating it reads a stale buffer
|
||||
// and says nothing, which is the one direction that set may not fail in.
|
||||
//
|
||||
// PUSH BUILDS ONLY, so the pull build's TextureState keeps its layout and its .text byte
|
||||
// for byte (G1): the only reader is a push-build path and the only writer -
|
||||
// MG_Impl/GLImpl/Texture/GL_Texture.cpp's BindImageTexture - is guarded the same way.
|
||||
void NoteImageUnitTouched(Int unit) {
|
||||
if (unit > m_maxTouchedImageUnit && unit < MAX_TEXTURE_IMAGE_UNITS) {
|
||||
m_maxTouchedImageUnit = unit;
|
||||
}
|
||||
}
|
||||
// -1 until an image unit is bound for the first time, i.e. "there is nothing to sweep".
|
||||
Int GetMaxTouchedImageUnit() const { return m_maxTouchedImageUnit; }
|
||||
#endif
|
||||
Uint64 GetTextureBindGeneration() const { return m_textureBindGeneration; }
|
||||
// Both counters below are pushed PipeInputs fields AND are moved by writes the
|
||||
// backends make into frontend objects during their own verb - a synthesised fallback
|
||||
@@ -164,6 +197,8 @@ namespace MobileGL::MG_State::GLState {
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
Uint64 m_anyTextureContentGeneration = 0;
|
||||
Uint64 m_anyTextureParamsGeneration = 0;
|
||||
// See NoteImageUnitTouched: the image-unit twin of m_maxTouchedUnit, push builds only.
|
||||
Int m_maxTouchedImageUnit = -1;
|
||||
#endif
|
||||
static Uint64 AllocateContextId();
|
||||
|
||||
|
||||
@@ -171,6 +171,11 @@ TEST_F(SplitBufferSet, Row2OnlyAWritableImageBufferTextureCounts) {
|
||||
}
|
||||
|
||||
// Row 2's WALK, through the image unit the context actually holds.
|
||||
//
|
||||
// THE FIXTURE BINDS THE UNIT BY HAND, so it has to move the image-unit high-water mark by hand
|
||||
// too (P5d round 3, package C): the walk is bounded by that mark now, and a case that writes the
|
||||
// binding straight into the slot never went through glBindImageTexture, which is what feeds it.
|
||||
// The mark's own producer has its own case - ImageEmit.TheBindFeedsTheImageUnitHighWaterMark.
|
||||
TEST_F(SplitBufferSet, Row2AWritableImageBufferTextureIsMarkedByADraw) {
|
||||
auto texture = MakeShared<MG_State::GLState::TextureObjectBuffer>(8u);
|
||||
auto backing = MakeBuffer(14u, 128);
|
||||
@@ -178,6 +183,7 @@ TEST_F(SplitBufferSet, Row2AWritableImageBufferTextureIsMarkedByADraw) {
|
||||
auto& binding = MG_State::pGLContext->GetImageTextureBinding(0);
|
||||
binding.Texture = texture;
|
||||
binding.Access = GL_WRITE_ONLY;
|
||||
MG_State::pGLContext->NoteImageUnitTouched(0);
|
||||
|
||||
MG_Remote::Client::MarkGpuWritesForDraw();
|
||||
|
||||
@@ -186,6 +192,41 @@ TEST_F(SplitBufferSet, Row2AWritableImageBufferTextureIsMarkedByADraw) {
|
||||
binding = MG_State::GLState::ImageTextureBinding{};
|
||||
}
|
||||
|
||||
// Row 2's BOUND, and it is the half an optimisation is allowed to get wrong in exactly one
|
||||
// direction (P5d round 3, package C). The sweep used to be MAX_TEXTURE_IMAGE_UNITS wide on every
|
||||
// draw - 2.15% self of the GL thread on the Minecraft inproc profile, in a workload with no image
|
||||
// binding anywhere - and is now bounded by the frontend's image-unit high-water mark.
|
||||
//
|
||||
// THE CASE PINS BOTH ENDS OF THAT BOUND. Below the mark a writable image-buffer texture is still
|
||||
// found; a mark that has never moved means the walk does not run at all, which is the whole
|
||||
// saving and is what makes "the mark only ever grows" load-bearing rather than decorative. Revert
|
||||
// the bound to `unit < MAX_TEXTURE_IMAGE_UNITS` and the second half goes red; drop
|
||||
// NoteImageUnitTouched from glBindImageTexture and ImageEmit.TheBindFeedsTheImageUnitHighWaterMark
|
||||
// goes red instead - the two together are what say the narrowing is safe.
|
||||
TEST_F(SplitBufferSet, Row2TheSweepIsBoundedByTheImageUnitHighWaterMark) {
|
||||
ASSERT_EQ(MG_State::pGLContext->GetMaxTouchedImageUnit(), -1)
|
||||
<< "a fresh context has bound no image unit, so the sweep has nothing to walk";
|
||||
|
||||
auto texture = MakeShared<MG_State::GLState::TextureObjectBuffer>(9u);
|
||||
auto backing = MakeBuffer(18u, 128);
|
||||
texture->GetBufferBindingSlot().Bind(backing);
|
||||
constexpr Int kUnit = 5;
|
||||
auto& binding = MG_State::pGLContext->GetImageTextureBinding(kUnit);
|
||||
binding.Texture = texture;
|
||||
binding.Access = GL_READ_WRITE;
|
||||
|
||||
MG_Remote::Client::MarkGpuWritesForDraw();
|
||||
EXPECT_EQ(MG_Remote::Client::ProducerMarkCount(GpuWriteProducer::WritableImageBufferTexture), 0u)
|
||||
<< "the mark has never moved, so the sweep must not walk a single unit";
|
||||
|
||||
MG_State::pGLContext->NoteImageUnitTouched(kUnit);
|
||||
MG_Remote::Client::MarkGpuWritesForDraw();
|
||||
EXPECT_EQ(MG_Remote::Client::ProducerMarkCount(GpuWriteProducer::WritableImageBufferTexture), 1u)
|
||||
<< "a unit at the mark is inside the walk";
|
||||
|
||||
binding = MG_State::GLState::ImageTextureBinding{};
|
||||
}
|
||||
|
||||
// Row 3 - VulkanRenderer.cpp:11618. With no capture active there is nothing to mark, and that
|
||||
// gate is the half worth pinning: a mark taken with no active capture would mark whatever the
|
||||
// binding points happened to hold from a previous one.
|
||||
@@ -506,9 +547,195 @@ TEST_F(SplitBufferSet, OnlyAdoptTierTwoIsImplemented) {
|
||||
MG_Config::Ipc.AdoptTier = 2;
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
// THE MPROTECT TRACKER'S OUTWARD ALIGNMENT (P5d round 3). A split build's shadow is
|
||||
// page-aligned AND page-granular (PipeResource.h), so every page a mapped range touches is
|
||||
// the shadow's own and the tracker protects the range's containing pages whole: no
|
||||
// unprotected edge bytes, no per-draw XXH3 (8.5% of the client thread at VD12 before this).
|
||||
// White-box on purpose - which pages a map protected is not observable through any push
|
||||
// count, and the epoch (the one thing a protected page moves) is the tracker's own.
|
||||
// =====================================================================================
|
||||
|
||||
// A sub-page map used to register with an EMPTY interior and two hashed edges; now it is
|
||||
// one protected page, and a write through the pointer FAULTS - which is the whole point.
|
||||
TEST_F(SplitBufferSet, ASubPageMapIsOneProtectedPageAndAWriteThroughItFaults) {
|
||||
if (!PersistentMapTracker::MprotectArmAvailableForTest()) {
|
||||
GTEST_SKIP() << "no mprotect arm on this host (handler not installable, or the kernel "
|
||||
"page is not the tracker's 4 KB); the hash arm serves every map here";
|
||||
}
|
||||
constexpr SizeT kSize = 100; // well under a page, and not a multiple of anything
|
||||
auto buffer = MakeBuffer(26u, kSize);
|
||||
ASSERT_EQ(buffer->ShadowAllocationBytes() % 4096u, 0u)
|
||||
<< "the split build's shadow allocator rounds the SIZE to whole pages, not just the base";
|
||||
ASSERT_GE(buffer->ShadowAllocationBytes(), kSize);
|
||||
auto* mapped = static_cast<Uint8*>(buffer->AcquireMemoryRange(
|
||||
Range1D{0, kSize}, BufferMappingAccessBit::Write | BufferMappingAccessBit::Persistent));
|
||||
ASSERT_NE(mapped, nullptr);
|
||||
ASSERT_EQ(reinterpret_cast<uintptr_t>(mapped) % 4096u, 0u) << "the shadow base is page-aligned";
|
||||
|
||||
const auto* slot = PersistentMapTracker::TrackedSlotForTest(*buffer);
|
||||
ASSERT_NE(slot, nullptr) << "a page-aligned, page-granular shadow registers on the mprotect arm";
|
||||
EXPECT_EQ(slot->pageCount, 1u)
|
||||
<< "a sub-page map is ONE protected page under outward alignment, not an empty interior";
|
||||
EXPECT_FALSE(slot->hasEdges) << "outward alignment leaves no unprotected edge bytes to hash";
|
||||
const uintptr_t base = slot->base.load();
|
||||
const uintptr_t end = slot->end.load();
|
||||
EXPECT_EQ(base, reinterpret_cast<uintptr_t>(mapped));
|
||||
EXPECT_EQ(end, base + 4096u);
|
||||
EXPECT_LE(end, reinterpret_cast<uintptr_t>(mapped) + buffer->ShadowAllocationBytes())
|
||||
<< "the protected span never runs past the shadow's own allocation";
|
||||
|
||||
// Fresh state ships everything once, then re-arms; with nothing written a second push
|
||||
// ships nothing (and, with no edges, hashes nothing).
|
||||
MG_Remote::Client::PushPersistentMapsBeforeVerb();
|
||||
EXPECT_EQ(PersistentMapTracker::Instance().BlocksPushed(), 1u);
|
||||
EXPECT_EQ(PersistentMapTracker::Instance().BytesPushed(), static_cast<Uint64>(kSize));
|
||||
MG_Remote::Client::PushPersistentMapsBeforeVerb();
|
||||
EXPECT_EQ(PersistentMapTracker::Instance().BlocksPushed(), 1u);
|
||||
|
||||
// The one page IS protected: a write through the application's pointer faults into the
|
||||
// handler (the epoch moves), and the next push ships the page's block clamped to the
|
||||
// mapped range. Under the old empty-interior registration nothing faulted here.
|
||||
const Uint64 epochBefore = PersistentMapTracker::FaultEpochForTest();
|
||||
mapped[kSize - 1] = 0x5A;
|
||||
EXPECT_GT(PersistentMapTracker::FaultEpochForTest(), epochBefore)
|
||||
<< "the sub-page map's page was not protected: the write did not fault";
|
||||
MG_Remote::Client::PushPersistentMapsBeforeVerb();
|
||||
EXPECT_EQ(PersistentMapTracker::Instance().BlocksPushed(), 2u);
|
||||
EXPECT_EQ(PersistentMapTracker::Instance().BytesPushed(), static_cast<Uint64>(2 * kSize))
|
||||
<< "the push is clamped to [begin, end) even though the protected page is wider";
|
||||
|
||||
// The unmap retires the slot and restores the page writable: an API write into the
|
||||
// shadow afterwards must not fault (an unowned fault chains to SIG_DFL and dies).
|
||||
buffer->ReleaseMemory(false);
|
||||
EXPECT_EQ(PersistentMapTracker::TrackedSlotForTest(*buffer), nullptr);
|
||||
const Uint8 byte = 0x3C;
|
||||
buffer->UploadSubData(DataPtr{const_cast<Uint8*>(&byte), 1}, 0);
|
||||
}
|
||||
|
||||
// The inward fallback is kept for any shadow that fails the page-granular test, and the
|
||||
// only way to reach it on this build - whose allocator never hands out such a shadow - is
|
||||
// to register a range by hand with a base or an extent the tracker cannot vouch for.
|
||||
TEST_F(SplitBufferSet, AShadowThatFailsThePageGranularTestKeepsTheInwardAlignmentAndItsEdges) {
|
||||
if (!PersistentMapTracker::MprotectArmAvailableForTest()) {
|
||||
GTEST_SKIP() << "no mprotect arm on this host (handler not installable, or the kernel "
|
||||
"page is not the tracker's 4 KB); the hash arm serves every map here";
|
||||
}
|
||||
// Three whole pages from the shadow allocator itself: page-aligned, page-granular.
|
||||
MG_State::GLState::MapAlignedData store(3u * 4096u);
|
||||
const auto storeBase = reinterpret_cast<uintptr_t>(store.data());
|
||||
ASSERT_EQ(storeBase % 4096u, 0u);
|
||||
const SizeT extent = MG_State::GLState::ShadowAllocationBytesFor(store.capacity());
|
||||
ASSERT_EQ(extent, 3u * 4096u);
|
||||
// Never a real buffer's id: BufferObject lifetime ids count up from 1.
|
||||
constexpr Uint64 kId = ~0ull - 7u;
|
||||
|
||||
// An UNALIGNED base (the shadow's own storage, offset by 64) with a range of two pages:
|
||||
// only the one page fully inside [base+64, base+64+8192) is protected, both ends are
|
||||
// edges - the pre-round-3 shape, and still the safe answer for a base like this.
|
||||
const auto* slot = PersistentMapTracker::TrackForTest(kId, store.data() + 64, 0, 2u * 4096u, extent);
|
||||
ASSERT_NE(slot, nullptr);
|
||||
EXPECT_EQ(slot->pageCount, 1u);
|
||||
EXPECT_TRUE(slot->hasEdges);
|
||||
EXPECT_EQ(slot->base.load(), storeBase + 4096u);
|
||||
EXPECT_EQ(slot->end.load(), storeBase + 2u * 4096u);
|
||||
PersistentMapTracker::UntrackForTest(kId);
|
||||
|
||||
// An aligned base with an extent the caller could NOT vouch for (0): inward as well.
|
||||
slot = PersistentMapTracker::TrackForTest(kId, store.data(), 64, 2u * 4096u + 64, 0);
|
||||
ASSERT_NE(slot, nullptr);
|
||||
EXPECT_EQ(slot->pageCount, 1u);
|
||||
EXPECT_TRUE(slot->hasEdges);
|
||||
PersistentMapTracker::UntrackForTest(kId);
|
||||
|
||||
// A range that runs PAST the extent it was told about is never widened into it.
|
||||
slot = PersistentMapTracker::TrackForTest(kId, store.data(), 64, 2u * 4096u + 64, 2u * 4096u);
|
||||
ASSERT_NE(slot, nullptr);
|
||||
EXPECT_EQ(slot->pageCount, 1u);
|
||||
EXPECT_TRUE(slot->hasEdges);
|
||||
PersistentMapTracker::UntrackForTest(kId);
|
||||
|
||||
// And the same range on the same aligned base with the TRUE extent widens outward to
|
||||
// its three containing pages - exactly the extent, so the clamp sits on its boundary.
|
||||
slot = PersistentMapTracker::TrackForTest(kId, store.data(), 64, 2u * 4096u + 64, extent);
|
||||
ASSERT_NE(slot, nullptr);
|
||||
EXPECT_EQ(slot->pageCount, 3u);
|
||||
EXPECT_FALSE(slot->hasEdges);
|
||||
EXPECT_EQ(slot->base.load(), storeBase);
|
||||
EXPECT_EQ(slot->end.load(), storeBase + extent);
|
||||
PersistentMapTracker::UntrackForTest(kId);
|
||||
// Restored writable before the store goes out of scope: freeing a still-protected page
|
||||
// would fault inside the allocator with no owner to answer.
|
||||
store[0] = 1;
|
||||
store[extent - 1] = 1;
|
||||
}
|
||||
|
||||
// THE DRAIN THE EPOCH SKIP RESTS ON. A fault marks a page and moves the epoch; the next
|
||||
// draw's walk consumes the epoch. If that walk pushed only the buffers the draw bound, a
|
||||
// faulted map the draw did NOT bind would be left marked, writable and unable to move the
|
||||
// epoch ever again - and the next draw that does bind it would skip, and the server would
|
||||
// draw its pre-write bytes. Before round 3 the skip's edge service drained every member
|
||||
// with edges by accident (nearly all of them); with page-granular shadows nothing has
|
||||
// edges, so the walk drains every marked member on purpose. Two maps, one bound: the write
|
||||
// to the unbound one must ship before the draw that binds it. Driven through
|
||||
// PushDrawConsumers itself - PushPersistentMapsBeforeVerb never reaches the skip.
|
||||
TEST_F(SplitBufferSet, AFaultedMapTheDrawDidNotBindStillShipsBeforeTheDrawThatDoes) {
|
||||
if (!PersistentMapTracker::MprotectArmAvailableForTest()) {
|
||||
GTEST_SKIP() << "no mprotect arm on this host (handler not installable, or the kernel "
|
||||
"page is not the tracker's 4 KB); the hash arm serves every map here";
|
||||
}
|
||||
constexpr SizeT kSize = 4096; // one page, one block each
|
||||
auto a = MakeBuffer(29u, kSize);
|
||||
auto b = MakeBuffer(30u, kSize);
|
||||
auto* aMapped = static_cast<Uint8*>(a->AcquireMemoryRange(
|
||||
Range1D{0, kSize}, BufferMappingAccessBit::Write | BufferMappingAccessBit::Persistent));
|
||||
b->AcquireMemoryRange(Range1D{0, kSize},
|
||||
BufferMappingAccessBit::Write | BufferMappingAccessBit::Persistent);
|
||||
ASSERT_NE(aMapped, nullptr);
|
||||
ASSERT_NE(PersistentMapTracker::TrackedSlotForTest(*a), nullptr)
|
||||
<< "both maps must be on the mprotect arm, or the epoch is not what decides";
|
||||
ASSERT_NE(PersistentMapTracker::TrackedSlotForTest(*b), nullptr);
|
||||
auto& tracker = PersistentMapTracker::Instance();
|
||||
auto& point = MG_State::pGLContext->GetBufferBindingPoint(BufferTarget::ShaderStorage, 0);
|
||||
|
||||
// Draw 1 binds B only. Both maps are fresh - every page marked, and the registration
|
||||
// moved the epoch - so this walk ships both once: the unbound A as well.
|
||||
point.Bind(b);
|
||||
tracker.PushDrawConsumers();
|
||||
EXPECT_EQ(tracker.BlocksPushed(), 2u) << "first push ships everything once, the unbound map too";
|
||||
// Draw 2, nothing written: the epoch is unmoved and the skip ships nothing.
|
||||
tracker.PushDrawConsumers();
|
||||
EXPECT_EQ(tracker.BlocksPushed(), 2u);
|
||||
|
||||
// The application writes A through its pointer (a fault: A's page is marked, the epoch
|
||||
// moves) and the next draw binds B only.
|
||||
const Uint64 epochBefore = PersistentMapTracker::FaultEpochForTest();
|
||||
aMapped[kSize / 2] = 0x5A;
|
||||
ASSERT_GT(PersistentMapTracker::FaultEpochForTest(), epochBefore)
|
||||
<< "the write did not fault: A's page was not re-armed by its first push";
|
||||
tracker.PushDrawConsumers();
|
||||
EXPECT_EQ(tracker.BlocksPushed(), 3u)
|
||||
<< "the walk that consumed the epoch must drain A's marked page although this draw "
|
||||
"bound only B - nothing will ever move the epoch for that page again";
|
||||
|
||||
// Draw 4 binds A. The epoch is unmoved and the skip fires - correctly, because A's
|
||||
// write already crossed. With the drain reverted, this is the draw that reads stale.
|
||||
point.Bind(a);
|
||||
tracker.PushDrawConsumers();
|
||||
EXPECT_EQ(tracker.BlocksPushed(), 3u) << "nothing left to ship";
|
||||
EXPECT_EQ(tracker.BytesPushed(), static_cast<Uint64>(3u * kSize));
|
||||
|
||||
point.Bind(nullptr);
|
||||
a->ReleaseMemory(false);
|
||||
b->ReleaseMemory(false);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// THE SAME SIXTEEN NAMES, SO THE ctest NAME SET DOES NOT MOVE BETWEEN LANES. G2 compares the
|
||||
// THE SAME NAMES, ONE FOR ONE, SO THE ctest NAME SET DOES NOT MOVE BETWEEN LANES. (The count
|
||||
// is deliberately NOT written out here: it read "SIXTEEN" against seventeen stubs before this
|
||||
// commit and "SEVENTEEN" against eighteen after, so it has never once matched the list it
|
||||
// claims to describe - and the list below is the authority either way.) G2 compares the
|
||||
// pull and push name lists line for line and G14 allows build-split to ADD names but never to
|
||||
// remove one, so a case that exists only where it can run would break both gates for a reason
|
||||
// that has nothing to do with what it tests. It skips instead, and says why.
|
||||
@@ -516,6 +743,7 @@ TEST(SplitBufferSet, Row0EverySsboBindingPointIsMarkedByADraw) { MGL_SPLIT_ONLY_
|
||||
TEST(SplitBufferSet, Row1EveryBoundAtomicCounterIsMarkedByADraw) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, Row2OnlyAWritableImageBufferTextureCounts) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, Row2AWritableImageBufferTextureIsMarkedByADraw) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, Row2TheSweepIsBoundedByTheImageUnitHighWaterMark) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, Row3TransformFeedbackTargetsAreOnlyMarkedWhileACaptureIsActive) {
|
||||
MGL_SPLIT_ONLY_OR_SKIP();
|
||||
}
|
||||
@@ -531,6 +759,11 @@ TEST(SplitBufferSet, AZeroBlockSizeTurnsThePushOffRatherThanMakingItUnlimited) {
|
||||
TEST(SplitBufferSet, ADestroyedBufferLeavesTheSet) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, UnderSplitTheWritebackClearsThePendingFlagAndNotTheRequest) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, OnlyAdoptTierTwoIsImplemented) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, ASubPageMapIsOneProtectedPageAndAWriteThroughItFaults) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
TEST(SplitBufferSet, AShadowThatFailsThePageGranularTestKeepsTheInwardAlignmentAndItsEdges) {
|
||||
MGL_SPLIT_ONLY_OR_SKIP();
|
||||
}
|
||||
TEST(SplitBufferSet, AFaultedMapTheDrawDidNotBindStillShipsBeforeTheDrawThatDoes) { MGL_SPLIT_ONLY_OR_SKIP(); }
|
||||
|
||||
#endif // MOBILEGL_BUILD_DISAGGREGATED
|
||||
|
||||
|
||||
@@ -141,7 +141,10 @@ endif()
|
||||
# have to come back to this file to add a case.
|
||||
#
|
||||
# P4a's six are FramebufferEmitTest, TextureEmitTest, SamplerEmitTest, ImageEmitTest,
|
||||
# ProgramEmitTest and CompositeResolverTest. Each lands from the contract commit with one case
|
||||
# ProgramEmitTest and CompositeResolverTest; P5e's one is ShaderBufferEmitTest (package sb, the
|
||||
# indexed buffer binding points), which takes the same shape because it has the same needs - a
|
||||
# live frontend context, a route that reaches the applier, and refusals that are a log line in
|
||||
# a shipped push build. Each lands from the contract commit with one case
|
||||
# that pins the shape its later cases depend on - the emitter is one never-destroyed process
|
||||
# singleton, or the composite band has exactly one door - so none of them is an empty file
|
||||
# waiting for a package, and none of them can be registered wrongly without a red test.
|
||||
@@ -153,7 +156,8 @@ endif()
|
||||
# HERE is what keeps the later packages out of this file.
|
||||
foreach(pipeTest ResourceEmitTest VertexInputEmitTest
|
||||
FramebufferEmitTest TextureEmitTest SamplerEmitTest ImageEmitTest
|
||||
ProgramEmitTest CompositeResolverTest)
|
||||
ProgramEmitTest CompositeResolverTest
|
||||
ShaderBufferEmitTest)
|
||||
add_executable(${pipeTest} ${pipeTest}.cpp)
|
||||
|
||||
target_include_directories(${pipeTest} PRIVATE
|
||||
@@ -212,7 +216,8 @@ gtest_discover_tests(PipeCatalogueTest DISCOVERY_TIMEOUT 30 PROPERTIES LABELS un
|
||||
gtest_discover_tests(FieldOwnershipTest DISCOVERY_TIMEOUT 30 PROPERTIES LABELS unit)
|
||||
foreach(pipeTest ResourceEmitTest VertexInputEmitTest
|
||||
FramebufferEmitTest TextureEmitTest SamplerEmitTest ImageEmitTest
|
||||
ProgramEmitTest CompositeResolverTest)
|
||||
ProgramEmitTest CompositeResolverTest
|
||||
ShaderBufferEmitTest)
|
||||
gtest_discover_tests(${pipeTest} DISCOVERY_TIMEOUT 30 PROPERTIES LABELS unit)
|
||||
endforeach()
|
||||
gtest_discover_tests(MagmaPipeIdentityTest DISCOVERY_TIMEOUT 30 PROPERTIES LABELS unit)
|
||||
|
||||
@@ -279,7 +279,7 @@ TEST(CompositeResolver, ACompositeRecordLandsInTheBandsOwnTableAndNeverGrowsTheO
|
||||
const MGPipeHandle composite{kMGPipeShaderCsoCompositeSlotBase + 2, 1};
|
||||
ASSERT_TRUE(MGPipeIsCompositeShaderSlot(composite.Slot));
|
||||
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(composite, 0x3u), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(composite, 0x3u), &link, &spirv, nullptr);
|
||||
EXPECT_TRUE(MGPipeApplier().ShaderCsos.empty())
|
||||
<< "one composite grew the ordinary table to the band's base - that is the 236 MB spike";
|
||||
ASSERT_EQ(MGPipeApplier().CompositeShaderCsos.size(), 3u)
|
||||
@@ -298,7 +298,7 @@ TEST(CompositeResolver, ACompositeRecordLandsInTheBandsOwnTableAndNeverGrowsTheO
|
||||
|
||||
// An ordinary program lands in the other table, and the two do not see each other even
|
||||
// though the composite's record is at index 2 of its own.
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(MGPipeHandle{2, 1}, 0x7u), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(MGPipeHandle{2, 1}, 0x7u), &link, &spirv, nullptr);
|
||||
ASSERT_GT(MGPipeApplier().ShaderCsos.size(), 2u);
|
||||
EXPECT_EQ(MGPipeApplier().ShaderCsos[2].Desc.StageMask, 0x7u);
|
||||
EXPECT_EQ(MGPipeApplier().CompositeShaderCsos[2].Desc.StageMask, 0x3u)
|
||||
@@ -319,7 +319,7 @@ TEST(CompositeResolver, ASecondDeleteOfACompositeIsARefusedNoOpRatherThanASecond
|
||||
const SpirvArtifacts spirv;
|
||||
const MGPipeHandle composite{kMGPipeShaderCsoCompositeSlotBase, 3};
|
||||
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(composite, 0x3u), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(composite, 0x3u), &link, &spirv, nullptr);
|
||||
MGPipeApplySetDrawProgram(ProgramHandle(composite));
|
||||
ASSERT_EQ(MGPipeApplier().DrawProgram, composite);
|
||||
|
||||
@@ -337,7 +337,7 @@ TEST(CompositeResolver, ASecondDeleteOfACompositeIsARefusedNoOpRatherThanASecond
|
||||
|
||||
// And the band's slot is re-usable afterwards: a recycled composite is a new identity and
|
||||
// starts its record over.
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(MGPipeHandle{composite.Slot, 4}, 0x1u), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(MGPipeHandle{composite.Slot, 4}, 0x1u), &link, &spirv, nullptr);
|
||||
EXPECT_TRUE(MGPipeApplier().CompositeShaderCsos[0].Live);
|
||||
EXPECT_EQ(MGPipeApplier().CompositeShaderCsos[0].Gen, 4u);
|
||||
EXPECT_EQ(MGPipeApplier().CompositeShaderCsos[0].Serial, 0u);
|
||||
@@ -358,7 +358,7 @@ TEST(CompositeResolver, ASlotAtTheShaderCsoLimitIsRefusedWhileTheLastBandSlotIsN
|
||||
// The positive control: the LAST slot of the band is a legal composite handle.
|
||||
const MGPipeHandle last{kMGPipeShaderCsoSlotLimit - 1, 1};
|
||||
ASSERT_TRUE(MGPipeIsCompositeShaderSlot(last.Slot));
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(last, 0x3u), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(last, 0x3u), &link, &spirv, nullptr);
|
||||
ASSERT_EQ(MGPipeApplier().CompositeShaderCsos.size(),
|
||||
static_cast<SizeT>(kMGPipeShaderCsoSlotLimit - kMGPipeShaderCsoCompositeSlotBase));
|
||||
EXPECT_TRUE(MGPipeApplier().CompositeShaderCsos.back().Live);
|
||||
@@ -367,7 +367,7 @@ TEST(CompositeResolver, ASlotAtTheShaderCsoLimitIsRefusedWhileTheLastBandSlotIsN
|
||||
const MGPProgramDesc past = CompositeDesc(MGPipeHandle{kMGPipeShaderCsoSlotLimit, 1}, 0x3u);
|
||||
ExpectRefusedNaming("create_shader_state {slot=1048576, gen=1}: the slot is outside the record table's "
|
||||
"bound",
|
||||
[&past, &link, &spirv]() { MGPipeApplyCreateShaderState(past, &link, &spirv); });
|
||||
[&past, &link, &spirv]() { MGPipeApplyCreateShaderState(past, &link, &spirv, nullptr); });
|
||||
|
||||
// And an ORDINARY slot at or above the band's base is out of range by definition: the
|
||||
// allocator refuses the band for an ordinary program, so nothing legal can name one.
|
||||
@@ -684,7 +684,7 @@ void main() { o_color = vec4(0.5); }
|
||||
const MGPipeHandle handleB = MGPipeSlots().AllocateComposite(compositeB->GetLifetimeId());
|
||||
ASSERT_NE(handleA, handleB);
|
||||
for (const MGPipeHandle handle : {handleA, handleB}) {
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(handle, 0x3u), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(handle, 0x3u), &link, &spirv, nullptr);
|
||||
MGPipeNoteHandlePublished(MGPipeKind::ShaderCso, handle);
|
||||
}
|
||||
const Uint64 releasesBefore = resolver.GetCounters().Releases;
|
||||
@@ -736,7 +736,7 @@ void main() { o_color = vec4(0.5); }
|
||||
const ProgramPipelineObject pipeline{kPipelineName};
|
||||
SharedPtr<ProgramObject> composite = MakeShared<ProgramObject>(0u);
|
||||
const MGPipeHandle handle = MGPipeSlots().AllocateComposite(composite->GetLifetimeId());
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(handle, 0x3u), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(CompositeDesc(handle, 0x3u), &link, &spirv, nullptr);
|
||||
MGPipeNoteHandlePublished(MGPipeKind::ShaderCso, handle);
|
||||
ASSERT_EQ(resolver.Observe(kDoomedContext, pipeline, *composite, handle), handle);
|
||||
ASSERT_EQ(resolver.Size(), sizeBefore + 1u);
|
||||
|
||||
@@ -166,6 +166,9 @@ TEST(FieldOwnershipTest, TheSevenStickyForwardsAgreeWithTheirFieldRows) {
|
||||
TEST(FieldOwnershipTest, VerbBoundaryOpsCoverEveryVerbShapedCall) {
|
||||
GTEST_SKIP() << "push not compiled in (MOBILEGL_PIPE_PUSH=OFF)";
|
||||
}
|
||||
TEST(FieldOwnershipTest, TheResidualFillsSuppliedMemoReKeysOnEveryInputThatMovesAnAnswer) {
|
||||
GTEST_SKIP() << "push not compiled in (MOBILEGL_PIPE_PUSH=OFF)";
|
||||
}
|
||||
|
||||
#else // MOBILEGL_PIPE_PUSH
|
||||
|
||||
@@ -387,6 +390,124 @@ TEST_F(FieldOwnershipTest, VerbBoundaryOpsCoverEveryVerbShapedCall) {
|
||||
// that arms all of it, and nothing in a monolith lane stamps.
|
||||
// ---------------------------------------------------------------------------------------
|
||||
|
||||
// P5d round 3 (package C): THE RESIDUAL FILL's SUPPLIED-SET MEMO, and the one thing about it
|
||||
// that can be wrong. The predicate is the same expression step 4 used to spell once per field
|
||||
// per verb, so the change carries no new verdict - what it carries is a KEY, and a key that
|
||||
// misses one of its inputs answers the PREVIOUS environment's question at the new one. In the
|
||||
// direction that loses that means the fill SKIPS a field no call supplied - and that is SILENT,
|
||||
// not an abort: the walk stamps FilledGen from the verb serial whether or not it copied, so the
|
||||
// field reads FRESH with the previous verb's value and the draw goes out with a stale binding
|
||||
// slot. Poison catches an UNSTAMPED read; it cannot catch a stamped-but-uncopied one. That is
|
||||
// exactly why this case exists - there is no second line of defence behind it.
|
||||
//
|
||||
// So each input is moved on its own with the answer read back in between, and in an order where
|
||||
// a memo that ignored that input would have to return the stale answer rather than the right one
|
||||
// by luck. This case lives outside the split-only block because the memo is in the push build
|
||||
// too (PipeFill.cpp is compiled at MOBILEGL_PIPE_PUSH), and the fields it names are the same
|
||||
// three in both.
|
||||
//
|
||||
// THE FOURTH KEY INPUT - the P4a consumer signal - GETS STEP 4 AND A DIFFERENT SHAPE, because
|
||||
// it cannot move an answer today and no honest case can pretend otherwise: every field whose
|
||||
// emitter belongs to a P4a family is also a field the applier cannot supply whole (its storage
|
||||
// is a frontend pointer), so that conjunct is DOMINATED and the mask is identical either way.
|
||||
// Step 4 moves the signal for real and pins the domination instead, so that the day a P4a row
|
||||
// gains a twin the case goes red and says what to write - the same day PipeFill.cpp's
|
||||
// NoP4aFamilyFieldIsWhollySupplied() static_assert fires.
|
||||
TEST_F(FieldOwnershipTest, TheResidualFillsSuppliedMemoReKeysOnEveryInputThatMovesAnAnswer) {
|
||||
constexpr Uint64 kNoSubsystems = 0;
|
||||
constexpr Uint64 kEverySubsystem = ~Uint64{0};
|
||||
|
||||
// 1. THE PUSH MASK. create_render_state carries GetRenderStateParameters whole and the
|
||||
// applier writes it without deriving, so at a mask that carries the render-state bit the
|
||||
// fill skips it - and at 0, which is what a unit lane runs at (Features.PipePush defaults
|
||||
// to 0), nothing is emitted and every field is pulled.
|
||||
EXPECT_FALSE(MGPipeResidualFillSuppliesField(MGPipeInputField::GetRenderStateParameters,
|
||||
kNoSubsystems, true, false));
|
||||
EXPECT_TRUE(MGPipeResidualFillSuppliesField(MGPipeInputField::GetRenderStateParameters,
|
||||
kEverySubsystem, true, false));
|
||||
EXPECT_FALSE(MGPipeResidualFillSuppliesField(MGPipeInputField::GetRenderStateParameters,
|
||||
kNoSubsystems, true, false))
|
||||
<< "the memo answered the previous mask: MOBILEGL_PIPE_PUSH is not in its key, and a "
|
||||
"per-subsystem A/B would then fill from the wrong subsystem set";
|
||||
|
||||
// 2. THE DERIVATION LATCH. GetViewport reaches PipeInputs only through
|
||||
// MGPipeDeriveRenderStateFields, so a build whose derivation is a stub must keep PULLING
|
||||
// it - skipping it there leaves the mirror unwritten and the backend reading a default.
|
||||
EXPECT_TRUE(MGPipeResidualFillSuppliesField(MGPipeInputField::GetViewport, kEverySubsystem,
|
||||
true, false));
|
||||
EXPECT_FALSE(MGPipeResidualFillSuppliesField(MGPipeInputField::GetViewport, kEverySubsystem,
|
||||
false, false))
|
||||
<< "the memo answered the previous latch: ApplierDerivesRenderStateFields is not in its key";
|
||||
|
||||
// 3. P5c rv's WIRE GATE (CONTRACT-P5C.md §5.3). set_context_values has no producer without a
|
||||
// live wire, so its eight value-class fields keep being pulled under monolith - G1's
|
||||
// byte-for-byte rule - and are skipped only when the record really crosses.
|
||||
EXPECT_FALSE(MGPipeResidualFillSuppliesField(MGPipeInputField::GetActiveTextureUnit,
|
||||
kEverySubsystem, true, false));
|
||||
EXPECT_TRUE(MGPipeResidualFillSuppliesField(MGPipeInputField::GetActiveTextureUnit,
|
||||
kEverySubsystem, true, true))
|
||||
<< "the memo answered the previous wire state: contextValuesWireLive is not in its key, "
|
||||
"and the emission's half of the gate and the fill's half would then disagree";
|
||||
|
||||
// 4. THE P4a CONSUMER SIGNAL, which is in the key and is DOMINATED, so this step pins the
|
||||
// domination rather than pretending to move an answer. Under monolith the signal IS "did
|
||||
// a backend register the resource op table" (P4aFamilyHasItsConsumer, PipeFill.cpp), and
|
||||
// MG_Config::Transport is a constexpr Monolith in every lane but a split one - so the
|
||||
// signal really moves here, at a mask that carries all four P4a bits, which is the only
|
||||
// mask at which the fill reads it at all.
|
||||
if (MG_Config::Transport == MG_Config::TransportMode::Monolith) {
|
||||
const MGPipeResourceOps* const savedOps = MGPipeGetResourceOps();
|
||||
MGPipeResourceOps ops{};
|
||||
MGPipeFieldMask withConsumer{};
|
||||
MGPipeFieldMask withoutConsumer{};
|
||||
|
||||
// An EMPTY table is enough: the predicate only asks whether ONE IS REGISTERED, which is
|
||||
// how MG_Test/Pipe arms this subsystem everywhere else.
|
||||
MGPipeSetResourceOps(&ops);
|
||||
ASSERT_NE(MGPipeGetResourceOps(), nullptr)
|
||||
<< "the fixture did not move the signal it names, so this step observes nothing";
|
||||
for (SizeT i = 0; i < kMGPipeInputFieldCount; ++i) {
|
||||
if (MGPipeResidualFillSuppliesField(static_cast<MGPipeInputField>(i), kEverySubsystem,
|
||||
true, true)) {
|
||||
withConsumer.Words[i / 64] |= (Uint64{1} << (i % 64));
|
||||
}
|
||||
}
|
||||
|
||||
MGPipeSetResourceOps(nullptr);
|
||||
ASSERT_EQ(MGPipeGetResourceOps(), nullptr);
|
||||
for (SizeT i = 0; i < kMGPipeInputFieldCount; ++i) {
|
||||
if (MGPipeResidualFillSuppliesField(static_cast<MGPipeInputField>(i), kEverySubsystem,
|
||||
true, true)) {
|
||||
withoutConsumer.Words[i / 64] |= (Uint64{1} << (i % 64));
|
||||
}
|
||||
}
|
||||
MGPipeSetResourceOps(savedOps);
|
||||
|
||||
// THE NAMED ROW, both ways: GetFramebufferBindingSlot is emitted by set_framebuffer_state
|
||||
// and so rides the framebuffer family's consumer gate - and is pulled regardless, because
|
||||
// its storage is a BindingSlot<FramebufferObject> no payload can carry.
|
||||
EXPECT_FALSE(MGPipeFieldMaskHas(withConsumer, MGPipeInputField::GetFramebufferBindingSlot));
|
||||
EXPECT_FALSE(
|
||||
MGPipeFieldMaskHas(withoutConsumer, MGPipeInputField::GetFramebufferBindingSlot));
|
||||
|
||||
for (SizeT i = 0; i < kMGPipeInputFieldCount; ++i) {
|
||||
const auto field = static_cast<MGPipeInputField>(i);
|
||||
EXPECT_EQ(MGPipeFieldMaskHas(withConsumer, field),
|
||||
MGPipeFieldMaskHas(withoutConsumer, field))
|
||||
<< kMGPipeInputFieldNames[i]
|
||||
<< "'s supplied answer moved with the P4a consumer signal. That is CORRECT "
|
||||
"behaviour and this assertion is a trip wire, not a defect report: the "
|
||||
"conjunct stopped being dominated, so the memo's fourth key input is now "
|
||||
"observable and needs the move-it-and-read-it-back pair steps 1-3 give the "
|
||||
"other three - under split through CapsMirrorInstance().Adopt() with and "
|
||||
"without kMGPipeSubsystemResources in the CallMask, as "
|
||||
"SanityTest.ACapsMaskWithoutTheResourceFamilyEmitsNothingAndCountsTheRefusal "
|
||||
"already does. Rewrite this step into that pair; PipeFill.cpp's "
|
||||
"NoP4aFamilyFieldIsWhollySupplied() static_assert fires on the same change";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if MOBILEGL_BUILD_DISAGGREGATED
|
||||
|
||||
TEST_F(FieldOwnershipTest, AServerStampMakesRecordSuppliedFieldsFreshAndWithdrawsTheRest) {
|
||||
@@ -613,8 +734,13 @@ TEST_F(FieldOwnershipTest, StrictErrorsTurnsABarrierPulledReadIntoANamedAbort) {
|
||||
EXPECT_NE(r.Log.find("BARRIER-PULLED"), std::string::npos) << r.Log;
|
||||
EXPECT_NE(r.Log.find("MOBILEGL_IPC_STRICT_ERRORS=1"), std::string::npos) << r.Log;
|
||||
// The strict line names the phase that owes the answer; a strict abort that did not would
|
||||
// leave the reader exactly where the gate found them.
|
||||
EXPECT_NE(r.Log.find("retires in P8]"), std::string::npos) << r.Log;
|
||||
// leave the reader exactly where the gate found them. P5e re-annotated this row (and the
|
||||
// five object-class rows beside it) from "P8" to the phase that actually retires the pull,
|
||||
// which is why the expected text moved with FieldOwnership.def rather than the case being
|
||||
// re-pointed at another field: the string IS the debt entry, read out of the generated
|
||||
// table, and a case that stopped checking it would let the annotation rot.
|
||||
EXPECT_NE(r.Log.find("retires in P5e (Espryt unbarriered), P7 (Magma)]"), std::string::npos)
|
||||
<< r.Log;
|
||||
}
|
||||
|
||||
TEST_F(FieldOwnershipTest, TheSameReadWithoutStrictErrorsSurvivesAndIsCounted) {
|
||||
|
||||
@@ -242,7 +242,9 @@ TEST(FramebufferEmit, TheEmitterIsOneNeverDestroyedProcessSingleton) {
|
||||
X(FramebufferEmit, ADrawBufferTokenAboveTheWireWidthIsRefusedNotTruncated) \
|
||||
X(FramebufferEmit, ALayeredCubeAttachmentDoesNotAssertAFaceItCannotKnow) \
|
||||
X(FramebufferEmit, EveryNonTexturePointCarriesTheUnknownSentinelsRatherThanZero) \
|
||||
X(FramebufferEmit, ADeadFramebuffersNamedRecordLatchIsRetired)
|
||||
X(FramebufferEmit, ADeadFramebuffersNamedRecordLatchIsRetired) \
|
||||
X(FramebufferEmit, TheRecordsElevenSurfacesAreTheWholePointSetTheServerReads) \
|
||||
X(FramebufferEmit, ADefaultFramebufferResizeReEmitsTheRecordWithItsNewExtent)
|
||||
|
||||
#define MGL_DECLARE_PULL_SKIP(Suite, Name) \
|
||||
TEST(Suite, Name) { GTEST_SKIP() << "compiled only under MOBILEGL_PIPE_PUSH"; }
|
||||
@@ -579,6 +581,130 @@ TEST(FramebufferEmit, AnAttachmentPointAboveTheWireWidthIsRefusedNotTruncated) {
|
||||
EXPECT_GE(Framebuffers().RefusedCount(), 1u) << "the refusal was not counted";
|
||||
}
|
||||
|
||||
// ============================ P5e (fb), CONTRACT-P5E.md §5.4 ============================
|
||||
//
|
||||
// THE SERVER TWIN of AnAttachmentPointAboveTheWireWidthIsRefusedNotTruncated above.
|
||||
//
|
||||
// That case pins the CLIENT half: a framebuffer holding a point at or above the wire width is
|
||||
// refused rather than truncated. P5e turns that refusal into a licence the server SPENDS - the
|
||||
// by-handle attachment walk stopped iterating the frontend's 41 points and now walks
|
||||
// Color[0..7] + Depth + Stencil and nothing else, on the argument that the record's eleven
|
||||
// surfaces ARE the point set. So the statement the server relies on needs a case of its own,
|
||||
// and it has two halves:
|
||||
//
|
||||
// 1. a framebuffer that fills every point the wire can describe round-trips ALL of them into
|
||||
// the applier's record - so "eleven" is not eleven minus whatever the emitter dropped;
|
||||
// 2. when a point above the width appears, the record the server is holding does not change
|
||||
// at all. The refusal is not merely counted: the server keeps describing the framebuffer
|
||||
// as it last legally was, rather than a truncated version of what it now is.
|
||||
//
|
||||
// Half 2 is the one that would go quiet on its own. A truncating emitter would still refuse
|
||||
// nothing, publish a record, and leave the server's walk perfectly self-consistent over eight
|
||||
// colour points while one attachment silently stopped existing.
|
||||
TEST(FramebufferEmit, TheRecordsElevenSurfacesAreTheWholePointSetTheServerReads) {
|
||||
FramebufferScope scope;
|
||||
const auto fbo = MakeShared<FramebufferObject>(21);
|
||||
Vector<SharedPtr<TextureObject2D>> colors;
|
||||
for (Uint i = 0; i < kMGPipeMaxColorAttachments; ++i) {
|
||||
colors.push_back(MakeColorTexture(70 + i, 32));
|
||||
fbo->AttachTexture(static_cast<FramebufferAttachmentType>(
|
||||
static_cast<Int>(FramebufferAttachmentType::Color0) + static_cast<Int>(i)),
|
||||
colors.back(), TextureUploadTarget::Texture2D);
|
||||
}
|
||||
const auto depth = MakeShared<RenderbufferObject>(21);
|
||||
depth->SetInternalFormat(TextureInternalFormat::Depth24Stencil8);
|
||||
depth->AllocateStorage(IntVec2{32, 32});
|
||||
fbo->AttachRenderbuffer(FramebufferAttachmentType::Depth, depth);
|
||||
const auto stencil = MakeShared<RenderbufferObject>(22);
|
||||
stencil->SetInternalFormat(TextureInternalFormat::Depth24Stencil8);
|
||||
stencil->AllocateStorage(IntVec2{32, 32});
|
||||
fbo->AttachRenderbuffer(FramebufferAttachmentType::Stencil, stencil);
|
||||
BindDrawAndRead(fbo, fbo);
|
||||
Framebuffers().EmitFramebufferState(Ctx());
|
||||
ASSERT_EQ(Framebuffers().RefusedCount(), 0u) << "a full but legal framebuffer was refused";
|
||||
|
||||
// The wire's colour width and the server's walk width are ONE number.
|
||||
static_assert(std::size(MGPFramebufferState{}.Color) == kMGPipeMaxColorAttachments,
|
||||
"the server walks Color[0..kMGPipeMaxColorAttachments); the array must be that wide");
|
||||
|
||||
const MGPFramebufferState* const applied = MGPipeApplier().DrawFramebuffer();
|
||||
ASSERT_NE(applied, nullptr);
|
||||
for (Uint i = 0; i < kMGPipeMaxColorAttachments; ++i) {
|
||||
const MGPipeHandle expected =
|
||||
MGPipeSlots().FindByLifetimeId(MGPipeKind::Texture, colors[i]->GetLifetimeId());
|
||||
EXPECT_FALSE(MGPipeHandleIsNull(expected)) << "colour point " << i << " minted no handle";
|
||||
EXPECT_TRUE(applied->Color[i].Res == expected)
|
||||
<< "colour point " << i << " did not reach the server's record";
|
||||
EXPECT_EQ(applied->Color[i].Kind, kMGPipeSurfaceKindTexture) << "at colour point " << i;
|
||||
}
|
||||
EXPECT_EQ(applied->Depth.Kind, kMGPipeSurfaceKindRenderbuffer) << "the Depth point";
|
||||
EXPECT_EQ(applied->Stencil.Kind, kMGPipeSurfaceKindRenderbuffer) << "the Stencil point";
|
||||
|
||||
// HALF 2. A point the wire cannot describe appears; the record the server holds must not
|
||||
// move, because a moved one would be a description of a framebuffer that does not exist.
|
||||
const Uint64 hashBefore = applied->ContentHash;
|
||||
const Uint64 serialBefore = MGPipeApplier().FramebufferSerial;
|
||||
const auto beyond = MakeColorTexture(90, 32);
|
||||
fbo->AttachTexture(static_cast<FramebufferAttachmentType>(
|
||||
static_cast<Int>(FramebufferAttachmentType::Color0) +
|
||||
static_cast<Int>(kMGPipeMaxColorAttachments)),
|
||||
beyond, TextureUploadTarget::Texture2D);
|
||||
Framebuffers().EmitFramebufferState(Ctx());
|
||||
EXPECT_GE(Framebuffers().RefusedCount(), 1u) << "the over-wide framebuffer was not refused";
|
||||
const MGPFramebufferState* const after = MGPipeApplier().DrawFramebuffer();
|
||||
ASSERT_NE(after, nullptr);
|
||||
EXPECT_EQ(after->ContentHash, hashBefore)
|
||||
<< "a refused framebuffer still moved the record the server walks - the eleven surfaces "
|
||||
"are no longer the whole point set";
|
||||
EXPECT_EQ(MGPipeApplier().FramebufferSerial, serialBefore)
|
||||
<< "a refused framebuffer advanced FramebufferSerial, which is the server's clean gate";
|
||||
}
|
||||
|
||||
// ============================ P5e (fb), ruling 15 / ID-98's §5.4 note ====================
|
||||
//
|
||||
// AN EGL SURFACE RESIZE RE-EMITS THE DEFAULT FRAMEBUFFER'S RECORD, extent and all.
|
||||
//
|
||||
// S3 could not settle this and flagged it: FramebufferEmit's dirty rule is
|
||||
// m_anyAttachmentGeneration plus the object/slot version, and a resize that moved NEITHER would
|
||||
// be suppressed - leaving the server with the old extent and no other source for it, because
|
||||
// under run-ahead the frontend's is unreachable. The brief's ruling 15 verified the path
|
||||
// (ClientSession's surface-changed consumer -> TextureObjectBase::PipePublishLevelDescriptor ->
|
||||
// MGP_NOTE_AGGREGATE(FramebufferAttachment) -> the framebuffer shutter) and told fb to pin it.
|
||||
//
|
||||
// THE CASE DRIVES THE CONSUMER'S OWN CALL, not a synthetic bump: AllocateStorage on the colour
|
||||
// attachment at the new extent is literally what ClientSession does when the swapchain
|
||||
// publishes a new size. No rebind, no re-attach, no draw-buffer edit - which is exactly the
|
||||
// shape that would have been suppressed.
|
||||
TEST(FramebufferEmit, ADefaultFramebufferResizeReEmitsTheRecordWithItsNewExtent) {
|
||||
FramebufferScope scope;
|
||||
const auto color = MakeColorTexture(95, 64);
|
||||
const auto fbo = MakeShared<FramebufferObject>(22);
|
||||
fbo->AttachTexture(FramebufferAttachmentType::Color0, color, TextureUploadTarget::Texture2D);
|
||||
BindDrawAndRead(fbo, fbo);
|
||||
Framebuffers().EmitFramebufferState(Ctx());
|
||||
|
||||
const MGPFramebufferState* applied = MGPipeApplier().DrawFramebuffer();
|
||||
ASSERT_NE(applied, nullptr);
|
||||
ASSERT_EQ(applied->Width, 64u);
|
||||
ASSERT_EQ(applied->Height, 64u);
|
||||
const Uint64 hashBefore = applied->ContentHash;
|
||||
const Uint64 emissionsBefore = Framebuffers().EmissionCount();
|
||||
|
||||
// THE RESIZE, exactly as the surface-changed consumer performs it.
|
||||
color->AllocateStorage(TextureUploadTarget::Texture2D, 0,
|
||||
MipmapInput{IntVec3{128, 96, 1}, static_cast<SizeT>(128 * 96 * 4)});
|
||||
Framebuffers().EmitFramebufferState(Ctx());
|
||||
|
||||
EXPECT_GT(Framebuffers().EmissionCount(), emissionsBefore)
|
||||
<< "a resize of an attached surface published no framebuffer record - under run-ahead the "
|
||||
"server would keep the old extent and has no other source for it";
|
||||
applied = MGPipeApplier().DrawFramebuffer();
|
||||
ASSERT_NE(applied, nullptr);
|
||||
EXPECT_NE(applied->ContentHash, hashBefore) << "the resize did not move the record's content hash";
|
||||
EXPECT_EQ(applied->Width, 128u);
|
||||
EXPECT_EQ(applied->Height, 96u);
|
||||
}
|
||||
|
||||
// ============================ D-D2 ============================
|
||||
//
|
||||
// RED BEFORE THIS PACKAGE LANDED. RenderbufferObject's three storage setters bump no version
|
||||
|
||||
@@ -356,7 +356,9 @@ TEST(ImageEmit, AMakeCurrentClearsTheImageSetAndAdvancesItsSerial) {
|
||||
X(ImageEmit, AnAccessModeChangeAloneStillEmitsTheSet) \
|
||||
X(ImageEmit, AnInternalFormatChangeAloneStillEmitsTheSet) \
|
||||
X(ImageEmit, TheApplicationsFormatAndAccessTravelUnrecast) \
|
||||
X(ImageEmit, AnImageBoundTextureIsMarkedShaderImageBoundAtTheBind)
|
||||
X(ImageEmit, AnImageBoundTextureIsMarkedShaderImageBoundAtTheBind) \
|
||||
X(ImageEmit, TheBindFeedsTheImageUnitHighWaterMark) \
|
||||
X(ImageEmit, TheThreeAccessConstantsArePinnedOnBothSidesOfTheWire)
|
||||
|
||||
#define MGL_DECLARE_PULL_SKIP(Suite, Name) \
|
||||
TEST(Suite, Name) { GTEST_SKIP() << "compiled only under MOBILEGL_PIPE_PUSH"; }
|
||||
@@ -410,10 +412,12 @@ namespace {
|
||||
// binds an image pays one integer test per draw, taken BEFORE any hash and before any
|
||||
// 192-entry walk.
|
||||
//
|
||||
// The frontend has no image-unit high-water mark of its own - NoteUnitTouched is the
|
||||
// TEXTURE-unit path and glBindImageTexture does not reach it - so the window is derived
|
||||
// from the highest image unit the CURRENT PROGRAM names. A program with no image uniform
|
||||
// names none, and the set is not emitted at all.
|
||||
// The window is derived from the highest image unit the CURRENT PROGRAM names, and it stays
|
||||
// that way now that the frontend DOES keep an image-unit high-water mark (P5d round 3,
|
||||
// package C, TextureState::NoteImageUnitTouched): the mark answers "which units could hold a
|
||||
// binding", and this emitter's question is the narrower "which units could a shader READ".
|
||||
// A program with no image uniform names none, and the set is not emitted at all - even with
|
||||
// a texture sitting on unit 0, as below.
|
||||
TEST(ImageEmit, AZeroHighWaterMarkEmitsNothingWithoutHashing) {
|
||||
EmitterScope scope;
|
||||
static const char* kNoImages = R"(#version 430 core
|
||||
@@ -484,6 +488,87 @@ void main() { imageStore(img, ivec2(0), vec4(1.0)); }
|
||||
GL::UseProgram(0);
|
||||
}
|
||||
|
||||
// ============================ P5e, ruling 16 / ID-94 ============================
|
||||
//
|
||||
// THE THREE CONSTANTS, PINNED ON BOTH SIDES OF THE WIRE, in one case, because the whole of
|
||||
// ruling 16 is that they are ONE table and not two that happen to agree.
|
||||
//
|
||||
// Before P5e the client folded the three GL names into 0/1/2 in ImageEmit.h and the server
|
||||
// read MGPImageBinding::Access off the FRONTEND instead of decoding the byte, under a
|
||||
// comment saying the encoding "does not exist at the contract commit" - which was stale
|
||||
// when it was written. c0e moved the numbers into MG_Pipe/MGPipeValueTypes.h and fb made
|
||||
// the backend decode through them, so the failure this case exists to catch is the two
|
||||
// halves drifting: an encode that writes 1 for GL_WRITE_ONLY against a decode that reads 1
|
||||
// as GL_READ_WRITE is a `writeonly` image the shader can read back, and no pixel test on a
|
||||
// lockstep tree would see it because the frontend value was answering.
|
||||
//
|
||||
// 0 IS READ-ONLY AND THAT IS ASSERTED RATHER THAN ASSUMED: a zeroed MGPImageView must
|
||||
// decode to the most restrictive access, so a record that forgot to set the field can only
|
||||
// lose a write, never invent one.
|
||||
TEST(ImageEmit, TheThreeAccessConstantsArePinnedOnBothSidesOfTheWire) {
|
||||
// --- the numbers themselves -------------------------------------------------------
|
||||
EXPECT_EQ(kMGPipeImageAccessReadOnly, 0u);
|
||||
EXPECT_EQ(kMGPipeImageAccessWriteOnly, 1u);
|
||||
EXPECT_EQ(kMGPipeImageAccessReadWrite, 2u);
|
||||
EXPECT_EQ(static_cast<Uint8>(MGPipeImageAccess::Count), 3u);
|
||||
|
||||
// --- the CLIENT half: the encode names those enumerators, not literals -------------
|
||||
EXPECT_EQ(MGPipeEncodeImageAccess(GL_READ_ONLY), kMGPipeImageAccessReadOnly);
|
||||
EXPECT_EQ(MGPipeEncodeImageAccess(GL_WRITE_ONLY), kMGPipeImageAccessWriteOnly);
|
||||
EXPECT_EQ(MGPipeEncodeImageAccess(GL_READ_WRITE), kMGPipeImageAccessReadWrite);
|
||||
|
||||
// --- the SERVER half: the decode is the inverse, and only those three are valid -----
|
||||
EXPECT_TRUE(MGPipeImageAccessIsValid(kMGPipeImageAccessReadOnly));
|
||||
EXPECT_TRUE(MGPipeImageAccessIsValid(kMGPipeImageAccessWriteOnly));
|
||||
EXPECT_TRUE(MGPipeImageAccessIsValid(kMGPipeImageAccessReadWrite));
|
||||
EXPECT_FALSE(MGPipeImageAccessIsValid(3))
|
||||
<< "a fourth value must be Fatal{ProtocolCorruption, \"ImageView.Access\"} at the reader";
|
||||
EXPECT_EQ(MGPipeDecodeImageAccess(kMGPipeImageAccessReadOnly), MGPipeImageAccess::ReadOnly);
|
||||
EXPECT_EQ(MGPipeDecodeImageAccess(kMGPipeImageAccessWriteOnly), MGPipeImageAccess::WriteOnly);
|
||||
EXPECT_EQ(MGPipeDecodeImageAccess(kMGPipeImageAccessReadWrite), MGPipeImageAccess::ReadWrite);
|
||||
|
||||
// The two predicates the backend's writable-image set and the barrier plan ask with.
|
||||
EXPECT_TRUE(MGPipeImageAccessReads(MGPipeImageAccess::ReadOnly));
|
||||
EXPECT_FALSE(MGPipeImageAccessWrites(MGPipeImageAccess::ReadOnly));
|
||||
EXPECT_FALSE(MGPipeImageAccessReads(MGPipeImageAccess::WriteOnly));
|
||||
EXPECT_TRUE(MGPipeImageAccessWrites(MGPipeImageAccess::WriteOnly));
|
||||
EXPECT_TRUE(MGPipeImageAccessReads(MGPipeImageAccess::ReadWrite));
|
||||
EXPECT_TRUE(MGPipeImageAccessWrites(MGPipeImageAccess::ReadWrite));
|
||||
|
||||
// --- and the byte that actually crosses, for each of the three -------------------
|
||||
//
|
||||
// ROUND TRIP THROUGH A REAL BIND, not through the encode alone: what the case is about
|
||||
// is the value the SERVER will decode, and that is MGPImageView::Access as the emitter
|
||||
// wrote it.
|
||||
const struct {
|
||||
GLenum gl;
|
||||
Uint8 encoded;
|
||||
MGPipeImageAccess decoded;
|
||||
} kCases[] = {
|
||||
{GL_READ_ONLY, kMGPipeImageAccessReadOnly, MGPipeImageAccess::ReadOnly},
|
||||
{GL_WRITE_ONLY, kMGPipeImageAccessWriteOnly, MGPipeImageAccess::WriteOnly},
|
||||
{GL_READ_WRITE, kMGPipeImageAccessReadWrite, MGPipeImageAccess::ReadWrite},
|
||||
};
|
||||
for (const auto& c : kCases) {
|
||||
EmitterScope scope;
|
||||
const GLuint program = MakeComputeProgram(kImageCompute);
|
||||
GL::UseProgram(program);
|
||||
const GLuint texture = MakeImageTexture();
|
||||
GL::BindImageTexture(1, texture, 0, GL_FALSE, 0, c.gl, GL_RGBA8);
|
||||
Emitter().EmitShaderImages(Ctx());
|
||||
ASSERT_GE(Emitter().ImageSetCount(), 1u);
|
||||
ASSERT_GE(Emitter().LastShaderImages().Count, 2u);
|
||||
const MGPImageView& view = Emitter().LastImageViews()[1];
|
||||
EXPECT_EQ(view.Access, c.encoded)
|
||||
<< "glBindImageTexture(access=0x" << std::hex << static_cast<Uint>(c.gl) << std::dec
|
||||
<< ") did not travel as the shared constant";
|
||||
ASSERT_TRUE(MGPipeImageAccessIsValid(view.Access));
|
||||
EXPECT_EQ(MGPipeDecodeImageAccess(view.Access), c.decoded)
|
||||
<< "the server's decode does not invert the client's encode";
|
||||
GL::UseProgram(0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ImageEmit, AnAccessModeChangeAloneStillEmitsTheSet) {
|
||||
EmitterScope scope;
|
||||
const GLuint program = MakeComputeProgram(kImageCompute);
|
||||
@@ -562,6 +647,42 @@ void main() { imageStore(img, ivec2(0, 0), vec4(1.0)); }
|
||||
GL::UseProgram(0);
|
||||
GL::BindImageTexture(0, 0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);
|
||||
}
|
||||
|
||||
// P5d round 3, package C: glBindImageTexture IS THE PRODUCER OF THE IMAGE-UNIT HIGH-WATER
|
||||
// MARK, and this case is the reason a reader may bound a walk with it. The split client's
|
||||
// per-draw GPU-write sweep (MG_Remote/Client/GpuWritePending.cpp) stops at the mark instead
|
||||
// of walking all MAX_TEXTURE_IMAGE_UNITS units; drop the NoteImageUnitTouched call from
|
||||
// GL_Texture.cpp's BindImageTexture and this goes red here, where the entry point is, rather
|
||||
// than as a missed GPU write in a scenario nobody runs on a desktop lane.
|
||||
//
|
||||
// AND THE UNBIND HALF IS THE OTHER ASSERTION. The mark only ever grows: a binding that goes
|
||||
// away leaves it standing, so the walk stays an over-approximation of the units that hold a
|
||||
// binding - the one direction a conservative GPU-write set may fail in.
|
||||
TEST(ImageEmit, TheBindFeedsTheImageUnitHighWaterMark) {
|
||||
EmitterScope scope;
|
||||
const GLuint name = MakeImageTexture();
|
||||
// UNIT 1, LIKE EVERY OTHER CASE IN THIS FILE, and deliberately not a higher one:
|
||||
// BindImageTexture refuses `unit >= GetAdvertisedImageUnitCount()` before it reaches
|
||||
// either the slot or the mark, and that count comes from the backend's
|
||||
// DynamicParameters.MaxImageUnits - so a case that needs unit 4 fails on a lane whose
|
||||
// backend advertises fewer, for a reason that has nothing to do with the mark. Unit 1
|
||||
// still separates "the mark moved" from "the mark is trivially 0".
|
||||
constexpr Int kUnit = 1;
|
||||
GL::BindImageTexture(static_cast<GLuint>(kUnit), name, 0, GL_FALSE, 0, GL_WRITE_ONLY, GL_RGBA8);
|
||||
// And the bind is checked before the mark is, so a REFUSED bind says so rather than
|
||||
// reading as a missing NoteImageUnitTouched.
|
||||
ASSERT_TRUE(Ctx().GetImageTextureBinding(kUnit).Texture != nullptr)
|
||||
<< "glBindImageTexture did not take: this lane's backend advertises fewer than "
|
||||
<< (kUnit + 1) << " image units, so the case cannot observe the mark at all";
|
||||
EXPECT_GE(Ctx().GetMaxTouchedImageUnit(), kUnit)
|
||||
<< "glBindImageTexture did not move the image-unit high-water mark, so every reader "
|
||||
"that bounds a per-draw walk with it now walks past this binding";
|
||||
|
||||
GL::BindImageTexture(static_cast<GLuint>(kUnit), 0, 0, GL_FALSE, 0, GL_READ_ONLY, GL_RGBA8);
|
||||
EXPECT_GE(Ctx().GetMaxTouchedImageUnit(), kUnit)
|
||||
<< "the mark must not shrink on an unbind: a walk bounded by it has to stay an "
|
||||
"over-approximation";
|
||||
}
|
||||
} // namespace
|
||||
#endif // MOBILEGL_PIPE_PUSH
|
||||
|
||||
|
||||
@@ -56,7 +56,8 @@ namespace {
|
||||
X(MagmaPipeIdentityTest, AnIdleSlotIsRetiredAndReusedWithANewGeneration) \
|
||||
X(MagmaPipeIdentityTest, AReusedSlotDoesNotServeItsPredecessorsMemo) \
|
||||
X(MagmaPipeIdentityTest, TheAbaControlKnobServesTheStaleMemoAcrossAReusedSlot) \
|
||||
X(MagmaPipeIdentityTest, ALiveObjectKeepsItsSlotItsGenerationAndItsMemo)
|
||||
X(MagmaPipeIdentityTest, ALiveObjectKeepsItsSlotItsGenerationAndItsMemo) \
|
||||
X(MagmaPipeIdentityTest, AMagmaServerNeverPublishesTheRunAheadCapBit)
|
||||
|
||||
#define MGL_DECLARE_PULL_SKIP(Suite, Name) \
|
||||
TEST(Suite, Name) { GTEST_SKIP() << "compiled only under MOBILEGL_PIPE_PUSH"; }
|
||||
@@ -213,5 +214,48 @@ namespace {
|
||||
<< "a live object's memo was cleared without its slot changing owner";
|
||||
EXPECT_EQ(mint.Count(), 1u);
|
||||
}
|
||||
|
||||
// ---- P5e (MG_Remote/CONTRACT-P5E.md §1, §6, ruling 12) -------------------------------
|
||||
//
|
||||
// MAGMA DOES NOT RUN AHEAD, AND THIS IS WHERE THAT IS A TEST RATHER THAN A COMMENT.
|
||||
// kCapRunAheadApply is the client's whole permission to publish a record and move on: the
|
||||
// moment a server sets it, the apply thread promises it reads nothing of the client's. That
|
||||
// promise is FALSE for Magma for the whole of P5e - the four apply-thread allocator sites
|
||||
// inside MagmaP7AllocatorDebtScope are real debt P7 retires, and
|
||||
// MGPipeApplierCurrentRecordIsBarriered() answering true for every record on a server
|
||||
// without the bit is exactly what keeps them inside P5C's semantics and keeps rsp honest.
|
||||
//
|
||||
// The arm is a pure function precisely so this case can reach it: InitSplitRoles needs a
|
||||
// live session, a backend and a handshake, and none of those belong in a unit lane. RED
|
||||
// ONCE by making MGPipeRunAheadCapBitsFor answer for DirectVulkan too (the exact
|
||||
// perturbation the phase's red-once list names) - both EXPECTs below fail, by name.
|
||||
TEST_F(MagmaPipeIdentityTest, AMagmaServerNeverPublishesTheRunAheadCapBit) {
|
||||
// Whatever the integration constant says. `true` is what the P5e integration commit
|
||||
// will pass, so the Magma answer is pinned on BOTH sides of that flip and the case
|
||||
// does not quietly stop asserting anything the day the constant moves.
|
||||
EXPECT_EQ(MG_Pipe::MGPipeRunAheadCapBitsFor(BackendType::DirectVulkan, /*ready=*/false) &
|
||||
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply),
|
||||
0u);
|
||||
EXPECT_EQ(MG_Pipe::MGPipeRunAheadCapBitsFor(BackendType::DirectVulkan, /*ready=*/true) &
|
||||
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply),
|
||||
0u);
|
||||
|
||||
// And the Espryt half, so the case says what the arm IS and not only what it is not:
|
||||
// the bit is published for DirectGLES and ONLY once the integration commit flips
|
||||
// kMGPipeP5eRunAheadReady. Until then every P5e package lands with the wait rule inert.
|
||||
EXPECT_EQ(MG_Pipe::MGPipeRunAheadCapBitsFor(BackendType::DirectGLES, /*ready=*/false) &
|
||||
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply),
|
||||
0u);
|
||||
EXPECT_EQ(MG_Pipe::MGPipeRunAheadCapBitsFor(BackendType::DirectGLES, /*ready=*/true) &
|
||||
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply),
|
||||
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply));
|
||||
|
||||
// Bit 10 and nothing else: the arm contributes ONE bit, so a future editor cannot fold
|
||||
// an unrelated capability into it and have the two pins above still pass.
|
||||
EXPECT_EQ(MG_Pipe::MGPipeRunAheadCapBitsFor(BackendType::DirectGLES, /*ready=*/true),
|
||||
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply));
|
||||
static_assert(static_cast<Uint64>(MG_Pipe::kCapRunAheadApply) == (1ull << 10),
|
||||
"kCapRunAheadApply moved bit; CONTRACT-P5E table 0 names bit 10");
|
||||
}
|
||||
#endif // MOBILEGL_PIPE_PUSH
|
||||
} // namespace
|
||||
|
||||
@@ -65,8 +65,8 @@ TEST(PipeCatalogue, FrontendNeverTakesAnApplierAddress) {
|
||||
namespace {
|
||||
// Counting expansions of the catalogue. The Class parameter is a real enumerator, so a
|
||||
// per-class count is a constant expression too.
|
||||
#define MGP_COUNT_ONE(Name, Payload, Class, Flags) +1
|
||||
#define MGP_COUNT_CLASS(Name, Payload, Class, Flags) +((Class) == countedClass ? 1 : 0)
|
||||
#define MGP_COUNT_ONE(Name, Payload, Class, Flags, Wait) +1
|
||||
#define MGP_COUNT_CLASS(Name, Payload, Class, Flags, Wait) +((Class) == countedClass ? 1 : 0)
|
||||
|
||||
constexpr SizeT kExpandedCallCount = 0 MGP_CALL_LIST(MGP_COUNT_ONE);
|
||||
|
||||
@@ -77,13 +77,32 @@ namespace {
|
||||
|
||||
// Every payload named in the catalogue must be a memcpy-able POD, and so must every
|
||||
// payload the verify comparator knows about.
|
||||
#define MGP_ASSERT_CALL_PAYLOAD_POD(Name, Payload, Class, Flags) \
|
||||
#define MGP_ASSERT_CALL_PAYLOAD_POD(Name, Payload, Class, Flags, Wait) \
|
||||
static_assert(std::is_trivially_copyable_v<Payload>, #Name "'s payload " #Payload " is not trivially copyable");
|
||||
MGP_CALL_LIST(MGP_ASSERT_CALL_PAYLOAD_POD)
|
||||
|
||||
#define MGP_ASSERT_VERIFY_PAYLOAD_POD(Payload) \
|
||||
static_assert(std::is_trivially_copyable_v<Payload>, #Payload " is not trivially copyable");
|
||||
MGP_VERIFY_PAYLOAD_LIST(MGP_ASSERT_VERIFY_PAYLOAD_POD)
|
||||
|
||||
// The catalogue's own spelling of an opcode, for a failure message. The wire codec has one
|
||||
// of these and MG_Pipe may not reach it (MG_Remote is above this layer), so the table is
|
||||
// expanded from the catalogue here rather than a name being duplicated per EXPECT.
|
||||
#define MGP_CATALOGUE_NAME_ROW(Name, Payload, Class, Flags, Wait) #Name,
|
||||
constexpr const char* kCatalogueOpNames[] = {
|
||||
"<kInvalid>",
|
||||
MGP_CALL_LIST(MGP_CATALOGUE_NAME_ROW)
|
||||
};
|
||||
#undef MGP_CATALOGUE_NAME_ROW
|
||||
static_assert(sizeof(kCatalogueOpNames) / sizeof(kCatalogueOpNames[0]) ==
|
||||
static_cast<SizeT>(MGPWireOp::kOpCount),
|
||||
"the diagnostic name table and the opcode space disagree");
|
||||
|
||||
const char* WireOpNameForDiag(MGPWireOp op) {
|
||||
const SizeT index = static_cast<SizeT>(op);
|
||||
return index < static_cast<SizeT>(MGPWireOp::kOpCount) ? kCatalogueOpNames[index]
|
||||
: "<opcode out of range>";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// The handle is the whole object model. Eight bytes, a register pair, no padding.
|
||||
@@ -127,11 +146,12 @@ TEST(PipeCatalogue, GeneratedTablesHoldTheWholeCatalogue) {
|
||||
// The per-class counts PipeCalls.def documents in its header.
|
||||
// kScreen is 11 + P5c's applier_reset (MG_Remote/CONTRACT-P5C.md §5.1); kCtxObject is
|
||||
// 9 + P5c's object_death (§5.2), the framebuffer family's first wire delete opcode.
|
||||
// kCtxState is 17 + P5c rv's set_context_values (§5.3), the residual-value record.
|
||||
// kCtxState is 17 + P5c rv's set_context_values (§5.3), the residual-value record, + P5e's
|
||||
// set_program_bindings (MG_Remote/CONTRACT-P5E.md §1), the post-link binding record.
|
||||
EXPECT_EQ(ClassCount<kScreen>(), 12u);
|
||||
EXPECT_EQ(ClassCount<kCtxQuery>(), 8u);
|
||||
EXPECT_EQ(ClassCount<kCtxCso>(), 13u);
|
||||
EXPECT_EQ(ClassCount<kCtxState>(), 18u);
|
||||
EXPECT_EQ(ClassCount<kCtxState>(), 19u);
|
||||
EXPECT_EQ(ClassCount<kCtxObject>(), 10u);
|
||||
// 13 + the five P5b-appended verbs (MG_Remote/CONTRACT-P5B.md): bind_shader_image,
|
||||
// patch_parameter, bind_stream_output, set_storage_block_binding,
|
||||
@@ -143,12 +163,15 @@ TEST(PipeCatalogue, GeneratedTablesHoldTheWholeCatalogue) {
|
||||
// migrated, keep pulling" means (plan B section 4.1).
|
||||
//
|
||||
// UNTIL P5 R-17 THAT WAS EVERY ROW, and this case said so. It is now EXACTLY THE 41 ROWS WITH
|
||||
// NO MGPipeApply* ENTRY POINT (79 - the 38 that have one; the number was 34 at P5, 39 after
|
||||
// P5b's five sink-only verbs, and rv's set_context_values grew BOTH sides of the difference):
|
||||
// the other 38 have an applier, R-17 installs adapters over them,
|
||||
// NO BODIED MGPipeApply* ENTRY POINT (80 - the 39 that have one; the number was 34 at P5, 39
|
||||
// after P5b's five sink-only verbs, rv's set_context_values grew BOTH sides of the difference,
|
||||
// P5e's set_program_bindings grew the null side alone, and P5e's set_shader_buffers moved one
|
||||
// row from the null side to the other - sb gave it its applier, its adapter and its emitter in
|
||||
// one commit):
|
||||
// the other 39 have an applier, R-17 installs adapters over them,
|
||||
// and a null there would no longer mean "keep pulling" - `MG_Impl/Pipe`'s call sites go through
|
||||
// the thunks, so a null would mean "call through a null pointer". The number is asserted rather
|
||||
// than the emptiness, because "38 installed" and "41 still null" are the two halves of a
|
||||
// than the emptiness, because "39 installed" and "41 still null" are the two halves of a
|
||||
// partition and a case that checked only one of them would pass an installer that had
|
||||
// overwritten rows it does not own.
|
||||
// THE NAME IS KEPT, AND SO IS THE STATEMENT IT MAKES - only the ROWS it makes it about have
|
||||
@@ -161,13 +184,18 @@ TEST(PipeCatalogue, UninstalledTablesAreAllNull) {
|
||||
const void* const* context = reinterpret_cast<const void* const*>(&gMGPipeContext);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
MGPipeInstallMonolithTables();
|
||||
// The 41 rows with no MGPipeApply* entry point are still null, and null still means "this
|
||||
// The 41 rows with no MGPipeApply* body are still null, and null still means "this
|
||||
// subsystem has not been migrated, keep pulling". Named rather than counted, because the
|
||||
// count is the other case's job and two cases asserting the same number would both go red
|
||||
// for one change. P5c's two control records are among them by design (CONTRACT-P5C.md §5:
|
||||
// no MGPipeApply* entry point, no monolith producer - under a transport they reach
|
||||
// WireVerbSink instead).
|
||||
EXPECT_EQ(gMGPipeContext.SetShaderBuffers, nullptr);
|
||||
//
|
||||
// P5e (sb): SetShaderBuffers HAS LEFT THIS LIST and the inversion is itself the proof the
|
||||
// route landed - the row was pinned null "since P4a" by two cases, and its applier, its
|
||||
// adapter and its emitter all arrive together. SetStreamOutputTargets stays, because XFB
|
||||
// stays lockstep for the whole of P5e (CONTRACT-P5E.md §5.7).
|
||||
EXPECT_NE(gMGPipeContext.SetShaderBuffers, nullptr);
|
||||
EXPECT_EQ(gMGPipeContext.SetStreamOutputTargets, nullptr);
|
||||
EXPECT_EQ(gMGPipeContext.DrawVbo, nullptr);
|
||||
EXPECT_EQ(gMGPipeContext.Present, nullptr);
|
||||
@@ -177,6 +205,10 @@ TEST(PipeCatalogue, UninstalledTablesAreAllNull) {
|
||||
EXPECT_EQ(gMGPipeScreen.FenceCreate, nullptr);
|
||||
EXPECT_EQ(gMGPipeScreen.ApplierReset, nullptr);
|
||||
EXPECT_EQ(gMGPipeContext.ObjectDeath, nullptr);
|
||||
// P5e's opcode 80 joins them: the row is catalogued, its codec layout is written and its
|
||||
// tails are validated, but there is no MGPipeApplySetProgramBindings and no route - package
|
||||
// pg installs both. A null here is the contract, not an omission.
|
||||
EXPECT_EQ(gMGPipeContext.SetProgramBindings, nullptr);
|
||||
#else
|
||||
// A pull build compiles no applier and no routing, so the pre-migration statement is the
|
||||
// whole truth there and this case is the one that says so.
|
||||
@@ -211,35 +243,49 @@ TEST(PipeCatalogue, ExactlyTheRoutedRowsAreInstalledAndTheRestAreStillNull) {
|
||||
EXPECT_EQ(installed + nulls, static_cast<SizeT>(kMGPipeCallCount));
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// 34 + 4 = 38, and the split is the honest shape of R-17 rather than an implementation
|
||||
// detail: 38 is the number of MGPipeApply* entry points PipeApply.h declares (37 at P5, and
|
||||
// P5c rv's set_context_values - CONTRACT-P5C.md §5.3 - is the 38th), 34 of them
|
||||
// fit a GENERATED row and go in the two tables, and FOUR cannot be expressed by any
|
||||
// generated signature and go in the hand-written escape table beside them
|
||||
// 35 + 5 = 40, and the split is the honest shape of R-17 rather than an implementation
|
||||
// detail: 40 is the number of MGPipeApply* entry points PipeApply.h declares WITH A BODY
|
||||
// (37 at P5, P5c rv's set_context_values was the 38th, P5e sb's set_shader_buffers is the
|
||||
// 39th and P5e pg's set_program_bindings the 40th - the two landed in parallel packages,
|
||||
// each of which read 38 as its base and wrote 39; this is the merge saying so), 35 of them
|
||||
// fit a GENERATED row and go in the two tables, and FIVE cannot be
|
||||
// expressed by any generated signature and go in the hand-written escape table beside them
|
||||
// (ResourceRespecify's uncarried initialBytes, ResourceFlushRange's likewise,
|
||||
// MapPersistent's size + seedBytes + void* return, CreateShaderState's seven blobrefs and
|
||||
// two typed pointers - each one a CONTRACT-P5 ruling, see MG_Pipe/PipeRoute.h).
|
||||
//
|
||||
// set_program_bindings (opcode 80) HAS its body since package pg, and it is the fifth
|
||||
// escape rather than a generated row; its `gMGPipeContext` slot therefore stays null and is
|
||||
// pinned null below, which is what an escaped row looks like here.
|
||||
//
|
||||
// BOTH NUMBERS ARE ASSERTED. If the escape table were left out of this case, moving a row
|
||||
// out of the generated tables and forgetting to install its escape would read as a smaller
|
||||
// "installed" count and nothing else - and the call site would take a null.
|
||||
EXPECT_EQ(installed, 34u) << "the routed rows and the applier's entry points disagree";
|
||||
EXPECT_EQ(nulls, static_cast<SizeT>(kMGPipeCallCount) - 34u);
|
||||
EXPECT_EQ(installed, 35u) << "the routed rows and the applier's entry points disagree";
|
||||
EXPECT_EQ(nulls, static_cast<SizeT>(kMGPipeCallCount) - 35u);
|
||||
const void* const* escapes = reinterpret_cast<const void* const*>(&gMGPipeRouteEscapes);
|
||||
SizeT escapesInstalled = 0;
|
||||
for (SizeT i = 0; i < sizeof(MGPipeRouteEscapes) / sizeof(void*); ++i) {
|
||||
if (escapes[i] != nullptr) ++escapesInstalled;
|
||||
}
|
||||
EXPECT_EQ(escapesInstalled, 4u) << "an escape row is null; its call site would take a null "
|
||||
// P5e (pg) MADE IT FIVE: set_program_bindings carries three tails in three index spaces
|
||||
// plus a parallel name array, which no generated (payload, varTail, varTailCount) row can
|
||||
// express - so opcode 80's `gMGPipeContext` slot stays null (pinned below, unchanged) and
|
||||
// its adapter lives in the escape table beside create_shader_state's. The applier's entry
|
||||
// points are 40 with it and with sb's generated row.
|
||||
EXPECT_EQ(escapesInstalled, 5u) << "an escape row is null; its call site would take a null "
|
||||
"pointer rather than fall back to anything";
|
||||
EXPECT_EQ(installed + escapesInstalled, 38u)
|
||||
<< "the two tables plus the escapes must be exactly PipeApply.h's entry points";
|
||||
EXPECT_EQ(installed + escapesInstalled, 40u)
|
||||
<< "the two tables plus the escapes must be exactly PipeApply.h's bodied entry points";
|
||||
|
||||
// And the rows that MUST still be null, named rather than counted: these are calls with no
|
||||
// applier at all (CONTRACT-P5 table 1 rows 13, 14: "no applier entry point exists"), plus
|
||||
// the two verbs the census measured as having zero MG_Impl call sites. An installer that
|
||||
// filled one of these would be claiming an implementation that does not exist.
|
||||
EXPECT_EQ(gMGPipeContext.SetShaderBuffers, nullptr);
|
||||
//
|
||||
// P5e (sb): row 13 (set_shader_buffers) is no longer one of them - see the sibling case
|
||||
// above. Row 14 (set_stream_output_targets) still is.
|
||||
EXPECT_NE(gMGPipeContext.SetShaderBuffers, nullptr);
|
||||
EXPECT_EQ(gMGPipeContext.SetStreamOutputTargets, nullptr);
|
||||
EXPECT_EQ(gMGPipeContext.DrawVbo, nullptr);
|
||||
EXPECT_EQ(gMGPipeContext.Present, nullptr);
|
||||
@@ -251,6 +297,9 @@ TEST(PipeCatalogue, ExactlyTheRoutedRowsAreInstalledAndTheRestAreStillNull) {
|
||||
// notice's mailbox are the producers, byte for byte as before (G1/G2).
|
||||
EXPECT_EQ(gMGPipeScreen.ApplierReset, nullptr);
|
||||
EXPECT_EQ(gMGPipeContext.ObjectDeath, nullptr);
|
||||
// P5e's set_program_bindings (CONTRACT-P5E.md §1): catalogued with a null route until pg
|
||||
// installs the applier entry point and the adapter beside it.
|
||||
EXPECT_EQ(gMGPipeContext.SetProgramBindings, nullptr);
|
||||
#else
|
||||
// A pull build compiles no applier and no routing, so the pre-migration statement is still
|
||||
// the whole truth there.
|
||||
@@ -584,7 +633,14 @@ TEST(PipeCatalogue, LateArrivalsAreAppendedWithoutRenumbering) {
|
||||
// - fixed POD, no blob, no tail, no reply - with an MGPipeApply* entry point, which the two
|
||||
// control records deliberately do not have.
|
||||
EXPECT_EQ(static_cast<Uint16>(MGPWireOp::SetContextValues), 79);
|
||||
EXPECT_EQ(static_cast<Uint16>(MGPWireOp::kOpCount), 80);
|
||||
// P5e (MG_Remote/CONTRACT-P5E.md §1) appended ONE more, by the same rule: opcode 80, and
|
||||
// nothing before it moved. set_program_bindings is a kCtxState row with THREE tails and a
|
||||
// host span in the third; it lands with a null route and a sink that refuses it by name,
|
||||
// exactly as set_shader_buffers has sat catalogued-and-dead since P4a.
|
||||
EXPECT_EQ(static_cast<Uint16>(MGPWireOp::SetProgramBindings), 80);
|
||||
EXPECT_EQ(static_cast<Uint16>(MGPWireOp::kOpCount), 81);
|
||||
EXPECT_EQ(MGPipeCallFlagsFor(MGPWireOp::SetProgramBindings),
|
||||
static_cast<Uint32>(kVarTail | kHostSpan));
|
||||
EXPECT_EQ(MGPipeCallFlagsFor(MGPWireOp::ApplierReset), static_cast<Uint32>(kNone));
|
||||
EXPECT_EQ(MGPipeCallFlagsFor(MGPWireOp::ObjectDeath), static_cast<Uint32>(kNone));
|
||||
EXPECT_EQ(MGPipeCallFlagsFor(MGPWireOp::SetContextValues), static_cast<Uint32>(kNone));
|
||||
@@ -618,9 +674,44 @@ TEST(PipeCatalogue, LateArrivalsAreAppendedWithoutRenumbering) {
|
||||
EXPECT_EQ(sizeof(MGPContextValues::TouchedBufferBindingPointCount), 60u);
|
||||
EXPECT_EQ(sizeof(MGPAttribValue), 56u);
|
||||
EXPECT_EQ(sizeof(MGPVertexAttribDefaults), 8u);
|
||||
// P5e's payloads (CONTRACT-P5E.md §1), pinned at runtime like every other MGP_ASSERT_POD.
|
||||
//
|
||||
// MGPProgramDesc GREW 192 -> 200, and that is the phase's one wire-format widening: the
|
||||
// descriptor's four trailing Uint8s end exactly at offset 24 and MGPBlobRef is 8-aligned,
|
||||
// so there was no spare byte for LinkStatus and the draft's "in the descriptor's existing
|
||||
// pad" was wrong. Pinned here, by value, because a record whose size moved silently is a
|
||||
// protocol break no other test would see - and because THIS number is the red-once the
|
||||
// phase names: change MGPProgramBindings' or the descriptor's size and this case fails.
|
||||
EXPECT_EQ(sizeof(MGPProgramDesc), 200u);
|
||||
EXPECT_EQ(sizeof(MGPProgramBindings), 32u);
|
||||
EXPECT_EQ(sizeof(MGPProgramSamplerUnit), 8u);
|
||||
EXPECT_EQ(sizeof(MGPProgramStorageOverride), 40u);
|
||||
// The three declared tail bounds. A program past one of them is a COUNTED REFUSAL and never
|
||||
// a truncation, so the numbers are the contract rather than an implementation detail.
|
||||
EXPECT_EQ(kMGPipeMaxProgramBlockBindings, 64u);
|
||||
EXPECT_EQ(kMGPipeMaxProgramSamplerUnits, 256u);
|
||||
EXPECT_EQ(kMGPipeMaxProgramStorageOverrides, 64u);
|
||||
// LinkStatus is a real byte and a zeroed descriptor means "not linked", which is what makes
|
||||
// the server's decline the safe default.
|
||||
MGPProgramDesc program{};
|
||||
EXPECT_EQ(program.LinkStatus, 0u);
|
||||
// set_shader_buffers' capacity, pinned on the wire side; MG_Impl/Pipe/PipeFill.cpp is the
|
||||
// one translation unit that also sees BufferState.h's constant and pins them together.
|
||||
EXPECT_EQ(kMGPipeMaxBufferBindingPoints, 84u);
|
||||
// The two draw-flag bits P5b's d1 arms are exclusive by contract and distinct by value.
|
||||
EXPECT_EQ(static_cast<Uint32>(kDrawIsIndirect), 1u << 5);
|
||||
EXPECT_EQ(static_cast<Uint32>(kDrawHasUserIndices) & static_cast<Uint32>(kDrawIsIndirect), 0u);
|
||||
// P5e's draw flag: the next free bit, and disjoint from all five before it.
|
||||
EXPECT_EQ(static_cast<Uint32>(kDrawClientArrays), 1u << 6);
|
||||
EXPECT_EQ(static_cast<Uint32>(kDrawClientArrays) &
|
||||
static_cast<Uint32>(kDrawHasUserIndices | kDrawPrimitiveRestart |
|
||||
kDrawIndicesAreClient | kDrawHasIndexRange |
|
||||
kDrawHasXfbCount | kDrawIsIndirect),
|
||||
0u);
|
||||
// ... and it still fits the one byte MGPDrawInfo::Flags is, which is why the record did not
|
||||
// grow: MGPDrawInfo stays 56 bytes.
|
||||
EXPECT_EQ(sizeof(MGPDrawInfo), 56u);
|
||||
EXPECT_LE(static_cast<Uint32>(kDrawClientArrays), 0xFFu);
|
||||
// The clear discriminants have ONE spelling now, and Whole is 0 so a zeroed record is a
|
||||
// whole-framebuffer clear.
|
||||
EXPECT_EQ(kMGPipeClearKindWhole, 0u);
|
||||
@@ -628,6 +719,107 @@ TEST(PipeCatalogue, LateArrivalsAreAppendedWithoutRenumbering) {
|
||||
EXPECT_EQ(kMGPipeClearValueClassUint + 1, kMGPipeClearValueClassCount);
|
||||
}
|
||||
|
||||
// ---- P5e: the wait-class column (MG_Remote/CONTRACT-P5E.md §2.2) --------------------------
|
||||
//
|
||||
// THE POINT OF THIS CASE IS THAT IT DOES NOT READ PipeCalls.def. Every other statement about
|
||||
// the column - the generated table, the two gates in gen_pipe.py, the static_asserts in
|
||||
// PipeWire.inc - is derived from the def, so all of them move together when a row is edited.
|
||||
// This case re-states CONTRACT-P5E §2.2's table BY NAME, in the contract's own grouping, so a
|
||||
// row silently moved from kWaitApplied to kWaitNone has to be argued in two places or it goes
|
||||
// red here. That is the difference between a table and a contract.
|
||||
//
|
||||
// It matters because the column is not decoration: on a run-ahead server kWaitNone is a promise
|
||||
// that the record's apply reads NOTHING of the client's (rule F), and a row demoted to it by
|
||||
// accident is a torn read that renders wrong rather than aborting.
|
||||
TEST(PipeCatalogue, EveryRowCarriesTheWaitClassTheContractGivesIt) {
|
||||
// kWaitPresent: present alone, paced by the credit taken BEFORE the encode (§2.4).
|
||||
EXPECT_EQ(MGPipeWaitClassFor(MGPWireOp::Present), kWaitPresent);
|
||||
|
||||
// kWaitReply: every row whose answer is not derivable (R-5). Named, all fourteen, because
|
||||
// the flag-to-class agreement is what keeps a waiter from hanging on a slot nobody posts.
|
||||
const MGPWireOp replyRows[] = {
|
||||
MGPWireOp::GetCaps, MGPWireOp::ResourceCreate, MGPWireOp::ResourceRespecify,
|
||||
MGPWireOp::MapPersistent, MGPWireOp::FenceStatus, MGPWireOp::FenceWait,
|
||||
MGPWireOp::QueryAvailable, MGPWireOp::QueryResult, MGPWireOp::QueryTimestamp,
|
||||
MGPWireOp::SetTextureParams, MGPWireOp::ResourceSubData, MGPWireOp::ResourceReadback,
|
||||
MGPWireOp::GetTextureImage, MGPWireOp::ReadPixels,
|
||||
};
|
||||
for (const MGPWireOp op : replyRows) {
|
||||
EXPECT_EQ(MGPipeWaitClassFor(op), kWaitReply) << WireOpNameForDiag(op);
|
||||
EXPECT_NE(MGPipeCallFlagsFor(op) & static_cast<Uint32>(kReplySlot), 0u)
|
||||
<< WireOpNameForDiag(op);
|
||||
}
|
||||
|
||||
// kWaitApplied: the rows whose apply STILL reads a BARRIER_PULLED row or probes the client
|
||||
// allocator, so the client parks in its own wait and CONTRACT-P5C's semantics hold for them
|
||||
// unchanged - their pulls count into rsp and their probes are legal inside a scope. Two of
|
||||
// them are trailing items and are expected to leave this list in a later package:
|
||||
// generate_mipmap the moment tx2 resolves the texture from VerbMipRes instead of the active
|
||||
// unit, and set_storage_block_binding the moment pg resolves it through
|
||||
// MGPStorageBlockBinding::ShaderCso. When they do, THIS list is what has to be edited.
|
||||
const MGPWireOp appliedRows[] = {
|
||||
MGPWireOp::ApplierReset, MGPWireOp::GenerateMipmap,
|
||||
MGPWireOp::SetStorageBlockBinding, MGPWireOp::BeginStreamOutput,
|
||||
MGPWireOp::EndStreamOutput, MGPWireOp::PauseStreamOutput,
|
||||
MGPWireOp::ResumeStreamOutput, MGPWireOp::BindStreamOutput,
|
||||
MGPWireOp::CopyFramebufferToTexture,
|
||||
};
|
||||
for (const MGPWireOp op : appliedRows) {
|
||||
EXPECT_EQ(MGPipeWaitClassFor(op), kWaitApplied) << WireOpNameForDiag(op);
|
||||
}
|
||||
|
||||
// kWaitNone: the steady draw path and every state/CSO/object row without a reply. Named for
|
||||
// the rows the phase exists for, and then counted for the rest, so a new row cannot join
|
||||
// the set unnoticed.
|
||||
const MGPWireOp noneRows[] = {
|
||||
MGPWireOp::DrawVbo, MGPWireOp::LaunchGrid, MGPWireOp::Clear,
|
||||
MGPWireOp::Blit, MGPWireOp::MemoryBarrier, MGPWireOp::Flush,
|
||||
MGPWireOp::SetSwapInterval, MGPWireOp::BindShaderImage, MGPWireOp::PatchParameter,
|
||||
MGPWireOp::ObjectDeath, MGPWireOp::ResourceDestroy, MGPWireOp::UnmapPersistent,
|
||||
MGPWireOp::FenceCreate, MGPWireOp::FenceDestroy, MGPWireOp::FenceWaitServer,
|
||||
MGPWireOp::QueryCreate, MGPWireOp::QueryBegin, MGPWireOp::QueryEnd,
|
||||
MGPWireOp::QueryDestroy, MGPWireOp::QueryCounter, MGPWireOp::SetContextValues,
|
||||
MGPWireOp::SetProgramBindings, MGPWireOp::SetShaderBuffers,
|
||||
MGPWireOp::SetVertexBuffers, MGPWireOp::SetFramebufferState,
|
||||
MGPWireOp::CreateShaderState, MGPWireOp::SetDrawProgram,
|
||||
};
|
||||
for (const MGPWireOp op : noneRows) {
|
||||
EXPECT_EQ(MGPipeWaitClassFor(op), kWaitNone) << WireOpNameForDiag(op);
|
||||
}
|
||||
|
||||
// The partition, by count. 14 + 1 + 9 = 24 rows wait; every other row of the catalogue does
|
||||
// not. A row that changed class moves two of these numbers at once.
|
||||
SizeT reply = 0, applied = 0, present = 0, none = 0, other = 0;
|
||||
for (SizeT i = 1; i < static_cast<SizeT>(MGPWireOp::kOpCount); ++i) {
|
||||
switch (MGPipeWaitClassFor(static_cast<MGPWireOp>(i))) {
|
||||
case kWaitReply: ++reply; break;
|
||||
case kWaitApplied: ++applied; break;
|
||||
case kWaitPresent: ++present; break;
|
||||
case kWaitNone: ++none; break;
|
||||
default: ++other; break;
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(reply, 14u);
|
||||
EXPECT_EQ(applied, 9u);
|
||||
EXPECT_EQ(present, 1u);
|
||||
EXPECT_EQ(none, static_cast<SizeT>(kMGPipeCallCount) - 24u);
|
||||
EXPECT_EQ(other, 0u) << "a row carries the kWaitClassCount terminator as its class";
|
||||
|
||||
// And the reply half of the partition BOTH WAYS, over the whole catalogue: exactly the rows
|
||||
// that own a slot wait for one. gen_pipe.py refuses a catalogue where they disagree; this
|
||||
// is the same statement where a reader of the table will look for it.
|
||||
for (SizeT i = 1; i < static_cast<SizeT>(MGPWireOp::kOpCount); ++i) {
|
||||
const auto op = static_cast<MGPWireOp>(i);
|
||||
const Bool ownsSlot = (MGPipeCallFlagsFor(op) & static_cast<Uint32>(kReplySlot)) != 0;
|
||||
EXPECT_EQ(ownsSlot, MGPipeWaitClassFor(op) == kWaitReply) << WireOpNameForDiag(op);
|
||||
}
|
||||
|
||||
// Opcode 0 is not a call and has no class, for the flags table's reason: a decoder holding
|
||||
// a byte off a corrupt stream must reach its own Fatal rather than a wait decision.
|
||||
EXPECT_EQ(MGPipeWaitClassFor(MGPWireOp::kInvalid), kWaitClassCount);
|
||||
EXPECT_EQ(MGPipeWaitClassFor(MGPWireOp::kOpCount), kWaitClassCount);
|
||||
}
|
||||
|
||||
// A well-formed record passes the applier's bounds gate. P0 has no applier, so "accepted"
|
||||
// is reported as "not applied" rather than "fatal".
|
||||
TEST(PipeCatalogue, ApplierAcceptsAWellFormedRecord) {
|
||||
@@ -817,8 +1009,12 @@ TEST(PipeCatalogue, SixValueStructsHaveFieldLists) {
|
||||
// each with its own field list, so the comparator sees every one of them: 77. P5c appended
|
||||
// applier_reset's MGPApplierReset (CONTRACT-P5C.md §5.1) - object_death reuses
|
||||
// MGPHandleOnly, which has had a list since P0 - and rv added set_context_values'
|
||||
// MGPContextValues (§5.3): 79.
|
||||
EXPECT_EQ(kMGPipeVerifiedPayloadCount, 79u);
|
||||
// MGPContextValues (§5.3): 79. P5e appended set_program_bindings' MGPProgramBindings AND
|
||||
// the two TAIL ELEMENT types beside it, MGPProgramSamplerUnit and MGPProgramStorageOverride
|
||||
// (MG_Remote/CONTRACT-P5E.md §1) - the tails are listed for the same reason MGPBufferRange
|
||||
// and MGPVertexAttribWire are: the comparator has to see INTO an element whose members
|
||||
// include an MGHostSpan and a pad word, or it would memcmp the padding: 82.
|
||||
EXPECT_EQ(kMGPipeVerifiedPayloadCount, 82u);
|
||||
static_assert(MGPipeHasFieldVerifier<RenderStateParameters>::value);
|
||||
static_assert(MGPipeHasFieldVerifier<PixelStoreParameters>::value);
|
||||
static_assert(MGPipeHasFieldVerifier<PerBufferBlendState>::value);
|
||||
@@ -920,12 +1116,20 @@ TEST(PipeCatalogue, HostSpanResolvesTheMonolithPointer) {
|
||||
// ranges - the majority - pay nothing for a payload whose shape is not frozen yet.
|
||||
TEST(PipeCatalogue, BufferRangeCarriesNoInlineHostSpan) {
|
||||
static_assert(sizeof(MGPBufferRange) == 24);
|
||||
static_assert(sizeof(MGPShaderBuffers) == 32);
|
||||
// P5e (sb, ID-104): 32 -> 40. WritableMask was ONE Uint32 against an 84-point window, so
|
||||
// it could describe only the first 32 points and a storage buffer bound at point 32 or
|
||||
// above read as read-only with nothing able to see it. The ruling widens the FIELD rather
|
||||
// than narrowing the window - narrowing would change what an application may bind - and the
|
||||
// eight bytes are paid by a record that fires at most once per class per change, in a push
|
||||
// build only. The ABI fingerprint already moved this phase for opcode 80.
|
||||
static_assert(sizeof(MGPShaderBuffers) == 40);
|
||||
static_assert(sizeof(MGPShaderBuffers::WritableMask) * 8u >= kMGPipeMaxBufferBindingPoints,
|
||||
"the mask must cover the window the same record declares");
|
||||
EXPECT_LT(sizeof(MGPBufferRange), sizeof(MGHostSpan));
|
||||
|
||||
// The call still declares the span it may carry, so the transport lays the tail out.
|
||||
Uint32 flags = 0;
|
||||
#define MGP_FLAGS_OF_SET_SHADER_BUFFERS(Name, Payload, Class, Flags) \
|
||||
#define MGP_FLAGS_OF_SET_SHADER_BUFFERS(Name, Payload, Class, Flags, Wait) \
|
||||
if (std::strcmp(#Name, "SetShaderBuffers") == 0) flags = static_cast<Uint32>(Flags);
|
||||
MGP_CALL_LIST(MGP_FLAGS_OF_SET_SHADER_BUFFERS)
|
||||
#undef MGP_FLAGS_OF_SET_SHADER_BUFFERS
|
||||
@@ -939,6 +1143,21 @@ TEST(PipeCatalogue, BufferRangeCarriesNoInlineHostSpan) {
|
||||
b.HostSpanCount = 4;
|
||||
EXPECT_FALSE(MGPipeVerify(a, b, &field));
|
||||
EXPECT_STREQ(field, "HostSpanCount");
|
||||
|
||||
// P5e (sb, ID-104): THE COMPARATOR SEES EVERY WORD OF THE WIDENED MASK, and the HIGH one
|
||||
// is what the case is for. PipeFields.def names WritableMask once and the array overload
|
||||
// of MGPipeFieldEqual walks it, so this would have passed before the widening too - on the
|
||||
// 32 points that existed. Point 83 is the one the old field could not describe at all.
|
||||
b = a;
|
||||
ASSERT_TRUE(MGPipeVerify(a, b, &field));
|
||||
MGPipeShaderBufferMaskSet(b.WritableMask, kMGPipeMaxBufferBindingPoints - 1);
|
||||
EXPECT_TRUE(MGPipeShaderBufferMaskHas(b.WritableMask, kMGPipeMaxBufferBindingPoints - 1));
|
||||
EXPECT_FALSE(MGPipeShaderBufferMaskHas(a.WritableMask, kMGPipeMaxBufferBindingPoints - 1));
|
||||
EXPECT_FALSE(MGPipeVerify(a, b, &field));
|
||||
EXPECT_STREQ(field, "WritableMask");
|
||||
// And out of range is "not writable" / "write nothing" rather than a word past the end.
|
||||
MGPipeShaderBufferMaskSet(b.WritableMask, kMGPipeMaxBufferBindingPoints);
|
||||
EXPECT_FALSE(MGPipeShaderBufferMaskHas(b.WritableMask, kMGPipeMaxBufferBindingPoints));
|
||||
}
|
||||
|
||||
// The buffer half of resource_subdata has no level and no box of its own: [offset, size)
|
||||
@@ -1048,7 +1267,7 @@ TEST(PipeCatalogue, VertexWireViewsAreFlatAndCarryIsLongSeparately) {
|
||||
// inherits this pin rather than the guess.
|
||||
TEST(PipeCatalogue, ResourceRespecifyAcksOnlyImmutableStorage) {
|
||||
Uint32 flags = 0;
|
||||
#define MGP_FLAGS_OF_RESOURCE_RESPECIFY(Name, Payload, Class, Flags) \
|
||||
#define MGP_FLAGS_OF_RESOURCE_RESPECIFY(Name, Payload, Class, Flags, Wait) \
|
||||
if (std::strcmp(#Name, "ResourceRespecify") == 0) flags = static_cast<Uint32>(Flags);
|
||||
MGP_CALL_LIST(MGP_FLAGS_OF_RESOURCE_RESPECIFY)
|
||||
#undef MGP_FLAGS_OF_RESOURCE_RESPECIFY
|
||||
@@ -1056,7 +1275,7 @@ TEST(PipeCatalogue, ResourceRespecifyAcksOnlyImmutableStorage) {
|
||||
// And it is the ONLY call that carries it: a second one would be a second decision, and
|
||||
// this predicate answers for exactly one call.
|
||||
Uint32 ackingCalls = 0;
|
||||
#define MGP_COUNT_ACKING_CALLS(Name, Payload, Class, Flags) \
|
||||
#define MGP_COUNT_ACKING_CALLS(Name, Payload, Class, Flags, Wait) \
|
||||
if ((static_cast<Uint32>(Flags) & static_cast<Uint32>(kNeedsAck)) != 0) ++ackingCalls;
|
||||
MGP_CALL_LIST(MGP_COUNT_ACKING_CALLS)
|
||||
#undef MGP_COUNT_ACKING_CALLS
|
||||
@@ -1071,7 +1290,7 @@ TEST(PipeCatalogue, ResourceRespecifyAcksOnlyImmutableStorage) {
|
||||
// ROWS, whose applier entry points return a Bool the client acts on destructively and which
|
||||
// carried no flag because in monolith that answer is a direct call's return value.
|
||||
Uint32 replySlotCalls = 0;
|
||||
#define MGP_COUNT_REPLY_SLOT_CALLS(Name, Payload, Class, Flags) \
|
||||
#define MGP_COUNT_REPLY_SLOT_CALLS(Name, Payload, Class, Flags, Wait) \
|
||||
if ((static_cast<Uint32>(Flags) & static_cast<Uint32>(kReplySlot)) != 0) ++replySlotCalls;
|
||||
MGP_CALL_LIST(MGP_COUNT_REPLY_SLOT_CALLS)
|
||||
#undef MGP_COUNT_REPLY_SLOT_CALLS
|
||||
@@ -1082,7 +1301,7 @@ TEST(PipeCatalogue, ResourceRespecifyAcksOnlyImmutableStorage) {
|
||||
// (PipeApply.h:820, :868, :897, :1023); map_persistent's void* is the fifth answer and was
|
||||
// already declared.
|
||||
Uint32 acceptanceWithSlot = 0;
|
||||
#define MGP_COUNT_ACCEPTANCE_ROWS(Name, Payload, Class, Flags) \
|
||||
#define MGP_COUNT_ACCEPTANCE_ROWS(Name, Payload, Class, Flags, Wait) \
|
||||
if ((std::strcmp(#Name, "ResourceCreate") == 0 || std::strcmp(#Name, "ResourceRespecify") == 0 || \
|
||||
std::strcmp(#Name, "ResourceSubData") == 0 || std::strcmp(#Name, "SetTextureParams") == 0) && \
|
||||
(static_cast<Uint32>(Flags) & static_cast<Uint32>(kReplySlot)) != 0) { \
|
||||
|
||||
@@ -66,6 +66,9 @@
|
||||
// drives create_shader_state needs their definitions - the applier's own header deliberately
|
||||
// only forward-declares them.
|
||||
#include <MG_State/GLState/ProgramState/ProgramArtifacts.h>
|
||||
// P5e (pg): the FRAMED archive - ProgramArchive and the two frame entry points - is what
|
||||
// crosses under split, and the record holds one; the round-trip case below drives it directly.
|
||||
#include <MG_State/GLState/ProgramState/ProgramArtifactsCodec.h>
|
||||
#include <MG_State/GLState/Core.h>
|
||||
#endif
|
||||
|
||||
@@ -258,7 +261,7 @@ TEST(ProgramEmit, ACreateStoresTheDescriptorAndARelinkCountsUpAndDropsTheBlockKe
|
||||
const MGPipeHandle cso{5, 2};
|
||||
const Uint8 block[64] = {};
|
||||
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x3u, 64), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x3u, 64), &link, &spirv, nullptr);
|
||||
EXPECT_TRUE(ProgramRecordOf(5).Live);
|
||||
EXPECT_EQ(ProgramRecordOf(5).Gen, 2u);
|
||||
EXPECT_EQ(ProgramRecordOf(5).Serial, 0u) << "a create is not a mutation";
|
||||
@@ -274,7 +277,7 @@ TEST(ProgramEmit, ACreateStoresTheDescriptorAndARelinkCountsUpAndDropsTheBlockKe
|
||||
const Uint64 blockSerial = ProgramRecordOf(5).GlobalConstantsSerial;
|
||||
|
||||
// The relink.
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x7u, 32), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x7u, 32), &link, &spirv, nullptr);
|
||||
EXPECT_EQ(ProgramRecordOf(5).Serial, 1u);
|
||||
EXPECT_EQ(ProgramRecordOf(5).Desc.StageMask, 0x7u);
|
||||
EXPECT_TRUE(ProgramRecordOf(5).GlobalConstants.empty())
|
||||
@@ -285,7 +288,7 @@ TEST(ProgramEmit, ACreateStoresTheDescriptorAndARelinkCountsUpAndDropsTheBlockKe
|
||||
|
||||
// A RECYCLED SLOT STARTS OVER: inheriting one field of the previous occupant is how a
|
||||
// program at a recycled slot inherits its predecessor's reflection.
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(MGPipeHandle{5, 3}, 0x1u, 16), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(MGPipeHandle{5, 3}, 0x1u, 16), &link, &spirv, nullptr);
|
||||
EXPECT_EQ(ProgramRecordOf(5).Gen, 3u);
|
||||
EXPECT_EQ(ProgramRecordOf(5).Serial, 0u) << "a recycled slot kept its predecessor's serial";
|
||||
EXPECT_EQ(ProgramRecordOf(5).Desc.StageMask, 0x1u);
|
||||
@@ -305,23 +308,23 @@ TEST(ProgramEmit, ACreateWithNoArtefactsAnOversizedBlockOrACorruptSlotIsRefusedN
|
||||
const MGPProgramDesc desc = ProgramDesc(MGPipeHandle{4, 1}, 0x3u, 0);
|
||||
ExpectRefusedNaming("create_shader_state {slot=4, gen=1}: the record declares no blobs and carries no "
|
||||
"artefacts",
|
||||
[&desc, &spirv]() { MGPipeApplyCreateShaderState(desc, nullptr, &spirv); });
|
||||
[&desc, &spirv]() { MGPipeApplyCreateShaderState(desc, nullptr, &spirv, nullptr); });
|
||||
ExpectRefusedNaming("create_shader_state {slot=4, gen=1}: the record declares no blobs and carries no "
|
||||
"artefacts",
|
||||
[&desc, &link]() { MGPipeApplyCreateShaderState(desc, &link, nullptr); });
|
||||
[&desc, &link]() { MGPipeApplyCreateShaderState(desc, &link, nullptr, nullptr); });
|
||||
EXPECT_TRUE(MGPipeApplier().ShaderCsos.empty());
|
||||
|
||||
const MGPProgramDesc huge = ProgramDesc(MGPipeHandle{4, 1}, 0x3u, kMGPipeMaxGlobalConstantsBytes + 1);
|
||||
ExpectRefusedNaming("create_shader_state {slot=4, gen=1}: the default uniform block is larger than any "
|
||||
"program may declare",
|
||||
[&huge, &link, &spirv]() { MGPipeApplyCreateShaderState(huge, &link, &spirv); });
|
||||
[&huge, &link, &spirv]() { MGPipeApplyCreateShaderState(huge, &link, &spirv, nullptr); });
|
||||
EXPECT_TRUE(MGPipeApplier().ShaderCsos.empty()) << "the table was grown by a refused record";
|
||||
|
||||
const MGPProgramDesc pastTheBound = ProgramDesc(MGPipeHandle{kMGPipeMaxShaderCsoSlots, 1}, 0x3u, 0);
|
||||
ExpectRefusedNaming("create_shader_state {slot=1048576, gen=1}: the slot is outside the record table's "
|
||||
"bound",
|
||||
[&pastTheBound, &link, &spirv]() {
|
||||
MGPipeApplyCreateShaderState(pastTheBound, &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(pastTheBound, &link, &spirv, nullptr);
|
||||
});
|
||||
EXPECT_TRUE(MGPipeApplier().ShaderCsos.empty());
|
||||
EXPECT_TRUE(MGPipeApplier().CompositeShaderCsos.empty());
|
||||
@@ -340,8 +343,8 @@ TEST(ProgramEmit, TheThreeBindingsFollowTheirOwnHandleAndADeadOneLeavesThePrevio
|
||||
const SpirvArtifacts spirv;
|
||||
const MGPipeHandle draw{2, 1};
|
||||
const MGPipeHandle dispatch{3, 1};
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(draw, 0x3u, 0), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(dispatch, 0x20u, 0), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(draw, 0x3u, 0), &link, &spirv, nullptr);
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(dispatch, 0x20u, 0), &link, &spirv, nullptr);
|
||||
|
||||
const Uint64 serialBefore = MGPipeApplier().ProgramBindingSerial;
|
||||
MGPipeApplyBindShaderState(ProgramHandle(draw));
|
||||
@@ -383,7 +386,7 @@ TEST(ProgramEmit, ADeleteDropsTheRecordAndClearsEveryBindingThatNamedIt) {
|
||||
const LinkArtifacts link;
|
||||
const SpirvArtifacts spirv;
|
||||
const MGPipeHandle cso{6, 4};
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x3u, 0), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x3u, 0), &link, &spirv, nullptr);
|
||||
MGPipeApplyBindShaderState(ProgramHandle(cso));
|
||||
MGPipeApplySetDrawProgram(ProgramHandle(cso));
|
||||
MGPipeApplySetDispatchProgram(ProgramHandle(cso));
|
||||
@@ -420,7 +423,7 @@ TEST(ProgramEmit, TheDefaultUniformBlockLandsOnTheProgramsRecordAndTheSentinelIs
|
||||
const LinkArtifacts link;
|
||||
const SpirvArtifacts spirv;
|
||||
const MGPipeHandle cso{7, 1};
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x3u, 8), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x3u, 8), &link, &spirv, nullptr);
|
||||
|
||||
Uint8 block[8] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
MGPipeApplySetGlobalConstants(GlobalConstants(cso, 11), block);
|
||||
@@ -473,7 +476,7 @@ TEST(ProgramEmit, TheProgramRecordSurvivesAMakeCurrentWhileTheThreeBindingsDoNot
|
||||
const SpirvArtifacts spirv;
|
||||
const MGPipeHandle cso{8, 1};
|
||||
const Uint8 block[4] = {9, 9, 9, 9};
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x3u, 4), &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x3u, 4), &link, &spirv, nullptr);
|
||||
MGPipeApplySetGlobalConstants(GlobalConstants(cso, 21), block);
|
||||
MGPipeApplyBindShaderState(ProgramHandle(cso));
|
||||
MGPipeApplySetDrawProgram(ProgramHandle(cso));
|
||||
@@ -509,7 +512,11 @@ TEST(ProgramEmit, TheProgramRecordSurvivesAMakeCurrentWhileTheThreeBindingsDoNot
|
||||
X(ProgramEmit, TheDrawAndDispatchProgramsAreTwoIndependentSlots) \
|
||||
X(ProgramEmit, AnUnchangedProgramEmitsNothingAtAll) \
|
||||
X(ProgramEmit, AReIssuedCreateReSendsTheDefaultUniformBlock) \
|
||||
X(ProgramEmit, ADeadProgramsRecordLatchIsRetiredAtItsDeath)
|
||||
X(ProgramEmit, ADeadProgramsRecordLatchIsRetiredAtItsDeath) \
|
||||
X(ProgramEmit, AUniformBlockBindingAfterTheLinkTravelsOnItsOwnRecord) \
|
||||
X(ProgramEmit, TheThreeBindingTailsAreWholeSetsAndAReIssuedCreateDropsThem) \
|
||||
X(ProgramEmit, AFailedRelinkReIssuesWithLinkStatusZeroAndNeverAnObjectDeath) \
|
||||
X(ProgramEmit, TheFramedArchiveRoundTripsWithTheStageOfEveryModule)
|
||||
|
||||
#define MGL_DECLARE_PULL_SKIP(Suite, Name) \
|
||||
TEST(Suite, Name) { GTEST_SKIP() << "compiled only under MOBILEGL_PIPE_PUSH"; }
|
||||
@@ -802,6 +809,199 @@ void main() { gl_Position = vec4(0.0); EmitVertex(); }
|
||||
EXPECT_FALSE(Emitter().RecordIsPublished(handle))
|
||||
<< "a dead program still reads as published in the program emitter's memo";
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
// P5e (pg): set_program_bindings, and the archive as the server owns it
|
||||
// =====================================================================================
|
||||
|
||||
// THE CASE THE PACKAGE'S FIRST RED-ONCE IS BUILT ON. glUniformBlockBinding moves a block's
|
||||
// binding INSIDE LinkArtifacts after the link that produced the archive, so a server that
|
||||
// answered a draw from the archive alone would bind the uniform blocks the program was
|
||||
// LINKED with rather than the ones it is BOUND with. The record is what closes that, and
|
||||
// this is the case that says the client sends it.
|
||||
TEST(ProgramEmit, AUniformBlockBindingAfterTheLinkTravelsOnItsOwnRecord) {
|
||||
EmitterScope scope;
|
||||
const GLuint name = MakeVsFsProgram();
|
||||
const SharedPtr<ProgramObject>& program = Ctx().GetProgramObject(name);
|
||||
ASSERT_TRUE(program);
|
||||
Uint64 bytes = 0;
|
||||
const MGPipeHandle cso = Emitter().AcquireShaderCso(*program, bytes);
|
||||
ASSERT_FALSE(MGPipeHandleIsNull(cso));
|
||||
|
||||
// The create clears the latch, so the first bindings emission always goes out - which
|
||||
// is the ordering the applier depends on (a re-issued create wipes all three tails).
|
||||
const Uint64 before = Emitter().ProgramBindingsSetCount();
|
||||
Emitter().EmitProgramBindings(*program, cso);
|
||||
EXPECT_EQ(Emitter().ProgramBindingsSetCount(), before + 1)
|
||||
<< "the bindings that follow a create were suppressed, so the server would draw "
|
||||
"this program off its archive's link-time snapshot for ever";
|
||||
EXPECT_EQ(Emitter().LastProgramBindings().Cso, cso);
|
||||
EXPECT_EQ(Emitter().ProgramBindingsRefusalCount(), 0u);
|
||||
|
||||
// UNCHANGED STATE EMITS NOTHING. The latch is (Cso, backendStateVersion,
|
||||
// blockBindingVersion) and neither setter moves a counter on an unchanged value, which
|
||||
// is what keeps a program-pipeline composite's per-draw uniform mirror free.
|
||||
const Uint64 latched = Emitter().ProgramBindingsSetCount();
|
||||
Emitter().EmitProgramBindings(*program, cso);
|
||||
EXPECT_EQ(Emitter().ProgramBindingsSetCount(), latched)
|
||||
<< "an unchanged binding set was re-sent";
|
||||
|
||||
// A REAL glUniformBlockBinding, after the link, on a program that declares no block:
|
||||
// the frontend's setter bails out on an out-of-range index, so this drives the other
|
||||
// half - glUniform1i on the sampler-shaped uniform the test shader declares - which
|
||||
// moves m_backendStateVersion and must unlatch the record.
|
||||
const Int location = program->GetUniformLocation("u_value");
|
||||
if (location >= 0) {
|
||||
program->SetUniformSamplerOrImageUnitIndex(static_cast<Uint>(location), 3);
|
||||
Emitter().EmitProgramBindings(*program, cso);
|
||||
EXPECT_EQ(Emitter().ProgramBindingsSetCount(), latched + 1)
|
||||
<< "a post-link unit assignment did not move the latch, so it never travels";
|
||||
const auto& hdr = Emitter().LastProgramBindings();
|
||||
EXPECT_EQ(hdr.Cso, cso);
|
||||
EXPECT_GE(hdr.SamplerUnitCount, 1u)
|
||||
<< "the assigned unit is not in the record's second tail";
|
||||
}
|
||||
}
|
||||
|
||||
// The applier's half: whole-set replacement in all three tails, and a re-issued create
|
||||
// drops them because they are INDICES INTO the archive it has just replaced.
|
||||
TEST(ProgramEmit, TheThreeBindingTailsAreWholeSetsAndAReIssuedCreateDropsThem) {
|
||||
ApplierGuard guard;
|
||||
const LinkArtifacts link;
|
||||
const SpirvArtifacts spirv;
|
||||
const MGPipeHandle cso{9, 1};
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x3u, 0), &link, &spirv, nullptr);
|
||||
ASSERT_TRUE(ProgramRecordOf(9).Live) << "the create did not land, so nothing below is about "
|
||||
"set_program_bindings at all";
|
||||
const Uint64 bindingsSerialAfterCreate = ProgramRecordOf(9).BindingsSerial;
|
||||
const Uint64 refusalsBefore = MGPipeApplier().RefusedObjectCalls;
|
||||
|
||||
const Int32 blocks[3] = {0, 5, 2};
|
||||
const MGPProgramSamplerUnit units[2] = {{4u, 1}, {9u, 7}};
|
||||
MGPProgramStorageOverride overrides[1]{};
|
||||
overrides[0].Binding = 6;
|
||||
const char* const names[1] = {"Blocky"};
|
||||
MGPProgramBindings hdr{};
|
||||
hdr.Cso = cso;
|
||||
hdr.Signature = 0xABCDEFull;
|
||||
hdr.BlockBindingCount = 3;
|
||||
hdr.SamplerUnitCount = 2;
|
||||
hdr.StorageOverrideCount = 1;
|
||||
MGPipeApplySetProgramBindings(hdr, blocks, units, overrides, names);
|
||||
ASSERT_EQ(MGPipeApplier().RefusedObjectCalls, refusalsBefore)
|
||||
<< "the record the bindings name was not resolved";
|
||||
|
||||
ASSERT_EQ(ProgramRecordOf(9).BlockBindings.size(), 3u);
|
||||
EXPECT_EQ(ProgramRecordOf(9).BlockBindings[1], 5);
|
||||
ASSERT_EQ(ProgramRecordOf(9).SamplerUnits.size(), 2u);
|
||||
EXPECT_EQ(ProgramRecordOf(9).SamplerUnits[1].Location, 9u);
|
||||
EXPECT_EQ(ProgramRecordOf(9).SamplerUnits[1].Unit, 7);
|
||||
ASSERT_EQ(ProgramRecordOf(9).StorageOverrides.size(), 1u);
|
||||
// COPIED, NOT POINTED AT (rule C): the wire's name is a host span into SEG_STAGE, which
|
||||
// retires with the record that named it, and the rebuild that reads this may be a frame
|
||||
// later.
|
||||
EXPECT_EQ(ProgramRecordOf(9).StorageOverrides[0].Name, String("Blocky"));
|
||||
EXPECT_EQ(ProgramRecordOf(9).StorageOverrides[0].Binding, 6);
|
||||
EXPECT_EQ(ProgramRecordOf(9).Signature, 0xABCDEFull);
|
||||
EXPECT_GT(ProgramRecordOf(9).BindingsSerial, bindingsSerialAfterCreate)
|
||||
<< "BindingsSerial did not advance, so both texture memos and the twin's clean "
|
||||
"condition would match state they have never seen";
|
||||
|
||||
// A SHORTER SET REPLACES, never merges: a merge would leave a binding the application
|
||||
// has since reset to its declared default standing for ever.
|
||||
const Int32 oneBlock[1] = {4};
|
||||
MGPProgramBindings second = hdr;
|
||||
second.BlockBindingCount = 1;
|
||||
second.SamplerUnitCount = 0;
|
||||
second.StorageOverrideCount = 0;
|
||||
MGPipeApplySetProgramBindings(second, oneBlock, nullptr, nullptr, nullptr);
|
||||
ASSERT_EQ(ProgramRecordOf(9).BlockBindings.size(), 1u);
|
||||
EXPECT_TRUE(ProgramRecordOf(9).SamplerUnits.empty());
|
||||
EXPECT_TRUE(ProgramRecordOf(9).StorageOverrides.empty());
|
||||
|
||||
// THE RE-ISSUE DROPS ALL THREE, for the reason it drops the default uniform block.
|
||||
MGPipeApplyCreateShaderState(ProgramDesc(cso, 0x7u, 0), &link, &spirv, nullptr);
|
||||
EXPECT_TRUE(ProgramRecordOf(9).BlockBindings.empty())
|
||||
<< "a tail indexing an archive the relink replaced survived it";
|
||||
EXPECT_EQ(ProgramRecordOf(9).Signature, 0u);
|
||||
}
|
||||
|
||||
// ID-88 / ruling 9, VERIFIED IN THE FRONTEND rather than assumed: Link()'s prologue bumps
|
||||
// the link version and assigns `m_artifacts = {}` - "the complete not-linked state" in its
|
||||
// own words - BEFORE the link body runs, so a failed relink reports UNLINKED. The emitter
|
||||
// therefore re-issues on the same handle with LinkStatus = 0, and nothing needs an
|
||||
// object_death: the program object is alive and its twin must survive to be rebuilt.
|
||||
TEST(ProgramEmit, AFailedRelinkReIssuesWithLinkStatusZeroAndNeverAnObjectDeath) {
|
||||
EmitterScope scope;
|
||||
const GLuint name = MakeVsFsProgram();
|
||||
const SharedPtr<ProgramObject>& program = Ctx().GetProgramObject(name);
|
||||
ASSERT_TRUE(program);
|
||||
Uint64 bytes = 0;
|
||||
const MGPipeHandle cso = Emitter().AcquireShaderCso(*program, bytes);
|
||||
ASSERT_FALSE(MGPipeHandleIsNull(cso));
|
||||
EXPECT_TRUE(program->GetLinkStatus());
|
||||
EXPECT_EQ(Emitter().LastProgramDesc().LinkStatus, 1u);
|
||||
const Uint64 creates = Emitter().CreateCount();
|
||||
|
||||
// A relink with a shader that cannot compile. Detaching everything is the cleanest
|
||||
// failure this suite can produce without a compiler diagnostic of its own: Link() with
|
||||
// no shaders attached is the "No shader objects are attached" arm, which leaves
|
||||
// linkStatus false.
|
||||
for (const auto& attached : program->GetAttachedShaders()) {
|
||||
GL::DetachShader(name, attached->GetExternalIndex());
|
||||
}
|
||||
GL::LinkProgram(name);
|
||||
ASSERT_FALSE(program->GetLinkStatus()) << "the frontend did NOT withdraw LINK_STATUS on a "
|
||||
"failed relink; ID-88's 'iff' is then false and "
|
||||
"the emitter's rule has to be re-decided";
|
||||
|
||||
const MGPipeHandle again = Emitter().AcquireShaderCso(*program, bytes);
|
||||
EXPECT_EQ(again, cso) << "a relink minted a second handle; the twin table would be asked "
|
||||
"for two twins of one GL object";
|
||||
EXPECT_EQ(Emitter().CreateCount(), creates + 1)
|
||||
<< "the failed relink did not re-issue, so the server keeps drawing an executable "
|
||||
"the frontend reports unlinked";
|
||||
EXPECT_EQ(Emitter().LastProgramDesc().LinkStatus, 0u)
|
||||
<< "the re-issue claims the program linked";
|
||||
EXPECT_TRUE(MGPipeSlots().IsLive(MGPipeKind::ShaderCso, cso))
|
||||
<< "a failed relink must never be modelled as an object_death";
|
||||
}
|
||||
|
||||
// The frame, both ways round. SpirvArtifacts carries no stage list and MGPProgramDesc::
|
||||
// StageMask cannot stand in for one - it is a bit SET, and GL lets two shader objects of
|
||||
// one stage be attached to a program, so a list rebuilt from the mask can be SHORTER than
|
||||
// generatedSpirv while the backend pairs the two by one running index.
|
||||
TEST(ProgramEmit, TheFramedArchiveRoundTripsWithTheStageOfEveryModule) {
|
||||
MG_State::GLState::LinkArtifacts link;
|
||||
MG_State::GLState::SpirvArtifacts spirv;
|
||||
spirv.spirvStatus = true;
|
||||
// TWO MODULES OF THE SAME STAGE, which is the shape a mask cannot describe.
|
||||
spirv.generatedSpirv.resize(2);
|
||||
spirv.generatedSpirv[0].assign(3, 0x07230203u);
|
||||
spirv.generatedSpirv[1].assign(5, 0x07230204u);
|
||||
const Vector<Uint32> stages{static_cast<Uint32>(ShaderStage::Vertex),
|
||||
static_cast<Uint32>(ShaderStage::Vertex)};
|
||||
|
||||
Vector<Uint8> framed;
|
||||
MG_State::GLState::EncodeProgramArchive(link, spirv, stages, framed);
|
||||
ASSERT_FALSE(framed.empty());
|
||||
|
||||
MG_State::GLState::ProgramArchive back;
|
||||
ASSERT_TRUE(MG_State::GLState::DecodeProgramArchive(framed.data(), framed.size(), back));
|
||||
EXPECT_EQ(back.LinkedStages, stages);
|
||||
ASSERT_EQ(back.Spirv.generatedSpirv.size(), 2u);
|
||||
EXPECT_EQ(back.Spirv.generatedSpirv[1].size(), 5u);
|
||||
EXPECT_EQ(back.Link.program, nullptr)
|
||||
<< "the one member the codec skips is the live glslang TProgram, and decode must "
|
||||
"leave it null";
|
||||
|
||||
// A TRUNCATED FRAME IS REFUSED, not guessed, and both outputs come back defined.
|
||||
MG_State::GLState::ProgramArchive refused;
|
||||
EXPECT_FALSE(
|
||||
MG_State::GLState::DecodeProgramArchive(framed.data(), framed.size() - 1, refused));
|
||||
EXPECT_TRUE(refused.LinkedStages.empty());
|
||||
EXPECT_TRUE(refused.Spirv.generatedSpirv.empty());
|
||||
}
|
||||
} // namespace
|
||||
#endif // MOBILEGL_PIPE_PUSH
|
||||
|
||||
|
||||
@@ -1522,7 +1522,7 @@ namespace {
|
||||
MGPipeApplySetSamplerViews(viewSet, viewTail);
|
||||
MGPipeApplyBindSamplerStates(stateSet, stateTail);
|
||||
MGPipeApplySetShaderImages(imageSet, imageTail);
|
||||
MGPipeApplyCreateShaderState(program, &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(program, &link, &spirv, nullptr);
|
||||
MGPipeApplyBindShaderState(csoHandle);
|
||||
MGPipeApplySetDrawProgram(csoHandle);
|
||||
MGPipeApplySetDispatchProgram(csoHandle);
|
||||
@@ -1583,7 +1583,7 @@ namespace {
|
||||
MGPipeApplySetSamplerViews(viewSet, viewTail);
|
||||
MGPipeApplyBindSamplerStates(stateSet, stateTail);
|
||||
MGPipeApplySetShaderImages(imageSet, imageTail);
|
||||
MGPipeApplyCreateShaderState(program, &link, &spirv);
|
||||
MGPipeApplyCreateShaderState(program, &link, &spirv, nullptr);
|
||||
MGPipeApplyBindShaderState(csoHandle);
|
||||
MGPipeApplySetDrawProgram(csoHandle);
|
||||
MGPipeApplySetDispatchProgram(csoHandle);
|
||||
|
||||
@@ -0,0 +1,508 @@
|
||||
// MobileGL - MobileGL/MG_Test/Pipe/ShaderBufferEmitTest.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
|
||||
|
||||
// P5e's set_shader_buffers - the INDEXED BUFFER BINDING POINTS - on both sides of the call
|
||||
// (MG_Remote/CONTRACT-P5E.md §5.6, rulings 10 and 11; package sb).
|
||||
//
|
||||
// WHAT THIS SUITE IS FOR. Three properties of this family are invisible in a picture and are
|
||||
// exactly what an optimisation or a merge deletes:
|
||||
// 1. the ZERO EARLY-OUT - a class nothing has bound emits nothing, before any hash;
|
||||
// 2. a BASE binding travels as kMGPipeWholeBuffer and never as a resolved extent, so a
|
||||
// glBufferData between the emission and the apply binds the NEW extent as GL does;
|
||||
// 3. THREE SUPPRESSOR SLOTS, one per class, so an emission of one class never cancels
|
||||
// another's (ruling 11) - a single slot would make the shader-storage set disappear
|
||||
// whenever a uniform set happened to hash the same way.
|
||||
// Plus ID-104's widened WritableMask, whose whole point is the points a Uint32 could not
|
||||
// describe: the case that matters is point 83, not point 3.
|
||||
//
|
||||
// THE SUITE IS `ShaderBufferEmit`, not `ShaderBufferEmitTest`: the file is XTest.cpp and the
|
||||
// suite is X, this directory's convention.
|
||||
//
|
||||
// IT HAS ITS OWN main() for VertexInputEmitTest's reason: the applier refuses a malformed
|
||||
// window, and that verdict is a log line in a shipped push build and std::abort() in a poison
|
||||
// or verify one. Every case is a visible SKIP in a pull build rather than a vanishing test, so
|
||||
// `ctest -N` stays name-for-name identical between the pull and the push trees (G2/G14).
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
#if defined(_WIN32)
|
||||
#include <process.h>
|
||||
#define MGTEST_HAVE_FORK 0
|
||||
#else
|
||||
#include <csignal>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#define MGTEST_HAVE_FORK 1
|
||||
#endif
|
||||
|
||||
#include "Includes.h"
|
||||
#include <MG_Pipe/MGPipe.h>
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
#include "Init.h"
|
||||
#include <Config.h>
|
||||
// MOBILEGL_PIPE_POISON is DERIVED in the header below (PipeInputs.h:20-26) and nowhere else,
|
||||
// so a TU that tests it without this include silently reads it as 0 - and then
|
||||
// ExpectRefusedNaming takes the in-process arm while the applier's trip wire really does
|
||||
// abort, which takes the whole binary down with it. ImageEmitTest carries the same include for
|
||||
// the same reason and learned it the same way.
|
||||
#include <MG_Backend/MGPipe/PipeInputs.h>
|
||||
#include <MG_Impl/GLImpl/Buffer/GL_Buffer.h>
|
||||
#include <MG_Impl/GLImpl/Getter/GL_Getter.h>
|
||||
#include <MG_Impl/Pipe/SetHashSuppressor.h>
|
||||
#include <MG_Impl/Pipe/ShaderBufferEmit.h>
|
||||
#include <MG_Impl/Pipe/SlotAllocator.h>
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#include <MG_Pipe/PipeRoute.h>
|
||||
#include <MG_State/GLState/Core.h>
|
||||
#endif
|
||||
|
||||
using namespace MobileGL;
|
||||
using namespace MobileGL::MG_Pipe;
|
||||
|
||||
namespace {
|
||||
String g_logPath;
|
||||
|
||||
int ProcessId() {
|
||||
#if defined(_WIN32)
|
||||
return _getpid();
|
||||
#else
|
||||
return static_cast<int>(getpid());
|
||||
#endif
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#if !MOBILEGL_PIPE_PUSH
|
||||
namespace {
|
||||
// G2/G14: the pull build gets the same ctest names, skipping.
|
||||
#define MGL_SHADER_BUFFER_EMIT_TEST_LIST(X) \
|
||||
X(ShaderBufferEmit, TheEmitterIsOneNeverDestroyedProcessSingleton) \
|
||||
X(ShaderBufferEmit, AnUntouchedClassEmitsNothingWithoutHashing) \
|
||||
X(ShaderBufferEmit, ABaseBindingTravelsAsWholeBufferAndARangeBindingTravelsResolved) \
|
||||
X(ShaderBufferEmit, OnlyTheWritableClassesSetAMaskAndItReachesTheLastPoint) \
|
||||
X(ShaderBufferEmit, EachClassLatchesItsOwnSuppressorSlot) \
|
||||
X(ShaderBufferEmit, TheAppliedWindowIsPerClassAndTheSerialMovesOnEveryRecord) \
|
||||
X(ShaderBufferEmit, AWindowPastTheCapacityOrAnUnknownClassIsRefusedRatherThanStored) \
|
||||
X(ShaderBufferEmit, AResetApplierCarriesNoBindingPointStateOverAndTheSerialAdvances)
|
||||
|
||||
#define MGL_DECLARE_PULL_SKIP(Suite, Name) \
|
||||
TEST(Suite, Name) { GTEST_SKIP() << "compiled only under MOBILEGL_PIPE_PUSH"; }
|
||||
MGL_SHADER_BUFFER_EMIT_TEST_LIST(MGL_DECLARE_PULL_SKIP)
|
||||
#undef MGL_DECLARE_PULL_SKIP
|
||||
} // namespace
|
||||
#else
|
||||
|
||||
namespace {
|
||||
namespace GL = MobileGL::MG_Impl::GLImpl;
|
||||
using GLContext = MG_State::GLState::GLContext;
|
||||
|
||||
// Each case starts from an emitter with no latch, an applier with no window and a
|
||||
// suppressor that has never seen a hash, because every property below is about what the
|
||||
// NEXT emission does.
|
||||
struct EmitterScope {
|
||||
EmitterScope() { Clear(); }
|
||||
~EmitterScope() { Clear(); }
|
||||
EmitterScope(const EmitterScope&) = delete;
|
||||
EmitterScope& operator=(const EmitterScope&) = delete;
|
||||
|
||||
static void Clear() {
|
||||
MGPipeInstallMonolithTables(); // idempotent; the route has to reach the applier
|
||||
MGPipeShaderBufferEmitterInstance().Reset();
|
||||
MGPipeShaderBufferEmitterInstance().ResetCounters();
|
||||
MGPipeSetHashSuppressorInstance().InvalidateAll();
|
||||
for (Uint32 cls = 0; cls < kMGPipeShaderBufferClassCount; ++cls) {
|
||||
MGPipeApplier().BoundShaderBuffers[cls] = {};
|
||||
MGPipeApplier().ShaderBufferStart[cls] = 0;
|
||||
MGPipeApplier().ShaderBufferCount[cls] = 0;
|
||||
for (Uint32 w = 0; w < kMGPipeShaderBufferWritableMaskWords; ++w) {
|
||||
MGPipeApplier().ShaderBufferWritableMask[cls][w] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GLContext& Ctx() { return *MG_State::pGLContext; }
|
||||
MGPipeShaderBufferEmitter& Emitter() { return MGPipeShaderBufferEmitterInstance(); }
|
||||
|
||||
// ---- driving a refusal, in ImageEmitTest's shape and for its reason ------------------
|
||||
//
|
||||
// The applier's trip wires report through a log line in a shipped push build and
|
||||
// std::abort() in a poison or verify one - and MOBILEGL_PIPE_POISON is DERIVED from
|
||||
// MOBILEGL_BUILD_DISAGGREGATED behind PipeInputs.h, so the split build this campaign gates
|
||||
// on is the aborting arm. A case that drove one in process would therefore take the whole
|
||||
// binary down, which is why the drive is a forked child there and the parent reads SIGABRT
|
||||
// plus the line the wire appended to the log.
|
||||
std::string ReadLog(std::streamoff from = 0) {
|
||||
std::ifstream in(g_logPath, std::ios::binary);
|
||||
if (from > 0) in.seekg(from, std::ios::beg);
|
||||
std::ostringstream ss;
|
||||
ss << in.rdbuf();
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
std::streamoff LogEnd() {
|
||||
std::ifstream in(g_logPath, std::ios::binary | std::ios::ate);
|
||||
return in ? static_cast<std::streamoff>(in.tellg()) : std::streamoff{0};
|
||||
}
|
||||
|
||||
#if MGTEST_HAVE_FORK
|
||||
struct ChildResult {
|
||||
int Status = -1;
|
||||
std::string Log;
|
||||
};
|
||||
|
||||
template <class Body>
|
||||
ChildResult RunInChild(Body body) {
|
||||
ChildResult result;
|
||||
// The log path is NOT unlinked: main() has already opened it, fork() duplicates the
|
||||
// handle, and removing it would leave the child writing into a deleted inode while the
|
||||
// parent read an empty file. Only what the child appended is this drive's evidence.
|
||||
const std::streamoff before = LogEnd();
|
||||
std::fflush(nullptr);
|
||||
const pid_t pid = ::fork();
|
||||
if (pid < 0) return result;
|
||||
if (pid == 0) {
|
||||
body();
|
||||
::_exit(0);
|
||||
}
|
||||
int status = 0;
|
||||
if (::waitpid(pid, &status, 0) != pid) return result;
|
||||
result.Status = status;
|
||||
result.Log = ReadLog(before);
|
||||
return result;
|
||||
}
|
||||
|
||||
Bool DiedOfAbort(const ChildResult& r) {
|
||||
return WIFSIGNALED(r.Status) && WTERMSIG(r.Status) == SIGABRT;
|
||||
}
|
||||
std::string DescribeStatus(const ChildResult& r) {
|
||||
if (r.Status < 0) return "fork/waitpid failed";
|
||||
if (WIFEXITED(r.Status)) return "exited " + std::to_string(WEXITSTATUS(r.Status));
|
||||
if (WIFSIGNALED(r.Status)) return "signal " + std::to_string(WTERMSIG(r.Status));
|
||||
return "status " + std::to_string(r.Status);
|
||||
}
|
||||
#endif // MGTEST_HAVE_FORK
|
||||
|
||||
template <class Body>
|
||||
void ExpectRefusedNaming(const char* needle, Body body) {
|
||||
#if MOBILEGL_PIPE_POISON || MOBILEGL_PIPE_VERIFY
|
||||
#if MGTEST_HAVE_FORK
|
||||
const std::string tagged = std::string("Fatal{ProtocolCorruption} ") + needle;
|
||||
const ChildResult child = RunInChild(body);
|
||||
EXPECT_TRUE(DiedOfAbort(child)) << DescribeStatus(child) << "; log: " << child.Log;
|
||||
EXPECT_NE(child.Log.find(tagged), std::string::npos)
|
||||
<< "the gate fired without naming what it refused; wanted \"" << tagged
|
||||
<< "\"; log: " << child.Log;
|
||||
#else
|
||||
(void)needle;
|
||||
(void)body; // no fork on this platform; the verdict here is std::abort()
|
||||
#endif
|
||||
#else
|
||||
const std::string tagged = std::string("ProtocolCorruption ") + needle;
|
||||
const std::string before = ReadLog();
|
||||
body();
|
||||
EXPECT_NE(ReadLog().substr(before.size()).find(tagged), std::string::npos)
|
||||
<< "the gate refused without saying what it refused; wanted \"" << tagged << "\"";
|
||||
#endif
|
||||
}
|
||||
|
||||
GLuint MakeBuffer(GLenum target, GLsizeiptr size) {
|
||||
GLuint name = 0;
|
||||
GL::GenBuffers(1, &name);
|
||||
GL::BindBuffer(target, name);
|
||||
GL::BufferData(target, size, nullptr, GL_DYNAMIC_DRAW);
|
||||
return name;
|
||||
}
|
||||
|
||||
// The frontend keeps the touched high-water mark per target for the life of the context and
|
||||
// only ever raises it, so a case that binds point 83 raises it for every case after it in
|
||||
// the same process. Each case therefore states the window it expects rather than assuming
|
||||
// it is the number of points it just bound.
|
||||
Uint32 TouchedWindow(BufferTarget target) {
|
||||
return static_cast<Uint32>(Ctx().GetTouchedBufferBindingPointCount(target));
|
||||
}
|
||||
|
||||
TEST(ShaderBufferEmit, TheEmitterIsOneNeverDestroyedProcessSingleton) {
|
||||
EXPECT_EQ(&MGPipeShaderBufferEmitterInstance(), &MGPipeShaderBufferEmitterInstance());
|
||||
}
|
||||
|
||||
// PROPERTY 1, and it is what makes this whole family cost one integer read per validate
|
||||
// point on a workload that binds no indexed buffer - which is every Minecraft frame:
|
||||
// MC's touched SSBO and atomic-counter counts are both 0.
|
||||
TEST(ShaderBufferEmit, AnUntouchedClassEmitsNothingWithoutHashing) {
|
||||
EmitterScope scope;
|
||||
ASSERT_EQ(TouchedWindow(BufferTarget::AtomicCounter), 0u)
|
||||
<< "this case needs a class nothing in this process has ever bound";
|
||||
EXPECT_EQ(Emitter().EmitShaderBuffers(Ctx()), 0u);
|
||||
EXPECT_EQ(Emitter().EmissionCount(kMGPipeShaderBufferClassAtomicCounter), 0u);
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBufferCount[kMGPipeShaderBufferClassAtomicCounter], 0u);
|
||||
}
|
||||
|
||||
// PROPERTY 2, the one that is silent under run-ahead: glBindBufferBase does not freeze an
|
||||
// extent - GL resolves it against the object's size at every USE - so resolving it at emit
|
||||
// would make a glBufferData issued between the emission and the apply bind the OLD size,
|
||||
// with the right handle and no diagnostic anywhere. glBindBufferRange DOES pin a window,
|
||||
// and that one travels resolved.
|
||||
TEST(ShaderBufferEmit, ABaseBindingTravelsAsWholeBufferAndARangeBindingTravelsResolved) {
|
||||
EmitterScope scope;
|
||||
GLint alignment = 0;
|
||||
GL::GetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &alignment);
|
||||
if (alignment <= 0) alignment = 256;
|
||||
const GLuint whole = MakeBuffer(GL_UNIFORM_BUFFER, 1024);
|
||||
const GLuint ranged = MakeBuffer(GL_UNIFORM_BUFFER, 1024);
|
||||
GL::BindBufferBase(GL_UNIFORM_BUFFER, 0, whole);
|
||||
GL::BindBufferRange(GL_UNIFORM_BUFFER, 1, ranged, alignment, 256);
|
||||
|
||||
ASSERT_NE(Emitter().EmitConstBuffers(Ctx()), 0u) << "the uniform window did not emit";
|
||||
const MGPShaderBuffers& header = Emitter().LastHeader(kMGPipeShaderBufferClassUniform);
|
||||
EXPECT_EQ(header.Class, kMGPipeShaderBufferClassUniform);
|
||||
EXPECT_EQ(header.Start, 0u);
|
||||
EXPECT_EQ(header.Count, TouchedWindow(BufferTarget::Uniform));
|
||||
EXPECT_EQ(header.HostSpanCount, 0u)
|
||||
<< "kCapNeedsHostUboBytes is 0 for the whole of P5, so Espryt ships no second tail";
|
||||
|
||||
const auto& ranges = Emitter().LastRanges();
|
||||
EXPECT_EQ(ranges[0].Offset, 0u);
|
||||
EXPECT_EQ(ranges[0].Size, kMGPipeWholeBuffer)
|
||||
<< "a base binding must let the SERVER re-resolve the extent at use";
|
||||
EXPECT_FALSE(MGPipeHandleIsNull(ranges[0].Res));
|
||||
EXPECT_EQ(ranges[1].Offset, static_cast<Uint64>(alignment));
|
||||
EXPECT_EQ(ranges[1].Size, 256u);
|
||||
EXPECT_NE(ranges[0].Res.Slot, ranges[1].Res.Slot) << "two buffers, two handles";
|
||||
|
||||
// And the record reached the applier through the monolith adapter this route installs.
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBufferCount[kMGPipeShaderBufferClassUniform], header.Count);
|
||||
EXPECT_EQ(MGPipeApplier().BoundShaderBuffers[kMGPipeShaderBufferClassUniform][0].Size,
|
||||
kMGPipeWholeBuffer);
|
||||
}
|
||||
|
||||
// ID-104's case. The mask is what replaces the backend's own GPU-write walk, and until this
|
||||
// phase it was a single Uint32 against an 84-point window - so a storage buffer bound at
|
||||
// point 32 or above was unwritable as far as the record said, with nothing able to see it.
|
||||
//
|
||||
// THE EMITTER HALF BINDS THE HIGHEST POINT THE TARGET ALLOWS rather than a literal 83: the
|
||||
// frontend's array is 84 deep, but glBindBufferBase(GL_SHADER_STORAGE_BUFFER, ...) is
|
||||
// bounded by GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, which is a DEVICE number and is exactly
|
||||
// what ruling 10 says the client must not pre-clamp the WIRE to. The wire-field half - that
|
||||
// the mask reaches point 83 at all - is driven through the applier below, where the window
|
||||
// is 84 by construction, and pinned again in PipeCatalogueTest.
|
||||
TEST(ShaderBufferEmit, OnlyTheWritableClassesSetAMaskAndItReachesTheLastPoint) {
|
||||
EmitterScope scope;
|
||||
GLint storageBindings = 0;
|
||||
GL::GetIntegerv(GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS, &storageBindings);
|
||||
ASSERT_GT(storageBindings, 0);
|
||||
const Uint32 top = static_cast<Uint32>(storageBindings) - 1u;
|
||||
const GLuint storage = MakeBuffer(GL_SHADER_STORAGE_BUFFER, 512);
|
||||
const GLuint uniform = MakeBuffer(GL_UNIFORM_BUFFER, 512);
|
||||
GL::BindBufferBase(GL_SHADER_STORAGE_BUFFER, static_cast<GLuint>(top), storage);
|
||||
GL::BindBufferBase(GL_UNIFORM_BUFFER, 0, uniform);
|
||||
|
||||
ASSERT_NE(Emitter().EmitShaderBuffers(Ctx()), 0u);
|
||||
const MGPShaderBuffers& storageHeader =
|
||||
Emitter().LastHeader(kMGPipeShaderBufferClassShaderStorage);
|
||||
ASSERT_EQ(storageHeader.Count, top + 1u)
|
||||
<< "the window is the touched high-water mark, so binding the top point describes "
|
||||
"every point below it too";
|
||||
EXPECT_TRUE(MGPipeShaderBufferMaskHas(storageHeader.WritableMask, top))
|
||||
<< "the shader may write through binding point " << top << " and the mask must say so";
|
||||
EXPECT_FALSE(MGPipeShaderBufferMaskHas(storageHeader.WritableMask, 0u))
|
||||
<< "nothing is bound at storage point 0, so nothing is writable there";
|
||||
|
||||
ASSERT_NE(Emitter().EmitConstBuffers(Ctx()), 0u);
|
||||
const MGPShaderBuffers& uniformHeader =
|
||||
Emitter().LastHeader(kMGPipeShaderBufferClassUniform);
|
||||
for (Uint32 w = 0; w < kMGPipeShaderBufferWritableMaskWords; ++w) {
|
||||
EXPECT_EQ(uniformHeader.WritableMask[w], 0u)
|
||||
<< "a UBO is read-only to the shader by definition (word " << w << ")";
|
||||
}
|
||||
// And the applier carries the mask by class, not by record.
|
||||
EXPECT_TRUE(MGPipeShaderBufferMaskHas(
|
||||
MGPipeApplier().ShaderBufferWritableMask[kMGPipeShaderBufferClassShaderStorage], top));
|
||||
EXPECT_FALSE(MGPipeShaderBufferMaskHas(
|
||||
MGPipeApplier().ShaderBufferWritableMask[kMGPipeShaderBufferClassUniform], top));
|
||||
|
||||
// THE WIRE FIELD's OWN HALF (ID-104): a mask bit at the LAST point the window may
|
||||
// describe survives the record and the applier. A Uint32 field could not have carried
|
||||
// it at all - it would have been silently dropped, and the server would have read the
|
||||
// point as read-only while the shader wrote to it.
|
||||
const Uint32 last = kMGPipeMaxBufferBindingPoints - 1;
|
||||
MGPBufferRange range{};
|
||||
range.Res = MGPipeHandle{41, 1};
|
||||
range.Size = kMGPipeWholeBuffer;
|
||||
MGPShaderBuffers forged{};
|
||||
forged.Class = kMGPipeShaderBufferClassAtomicCounter;
|
||||
forged.Start = last;
|
||||
forged.Count = 1;
|
||||
MGPipeShaderBufferMaskSet(forged.WritableMask, last);
|
||||
MGPipeApplySetShaderBuffers(forged, &range);
|
||||
EXPECT_TRUE(MGPipeShaderBufferMaskHas(
|
||||
MGPipeApplier().ShaderBufferWritableMask[kMGPipeShaderBufferClassAtomicCounter], last))
|
||||
<< "the widened mask must describe the whole 84-point window the record declares";
|
||||
}
|
||||
|
||||
// RULING 11. One slot for the call would make each class's emission cancel the previous
|
||||
// class's latch: the storage set would go out, the uniform set would go out behind it, and
|
||||
// then a storage set that had NOT changed would go out again - or, worse on the other side
|
||||
// of the coin, an unchanged uniform set would be re-sent and a changed storage set would
|
||||
// not, because the slot held the other class's hash.
|
||||
TEST(ShaderBufferEmit, EachClassLatchesItsOwnSuppressorSlot) {
|
||||
EmitterScope scope;
|
||||
const GLuint storage = MakeBuffer(GL_SHADER_STORAGE_BUFFER, 512);
|
||||
const GLuint uniform = MakeBuffer(GL_UNIFORM_BUFFER, 512);
|
||||
GL::BindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, storage);
|
||||
GL::BindBufferBase(GL_UNIFORM_BUFFER, 2, uniform);
|
||||
|
||||
ASSERT_NE(Emitter().EmitConstBuffers(Ctx()), 0u);
|
||||
ASSERT_NE(Emitter().EmitShaderBuffers(Ctx()), 0u);
|
||||
const Uint64 uniformEmissions = Emitter().EmissionCount(kMGPipeShaderBufferClassUniform);
|
||||
const Uint64 storageEmissions =
|
||||
Emitter().EmissionCount(kMGPipeShaderBufferClassShaderStorage);
|
||||
|
||||
// Nothing moved: both classes must be suppressed, and each on its OWN latch.
|
||||
EXPECT_EQ(Emitter().EmitConstBuffers(Ctx()), 0u);
|
||||
EXPECT_EQ(Emitter().EmitShaderBuffers(Ctx()), 0u);
|
||||
EXPECT_EQ(Emitter().EmissionCount(kMGPipeShaderBufferClassUniform), uniformEmissions);
|
||||
EXPECT_EQ(Emitter().EmissionCount(kMGPipeShaderBufferClassShaderStorage), storageEmissions);
|
||||
|
||||
// ONE class moves. The other must stay suppressed - with a shared slot it would be
|
||||
// re-sent, and the case would pass for the wrong reason if it only asserted the mover.
|
||||
GL::BindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, 0);
|
||||
EXPECT_NE(Emitter().EmitShaderBuffers(Ctx()), 0u);
|
||||
EXPECT_EQ(Emitter().EmissionCount(kMGPipeShaderBufferClassShaderStorage),
|
||||
storageEmissions + 1u);
|
||||
EXPECT_EQ(Emitter().EmitConstBuffers(Ctx()), 0u)
|
||||
<< "the uniform class did not move and must not be re-sent on the storage class's "
|
||||
"account";
|
||||
EXPECT_EQ(Emitter().EmissionCount(kMGPipeShaderBufferClassUniform), uniformEmissions);
|
||||
}
|
||||
|
||||
// The applier's half, driven directly so the window arithmetic is stated rather than
|
||||
// inferred from an emission: three classes, three windows, ONE serial.
|
||||
TEST(ShaderBufferEmit, TheAppliedWindowIsPerClassAndTheSerialMovesOnEveryRecord) {
|
||||
EmitterScope scope;
|
||||
MGPBufferRange ranges[2]{};
|
||||
ranges[0].Res = MGPipeHandle{11, 1};
|
||||
ranges[0].Size = kMGPipeWholeBuffer;
|
||||
ranges[1].Res = MGPipeHandle{12, 1};
|
||||
ranges[1].Offset = 64;
|
||||
ranges[1].Size = 128;
|
||||
|
||||
const Uint64 before = MGPipeApplier().ShaderBuffersSerial;
|
||||
MGPShaderBuffers header{};
|
||||
header.Class = kMGPipeShaderBufferClassShaderStorage;
|
||||
header.Start = 0;
|
||||
header.Count = 2;
|
||||
MGPipeShaderBufferMaskSet(header.WritableMask, 1);
|
||||
MGPipeApplySetShaderBuffers(header, ranges);
|
||||
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBufferCount[kMGPipeShaderBufferClassShaderStorage], 2u);
|
||||
EXPECT_EQ(MGPipeApplier().BoundShaderBuffers[kMGPipeShaderBufferClassShaderStorage][1].Offset,
|
||||
64u);
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBuffersSerial, before + 1u);
|
||||
// THE OTHER TWO CLASSES ARE UNTOUCHED, which is the whole reason Class is a field: one
|
||||
// record describes one array and says nothing about the other two.
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBufferCount[kMGPipeShaderBufferClassUniform], 0u);
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBufferCount[kMGPipeShaderBufferClassAtomicCounter], 0u);
|
||||
|
||||
header.Class = kMGPipeShaderBufferClassUniform;
|
||||
header.Count = 1;
|
||||
MGPipeApplySetShaderBuffers(header, ranges);
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBufferCount[kMGPipeShaderBufferClassUniform], 1u);
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBufferCount[kMGPipeShaderBufferClassShaderStorage], 2u)
|
||||
<< "the storage window survived a uniform record";
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBuffersSerial, before + 2u)
|
||||
<< "ONE serial for all three classes, and it moves on every applied record";
|
||||
}
|
||||
|
||||
// The two refusals the contract names by string (§1), and they are asserted BY NAME: a
|
||||
// trip wire that fired without saying which field it refused would leave a reader of the
|
||||
// lane guessing between a class nobody allocated and a window nobody can hold.
|
||||
TEST(ShaderBufferEmit, AWindowPastTheCapacityOrAnUnknownClassIsRefusedRatherThanStored) {
|
||||
EmitterScope scope;
|
||||
ExpectRefusedNaming("SetShaderBuffers.Count", [] {
|
||||
MGPBufferRange range{};
|
||||
range.Res = MGPipeHandle{21, 1};
|
||||
MGPShaderBuffers header{};
|
||||
header.Class = kMGPipeShaderBufferClassAtomicCounter;
|
||||
header.Start = kMGPipeMaxBufferBindingPoints - 1;
|
||||
header.Count = 4; // Start + Count = 87 > 84
|
||||
const Uint64 before = MGPipeApplier().ShaderBuffersSerial;
|
||||
MGPipeApplySetShaderBuffers(header, &range);
|
||||
// Only reached on the non-aborting arm, and the point of reaching it is that a
|
||||
// refusal which had stored half a window would be worse than an abort.
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBufferCount[kMGPipeShaderBufferClassAtomicCounter], 0u);
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBuffersSerial, before)
|
||||
<< "a refused record must not move the serial a twin memoises on";
|
||||
});
|
||||
ExpectRefusedNaming("SetShaderBuffers.Class", [] {
|
||||
MGPBufferRange range{};
|
||||
range.Res = MGPipeHandle{22, 1};
|
||||
MGPShaderBuffers header{};
|
||||
header.Class = kMGPipeShaderBufferClassCount; // one past the last class
|
||||
header.Start = 0;
|
||||
header.Count = 1;
|
||||
const Uint64 before = MGPipeApplier().ShaderBuffersSerial;
|
||||
MGPipeApplySetShaderBuffers(header, &range);
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBuffersSerial, before);
|
||||
});
|
||||
}
|
||||
|
||||
// A make-current clears the three windows and ADVANCES the serial, for the reason
|
||||
// VertexBuffersSerial's own comment gives: a counter that restarts walks back through every
|
||||
// value it has already stamped into a backend memo that outlived the switch.
|
||||
TEST(ShaderBufferEmit, AResetApplierCarriesNoBindingPointStateOverAndTheSerialAdvances) {
|
||||
EmitterScope scope;
|
||||
MGPipeApplierState& applier = MGPipeApplier();
|
||||
applier.ShaderBufferStart[kMGPipeShaderBufferClassUniform] = 0;
|
||||
applier.ShaderBufferCount[kMGPipeShaderBufferClassUniform] = 7;
|
||||
applier.BoundShaderBuffers[kMGPipeShaderBufferClassUniform][0].Res = MGPipeHandle{31, 1};
|
||||
MGPipeShaderBufferMaskSet(
|
||||
applier.ShaderBufferWritableMask[kMGPipeShaderBufferClassShaderStorage],
|
||||
kMGPipeMaxBufferBindingPoints - 1);
|
||||
applier.ShaderBuffersSerial = 99;
|
||||
|
||||
MGPipeApplierReset();
|
||||
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBufferCount[kMGPipeShaderBufferClassUniform], 0u);
|
||||
EXPECT_TRUE(MGPipeHandleIsNull(
|
||||
MGPipeApplier().BoundShaderBuffers[kMGPipeShaderBufferClassUniform][0].Res));
|
||||
EXPECT_FALSE(MGPipeShaderBufferMaskHas(
|
||||
MGPipeApplier().ShaderBufferWritableMask[kMGPipeShaderBufferClassShaderStorage],
|
||||
kMGPipeMaxBufferBindingPoints - 1));
|
||||
EXPECT_EQ(MGPipeApplier().ShaderBuffersSerial, 100u);
|
||||
EXPECT_GT(MGPipeApplier().ShaderBuffersSerial, 99u)
|
||||
<< "ADVANCED, never zeroed: no value this counter has handed a twin may come back";
|
||||
}
|
||||
} // namespace
|
||||
#endif // MOBILEGL_PIPE_PUSH
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
namespace fs = std::filesystem;
|
||||
const fs::path path = fs::temp_directory_path() /
|
||||
("mobilegl-shaderbufferemit-test-" + std::to_string(ProcessId()) + ".log");
|
||||
std::error_code ec;
|
||||
fs::remove(path, ec);
|
||||
g_logPath = path.string();
|
||||
#if defined(_WIN32)
|
||||
_putenv_s("MOBILEGL_LOG_FILE_PATH", g_logPath.c_str());
|
||||
#else
|
||||
setenv("MOBILEGL_LOG_FILE_PATH", g_logPath.c_str(), 1);
|
||||
#endif
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
MobileGL::Initialize();
|
||||
#endif
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
const int rc = RUN_ALL_TESTS();
|
||||
fs::remove(path, ec);
|
||||
return rc;
|
||||
}
|
||||
@@ -19,6 +19,9 @@
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
#include <Config.h>
|
||||
// P5e (sb): the binding-point shutter cases drive the REAL glBindBufferBase entry point,
|
||||
// because the claim they make is about what a frontend mutator publishes.
|
||||
#include <MG_Impl/GLImpl/Buffer/GL_Buffer.h>
|
||||
#include <MG_Impl/Pipe/CsoCache.h>
|
||||
#include <MG_Impl/Pipe/PipeFill.h>
|
||||
#include <MG_Impl/Pipe/SetHashSuppressor.h>
|
||||
@@ -85,6 +88,8 @@ namespace {
|
||||
X(TrackerWalk, AProgramSwitchAloneFiresTheSamplerViewBit) \
|
||||
X(TrackerWalk, ATextureParameterAloneFiresTheSamplerViewBit) \
|
||||
X(TrackerWalk, AProgramSwitchBetweenEqualImageUnitCountersFiresTheShaderImageBit) \
|
||||
X(TrackerWalk, ARebindOfOneUniformPointToADifferentBufferFiresTheConstBufferBit) \
|
||||
X(TrackerWalk, TheBindingPointBitsDoNotFireOnAnUnrelatedBufferWrite) \
|
||||
X(TrackerAttribPayload, AFloatWriteCarriesTheFloatBitsAndNamesItsClass) \
|
||||
X(TrackerAttribPayload, AnIntWriteCarriesTheIntWordsAndNamesItsClass) \
|
||||
X(TrackerAttribPayload, AUintWriteCarriesTheUintWordsAndNamesItsClass) \
|
||||
@@ -362,29 +367,44 @@ namespace {
|
||||
// keeps the name it was born with and follows the phase constant instead of a literal
|
||||
// five: what it has always asserted is "a bit names a subsystem if and only if this build
|
||||
// emits a call for it", which is the property the emission gate and the residual-fill
|
||||
// skip both rest on. P3a took the vertex-input family over and P4a takes seven more bits
|
||||
// across four subsystems, so the set it compares against is now kMGPipeDirtyEmittedAtP4a -
|
||||
// and a bit that gained an arm without gaining an emitter, or the reverse, still fails
|
||||
// here.
|
||||
// skip both rest on. P3a took the vertex-input family over, P4a took seven more bits across
|
||||
// four subsystems, and P5e takes THE LAST THREE onto kMGPipeSubsystemBufferBindings, so the
|
||||
// set it compares against is now kMGPipeDirtyEmittedAtP5e - and a bit that gained an arm
|
||||
// without gaining an emitter, or the reverse, still fails here.
|
||||
TEST_F(TrackerWalk, OnlyTheFiveEmittedBitsNameASubsystem) {
|
||||
for (SizeT i = 0; i < kMGPipeDirtyCount; ++i) {
|
||||
const auto bit = static_cast<MGPipeDirty>(i);
|
||||
const Bool emitted = (kMGPipeDirtyEmittedAtP4a & MGPipeDirtyBit(bit)) != 0;
|
||||
const Bool emitted = (kMGPipeDirtyEmittedAtP5e & MGPipeDirtyBit(bit)) != 0;
|
||||
EXPECT_EQ(MGPipeSubsystemForDirty(bit) != 0, emitted) << kMGPipeDirtyNames[i];
|
||||
}
|
||||
// Each phase's constant SURVIVES as the next phase's A/B control, so the three are
|
||||
// pinned as a chain rather than one being edited into the next: 0x1ff is P4a's "T2"
|
||||
// arm and 0x7f is P3a's, and an operator's recorded mask has to keep meaning what it
|
||||
// meant.
|
||||
EXPECT_EQ(kMGPipeDirtyEmittedAtP5e & kMGPipeDirtyEmittedAtP4a, kMGPipeDirtyEmittedAtP4a);
|
||||
EXPECT_EQ(kMGPipeDirtyEmittedAtP4a & kMGPipeDirtyEmittedAtP3a, kMGPipeDirtyEmittedAtP3a);
|
||||
EXPECT_EQ(kMGPipeDirtyEmittedAtP3a & kMGPipeDirtyEmittedAtP2, kMGPipeDirtyEmittedAtP2);
|
||||
// The three bits P4a still does not emit for - the const-buffer, shader-buffer and
|
||||
// stream-output sets - name no subsystem, so their fields keep going through the
|
||||
// residual fill. Stated positively as well as through the loop above, because "only
|
||||
// these three are left" is the phase's own scope statement.
|
||||
EXPECT_EQ(MGPipeSubsystemForDirty(MGPipeDirty::NewConstBuffers), 0u);
|
||||
EXPECT_EQ(MGPipeSubsystemForDirty(MGPipeDirty::NewShaderBuffers), 0u);
|
||||
EXPECT_EQ(MGPipeSubsystemForDirty(MGPipeDirty::NewSoTargets), 0u);
|
||||
// THE LAST THREE BITS, which P4a still did not emit for and P5e takes: the const-buffer,
|
||||
// shader-buffer and stream-output sets are ONE family - the indexed buffer binding
|
||||
// points - on ONE subsystem, so an operator clearing bit 13 gets the whole family's
|
||||
// frontend walk back rather than two thirds of it. Stated positively as well as through
|
||||
// the loop above, because "these three, together" is the phase's own scope statement.
|
||||
//
|
||||
// set_stream_output_targets stays UNEMITTED for the whole of P5e (XFB is lockstep by
|
||||
// escalation, MG_Remote/CONTRACT-P5E.md §5.7) and still names the subsystem, for the
|
||||
// same reason: the bit answers "which A/B switch owns this family's legacy arm", not
|
||||
// "is there a record on the wire for me today".
|
||||
EXPECT_EQ(MGPipeSubsystemForDirty(MGPipeDirty::NewConstBuffers),
|
||||
kMGPipeSubsystemBufferBindings);
|
||||
EXPECT_EQ(MGPipeSubsystemForDirty(MGPipeDirty::NewShaderBuffers),
|
||||
kMGPipeSubsystemBufferBindings);
|
||||
EXPECT_EQ(MGPipeSubsystemForDirty(MGPipeDirty::NewSoTargets),
|
||||
kMGPipeSubsystemBufferBindings);
|
||||
// AND THE PHASE CONSTANT IS NOW THE WHOLE BIT SET: after P5e every dirty bit names a
|
||||
// subsystem, so the loop above has no "names none" case left to exercise, and this is
|
||||
// what says so rather than leaving the loop looking stronger than it is.
|
||||
EXPECT_EQ(kMGPipeDirtyEmittedAtP5e,
|
||||
static_cast<Uint32>((Uint64{1} << kMGPipeDirtyCount) - 1u));
|
||||
EXPECT_EQ(MGPipeSubsystemForDirty(MGPipeDirty::NewRenderState), kMGPipeSubsystemRenderState);
|
||||
EXPECT_EQ(MGPipeSubsystemForDirty(MGPipeDirty::NewPixelPack), kMGPipeSubsystemPixelPack);
|
||||
EXPECT_EQ(MGPipeSubsystemForDirty(MGPipeDirty::NewPatchState), kMGPipeSubsystemPatchState);
|
||||
@@ -564,6 +584,76 @@ namespace {
|
||||
//
|
||||
// THIS IS THE ONE CASE THE OLD SHUTTER COULD NOT PASS, which is why it is here rather
|
||||
// than in the narrowing commit's prose.
|
||||
// ---- P5e (sb): the indexed binding points, bits 15/16/17 -------------------------
|
||||
//
|
||||
// THE RED-ONCE FOR THE SHUTTER REWRITE (CONTRACT-P5E.md §5.6, brief red-once (b)). Until
|
||||
// P5e all three bits shuttered on the buffer CONTENT aggregate, and glBindBufferBase moves
|
||||
// a binding point through a returned reference - BindingSlotRange1D::Bind, which advances
|
||||
// the slot's own Uint16 version - so this sequence fired NOTHING. Harmless while nothing
|
||||
// was emitted for the bits; an under-fire the moment set_shader_buffers is, because the
|
||||
// server would go on binding the first buffer. Same defect class as P4a's glBindSampler
|
||||
// hole, closed the same way: the shutter reads the generation the mutator moves.
|
||||
//
|
||||
// The action under test is the BIND ITSELF, through the real GL entry point, because the
|
||||
// claim is about what a frontend mutator publishes and not about what a generation does
|
||||
// once bumped (ID-102).
|
||||
TEST_F(TrackerWalk, ARebindOfOneUniformPointToADifferentBufferFiresTheConstBufferBit) {
|
||||
GLuint a = 0;
|
||||
GLuint b = 0;
|
||||
MG_Impl::GLImpl::GenBuffers(1, &a);
|
||||
MG_Impl::GLImpl::GenBuffers(1, &b);
|
||||
|
||||
MG_Impl::GLImpl::BindBufferBase(GL_UNIFORM_BUFFER, 1, a);
|
||||
Walk();
|
||||
Walk();
|
||||
ASSERT_EQ(m_tracker.LastDirty() & MGPipeDirtyBit(MGPipeDirty::NewConstBuffers), 0u)
|
||||
<< "the steady state must be quiet before the interesting half of this case";
|
||||
|
||||
// The same point, a different buffer. Nothing about any buffer's CONTENTS moved.
|
||||
MG_Impl::GLImpl::BindBufferBase(GL_UNIFORM_BUFFER, 1, b);
|
||||
Walk();
|
||||
EXPECT_NE(m_tracker.LastDirty() & MGPipeDirtyBit(MGPipeDirty::NewConstBuffers), 0u)
|
||||
<< "NEW_CONST_BUFFERS did not fire when a uniform binding point moved onto another "
|
||||
"buffer - the emitted window would still name the first one";
|
||||
// And the unbind, which is the case a shutter may least afford to miss: it leaves the
|
||||
// high-water mark where it was, so nothing but the generation can carry it.
|
||||
Walk();
|
||||
ASSERT_EQ(m_tracker.LastDirty() & MGPipeDirtyBit(MGPipeDirty::NewConstBuffers), 0u);
|
||||
MG_Impl::GLImpl::BindBufferBase(GL_UNIFORM_BUFFER, 1, 0);
|
||||
Walk();
|
||||
EXPECT_NE(m_tracker.LastDirty() & MGPipeDirtyBit(MGPipeDirty::NewConstBuffers), 0u)
|
||||
<< "NEW_CONST_BUFFERS did not fire for an unbind";
|
||||
m_cache.Reset();
|
||||
}
|
||||
|
||||
// The other half of the rewrite, and the reason it is a narrowing rather than a swap: the
|
||||
// content aggregate LEFT all three bits, so a glBufferSubData into an unrelated buffer no
|
||||
// longer republishes every binding-point set in the context. Whether the BYTES behind a
|
||||
// bound buffer moved is the resource family's question, answered server-side by the
|
||||
// resource record's own Serial; what these records carry is {handle, offset, size}.
|
||||
TEST_F(TrackerWalk, TheBindingPointBitsDoNotFireOnAnUnrelatedBufferWrite) {
|
||||
GLuint bound = 0;
|
||||
MG_Impl::GLImpl::GenBuffers(1, &bound);
|
||||
MG_Impl::GLImpl::BindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, bound);
|
||||
Walk();
|
||||
Walk();
|
||||
const Uint32 family = MGPipeDirtyBit(MGPipeDirty::NewConstBuffers) |
|
||||
MGPipeDirtyBit(MGPipeDirty::NewShaderBuffers) |
|
||||
MGPipeDirtyBit(MGPipeDirty::NewSoTargets);
|
||||
ASSERT_EQ(m_tracker.LastDirty() & family, 0u)
|
||||
<< "the steady state must be quiet before the interesting half of this case";
|
||||
|
||||
const SharedPtr<MG_State::GLState::BufferObject> unrelated = Ctx().CreateBufferObject(64);
|
||||
unrelated->Respecify(4096, nullptr);
|
||||
Array<Uint8, 16> bytes{};
|
||||
unrelated->UploadSubData(DataPtr{bytes.data(), bytes.size()}, 0);
|
||||
ASSERT_NE(Ctx().GetAnyBufferChangeGeneration(), 0u) << "the buffer aggregate did move";
|
||||
Walk();
|
||||
EXPECT_EQ(m_tracker.LastDirty() & family, 0u)
|
||||
<< "a write to a buffer bound to no binding point republished the binding-point sets";
|
||||
m_cache.Reset();
|
||||
}
|
||||
|
||||
TEST_F(TrackerWalk, TheIndexBufferBitDoesNotFireOnAnUnrelatedBufferWrite) {
|
||||
const SharedPtr<MG_State::GLState::BufferObject> indices = Ctx().CreateBufferObject(1);
|
||||
indices->Respecify(64, nullptr);
|
||||
|
||||
@@ -129,6 +129,7 @@ namespace {
|
||||
X(VertexInputEmit, IsLongAndFloat64TravelSeparately) \
|
||||
X(VertexInputEmit, ABaseInstanceChangeAloneStillEmitsTheVertexBufferSet) \
|
||||
X(VertexInputEmit, AnUnchangedSetWithAnUnchangedBaseInstanceEmitsNothing) \
|
||||
X(VertexInputEmit, TheVertexBufferWindowCoversEveryAttributeTheCsoDeclaresEnabled) \
|
||||
X(VertexInputEmit, RebindingTheSameVaoEmitsABindAndNoCreate) \
|
||||
X(VertexInputEmit, PingPongingBetweenTwoVaosNeverRecreatesEither) \
|
||||
X(VertexInputEmit, DestroyedVertexArraysReturnTheirCsoSlotsAndRecords) \
|
||||
@@ -433,6 +434,78 @@ namespace {
|
||||
EXPECT_EQ(Emitter().VertexBufferSetCount(), 2u);
|
||||
}
|
||||
|
||||
// ==================== P5e (vi), ID-95 / ruling 19 / CONTRACT-P5E §5.3 ====================
|
||||
//
|
||||
// THE WINDOW RULE, PINNED RATHER THAN ARGUED: set_vertex_buffers' window must COVER every
|
||||
// attribute the vertex-elements CSO declares ENABLED.
|
||||
//
|
||||
// Why it needs a case at all (scout S1's caveat R4). The two views are emitted from the
|
||||
// same validate step and both walk the same `Enabled` bits, so today they cannot disagree -
|
||||
// which is exactly the shape of unpinned invariant that a later narrowing turns into a
|
||||
// silent wrong picture. An attribute the RECORD says is enabled but that falls outside the
|
||||
// window resolves VertexBufferForAttributeIndex == nullptr on the server and is SKIPPED at
|
||||
// the attribute walk (Managers.cpp): the array stays enabled in the driver VAO with no
|
||||
// buffer bound under it, which is not a refusal and not a black triangle, it is whatever
|
||||
// that attribute last pointed at.
|
||||
//
|
||||
// The oracle is the RECORD, not the emitter's arithmetic: whatever create_vertex_elements
|
||||
// declared enabled must be inside [Start, Start+Count). Sparse on purpose - a hole at 1..6
|
||||
// is what distinguishes "the window covers the enabled set" from "the window happens to be
|
||||
// as long as the attribute array".
|
||||
//
|
||||
// The sink half is CheckUnitWindows (tx2's, called at every draw/dispatch), whose verdict
|
||||
// for a narrow window is Fatal{ProtocolCorruption, "SetVertexBuffers.Count"}. This case is
|
||||
// the PRODUCER half and is the one that goes red if the emitter narrows.
|
||||
TEST(VertexInputEmit, TheVertexBufferWindowCoversEveryAttributeTheCsoDeclaresEnabled) {
|
||||
EmitterScope scope;
|
||||
const SharedPtr<VertexArrayObject> vao = MakeVao(1);
|
||||
const SharedPtr<BufferObject> buffer = Ctx().CreateBufferObject(1);
|
||||
buffer->Respecify(4096, nullptr);
|
||||
|
||||
// Enabled: 0 and 7. Disabled: everything between, and everything above.
|
||||
const Uint kEnabled[] = {0u, 7u};
|
||||
for (Uint index : kEnabled) {
|
||||
vao->SetAttributeFormat(index, 4, DataType::Float32, false, 16, 0, false);
|
||||
vao->BindAttributeBuffer(index, buffer);
|
||||
vao->EnableAttribute(index);
|
||||
}
|
||||
|
||||
ASSERT_GT(Emitter().EmitVertexElements(Ctx()), 0u);
|
||||
ASSERT_GT(Emitter().EmitVertexBuffers(Ctx(), 0), 0u);
|
||||
|
||||
const MGPVertexBuffers& window = Emitter().LastVertexBuffers();
|
||||
const auto& declared = Emitter().LastAttributes();
|
||||
const Uint32 declaredCount = Emitter().LastElements().AttributeCount;
|
||||
|
||||
Uint32 covered = 0;
|
||||
for (Uint32 i = 0; i < declaredCount; ++i) {
|
||||
if (!declared[i].Enabled) continue;
|
||||
++covered;
|
||||
SCOPED_TRACE(::testing::Message() << "attribute " << i);
|
||||
EXPECT_GE(i, window.Start)
|
||||
<< "create_vertex_elements declares attribute " << i
|
||||
<< " ENABLED but set_vertex_buffers' window starts at " << window.Start
|
||||
<< ". The backend resolves no binding for it and SKIPS it, leaving the driver "
|
||||
"array enabled over whatever it last pointed at (ID-95 / ruling 19)";
|
||||
EXPECT_LT(i, window.Start + window.Count)
|
||||
<< "create_vertex_elements declares attribute " << i
|
||||
<< " ENABLED but set_vertex_buffers' window ends at " << (window.Start + window.Count)
|
||||
<< " - the same skip, at the other end. A narrower window is the sink's "
|
||||
"Fatal{ProtocolCorruption, \"SetVertexBuffers.Count\"}";
|
||||
}
|
||||
ASSERT_EQ(covered, 2u)
|
||||
<< "the record did not declare the two attributes this case enabled, so the window "
|
||||
"check above had nothing to be about";
|
||||
|
||||
// And the window's own entries agree with the record about WHICH attribute each is, so
|
||||
// "covered" cannot be satisfied by a window of the right LENGTH over the wrong indices.
|
||||
for (Uint32 i = 0; i < window.Count; ++i) {
|
||||
EXPECT_EQ(Emitter().LastEntries()[i].BindingIndex, window.Start + i)
|
||||
<< "entry " << i << " of the window does not name attribute " << (window.Start + i)
|
||||
<< "; the server indexes this window BY ATTRIBUTE";
|
||||
}
|
||||
}
|
||||
|
||||
// D-G3's per-handle latch. create_vertex_elements is re-issued on the SAME handle when a
|
||||
// configuration moves, and the latch is stored per handle rather than globally so that
|
||||
// rebinding cannot look like a configuration change.
|
||||
|
||||
@@ -3141,6 +3141,95 @@ TEST(DirectGLESTextureSync, UnitMemoRefusesToDriveATwinFromAnotherTexture) {
|
||||
MG_Impl::GLImpl::BindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P5e (tx2), CONTRACT-P5E §4.3: THE HANDLE ARM'S SIBLING OF THE CASE ABOVE, WITH ABA AS THE
|
||||
// HAZARD INSTEAD OF A SILENT SLOT SWAP.
|
||||
//
|
||||
// The case above pins what the BORROWED-SLOT work list needs: a pointer compare per entry,
|
||||
// because its key is derived state and a slot swap that never reached the key would drive
|
||||
// texture A's twin from texture B. The by-handle work list carries no such pointer and no
|
||||
// PairingsIntact, and this is the argument for why it does not have to:
|
||||
//
|
||||
// a handle is {slot, gen}. A slot recycled to a NEW object arrives as {s, g+1}, and
|
||||
// GetOrCreateByHandle RESETS the entry on a forward generation (SlotTables.h) - so the
|
||||
// successor gets a fresh twin with a fresh driver texture, and the predecessor's handle
|
||||
// stops resolving. There is no window in which one handle names two objects, which is
|
||||
// exactly the window the pointer compare above exists to close.
|
||||
//
|
||||
// THE RED: drop the forward-Gen reset (make GetOrCreate return the live entry for any
|
||||
// generation) and `reMinted` below is the SAME twin as `first` - the successor inherits its
|
||||
// predecessor's driver texture and its predecessor's synced serials, so the first draw that
|
||||
// samples it reads the dead object's pixels and the clean gate says there is nothing to do.
|
||||
TEST(DirectGLESTextureSync, ARecycledTextureSlotReMintsTheTwinOnTheHandleArm) {
|
||||
using namespace MobileGL;
|
||||
using namespace MobileGL::MG_Backend::DirectGLES;
|
||||
ScopedDirectGLESTextureBindings scoped; // fresh GLContext + registry + binding caches
|
||||
// The {slot, gen} table is what this case is about; the FAMILY bit is not.
|
||||
if (!EsprytSlotTablesEnabled()) {
|
||||
GTEST_SKIP() << "the {slot, gen} twin table arm is not selected in this configuration";
|
||||
}
|
||||
|
||||
// ON THE REAL TEXTURE REGISTRY, not a fake one: id's DirectGLESSlotTable cases pin the
|
||||
// TABLE's rule in isolation, and this pins that the table tx2's work list indexes is the one
|
||||
// that keeps it. Two lifetime ids stand in for two frontend textures, so the client
|
||||
// allocator hands the SAME SLOT back at a higher generation for the second - the hazard.
|
||||
//
|
||||
// No applier record and no SyncTextureToBackendByHandle here: MGPipeApplyResourceCreate
|
||||
// declines for a texture on a process with no P4a consumer (NoP4aConsumer), which is every
|
||||
// unit-lane process, and the ABA answer is the twin TABLE's rather than the record's.
|
||||
auto firstOwner = MakeShared<MG_State::GLState::SamplerObject>(0u);
|
||||
const MG_Pipe::MGPipeHandle first =
|
||||
MG_Pipe::MGPipeSlots().Acquire(MG_Pipe::MGPipeKind::Texture, firstOwner->GetLifetimeId());
|
||||
ASSERT_FALSE(MG_Pipe::MGPipeHandleIsNull(first));
|
||||
|
||||
auto& registry = TextureImpl::g_backendTextureObjects;
|
||||
auto* firstSlot = registry.GetOrCreateByHandle(first);
|
||||
ASSERT_NE(firstSlot, nullptr);
|
||||
if (!*firstSlot) *firstSlot = MakeShared<TextureImpl::BackendTextureObject>();
|
||||
(*firstSlot)->NotePushedSyncHandle(first);
|
||||
ASSERT_EQ((*firstSlot)->PushedSyncHandle().Slot, first.Slot);
|
||||
|
||||
// The recycle: the client frees the slot and hands it straight back out at {s, g+1}.
|
||||
MG_Pipe::MGPipeSlots().Free(MG_Pipe::MGPipeKind::Texture, first);
|
||||
auto secondOwner = MakeShared<MG_State::GLState::SamplerObject>(0u);
|
||||
const MG_Pipe::MGPipeHandle second =
|
||||
MG_Pipe::MGPipeSlots().Acquire(MG_Pipe::MGPipeKind::Texture, secondOwner->GetLifetimeId());
|
||||
ASSERT_FALSE(MG_Pipe::MGPipeHandleIsNull(second));
|
||||
ASSERT_EQ(second.Slot, first.Slot) << "the allocator did not recycle the slot, so this case "
|
||||
"is not exercising ABA at all";
|
||||
ASSERT_GT(second.Gen, first.Gen);
|
||||
|
||||
auto* secondSlot = registry.GetOrCreateByHandle(second);
|
||||
ASSERT_NE(secondSlot, nullptr);
|
||||
EXPECT_EQ(*secondSlot, nullptr)
|
||||
<< "the successor at a recycled texture slot inherited its predecessor's twin: it would "
|
||||
"sample the dead object's driver texture, and the twin's synced serials and noted "
|
||||
"handle would tell the clean gate there is nothing to do";
|
||||
// DELIBERATELY NOT A POINTER COMPARE against the predecessor's twin: the reset released it,
|
||||
// so the allocator is free to hand the successor's twin the very same heap address - which
|
||||
// it does, and which is exactly why a raw address is never an identity in this tree
|
||||
// (section 4.2.1). "The slot came back empty" is the assertion; "it came back at a different
|
||||
// address" is a coincidence that would make this case pass for the wrong reason.
|
||||
if (!*secondSlot) *secondSlot = MakeShared<TextureImpl::BackendTextureObject>();
|
||||
EXPECT_TRUE(MG_Pipe::MGPipeHandleIsNull((*secondSlot)->PushedSyncHandle()))
|
||||
<< "the re-minted twin kept the dead handle, so its sync prologues would resolve the "
|
||||
"predecessor's record";
|
||||
|
||||
// ...and the predecessor's handle stops resolving, which is what makes a stale entry left in
|
||||
// a by-handle work list harmless: the lookup answers null and the entry is skipped, where a
|
||||
// borrowed slot would have been replayed against the wrong object.
|
||||
EXPECT_EQ(registry.FindByHandle(first), nullptr)
|
||||
<< "the predecessor's handle still resolves at a recycled slot";
|
||||
|
||||
MG_Pipe::MGPipeSlots().Free(MG_Pipe::MGPipeKind::Texture, second);
|
||||
}
|
||||
#else
|
||||
// G2/G14: the same ctest entry exists in the pull build and skips visibly.
|
||||
TEST(DirectGLESTextureSync, ARecycledTextureSlotReMintsTheTwinOnTheHandleArm) {
|
||||
GTEST_SKIP() << "the by-handle texture twin is compiled only under MOBILEGL_PIPE_PUSH";
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
// What glTexParameteri actually reached the driver, and which backend texture was bound
|
||||
// when it did. The G9 probe below is a WHITE-BOX assertion (ID-19): the parameter push is
|
||||
@@ -3410,6 +3499,12 @@ namespace {
|
||||
BackendSlotTable<FakeStateObject, FakeBackendObject, MobileGL::MG_Pipe::MGPipeKind::Query>;
|
||||
using FakeSharedKindSlotTable = MobileGL::MG_Backend::DirectGLES::
|
||||
BackendSlotTable<FakeStateObject, FakeBackendObject, MobileGL::MG_Pipe::MGPipeKind::Fence>;
|
||||
// P5e (id): ShaderCso is the ONE kind with a composite band, so the band case needs a table
|
||||
// of that kind. It never touches MGPipeSlots() - the whole case runs through the by-handle
|
||||
// overloads - and the holder list is per TABLE TYPE, so this instantiation shares nothing
|
||||
// with the real g_backendProgramObjects.
|
||||
using FakeShaderCsoSlotTable = MobileGL::MG_Backend::DirectGLES::
|
||||
BackendSlotTable<FakeStateObject, FakeBackendObject, MobileGL::MG_Pipe::MGPipeKind::ShaderCso>;
|
||||
|
||||
// A log file path no other process and no other case can be writing to: the pid keeps two
|
||||
// SanityTest processes on one host apart, the counter keeps two cases in one process apart.
|
||||
@@ -4932,6 +5027,234 @@ TEST(DirectGLESSlotTable, AGenerationBehindTheLiveTwinIsRefusedRatherThanAdopted
|
||||
EXPECT_EQ(table.FindByHandle(MG_Pipe::MGPipeHandle{FakeSlotTable::kMaxHandleSlot, 1u}), nullptr);
|
||||
}
|
||||
|
||||
// P5e (id), CONTRACT-P5E §4.3's last paragraph: THE COMPOSITE BAND, and why it is a P5e
|
||||
// prerequisite rather than a follow-up.
|
||||
//
|
||||
// A program-pipeline composite's ShaderCso slot comes out of the reserved top 1/16 of the slot
|
||||
// space (kMGPipeShaderCsoCompositeSlotBase = 983040). EntryAt indexes BY SLOT and resizes to
|
||||
// it, so before the band a single composite grew g_backendProgramObjects to ~983k entries of
|
||||
// ~40 B - ~40 MB for one glBindProgramPipeline. That was reachable only through
|
||||
// GetOrCreate(StatePtr) for a composite program; after id's rekey the by-handle resolution IS
|
||||
// the ordinary path (ResolveProgramTwin), so every composite bind would pay it.
|
||||
//
|
||||
// THE RED: make EntryAt index m_slots unconditionally again (drop the SlotIsBanded branch) and
|
||||
// the first assertion below goes from 0 to 983044. LiveCount alone could not see that - the
|
||||
// table would hold exactly one live entry either way - which is why the case asserts on the
|
||||
// two spaces' CAPACITIES and not on liveness.
|
||||
TEST(DirectGLESSlotTable, ACompositeHandleDoesNotGrowTheOrdinaryTable) {
|
||||
using namespace MobileGL;
|
||||
using namespace MobileGL::MG_Backend::DirectGLES;
|
||||
|
||||
FakeShaderCsoSlotTable table;
|
||||
const MG_Pipe::MGPipeHandle composite{MG_Pipe::kMGPipeShaderCsoCompositeSlotBase + 3u, 1u};
|
||||
ASSERT_TRUE(MG_Pipe::MGPipeIsCompositeShaderSlot(composite.Slot));
|
||||
|
||||
auto& twin = table.GetOrCreate(composite);
|
||||
twin = MakeShared<FakeBackendObject>();
|
||||
twin->marker = 0x5A;
|
||||
|
||||
EXPECT_EQ(table.OrdinaryCapacityForTest(), 0u)
|
||||
<< "a composite slot grew the ORDINARY table - one program pipeline is ~40 MB of twin "
|
||||
"entries for a single live program";
|
||||
EXPECT_EQ(table.CompositeCapacityForTest(), 4u)
|
||||
<< "the band is indexed by (slot - base), so slot base+3 needs exactly four entries";
|
||||
EXPECT_EQ(table.LiveCount(), 1u);
|
||||
EXPECT_EQ(table.CompositeLiveCount(), 1u) << "the live composite was counted in the wrong space";
|
||||
|
||||
auto* const found = table.FindByHandle(composite);
|
||||
ASSERT_NE(found, nullptr) << "the band entry is invisible to the lookup that has to find it";
|
||||
EXPECT_EQ((*found)->marker, 0x5A);
|
||||
|
||||
// An ordinary ShaderCso lands in the ordinary space and disturbs neither the band's
|
||||
// contents nor its size: the two are dense against their OWN high-water marks.
|
||||
auto& ordinary = table.GetOrCreate(MG_Pipe::MGPipeHandle{5u, 1u});
|
||||
ordinary = MakeShared<FakeBackendObject>();
|
||||
EXPECT_EQ(table.OrdinaryCapacityForTest(), 6u);
|
||||
EXPECT_EQ(table.CompositeCapacityForTest(), 4u);
|
||||
EXPECT_EQ(table.CompositeLiveCount(), 1u);
|
||||
|
||||
// ForEachLive reports the composite at THE SLOT THE CLIENT MINTED, never the band index -
|
||||
// the handle it hands over is the one a caller turns straight back into a record lookup.
|
||||
Vector<Uint32> walked;
|
||||
table.ForEachLive([&](MG_Pipe::MGPipeHandle handle, const SharedPtr<FakeBackendObject>&) {
|
||||
walked.push_back(handle.Slot);
|
||||
});
|
||||
ASSERT_EQ(walked.size(), 2u);
|
||||
EXPECT_EQ(walked[0], 5u) << "the ordinary space is walked first, at its own slot";
|
||||
EXPECT_EQ(walked[1], composite.Slot)
|
||||
<< "the band was reported at its INDEX rather than at the client's slot, so a caller "
|
||||
"resolving the record for it would read another program's";
|
||||
|
||||
// §4.3's recycle answer holds inside the band exactly as it does outside it.
|
||||
auto& recycled = table.GetOrCreate(MG_Pipe::MGPipeHandle{composite.Slot, 2u});
|
||||
EXPECT_EQ(recycled, nullptr) << "a successor at a recycled composite slot inherited its "
|
||||
"predecessor's driver program";
|
||||
EXPECT_EQ(table.FindByHandle(composite), nullptr) << "the predecessor's handle still resolves";
|
||||
EXPECT_EQ(table.CompositeCapacityForTest(), 4u) << "the recycle re-grew the band";
|
||||
}
|
||||
|
||||
// ==========================================================================================
|
||||
// P5e (vi), CONTRACT-P5E §5.1: THE DRAW'S BUFFERS COME FROM THE RECORD, NOT FROM THE VAO.
|
||||
// ==========================================================================================
|
||||
//
|
||||
// The two cases below are BRIEF-P5E's red-onces (2) and (3) for this package, and they are
|
||||
// built the way ID-102 says a red-once has to be: the thing under test is THE PRODUCTION
|
||||
// DECISION ITSELF (BufferImpl::ResolveDrawVertexBuffersFromRecord and
|
||||
// ResolveDrawIndexBufferFromRecord, which are the only enumeration
|
||||
// SyncNeccessaryBuffers' record arm has), not a copy of it written here. Both take the applier
|
||||
// state and NOTHING ELSE, so the only way to revert §5.1's substitution is to put a frontend
|
||||
// read back inside one of them - and then these go red naming the field.
|
||||
//
|
||||
// THE SETUP IS THE DIVERGENCE ITSELF: the frontend VAO is pointed at a buffer the RECORD does
|
||||
// not name. That state is unreachable in one process today (the client re-emits at every
|
||||
// validate point, so the two always agree); under run-ahead it is the ordinary state of the
|
||||
// world, because the client has moved on by the time the record is applied. Producing it here
|
||||
// by hand is the only way to ask "which one did you read" at all.
|
||||
//
|
||||
// WHAT IS NOT HERE, and deliberately: the ensure, the memo and the clean probe. They need an ES
|
||||
// context and a driver, and DirectGLES.Split.* is where they are exercised
|
||||
// (ClientVertexArrayScenario, TriangleScenario, IndexedDrawFamilyScenario and the rest of the
|
||||
// lane draw through exactly this arm).
|
||||
TEST(DirectGLESVertexInputDraw, TheAttributeWalkTakesItsBuffersFromTheRecordNotTheFrontendVao) {
|
||||
using namespace MobileGL;
|
||||
using namespace MobileGL::MG_Backend::DirectGLES;
|
||||
using namespace MobileGL::MG_State::GLState;
|
||||
#if !MOBILEGL_BUILD_DISAGGREGATED
|
||||
GTEST_SKIP() << "the record arm of the attribute walk is compiled only under "
|
||||
"MOBILEGL_BUILD_DISAGGREGATED";
|
||||
#else
|
||||
// A, B and C, with handles minted the way the client mints them.
|
||||
auto bufferA = MakeShared<BufferObject>(0u);
|
||||
auto bufferB = MakeShared<BufferObject>(0u);
|
||||
auto bufferC = MakeShared<BufferObject>(0u);
|
||||
const MG_Pipe::MGPipeHandle a =
|
||||
MG_Pipe::MGPipeSlots().Acquire(MG_Pipe::MGPipeKind::Buffer, bufferA->GetLifetimeId());
|
||||
const MG_Pipe::MGPipeHandle b =
|
||||
MG_Pipe::MGPipeSlots().Acquire(MG_Pipe::MGPipeKind::Buffer, bufferB->GetLifetimeId());
|
||||
const MG_Pipe::MGPipeHandle c =
|
||||
MG_Pipe::MGPipeSlots().Acquire(MG_Pipe::MGPipeKind::Buffer, bufferC->GetLifetimeId());
|
||||
ASSERT_FALSE(MG_Pipe::MGPipeHandleIsNull(a));
|
||||
ASSERT_FALSE(MG_Pipe::MGPipeHandleIsNull(b));
|
||||
ASSERT_FALSE(MG_Pipe::MGPipeHandleIsNull(c));
|
||||
|
||||
// THE PUBLISHED STATE: attribute 0 fetches from A, attribute 1 from B, attribute 2 from A
|
||||
// again (the dedupe), attribute 3 is a client-memory array (null Res, nothing to ensure).
|
||||
MG_Pipe::MGPipeApplierState& st = MG_Pipe::MGPipeApplier();
|
||||
const MG_Pipe::MGPipeApplierState saved = st;
|
||||
st.VertexBufferStart = 0;
|
||||
st.VertexBufferCount = 4;
|
||||
for (Uint32 i = 0; i < 4; ++i) {
|
||||
st.VertexBuffers[i] = MG_Pipe::MGPVertexBuffer{};
|
||||
st.VertexBuffers[i].BindingIndex = i;
|
||||
}
|
||||
st.VertexBuffers[0].Res = a;
|
||||
st.VertexBuffers[1].Res = b;
|
||||
st.VertexBuffers[2].Res = a;
|
||||
st.VertexBuffers[3].Res = MG_Pipe::kMGPipeNullHandle;
|
||||
|
||||
// THE FRONTEND, MOVED ON: every enabled attribute now points at C, and nothing was
|
||||
// re-emitted. A walk that read GetAllAttributes() answers {C}. The VAO is BOUND IN A REAL
|
||||
// CONTEXT rather than free-standing, because that is the only shape in which the revert
|
||||
// this case exists to catch - MGB_CTX->GetBoundVertexArray()->GetAllAttributes() - has
|
||||
// anything to read at all; a free-standing object would make the revert crash instead of
|
||||
// disagree, which is a red for the wrong reason.
|
||||
UniquePtr<GLContext> previousContext = Move(MG_State::pGLContext);
|
||||
MG_State::pGLContext = MakeUnique<GLContext>();
|
||||
MG_State::pGLContext->CreateVertexArrayObject(1);
|
||||
MG_State::pGLContext->BindVertexArray(1);
|
||||
const SharedPtr<VertexArrayObject> vao = MG_State::pGLContext->GetBoundVertexArray();
|
||||
ASSERT_NE(vao, nullptr);
|
||||
for (Uint i = 0; i < 4; ++i) {
|
||||
vao->SetAttributeFormat(i, 2, DataType::Float32, false, 8, 0, false, false, 8);
|
||||
vao->BindAttributeBuffer(i, bufferC);
|
||||
vao->EnableAttribute(i);
|
||||
}
|
||||
|
||||
BufferImpl::DrawVertexBufferRequest requests[VertexArrayObject::MAX_VERTEX_ATTRIBS];
|
||||
const Uint count = BufferImpl::ResolveDrawVertexBuffersFromRecord(
|
||||
st, requests, VertexArrayObject::MAX_VERTEX_ATTRIBS);
|
||||
|
||||
ASSERT_EQ(count, 2u)
|
||||
<< "the walk did not resolve st.VertexBuffers[Start..+Count): two DISTINCT handles are "
|
||||
"named there (A twice and B), plus one client-memory array with no store to ensure";
|
||||
EXPECT_EQ(requests[0].Res, a)
|
||||
<< "the first buffer is not st.VertexBuffers[0].Res. If it is the frontend VAO's C, the "
|
||||
"walk went back to GetAllAttributes() and §5.1's substitution is reverted";
|
||||
EXPECT_EQ(requests[1].Res, b) << "the second buffer is not st.VertexBuffers[1].Res";
|
||||
EXPECT_EQ(requests[0].BindingIndex, 0u);
|
||||
EXPECT_EQ(requests[1].BindingIndex, 1u);
|
||||
for (Uint i = 0; i < count; ++i) {
|
||||
EXPECT_NE(requests[i].Res, c)
|
||||
<< "the walk ensured the buffer the FRONTEND VAO points at, which is the object a "
|
||||
"run-ahead client has already moved on from";
|
||||
}
|
||||
|
||||
st = saved;
|
||||
MG_State::pGLContext.reset();
|
||||
MG_State::pGLContext = Move(previousContext);
|
||||
MG_Pipe::MGPipeSlots().Free(MG_Pipe::MGPipeKind::Buffer, a);
|
||||
MG_Pipe::MGPipeSlots().Free(MG_Pipe::MGPipeKind::Buffer, b);
|
||||
MG_Pipe::MGPipeSlots().Free(MG_Pipe::MGPipeKind::Buffer, c);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Red-once (3), the index half. The claim has TWO parts and the second is what this package
|
||||
// added: the handle comes from st.IndexBuffer.Res, and IndexBufferSerial comes with it - the
|
||||
// legacy and push-monolith arms re-read the VAO's element slot on every indexed draw and so see
|
||||
// a rebind for free, while this arm reads nothing and needs the serial in the key
|
||||
// (ResolvedDrawBuffers::iboSerial). A rebind of the SAME buffer still moves the serial, which is
|
||||
// exactly the case an identity-only compare would call a hit.
|
||||
TEST(DirectGLESVertexInputDraw, TheIndexArmTakesItsBufferAndItsSerialFromTheRecord) {
|
||||
using namespace MobileGL;
|
||||
using namespace MobileGL::MG_Backend::DirectGLES;
|
||||
using namespace MobileGL::MG_State::GLState;
|
||||
#if !MOBILEGL_BUILD_DISAGGREGATED
|
||||
GTEST_SKIP() << "the record arm of the index-buffer sync is compiled only under "
|
||||
"MOBILEGL_BUILD_DISAGGREGATED";
|
||||
#else
|
||||
auto published = MakeShared<BufferObject>(0u);
|
||||
auto rebound = MakeShared<BufferObject>(0u);
|
||||
const MG_Pipe::MGPipeHandle publishedHandle =
|
||||
MG_Pipe::MGPipeSlots().Acquire(MG_Pipe::MGPipeKind::Buffer, published->GetLifetimeId());
|
||||
ASSERT_FALSE(MG_Pipe::MGPipeHandleIsNull(publishedHandle));
|
||||
|
||||
MG_Pipe::MGPipeApplierState& st = MG_Pipe::MGPipeApplier();
|
||||
const MG_Pipe::MGPipeApplierState saved = st;
|
||||
st.IndexBuffer = MG_Pipe::MGPIndexBuffer{};
|
||||
st.IndexBuffer.Res = publishedHandle;
|
||||
st.IndexBufferSerial = 11;
|
||||
|
||||
// The frontend's element slot has moved to another buffer with nothing emitted, in a real
|
||||
// context for the reason the case above gives.
|
||||
UniquePtr<GLContext> previousContext = Move(MG_State::pGLContext);
|
||||
MG_State::pGLContext = MakeUnique<GLContext>();
|
||||
MG_State::pGLContext->CreateVertexArrayObject(1);
|
||||
MG_State::pGLContext->BindVertexArray(1);
|
||||
const SharedPtr<VertexArrayObject> vao = MG_State::pGLContext->GetBoundVertexArray();
|
||||
ASSERT_NE(vao, nullptr);
|
||||
vao->GetIndexBufferBindingSlot().Bind(rebound);
|
||||
|
||||
BufferImpl::DrawIndexBufferRequest request = BufferImpl::ResolveDrawIndexBufferFromRecord(st);
|
||||
EXPECT_EQ(request.Res, publishedHandle)
|
||||
<< "the index arm did not read st.IndexBuffer.Res; if it answered the VAO's element "
|
||||
"slot it is reading a binding the client has already changed";
|
||||
EXPECT_EQ(request.Serial, 11u) << "IndexBufferSerial did not travel with the handle";
|
||||
|
||||
// The same buffer re-bound: the handle is unchanged and ONLY the serial says so.
|
||||
st.IndexBufferSerial = 12;
|
||||
request = BufferImpl::ResolveDrawIndexBufferFromRecord(st);
|
||||
EXPECT_EQ(request.Res, publishedHandle);
|
||||
EXPECT_EQ(request.Serial, 12u)
|
||||
<< "a re-emitted set_index_buffer on the SAME handle is invisible to this arm without "
|
||||
"the serial, and the memo would read clean over it";
|
||||
|
||||
st = saved;
|
||||
MG_State::pGLContext.reset();
|
||||
MG_State::pGLContext = Move(previousContext);
|
||||
MG_Pipe::MGPipeSlots().Free(MG_Pipe::MGPipeKind::Buffer, publishedHandle);
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
// G2 wants the pull and the push build to list the SAME ctest entries. The twin table only
|
||||
// exists under MOBILEGL_PIPE_PUSH, so in the pull build each case above keeps its name and
|
||||
@@ -5012,6 +5335,10 @@ TEST(DirectGLESSlotTable, AGenerationBehindTheLiveTwinIsRefusedRatherThanAdopted
|
||||
GTEST_SKIP() << "the {slot, gen} twin table is compiled only under MOBILEGL_PIPE_PUSH";
|
||||
}
|
||||
|
||||
TEST(DirectGLESSlotTable, ACompositeHandleDoesNotGrowTheOrdinaryTable) {
|
||||
GTEST_SKIP() << "the {slot, gen} twin table is compiled only under MOBILEGL_PIPE_PUSH";
|
||||
}
|
||||
|
||||
TEST(DirectGLESSlotTable, ADeathNoticeForEveryP4aKindIsIdempotent) {
|
||||
GTEST_SKIP() << "the {slot, gen} twin table is compiled only under MOBILEGL_PIPE_PUSH";
|
||||
}
|
||||
@@ -5027,4 +5354,11 @@ TEST(DirectGLESBufferDrawProbe, UnderSplitTheRecordAloneAnswersTheLiveHostMapQue
|
||||
TEST(DirectGLESBufferDrawProbe, ACapsMaskWithoutTheResourceFamilyEmitsNothingAndCountsTheRefusal) {
|
||||
GTEST_SKIP() << "the handle-keyed resource table is compiled only under MOBILEGL_PIPE_PUSH";
|
||||
}
|
||||
// P5e (vi): G2/G14's skip twins for the two record-arm cases above.
|
||||
TEST(DirectGLESVertexInputDraw, TheAttributeWalkTakesItsBuffersFromTheRecordNotTheFrontendVao) {
|
||||
GTEST_SKIP() << "the record arm of the attribute walk is compiled only under MOBILEGL_PIPE_PUSH";
|
||||
}
|
||||
TEST(DirectGLESVertexInputDraw, TheIndexArmTakesItsBufferAndItsSerialFromTheRecord) {
|
||||
GTEST_SKIP() << "the record arm of the index-buffer sync is compiled only under MOBILEGL_PIPE_PUSH";
|
||||
}
|
||||
#endif // MOBILEGL_PIPE_PUSH
|
||||
|
||||
@@ -171,6 +171,14 @@ namespace {
|
||||
// And the new ByteClass rides the ordinary bytes[] bracket under a short name that is
|
||||
// NOT "csob": the cso[] bracket above already prints csob= for the CSO bind count.
|
||||
EXPECT_NE(line.find("csob-blob="), String::npos) << line;
|
||||
// P5d round 3's wait ledger. Four fields on a bracket of their own, and they are
|
||||
// pinned here for the reason every other short name is: they are what the inproc
|
||||
// performance work reads out of a run's log, so a rename or a dropped field breaks
|
||||
// every recorded measurement of the split's handoff.
|
||||
EXPECT_NE(line.find("wait[srv="), String::npos) << line;
|
||||
EXPECT_NE(line.find("srvpark="), String::npos) << line;
|
||||
EXPECT_NE(line.find("cli="), String::npos) << line;
|
||||
EXPECT_NE(line.find("clipark="), String::npos) << line;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -316,6 +316,84 @@ TEST(InProcessTransportTest, DoorbellReturnsImmediatelyWhenAlreadyReady) {
|
||||
EXPECT_EQ(parked.load(), 0u);
|
||||
}
|
||||
|
||||
// P5d round 3, package T item 3: the spin phase is a CALIBRATED ITERATION BUDGET and reads no
|
||||
// clock. Two things have to be true of it and neither is visible from the outside without the
|
||||
// park counter, which is why ParkEntries() exists: a condition that flips WITHIN the budget must
|
||||
// be caught by the spin (no park, no syscall - that is the whole saving), and a condition that
|
||||
// never flips must still reach the park (a budget that silently came out as zero, or a
|
||||
// calibration that returned zero iterations per microsecond, would turn every wait into a park
|
||||
// and would be invisible in a test that only checked the return value).
|
||||
TEST(InProcessTransportTest, DoorbellSpinsWithoutParkingWhenReadyFlipsInsideTheBudget) {
|
||||
std::unique_ptr<InProcessTransport> client;
|
||||
std::unique_ptr<InProcessTransport> server;
|
||||
InProcessTransport::CreatePair(client, server);
|
||||
|
||||
// The budget itself must be a usable number: SpinItersPerUs() is what multiplies spinUs,
|
||||
// so a zero here would mean "never spin" and the case below would pass for the wrong reason.
|
||||
ASSERT_GT(SpinItersPerUs(), 0u);
|
||||
|
||||
std::atomic<std::uint32_t> parked{0};
|
||||
Doorbell& bell = client->SelfDoorbell();
|
||||
const std::uint64_t parksBefore = bell.ParkEntries();
|
||||
|
||||
// Flips on the 8th probe - far inside a 50 us budget on any core that can run this suite,
|
||||
// and deliberately NOT on the first, so the spin loop really iterates.
|
||||
int probes = 0;
|
||||
EXPECT_TRUE(bell.Wait(
|
||||
parked, [&probes] { return ++probes >= 8; }, kDefaultSpinUs, 5000));
|
||||
EXPECT_GE(probes, 8);
|
||||
EXPECT_EQ(bell.ParkEntries(), parksBefore)
|
||||
<< "the wait blocked although its condition flipped inside the spin budget: the "
|
||||
"clock-free spin is not spinning, and every verb barrier is paying a futex round "
|
||||
"trip it does not need";
|
||||
EXPECT_EQ(parked.load(), 0u);
|
||||
}
|
||||
|
||||
TEST(InProcessTransportTest, DoorbellStillParksWhenTheSpinBudgetRunsOut) {
|
||||
std::unique_ptr<InProcessTransport> client;
|
||||
std::unique_ptr<InProcessTransport> server;
|
||||
InProcessTransport::CreatePair(client, server);
|
||||
|
||||
std::atomic<std::uint32_t> parked{0};
|
||||
Doorbell& bell = client->SelfDoorbell();
|
||||
const std::uint64_t parksBefore = bell.ParkEntries();
|
||||
|
||||
EXPECT_FALSE(bell.Wait(
|
||||
parked, [] { return false; }, kDefaultSpinUs, 30));
|
||||
EXPECT_GT(bell.ParkEntries(), parksBefore)
|
||||
<< "the wait never reached the blocking park, so a waiter with no deadline would burn "
|
||||
"a core at full clock for ever";
|
||||
EXPECT_EQ(parked.load(), 0u);
|
||||
}
|
||||
|
||||
// The park number is published as the SUBSET of the waits that blocked, and it only stays one
|
||||
// if a Wait that traverses the park loop twice counts once. That is not a contrived path: a
|
||||
// CondVarDoorbell REMEMBERS a notify delivered while nobody was waiting, so the first Park
|
||||
// returns at once, the condition is still false (the peer had already drained what it
|
||||
// published) and the wait parks again. Counting per Park() rather than per Wait() made
|
||||
// `srvpark`/`clipark` able to print LARGER than `srv`/`cli`, which turns the one ratio the
|
||||
// ledger exists to publish into an argument for the opposite conclusion.
|
||||
TEST(InProcessTransportTest, AWaitThatParksTwiceOnARememberedNotifyIsStillOnePark) {
|
||||
std::unique_ptr<InProcessTransport> client;
|
||||
std::unique_ptr<InProcessTransport> server;
|
||||
InProcessTransport::CreatePair(client, server);
|
||||
|
||||
std::atomic<std::uint32_t> parked{0};
|
||||
Doorbell& bell = client->SelfDoorbell();
|
||||
// Delivered with nobody waiting: the bell remembers it, so the FIRST Park below returns
|
||||
// immediately with the condition still false and the loop parks a second time.
|
||||
bell.Notify();
|
||||
|
||||
const std::uint64_t parksBefore = bell.ParkEntries();
|
||||
EXPECT_FALSE(bell.Wait(
|
||||
parked, [] { return false; }, kDefaultSpinUs, 30));
|
||||
EXPECT_EQ(bell.ParkEntries(), parksBefore + 1)
|
||||
<< "one wait counted more than one park: the ledger's parks are no longer a subset of "
|
||||
"its waits, and `clipark > cli` reads as 'every verb pays a futex round trip' when "
|
||||
"the truth is one remembered notify";
|
||||
EXPECT_EQ(parked.load(), 0u);
|
||||
}
|
||||
|
||||
TEST(InProcessTransportTest, DoorbellTimesOutWhenNothingHappens) {
|
||||
std::unique_ptr<InProcessTransport> client;
|
||||
std::unique_ptr<InProcessTransport> server;
|
||||
|
||||
@@ -756,9 +756,11 @@ TEST_F(PipeWireCodecTest, KHostSpanClassIsValidatedEvenThoughP5ProducesNone) {
|
||||
kInvalidSeq);
|
||||
bool applied = false;
|
||||
ASSERT_TRUE(wire.PumpOne(&applied));
|
||||
// No applier entry point exists and the call is off the reduced path, so the honest answer
|
||||
// is "this build does not implement it" - after the tails have been checked.
|
||||
EXPECT_FALSE(applied);
|
||||
// P5e (sb): the applier entry point EXISTS now, so the record is applied after the tails
|
||||
// have been checked. The case's own subject is unchanged and is what its name says - the
|
||||
// kHostSpan class is validated whether or not P5 ever produces one - and the flip is the
|
||||
// proof that the honesty pass runs IN FRONT of the apply rather than instead of it.
|
||||
EXPECT_TRUE(applied);
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
@@ -877,7 +879,9 @@ TEST_F(PipeWireCodecTest, SetShaderBuffersCarriesBothTailsWhenTheSpanTailIsPrese
|
||||
kInvalidSeq);
|
||||
bool applied = false;
|
||||
ASSERT_TRUE(wire.PumpOne(&applied));
|
||||
EXPECT_FALSE(applied);
|
||||
// P5e (sb): applied, for the reason the sibling case above states. BOTH tails still cross
|
||||
// and both are still laid out by MGPipeWireRecordLayout, which is what this case is about.
|
||||
EXPECT_TRUE(applied);
|
||||
}
|
||||
|
||||
TEST_F(PipeWireCodecTest, ResourceSubDataCarriesABlobAndARegionTailTogether) {
|
||||
@@ -1557,8 +1561,14 @@ TEST_F(PipeWireCodecTest, CreateShaderStateCrossesAsOneArchiveAndSixUndeclaredRu
|
||||
}
|
||||
spirv.globalUboScratch.assign(32, 0xAB);
|
||||
|
||||
// P5e (pg): THE FRAMED archive is what crosses now - the codec's own stream with the stage
|
||||
// of each module in front of it. SpirvArtifacts does not carry the stages and StageMask
|
||||
// cannot stand in for them (two shader objects may share a stage, so a list rebuilt from
|
||||
// the mask can be shorter than generatedSpirv), and the server pairs the two by one running
|
||||
// index. See ProgramArtifactsCodec.h.
|
||||
const Vector<Uint32> stages{0, 1, 2, 3, 4, 5};
|
||||
Vector<Uint8> archive;
|
||||
MG_State::GLState::EncodeProgramArtifacts(link, spirv, archive);
|
||||
MG_State::GLState::EncodeProgramArchive(link, spirv, stages, archive);
|
||||
ASSERT_FALSE(archive.empty());
|
||||
|
||||
MGPProgramDesc desc{};
|
||||
@@ -1582,16 +1592,16 @@ TEST_F(PipeWireCodecTest, CreateShaderStateCrossesAsOneArchiveAndSixUndeclaredRu
|
||||
EXPECT_TRUE(applied);
|
||||
|
||||
// And the archive really did carry the six modules: decode it the way the arm does.
|
||||
MG_State::GLState::LinkArtifacts back;
|
||||
MG_State::GLState::SpirvArtifacts backSpirv;
|
||||
ASSERT_TRUE(MG_State::GLState::DecodeProgramArtifacts(archive.data(), archive.size(), back,
|
||||
backSpirv));
|
||||
ASSERT_EQ(backSpirv.generatedSpirv.size(), 6u);
|
||||
MG_State::GLState::ProgramArchive back;
|
||||
ASSERT_TRUE(MG_State::GLState::DecodeProgramArchive(archive.data(), archive.size(), back));
|
||||
ASSERT_EQ(back.Spirv.generatedSpirv.size(), 6u);
|
||||
for (std::size_t stage = 0; stage < 6; ++stage) {
|
||||
EXPECT_EQ(backSpirv.generatedSpirv[stage].size(), 4 + stage);
|
||||
EXPECT_EQ(backSpirv.generatedSpirv[stage][0], 0x07230203u + stage);
|
||||
EXPECT_EQ(back.Spirv.generatedSpirv[stage].size(), 4 + stage);
|
||||
EXPECT_EQ(back.Spirv.generatedSpirv[stage][0], 0x07230203u + stage);
|
||||
}
|
||||
EXPECT_TRUE(backSpirv.spirvStatus);
|
||||
EXPECT_TRUE(back.Spirv.spirvStatus);
|
||||
// The frame's own half: one stage word per module, at the same index.
|
||||
EXPECT_EQ(back.LinkedStages, stages);
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
|
||||
@@ -47,6 +47,7 @@
|
||||
#include <MG_Impl/GLImpl/Buffer/GL_Buffer.h>
|
||||
#include <MG_Pipe/PipeMutation.h>
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#include <MG_Backend/MGPipe/PipeInputs.h>
|
||||
#include <MG_Impl/Pipe/PipeFill.h>
|
||||
#include <Init.h>
|
||||
#include <MG_Impl/EGLImpl/EGLImpl.h>
|
||||
@@ -1124,6 +1125,10 @@ TEST(PipeRouting, TheInstalledClientArmIsWireAndNotMonolithAndEveryRoutedRowMove
|
||||
C1F_MOVED(Context, SetSamplerViews);
|
||||
C1F_MOVED(Context, BindSamplerStates);
|
||||
C1F_MOVED(Context, SetShaderImages);
|
||||
// P5e (sb, CONTRACT-P5E.md §5.6): set_shader_buffers is the 35th routed row. It rides both
|
||||
// tables like every other set_* with an applier entry point - the class is a FIELD of the
|
||||
// payload, so all three binding-point classes go through this one cell.
|
||||
C1F_MOVED(Context, SetShaderBuffers);
|
||||
C1F_MOVED(Context, SetGlobalConstants);
|
||||
C1F_MOVED(Context, SetVertexAttribDefaults);
|
||||
C1F_MOVED(Context, SetPixelPackState);
|
||||
@@ -1144,18 +1149,21 @@ TEST(PipeRouting, TheInstalledClientArmIsWireAndNotMonolithAndEveryRoutedRowMove
|
||||
C1F_ESCAPE(ResourceFlushRange);
|
||||
C1F_ESCAPE(MapPersistent);
|
||||
C1F_ESCAPE(CreateShaderState);
|
||||
// P5e (pg): set_program_bindings is the fifth escape - three tails in three index spaces
|
||||
// plus a parallel name array, which no generated row can express (MG_Pipe/PipeRoute.h).
|
||||
C1F_ESCAPE(SetProgramBindings);
|
||||
#undef C1F_ESCAPE
|
||||
const SizeT movedContext = CountDifferingCells(gMGPipeContext, MGPipeMonolithContext());
|
||||
EXPECT_EQ(movedScreen + movedContext, 34u)
|
||||
<< "exactly the 34 generated routed rows must differ from the monolith adapters "
|
||||
"(33 at P5, + set_context_values at P5c rv); "
|
||||
EXPECT_EQ(movedScreen + movedContext, 35u)
|
||||
<< "exactly the 35 generated routed rows must differ from the monolith adapters "
|
||||
"(33 at P5, + set_context_values at P5c rv, + set_shader_buffers at P5e sb); "
|
||||
<< movedScreen + movedContext
|
||||
<< " did, so a row was left on the monolith adapter (it would run the applier on the GL "
|
||||
"thread under split) or an unrouted row was overwritten";
|
||||
|
||||
const SizeT movedEscapes = CountDifferingCells(gMGPipeRouteEscapes, MGPipeMonolithEscapes());
|
||||
EXPECT_EQ(movedEscapes, 4u)
|
||||
<< "the four escape routes must move off the monolith escapes too";
|
||||
EXPECT_EQ(movedEscapes, 5u)
|
||||
<< "the five escape routes must move off the monolith escapes too";
|
||||
|
||||
// Restore the monolith arm for the sibling cases that assert it (and for a clean binary).
|
||||
MGPipeInstallMonolithTables();
|
||||
@@ -1847,6 +1855,108 @@ MGL_BUFFER_GUARD_TEST(BufferSyncPersistentMappedRangeFromTheApplyThreadIsFatalBy
|
||||
MGL_BUFFER_GUARD_TEST(BufferHasDefinedContentFromTheApplyThreadIsFatalByName, 707, (void)buffer.HasDefinedContent())
|
||||
#undef MGL_BUFFER_GUARD_TEST
|
||||
|
||||
// P5d round 3 (package D): the two NAMED EXEMPTION scopes of CONTRACT-P5C §3.1 / §5.4 stopped
|
||||
// keeping their depth in a thread_local and now count ONLY while ServerLoop::OnApplyThread() is
|
||||
// true (SlotAllocator.cpp). The claim that makes that legal is "the apply-thread guard is the
|
||||
// counter's only reader, so a depth kept on any other thread cannot change an answer" - and
|
||||
// these three cases are that claim in executable form. They are the red-once for the change:
|
||||
//
|
||||
// (a) drop the `if (m_counted)` from the constructor (or make it unconditional again on a
|
||||
// thread that is not the apply thread) and (c) goes red - a GL-thread scope would start
|
||||
// exempting the apply thread, which is exactly the leak the thread_local used to prevent;
|
||||
// (b) drop the increment altogether and (a) goes red - the exemption stops exempting and
|
||||
// the debt's own sites (DirectGLES' HandleOf probes) abort the server;
|
||||
// (c) drop the guard's `MagmaP7AllocatorDebtScope::ActiveOnApplyThread()` /
|
||||
// `FrontendKeyedRegistryScope::ActiveOnApplyThread()` rows and (b) - the control - stops
|
||||
// being the only aborting arm.
|
||||
//
|
||||
// P5e (id), CONTRACT-P5E §4.4 REPLACED (b). The case that used to sit there -
|
||||
// `AnAllocatorProbeInsideAnExemptionScopeOnTheApplyThreadIsAllowed` - asserted that a scope
|
||||
// exempts UNCONDITIONALLY, which is exactly the rule §4.4 retires: an exemption is a debt the
|
||||
// CLIENT'S WAIT pays for, so it holds only while the record being applied is barriered. Its
|
||||
// replacement below drives the same scope with the barriered flag forced false and expects the
|
||||
// abort. The green half of the old case did not need a test of its own: every Espryt
|
||||
// `integration-split` entry runs the frontend-keyed scope's surviving sites on the apply thread
|
||||
// behind barriered records, so a guard that stopped exempting would take the whole lane down.
|
||||
TEST(RemoteGuards, AnAllocatorProbeFromTheApplyThreadOutsideEveryScopeIsFatalByName) {
|
||||
const auto child = RunInChild([] {
|
||||
StartControlSession();
|
||||
Srv::ServerLoopInstance().RunOnApplyThread(
|
||||
+[](void*) -> MobileGLResult {
|
||||
MG_Pipe::MGPipeRefuseAllocatorFromApplyThread("FindByLifetimeId");
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
nullptr);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectNamedAbort(child, "Fatal{RoleViolation, \"MGPipeSlots\"}");
|
||||
}
|
||||
|
||||
// P5e (id) RED-ONCE, CONTRACT-P5E §4.4. The exemption scope is OPEN and the probe is the one
|
||||
// the debt is named for - `HandleOf`, the frontend-keyed registry's own entry - and it still
|
||||
// aborts, because the record being applied is unbarriered: the client is running ahead and the
|
||||
// allocator's free list and lifetimeId -> slot map are moving under the read.
|
||||
//
|
||||
// THE HOOK IS THE APPLIER FIELD ITSELF and that is deliberate: `CurrentRecordBarriered` is what
|
||||
// PipeApplier::ApplyOne stamps from MGPipeBarriered() on every record, so forcing it here drives
|
||||
// the production path rather than a test-only branch beside it. Until ra lands the wait rule
|
||||
// MGPipeBarriered answers true for every record, so this is the ONLY way to reach the arm - and
|
||||
// the arm has to exist before ra, because ra is what makes it reachable in production.
|
||||
//
|
||||
// The red: put §4.4's `if (MGPipeApplierCurrentRecordIsBarriered())` back to an unconditional
|
||||
// exemption in MGPipeRefuseAllocatorFromApplyThread and this case stops aborting - red by
|
||||
// expectation, which is the shape a guard case fails in.
|
||||
// EVERYTHING BUT THE PROBE RUNS ON THE CLIENT THREAD, which is the buffer/texture guard cases'
|
||||
// shape one block down and is load-bearing here rather than tidy: a TextureObject2D's
|
||||
// constructor MINTS a resource handle, and building it on the apply thread would abort at the
|
||||
// mint with the same diagnostic - a case that passes for a reason other than the one it names.
|
||||
TEST(RemoteGuards, AnAllocatorProbeInsideAnExemptionScopeFromTheApplyThreadIsFatalEvenAtTheOldDebtSites) {
|
||||
struct Probe {
|
||||
TestTextureTable* table;
|
||||
MG_State::GLState::TextureObject2D* texture;
|
||||
};
|
||||
const auto child = RunInChild([] {
|
||||
StartControlSession();
|
||||
MG_State::GLState::TextureObject2D texture(46);
|
||||
TestTextureTable table;
|
||||
Probe probe{&table, &texture};
|
||||
Srv::ServerLoopInstance().RunOnApplyThread(
|
||||
+[](void* self) -> MobileGLResult {
|
||||
auto& probe = *static_cast<Probe*>(self);
|
||||
// The record being applied is one the client did NOT park behind. The stamp is
|
||||
// the thread_local the sink writes (ID-103), so setting it here puts this
|
||||
// thread in exactly the state an unbarriered apply is in.
|
||||
MG_Pipe::MGPipeApplierSetCurrentRecordBarriered(false);
|
||||
const MG_Pipe::MGPipeFrontendKeyedRegistryScope frontendKeyedRegistry;
|
||||
probe.table->HandleOf(probe.texture);
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
&probe);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectNamedAbort(child, "Fatal{RoleViolation, \"MGPipeSlots\"}");
|
||||
}
|
||||
|
||||
// THE ONE THAT PINS THE SINGLE-WRITER ARGUMENT. The scope is open on the GL thread for the
|
||||
// whole of the posted request; the apply thread's probe must still abort, because the exemption
|
||||
// belongs to the thread that entered the scope and never to another one. With the depth kept in
|
||||
// a plain counter that every thread incremented, this case would go green - and a real
|
||||
// apply-thread violation would be silently exempted for as long as any GL thread held a scope.
|
||||
TEST(RemoteGuards, AnExemptionScopeHeldOnTheGLThreadDoesNotExemptTheApplyThread) {
|
||||
const auto child = RunInChild([] {
|
||||
StartControlSession();
|
||||
const MG_Pipe::MGPipeFrontendKeyedRegistryScope frontendKeyedRegistry;
|
||||
Srv::ServerLoopInstance().RunOnApplyThread(
|
||||
+[](void*) -> MobileGLResult {
|
||||
MG_Pipe::MGPipeRefuseAllocatorFromApplyThread("FindByLifetimeId");
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
nullptr);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectNamedAbort(child, "Fatal{RoleViolation, \"MGPipeSlots\"}");
|
||||
}
|
||||
|
||||
TEST(RemoteGuards, CapsMirrorFallbackWithNoServerBackendIsFatalByName) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Transport = MG_Config::TransportMode::InProcess;
|
||||
@@ -1869,10 +1979,23 @@ TEST(RemoteGuards, CapsMirrorFallbackWithNoServerBackendIsFatalByName) {
|
||||
// MarkStorageDirty, MarkStorageDirtyRegion, IsStorageDirty, GetStorageDirtyRegion,
|
||||
// GetStorageDirtyRects
|
||||
//
|
||||
// Deliberately NOT in the list: the shape reads (GetMipmapTexelSize / GetMipmapByteSize /
|
||||
// GetMipmapLevelCount / GetUploadTargets / GetTarget / IsComplete), which the pinned
|
||||
// BARRIER-PULLED object-class rows still answer through the unit-object pointer
|
||||
// (FieldOwnershipTest's list, P3b/P4b/P7) - the per-draw binding walk reads them every draw.
|
||||
// P5e (tx2): THE SHAPE READS JOIN THE LIST, and the sentence that stood here is why they could
|
||||
// not before - "the per-draw binding walk reads them every draw". P5e is the commit that makes
|
||||
// that untrue: the unit work list is st.BoundSamplerViews[], the clean gate is
|
||||
// IsDrawSyncCleanByRecord, and the three sync bodies read the resource record and the server's
|
||||
// staged-texture store. Nothing on the draw path asks a frontend texture for a level count, a
|
||||
// level extent, a level byte size or a compressed level any more, so the exemption becomes a
|
||||
// guard and reverting any handle arm aborts BY ACCESSOR NAME:
|
||||
//
|
||||
// GetMipmapLevelCount, GetMipmapTexelSize, GetMipmapByteSize,
|
||||
// GetCompressedFormat, GetCompressedByteSize, MapCompressedMipmapData,
|
||||
// GetRequestedCompressedFormat
|
||||
//
|
||||
// Keyed on the SERVER BACKEND being DirectGLES (ruling 12's shape): Magma is lockstep through
|
||||
// P7 and its named blit still asks a frontend texture IsComplete(), which is legal for a client
|
||||
// parked in its own wait. Still NOT in the list: GetUploadTargets / GetTarget / IsComplete,
|
||||
// which are TextureObject's own and not MipmapStorage's - their rows retire with the object
|
||||
// class in P7/P9.
|
||||
#define MGL_TEXTURE_GUARD_TEST(Name, Id, Call) \
|
||||
TEST(RemoteGuards, Name) { \
|
||||
const auto child = RunInChild([] { \
|
||||
@@ -1910,6 +2033,21 @@ MGL_TEXTURE_GUARD_TEST(TextureGetStorageDirtyRegionFromTheApplyThreadIsFatalByNa
|
||||
MGL_TEXTURE_GUARD_TEST(TextureGetStorageDirtyRectsFromTheApplyThreadIsFatalByName, 719,
|
||||
(void)texture.GetStorageDirtyRects(TextureUploadTarget::Texture2D, 0,
|
||||
nullptr, 0))
|
||||
// ---- P5e (tx2): the seven shape reads the P4a/P5c list exempted ----------------------------
|
||||
MGL_TEXTURE_GUARD_TEST(TextureGetMipmapLevelCountFromTheApplyThreadIsFatalByName, 721,
|
||||
(void)texture.GetMipmapLevelCount())
|
||||
MGL_TEXTURE_GUARD_TEST(TextureGetMipmapTexelSizeFromTheApplyThreadIsFatalByName, 722,
|
||||
(void)texture.GetMipmapTexelSize(TextureUploadTarget::Texture2D, 0))
|
||||
MGL_TEXTURE_GUARD_TEST(TextureGetMipmapByteSizeFromTheApplyThreadIsFatalByName, 723,
|
||||
(void)texture.GetMipmapByteSize(TextureUploadTarget::Texture2D, 0))
|
||||
MGL_TEXTURE_GUARD_TEST(TextureGetCompressedFormatFromTheApplyThreadIsFatalByName, 724,
|
||||
(void)texture.GetMipmapCompressedFormat(TextureUploadTarget::Texture2D, 0))
|
||||
MGL_TEXTURE_GUARD_TEST(TextureGetCompressedByteSizeFromTheApplyThreadIsFatalByName, 725,
|
||||
(void)texture.GetMipmapCompressedByteSize(TextureUploadTarget::Texture2D, 0))
|
||||
MGL_TEXTURE_GUARD_TEST(TextureMapCompressedMipmapDataFromTheApplyThreadIsFatalByName, 726,
|
||||
(void)texture.MapMipmapCompressedImage(TextureUploadTarget::Texture2D, 0))
|
||||
MGL_TEXTURE_GUARD_TEST(TextureGetRequestedCompressedFormatFromTheApplyThreadIsFatalByName, 727,
|
||||
(void)texture.GetMipmapRequestedCompressedFormat(TextureUploadTarget::Texture2D, 0))
|
||||
#undef MGL_TEXTURE_GUARD_TEST
|
||||
|
||||
// P5c (gt, CONTRACT-P5C §6 layer 2 / audit A1): the client-side half of the gPipeInputs
|
||||
@@ -1960,8 +2098,379 @@ TEST(RemoteGuards, ClientPipeInputsFillWithTheApplierIdleIsAllowed) {
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// ===========================================================================================
|
||||
// P5e (ra) - the wait rule, the present credit and gPipeInputs' ownership
|
||||
// (MG_Remote/CONTRACT-P5E.md §1, §2.3, §2.4, §3.1, §3.3, §3.5)
|
||||
// ===========================================================================================
|
||||
//
|
||||
// EVERY CASE BELOW ARMS RUN-AHEAD BY PUBLISHING THE CAP BIT, because that is the only thing
|
||||
// that arms it: RunAheadArmed() is a conjunction whose third term is the SERVER's own
|
||||
// statement that it applies an unbarriered record without reading client memory, and in a
|
||||
// tree where kMGPipeP5eRunAheadReady is still false no production session sets it. Driving the
|
||||
// arm through the caps mirror rather than through a test-only setter is deliberate (ID-102's
|
||||
// lesson): what these cases exercise is then the production latch and not a branch beside it.
|
||||
//
|
||||
// NONE OF THEM DRAWS. The draw path is the family packages' to migrate; until they land, a
|
||||
// draw under run-ahead would abort inside the backend for a reason that has nothing to do with
|
||||
// what is being asserted here.
|
||||
void StartRunAheadSession() {
|
||||
::alarm(15);
|
||||
MG_Config::Transport = MG_Config::TransportMode::InProcess;
|
||||
MG_Config::Ipc.RunAhead = 1;
|
||||
Srv::ServerSessionInstance().SetCapabilityBits(
|
||||
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply));
|
||||
Srv::ServerSessionInstance().SetConsumedSubsystems(kMGPipeSubsystemsMigratedAtP4a);
|
||||
// THE MIRROR IS ADOPTED BEFORE Start, AND THAT IS THE LATCH'S RULE MADE VISIBLE. This
|
||||
// process has no server backend, so PublishCapsSnapshot is deferred and the handshake
|
||||
// carries no snapshot at all - and §1 says a later snapshot may only turn run-ahead OFF,
|
||||
// never on. So the arm has to be true at the FIRST adoption, which for a fixture means
|
||||
// before the session takes its latch. A test that adopted afterwards and found the client
|
||||
// still lockstep would be reading the contract's own rule as a failure.
|
||||
{
|
||||
MG_Pipe::MGPCaps caps{};
|
||||
caps.CallMask = static_cast<Uint64>(MG_Pipe::kCapRunAheadApply) |
|
||||
MG_Remote::MGCapsConsumerBits(kMGPipeSubsystemsMigratedAtP4a);
|
||||
CapsMirrorInstance().Adopt(caps, MG_Backend::FormatCapabilityCache{}, RendererInfo{},
|
||||
String{"4.6"}, BackendType::DirectGLES);
|
||||
}
|
||||
if (ClientSessionInstance().Start(MG_Config::TransportMode::InProcess, {}) != MOBILEGL_OK) {
|
||||
::_exit(81);
|
||||
}
|
||||
if (!ClientSessionInstance().RunAheadArmed()) ::_exit(83); // the latch never took
|
||||
}
|
||||
|
||||
// THE SERVER HALF OF §2.4, SUBSTITUTED - and it is substituted because this fixture has no
|
||||
// backend object at all, so ServerVerbSink::OnPresent DECLINES before it can reach
|
||||
// ServerSession::ReturnPresentCredit ("present arrived with no backend object"). What the
|
||||
// cases below assert is therefore the CLIENT's half of the credit: that it pays, when, and in
|
||||
// whose id space. That the server returns exactly one credit per swap, after Present() has
|
||||
// returned, is PipeApplier::OnPresent's own three lines and the device exit's `credit-waits`
|
||||
// reading; a peer here cannot pin it without a backend to swap on.
|
||||
struct PresentCreditPeer : Codec::WireVerbSink {
|
||||
std::atomic<Uint64> lastSerial{0};
|
||||
Bool OnPresent(const MGPPresent& present) override {
|
||||
lastSerial.store(present.FrameSerial);
|
||||
Srv::ServerSessionInstance().ReturnPresentCredit(present.FrameSerial);
|
||||
return true;
|
||||
}
|
||||
void Install() {
|
||||
if (Srv::ServerLoopInstance().RunOnApplyThread(
|
||||
[](void* self) {
|
||||
auto& decoder = Srv::ServerSessionInstance().Applier().*PeerMember(DecoderTag{});
|
||||
decoder.SetVerbSink(static_cast<PresentCreditPeer*>(self));
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
this) != MOBILEGL_OK) {
|
||||
::_exit(82);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// §1: the conjunction, and the half of it that is not the client's to decide. The cap bit is
|
||||
// absent here, so the knob alone changes nothing - which is the whole reason the knob is
|
||||
// parsed on every arm rather than only where it means something (Config.h).
|
||||
TEST(RemoteRunAhead, TheKnobAloneDoesNotArmRunAheadWithoutTheServersCapBit) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.RunAhead = 1;
|
||||
StartControlSession(); // SetCapabilityBits(0)
|
||||
if (ClientSessionInstance().RunAheadArmed()) ::_exit(101);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// §1 again, from the other side: MOBILEGL_IPC_VERB_BARRIER=0 is the LOCKSTEP arm's negative
|
||||
// control and it disarms run-ahead outright, because the barrier is the first term of the
|
||||
// conjunction. Under run-ahead its documented red is the first barriered row's stale pull -
|
||||
// that one is a scenario, not a unit case; what is pinned here is that the two controls do not
|
||||
// silently compose into a third mode nobody designed.
|
||||
TEST(RemoteRunAhead, ClearingTheVerbBarrierDisarmsRunAheadEvenWithTheCapBit) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.RunAhead = 1;
|
||||
MG_Config::Ipc.VerbBarrier = 0;
|
||||
::alarm(15);
|
||||
MG_Config::Transport = MG_Config::TransportMode::InProcess;
|
||||
Srv::ServerSessionInstance().SetCapabilityBits(
|
||||
static_cast<Uint64>(MG_Pipe::kCapRunAheadApply));
|
||||
Srv::ServerSessionInstance().SetConsumedSubsystems(kMGPipeSubsystemsMigratedAtP4a);
|
||||
MG_Pipe::MGPCaps caps{};
|
||||
caps.CallMask = static_cast<Uint64>(MG_Pipe::kCapRunAheadApply) |
|
||||
MG_Remote::MGCapsConsumerBits(kMGPipeSubsystemsMigratedAtP4a);
|
||||
CapsMirrorInstance().Adopt(caps, MG_Backend::FormatCapabilityCache{}, RendererInfo{},
|
||||
String{"4.6"}, BackendType::DirectGLES);
|
||||
if (ClientSessionInstance().Start(MG_Config::TransportMode::InProcess, {}) != MOBILEGL_OK) {
|
||||
::_exit(81);
|
||||
}
|
||||
if (ClientSessionInstance().RunAheadArmed()) ::_exit(101);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// §2.4's RED-ONCE, BY COUNT. With a credit of 1 the client may have one present in flight, so
|
||||
// the second and third presents each pay the credit before they encode - `credit-waits` is 2
|
||||
// after three presents and the present-ack watermark has reached 2. Delete the
|
||||
// WaitForPresentAck arm from ClientSession::AcquirePresentCredit and the counter stays 0 while
|
||||
// all three presents publish: red by count, which is the only way a wait that is usually
|
||||
// already satisfied can be tested at all.
|
||||
//
|
||||
// The serial is asserted too, because the counter alone would survive a credit paid against
|
||||
// the wrong id space (the pre-P5e FrameSerial was 0 and the server stamped its own).
|
||||
TEST(RemoteRunAhead, ACreditOneClientPaysTheCreditAtEveryPresentAfterTheFirst) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.PresentCredit = 1;
|
||||
StartRunAheadSession();
|
||||
PresentCreditPeer peer;
|
||||
peer.Install();
|
||||
ClientSession& session = ClientSessionInstance();
|
||||
if (session.PresentCreditWaits() != 0) ::_exit(101);
|
||||
RemoteEmitTable().Present();
|
||||
if (session.PresentCreditWaits() != 0) ::_exit(102); // the first one is free
|
||||
RemoteEmitTable().Present();
|
||||
RemoteEmitTable().Present();
|
||||
if (session.PresentCreditWaits() != 2) ::_exit(103);
|
||||
// ONE CREDIT PER SWAP, in the client's own 1-based space: the server returned the
|
||||
// second present's credit, so the watermark is at least 2.
|
||||
if (session.Control() == nullptr ||
|
||||
session.Control()->presentAckSerial.load() < 2u) {
|
||||
::_exit(104);
|
||||
}
|
||||
session.Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// §2.4's other half: with the credit raised the client stops paying until it is that far
|
||||
// ahead. It is the control that keeps the case above from passing because of an unconditional
|
||||
// counter rather than because of the credit.
|
||||
TEST(RemoteRunAhead, ACreditThreeClientPaysNothingForItsFirstThreePresents) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.PresentCredit = 3;
|
||||
StartRunAheadSession();
|
||||
PresentCreditPeer peer;
|
||||
peer.Install();
|
||||
ClientSession& session = ClientSessionInstance();
|
||||
RemoteEmitTable().Present();
|
||||
RemoteEmitTable().Present();
|
||||
RemoteEmitTable().Present();
|
||||
if (session.PresentCreditWaits() != 0) ::_exit(101);
|
||||
RemoteEmitTable().Present();
|
||||
if (session.PresentCreditWaits() != 1) ::_exit(102);
|
||||
session.Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// §3.1 / §3.5's RED-ONCE. `Clear` is a kWaitNone row, so under run-ahead the client publishes
|
||||
// it and moves on - and therefore does not fill gPipeInputs for it. This case is the GREEN
|
||||
// half: the validate point runs the tracker walk and the emitters and touches the block not at
|
||||
// all, so nothing aborts.
|
||||
//
|
||||
// THE RED: in MGPipeValidateForVerb change `const Bool fillOwed = barriered;` to `= true` -
|
||||
// which is exactly "leave one CopyField in an unbarriered fill" - and the guard below it fires
|
||||
// Fatal{RoleViolation, "gPipeInputs"} on this very call.
|
||||
TEST(RemoteRunAhead, AnUnbarrieredVerbDoesNotFillPipeInputsAndIsAllowed) {
|
||||
const auto child = RunInChild([] {
|
||||
StartRunAheadSession();
|
||||
MGPipeValidateForVerb(MGPipeVerb::Clear);
|
||||
MGPipeLeaveVerb();
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// §3.5, the aborting arm, driven at the guard itself: a GL-thread touch that is NOT the
|
||||
// residual fill of a barriered record. Under lockstep this same call is a no-op (the apply
|
||||
// thread is not inside the applier and MOBILEGL_IPC_BATCH_WAITS is 1); under run-ahead there
|
||||
// is no such window to be outside of, because the client never parks for an unbarriered
|
||||
// record - so the answer stops depending on timing and becomes the rule.
|
||||
TEST(RemoteGuards, ClientPipeInputsTouchOutsideABarrieredFillUnderRunAheadIsFatalByName) {
|
||||
const auto child = RunInChild([] {
|
||||
StartRunAheadSession();
|
||||
ClientSession::RefusePipeInputsTouchWhileApplierOwnsIt("ra-test-surface",
|
||||
/*isBarrieredFill=*/false);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectNamedAbort(child, "Fatal{RoleViolation, \"gPipeInputs\"}");
|
||||
}
|
||||
|
||||
// ... and the control: the barriered fill says so and is let through. Without this the case
|
||||
// above would pass just as well against "abort unconditionally".
|
||||
TEST(RemoteGuards, ClientPipeInputsTouchInsideABarrieredFillUnderRunAheadIsAllowed) {
|
||||
const auto child = RunInChild([] {
|
||||
StartRunAheadSession();
|
||||
ClientSession::RefusePipeInputsTouchWhileApplierOwnsIt("ra-test-surface",
|
||||
/*isBarrieredFill=*/true);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// §3.3's RED-ONCE, and the one that turns the strict lane into a gate. The probe is the
|
||||
// sticky forward itself, run on the apply thread inside a server-stamped verb with the
|
||||
// current record marked UNBARRIERED - which is the state the sink puts that thread in for
|
||||
// every kWaitNone row once the wait rule is live. MOBILEGL_IPC_STRICT_ERRORS is deliberately
|
||||
// NOT set: the point is that the knob has stopped being the deciding input, because a row the
|
||||
// client never filled has no value to count.
|
||||
//
|
||||
// THE RED: put CountBarrierPull's first line back to `if (MG_Config::Ipc.StrictErrors)` only
|
||||
// and this case stops aborting - and, on the lane, every scenario that still pulls a row goes
|
||||
// from a named abort to a wrong picture with a number beside it.
|
||||
TEST(RemoteGuards, AResidualPullUnderAnUnbarrieredRecordIsFatalWithoutTheStrictKnob) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.StrictErrors = false;
|
||||
StartRunAheadSession();
|
||||
Srv::ServerLoopInstance().RunOnApplyThread(
|
||||
+[](void*) -> MobileGLResult {
|
||||
MG_Pipe::MGPipeServerStampVerbBoundary(MGPipeVerb::Clear);
|
||||
MG_Pipe::MGPipeApplierSetCurrentRecordBarriered(false);
|
||||
MG_Pipe::MGPipeStickyForwardPull(MGPipeInputField::GetProgramObject);
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
nullptr);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectNamedAbort(child, "Fatal{UnmigratedPipeInput, \"GetProgramObject@Clear\"}");
|
||||
}
|
||||
|
||||
// The control: the SAME probe inside a BARRIERED record is P5C's counted residual pull, and
|
||||
// with the strict knob off it counts and carries on. Ruling 4 is this line - a barriered
|
||||
// record keeps P5C's semantics exactly, because the client is parked in its own wait.
|
||||
TEST(RemoteGuards, AResidualPullUnderABarrieredRecordStillOnlyCounts) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.StrictErrors = false;
|
||||
StartRunAheadSession();
|
||||
Srv::ServerLoopInstance().RunOnApplyThread(
|
||||
+[](void*) -> MobileGLResult {
|
||||
MG_Pipe::MGPipeServerStampVerbBoundary(MGPipeVerb::Clear);
|
||||
MG_Pipe::MGPipeApplierSetCurrentRecordBarriered(true);
|
||||
const Uint64 before = MG_Pipe::MGPipeResidualPullCount();
|
||||
MG_Pipe::MGPipeStickyForwardPull(MGPipeInputField::GetProgramObject);
|
||||
if (MG_Pipe::MGPipeResidualPullCount() != before + 1) ::_exit(101);
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
nullptr);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// §2.6's RED-ONCE, and the one the brief names: ~300 KiB of kEventGpuWritten published from
|
||||
// the apply thread behind a sequence nobody waited for. SEG_EVENT is 256 KiB, so this is
|
||||
// several ringfuls; under P5C's rule the FIRST Reserve that failed was Fatal{EventRingOverflow}
|
||||
// and this case aborts by that name. With flow control the producer publishes, rings, parks on
|
||||
// the latch and retries, and the burst completes.
|
||||
//
|
||||
// THE DRAIN RUNS ON A THREAD OF ITS OWN, and that is forced by the fixture rather than chosen:
|
||||
// RunOnApplyThread is synchronous, so the thread that posted the burst cannot also be the
|
||||
// thread that empties the ring. In production it is the GL thread draining at its own waits
|
||||
// (§2.6's deadlock argument); here it is a drainer beside the poster, which puts the producer
|
||||
// in exactly the state that argument describes.
|
||||
TEST(RemoteRunAhead, AnEventBurstBehindAnUnwaitedSequenceFlowControlsInsteadOfAborting) {
|
||||
const auto child = RunInChild([] {
|
||||
StartRunAheadSession();
|
||||
std::atomic<bool> stop{false};
|
||||
std::atomic<Uint64> delivered{0};
|
||||
std::thread drainer([&stop, &delivered] {
|
||||
// THE FIRST DRAIN IS DELAYED ON PURPOSE. A drainer that starts immediately can
|
||||
// keep a 256 KiB ring from ever being full, and a red-once that depends on the
|
||||
// scheduler losing a race is not a red-once. 50 ms is four orders of magnitude
|
||||
// more than the burst needs to fill the ring, so the producer is provably parked
|
||||
// on the latch before anything empties it.
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
while (!stop.load(std::memory_order_acquire)) {
|
||||
delivered.fetch_add(ClientSessionInstance().DrainPublishedEvents());
|
||||
std::this_thread::yield();
|
||||
}
|
||||
delivered.fetch_add(ClientSessionInstance().DrainPublishedEvents());
|
||||
});
|
||||
// 3000 records of 64 ranges each is ~3 MB against a 256 KiB ring - twelve ringfuls,
|
||||
// with a drainer racing it - so the full latch is hit many times over rather than
|
||||
// maybe once. That margin is what makes the red-once (restore the Fatal) reliable:
|
||||
// a burst that merely might fill the ring would be a red-once that merely might be red.
|
||||
Srv::ServerLoopInstance().RunOnApplyThread(
|
||||
+[](void*) -> MobileGLResult {
|
||||
MG_Pipe::MGPRange ranges[64];
|
||||
for (Uint32 r = 0; r < 64; ++r) ranges[r] = MG_Pipe::MGPRange{r * 64ull, 64ull};
|
||||
for (Uint32 i = 0; i < 3000; ++i) {
|
||||
MG_Pipe::gMGPipeCallbacks.OnGpuWritten(MG_Pipe::MGPipeHandle{7, 1}, 64, ranges);
|
||||
}
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
nullptr);
|
||||
stop.store(true, std::memory_order_release);
|
||||
drainer.join();
|
||||
// LOSSLESS, which is the property flow control had to preserve: every one of the 3000
|
||||
// records crossed. A drop policy would have been the other way to survive a full ring,
|
||||
// and P5C's §4.4 refuses it - a writeback or a GPU-write mark that did not arrive is a
|
||||
// stale buffer, not a missing statistic.
|
||||
if (delivered.load() < 3000u) ::_exit(101);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
|
||||
// §2.7 / ruling 13: the deferred-destroy queue stays, and an enqueue from an unbarriered
|
||||
// apply is the finding. Under strict it is the abort; this is the arm the lane owns.
|
||||
TEST(RemoteGuards, ADeferredDestroyFromAnUnbarrieredApplyIsFatalUnderStrict) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.StrictErrors = true;
|
||||
StartRunAheadSession();
|
||||
Srv::ServerLoopInstance().RunOnApplyThread(
|
||||
+[](void*) -> MobileGLResult {
|
||||
MG_Pipe::MGPipeApplierSetCurrentRecordBarriered(false);
|
||||
(void)MG_Pipe::MGPipeDeferDestroyAndFreeIfOnApplyThread(MG_Pipe::MGPipeKind::Texture,
|
||||
4242);
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
nullptr);
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectNamedAbort(child, "Fatal{RoleViolation, \"deferred-destroy\"}");
|
||||
}
|
||||
|
||||
// The control, and the whole of ruling 13: a BARRIERED apply may still be a last owner (its
|
||||
// fill's O-class rows, XFB's pinned targets), so the queue takes the death and the GL thread
|
||||
// replays it. Deleting the queue would have made this an allocator touch from the server role.
|
||||
TEST(RemoteGuards, ADeferredDestroyFromABarrieredApplyIsStillServed) {
|
||||
const auto child = RunInChild([] {
|
||||
MG_Config::Ipc.StrictErrors = true;
|
||||
StartRunAheadSession();
|
||||
Srv::ServerLoopInstance().RunOnApplyThread(
|
||||
+[](void*) -> MobileGLResult {
|
||||
MG_Pipe::MGPipeApplierSetCurrentRecordBarriered(true);
|
||||
if (!MG_Pipe::MGPipeDeferDestroyAndFreeIfOnApplyThread(MG_Pipe::MGPipeKind::Texture,
|
||||
4243)) {
|
||||
::_exit(101);
|
||||
}
|
||||
return MOBILEGL_OK;
|
||||
},
|
||||
nullptr);
|
||||
MG_Pipe::MGPipeDrainDeferredDestroys();
|
||||
ClientSessionInstance().Stop();
|
||||
});
|
||||
ExpectChildSuccess(child);
|
||||
}
|
||||
#endif
|
||||
|
||||
// §2.5 / ruling 15 (ID-93): which half of resource_subdata wants its answer. One predicate,
|
||||
// read by MGPipeRouteResourceSubData and by Wire_ResourceSubData - a second spelling of it is
|
||||
// how the client comes to wait for an answer the emitter told the server not to bother with.
|
||||
// The buffer target's whole packed field is 0 (MGPipeTypes.h asserts it beside the packer),
|
||||
// which is what makes the test a comparison and not a mask.
|
||||
TEST(RemoteRunAhead, OnlyTheTextureHalfOfResourceSubDataWantsItsReply) {
|
||||
MG_Pipe::MGPSubData buffer{};
|
||||
buffer.Target = MG_Pipe::MGPipePackSubDataTarget(MG_Pipe::kMGPipeResourceTargetBuffer, 0u);
|
||||
EXPECT_FALSE(MG_Pipe::MGPipeSubDataWantsItsReply(buffer));
|
||||
|
||||
MG_Pipe::MGPSubData texture{};
|
||||
texture.Target = MG_Pipe::MGPipePackSubDataTarget(
|
||||
static_cast<Uint32>(MG_Pipe::MGPipeResourceTarget::Tex2D),
|
||||
static_cast<Uint32>(TextureUploadTarget::Texture2D));
|
||||
EXPECT_TRUE(MG_Pipe::MGPipeSubDataWantsItsReply(texture));
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user