Make sure we invalidate mapped memory from vk transfer buffers before reading.

When doing asyncRead we were not calling invalidatemappedMemory after calling
map on the transfer buffer. This is an issue if we happen to be using
non-coherent memory to back the buffer. Our normal read pixels call was manually
calling invalidate so that was working fine.

Bug: skia:9867
Change-Id: I765d12f75c914db0dba008433836463898a9712c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/268681
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/vk/GrVkGpu.cpp b/src/gpu/vk/GrVkGpu.cpp
index 5435e28..85b199b 100644
--- a/src/gpu/vk/GrVkGpu.cpp
+++ b/src/gpu/vk/GrVkGpu.cpp
@@ -2561,8 +2561,6 @@
         return false;
     }
     void* mappedMemory = transferBuffer->map();
-    const GrVkAlloc& transAlloc = transferBuffer->alloc();
-    GrVkMemory::InvalidateMappedAlloc(this, transAlloc, 0, transAlloc.fSize);
 
     if (copyFromOrigin) {
         uint32_t skipRows = region.imageExtent.height - height;
diff --git a/src/gpu/vk/GrVkTransferBuffer.h b/src/gpu/vk/GrVkTransferBuffer.h
index 210cf22..3523745 100644
--- a/src/gpu/vk/GrVkTransferBuffer.h
+++ b/src/gpu/vk/GrVkTransferBuffer.h
@@ -28,7 +28,14 @@
     void setMemoryBacking(SkTraceMemoryDump* traceMemoryDump,
                           const SkString& dumpName) const override;
 
-    void onMap() override { this->GrGpuBuffer::fMapPtr = this->vkMap(this->getVkGpu()); }
+    void onMap() override {
+        this->GrGpuBuffer::fMapPtr = this->vkMap(this->getVkGpu());
+        if (this->GrGpuBuffer::fMapPtr &&
+            this->intendedType() == GrGpuBufferType::kXferGpuToCpu) {
+            const GrVkAlloc& alloc = this->alloc();
+            GrVkMemory::InvalidateMappedAlloc(this->getVkGpu(), alloc, 0, alloc.fSize);
+        }
+    }
 
     void onUnmap() override { this->vkUnmap(this->getVkGpu()); }