mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Optimize] (MG_Backend/DirectGLES): sync buffer object directly
This commit is contained in:
@@ -86,63 +86,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
// TODO: deletion for deleted objects
|
// TODO: deletion for deleted objects
|
||||||
|
|
||||||
namespace BufferImpl {
|
namespace BufferImpl {
|
||||||
void SyncNeccessaryBuffers(Bool includeIBO = false, Bool includeIndirectBuffer = false) {
|
void CreateAndSyncBufferObject(SharedPtr<MG_State::GLState::BufferObject>& bufferObject) {
|
||||||
#ifdef TRACY_ENABLE
|
if (!(bufferObject->GetChangeBits() & BufferChangeBits::DirtyBit))
|
||||||
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
|
||||||
#endif
|
|
||||||
// All buffers we need are:
|
|
||||||
// 1.VBO 2.IBO (if needed) 3.UBO 4.IndirectBuffer (if needed) 5.SSBO (TODO)
|
|
||||||
// PBO is not needed since it should be handled in frontend
|
|
||||||
|
|
||||||
static Vector<SharedPtr<MG_State::GLState::BufferObject>> buffersToSync;
|
|
||||||
|
|
||||||
buffersToSync.clear();
|
|
||||||
|
|
||||||
const auto& currentVAOObject = MG_State::pGLContext->GetBoundVertexArray();
|
|
||||||
if (!currentVAOObject) {
|
|
||||||
MGLOG_E("No VAO is currently bound, cannot sync necessary buffers.");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// VBO
|
|
||||||
for (const auto& attrib : currentVAOObject->GetAllAttributes()) {
|
|
||||||
if (!attrib.Enabled) continue;
|
|
||||||
const auto& bufferObject = attrib.Buffer;
|
|
||||||
if (bufferObject) {
|
|
||||||
buffersToSync.push_back(bufferObject);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// IBO
|
|
||||||
if (includeIBO) {
|
|
||||||
const auto& possibleIBO = currentVAOObject->GetIndexBufferBindingSlot().GetBoundObject();
|
|
||||||
if (possibleIBO) {
|
|
||||||
buffersToSync.push_back(possibleIBO);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Indirect Buffer Object
|
|
||||||
if (includeIndirectBuffer) {
|
|
||||||
const auto& possibleIndirectBuffer =
|
|
||||||
MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::DrawIndirect).GetBoundObject();
|
|
||||||
if (possibleIndirectBuffer) {
|
|
||||||
buffersToSync.push_back(possibleIndirectBuffer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// UBO
|
|
||||||
auto uboBindingPointCnt = MG_State::pGLContext->GetBufferBindingPointCount(BufferTarget::Uniform);
|
|
||||||
for (SizeT i = 0; i < uboBindingPointCnt; ++i) {
|
|
||||||
auto& point = MG_State::pGLContext->GetBufferBindingPoint(BufferTarget::Uniform, i);
|
|
||||||
auto obj = point.GetBoundObject();
|
|
||||||
if (obj) {
|
|
||||||
buffersToSync.push_back(obj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Do real sync
|
|
||||||
for (auto& bufferObject : buffersToSync) {
|
|
||||||
if (!(bufferObject->GetChangeBits() & BufferChangeBits::DirtyBit)) continue;
|
|
||||||
|
|
||||||
const auto& backendBufferIt = g_backendBufferObjects.find(bufferObject);
|
const auto& backendBufferIt = g_backendBufferObjects.find(bufferObject);
|
||||||
SharedPtr<BackendBufferObject> backendBufferObject;
|
SharedPtr<BackendBufferObject> backendBufferObject;
|
||||||
@@ -154,6 +100,59 @@ namespace MobileGL::MG_Backend::DirectGLES {
|
|||||||
}
|
}
|
||||||
backendBufferObject->SyncToBackend(bufferObject);
|
backendBufferObject->SyncToBackend(bufferObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SyncNeccessaryBuffers(Bool includeIBO = false, Bool includeIndirectBuffer = false) {
|
||||||
|
#ifdef TRACY_ENABLE
|
||||||
|
ZoneScopedC(TRACY_ZONECOLOR_BACKEND);
|
||||||
|
#endif
|
||||||
|
// All buffers we need are:
|
||||||
|
// 1.VBO 2.IBO (if needed) 3.UBO 4.IndirectBuffer (if needed) 5.SSBO (TODO)
|
||||||
|
// PBO is not needed since it should be handled in frontend
|
||||||
|
|
||||||
|
// static Vector<SharedPtr<MG_State::GLState::BufferObject>> buffersToSync;
|
||||||
|
// buffersToSync.clear();
|
||||||
|
|
||||||
|
const auto& currentVAOObject = MG_State::pGLContext->GetBoundVertexArray();
|
||||||
|
if (!currentVAOObject) {
|
||||||
|
MGLOG_E("No VAO is currently bound, cannot sync necessary buffers.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// VBO
|
||||||
|
for (const auto& attrib : currentVAOObject->GetAllAttributes()) {
|
||||||
|
if (!attrib.Enabled) continue;
|
||||||
|
auto bufferObject = attrib.Buffer;
|
||||||
|
if (bufferObject) {
|
||||||
|
CreateAndSyncBufferObject(bufferObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IBO
|
||||||
|
if (includeIBO) {
|
||||||
|
auto possibleIBO = currentVAOObject->GetIndexBufferBindingSlot().GetBoundObject();
|
||||||
|
if (possibleIBO) {
|
||||||
|
CreateAndSyncBufferObject(possibleIBO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indirect Buffer Object
|
||||||
|
if (includeIndirectBuffer) {
|
||||||
|
auto possibleIndirectBuffer =
|
||||||
|
MG_State::pGLContext->GetBufferBindingSlot(BufferTarget::DrawIndirect).GetBoundObject();
|
||||||
|
if (possibleIndirectBuffer) {
|
||||||
|
CreateAndSyncBufferObject(possibleIndirectBuffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UBO
|
||||||
|
auto uboBindingPointCnt = MG_State::pGLContext->GetBufferBindingPointCount(BufferTarget::Uniform);
|
||||||
|
for (SizeT i = 0; i < uboBindingPointCnt; ++i) {
|
||||||
|
auto& point = MG_State::pGLContext->GetBufferBindingPoint(BufferTarget::Uniform, i);
|
||||||
|
auto obj = point.GetBoundObject();
|
||||||
|
if (obj) {
|
||||||
|
CreateAndSyncBufferObject(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // namespace BufferImpl
|
} // namespace BufferImpl
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user