commit 3f223349cf1c24bd71a7b32b7eb62cdf36f850da
parent be62884d661cc13cba783c7dd3f0b0bde748454e
Author: Sotaro Ikeda <sotaro.ikeda.g@gmail.com>
Date: Wed, 24 Dec 2025 11:05:42 +0000
Bug 2007643 - Deliver FenceD3D11 to DXGITextureHostD3D11 r=gfx-reviewers,lsalzman
Preparation of Bug 2007464.
Differential Revision: https://phabricator.services.mozilla.com/D277503
Diffstat:
11 files changed, 72 insertions(+), 23 deletions(-)
diff --git a/gfx/layers/composite/GPUVideoTextureHost.cpp b/gfx/layers/composite/GPUVideoTextureHost.cpp
@@ -209,6 +209,12 @@ void GPUVideoTextureHost::NotifyNotUsed() {
TextureHost::NotifyNotUsed();
}
+void GPUVideoTextureHost::SetReadFence(Fence* aReadFence) {
+ if (EnsureWrappedTextureHost()) {
+ EnsureWrappedTextureHost()->SetReadFence(aReadFence);
+ }
+}
+
BufferTextureHost* GPUVideoTextureHost::AsBufferTextureHost() {
if (EnsureWrappedTextureHost()) {
return EnsureWrappedTextureHost()->AsBufferTextureHost();
diff --git a/gfx/layers/composite/GPUVideoTextureHost.h b/gfx/layers/composite/GPUVideoTextureHost.h
@@ -67,6 +67,8 @@ class GPUVideoTextureHost final : public TextureHost {
void NotifyNotUsed() override;
+ void SetReadFence(Fence* aReadFence) override;
+
BufferTextureHost* AsBufferTextureHost() override;
DXGITextureHostD3D11* AsDXGITextureHostD3D11() override;
diff --git a/gfx/layers/composite/RemoteTextureHostWrapper.cpp b/gfx/layers/composite/RemoteTextureHostWrapper.cpp
@@ -161,6 +161,12 @@ void RemoteTextureHostWrapper::NotifyNotUsed() {
mTextureId, mOwnerId, mForPid);
}
+void RemoteTextureHostWrapper::SetReadFence(Fence* aReadFence) {
+ if (mRemoteTexture) {
+ mRemoteTexture->SetReadFence(aReadFence);
+ }
+}
+
TextureHostType RemoteTextureHostWrapper::GetTextureHostType() {
if (!mRemoteTexture) {
return TextureHostType::Unknown;
diff --git a/gfx/layers/composite/RemoteTextureHostWrapper.h b/gfx/layers/composite/RemoteTextureHostWrapper.h
@@ -66,6 +66,8 @@ class RemoteTextureHostWrapper : public TextureHost {
void NotifyNotUsed() override;
+ void SetReadFence(Fence* aReadFence) override;
+
RemoteTextureHostWrapper* AsRemoteTextureHostWrapper() override {
return this;
}
diff --git a/gfx/layers/composite/TextureHost.h b/gfx/layers/composite/TextureHost.h
@@ -64,6 +64,7 @@ class ReadLockDescriptor;
class CompositorBridgeParent;
class DXGITextureHostD3D11;
class DXGIYCbCrTextureHostD3D11;
+class Fence;
class SurfaceDescriptor;
class HostIPCAllocator;
class ISurfaceAllocator;
@@ -718,6 +719,8 @@ class TextureHost : public AtomicRefCountedWithFinalize<TextureHost> {
virtual TextureHostType GetTextureHostType() { return mTextureHostType; }
+ virtual void SetReadFence(Fence* aReadFence) {}
+
// Our WebRender backend may impose restrictions on whether textures are
// prepared as native textures or not, or it may have no restriction at
// all. This enumerates those possibilities.
diff --git a/gfx/layers/d3d11/TextureD3D11.cpp b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -1226,6 +1226,32 @@ bool DXGITextureHostD3D11::SupportsExternalCompositing(
return false;
}
+void DXGITextureHostD3D11::NotifyNotUsed() {
+ if (!mReadFence || mFencesHolderId.isNothing()) {
+ return;
+ }
+
+ auto* fenceHolderMap = CompositeProcessD3D11FencesHolderMap::Get();
+ if (!fenceHolderMap) {
+ MOZ_ASSERT_UNREACHABLE("unexpected to be called");
+ return;
+ }
+ fenceHolderMap->SetReadFence(mFencesHolderId.ref(), mReadFence);
+ mReadFence = nullptr;
+}
+
+void DXGITextureHostD3D11::SetReadFence(Fence* aReadFence) {
+ MOZ_ASSERT(aReadFence);
+ MOZ_ASSERT(aReadFence->AsFenceD3D11());
+
+ if (!aReadFence || !aReadFence->AsFenceD3D11() ||
+ mFencesHolderId.isNothing()) {
+ return;
+ }
+
+ mReadFence = aReadFence->AsFenceD3D11();
+}
+
DXGIYCbCrTextureHostD3D11::DXGIYCbCrTextureHostD3D11(
TextureFlags aFlags, const SurfaceDescriptorDXGIYCbCr& aDescriptor)
: TextureHost(TextureHostType::DXGIYCbCr, aFlags),
@@ -1352,14 +1378,15 @@ void DXGIYCbCrTextureHostD3D11::NotifyNotUsed() {
mReadFence = nullptr;
}
-void DXGIYCbCrTextureHostD3D11::SetReadFence(RefPtr<FenceD3D11> aReadFence) {
+void DXGIYCbCrTextureHostD3D11::SetReadFence(Fence* aReadFence) {
MOZ_ASSERT(aReadFence);
+ MOZ_ASSERT(aReadFence->AsFenceD3D11());
- if (!aReadFence) {
+ if (!aReadFence || !aReadFence->AsFenceD3D11()) {
return;
}
- mReadFence = aReadFence;
+ mReadFence = aReadFence->AsFenceD3D11();
}
bool DataTextureSourceD3D11::Update(DataSourceSurface* aSurface,
diff --git a/gfx/layers/d3d11/TextureD3D11.h b/gfx/layers/d3d11/TextureD3D11.h
@@ -391,6 +391,10 @@ class DXGITextureHostD3D11 : public TextureHost {
DXGITextureHostD3D11* AsDXGITextureHostD3D11() override { return this; }
+ void NotifyNotUsed() override;
+
+ void SetReadFence(Fence* aReadFence) override;
+
const RefPtr<gfx::FileHandleWrapper> mHandle;
const Maybe<GpuProcessTextureId> mGpuProcessTextureId;
const uint32_t mArrayIndex;
@@ -400,6 +404,9 @@ class DXGITextureHostD3D11 : public TextureHost {
const Maybe<CompositeProcessFencesHolderId> mFencesHolderId;
const gfx::ColorSpace2 mColorSpace;
const gfx::ColorRange mColorRange;
+
+ protected:
+ RefPtr<FenceD3D11> mReadFence;
};
class DXGIYCbCrTextureHostD3D11 : public TextureHost {
@@ -451,7 +458,7 @@ class DXGIYCbCrTextureHostD3D11 : public TextureHost {
return this;
}
- void SetReadFence(RefPtr<FenceD3D11> aReadFence);
+ void SetReadFence(Fence* aReadFence) override;
// Handles will be closed automatically when `UniqueFileHandle` gets
// destroyed.
diff --git a/gfx/layers/wr/AsyncImagePipelineManager.cpp b/gfx/layers/wr/AsyncImagePipelineManager.cpp
@@ -711,7 +711,7 @@ void AsyncImagePipelineManager::ProcessPipelineUpdates() {
auto& holder = update.second;
const auto& info = holder.mInfo->Raw();
- mReleaseFence = std::move(holder.mFence);
+ mReadFence = std::move(holder.mFence);
for (auto& epoch : info.epochs) {
ProcessPipelineRendered(epoch.pipeline_id, epoch.epoch, update.first);
@@ -742,10 +742,10 @@ void AsyncImagePipelineManager::ProcessPipelineRendered(
for (auto it = holder->mTextureHostsUntilRenderSubmitted.begin();
it != firstSubmittedHostToKeep; ++it) {
const auto& entry = it;
- if (entry->mTexture->GetAndroidHardwareBuffer() && mReleaseFence &&
- mReleaseFence->AsFenceFileHandle()) {
+ if (entry->mTexture->GetAndroidHardwareBuffer() && mReadFence &&
+ mReadFence->AsFenceFileHandle()) {
entry->mTexture->SetReleaseFence(
- mReleaseFence->AsFenceFileHandle()->DuplicateFileHandle());
+ mReadFence->AsFenceFileHandle()->DuplicateFileHandle());
}
}
#endif
@@ -762,16 +762,14 @@ void AsyncImagePipelineManager::ProcessPipelineRendered(
holder->mTextureHostsUntilRenderCompleted.end(),
[&aEpoch](const auto& entry) { return aEpoch <= entry->mEpoch; });
-#ifdef XP_WIN
for (auto it = holder->mTextureHostsUntilRenderCompleted.begin();
it != firstCompletedHostToKeep; ++it) {
const auto& entry = *it;
- auto* host = entry->mTexture->AsDXGIYCbCrTextureHostD3D11();
- if (host && mReleaseFence && mReleaseFence->AsFenceD3D11()) {
- host->SetReadFence(mReleaseFence->AsFenceD3D11());
+ auto* texture = entry->mTexture.get();
+ if (texture && mReadFence) {
+ texture->SetReadFence(mReadFence);
}
}
-#endif
if (firstCompletedHostToKeep !=
holder->mTextureHostsUntilRenderCompleted.begin()) {
diff --git a/gfx/layers/wr/AsyncImagePipelineManager.h b/gfx/layers/wr/AsyncImagePipelineManager.h
@@ -292,7 +292,7 @@ class AsyncImagePipelineManager final {
std::vector<std::pair<wr::RenderedFrameId,
std::vector<UniquePtr<ForwardingTextureHost>>>>
mTexturesInUseByGPU;
- RefPtr<Fence> mReleaseFence;
+ RefPtr<Fence> mReadFence;
};
} // namespace layers
diff --git a/gfx/layers/wr/WebRenderTextureHost.cpp b/gfx/layers/wr/WebRenderTextureHost.cpp
@@ -123,15 +123,7 @@ void WebRenderTextureHost::NotifyNotUsed() {
wr::RenderThread::Get()->NotifyNotUsed(GetExternalImageKey());
}
#endif
- if (mWrappedTextureHost->AsRemoteTextureHostWrapper() ||
- mWrappedTextureHost->AsTextureHostWrapperD3D11()) {
- mWrappedTextureHost->NotifyNotUsed();
- }
-#ifdef XP_WIN
- if (auto* host = AsDXGIYCbCrTextureHostD3D11()) {
- host->NotifyNotUsed();
- }
-#endif
+ mWrappedTextureHost->NotifyNotUsed();
TextureHost::NotifyNotUsed();
}
@@ -220,6 +212,10 @@ UniqueFileHandle WebRenderTextureHost::GetAndResetReleaseFence() {
return mWrappedTextureHost->GetAndResetReleaseFence();
}
+void WebRenderTextureHost::SetReadFence(Fence* aReadFence) {
+ return mWrappedTextureHost->SetReadFence(aReadFence);
+}
+
AndroidHardwareBuffer* WebRenderTextureHost::GetAndroidHardwareBuffer() const {
return mWrappedTextureHost->GetAndroidHardwareBuffer();
}
diff --git a/gfx/layers/wr/WebRenderTextureHost.h b/gfx/layers/wr/WebRenderTextureHost.h
@@ -107,6 +107,8 @@ class WebRenderTextureHost final : public TextureHost {
void SetReleaseFence(UniqueFileHandle&& aFenceFd) override;
+ void SetReadFence(Fence* aReadFence) override;
+
UniqueFileHandle GetAndResetReleaseFence() override;
AndroidHardwareBuffer* GetAndroidHardwareBuffer() const override;