microsoft / microsoft/DirectX-Graphics-Samples

Potential Synchronization Issue in MeshSorter::RenderMeshes with UploadBuffer

Open
#903 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

miniengine
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.