• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Tint 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 SRC_AST_INTRINSIC_TEXTURE_HELPER_TEST_H_
16 #define SRC_AST_INTRINSIC_TEXTURE_HELPER_TEST_H_
17 
18 #include <vector>
19 
20 #include "src/ast/access.h"
21 #include "src/program_builder.h"
22 #include "src/sem/storage_texture_type.h"
23 
24 namespace tint {
25 namespace ast {
26 namespace intrinsic {
27 namespace test {
28 
29 enum class TextureKind {
30   kRegular,
31   kDepth,
32   kDepthMultisampled,
33   kMultisampled,
34   kStorage
35 };
36 enum class TextureDataType { kF32, kU32, kI32 };
37 
38 std::ostream& operator<<(std::ostream& out, const TextureKind& kind);
39 std::ostream& operator<<(std::ostream& out, const TextureDataType& ty);
40 
41 /// Non-exhaustive list of valid texture overloads
42 enum class ValidTextureOverload {
43   kDimensions1d,
44   kDimensions2d,
45   kDimensions2dLevel,
46   kDimensions2dArray,
47   kDimensions2dArrayLevel,
48   kDimensions3d,
49   kDimensions3dLevel,
50   kDimensionsCube,
51   kDimensionsCubeLevel,
52   kDimensionsCubeArray,
53   kDimensionsCubeArrayLevel,
54   kDimensionsMultisampled2d,
55   kDimensionsDepth2d,
56   kDimensionsDepth2dLevel,
57   kDimensionsDepth2dArray,
58   kDimensionsDepth2dArrayLevel,
59   kDimensionsDepthCube,
60   kDimensionsDepthCubeLevel,
61   kDimensionsDepthCubeArray,
62   kDimensionsDepthCubeArrayLevel,
63   kDimensionsDepthMultisampled2d,
64   kDimensionsStorageWO1d,
65   kDimensionsStorageWO2d,
66   kDimensionsStorageWO2dArray,
67   kDimensionsStorageWO3d,
68   kGather2dF32,
69   kGather2dOffsetF32,
70   kGather2dArrayF32,
71   kGather2dArrayOffsetF32,
72   kGatherCubeF32,
73   kGatherCubeArrayF32,
74   kGatherDepth2dF32,
75   kGatherDepth2dOffsetF32,
76   kGatherDepth2dArrayF32,
77   kGatherDepth2dArrayOffsetF32,
78   kGatherDepthCubeF32,
79   kGatherDepthCubeArrayF32,
80   kGatherCompareDepth2dF32,
81   kGatherCompareDepth2dOffsetF32,
82   kGatherCompareDepth2dArrayF32,
83   kGatherCompareDepth2dArrayOffsetF32,
84   kGatherCompareDepthCubeF32,
85   kGatherCompareDepthCubeArrayF32,
86   kNumLayers2dArray,
87   kNumLayersCubeArray,
88   kNumLayersDepth2dArray,
89   kNumLayersDepthCubeArray,
90   kNumLayersStorageWO2dArray,
91   kNumLevels2d,
92   kNumLevels2dArray,
93   kNumLevels3d,
94   kNumLevelsCube,
95   kNumLevelsCubeArray,
96   kNumLevelsDepth2d,
97   kNumLevelsDepth2dArray,
98   kNumLevelsDepthCube,
99   kNumLevelsDepthCubeArray,
100   kNumSamplesMultisampled2d,
101   kNumSamplesDepthMultisampled2d,
102   kSample1dF32,
103   kSample2dF32,
104   kSample2dOffsetF32,
105   kSample2dArrayF32,
106   kSample2dArrayOffsetF32,
107   kSample3dF32,
108   kSample3dOffsetF32,
109   kSampleCubeF32,
110   kSampleCubeArrayF32,
111   kSampleDepth2dF32,
112   kSampleDepth2dOffsetF32,
113   kSampleDepth2dArrayF32,
114   kSampleDepth2dArrayOffsetF32,
115   kSampleDepthCubeF32,
116   kSampleDepthCubeArrayF32,
117   kSampleBias2dF32,
118   kSampleBias2dOffsetF32,
119   kSampleBias2dArrayF32,
120   kSampleBias2dArrayOffsetF32,
121   kSampleBias3dF32,
122   kSampleBias3dOffsetF32,
123   kSampleBiasCubeF32,
124   kSampleBiasCubeArrayF32,
125   kSampleLevel2dF32,
126   kSampleLevel2dOffsetF32,
127   kSampleLevel2dArrayF32,
128   kSampleLevel2dArrayOffsetF32,
129   kSampleLevel3dF32,
130   kSampleLevel3dOffsetF32,
131   kSampleLevelCubeF32,
132   kSampleLevelCubeArrayF32,
133   kSampleLevelDepth2dF32,
134   kSampleLevelDepth2dOffsetF32,
135   kSampleLevelDepth2dArrayF32,
136   kSampleLevelDepth2dArrayOffsetF32,
137   kSampleLevelDepthCubeF32,
138   kSampleLevelDepthCubeArrayF32,
139   kSampleGrad2dF32,
140   kSampleGrad2dOffsetF32,
141   kSampleGrad2dArrayF32,
142   kSampleGrad2dArrayOffsetF32,
143   kSampleGrad3dF32,
144   kSampleGrad3dOffsetF32,
145   kSampleGradCubeF32,
146   kSampleGradCubeArrayF32,
147   kSampleCompareDepth2dF32,
148   kSampleCompareDepth2dOffsetF32,
149   kSampleCompareDepth2dArrayF32,
150   kSampleCompareDepth2dArrayOffsetF32,
151   kSampleCompareDepthCubeF32,
152   kSampleCompareDepthCubeArrayF32,
153   kSampleCompareLevelDepth2dF32,
154   kSampleCompareLevelDepth2dOffsetF32,
155   kSampleCompareLevelDepth2dArrayF32,
156   kSampleCompareLevelDepth2dArrayOffsetF32,
157   kSampleCompareLevelDepthCubeF32,
158   kSampleCompareLevelDepthCubeArrayF32,
159   kLoad1dLevelF32,
160   kLoad1dLevelU32,
161   kLoad1dLevelI32,
162   kLoad2dLevelF32,
163   kLoad2dLevelU32,
164   kLoad2dLevelI32,
165   kLoad2dArrayLevelF32,
166   kLoad2dArrayLevelU32,
167   kLoad2dArrayLevelI32,
168   kLoad3dLevelF32,
169   kLoad3dLevelU32,
170   kLoad3dLevelI32,
171   kLoadMultisampled2dF32,
172   kLoadMultisampled2dU32,
173   kLoadMultisampled2dI32,
174   kLoadDepth2dLevelF32,
175   kLoadDepth2dArrayLevelF32,
176   kLoadDepthMultisampled2dF32,
177   kStoreWO1dRgba32float,       // Not permutated for all texel formats
178   kStoreWO2dRgba32float,       // Not permutated for all texel formats
179   kStoreWO2dArrayRgba32float,  // Not permutated for all texel formats
180   kStoreWO3dRgba32float,       // Not permutated for all texel formats
181 };
182 
183 /// @param texture_overload the ValidTextureOverload
184 /// @returns true if the ValidTextureOverload intrinsic returns no value.
185 bool ReturnsVoid(ValidTextureOverload texture_overload);
186 
187 /// Describes a texture intrinsic overload
188 struct TextureOverloadCase {
189   /// Constructor for textureSample...() functions
190   TextureOverloadCase(ValidTextureOverload,
191                       const char*,
192                       TextureKind,
193                       ast::SamplerKind,
194                       ast::TextureDimension,
195                       TextureDataType,
196                       const char*,
197                       std::function<ExpressionList(ProgramBuilder*)>);
198   /// Constructor for textureLoad() functions with non-storage textures
199   TextureOverloadCase(ValidTextureOverload,
200                       const char*,
201                       TextureKind,
202                       ast::TextureDimension,
203                       TextureDataType,
204                       const char*,
205                       std::function<ExpressionList(ProgramBuilder*)>);
206   /// Constructor for textureLoad() with storage textures
207   TextureOverloadCase(ValidTextureOverload,
208                       const char*,
209                       Access,
210                       ast::ImageFormat,
211                       ast::TextureDimension,
212                       TextureDataType,
213                       const char*,
214                       std::function<ExpressionList(ProgramBuilder*)>);
215   /// Copy constructor
216   TextureOverloadCase(const TextureOverloadCase&);
217   /// Destructor
218   ~TextureOverloadCase();
219 
220   /// @return a vector containing a large number (non-exhaustive) of valid
221   /// texture overloads.
222   static std::vector<TextureOverloadCase> ValidCases();
223 
224   /// @param builder the AST builder used for the test
225   /// @returns the vector component type of the texture function return value
226   const ast::Type* BuildResultVectorComponentType(
227       ProgramBuilder* builder) const;
228   /// @param builder the AST builder used for the test
229   /// @returns a variable holding the test texture, automatically registered as
230   /// a global variable.
231   const ast::Variable* BuildTextureVariable(ProgramBuilder* builder) const;
232   /// @param builder the AST builder used for the test
233   /// @returns a Variable holding the test sampler, automatically registered as
234   /// a global variable.
235   const ast::Variable* BuildSamplerVariable(ProgramBuilder* builder) const;
236 
237   /// The enumerator for this overload
238   const ValidTextureOverload overload;
239   /// A human readable description of the overload
240   const char* const description;
241   /// The texture kind for the texture parameter
242   const TextureKind texture_kind;
243   /// The sampler kind for the sampler parameter
244   /// Used only when texture_kind is not kStorage
245   ast::SamplerKind const sampler_kind = ast::SamplerKind::kSampler;
246   /// The access control for the storage texture
247   /// Used only when texture_kind is kStorage
248   Access const access = Access::kReadWrite;
249   /// The image format for the storage texture
250   /// Used only when texture_kind is kStorage
251   ast::ImageFormat const image_format = ast::ImageFormat::kNone;
252   /// The dimensions of the texture parameter
253   ast::TextureDimension const texture_dimension;
254   /// The data type of the texture parameter
255   const TextureDataType texture_data_type;
256   /// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc
257   const char* const function;
258   /// A function that builds the AST arguments for the overload
259   std::function<ExpressionList(ProgramBuilder*)> const args;
260 };
261 
262 std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data);
263 
264 }  // namespace test
265 }  // namespace intrinsic
266 }  // namespace ast
267 }  // namespace tint
268 
269 #endif  // SRC_AST_INTRINSIC_TEXTURE_HELPER_TEST_H_
270