Skip to content

Potential Synchronization Issue in MeshSorter::RenderMeshes with UploadBuffer #903

@xuezchuang

Description

@xuezchuang

Hi,

I noticed that in void MeshSorter::RenderMeshes, the function context.SetConstantBuffer is used instead of SetDynamicConstantBufferView. From the code, I see that it directly passes a GPU handle, which is obtained via ModelInstance::Update(), where gfxContext.GetCommandList()->CopyBufferRegion(...) copies data from a CPU UploadBuffer (m_MeshConstantsCPU) to a GPU buffer (m_MeshConstantsGPU).

My concern is that m_MeshConstantsCPU is an UploadBuffer, but it does not use LinearAllocator for resource allocation. How can we ensure that m_MeshConstantsCPU is not being written to while CopyBufferRegion is executing? There doesn’t seem to be any explicit synchronization mechanism like a fence to manage this.

I understand that EngineProfiling::Update(); includes a WaitForFence, which ensures GPU completion every frame, but this is primarily for performance profiling. If we remove EngineProfiling::Update(), how do we guarantee that m_MeshConstantsCPU is not modified while CopyBufferRegion is in progress?

Would it be more appropriate to allocate the UploadBuffer using LinearAllocator to ensure proper synchronization and avoid potential data corruption?

Looking forward to your thoughts!

Metadata

Metadata

Assignees

No one assigned

    Labels

    miniengineIssues related to MiniEngine

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions