Bug 1847665 - Reduce SyncObjectD3D11Host::Synchronize() call in RenderCompositorANGLE::BeginFrame() r=gfx-reviewers,lsalzman

SyncObjectD3D11Host::Synchronize() could spend time when GPU is busy.
The Synchronize() call is not necessary when all RenderDXGITextureHosts have GpuProcessTextureId or KeyedMutex.

Differential Revision: https://phabricator.services.mozilla.com/D185619
This commit is contained in:
sotaro 2023-08-08 04:50:54 +00:00
Родитель 7fcb244e50
Коммит 2cae2b6402
8 изменённых файлов: 31 добавлений и 16 удалений

Просмотреть файл

@ -144,7 +144,7 @@ SharedSurface_ANGLEShareHandle::ToSurfaceDescriptor() {
return Some(layers::SurfaceDescriptorD3D10(
(WindowsHandle)mShareHandle, /* gpuProcessTextureId */ Nothing(),
/* arrayIndex */ 0, format, mDesc.size, mDesc.colorSpace,
gfx::ColorRange::FULL));
gfx::ColorRange::FULL, /* hasKeyedMutex */ !!mKeyedMutex));
}
class ScopedLockTexture final {

Просмотреть файл

@ -444,7 +444,7 @@ SharedSurface_D3D11Interop::ToSurfaceDescriptor() {
return Some(layers::SurfaceDescriptorD3D10(
WindowsHandle(mData.dxgiHandle), /* gpuProcessTextureId */ Nothing(),
/* arrayIndex */ 0, format, mDesc.size, mDesc.colorSpace,
gfx::ColorRange::FULL));
gfx::ColorRange::FULL, /* hasKeyedMutex */ true));
}
//////////////////////////////////////////////////////////////////////////////////////////

Просмотреть файл

@ -83,7 +83,8 @@ bool DXGID3D9TextureData::Serialize(SurfaceDescriptor& aOutDescriptor) {
SurfaceDescriptorD3D10 desc((WindowsHandle)(mHandle),
/* gpuProcessTextureId */ Nothing(),
/* arrayIndex */ 0, mFormat, GetSize(),
gfx::ColorSpace2::SRGB, gfx::ColorRange::FULL);
gfx::ColorSpace2::SRGB, gfx::ColorRange::FULL,
/* hasKeyedMutex */ false);
// In reality, with D3D9 we will only ever deal with RGBA textures.
bool isYUV = mFormat == gfx::SurfaceFormat::NV12 ||
mFormat == gfx::SurfaceFormat::P010 ||

Просмотреть файл

@ -290,7 +290,7 @@ D3D11TextureData::D3D11TextureData(ID3D11Texture2D* aTexture,
: mSize(aSize),
mFormat(aFormat),
mNeedsClear(aFlags & ALLOC_CLEAR_BUFFER),
mHasSynchronization(HasKeyedMutex(aTexture)),
mHasKeyedMutex(HasKeyedMutex(aTexture)),
mTexture(aTexture),
mArrayIndex(aArrayIndex),
mAllocationFlags(aFlags) {
@ -370,11 +370,11 @@ void D3D11TextureData::FillInfo(TextureData::Info& aInfo) const {
aInfo.size = mSize;
aInfo.format = mFormat;
aInfo.supportsMoz2D = true;
aInfo.hasSynchronization = mHasSynchronization;
aInfo.hasSynchronization = mHasKeyedMutex;
}
void D3D11TextureData::SyncWithObject(RefPtr<SyncObjectClient> aSyncObject) {
if (!aSyncObject || mHasSynchronization) {
if (!aSyncObject || mHasKeyedMutex) {
// When we have per texture synchronization we sync using the keyed mutex.
return;
}
@ -400,9 +400,9 @@ bool D3D11TextureData::SerializeSpecific(
return false;
}
}
*aOutDesc = SurfaceDescriptorD3D10((WindowsHandle)sharedHandle,
mGpuProcessTextureId, mArrayIndex, mFormat,
mSize, mColorSpace, mColorRange);
*aOutDesc = SurfaceDescriptorD3D10(
(WindowsHandle)sharedHandle, mGpuProcessTextureId, mArrayIndex, mFormat,
mSize, mColorSpace, mColorRange, /* hasKeyedMutex */ mHasKeyedMutex);
return true;
}
@ -804,6 +804,7 @@ DXGITextureHostD3D11::DXGITextureHostD3D11(
mSize(aDescriptor.size()),
mHandle(aDescriptor.handle()),
mFormat(aDescriptor.format()),
mHasKeyedMutex(aDescriptor.hasKeyedMutex()),
mColorSpace(aDescriptor.colorSpace()),
mColorRange(aDescriptor.colorRange()),
mIsLocked(false) {}
@ -951,9 +952,9 @@ void DXGITextureHostD3D11::UnlockInternal() {
void DXGITextureHostD3D11::CreateRenderTexture(
const wr::ExternalImageId& aExternalImageId) {
RefPtr<wr::RenderDXGITextureHost> texture =
new wr::RenderDXGITextureHost(mHandle, mGpuProcessTextureId, mArrayIndex,
mFormat, mColorSpace, mColorRange, mSize);
RefPtr<wr::RenderDXGITextureHost> texture = new wr::RenderDXGITextureHost(
mHandle, mGpuProcessTextureId, mArrayIndex, mFormat, mColorSpace,
mColorRange, mSize, mHasKeyedMutex);
if (mFlags & TextureFlags::SOFTWARE_DECODED_VIDEO) {
texture->SetIsSoftwareDecodedVideo();
}

Просмотреть файл

@ -141,7 +141,7 @@ class D3D11TextureData final : public TextureData {
private:
gfx::ColorRange mColorRange = gfx::ColorRange::LIMITED;
bool mNeedsClear = false;
const bool mHasSynchronization;
const bool mHasKeyedMutex;
RefPtr<ID3D11Texture2D> mTexture;
Maybe<GpuProcessTextureId> mGpuProcessTextureId;
@ -391,6 +391,7 @@ class DXGITextureHostD3D11 : public TextureHost {
gfx::IntSize mSize;
WindowsHandle mHandle;
gfx::SurfaceFormat mFormat;
bool mHasKeyedMutex;
public:
const gfx::ColorSpace2 mColorSpace;

Просмотреть файл

@ -38,6 +38,7 @@ namespace layers {
IntSize size;
ColorSpace2 colorSpace;
ColorRange colorRange;
bool hasKeyedMutex;
};
[Comparable] struct SurfaceDescriptorDXGIYCbCr {

Просмотреть файл

@ -24,7 +24,7 @@ RenderDXGITextureHost::RenderDXGITextureHost(
Maybe<layers::GpuProcessTextureId>& aGpuProcessTextureId,
uint32_t aArrayIndex, gfx::SurfaceFormat aFormat,
gfx::ColorSpace2 aColorSpace, gfx::ColorRange aColorRange,
gfx::IntSize aSize)
gfx::IntSize aSize, bool aHasKeyedMutex)
: mHandle(aHandle),
mGpuProcessTextureId(aGpuProcessTextureId),
mArrayIndex(aArrayIndex),
@ -35,6 +35,7 @@ RenderDXGITextureHost::RenderDXGITextureHost(
mColorSpace(aColorSpace),
mColorRange(aColorRange),
mSize(aSize),
mHasKeyedMutex(aHasKeyedMutex),
mLocked(false) {
MOZ_COUNT_CTOR_INHERITED(RenderDXGITextureHost, RenderTextureHost);
MOZ_ASSERT((mFormat != gfx::SurfaceFormat::NV12 &&
@ -221,6 +222,11 @@ bool RenderDXGITextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
}
MOZ_ASSERT(mTexture.get());
mTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mKeyedMutex));
MOZ_ASSERT(mHasKeyedMutex == !!mKeyedMutex);
if (mHasKeyedMutex != !!mKeyedMutex) {
gfxCriticalNoteOnce << "KeyedMutex mismatch";
}
return true;
}
@ -430,6 +436,10 @@ gfx::IntSize RenderDXGITextureHost::GetSize(uint8_t aChannelIndex) const {
}
}
bool RenderDXGITextureHost::SyncObjectNeeded() {
return mGpuProcessTextureId.isNothing() && !mHasKeyedMutex;
}
RenderDXGIYCbCrTextureHost::RenderDXGIYCbCrTextureHost(
WindowsHandle (&aHandles)[3], gfx::YUVColorSpace aYUVColorSpace,
gfx::ColorDepth aColorDepth, gfx::ColorRange aColorRange,

Просмотреть файл

@ -25,7 +25,7 @@ class RenderDXGITextureHost final : public RenderTextureHostSWGL {
WindowsHandle aHandle,
Maybe<layers::GpuProcessTextureId>& aGpuProcessTextureId,
uint32_t aArrayIndex, gfx::SurfaceFormat aFormat, gfx::ColorSpace2,
gfx::ColorRange aColorRange, gfx::IntSize aSize);
gfx::ColorRange aColorRange, gfx::IntSize aSize, bool aHasKeyedMutex);
wr::WrExternalImage Lock(uint8_t aChannelIndex, gl::GLContext* aGL) override;
void Unlock() override;
@ -34,7 +34,7 @@ class RenderDXGITextureHost final : public RenderTextureHostSWGL {
gfx::IntSize GetSize(uint8_t aChannelIndex) const;
GLuint GetGLHandle(uint8_t aChannelIndex) const;
bool SyncObjectNeeded() override { return true; }
bool SyncObjectNeeded() override;
RenderDXGITextureHost* AsRenderDXGITextureHost() override { return this; }
@ -119,6 +119,7 @@ class RenderDXGITextureHost final : public RenderTextureHostSWGL {
const gfx::ColorSpace2 mColorSpace;
const gfx::ColorRange mColorRange;
const gfx::IntSize mSize;
const bool mHasKeyedMutex;
private:
bool mLocked;