microsoft / microsoft/DirectX-Graphics-Samples
Potential Synchronization Issue in MeshSorter::RenderMeshes with UploadBuffer
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 6.8k
- Forks
- 2.2k
- PR merge metrics
- No merged PRs in 30d
Description
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!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at MeshSorter::RenderMeshes and trace the buffer handle through ModelInstance::Update(), including CopyBufferRegion and the m_MeshConstantsCPU and m_MeshConstantsGPU resources. Compare this with EngineProfiling::Update() and its WaitForFence; the work is done when the upload-buffer lifetime and required synchronization are established, with any needed fix or documentation identified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 28/100