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,
TextureCopySubresource ComputeTextureCopySubresource(Origin3D origin,
Extent3D copySize,
const TexelBlockInfo& blockInfo,
uint64_t offset,
uint32_t bytesPerRow,
uint32_t rowsPerImage) {
Texture2DCopySplit copy;
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,22 +233,22 @@ 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,
copies.copySubresources[1] =
ComputeTextureCopySubresource(copyFirstLayerOrigin, copyOneLayerSize, blockInfo,
bufferOffsetNextLayer, bytesPerRow, rowsPerImage);
}

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,12 +44,12 @@ 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,
TextureCopySubresource ComputeTextureCopySubresource(Origin3D origin,
Extent3D copySize,
const TexelBlockInfo& blockInfo,
uint64_t offset,

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,

View File

@ -44,7 +44,7 @@ namespace {
};
// Check that each copy region fits inside the buffer footprint
void ValidateFootprints(const Texture2DCopySplit& copySplit) {
void ValidateFootprints(const TextureCopySubresource& copySplit) {
for (uint32_t i = 0; i < copySplit.count; ++i) {
const auto& copy = copySplit.copies[i];
ASSERT_LE(copy.bufferOffset.x + copy.copySize.width, copy.bufferSize.width);
@ -55,7 +55,7 @@ namespace {
}
// Check that the offset is aligned
void ValidateOffset(const Texture2DCopySplit& copySplit) {
void ValidateOffset(const TextureCopySubresource& copySplit) {
ASSERT_TRUE(Align(copySplit.offset, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT) ==
copySplit.offset);
}
@ -65,7 +65,7 @@ namespace {
}
// Check that no pair of copy regions intersect each other
void ValidateDisjoint(const Texture2DCopySplit& copySplit) {
void ValidateDisjoint(const TextureCopySubresource& copySplit) {
for (uint32_t i = 0; i < copySplit.count; ++i) {
const auto& a = copySplit.copies[i];
for (uint32_t j = i + 1; j < copySplit.count; ++j) {
@ -86,7 +86,7 @@ namespace {
// Check that the union of the copy regions exactly covers the texture region
void ValidateTextureBounds(const TextureSpec& textureSpec,
const Texture2DCopySplit& copySplit) {
const TextureCopySubresource& copySplit) {
ASSERT_TRUE(copySplit.count > 0);
uint32_t minX = copySplit.copies[0].textureOffset.x;
@ -117,7 +117,8 @@ namespace {
// Validate that the number of pixels copied is exactly equal to the number of pixels in the
// texture region
void ValidatePixelCount(const TextureSpec& textureSpec, const Texture2DCopySplit& copySplit) {
void ValidatePixelCount(const TextureSpec& textureSpec,
const TextureCopySubresource& copySplit) {
uint32_t count = 0;
for (uint32_t i = 0; i < copySplit.count; ++i) {
const auto& copy = copySplit.copies[i];
@ -129,7 +130,7 @@ namespace {
// Check that every buffer offset is at the correct pixel location
void ValidateBufferOffset(const TextureSpec& textureSpec,
const BufferSpec& bufferSpec,
const Texture2DCopySplit& copySplit) {
const TextureCopySubresource& copySplit) {
ASSERT_TRUE(copySplit.count > 0);
uint32_t texelsPerBlock = textureSpec.blockWidth * textureSpec.blockHeight;
@ -165,7 +166,7 @@ namespace {
void ValidateCopySplit(const TextureSpec& textureSpec,
const BufferSpec& bufferSpec,
const Texture2DCopySplit& copySplit) {
const TextureCopySubresource& copySplit) {
ValidateFootprints(copySplit);
ValidateOffset(copySplit);
ValidateDisjoint(copySplit);
@ -188,7 +189,7 @@ namespace {
return os;
}
std::ostream& operator<<(std::ostream& os, const Texture2DCopySplit& copySplit) {
std::ostream& operator<<(std::ostream& os, const TextureCopySubresource& copySplit) {
os << "CopySplit" << std::endl;
for (uint32_t i = 0; i < copySplit.count; ++i) {
const auto& copy = copySplit.copies[i];
@ -294,14 +295,14 @@ namespace {
class CopySplitTest : public testing::Test {
protected:
Texture2DCopySplit DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
TextureCopySubresource DoTest(const TextureSpec& textureSpec, const BufferSpec& bufferSpec) {
ASSERT(textureSpec.width % textureSpec.blockWidth == 0 &&
textureSpec.height % textureSpec.blockHeight == 0);
dawn_native::TexelBlockInfo blockInfo = {};
blockInfo.width = textureSpec.blockWidth;
blockInfo.height = textureSpec.blockHeight;
blockInfo.byteSize = textureSpec.texelBlockSizeInBytes;
Texture2DCopySplit copySplit = ComputeTextureCopySplit(
TextureCopySubresource copySplit = ComputeTextureCopySubresource(
{textureSpec.x, textureSpec.y, textureSpec.z},
{textureSpec.width, textureSpec.height, textureSpec.depth}, blockInfo,
bufferSpec.offset, bufferSpec.bytesPerRow, bufferSpec.rowsPerImage);
@ -313,7 +314,7 @@ class CopySplitTest : public testing::Test {
TEST_F(CopySplitTest, General) {
for (TextureSpec textureSpec : kBaseTextureSpecs) {
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
Texture2DCopySplit copySplit = DoTest(textureSpec, bufferSpec);
TextureCopySubresource copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
@ -333,7 +334,7 @@ TEST_F(CopySplitTest, TextureWidth) {
}
textureSpec.width = val;
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
Texture2DCopySplit copySplit = DoTest(textureSpec, bufferSpec);
TextureCopySubresource copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
@ -354,7 +355,7 @@ TEST_F(CopySplitTest, TextureHeight) {
}
textureSpec.height = val;
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
Texture2DCopySplit copySplit = DoTest(textureSpec, bufferSpec);
TextureCopySubresource copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
@ -372,7 +373,7 @@ TEST_F(CopySplitTest, TextureX) {
for (uint32_t val : kCheckValues) {
textureSpec.x = val;
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
Texture2DCopySplit copySplit = DoTest(textureSpec, bufferSpec);
TextureCopySubresource copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
@ -390,7 +391,7 @@ TEST_F(CopySplitTest, TextureY) {
for (uint32_t val : kCheckValues) {
textureSpec.y = val;
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
Texture2DCopySplit copySplit = DoTest(textureSpec, bufferSpec);
TextureCopySubresource copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
@ -408,7 +409,7 @@ TEST_F(CopySplitTest, TexelSize) {
for (uint32_t texelSize : {4, 8, 16, 32, 64}) {
textureSpec.texelBlockSizeInBytes = texelSize;
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
Texture2DCopySplit copySplit = DoTest(textureSpec, bufferSpec);
TextureCopySubresource copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
@ -427,7 +428,7 @@ TEST_F(CopySplitTest, BufferOffset) {
for (uint32_t val : kCheckValues) {
bufferSpec.offset = textureSpec.texelBlockSizeInBytes * val;
Texture2DCopySplit copySplit = DoTest(textureSpec, bufferSpec);
TextureCopySubresource copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
@ -447,7 +448,7 @@ TEST_F(CopySplitTest, RowPitch) {
for (uint32_t i = 0; i < 5; ++i) {
bufferSpec.bytesPerRow = baseRowPitch + i * 256;
Texture2DCopySplit copySplit = DoTest(textureSpec, bufferSpec);
TextureCopySubresource copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
@ -467,7 +468,7 @@ TEST_F(CopySplitTest, ImageHeight) {
for (uint32_t i = 0; i < 5; ++i) {
bufferSpec.rowsPerImage = baseImageHeight + i * 256;
Texture2DCopySplit copySplit = DoTest(textureSpec, bufferSpec);
TextureCopySubresource copySplit = DoTest(textureSpec, bufferSpec);
if (HasFatalFailure()) {
std::ostringstream message;
message << "Failed generating splits: " << textureSpec << ", " << bufferSpec