D3D12: revert saving bufferLocation into TextureCopySubresource::CopyInfo

This effectively reverts
https://dawn-review.googlesource.com/c/dawn/+/208597

We want to use strong types for texels and blocks, and storing the D3D12
types in CopyInfo won't allow this.

Bug: chromium:424536624
Change-Id: I6197efbbf0ed8aa97882290593c50672e337a91a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/246734
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
diff --git a/src/dawn/native/d3d12/TextureCopySplitter.cpp b/src/dawn/native/d3d12/TextureCopySplitter.cpp
index 3f895ea..91c1853 100644
--- a/src/dawn/native/d3d12/TextureCopySplitter.cpp
+++ b/src/dawn/native/d3d12/TextureCopySplitter.cpp
@@ -77,18 +77,11 @@
     }
 }
 
-void FillFootprintAndOffsetOfBufferLocation(D3D12_TEXTURE_COPY_LOCATION* bufferLocation,
-                                            uint64_t alignedOffset,
-                                            Extent3D bufferSize,
-                                            uint32_t bytesPerRow) {
-    bufferLocation->Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
-    bufferLocation->pResource = nullptr;
-    bufferLocation->PlacedFootprint.Offset = alignedOffset;
-    bufferLocation->PlacedFootprint.Footprint.Width = bufferSize.width;
-    bufferLocation->PlacedFootprint.Footprint.Height = bufferSize.height;
-    bufferLocation->PlacedFootprint.Footprint.Depth = bufferSize.depthOrArrayLayers;
-    bufferLocation->PlacedFootprint.Footprint.RowPitch = bytesPerRow;
-    bufferLocation->PlacedFootprint.Footprint.Format = DXGI_FORMAT_UNKNOWN;
+void FillAlignedOffsetAndBufferSize(TextureCopySubresource::CopyInfo* copyInfo,
+                                    uint64_t alignedOffset,
+                                    Extent3D bufferSize) {
+    copyInfo->alignedOffset = alignedOffset;
+    copyInfo->bufferSize = bufferSize;
 }
 
 }  // namespace
@@ -122,28 +115,6 @@
     }
 }
 
-uint64_t TextureCopySubresource::CopyInfo::GetAlignedOffset() const {
-    return bufferLocation.PlacedFootprint.Offset;
-}
-
-Extent3D TextureCopySubresource::CopyInfo::GetBufferSize() const {
-    return {bufferLocation.PlacedFootprint.Footprint.Width,
-            bufferLocation.PlacedFootprint.Footprint.Height,
-            bufferLocation.PlacedFootprint.Footprint.Depth};
-}
-
-void TextureCopySubresource::CopyInfo::SetAlignedOffset(uint64_t alignedOffset) {
-    bufferLocation.PlacedFootprint.Offset = alignedOffset;
-}
-
-void TextureCopySubresource::CopyInfo::SetHeightInBufferLocation(uint32_t bufferHeight) {
-    bufferLocation.PlacedFootprint.Footprint.Height = bufferHeight;
-}
-
-void TextureCopySubresource::CopyInfo::SetDepthInBufferLocation(uint32_t bufferDepth) {
-    bufferLocation.PlacedFootprint.Footprint.Depth = bufferDepth;
-}
-
 TextureCopySubresource::CopyInfo* TextureCopySubresource::AddCopy() {
     DAWN_ASSERT(this->count < kMaxTextureCopyRegions);
     return &this->copies[this->count++];
@@ -158,8 +129,7 @@
                                         uint64_t alignedOffset,
                                         uint32_t bytesPerRow) {
     ComputeSourceRegionForCopyInfo(copyInfo, direction, bufferOffset, textureOffset, copySize);
-    FillFootprintAndOffsetOfBufferLocation(&copyInfo->bufferLocation, alignedOffset, bufferSize,
-                                           bytesPerRow);
+    FillAlignedOffsetAndBufferSize(copyInfo, alignedOffset, bufferSize);
 }
 
 TextureCopySubresource Compute2DTextureCopySubresource(BufferTextureCopyDirection direction,
@@ -375,11 +345,11 @@
     if (bytesPerLayer % D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT == 0) {
         copies.copySubresources[1] = copies.copySubresources[0];
         uint64_t alignedOffset0 =
-            copies.copySubresources[1].copies[0].GetAlignedOffset() + bytesPerLayer;
+            copies.copySubresources[1].copies[0].alignedOffset + bytesPerLayer;
         uint64_t alignedOffset1 =
-            copies.copySubresources[1].copies[1].GetAlignedOffset() + bytesPerLayer;
-        copies.copySubresources[1].copies[0].SetAlignedOffset(alignedOffset0);
-        copies.copySubresources[1].copies[1].SetAlignedOffset(alignedOffset1);
+            copies.copySubresources[1].copies[1].alignedOffset + bytesPerLayer;
+        copies.copySubresources[1].copies[0].alignedOffset = alignedOffset0;
+        copies.copySubresources[1].copies[1].alignedOffset = alignedOffset1;
     } else {
         const uint64_t bufferOffsetNextLayer = offset + bytesPerLayer;
         copies.copySubresources[1] =
@@ -494,7 +464,7 @@
     Extent3D copySize0 = copy0.GetCopySize();
     copySize0.height = copySize.height - blockInfo.height;
     uint32_t bufferHeight0 = rowsPerImage * blockInfo.height;  // rowsPerImageInTexels
-    copy0.SetHeightInBufferLocation(bufferHeight0);
+    copy0.bufferSize.height = bufferHeight0;
     const Origin3D bufferOffset0 = copy0.GetBufferOffset(direction);
     const Origin3D textureOffset0 = copy0.GetTextureOffset(direction);
     ComputeSourceRegionForCopyInfo(&copy0, direction, bufferOffset0, textureOffset0, copySize0);
@@ -503,8 +473,8 @@
     // but the last one.
     TextureCopySubresource::CopyInfo* copy1 = copy.AddCopy();
     *copy1 = copy0;
-    uint64_t alignedOffset1 = copy1->GetAlignedOffset() + 2 * bytesPerRow;
-    copy1->SetAlignedOffset(alignedOffset1);
+    uint64_t alignedOffset1 = copy1->alignedOffset + 2 * bytesPerRow;
+    copy1->alignedOffset = alignedOffset1;
     Origin3D textureOffset1 = textureOffset0;
     Origin3D bufferOffset1 = bufferOffset0;
     textureOffset1.y += copySize.height - blockInfo.height;
@@ -515,14 +485,14 @@
     Extent3D copySize1 = copySize0;
     copySize1.height = blockInfo.height;
     copySize1.depthOrArrayLayers--;
-    uint32_t bufferDepth1 = copy1->GetBufferSize().depthOrArrayLayers;
+    uint32_t bufferDepth1 = copy1->bufferSize.depthOrArrayLayers;
     bufferDepth1--;
-    copy1->SetDepthInBufferLocation(bufferDepth1);
+    copy1->bufferSize.depthOrArrayLayers = bufferDepth1;
     ComputeSourceRegionForCopyInfo(copy1, direction, bufferOffset1, textureOffset1, copySize1);
 
     // Copy 2: copy the last row of the last image.
     uint64_t offsetForCopy0 =
-        OffsetToFirstCopiedTexel(blockInfo, bytesPerRow, copy0.GetAlignedOffset(), bufferOffset0);
+        OffsetToFirstCopiedTexel(blockInfo, bytesPerRow, copy0.alignedOffset, bufferOffset0);
     uint64_t offsetForLastRowOfLastImage =
         offsetForCopy0 + bytesPerRow * (copySize0.height / blockInfo.height +
                                         rowsPerImage * (copySize.depthOrArrayLayers - 1));
@@ -543,9 +513,8 @@
     bufferOffset2 = texelOffsetForLastRowOfLastImage;
     DAWN_ASSERT(copySize2.height == blockInfo.height);
     ComputeSourceRegionForCopyInfo(copy2, direction, bufferOffset2, textureOffset2, copySize2);
-    Extent3D bufferSize2 = {copy1->GetBufferSize().width, bufferOffset2.y + copySize2.height, 1};
-    FillFootprintAndOffsetOfBufferLocation(&copy2->bufferLocation, alignedOffset2, bufferSize2,
-                                           bytesPerRow);
+    Extent3D bufferSize2 = {copy1->bufferSize.width, bufferOffset2.y + copySize2.height, 1};
+    FillAlignedOffsetAndBufferSize(copy2, alignedOffset2, bufferSize2);
 }
 
 void Recompute3DTextureCopyRegionWithEmptyFirstRowAndOddCopyHeight(
@@ -570,7 +539,7 @@
     Extent3D copySize0 = copy0.GetCopySize();
     copySize0.depthOrArrayLayers = 1;
     const uint32_t kBufferDepth0 = 1u;
-    copy0.SetDepthInBufferLocation(kBufferDepth0);
+    copy0.bufferSize.depthOrArrayLayers = kBufferDepth0;
     const Origin3D bufferOffset0 = copy0.GetBufferOffset(direction);
     const Origin3D textureOffset0 = copy0.GetTextureOffset(direction);
     ComputeSourceRegionForCopyInfo(&copy0, direction, bufferOffset0, textureOffset0, copySize0);
@@ -580,9 +549,9 @@
     *copy1 = copy0;
     DAWN_ASSERT((copySize.height / blockInfo.height) % 2 == 1);
     uint64_t alignedOffset1 =
-        copy0.GetAlignedOffset() + (copySize.height / blockInfo.height + 1) * bytesPerRow;
+        copy0.alignedOffset + (copySize.height / blockInfo.height + 1) * bytesPerRow;
     DAWN_ASSERT(alignedOffset1 % D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT == 0);
-    copy1->SetAlignedOffset(alignedOffset1);
+    copy1->alignedOffset = alignedOffset1;
     // textureOffset1.z should add one because the first slice has already been copied in copy0.
     Origin3D textureOffset1 = textureOffset0;
     textureOffset1.z++;
@@ -593,8 +562,8 @@
     Extent3D copySize1 = copySize0;
     copySize1.height = copySize.height;
     copySize1.depthOrArrayLayers = copySize.depthOrArrayLayers - 1;
-    copy1->SetHeightInBufferLocation(copySize.height);
-    copy1->SetDepthInBufferLocation(copySize.depthOrArrayLayers - 1);
+    copy1->bufferSize.height = copySize.height;
+    copy1->bufferSize.depthOrArrayLayers = copySize.depthOrArrayLayers - 1;
     ComputeSourceRegionForCopyInfo(copy1, direction, bufferOffset1, textureOffset1, copySize1);
 }
 
@@ -636,7 +605,7 @@
     uint32_t originalCopyCount = copySubresource.count;
     for (uint32_t i = 0; i < originalCopyCount; ++i) {
         // There can be one empty row at most in a copy region.
-        uint32_t bufferHeight = copySubresource.copies[i].GetBufferSize().height;
+        uint32_t bufferHeight = copySubresource.copies[i].bufferSize.height;
         DAWN_ASSERT(bufferHeight <= rowsPerImageInTexels + blockInfo.height);
 
         if (bufferHeight == rowsPerImageInTexels) {
@@ -648,7 +617,7 @@
         if (bufferHeight < rowsPerImageInTexels) {
             // If we are copying multiple depth slices, we should skip rowsPerImageInTexels rows for
             // each slice even though we only copy partial rows in each slice sometimes.
-            copySubresource.copies[i].SetHeightInBufferLocation(rowsPerImageInTexels);
+            copySubresource.copies[i].bufferSize.height = rowsPerImageInTexels;
         } else {
             // bufferHeight > rowsPerImageInTexels. There is an empty row in this copy region due to
             // alignment adjustment.
@@ -715,8 +684,7 @@
 
     Extent3D bufferSize = {copySize.width, copySize.height, 1};
 
-    FillFootprintAndOffsetOfBufferLocation(&copyInfo->bufferLocation, offset, bufferSize,
-                                           bytesPerRow);
+    FillAlignedOffsetAndBufferSize(copyInfo, offset, bufferSize);
 
     return copy;
 }
@@ -770,8 +738,7 @@
 
         Extent3D bufferSize1 = {copySize.width, rowsPerImage1, depthInCopy1};
 
-        FillFootprintAndOffsetOfBufferLocation(&copyInfo1->bufferLocation, offset1, bufferSize1,
-                                               bytesPerRow);
+        FillAlignedOffsetAndBufferSize(copyInfo1, offset1, bufferSize1);
     }
 
     {
@@ -806,8 +773,7 @@
 
         Extent3D bufferSize2 = {copySize.width, rowsPerImage2, depthInCopy2};
 
-        FillFootprintAndOffsetOfBufferLocation(&copyInfo2->bufferLocation, offset2, bufferSize2,
-                                               bytesPerRow);
+        FillAlignedOffsetAndBufferSize(copyInfo2, offset2, bufferSize2);
     }
 
     return copy;
diff --git a/src/dawn/native/d3d12/TextureCopySplitter.h b/src/dawn/native/d3d12/TextureCopySplitter.h
index 605bc40..8cf6138 100644
--- a/src/dawn/native/d3d12/TextureCopySplitter.h
+++ b/src/dawn/native/d3d12/TextureCopySplitter.h
@@ -45,10 +45,13 @@
     static constexpr unsigned int kMaxTextureCopyRegions = 4;
 
     struct CopyInfo {
+        // The 512-byte aligned offset into buffer
+        uint64_t alignedOffset = 0;
         Origin3D destinationOffset;
+        // width,height,depth of buffer
+        Extent3D bufferSize;
 
         D3D12_BOX sourceRegion;
-        D3D12_TEXTURE_COPY_LOCATION bufferLocation;
 
         // Returns x,y,z offset in buffer (from sourceRegion if B2T, or destinationOffset if T2B)
         Origin3D GetBufferOffset(BufferTextureCopyDirection direction) const;
@@ -56,14 +59,6 @@
         Origin3D GetTextureOffset(BufferTextureCopyDirection direction) const;
         // Returns width,height,depth of source region
         Extent3D GetCopySize() const;
-        // Returns 512-byte aligned offset into buffer
-        uint64_t GetAlignedOffset() const;
-        // Returns width,height,depth of buffer footprint
-        Extent3D GetBufferSize() const;
-
-        void SetAlignedOffset(uint64_t alignedOffset);
-        void SetHeightInBufferLocation(uint32_t bufferHeight);
-        void SetDepthInBufferLocation(uint32_t bufferDepth);
     };
 
     CopyInfo* AddCopy();
diff --git a/src/dawn/native/d3d12/UtilsD3D12.cpp b/src/dawn/native/d3d12/UtilsD3D12.cpp
index 0b86d61..3fe7630 100644
--- a/src/dawn/native/d3d12/UtilsD3D12.cpp
+++ b/src/dawn/native/d3d12/UtilsD3D12.cpp
@@ -102,6 +102,26 @@
     return (bufferCopy.buffer->GetAllocatedSize() - bufferCopy.offset) < requiredCopySizeByD3D12;
 }
 
+D3D12_TEXTURE_COPY_LOCATION ComputeBufferLocationForCopyTextureRegion(
+    const Texture* texture,
+    ID3D12Resource* bufferResource,
+    const Extent3D& bufferSize,
+    const uint64_t offset,
+    const uint32_t rowPitch,
+    Aspect aspect) {
+    D3D12_TEXTURE_COPY_LOCATION bufferLocation;
+    bufferLocation.pResource = bufferResource;
+    bufferLocation.Type = D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT;
+    bufferLocation.PlacedFootprint.Offset = offset;
+    bufferLocation.PlacedFootprint.Footprint.Format =
+        texture->GetD3D12CopyableSubresourceFormat(aspect);
+    bufferLocation.PlacedFootprint.Footprint.Width = bufferSize.width;
+    bufferLocation.PlacedFootprint.Footprint.Height = bufferSize.height;
+    bufferLocation.PlacedFootprint.Footprint.Depth = bufferSize.depthOrArrayLayers;
+    bufferLocation.PlacedFootprint.Footprint.RowPitch = rowPitch;
+    return bufferLocation;
+}
+
 }  // anonymous namespace
 
 D3D12_COMPARISON_FUNC ToD3D12ComparisonFunc(wgpu::CompareFunction func) {
@@ -180,14 +200,14 @@
     const D3D12_TEXTURE_COPY_LOCATION textureLocation =
         ComputeTextureCopyLocationForTexture(texture, textureMiplevel, textureLayer, aspect);
 
-    DXGI_FORMAT dxgiFormat = texture->GetD3D12CopyableSubresourceFormat(aspect);
     for (uint32_t i = 0; i < baseCopySplit.count; ++i) {
         const TextureCopySubresource::CopyInfo& info = baseCopySplit.copies[i];
 
-        D3D12_TEXTURE_COPY_LOCATION bufferLocation = info.bufferLocation;
-        bufferLocation.pResource = bufferResource;
-        bufferLocation.PlacedFootprint.Offset += baseOffset;
-        bufferLocation.PlacedFootprint.Footprint.Format = dxgiFormat;
+        const uint64_t offsetBytes = info.alignedOffset + baseOffset;
+        const D3D12_TEXTURE_COPY_LOCATION bufferLocation =
+            ComputeBufferLocationForCopyTextureRegion(texture, bufferResource, info.bufferSize,
+                                                      offsetBytes, bufferBytesPerRow, aspect);
+
         if (direction == BufferTextureCopyDirection::B2T) {
             commandList->CopyTextureRegion(&textureLocation, info.destinationOffset.x,
                                            info.destinationOffset.y, info.destinationOffset.z,
diff --git a/src/dawn/tests/unittests/d3d12/CopySplitTests.cpp b/src/dawn/tests/unittests/d3d12/CopySplitTests.cpp
index 637f658..ef71361 100644
--- a/src/dawn/tests/unittests/d3d12/CopySplitTests.cpp
+++ b/src/dawn/tests/unittests/d3d12/CopySplitTests.cpp
@@ -59,12 +59,6 @@
     uint32_t rowsPerImage;  // rows per image slice (user-defined)
 };
 
-Extent3D GetBufferSize(D3D12_TEXTURE_COPY_LOCATION bufferLocation) {
-    return {bufferLocation.PlacedFootprint.Footprint.Width,
-            bufferLocation.PlacedFootprint.Footprint.Height,
-            bufferLocation.PlacedFootprint.Footprint.Depth};
-}
-
 // Check that each copy region fits inside the buffer footprint
 void ValidateFootprints(const TextureSpec& textureSpec,
                         const BufferSpec& bufferSpec,
@@ -75,7 +69,7 @@
         const auto& copy = copySplit.copies[i];
         Extent3D copySize = copy.GetCopySize();
         Origin3D bufferOffset = copy.GetBufferOffset(direction);
-        Extent3D bufferSize = GetBufferSize(copy.bufferLocation);
+        Extent3D bufferSize = copy.bufferSize;
         ASSERT_LE(bufferOffset.x + copySize.width, bufferSize.width);
         ASSERT_LE(bufferOffset.y + copySize.height, bufferSize.height);
         ASSERT_LE(bufferOffset.z + copySize.depthOrArrayLayers, bufferSize.depthOrArrayLayers);
@@ -112,7 +106,7 @@
             uint32_t footprintHeightInBlocks = footprintHeight / textureSpec.blockHeight;
 
             uint64_t bufferSizeForFootprint =
-                copy.GetAlignedOffset() +
+                copy.alignedOffset +
                 utils::RequiredBytesInCopy(
                     bufferSpec.bytesPerRow, bufferSize.height / textureSpec.blockHeight,
                     footprintWidthInBlocks, footprintHeightInBlocks, bufferSize.depthOrArrayLayers,
@@ -129,8 +123,8 @@
 void ValidateOffset(const TextureCopySubresource& copySplit) {
     for (uint32_t i = 0; i < copySplit.count; ++i) {
         ASSERT_TRUE(
-            Align(copySplit.copies[i].GetAlignedOffset(), D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT) ==
-            copySplit.copies[i].GetAlignedOffset());
+            Align(copySplit.copies[i].alignedOffset, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT) ==
+            copySplit.copies[i].alignedOffset);
     }
 }
 
@@ -232,7 +226,7 @@
         uint32_t rowPitchInBlocks = bufferSpec.bytesPerRow / textureSpec.texelBlockSizeInBytes;
         uint32_t slicePitchInBlocks = rowPitchInBlocks * bufferSpec.rowsPerImage;
         uint32_t absoluteOffsetInBlocks =
-            copy.GetAlignedOffset() / textureSpec.texelBlockSizeInBytes +
+            copy.alignedOffset / textureSpec.texelBlockSizeInBytes +
             bufferOffset.x / textureSpec.blockWidth +
             bufferOffset.y / textureSpec.blockHeight * rowPitchInBlocks;
 
@@ -292,7 +286,7 @@
     os << "CopySplit\n";
     for (uint32_t i = 0; i < copySplit.count; ++i) {
         const auto& copy = copySplit.copies[i];
-        Extent3D bufferSize = GetBufferSize(copy.bufferLocation);
+        Extent3D bufferSize = copy.bufferSize;
         os << "  " << i << ": destinationOffset at (" << copy.destinationOffset.x << ", "
            << copy.destinationOffset.y << ", " << copy.destinationOffset.z << "), sourceRegion ("
            << copy.sourceRegion.left << ", " << copy.sourceRegion.top << ", "