Bug 1497294 - P5. Clip source to destination size when copying the D3D11 texture. r=mattwoodrow
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 11 Oct 2018 01:43:29 +0000
changeset 499198 e62671b3410d0a27ab55852aff7aaca9c7deca5d
parent 499197 7a75881a86843c15f7f8977fa7b21388593a4628
child 499199 227a0a6ae1dfbadd73f96c64a307d001fb351108
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1497294
milestone64.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 1497294 - P5. Clip source to destination size when copying the D3D11 texture. r=mattwoodrow The Windows' hardware decoder always return an image whose dimensions are multiple of 16 pixels. As such, the image coming out of the decoder is typically bigger than the wanted image. The D3D11 documentation states that " If you try and copy outside the destination resource or specify a source box that is larger than the source resource, the behavior of CopySubresourceRegion is undefined." We've always copied from a bigger texture into a smaller one without specifying clipping. It seems to have always worked but falls into the undefined behaviour category. So to be extra safe, we clip the source so that it matches the dimension of the destination texture. Depends on D8129 Differential Revision: https://phabricator.services.mozilla.com/D8203
dom/media/platforms/wmf/DXVA2Manager.cpp
--- a/dom/media/platforms/wmf/DXVA2Manager.cpp
+++ b/dom/media/platforms/wmf/DXVA2Manager.cpp
@@ -965,20 +965,23 @@ D3D11DXVA2Manager::CopyToImage(IMFSample
     if (!mutex && mDevice != DeviceManagerDx::Get()->GetCompositorDevice()) {
       NS_ENSURE_TRUE(mSyncObject, E_FAIL);
     }
 
     if (outDesc.Format == inDesc.Format) {
       // Our video frame is stored in a non-sharable ID3D11Texture2D. We need
       // to create a copy of that frame as a sharable resource, save its share
       // handle, and put that handle into the rendering pipeline.
+      MOZ_DIAGNOSTIC_ASSERT(outDesc.Width <= inDesc.Width &&
+                            outDesc.Height <= inDesc.Height);
+      D3D11_BOX srcBox = { 0, 0, 0, outDesc.Width, outDesc.Height, 1 };
 
       UINT index;
       dxgiBuf->GetSubresourceIndex(&index);
-      mContext->CopySubresourceRegion(texture, 0, 0, 0, 0, tex, index, nullptr);
+      mContext->CopySubresourceRegion(texture, 0, 0, 0, 0, tex, index, &srcBox);
     } else {
       // Use MFT to do color conversion.
       hr = E_FAIL;
       mozilla::mscom::EnsureMTA(
         [&]() -> void { hr = mTransform->Input(aVideoSample); });
       NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
 
       RefPtr<IMFSample> sample;