Rename some data structures in TextureCopySplitter

The change renames Texture2DCopySplit and copies2D to
TextureCopySubresource and copySubresources respectively.
Because they are not used for 2D only.

I didn't change Texture2DCopySplit to TextureCopySplit in order
to reflect its meaning and distinguish it from TextureCopySplits.
TextureCopySubresource is a collection of copy regions for either a
single layer of a 1D/2D texture or all depth slices on the same
mip level of a 3D texture (They are exactly what subresources are).

It also renames function ComputeTextureCopySplit to
ComputeTextureCopySubresource, and a couple similar renaming.

Bug: dawn:547
Change-Id: I17f8b349e209af0ed1ccaee4634be1e8235a63b3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/50920
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Yunchao He
2021-05-17 10:35:57 +00:00
committed by Commit Bot service account
parent 75de553398
commit e8c271dab7
6 changed files with 78 additions and 73 deletions

View File

@@ -33,13 +33,13 @@ namespace dawn_native { namespace d3d12 {
}
} // namespace
Texture2DCopySplit ComputeTextureCopySplit(Origin3D origin,
Extent3D copySize,
const TexelBlockInfo& blockInfo,
uint64_t offset,
uint32_t bytesPerRow,
uint32_t rowsPerImage) {
Texture2DCopySplit copy;
TextureCopySubresource ComputeTextureCopySubresource(Origin3D origin,
Extent3D copySize,
const TexelBlockInfo& blockInfo,
uint64_t offset,
uint32_t bytesPerRow,
uint32_t rowsPerImage) {
TextureCopySubresource copy;
ASSERT(bytesPerRow % blockInfo.byteSize == 0);
@@ -215,7 +215,7 @@ namespace dawn_native { namespace d3d12 {
const uint64_t bytesPerSlice = bytesPerRow * rowsPerImage;
// The function ComputeTextureCopySplit() decides how to split the copy based on:
// The function ComputeTextureCopySubresource() decides how to split the copy based on:
// - the alignment of the buffer offset with D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT (512)
// - the alignment of the buffer offset with D3D12_TEXTURE_DATA_PITCH_ALIGNMENT (256)
// Each slice of a 2D array or 3D copy might need to be split, but because of the WebGPU
@@ -233,23 +233,23 @@ namespace dawn_native { namespace d3d12 {
copyFirstLayerOrigin.z = 0;
}
copies.copies2D[0] = ComputeTextureCopySplit(copyFirstLayerOrigin, copyOneLayerSize,
blockInfo, offset, bytesPerRow, rowsPerImage);
copies.copySubresources[0] = ComputeTextureCopySubresource(
copyFirstLayerOrigin, copyOneLayerSize, blockInfo, offset, bytesPerRow, rowsPerImage);
// When the copy only refers one texture 2D array layer or a 3D texture, copies.copies2D[1]
// will never be used so we can safely early return here.
// When the copy only refers one texture 2D array layer or a 3D texture,
// copies.copySubresources[1] will never be used so we can safely early return here.
if (copySize.depthOrArrayLayers == 1 || is3DTexture) {
return copies;
}
if (bytesPerSlice % D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT == 0) {
copies.copies2D[1] = copies.copies2D[0];
copies.copies2D[1].offset += bytesPerSlice;
copies.copySubresources[1] = copies.copySubresources[0];
copies.copySubresources[1].offset += bytesPerSlice;
} else {
const uint64_t bufferOffsetNextLayer = offset + bytesPerSlice;
copies.copies2D[1] =
ComputeTextureCopySplit(copyFirstLayerOrigin, copyOneLayerSize, blockInfo,
bufferOffsetNextLayer, bytesPerRow, rowsPerImage);
copies.copySubresources[1] =
ComputeTextureCopySubresource(copyFirstLayerOrigin, copyOneLayerSize, blockInfo,
bufferOffsetNextLayer, bytesPerRow, rowsPerImage);
}
return copies;

View File

@@ -27,7 +27,7 @@ namespace dawn_native {
namespace dawn_native { namespace d3d12 {
struct Texture2DCopySplit {
struct TextureCopySubresource {
static constexpr unsigned int kMaxTextureCopyRegions = 2;
struct CopyInfo {
@@ -44,17 +44,17 @@ namespace dawn_native { namespace d3d12 {
};
struct TextureCopySplits {
static constexpr uint32_t kMaxTextureCopySplits = 2;
static constexpr uint32_t kMaxTextureCopySubresources = 2;
std::array<Texture2DCopySplit, kMaxTextureCopySplits> copies2D;
std::array<TextureCopySubresource, kMaxTextureCopySubresources> copySubresources;
};
Texture2DCopySplit ComputeTextureCopySplit(Origin3D origin,
Extent3D copySize,
const TexelBlockInfo& blockInfo,
uint64_t offset,
uint32_t bytesPerRow,
uint32_t rowsPerImage);
TextureCopySubresource ComputeTextureCopySubresource(Origin3D origin,
Extent3D copySize,
const TexelBlockInfo& blockInfo,
uint64_t offset,
uint32_t bytesPerRow,
uint32_t rowsPerImage);
TextureCopySplits ComputeTextureCopySplits(Origin3D origin,
Extent3D copySize,

View File

@@ -967,7 +967,7 @@ namespace dawn_native { namespace d3d12 {
Extent3D copySize = GetMipLevelPhysicalSize(level);
uint32_t rowsPerImage = GetHeight() / blockInfo.height;
Texture2DCopySplit copySplit = ComputeTextureCopySplit(
TextureCopySubresource copySplit = ComputeTextureCopySubresource(
{0, 0, 0}, copySize, blockInfo, uploadHandle.startOffset, bytesPerRow,
rowsPerImage);

View File

@@ -143,7 +143,7 @@ namespace dawn_native { namespace d3d12 {
}
void RecordCopyBufferToTextureFromTextureCopySplit(ID3D12GraphicsCommandList* commandList,
const Texture2DCopySplit& baseCopySplit,
const TextureCopySubresource& baseCopySplit,
ID3D12Resource* bufferResource,
uint64_t baseOffset,
uint64_t bufferBytesPerRow,
@@ -158,10 +158,10 @@ namespace dawn_native { namespace d3d12 {
const uint64_t offsetBytes = baseCopySplit.offset + baseOffset;
for (uint32_t i = 0; i < baseCopySplit.count; ++i) {
const Texture2DCopySplit::CopyInfo& info = baseCopySplit.copies[i];
const TextureCopySubresource::CopyInfo& info = baseCopySplit.copies[i];
// TODO(jiawei.shao@intel.com): pre-compute bufferLocation and sourceRegion as
// members in Texture2DCopySplit::CopyInfo.
// members in TextureCopySubresource::CopyInfo.
const D3D12_TEXTURE_COPY_LOCATION bufferLocation =
ComputeBufferLocationForCopyTextureRegion(texture, bufferResource, info.bufferSize,
offsetBytes, bufferBytesPerRow, aspect);
@@ -191,20 +191,21 @@ namespace dawn_native { namespace d3d12 {
const uint64_t bytesPerSlice = bytesPerRow * rowsPerImage;
// copySplits.copies2D[1] is always calculated for the second copy slice with
// copySplits.copySubresources[1] is always calculated for the second copy slice with
// extra "bytesPerSlice" copy offset compared with the first copy slice. So
// here we use an array bufferOffsetsForNextSlice to record the extra offsets
// for each copy slice: bufferOffsetsForNextSlice[0] is the extra offset for
// the next copy slice that uses copySplits.copies2D[0], and
// the next copy slice that uses copySplits.copySubresources[0], and
// bufferOffsetsForNextSlice[1] is the extra offset for the next copy slice
// that uses copySplits.copies2D[1].
std::array<uint64_t, TextureCopySplits::kMaxTextureCopySplits> bufferOffsetsForNextSlice = {
{0u, 0u}};
// that uses copySplits.copySubresources[1].
std::array<uint64_t, TextureCopySplits::kMaxTextureCopySubresources>
bufferOffsetsForNextSlice = {{0u, 0u}};
for (uint32_t copyLayer = 0; copyLayer < copySize.depthOrArrayLayers; ++copyLayer) {
const uint32_t splitIndex = copyLayer % copySplits.copies2D.size();
const uint32_t splitIndex = copyLayer % copySplits.copySubresources.size();
const Texture2DCopySplit& copySplitPerLayerBase = copySplits.copies2D[splitIndex];
const TextureCopySubresource& copySplitPerLayerBase =
copySplits.copySubresources[splitIndex];
const uint64_t bufferOffsetForNextSlice = bufferOffsetsForNextSlice[splitIndex];
const uint32_t copyTextureLayer = copyLayer + textureCopy.origin.z;
@@ -213,7 +214,8 @@ namespace dawn_native { namespace d3d12 {
bufferOffsetForNextSlice, bytesPerRow, texture, textureCopy.mipLevel,
copyTextureLayer, aspect);
bufferOffsetsForNextSlice[splitIndex] += bytesPerSlice * copySplits.copies2D.size();
bufferOffsetsForNextSlice[splitIndex] +=
bytesPerSlice * copySplits.copySubresources.size();
}
}
@@ -233,7 +235,7 @@ namespace dawn_native { namespace d3d12 {
textureCopy.origin, copySize, blockInfo, offset, bytesPerRow, rowsPerImage, true);
RecordCopyBufferToTextureFromTextureCopySplit(
commandContext->GetCommandList(), copySplits.copies2D[0], bufferResource, 0,
commandContext->GetCommandList(), copySplits.copySubresources[0], bufferResource, 0,
bytesPerRow, texture, textureCopy.mipLevel, 0, aspect);
}
@@ -261,7 +263,7 @@ namespace dawn_native { namespace d3d12 {
}
void RecordCopyTextureToBufferFromTextureCopySplit(ID3D12GraphicsCommandList* commandList,
const Texture2DCopySplit& baseCopySplit,
const TextureCopySubresource& baseCopySplit,
Buffer* buffer,
uint64_t baseOffset,
uint64_t bufferBytesPerRow,
@@ -275,10 +277,10 @@ namespace dawn_native { namespace d3d12 {
const uint64_t offset = baseCopySplit.offset + baseOffset;
for (uint32_t i = 0; i < baseCopySplit.count; ++i) {
const Texture2DCopySplit::CopyInfo& info = baseCopySplit.copies[i];
const TextureCopySubresource::CopyInfo& info = baseCopySplit.copies[i];
// TODO(jiawei.shao@intel.com): pre-compute bufferLocation and sourceRegion as
// members in Texture2DCopySplit::CopyInfo.
// members in TextureCopySubresource::CopyInfo.
const D3D12_TEXTURE_COPY_LOCATION bufferLocation =
ComputeBufferLocationForCopyTextureRegion(texture, buffer->GetD3D12Resource(),
info.bufferSize, offset,
@@ -309,19 +311,20 @@ namespace dawn_native { namespace d3d12 {
const uint64_t bytesPerSlice = bufferCopy.bytesPerRow * bufferCopy.rowsPerImage;
// copySplits.copies2D[1] is always calculated for the second copy slice with
// copySplits.copySubresources[1] is always calculated for the second copy slice with
// extra "bytesPerSlice" copy offset compared with the first copy slice. So
// here we use an array bufferOffsetsForNextSlice to record the extra offsets
// for each copy slice: bufferOffsetsForNextSlice[0] is the extra offset for
// the next copy slice that uses copySplits.copies2D[0], and
// the next copy slice that uses copySplits.copySubresources[0], and
// bufferOffsetsForNextSlice[1] is the extra offset for the next copy slice
// that uses copySplits.copies2D[1].
std::array<uint64_t, TextureCopySplits::kMaxTextureCopySplits> bufferOffsetsForNextSlice = {
{0u, 0u}};
// that uses copySplits.copySubresources[1].
std::array<uint64_t, TextureCopySplits::kMaxTextureCopySubresources>
bufferOffsetsForNextSlice = {{0u, 0u}};
for (uint32_t copyLayer = 0; copyLayer < copySize.depthOrArrayLayers; ++copyLayer) {
const uint32_t splitIndex = copyLayer % copySplits.copies2D.size();
const uint32_t splitIndex = copyLayer % copySplits.copySubresources.size();
const Texture2DCopySplit& copySplitPerLayerBase = copySplits.copies2D[splitIndex];
const TextureCopySubresource& copySplitPerLayerBase =
copySplits.copySubresources[splitIndex];
const uint64_t bufferOffsetForNextSlice = bufferOffsetsForNextSlice[splitIndex];
const uint32_t copyTextureLayer = copyLayer + textureCopy.origin.z;
@@ -330,7 +333,8 @@ namespace dawn_native { namespace d3d12 {
bufferCopy.bytesPerRow, texture, textureCopy.mipLevel, copyTextureLayer,
textureCopy.aspect);
bufferOffsetsForNextSlice[splitIndex] += bytesPerSlice * copySplits.copies2D.size();
bufferOffsetsForNextSlice[splitIndex] +=
bytesPerSlice * copySplits.copySubresources.size();
}
}
@@ -349,8 +353,8 @@ namespace dawn_native { namespace d3d12 {
ComputeTextureCopySplits(textureCopy.origin, copySize, blockInfo, bufferCopy.offset,
bufferCopy.bytesPerRow, bufferCopy.rowsPerImage, true);
RecordCopyTextureToBufferFromTextureCopySplit(commandList, copySplits.copies2D[0], buffer,
0, bufferCopy.bytesPerRow, texture,
RecordCopyTextureToBufferFromTextureCopySplit(commandList, copySplits.copySubresources[0],
buffer, 0, bufferCopy.bytesPerRow, texture,
textureCopy.mipLevel, 0, textureCopy.aspect);
}

View File

@@ -45,7 +45,7 @@ namespace dawn_native { namespace d3d12 {
bool IsTypeless(DXGI_FORMAT format);
void RecordCopyBufferToTextureFromTextureCopySplit(ID3D12GraphicsCommandList* commandList,
const Texture2DCopySplit& baseCopySplit,
const TextureCopySubresource& baseCopySplit,
ID3D12Resource* bufferResource,
uint64_t baseOffset,
uint64_t bufferBytesPerRow,
@@ -65,7 +65,7 @@ namespace dawn_native { namespace d3d12 {
Aspect aspect);
void RecordCopyTextureToBufferFromTextureCopySplit(ID3D12GraphicsCommandList* commandList,
const Texture2DCopySplit& baseCopySplit,
const TextureCopySubresource& baseCopySplit,
Buffer* buffer,
uint64_t baseOffset,
uint64_t bufferBytesPerRow,