mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-05-16 04:11:25 +00:00
Buffer allocations in Dawn may be padded. This padding could be visible, depending on how the backend implements robust vertex buffer access. This commit updates buffer creation to clear all padding bytes immediately after creation. It is not counted as a lazy clear. And, add a test which reads off the end of a padded vertex buffer to check that the padding bytes are also initialized. Also: Update Metal buffers to always allocate enough space for Tint's vertex pulling, and pass the full allocated size to Tint. While writing the test in this commit, a bug was found where Tint assumes there is at least 4 bytes in the vertex pulling buffer. The WebGPU API currently allows zero-sized bindings, so Dawn needs to always allocate enough space for one element. Also: Update Vulkan vertex/index buffers to allocate at least one more byte than requested because vkCmdSetVertexBuffers and vkCmdSetIndexBuffer disallow the offset to be equal to the buffer size. We need at least one more byte to make zero-sized bindings as the end of the buffer valid. Lastly: Update helper so that a T2B copy of a single row that touches all bytes in a buffer updates the buffer state to be fully initialized. This is a small optimization that is necessary to write the test. Bug: dawn:837 Change-Id: I829f4764509c4ec784c5aeaaf40b6dcbd4be6866 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/62161 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
68 lines
2.6 KiB
C++
68 lines
2.6 KiB
C++
// Copyright 2020 The Dawn Authors
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#ifndef UTILS_TESTHELPERS_H_
|
|
#define UTILS_TESTHELPERS_H_
|
|
|
|
#include <dawn/webgpu_cpp.h>
|
|
|
|
namespace utils {
|
|
|
|
struct TextureDataCopyLayout {
|
|
uint64_t byteLength;
|
|
uint64_t texelBlockCount;
|
|
uint32_t bytesPerRow;
|
|
uint32_t rowsPerImage;
|
|
uint32_t texelBlocksPerRow;
|
|
uint32_t bytesPerImage;
|
|
uint32_t texelBlocksPerImage;
|
|
wgpu::Extent3D mipSize;
|
|
};
|
|
|
|
uint32_t GetMinimumBytesPerRow(wgpu::TextureFormat format, uint32_t width);
|
|
TextureDataCopyLayout GetTextureDataCopyLayoutForTextureAtLevel(
|
|
wgpu::TextureFormat format,
|
|
wgpu::Extent3D textureSizeAtLevel0,
|
|
uint32_t mipmapLevel,
|
|
wgpu::TextureDimension dimension = wgpu::TextureDimension::e2D,
|
|
uint32_t rowsPerImage = wgpu::kCopyStrideUndefined);
|
|
|
|
uint64_t RequiredBytesInCopy(uint64_t bytesPerRow,
|
|
uint64_t rowsPerImage,
|
|
wgpu::Extent3D copyExtent,
|
|
wgpu::TextureFormat textureFormat);
|
|
uint64_t RequiredBytesInCopy(uint64_t bytesPerRow,
|
|
uint64_t rowsPerImage,
|
|
uint64_t widthInBlocks,
|
|
uint64_t heightInBlocks,
|
|
uint64_t depth,
|
|
uint64_t bytesPerBlock);
|
|
|
|
uint64_t GetTexelCountInCopyRegion(uint64_t bytesPerRow,
|
|
uint64_t rowsPerImage,
|
|
wgpu::Extent3D copyExtent,
|
|
wgpu::TextureFormat textureFormat);
|
|
|
|
// A helper function used for testing DynamicUploader offset alignment.
|
|
// A call of this function will do a Queue::WriteTexture with 1 byte of data,
|
|
// so that assuming that WriteTexture uses DynamicUploader, the first RingBuffer
|
|
// in it will contain 1 byte of data.
|
|
void UnalignDynamicUploader(wgpu::Device device);
|
|
|
|
uint32_t VertexFormatSize(wgpu::VertexFormat format);
|
|
|
|
} // namespace utils
|
|
|
|
#endif // UTILS_TESTHELPERS_H_
|