[Perf] (MG_Pipe): inline process applier, a precomputed residual-fill walk, word-wise uniform spans and memo-answered draw bindings (rd12 monolith Espryt 83.5 -> 88.6, Magma 67.0 -> 69.5 fps).

This commit is contained in:
2026-10-07 15:21:58 -04:00
parent 81bdfb1f80
commit 94705adccd
6 changed files with 129 additions and 29 deletions
+23 -6
View File
@@ -793,7 +793,12 @@ namespace MobileGL::MG_Pipe {
if (const auto hook = g_compileEnvChangedHook.load(std::memory_order_acquire)) hook();
}
MGPipeApplierState& MGPipeApplier() {
namespace Detail {
void* g_applierResolverInstalled = nullptr;
MGPipeApplierState* g_processApplier = &g_defaultApplier;
} // namespace Detail
MGPipeApplierState& MGPipeApplierForSession() {
const MGPipeApplierKeyResolver resolve = g_applierKeyResolver;
if (resolve == nullptr) return g_defaultApplier;
MGPipeApplierKey key;
@@ -815,7 +820,10 @@ namespace MobileGL::MG_Pipe {
return *applier;
}
void MGPipeSetApplierKeyResolver(MGPipeApplierKeyResolver resolver) { g_applierKeyResolver = resolver; }
void MGPipeSetApplierKeyResolver(MGPipeApplierKeyResolver resolver) {
g_applierKeyResolver = resolver;
Detail::g_applierResolverInstalled = reinterpret_cast<void*>(resolver);
}
void MGPipeApplierRegisterContext(Uint64 sessionKey, Uint64 contextToken, Uint64 shareGroupToken) {
std::lock_guard<std::mutex> guard(g_applierSessionsMutex);
@@ -2979,12 +2987,21 @@ namespace MobileGL::MG_Pipe {
MGPipeApplier().BoundVertexElements = handle.Handle;
// The array's kept bindings come back with it, through the same two applies their
// records take, so every serial and field moves exactly as it would for the records.
// (The apply writes the same entries back over themselves: harmless, and no copy.)
// The window copy and the serial bumps are the two applies' own (the kept set passed
// their gates when it arrived); only the store-back into this same record is skipped.
auto& applier = MGPipeApplier();
if (record->StoredBuffersValid) {
const MGPVertexBuffers header = record->StoredBuffersHeader;
MGPipeApplySetVertexBuffers(header, record->StoredBuffers.data());
const MGPVertexBuffers& header = record->StoredBuffersHeader;
for (Uint32 i = 0; i < header.Count; ++i) applier.VertexBuffers[header.Start + i] = record->StoredBuffers[i];
applier.VertexBufferStart = header.Start;
applier.VertexBufferCount = header.Count;
applier.VertexFetchBaseInstance = header.BaseInstance;
++applier.VertexBuffersSerial;
}
if (record->StoredIndexValid) {
applier.IndexBuffer = record->StoredIndex;
++applier.IndexBufferSerial;
}
if (record->StoredIndexValid) MGPipeApplySetIndexBuffer(record->StoredIndex);
}
void MGPipeApplyDeleteVertexElements(const MGPHandleOnly& handle) {
+15 -1
View File
@@ -1057,7 +1057,21 @@ namespace MobileGL::MG_Pipe {
// every other thread - the client process, the in-process client+server shape, a unit case,
// the whole monolith - it is the process-wide applier, which is what it has always been and
// is byte-for-byte the old behaviour.
MGPipeApplierState& MGPipeApplier();
//
// P14: INLINE, because the backends ask it per state read (dozens of times per draw): in a
// process that serves no session - the whole monolith - no resolver is installed and the
// answer is the process-wide applier, a load and a branch with no call.
namespace Detail {
// Mirrors of PipeApply.cpp's g_applierKeyResolver / g_defaultApplier, written only there.
extern void* g_applierResolverInstalled;
extern MGPipeApplierState* g_processApplier;
} // namespace Detail
MGPipeApplierState& MGPipeApplierForSession();
inline MGPipeApplierState& MGPipeApplier() {
if (Detail::g_applierResolverInstalled == nullptr && Detail::g_processApplier != nullptr)
return *Detail::g_processApplier;
return MGPipeApplierForSession();
}
// P13 W6: the backend's "my capabilities changed" notice, without naming the frontend. A
// backend whose advertised limits / extensions move after a context exists (Magma's caps