mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-18 07:23:24 +09:00
[Feat] (Pipe, State): mint a {slot, gen} handle for every buffer object and publish its create, respecify, sub-data, flush, readback and destroy as pipe calls
This commit is contained in:
@@ -34,9 +34,28 @@ namespace MobileGL::MG_State::GLState {
|
||||
|
||||
BufferObject::BufferObject(Uint externalIndex)
|
||||
: m_externalIndex(externalIndex), m_size(0), m_usage(BufferUsage::StaticDraw), m_isMapped(false),
|
||||
m_mappingAccess(BufferMappingAccessBit::Null), m_mappedRange({0, 0}), m_ownsStagingData{} {}
|
||||
m_mappingAccess(BufferMappingAccessBit::Null), m_mappedRange({0, 0}), m_ownsStagingData{} {
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P3a D-A2: a resource EXISTS before anything can name it, so resource_create is
|
||||
// emitted from the constructor and carries no storage - the store is defined lazily
|
||||
// by the first respecify and every backend already tolerates a resource with none.
|
||||
// The handle itself is minted whatever the subsystem bitmask says, because
|
||||
// set_vertex_buffers names this buffer by handle out of a different subsystem.
|
||||
MG_Pipe::MGPipeMintResourceHandle(*this);
|
||||
if (MG_Pipe::MGPipeResourceSubsystemEnabled()) MG_Pipe::MGPipeEmitResourceCreate(*this);
|
||||
#endif
|
||||
}
|
||||
|
||||
BufferObject::~BufferObject() {
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// P3a D-L: the buffer's death crosses as resource_destroy, which is the catalogue
|
||||
// call for it - no seventh NotifyStateObjectDestroyed raiser is added, because that
|
||||
// header exists for kinds that have no such call. The emit-then-free ORDER is fixed
|
||||
// inside the helper and is not negotiable.
|
||||
const Bool pushedResources = MG_Pipe::MGPipeResourceSubsystemEnabled();
|
||||
MG_Pipe::MGPipeEmitResourceDestroyAndFree(*this);
|
||||
if (pushedResources) return;
|
||||
#endif
|
||||
if (m_resource.Backend() && g_bufferBackendOps && g_bufferBackendOps->OnDestroy) {
|
||||
g_bufferBackendOps->OnDestroy(m_resource.ReleaseBackend());
|
||||
}
|
||||
@@ -45,6 +64,12 @@ namespace MobileGL::MG_State::GLState {
|
||||
void BufferObject::NotifyRespecify() {
|
||||
++m_changeSerial;
|
||||
MGP_NOTE_AGGREGATE(BufferChange);
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
if (MG_Pipe::MGPipeResourceSubsystemEnabled()) {
|
||||
MG_Pipe::MGPipeEmitResourceRespecify(*this);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (g_bufferBackendOps && g_bufferBackendOps->Respecify) {
|
||||
g_bufferBackendOps->Respecify(*this);
|
||||
}
|
||||
@@ -55,6 +80,12 @@ namespace MobileGL::MG_State::GLState {
|
||||
MGP_NOTE_AGGREGATE(BufferChange);
|
||||
if (size == 0) return;
|
||||
m_hasDefinedContent = true;
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
if (MG_Pipe::MGPipeResourceSubsystemEnabled()) {
|
||||
MG_Pipe::MGPipeEmitResourceSubData(*this, offset, size);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (g_bufferBackendOps && g_bufferBackendOps->SubData) {
|
||||
g_bufferBackendOps->SubData(*this, offset, size);
|
||||
}
|
||||
@@ -65,6 +96,16 @@ namespace MobileGL::MG_State::GLState {
|
||||
MGP_NOTE_AGGREGATE(BufferChange);
|
||||
if (range.start >= range.end) return;
|
||||
m_hasDefinedContent = true;
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
if (MG_Pipe::MGPipeResourceSubsystemEnabled()) {
|
||||
static_assert(sizeof(appAccess.GetRaw()) <= sizeof(Uint32),
|
||||
"MGPFlushRange::AccessFlags is a Uint32 and carries the application's "
|
||||
"real Flags<BufferMappingAccessBit>, unnormalised");
|
||||
MG_Pipe::MGPipeEmitResourceFlushRange(*this, range.start, range.end - range.start,
|
||||
static_cast<Uint32>(appAccess.GetRaw()));
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (g_bufferBackendOps && g_bufferBackendOps->FlushMappedRange) {
|
||||
g_bufferBackendOps->FlushMappedRange(*this, range, appAccess);
|
||||
}
|
||||
@@ -189,6 +230,12 @@ namespace MobileGL::MG_State::GLState {
|
||||
if (m_size < kLargeBufferAdoptBytes) return;
|
||||
if (m_resource.IsGpuResident()) return;
|
||||
if (m_isMapped) return;
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
if (MG_Pipe::MGPipeResourceSubsystemEnabled()) {
|
||||
if (void* base = MG_Pipe::MGPipeEmitMapPersistent(*this)) m_resource.AdoptPersistentMap(base);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (g_bufferBackendOps == nullptr || g_bufferBackendOps->AcquirePersistentMap == nullptr) return;
|
||||
if (void* base = g_bufferBackendOps->AcquirePersistentMap(*this)) {
|
||||
m_resource.AdoptPersistentMap(base);
|
||||
@@ -321,6 +368,17 @@ namespace MobileGL::MG_State::GLState {
|
||||
// Cleared unconditionally: without a readback op the shadow can never catch up,
|
||||
// and retrying on every subsequent read would only repeat the same no-op.
|
||||
m_gpuWritePending = false;
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
if (m_size != 0 && MG_Pipe::MGPipeResourceSubsystemEnabled()) {
|
||||
// The answer comes back through the reverse channel's OnBufferWriteback, which
|
||||
// resolves this handle to this object and writes the shadow before the server
|
||||
// bumps its mutation epoch. In monolith the whole sequence is synchronous inside
|
||||
// the applier, so the caller sees the reconciled shadow on return exactly as it
|
||||
// does today.
|
||||
MG_Pipe::MGPipeEmitResourceReadback(*this);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (m_size == 0 || g_bufferBackendOps == nullptr || g_bufferBackendOps->ReadbackFromGpu == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -369,6 +427,30 @@ namespace MobileGL::MG_State::GLState {
|
||||
// NotifyContentWrite on a resident store only bumps the serial: the backend has no
|
||||
// separate copy to sync, so no transfer op runs.
|
||||
void BufferObject::LandBytesIntoResidentStore(SizeT offset, DataPtr bytes) {
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// buffer_subdata_resident stays NULLABLE and stays asymmetric: one backend
|
||||
// deliberately does not implement it, and the frontend checks the pipe table exactly
|
||||
// as it checks the op table it replaces, so a backend without it keeps the legacy
|
||||
// ordered in-place host write below.
|
||||
if (bytes.size > 0 && MG_Pipe::MGPipeResourceSubsystemEnabled() &&
|
||||
MG_Pipe::MGPipeResourceOpsHaveSubDataResident()) {
|
||||
MG_Pipe::MGPipeEmitBufferSubDataResident(*this, offset, bytes.data, bytes.size);
|
||||
m_hasDefinedContent = true;
|
||||
++m_changeSerial;
|
||||
MGP_NOTE_AGGREGATE(BufferChange);
|
||||
m_gpuWritePending = true;
|
||||
return;
|
||||
}
|
||||
// No resident op: the write lands in place below, after retiring the GPU writes this
|
||||
// store is known to be waiting on - which is the same answer, and the same code, a
|
||||
// backend with a null ResidentSubData gets today.
|
||||
if (MG_Pipe::MGPipeResourceSubsystemEnabled()) {
|
||||
SyncGpuWrites();
|
||||
Memcpy(m_resource.Bytes() + offset, bytes.data, bytes.size);
|
||||
NotifyContentWrite(offset, bytes.size);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (bytes.size > 0 && g_bufferBackendOps && g_bufferBackendOps->ResidentSubData) {
|
||||
g_bufferBackendOps->ResidentSubData(*this, offset, bytes);
|
||||
m_hasDefinedContent = true;
|
||||
@@ -402,7 +484,16 @@ namespace MobileGL::MG_State::GLState {
|
||||
// op the landing would memcpy the expansion into the mapping the loop below
|
||||
// fills in place anyway, so a whole-arena clear would allocate a whole arena
|
||||
// for nothing.
|
||||
if (m_resource.IsGpuResident() && g_bufferBackendOps && g_bufferBackendOps->ResidentSubData) {
|
||||
if (m_resource.IsGpuResident() &&
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
// The same question, asked of whichever table owns the family in this build.
|
||||
(MG_Pipe::MGPipeResourceSubsystemEnabled()
|
||||
? MG_Pipe::MGPipeResourceOpsHaveSubDataResident()
|
||||
: (g_bufferBackendOps && g_bufferBackendOps->ResidentSubData))
|
||||
#else
|
||||
g_bufferBackendOps && g_bufferBackendOps->ResidentSubData
|
||||
#endif
|
||||
) {
|
||||
Vector<Uint8> expanded(size);
|
||||
if (pattern.size == 1) {
|
||||
Memset(expanded.data(), *static_cast<const Uint8*>(pattern.data), size);
|
||||
@@ -504,6 +595,14 @@ namespace MobileGL::MG_State::GLState {
|
||||
if (m_isMapped) {
|
||||
return false;
|
||||
}
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
if (m_size != 0 && MG_Pipe::MGPipeResourceSubsystemEnabled()) {
|
||||
void* pushedBase = MG_Pipe::MGPipeEmitMapPersistent(*this);
|
||||
if (pushedBase == nullptr) return false;
|
||||
m_resource.AdoptPersistentMap(pushedBase);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
if (m_size == 0 || g_bufferBackendOps == nullptr || g_bufferBackendOps->AcquirePersistentMap == nullptr) {
|
||||
return false;
|
||||
}
|
||||
@@ -548,6 +647,16 @@ namespace MobileGL::MG_State::GLState {
|
||||
// returning; AdoptPersistentMap then releases the shadow. Falls back to the
|
||||
// shadow when the backend declines (returns null). Only attempted once - the
|
||||
// storage is immutable and outlives unmap/remap.
|
||||
#if MOBILEGL_PIPE_PUSH
|
||||
if (!m_resource.IsGpuResident() && (access & BufferMappingAccessBit::Write) &&
|
||||
!(access & BufferMappingAccessBit::FlushExplicit) &&
|
||||
MG_Pipe::MGPipeResourceSubsystemEnabled()) {
|
||||
if (void* pushedBase = MG_Pipe::MGPipeEmitMapPersistent(*this)) {
|
||||
m_resource.AdoptPersistentMap(pushedBase);
|
||||
}
|
||||
return m_resource.Bytes() + range.start;
|
||||
}
|
||||
#endif
|
||||
if (!m_resource.IsGpuResident() && (access & BufferMappingAccessBit::Write) &&
|
||||
!(access & BufferMappingAccessBit::FlushExplicit) && g_bufferBackendOps &&
|
||||
g_bufferBackendOps->AcquirePersistentMap) {
|
||||
|
||||
Reference in New Issue
Block a user