Add WGPU_STRIDE_UNDEFINED and update bytesPerRow/rowsPerImage validation

This makes a nearly one-to-one mapping between the JS and C APIs, which
benefits projects like Blink and Emscripten.

- JavaScript's `undefined` is equivalent to C `WGPU_STRIDE_UNDEFINED`.
- JavaScript's `0` is equivalent to C `0`.
- To implement the API correctly, Blink must special-case an actual
  value coming in from JS that is equal to WGPU_STRIDE_UNDEFINED
  (0xFFFF'FFFF), and inject an error.

Keeps but deprecates a reasonable approximation of the old behavior.

Bug: dawn:520
Change-Id: Ie9c992ffab82830090d0dfc3120731e89cd9691c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/31140
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Kai Ninomiya
2020-11-06 13:41:50 +00:00
committed by Commit Bot service account
parent 973d145df8
commit 16036cf206
29 changed files with 712 additions and 369 deletions

View File

@@ -44,8 +44,12 @@ namespace utils {
layout.bytesPerRow = GetMinimumBytesPerRow(format, layout.mipSize.width);
uint32_t appliedRowsPerImage = rowsPerImage > 0 ? rowsPerImage : layout.mipSize.height;
layout.bytesPerImage = layout.bytesPerRow * appliedRowsPerImage;
if (rowsPerImage == wgpu::kStrideUndefined) {
rowsPerImage = layout.mipSize.height;
}
layout.rowsPerImage = rowsPerImage;
layout.bytesPerImage = layout.bytesPerRow * rowsPerImage;
// TODO(kainino@chromium.org): Remove this intermediate variable.
// It is currently needed because of an issue in the D3D12 copy splitter
@@ -54,9 +58,9 @@ namespace utils {
// the actual height.
wgpu::Extent3D mipSizeWithHeightWorkaround = layout.mipSize;
mipSizeWithHeightWorkaround.height =
appliedRowsPerImage * utils::GetTextureFormatBlockHeight(format);
rowsPerImage * utils::GetTextureFormatBlockHeight(format);
layout.byteLength = RequiredBytesInCopy(layout.bytesPerRow, appliedRowsPerImage,
layout.byteLength = RequiredBytesInCopy(layout.bytesPerRow, rowsPerImage,
mipSizeWithHeightWorkaround, format);
const uint32_t bytesPerTexel = utils::GetTexelBlockSizeInBytes(format);
@@ -120,7 +124,8 @@ namespace utils {
wgpu::Texture texture = device.CreateTexture(&descriptor);
wgpu::TextureCopyView textureCopyView = utils::CreateTextureCopyView(texture, 0, {0, 0, 0});
wgpu::TextureDataLayout textureDataLayout = utils::CreateTextureDataLayout(0, 0, 0);
wgpu::TextureDataLayout textureDataLayout =
utils::CreateTextureDataLayout(0, wgpu::kStrideUndefined);
wgpu::Extent3D copyExtent = {1, 1, 1};
// WriteTexture with exactly 1 byte of data.

View File

@@ -23,6 +23,7 @@ namespace utils {
uint64_t byteLength;
uint64_t texelBlockCount;
uint32_t bytesPerRow;
uint32_t rowsPerImage;
uint32_t texelBlocksPerRow;
uint32_t bytesPerImage;
uint32_t texelBlocksPerImage;
@@ -34,7 +35,7 @@ namespace utils {
wgpu::TextureFormat format,
wgpu::Extent3D textureSizeAtLevel0,
uint32_t mipmapLevel,
uint32_t rowsPerImage);
uint32_t rowsPerImage = wgpu::kStrideUndefined);
uint64_t RequiredBytesInCopy(uint64_t bytesPerRow,
uint64_t rowsPerImage,

View File

@@ -53,7 +53,7 @@ namespace utils {
wgpu::BufferCopyView CreateBufferCopyView(wgpu::Buffer buffer,
uint64_t offset,
uint32_t bytesPerRow,
uint32_t rowsPerImage);
uint32_t rowsPerImage = wgpu::kStrideUndefined);
wgpu::TextureCopyView CreateTextureCopyView(
wgpu::Texture texture,
uint32_t level,
@@ -61,7 +61,7 @@ namespace utils {
wgpu::TextureAspect aspect = wgpu::TextureAspect::All);
wgpu::TextureDataLayout CreateTextureDataLayout(uint64_t offset,
uint32_t bytesPerRow,
uint32_t rowsPerImage);
uint32_t rowsPerImage = wgpu::kStrideUndefined);
struct ComboRenderPassDescriptor : public wgpu::RenderPassDescriptor {
public: