Skip to content

Commit

Permalink
Merge pull request PixarAnimationStudios#2794 from erikaharrison-adsk…
Browse files Browse the repository at this point in the history
…/adsk/bugfix/WaitUntilCompleted

Autodesk: WaitUntilCompleted on Metal

(Internal change: 2332494)
  • Loading branch information
pixar-oss committed Jun 28, 2024
2 parents 947c971 + 5da4e92 commit ee337ef
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
3 changes: 3 additions & 0 deletions pxr/imaging/hgiMetal/blitCmds.mm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
[_label release];
_label = nil;
}
if (!_secondaryCommandBuffer) {
_hgi->SetHasWork();
}
}
}

Expand Down
1 change: 0 additions & 1 deletion pxr/imaging/hgiMetal/computeCmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class HgiMetalComputeCmds final : public HgiComputeCmds
id<MTLBuffer> _argumentBuffer;
id<MTLComputeCommandEncoder> _encoder;
bool _secondaryCommandBuffer;
bool _hasWork;
HgiComputeDispatch _dispatchMethod;
};

Expand Down
10 changes: 5 additions & 5 deletions pxr/imaging/hgiMetal/computeCmds.mm
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
, _argumentBuffer(nil)
, _encoder(nil)
, _secondaryCommandBuffer(false)
, _hasWork(false)
, _dispatchMethod(desc.dispatchMethod)
{
_CreateEncoder();
Expand Down Expand Up @@ -135,7 +134,10 @@
threadsPerThreadgroup:MTLSizeMake(MIN(thread_width, dimX),
MIN(thread_height, dimY), 1)];

_hasWork = true;
if (!_secondaryCommandBuffer) {
_hgi->SetHasWork();
}

_argumentBuffer = nil;
}

Expand Down Expand Up @@ -174,11 +176,9 @@
bool
HgiMetalComputeCmds::_Submit(Hgi* hgi, HgiSubmitWaitType wait)
{
bool submittedWork = false;
if (_encoder) {
[_encoder endEncoding];
_encoder = nil;
submittedWork = true;

HgiMetal::CommitCommandBufferWaitType waitType;
switch(wait) {
Expand All @@ -204,7 +204,7 @@
_commandBuffer = nil;
_argumentBuffer = nil;

return submittedWork;
return true;
}

HGIMETAL_API
Expand Down
1 change: 0 additions & 1 deletion pxr/imaging/hgiMetal/graphicsCmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class HgiMetalGraphicsCmds final : public HgiGraphicsCmds
uint32_t _primitiveIndexSize;
uint32_t _drawBufferBindingIndex;
NSString* _debugLabel;
bool _hasWork;
bool _viewportSet;
bool _scissorRectSet;
bool _enableParallelEncoder;
Expand Down
11 changes: 7 additions & 4 deletions pxr/imaging/hgiMetal/graphicsCmds.mm
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
, _primitiveIndexSize(0)
, _drawBufferBindingIndex(0)
, _debugLabel(nil)
, _hasWork(false)
, _viewportSet(false)
, _scissorRectSet(false)
, _enableParallelEncoder(false)
Expand Down Expand Up @@ -549,7 +548,7 @@
}
}

_hasWork = true;
_hgi->SetHasWork();
}

void
Expand Down Expand Up @@ -619,6 +618,8 @@
});
}
});

_hgi->SetHasWork();
}

void
Expand Down Expand Up @@ -668,7 +669,7 @@
baseInstance:baseInstance];
}

_hasWork = true;
_hgi->SetHasWork();
}

void
Expand Down Expand Up @@ -761,6 +762,8 @@
});
}
});

_hgi->SetHasWork();
}

void
Expand Down Expand Up @@ -858,7 +861,7 @@
_encoders.clear();
_CachedEncState.ResetCachedEncoderState();

return _hasWork;
return true;
}

PXR_NAMESPACE_CLOSE_SCOPE
7 changes: 6 additions & 1 deletion pxr/imaging/hgiMetal/hgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,19 @@ class HgiMetal final : public Hgi
// So for the sake of efficiency, we try to create only one cmd buf and
// only use the secondary command buffer when the client code requires it.
// For example, the client code may record in a HgiBlitCmds and a
// HgiComputeCmds at the same time.
// HgiComputeCmds at the same time. It is the responsibility of the
// command buffer implementation to call SetHasWork() if there is
// work to be submitted from the primary command buffer.
HGIMETAL_API
id<MTLCommandBuffer> GetPrimaryCommandBuffer(HgiCmds *requester = nullptr,
bool flush = true);

HGIMETAL_API
id<MTLCommandBuffer> GetSecondaryCommandBuffer();

HGIMETAL_API
void SetHasWork();

HGIMETAL_API
int GetAPIVersion() const;

Expand Down
8 changes: 7 additions & 1 deletion pxr/imaging/hgiMetal/hgi.mm
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,12 @@ void Drain() {}
return commandBuffer;
}

void
HgiMetal::SetHasWork()
{
_workToFlush = true;
}

int
HgiMetal::GetAPIVersion() const
{
Expand Down Expand Up @@ -516,7 +522,7 @@ void Drain() {}
TRACE_FUNCTION();

if (cmds) {
_workToFlush = Hgi::_SubmitCmds(cmds, wait);
Hgi::_SubmitCmds(cmds, wait);
if (cmds == _currentCmds) {
_currentCmds = nullptr;
}
Expand Down

0 comments on commit ee337ef

Please sign in to comment.