1 // Copyright 2019 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 DAWNNATIVE_COMMANDVALIDATION_H_ 16 #define DAWNNATIVE_COMMANDVALIDATION_H_ 17 18 #include "dawn_native/CommandAllocator.h" 19 #include "dawn_native/Error.h" 20 #include "dawn_native/Texture.h" 21 22 #include <vector> 23 24 namespace dawn_native { 25 26 class QuerySetBase; 27 struct SyncScopeResourceUsage; 28 struct TexelBlockInfo; 29 30 MaybeError ValidateSyncScopeResourceUsage(const SyncScopeResourceUsage& usage); 31 32 MaybeError ValidateTimestampQuery(QuerySetBase* querySet, uint32_t queryIndex); 33 34 MaybeError ValidateWriteBuffer(const DeviceBase* device, 35 const BufferBase* buffer, 36 uint64_t bufferOffset, 37 uint64_t size); 38 39 ResultOrError<uint64_t> ComputeRequiredBytesInCopy(const TexelBlockInfo& blockInfo, 40 const Extent3D& copySize, 41 uint32_t bytesPerRow, 42 uint32_t rowsPerImage); 43 44 void ApplyDefaultTextureDataLayoutOptions(TextureDataLayout* layout, 45 const TexelBlockInfo& blockInfo, 46 const Extent3D& copyExtent); 47 MaybeError ValidateLinearTextureData(const TextureDataLayout& layout, 48 uint64_t byteSize, 49 const TexelBlockInfo& blockInfo, 50 const Extent3D& copyExtent); 51 MaybeError ValidateTextureCopyRange(DeviceBase const* device, 52 const ImageCopyTexture& imageCopyTexture, 53 const Extent3D& copySize); 54 ResultOrError<Aspect> SingleAspectUsedByImageCopyTexture(const ImageCopyTexture& view); 55 MaybeError ValidateLinearToDepthStencilCopyRestrictions(const ImageCopyTexture& dst); 56 57 MaybeError ValidateImageCopyBuffer(DeviceBase const* device, 58 const ImageCopyBuffer& imageCopyBuffer); 59 MaybeError ValidateImageCopyTexture(DeviceBase const* device, 60 const ImageCopyTexture& imageCopyTexture, 61 const Extent3D& copySize); 62 63 MaybeError ValidateCopySizeFitsInBuffer(const Ref<BufferBase>& buffer, 64 uint64_t offset, 65 uint64_t size); 66 67 bool IsRangeOverlapped(uint32_t startA, uint32_t startB, uint32_t length); 68 69 MaybeError ValidateTextureToTextureCopyCommonRestrictions(const ImageCopyTexture& src, 70 const ImageCopyTexture& dst, 71 const Extent3D& copySize); 72 MaybeError ValidateTextureToTextureCopyRestrictions(const ImageCopyTexture& src, 73 const ImageCopyTexture& dst, 74 const Extent3D& copySize); 75 76 MaybeError ValidateCanUseAs(const TextureBase* texture, wgpu::TextureUsage usage); 77 78 MaybeError ValidateInternalCanUseAs(const TextureBase* texture, wgpu::TextureUsage usage); 79 80 MaybeError ValidateCanUseAs(const BufferBase* buffer, wgpu::BufferUsage usage); 81 82 } // namespace dawn_native 83 84 #endif // DAWNNATIVE_COMMANDVALIDATION_H_ 85