mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-16 08:27:05 +00:00
Implement BufferCopyView.imageHeight Parameter
Implement BufferCopyView.imageHeight Parameter. Adds validation tests. Adequate functional testing not possible without 3D texture support. Bug: dawn:48 Change-Id: I00e4464eb451c948dee2890a11fb0984eff681a0 Reviewed-on: https://dawn-review.googlesource.com/c/2980 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:
committed by
Commit Bot service account
parent
a49242766a
commit
d86edb310a
@@ -37,6 +37,7 @@ namespace {
|
||||
struct BufferSpec {
|
||||
uint32_t offset;
|
||||
uint32_t rowPitch;
|
||||
uint32_t imageHeight;
|
||||
};
|
||||
|
||||
// Check that each copy region fits inside the buffer footprint
|
||||
@@ -119,7 +120,7 @@ namespace {
|
||||
const auto& copy = copySplit.copies[i];
|
||||
|
||||
uint32_t rowPitchInTexels = bufferSpec.rowPitch / textureSpec.texelSize;
|
||||
uint32_t slicePitchInTexels = rowPitchInTexels * copy.copySize.height;
|
||||
uint32_t slicePitchInTexels = rowPitchInTexels * bufferSpec.imageHeight;
|
||||
uint32_t absoluteTexelOffset = copySplit.offset / textureSpec.texelSize + copy.bufferOffset.x + copy.bufferOffset.y * rowPitchInTexels + copy.bufferOffset.z * slicePitchInTexels;
|
||||
|
||||
ASSERT(absoluteTexelOffset >= bufferSpec.offset / textureSpec.texelSize);
|
||||
@@ -153,7 +154,8 @@ namespace {
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const BufferSpec& bufferSpec) {
|
||||
os << "BufferSpec(" << bufferSpec.offset << ", " << bufferSpec.rowPitch << ")";
|
||||
os << "BufferSpec(" << bufferSpec.offset << ", " << bufferSpec.rowPitch << ", "
|
||||
<< bufferSpec.imageHeight << ")";
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -169,22 +171,25 @@ namespace {
|
||||
|
||||
// Define base texture sizes and offsets to test with: some aligned, some unaligned
|
||||
constexpr TextureSpec kBaseTextureSpecs[] = {
|
||||
{ 0, 0, 0, 1, 1, 1, 4 },
|
||||
{ 31, 16, 0, 1, 1, 1, 4 },
|
||||
{ 64, 16, 0, 1, 1, 1, 4 },
|
||||
{0, 0, 0, 1, 1, 1, 4},
|
||||
{31, 16, 0, 1, 1, 1, 4},
|
||||
{64, 16, 0, 1, 1, 1, 4},
|
||||
{64, 16, 8, 1, 1, 1, 4},
|
||||
|
||||
{ 0, 0, 0, 1024, 1024, 1, 4 },
|
||||
{ 256, 512, 0, 1024, 1024, 1, 4 },
|
||||
{ 64, 48, 0, 1024, 1024, 1, 4 },
|
||||
{0, 0, 0, 1024, 1024, 1, 4},
|
||||
{256, 512, 0, 1024, 1024, 1, 4},
|
||||
{64, 48, 0, 1024, 1024, 1, 4},
|
||||
{64, 48, 16, 1024, 1024, 1024, 4},
|
||||
|
||||
{ 0, 0, 0, 257, 31, 1, 4 },
|
||||
{ 0, 0, 0, 17, 93, 1, 4 },
|
||||
{ 59, 13, 0, 257, 31, 1, 4 },
|
||||
{ 17, 73, 0, 17, 93, 1, 4 },
|
||||
{0, 0, 0, 257, 31, 1, 4},
|
||||
{0, 0, 0, 17, 93, 1, 4},
|
||||
{59, 13, 0, 257, 31, 1, 4},
|
||||
{17, 73, 0, 17, 93, 1, 4},
|
||||
{17, 73, 59, 17, 93, 99, 4},
|
||||
};
|
||||
|
||||
// Define base buffer sizes to work with: some offsets aligned, some unaligned. rowPitch is the minimum required
|
||||
std::array<BufferSpec, 10> BaseBufferSpecs(const TextureSpec& textureSpec) {
|
||||
std::array<BufferSpec, 13> BaseBufferSpecs(const TextureSpec& textureSpec) {
|
||||
uint32_t rowPitch = Align(textureSpec.texelSize * textureSpec.width, kTextureRowPitchAlignment);
|
||||
|
||||
auto alignNonPow2 = [](uint32_t value, uint32_t size) -> uint32_t {
|
||||
@@ -192,18 +197,21 @@ namespace {
|
||||
};
|
||||
|
||||
return {
|
||||
BufferSpec{alignNonPow2(0, textureSpec.texelSize), rowPitch},
|
||||
BufferSpec{alignNonPow2(512, textureSpec.texelSize), rowPitch},
|
||||
BufferSpec{alignNonPow2(1024, textureSpec.texelSize), rowPitch},
|
||||
BufferSpec{alignNonPow2(0, textureSpec.texelSize), rowPitch, textureSpec.height},
|
||||
BufferSpec{alignNonPow2(512, textureSpec.texelSize), rowPitch, textureSpec.height},
|
||||
BufferSpec{alignNonPow2(1024, textureSpec.texelSize), rowPitch, textureSpec.height},
|
||||
BufferSpec{alignNonPow2(1024, textureSpec.texelSize), rowPitch, textureSpec.height * 2},
|
||||
|
||||
BufferSpec{alignNonPow2(32, textureSpec.texelSize), rowPitch},
|
||||
BufferSpec{alignNonPow2(64, textureSpec.texelSize), rowPitch},
|
||||
BufferSpec{alignNonPow2(32, textureSpec.texelSize), rowPitch, textureSpec.height},
|
||||
BufferSpec{alignNonPow2(64, textureSpec.texelSize), rowPitch, textureSpec.height},
|
||||
BufferSpec{alignNonPow2(64, textureSpec.texelSize), rowPitch, textureSpec.height * 2},
|
||||
|
||||
BufferSpec{alignNonPow2(31, textureSpec.texelSize), rowPitch},
|
||||
BufferSpec{alignNonPow2(257, textureSpec.texelSize), rowPitch},
|
||||
BufferSpec{alignNonPow2(511, textureSpec.texelSize), rowPitch},
|
||||
BufferSpec{alignNonPow2(513, textureSpec.texelSize), rowPitch},
|
||||
BufferSpec{alignNonPow2(1023, textureSpec.texelSize), rowPitch},
|
||||
BufferSpec{alignNonPow2(31, textureSpec.texelSize), rowPitch, textureSpec.height},
|
||||
BufferSpec{alignNonPow2(257, textureSpec.texelSize), rowPitch, textureSpec.height},
|
||||
BufferSpec{alignNonPow2(511, textureSpec.texelSize), rowPitch, textureSpec.height},
|
||||
BufferSpec{alignNonPow2(513, textureSpec.texelSize), rowPitch, textureSpec.height},
|
||||
BufferSpec{alignNonPow2(1023, textureSpec.texelSize), rowPitch, textureSpec.height},
|
||||
BufferSpec{alignNonPow2(1023, textureSpec.texelSize), rowPitch, textureSpec.height * 2},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -223,7 +231,7 @@ class CopySplitTest : public testing::Test {
|
||||
TextureCopySplit copySplit = ComputeTextureCopySplit(
|
||||
{textureSpec.x, textureSpec.y, textureSpec.z},
|
||||
{textureSpec.width, textureSpec.height, textureSpec.depth}, textureSpec.texelSize,
|
||||
bufferSpec.offset, bufferSpec.rowPitch);
|
||||
bufferSpec.offset, bufferSpec.rowPitch, bufferSpec.imageHeight);
|
||||
ValidateCopySplit(textureSpec, bufferSpec, copySplit);
|
||||
return copySplit;
|
||||
}
|
||||
@@ -370,3 +378,23 @@ TEST_F(CopySplitTest, RowPitch) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(CopySplitTest, ImageHeight) {
|
||||
for (TextureSpec textureSpec : kBaseTextureSpecs) {
|
||||
for (BufferSpec bufferSpec : BaseBufferSpecs(textureSpec)) {
|
||||
uint32_t baseImageHeight = bufferSpec.imageHeight;
|
||||
for (uint32_t i = 0; i < 5; ++i) {
|
||||
bufferSpec.imageHeight = baseImageHeight + i * 256;
|
||||
|
||||
TextureCopySplit copySplit = DoTest(textureSpec, bufferSpec);
|
||||
if (HasFatalFailure()) {
|
||||
std::ostringstream message;
|
||||
message << "Failed generating splits: " << textureSpec << ", " << bufferSpec
|
||||
<< std::endl
|
||||
<< copySplit << std::endl;
|
||||
FAIL() << message.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -340,6 +340,29 @@ TEST_F(CopyCommandTest_B2T, IncorrectRowPitch) {
|
||||
dawn::TextureAspect::Color, {65, 1, 1});
|
||||
}
|
||||
|
||||
TEST_F(CopyCommandTest_B2T, ImageHeightConstraint) {
|
||||
uint32_t bufferSize = BufferSizeForTextureCopy(5, 5, 1);
|
||||
dawn::Buffer source = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferSrc);
|
||||
dawn::Texture destination = Create2DTexture(16, 16, 1, 1, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferDst);
|
||||
|
||||
// Image height is zero (Valid)
|
||||
TestB2TCopy(utils::Expectation::Success, source, 0, 256, 0, destination, 0, 0, {0, 0, 0},
|
||||
dawn::TextureAspect::Color, {4, 4, 1});
|
||||
|
||||
// Image height is equal to copy height (Valid)
|
||||
TestB2TCopy(utils::Expectation::Success, source, 0, 256, 0, destination, 0, 0, {0, 0, 0},
|
||||
dawn::TextureAspect::Color, {4, 4, 1});
|
||||
|
||||
// Image height is larger than copy height (Valid)
|
||||
TestB2TCopy(utils::Expectation::Success, source, 0, 256, 4, destination, 0, 0, {0, 0, 0},
|
||||
dawn::TextureAspect::Color, {4, 4, 1});
|
||||
|
||||
// Image height is less than copy height (Invalid)
|
||||
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 3, destination, 0, 0, {0, 0, 0},
|
||||
dawn::TextureAspect::Color, {4, 4, 1});
|
||||
}
|
||||
|
||||
// Test B2T copies with incorrect buffer offset usage
|
||||
TEST_F(CopyCommandTest_B2T, IncorrectBufferOffset) {
|
||||
uint32_t bufferSize = BufferSizeForTextureCopy(4, 4, 1);
|
||||
@@ -523,6 +546,29 @@ TEST_F(CopyCommandTest_T2B, IncorrectRowPitch) {
|
||||
destination, 0, 256, 0, {65, 1, 1});
|
||||
}
|
||||
|
||||
TEST_F(CopyCommandTest_T2B, ImageHeightConstraint) {
|
||||
uint32_t bufferSize = BufferSizeForTextureCopy(5, 5, 1);
|
||||
dawn::Texture source = Create2DTexture(16, 16, 1, 1, dawn::TextureFormat::R8G8B8A8Unorm,
|
||||
dawn::TextureUsageBit::TransferSrc);
|
||||
dawn::Buffer destination = CreateBuffer(bufferSize, dawn::BufferUsageBit::TransferDst);
|
||||
|
||||
// Image height is zero (Valid)
|
||||
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
|
||||
destination, 0, 256, 0, {4, 4, 1});
|
||||
|
||||
// Image height is equal to copy height (Valid)
|
||||
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
|
||||
destination, 0, 256, 4, {4, 4, 1});
|
||||
|
||||
// Image height exceeds copy height (Valid)
|
||||
TestT2BCopy(utils::Expectation::Success, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
|
||||
destination, 0, 256, 5, {4, 4, 1});
|
||||
|
||||
// Image height is less than copy height (Invalid)
|
||||
TestT2BCopy(utils::Expectation::Failure, source, 0, 0, {0, 0, 0}, dawn::TextureAspect::Color,
|
||||
destination, 0, 256, 3, {4, 4, 1});
|
||||
}
|
||||
|
||||
// Test T2B copies with incorrect buffer offset usage
|
||||
TEST_F(CopyCommandTest_T2B, IncorrectBufferOffset) {
|
||||
uint32_t bufferSize = BufferSizeForTextureCopy(128, 16, 1);
|
||||
|
||||
Reference in New Issue
Block a user