1 // Copyright 2020 The Dawn Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef UTILS_TESTHELPERS_H_ 16 #define UTILS_TESTHELPERS_H_ 17 18 #include <dawn/webgpu_cpp.h> 19 20 namespace utils { 21 22 struct TextureDataCopyLayout { 23 uint64_t byteLength; 24 uint64_t texelBlockCount; 25 uint32_t bytesPerRow; 26 uint32_t rowsPerImage; 27 uint32_t texelBlocksPerRow; 28 uint32_t bytesPerImage; 29 uint32_t texelBlocksPerImage; 30 wgpu::Extent3D mipSize; 31 }; 32 33 uint32_t GetMinimumBytesPerRow(wgpu::TextureFormat format, uint32_t width); 34 TextureDataCopyLayout GetTextureDataCopyLayoutForTextureAtLevel( 35 wgpu::TextureFormat format, 36 wgpu::Extent3D textureSizeAtLevel0, 37 uint32_t mipmapLevel, 38 wgpu::TextureDimension dimension = wgpu::TextureDimension::e2D, 39 uint32_t rowsPerImage = wgpu::kCopyStrideUndefined); 40 41 uint64_t RequiredBytesInCopy(uint64_t bytesPerRow, 42 uint64_t rowsPerImage, 43 wgpu::Extent3D copyExtent, 44 wgpu::TextureFormat textureFormat); 45 uint64_t RequiredBytesInCopy(uint64_t bytesPerRow, 46 uint64_t rowsPerImage, 47 uint64_t widthInBlocks, 48 uint64_t heightInBlocks, 49 uint64_t depth, 50 uint64_t bytesPerBlock); 51 52 uint64_t GetTexelCountInCopyRegion(uint64_t bytesPerRow, 53 uint64_t rowsPerImage, 54 wgpu::Extent3D copyExtent, 55 wgpu::TextureFormat textureFormat); 56 57 // A helper function used for testing DynamicUploader offset alignment. 58 // A call of this function will do a Queue::WriteTexture with 1 byte of data, 59 // so that assuming that WriteTexture uses DynamicUploader, the first RingBuffer 60 // in it will contain 1 byte of data. 61 void UnalignDynamicUploader(wgpu::Device device); 62 63 uint32_t VertexFormatSize(wgpu::VertexFormat format); 64 65 } // namespace utils 66 67 #endif // UTILS_TESTHELPERS_H_ 68