-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support external semaphore imported from MTLSharedEvent
- Loading branch information
1 parent
90c66ff
commit eb455ff
Showing
16 changed files
with
557 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2021 The ANGLE Project Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// | ||
// SemaphoreMtl.h: Defines the class interface for SemaphoreMtl, | ||
// implementing SemaphoreImpl. | ||
|
||
#ifndef LIBANGLE_RENDERER_METAL_SEMAPHOREMTL_H_ | ||
#define LIBANGLE_RENDERER_METAL_SEMAPHOREMTL_H_ | ||
|
||
#include "libANGLE/renderer/SemaphoreImpl.h" | ||
#include "libANGLE/renderer/metal/mtl_common.h" | ||
|
||
namespace rx | ||
{ | ||
|
||
class SemaphoreMtl : public SemaphoreImpl | ||
{ | ||
public: | ||
SemaphoreMtl(); | ||
~SemaphoreMtl() override; | ||
|
||
void onDestroy(const gl::Context *context) override; | ||
|
||
angle::Result importFd(gl::Context *context, gl::HandleType handleType, GLint fd) override; | ||
|
||
angle::Result wait(gl::Context *context, | ||
const gl::BufferBarrierVector &bufferBarriers, | ||
const gl::TextureBarrierVector &textureBarriers) override; | ||
|
||
angle::Result signal(gl::Context *context, | ||
const gl::BufferBarrierVector &bufferBarriers, | ||
const gl::TextureBarrierVector &textureBarriers) override; | ||
|
||
void parameterui64v(GLenum pname, const GLuint64 *params) override; | ||
void getParameterui64v(GLenum pname, GLuint64 *params) override; | ||
private: | ||
angle::Result importOpaqueFd(gl::Context *context, GLint fd); | ||
|
||
mtl::SharedEventRef mMetalSharedEvent; | ||
GLuint64 mTimelineValue = 0; | ||
}; | ||
|
||
} // namespace rx | ||
|
||
#endif // LIBANGLE_RENDERER_METAL_SEMAPHOREMTL_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright 2021 The ANGLE Project Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// | ||
// SemaphoreMtl.cpp: Defines the class interface for SemaphoreMtl, implementing | ||
// SemaphoreImpl. | ||
|
||
#include "libANGLE/renderer/metal/SemaphoreMtl.h" | ||
|
||
#include "common/debug.h" | ||
#include "libANGLE/Context.h" | ||
#include "libANGLE/renderer/metal/ContextMtl.h" | ||
|
||
namespace rx | ||
{ | ||
|
||
SemaphoreMtl::SemaphoreMtl() = default; | ||
|
||
SemaphoreMtl::~SemaphoreMtl() = default; | ||
|
||
void SemaphoreMtl::onDestroy(const gl::Context *context) | ||
{ | ||
mMetalSharedEvent = nil; | ||
} | ||
|
||
angle::Result SemaphoreMtl::importFd(gl::Context *context, gl::HandleType handleType, GLint fd) | ||
{ | ||
switch (handleType) | ||
{ | ||
case gl::HandleType::OpaqueFd: | ||
return importOpaqueFd(context, fd); | ||
|
||
default: | ||
UNREACHABLE(); | ||
return angle::Result::Stop; | ||
} | ||
} | ||
|
||
angle::Result SemaphoreMtl::wait(gl::Context *context, | ||
const gl::BufferBarrierVector &bufferBarriers, | ||
const gl::TextureBarrierVector &textureBarriers) | ||
{ | ||
// bufferBarriers & textureBarriers are unused for now because metal always end | ||
// current render pass when there is a wait command. | ||
|
||
#if ANGLE_MTL_EVENT_AVAILABLE | ||
ContextMtl *contextMtl = mtl::GetImpl(context); | ||
contextMtl->serverWaitEvent(mMetalSharedEvent, mTimelineValue); | ||
#endif // ANGLE_MTL_EVENT_AVAILABLE | ||
|
||
return angle::Result::Continue; | ||
} | ||
|
||
angle::Result SemaphoreMtl::signal(gl::Context *context, | ||
const gl::BufferBarrierVector &bufferBarriers, | ||
const gl::TextureBarrierVector &textureBarriers) | ||
{ | ||
#if ANGLE_MTL_EVENT_AVAILABLE | ||
ContextMtl *contextMtl = mtl::GetImpl(context); | ||
contextMtl->queueEventSignal(mMetalSharedEvent, mTimelineValue); | ||
#endif // ANGLE_MTL_EVENT_AVAILABLE | ||
|
||
contextMtl->flushCommandBufer(); | ||
return angle::Result::Continue; | ||
} | ||
|
||
void SemaphoreMtl::parameterui64v(GLenum pname, const GLuint64 *params) | ||
{ | ||
switch (pname) | ||
{ | ||
case GL_TIMELINE_SEMAPHORE_VALUE_MGL: | ||
mTimelineValue = *params; | ||
break; | ||
default: | ||
UNREACHABLE(); | ||
} | ||
} | ||
|
||
void SemaphoreMtl::getParameterui64v(GLenum pname, GLuint64 *params) | ||
{ | ||
switch (pname) | ||
{ | ||
case GL_TIMELINE_SEMAPHORE_VALUE_MGL: | ||
*params = mTimelineValue; | ||
break; | ||
default: | ||
UNREACHABLE(); | ||
} | ||
} | ||
|
||
angle::Result SemaphoreMtl::importOpaqueFd(gl::Context *context, GLint fd) | ||
{ | ||
#if !ANGLE_MTL_EVENT_AVAILABLE | ||
UNREACHABLE(); | ||
#else | ||
ContextMtl *contextMtl = mtl::GetImpl(context); | ||
|
||
// NOTE(hqle): This import assumes the address of MTLSharedEvent is stored in the file. | ||
void* sharedEventPtr = nullptr; | ||
ANGLE_MTL_TRY(contextMtl, read(fd, &sharedEventPtr, sizeof(sharedEventPtr))); | ||
ANGLE_MTL_TRY(contextMtl, sharedEventPtr); | ||
|
||
// The ownership of this fd belongs to Semaphore now, so we can close it here. | ||
close(fd); | ||
|
||
auto sharedEvent = (__bridge id<MTLSharedEvent>)sharedEventPtr; | ||
|
||
mMetalSharedEvent = std::move(sharedEvent); | ||
#endif // ANGLE_MTL_EVENT_AVAILABLE | ||
|
||
return angle::Result::Continue; | ||
} | ||
|
||
} // namespace rx |
Oops, something went wrong.