Skip to content

Commit

Permalink
Bug 1866412 - Add FenceD3D11 for wrapping ID3D11Fence r=gfx-reviewers…
Browse files Browse the repository at this point in the history
…,jrmuizel

The change is a preparation for Bug 1865984, Bug 1863474 and Bug 1861605.

FenceD3D11 is going to be used by Bug 1865984 and Bug 1863474. And FileHandleWrapper is going to be added for wrapping shared handle of ID3D11Fence and ID3D11Texture2D(Bug 1861605).

For now, FenceInfo is expected to be delivered just during creating TextureHost. It works for WebGL and WebGPU.

Differential Revision: https://phabricator.services.mozilla.com/D194612
  • Loading branch information
sotaro committed Dec 8, 2023
1 parent 2487ce0 commit 1ef38c3
Show file tree
Hide file tree
Showing 16 changed files with 473 additions and 14 deletions.
2 changes: 1 addition & 1 deletion dom/webgpu/ExternalTextureD3D11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Maybe<layers::SurfaceDescriptor> ExternalTextureD3D11::ToSurfaceDescriptor() {
/* gpuProcessTextureId */ Nothing(),
/* arrayIndex */ 0, format, gfx::IntSize(mWidth, mHeight),
gfx::ColorSpace2::SRGB, gfx::ColorRange::FULL,
/* hasKeyedMutex */ false));
/* hasKeyedMutex */ false, /* fenceInfo */ Nothing()));
}

void ExternalTextureD3D11::GetSnapshot(const ipc::Shmem& aDestShmem,
Expand Down
3 changes: 2 additions & 1 deletion gfx/gl/SharedSurfaceANGLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ SharedSurface_ANGLEShareHandle::ToSurfaceDescriptor() {
return Some(layers::SurfaceDescriptorD3D10(
(WindowsHandle)mShareHandle, /* gpuProcessTextureId */ Nothing(),
/* arrayIndex */ 0, format, mDesc.size, mDesc.colorSpace,
gfx::ColorRange::FULL, /* hasKeyedMutex */ true));
gfx::ColorRange::FULL, /* hasKeyedMutex */ true,
/* fenceInfo */ Nothing()));
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion gfx/gl/SharedSurfaceD3D11Interop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ SharedSurface_D3D11Interop::ToSurfaceDescriptor() {
return Some(layers::SurfaceDescriptorD3D10(
WindowsHandle(mData.dxgiHandle), /* gpuProcessTextureId */ Nothing(),
/* arrayIndex */ 0, format, mDesc.size, mDesc.colorSpace,
gfx::ColorRange::FULL, /* hasKeyedMutex */ true));
gfx::ColorRange::FULL, /* hasKeyedMutex */ true,
/* fenceInfo */ Nothing()));
}

//////////////////////////////////////////////////////////////////////////////////////////
Expand Down
20 changes: 20 additions & 0 deletions gfx/ipc/FileHandleWrapper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "FileHandleWrapper.h"

namespace mozilla::gfx {

FileHandleWrapper::FileHandleWrapper(mozilla::UniqueFileHandle&& aHandle)
: mHandle(std::move(aHandle)) {}

FileHandleWrapper::~FileHandleWrapper() {}

mozilla::detail::FileHandleType FileHandleWrapper::GetHandle() {
return mHandle.get();
}

} // namespace mozilla::gfx
61 changes: 61 additions & 0 deletions gfx/ipc/FileHandleWrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef _include_gfx_ipc_FileHandleWrapper_h__
#define _include_gfx_ipc_FileHandleWrapper_h__

#include "mozilla/UniquePtrExtensions.h"
#include "nsISupportsImpl.h"

namespace mozilla {

namespace ipc {
template <typename T>
struct IPDLParamTraits;
} // namespace ipc

namespace gfx {

//
// A class for sharing file handle or shared handle among multiple clients.
//
// The file handles or the shared handles consume system resources. The class
// could reduce the number of shared handles in a process.
//
class FileHandleWrapper {
friend struct mozilla::ipc::IPDLParamTraits<gfx::FileHandleWrapper*>;

public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FileHandleWrapper);

explicit FileHandleWrapper(mozilla::UniqueFileHandle&& aHandle);

mozilla::detail::FileHandleType GetHandle();

protected:
~FileHandleWrapper();

const mozilla::UniqueFileHandle mHandle;
};

struct FenceInfo {
FenceInfo() = default;
FenceInfo(FileHandleWrapper* aFenceHandle, uint64_t aFenceValue)
: mFenceHandle(aFenceHandle), mFenceValue(aFenceValue) {}

bool operator==(const FenceInfo& aOther) const {
return mFenceHandle == aOther.mFenceHandle &&
mFenceValue == aOther.mFenceValue;
}

RefPtr<FileHandleWrapper> mFenceHandle;
uint64_t mFenceValue = 0;
};

} // namespace gfx
} // namespace mozilla

#endif // _include_gfx_ipc_FileHandleWrapper_h__
58 changes: 58 additions & 0 deletions gfx/ipc/GfxMessageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
#include "ipc/EnumSerializer.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "mozilla/gfx/CrossProcessPaint.h"
#include "mozilla/gfx/FileHandleWrapper.h"
#include "mozilla/gfx/Matrix.h"
#include "mozilla/gfx/ScaleFactor.h"
#include "mozilla/gfx/ScaleFactors2D.h"
#include "SharedFontList.h"
#include "nsRect.h"
#include "nsRegion.h"
#include "mozilla/Array.h"
#include "mozilla/ipc/FileDescriptor.h"
#include "mozilla/ipc/IPDLParamTraits.h"
#include "mozilla/ipc/ProtocolMessageUtils.h"
#include "mozilla/ipc/ProtocolUtils.h"
#include "mozilla/ipc/ShmemMessageUtils.h"

Expand Down Expand Up @@ -1186,6 +1189,24 @@ struct ParamTraits<mozilla::fontlist::Pointer> {
}
};

template <>
struct ParamTraits<mozilla::gfx::FenceInfo> {
typedef mozilla::gfx::FenceInfo paramType;

static void Write(MessageWriter* aWriter, const paramType& aParam) {
WriteParam(aWriter, aParam.mFenceHandle);
WriteParam(aWriter, aParam.mFenceValue);
}

static bool Read(MessageReader* aReader, paramType* aResult) {
if (!ReadParam(aReader, &aResult->mFenceHandle) ||
!ReadParam(aReader, &aResult->mFenceValue)) {
return false;
}
return true;
}
};

} // namespace IPC

namespace mozilla {
Expand Down Expand Up @@ -1239,6 +1260,43 @@ struct IPDLParamTraits<gfx::PaintFragment> {
}
};

template <>
struct IPDLParamTraits<gfx::FileHandleWrapper*> {
static void Write(IPC::MessageWriter* aWriter, IProtocol* aActor,
gfx::FileHandleWrapper* aParam) {
if (!aParam) {
WriteIPDLParam(aWriter, aActor, false);
return;
}
WriteIPDLParam(aWriter, aActor, true);

mozilla::ipc::FileDescriptor desc(aParam->GetHandle());
WriteIPDLParam(aWriter, aActor, desc);
}

static bool Read(IPC::MessageReader* aReader, IProtocol* aActor,
RefPtr<gfx::FileHandleWrapper>* aResult) {
*aResult = nullptr;
bool notnull = false;
if (!ReadIPDLParam(aReader, aActor, &notnull)) {
return false;
}

if (!notnull) {
return true;
}

mozilla::ipc::FileDescriptor desc;
if (!ReadIPDLParam(aReader, aActor, &desc)) {
return false;
}
auto wrapper =
MakeRefPtr<gfx::FileHandleWrapper>(desc.TakePlatformHandle());
*aResult = std::move(wrapper);
return true;
}
};

} // namespace ipc
} // namespace mozilla

Expand Down
2 changes: 2 additions & 0 deletions gfx/ipc/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ EXPORTS.mozilla.gfx += [
"CanvasManagerParent.h",
"CanvasRenderThread.h",
"CrossProcessPaint.h",
"FileHandleWrapper.h",
"GPUChild.h",
"GPUParent.h",
"GPUProcessHost.h",
Expand Down Expand Up @@ -45,6 +46,7 @@ UNIFIED_SOURCES += [
"CompositorWidgetVsyncObserver.cpp",
"CrossProcessPaint.cpp",
"D3DMessageUtils.cpp",
"FileHandleWrapper.cpp",
"GPUChild.cpp",
"GPUProcessHost.cpp",
"GPUProcessImpl.cpp",
Expand Down
Loading

0 comments on commit 1ef38c3

Please sign in to comment.