Files
MobileGL/MobileGL/MG_Test/ScopedPipeVerb.h
T
swung0x48 fcd4ad3799 [Feat] (Pipe): compute the per-verb dirty mask at the validate point and count how often each bit fires
- MGPipeFillForVerb becomes MGPipeValidateForVerb and MGP_FILL expands to the new name. The
  macro spelling, the 83 call sites and the verb enum do not change: the dispatch is
  kMGPipeVerbClass's nine classes, which is the same code as nine named ValidateFor* entry
  points with one call site per verb instead of nine (P2 brief D1, against ARCHITECTURE.md's
  eight - FillPoints.def argues in its own comment for splitting kProgramOp out, and the landed
  table is what runs).
- MG_Impl/Pipe/Tracker.h: MGPipeDirty's 18 bits, the widened Uint16 shutters, the per-verb walk
  and the per-bit-per-verb-class fire tallies. The widening happens in the TRACKER and MG_State
  is not changed for it; a wrap costs one extra re-push and never a missed one.
- NOTHING IS EMITTED YET. The mask is computed, latched and counted, and the full P1 residual
  fill runs after it unchanged. That is the point of this step: it says the walk is
  semantically free before any field stops being pulled, so a regression in the next commit
  cannot be blamed on the walk.
- Every shutter over-fires on purpose. Bits 2 and 3 are BYTE compares, not value compares,
  because a NaN patch level is a legal glPatchParameterfv value and has to equal itself; bits
  5..17 are composed with a mixing hash, which can in principle collide, and that is stated in
  the file and is acceptable only because nothing consumes those bits in P2.
- The shutter for bits 6..8 reads the current program's version counters WITHOUT
  GetProgramForDraw, so the walk never joins a pending link to answer "did the shader move".
- Header-only rather than Tracker.{h,cpp}: the root CMakeLists.txt that would have to name a
  new .cpp belongs to package A and is frozen behind the p2/contract tag. One translation unit
  in the library includes it, so inline costs nothing, and splitting it out is one list(APPEND)
  line whenever the ownership allows.
- MG_Test/ScopedPipeVerb.h and MG_Test/Pipe/PipeInputsTest.cpp follow the rename. Five comment
  references to the old name live in package A's files (MGPipe.h, the two generated .inc, and
  gen_pipe.py) and are deliberately left for their owner.
2026-09-07 23:18:09 -04:00

80 lines
3.8 KiB
C++

// MobileGL - MobileGL/MG_Test/ScopedPipeVerb.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 <MG_Pipe/MGPipe.h>
#if MOBILEGL_PIPE_PUSH
#include <MG_Impl/Pipe/PipeFill.h>
#endif
namespace MobileGL::MG_Test {
// "This test is standing inside verb X."
//
// A unit test that constructs a GLContext by hand and then calls a BACKEND helper
// directly enters through no GL entry point, so no MGP_FILL ever fires (P1 brief D7) and
// in a push build the PipeInputs block the helper's MGB_CTX reads is empty and unstamped:
// its first accessor read is Fatal{UnmigratedPipeInput, "Field@<none>"}. The test is
// right and the poison is right - what was missing is the verb, and this object is how a
// test states it. Constructing it runs the real filler for `verb`, exactly the call
// MG_Impl makes before that verb reaches a backend; destroying it leaves the verb again.
//
// It is not an escape hatch and it weakens nothing:
// - it fills exactly kMGPipeClassFieldMask[class of verb] out of the live GLContext, so
// a read of a field that verb does not fill is still Fatal, naming the field and this
// verb - the fill table stays the only thing that says what a verb may read;
// - leaving the scope re-arms the poison. The exit fill is a kQuery verb, whose class
// mask is a single field, so every field this scope stamped goes stale the moment the
// scope ends. That matters when the suite runs as one process (a developer running
// the test binary directly, rather than one ctest entry per case): without it, one
// case's declaration would cover a later case that forgot to make one;
// - it is a no-op in the pull build, where MGB_CTX is the live context and there is
// nothing to fill, so the pull build stays byte-identical.
//
// Place it the way MGP_FILL is placed in production (P1 brief D7): immediately BEFORE the
// backend call, after every frontend mutation that call is meant to see. A test that
// drives the helper again with frontend state changed in between issues a second verb -
// Renew() - because that is what a second GL entry point would have done. A test that
// drives a helper of a DIFFERENT verb class opens a nested scope for it.
class ScopedPipeVerb {
public:
explicit ScopedPipeVerb([[maybe_unused]] MG_Pipe::MGPipeVerb verb)
#if MOBILEGL_PIPE_PUSH
: m_verb(verb) {
MG_Pipe::MGPipeValidateForVerb(m_verb);
}
#else
{
}
#endif
ScopedPipeVerb(const ScopedPipeVerb&) = delete;
ScopedPipeVerb& operator=(const ScopedPipeVerb&) = delete;
// A second verb of the same kind begins: re-fill and re-stamp, so a helper driven
// again after the test moved frontend state sees the new values, the way the next GL
// entry point's MGP_FILL would.
void Renew() {
#if MOBILEGL_PIPE_PUSH
MG_Pipe::MGPipeValidateForVerb(m_verb);
#endif
}
#if MOBILEGL_PIPE_PUSH
// Leaving bumps the serial and puts the current verb back to "none": every field
// this scope stamped goes stale, and a later test that forgets its own declaration
// aborts with "<Field>@<none>" rather than with the name of a verb it never issued.
// That matters when the suite runs as one process (a developer running the test
// binary directly, rather than one ctest entry per case).
~ScopedPipeVerb() { MG_Pipe::MGPipeLeaveVerb(); }
private:
MG_Pipe::MGPipeVerb m_verb;
#endif
};
} // namespace MobileGL::MG_Test