blob: 01c7a65bf55bcc83e205497c60cdf5d50d329085 [file] [log] [blame]
Austin Eng3318caa2019-08-13 00:22:28 +00001// 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"
Tomek Ponitka0f5d4962020-07-07 10:18:51 +000020#include "dawn_native/Texture.h"
Austin Eng3318caa2019-08-13 00:22:28 +000021
22#include <vector>
23
24namespace dawn_native {
25
Hao Li5191adc2020-07-01 10:48:16 +000026 class QuerySetBase;
Corentin Wallez2dd2d672021-05-05 15:41:13 +000027 struct SyncScopeResourceUsage;
Austin Eng0d9fce12020-07-30 15:29:57 +000028 struct TexelBlockInfo;
Austin Eng3318caa2019-08-13 00:22:28 +000029
Corentin Wallez2dd2d672021-05-05 15:41:13 +000030 MaybeError ValidateSyncScopeResourceUsage(const SyncScopeResourceUsage& usage);
Austin Eng3318caa2019-08-13 00:22:28 +000031
Hao Li575729e2020-11-16 02:24:06 +000032 MaybeError ValidateTimestampQuery(QuerySetBase* querySet, uint32_t queryIndex);
Hao Li5191adc2020-07-01 10:48:16 +000033
Tomek Ponitka11c0f572020-08-11 12:04:52 +000034 ResultOrError<uint64_t> ComputeRequiredBytesInCopy(const TexelBlockInfo& blockInfo,
35 const Extent3D& copySize,
36 uint32_t bytesPerRow,
37 uint32_t rowsPerImage);
Tomek Ponitka9d66c532020-07-15 18:06:07 +000038
Kai Ninomiya16036cf2020-11-06 13:41:50 +000039 TextureDataLayout FixUpDeprecatedTextureDataLayoutOptions(
40 DeviceBase* device,
41 const TextureDataLayout& originalLayout,
42 const TexelBlockInfo& blockInfo,
43 const Extent3D& copyExtent);
44 void ApplyDefaultTextureDataLayoutOptions(TextureDataLayout* layout,
45 const TexelBlockInfo& blockInfo,
46 const Extent3D& copyExtent);
47 MaybeError ValidateLinearTextureData(const TextureDataLayout& layout,
Tomek Ponitka0f5d4962020-07-07 10:18:51 +000048 uint64_t byteSize,
Austin Eng0d9fce12020-07-30 15:29:57 +000049 const TexelBlockInfo& blockInfo,
Tomek Ponitka0f5d4962020-07-07 10:18:51 +000050 const Extent3D& copyExtent);
Yunchao He3e8f3f92021-04-01 22:40:43 +000051 MaybeError ValidateTextureCopyRange(DeviceBase const* device,
52 const ImageCopyTexture& imageCopyTexture,
Tomek Ponitka0f5d4962020-07-07 10:18:51 +000053 const Extent3D& copySize);
Corentin Wallez80915842021-03-04 18:13:45 +000054 ResultOrError<Aspect> SingleAspectUsedByImageCopyTexture(const ImageCopyTexture& view);
55 MaybeError ValidateLinearToDepthStencilCopyRestrictions(const ImageCopyTexture& dst);
Tomek Ponitka0f5d4962020-07-07 10:18:51 +000056
Corentin Wallez80915842021-03-04 18:13:45 +000057 MaybeError ValidateImageCopyBuffer(DeviceBase const* device,
58 const ImageCopyBuffer& imageCopyBuffer);
59 MaybeError ValidateImageCopyTexture(DeviceBase const* device,
60 const ImageCopyTexture& imageCopyTexture,
61 const Extent3D& copySize);
Tomek Ponitka0f5d4962020-07-07 10:18:51 +000062
Tomek Ponitka0f5d4962020-07-07 10:18:51 +000063 MaybeError ValidateCopySizeFitsInBuffer(const Ref<BufferBase>& buffer,
64 uint64_t offset,
65 uint64_t size);
66
Jiawei Shaoe472c452020-06-08 11:30:01 +000067 bool IsRangeOverlapped(uint32_t startA, uint32_t startB, uint32_t length);
68
Corentin Wallez80915842021-03-04 18:13:45 +000069 MaybeError ValidateTextureToTextureCopyRestrictions(const ImageCopyTexture& src,
70 const ImageCopyTexture& dst,
Yan, Shaobodb8766b2020-11-04 02:30:16 +000071 const Extent3D& copySize);
72
Yan, Shaobod42f4b32021-03-23 02:09:37 +000073 MaybeError ValidateCopyTextureForBrowserRestrictions(const ImageCopyTexture& src,
74 const ImageCopyTexture& dst,
75 const Extent3D& copySize);
76
Yan, Shaobodb8766b2020-11-04 02:30:16 +000077 MaybeError ValidateCanUseAs(const TextureBase* texture, wgpu::TextureUsage usage);
78
79 MaybeError ValidateCanUseAs(const BufferBase* buffer, wgpu::BufferUsage usage);
80
Austin Eng3318caa2019-08-13 00:22:28 +000081} // namespace dawn_native
82
83#endif // DAWNNATIVE_COMMANDVALIDATION_H_