mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-11-18 15:33:22 +09:00
[Fix] (DirectVulkan, tools/trace_replay): preserve resident buffer ordering and coherent trace copies - fix intermittent geometry and UI corruption in Minecraft 26.3-rc-3
Stage updates to adopted GPU-resident buffers on the command timeline instead of overwriting memory that earlier draws still read. Wait for submitted copies as well as pending commands before CPU readback. Commit coherent mapped writes before Android trace buffer copies, and retire buffer shadows on deletion so copies see current vertices and name reuse cannot leave dangling dirty-shadow entries. Validated draw ordering, submitted-copy readback, traced buffer copies, and mapped-buffer deletion/name reuse on Redmi Adreno 830. Minecraft 26.3-rc-3 Magma passed movement, HUD, and menu checks and exited normally; the new trace parsed all 64,410 frames without warnings.
This commit is contained in:
@@ -65,6 +65,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
}
|
||||
}
|
||||
|
||||
void Ops_ResidentSubData(BufferObject& bufferObject, SizeT offset, DataPtr data) {
|
||||
if (g_activeBufferManager) {
|
||||
g_activeBufferManager->OnResidentSubData(bufferObject, offset, data);
|
||||
}
|
||||
}
|
||||
|
||||
void Ops_FlushMappedRange(BufferObject& bufferObject, Range1D range,
|
||||
Flags<BufferMappingAccessBit> appAccess) {
|
||||
if (g_activeBufferManager) {
|
||||
@@ -76,11 +82,12 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// host-visible GPU storage (EnsureGpuResidentStorage adopts it when the buffer is
|
||||
// bound as a shader storage buffer), so nothing needs copying - but coherence only
|
||||
// says the writes are visible once they have happened, so the work has to retire
|
||||
// first.
|
||||
// first, including copies already submitted by a sync-point flush.
|
||||
void Ops_ReadbackFromGpu(BufferObject& bufferObject) {
|
||||
(void)bufferObject;
|
||||
if (pVulkanRenderer) {
|
||||
pVulkanRenderer->FinishPendingGpuWork();
|
||||
pVulkanRenderer->WaitForSubmitIndex(
|
||||
pVulkanRenderer->GetSyncPointSubmitIndex(), UINT64_MAX, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +111,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
const BufferBackendOps g_vulkanBufferBackendOps = {
|
||||
.Respecify = Ops_Respecify,
|
||||
.SubData = Ops_SubData,
|
||||
.ResidentSubData = Ops_ResidentSubData,
|
||||
.FlushMappedRange = Ops_FlushMappedRange,
|
||||
.OnDestroy = Ops_OnDestroy,
|
||||
.AcquirePersistentMap = Ops_AcquirePersistentMap,
|
||||
@@ -343,13 +351,13 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
return true;
|
||||
}
|
||||
|
||||
Bool VkBufferManager::StagedRangeCopy(VkBufferResource& resource, MG_State::GLState::BufferObject& bufferObject,
|
||||
Bool VkBufferManager::StagedRangeCopy(VkBufferResource& resource, const void* data,
|
||||
SizeT offset, SizeT size) {
|
||||
if (!m_copyProvider) {
|
||||
return false;
|
||||
}
|
||||
BufferSlice staging{};
|
||||
if (!m_transientUploadArena.Upload(m_currentFrameIndex, bufferObject.MappedData() + offset,
|
||||
if (!m_transientUploadArena.Upload(m_currentFrameIndex, data,
|
||||
static_cast<VkDeviceSize>(size), 16, staging)) {
|
||||
return false;
|
||||
}
|
||||
@@ -454,11 +462,32 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
// Busy partial write: stage + GPU copy preserves GL ordering within the
|
||||
// frame and leaves bytes outside the range (possibly GPU-written, e.g.
|
||||
// SSBO) intact. Fall back to a storage swap if staging is unavailable.
|
||||
if (!StagedRangeCopy(*resource, bufferObject, offset, size)) {
|
||||
if (!StagedRangeCopy(*resource, bufferObject.MappedData() + offset, offset, size)) {
|
||||
SwapStorageAndUploadAll(*resource, bufferObject);
|
||||
}
|
||||
}
|
||||
|
||||
void VkBufferManager::OnResidentSubData(MG_State::GLState::BufferObject& bufferObject,
|
||||
SizeT offset, DataPtr data) {
|
||||
auto* resource = ResourceOf(bufferObject);
|
||||
MOBILEGL_ASSERT(resource && resource->persistentMapped && resource->buffer.IsValid(),
|
||||
"OnResidentSubData requires adopted Vulkan storage");
|
||||
// The mapping is also the GPU's storage. Copy the supplied bytes onto the
|
||||
// command timeline before touching it: earlier draws must keep seeing the
|
||||
// old contents, including draws recorded but not yet submitted. The buffer
|
||||
// cannot be orphaned because the application may hold its mapped pointer.
|
||||
if (StagedRangeCopy(*resource, data.data, offset, data.size)) {
|
||||
return;
|
||||
}
|
||||
// Allocation failure: a host write is safe only after all prior work retires.
|
||||
if (pVulkanRenderer && pVulkanRenderer->WaitForSubmitIndex(
|
||||
pVulkanRenderer->GetSyncPointSubmitIndex(), UINT64_MAX, true)) {
|
||||
resource->buffer.Upload(data.data, data.size, offset);
|
||||
} else {
|
||||
MGLOG_E_ONCE("VkBufferManager::OnResidentSubData: ordered upload failed");
|
||||
}
|
||||
}
|
||||
|
||||
void VkBufferManager::OnFlushMappedRange(MG_State::GLState::BufferObject& bufferObject, Range1D range,
|
||||
Flags<BufferMappingAccessBit> appAccess) {
|
||||
auto* resource = ResourceOf(bufferObject);
|
||||
@@ -488,7 +517,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!StagedRangeCopy(*resource, bufferObject, offset, size)) {
|
||||
if (!StagedRangeCopy(*resource, bufferObject.MappedData() + offset, offset, size)) {
|
||||
SwapStorageAndUploadAll(*resource, bufferObject);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user