Bug 1382829 - Don't mix and match Y/Cb/Cr slots when binding video. r=bas
authorDavid Anderson <danderson@mozilla.com>
Tue, 25 Jul 2017 14:51:27 -0400
changeset 422110 8a86ac7188adb863a1dac349c0b31be4927adccf
parent 422109 a3a834899c7335e179ad77d0b48b9ed6df0a231a
child 422111 710b97157320ea30bb87a1cc3845e2d6e80fbb83
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs1382829
milestone56.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 1382829 - Don't mix and match Y/Cb/Cr slots when binding video. r=bas
gfx/layers/d3d11/MLGDeviceD3D11.cpp
gfx/layers/d3d11/MLGDeviceD3D11.h
--- a/gfx/layers/d3d11/MLGDeviceD3D11.cpp
+++ b/gfx/layers/d3d11/MLGDeviceD3D11.cpp
@@ -1646,47 +1646,47 @@ MLGDeviceD3D11::DrawInstanced(uint32_t a
                               uint32_t aVertexOffset, uint32_t aInstanceOffset)
 {
   mCtx->DrawInstanced(aVertexCountPerInstance, aInstanceCount, aVertexOffset, aInstanceOffset);
 }
 
 void
 MLGDeviceD3D11::SetPSTextures(uint32_t aSlot, uint32_t aNumTextures, TextureSource* const* aTextures)
 {
-  StackArray<ID3D11ShaderResourceView*, 2> textures(aNumTextures);
+  // TextureSource guarantees that the ID3D11ShaderResourceView will be cached,
+  // so we don't hold a RefPtr here.
+  StackArray<ID3D11ShaderResourceView*, 3> views(aNumTextures);
 
   for (size_t i = 0; i < aNumTextures; i++) {
-    if (!aTextures[i]) {
-      gfxWarning() << "Null TextureRef in SetPSTextures";
-      continue;
+    views[i] = ResolveTextureSourceForShader(aTextures[i]);
+  }
+
+  mCtx->PSSetShaderResources(aSlot, aNumTextures, views.data());
+}
+
+ID3D11ShaderResourceView*
+MLGDeviceD3D11::ResolveTextureSourceForShader(TextureSource* aTexture)
+{
+  if (!aTexture) {
+    return nullptr;
+  }
+
+  if (TextureSourceD3D11* source = aTexture->AsSourceD3D11()) {
+    ID3D11Texture2D* texture = source->GetD3D11Texture();
+    if (!texture) {
+      gfxWarning() << "No D3D11 texture present in SetPSTextures";
+      return nullptr;
     }
 
-    ID3D11ShaderResourceView* view = nullptr;
-    if (TextureSourceD3D11* source = aTextures[i]->AsSourceD3D11()) {
-      ID3D11Texture2D* texture = source->GetD3D11Texture();
-      if (!texture) {
-        gfxWarning() << "No D3D11 texture present in SetPSTextures";
-        continue;
-      }
-      MaybeLockTexture(texture);
-
-      view = source->GetShaderResourceView();
-    } else {
-      gfxWarning() << "Unknown texture type in SetPSTextures";
-      continue;
-    }
-
-    if (!view) {
-      gfxWarning() << "Failed to get shader resource view for texture";
-      continue;
-    }
-    textures[i] = view;
+    MaybeLockTexture(texture);
+    return source->GetShaderResourceView();
   }
 
-  mCtx->PSSetShaderResources(aSlot, aNumTextures, textures.data());
+  gfxWarning() << "Unknown texture type in SetPSTextures";
+  return nullptr;
 }
 
 void
 MLGDeviceD3D11::SetPSTexture(uint32_t aSlot, MLGTexture* aTexture)
 {
   RefPtr<ID3D11ShaderResourceView> view;
   if (aTexture) {
     MLGTextureD3D11* texture = aTexture->AsD3D11();
--- a/gfx/layers/d3d11/MLGDeviceD3D11.h
+++ b/gfx/layers/d3d11/MLGDeviceD3D11.h
@@ -272,16 +272,20 @@ private:
   bool InitSamplerStates();
   bool InitBlendStates();
   bool InitDepthStencilState();
   bool VerifyConstantBufferOffsetting() override;
 
   void SetInputLayout(ID3D11InputLayout* aLayout);
   void SetVertexShader(ID3D11VertexShader* aShader);
 
+  // Resolve a TextureSource to an ID3D11ShaderResourceView, locking the
+  // texture if needed. The lock is released at the end of the frame.
+  ID3D11ShaderResourceView* ResolveTextureSourceForShader(TextureSource* aSource);
+
 private:
   RefPtr<ID3D11Device> mDevice;
   RefPtr<ID3D11DeviceContext> mCtx;
   RefPtr<ID3D11DeviceContext1> mCtx1;
   UniquePtr<DiagnosticsD3D11> mDiagnostics;
 
   typedef EnumeratedArray<PixelShaderID, PixelShaderID::MaxShaders, RefPtr<ID3D11PixelShader>> PixelShaderArray;
   typedef EnumeratedArray<VertexShaderID, VertexShaderID::MaxShaders, RefPtr<ID3D11VertexShader>> VertexShaderArray;