mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 15:46:28 +00:00
Add texture aspect to texture copy view and validation tests
Bug: dawn:439 Change-Id: I0ca283f58fe2b63ac3a8c468f8ea1bb2d300856f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24683 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Jiawei Shao <jiawei.shao@intel.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
b8a56af176
commit
0d9fce100d
@@ -75,11 +75,12 @@ class CopyCommandTest : public ValidationTest {
|
||||
wgpu::Texture destTexture,
|
||||
uint32_t destLevel,
|
||||
wgpu::Origin3D destOrigin,
|
||||
wgpu::Extent3D extent3D) {
|
||||
wgpu::Extent3D extent3D,
|
||||
wgpu::TextureAspect aspect = wgpu::TextureAspect::All) {
|
||||
wgpu::BufferCopyView bufferCopyView =
|
||||
utils::CreateBufferCopyView(srcBuffer, srcOffset, srcBytesPerRow, srcRowsPerImage);
|
||||
wgpu::TextureCopyView textureCopyView =
|
||||
utils::CreateTextureCopyView(destTexture, destLevel, destOrigin);
|
||||
utils::CreateTextureCopyView(destTexture, destLevel, destOrigin, aspect);
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, &extent3D);
|
||||
@@ -95,11 +96,12 @@ class CopyCommandTest : public ValidationTest {
|
||||
uint64_t destOffset,
|
||||
uint32_t destBytesPerRow,
|
||||
uint32_t destRowsPerImage,
|
||||
wgpu::Extent3D extent3D) {
|
||||
wgpu::Extent3D extent3D,
|
||||
wgpu::TextureAspect aspect = wgpu::TextureAspect::All) {
|
||||
wgpu::BufferCopyView bufferCopyView =
|
||||
utils::CreateBufferCopyView(destBuffer, destOffset, destBytesPerRow, destRowsPerImage);
|
||||
wgpu::TextureCopyView textureCopyView =
|
||||
utils::CreateTextureCopyView(srcTexture, srcLevel, srcOrigin);
|
||||
utils::CreateTextureCopyView(srcTexture, srcLevel, srcOrigin, aspect);
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, &extent3D);
|
||||
@@ -114,11 +116,12 @@ class CopyCommandTest : public ValidationTest {
|
||||
wgpu::Texture dstTexture,
|
||||
uint32_t dstLevel,
|
||||
wgpu::Origin3D dstOrigin,
|
||||
wgpu::Extent3D extent3D) {
|
||||
wgpu::Extent3D extent3D,
|
||||
wgpu::TextureAspect aspect = wgpu::TextureAspect::All) {
|
||||
wgpu::TextureCopyView srcTextureCopyView =
|
||||
utils::CreateTextureCopyView(srcTexture, srcLevel, srcOrigin);
|
||||
utils::CreateTextureCopyView(srcTexture, srcLevel, srcOrigin, aspect);
|
||||
wgpu::TextureCopyView dstTextureCopyView =
|
||||
utils::CreateTextureCopyView(dstTexture, dstLevel, dstOrigin);
|
||||
utils::CreateTextureCopyView(dstTexture, dstLevel, dstOrigin, aspect);
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
encoder.CopyTextureToTexture(&srcTextureCopyView, &dstTextureCopyView, &extent3D);
|
||||
@@ -682,6 +685,83 @@ TEST_F(CopyCommandTest_B2T, CopyToMipmapOfNonSquareTexture) {
|
||||
{0, 0, 0}, {2, 2, 1});
|
||||
}
|
||||
|
||||
// Test it is invalid to copy to a depth texture
|
||||
TEST_F(CopyCommandTest_B2T, CopyToDepthAspect) {
|
||||
// Test it is invalid to copy from a buffer into Depth32Float
|
||||
{
|
||||
uint64_t bufferSize = BufferSizeForTextureCopy(16, 16, 1, wgpu::TextureFormat::R32Float);
|
||||
wgpu::Buffer source = CreateBuffer(bufferSize, wgpu::BufferUsage::CopySrc);
|
||||
|
||||
wgpu::Texture destination = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::Depth32Float,
|
||||
wgpu::TextureUsage::CopyDst);
|
||||
|
||||
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 0, {0, 0, 0},
|
||||
{16, 16, 1}, wgpu::TextureAspect::All);
|
||||
|
||||
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 0, {0, 0, 0},
|
||||
{16, 16, 1}, wgpu::TextureAspect::DepthOnly);
|
||||
}
|
||||
|
||||
// Test it is invalid to copy from a buffer into Depth24Plus
|
||||
{
|
||||
uint64_t bufferSize = BufferSizeForTextureCopy(16, 16, 1, wgpu::TextureFormat::R32Float);
|
||||
wgpu::Buffer source = CreateBuffer(bufferSize, wgpu::BufferUsage::CopySrc);
|
||||
|
||||
wgpu::Texture destination = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::Depth24Plus,
|
||||
wgpu::TextureUsage::CopyDst);
|
||||
|
||||
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 0, {0, 0, 0},
|
||||
{16, 16, 1}, wgpu::TextureAspect::All);
|
||||
|
||||
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 0, {0, 0, 0},
|
||||
{16, 16, 1}, wgpu::TextureAspect::DepthOnly);
|
||||
}
|
||||
}
|
||||
|
||||
// Test copy to only the stencil aspect of a texture
|
||||
TEST_F(CopyCommandTest_B2T, CopyToStencilAspect) {
|
||||
// Test it is valid to copy from a buffer into the stencil aspect of Depth24PlusStencil8
|
||||
{
|
||||
uint64_t bufferSize = BufferSizeForTextureCopy(16, 16, 1, wgpu::TextureFormat::R8Uint);
|
||||
wgpu::Buffer source = CreateBuffer(bufferSize, wgpu::BufferUsage::CopySrc);
|
||||
|
||||
wgpu::Texture destination = Create2DTexture(
|
||||
16, 16, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopyDst);
|
||||
|
||||
TestB2TCopy(utils::Expectation::Success, source, 0, 256, 0, destination, 0, {0, 0, 0},
|
||||
{16, 16, 1}, wgpu::TextureAspect::StencilOnly);
|
||||
|
||||
// And that it fails if the buffer is one byte too small
|
||||
wgpu::Buffer sourceSmall = CreateBuffer(bufferSize - 1, wgpu::BufferUsage::CopySrc);
|
||||
TestB2TCopy(utils::Expectation::Failure, sourceSmall, 0, 256, 0, destination, 0, {0, 0, 0},
|
||||
{16, 16, 1}, wgpu::TextureAspect::StencilOnly);
|
||||
}
|
||||
|
||||
// Test it is invalid to copy from a buffer into the stencil aspect of Depth24Plus (no stencil)
|
||||
{
|
||||
uint64_t bufferSize = BufferSizeForTextureCopy(16, 16, 1, wgpu::TextureFormat::R8Uint);
|
||||
wgpu::Buffer source = CreateBuffer(bufferSize, wgpu::BufferUsage::CopySrc);
|
||||
|
||||
wgpu::Texture destination = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::Depth24Plus,
|
||||
wgpu::TextureUsage::CopyDst);
|
||||
|
||||
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 0, {0, 0, 0},
|
||||
{16, 16, 1}, wgpu::TextureAspect::StencilOnly);
|
||||
}
|
||||
|
||||
// Test it is invalid to copy from a buffer into the stencil aspect of a color texture
|
||||
{
|
||||
uint64_t bufferSize = BufferSizeForTextureCopy(16, 16, 1, wgpu::TextureFormat::R8Uint);
|
||||
wgpu::Buffer source = CreateBuffer(bufferSize, wgpu::BufferUsage::CopySrc);
|
||||
|
||||
wgpu::Texture destination = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::RGBA8Uint,
|
||||
wgpu::TextureUsage::CopyDst);
|
||||
|
||||
TestB2TCopy(utils::Expectation::Failure, source, 0, 256, 0, destination, 0, {0, 0, 0},
|
||||
{16, 16, 1}, wgpu::TextureAspect::StencilOnly);
|
||||
}
|
||||
}
|
||||
|
||||
class CopyCommandTest_T2B : public CopyCommandTest {};
|
||||
|
||||
// Test a successfull T2B copy
|
||||
@@ -1010,6 +1090,83 @@ TEST_F(CopyCommandTest_T2B, CopyFromMipmapOfNonSquareTexture) {
|
||||
256, 0, {2, 1, 1});
|
||||
}
|
||||
|
||||
// Test copy from only the depth aspect of a texture
|
||||
TEST_F(CopyCommandTest_T2B, CopyFromDepthAspect) {
|
||||
uint64_t bufferSize = BufferSizeForTextureCopy(16, 16, 1, wgpu::TextureFormat::R32Float);
|
||||
wgpu::Buffer destination = CreateBuffer(bufferSize, wgpu::BufferUsage::CopyDst);
|
||||
{
|
||||
wgpu::Texture source = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::Depth32Float,
|
||||
wgpu::TextureUsage::CopySrc);
|
||||
|
||||
// Test "all" of a depth texture which is only the depth aspect.
|
||||
TestT2BCopy(utils::Expectation::Success, source, 0, {0, 0, 0}, destination, 0, 256, 0,
|
||||
{16, 16, 1}, wgpu::TextureAspect::All);
|
||||
|
||||
// Test it is valid to copy the depth aspect of a depth texture
|
||||
TestT2BCopy(utils::Expectation::Success, source, 0, {0, 0, 0}, destination, 0, 256, 0,
|
||||
{16, 16, 1}, wgpu::TextureAspect::DepthOnly);
|
||||
}
|
||||
{
|
||||
wgpu::Texture source = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::Depth24Plus,
|
||||
wgpu::TextureUsage::CopySrc);
|
||||
|
||||
// Test it is invalid to copy from the depth aspect of depth24plus
|
||||
TestT2BCopy(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0, 256, 0,
|
||||
{16, 16, 1}, wgpu::TextureAspect::DepthOnly);
|
||||
}
|
||||
{
|
||||
wgpu::Texture source = Create2DTexture(
|
||||
16, 16, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopySrc);
|
||||
|
||||
// Test it is invalid to copy from the depth aspect of depth24plus-stencil8
|
||||
TestT2BCopy(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0, 256, 0,
|
||||
{16, 16, 1}, wgpu::TextureAspect::DepthOnly);
|
||||
}
|
||||
{
|
||||
wgpu::Texture source = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::R32Float,
|
||||
wgpu::TextureUsage::CopySrc);
|
||||
|
||||
// Test it is invalid to copy from the depth aspect of a color texture
|
||||
TestT2BCopy(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0, 256, 0,
|
||||
{16, 16, 1}, wgpu::TextureAspect::DepthOnly);
|
||||
}
|
||||
}
|
||||
|
||||
// Test copy from only the stencil aspect of a texture
|
||||
TEST_F(CopyCommandTest_T2B, CopyFromStencilAspect) {
|
||||
uint64_t bufferSize = BufferSizeForTextureCopy(16, 16, 1, wgpu::TextureFormat::R8Uint);
|
||||
wgpu::Buffer destination = CreateBuffer(bufferSize, wgpu::BufferUsage::CopyDst);
|
||||
{
|
||||
wgpu::Texture source = Create2DTexture(
|
||||
16, 16, 1, 1, wgpu::TextureFormat::Depth24PlusStencil8, wgpu::TextureUsage::CopySrc);
|
||||
|
||||
// Test it is valid to copy from the stencil aspect of a depth24plus-stencil8 texture
|
||||
TestT2BCopy(utils::Expectation::Success, source, 0, {0, 0, 0}, destination, 0, 256, 0,
|
||||
{16, 16, 1}, wgpu::TextureAspect::StencilOnly);
|
||||
|
||||
// Test it is invalid if the buffer is too small
|
||||
wgpu::Buffer destinationSmall = CreateBuffer(bufferSize - 1, wgpu::BufferUsage::CopyDst);
|
||||
TestT2BCopy(utils::Expectation::Failure, source, 0, {0, 0, 0}, destinationSmall, 0, 256, 0,
|
||||
{16, 16, 1}, wgpu::TextureAspect::StencilOnly);
|
||||
}
|
||||
{
|
||||
wgpu::Texture source =
|
||||
Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::R8Uint, wgpu::TextureUsage::CopySrc);
|
||||
|
||||
// Test it is invalid to copy from the stencil aspect of a color texture
|
||||
TestT2BCopy(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0, 256, 0,
|
||||
{16, 16, 1}, wgpu::TextureAspect::StencilOnly);
|
||||
}
|
||||
{
|
||||
wgpu::Texture source = Create2DTexture(16, 16, 1, 1, wgpu::TextureFormat::Depth24Plus,
|
||||
wgpu::TextureUsage::CopySrc);
|
||||
|
||||
// Test it is invalid to copy from the stencil aspect of a depth-only texture
|
||||
TestT2BCopy(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0, 256, 0,
|
||||
{16, 16, 1}, wgpu::TextureAspect::StencilOnly);
|
||||
}
|
||||
}
|
||||
|
||||
class CopyCommandTest_T2T : public CopyCommandTest {};
|
||||
|
||||
TEST_F(CopyCommandTest_T2T, Success) {
|
||||
@@ -1164,6 +1321,14 @@ TEST_F(CopyCommandTest_T2T, 2DTextureDepthStencil) {
|
||||
// Failure when depth stencil subresource is partially copied
|
||||
TestT2TCopy(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0, {0, 0, 0},
|
||||
{15, 15, 1});
|
||||
|
||||
// Failure when selecting the depth aspect (not all)
|
||||
TestT2TCopy(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0, {0, 0, 0},
|
||||
{16, 16, 1}, wgpu::TextureAspect::DepthOnly);
|
||||
|
||||
// Failure when selecting the stencil aspect (not all)
|
||||
TestT2TCopy(utils::Expectation::Failure, source, 0, {0, 0, 0}, destination, 0, {0, 0, 0},
|
||||
{16, 16, 1}, wgpu::TextureAspect::StencilOnly);
|
||||
}
|
||||
|
||||
TEST_F(CopyCommandTest_T2T, 2DTextureArrayDepthStencil) {
|
||||
|
||||
@@ -53,7 +53,8 @@ namespace {
|
||||
wgpu::Texture texture,
|
||||
uint32_t texLevel,
|
||||
wgpu::Origin3D texOrigin,
|
||||
wgpu::Extent3D size) {
|
||||
wgpu::Extent3D size,
|
||||
wgpu::TextureAspect aspect = wgpu::TextureAspect::All) {
|
||||
std::vector<uint8_t> data(dataSize);
|
||||
|
||||
wgpu::TextureDataLayout textureDataLayout;
|
||||
@@ -62,7 +63,7 @@ namespace {
|
||||
textureDataLayout.rowsPerImage = dataRowsPerImage;
|
||||
|
||||
wgpu::TextureCopyView textureCopyView =
|
||||
utils::CreateTextureCopyView(texture, texLevel, texOrigin);
|
||||
utils::CreateTextureCopyView(texture, texLevel, texOrigin, aspect);
|
||||
|
||||
queue.WriteTexture(&textureCopyView, data.data(), dataSize, &textureDataLayout, &size);
|
||||
}
|
||||
@@ -402,6 +403,71 @@ namespace {
|
||||
{0, 0, 1}, {4, 2, 3});
|
||||
}
|
||||
|
||||
// Test it is invalid to write into a depth texture.
|
||||
TEST_F(QueueWriteTextureValidationTest, WriteToDepthAspect) {
|
||||
uint32_t bytesPerRow = sizeof(float) * 4;
|
||||
const uint64_t dataSize = utils::RequiredBytesInCopy(bytesPerRow, 0, {4, 4, 1},
|
||||
wgpu::TextureFormat::Depth32Float);
|
||||
|
||||
// Invalid to write into depth32float
|
||||
{
|
||||
wgpu::Texture destination = QueueWriteTextureValidationTest::Create2DTexture(
|
||||
{4, 4, 1}, 1, wgpu::TextureFormat::Depth32Float, wgpu::TextureUsage::CopyDst);
|
||||
|
||||
ASSERT_DEVICE_ERROR(TestWriteTexture(dataSize, 0, bytesPerRow, 0, destination, 0,
|
||||
{0, 0, 0}, {4, 4, 1}, wgpu::TextureAspect::All));
|
||||
|
||||
ASSERT_DEVICE_ERROR(TestWriteTexture(dataSize, 0, bytesPerRow, 0, destination, 0,
|
||||
{0, 0, 0}, {4, 4, 1},
|
||||
wgpu::TextureAspect::DepthOnly));
|
||||
}
|
||||
|
||||
// Invalid to write into depth24plus
|
||||
{
|
||||
wgpu::Texture destination = QueueWriteTextureValidationTest::Create2DTexture(
|
||||
{4, 4, 1}, 1, wgpu::TextureFormat::Depth24Plus, wgpu::TextureUsage::CopyDst);
|
||||
|
||||
ASSERT_DEVICE_ERROR(TestWriteTexture(dataSize, 0, bytesPerRow, 0, destination, 0,
|
||||
{0, 0, 0}, {4, 4, 1}, wgpu::TextureAspect::All));
|
||||
|
||||
ASSERT_DEVICE_ERROR(TestWriteTexture(dataSize, 0, bytesPerRow, 0, destination, 0,
|
||||
{0, 0, 0}, {4, 4, 1},
|
||||
wgpu::TextureAspect::DepthOnly));
|
||||
}
|
||||
}
|
||||
|
||||
// Test write texture to the stencil aspect
|
||||
TEST_F(QueueWriteTextureValidationTest, WriteToStencilAspect) {
|
||||
uint32_t bytesPerRow = 4;
|
||||
const uint64_t dataSize =
|
||||
utils::RequiredBytesInCopy(bytesPerRow, 0, {4, 4, 1}, wgpu::TextureFormat::R8Uint);
|
||||
|
||||
// It is valid to write into the stencil aspect of depth24plus-stencil8
|
||||
{
|
||||
wgpu::Texture destination = QueueWriteTextureValidationTest::Create2DTexture(
|
||||
{4, 4, 1}, 1, wgpu::TextureFormat::Depth24PlusStencil8,
|
||||
wgpu::TextureUsage::CopyDst);
|
||||
|
||||
TestWriteTexture(dataSize, 0, bytesPerRow, 0, destination, 0, {0, 0, 0}, {4, 4, 1},
|
||||
wgpu::TextureAspect::StencilOnly);
|
||||
|
||||
// And that it fails if the buffer is one byte too small
|
||||
ASSERT_DEVICE_ERROR(TestWriteTexture(dataSize - 1, 0, bytesPerRow, 0, destination, 0,
|
||||
{0, 0, 0}, {4, 4, 1},
|
||||
wgpu::TextureAspect::StencilOnly));
|
||||
}
|
||||
|
||||
// It is invalid to write into the stencil aspect of depth24plus (no stencil)
|
||||
{
|
||||
wgpu::Texture destination = QueueWriteTextureValidationTest::Create2DTexture(
|
||||
{4, 4, 1}, 1, wgpu::TextureFormat::Depth24Plus, wgpu::TextureUsage::CopyDst);
|
||||
|
||||
ASSERT_DEVICE_ERROR(TestWriteTexture(dataSize, 0, bytesPerRow, 0, destination, 0,
|
||||
{0, 0, 0}, {4, 4, 1},
|
||||
wgpu::TextureAspect::StencilOnly));
|
||||
}
|
||||
}
|
||||
|
||||
class WriteTextureTest_CompressedTextureFormats : public QueueWriteTextureValidationTest {
|
||||
public:
|
||||
WriteTextureTest_CompressedTextureFormats() : QueueWriteTextureValidationTest() {
|
||||
|
||||
Reference in New Issue
Block a user