Change Copy Operation Interfaces to Match WebGPU IDL

Cosmetic changes to copyBufferToTexture and copyTextureToBuffer to
match WebGPU IDL. Introduces BufferCopyView, TextureCopyView,
TextureAspect, and Origin3D types.

Bug: dawn:17
Change-Id: Ic0e7f472a9dc1353d3fc3839ff02f348bb6067e8
Reviewed-on: https://dawn-review.googlesource.com/c/2520
Commit-Queue: Brandon1 Jones <brandon1.jones@intel.com>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
Brandon Jones
2018-11-28 17:54:13 +00:00
committed by Commit Bot service account
parent e06d57d338
commit ac71e34d4a
13 changed files with 396 additions and 378 deletions

View File

@@ -301,10 +301,14 @@ std::ostringstream& DawnTest::AddTextureExpectation(const char* file,
// We need to enqueue the copy immediately because by the time we resolve the expectation,
// the texture might have been modified.
dawn::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(texture, level, 0, {x, y, 0}, dawn::TextureAspect::Color);
dawn::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(readback.buffer, readback.offset, rowPitch, 0);
dawn::Extent3D copySize = {width, height, 1};
dawn::CommandBuffer commands =
device.CreateCommandBufferBuilder()
.CopyTextureToBuffer(texture, x, y, 0, width, height, 1, level, 0, readback.buffer,
readback.offset, rowPitch)
.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize)
.GetResult();
queue.Submit(1, &commands);

View File

@@ -258,7 +258,12 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) {
.GetResult();
dawn::CommandBufferBuilder builder = device.CreateCommandBufferBuilder();
builder.CopyBufferToTexture(stagingBuffer, 0, widthInBytes, texture, 0, 0, 0, width, height, 1, 0, 0);
dawn::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(stagingBuffer, 0, widthInBytes, 0);
dawn::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color);
dawn::Extent3D copySize = {width, height, 1};
builder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
dawn::RenderPassEncoder pass = builder.BeginRenderPass(renderPass.renderPassInfo);
pass.SetRenderPipeline(pipeline);
pass.SetBindGroup(0, bindGroup);

View File

@@ -100,8 +100,12 @@ class CopyTests_T2B : public CopyTests {
// Create an upload buffer and use it to populate the current slice of the texture in `level` mip level
dawn::Buffer uploadBuffer = utils::CreateBufferFromData(device, textureArrayData[slice].data(),
static_cast<uint32_t>(sizeof(RGBA8) * textureArrayData[slice].size()), dawn::BufferUsageBit::TransferSrc);
cmdBuilder.CopyBufferToTexture(uploadBuffer, 0, rowPitch, texture, 0, 0, 0, width, height, 1, textureSpec.level, slice);
dawn::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
texture, textureSpec.level, slice, {0, 0, 0}, dawn::TextureAspect::Color);
dawn::Extent3D copySize = {width, height, 1};
cmdBuilder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
}
// Create a buffer of size `size * textureSpec.arrayLayer` and populate it with empty data (0,0,0,0)
@@ -117,7 +121,13 @@ class CopyTests_T2B : public CopyTests {
uint32_t bufferOffset = bufferSpec.offset;
for (uint32_t slice = 0; slice < textureSpec.arrayLayer; ++slice) {
// Copy the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] from the `level` mip into the buffer at `offset + bufferSpec.size * slice` and `rowPitch`
cmdBuilder.CopyTextureToBuffer(texture, textureSpec.x, textureSpec.y, 0, textureSpec.copyWidth, textureSpec.copyHeight, 1, textureSpec.level, slice, buffer, bufferOffset, bufferSpec.rowPitch);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
texture, textureSpec.level, slice, {textureSpec.x, textureSpec.y, 0},
dawn::TextureAspect::Color);
dawn::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(buffer, bufferOffset, bufferSpec.rowPitch, 0);
dawn::Extent3D copySize = {textureSpec.copyWidth, textureSpec.copyHeight, 1};
cmdBuilder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &copySize);
bufferOffset += bufferSpec.size;
}
@@ -198,12 +208,24 @@ protected:
std::vector<RGBA8> emptyData(texelCount);
dawn::Buffer uploadBuffer = utils::CreateBufferFromData(device, emptyData.data(), static_cast<uint32_t>(sizeof(RGBA8) * emptyData.size()), dawn::BufferUsageBit::TransferSrc);
cmdBuilder.CopyBufferToTexture(uploadBuffer, 0, rowPitch, texture, 0, 0, 0, width, height, 1, textureSpec.level, 0);
dawn::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(uploadBuffer, 0, rowPitch, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
texture, textureSpec.level, 0, {0, 0, 0}, dawn::TextureAspect::Color);
dawn::Extent3D copySize = {width, height, 1};
cmdBuilder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
}
// Copy to the region [(`x`, `y`), (`x + copyWidth, `y + copyWidth`)] at the `level` mip from the buffer at the specified `offset` and `rowPitch`
cmdBuilder.CopyBufferToTexture(buffer, bufferSpec.offset, bufferSpec.rowPitch, texture, textureSpec.x, textureSpec.y, 0, textureSpec.copyWidth, textureSpec.copyHeight, 1, textureSpec.level, 0);
{
dawn::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(buffer, bufferSpec.offset, bufferSpec.rowPitch, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
texture, textureSpec.level, 0, {textureSpec.x, textureSpec.y, 0},
dawn::TextureAspect::Color);
dawn::Extent3D copySize = {textureSpec.copyWidth, textureSpec.copyHeight, 1};
cmdBuilder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
}
dawn::CommandBuffer commands = cmdBuilder.GetResult();
queue.Submit(1, &commands);

View File

@@ -100,9 +100,14 @@ protected:
data[1] = data[rowPixels] = white;
dawn::Buffer stagingBuffer = utils::CreateBufferFromData(device, data, sizeof(data), dawn::BufferUsageBit::TransferSrc);
dawn::CommandBuffer copy = device.CreateCommandBufferBuilder()
.CopyBufferToTexture(stagingBuffer, 0, 256, texture, 0, 0, 0, 2, 2, 1, 0, 0)
.GetResult();
dawn::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(stagingBuffer, 0, 256, 0);
dawn::TextureCopyView textureCopyView =
utils::CreateTextureCopyView(texture, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color);
dawn::Extent3D copySize = {2, 2, 1};
dawn::CommandBuffer copy =
device.CreateCommandBufferBuilder()
.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize)
.GetResult();
queue.Submit(1, &copy);
mTextureView = texture.CreateDefaultTextureView();

View File

@@ -124,9 +124,12 @@ protected:
dawn::Buffer stagingBuffer = utils::CreateBufferFromData(
device, data.data(), data.size() * sizeof(RGBA8),
dawn::BufferUsageBit::TransferSrc);
builder.CopyBufferToTexture(
stagingBuffer, 0, kTextureRowPitchAlignment, mTexture, 0, 0, 0, texWidth,
texHeight, 1, level, layer);
dawn::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(stagingBuffer, 0, kTextureRowPitchAlignment, 0);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
mTexture, level, layer, {0, 0, 0}, dawn::TextureAspect::Color);
dawn::Extent3D copySize = {texWidth, texHeight, 1};
builder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &copySize);
}
}
dawn::CommandBuffer copy = builder.GetResult();

View File

@@ -15,6 +15,7 @@
#include "common/Constants.h"
#include "common/Math.h"
#include "tests/unittests/validation/ValidationTest.h"
#include "utils/DawnHelpers.h"
class CopyCommandTest : public ValidationTest {
protected:
@@ -45,6 +46,64 @@ class CopyCommandTest : public ValidationTest {
uint32_t rowPitch = Align(width * 4, kTextureRowPitchAlignment);
return (rowPitch * (height - 1) + width) * depth;
}
void TestB2TCopy(utils::Expectation expectation,
dawn::Buffer srcBuffer,
uint32_t srcOffset,
uint32_t srcRowPitch,
uint32_t srcImageHeight,
dawn::Texture destTexture,
uint32_t destLevel,
uint32_t destSlice,
dawn::Origin3D destOrigin,
dawn::TextureAspect destAspect,
dawn::Extent3D extent3D) {
dawn::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(srcBuffer, srcOffset, srcRowPitch, srcImageHeight);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
destTexture, destLevel, destSlice, destOrigin, destAspect);
if (expectation == utils::Expectation::Success) {
dawn::CommandBuffer commands =
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &extent3D)
.GetResult();
} else {
dawn::CommandBuffer commands =
AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &extent3D)
.GetResult();
}
}
void TestT2BCopy(utils::Expectation expectation,
dawn::Texture srcTexture,
uint32_t srcLevel,
uint32_t srcSlice,
dawn::Origin3D srcOrigin,
dawn::TextureAspect srcAspect,
dawn::Buffer destBuffer,
uint32_t destOffset,
uint32_t destRowPitch,
uint32_t destImageHeight,
dawn::Extent3D extent3D) {
dawn::BufferCopyView bufferCopyView =
utils::CreateBufferCopyView(destBuffer, destOffset, destRowPitch, destImageHeight);
dawn::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
srcTexture, srcLevel, srcSlice, srcOrigin, srcAspect);
if (expectation == utils::Expectation::Success) {
dawn::CommandBuffer commands =
AssertWillBeSuccess(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &extent3D)
.GetResult();
} else {
dawn::CommandBuffer commands =
AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &extent3D)
.GetResult();
}
}
};
class CopyCommandTest_B2B : public CopyCommandTest {
@@ -129,40 +188,44 @@ TEST_F(CopyCommandTest_B2T, Success) {
// Different copies, including some that touch the OOB condition
{
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
// Copy 4x4 block in corner of first mip.
.CopyBufferToTexture(source, 0, 256, destination, 0, 0, 0, 4, 4, 1, 0, 0)
// Copy 4x4 block in opposite corner of first mip.
.CopyBufferToTexture(source, 0, 256, destination, 12, 12, 0, 4, 4, 1, 0, 0)
// Copy 4x4 block in the 4x4 mip.
.CopyBufferToTexture(source, 0, 256, destination, 0, 0, 0, 4, 4, 1, 2, 0)
// Copy with a buffer offset
.CopyBufferToTexture(source, bufferSize - 4, 256, destination, 0, 0, 0, 1, 1, 1, 0, 0)
.GetResult();
// Copy 4x4 block in corner of first mip.
TestB2TCopy(utils::Expectation::Success, source, 0, 256, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {4, 4, 1});
// Copy 4x4 block in opposite corner of first mip.
TestB2TCopy(utils::Expectation::Success, source, 0, 256, 0, destination, 0, 0, {12, 12, 0},
dawn::TextureAspect::Color, {4, 4, 1});
// Copy 4x4 block in the 4x4 mip.
TestB2TCopy(utils::Expectation::Success, source, 0, 256, 0, destination, 2, 0, {0, 0, 0},
dawn::TextureAspect::Color, {4, 4, 1});
// Copy with a buffer offset
TestB2TCopy(utils::Expectation::Success, source, bufferSize - 4, 256, 0, destination, 0, 0,
{0, 0, 0}, dawn::TextureAspect::Color, {1, 1, 1});
}
// Copies with a 256-byte aligned row pitch but unaligned texture region
{
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
// Unaligned region
.CopyBufferToTexture(source, 0, 256, destination, 0, 0, 0, 3, 4, 1, 0, 0)
// Unaligned region with texture offset
.CopyBufferToTexture(source, 0, 256, destination, 5, 7, 0, 2, 3, 1, 0, 0)
// Unaligned region, with buffer offset
.CopyBufferToTexture(source, 31 * 4, 256, destination, 0, 0, 0, 3, 3, 1, 0, 0)
.GetResult();
// Unaligned region
TestB2TCopy(utils::Expectation::Success, source, 0, 256, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {3, 4, 1});
// Unaligned region with texture offset
TestB2TCopy(utils::Expectation::Success, source, 0, 256, 0, destination, 0, 0, {5, 7, 0},
dawn::TextureAspect::Color, {2, 3, 1});
// Unaligned region, with buffer offset
TestB2TCopy(utils::Expectation::Success, source, 31 * 4, 256, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {3, 3, 1});
}
// Empty copies are valid
{
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
// An empty copy
.CopyBufferToTexture(source, 0, 0, destination, 0, 0, 0, 0, 0, 1, 0, 0)
// An empty copy touching the end of the buffer
.CopyBufferToTexture(source, bufferSize, 0, destination, 0, 0, 0, 0, 0, 1, 0, 0)
// An empty copy touching the side of the texture
.CopyBufferToTexture(source, 0, 0, destination, 16, 16, 0, 0, 0, 1, 0, 0)
.GetResult();
// An empty copy
TestB2TCopy(utils::Expectation::Success, source, 0, 0, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {0, 0, 1});
// An empty copy touching the end of the buffer
TestB2TCopy(utils::Expectation::Success, source, bufferSize, 0, 0, destination, 0, 0, {0, 0,
0}, dawn::TextureAspect::Color, {0, 0, 1});
// An empty copy touching the side of the texture
TestB2TCopy(utils::Expectation::Success, source, 0, 0, 0, destination, 0, 0, {16, 16, 0},
dawn::TextureAspect::Color, {0, 0, 1});
}
}
@@ -174,25 +237,16 @@ TEST_F(CopyCommandTest_B2T, OutOfBoundsOnBuffer) {
dawn::TextureUsageBit::TransferDst);
// OOB on the buffer because we copy too many pixels
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 256, destination, 0, 0, 0, 4, 5, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {4, 5, 1});
// OOB on the buffer because of the offset
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 4, 256, destination, 0, 0, 0, 4, 4, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 4, 256, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {4, 4, 1});
// OOB on the buffer because (row pitch * (height - 1) + width) * depth overflows
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 512, destination, 0, 0, 0, 4, 3, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 512, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {4, 3, 1});
// Not OOB on the buffer although row pitch * height overflows
// but (row pitch * (height - 1) + width) * depth does not overlow
@@ -200,9 +254,9 @@ TEST_F(CopyCommandTest_B2T, OutOfBoundsOnBuffer) {
uint32_t sourceBufferSize = BufferSizeForTextureCopy(7, 3, 1);
ASSERT_TRUE(256 * 3 > sourceBufferSize) << "row pitch * height should overflow buffer";
dawn::Buffer sourceBuffer = CreateBuffer(sourceBufferSize, dawn::BufferUsageBit::TransferSrc);
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(sourceBuffer, 0, 256, destination, 0, 0, 0, 7, 3, 1, 0, 0)
.GetResult();
TestB2TCopy(utils::Expectation::Success, source, 0, 256, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {7, 3, 1});
}
}
@@ -214,39 +268,24 @@ TEST_F(CopyCommandTest_B2T, OutOfBoundsOnTexture) {
dawn::TextureUsageBit::TransferDst);
// OOB on the texture because x + width overflows
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 256, destination, 13, 12, 0, 4, 4, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 0, 0, {13, 12, 0},
dawn::TextureAspect::Color, {4, 4, 1});
// OOB on the texture because y + width overflows
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 256, destination, 12, 13, 0, 4, 4, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 0, 0, {12, 13, 0},
dawn::TextureAspect::Color, {4, 4, 1});
// OOB on the texture because we overflow a non-zero mip
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 256, destination, 1, 0, 0, 4, 4, 1, 2, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 2, 0, {1, 0, 0},
dawn::TextureAspect::Color, {4, 4, 1});
// OOB on the texture even on an empty copy when we copy to a non-existent mip.
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 0, destination, 0, 0, 0, 0, 0, 1, 5, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 0, 0, destination, 5, 0, {0, 0, 0},
dawn::TextureAspect::Color, {0, 0, 1});
// OOB on the texture because slice overflows
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 0, destination, 0, 0, 0, 0, 0, 1, 0, 2)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 0, 0, destination, 0, 2, {0, 0, 0},
dawn::TextureAspect::Color, {0, 0, 1});
}
// Test that we force Z=0 and Depth=1 on copies to 2D textures
@@ -256,18 +295,12 @@ TEST_F(CopyCommandTest_B2T, ZDepthConstraintFor2DTextures) {
dawn::TextureUsageBit::TransferDst);
// Z=1 on an empty copy still errors
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 0, destination, 0, 0, 1, 0, 0, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 0, 0, destination, 0, 0, {0, 0, 1},
dawn::TextureAspect::Color, {0, 0, 1});
// Depth=0 on an empty copy still errors
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 0, destination, 0, 0, 0, 0, 0, 0, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 0, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {0, 0, 0});
}
// Test B2T copies with incorrect buffer usage
@@ -280,18 +313,12 @@ TEST_F(CopyCommandTest_B2T, IncorrectUsage) {
dawn::TextureUsageBit::Sampled);
// Incorrect source usage
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(vertex, 0, 256, destination, 0, 0, 0, 4, 4, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, vertex, 0, 256, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {4, 4, 1});
// Incorrect destination usage
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 256, sampled, 0, 0, 0, 4, 4, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, sampled, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {4, 4, 1});
}
TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) {
@@ -301,25 +328,16 @@ TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) {
dawn::TextureUsageBit::TransferDst);
// Default row pitch is not 256-byte aligned
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 0, destination, 0, 0, 0, 3, 4, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 0, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {3, 4, 1});
// Row pitch is not 256-byte aligned
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 128, destination, 0, 0, 0, 4, 4, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 128, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {4, 4, 1});
// Row pitch is less than width * bytesPerPixel
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, 0, 256, destination, 0, 0, 0, 65, 1, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 0, 0, {0, 0, 0},
dawn::TextureAspect::Color, {65, 1, 1});
}
// Test B2T copies with incorrect buffer offset usage
@@ -330,26 +348,17 @@ TEST_F(CopyCommandTest_B2T, IncorrectBufferOffset) {
dawn::TextureUsageBit::TransferDst);
// Correct usage
{
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, bufferSize - 4, 256, destination, 0, 0, 0, 1, 1, 1, 0, 0)
.GetResult();
}
TestB2TCopy(utils::Expectation::Success, source, bufferSize - 4, 256, 0, destination, 0, 0, {0,
0, 0}, dawn::TextureAspect::Color, {1, 1, 1});
// Incorrect usages
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, bufferSize - 5, 256, destination, 0, 0, 0, 1, 1, 1, 0, 0)
.GetResult();
}
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, bufferSize - 6, 256, destination, 0, 0, 0, 1, 1, 1, 0, 0)
.GetResult();
}
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyBufferToTexture(source, bufferSize - 7, 256, destination, 0, 0, 0, 1, 1, 1, 0, 0)
.GetResult();
TestB2TCopy(utils::Expectation::Failure, source, bufferSize - 5, 256, 0, destination, 0, 0,
{0, 0, 0}, dawn::TextureAspect::Color, {1, 1, 1});
TestB2TCopy(utils::Expectation::Failure, source, bufferSize - 6, 256, 0, destination, 0, 0,
{0, 0, 0}, dawn::TextureAspect::Color, {1, 1, 1});
TestB2TCopy(utils::Expectation::Failure, source, bufferSize - 7, 256, 0, destination, 0, 0,
{0, 0, 0}, dawn::TextureAspect::Color, {1, 1, 1});
}
}
@@ -365,40 +374,44 @@ TEST_F(CopyCommandTest_T2B, Success) {
// Different copies, including some that touch the OOB condition
{
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
// Copy from 4x4 block in corner of first mip.
.CopyTextureToBuffer(source, 0, 0, 0, 4, 4, 1, 0, 0, destination, 0, 256)
// Copy from 4x4 block in opposite corner of first mip.
.CopyTextureToBuffer(source, 12, 12, 0, 4, 4, 1, 0, 0, destination, 0, 256)
// Copy from 4x4 block in the 4x4 mip.
.CopyTextureToBuffer(source, 0, 0, 0, 4, 4, 1, 2, 0, destination, 0, 256)
// Copy with a buffer offset
.CopyTextureToBuffer(source, 0, 0, 0, 1, 1, 1, 0, 0, destination, bufferSize - 4, 256)
.GetResult();
// Copy from 4x4 block in corner of first mip.
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {4, 4, 1});
// Copy from 4x4 block in opposite corner of first mip.
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {12, 12, 0},
dawn::TextureAspect::Color, destination, 0, 256, 0, {4, 4, 1});
// Copy from 4x4 block in the 4x4 mip.
TestT2BCopy(utils::Expectation::Success, source, 2, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {4, 4, 1});
// Copy with a buffer offset
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, bufferSize - 4, 256, 0, {1, 1, 1});
}
// Copies with a 256-byte aligned row pitch but unaligned texture region
{
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
// Unaligned region
.CopyTextureToBuffer(source, 0, 0, 0, 3, 4, 1, 0, 0, destination, 0, 256)
// Unaligned region with texture offset
.CopyTextureToBuffer(source, 5, 7, 0, 2, 3, 1, 0, 0, destination, 0, 256)
// Unaligned region, with buffer offset
.CopyTextureToBuffer(source, 0, 0, 0, 3, 3, 1, 2, 0, destination, 31 * 4, 256)
.GetResult();
// Unaligned region
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {3, 4, 1});
// Unaligned region with texture offset
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {5, 7, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {2, 3, 1});
// Unaligned region, with buffer offset
TestT2BCopy(utils::Expectation::Success, source, 2, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 31 * 4, 256, 0, {3, 3, 1});
}
// Empty copies are valid
{
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
// An empty copy
.CopyTextureToBuffer(source, 0, 0, 0, 0, 0, 1, 0, 0, destination, 0, 0)
// An empty copy touching the end of the buffer
.CopyTextureToBuffer(source, 0, 0, 0, 0, 0, 1, 0, 0, destination, bufferSize, 0)
// An empty copy touching the side of the texture
.CopyTextureToBuffer(source, 16, 16, 0, 0, 0, 1, 0, 0, destination, 0, 0)
.GetResult();
// An empty copy
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 0, 0, {0, 0, 1});
// An empty copy touching the end of the buffer
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, bufferSize, 0, 0, {0, 0, 1});
// An empty copy touching the side of the texture
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {16, 16, 0},
dawn::TextureAspect::Color, destination, 0, 0, 0, {0, 0, 1});
}
}
@@ -410,32 +423,20 @@ TEST_F(CopyCommandTest_T2B, OutOfBoundsOnTexture) {
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
// OOB on the texture because x + width overflows
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 13, 12, 0, 4, 4, 1, 0, 0, destination, 0, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {13, 12, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {4, 4, 1});
// OOB on the texture because y + width overflows
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 12, 13, 0, 4, 4, 1, 0, 0, destination, 0, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {12, 13, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {4, 4, 1});
// OOB on the texture because we overflow a non-zero mip
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 1, 0, 0, 4, 4, 1, 2, 0, destination, 0, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 2, 0, {1, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {4, 4, 1});
// OOB on the texture even on an empty copy when we copy from a non-existent mip.
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 0, 0, 1, 5, 0, destination, 0, 0)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 5, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 0, 0, {0, 0, 1});
}
// Test OOB conditions on the buffer
@@ -446,25 +447,16 @@ TEST_F(CopyCommandTest_T2B, OutOfBoundsOnBuffer) {
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
// OOB on the buffer because we copy too many pixels
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 4, 5, 1, 0, 0, destination, 0, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {4, 5, 1});
// OOB on the buffer because of the offset
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 4, 4, 1, 0, 0, destination, 4, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 4, 256, 0, {4, 4, 1});
// OOB on the buffer because (row pitch * (height - 1) + width) * depth overflows
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 4, 3, 1, 0, 0, destination, 0, 512)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 512, 0, {4, 3, 1});
// Not OOB on the buffer although row pitch * height overflows
// but (row pitch * (height - 1) + width) * depth does not overlow
@@ -472,9 +464,8 @@ TEST_F(CopyCommandTest_T2B, OutOfBoundsOnBuffer) {
uint32_t destinationBufferSize = BufferSizeForTextureCopy(7, 3, 1);
ASSERT_TRUE(256 * 3 > destinationBufferSize) << "row pitch * height should overflow buffer";
dawn::Buffer destinationBuffer = CreateBuffer(destinationBufferSize, dawn::BufferUsageBit::TransferDst);
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 7, 3, 1, 0, 0, destinationBuffer, 0, 256)
.GetResult();
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destinationBuffer, 0, 256, 0, {7, 3, 1});
}
}
@@ -486,18 +477,12 @@ TEST_F(CopyCommandTest_T2B, ZDepthConstraintFor2DTextures) {
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
// Z=1 on an empty copy still errors
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 1, 0, 0, 1, 0, 0, destination, 0, 0)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 1}, dawn::TextureAspect::Color,
destination, 0, 0, 0, {0, 0, 1});
// Depth=0 on an empty copy still errors
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 0, 0, 0, 0, 0, destination, 0, 0)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 0, 0, {0, 0, 0});
}
// Test T2B copies with incorrect buffer usage
@@ -511,18 +496,12 @@ TEST_F(CopyCommandTest_T2B, IncorrectUsage) {
dawn::Buffer vertex = CreateBuffer(bufferSize, dawn::BufferUsageBit::Vertex);
// Incorrect source usage
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(sampled, 0, 0, 0, 4, 4, 1, 0, 0, destination, 0, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, sampled, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {4, 4, 1});
// Incorrect destination usage
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 4, 4, 1, 0, 0, vertex, 0, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
vertex, 0, 256, 0, {4, 4, 1});
}
TEST_F(CopyCommandTest_T2B, IncorrectRowPitch) {
@@ -532,25 +511,16 @@ TEST_F(CopyCommandTest_T2B, IncorrectRowPitch) {
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
// Default row pitch is not 256-byte aligned
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 3, 4, 1, 0, 0, destination, 0, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {3, 4, 1});
// Row pitch is not 256-byte aligned
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 4, 4, 1, 0, 0, destination, 0, 257)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 257, 0, {4, 4, 1});
// Row pitch is less than width * bytesPerPixel
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 65, 1, 1, 0, 0, destination, 0, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, 0, 256, 0, {65, 1, 1});
}
// Test T2B copies with incorrect buffer offset usage
@@ -561,26 +531,15 @@ TEST_F(CopyCommandTest_T2B, IncorrectBufferOffset) {
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
// Correct usage
{
dawn::CommandBuffer commands = AssertWillBeSuccess(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 1, 1, 1, 0, 0, destination, bufferSize - 4, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, bufferSize - 4, 256, 0, {1, 1, 1});
// Incorrect usages
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 1, 1, 1, 0, 0, destination, bufferSize - 5, 256)
.GetResult();
}
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 1, 1, 1, 0, 0, destination, bufferSize - 6, 256)
.GetResult();
}
{
dawn::CommandBuffer commands = AssertWillBeError(device.CreateCommandBufferBuilder())
.CopyTextureToBuffer(source, 0, 0, 0, 1, 1, 1, 0, 0, destination, bufferSize - 7, 256)
.GetResult();
}
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, bufferSize - 5, 256, 0, {1, 1, 1});
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, bufferSize - 6, 256, 0, {1, 1, 1});
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
destination, bufferSize - 7, 256, 0, {1, 1, 1});
}