mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-29 20:52:16 +09:00
[Fix, Test] (DirectGLES, pipe, tests): isolate server buffer lookup and verify FBO ownership
This commit is contained in:
1 parent
04f7faedc1
commit
df0e1d3bdd
13 files changed
+97
-111
No files matched your search
@@ -25,12 +25,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// the dedupe a {slot, gen} compare instead of a raw address compare. An address
|
||||
// a successor object can reproduce is the identity hazard this whole
|
||||
// phase is about; a handle cannot be reproduced (Gen moves on reuse).
|
||||
// the ensure EnsureBufferResourceForHandle(nullptr, Res). The frontend argument
|
||||
// is only ever used for BufferObject::SyncPersistentMappedRange, which
|
||||
// that function already skips under a transport (D-N), so passing
|
||||
// nullptr removes a read rather than dropping work - and (nullptr, h)
|
||||
// is already the live shape of the indirect-buffer ensure two hundred
|
||||
// lines below.
|
||||
// the ensure EnsureBufferResourceForHandle(Res) uses the same handle as the lookup.
|
||||
//
|
||||
// The IBO half lives in SyncNeccessaryBuffers beside the legacy one, for the reason it
|
||||
// always did: the index slot is not part of the configuration (D5).
|
||||
@@ -70,7 +65,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// attribute index to re-read attrib.Buffer; here the entry already
|
||||
// names the resource the record named, so the repair needs nothing the
|
||||
// walk did not already have.
|
||||
entry.resource = EnsureBufferResourceForHandle(nullptr, entry.handle);
|
||||
entry.resource = EnsureBufferResourceForHandle(entry.handle);
|
||||
}
|
||||
memo->vboCleanEpoch = allClean ? bufferEpoch : 0;
|
||||
}
|
||||
@@ -86,7 +81,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
const Uint syncedBufferCount = ResolveDrawVertexBuffersFromRecord(
|
||||
st, requests, MG_State::GLState::VertexArrayObject::MAX_VERTEX_ATTRIBS);
|
||||
for (Uint i = 0; i < syncedBufferCount; ++i) {
|
||||
auto* resource = EnsureBufferResourceForHandle(nullptr, requests[i].Res);
|
||||
auto* resource = EnsureBufferResourceForHandle(requests[i].Res);
|
||||
if (memo) {
|
||||
auto& entry = memo->entries[i];
|
||||
// Explicitly cleared rather than left as whatever the previous build of
|
||||
@@ -175,7 +170,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
} else if (identityHolds && IsBufferDrawCleanByHandle(iboHandle, memo->iboResource, nullptr)) {
|
||||
memo->iboCleanEpoch = bufferEpoch;
|
||||
} else {
|
||||
auto* resource = EnsureBufferResourceForHandle(nullptr, iboHandle);
|
||||
auto* resource = EnsureBufferResourceForHandle(iboHandle);
|
||||
if (memo) {
|
||||
memo->iboHandle = iboHandle;
|
||||
memo->iboSerial = iboSerial;
|
||||
@@ -196,7 +191,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// never read (T2). The twin's ensure is what SyncBoundBuffer's did.
|
||||
const MG_Pipe::MGPipeHandle handle = MG_Pipe::MGPipeApplier().VerbIndirectBuffer;
|
||||
if (!MG_Pipe::MGPipeHandleIsNull(handle)) {
|
||||
auto* resource = EnsureBufferResourceForHandle(nullptr, handle);
|
||||
auto* resource = EnsureBufferResourceForHandle(handle);
|
||||
if (resource && resource->id != 0) {
|
||||
BindBufferId(GL_DRAW_INDIRECT_BUFFER, resource->id);
|
||||
}
|
||||
@@ -299,7 +294,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
if (!span || i >= 4) continue;
|
||||
const auto& range = span->Targets[i];
|
||||
if (MG_Pipe::MGPipeHandleIsNull(range.Res) || range.Size == 0) continue;
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(nullptr, range.Res);
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(range.Res);
|
||||
if (!resource || resource->id == 0) continue;
|
||||
xfb.targets.push_back({nullptr, resource->id, static_cast<SizeT>(range.Offset),
|
||||
static_cast<SizeT>(range.Offset + range.Size), i, range.Res});
|
||||
@@ -1550,7 +1545,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BufferImpl::IsBufferDrawCleanByHandle(entry.Res, backendResource, nullptr)) {
|
||||
backendResource->drawCleanEpoch = bufferEpoch;
|
||||
} else {
|
||||
backendResource = BufferImpl::EnsureBufferResourceForHandle(nullptr, entry.Res);
|
||||
backendResource = BufferImpl::EnsureBufferResourceForHandle(entry.Res);
|
||||
}
|
||||
}
|
||||
if (backendResource && backendResource->id != 0) {
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BindBufferBaseCached(glTarget, static_cast<GLuint>(i), 0);
|
||||
continue;
|
||||
}
|
||||
auto* backendResource = EnsureBufferResourceForHandle(nullptr, entry.Res);
|
||||
auto* backendResource = EnsureBufferResourceForHandle(entry.Res);
|
||||
if (!backendResource || backendResource->id == 0) {
|
||||
MGLOG_E_ONCE("No backend buffer found for %s binding point %zu (handle {%u, %u}).",
|
||||
MG_Util::ConvertGLEnumToString(glTarget).c_str(), i, entry.Res.Slot, entry.Res.Gen);
|
||||
@@ -169,7 +169,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
BindBufferBaseCached(GL_SHADER_STORAGE_BUFFER, static_cast<Uint>(esslBinding), 0);
|
||||
continue;
|
||||
}
|
||||
auto* backendResource = EnsureBufferResourceForHandle(nullptr, entry->Res);
|
||||
auto* backendResource = EnsureBufferResourceForHandle(entry->Res);
|
||||
if (!backendResource || backendResource->id == 0) {
|
||||
MGLOG_E_ONCE("No backend buffer found for atomic counter binding point %d "
|
||||
"(handle {%u, %u}).",
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// record's handle, never the frontend binding slot or the client allocator.
|
||||
const MG_Pipe::MGPipeHandle handle = MG_Pipe::MGPipeApplier().VerbDispatchIndirectBuffer;
|
||||
if (!MG_Pipe::MGPipeHandleIsNull(handle)) {
|
||||
auto* resource = EnsureBufferResourceForHandle(nullptr, handle);
|
||||
auto* resource = EnsureBufferResourceForHandle(handle);
|
||||
if (resource && resource->id != 0) {
|
||||
BindBufferId(GL_DISPATCH_INDIRECT_BUFFER, resource->id);
|
||||
}
|
||||
|
||||
@@ -387,7 +387,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
const auto backendProgram = GetCurrentBackendProgram();
|
||||
const Int paramsBinding = backendProgram ? backendProgram->GetIndirectParamsBinding() : -1;
|
||||
if (paramsBinding >= 0) {
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(nullptr, verbBufferHandle);
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(verbBufferHandle);
|
||||
if (resource && resource->id != 0) {
|
||||
BufferImpl::BindBufferBaseCached(GL_SHADER_STORAGE_BUFFER, static_cast<GLuint>(paramsBinding),
|
||||
resource->id);
|
||||
@@ -468,7 +468,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
const auto backendProgram = GetCurrentBackendProgram();
|
||||
const Int paramsBinding = backendProgram ? backendProgram->GetIndirectParamsBinding() : -1;
|
||||
if (paramsBinding >= 0) {
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(nullptr, verbBufferHandle);
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(verbBufferHandle);
|
||||
if (resource && resource->id != 0) {
|
||||
BufferImpl::BindBufferBaseCached(GL_SHADER_STORAGE_BUFFER, static_cast<GLuint>(paramsBinding),
|
||||
resource->id);
|
||||
@@ -1137,8 +1137,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
const SizeT commandBytes = commandOffset + static_cast<SizeT>(stride) * static_cast<SizeT>(maxdrawcount - 1) +
|
||||
sizeof(DrawElementsIndirectCommand);
|
||||
auto* drawResource = BufferImpl::FindBufferResourceForHandle(applierState.VerbIndirectBuffer);
|
||||
auto* paramResource =
|
||||
BufferImpl::EnsureBufferResourceForHandle(nullptr, applierState.VerbIndirectParameterBuffer);
|
||||
auto* paramResource = BufferImpl::EnsureBufferResourceForHandle(applierState.VerbIndirectParameterBuffer);
|
||||
// P8-C: the count is CONSUMED here, so the parameter buffer is made current first
|
||||
// (a store a shader wrote on this side is read back); the command buffer only gets a
|
||||
// first copy when it has none - its fields are made current by the executor, and
|
||||
@@ -1250,8 +1249,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
const SizeT commandBytes = commandOffset + static_cast<SizeT>(stride) * static_cast<SizeT>(maxdrawcount - 1) +
|
||||
sizeof(DrawArraysIndirectCommand);
|
||||
auto* drawResource = BufferImpl::FindBufferResourceForHandle(applierState.VerbIndirectBuffer);
|
||||
auto* paramResource =
|
||||
BufferImpl::EnsureBufferResourceForHandle(nullptr, applierState.VerbIndirectParameterBuffer);
|
||||
auto* paramResource = BufferImpl::EnsureBufferResourceForHandle(applierState.VerbIndirectParameterBuffer);
|
||||
// P8-C: the count is CONSUMED here, so the parameter buffer is made current first
|
||||
// (a store a shader wrote on this side is read back); the command buffer only gets a
|
||||
// first copy when it has none - its fields are made current by the executor, and
|
||||
|
||||
@@ -1042,8 +1042,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// at the definition; passing null means "no live map", not "unknown".
|
||||
Bool IsBufferDrawCleanByHandle(MG_Pipe::MGPipeHandle res, const GLESBufferResource* resource,
|
||||
const MG_State::GLState::BufferObject* frontend);
|
||||
GLESBufferResource* EnsureBufferResourceForHandle(
|
||||
const SharedPtr<MG_State::GLState::BufferObject>& bufferObject, MG_Pipe::MGPipeHandle res);
|
||||
GLESBufferResource* EnsureBufferResourceForHandle(MG_Pipe::MGPipeHandle res);
|
||||
|
||||
// The applier's stored extent for this resource, 0 when it has no record. The one
|
||||
// thing outside BufferImpl that needs it is the fp64 narrowing, whose source extent
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "ManagersInternal.h"
|
||||
|
||||
#include <MG_Impl/Pipe/ResourceTracker.h>
|
||||
#include <MG_Pipe/MGPipeCallbacks.h>
|
||||
|
||||
namespace MobileGL::MG_Backend::DirectGLES {
|
||||
constexpr Bool PREFER_MAP_BUFFER_RANGE_FOR_BUFFER_SYNC = false;
|
||||
@@ -853,7 +853,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
if (CanTouchGLNow() &&
|
||||
(resource->id == 0 || !resource->storageInitialized || resource->pendingRespecify ||
|
||||
resource->contextGeneration != g_bufferContextGeneration)) {
|
||||
resource = EnsureBufferResourceForHandle(nullptr, res);
|
||||
resource = EnsureBufferResourceForHandle(res);
|
||||
}
|
||||
if (resource != nullptr && CanTouchGLNow() && resource->id != 0 && resource->storageInitialized &&
|
||||
!resource->persistentMapped && !resource->pendingRespecify &&
|
||||
@@ -1017,7 +1017,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Bool Ops_H_Readback(MG_Pipe::MGPipeHandle res, const MG_Pipe::MGPReadback& record) {
|
||||
// Check the context before ensure, which may allocate driver storage.
|
||||
if (!CanTouchGLNow()) return false;
|
||||
auto* resource = EnsureBufferResourceForHandle(nullptr, res);
|
||||
auto* resource = EnsureBufferResourceForHandle(res);
|
||||
if (!resource || resource->id == 0 || !resource->storageInitialized || resource->pendingRespecify ||
|
||||
resource->contextGeneration != g_bufferContextGeneration) {
|
||||
return false;
|
||||
@@ -2242,25 +2242,10 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return resource->syncedChangeSerial.load(std::memory_order_acquire) == record->Serial;
|
||||
}
|
||||
|
||||
// A split server reads its own staged bytes. A local backend can resolve a live shadow
|
||||
// by handle to refresh an alias after the frontend reallocates it.
|
||||
GLESBufferResource* EnsureBufferResourceForHandle(
|
||||
const SharedPtr<MG_State::GLState::BufferObject>& bufferObject, MG_Pipe::MGPipeHandle res) {
|
||||
GLESBufferResource* EnsureBufferResourceForHandle(MG_Pipe::MGPipeHandle res) {
|
||||
auto* resource = GetOrCreateBufferResourceForHandle(res);
|
||||
if (!resource) return nullptr;
|
||||
|
||||
const MG_State::GLState::BufferObject* frontend = nullptr;
|
||||
const auto liveHostBase = [&](SizeT width) -> const Uint8* {
|
||||
if (!MG_Config::RecordArmAliasesFrontend()) return resource->hostBytes;
|
||||
if (!frontend) {
|
||||
frontend =
|
||||
bufferObject ? bufferObject.get() : MG_Pipe::MGPipeResourceTrackerInstance().Resolve(res);
|
||||
}
|
||||
if (!frontend) return resource->hostBytes;
|
||||
if (frontend->GetSize() != width || frontend->IsBackendPersistentMapped()) return nullptr;
|
||||
return frontend->MappedData();
|
||||
};
|
||||
|
||||
if (resource->contextGeneration != g_bufferContextGeneration) {
|
||||
// A stale driver name cannot be reused in the new context. Keep any
|
||||
// shadow staged by records that preceded the first use of this twin.
|
||||
@@ -2324,9 +2309,20 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
return resource;
|
||||
}
|
||||
|
||||
const auto* record = ResourceRecordOf(res);
|
||||
const SizeT size = record != nullptr ? static_cast<SizeT>(record->Desc.Width) : 0;
|
||||
// Refresh the borrowed monolith alias after a resize or a revoked mapping.
|
||||
// Transport consumers use only the bytes staged by records.
|
||||
std::optional<MG_Pipe::MGPipeLocalBufferShadow> shadow;
|
||||
if (size != 0 && MG_Config::RecordArmAliasesFrontend() && MG_Pipe::gMGPipeQueryLocalBufferShadow) {
|
||||
shadow = MG_Pipe::gMGPipeQueryLocalBufferShadow(res, size);
|
||||
if (shadow) resource->hostBytes = shadow->Bytes;
|
||||
}
|
||||
const Uint8* const hostBase = resource->hostBytes;
|
||||
|
||||
if (resource->id == 0) {
|
||||
const SizeT poolSize = ResourceWidthOf(res);
|
||||
const Uint8* const poolBytes = liveHostBase(poolSize);
|
||||
const SizeT poolSize = size;
|
||||
const Uint8* const poolBytes = hostBase;
|
||||
const Bool canReuse =
|
||||
poolSize > 0 && !resource->persistentMapped && !resource->immutableStorage && poolBytes != nullptr;
|
||||
const Uint reused = canReuse ? AcquireFromPool(poolSize) : 0;
|
||||
@@ -2371,22 +2367,18 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
}
|
||||
}
|
||||
|
||||
const auto* record = ResourceRecordOf(res);
|
||||
const SizeT size = record != nullptr ? static_cast<SizeT>(record->Desc.Width) : 0;
|
||||
if (size == 0) {
|
||||
return resource;
|
||||
}
|
||||
const Uint64 serial = record->Serial;
|
||||
const GLenum usage = MG_Util::ConvertBufferUsageToGLEnum(static_cast<BufferUsage>(record->Desc.Usage));
|
||||
const Uint8* const hostBase = liveHostBase(size);
|
||||
if (frontend) resource->hostBytes = hostBase;
|
||||
|
||||
// Upload only surviving host content. Adoption drops the shadow.
|
||||
const Bool shadowHasContent =
|
||||
frontend ? frontend->HasDefinedContent()
|
||||
: (record->Desc.HasDefinedContent != 0 ||
|
||||
(ServerStaged().CopiesIntoServerStorage() ? ServerStaged().CoveredRunCount(resource) != 0
|
||||
: resource->contentSinceRespecify));
|
||||
shadow ? shadow->HasDefinedContent
|
||||
: (record->Desc.HasDefinedContent != 0 ||
|
||||
(ServerStaged().CopiesIntoServerStorage() ? ServerStaged().CoveredRunCount(resource) != 0
|
||||
: resource->contentSinceRespecify));
|
||||
const void* initialData = shadowHasContent ? hostBase : nullptr;
|
||||
const auto requireWholeStoreCoverage = [&]() {
|
||||
if (initialData != nullptr && record->Desc.HasDefinedContent != 0) {
|
||||
|
||||
@@ -362,8 +362,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
|
||||
Uint64 ResourceSerialForHandle(MG_Pipe::MGPipeHandle res);
|
||||
|
||||
GLESBufferResource* EnsureBufferResourceForHandle(
|
||||
const SharedPtr<MG_State::GLState::BufferObject>& bufferObject, MG_Pipe::MGPipeHandle res);
|
||||
GLESBufferResource* EnsureBufferResourceForHandle(MG_Pipe::MGPipeHandle res);
|
||||
|
||||
void BindBufferId(GLenum target, Uint id);
|
||||
|
||||
|
||||
@@ -2300,15 +2300,6 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
// BufSize` name the range, so the frontend binding slot below is not read at all
|
||||
// on the handle arm.
|
||||
//
|
||||
// The one thing that argument had to answer is D-A4's `frontend` parameter of
|
||||
// EnsureBufferResourceForHandle, which existed for the emulated-persistent-map
|
||||
// question. The E note's reading is confirmed at this head: that function's three
|
||||
// frontend reads (Managers.cpp's MappedData / SyncPersistentMappedRange /
|
||||
// HasDefinedContent) are all inside its MONOLITH arm - under an active transport
|
||||
// it is client-free (kimi audit row 29) - so `nullptr` is not a hole, it is the
|
||||
// whole of the split answer, and it is what §4.2's Buffer row already prescribes
|
||||
// (`EnsureBufferResourceForHandle(nullptr, h)`).
|
||||
//
|
||||
// WHOLE-VS-RANGE likewise stops asking the buffer object for its size: the
|
||||
// sentinel kMGPipeWholeBuffer IS "the whole store", which is the question
|
||||
// `rangeSize == buffer->GetSize()` was spelling the long way round.
|
||||
@@ -2351,7 +2342,7 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
||||
Bool needsRegeneration = !m_isInitialized || (currentTextureInfo != m_prevTextureInfo);
|
||||
|
||||
// Need to sync texture buffer if not synced yet
|
||||
auto* backendBufferResource = BufferImpl::EnsureBufferResourceForHandle(buffer, pushedTexBuffer);
|
||||
auto* backendBufferResource = BufferImpl::EnsureBufferResourceForHandle(pushedTexBuffer);
|
||||
if (!backendBufferResource || backendBufferResource->id == 0) {
|
||||
MGLOG_E_ONCE("Failed to sync backing buffer for texture buffer with ID: %u",
|
||||
MGB_TEXTURE_DIAG_NAME(pushedStorage, stateTextureObject));
|
||||
|
||||
@@ -215,7 +215,7 @@ namespace MobileGL::MG_Backend::DirectGLES::MultiDrawImpl {
|
||||
return view;
|
||||
}
|
||||
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(nullptr, res);
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(res);
|
||||
if (resource == nullptr) RefuseMissingIndexBufferRecord(entry, res, "backend resource");
|
||||
view.Id = resource->id;
|
||||
if (question == IndexBufferQuestion::DriverNameAndSize) {
|
||||
@@ -266,7 +266,7 @@ namespace MobileGL::MG_Backend::DirectGLES::MultiDrawImpl {
|
||||
Uint BoundDrawIndirectBufferId() {
|
||||
const MG_Pipe::MGPipeHandle res = MG_Pipe::MGPipeApplier().VerbIndirectBuffer;
|
||||
if (MG_Pipe::MGPipeHandleIsNull(res)) return 0;
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(nullptr, res);
|
||||
auto* resource = BufferImpl::EnsureBufferResourceForHandle(res);
|
||||
if (resource == nullptr) {
|
||||
RefuseMissingIndirectBufferRecord("BoundDrawIndirectBufferId", res);
|
||||
}
|
||||
|
||||
@@ -596,6 +596,13 @@ namespace MobileGL::MG_Pipe {
|
||||
buffer->MarkGpuWrittenInChannelOrder();
|
||||
}
|
||||
|
||||
inline std::optional<MGPipeLocalBufferShadow> MGPipeClientQueryLocalBufferShadow(MGPipeHandle res, SizeT width) {
|
||||
const auto* buffer = MGPipeResourceTrackerInstance().Resolve(res);
|
||||
if (buffer == nullptr) return std::nullopt;
|
||||
if (buffer->GetSize() != width || buffer->IsBackendPersistentMapped()) return MGPipeLocalBufferShadow{};
|
||||
return MGPipeLocalBufferShadow{buffer->MappedData(), buffer->HasDefinedContent()};
|
||||
}
|
||||
|
||||
// MONOLITH ONLY (CONTRACT-P5C §4.1): with an active transport the three reverse entries
|
||||
// of gMGPipeCallbacks are the SERVER session's producer callbacks and the client
|
||||
// consumers are invoked BY NAME from DrainEventRing - the global table is a
|
||||
@@ -620,6 +627,7 @@ namespace MobileGL::MG_Pipe {
|
||||
};
|
||||
install(gMGPipeCallbacks.OnBufferWriteback, &MGPipeClientOnBufferWriteback, "OnBufferWriteback");
|
||||
install(gMGPipeCallbacks.OnGpuWritten, &MGPipeClientOnGpuWritten, "OnGpuWritten");
|
||||
install(gMGPipeQueryLocalBufferShadow, &MGPipeClientQueryLocalBufferShadow, "QueryLocalBufferShadow");
|
||||
}
|
||||
|
||||
// Legacy-object entry for the monolith backend. Transport consumers carry handles
|
||||
|
||||
@@ -45,6 +45,16 @@ namespace MobileGL::MG_Pipe {
|
||||
// Null-initialized: a backend that installs nothing sends nothing.
|
||||
inline MGPipeCallbacks gMGPipeCallbacks{};
|
||||
|
||||
struct MGPipeLocalBufferShadow {
|
||||
const Uint8* Bytes = nullptr;
|
||||
Bool HasDefinedContent = false;
|
||||
};
|
||||
|
||||
// Monolith only. The optional is empty for an unknown handle. A known buffer can have
|
||||
// no shadow at the requested width. The bytes are borrowed for the current buffer sync.
|
||||
using MGPipeLocalBufferShadowQuery = std::optional<MGPipeLocalBufferShadow> (*)(MGPipeHandle, SizeT);
|
||||
inline MGPipeLocalBufferShadowQuery gMGPipeQueryLocalBufferShadow = nullptr;
|
||||
|
||||
// Size of the SEG_EVENT ring, which bounds one reverse-channel record. OnBufferWriteback
|
||||
// carries its bytes inline, and the ring producer always refuses a record above half its
|
||||
// capacity (Transport/Ring.h) with Fatal{EventRingOverflow}, so producers slice wide ranges
|
||||
|
||||
@@ -2811,18 +2811,21 @@ TEST(DirectGLESBackendFramebuffer, DestructorDeletesIdAndScrubsBindingShadow) {
|
||||
}
|
||||
ASSERT_EQ(mocks.sinks.framebuffers.size(), 1u);
|
||||
EXPECT_EQ(mocks.sinks.framebuffers[0], id);
|
||||
// ES reverts every target bound to a deleted framebuffer to 0. The shadow has to follow, or
|
||||
// the next BindFramebufferId(0) is deduped away and the driver keeps the dead name bound.
|
||||
// ES resets any target bound to the deleted framebuffer to 0.
|
||||
EXPECT_EQ(FramebufferImpl::CurrentFramebufferBinding(MobileGL::FramebufferTarget::Draw), 0u);
|
||||
|
||||
// A twin whose context died must NOT delete a name a successor context may have recycled.
|
||||
{
|
||||
auto backendFBO = MobileGL::MakeShared<FramebufferImpl::BackendFramebufferObject>();
|
||||
++g_backendContextGeneration;
|
||||
backendFBO.reset();
|
||||
--g_backendContextGeneration; // restore for later tests
|
||||
EXPECT_EQ(mocks.sinks.framebuffers.size(), 1u);
|
||||
}
|
||||
// A successor context can reuse the same name for its own framebuffer.
|
||||
auto& boundSerial = t_nativeContextThread.BoundSerial;
|
||||
const auto previousSerial = boundSerial;
|
||||
boundSerial = 1;
|
||||
auto oldFBO = MobileGL::MakeShared<FramebufferImpl::BackendFramebufferObject>();
|
||||
const auto reusedId = oldFBO->GetBackendFramebufferId();
|
||||
boundSerial = 2;
|
||||
FramebufferImpl::BindFramebufferId(GL_READ_FRAMEBUFFER, reusedId);
|
||||
oldFBO.reset();
|
||||
EXPECT_EQ(mocks.sinks.framebuffers.size(), 1u);
|
||||
EXPECT_EQ(FramebufferImpl::CurrentFramebufferBinding(MobileGL::FramebufferTarget::Read), reusedId);
|
||||
boundSerial = previousSerial;
|
||||
}
|
||||
|
||||
TEST(DirectGLESBackendRenderbuffer, DestructorDeletesId) {
|
||||
|
||||
@@ -1723,7 +1723,7 @@ namespace {
|
||||
}
|
||||
|
||||
MG_Backend::DirectGLES::BufferImpl::GLESBufferResource* Ensure(MG_Pipe::MGPipeHandle res) {
|
||||
return MG_Backend::DirectGLES::BufferImpl::EnsureBufferResourceForHandle({}, res);
|
||||
return MG_Backend::DirectGLES::BufferImpl::EnsureBufferResourceForHandle(res);
|
||||
}
|
||||
|
||||
MG_Backend::DirectGLES::BufferImpl::GLESBufferResource* Twin(MG_Pipe::MGPipeHandle res) {
|
||||
@@ -2365,16 +2365,8 @@ TEST(StagedShadowProductionTest, ATwinSurvivingContextLossDropsItsFreedShadowBas
|
||||
fixture.TearDown();
|
||||
}
|
||||
|
||||
// M-2 / ID-52 item 3, SHIPPED AND EXECUTED (joint report joint-v1.md 3, "Audit and its R-16
|
||||
// limit": the corrupt-staged-bytes perturbation existed only by hand). Under an active transport
|
||||
// the server's staged copy is the draw's ONLY base; the frontend object's MappedData() - which under
|
||||
// inproc is the same process's memory and always non-null - may not be read. So: a real frontend
|
||||
// BufferObject whose shadow holds pattern A, a server shadow staged with pattern B through the real
|
||||
// op table (what resource_subdata delivers), and the production ensure path given BOTH. The driver
|
||||
// store must hold B. That is the executable form of "corrupt only the staged bytes and the draw
|
||||
// shows it": B is the corruption, the upload is the draw, the mapped read-back is the picture. Red
|
||||
// once by restoring the MappedData() fallback in liveHostBase(): the store then holds A, the
|
||||
// client's bytes, and the R-2.5 audit could never reach a draw again.
|
||||
// The split server must use its staged copy even when the same process has a live
|
||||
// frontend shadow for the same handle and the monolith query is installed.
|
||||
TEST(StagedShadowProductionTest, TheEnsurePathUploadsTheServerShadowNotTheClientObjectsBytes) {
|
||||
EglServerFixture fixture;
|
||||
MGL_EGL_BRING_UP_OR_BAIL(fixture);
|
||||
@@ -2388,36 +2380,39 @@ TEST(StagedShadowProductionTest, TheEnsurePathUploadsTheServerShadowNotTheClient
|
||||
ASSERT_EQ(buffer->MappedData()[0], 0xA5);
|
||||
ASSERT_TRUE(buffer->HasDefinedContent());
|
||||
|
||||
// Keep this object coherently mapped: Ensure's retained backend sync site must not
|
||||
// re-enter the client producer and replace the staged 0x5B bytes with this 0xA5 map.
|
||||
// Keep a live coherent map while the server consumes the staged copy.
|
||||
ASSERT_NE(buffer->AcquireMemoryRange({0, 64}, BufferMappingAccessBit::Write | BufferMappingAccessBit::Persistent |
|
||||
BufferMappingAccessBit::Coherent),
|
||||
nullptr);
|
||||
ASSERT_TRUE(buffer->IsMapped());
|
||||
|
||||
// The server shadow for the twin the draw will use: B, staged the way the wire delivers it.
|
||||
const MG_Pipe::MGPipeHandle res = DeclareBuffer(BufferDesc(26, 64, true));
|
||||
auto desc = BufferDesc(0, 64, true);
|
||||
desc.Resource = MG_Pipe::MGPipeResourceTrackerInstance().Find(*buffer);
|
||||
ASSERT_FALSE(MG_Pipe::MGPipeHandleIsNull(desc.Resource));
|
||||
const MG_Pipe::MGPipeHandle res = DeclareBuffer(desc);
|
||||
StageBytes(res, 0, 64, 0x5B);
|
||||
|
||||
// The production ensure, WITH the frontend object (the draw-time shape), on the apply thread;
|
||||
// then the driver's store read back through a READ map on the same thread.
|
||||
Vector<Uint8> store(64, 0);
|
||||
Bool ensured = false;
|
||||
Bool mapped = false;
|
||||
ASSERT_EQ(OnApply([&] {
|
||||
ensured = MG_Backend::DirectGLES::BufferImpl::EnsureBufferResourceForHandle(buffer, res) != nullptr;
|
||||
auto* twin = Twin(res);
|
||||
if (!ensured || twin == nullptr || twin->id == 0) return;
|
||||
const auto& gl = MG_Backend::DirectGLES::g_GLESFuncs;
|
||||
gl.glBindBuffer(GL_ARRAY_BUFFER, twin->id);
|
||||
void* view = gl.glMapBufferRange(GL_ARRAY_BUFFER, 0, 64, GL_MAP_READ_BIT);
|
||||
if (view != nullptr) {
|
||||
std::memcpy(store.data(), view, 64);
|
||||
gl.glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
mapped = true;
|
||||
}
|
||||
}),
|
||||
MOBILEGL_OK);
|
||||
const auto savedQuery = MG_Pipe::gMGPipeQueryLocalBufferShadow;
|
||||
MG_Pipe::gMGPipeQueryLocalBufferShadow = &MG_Pipe::MGPipeClientQueryLocalBufferShadow;
|
||||
const auto result = OnApply([&] {
|
||||
ensured = Ensure(res) != nullptr;
|
||||
auto* twin = Twin(res);
|
||||
if (!ensured || twin == nullptr || twin->id == 0) return;
|
||||
const auto& gl = MG_Backend::DirectGLES::g_GLESFuncs;
|
||||
gl.glBindBuffer(GL_ARRAY_BUFFER, twin->id);
|
||||
void* view = gl.glMapBufferRange(GL_ARRAY_BUFFER, 0, 64, GL_MAP_READ_BIT);
|
||||
if (view != nullptr) {
|
||||
std::memcpy(store.data(), view, 64);
|
||||
gl.glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
mapped = true;
|
||||
}
|
||||
});
|
||||
MG_Pipe::gMGPipeQueryLocalBufferShadow = savedQuery;
|
||||
ASSERT_EQ(result, MOBILEGL_OK);
|
||||
ASSERT_TRUE(ensured);
|
||||
ASSERT_TRUE(mapped) << "the driver store could not be mapped for reading, so the case cannot see the upload";
|
||||
|
||||
@@ -2457,10 +2452,6 @@ namespace {
|
||||
[[noreturn]] void RunTheStreamingIdiomAndExit(IdiomArm arm) {
|
||||
EglServerFixture fixture;
|
||||
if (!fixture.BringUp().empty() || !fixture.MakeCurrent()) ::_exit(8);
|
||||
Vector<Uint8> sixteen(16, Uint8{0x77});
|
||||
auto buffer = MakeShared<MG_State::GLState::BufferObject>(arm == IdiomArm::PoolReuse ? 33u : 32u);
|
||||
buffer->Respecify(64, nullptr);
|
||||
buffer->UploadSubData(DataPtr{sixteen.data(), sixteen.size()}, 0);
|
||||
Bool ok = false;
|
||||
(void)OnApply([&] {
|
||||
if (arm == IdiomArm::PoolReuse) {
|
||||
@@ -2476,7 +2467,7 @@ namespace {
|
||||
const Uint32 slot = arm == IdiomArm::PoolReuse ? 30u : 28u;
|
||||
const MG_Pipe::MGPipeHandle b = DeclareBuffer(BufferDesc(slot, 64, false));
|
||||
StageBytes(b, 0, 16, 0x77);
|
||||
auto* twin = MG_Backend::DirectGLES::BufferImpl::EnsureBufferResourceForHandle(buffer, b); // the draw
|
||||
auto* twin = Ensure(b); // the draw
|
||||
if (twin == nullptr || twin->id == 0) return;
|
||||
const auto& gl = MG_Backend::DirectGLES::g_GLESFuncs;
|
||||
gl.glBindBuffer(GL_ARRAY_BUFFER, twin->id);
|
||||
|
||||
Reference in new issue
Block a user