From e4f8e19e72e9775360afb7750ccd17257446f5b2 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Fri, 29 May 2020 07:28:38 +0000 Subject: [PATCH] Remove the defaulting for bytesPerRow = 0 Bug: dawn:432 Change-Id: I335cdc367c322764861878bfb604ecc6a146b732 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/22340 Reviewed-by: Stephen White Reviewed-by: Austin Eng Commit-Queue: Corentin Wallez --- src/dawn_native/CommandEncoder.cpp | 34 ++--- .../end2end/CompressedTextureFormatTests.cpp | 28 ----- .../end2end/NonzeroTextureCreationTests.cpp | 4 +- src/tests/end2end/TextureZeroInitTests.cpp | 21 ++-- .../CopyCommandsValidationTests.cpp | 118 +++++++----------- 5 files changed, 71 insertions(+), 134 deletions(-) diff --git a/src/dawn_native/CommandEncoder.cpp b/src/dawn_native/CommandEncoder.cpp index 79db419408..db0271b76e 100644 --- a/src/dawn_native/CommandEncoder.cpp +++ b/src/dawn_native/CommandEncoder.cpp @@ -204,10 +204,6 @@ namespace dawn_native { return {}; } - uint32_t ComputeDefaultBytesPerRow(const Format& format, uint32_t width) { - return width / format.blockWidth * format.blockByteSize; - } - MaybeError ValidateBytesPerRow(const Format& format, const Extent3D& copySize, uint32_t bytesPerRow) { @@ -653,13 +649,7 @@ namespace dawn_native { DAWN_TRY(GetDevice()->ValidateObject(destination->texture)); } - // Compute default values for bytesPerRow/rowsPerImage - uint32_t defaultedBytesPerRow = source->bytesPerRow; - if (defaultedBytesPerRow == 0) { - defaultedBytesPerRow = - ComputeDefaultBytesPerRow(destination->texture->GetFormat(), copySize->width); - } - + // Compute default value for rowsPerImage uint32_t defaultedRowsPerImage = source->rowsPerImage; if (defaultedRowsPerImage == 0) { defaultedRowsPerImage = copySize->height; @@ -677,10 +667,10 @@ namespace dawn_native { uint32_t bufferCopySize = 0; DAWN_TRY(ValidateBytesPerRow(destination->texture->GetFormat(), *copySize, - defaultedBytesPerRow)); + source->bytesPerRow)); DAWN_TRY(ComputeTextureCopyBufferSize(destination->texture->GetFormat(), *copySize, - defaultedBytesPerRow, defaultedRowsPerImage, + source->bytesPerRow, defaultedRowsPerImage, &bufferCopySize)); DAWN_TRY(ValidateCopySizeFitsInTexture(*destination, *copySize)); @@ -699,7 +689,7 @@ namespace dawn_native { allocator->Allocate(Command::CopyBufferToTexture); copy->source.buffer = source->buffer; copy->source.offset = source->offset; - copy->source.bytesPerRow = defaultedBytesPerRow; + copy->source.bytesPerRow = source->bytesPerRow; copy->source.rowsPerImage = defaultedRowsPerImage; copy->destination.texture = destination->texture; copy->destination.origin = destination->origin; @@ -721,13 +711,7 @@ namespace dawn_native { DAWN_TRY(GetDevice()->ValidateObject(destination->buffer)); } - // Compute default values for bytesPerRow/rowsPerImage - uint32_t defaultedBytesPerRow = destination->bytesPerRow; - if (defaultedBytesPerRow == 0) { - defaultedBytesPerRow = - ComputeDefaultBytesPerRow(source->texture->GetFormat(), copySize->width); - } - + // Compute default value for rowsPerImage uint32_t defaultedRowsPerImage = destination->rowsPerImage; if (defaultedRowsPerImage == 0) { defaultedRowsPerImage = copySize->height; @@ -744,10 +728,10 @@ namespace dawn_native { uint32_t bufferCopySize = 0; DAWN_TRY(ValidateBytesPerRow(source->texture->GetFormat(), *copySize, - defaultedBytesPerRow)); + destination->bytesPerRow)); DAWN_TRY(ComputeTextureCopyBufferSize(source->texture->GetFormat(), *copySize, - defaultedBytesPerRow, defaultedRowsPerImage, - &bufferCopySize)); + destination->bytesPerRow, + defaultedRowsPerImage, &bufferCopySize)); DAWN_TRY(ValidateCopySizeFitsInTexture(*source, *copySize)); DAWN_TRY(ValidateCopySizeFitsInBuffer(*destination, bufferCopySize)); @@ -770,7 +754,7 @@ namespace dawn_native { copy->source.arrayLayer = source->arrayLayer; copy->destination.buffer = destination->buffer; copy->destination.offset = destination->offset; - copy->destination.bytesPerRow = defaultedBytesPerRow; + copy->destination.bytesPerRow = destination->bytesPerRow; copy->destination.rowsPerImage = defaultedRowsPerImage; return {}; diff --git a/src/tests/end2end/CompressedTextureFormatTests.cpp b/src/tests/end2end/CompressedTextureFormatTests.cpp index 41ea507f37..b29729a80a 100644 --- a/src/tests/end2end/CompressedTextureFormatTests.cpp +++ b/src/tests/end2end/CompressedTextureFormatTests.cpp @@ -488,34 +488,6 @@ TEST_P(CompressedTextureBCFormatTest, CopyIntoSubRegion) { } } -// Test using bytesPerRow == 0 in the copies with BC formats works correctly. -TEST_P(CompressedTextureBCFormatTest, CopyWithZeroRowPitch) { - // TODO(jiawei.shao@intel.com): find out why this test is flaky on Windows Intel Vulkan - // bots. - DAWN_SKIP_TEST_IF(IsIntel() && IsVulkan() && IsWindows()); - - // TODO(jiawei.shao@intel.com): find out why this test fails on Windows Intel OpenGL drivers. - DAWN_SKIP_TEST_IF(IsIntel() && IsOpenGL() && IsWindows()); - - DAWN_SKIP_TEST_IF(!IsBCFormatSupported()); - - CopyConfig config; - config.textureDescriptor.usage = kDefaultBCFormatTextureUsage; - config.textureDescriptor.size.height = 8; - config.textureDescriptor.size.depth = 1; - - config.bytesPerRowAlignment = 0; - - for (wgpu::TextureFormat format : kBCFormats) { - config.textureDescriptor.format = format; - config.textureDescriptor.size.width = kTextureBytesPerRowAlignment / - CompressedFormatBlockSizeInBytes(format) * - kBCBlockWidthInTexels; - config.copyExtent3D = config.textureDescriptor.size; - TestCopyRegionIntoBCFormatTextures(config); - } -} - // Test copying into the non-zero layer of a 2D array texture with BC formats works correctly. TEST_P(CompressedTextureBCFormatTest, CopyIntoNonZeroArrayLayer) { // TODO(jiawei.shao@intel.com): find out why this test is flaky on Windows Intel Vulkan diff --git a/src/tests/end2end/NonzeroTextureCreationTests.cpp b/src/tests/end2end/NonzeroTextureCreationTests.cpp index 7cdafd521e..0026322e6b 100644 --- a/src/tests/end2end/NonzeroTextureCreationTests.cpp +++ b/src/tests/end2end/NonzeroTextureCreationTests.cpp @@ -141,7 +141,7 @@ TEST_P(NonzeroTextureCreationTests, NonrenderableTextureFormat) { wgpu::Buffer bufferDst = utils::CreateBufferFromData( device, data.data(), static_cast(data.size()), wgpu::BufferUsage::CopySrc); - wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0); + wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, kSize * 4, 0); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::Extent3D copySize = {kSize, kSize, 1}; @@ -175,7 +175,7 @@ TEST_P(NonzeroTextureCreationTests, NonRenderableTextureClearWithMultiArrayLayer wgpu::Buffer bufferDst = utils::CreateBufferFromData( device, data.data(), static_cast(data.size()), wgpu::BufferUsage::CopySrc); - wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0); + wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, kSize * 4, 0); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 1, {0, 0, 0}); wgpu::Extent3D copySize = {kSize, kSize, 1}; diff --git a/src/tests/end2end/TextureZeroInitTests.cpp b/src/tests/end2end/TextureZeroInitTests.cpp index 95e8119144..d6b0df8190 100644 --- a/src/tests/end2end/TextureZeroInitTests.cpp +++ b/src/tests/end2end/TextureZeroInitTests.cpp @@ -231,7 +231,8 @@ TEST_P(TextureZeroInitTest, CopyBufferToTexture) { wgpu::Buffer stagingBuffer = utils::CreateBufferFromData( device, data.data(), static_cast(data.size()), wgpu::BufferUsage::CopySrc); - wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0); + wgpu::BufferCopyView bufferCopyView = + utils::CreateBufferCopyView(stagingBuffer, 0, kSize * sizeof(uint32_t), 0); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::Extent3D copySize = {kSize, kSize, 1}; @@ -261,7 +262,8 @@ TEST_P(TextureZeroInitTest, CopyBufferToTextureHalf) { wgpu::Buffer stagingBuffer = utils::CreateBufferFromData( device, data.data(), static_cast(data.size()), wgpu::BufferUsage::CopySrc); - wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0); + wgpu::BufferCopyView bufferCopyView = + utils::CreateBufferCopyView(stagingBuffer, 0, kSize * sizeof(uint16_t), 0); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::Extent3D copySize = {kSize / 2, kSize, 1}; @@ -331,7 +333,8 @@ TEST_P(TextureZeroInitTest, CopyTextureToTextureHalf) { std::vector data(kFormatBlockByteSize * kSize * kSize, 100); wgpu::Buffer stagingBuffer = utils::CreateBufferFromData( device, data.data(), static_cast(data.size()), wgpu::BufferUsage::CopySrc); - wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0); + wgpu::BufferCopyView bufferCopyView = + utils::CreateBufferCopyView(stagingBuffer, 0, kSize * kFormatBlockByteSize, 0); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(srcTexture, 0, 0, {0, 0, 0}); wgpu::Extent3D copySize = {kSize, kSize, 1}; @@ -704,7 +707,8 @@ TEST_P(TextureZeroInitTest, NonRenderableTextureClearWithMultiArrayLayers) { wgpu::Buffer bufferDst = utils::CreateBufferFromData( device, data.data(), static_cast(data.size()), wgpu::BufferUsage::CopySrc); - wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(bufferDst, 0, 0, 0); + wgpu::BufferCopyView bufferCopyView = + utils::CreateBufferCopyView(bufferDst, 0, kSize * kFormatBlockByteSize, 0); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 1, {0, 0, 0}); wgpu::Extent3D copySize = {kSize, kSize, 1}; @@ -741,7 +745,8 @@ TEST_P(TextureZeroInitTest, RenderPassStoreOpClear) { std::vector data(kFormatBlockByteSize * kSize * kSize, 1); wgpu::Buffer stagingBuffer = utils::CreateBufferFromData( device, data.data(), static_cast(data.size()), wgpu::BufferUsage::CopySrc); - wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0); + wgpu::BufferCopyView bufferCopyView = + utils::CreateBufferCopyView(stagingBuffer, 0, kSize * kFormatBlockByteSize, 0); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}); wgpu::Extent3D copySize = {kSize, kSize, 1}; wgpu::CommandEncoder encoder = device.CreateCommandEncoder(); @@ -888,7 +893,8 @@ TEST_P(TextureZeroInitTest, PreservesInitializedMip) { std::vector data(kFormatBlockByteSize * mipSize * mipSize, 2); wgpu::Buffer stagingBuffer = utils::CreateBufferFromData( device, data.data(), static_cast(data.size()), wgpu::BufferUsage::CopySrc); - wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0); + wgpu::BufferCopyView bufferCopyView = + utils::CreateBufferCopyView(stagingBuffer, 0, mipSize * kFormatBlockByteSize, 0); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(sampleTexture, 1, 0, {0, 0, 0}); wgpu::Extent3D copySize = {mipSize, mipSize, 1}; @@ -965,7 +971,8 @@ TEST_P(TextureZeroInitTest, PreservesInitializedArrayLayer) { std::vector data(kFormatBlockByteSize * kSize * kSize, 2); wgpu::Buffer stagingBuffer = utils::CreateBufferFromData( device, data.data(), static_cast(data.size()), wgpu::BufferUsage::CopySrc); - wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 0, 0); + wgpu::BufferCopyView bufferCopyView = + utils::CreateBufferCopyView(stagingBuffer, 0, kSize * kFormatBlockByteSize, 0); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(sampleTexture, 0, 1, {0, 0, 0}); wgpu::Extent3D copySize = {kSize, kSize, 1}; diff --git a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp index de1da260a3..917446b675 100644 --- a/src/tests/unittests/validation/CopyCommandsValidationTests.cpp +++ b/src/tests/unittests/validation/CopyCommandsValidationTests.cpp @@ -83,15 +83,15 @@ class CopyCommandTest : public ValidationTest { void TestB2TCopy(utils::Expectation expectation, wgpu::Buffer srcBuffer, uint64_t srcOffset, - uint32_t srcRowPitch, - uint32_t srcImageHeight, + uint32_t srcBytesPerRow, + uint32_t srcRowsPerImage, wgpu::Texture destTexture, uint32_t destLevel, uint32_t destSlice, wgpu::Origin3D destOrigin, wgpu::Extent3D extent3D) { wgpu::BufferCopyView bufferCopyView = - utils::CreateBufferCopyView(srcBuffer, srcOffset, srcRowPitch, srcImageHeight); + utils::CreateBufferCopyView(srcBuffer, srcOffset, srcBytesPerRow, srcRowsPerImage); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(destTexture, destLevel, destSlice, destOrigin); @@ -108,11 +108,11 @@ class CopyCommandTest : public ValidationTest { wgpu::Origin3D srcOrigin, wgpu::Buffer destBuffer, uint64_t destOffset, - uint32_t destRowPitch, - uint32_t destImageHeight, + uint32_t destBytesPerRow, + uint32_t destRowsPerImage, wgpu::Extent3D extent3D) { wgpu::BufferCopyView bufferCopyView = - utils::CreateBufferCopyView(destBuffer, destOffset, destRowPitch, destImageHeight); + utils::CreateBufferCopyView(destBuffer, destOffset, destBytesPerRow, destRowsPerImage); wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(srcTexture, srcLevel, srcSlice, srcOrigin); @@ -465,15 +465,15 @@ TEST_F(CopyCommandTest_B2T, IncorrectUsage) { {4, 4, 1}); } -TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) { +TEST_F(CopyCommandTest_B2T, IncorrectBytesPerRow) { uint64_t bufferSize = BufferSizeForTextureCopy(128, 16, 1); wgpu::Buffer source = CreateBuffer(bufferSize, wgpu::BufferUsage::CopySrc); wgpu::Texture destination = Create2DTexture(128, 16, 5, 1, wgpu::TextureFormat::RGBA8Unorm, wgpu::TextureUsage::CopyDst); - // Default bytes per row is not 256-byte aligned + // bytes per row is 0 TestB2TCopy(utils::Expectation::Failure, source, 0, 0, 0, destination, 0, 0, {0, 0, 0}, - {3, 4, 1}); + {64, 4, 1}); // bytes per row is not 256-byte aligned TestB2TCopy(utils::Expectation::Failure, source, 0, 128, 0, destination, 0, 0, {0, 0, 0}, @@ -582,7 +582,7 @@ TEST_F(CopyCommandTest_B2T, BufferOrTextureInErrorState) { // Regression tests for a bug in the computation of texture copy buffer size in Dawn. TEST_F(CopyCommandTest_B2T, TextureCopyBufferSizeLastRowComputation) { - constexpr uint32_t kRowPitch = 256; + constexpr uint32_t kBytesPerRow = 256; constexpr uint32_t kWidth = 4; constexpr uint32_t kHeight = 4; @@ -590,15 +590,15 @@ TEST_F(CopyCommandTest_B2T, TextureCopyBufferSizeLastRowComputation) { wgpu::TextureFormat::RG8Unorm}; { - // kRowPitch * (kHeight - 1) + kWidth is not large enough to be the valid buffer size in + // kBytesPerRow * (kHeight - 1) + kWidth is not large enough to be the valid buffer size in // this test because the buffer sizes in B2T copies are not in texels but in bytes. - constexpr uint32_t kInvalidBufferSize = kRowPitch * (kHeight - 1) + kWidth; + constexpr uint32_t kInvalidBufferSize = kBytesPerRow * (kHeight - 1) + kWidth; for (wgpu::TextureFormat format : kFormats) { wgpu::Buffer source = CreateBuffer(kInvalidBufferSize, wgpu::BufferUsage::CopySrc); wgpu::Texture destination = Create2DTexture(kWidth, kHeight, 1, 1, format, wgpu::TextureUsage::CopyDst); - TestB2TCopy(utils::Expectation::Failure, source, 0, kRowPitch, 0, destination, 0, 0, + TestB2TCopy(utils::Expectation::Failure, source, 0, kBytesPerRow, 0, destination, 0, 0, {0, 0, 0}, {kWidth, kHeight, 1}); } } @@ -614,14 +614,14 @@ TEST_F(CopyCommandTest_B2T, TextureCopyBufferSizeLastRowComputation) { { uint32_t invalidBuffferSize = validBufferSize - 1; wgpu::Buffer source = CreateBuffer(invalidBuffferSize, wgpu::BufferUsage::CopySrc); - TestB2TCopy(utils::Expectation::Failure, source, 0, kRowPitch, 0, destination, 0, 0, - {0, 0, 0}, {kWidth, kHeight, 1}); + TestB2TCopy(utils::Expectation::Failure, source, 0, kBytesPerRow, 0, destination, 0, + 0, {0, 0, 0}, {kWidth, kHeight, 1}); } { wgpu::Buffer source = CreateBuffer(validBufferSize, wgpu::BufferUsage::CopySrc); - TestB2TCopy(utils::Expectation::Success, source, 0, kRowPitch, 0, destination, 0, 0, - {0, 0, 0}, {kWidth, kHeight, 1}); + TestB2TCopy(utils::Expectation::Success, source, 0, kBytesPerRow, 0, destination, 0, + 0, {0, 0, 0}, {kWidth, kHeight, 1}); } } } @@ -798,15 +798,15 @@ TEST_F(CopyCommandTest_T2B, IncorrectUsage) { TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, vertex, 0, 256, 0, {4, 4, 1}); } -TEST_F(CopyCommandTest_T2B, IncorrectRowPitch) { +TEST_F(CopyCommandTest_T2B, IncorrectBytesPerRow) { uint64_t bufferSize = BufferSizeForTextureCopy(128, 16, 1); wgpu::Texture source = Create2DTexture(128, 16, 5, 1, wgpu::TextureFormat::RGBA8Unorm, wgpu::TextureUsage::CopyDst); wgpu::Buffer destination = CreateBuffer(bufferSize, wgpu::BufferUsage::CopySrc); - // Default bytes per row is not 256-byte aligned + // bytes per row is 0 TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, destination, 0, 256, 0, - {3, 4, 1}); + {64, 4, 1}); // bytes per row is not 256-byte aligned TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, destination, 0, 257, 0, @@ -913,7 +913,7 @@ TEST_F(CopyCommandTest_T2B, BufferOrTextureInErrorState) { // Regression tests for a bug in the computation of texture copy buffer size in Dawn. TEST_F(CopyCommandTest_T2B, TextureCopyBufferSizeLastRowComputation) { - constexpr uint32_t kRowPitch = 256; + constexpr uint32_t kBytesPerRow = 256; constexpr uint32_t kWidth = 4; constexpr uint32_t kHeight = 4; @@ -921,9 +921,9 @@ TEST_F(CopyCommandTest_T2B, TextureCopyBufferSizeLastRowComputation) { wgpu::TextureFormat::RG8Unorm}; { - // kRowPitch * (kHeight - 1) + kWidth is not large enough to be the valid buffer size in + // kBytesPerRow * (kHeight - 1) + kWidth is not large enough to be the valid buffer size in // this test because the buffer sizes in T2B copies are not in texels but in bytes. - constexpr uint32_t kInvalidBufferSize = kRowPitch * (kHeight - 1) + kWidth; + constexpr uint32_t kInvalidBufferSize = kBytesPerRow * (kHeight - 1) + kWidth; for (wgpu::TextureFormat format : kFormats) { wgpu::Texture source = @@ -931,7 +931,7 @@ TEST_F(CopyCommandTest_T2B, TextureCopyBufferSizeLastRowComputation) { wgpu::Buffer destination = CreateBuffer(kInvalidBufferSize, wgpu::BufferUsage::CopySrc); TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, destination, 0, - kRowPitch, 0, {kWidth, kHeight, 1}); + kBytesPerRow, 0, {kWidth, kHeight, 1}); } } @@ -948,14 +948,14 @@ TEST_F(CopyCommandTest_T2B, TextureCopyBufferSizeLastRowComputation) { wgpu::Buffer destination = CreateBuffer(invalidBufferSize, wgpu::BufferUsage::CopyDst); TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, destination, 0, - kRowPitch, 0, {kWidth, kHeight, 1}); + kBytesPerRow, 0, {kWidth, kHeight, 1}); } { wgpu::Buffer destination = CreateBuffer(validBufferSize, wgpu::BufferUsage::CopyDst); TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, destination, 0, - kRowPitch, 0, {kWidth, kHeight, 1}); + kBytesPerRow, 0, {kWidth, kHeight, 1}); } } } @@ -1263,17 +1263,17 @@ class CopyCommandTest_CompressedTextureFormats : public CopyCommandTest { void TestBothTBCopies(utils::Expectation expectation, wgpu::Buffer buffer, uint64_t bufferOffset, - uint32_t bufferRowPitch, + uint32_t bufferBytesPerRow, uint32_t rowsPerImage, wgpu::Texture texture, uint32_t level, uint32_t arraySlice, wgpu::Origin3D origin, wgpu::Extent3D extent3D) { - TestB2TCopy(expectation, buffer, bufferOffset, bufferRowPitch, rowsPerImage, texture, level, - arraySlice, origin, extent3D); + TestB2TCopy(expectation, buffer, bufferOffset, bufferBytesPerRow, rowsPerImage, texture, + level, arraySlice, origin, extent3D); TestT2BCopy(expectation, texture, level, arraySlice, origin, buffer, bufferOffset, - bufferRowPitch, rowsPerImage, extent3D); + bufferBytesPerRow, rowsPerImage, extent3D); } void TestBothT2TCopies(utils::Expectation expectation, @@ -1330,12 +1330,10 @@ TEST_F(CopyCommandTest_CompressedTextureFormats, BufferOffset) { } } -// Tests to verify that RowPitch must not be smaller than (width / blockWidth) * blockSizeInBytes -// and it is valid to use 0 as RowPitch in buffer-to-texture or texture-to-buffer copies with -// compressed texture formats. -// Note that in Dawn we require RowPitch be a multiple of 256, which ensures RowPitch will always be -// the multiple of compressed texture block width in bytes. -TEST_F(CopyCommandTest_CompressedTextureFormats, RowPitch) { +// Tests to verify that bytesPerRow must not be less than (width / blockWidth) * blockSizeInBytes. +// Note that in Dawn we require bytesPerRow be a multiple of 256, which ensures bytesPerRow will +// always be the multiple of compressed texture block width in bytes. +TEST_F(CopyCommandTest_CompressedTextureFormats, BytesPerRow) { wgpu::Buffer buffer = CreateBuffer(1024, wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst); @@ -1343,60 +1341,36 @@ TEST_F(CopyCommandTest_CompressedTextureFormats, RowPitch) { constexpr uint32_t kTestWidth = 160; constexpr uint32_t kTestHeight = 160; - // Failures on the RowPitch that is not large enough. + // Failures on the BytesPerRow that is not large enough. { - constexpr uint32_t kSmallRowPitch = 256; + constexpr uint32_t kSmallBytesPerRow = 256; for (wgpu::TextureFormat bcFormat : kBCFormats) { wgpu::Texture texture = Create2DTexture(bcFormat, 1, kTestWidth, kTestHeight); - TestBothTBCopies(utils::Expectation::Failure, buffer, 0, kSmallRowPitch, 4, texture, - 0, 0, {0, 0, 0}, {kTestWidth, 4, 1}); + TestBothTBCopies(utils::Expectation::Failure, buffer, 0, kSmallBytesPerRow, 4, + texture, 0, 0, {0, 0, 0}, {kTestWidth, 4, 1}); } } - // Test it is not valid to use a RowPitch that is not a multiple of 256. + // Test it is not valid to use a BytesPerRow that is not a multiple of 256. { for (wgpu::TextureFormat bcFormat : kBCFormats) { wgpu::Texture texture = Create2DTexture(bcFormat, 1, kTestWidth, kTestHeight); - uint32_t inValidRowPitch = + uint32_t inValidBytesPerRow = kTestWidth / 4 * CompressedFormatBlockSizeInBytes(bcFormat); - ASSERT_NE(0u, inValidRowPitch % 256); - TestBothTBCopies(utils::Expectation::Failure, buffer, 0, inValidRowPitch, 4, + ASSERT_NE(0u, inValidBytesPerRow % 256); + TestBothTBCopies(utils::Expectation::Failure, buffer, 0, inValidBytesPerRow, 4, texture, 0, 0, {0, 0, 0}, {kTestWidth, 4, 1}); } } - // Test the smallest valid RowPitch should work. + // Test the smallest valid BytesPerRow should work. { for (wgpu::TextureFormat bcFormat : kBCFormats) { wgpu::Texture texture = Create2DTexture(bcFormat, 1, kTestWidth, kTestHeight); - uint32_t smallestValidRowPitch = + uint32_t smallestValidBytesPerRow = Align(kTestWidth / 4 * CompressedFormatBlockSizeInBytes(bcFormat), 256); - TestBothTBCopies(utils::Expectation::Success, buffer, 0, smallestValidRowPitch, 4, - texture, 0, 0, {0, 0, 0}, {kTestWidth, 4, 1}); - } - } - } - - // Test RowPitch == 0. - { - constexpr uint32_t kZeroRowPitch = 0; - constexpr uint32_t kTestHeight = 128; - - { - constexpr uint32_t kValidWidth = 128; - for (wgpu::TextureFormat bcFormat : kBCFormats) { - wgpu::Texture texture = Create2DTexture(bcFormat, 1, kValidWidth, kTestHeight); - TestBothTBCopies(utils::Expectation::Success, buffer, 0, kZeroRowPitch, 4, texture, - 0, 0, {0, 0, 0}, {kValidWidth, 4, 1}); - } - } - - { - constexpr uint32_t kInValidWidth = 16; - for (wgpu::TextureFormat bcFormat : kBCFormats) { - wgpu::Texture texture = Create2DTexture(bcFormat, 1, kInValidWidth, kTestHeight); - TestBothTBCopies(utils::Expectation::Failure, buffer, 0, kZeroRowPitch, 4, texture, - 0, 0, {0, 0, 0}, {kInValidWidth, 4, 1}); + TestBothTBCopies(utils::Expectation::Success, buffer, 0, smallestValidBytesPerRow, + 4, texture, 0, 0, {0, 0, 0}, {kTestWidth, 4, 1}); } } }