Bug 2068875 - Store GpuFenceMTLSharedEvent in CompositeProcessFencesHolderMap r=gfx-reviewers,bradwerth

Differential Revision: https://phabricator.services.mozilla.com/D323499
This commit is contained in:
Sotaro Ikeda
2026-09-10 06:31:34 +00:00
committed by sikeda.birchill@mozilla.com
parent 5fa3641b28
commit c8196f9387
29 changed files with 239 additions and 134 deletions
-9
View File
@@ -1386,15 +1386,6 @@ bool WebGLContext::PushRemoteTexture(
Maybe<layers::SurfaceDescriptor> desc;
if (surf) {
desc = surf->ToSurfaceDescriptor();
// Move surface's GpuFence to the SurfaceDescriptor. Done here rather than
// in SharedSurface_MacIOSurface::ToSurfaceDescriptor() as we know this
// surface will not be sent cross process, but that's not true for all
// callers of SharedSurface::ToSurfaceDescriptor().
if (desc && desc->type() ==
layers::SurfaceDescriptor::TSurfaceDescriptorMacIOSurface) {
auto& ioDesc = desc->get_SurfaceDescriptorMacIOSurface();
ioDesc.gpuFence() = surf->TakeGpuFence();
}
}
if (!desc) {
if (surf && surf->mDesc.type != gl::SharedSurfaceType::Basic) {
+1 -1
View File
@@ -843,7 +843,7 @@ ExternalTextureSourceHost::CreateFromMacIOSurfaceTextureHost(
// WebGPU presentation. In our case the IOSurface has been written to from
// the CPU or obtained from a CVPixelBuffer, and no additional synchronization
// is required.
MOZ_ASSERT(!aTextureHost->mGpuFence);
MOZ_ASSERT(aTextureHost->mDescriptor.fencesHolderId().isNothing());
const gfx::SurfaceFormat format = ioSurface->GetFormat();
const gfx::YUVRangedColorSpace colorSpace = gfx::ToYUVRangedColorSpace(
+30 -7
View File
@@ -6,6 +6,7 @@
#include "mozilla/gfx/Logging.h"
#include "mozilla/gfx/MacIOSurface.h"
#include "mozilla/layers/CompositeProcessFencesHolderMap.h"
#include "mozilla/layers/GpuFenceMTLSharedEvent.h"
#include "mozilla/webgpu/WebGPUParent.h"
@@ -37,23 +38,43 @@ UniquePtr<SharedTextureMacIOSurface> SharedTextureMacIOSurface::Create(
return nullptr;
}
auto fencesHolderId = layers::CompositeProcessFencesHolderId::GetNext();
auto* fencesHolderMap = layers::CompositeProcessFencesHolderMap::Get();
MOZ_ASSERT(fencesHolderMap);
fencesHolderMap->Register(fencesHolderId);
return MakeUnique<SharedTextureMacIOSurface>(
aParent, aDeviceId, aWidth, aHeight, aFormat, aUsage, std::move(surface));
aParent, aDeviceId, aWidth, aHeight, aFormat, aUsage, std::move(surface),
fencesHolderId);
}
SharedTextureMacIOSurface::SharedTextureMacIOSurface(
WebGPUParent* aParent, const ffi::WGPUDeviceId aDeviceId,
const uint32_t aWidth, const uint32_t aHeight,
const struct ffi::WGPUTextureFormat aFormat,
const ffi::WGPUTextureUsages aUsage, RefPtr<MacIOSurface>&& aSurface)
const ffi::WGPUTextureUsages aUsage, RefPtr<MacIOSurface>&& aSurface,
const layers::CompositeProcessFencesHolderId aFencesHolderId)
: SharedTexture(aWidth, aHeight, aFormat, aUsage),
mParent(aParent),
mDeviceId(aDeviceId),
mSurface(std::move(aSurface)) {}
mSurface(std::move(aSurface)),
mFencesHolderId(aFencesHolderId) {}
SharedTextureMacIOSurface::~SharedTextureMacIOSurface() = default;
SharedTextureMacIOSurface::~SharedTextureMacIOSurface() {
auto* fencesHolderMap = layers::CompositeProcessFencesHolderMap::Get();
if (fencesHolderMap) {
fencesHolderMap->Unregister(mFencesHolderId);
} else {
gfxCriticalNoteOnce << "CompositeProcessFencesHolderMap does not exist";
}
}
uint32_t SharedTextureMacIOSurface::GetIOSurfaceId() {
auto* fencesHolderMap = layers::CompositeProcessFencesHolderMap::Get();
MOZ_ASSERT(fencesHolderMap);
// XXX Add previous fences handling
auto fences = fencesHolderMap->TakeAllFencesAndForget(mFencesHolderId);
return mSurface->GetIOSurfaceID();
}
@@ -61,12 +82,14 @@ Maybe<layers::SurfaceDescriptor>
SharedTextureMacIOSurface::ToSurfaceDescriptor() {
MOZ_ASSERT(mSubmissionIndex > 0);
RefPtr<layers::GpuFence> gpuFence;
void* const eventHandle = wgpu_server_get_device_fence_metal_shared_event(
mParent->GetContext(), mDeviceId);
if (eventHandle) {
gpuFence =
RefPtr<layers::GpuFence> writeFence =
layers::GpuFenceMTLSharedEvent::Create(eventHandle, mSubmissionIndex);
auto* fencesHolderMap = layers::CompositeProcessFencesHolderMap::Get();
MOZ_ASSERT(fencesHolderMap);
fencesHolderMap->SetWriteFence(mFencesHolderId, writeFence);
} else {
gfxCriticalNoteOnce << "Failed to get MetalSharedEventHandle";
}
@@ -74,7 +97,7 @@ SharedTextureMacIOSurface::ToSurfaceDescriptor() {
return Some(layers::SurfaceDescriptorMacIOSurface(
mSurface->GetIOSurfaceID(), !mSurface->HasAlpha(),
mSurface->GetYUVColorSpace(), mSurface->GetTransferFunction(),
std::move(gpuFence)));
Some(mFencesHolderId)));
}
void SharedTextureMacIOSurface::GetSnapshot(const ipc::Shmem& aDestShmem,
+8 -6
View File
@@ -7,6 +7,7 @@
#include "mozilla/WeakPtr.h"
#include "mozilla/gfx/FileHandleWrapper.h"
#include "mozilla/layers/LayersTypes.h"
#include "mozilla/webgpu/SharedTexture.h"
class MacIOSurface;
@@ -23,12 +24,12 @@ class SharedTextureMacIOSurface final : public SharedTexture {
const struct ffi::WGPUTextureFormat aFormat,
const ffi::WGPUTextureUsages aUsage);
SharedTextureMacIOSurface(WebGPUParent* aParent,
const ffi::WGPUDeviceId aDeviceId,
const uint32_t aWidth, const uint32_t aHeight,
const struct ffi::WGPUTextureFormat aFormat,
const ffi::WGPUTextureUsages aUsage,
RefPtr<MacIOSurface>&& aSurface);
SharedTextureMacIOSurface(
WebGPUParent* aParent, const ffi::WGPUDeviceId aDeviceId,
const uint32_t aWidth, const uint32_t aHeight,
const struct ffi::WGPUTextureFormat aFormat,
const ffi::WGPUTextureUsages aUsage, RefPtr<MacIOSurface>&& aSurface,
const layers::CompositeProcessFencesHolderId aFencesHolderId);
virtual ~SharedTextureMacIOSurface();
Maybe<layers::SurfaceDescriptor> ToSurfaceDescriptor() override;
@@ -45,6 +46,7 @@ class SharedTextureMacIOSurface final : public SharedTexture {
const WeakPtr<WebGPUParent> mParent;
const RawId mDeviceId;
const RefPtr<MacIOSurface> mSurface;
const layers::CompositeProcessFencesHolderId mFencesHolderId;
};
} // namespace webgpu
+10 -3
View File
@@ -20,6 +20,7 @@
#include "mozilla/gfx/BuildConstants.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/gfx/Matrix.h"
#include "mozilla/layers/CompositeProcessFencesHolderMap.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/ImageDataSerializer.h"
#include "mozilla/layers/LayersSurfaces.h"
@@ -953,9 +954,15 @@ bool GLBlitHelper::BlitSdToFramebuffer(const layers::SurfaceDescriptor& asd,
#ifdef XP_MACOSX
case layers::SurfaceDescriptor::TSurfaceDescriptorMacIOSurface: {
const auto& sd = asd.get_SurfaceDescriptorMacIOSurface();
if (sd.gpuFence() &&
!sd.gpuFence()->ServerWait(mGL, TimeDuration::Forever())) {
return false;
if (sd.fencesHolderId().isSome()) {
auto* fencesHolderMap = layers::CompositeProcessFencesHolderMap::Get();
RefPtr<layers::Fence> fence =
fencesHolderMap->GetWriteFence(sd.fencesHolderId().ref());
RefPtr<layers::GpuFence> gpuFence =
fence ? fence->AsGpuFence() : nullptr;
if (gpuFence && gpuFence->ServerWait(mGL, TimeDuration::Forever())) {
return false;
}
}
const auto surf = LookupSurface(sd);
if (!surf) {
-2
View File
@@ -25,7 +25,6 @@
#include "mozilla/UniquePtr.h"
#include "mozilla/WeakPtr.h"
#include "mozilla/gfx/Point.h"
#include "mozilla/layers/GpuFence.h"
class nsIThread;
@@ -159,7 +158,6 @@ class SharedSurface {
virtual bool IsValid() const { return true; };
virtual Maybe<layers::SurfaceDescriptor> ToSurfaceDescriptor() = 0;
virtual RefPtr<layers::GpuFence> TakeGpuFence() { return nullptr; }
void BeginWrite() {
WaitForBufferOwnership();
+93 -44
View File
@@ -9,6 +9,8 @@
#include "MozFramebuffer.h"
#include "ScopedGLHelpers.h"
#include "mozilla/gfx/MacIOSurface.h"
#include "mozilla/layers/CompositeProcessFencesHolderMap.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/GpuFenceMTLSharedEvent.h"
#include "mozilla/layers/LayersSurfaces.h" // for SurfaceDescriptor, etc
#include "mozilla/layers/LayersTypes.h"
@@ -71,66 +73,113 @@ UniquePtr<SharedSurface_IOSurface> SharedSurface_IOSurface::Create(
auto fb = MozFramebuffer::CreateForBacking(desc.gl, desc.size, 0, false,
false, *target, tex->name);
if (!fb) return nullptr;
if (!fb) {
return nullptr;
}
return AsUnique(
new SharedSurface_IOSurface(desc, std::move(fb), std::move(tex), ioSurf));
Maybe<layers::CompositeProcessFencesHolderId> fencesHolderId;
auto* fencesHolderMap = layers::CompositeProcessFencesHolderMap::Get();
const bool useFence = [&]() -> bool {
if (desc.gl->GetContextType() != GLContextType::EGL) {
return false;
}
const auto& gle = GLContextEGL::Cast(desc.gl);
const auto& egl = gle->mEgl;
return fencesHolderMap && egl->IsExtensionSupported(
EGLExtension::ANGLE_metal_shared_event_sync);
}();
if (useFence) {
fencesHolderId = Some(layers::CompositeProcessFencesHolderId::GetNext());
fencesHolderMap->Register(fencesHolderId.ref());
}
return AsUnique(new SharedSurface_IOSurface(
desc, std::move(fb), std::move(tex), ioSurf, fencesHolderId));
}
SharedSurface_IOSurface::SharedSurface_IOSurface(
const SharedSurfaceDesc& desc, UniquePtr<MozFramebuffer> fb,
UniquePtr<Texture> tex, const RefPtr<MacIOSurface>& ioSurf)
: SharedSurface(desc, std::move(fb)),
mTex(std::move(tex)),
mIOSurf(ioSurf) {}
const SharedSurfaceDesc& aDesc, UniquePtr<MozFramebuffer> aFb,
UniquePtr<Texture> aTex, const RefPtr<MacIOSurface>& aIOSurf,
const Maybe<layers::CompositeProcessFencesHolderId> aFencesHolderId)
: SharedSurface(aDesc, std::move(aFb)),
mTex(std::move(aTex)),
mIOSurf(aIOSurf),
mFencesHolderId(aFencesHolderId) {}
SharedSurface_IOSurface::~SharedSurface_IOSurface() = default;
SharedSurface_IOSurface::~SharedSurface_IOSurface() {
if (mFencesHolderId.isSome()) {
auto* fencesHolderMap = layers::CompositeProcessFencesHolderMap::Get();
if (fencesHolderMap) {
fencesHolderMap->Unregister(mFencesHolderId.ref());
} else {
gfxCriticalNoteOnce << "CompositeProcessFencesHolderMap does not exist";
}
}
}
void SharedSurface_IOSurface::ProducerAcquireImpl() {
if (mFencesHolderId.isNothing()) {
return;
}
auto* fencesHolderMap = layers::CompositeProcessFencesHolderMap::Get();
MOZ_ASSERT(fencesHolderMap);
// XXX Add previous fences handling
auto fences = fencesHolderMap->TakeAllFencesAndForget(mFencesHolderId.ref());
}
void SharedSurface_IOSurface::ProducerReleaseImpl() {
const auto& gl = mDesc.gl;
if (!gl) return;
gl->MakeCurrent();
MOZ_ASSERT(!mGpuFence);
if (gl->GetContextType() == GLContextType::EGL) {
if (mFencesHolderId.isSome()) {
MOZ_ASSERT(gl->GetContextType() == GLContextType::EGL);
const auto& gle = GLContextEGL::Cast(gl);
const auto& egl = gle->mEgl;
if (egl->IsExtensionSupported(
EGLExtension::ANGLE_metal_shared_event_sync)) {
const uint64_t signalValue = 1;
const EGLAttrib attribs[] = {
LOCAL_EGL_SYNC_METAL_SHARED_EVENT_SIGNAL_VALUE_LO_ANGLE,
static_cast<EGLAttrib>(signalValue & 0xFFFFFFFF),
LOCAL_EGL_SYNC_METAL_SHARED_EVENT_SIGNAL_VALUE_HI_ANGLE,
static_cast<EGLAttrib>(signalValue >> 32), LOCAL_EGL_NONE};
const EGLSync sync = egl->fCreateSyncEGL15(
LOCAL_EGL_SYNC_METAL_SHARED_EVENT_ANGLE, attribs);
if (!sync) {
gfxCriticalNote << "Creating EGL_SYNC_METAL_SHARED_EVENT sync failed";
gl->fFinish();
return;
}
void* const sharedEvent = egl->fCopyMetalSharedEventANGLE(sync);
egl->fDestroySync(sync);
MOZ_ASSERT(
egl->IsExtensionSupported(EGLExtension::ANGLE_metal_shared_event_sync));
if (!sharedEvent) {
gfxCriticalNote << "eglCopyMetalSharedEventANGLE failed";
gl->fFinish();
return;
}
mGpuFence =
layers::GpuFenceMTLSharedEvent::Create(sharedEvent, signalValue);
if (!mGpuFence) {
gfxCriticalNote << "GpuFenceMTLSharedEvent::Create failed";
gl->fFinish();
return;
}
// We must flush here else the shared event may never be signalled.
gl->fFlush();
const uint64_t signalValue = 1;
const EGLAttrib attribs[] = {
LOCAL_EGL_SYNC_METAL_SHARED_EVENT_SIGNAL_VALUE_LO_ANGLE,
static_cast<EGLAttrib>(signalValue & 0xFFFFFFFF),
LOCAL_EGL_SYNC_METAL_SHARED_EVENT_SIGNAL_VALUE_HI_ANGLE,
static_cast<EGLAttrib>(signalValue >> 32), LOCAL_EGL_NONE};
const EGLSync sync =
egl->fCreateSyncEGL15(LOCAL_EGL_SYNC_METAL_SHARED_EVENT_ANGLE, attribs);
if (!sync) {
gfxCriticalNote << "Creating EGL_SYNC_METAL_SHARED_EVENT sync failed";
gl->fFinish();
return;
}
void* const sharedEvent = egl->fCopyMetalSharedEventANGLE(sync);
egl->fDestroySync(sync);
if (!sharedEvent) {
gfxCriticalNote << "eglCopyMetalSharedEventANGLE failed";
gl->fFinish();
return;
}
RefPtr<layers::GpuFence> writeFence =
layers::GpuFenceMTLSharedEvent::Create(sharedEvent, signalValue);
if (!writeFence) {
gfxCriticalNote << "GpuFenceMTLSharedEvent::Create failed";
gl->fFinish();
return;
}
// We must flush here else the shared event may never be signalled.
gl->fFlush();
auto* fencesHolderMap = layers::CompositeProcessFencesHolderMap::Get();
MOZ_ASSERT(fencesHolderMap);
fencesHolderMap->SetWriteFence(mFencesHolderId.ref(), writeFence);
return;
}
gl->fFlush();
@@ -141,7 +190,7 @@ SharedSurface_IOSurface::ToSurfaceDescriptor() {
const bool isOpaque = false; // RGBA
return Some(layers::SurfaceDescriptorMacIOSurface(
mIOSurf->GetIOSurfaceID(), isOpaque, mIOSurf->GetYUVColorSpace(),
mIOSurf->GetTransferFunction(), (layers::GpuFence*)nullptr));
mIOSurf->GetTransferFunction(), mFencesHolderId));
}
} // namespace gl
+7 -10
View File
@@ -7,7 +7,7 @@
#include "SharedSurface.h"
#include "mozilla/RefPtr.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/LayersTypes.h"
class MacIOSurface;
@@ -17,18 +17,18 @@ namespace gl {
class Texture;
class SharedSurface_IOSurface final : public SharedSurface {
private:
RefPtr<layers::GpuFence> mGpuFence;
public:
const UniquePtr<Texture> mTex;
const RefPtr<MacIOSurface> mIOSurf;
const Maybe<layers::CompositeProcessFencesHolderId> mFencesHolderId;
static UniquePtr<SharedSurface_IOSurface> Create(const SharedSurfaceDesc&);
private:
SharedSurface_IOSurface(const SharedSurfaceDesc&, UniquePtr<MozFramebuffer>,
UniquePtr<Texture>, const RefPtr<MacIOSurface>&);
SharedSurface_IOSurface(
const SharedSurfaceDesc& aDesc, UniquePtr<MozFramebuffer> aFb,
UniquePtr<Texture> aTex, const RefPtr<MacIOSurface>& aIOSurf,
const Maybe<layers::CompositeProcessFencesHolderId> aFencesHolderId);
public:
~SharedSurface_IOSurface();
@@ -36,7 +36,7 @@ class SharedSurface_IOSurface final : public SharedSurface {
virtual void LockProdImpl() override {}
virtual void UnlockProdImpl() override {}
virtual void ProducerAcquireImpl() override {}
virtual void ProducerAcquireImpl() override;
virtual void ProducerReleaseImpl() override;
// Empty override to avoid the default calling ProducerReleaseImpl() which
// creates a GPU Fence.
@@ -45,9 +45,6 @@ class SharedSurface_IOSurface final : public SharedSurface {
virtual bool NeedsIndirectReads() const override { return true; }
Maybe<layers::SurfaceDescriptor> ToSurfaceDescriptor() override;
RefPtr<layers::GpuFence> TakeGpuFence() override {
return std::move(mGpuFence);
}
};
class SurfaceFactory_IOSurface : public SurfaceFactory {
+10 -3
View File
@@ -48,6 +48,7 @@
#include "mozilla/layers/APZInputBridgeParent.h"
#include "mozilla/layers/APZPublicUtils.h" // for apz::InitializeGlobalState
#include "mozilla/layers/APZThreadUtils.h"
#include "mozilla/layers/CompositeProcessFencesHolderMap.h"
#include "mozilla/layers/CompositorBridgeParent.h"
#include "mozilla/layers/CompositorManagerParent.h"
#include "mozilla/layers/CompositorThread.h"
@@ -77,7 +78,6 @@
# include "gfxDWriteFonts.h"
# include "gfxWindowsPlatform.h"
# include "mozilla/gfx/DeviceManagerDx.h"
# include "mozilla/layers/CompositeProcessFencesHolderMap.h"
# include "mozilla/layers/GpuProcessD3D11TextureMap.h"
# include "mozilla/layers/TextureD3D11.h"
# include "mozilla/widget/WinCompositorWindowThread.h"
@@ -197,7 +197,6 @@ bool GPUParent::Init(mozilla::ipc::UntypedEndpoint&& aEndpoint,
#if defined(XP_WIN)
gfxWindowsPlatform::InitMemoryReportersForGPUProcess();
DeviceManagerDx::Init();
CompositeProcessFencesHolderMap::Init();
GpuProcessD3D11TextureMap::Init();
auto rv = wmf::MediaFoundationInitializer::HasInitialized();
if (!rv) {
@@ -205,6 +204,10 @@ bool GPUParent::Init(mozilla::ipc::UntypedEndpoint&& aEndpoint,
}
#endif
#if defined(XP_WIN) || defined(XP_MACOSX)
CompositeProcessFencesHolderMap::Init();
#endif
CompositorThreadHolder::Start();
RemoteTextureMap::Init();
APZThreadUtils::SetControllerThread(NS_GetCurrentThread());
@@ -806,9 +809,13 @@ void GPUParent::ActorDestroy(ActorDestroyReason aWhy) {
#if defined(XP_WIN)
GpuProcessD3D11TextureMap::Shutdown();
CompositeProcessFencesHolderMap::Shutdown();
DeviceManagerDx::Shutdown();
#endif
#if defined(XP_WIN) || defined(XP_MACOSX)
CompositeProcessFencesHolderMap::Shutdown();
#endif
LayerTreeOwnerTracker::Shutdown();
gfxVars::Shutdown();
gfxConfig::Shutdown();
+2
View File
@@ -14,6 +14,7 @@ namespace layers {
class FenceD3D11;
class FenceFileHandle;
class GpuFence;
class Fence {
public:
@@ -21,6 +22,7 @@ class Fence {
virtual FenceD3D11* AsFenceD3D11() { return nullptr; }
virtual FenceFileHandle* AsFenceFileHandle() { return nullptr; }
virtual GpuFence* AsGpuFence() { return nullptr; }
protected:
virtual ~Fence() = default;
+3 -2
View File
@@ -6,6 +6,7 @@
#define MOZILLA_GFX_GpuFence_H
#include "mozilla/TimeStamp.h"
#include "mozilla/layers/Fence.h"
#include "nsISupportsImpl.h"
namespace mozilla {
@@ -15,9 +16,9 @@ class GLContext;
namespace layers {
class GpuFence {
class GpuFence : public Fence {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(GpuFence);
GpuFence* AsGpuFence() override { return this; }
virtual bool HasCompleted() = 0;
virtual bool ClientWait(TimeDuration aTimeout) = 0;
+2 -1
View File
@@ -10,6 +10,7 @@
#include "mozilla/Range.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/gfx/Types.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/ScreenshotGrabber.h"
#include "nsISupportsImpl.h"
#include "nsRegion.h"
@@ -252,7 +253,7 @@ class NativeLayer {
virtual void AttachExternalImage(wr::RenderTextureHost* aExternalImage) = 0;
virtual GpuFence* GetGpuFence() = 0;
virtual RefPtr<GpuFence> GetGpuFence() = 0;
protected:
virtual ~NativeLayer() = default;
+1 -1
View File
@@ -406,7 +406,7 @@ class NativeLayerCA : public NativeLayer {
CMVideoFormatDescriptionRef aFormat);
void AttachExternalImage(wr::RenderTextureHost* aExternalImage) override;
GpuFence* GetGpuFence() override;
RefPtr<GpuFence> GetGpuFence() override;
void SetRootWindowIsFullscreen(bool aFullscreen);
+1 -1
View File
@@ -903,7 +903,7 @@ void NativeLayerCA::AttachExternalImage(wr::RenderTextureHost* aExternalImage) {
});
}
GpuFence* NativeLayerCA::GetGpuFence() {
RefPtr<GpuFence> NativeLayerCA::GetGpuFence() {
if (!mTextureHost) {
return nullptr;
}
+1 -1
View File
@@ -59,7 +59,7 @@ class NativeLayerRemoteMac final : public NativeLayer {
bool SurfaceIsFlipped() override;
void AttachExternalImage(wr::RenderTextureHost* aExternalImage) override;
GpuFence* GetGpuFence() override;
RefPtr<GpuFence> GetGpuFence() override;
Maybe<SurfaceWithInvalidRegion> FrontSurface();
+1 -1
View File
@@ -91,7 +91,7 @@ void NativeLayerRemoteMac::AttachExternalImage(
mDirtyChangedSurface = true;
}
GpuFence* NativeLayerRemoteMac::GetGpuFence() { return nullptr; }
RefPtr<GpuFence> NativeLayerRemoteMac::GetGpuFence() { return nullptr; }
IntSize NativeLayerRemoteMac::GetSize() {
if (mSurfaceHandler) {
+1 -1
View File
@@ -220,7 +220,7 @@ class NativeLayerWayland : public NativeLayer {
void RenderLayer(double aScale);
// TODO
GpuFence* GetGpuFence() override { return nullptr; }
RefPtr<GpuFence> GetGpuFence() override { return nullptr; }
RefPtr<widget::WaylandSurface> GetWaylandSurface() { return mSurface; }
-11
View File
@@ -525,11 +525,6 @@ already_AddRefed<gfx::SourceSurface> CanvasTranslator::WaitForSurface(
if (surf->mSharedSurface) {
surf->mSharedSurface->BeginRead();
*aDesc = surf->mSharedSurface->ToSurfaceDescriptor();
if (*aDesc && aDesc->ref().type() ==
SurfaceDescriptor::TSurfaceDescriptorMacIOSurface) {
aDesc->ref().get_SurfaceDescriptorMacIOSurface().gpuFence() =
surf->mSharedSurface->TakeGpuFence();
}
surf->mSharedSurface->EndRead();
}
}
@@ -1766,12 +1761,6 @@ mozilla::ipc::IPCResult CanvasTranslator::RecvSnapshotExternalCanvas(
snapshot.mWebgl = webgl;
snapshot.mDescriptor =
snapshot.mSharedSurface->ToSurfaceDescriptor();
if (snapshot.mDescriptor &&
snapshot.mDescriptor->type() ==
SurfaceDescriptor::TSurfaceDescriptorMacIOSurface) {
snapshot.mDescriptor->get_SurfaceDescriptorMacIOSurface()
.gpuFence() = snapshot.mSharedSurface->TakeGpuFence();
}
}
}
if (!snapshot.mDescriptor) {
+1 -2
View File
@@ -28,7 +28,6 @@ using gfxImageFormat from "gfxTypes.h";
using mozilla::layers::MaybeVideoBridgeSource from "mozilla/layers/VideoBridgeUtils.h";
using mozilla::layers::RemoteTextureId from "mozilla/layers/LayersTypes.h";
using mozilla::layers::RemoteTextureOwnerId from "mozilla/layers/LayersTypes.h";
[RefCounted] using mozilla::layers::GpuFence from "mozilla/layers/GpuFence.h";
using mozilla::layers::GpuProcessTextureId from "mozilla/layers/LayersTypes.h";
using mozilla::layers::CompositeProcessFencesHolderId from "mozilla/layers/LayersTypes.h";
using mozilla::wr::ExternalImageSource from "mozilla/webrender/WebRenderTypes.h";
@@ -76,7 +75,7 @@ namespace layers {
bool isOpaque;
YUVColorSpace yUVColorSpace;
TransferFunction transferFunction;
nullable GpuFence gpuFence;
CompositeProcessFencesHolderId? fencesHolderId;
};
[Comparable] struct SurfaceDescriptorDMABuf {
@@ -52,11 +52,10 @@ MacIOSurfaceTextureData* MacIOSurfaceTextureData::Create(const IntSize& aSize,
}
bool MacIOSurfaceTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) {
RefPtr<layers::GpuFence> gpuFence;
aOutDescriptor = SurfaceDescriptorMacIOSurface(
mSurface->GetIOSurfaceID(), !mSurface->HasAlpha(),
mSurface->GetYUVColorSpace(), mSurface->GetTransferFunction(),
std::move(gpuFence));
/* fencesHolderId */ Nothing());
return true;
}
@@ -6,7 +6,7 @@
#include "mozilla/gfx/MacIOSurface.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/CompositeProcessFencesHolderMap.h"
#include "mozilla/webrender/RenderMacIOSurfaceTextureHost.h"
#include "mozilla/webrender/RenderThread.h"
#include "mozilla/webrender/WebRenderAPI.h"
@@ -22,16 +22,34 @@ MacIOSurfaceTextureHostOGL::MacIOSurfaceTextureHostOGL(
aDescriptor.surfaceId(), aDescriptor.yUVColorSpace(),
aDescriptor.transferFunction(),
aDescriptor.isOpaque() ? MacIOSurface::AllowAlpha::No
: MacIOSurface::AllowAlpha::Yes)),
mGpuFence(aDescriptor.gpuFence()) {
: MacIOSurface::AllowAlpha::Yes)) {
MOZ_COUNT_CTOR(MacIOSurfaceTextureHostOGL);
if (!mSurface) {
gfxCriticalNote << "Failed to look up MacIOSurface";
}
if (!mDescriptor.fencesHolderId()) {
return;
}
MOZ_ASSERT(mDescriptor.fencesHolderId()->IsValid());
if (auto* fenceHolderMap = CompositeProcessFencesHolderMap::Get()) {
fenceHolderMap->RegisterReference(mDescriptor.fencesHolderId().ref());
} else {
MOZ_ASSERT_UNREACHABLE("FencesHolderMap not available");
}
}
MacIOSurfaceTextureHostOGL::~MacIOSurfaceTextureHostOGL() {
MOZ_COUNT_DTOR(MacIOSurfaceTextureHostOGL);
if (!mDescriptor.fencesHolderId()) {
return;
}
if (auto* fenceHolderMap = CompositeProcessFencesHolderMap::Get()) {
fenceHolderMap->Unregister(mDescriptor.fencesHolderId().ref());
} else {
MOZ_ASSERT_UNREACHABLE("FencesHolderMap not available");
}
}
gfx::SurfaceFormat MacIOSurfaceTextureHostOGL::GetFormat() const {
@@ -85,7 +103,7 @@ void MacIOSurfaceTextureHostOGL::CreateRenderTexture(
MOZ_ASSERT(mExternalImageId.isSome());
RefPtr texture = MakeRefPtr<wr::RenderMacIOSurfaceTextureHost>(
GetMacIOSurface(), mGpuFence);
GetMacIOSurface(), mDescriptor.fencesHolderId());
bool isDRM = (bool)(mFlags & TextureFlags::DRM_SOURCE);
texture->SetIsFromDRMSource(isDRM);
@@ -15,8 +15,6 @@ class MacIOSurface;
namespace mozilla {
namespace layers {
class GpuFence;
/**
* A TextureHost for shared MacIOSurface
*
@@ -78,7 +76,6 @@ class MacIOSurfaceTextureHostOGL : public TextureHost {
const SurfaceDescriptorMacIOSurface mDescriptor;
const RefPtr<MacIOSurface> mSurface;
const RefPtr<GpuFence> mGpuFence;
protected:
RefPtr<GLTextureSource> mTextureSource;
+8 -4
View File
@@ -43,6 +43,7 @@
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/glean/GfxMetrics.h"
#include "mozilla/image/ImageMemoryReporter.h"
#include "mozilla/layers/CompositeProcessFencesHolderMap.h"
#include "mozilla/layers/CompositorBridgeChild.h"
#include "mozilla/layers/CompositorManagerChild.h"
#include "mozilla/layers/CompositorThread.h"
@@ -72,7 +73,6 @@
#if defined(XP_WIN)
# include "gfxWindowsPlatform.h"
# include "mozilla/layers/CompositeProcessFencesHolderMap.h"
# include "mozilla/widget/WinWindowOcclusionTracker.h"
#elif defined(XP_DARWIN)
# include "gfxPlatformMac.h"
@@ -1346,7 +1346,7 @@ void gfxPlatform::InitLayersIPC() {
}
#endif
if (!gfxConfig::IsEnabled(Feature::GPU_PROCESS)) {
#if defined(XP_WIN)
#if defined(XP_WIN) || defined(XP_MACOSX)
CompositeProcessFencesHolderMap::Init();
#endif
RemoteTextureMap::Init();
@@ -1403,8 +1403,12 @@ void gfxPlatform::ShutdownLayersIPC() {
nsDependentCString(
StaticPrefs::GetPrefName_gfx_webrender_blob_tile_size()));
}
#if defined(XP_WIN)
#if defined(XP_WIN) || defined(XP_MACOSX)
CompositeProcessFencesHolderMap::Shutdown();
#endif
#if defined(XP_WIN)
widget::WinWindowOcclusionTracker::ShutDown();
#endif
} else {
@@ -4228,7 +4232,7 @@ void gfxPlatform::DisableGPUProcess() {
"Disabled by fallback to GPU Process disabled",
"FEATURE_FAILURE_DISABLED_BY_FALLBACK_GPU_PROCESS_DISABLED"_ns);
#if defined(XP_WIN)
#if defined(XP_WIN) || defined(XP_MACOSX)
CompositeProcessFencesHolderMap::Init();
#endif
RemoteTextureMap::Init();
@@ -14,7 +14,6 @@
#include "mozilla/gfx/Logging.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/layers/CompositionRecorder.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/NativeLayer.h"
#include "mozilla/layers/ProfilerScreenshots.h"
#include "mozilla/layers/SurfacePool.h"
@@ -11,13 +11,13 @@
#include "GLTypes.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/ScreenshotGrabber.h"
#include "mozilla/webrender/RenderCompositor.h"
namespace mozilla {
namespace layers {
class GpuFence;
class NativeLayerRootSnapshotter;
class NativeLayerRoot;
class NativeLayer;
@@ -14,7 +14,6 @@
#include "mozilla/gfx/Logging.h"
#include "mozilla/gfx/gfxVars.h"
#include "mozilla/layers/CompositionRecorder.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/NativeLayer.h"
#include "mozilla/layers/ProfilerScreenshots.h"
#include "mozilla/layers/SurfacePool.h"
@@ -11,13 +11,13 @@
#include "GLTypes.h"
#include "mozilla/HashFunctions.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/ScreenshotGrabber.h"
#include "mozilla/webrender/RenderCompositor.h"
namespace mozilla {
namespace layers {
class GpuFence;
class NativeLayerRootSnapshotter;
class NativeLayerRoot;
class NativeLayer;
@@ -15,7 +15,7 @@
#include "mozilla/ProfilerMarkers.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/gfx/Logging.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/CompositeProcessFencesHolderMap.h"
namespace mozilla {
namespace wr {
@@ -42,8 +42,11 @@ static bool CreateTextureForPlane(uint8_t aPlaneID, gl::GLContext* aGL,
}
RenderMacIOSurfaceTextureHost::RenderMacIOSurfaceTextureHost(
MacIOSurface* aSurface, layers::GpuFence* aGpuFence)
: mSurface(aSurface), mGpuFence(aGpuFence), mTextureHandles{0, 0, 0} {
MacIOSurface* aSurface,
const Maybe<layers::CompositeProcessFencesHolderId>& aFencesHolderId)
: mSurface(aSurface),
mFencesHolderId(aFencesHolderId),
mTextureHandles{0, 0, 0} {
MOZ_COUNT_CTOR_INHERITED(RenderMacIOSurfaceTextureHost, RenderTextureHost);
}
@@ -52,6 +55,23 @@ RenderMacIOSurfaceTextureHost::~RenderMacIOSurfaceTextureHost() {
DeleteTextureHandle();
}
RefPtr<layers::GpuFence> RenderMacIOSurfaceTextureHost::GetGpuFence() {
if (mFencesHolderId.isNothing()) {
return nullptr;
}
auto* fencesHolderMap = layers::CompositeProcessFencesHolderMap::Get();
if (!fencesHolderMap) {
return nullptr;
}
RefPtr<layers::Fence> fence =
fencesHolderMap->GetWriteFence(mFencesHolderId.ref());
if (!fence) {
return nullptr;
}
MOZ_ASSERT(fence->AsGpuFence());
return fence->AsGpuFence();
}
GLuint RenderMacIOSurfaceTextureHost::GetGLHandle(uint8_t aChannelIndex) const {
MOZ_ASSERT(mSurface);
MOZ_ASSERT((mSurface->GetPlaneCount() == 0)
@@ -108,11 +128,12 @@ wr::WrExternalImage RenderMacIOSurfaceTextureHost::Lock(uint8_t aChannelIndex,
}
}
if (mGpuFence) {
RefPtr<layers::GpuFence> writeFence = GetGpuFence();
if (writeFence) {
// This timeout matches the acquisition timeout for the keyed mutex
// in the D3D11 texture host.
AUTO_PROFILER_MARKER("Lock MacIOSurfaceTexture", GRAPHICS);
mGpuFence->ServerWait(mGL, TimeDuration::FromMilliseconds(10000));
writeFence->ServerWait(mGL, TimeDuration::FromMilliseconds(10000));
} else {
PROFILER_MARKER_UNTYPED("No GpuFence", GRAPHICS);
}
@@ -7,12 +7,12 @@
#include "RenderTextureHostSWGL.h"
#include "mozilla/gfx/MacIOSurface.h"
#include "mozilla/layers/GpuFence.h"
#include "mozilla/layers/TextureHostOGL.h"
namespace mozilla {
namespace layers {
class GpuFence;
class SurfaceDescriptorMacIOSurface;
} // namespace layers
@@ -20,8 +20,9 @@ namespace wr {
class RenderMacIOSurfaceTextureHost final : public RenderTextureHostSWGL {
public:
explicit RenderMacIOSurfaceTextureHost(MacIOSurface* aSurface,
layers::GpuFence* aGpuFence);
explicit RenderMacIOSurfaceTextureHost(
MacIOSurface* aSurface,
const Maybe<layers::CompositeProcessFencesHolderId>& aFencesHolderId);
wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
void Unlock() override;
@@ -47,14 +48,15 @@ class RenderMacIOSurfaceTextureHost final : public RenderTextureHostSWGL {
PlaneInfo& aPlaneInfo) override;
void UnmapPlanes() override;
layers::GpuFence* GetGpuFence() { return mGpuFence; }
RefPtr<layers::GpuFence> GetGpuFence();
const RefPtr<MacIOSurface> mSurface;
const Maybe<layers::CompositeProcessFencesHolderId> mFencesHolderId;
private:
virtual ~RenderMacIOSurfaceTextureHost();
void DeleteTextureHandle();
RefPtr<MacIOSurface> mSurface;
RefPtr<layers::GpuFence> mGpuFence;
RefPtr<gl::GLContext> mGL;
GLuint mTextureHandles[3];
};