Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 1 | // Copyright 2020 The Dawn & Tint Authors |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 2 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 3 | // Redistribution and use in source and binary forms, with or without |
| 4 | // modification, are permitted provided that the following conditions are met: |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 5 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 6 | // 1. Redistributions of source code must retain the above copyright notice, this |
| 7 | // list of conditions and the following disclaimer. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 8 | // |
Austin Eng | cc2516a | 2023-10-17 20:57:54 +0000 | [diff] [blame] | 9 | // 2. Redistributions in binary form must reproduce the above copyright notice, |
| 10 | // this list of conditions and the following disclaimer in the documentation |
| 11 | // and/or other materials provided with the distribution. |
| 12 | // |
| 13 | // 3. Neither the name of the copyright holder nor the names of its |
| 14 | // contributors may be used to endorse or promote products derived from |
| 15 | // this software without specific prior written permission. |
| 16 | // |
| 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 | // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 21 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 24 | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 27 | |
dan sinclair | 99181d8 | 2023-07-20 01:14:15 +0000 | [diff] [blame] | 28 | #ifndef SRC_TINT_LANG_WGSL_AST_BUILTIN_TEXTURE_HELPER_TEST_H_ |
| 29 | #define SRC_TINT_LANG_WGSL_AST_BUILTIN_TEXTURE_HELPER_TEST_H_ |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 30 | |
| 31 | #include <vector> |
| 32 | |
Ben Clayton | cd52f38 | 2023-08-07 13:11:08 +0000 | [diff] [blame] | 33 | #include "src/tint/lang/core/access.h" |
| 34 | #include "src/tint/lang/core/texel_format.h" |
dan sinclair | 352f8c8 | 2023-07-21 00:40:07 +0000 | [diff] [blame] | 35 | #include "src/tint/lang/core/type/storage_texture.h" |
| 36 | #include "src/tint/lang/core/type/texture_dimension.h" |
Ben Clayton | ae18c41 | 2023-07-29 13:00:40 +0000 | [diff] [blame] | 37 | #include "src/tint/lang/wgsl/ast/builder.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 38 | |
James Price | f7a4d9f | 2023-05-11 13:03:38 +0000 | [diff] [blame] | 39 | namespace tint::ast::test { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 40 | |
Ben Clayton | ed3389f | 2023-02-09 23:56:42 +0000 | [diff] [blame] | 41 | /// The name of the texture global variable used by the tests. |
| 42 | static constexpr const char* kTextureName = "Texture"; |
| 43 | |
| 44 | /// The name of the sampler global variable used by the tests. |
| 45 | static constexpr const char* kSamplerName = "Sampler"; |
| 46 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 47 | enum class TextureKind { kRegular, kDepth, kDepthMultisampled, kMultisampled, kStorage }; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 48 | enum class TextureDataType { kF32, kU32, kI32 }; |
| 49 | |
| 50 | std::ostream& operator<<(std::ostream& out, const TextureKind& kind); |
| 51 | std::ostream& operator<<(std::ostream& out, const TextureDataType& ty); |
| 52 | |
| 53 | /// Non-exhaustive list of valid texture overloads |
| 54 | enum class ValidTextureOverload { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 55 | kDimensions1d, |
| 56 | kDimensions2d, |
| 57 | kDimensions2dLevel, |
| 58 | kDimensions2dArray, |
| 59 | kDimensions2dArrayLevel, |
| 60 | kDimensions3d, |
| 61 | kDimensions3dLevel, |
| 62 | kDimensionsCube, |
| 63 | kDimensionsCubeLevel, |
| 64 | kDimensionsCubeArray, |
| 65 | kDimensionsCubeArrayLevel, |
| 66 | kDimensionsMultisampled2d, |
| 67 | kDimensionsDepth2d, |
| 68 | kDimensionsDepth2dLevel, |
| 69 | kDimensionsDepth2dArray, |
| 70 | kDimensionsDepth2dArrayLevel, |
| 71 | kDimensionsDepthCube, |
| 72 | kDimensionsDepthCubeLevel, |
| 73 | kDimensionsDepthCubeArray, |
| 74 | kDimensionsDepthCubeArrayLevel, |
| 75 | kDimensionsDepthMultisampled2d, |
| 76 | kDimensionsStorageWO1d, |
| 77 | kDimensionsStorageWO2d, |
| 78 | kDimensionsStorageWO2dArray, |
| 79 | kDimensionsStorageWO3d, |
| 80 | kGather2dF32, |
| 81 | kGather2dOffsetF32, |
| 82 | kGather2dArrayF32, |
| 83 | kGather2dArrayOffsetF32, |
| 84 | kGatherCubeF32, |
| 85 | kGatherCubeArrayF32, |
| 86 | kGatherDepth2dF32, |
| 87 | kGatherDepth2dOffsetF32, |
| 88 | kGatherDepth2dArrayF32, |
| 89 | kGatherDepth2dArrayOffsetF32, |
| 90 | kGatherDepthCubeF32, |
| 91 | kGatherDepthCubeArrayF32, |
| 92 | kGatherCompareDepth2dF32, |
| 93 | kGatherCompareDepth2dOffsetF32, |
| 94 | kGatherCompareDepth2dArrayF32, |
| 95 | kGatherCompareDepth2dArrayOffsetF32, |
| 96 | kGatherCompareDepthCubeF32, |
| 97 | kGatherCompareDepthCubeArrayF32, |
| 98 | kNumLayers2dArray, |
Ben Clayton | 068eb3e | 2023-03-08 02:48:34 +0000 | [diff] [blame] | 99 | kNumLayersCubeArray, |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 100 | kNumLayersDepth2dArray, |
Ben Clayton | 068eb3e | 2023-03-08 02:48:34 +0000 | [diff] [blame] | 101 | kNumLayersDepthCubeArray, |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 102 | kNumLayersStorageWO2dArray, |
| 103 | kNumLevels2d, |
| 104 | kNumLevels2dArray, |
| 105 | kNumLevels3d, |
| 106 | kNumLevelsCube, |
| 107 | kNumLevelsCubeArray, |
| 108 | kNumLevelsDepth2d, |
| 109 | kNumLevelsDepth2dArray, |
| 110 | kNumLevelsDepthCube, |
| 111 | kNumLevelsDepthCubeArray, |
| 112 | kNumSamplesMultisampled2d, |
| 113 | kNumSamplesDepthMultisampled2d, |
| 114 | kSample1dF32, |
| 115 | kSample2dF32, |
| 116 | kSample2dOffsetF32, |
| 117 | kSample2dArrayF32, |
| 118 | kSample2dArrayOffsetF32, |
| 119 | kSample3dF32, |
| 120 | kSample3dOffsetF32, |
| 121 | kSampleCubeF32, |
| 122 | kSampleCubeArrayF32, |
| 123 | kSampleDepth2dF32, |
| 124 | kSampleDepth2dOffsetF32, |
| 125 | kSampleDepth2dArrayF32, |
| 126 | kSampleDepth2dArrayOffsetF32, |
| 127 | kSampleDepthCubeF32, |
| 128 | kSampleDepthCubeArrayF32, |
| 129 | kSampleBias2dF32, |
| 130 | kSampleBias2dOffsetF32, |
| 131 | kSampleBias2dArrayF32, |
| 132 | kSampleBias2dArrayOffsetF32, |
| 133 | kSampleBias3dF32, |
| 134 | kSampleBias3dOffsetF32, |
| 135 | kSampleBiasCubeF32, |
| 136 | kSampleBiasCubeArrayF32, |
| 137 | kSampleLevel2dF32, |
| 138 | kSampleLevel2dOffsetF32, |
| 139 | kSampleLevel2dArrayF32, |
| 140 | kSampleLevel2dArrayOffsetF32, |
| 141 | kSampleLevel3dF32, |
| 142 | kSampleLevel3dOffsetF32, |
| 143 | kSampleLevelCubeF32, |
| 144 | kSampleLevelCubeArrayF32, |
| 145 | kSampleLevelDepth2dF32, |
| 146 | kSampleLevelDepth2dOffsetF32, |
| 147 | kSampleLevelDepth2dArrayF32, |
| 148 | kSampleLevelDepth2dArrayOffsetF32, |
| 149 | kSampleLevelDepthCubeF32, |
| 150 | kSampleLevelDepthCubeArrayF32, |
| 151 | kSampleGrad2dF32, |
| 152 | kSampleGrad2dOffsetF32, |
| 153 | kSampleGrad2dArrayF32, |
| 154 | kSampleGrad2dArrayOffsetF32, |
| 155 | kSampleGrad3dF32, |
| 156 | kSampleGrad3dOffsetF32, |
| 157 | kSampleGradCubeF32, |
| 158 | kSampleGradCubeArrayF32, |
| 159 | kSampleCompareDepth2dF32, |
| 160 | kSampleCompareDepth2dOffsetF32, |
| 161 | kSampleCompareDepth2dArrayF32, |
| 162 | kSampleCompareDepth2dArrayOffsetF32, |
| 163 | kSampleCompareDepthCubeF32, |
| 164 | kSampleCompareDepthCubeArrayF32, |
| 165 | kSampleCompareLevelDepth2dF32, |
| 166 | kSampleCompareLevelDepth2dOffsetF32, |
| 167 | kSampleCompareLevelDepth2dArrayF32, |
| 168 | kSampleCompareLevelDepth2dArrayOffsetF32, |
| 169 | kSampleCompareLevelDepthCubeF32, |
| 170 | kSampleCompareLevelDepthCubeArrayF32, |
| 171 | kLoad1dLevelF32, |
| 172 | kLoad1dLevelU32, |
| 173 | kLoad1dLevelI32, |
| 174 | kLoad2dLevelF32, |
| 175 | kLoad2dLevelU32, |
| 176 | kLoad2dLevelI32, |
| 177 | kLoad2dArrayLevelF32, |
| 178 | kLoad2dArrayLevelU32, |
| 179 | kLoad2dArrayLevelI32, |
| 180 | kLoad3dLevelF32, |
| 181 | kLoad3dLevelU32, |
| 182 | kLoad3dLevelI32, |
| 183 | kLoadMultisampled2dF32, |
| 184 | kLoadMultisampled2dU32, |
| 185 | kLoadMultisampled2dI32, |
| 186 | kLoadDepth2dLevelF32, |
| 187 | kLoadDepth2dArrayLevelF32, |
| 188 | kLoadDepthMultisampled2dF32, |
| 189 | kStoreWO1dRgba32float, // Not permutated for all texel formats |
| 190 | kStoreWO2dRgba32float, // Not permutated for all texel formats |
| 191 | kStoreWO2dArrayRgba32float, // Not permutated for all texel formats |
| 192 | kStoreWO3dRgba32float, // Not permutated for all texel formats |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | /// @param texture_overload the ValidTextureOverload |
| 196 | /// @returns true if the ValidTextureOverload builtin returns no value. |
| 197 | bool ReturnsVoid(ValidTextureOverload texture_overload); |
| 198 | |
| 199 | /// Describes a texture builtin overload |
| 200 | struct TextureOverloadCase { |
Ben Clayton | 5662f79 | 2023-02-22 00:08:55 +0000 | [diff] [blame] | 201 | /// Args is a list of Expression used as arguments to the texture overload case. |
dan sinclair | bae54e7 | 2023-07-28 15:01:54 +0000 | [diff] [blame] | 202 | using Args = tint::Vector<const Expression*, 8>; |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 203 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 204 | /// Constructor for textureSample...() functions |
| 205 | TextureOverloadCase(ValidTextureOverload, |
| 206 | const char*, |
| 207 | TextureKind, |
dan sinclair | cedcdf3 | 2023-08-10 02:39:48 +0000 | [diff] [blame] | 208 | core::type::SamplerKind, |
| 209 | core::type::TextureDimension, |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 210 | TextureDataType, |
| 211 | const char*, |
Ben Clayton | b549b30 | 2023-02-22 16:18:22 +0000 | [diff] [blame] | 212 | std::function<Args(ProgramBuilder*)>, |
| 213 | bool /* returns_value */); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 214 | /// Constructor for textureLoad() functions with non-storage textures |
| 215 | TextureOverloadCase(ValidTextureOverload, |
| 216 | const char*, |
| 217 | TextureKind, |
dan sinclair | cedcdf3 | 2023-08-10 02:39:48 +0000 | [diff] [blame] | 218 | core::type::TextureDimension, |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 219 | TextureDataType, |
| 220 | const char*, |
Ben Clayton | b549b30 | 2023-02-22 16:18:22 +0000 | [diff] [blame] | 221 | std::function<Args(ProgramBuilder*)>, |
| 222 | bool /* returns_value */); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 223 | /// Constructor for textureLoad() with storage textures |
| 224 | TextureOverloadCase(ValidTextureOverload, |
| 225 | const char*, |
Ben Clayton | cd52f38 | 2023-08-07 13:11:08 +0000 | [diff] [blame] | 226 | tint::core::Access, |
| 227 | tint::core::TexelFormat, |
dan sinclair | cedcdf3 | 2023-08-10 02:39:48 +0000 | [diff] [blame] | 228 | core::type::TextureDimension, |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 229 | TextureDataType, |
| 230 | const char*, |
Ben Clayton | b549b30 | 2023-02-22 16:18:22 +0000 | [diff] [blame] | 231 | std::function<Args(ProgramBuilder*)>, |
| 232 | bool /* returns_value */); |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 233 | /// Copy constructor |
| 234 | TextureOverloadCase(const TextureOverloadCase&); |
Ben Clayton | 9a56b25 | 2023-03-15 14:09:40 +0000 | [diff] [blame] | 235 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 236 | /// Destructor |
| 237 | ~TextureOverloadCase(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 238 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 239 | /// @return a vector containing a large number (non-exhaustive) of valid |
| 240 | /// texture overloads. |
| 241 | static std::vector<TextureOverloadCase> ValidCases(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 242 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 243 | /// @param builder the AST builder used for the test |
| 244 | /// @returns the vector component type of the texture function return value |
Ben Clayton | 5662f79 | 2023-02-22 00:08:55 +0000 | [diff] [blame] | 245 | Type BuildResultVectorComponentType(ProgramBuilder* builder) const; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 246 | /// @param builder the AST builder used for the test |
| 247 | /// @returns a variable holding the test texture, automatically registered as |
| 248 | /// a global variable. |
Ben Clayton | 5662f79 | 2023-02-22 00:08:55 +0000 | [diff] [blame] | 249 | const Variable* BuildTextureVariable(ProgramBuilder* builder) const; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 250 | /// @param builder the AST builder used for the test |
| 251 | /// @returns a Variable holding the test sampler, automatically registered as |
| 252 | /// a global variable. |
Ben Clayton | 5662f79 | 2023-02-22 00:08:55 +0000 | [diff] [blame] | 253 | const Variable* BuildSamplerVariable(ProgramBuilder* builder) const; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 254 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 255 | /// The enumerator for this overload |
| 256 | const ValidTextureOverload overload; |
| 257 | /// A human readable description of the overload |
| 258 | const char* const description; |
| 259 | /// The texture kind for the texture parameter |
| 260 | const TextureKind texture_kind; |
| 261 | /// The sampler kind for the sampler parameter |
| 262 | /// Used only when texture_kind is not kStorage |
dan sinclair | cedcdf3 | 2023-08-10 02:39:48 +0000 | [diff] [blame] | 263 | core::type::SamplerKind const sampler_kind = core::type::SamplerKind::kSampler; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 264 | /// The access control for the storage texture |
| 265 | /// Used only when texture_kind is kStorage |
Ben Clayton | cd52f38 | 2023-08-07 13:11:08 +0000 | [diff] [blame] | 266 | tint::core::Access const access = tint::core::Access::kReadWrite; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 267 | /// The image format for the storage texture |
| 268 | /// Used only when texture_kind is kStorage |
Ben Clayton | cd52f38 | 2023-08-07 13:11:08 +0000 | [diff] [blame] | 269 | tint::core::TexelFormat const texel_format = tint::core::TexelFormat::kUndefined; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 270 | /// The dimensions of the texture parameter |
dan sinclair | cedcdf3 | 2023-08-10 02:39:48 +0000 | [diff] [blame] | 271 | core::type::TextureDimension const texture_dimension; |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 272 | /// The data type of the texture parameter |
| 273 | const TextureDataType texture_data_type; |
| 274 | /// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc |
| 275 | const char* const function; |
| 276 | /// A function that builds the AST arguments for the overload |
Ben Clayton | 783b169 | 2022-08-02 17:03:35 +0000 | [diff] [blame] | 277 | std::function<Args(ProgramBuilder*)> const args; |
Ben Clayton | b549b30 | 2023-02-22 16:18:22 +0000 | [diff] [blame] | 278 | /// True if the function returns a value |
| 279 | const bool returns_value; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 280 | }; |
| 281 | |
| 282 | std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data); |
| 283 | |
James Price | f7a4d9f | 2023-05-11 13:03:38 +0000 | [diff] [blame] | 284 | } // namespace tint::ast::test |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 285 | |
dan sinclair | 99181d8 | 2023-07-20 01:14:15 +0000 | [diff] [blame] | 286 | #endif // SRC_TINT_LANG_WGSL_AST_BUILTIN_TEXTURE_HELPER_TEST_H_ |