mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 15:46:28 +00:00
Support copying multiple array layers in one B2T and T2B copy command
This patch adds the support of copying with multiple texture array layers in one buffer-to-texture and texture-to-buffer copy command. BUG=dawn:453 TEST=dawn_end2end_tests Change-Id: If009dbb29f2b0ef0667715eed0d66053b1491fd4 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/23248 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
committed by
Commit Bot service account
parent
250f26229b
commit
92379bff49
@@ -34,6 +34,7 @@ class CopyTests : public DawnTest {
|
||||
uint64_t size;
|
||||
uint64_t offset;
|
||||
uint32_t bytesPerRow;
|
||||
uint32_t rowsPerImage;
|
||||
};
|
||||
|
||||
static std::vector<RGBA8> GetExpectedTextureData(
|
||||
@@ -56,12 +57,14 @@ class CopyTests : public DawnTest {
|
||||
}
|
||||
|
||||
static BufferSpec MinimumBufferSpec(uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t arrayLayer = 1) {
|
||||
uint32_t rowsPerImage,
|
||||
uint32_t arrayLayer = 1,
|
||||
bool testZeroRowsPerImage = true) {
|
||||
const uint32_t bytesPerRow = utils::GetMinimumBytesPerRow(kTextureFormat, width);
|
||||
const uint32_t totalBufferSize = utils::GetBytesInBufferTextureCopy(
|
||||
kTextureFormat, width, bytesPerRow, height, arrayLayer);
|
||||
return {totalBufferSize, 0, bytesPerRow};
|
||||
kTextureFormat, width, bytesPerRow, rowsPerImage, arrayLayer);
|
||||
uint32_t appliedRowsPerImage = testZeroRowsPerImage ? 0 : rowsPerImage;
|
||||
return {totalBufferSize, 0, bytesPerRow, appliedRowsPerImage};
|
||||
}
|
||||
|
||||
static void PackTextureData(const RGBA8* srcData, uint32_t width, uint32_t height, uint32_t srcTexelsPerRow, RGBA8* dstData, uint32_t dstTexelsPerRow) {
|
||||
@@ -90,30 +93,24 @@ class CopyTests_T2B : public CopyTests {
|
||||
descriptor.usage = wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc;
|
||||
wgpu::Texture texture = device.CreateTexture(&descriptor);
|
||||
|
||||
const uint32_t rowsPerImage = textureSpec.textureSize.height >> textureSpec.level;
|
||||
const utils::BufferTextureCopyLayout copyLayout =
|
||||
utils::GetBufferTextureCopyLayoutForTexture2DAtLevel(
|
||||
kTextureFormat, textureSpec.textureSize, textureSpec.level, rowsPerImage);
|
||||
kTextureFormat, textureSpec.textureSize, textureSpec.level,
|
||||
bufferSpec.rowsPerImage);
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
|
||||
// Initialize the source texture
|
||||
std::vector<RGBA8> textureArrayData = GetExpectedTextureData(copyLayout);
|
||||
|
||||
// TODO(jiawei.shao@intel.com): copy into multiple texture array layers in one
|
||||
// buffer-to-texture copy command.
|
||||
wgpu::Buffer uploadBuffer = utils::CreateBufferFromData(
|
||||
device, textureArrayData.data(), copyLayout.byteLength, wgpu::BufferUsage::CopySrc);
|
||||
uint64_t uploadBufferOffset = 0;
|
||||
for (uint32_t slice = 0; slice < textureSpec.textureSize.depth; ++slice) {
|
||||
{
|
||||
wgpu::Buffer uploadBuffer =
|
||||
utils::CreateBufferFromData(device, textureArrayData.data(),
|
||||
copyLayout.byteLength, wgpu::BufferUsage::CopySrc);
|
||||
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(
|
||||
uploadBuffer, uploadBufferOffset, copyLayout.bytesPerRow, 0);
|
||||
uploadBuffer, 0, copyLayout.bytesPerRow, bufferSpec.rowsPerImage);
|
||||
wgpu::TextureCopyView textureCopyView =
|
||||
utils::CreateTextureCopyView(texture, textureSpec.level, {0, 0, slice});
|
||||
wgpu::Extent3D copyOneLayerSize = {copyLayout.mipSize.width,
|
||||
copyLayout.mipSize.height, 1};
|
||||
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©OneLayerSize);
|
||||
uploadBufferOffset += copyLayout.bytesPerImage;
|
||||
utils::CreateTextureCopyView(texture, textureSpec.level, {0, 0, 0});
|
||||
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Layout.mipSize);
|
||||
}
|
||||
|
||||
// Create a buffer of `size` and populate it with empty data (0,0,0,0) Note:
|
||||
@@ -128,31 +125,21 @@ class CopyTests_T2B : public CopyTests {
|
||||
utils::CreateBufferFromData(device, emptyData.data(), bufferSpec.size,
|
||||
wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst);
|
||||
|
||||
const uint32_t maxArrayLayer = textureSpec.copyOrigin.z + copySize.depth;
|
||||
|
||||
// TODO(jiawei.shao@intel.com): copy from multiple texture array layers in one
|
||||
// texture-to-buffer copy command.
|
||||
uint64_t bufferOffset = bufferSpec.offset;
|
||||
for (uint32_t slice = textureSpec.copyOrigin.z; slice < maxArrayLayer; ++slice) {
|
||||
// Copy the region [(`x`, `y`, slice), (`x + testCopySize.width, `y +
|
||||
// testCopySize.height`, 1)] from the `level` mip into the buffer at `offset +
|
||||
// bufferSpec.size * slice` and `bytesPerRow`
|
||||
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
|
||||
texture, textureSpec.level,
|
||||
{textureSpec.copyOrigin.x, textureSpec.copyOrigin.y, slice});
|
||||
wgpu::BufferCopyView bufferCopyView =
|
||||
utils::CreateBufferCopyView(buffer, bufferOffset, bufferSpec.bytesPerRow, 0);
|
||||
wgpu::Extent3D copyOneLayerSize = {copySize.width, copySize.height, 1};
|
||||
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, ©OneLayerSize);
|
||||
bufferOffset += copyLayout.bytesPerImage;
|
||||
{
|
||||
wgpu::TextureCopyView textureCopyView =
|
||||
utils::CreateTextureCopyView(texture, textureSpec.level, textureSpec.copyOrigin);
|
||||
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(
|
||||
buffer, bufferSpec.offset, bufferSpec.bytesPerRow, bufferSpec.rowsPerImage);
|
||||
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, ©Size);
|
||||
}
|
||||
|
||||
wgpu::CommandBuffer commands = encoder.Finish();
|
||||
queue.Submit(1, &commands);
|
||||
|
||||
bufferOffset = bufferSpec.offset;
|
||||
uint64_t bufferOffset = bufferSpec.offset;
|
||||
const uint32_t texelCountInCopyRegion =
|
||||
bufferSpec.bytesPerRow / bytesPerTexel * (copySize.height - 1) + copySize.width;
|
||||
const uint32_t maxArrayLayer = textureSpec.copyOrigin.z + copySize.depth;
|
||||
std::vector<RGBA8> expected(texelCountInCopyRegion);
|
||||
for (uint32_t slice = textureSpec.copyOrigin.z; slice < maxArrayLayer; ++slice) {
|
||||
// Pack the data used to create the upload buffer in the specified copy region to have
|
||||
@@ -218,34 +205,23 @@ protected:
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
|
||||
const uint32_t rowsPerImage = textureSpec.textureSize.height >> textureSpec.level;
|
||||
const utils::BufferTextureCopyLayout copyLayout =
|
||||
utils::GetBufferTextureCopyLayoutForTexture2DAtLevel(
|
||||
kTextureFormat, textureSpec.textureSize, textureSpec.level, rowsPerImage);
|
||||
kTextureFormat, textureSpec.textureSize, textureSpec.level,
|
||||
bufferSpec.rowsPerImage);
|
||||
|
||||
const uint32_t maxArrayLayer = textureSpec.copyOrigin.z + copySize.depth;
|
||||
|
||||
// TODO(jiawei.shao@intel.com): support copying into multiple texture array layers in one
|
||||
// copy command.
|
||||
uint64_t bufferOffset = bufferSpec.offset;
|
||||
for (uint32_t slice = textureSpec.copyOrigin.z; slice < maxArrayLayer; ++slice) {
|
||||
// Copy to the region [(`x`, `y`, `slice`), (`x + testCopySize.width, `y +
|
||||
// testCopySize.height`, 1] at the `level` mip
|
||||
// from the buffer at the specified `offset` and `bytesPerRow`
|
||||
wgpu::BufferCopyView bufferCopyView =
|
||||
utils::CreateBufferCopyView(buffer, bufferOffset, bufferSpec.bytesPerRow, 0);
|
||||
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
|
||||
texture, textureSpec.level,
|
||||
{textureSpec.copyOrigin.x, textureSpec.copyOrigin.y, slice});
|
||||
wgpu::Extent3D copyOneLayerSize = {copySize.width, copySize.height, 1};
|
||||
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©OneLayerSize);
|
||||
bufferOffset += copyLayout.bytesPerImage;
|
||||
}
|
||||
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(
|
||||
buffer, bufferSpec.offset, bufferSpec.bytesPerRow, bufferSpec.rowsPerImage);
|
||||
wgpu::TextureCopyView textureCopyView =
|
||||
utils::CreateTextureCopyView(texture, textureSpec.level, textureSpec.copyOrigin);
|
||||
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Size);
|
||||
|
||||
wgpu::CommandBuffer commands = encoder.Finish();
|
||||
queue.Submit(1, &commands);
|
||||
|
||||
bufferOffset = bufferSpec.offset;
|
||||
uint64_t bufferOffset = bufferSpec.offset;
|
||||
const uint32_t texelCountLastLayer =
|
||||
copyLayout.texelBlocksPerRow * (copyLayout.mipSize.height - 1) +
|
||||
copyLayout.mipSize.width;
|
||||
@@ -305,30 +281,21 @@ class CopyTests_T2T : public CopyTests {
|
||||
|
||||
// Create an upload buffer and use it to populate the current slice of the texture in
|
||||
// `level` mip level
|
||||
const uint32_t rowsPerImage = srcSpec.textureSize.height >> srcSpec.level;
|
||||
const utils::BufferTextureCopyLayout copyLayout =
|
||||
utils::GetBufferTextureCopyLayoutForTexture2DAtLevel(
|
||||
kTextureFormat,
|
||||
{srcSpec.textureSize.width, srcSpec.textureSize.height, copySize.depth},
|
||||
srcSpec.level, rowsPerImage);
|
||||
srcSpec.level, 0);
|
||||
|
||||
const std::vector<RGBA8> textureArrayCopyData = GetExpectedTextureData(copyLayout);
|
||||
|
||||
// TODO(jiawei.shao@intel.com): support copying into multiple contiguous array layers in one
|
||||
// copyBufferToTexture() call.
|
||||
wgpu::Buffer uploadBuffer = utils::CreateBufferFromData(
|
||||
device, textureArrayCopyData.data(), copyLayout.byteLength, wgpu::BufferUsage::CopySrc);
|
||||
uint64_t uploadBufferOffset = 0;
|
||||
for (uint32_t slice = 0; slice < copySize.depth; ++slice) {
|
||||
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(
|
||||
uploadBuffer, uploadBufferOffset, copyLayout.bytesPerRow, 0);
|
||||
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(
|
||||
srcTexture, srcSpec.level, {0, 0, srcSpec.copyOrigin.z + slice});
|
||||
wgpu::Extent3D copyOneLayerSize = {copyLayout.mipSize.width, copyLayout.mipSize.height,
|
||||
1};
|
||||
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©OneLayerSize);
|
||||
uploadBufferOffset += copyLayout.bytesPerImage;
|
||||
}
|
||||
wgpu::BufferCopyView bufferCopyView =
|
||||
utils::CreateBufferCopyView(uploadBuffer, 0, copyLayout.bytesPerRow, 0);
|
||||
wgpu::TextureCopyView textureCopyView =
|
||||
utils::CreateTextureCopyView(srcTexture, srcSpec.level, {0, 0, srcSpec.copyOrigin.z});
|
||||
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Layout.mipSize);
|
||||
|
||||
// Perform the texture to texture copy
|
||||
wgpu::TextureCopyView srcTextureCopyView =
|
||||
@@ -700,8 +667,12 @@ TEST_P(CopyTests_T2B, RowPitchUnaligned) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test that copying regions of each texture 2D array layer works
|
||||
// Test that copying whole texture 2D array layers in one texture-to-buffer-copy works.
|
||||
TEST_P(CopyTests_T2B, Texture2DArrayRegion) {
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layer fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
constexpr uint32_t kWidth = 256;
|
||||
constexpr uint32_t kHeight = 128;
|
||||
constexpr uint32_t kLayers = 6u;
|
||||
@@ -714,8 +685,12 @@ TEST_P(CopyTests_T2B, Texture2DArrayRegion) {
|
||||
DoTest(textureSpec, MinimumBufferSpec(kWidth, kHeight, kLayers), {kWidth, kHeight, kLayers});
|
||||
}
|
||||
|
||||
// Test that copying a sub-region of each texture 2D array layer works
|
||||
// Test that copying a range of texture 2D array layers in one texture-to-buffer-copy works.
|
||||
TEST_P(CopyTests_T2B, Texture2DArraySubRegion) {
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layer fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
constexpr uint32_t kWidth = 256;
|
||||
constexpr uint32_t kHeight = 128;
|
||||
constexpr uint32_t kLayers = 6u;
|
||||
@@ -733,6 +708,10 @@ TEST_P(CopyTests_T2B, Texture2DArraySubRegion) {
|
||||
|
||||
// Test that copying texture 2D array mips with 256-byte aligned sizes works
|
||||
TEST_P(CopyTests_T2B, Texture2DArrayMip) {
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layers fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
constexpr uint32_t kWidth = 256;
|
||||
constexpr uint32_t kHeight = 128;
|
||||
constexpr uint32_t kLayers = 6u;
|
||||
@@ -750,6 +729,31 @@ TEST_P(CopyTests_T2B, Texture2DArrayMip) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test that copying from a range of texture 2D array layers in one texture-to-buffer-copy when
|
||||
// RowsPerImage is not equal to the height of the texture works.
|
||||
TEST_P(CopyTests_T2B, Texture2DArrayRegionNonzeroRowsPerImage) {
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layers fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
constexpr uint32_t kWidth = 256;
|
||||
constexpr uint32_t kHeight = 128;
|
||||
constexpr uint32_t kLayers = 6u;
|
||||
constexpr uint32_t kBaseLayer = 2u;
|
||||
constexpr uint32_t kCopyLayers = 3u;
|
||||
|
||||
constexpr uint32_t kRowsPerImage = kHeight * 2;
|
||||
|
||||
TextureSpec textureSpec;
|
||||
textureSpec.copyOrigin = {0, 0, kBaseLayer};
|
||||
textureSpec.textureSize = {kWidth, kHeight, kLayers};
|
||||
textureSpec.level = 0;
|
||||
|
||||
BufferSpec bufferSpec = MinimumBufferSpec(kWidth, kRowsPerImage, kCopyLayers, false);
|
||||
bufferSpec.rowsPerImage = kRowsPerImage;
|
||||
DoTest(textureSpec, bufferSpec, {kWidth, kHeight, kCopyLayers});
|
||||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(CopyTests_T2B, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
|
||||
|
||||
// Test that copying an entire texture with 256-byte aligned dimensions works
|
||||
@@ -1038,8 +1042,12 @@ TEST_P(CopyTests_B2T, RowPitchUnaligned) {
|
||||
}
|
||||
}
|
||||
|
||||
// Test that copying into regions of each texture 2D array layer works
|
||||
// Test that copying whole texture 2D array layers in one texture-to-buffer-copy works.
|
||||
TEST_P(CopyTests_B2T, Texture2DArrayRegion) {
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layers fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
constexpr uint32_t kWidth = 256;
|
||||
constexpr uint32_t kHeight = 128;
|
||||
constexpr uint32_t kLayers = 6u;
|
||||
@@ -1052,8 +1060,12 @@ TEST_P(CopyTests_B2T, Texture2DArrayRegion) {
|
||||
DoTest(textureSpec, MinimumBufferSpec(kWidth, kHeight, kLayers), {kWidth, kHeight, kLayers});
|
||||
}
|
||||
|
||||
// Test that copying into a sub-region of each texture 2D array layer works
|
||||
// Test that copying a range of texture 2D array layers in one texture-to-buffer-copy works.
|
||||
TEST_P(CopyTests_B2T, Texture2DArraySubRegion) {
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layers fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
constexpr uint32_t kWidth = 256;
|
||||
constexpr uint32_t kHeight = 128;
|
||||
constexpr uint32_t kLayers = 6u;
|
||||
@@ -1069,6 +1081,31 @@ TEST_P(CopyTests_B2T, Texture2DArraySubRegion) {
|
||||
{kWidth, kHeight, kCopyLayers});
|
||||
}
|
||||
|
||||
// Test that copying into a range of texture 2D array layers in one texture-to-buffer-copy when
|
||||
// RowsPerImage is not equal to the height of the texture works.
|
||||
TEST_P(CopyTests_B2T, Texture2DArrayRegionNonzeroRowsPerImage) {
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layers fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
constexpr uint32_t kWidth = 256;
|
||||
constexpr uint32_t kHeight = 128;
|
||||
constexpr uint32_t kLayers = 6u;
|
||||
constexpr uint32_t kBaseLayer = 2u;
|
||||
constexpr uint32_t kCopyLayers = 3u;
|
||||
|
||||
constexpr uint32_t kRowsPerImage = kHeight * 2;
|
||||
|
||||
TextureSpec textureSpec;
|
||||
textureSpec.copyOrigin = {0, 0, kBaseLayer};
|
||||
textureSpec.textureSize = {kWidth, kHeight, kLayers};
|
||||
textureSpec.level = 0;
|
||||
|
||||
BufferSpec bufferSpec = MinimumBufferSpec(kWidth, kRowsPerImage, kCopyLayers, false);
|
||||
bufferSpec.rowsPerImage = kRowsPerImage;
|
||||
DoTest(textureSpec, bufferSpec, {kWidth, kHeight, kCopyLayers});
|
||||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(CopyTests_B2T, D3D12Backend(), MetalBackend(), OpenGLBackend(), VulkanBackend());
|
||||
|
||||
TEST_P(CopyTests_T2T, Texture) {
|
||||
|
||||
@@ -460,23 +460,14 @@ class StorageTextureTests : public DawnTest {
|
||||
CreateTexture(format, wgpu::TextureUsage::Storage | wgpu::TextureUsage::CopyDst, kWidth,
|
||||
kHeight, arrayLayerCount);
|
||||
|
||||
const wgpu::Extent3D copyExtent = {kWidth, kHeight, 1};
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
|
||||
// TODO(jiawei.shao@intel.com): copy multiple array layers in one CopyBufferToTexture() when
|
||||
// it is supported.
|
||||
for (uint32_t layer = 0; layer < arrayLayerCount; ++layer) {
|
||||
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(
|
||||
uploadBuffer, kTextureBytesPerRowAlignment * kHeight * layer,
|
||||
kTextureBytesPerRowAlignment, 0);
|
||||
|
||||
wgpu::TextureCopyView textureCopyView;
|
||||
textureCopyView.texture = outputTexture;
|
||||
textureCopyView.origin.z = layer;
|
||||
|
||||
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Extent);
|
||||
}
|
||||
const wgpu::Extent3D copyExtent = {kWidth, kHeight, arrayLayerCount};
|
||||
wgpu::BufferCopyView bufferCopyView =
|
||||
utils::CreateBufferCopyView(uploadBuffer, 0, kTextureBytesPerRowAlignment, 0);
|
||||
wgpu::TextureCopyView textureCopyView;
|
||||
textureCopyView.texture = outputTexture;
|
||||
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Extent);
|
||||
|
||||
wgpu::CommandBuffer commandBuffer = encoder.Finish();
|
||||
queue.Submit(1, &commandBuffer);
|
||||
@@ -643,23 +634,14 @@ class StorageTextureTests : public DawnTest {
|
||||
static_cast<uint32_t>(expectedData.size() / texelSize / (kWidth * kHeight));
|
||||
wgpu::Buffer resultBuffer = CreateEmptyBufferForTextureCopy(texelSize, arrayLayerCount);
|
||||
|
||||
const wgpu::Extent3D copyExtent = {kWidth, kHeight, 1};
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
|
||||
// TODO(jiawei.shao@intel.com): copy multiple array layers in one CopyTextureToBuffer() when
|
||||
// it is supported.
|
||||
for (uint32_t layer = 0; layer < arrayLayerCount; ++layer) {
|
||||
wgpu::TextureCopyView textureCopyView;
|
||||
textureCopyView.texture = writeonlyStorageTexture;
|
||||
textureCopyView.origin.z = layer;
|
||||
|
||||
const uint64_t bufferOffset = kTextureBytesPerRowAlignment * kHeight * layer;
|
||||
wgpu::BufferCopyView bufferCopyView = utils::CreateBufferCopyView(
|
||||
resultBuffer, bufferOffset, kTextureBytesPerRowAlignment, 0);
|
||||
|
||||
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, ©Extent);
|
||||
}
|
||||
const wgpu::Extent3D copyExtent = {kWidth, kHeight, arrayLayerCount};
|
||||
wgpu::TextureCopyView textureCopyView =
|
||||
utils::CreateTextureCopyView(writeonlyStorageTexture, 0, {0, 0, 0});
|
||||
wgpu::BufferCopyView bufferCopyView =
|
||||
utils::CreateBufferCopyView(resultBuffer, 0, kTextureBytesPerRowAlignment, 0);
|
||||
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, ©Extent);
|
||||
wgpu::CommandBuffer commandBuffer = encoder.Finish();
|
||||
queue.Submit(1, &commandBuffer);
|
||||
|
||||
@@ -955,6 +937,10 @@ TEST_P(StorageTextureTests, Readonly2DArrayStorageTexture) {
|
||||
// bug in spvc parser is fixed.
|
||||
DAWN_SKIP_TEST_IF(IsSpvcParserBeingUsed());
|
||||
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layer fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
constexpr uint32_t kArrayLayerCount = 3u;
|
||||
|
||||
constexpr wgpu::TextureFormat kTextureFormat = wgpu::TextureFormat::R32Uint;
|
||||
@@ -993,6 +979,10 @@ TEST_P(StorageTextureTests, Writeonly2DArrayStorageTexture) {
|
||||
// bug in spvc parser is fixed.
|
||||
DAWN_SKIP_TEST_IF(IsD3D12() && IsSpvcParserBeingUsed());
|
||||
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layer fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
constexpr uint32_t kArrayLayerCount = 3u;
|
||||
|
||||
constexpr wgpu::TextureFormat kTextureFormat = wgpu::TextureFormat::R32Uint;
|
||||
|
||||
@@ -130,6 +130,49 @@ TEST_P(TextureZeroInitTest, CopyTextureToBufferSource) {
|
||||
EXPECT_EQ(true, dawn_native::IsTextureSubresourceInitialized(texture.Get(), 0, 1, 0, 1));
|
||||
}
|
||||
|
||||
// This tests that the code path of CopyTextureToBuffer with multiple texture array layers clears
|
||||
// correctly to Zero after first usage
|
||||
TEST_P(TextureZeroInitTest, CopyMultipleTextureArrayLayersToBufferSource) {
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layers fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
constexpr uint32_t kArrayLayers = 6u;
|
||||
|
||||
const wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
|
||||
1, kArrayLayers, wgpu::TextureUsage::OutputAttachment | wgpu::TextureUsage::CopySrc,
|
||||
kColorFormat);
|
||||
wgpu::Texture texture = device.CreateTexture(&descriptor);
|
||||
|
||||
const uint32_t bytesPerRow = utils::GetMinimumBytesPerRow(kColorFormat, kSize);
|
||||
wgpu::BufferDescriptor bufferDescriptor;
|
||||
bufferDescriptor.usage = wgpu::BufferUsage::CopySrc | wgpu::BufferUsage::CopyDst;
|
||||
bufferDescriptor.size =
|
||||
utils::GetBytesInBufferTextureCopy(kColorFormat, kSize, bytesPerRow, kSize, kArrayLayers);
|
||||
wgpu::Buffer buffer = device.CreateBuffer(&bufferDescriptor);
|
||||
|
||||
const wgpu::BufferCopyView bufferCopyView =
|
||||
utils::CreateBufferCopyView(buffer, 0, bytesPerRow, 0);
|
||||
const wgpu::TextureCopyView textureCopyView =
|
||||
utils::CreateTextureCopyView(texture, 0, {0, 0, 0});
|
||||
const wgpu::Extent3D copySize = {kSize, kSize, kArrayLayers};
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
encoder.CopyTextureToBuffer(&textureCopyView, &bufferCopyView, ©Size);
|
||||
wgpu::CommandBuffer commandBuffer = encoder.Finish();
|
||||
|
||||
// Expect texture to be lazy initialized.
|
||||
EXPECT_LAZY_CLEAR(1u, queue.Submit(1, &commandBuffer));
|
||||
|
||||
// Expect texture subresource initialized to be true
|
||||
EXPECT_TRUE(dawn_native::IsTextureSubresourceInitialized(texture.Get(), 0, 1, 0, kArrayLayers));
|
||||
|
||||
const std::vector<RGBA8> kExpectedAllZero(kSize * kSize, {0, 0, 0, 0});
|
||||
for (uint32_t layer = 0; layer < kArrayLayers; ++layer) {
|
||||
EXPECT_TEXTURE_RGBA8_EQ(kExpectedAllZero.data(), texture, 0, 0, kSize, kSize, 0, layer);
|
||||
}
|
||||
}
|
||||
|
||||
// Test that non-zero mip level clears subresource to Zero after first use
|
||||
// This goes through the BeginRenderPass's code path
|
||||
TEST_P(TextureZeroInitTest, RenderingMipMapClearsToZero) {
|
||||
@@ -282,6 +325,47 @@ TEST_P(TextureZeroInitTest, CopyBufferToTextureHalf) {
|
||||
EXPECT_EQ(true, dawn_native::IsTextureSubresourceInitialized(texture.Get(), 0, 1, 0, 1));
|
||||
}
|
||||
|
||||
// This tests CopyBufferToTexture fully overwrites a range of subresources, so lazy initialization
|
||||
// is needed for neither the subresources involved in the copy nor the other subresources.
|
||||
TEST_P(TextureZeroInitTest, CopyBufferToTextureMultipleArrayLayers) {
|
||||
// TODO(jiawei.shao@intel.com): investigate why copies with multiple texture array layers fail
|
||||
// with swiftshader.
|
||||
DAWN_SKIP_TEST_IF(IsSwiftshader());
|
||||
|
||||
wgpu::TextureDescriptor descriptor = CreateTextureDescriptor(
|
||||
1, 6, wgpu::TextureUsage::CopyDst | wgpu::TextureUsage::CopySrc, kColorFormat);
|
||||
wgpu::Texture texture = device.CreateTexture(&descriptor);
|
||||
|
||||
constexpr uint32_t kBaseArrayLayer = 2u;
|
||||
constexpr uint32_t kCopyLayerCount = 3u;
|
||||
std::vector<uint8_t> data(kFormatBlockByteSize * kSize * kSize * kCopyLayerCount, 100);
|
||||
wgpu::Buffer stagingBuffer = utils::CreateBufferFromData(
|
||||
device, data.data(), static_cast<uint32_t>(data.size()), wgpu::BufferUsage::CopySrc);
|
||||
|
||||
const wgpu::BufferCopyView bufferCopyView =
|
||||
utils::CreateBufferCopyView(stagingBuffer, 0, kSize * kFormatBlockByteSize, 0);
|
||||
const wgpu::TextureCopyView textureCopyView =
|
||||
utils::CreateTextureCopyView(texture, 0, {0, 0, kBaseArrayLayer});
|
||||
const wgpu::Extent3D copySize = {kSize, kSize, kCopyLayerCount};
|
||||
|
||||
wgpu::CommandEncoder encoder = device.CreateCommandEncoder();
|
||||
encoder.CopyBufferToTexture(&bufferCopyView, &textureCopyView, ©Size);
|
||||
wgpu::CommandBuffer commands = encoder.Finish();
|
||||
|
||||
// The copy overwrites the whole subresources su we don't need to do lazy initialization on
|
||||
// them.
|
||||
EXPECT_LAZY_CLEAR(0u, queue.Submit(1, &commands));
|
||||
|
||||
// Expect texture subresource initialized to be true
|
||||
EXPECT_TRUE(dawn_native::IsTextureSubresourceInitialized(texture.Get(), 0, 1, kBaseArrayLayer,
|
||||
kCopyLayerCount));
|
||||
|
||||
const std::vector<RGBA8> expected100(kSize * kSize, {100, 100, 100, 100});
|
||||
for (uint32_t layer = kBaseArrayLayer; layer < kBaseArrayLayer + kCopyLayerCount; ++layer) {
|
||||
EXPECT_TEXTURE_RGBA8_EQ(expected100.data(), texture, 0, 0, kSize, kSize, 0, layer);
|
||||
}
|
||||
}
|
||||
|
||||
// This tests CopyTextureToTexture fully overwrites copy so lazy init is not needed.
|
||||
TEST_P(TextureZeroInitTest, CopyTextureToTexture) {
|
||||
wgpu::TextureDescriptor srcDescriptor = CreateTextureDescriptor(
|
||||
|
||||
Reference in New Issue
Block a user