[TextureD3D12] Add ASSERT verifying safety of concurrent read access

For concurrent read access to be safe on D3D12, textures must be
implicitly decayable to the COMMON state at all times that a read access
is occurring on the Texture. Otherwise, there is a risk that the Texture
is modified by one read access as part of modifying its compression
while another read access is reading the data being modified.

Change-Id: I4af4057612e26e866a86c7152e5d946feb77c0da
Bug: dawn:2359
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/171800
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Colin Blundell <blundell@chromium.org>
diff --git a/src/dawn/native/d3d12/TextureD3D12.cpp b/src/dawn/native/d3d12/TextureD3D12.cpp
index 6e9c693..921c0fa 100644
--- a/src/dawn/native/d3d12/TextureD3D12.cpp
+++ b/src/dawn/native/d3d12/TextureD3D12.cpp
@@ -571,6 +571,18 @@
         }
     }
 
+    if (mSharedTextureMemoryContents) {
+        // SharedTextureMemory supports concurrent reads of the underlying D3D12
+        // texture via multiple TextureD3D12 instances created from a single
+        // SharedTextureMemory instance. Concurrent read access requires that the
+        // texture is compatible with (i.e., implicitly decayable to) the COMMON
+        // state at all times that read accesses are happening; otherwise, the
+        // texture can enter a state where it could be modified by one read access
+        // (e.g., to be compressed or decrompessed) while being read by another.
+        bool inReadAccess = HasAccess() && IsReadOnly();
+        DAWN_ASSERT(state->isValidToDecay || !inReadAccess);
+    }
+
     D3D12_RESOURCE_BARRIER barrier;
     barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
     barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;