Direct3D: fix up tests

* Enable MipmappedTest
* Add didWriteToSurface calls to fix up MipmapInvalidation test
* Add flush & submit to fix DDLSkSurfaceFlush test

Change-Id: I9c3cad96b40491a54cab4edb8f56639d6cc16665
Bug: skia:10446
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/405496
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/d3d/GrD3DGpu.cpp b/src/gpu/d3d/GrD3DGpu.cpp
index 1e59bb8..e947a41 100644
--- a/src/gpu/d3d/GrD3DGpu.cpp
+++ b/src/gpu/d3d/GrD3DGpu.cpp
@@ -220,10 +220,15 @@
 void GrD3DGpu::submit(GrOpsRenderPass* renderPass) {
     SkASSERT(fCachedOpsRenderPass.get() == renderPass);
 
-    // TODO: actually submit something here
+    fCachedOpsRenderPass->submit();
     fCachedOpsRenderPass.reset();
 }
 
+void GrD3DGpu::endRenderPass(GrRenderTarget* target, GrSurfaceOrigin origin,
+                             const SkIRect& bounds) {
+    this->didWriteToSurface(target, origin, &bounds);
+}
+
 void GrD3DGpu::addFinishedProc(GrGpuFinishedProc finishedProc,
                                GrGpuFinishedContext finishedContext) {
     SkASSERT(finishedProc);
@@ -514,6 +519,10 @@
     SkASSERT(srcRT);
 
     this->resolveTexture(dst, dstPoint.fX, dstPoint.fY, srcRT, srcRect);
+    SkIRect dstRect = SkIRect::MakeXYWH(dstPoint.fX, dstPoint.fY,
+                                        srcRect.width(), srcRect.height());
+    // The rect is already in device space so we pass in kTopLeft so no flip is done.
+    this->didWriteToSurface(dst, kTopLeft_GrSurfaceOrigin, &dstRect);
 }
 
 void GrD3DGpu::resolveTexture(GrSurface* dst, int32_t dstX, int32_t dstY,
diff --git a/src/gpu/d3d/GrD3DGpu.h b/src/gpu/d3d/GrD3DGpu.h
index 6bcc400..9a9ece2 100644
--- a/src/gpu/d3d/GrD3DGpu.h
+++ b/src/gpu/d3d/GrD3DGpu.h
@@ -114,6 +114,8 @@
     }
 
     void submit(GrOpsRenderPass* renderPass) override;
+    void endRenderPass(GrRenderTarget* target, GrSurfaceOrigin origin,
+                       const SkIRect& bounds);
 
     void checkFinishProcs() override { this->checkForFinishedCommandLists(); }
     void finishOutstandingGpuWork() override;
diff --git a/src/gpu/d3d/GrD3DOpsRenderPass.cpp b/src/gpu/d3d/GrD3DOpsRenderPass.cpp
index 18e81e4..c4fc84b 100644
--- a/src/gpu/d3d/GrD3DOpsRenderPass.cpp
+++ b/src/gpu/d3d/GrD3DOpsRenderPass.cpp
@@ -347,5 +347,22 @@
     // If we ever start using copy command lists for doing uploads, then we'll need to make sure
     // we submit our main command list before doing the copy here and then start a new main command
     // list.
-    state->doUpload(upload);
+
+    fGpu->endRenderPass(fRenderTarget, fOrigin, fBounds);
+
+    // We pass in true here to signal that after the upload we need to set the upload texture's
+    // resource state back to D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE.
+    state->doUpload(upload, true);
+}
+
+void GrD3DOpsRenderPass::submit() {
+    if (!fRenderTarget) {
+        return;
+    }
+
+    // We don't use render passes in d3d, so there is nothing to submit here as all commands have
+    // already been recorded on the main command list. If in the future we start to use render
+    // passes on d3d12 devices that support them (most likely ARM devices), then we
+    // will submit them here.
+    fGpu->endRenderPass(fRenderTarget, fOrigin, fBounds);
 }
diff --git a/src/gpu/d3d/GrD3DOpsRenderPass.h b/src/gpu/d3d/GrD3DOpsRenderPass.h
index e301b4d..02266b8 100644
--- a/src/gpu/d3d/GrD3DOpsRenderPass.h
+++ b/src/gpu/d3d/GrD3DOpsRenderPass.h
@@ -31,6 +31,8 @@
         const GrOpsRenderPass::StencilLoadAndStoreInfo&,
         const SkTArray<GrSurfaceProxy*, true>& sampledProxies);
 
+    void submit();
+
 private:
     GrGpu* gpu() override;
 
diff --git a/tests/DeferredDisplayListTest.cpp b/tests/DeferredDisplayListTest.cpp
index 5b8f802..0604d26 100644
--- a/tests/DeferredDisplayListTest.cpp
+++ b/tests/DeferredDisplayListTest.cpp
@@ -1101,13 +1101,9 @@
 
     REPORTER_ASSERT(reporter, fulfillInfo.fFulfilled);
 
-    if (GrBackendApi::kVulkan == context->backend() ||
-        GrBackendApi::kMetal  == context->backend()) {
-        // In order to receive the done callback with Vulkan we need to perform the equivalent
-        // of a glFinish
-        s->flush();
-        context->submit(true);
-    }
+    // In order to receive the done callback with the low-level APIs we need to re-flush
+    s->flush();
+    context->submit(true);
 
     REPORTER_ASSERT(reporter, fulfillInfo.fReleased);
 
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
index b16e6a8..1ec5eeb 100644
--- a/tests/GrMipMappedTest.cpp
+++ b/tests/GrMipMappedTest.cpp
@@ -12,6 +12,9 @@
 #include "include/core/SkSurface.h"
 #include "include/gpu/GrBackendSurface.h"
 #include "include/gpu/GrDirectContext.h"
+#ifdef SK_DIRECT3D
+#include "include/gpu/d3d/GrD3DTypes.h"
+#endif
 #include "src/gpu/GrBackendTextureImageGenerator.h"
 #include "src/gpu/GrDirectContextPriv.h"
 #include "src/gpu/GrDrawingManager.h"
@@ -232,6 +235,24 @@
                     ERRORF(reporter, "Failed to get GrMtlTextureInfo");
                 }
 #endif
+#ifdef SK_DIRECT3D
+            } else if (GrBackendApi::kDirect3D == genBackendTex.backend()) {
+                GrD3DTextureResourceInfo genImageInfo;
+                GrD3DTextureResourceInfo origImageInfo;
+                if (genBackendTex.getD3DTextureResourceInfo(&genImageInfo) &&
+                    backendTex.getD3DTextureResourceInfo(&origImageInfo)) {
+                    if (requestMipmapped == GrMipmapped::kYes && betMipmapped == GrMipmapped::kNo) {
+                        // We did a copy so the texture resources should be different
+                        REPORTER_ASSERT(reporter,
+                                        origImageInfo.fResource != genImageInfo.fResource);
+                    } else {
+                        REPORTER_ASSERT(reporter,
+                                        origImageInfo.fResource == genImageInfo.fResource);
+                    }
+                } else {
+                    ERRORF(reporter, "Failed to get GrMtlTextureInfo");
+                }
+#endif
 #ifdef SK_DAWN
             } else if (GrBackendApi::kDawn == genBackendTex.backend()) {
                 GrDawnTextureInfo genImageInfo;