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

Autodesk: WaitUntilCompleted on Metal #2794

Conversation

erikaharrison-adsk
Copy link
Contributor

Description of Change(s)

Correct the behavior when we want to submit a command. This will also make WaitTypeWaitUntilCompleted work properly.

The issue was introduced in change 28116f1. Before the change, the command buffer is committed in HgiMetal::_SubmitCmds(), and before the buffer commit, HgiMetal::_workToFlush was set to indicate if there is dispatching work in compute encoder or drawing work in graphics encoder. So when command buffer is committed, if _workToFlush is true, it will commit the commands to GPU. But in change 28116f1, because they want to introduce the secondary command buffer, the commit of the command buffer is moved to HgiCmds::_Submit (in _hgi->CommitPrimaryCommandBuffer(waitType)), which is before the set of _workToFlush. So even if the encoder contains dispatching work or drawing work, the command buffer will not be committed to GPU. This has two drawbacks. For HgiSubmitWaitTypeNoWait waitType, we push the work to GPU too late. This didn't make the most use of GPU. For HgiSubmitWaitTypeWaitUntilCompleted waitType, it doesn't wait at all.

As you can see, the problem is that _workToFlush is set after the commit of command buffer. So in this change, I add an API HgiMetal::HasWork(). It will set _workToFlush to true. When graphics encoder encodes the draw command or the compute encoder encodes the dispatch command, it can call the HasWork API to indicate there is already work command. So when command buffer is committed, _workToFlush is correctly set.

Fixes Issue(s)

  • N/A
  • I have verified that all unit tests pass with the proposed changes
  • I have submitted a signed Contributor License Agreement

… make WaitTypeWaitUntilCompleted work properly.

The issue was introduced in change 28116f1. Before the change, the command buffer is committed in HgiMetal::_SubmitCmds(), and before the buffer commit, HgiMetal::_workToFlush was set to indicate if there is dispatching work in compute encoder or drawing work in graphics encoder. So when command buffer is committed, if _workToFlush is true, it will commit the commands to GPU.
But in change 28116f1, because they want to introduce the secondary command buffer, the commit of the command buffer is moved to HgiCmds::_Submit (in _hgi->CommitPrimaryCommandBuffer(waitType)), which is before the set of _workToFlush. So even if the encoder contains dispatching work or drawing work, the command buffer will not be committed to GPU. This has two drawbacks. For HgiSubmitWaitTypeNoWait waitType, we push the work to GPU too late. This didn't make the most use of GPU. For HgiSubmitWaitTypeWaitUntilCompleted waitType, it doesn't wait at all.

As you can see, the problem is that _workToFlush is set after the commit of command buffer. So in this change, I add an API HgiMetal::HasWork(). It will set _workToFlush to true. When graphics encoder encodes the draw command or the compute encoder encodes the dispatch command, it can call the HasWork API to indicate there is already work command. So when command buffer is committed, _workToFlush is correctly set.
@jesschimein
Copy link

Filed as internal issue #USD-8920

@pixar-oss pixar-oss merged commit ee337ef into PixarAnimationStudios:dev Jun 28, 2024
5 checks passed
@erikaharrison-adsk erikaharrison-adsk deleted the adsk/bugfix/WaitUntilCompleted branch October 5, 2024 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants