Bug 1322741 - Make sure ID3D11Device is up-to-date in SyncObjectD3D11. r=dvander
☠☠ backed out by df0b580da7bd ☠ ☠
authorvincentliu <vliu@mozilla.com>
Wed, 28 Dec 2016 16:36:12 +0800
changeset 327397 ef2dd5f6e702292c74bbabc1606bc6d54609ce04
parent 327396 f25c47181e916c5ba6fb2d1d296081274333526d
child 327398 7b341e3b719a7b68624ab9c9fae502200290e28f
push id85172
push uservliu@mozilla.com
push dateWed, 28 Dec 2016 08:37:16 +0000
treeherdermozilla-inbound@ef2dd5f6e702 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1322741
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1322741 - Make sure ID3D11Device is up-to-date in SyncObjectD3D11. r=dvander --- gfx/layers/client/ClientLayerManager.cpp | 6 +++++- gfx/layers/client/ClientLayerManager.h | 1 + gfx/layers/client/TextureClient.h | 2 ++ gfx/layers/d3d11/TextureD3D11.cpp | 19 +++++++++++++++++++ gfx/layers/d3d11/TextureD3D11.h | 3 +++ 5 files changed, 30 insertions(+), 1 deletion(-)
gfx/layers/client/ClientLayerManager.cpp
gfx/layers/client/ClientLayerManager.h
gfx/layers/client/TextureClient.h
gfx/layers/d3d11/TextureD3D11.cpp
gfx/layers/d3d11/TextureD3D11.h
--- a/gfx/layers/client/ClientLayerManager.cpp
+++ b/gfx/layers/client/ClientLayerManager.cpp
@@ -604,16 +604,19 @@ ClientLayerManager::FlushRendering()
     }
   }
 }
 
 void
 ClientLayerManager::UpdateTextureFactoryIdentifier(const TextureFactoryIdentifier& aNewIdentifier)
 {
   mForwarder->IdentifyTextureHost(aNewIdentifier);
+  if (mForwarder->GetSyncObject()) {
+    mForwarder->GetSyncObject()->UpdateContentDevice();
+  }
 }
 
 void
 ClientLayerManager::SendInvalidRegion(const nsIntRegion& aRegion)
 {
   if (mWidget) {
     if (CompositorBridgeChild* remoteRenderer = mWidget->GetRemoteRenderer()) {
       remoteRenderer->SendNotifyRegionInvalidated(aRegion);
@@ -646,17 +649,18 @@ ClientLayerManager::StopFrameTimeRecordi
 void
 ClientLayerManager::ForwardTransaction(bool aScheduleComposite)
 {
   TimeStamp start = TimeStamp::Now();
 
   // Skip the synchronization for buffer since we also skip the painting during
   // device-reset status.
   if (!gfxPlatform::GetPlatform()->DidRenderingDeviceReset()) {
-    if (mForwarder->GetSyncObject()) {
+    if (mForwarder->GetSyncObject() &&
+        mForwarder->GetSyncObject()->IsSyncObjectValid()) {
       mForwarder->GetSyncObject()->FinalizeFrame();
     }
   }
 
   mPhase = PHASE_FORWARD;
 
   mLatestTransactionId = mTransactionIdAllocator->GetTransactionId();
   TimeStamp transactionStart;
--- a/gfx/layers/client/ClientLayerManager.h
+++ b/gfx/layers/client/ClientLayerManager.h
@@ -87,16 +87,17 @@ public:
   virtual already_AddRefed<CanvasLayer> CreateCanvasLayer() override;
   virtual already_AddRefed<ReadbackLayer> CreateReadbackLayer() override;
   virtual already_AddRefed<ColorLayer> CreateColorLayer() override;
   virtual already_AddRefed<TextLayer> CreateTextLayer() override;
   virtual already_AddRefed<BorderLayer> CreateBorderLayer() override;
   virtual already_AddRefed<RefLayer> CreateRefLayer() override;
 
   void UpdateTextureFactoryIdentifier(const TextureFactoryIdentifier& aNewIdentifier);
+  void UpdateContentDeviceToSyncObject();
   TextureFactoryIdentifier GetTextureFactoryIdentifier()
   {
     return AsShadowForwarder()->GetTextureFactoryIdentifier();
   }
 
   virtual void FlushRendering() override;
   void SendInvalidRegion(const nsIntRegion& aRegion);
 
--- a/gfx/layers/client/TextureClient.h
+++ b/gfx/layers/client/TextureClient.h
@@ -106,16 +106,18 @@ public:
   static already_AddRefed<SyncObject> CreateSyncObject(SyncHandle aHandle);
 
   enum class SyncType {
     D3D11,
   };
 
   virtual SyncType GetSyncType() = 0;
   virtual void FinalizeFrame() = 0;
+  virtual void UpdateContentDevice() = 0;
+  virtual bool IsSyncObjectValid() = 0;
 
 protected:
   SyncObject() { }
 };
 
 /**
  * This class may be used to asynchronously receive an update when the content
  * drawn to this texture client is available for reading in CPU memory. This
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -1234,16 +1234,35 @@ SyncObjectD3D11::Init()
 }
 
 void
 SyncObjectD3D11::RegisterTexture(ID3D11Texture2D* aTexture)
 {
   mD3D11SyncedTextures.push_back(aTexture);
 }
 
+bool
+SyncObjectD3D11::IsSyncObjectValid()
+{
+  RefPtr<ID3D11Device> dev = DeviceManagerDx::Get()->GetContentDevice();
+  if (!dev || (dev != mD3D11Device)) {
+    return false;
+  }
+  return true;
+}
+
+void
+SyncObjectD3D11::UpdateContentDevice()
+{
+  RefPtr<ID3D11Device> dev = DeviceManagerDx::Get()->GetContentDevice();
+  if (!dev) {
+    mD3D11Device = dev;
+  }
+}
+
 void
 SyncObjectD3D11::FinalizeFrame()
 {
   if (!mD3D11SyncedTextures.size()) {
     return;
   }
   if (!Init()) {
     return;
--- a/gfx/layers/d3d11/TextureD3D11.h
+++ b/gfx/layers/d3d11/TextureD3D11.h
@@ -410,26 +410,29 @@ private:
   RefPtr<ID3D11RenderTargetView> mRTView;
 };
 
 class SyncObjectD3D11 : public SyncObject
 {
 public:
   explicit SyncObjectD3D11(SyncHandle aSyncHandle);
   virtual void FinalizeFrame();
+  virtual void UpdateContentDevice();
+  virtual bool IsSyncObjectValid();
 
   virtual SyncType GetSyncType() { return SyncType::D3D11; }
 
   void RegisterTexture(ID3D11Texture2D* aTexture);
 
 private:
   bool Init();
 
 private:
   SyncHandle mSyncHandle;
+  RefPtr<ID3D11Device> mD3D11Device;
   RefPtr<ID3D11Texture2D> mD3D11Texture;
   RefPtr<IDXGIKeyedMutex> mKeyedMutex;
   std::vector<ID3D11Texture2D*> mD3D11SyncedTextures;
 };
 
 inline uint32_t GetMaxTextureSizeForFeatureLevel(D3D_FEATURE_LEVEL aFeatureLevel)
 {
   int32_t maxTextureSize;