Enable CopyTests_T2T/CopyWithinSameTexture* tests on D3D12

This patch enables the tests CopyTests_T2T/CopyWithinSameTexture* on
D3D12 after the D3D12 texture subresource tracking has been supported.

This patch also changes the related comment in Vulkan as WebGPU CG has
already decided to disallow the overlaps among source and destination
subresources in texture-to-texture copies.

BUG=dawn:453
TEST=dawn_end2end_tests

Change-Id: Ibf008c800cfea62658050f565f321a391412c54c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/23000
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn_native/d3d12/CommandBufferD3D12.cpp b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
index 86254d7..9c57c29 100644
--- a/src/dawn_native/d3d12/CommandBufferD3D12.cpp
+++ b/src/dawn_native/d3d12/CommandBufferD3D12.cpp
@@ -17,6 +17,7 @@
 #include "common/Assert.h"
 #include "dawn_native/BindGroupAndStorageBarrierTracker.h"
 #include "dawn_native/CommandEncoder.h"
+#include "dawn_native/CommandValidation.h"
 #include "dawn_native/Commands.h"
 #include "dawn_native/RenderBundle.h"
 #include "dawn_native/d3d12/BindGroupD3D12.h"
@@ -689,6 +690,17 @@
                             commandContext, copy->destination.mipLevel, 1,
                             copy->destination.arrayLayer, copy->copySize.depth);
                     }
+
+                    if (copy->source.texture.Get() == copy->destination.texture.Get() &&
+                        copy->source.mipLevel == copy->destination.mipLevel) {
+                        // When there are overlapped subresources, the layout of the overlapped
+                        // subresources should all be COMMON instead of what we set now. Currently
+                        // it is not allowed to copy with overlapped subresources, but we still
+                        // add the ASSERT here as a reminder for this possible misuse.
+                        ASSERT(!IsRangeOverlapped(copy->source.arrayLayer,
+                                                  copy->destination.arrayLayer,
+                                                  copy->copySize.depth));
+                    }
                     source->TrackUsageAndTransitionNow(
                         commandContext, wgpu::TextureUsage::CopySrc, copy->source.mipLevel, 1,
                         copy->source.arrayLayer, copy->copySize.depth);
diff --git a/src/dawn_native/vulkan/CommandBufferVk.cpp b/src/dawn_native/vulkan/CommandBufferVk.cpp
index 54c0686..b306660 100644
--- a/src/dawn_native/vulkan/CommandBufferVk.cpp
+++ b/src/dawn_native/vulkan/CommandBufferVk.cpp
@@ -528,7 +528,7 @@
                         // When there are overlapped subresources, the layout of the overlapped
                         // subresources should all be GENERAL instead of what we set now. Currently
                         // it is not allowed to copy with overlapped subresources, but we still
-                        // add the ASSERT here as a reminder for possible changes in the future.
+                        // add the ASSERT here as a reminder for this possible misuse.
                         ASSERT(!IsRangeOverlapped(src.arrayLayer, dst.arrayLayer,
                                                   copy->copySize.depth));
                     }
diff --git a/src/tests/end2end/CopyTests.cpp b/src/tests/end2end/CopyTests.cpp
index d450fab..0f92076 100644
--- a/src/tests/end2end/CopyTests.cpp
+++ b/src/tests/end2end/CopyTests.cpp
@@ -769,10 +769,6 @@
 
 // Test copying one texture slice within the same texture.
 TEST_P(CopyTests_T2T, CopyWithinSameTextureOneSlice) {
-    // TODO(jiawei.shao@intel.com): support texture-to-texture copy within same texture on D3D12
-    // after D3D12 subresource tracking is implemented.
-    DAWN_SKIP_TEST_IF(IsD3D12());
-
     constexpr uint32_t kWidth = 256u;
     constexpr uint32_t kHeight = 128u;
     constexpr uint32_t kLayers = 6u;
@@ -788,9 +784,7 @@
 // slices.
 TEST_P(CopyTests_T2T, CopyWithinSameTextureNonOverlappedSlices) {
     // TODO(jiawei.shao@intel.com): investigate why this test fails with swiftshader.
-    // TODO(jiawei.shao@intel.com): support texture-to-texture copy within same texture on D3D12
-    // after D3D12 subresource tracking is implemented.
-    DAWN_SKIP_TEST_IF(IsSwiftshader() || IsD3D12());
+    DAWN_SKIP_TEST_IF(IsSwiftshader());
 
     constexpr uint32_t kWidth = 256u;
     constexpr uint32_t kHeight = 128u;