mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-21 00:41:57 +09:00
[Refactor] (P13): the legacy BufferBackendOps table, Magma's never-populated texture/render-pass/renderbuffer caches and VkClearManager go, and the buffer mock tests drive the resource op table instead (ratchet 36 -> 27).
This commit is contained in:
@@ -1556,7 +1556,7 @@ TEST_F(GeneralBufferTest, General_GeneralTest_1) {
|
||||
// ---------------------------------------------------------------------------
|
||||
// Zero-copy persistent-coherent mapping via the PipeResource layer (regression
|
||||
// guard for the GpuMemory OOM / rendering-corruption bug). A fake backend hands
|
||||
// out a block of "GPU" memory from AcquirePersistentMap; the frontend adopts it
|
||||
// out a block of "GPU" memory from MapPersistent; the frontend adopts it
|
||||
// as the buffer's storage. The test asserts (a) the app maps straight onto that
|
||||
// GPU memory, (b) EVERY reader (MappedData(), the accessor all backend consumers
|
||||
// now use) resolves to that same GPU memory rather than a stale shadow - the bug
|
||||
@@ -1583,50 +1583,53 @@ namespace {
|
||||
|
||||
ZeroCopyMockBackend* g_zeroCopyMock = nullptr;
|
||||
|
||||
void* ZeroCopyMock_AcquirePersistentMap(MG_State::GLState::BufferObject& bufferObject) {
|
||||
// P13: the mock is a MGPipeResourceOps table - the live resource family every backend
|
||||
// registers - and no longer the deleted BufferBackendOps table. The frontend reaches it the
|
||||
// way it reaches a real backend in monolith: the emitters build the records and the applier
|
||||
// dispatches them synchronously.
|
||||
void* ZeroCopyMock_MapPersistent(MG_Pipe::MGPipeHandle, Uint64 size, const void* seedBytes) {
|
||||
if (!g_zeroCopyMock || !g_zeroCopyMock->provideMap) return nullptr;
|
||||
if (g_zeroCopyMock->gpu.size() != bufferObject.GetSize()) {
|
||||
g_zeroCopyMock->gpu.assign(bufferObject.GetSize(), 0);
|
||||
// Seed from the shadow (still current: the frontend adopts only after we return).
|
||||
const Uint8* shadow = bufferObject.MappedData();
|
||||
if (shadow != nullptr && bufferObject.GetSize() > 0) {
|
||||
Memcpy(g_zeroCopyMock->gpu.data(), shadow, bufferObject.GetSize());
|
||||
if (g_zeroCopyMock->gpu.size() != size) {
|
||||
g_zeroCopyMock->gpu.assign(static_cast<SizeT>(size), 0);
|
||||
// Seed from the shadow the frontend hands over (it adopts only after we return).
|
||||
if (seedBytes != nullptr && size > 0) {
|
||||
Memcpy(g_zeroCopyMock->gpu.data(), seedBytes, static_cast<SizeT>(size));
|
||||
}
|
||||
}
|
||||
++g_zeroCopyMock->acquireMapCalls;
|
||||
return g_zeroCopyMock->gpu.data();
|
||||
}
|
||||
|
||||
void ZeroCopyMock_Respecify(MG_State::GLState::BufferObject&) {
|
||||
void ZeroCopyMock_Respecify(MG_Pipe::MGPipeHandle, const MG_Pipe::MGPResourceDesc&, const void*) {
|
||||
if (g_zeroCopyMock) ++g_zeroCopyMock->respecifyCalls;
|
||||
}
|
||||
void ZeroCopyMock_SubData(MG_State::GLState::BufferObject&, SizeT, SizeT) {
|
||||
void ZeroCopyMock_SubData(MG_Pipe::MGPipeHandle, const MG_Pipe::MGPSubData&, const void*) {
|
||||
if (g_zeroCopyMock) ++g_zeroCopyMock->subDataCalls;
|
||||
}
|
||||
void ZeroCopyMock_Flush(MG_State::GLState::BufferObject&, Range1D, Flags<BufferMappingAccessBit>) {
|
||||
void ZeroCopyMock_Flush(MG_Pipe::MGPipeHandle, const MG_Pipe::MGPFlushRange&, const void*) {
|
||||
if (g_zeroCopyMock) ++g_zeroCopyMock->flushCalls;
|
||||
}
|
||||
void ZeroCopyMock_OnDestroy(SharedPtr<MG_State::GLState::BackendBufferResource>&&) {}
|
||||
void ZeroCopyMock_Destroy(MG_Pipe::MGPipeHandle) {}
|
||||
|
||||
const MG_State::GLState::BufferBackendOps kZeroCopyMockOps = {
|
||||
const MG_Pipe::MGPipeResourceOps kZeroCopyMockOps = {
|
||||
.Respecify = ZeroCopyMock_Respecify,
|
||||
.SubData = ZeroCopyMock_SubData,
|
||||
.FlushMappedRange = ZeroCopyMock_Flush,
|
||||
.OnDestroy = ZeroCopyMock_OnDestroy,
|
||||
.AcquirePersistentMap = ZeroCopyMock_AcquirePersistentMap,
|
||||
.FlushRange = ZeroCopyMock_Flush,
|
||||
.Destroy = ZeroCopyMock_Destroy,
|
||||
.MapPersistent = ZeroCopyMock_MapPersistent,
|
||||
};
|
||||
|
||||
// The same backend with the GPU-ordered landing ops a staging-ring backend offers: a
|
||||
// CPU write into an adopted store is queued (the mapping is NOT written through), and
|
||||
// a readback is what lands the queue before the application reads.
|
||||
void ZeroCopyMock_ResidentSubData(MG_State::GLState::BufferObject&, SizeT offset, DataPtr data) {
|
||||
void ZeroCopyMock_ResidentSubData(MG_Pipe::MGPipeHandle, const MG_Pipe::MGPSubData& record, const void* bytes) {
|
||||
if (!g_zeroCopyMock) return;
|
||||
auto& write = g_zeroCopyMock->residentWrites.emplace_back();
|
||||
write.offset = offset;
|
||||
const auto* bytes = static_cast<const Uint8*>(data.data);
|
||||
write.bytes.assign(bytes, bytes + data.size);
|
||||
write.offset = static_cast<SizeT>(MG_Pipe::MGPipeSubDataBufferOffset(record));
|
||||
const auto* first = static_cast<const Uint8*>(bytes);
|
||||
write.bytes.assign(first, first + static_cast<SizeT>(MG_Pipe::MGPipeSubDataBufferSize(record)));
|
||||
}
|
||||
void ZeroCopyMock_ReadbackFromGpu(MG_State::GLState::BufferObject&) {
|
||||
void ZeroCopyMock_Readback(MG_Pipe::MGPipeHandle, const MG_Pipe::MGPReadback&) {
|
||||
if (!g_zeroCopyMock) return;
|
||||
++g_zeroCopyMock->readbackCalls;
|
||||
for (const auto& write : g_zeroCopyMock->residentWrites) {
|
||||
@@ -1639,32 +1642,32 @@ namespace {
|
||||
g_zeroCopyMock->residentWrites.clear();
|
||||
}
|
||||
|
||||
const MG_State::GLState::BufferBackendOps kResidentSubDataMockOps = {
|
||||
const MG_Pipe::MGPipeResourceOps kResidentSubDataMockOps = {
|
||||
.Respecify = ZeroCopyMock_Respecify,
|
||||
.SubData = ZeroCopyMock_SubData,
|
||||
.ResidentSubData = ZeroCopyMock_ResidentSubData,
|
||||
.FlushMappedRange = ZeroCopyMock_Flush,
|
||||
.OnDestroy = ZeroCopyMock_OnDestroy,
|
||||
.AcquirePersistentMap = ZeroCopyMock_AcquirePersistentMap,
|
||||
.ReadbackFromGpu = ZeroCopyMock_ReadbackFromGpu,
|
||||
.SubDataResident = ZeroCopyMock_ResidentSubData,
|
||||
.FlushRange = ZeroCopyMock_Flush,
|
||||
.Readback = ZeroCopyMock_Readback,
|
||||
.Destroy = ZeroCopyMock_Destroy,
|
||||
.MapPersistent = ZeroCopyMock_MapPersistent,
|
||||
};
|
||||
|
||||
// These cases are BufferBackendOps dispatch tests. Since P3a a push build also installs the
|
||||
// handle-shaped MGPipeResourceOps table at backend bring-up, and the frontend's push arms route
|
||||
// every buffer mutation there first; the fixture therefore scopes BOTH tables, the way
|
||||
// ResourceEmitTest's ApplierGuard scopes the applier, so the mock installed here is the arm
|
||||
// that actually runs. The pipe-side dispatch has its own coverage in ResourceEmitTest.
|
||||
// Installs the mock as the process's resource op table for the case and arms the resource
|
||||
// subsystem bit (a fixture that never ran Initialize() has not loaded the fixed mask), and
|
||||
// puts both back afterwards.
|
||||
struct ScopedBackendOps {
|
||||
explicit ScopedBackendOps(const MG_State::GLState::BufferBackendOps* ops) {
|
||||
MG_State::GLState::SetBufferBackendOps(ops);
|
||||
explicit ScopedBackendOps(const MG_Pipe::MGPipeResourceOps* ops) {
|
||||
m_savedPush = MG_Config::Features.PipePush;
|
||||
MG_Config::Features.PipePush |= MG_Pipe::kMGPipeSubsystemResources;
|
||||
m_savedResourceOps = MG_Pipe::MGPipeGetResourceOps();
|
||||
MG_Pipe::MGPipeSetResourceOps(nullptr);
|
||||
MG_Pipe::MGPipeSetResourceOps(ops);
|
||||
}
|
||||
~ScopedBackendOps() {
|
||||
MG_Pipe::MGPipeSetResourceOps(m_savedResourceOps);
|
||||
MG_State::GLState::SetBufferBackendOps(nullptr);
|
||||
MG_Config::Features.PipePush = m_savedPush;
|
||||
}
|
||||
const MG_Pipe::MGPipeResourceOps* m_savedResourceOps = nullptr;
|
||||
Uint64 m_savedPush = 0;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <Config.h>
|
||||
#include <MG_State/GLState/BufferState/BufferObject.h>
|
||||
#include <MG_Pipe/PipeApply.h>
|
||||
#include <MG_State/GLState/Core.h>
|
||||
#include <MG_State/GLState/TextureState/TextureObjectBuffer.h>
|
||||
#include <MG_State/GLState/TextureState/TextureState.h>
|
||||
@@ -42,20 +43,38 @@ namespace {
|
||||
using MG_Record::PersistentMapTracker;
|
||||
|
||||
// A backend that MINTS a persistent mapping, for the one case that needs the adopted arm
|
||||
// (TheAdoptedArmIsNotAMemberAndItIsTheChainRowThatSaysSo). Only AcquirePersistentMap is
|
||||
// filled in: the frontend null-checks every op individually, and a table with one live
|
||||
// member is the smallest thing that makes AcquireMemoryRange's legacy adoption arm fire.
|
||||
// The storage is the CASE's, not this table's - AdoptPersistentMap keeps the pointer and
|
||||
// never owns it - so the base travels through a file-scope variable the case sets and
|
||||
// clears around the one acquisition it wants minted.
|
||||
// (TheAdoptedArmIsNotAMemberAndItIsTheChainRowThatSaysSo): a resource op table (P13: the
|
||||
// only buffer op table there is) whose one live member is MapPersistent. The storage is the
|
||||
// CASE's, not this table's - AdoptPersistentMap keeps the pointer and never owns it - so the
|
||||
// base travels through a file-scope variable the case sets and clears.
|
||||
void* g_mintedPersistentBase = nullptr;
|
||||
void* MintPersistentMap(BufferObject&) { return g_mintedPersistentBase; }
|
||||
const MG_State::GLState::BufferBackendOps g_mintingBufferOps = [] {
|
||||
MG_State::GLState::BufferBackendOps ops{};
|
||||
ops.AcquirePersistentMap = &MintPersistentMap;
|
||||
void* MintPersistentMap(MG_Pipe::MGPipeHandle, Uint64, const void*) { return g_mintedPersistentBase; }
|
||||
const MG_Pipe::MGPipeResourceOps g_mintingResourceOps = [] {
|
||||
MG_Pipe::MGPipeResourceOps ops{};
|
||||
ops.MapPersistent = &MintPersistentMap;
|
||||
return ops;
|
||||
}();
|
||||
|
||||
// The window in which the case is a MONOLITH with that backend registered: the adopted buffer
|
||||
// is created, mapped and destroyed inside one, so its records are applied synchronously.
|
||||
struct ScopedMintingMonolith {
|
||||
ScopedMintingMonolith()
|
||||
: m_transport(MG_Config::Transport), m_push(MG_Config::Features.PipePush),
|
||||
m_ops(MG_Pipe::MGPipeGetResourceOps()) {
|
||||
MG_Config::Transport = MG_Config::TransportMode::Monolith;
|
||||
MG_Config::Features.PipePush |= MG_Pipe::kMGPipeSubsystemResources;
|
||||
MG_Pipe::MGPipeSetResourceOps(&g_mintingResourceOps);
|
||||
}
|
||||
~ScopedMintingMonolith() {
|
||||
MG_Pipe::MGPipeSetResourceOps(m_ops);
|
||||
MG_Config::Features.PipePush = m_push;
|
||||
MG_Config::Transport = m_transport;
|
||||
}
|
||||
MG_Config::TransportMode m_transport;
|
||||
Uint64 m_push;
|
||||
const MG_Pipe::MGPipeResourceOps* m_ops;
|
||||
};
|
||||
|
||||
// Everything in this package is gated on `Transport != Monolith`, so every case has to
|
||||
// put the process into a split configuration and put it back. A fixture rather than a
|
||||
// lambda because the tracker is a process-wide singleton and a case that left an entry in
|
||||
@@ -82,7 +101,6 @@ namespace {
|
||||
// Belt and braces for the one case that installs a minting backend: a table left
|
||||
// behind would make the NEXT case's acquisition land in the adopted arm, and every
|
||||
// membership assertion in this file would then be about a different code path.
|
||||
MG_State::GLState::SetBufferBackendOps(nullptr);
|
||||
g_mintedPersistentBase = nullptr;
|
||||
MG_Remote::Transport::ForgetAdoptTierSettlementForTest();
|
||||
PersistentMapTracker::Instance().ClearForTest();
|
||||
@@ -327,7 +345,11 @@ TEST_F(SplitBufferSet, TheAdoptedArmIsNotAMemberAndItIsTheChainRowThatSaysSo) {
|
||||
Vector<Uint8> minted(kSize, static_cast<Uint8>(0));
|
||||
g_mintedPersistentBase = minted.data();
|
||||
|
||||
auto adopted = MakeBuffer(27u, kSize);
|
||||
SharedPtr<BufferObject> adopted;
|
||||
{
|
||||
ScopedMintingMonolith minting;
|
||||
adopted = MakeBuffer(27u, kSize);
|
||||
}
|
||||
auto declined = MakeBuffer(28u, kSize);
|
||||
|
||||
// The declined twin first, with no backend ops at all: same flags, same size, same call.
|
||||
@@ -339,12 +361,9 @@ TEST_F(SplitBufferSet, TheAdoptedArmIsNotAMemberAndItIsTheChainRowThatSaysSo) {
|
||||
"assertion below proves nothing";
|
||||
|
||||
{
|
||||
MG_State::GLState::SetBufferBackendOps(&g_mintingBufferOps);
|
||||
MG_Config::Transport = MG_Config::TransportMode::Monolith;
|
||||
ScopedMintingMonolith minting;
|
||||
adopted->AcquireMemoryRange(Range1D{0, kSize},
|
||||
BufferMappingAccessBit::Write | BufferMappingAccessBit::Persistent);
|
||||
MG_Config::Transport = MG_Config::TransportMode::InProcess;
|
||||
MG_State::GLState::SetBufferBackendOps(nullptr);
|
||||
}
|
||||
ASSERT_TRUE(adopted->IsBackendPersistentMapped())
|
||||
<< "the backend declined the mint, so there is no adopted arm here to ask about";
|
||||
@@ -383,7 +402,10 @@ TEST_F(SplitBufferSet, TheAdoptedArmIsNotAMemberAndItIsTheChainRowThatSaysSo) {
|
||||
// being redefined, and a persistent map the application holds outlives every unmap by
|
||||
// definition (PipeResource.h:121-127). It is dropped here with the mapping still adopted,
|
||||
// which is also the shape ~BufferObject has to survive.
|
||||
adopted.reset();
|
||||
{
|
||||
ScopedMintingMonolith minting;
|
||||
adopted.reset();
|
||||
}
|
||||
g_mintedPersistentBase = nullptr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user