Implement new formula for requiredBytesInCopy

Changed upstream in:
- https://github.com/gpuweb/gpuweb/pull/1014
- https://github.com/gpuweb/gpuweb/pull/1130

Note that in some of the cases where width==0 || height==0 || depth==0,
this increases the number of linear data bytes required for a copy.
Since this is a corner case, no deprecation logic is added.

Removes a duplicated copy of this logic in TestUtils.cpp.

Bug: dawn:520
Change-Id: I3b3d079c6ef316df7d95ba5c349bf8de4646fa4d
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/30741
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Kai Ninomiya
2020-10-23 21:21:33 +00:00
committed by Commit Bot service account
parent ca5aa235da
commit c9d0b492d5
10 changed files with 157 additions and 87 deletions

View File

@@ -27,6 +27,7 @@
#include "utils/PlatformDebugLogger.h"
#include "utils/SystemUtils.h"
#include "utils/TerribleCommandBuffer.h"
#include "utils/TestUtils.h"
#include "utils/WGPUHelpers.h"
#include <algorithm>
@@ -851,7 +852,10 @@ std::ostringstream& DawnTestBase::AddTextureExpectationImpl(const char* file,
ASSERT(bytesPerRow == Align(bytesPerRow, kTextureBytesPerRowAlignment));
}
uint32_t size = bytesPerRow * (height - 1) + width * dataSize;
uint32_t rowsPerImage = height;
uint32_t depth = 1;
uint32_t size =
utils::RequiredBytesInCopy(bytesPerRow, rowsPerImage, width, height, depth, dataSize);
// TODO(enga): We should have the map async alignment in Contants.h. Also, it should change to 8
// for Float64Array.

View File

@@ -864,9 +864,9 @@ TEST_P(BufferZeroInitTest, CopyBufferToTexture) {
const wgpu::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(texture, 0, {0, 0, 0});
const uint32_t requiredBufferSizeForCopy = utils::GetBytesInBufferTextureCopy(
kTextureFormat, kTextureSize.width, kTextureBytesPerRowAlignment, kTextureSize.width,
kTextureSize.depth);
const uint32_t rowsPerImage = kTextureSize.height;
const uint32_t requiredBufferSizeForCopy = utils::RequiredBytesInCopy(
kTextureBytesPerRowAlignment, rowsPerImage, kTextureSize, kTextureFormat);
constexpr wgpu::BufferUsage kBufferUsage =
wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;

View File

@@ -52,18 +52,18 @@ class CompressedTextureBCFormatTest : public DawnTest {
std::vector<uint8_t> UploadData(const CopyConfig& copyConfig) {
uint32_t copyWidthInBlock = copyConfig.copyExtent3D.width / kBCBlockWidthInTexels;
uint32_t copyHeightInBlock = copyConfig.copyExtent3D.height / kBCBlockHeightInTexels;
uint32_t rowPitchInBytes = 0;
uint32_t copyBytesPerRow = 0;
if (copyConfig.bytesPerRowAlignment != 0) {
rowPitchInBytes = copyConfig.bytesPerRowAlignment;
copyBytesPerRow = copyConfig.bytesPerRowAlignment;
} else {
rowPitchInBytes = copyWidthInBlock *
copyBytesPerRow = copyWidthInBlock *
utils::GetTexelBlockSizeInBytes(copyConfig.textureDescriptor.format);
}
uint32_t copyRowsPerImage = copyConfig.rowsPerImage;
if (copyRowsPerImage == 0) {
copyRowsPerImage = copyHeightInBlock;
}
uint32_t copyBytesPerImage = rowPitchInBytes * copyRowsPerImage;
uint32_t copyBytesPerImage = copyBytesPerRow * copyRowsPerImage;
uint32_t uploadBufferSize =
copyConfig.bufferOffset + copyBytesPerImage * copyConfig.copyExtent3D.depth;
@@ -75,7 +75,7 @@ class CompressedTextureBCFormatTest : public DawnTest {
for (uint32_t h = 0; h < copyHeightInBlock; ++h) {
for (uint32_t w = 0; w < copyWidthInBlock; ++w) {
uint32_t uploadBufferOffset = copyConfig.bufferOffset +
copyBytesPerImage * layer + rowPitchInBytes * h +
copyBytesPerImage * layer + copyBytesPerRow * h +
oneBlockCompressedTextureData.size() * w;
std::memcpy(&data[uploadBufferOffset], oneBlockCompressedTextureData.data(),
oneBlockCompressedTextureData.size() * sizeof(uint8_t));

View File

@@ -57,13 +57,14 @@ class CopyTests : public DawnTest {
}
static BufferSpec MinimumBufferSpec(uint32_t width,
uint32_t rowsPerImage,
uint32_t height,
uint32_t arrayLayer = 1,
bool testZeroRowsPerImage = true) {
const uint32_t bytesPerRow = utils::GetMinimumBytesPerRow(kTextureFormat, width);
const uint32_t totalBufferSize = utils::GetBytesInBufferTextureCopy(
kTextureFormat, width, bytesPerRow, rowsPerImage, arrayLayer);
uint32_t appliedRowsPerImage = testZeroRowsPerImage ? 0 : rowsPerImage;
const uint32_t rowsPerImage = height;
const uint32_t totalBufferSize = utils::RequiredBytesInCopy(
bytesPerRow, rowsPerImage, {width, height, arrayLayer}, kTextureFormat);
uint32_t appliedRowsPerImage = testZeroRowsPerImage ? 0 : height;
return {totalBufferSize, 0, bytesPerRow, appliedRowsPerImage};
}

View File

@@ -145,10 +145,11 @@ TEST_P(TextureZeroInitTest, CopyMultipleTextureArrayLayersToBufferSource) {
wgpu::Texture texture = device.CreateTexture(&descriptor);
const uint32_t bytesPerRow = utils::GetMinimumBytesPerRow(kColorFormat, kSize);
const uint32_t rowsPerImage = kSize;
wgpu::BufferDescriptor bufferDescriptor;
bufferDescriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
bufferDescriptor.size =
utils::GetBytesInBufferTextureCopy(kColorFormat, kSize, bytesPerRow, kSize, kArrayLayers);
bufferDescriptor.size = utils::RequiredBytesInCopy(bytesPerRow, rowsPerImage,
{kSize, kSize, kArrayLayers}, kColorFormat);
wgpu::Buffer buffer = device.CreateBuffer(&bufferDescriptor);
const wgpu::BufferCopyView bufferCopyView =

View File

@@ -923,6 +923,34 @@ TEST_F(CopyCommandTest_T2B, Success) {
}
}
// Edge cases around requiredBytesInCopy computation for empty copies
TEST_F(CopyCommandTest_T2B, Empty) {
wgpu::Texture source =
Create2DTexture(16, 16, 1, 2, wgpu::TextureFormat::RGBA8Unorm, wgpu::TextureUsage::CopySrc);
TestT2BCopy(utils::Expectation::Success, source, 0, {0, 0, 0},
CreateBuffer(0, wgpu::BufferUsage::CopyDst), 0, 256, 4, {0, 0, 0});
TestT2BCopy(utils::Expectation::Success, source, 0, {0, 0, 0},
CreateBuffer(0, wgpu::BufferUsage::CopyDst), 0, 256, 4, {4, 0, 0});
TestT2BCopy(utils::Expectation::Success, source, 0, {0, 0, 0},
CreateBuffer(0, wgpu::BufferUsage::CopyDst), 0, 256, 4, {4, 4, 0});
TestT2BCopy(utils::Expectation::Success, source, 0, {0, 0, 0},
CreateBuffer(1024, wgpu::BufferUsage::CopyDst), 0, 256, 4, {4, 0, 2});
TestT2BCopy(utils::Expectation::Failure, source, 0, {0, 0, 0},
CreateBuffer(1023, wgpu::BufferUsage::CopyDst), 0, 256, 4, {4, 0, 2});
TestT2BCopy(utils::Expectation::Success, source, 0, {0, 0, 0},
CreateBuffer(1792, wgpu::BufferUsage::CopyDst), 0, 256, 4, {0, 4, 2});
TestT2BCopy(utils::Expectation::Failure, source, 0, {0, 0, 0},
CreateBuffer(1791, wgpu::BufferUsage::CopyDst), 0, 256, 4, {0, 4, 2});
TestT2BCopy(utils::Expectation::Success, source, 0, {0, 0, 0},
CreateBuffer(1024, wgpu::BufferUsage::CopyDst), 0, 256, 4, {0, 0, 2});
TestT2BCopy(utils::Expectation::Failure, source, 0, {0, 0, 0},
CreateBuffer(1023, wgpu::BufferUsage::CopyDst), 0, 256, 4, {0, 0, 2});
}
// Test OOB conditions on the texture
TEST_F(CopyCommandTest_T2B, OutOfBoundsOnTexture) {
uint64_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);