Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xuezchuang opened this issue Mar 14, 2025 · 0 comments
Labels
miniengine Issues related to MiniEngine

Comments

@xuezchuang
Copy link

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!

@walbourn walbourn added the miniengine Issues related to MiniEngine label Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
miniengine Issues related to MiniEngine
Projects
None yet
Development

No branches or pull requests

2 participants