From 3cbf3fc4c520306ab15a54a4e22020fdfd4bb31c Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Sat, 21 Jan 2023 19:16:15 +0000 Subject: [PATCH] Move TextureDimension to type/ This cl pulls TextureDimension out of ast/texture and into type/texture_dimension removing a type dependency on ast. Change-Id: Icf06ec32ee9051286f169ae9538c48416f513039 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/117603 Commit-Queue: Dan Sinclair Reviewed-by: Ben Clayton Kokoro: Kokoro --- src/tint/BUILD.gn | 3 + src/tint/CMakeLists.txt | 2 + src/tint/ast/builtin_texture_helper_test.cc | 283 +++++++++--------- src/tint/ast/builtin_texture_helper_test.h | 9 +- src/tint/ast/depth_multisampled_texture.cc | 6 +- src/tint/ast/depth_multisampled_texture.h | 6 +- .../ast/depth_multisampled_texture_test.cc | 6 +- src/tint/ast/depth_texture.cc | 8 +- src/tint/ast/depth_texture.h | 3 +- src/tint/ast/depth_texture_test.cc | 8 +- src/tint/ast/external_texture.cc | 5 +- src/tint/ast/external_texture_test.cc | 3 +- src/tint/ast/multisampled_texture.cc | 2 +- src/tint/ast/multisampled_texture.h | 3 +- src/tint/ast/multisampled_texture_test.cc | 10 +- src/tint/ast/sampled_texture.cc | 2 +- src/tint/ast/sampled_texture.h | 3 +- src/tint/ast/sampled_texture_test.cc | 10 +- src/tint/ast/storage_texture.cc | 2 +- src/tint/ast/storage_texture.h | 3 +- src/tint/ast/storage_texture_test.cc | 30 +- src/tint/ast/texture.cc | 61 ++-- src/tint/ast/texture.h | 38 +-- src/tint/ast/texture_test.cc | 28 +- src/tint/inspector/inspector_test.cc | 78 ++--- src/tint/inspector/resource_binding.cc | 17 +- src/tint/inspector/resource_binding.h | 6 +- src/tint/inspector/test_inspector_builder.cc | 16 +- src/tint/inspector/test_inspector_builder.h | 5 +- src/tint/program_builder.h | 21 +- src/tint/reader/spirv/enum_converter.cc | 20 +- src/tint/reader/spirv/enum_converter.h | 5 +- src/tint/reader/spirv/enum_converter_test.cc | 33 +- src/tint/reader/spirv/function.cc | 13 +- src/tint/reader/spirv/parser_impl.cc | 7 +- src/tint/reader/spirv/parser_type.cc | 23 +- src/tint/reader/spirv/parser_type.h | 26 +- src/tint/reader/spirv/parser_type_test.cc | 49 +-- src/tint/reader/wgsl/parser_impl.cc | 39 +-- src/tint/reader/wgsl/parser_impl.h | 7 +- .../wgsl/parser_impl_depth_texture_test.cc | 11 +- .../wgsl/parser_impl_sampled_texture_test.cc | 13 +- .../wgsl/parser_impl_storage_texture_test.cc | 9 +- .../wgsl/parser_impl_texture_sampler_test.cc | 15 +- .../resolver/assignment_validation_test.cc | 5 +- .../resolver/attribute_validation_test.cc | 33 +- src/tint/resolver/builtin_test.cc | 39 +-- src/tint/resolver/dependency_graph_test.cc | 15 +- src/tint/resolver/intrinsic_table.cc | 43 +-- src/tint/resolver/intrinsic_table_test.cc | 21 +- src/tint/resolver/load_test.cc | 11 +- src/tint/resolver/ptr_ref_validation_test.cc | 8 +- src/tint/resolver/resolver_test.cc | 19 +- src/tint/resolver/root_identifier_test.cc | 3 +- src/tint/resolver/side_effects_test.cc | 11 +- src/tint/resolver/type_validation_test.cc | 65 ++-- src/tint/resolver/validation_test.cc | 3 +- src/tint/resolver/validator.cc | 13 +- src/tint/resolver/variable_test.cc | 6 +- src/tint/resolver/variable_validation_test.cc | 8 +- src/tint/transform/builtin_polyfill.cc | 3 +- .../transform/multiplanar_external_texture.cc | 51 ++-- src/tint/transform/texture_1d_to_2d.cc | 17 +- src/tint/type/array.cc | 2 +- src/tint/type/depth_multisampled_texture.cc | 7 +- src/tint/type/depth_multisampled_texture.h | 3 +- .../type/depth_multisampled_texture_test.cc | 23 +- src/tint/type/depth_texture.cc | 9 +- src/tint/type/depth_texture.h | 3 +- src/tint/type/depth_texture_test.cc | 29 +- src/tint/type/external_texture.cc | 3 +- src/tint/type/external_texture_test.cc | 3 +- src/tint/type/multisampled_texture.cc | 3 +- src/tint/type/multisampled_texture.h | 3 +- src/tint/type/multisampled_texture_test.cc | 35 +-- src/tint/type/sampled_texture.cc | 3 +- src/tint/type/sampled_texture.h | 3 +- src/tint/type/sampled_texture_test.cc | 37 +-- src/tint/type/storage_texture.cc | 2 +- src/tint/type/storage_texture.h | 3 +- src/tint/type/storage_texture_test.cc | 73 +++-- src/tint/type/texture.cc | 2 +- src/tint/type/texture.h | 7 +- src/tint/type/texture_dimension.cc | 46 +++ src/tint/type/texture_dimension.h | 47 +++ src/tint/type/texture_test.cc | 14 +- src/tint/writer/flatten_bindings_test.cc | 11 +- src/tint/writer/glsl/generator_impl.cc | 19 +- .../writer/glsl/generator_impl_type_test.cc | 83 ++--- src/tint/writer/hlsl/generator_impl.cc | 47 +-- .../writer/hlsl/generator_impl_type_test.cc | 81 ++--- src/tint/writer/msl/generator_impl.cc | 51 ++-- .../writer/msl/generator_impl_type_test.cc | 39 +-- src/tint/writer/spirv/builder.cc | 29 +- src/tint/writer/spirv/builder_builtin_test.cc | 3 +- .../spirv/builder_global_variable_test.cc | 3 +- src/tint/writer/spirv/builder_type_test.cc | 45 +-- src/tint/writer/wgsl/generator_impl.cc | 13 +- .../wgsl/generator_impl_global_decl_test.cc | 3 +- .../writer/wgsl/generator_impl_type_test.cc | 35 +-- 100 files changed, 1134 insertions(+), 1009 deletions(-) create mode 100644 src/tint/type/texture_dimension.cc create mode 100644 src/tint/type/texture_dimension.h diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index 139f8ee8af..6e171e61b7 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -586,6 +586,7 @@ libtint_source_set("libtint_core_all_src") { "type/storage_texture.h", "type/struct.h", "type/texture.h", + "type/texture_dimension.h", "type/type.h", "type/u32.h", "type/unique_node.h", @@ -739,6 +740,8 @@ libtint_source_set("libtint_type_src") { "type/struct.h", "type/texture.cc", "type/texture.h", + "type/texture_dimension.cc", + "type/texture_dimension.h", "type/type.cc", "type/type.h", "type/u32.cc", diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 2f7bda7912..45c45e77d7 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -514,6 +514,8 @@ list(APPEND TINT_LIB_SRCS type/struct.h type/texture.cc type/texture.h + type/texture_dimension.cc + type/texture_dimension.h type/type.cc type/type.h type/u32.cc diff --git a/src/tint/ast/builtin_texture_helper_test.cc b/src/tint/ast/builtin_texture_helper_test.cc index 0ea2cedc9b..7dda560e1b 100644 --- a/src/tint/ast/builtin_texture_helper_test.cc +++ b/src/tint/ast/builtin_texture_helper_test.cc @@ -17,6 +17,7 @@ #include "src/tint/type/depth_texture.h" #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" using namespace tint::number_suffixes; // NOLINT @@ -26,7 +27,7 @@ TextureOverloadCase::TextureOverloadCase(ValidTextureOverload o, const char* desc, TextureKind tk, ast::SamplerKind sk, - ast::TextureDimension dims, + type::TextureDimension dims, TextureDataType datatype, const char* f, std::function a) @@ -41,7 +42,7 @@ TextureOverloadCase::TextureOverloadCase(ValidTextureOverload o, TextureOverloadCase::TextureOverloadCase(ValidTextureOverload o, const char* desc, TextureKind tk, - ast::TextureDimension dims, + type::TextureDimension dims, TextureDataType datatype, const char* f, std::function a) @@ -56,7 +57,7 @@ TextureOverloadCase::TextureOverloadCase(ValidTextureOverload o, const char* d, Access acc, ast::TexelFormat fmt, - ast::TextureDimension dims, + type::TextureDimension dims, TextureDataType datatype, const char* f, std::function a) @@ -186,7 +187,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_1d) -> u32", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -196,7 +197,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_2d) -> vec2", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -207,7 +208,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> vec2", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture", 1_i); }, @@ -217,7 +218,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_2d_array) -> vec2", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -228,7 +229,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> vec2", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture", 1_i); }, @@ -238,7 +239,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_3d) -> vec3", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -249,7 +250,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> vec3", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture", 1_i); }, @@ -259,7 +260,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_cube) -> vec2", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -270,7 +271,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> vec2", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture", 1_i); }, @@ -280,7 +281,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_cube_array) -> vec2", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -291,7 +292,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> vec2", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture", 1_i); }, @@ -301,7 +302,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_multisampled_2d)-> vec2", TextureKind::kMultisampled, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -311,7 +312,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_depth_2d) -> vec2", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -322,7 +323,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> vec2", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture", 1_i); }, @@ -332,7 +333,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_depth_2d_array) -> vec2", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -343,7 +344,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> vec2", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture", 1_i); }, @@ -353,7 +354,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_depth_cube) -> vec2", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -364,7 +365,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> vec2", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture", 1_i); }, @@ -374,7 +375,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_depth_cube_array) -> vec2", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -385,7 +386,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> vec2", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture", 1_i); }, @@ -395,7 +396,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_depth_multisampled_2d) -> vec2", TextureKind::kDepthMultisampled, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -405,7 +406,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_1d) -> u32", ast::Access::kWrite, ast::TexelFormat::kRgba32Float, - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -415,7 +416,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_2d) -> vec2", ast::Access::kWrite, ast::TexelFormat::kRgba32Float, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -425,7 +426,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_2d_array) -> vec2", ast::Access::kWrite, ast::TexelFormat::kRgba32Float, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -435,7 +436,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureDimensions(t : texture_storage_3d) -> vec3", ast::Access::kWrite, ast::TexelFormat::kRgba32Float, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureDimensions", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -449,7 +450,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -468,7 +469,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -488,7 +489,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : i32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -509,7 +510,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -529,7 +530,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec3) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -548,7 +549,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : u32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -566,7 +567,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2) -> vec4", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -583,7 +584,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -601,7 +602,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : u32) -> vec4", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -620,7 +621,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -638,7 +639,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec3) -> vec4", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -655,7 +656,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : u32) -> vec4", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureGather", [](ProgramBuilder* b) { @@ -673,7 +674,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> vec4", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureGatherCompare", [](ProgramBuilder* b) { @@ -692,7 +693,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureGatherCompare", [](ProgramBuilder* b) { @@ -712,7 +713,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> vec4", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureGatherCompare", [](ProgramBuilder* b) { @@ -733,7 +734,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureGatherCompare", [](ProgramBuilder* b) { @@ -753,7 +754,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> vec4", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureGatherCompare", [](ProgramBuilder* b) { @@ -772,7 +773,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> vec4", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureGatherCompare", [](ProgramBuilder* b) { @@ -788,7 +789,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLayers(t : texture_2d_array) -> u32", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureNumLayers", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -798,7 +799,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLayers(t : texture_cube_array) -> u32", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureNumLayers", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -808,7 +809,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLayers(t : texture_depth_2d_array) -> u32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureNumLayers", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -818,7 +819,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLayers(t : texture_depth_cube_array) -> u32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureNumLayers", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -828,7 +829,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLayers(t : texture_storage_2d_array) -> u32", ast::Access::kWrite, ast::TexelFormat::kRgba32Float, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureNumLayers", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -838,7 +839,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLevels(t : texture_2d) -> u32", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureNumLevels", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -848,7 +849,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLevels(t : texture_2d_array) -> u32", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureNumLevels", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -858,7 +859,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLevels(t : texture_3d) -> u32", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureNumLevels", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -868,7 +869,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLevels(t : texture_cube) -> u32", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureNumLevels", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -878,7 +879,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLevels(t : texture_cube_array) -> u32", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureNumLevels", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -888,7 +889,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLevels(t : texture_depth_2d) -> u32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureNumLevels", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -898,7 +899,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLevels(t : texture_depth_2d_array) -> u32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureNumLevels", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -908,7 +909,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLevels(t : texture_depth_cube) -> u32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureNumLevels", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -918,7 +919,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumLevels(t : texture_depth_cube_array) -> u32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureNumLevels", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -928,7 +929,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumSamples(t : texture_multisampled_2d) -> u32", TextureKind::kMultisampled, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureNumSamples", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -938,7 +939,7 @@ std::vector TextureOverloadCase::ValidCases() { "textureNumSamples(t : texture_depth_multisampled_2d) -> u32", TextureKind::kMultisampled, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureNumSamples", [](ProgramBuilder* b) { return b->ExprList("texture"); }, @@ -950,7 +951,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -966,7 +967,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -983,7 +984,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1001,7 +1002,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : i32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1020,7 +1021,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1038,7 +1039,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec3) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1055,7 +1056,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec3) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1072,7 +1073,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec3) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1089,7 +1090,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : i32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1106,7 +1107,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1123,7 +1124,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1141,7 +1142,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : i32) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1160,7 +1161,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1178,7 +1179,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec3) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1195,7 +1196,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : u32) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureSample", [](ProgramBuilder* b) { @@ -1213,7 +1214,7 @@ std::vector TextureOverloadCase::ValidCases() { " bias : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleBias", [](ProgramBuilder* b) { @@ -1232,7 +1233,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleBias", [](ProgramBuilder* b) { @@ -1252,7 +1253,7 @@ std::vector TextureOverloadCase::ValidCases() { " bias : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleBias", [](ProgramBuilder* b) { @@ -1273,7 +1274,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleBias", [](ProgramBuilder* b) { @@ -1293,7 +1294,7 @@ std::vector TextureOverloadCase::ValidCases() { " bias : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureSampleBias", [](ProgramBuilder* b) { @@ -1312,7 +1313,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec3) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureSampleBias", [](ProgramBuilder* b) { @@ -1331,7 +1332,7 @@ std::vector TextureOverloadCase::ValidCases() { " bias : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureSampleBias", [](ProgramBuilder* b) { @@ -1350,7 +1351,7 @@ std::vector TextureOverloadCase::ValidCases() { " bias : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureSampleBias", [](ProgramBuilder* b) { @@ -1369,7 +1370,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1388,7 +1389,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1408,7 +1409,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1429,7 +1430,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1449,7 +1450,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1468,7 +1469,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec3) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1487,7 +1488,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1506,7 +1507,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : f32) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1525,7 +1526,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : u32) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1544,7 +1545,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1564,7 +1565,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : u32) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1585,7 +1586,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1605,7 +1606,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1624,7 +1625,7 @@ std::vector TextureOverloadCase::ValidCases() { " level : i32) -> f32", TextureKind::kDepth, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureSampleLevel", [](ProgramBuilder* b) { @@ -1644,7 +1645,7 @@ std::vector TextureOverloadCase::ValidCases() { " ddy : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleGrad", [](ProgramBuilder* b) { @@ -1665,7 +1666,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleGrad", [](ProgramBuilder* b) { @@ -1687,7 +1688,7 @@ std::vector TextureOverloadCase::ValidCases() { " ddy : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleGrad", [](ProgramBuilder* b) { @@ -1710,7 +1711,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleGrad", [](ProgramBuilder* b) { @@ -1732,7 +1733,7 @@ std::vector TextureOverloadCase::ValidCases() { " ddy : vec3) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureSampleGrad", [](ProgramBuilder* b) { @@ -1753,7 +1754,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec3) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureSampleGrad", [](ProgramBuilder* b) { @@ -1774,7 +1775,7 @@ std::vector TextureOverloadCase::ValidCases() { " ddy : vec3) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureSampleGrad", [](ProgramBuilder* b) { @@ -1795,7 +1796,7 @@ std::vector TextureOverloadCase::ValidCases() { " ddy : vec3) -> vec4", TextureKind::kRegular, ast::SamplerKind::kSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureSampleGrad", [](ProgramBuilder* b) { @@ -1815,7 +1816,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleCompare", [](ProgramBuilder* b) { @@ -1834,7 +1835,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleCompare", [](ProgramBuilder* b) { @@ -1854,7 +1855,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleCompare", [](ProgramBuilder* b) { @@ -1875,7 +1876,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleCompare", [](ProgramBuilder* b) { @@ -1895,7 +1896,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureSampleCompare", [](ProgramBuilder* b) { @@ -1914,7 +1915,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureSampleCompare", [](ProgramBuilder* b) { @@ -1933,7 +1934,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleCompareLevel", [](ProgramBuilder* b) { @@ -1952,7 +1953,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureSampleCompareLevel", [](ProgramBuilder* b) { @@ -1972,7 +1973,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleCompareLevel", [](ProgramBuilder* b) { @@ -1993,7 +1994,7 @@ std::vector TextureOverloadCase::ValidCases() { " offset : vec2) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureSampleCompareLevel", [](ProgramBuilder* b) { @@ -2013,7 +2014,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::kF32, "textureSampleCompareLevel", [](ProgramBuilder* b) { @@ -2032,7 +2033,7 @@ std::vector TextureOverloadCase::ValidCases() { " depth_ref : f32) -> f32", TextureKind::kDepth, ast::SamplerKind::kComparisonSampler, - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::kF32, "textureSampleCompareLevel", [](ProgramBuilder* b) { @@ -2049,7 +2050,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : u32,\n" " level : u32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::kF32, "textureLoad", [](ProgramBuilder* b) { @@ -2064,7 +2065,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : i32,\n" " level : i32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::kU32, "textureLoad", [](ProgramBuilder* b) { @@ -2079,7 +2080,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : i32,\n" " level : i32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::kI32, "textureLoad", [](ProgramBuilder* b) { @@ -2094,7 +2095,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2,\n" " level : u32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureLoad", [](ProgramBuilder* b) { @@ -2109,7 +2110,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2,\n" " level : i32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kU32, "textureLoad", [](ProgramBuilder* b) { @@ -2124,7 +2125,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2,\n" " level : u32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kI32, "textureLoad", [](ProgramBuilder* b) { @@ -2140,7 +2141,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : i32,\n" " level : i32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureLoad", [](ProgramBuilder* b) { @@ -2157,7 +2158,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : i32,\n" " level : i32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kU32, "textureLoad", [](ProgramBuilder* b) { @@ -2174,7 +2175,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : u32,\n" " level : u32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kI32, "textureLoad", [](ProgramBuilder* b) { @@ -2190,7 +2191,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec3,\n" " level : i32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureLoad", [](ProgramBuilder* b) { @@ -2205,7 +2206,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec3,\n" " level : i32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kU32, "textureLoad", [](ProgramBuilder* b) { @@ -2220,7 +2221,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec3,\n" " level : u32) -> vec4", TextureKind::kRegular, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kI32, "textureLoad", [](ProgramBuilder* b) { @@ -2235,7 +2236,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2,\n" " sample_index : i32) -> vec4", TextureKind::kMultisampled, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureLoad", [](ProgramBuilder* b) { @@ -2250,7 +2251,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2,\n" " sample_index : i32) -> vec4", TextureKind::kMultisampled, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kU32, "textureLoad", [](ProgramBuilder* b) { @@ -2265,7 +2266,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2,\n" " sample_index : u32) -> vec4", TextureKind::kMultisampled, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kI32, "textureLoad", [](ProgramBuilder* b) { @@ -2280,7 +2281,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2,\n" " level : i32) -> f32", TextureKind::kDepth, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureLoad", [](ProgramBuilder* b) { @@ -2296,7 +2297,7 @@ std::vector TextureOverloadCase::ValidCases() { " array_index : u32,\n" " level : u32) -> f32", TextureKind::kDepth, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureLoad", [](ProgramBuilder* b) { @@ -2312,7 +2313,7 @@ std::vector TextureOverloadCase::ValidCases() { " coords : vec2,\n" " sample_index : u32) -> f32", TextureKind::kDepthMultisampled, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureLoad", [](ProgramBuilder* b) { @@ -2328,7 +2329,7 @@ std::vector TextureOverloadCase::ValidCases() { " value : vec4)", ast::Access::kWrite, ast::TexelFormat::kRgba32Float, - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::kF32, "textureStore", [](ProgramBuilder* b) { @@ -2344,7 +2345,7 @@ std::vector TextureOverloadCase::ValidCases() { " value : vec4)", ast::Access::kWrite, ast::TexelFormat::kRgba32Float, - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::kF32, "textureStore", [](ProgramBuilder* b) { @@ -2361,7 +2362,7 @@ std::vector TextureOverloadCase::ValidCases() { " value : vec4)", ast::Access::kWrite, ast::TexelFormat::kRgba32Float, - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::kF32, "textureStore", [](ProgramBuilder* b) { @@ -2378,7 +2379,7 @@ std::vector TextureOverloadCase::ValidCases() { " value : vec4)", ast::Access::kWrite, ast::TexelFormat::kRgba32Float, - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::kF32, "textureStore", [](ProgramBuilder* b) { diff --git a/src/tint/ast/builtin_texture_helper_test.h b/src/tint/ast/builtin_texture_helper_test.h index 744796a010..cfa180a7dc 100644 --- a/src/tint/ast/builtin_texture_helper_test.h +++ b/src/tint/ast/builtin_texture_helper_test.h @@ -20,6 +20,7 @@ #include "src/tint/ast/access.h" #include "src/tint/program_builder.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::ast::builtin::test { @@ -185,7 +186,7 @@ struct TextureOverloadCase { const char*, TextureKind, ast::SamplerKind, - ast::TextureDimension, + type::TextureDimension, TextureDataType, const char*, std::function); @@ -193,7 +194,7 @@ struct TextureOverloadCase { TextureOverloadCase(ValidTextureOverload, const char*, TextureKind, - ast::TextureDimension, + type::TextureDimension, TextureDataType, const char*, std::function); @@ -202,7 +203,7 @@ struct TextureOverloadCase { const char*, Access, ast::TexelFormat, - ast::TextureDimension, + type::TextureDimension, TextureDataType, const char*, std::function); @@ -243,7 +244,7 @@ struct TextureOverloadCase { /// Used only when texture_kind is kStorage ast::TexelFormat const texel_format = ast::TexelFormat::kUndefined; /// The dimensions of the texture parameter - ast::TextureDimension const texture_dimension; + type::TextureDimension const texture_dimension; /// The data type of the texture parameter const TextureDataType texture_data_type; /// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc diff --git a/src/tint/ast/depth_multisampled_texture.cc b/src/tint/ast/depth_multisampled_texture.cc index 64998b5170..2ab3e8af66 100644 --- a/src/tint/ast/depth_multisampled_texture.cc +++ b/src/tint/ast/depth_multisampled_texture.cc @@ -21,8 +21,8 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::DepthMultisampledTexture); namespace tint::ast { namespace { -bool IsValidDepthDimension(TextureDimension dim) { - return dim == TextureDimension::k2d; +bool IsValidDepthDimension(type::TextureDimension dim) { + return dim == type::TextureDimension::k2d; } } // namespace @@ -30,7 +30,7 @@ bool IsValidDepthDimension(TextureDimension dim) { DepthMultisampledTexture::DepthMultisampledTexture(ProgramID pid, NodeID nid, const Source& src, - TextureDimension d) + type::TextureDimension d) : Base(pid, nid, src, d) { TINT_ASSERT(AST, IsValidDepthDimension(dim)); } diff --git a/src/tint/ast/depth_multisampled_texture.h b/src/tint/ast/depth_multisampled_texture.h index 2cc8d78bd6..8986d493fd 100644 --- a/src/tint/ast/depth_multisampled_texture.h +++ b/src/tint/ast/depth_multisampled_texture.h @@ -18,6 +18,7 @@ #include #include "src/tint/ast/texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::ast { @@ -29,7 +30,10 @@ class DepthMultisampledTexture final : public Castable(TextureDimension::k2d); - EXPECT_EQ(d->dim, TextureDimension::k2d); + auto* d = create(type::TextureDimension::k2d); + EXPECT_EQ(d->dim, type::TextureDimension::k2d); } TEST_F(AstDepthMultisampledTextureTest, FriendlyName) { - auto* d = create(TextureDimension::k2d); + auto* d = create(type::TextureDimension::k2d); EXPECT_EQ(d->FriendlyName(Symbols()), "texture_depth_multisampled_2d"); } diff --git a/src/tint/ast/depth_texture.cc b/src/tint/ast/depth_texture.cc index 4aae6f32a6..199c0dab8a 100644 --- a/src/tint/ast/depth_texture.cc +++ b/src/tint/ast/depth_texture.cc @@ -21,14 +21,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::DepthTexture); namespace tint::ast { namespace { -bool IsValidDepthDimension(TextureDimension dim) { - return dim == TextureDimension::k2d || dim == TextureDimension::k2dArray || - dim == TextureDimension::kCube || dim == TextureDimension::kCubeArray; +bool IsValidDepthDimension(type::TextureDimension dim) { + return dim == type::TextureDimension::k2d || dim == type::TextureDimension::k2dArray || + dim == type::TextureDimension::kCube || dim == type::TextureDimension::kCubeArray; } } // namespace -DepthTexture::DepthTexture(ProgramID pid, NodeID nid, const Source& src, TextureDimension d) +DepthTexture::DepthTexture(ProgramID pid, NodeID nid, const Source& src, type::TextureDimension d) : Base(pid, nid, src, d) { TINT_ASSERT(AST, IsValidDepthDimension(dim)); } diff --git a/src/tint/ast/depth_texture.h b/src/tint/ast/depth_texture.h index 7df34a2736..e687612413 100644 --- a/src/tint/ast/depth_texture.h +++ b/src/tint/ast/depth_texture.h @@ -18,6 +18,7 @@ #include #include "src/tint/ast/texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::ast { @@ -29,7 +30,7 @@ class DepthTexture final : public Castable { /// @param nid the unique node identifier /// @param src the source of this node /// @param dim the dimensionality of the texture - DepthTexture(ProgramID pid, NodeID nid, const Source& src, TextureDimension dim); + DepthTexture(ProgramID pid, NodeID nid, const Source& src, type::TextureDimension dim); /// Move constructor DepthTexture(DepthTexture&&); ~DepthTexture() override; diff --git a/src/tint/ast/depth_texture_test.cc b/src/tint/ast/depth_texture_test.cc index 15dc356e09..e2a7b0ef5d 100644 --- a/src/tint/ast/depth_texture_test.cc +++ b/src/tint/ast/depth_texture_test.cc @@ -22,19 +22,19 @@ namespace { using AstDepthTextureTest = TestHelper; TEST_F(AstDepthTextureTest, IsTexture) { - Texture* ty = create(TextureDimension::kCube); + Texture* ty = create(type::TextureDimension::kCube); EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); } TEST_F(AstDepthTextureTest, Dim) { - auto* d = create(TextureDimension::kCube); - EXPECT_EQ(d->dim, TextureDimension::kCube); + auto* d = create(type::TextureDimension::kCube); + EXPECT_EQ(d->dim, type::TextureDimension::kCube); } TEST_F(AstDepthTextureTest, FriendlyName) { - auto* d = create(TextureDimension::kCube); + auto* d = create(type::TextureDimension::kCube); EXPECT_EQ(d->FriendlyName(Symbols()), "texture_depth_cube"); } diff --git a/src/tint/ast/external_texture.cc b/src/tint/ast/external_texture.cc index 488191389d..95d9bc73fa 100644 --- a/src/tint/ast/external_texture.cc +++ b/src/tint/ast/external_texture.cc @@ -15,14 +15,15 @@ #include "src/tint/ast/external_texture.h" #include "src/tint/program_builder.h" +#include "src/tint/type/texture_dimension.h" TINT_INSTANTIATE_TYPEINFO(tint::ast::ExternalTexture); namespace tint::ast { -// ExternalTexture::ExternalTexture() : Base(ast::TextureDimension::k2d) {} +// ExternalTexture::ExternalTexture() : Base(type::TextureDimension::k2d) {} ExternalTexture::ExternalTexture(ProgramID pid, NodeID nid, const Source& src) - : Base(pid, nid, src, ast::TextureDimension::k2d) {} + : Base(pid, nid, src, type::TextureDimension::k2d) {} ExternalTexture::ExternalTexture(ExternalTexture&&) = default; diff --git a/src/tint/ast/external_texture_test.cc b/src/tint/ast/external_texture_test.cc index dfe097e3df..873dca8dd3 100644 --- a/src/tint/ast/external_texture_test.cc +++ b/src/tint/ast/external_texture_test.cc @@ -15,6 +15,7 @@ #include "src/tint/ast/external_texture.h" #include "src/tint/ast/test_helper.h" +#include "src/tint/type/texture_dimension.h" namespace tint::ast { namespace { @@ -32,7 +33,7 @@ TEST_F(AstExternalTextureTest, IsTexture) { TEST_F(AstExternalTextureTest, Dim) { auto* ty = create(); - EXPECT_EQ(ty->dim, ast::TextureDimension::k2d); + EXPECT_EQ(ty->dim, type::TextureDimension::k2d); } TEST_F(AstExternalTextureTest, FriendlyName) { diff --git a/src/tint/ast/multisampled_texture.cc b/src/tint/ast/multisampled_texture.cc index 0c4485754d..05aea9dcd8 100644 --- a/src/tint/ast/multisampled_texture.cc +++ b/src/tint/ast/multisampled_texture.cc @@ -23,7 +23,7 @@ namespace tint::ast { MultisampledTexture::MultisampledTexture(ProgramID pid, NodeID nid, const Source& src, - TextureDimension d, + type::TextureDimension d, const Type* ty) : Base(pid, nid, src, d), type(ty) { TINT_ASSERT(AST, type); diff --git a/src/tint/ast/multisampled_texture.h b/src/tint/ast/multisampled_texture.h index 6887045fc5..dfa192ebe4 100644 --- a/src/tint/ast/multisampled_texture.h +++ b/src/tint/ast/multisampled_texture.h @@ -18,6 +18,7 @@ #include #include "src/tint/ast/texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::ast { @@ -33,7 +34,7 @@ class MultisampledTexture final : public Castable MultisampledTexture(ProgramID pid, NodeID nid, const Source& src, - TextureDimension dim, + type::TextureDimension dim, const Type* type); /// Move constructor MultisampledTexture(MultisampledTexture&&); diff --git a/src/tint/ast/multisampled_texture_test.cc b/src/tint/ast/multisampled_texture_test.cc index bc3b87f75b..ee05710ac0 100644 --- a/src/tint/ast/multisampled_texture_test.cc +++ b/src/tint/ast/multisampled_texture_test.cc @@ -39,7 +39,7 @@ using AstMultisampledTextureTest = TestHelper; TEST_F(AstMultisampledTextureTest, IsTexture) { auto* f32 = create(); - Texture* ty = create(TextureDimension::kCube, f32); + Texture* ty = create(type::TextureDimension::kCube, f32); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); @@ -48,19 +48,19 @@ TEST_F(AstMultisampledTextureTest, IsTexture) { TEST_F(AstMultisampledTextureTest, Dim) { auto* f32 = create(); - auto* s = create(TextureDimension::k3d, f32); - EXPECT_EQ(s->dim, TextureDimension::k3d); + auto* s = create(type::TextureDimension::k3d, f32); + EXPECT_EQ(s->dim, type::TextureDimension::k3d); } TEST_F(AstMultisampledTextureTest, Type) { auto* f32 = create(); - auto* s = create(TextureDimension::k3d, f32); + auto* s = create(type::TextureDimension::k3d, f32); EXPECT_EQ(s->type, f32); } TEST_F(AstMultisampledTextureTest, FriendlyName) { auto* f32 = create(); - auto* s = create(TextureDimension::k3d, f32); + auto* s = create(type::TextureDimension::k3d, f32); EXPECT_EQ(s->FriendlyName(Symbols()), "texture_multisampled_3d"); } diff --git a/src/tint/ast/sampled_texture.cc b/src/tint/ast/sampled_texture.cc index b8dfd61aee..cc33962c6a 100644 --- a/src/tint/ast/sampled_texture.cc +++ b/src/tint/ast/sampled_texture.cc @@ -23,7 +23,7 @@ namespace tint::ast { SampledTexture::SampledTexture(ProgramID pid, NodeID nid, const Source& src, - TextureDimension d, + type::TextureDimension d, const Type* ty) : Base(pid, nid, src, d), type(ty) { TINT_ASSERT(AST, type); diff --git a/src/tint/ast/sampled_texture.h b/src/tint/ast/sampled_texture.h index 1f33af3b6b..4ad7aa7e6b 100644 --- a/src/tint/ast/sampled_texture.h +++ b/src/tint/ast/sampled_texture.h @@ -18,6 +18,7 @@ #include #include "src/tint/ast/texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::ast { @@ -33,7 +34,7 @@ class SampledTexture final : public Castable { SampledTexture(ProgramID pid, NodeID nid, const Source& src, - TextureDimension dim, + type::TextureDimension dim, const Type* type); /// Move constructor SampledTexture(SampledTexture&&); diff --git a/src/tint/ast/sampled_texture_test.cc b/src/tint/ast/sampled_texture_test.cc index f85d2dff43..4b42da7e8b 100644 --- a/src/tint/ast/sampled_texture_test.cc +++ b/src/tint/ast/sampled_texture_test.cc @@ -24,7 +24,7 @@ using AstSampledTextureTest = TestHelper; TEST_F(AstSampledTextureTest, IsTexture) { auto* f32 = create(); - Texture* ty = create(TextureDimension::kCube, f32); + Texture* ty = create(type::TextureDimension::kCube, f32); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); @@ -32,19 +32,19 @@ TEST_F(AstSampledTextureTest, IsTexture) { TEST_F(AstSampledTextureTest, Dim) { auto* f32 = create(); - auto* s = create(TextureDimension::k3d, f32); - EXPECT_EQ(s->dim, TextureDimension::k3d); + auto* s = create(type::TextureDimension::k3d, f32); + EXPECT_EQ(s->dim, type::TextureDimension::k3d); } TEST_F(AstSampledTextureTest, Type) { auto* f32 = create(); - auto* s = create(TextureDimension::k3d, f32); + auto* s = create(type::TextureDimension::k3d, f32); EXPECT_EQ(s->type, f32); } TEST_F(AstSampledTextureTest, FriendlyName) { auto* f32 = create(); - auto* s = create(TextureDimension::k3d, f32); + auto* s = create(type::TextureDimension::k3d, f32); EXPECT_EQ(s->FriendlyName(Symbols()), "texture_3d"); } diff --git a/src/tint/ast/storage_texture.cc b/src/tint/ast/storage_texture.cc index 0a48a5bb38..32e233b10b 100644 --- a/src/tint/ast/storage_texture.cc +++ b/src/tint/ast/storage_texture.cc @@ -26,7 +26,7 @@ namespace tint::ast { StorageTexture::StorageTexture(ProgramID pid, NodeID nid, const Source& src, - TextureDimension d, + type::TextureDimension d, TexelFormat fmt, const Type* subtype, Access ac) diff --git a/src/tint/ast/storage_texture.h b/src/tint/ast/storage_texture.h index 9ae7b95416..a16212dd34 100644 --- a/src/tint/ast/storage_texture.h +++ b/src/tint/ast/storage_texture.h @@ -20,6 +20,7 @@ #include "src/tint/ast/access.h" #include "src/tint/ast/texel_format.h" #include "src/tint/ast/texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::ast { @@ -37,7 +38,7 @@ class StorageTexture final : public Castable { StorageTexture(ProgramID pid, NodeID nid, const Source& src, - TextureDimension dim, + type::TextureDimension dim, TexelFormat format, const Type* subtype, Access access_control); diff --git a/src/tint/ast/storage_texture_test.cc b/src/tint/ast/storage_texture_test.cc index 41f3d6552a..69ee4a0802 100644 --- a/src/tint/ast/storage_texture_test.cc +++ b/src/tint/ast/storage_texture_test.cc @@ -23,8 +23,8 @@ using AstStorageTextureTest = TestHelper; TEST_F(AstStorageTextureTest, IsTexture) { auto* subtype = StorageTexture::SubtypeFor(TexelFormat::kRgba32Float, *this); - Texture* ty = create(TextureDimension::k2dArray, TexelFormat::kRgba32Float, - subtype, Access::kRead); + Texture* ty = create(type::TextureDimension::k2dArray, + TexelFormat::kRgba32Float, subtype, Access::kRead); EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); EXPECT_TRUE(ty->Is()); @@ -32,29 +32,29 @@ TEST_F(AstStorageTextureTest, IsTexture) { TEST_F(AstStorageTextureTest, Dim) { auto* subtype = StorageTexture::SubtypeFor(TexelFormat::kRgba32Float, *this); - auto* s = create(TextureDimension::k2dArray, TexelFormat::kRgba32Float, subtype, - Access::kRead); - EXPECT_EQ(s->dim, TextureDimension::k2dArray); + auto* s = create(type::TextureDimension::k2dArray, TexelFormat::kRgba32Float, + subtype, Access::kRead); + EXPECT_EQ(s->dim, type::TextureDimension::k2dArray); } TEST_F(AstStorageTextureTest, Format) { auto* subtype = StorageTexture::SubtypeFor(TexelFormat::kRgba32Float, *this); - auto* s = create(TextureDimension::k2dArray, TexelFormat::kRgba32Float, subtype, - Access::kRead); + auto* s = create(type::TextureDimension::k2dArray, TexelFormat::kRgba32Float, + subtype, Access::kRead); EXPECT_EQ(s->format, TexelFormat::kRgba32Float); } TEST_F(AstStorageTextureTest, FriendlyName) { auto* subtype = StorageTexture::SubtypeFor(TexelFormat::kRgba32Float, *this); - auto* s = create(TextureDimension::k2dArray, TexelFormat::kRgba32Float, subtype, - Access::kRead); + auto* s = create(type::TextureDimension::k2dArray, TexelFormat::kRgba32Float, + subtype, Access::kRead); EXPECT_EQ(s->FriendlyName(Symbols()), "texture_storage_2d_array"); } TEST_F(AstStorageTextureTest, F32) { auto* subtype = StorageTexture::SubtypeFor(TexelFormat::kRgba32Float, *this); - Type* s = create(TextureDimension::k2dArray, TexelFormat::kRgba32Float, subtype, - Access::kRead); + Type* s = create(type::TextureDimension::k2dArray, TexelFormat::kRgba32Float, + subtype, Access::kRead); ASSERT_TRUE(s->Is()); ASSERT_TRUE(s->Is()); @@ -63,8 +63,8 @@ TEST_F(AstStorageTextureTest, F32) { TEST_F(AstStorageTextureTest, U32) { auto* subtype = StorageTexture::SubtypeFor(TexelFormat::kRg32Uint, *this); - Type* s = create(TextureDimension::k2dArray, TexelFormat::kRg32Uint, subtype, - Access::kRead); + Type* s = create(type::TextureDimension::k2dArray, TexelFormat::kRg32Uint, + subtype, Access::kRead); ASSERT_TRUE(s->Is()); ASSERT_TRUE(s->Is()); @@ -73,8 +73,8 @@ TEST_F(AstStorageTextureTest, U32) { TEST_F(AstStorageTextureTest, I32) { auto* subtype = StorageTexture::SubtypeFor(TexelFormat::kRgba32Sint, *this); - Type* s = create(TextureDimension::k2dArray, TexelFormat::kRgba32Sint, subtype, - Access::kRead); + Type* s = create(type::TextureDimension::k2dArray, TexelFormat::kRgba32Sint, + subtype, Access::kRead); ASSERT_TRUE(s->Is()); ASSERT_TRUE(s->Is()); diff --git a/src/tint/ast/texture.cc b/src/tint/ast/texture.cc index f3c01dff29..bcfbcb5381 100644 --- a/src/tint/ast/texture.cc +++ b/src/tint/ast/texture.cc @@ -18,66 +18,39 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Texture); namespace tint::ast { -std::ostream& operator<<(std::ostream& out, TextureDimension dim) { +bool IsTextureArray(type::TextureDimension dim) { switch (dim) { - case TextureDimension::kNone: - out << "None"; - break; - case TextureDimension::k1d: - out << "1d"; - break; - case TextureDimension::k2d: - out << "2d"; - break; - case TextureDimension::k2dArray: - out << "2d_array"; - break; - case TextureDimension::k3d: - out << "3d"; - break; - case TextureDimension::kCube: - out << "cube"; - break; - case TextureDimension::kCubeArray: - out << "cube_array"; - break; - } - return out; -} - -bool IsTextureArray(TextureDimension dim) { - switch (dim) { - case TextureDimension::k2dArray: - case TextureDimension::kCubeArray: + case type::TextureDimension::k2dArray: + case type::TextureDimension::kCubeArray: return true; - case TextureDimension::k2d: - case TextureDimension::kNone: - case TextureDimension::k1d: - case TextureDimension::k3d: - case TextureDimension::kCube: + case type::TextureDimension::k2d: + case type::TextureDimension::kNone: + case type::TextureDimension::k1d: + case type::TextureDimension::k3d: + case type::TextureDimension::kCube: return false; } return false; } -int NumCoordinateAxes(TextureDimension dim) { +int NumCoordinateAxes(type::TextureDimension dim) { switch (dim) { - case TextureDimension::kNone: + case type::TextureDimension::kNone: return 0; - case TextureDimension::k1d: + case type::TextureDimension::k1d: return 1; - case TextureDimension::k2d: - case TextureDimension::k2dArray: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: return 2; - case TextureDimension::k3d: - case TextureDimension::kCube: - case TextureDimension::kCubeArray: + case type::TextureDimension::k3d: + case type::TextureDimension::kCube: + case type::TextureDimension::kCubeArray: return 3; } return 0; } -Texture::Texture(ProgramID pid, NodeID nid, const Source& src, TextureDimension d) +Texture::Texture(ProgramID pid, NodeID nid, const Source& src, type::TextureDimension d) : Base(pid, nid, src), dim(d) {} Texture::Texture(Texture&&) = default; diff --git a/src/tint/ast/texture.h b/src/tint/ast/texture.h index fcfa3340ff..be78ba906c 100644 --- a/src/tint/ast/texture.h +++ b/src/tint/ast/texture.h @@ -16,35 +16,13 @@ #define SRC_TINT_AST_TEXTURE_H_ #include "src/tint/ast/type.h" +#include "src/tint/type/texture_dimension.h" namespace tint::ast { -/// The dimensionality of the texture -enum class TextureDimension { - /// Invalid texture - kNone = -1, - /// 1 dimensional texture - k1d, - /// 2 dimensional texture - k2d, - /// 2 dimensional array texture - k2dArray, - /// 3 dimensional texture - k3d, - /// cube texture - kCube, - /// cube array texture - kCubeArray, -}; - -/// @param out the std::ostream to write to -/// @param dim the TextureDimension -/// @return the std::ostream so calls can be chained -std::ostream& operator<<(std::ostream& out, TextureDimension dim); - -/// @param dim the TextureDimension to query -/// @return true if the given TextureDimension is an array texture -bool IsTextureArray(TextureDimension dim); +/// @param dim the type::TextureDimension to query +/// @return true if the given type::TextureDimension is an array texture +bool IsTextureArray(type::TextureDimension dim); /// Returns the number of axes in the coordinate used for accessing /// the texture, where an access is one of: sampling, fetching, load, @@ -56,9 +34,9 @@ bool IsTextureArray(TextureDimension dim); /// Note: To sample a cube texture, the coordinate has 3 dimensions, /// but textureDimensions on a cube or cube array returns a 2-element /// size, representing the (x,y) size of each cube face, in texels. -/// @param dim the TextureDimension to query +/// @param dim the type::TextureDimension to query /// @return number of dimensions in a coordinate for the dimensionality -int NumCoordinateAxes(TextureDimension dim); +int NumCoordinateAxes(type::TextureDimension dim); /// A texture type. class Texture : public Castable { @@ -68,13 +46,13 @@ class Texture : public Castable { /// @param nid the unique node identifier /// @param src the source of this node /// @param dim the dimensionality of the texture - Texture(ProgramID pid, NodeID nid, const Source& src, TextureDimension dim); + Texture(ProgramID pid, NodeID nid, const Source& src, type::TextureDimension dim); /// Move constructor Texture(Texture&&); ~Texture() override; /// The texture dimension - const TextureDimension dim; + const type::TextureDimension dim; }; } // namespace tint::ast diff --git a/src/tint/ast/texture_test.cc b/src/tint/ast/texture_test.cc index 7b7c0b01eb..cad2884007 100644 --- a/src/tint/ast/texture_test.cc +++ b/src/tint/ast/texture_test.cc @@ -33,23 +33,23 @@ namespace { using AstTextureTypeTest = TestHelper; TEST_F(AstTextureTypeTest, IsTextureArray) { - EXPECT_EQ(false, IsTextureArray(TextureDimension::kNone)); - EXPECT_EQ(false, IsTextureArray(TextureDimension::k1d)); - EXPECT_EQ(false, IsTextureArray(TextureDimension::k2d)); - EXPECT_EQ(true, IsTextureArray(TextureDimension::k2dArray)); - EXPECT_EQ(false, IsTextureArray(TextureDimension::k3d)); - EXPECT_EQ(false, IsTextureArray(TextureDimension::kCube)); - EXPECT_EQ(true, IsTextureArray(TextureDimension::kCubeArray)); + EXPECT_EQ(false, IsTextureArray(type::TextureDimension::kNone)); + EXPECT_EQ(false, IsTextureArray(type::TextureDimension::k1d)); + EXPECT_EQ(false, IsTextureArray(type::TextureDimension::k2d)); + EXPECT_EQ(true, IsTextureArray(type::TextureDimension::k2dArray)); + EXPECT_EQ(false, IsTextureArray(type::TextureDimension::k3d)); + EXPECT_EQ(false, IsTextureArray(type::TextureDimension::kCube)); + EXPECT_EQ(true, IsTextureArray(type::TextureDimension::kCubeArray)); } TEST_F(AstTextureTypeTest, NumCoordinateAxes) { - EXPECT_EQ(0, NumCoordinateAxes(TextureDimension::kNone)); - EXPECT_EQ(1, NumCoordinateAxes(TextureDimension::k1d)); - EXPECT_EQ(2, NumCoordinateAxes(TextureDimension::k2d)); - EXPECT_EQ(2, NumCoordinateAxes(TextureDimension::k2dArray)); - EXPECT_EQ(3, NumCoordinateAxes(TextureDimension::k3d)); - EXPECT_EQ(3, NumCoordinateAxes(TextureDimension::kCube)); - EXPECT_EQ(3, NumCoordinateAxes(TextureDimension::kCubeArray)); + EXPECT_EQ(0, NumCoordinateAxes(type::TextureDimension::kNone)); + EXPECT_EQ(1, NumCoordinateAxes(type::TextureDimension::k1d)); + EXPECT_EQ(2, NumCoordinateAxes(type::TextureDimension::k2d)); + EXPECT_EQ(2, NumCoordinateAxes(type::TextureDimension::k2dArray)); + EXPECT_EQ(3, NumCoordinateAxes(type::TextureDimension::k3d)); + EXPECT_EQ(3, NumCoordinateAxes(type::TextureDimension::kCube)); + EXPECT_EQ(3, NumCoordinateAxes(type::TextureDimension::kCubeArray)); } } // namespace diff --git a/src/tint/inspector/inspector_test.cc b/src/tint/inspector/inspector_test.cc index d6c635dc78..98f75b61e3 100644 --- a/src/tint/inspector/inspector_test.cc +++ b/src/tint/inspector/inspector_test.cc @@ -27,6 +27,7 @@ #include "src/tint/type/external_texture.h" #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" #include "tint/tint.h" using namespace tint::number_suffixes; // NOLINT @@ -76,7 +77,7 @@ class InspectorGetSampledTextureResourceBindingsTest : public InspectorBuilder, class InspectorGetSampledArrayTextureResourceBindingsTest : public InspectorBuilder, public testing::Test {}; struct GetSampledTextureTestParams { - ast::TextureDimension type_dim; + type::TextureDimension type_dim; inspector::ResourceBinding::TextureDimension inspector_dim; inspector::ResourceBinding::SampledKind sampled_kind; }; @@ -100,7 +101,7 @@ class InspectorGetMultisampledTextureResourceBindingsTestWithParam class InspectorGetStorageTextureResourceBindingsTest : public InspectorBuilder, public testing::Test {}; struct GetDepthTextureTestParams { - ast::TextureDimension type_dim; + type::TextureDimension type_dim; inspector::ResourceBinding::TextureDimension inspector_dim; }; class InspectorGetDepthTextureResourceBindingsTestWithParam @@ -110,7 +111,7 @@ class InspectorGetDepthTextureResourceBindingsTestWithParam class InspectorGetDepthMultisampledTextureResourceBindingsTest : public InspectorBuilder, public testing::Test {}; -typedef std::tuple DimensionParams; +typedef std::tuple DimensionParams; typedef std::tuple TexelFormatParams; typedef std::tuple GetStorageTextureTestParams; @@ -1784,14 +1785,14 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) { MemberInfo{0, ty.i32()}, }); - auto* s_texture_type = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* s_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); AddResource("s_texture", s_texture_type, 2, 0); AddSampler("s_var", 3, 0); AddGlobalVariable("s_coords", ty.f32()); MakeSamplerReferenceBodyFunction("s_func", "s_texture", "s_var", "s_coords", ty.f32(), utils::Empty); - auto* cs_depth_texture_type = ty.depth_texture(ast::TextureDimension::k2d); + auto* cs_depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); AddResource("cs_texture", cs_depth_texture_type, 3, 1); AddComparisonSampler("cs_var", 3, 2); AddGlobalVariable("cs_coords", ty.vec2()); @@ -1799,14 +1800,15 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) { MakeComparisonSamplerReferenceBodyFunction("cs_func", "cs_texture", "cs_var", "cs_coords", "cs_depth", ty.f32(), utils::Empty); - auto* depth_ms_texture_type = ty.depth_multisampled_texture(ast::TextureDimension::k2d); + auto* depth_ms_texture_type = ty.depth_multisampled_texture(type::TextureDimension::k2d); AddResource("depth_ms_texture", depth_ms_texture_type, 3, 3); Func("depth_ms_func", utils::Empty, ty.void_(), utils::Vector{ Ignore("depth_ms_texture"), }); - auto* st_type = MakeStorageTextureTypes(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint); + auto* st_type = + MakeStorageTextureTypes(type::TextureDimension::k2d, ast::TexelFormat::kR32Uint); AddStorageTexture("st_var", st_type, 4, 0); MakeStorageTextureBodyFunction("st_func", "st_var", ty.vec2(), utils::Empty); @@ -2586,7 +2588,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) { } TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) { - auto* sampled_texture_type = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); AddResource("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); @@ -2621,7 +2623,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) { } TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) { - auto* sampled_texture_type = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); AddResource("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); @@ -2646,7 +2648,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) { } TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) { - auto* sampled_texture_type = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); AddResource("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); @@ -2663,7 +2665,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) { } TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) { - auto* depth_texture_type = ty.depth_texture(ast::TextureDimension::k2d); + auto* depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); AddResource("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2684,7 +2686,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) { - auto* depth_texture_type = ty.depth_texture(ast::TextureDimension::k2d); + auto* depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); AddResource("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2721,7 +2723,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) { - auto* depth_texture_type = ty.depth_texture(ast::TextureDimension::k2d); + auto* depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); AddResource("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2747,7 +2749,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) { - auto* depth_texture_type = ty.depth_texture(ast::TextureDimension::k2d); + auto* depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); AddResource("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2766,7 +2768,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) { - auto* sampled_texture_type = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); AddResource("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); @@ -2833,16 +2835,16 @@ TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) { INSTANTIATE_TEST_SUITE_P( InspectorGetSampledTextureResourceBindingsTest, InspectorGetSampledTextureResourceBindingsTestWithParam, - testing::Values(GetSampledTextureTestParams{ast::TextureDimension::k1d, + testing::Values(GetSampledTextureTestParams{type::TextureDimension::k1d, inspector::ResourceBinding::TextureDimension::k1d, inspector::ResourceBinding::SampledKind::kFloat}, - GetSampledTextureTestParams{ast::TextureDimension::k2d, + GetSampledTextureTestParams{type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d, inspector::ResourceBinding::SampledKind::kFloat}, - GetSampledTextureTestParams{ast::TextureDimension::k3d, + GetSampledTextureTestParams{type::TextureDimension::k3d, inspector::ResourceBinding::TextureDimension::k3d, inspector::ResourceBinding::SampledKind::kFloat}, - GetSampledTextureTestParams{ast::TextureDimension::kCube, + GetSampledTextureTestParams{type::TextureDimension::kCube, inspector::ResourceBinding::TextureDimension::kCube, inspector::ResourceBinding::SampledKind::kFloat})); @@ -2878,10 +2880,10 @@ INSTANTIATE_TEST_SUITE_P( InspectorGetSampledArrayTextureResourceBindingsTest, InspectorGetSampledArrayTextureResourceBindingsTestWithParam, testing::Values( - GetSampledTextureTestParams{ast::TextureDimension::k2dArray, + GetSampledTextureTestParams{type::TextureDimension::k2dArray, inspector::ResourceBinding::TextureDimension::k2dArray, inspector::ResourceBinding::SampledKind::kFloat}, - GetSampledTextureTestParams{ast::TextureDimension::kCubeArray, + GetSampledTextureTestParams{type::TextureDimension::kCubeArray, inspector::ResourceBinding::TextureDimension::kCubeArray, inspector::ResourceBinding::SampledKind::kFloat})); @@ -2924,13 +2926,13 @@ INSTANTIATE_TEST_SUITE_P( InspectorGetMultisampledTextureResourceBindingsTest, InspectorGetMultisampledTextureResourceBindingsTestWithParam, testing::Values( - GetMultisampledTextureTestParams{ast::TextureDimension::k2d, + GetMultisampledTextureTestParams{type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d, inspector::ResourceBinding::SampledKind::kFloat}, - GetMultisampledTextureTestParams{ast::TextureDimension::k2d, + GetMultisampledTextureTestParams{type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d, inspector::ResourceBinding::SampledKind::kSInt}, - GetMultisampledTextureTestParams{ast::TextureDimension::k2d, + GetMultisampledTextureTestParams{type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d, inspector::ResourceBinding::SampledKind::kUInt})); @@ -2964,7 +2966,7 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) { TexelFormatParams format_params; std::tie(dim_params, format_params) = GetParam(); - ast::TextureDimension dim; + type::TextureDimension dim; ResourceBinding::TextureDimension expected_dim; std::tie(dim, expected_dim) = dim_params; @@ -2978,14 +2980,14 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) { const ast::Type* dim_type = nullptr; switch (dim) { - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: dim_type = ty.u32(); break; - case ast::TextureDimension::k2d: - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: dim_type = ty.vec2(); break; - case ast::TextureDimension::k3d: + case type::TextureDimension::k3d: dim_type = ty.vec3(); break; default: @@ -3016,13 +3018,13 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) { INSTANTIATE_TEST_SUITE_P( InspectorGetStorageTextureResourceBindingsTest, InspectorGetStorageTextureResourceBindingsTestWithParam, - testing::Combine(testing::Values(std::make_tuple(ast::TextureDimension::k1d, + testing::Combine(testing::Values(std::make_tuple(type::TextureDimension::k1d, ResourceBinding::TextureDimension::k1d), - std::make_tuple(ast::TextureDimension::k2d, + std::make_tuple(type::TextureDimension::k2d, ResourceBinding::TextureDimension::k2d), - std::make_tuple(ast::TextureDimension::k2dArray, + std::make_tuple(type::TextureDimension::k2dArray, ResourceBinding::TextureDimension::k2dArray), - std::make_tuple(ast::TextureDimension::k3d, + std::make_tuple(type::TextureDimension::k3d, ResourceBinding::TextureDimension::k3d)), testing::Values(std::make_tuple(ast::TexelFormat::kR32Float, ResourceBinding::TexelFormat::kR32Float, @@ -3101,17 +3103,17 @@ INSTANTIATE_TEST_SUITE_P( InspectorGetDepthTextureResourceBindingsTest, InspectorGetDepthTextureResourceBindingsTestWithParam, testing::Values( - GetDepthTextureTestParams{ast::TextureDimension::k2d, + GetDepthTextureTestParams{type::TextureDimension::k2d, inspector::ResourceBinding::TextureDimension::k2d}, - GetDepthTextureTestParams{ast::TextureDimension::k2dArray, + GetDepthTextureTestParams{type::TextureDimension::k2dArray, inspector::ResourceBinding::TextureDimension::k2dArray}, - GetDepthTextureTestParams{ast::TextureDimension::kCube, + GetDepthTextureTestParams{type::TextureDimension::kCube, inspector::ResourceBinding::TextureDimension::kCube}, - GetDepthTextureTestParams{ast::TextureDimension::kCubeArray, + GetDepthTextureTestParams{type::TextureDimension::kCubeArray, inspector::ResourceBinding::TextureDimension::kCubeArray})); TEST_F(InspectorGetDepthMultisampledTextureResourceBindingsTest, textureDimensions) { - auto* depth_ms_texture_type = ty.depth_multisampled_texture(ast::TextureDimension::k2d); + auto* depth_ms_texture_type = ty.depth_multisampled_texture(type::TextureDimension::k2d); AddResource("tex", depth_ms_texture_type, 0, 0); Func("ep", utils::Empty, ty.void_(), diff --git a/src/tint/inspector/resource_binding.cc b/src/tint/inspector/resource_binding.cc index 4dd26e008d..fbaf47a026 100644 --- a/src/tint/inspector/resource_binding.cc +++ b/src/tint/inspector/resource_binding.cc @@ -18,6 +18,7 @@ #include "src/tint/type/f32.h" #include "src/tint/type/i32.h" #include "src/tint/type/matrix.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/type/type.h" #include "src/tint/type/u32.h" #include "src/tint/type/vector.h" @@ -25,21 +26,21 @@ namespace tint::inspector { ResourceBinding::TextureDimension TypeTextureDimensionToResourceBindingTextureDimension( - const ast::TextureDimension& type_dim) { + const type::TextureDimension& type_dim) { switch (type_dim) { - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: return ResourceBinding::TextureDimension::k1d; - case ast::TextureDimension::k2d: + case type::TextureDimension::k2d: return ResourceBinding::TextureDimension::k2d; - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: return ResourceBinding::TextureDimension::k2dArray; - case ast::TextureDimension::k3d: + case type::TextureDimension::k3d: return ResourceBinding::TextureDimension::k3d; - case ast::TextureDimension::kCube: + case type::TextureDimension::kCube: return ResourceBinding::TextureDimension::kCube; - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: return ResourceBinding::TextureDimension::kCubeArray; - case ast::TextureDimension::kNone: + case type::TextureDimension::kNone: return ResourceBinding::TextureDimension::kNone; } return ResourceBinding::TextureDimension::kNone; diff --git a/src/tint/inspector/resource_binding.h b/src/tint/inspector/resource_binding.h index ef2257897d..386d188b1c 100644 --- a/src/tint/inspector/resource_binding.h +++ b/src/tint/inspector/resource_binding.h @@ -18,7 +18,7 @@ #include #include "src/tint/ast/storage_texture.h" -#include "src/tint/ast/texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/type/type.h" namespace tint::inspector { @@ -104,12 +104,12 @@ struct ResourceBinding { TexelFormat image_format; }; -/// Convert from internal ast::TextureDimension to public +/// Convert from internal type::TextureDimension to public /// ResourceBinding::TextureDimension /// @param type_dim internal value to convert from /// @returns the publicly visible equivalent ResourceBinding::TextureDimension TypeTextureDimensionToResourceBindingTextureDimension( - const ast::TextureDimension& type_dim); + const type::TextureDimension& type_dim); /// Infer ResourceBinding::SampledKind for a given type::Type /// @param base_type internal type to infer from diff --git a/src/tint/inspector/test_inspector_builder.cc b/src/tint/inspector/test_inspector_builder.cc index 97ae0973a1..81d8f39923 100644 --- a/src/tint/inspector/test_inspector_builder.cc +++ b/src/tint/inspector/test_inspector_builder.cc @@ -259,17 +259,17 @@ const ast::Type* InspectorBuilder::GetBaseType(ResourceBinding::SampledKind samp } } -const ast::Type* InspectorBuilder::GetCoordsType(ast::TextureDimension dim, +const ast::Type* InspectorBuilder::GetCoordsType(type::TextureDimension dim, const ast::Type* scalar) { switch (dim) { - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: return scalar; - case ast::TextureDimension::k2d: - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: return create(scalar, 2u); - case ast::TextureDimension::k3d: - case ast::TextureDimension::kCube: - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::k3d: + case type::TextureDimension::kCube: + case type::TextureDimension::kCubeArray: return create(scalar, 3u); default: [=]() { FAIL() << "Unsupported texture dimension: " << dim; }(); @@ -277,7 +277,7 @@ const ast::Type* InspectorBuilder::GetCoordsType(ast::TextureDimension dim, return nullptr; } -const ast::Type* InspectorBuilder::MakeStorageTextureTypes(ast::TextureDimension dim, +const ast::Type* InspectorBuilder::MakeStorageTextureTypes(type::TextureDimension dim, ast::TexelFormat format) { return ty.storage_texture(dim, format, ast::Access::kWrite); } diff --git a/src/tint/inspector/test_inspector_builder.h b/src/tint/inspector/test_inspector_builder.h index 8439bd684e..36c70b7cd5 100644 --- a/src/tint/inspector/test_inspector_builder.h +++ b/src/tint/inspector/test_inspector_builder.h @@ -31,6 +31,7 @@ #include "src/tint/type/external_texture.h" #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" #include "tint/tint.h" namespace tint::inspector { @@ -287,13 +288,13 @@ class InspectorBuilder : public ProgramBuilder { /// @param dim dimensionality of the texture being sampled /// @param scalar the scalar type /// @returns a pointer to a type appropriate for the coord param - const ast::Type* GetCoordsType(ast::TextureDimension dim, const ast::Type* scalar); + const ast::Type* GetCoordsType(type::TextureDimension dim, const ast::Type* scalar); /// Generates appropriate types for a Read-Only StorageTexture /// @param dim the texture dimension of the storage texture /// @param format the texel format of the storage texture /// @returns the storage texture type - const ast::Type* MakeStorageTextureTypes(ast::TextureDimension dim, ast::TexelFormat format); + const ast::Type* MakeStorageTextureTypes(type::TextureDimension dim, ast::TexelFormat format); /// Adds a storage texture variable to the program /// @param name the name of the variable diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 9b688f0e0b..e59318160e 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -107,6 +107,7 @@ #include "src/tint/type/pointer.h" #include "src/tint/type/sampled_texture.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/type/u32.h" #include "src/tint/type/vector.h" #include "src/tint/type/void.h" @@ -1012,7 +1013,7 @@ class ProgramBuilder { /// @param dims the dimensionality of the texture /// @returns the depth texture - const ast::DepthTexture* depth_texture(ast::TextureDimension dims) const { + const ast::DepthTexture* depth_texture(type::TextureDimension dims) const { return builder->create(dims); } @@ -1020,14 +1021,14 @@ class ProgramBuilder { /// @param dims the dimensionality of the texture /// @returns the depth texture const ast::DepthTexture* depth_texture(const Source& source, - ast::TextureDimension dims) const { + type::TextureDimension dims) const { return builder->create(source, dims); } /// @param dims the dimensionality of the texture /// @returns the multisampled depth texture const ast::DepthMultisampledTexture* depth_multisampled_texture( - ast::TextureDimension dims) const { + type::TextureDimension dims) const { return builder->create(dims); } @@ -1036,14 +1037,14 @@ class ProgramBuilder { /// @returns the multisampled depth texture const ast::DepthMultisampledTexture* depth_multisampled_texture( const Source& source, - ast::TextureDimension dims) const { + type::TextureDimension dims) const { return builder->create(source, dims); } /// @param dims the dimensionality of the texture /// @param subtype the texture subtype. /// @returns the sampled texture - const ast::SampledTexture* sampled_texture(ast::TextureDimension dims, + const ast::SampledTexture* sampled_texture(type::TextureDimension dims, const ast::Type* subtype) const { return builder->create(dims, subtype); } @@ -1053,7 +1054,7 @@ class ProgramBuilder { /// @param subtype the texture subtype. /// @returns the sampled texture const ast::SampledTexture* sampled_texture(const Source& source, - ast::TextureDimension dims, + type::TextureDimension dims, const ast::Type* subtype) const { return builder->create(source, dims, subtype); } @@ -1061,7 +1062,7 @@ class ProgramBuilder { /// @param dims the dimensionality of the texture /// @param subtype the texture subtype. /// @returns the multisampled texture - const ast::MultisampledTexture* multisampled_texture(ast::TextureDimension dims, + const ast::MultisampledTexture* multisampled_texture(type::TextureDimension dims, const ast::Type* subtype) const { return builder->create(dims, subtype); } @@ -1071,7 +1072,7 @@ class ProgramBuilder { /// @param subtype the texture subtype. /// @returns the multisampled texture const ast::MultisampledTexture* multisampled_texture(const Source& source, - ast::TextureDimension dims, + type::TextureDimension dims, const ast::Type* subtype) const { return builder->create(source, dims, subtype); } @@ -1080,7 +1081,7 @@ class ProgramBuilder { /// @param format the texel format of the texture /// @param access the access control of the texture /// @returns the storage texture - const ast::StorageTexture* storage_texture(ast::TextureDimension dims, + const ast::StorageTexture* storage_texture(type::TextureDimension dims, ast::TexelFormat format, ast::Access access) const { auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder); @@ -1093,7 +1094,7 @@ class ProgramBuilder { /// @param access the access control of the texture /// @returns the storage texture const ast::StorageTexture* storage_texture(const Source& source, - ast::TextureDimension dims, + type::TextureDimension dims, ast::TexelFormat format, ast::Access access) const { auto* subtype = ast::StorageTexture::SubtypeFor(format, *builder); diff --git a/src/tint/reader/spirv/enum_converter.cc b/src/tint/reader/spirv/enum_converter.cc index 8c701565a5..2ac571d2ec 100644 --- a/src/tint/reader/spirv/enum_converter.cc +++ b/src/tint/reader/spirv/enum_converter.cc @@ -14,6 +14,8 @@ #include "src/tint/reader/spirv/enum_converter.h" +#include "src/tint/type/texture_dimension.h" + namespace tint::reader::spirv { EnumConverter::EnumConverter(const FailStream& fs) : fail_stream_(fs) {} @@ -98,34 +100,34 @@ ast::BuiltinValue EnumConverter::ToBuiltin(spv::BuiltIn b) { return ast::BuiltinValue::kUndefined; } -ast::TextureDimension EnumConverter::ToDim(spv::Dim dim, bool arrayed) { +type::TextureDimension EnumConverter::ToDim(spv::Dim dim, bool arrayed) { if (arrayed) { switch (dim) { case spv::Dim::Dim2D: - return ast::TextureDimension::k2dArray; + return type::TextureDimension::k2dArray; case spv::Dim::Cube: - return ast::TextureDimension::kCubeArray; + return type::TextureDimension::kCubeArray; default: break; } Fail() << "arrayed dimension must be 2D or Cube. Got " << int(dim); - return ast::TextureDimension::kNone; + return type::TextureDimension::kNone; } // Assume non-arrayed switch (dim) { case spv::Dim::Dim1D: - return ast::TextureDimension::k1d; + return type::TextureDimension::k1d; case spv::Dim::Dim2D: - return ast::TextureDimension::k2d; + return type::TextureDimension::k2d; case spv::Dim::Dim3D: - return ast::TextureDimension::k3d; + return type::TextureDimension::k3d; case spv::Dim::Cube: - return ast::TextureDimension::kCube; + return type::TextureDimension::kCube; default: break; } Fail() << "invalid dimension: " << int(dim); - return ast::TextureDimension::kNone; + return type::TextureDimension::kNone; } ast::TexelFormat EnumConverter::ToTexelFormat(spv::ImageFormat fmt) { diff --git a/src/tint/reader/spirv/enum_converter.h b/src/tint/reader/spirv/enum_converter.h index 6b7a88974e..507fd77538 100644 --- a/src/tint/reader/spirv/enum_converter.h +++ b/src/tint/reader/spirv/enum_converter.h @@ -22,6 +22,7 @@ #include "src/tint/ast/pipeline_stage.h" #include "src/tint/reader/spirv/fail_stream.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::reader::spirv { @@ -57,14 +58,14 @@ class EnumConverter { /// @param dim the SPIR-V Dim value /// @param arrayed true if the texture is arrayed /// @returns a Tint AST texture dimension - ast::TextureDimension ToDim(spv::Dim dim, bool arrayed); + type::TextureDimension ToDim(spv::Dim dim, bool arrayed); /// Converts a possibly arrayed SPIR-V Dim to a Tint texture dimension. /// On failure, logs an error and returns kNone /// @param dim the SPIR-V Dim value /// @param arrayed true if the texture is arrayed /// @returns a Tint AST texture dimension - ast::TextureDimension ToDim(SpvDim dim, bool arrayed) { + type::TextureDimension ToDim(SpvDim dim, bool arrayed) { return ToDim(static_cast(dim), arrayed); } diff --git a/src/tint/reader/spirv/enum_converter_test.cc b/src/tint/reader/spirv/enum_converter_test.cc index bdb0247863..f49abca25b 100644 --- a/src/tint/reader/spirv/enum_converter_test.cc +++ b/src/tint/reader/spirv/enum_converter_test.cc @@ -17,6 +17,7 @@ #include #include "gmock/gmock.h" +#include "src/tint/type/texture_dimension.h" namespace tint::reader::spirv { namespace { @@ -217,7 +218,7 @@ struct DimCase { spv::Dim dim; bool arrayed; bool expect_success; - ast::TextureDimension expected; + type::TextureDimension expected; }; inline std::ostream& operator<<(std::ostream& out, DimCase dc) { out << "DimCase{ spv::Dim:::" << int(dc.dim) << " arrayed?:" << int(dc.arrayed) @@ -256,31 +257,31 @@ INSTANTIATE_TEST_SUITE_P(EnumConverterGood, SpvDimTest, testing::Values( // Non-arrayed - DimCase{spv::Dim::Dim1D, false, true, ast::TextureDimension::k1d}, - DimCase{spv::Dim::Dim2D, false, true, ast::TextureDimension::k2d}, - DimCase{spv::Dim::Dim3D, false, true, ast::TextureDimension::k3d}, - DimCase{spv::Dim::Cube, false, true, ast::TextureDimension::kCube}, + DimCase{spv::Dim::Dim1D, false, true, type::TextureDimension::k1d}, + DimCase{spv::Dim::Dim2D, false, true, type::TextureDimension::k2d}, + DimCase{spv::Dim::Dim3D, false, true, type::TextureDimension::k3d}, + DimCase{spv::Dim::Cube, false, true, type::TextureDimension::kCube}, // Arrayed - DimCase{spv::Dim::Dim2D, true, true, ast::TextureDimension::k2dArray}, + DimCase{spv::Dim::Dim2D, true, true, type::TextureDimension::k2dArray}, DimCase{spv::Dim::Cube, true, true, - ast::TextureDimension::kCubeArray})); + type::TextureDimension::kCubeArray})); INSTANTIATE_TEST_SUITE_P( EnumConverterBad, SpvDimTest, testing::Values( // Invalid SPIR-V dimensionality. - DimCase{spv::Dim::Max, false, false, ast::TextureDimension::kNone}, - DimCase{spv::Dim::Max, true, false, ast::TextureDimension::kNone}, + DimCase{spv::Dim::Max, false, false, type::TextureDimension::kNone}, + DimCase{spv::Dim::Max, true, false, type::TextureDimension::kNone}, // Vulkan non-arrayed dimensionalities not supported by WGSL. - DimCase{spv::Dim::Rect, false, false, ast::TextureDimension::kNone}, - DimCase{spv::Dim::Buffer, false, false, ast::TextureDimension::kNone}, - DimCase{spv::Dim::SubpassData, false, false, ast::TextureDimension::kNone}, + DimCase{spv::Dim::Rect, false, false, type::TextureDimension::kNone}, + DimCase{spv::Dim::Buffer, false, false, type::TextureDimension::kNone}, + DimCase{spv::Dim::SubpassData, false, false, type::TextureDimension::kNone}, // Arrayed dimensionalities not supported by WGSL - DimCase{spv::Dim::Dim3D, true, false, ast::TextureDimension::kNone}, - DimCase{spv::Dim::Rect, true, false, ast::TextureDimension::kNone}, - DimCase{spv::Dim::Buffer, true, false, ast::TextureDimension::kNone}, - DimCase{spv::Dim::SubpassData, true, false, ast::TextureDimension::kNone})); + DimCase{spv::Dim::Dim3D, true, false, type::TextureDimension::kNone}, + DimCase{spv::Dim::Rect, true, false, type::TextureDimension::kNone}, + DimCase{spv::Dim::Buffer, true, false, type::TextureDimension::kNone}, + DimCase{spv::Dim::SubpassData, true, false, type::TextureDimension::kNone})); // TexelFormat diff --git a/src/tint/reader/spirv/function.cc b/src/tint/reader/spirv/function.cc index a0b257bbb8..0bae341edf 100644 --- a/src/tint/reader/spirv/function.cc +++ b/src/tint/reader/spirv/function.cc @@ -36,6 +36,7 @@ #include "src/tint/transform/spirv_atomic.h" #include "src/tint/type/depth_texture.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/hashmap.h" #include "src/tint/utils/hashset.h" @@ -5619,9 +5620,9 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { << inst.PrettyPrint(); } switch (texture_type->dims) { - case ast::TextureDimension::k2d: - case ast::TextureDimension::k2dArray: - case ast::TextureDimension::k3d: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: + case type::TextureDimension::k3d: break; default: return Fail() << "ConstOffset is only permitted for 2D, 2D Arrayed, " @@ -5749,8 +5750,8 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) { const ast::Expression* dims_call = create(Source{}, dims_ident, dims_args); auto dims = texture_type->dims; - if ((dims == ast::TextureDimension::kCube) || - (dims == ast::TextureDimension::kCubeArray)) { + if ((dims == type::TextureDimension::kCube) || + (dims == type::TextureDimension::kCubeArray)) { // textureDimension returns a 3-element vector but SPIR-V expects 2. dims_call = create(Source{}, dims_call, PrefixSwizzle(2)); @@ -5952,7 +5953,7 @@ FunctionEmitter::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageA if (!texture_type) { return {}; } - ast::TextureDimension dim = texture_type->dims; + type::TextureDimension dim = texture_type->dims; // Number of regular coordinates. uint32_t num_axes = static_cast(ast::NumCoordinateAxes(dim)); bool is_arrayed = ast::IsTextureArray(dim); diff --git a/src/tint/reader/spirv/parser_impl.cc b/src/tint/reader/spirv/parser_impl.cc index 4fa4b2fbef..84e07ed007 100644 --- a/src/tint/reader/spirv/parser_impl.cc +++ b/src/tint/reader/spirv/parser_impl.cc @@ -30,6 +30,7 @@ #include "src/tint/type/depth_texture.h" #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/unique_vector.h" namespace tint::reader::spirv { @@ -2481,9 +2482,9 @@ const Type* ParserImpl::GetHandleTypeForSpirvHandle(const spvtools::opt::Instruc } } - const ast::TextureDimension dim = + const type::TextureDimension dim = enum_converter_.ToDim(image_type->dim(), image_type->is_arrayed()); - if (dim == ast::TextureDimension::kNone) { + if (dim == type::TextureDimension::kNone) { return nullptr; } @@ -2506,7 +2507,7 @@ const Type* ParserImpl::GetHandleTypeForSpirvHandle(const spvtools::opt::Instruc ast_handle_type = ty_.DepthTexture(dim); } } else if (image_type->is_multisampled()) { - if (dim != ast::TextureDimension::k2d) { + if (dim != type::TextureDimension::k2d) { Fail() << "WGSL multisampled textures must be 2d and non-arrayed: " "invalid multisampled texture variable or function parameter " << namer_.Name(obj.result_id()) << ": " << obj.PrettyPrint(); diff --git a/src/tint/reader/spirv/parser_type.cc b/src/tint/reader/spirv/parser_type.cc index 04036f24f1..ef46c1822d 100644 --- a/src/tint/reader/spirv/parser_type.cc +++ b/src/tint/reader/spirv/parser_type.cc @@ -19,6 +19,7 @@ #include #include "src/tint/program_builder.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/hash.h" #include "src/tint/utils/map.h" #include "src/tint/utils/string.h" @@ -222,24 +223,24 @@ const ast::Type* Sampler::Build(ProgramBuilder& b) const { return b.ty.sampler(kind); } -Texture::Texture(ast::TextureDimension d) : dims(d) {} +Texture::Texture(type::TextureDimension d) : dims(d) {} Texture::Texture(const Texture&) = default; -DepthTexture::DepthTexture(ast::TextureDimension d) : Base(d) {} +DepthTexture::DepthTexture(type::TextureDimension d) : Base(d) {} DepthTexture::DepthTexture(const DepthTexture&) = default; const ast::Type* DepthTexture::Build(ProgramBuilder& b) const { return b.ty.depth_texture(dims); } -DepthMultisampledTexture::DepthMultisampledTexture(ast::TextureDimension d) : Base(d) {} +DepthMultisampledTexture::DepthMultisampledTexture(type::TextureDimension d) : Base(d) {} DepthMultisampledTexture::DepthMultisampledTexture(const DepthMultisampledTexture&) = default; const ast::Type* DepthMultisampledTexture::Build(ProgramBuilder& b) const { return b.ty.depth_multisampled_texture(dims); } -MultisampledTexture::MultisampledTexture(ast::TextureDimension d, const Type* t) +MultisampledTexture::MultisampledTexture(type::TextureDimension d, const Type* t) : Base(d), type(t) {} MultisampledTexture::MultisampledTexture(const MultisampledTexture&) = default; @@ -247,14 +248,14 @@ const ast::Type* MultisampledTexture::Build(ProgramBuilder& b) const { return b.ty.multisampled_texture(dims, type->Build(b)); } -SampledTexture::SampledTexture(ast::TextureDimension d, const Type* t) : Base(d), type(t) {} +SampledTexture::SampledTexture(type::TextureDimension d, const Type* t) : Base(d), type(t) {} SampledTexture::SampledTexture(const SampledTexture&) = default; const ast::Type* SampledTexture::Build(ProgramBuilder& b) const { return b.ty.sampled_texture(dims, type->Build(b)); } -StorageTexture::StorageTexture(ast::TextureDimension d, ast::TexelFormat f, ast::Access a) +StorageTexture::StorageTexture(type::TextureDimension d, ast::TexelFormat f, ast::Access a) : Base(d), format(f), access(a) {} StorageTexture::StorageTexture(const StorageTexture&) = default; @@ -494,26 +495,26 @@ const spirv::Sampler* TypeManager::Sampler(ast::SamplerKind kind) { return state->samplers_.Get(kind); } -const spirv::DepthTexture* TypeManager::DepthTexture(ast::TextureDimension dims) { +const spirv::DepthTexture* TypeManager::DepthTexture(type::TextureDimension dims) { return state->depth_textures_.Get(dims); } const spirv::DepthMultisampledTexture* TypeManager::DepthMultisampledTexture( - ast::TextureDimension dims) { + type::TextureDimension dims) { return state->depth_multisampled_textures_.Get(dims); } -const spirv::MultisampledTexture* TypeManager::MultisampledTexture(ast::TextureDimension dims, +const spirv::MultisampledTexture* TypeManager::MultisampledTexture(type::TextureDimension dims, const Type* ty) { return state->multisampled_textures_.Get(dims, ty); } -const spirv::SampledTexture* TypeManager::SampledTexture(ast::TextureDimension dims, +const spirv::SampledTexture* TypeManager::SampledTexture(type::TextureDimension dims, const Type* ty) { return state->sampled_textures_.Get(dims, ty); } -const spirv::StorageTexture* TypeManager::StorageTexture(ast::TextureDimension dims, +const spirv::StorageTexture* TypeManager::StorageTexture(type::TextureDimension dims, ast::TexelFormat fmt, ast::Access access) { return state->storage_textures_.Get(dims, fmt, access); diff --git a/src/tint/reader/spirv/parser_type.h b/src/tint/reader/spirv/parser_type.h index 43c311cadb..4d42292c69 100644 --- a/src/tint/reader/spirv/parser_type.h +++ b/src/tint/reader/spirv/parser_type.h @@ -23,8 +23,8 @@ #include "src/tint/ast/address_space.h" #include "src/tint/ast/sampler.h" #include "src/tint/ast/storage_texture.h" -#include "src/tint/ast/texture.h" #include "src/tint/castable.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/block_allocator.h" // Forward declarations @@ -331,21 +331,21 @@ struct Texture : public Castable { /// Constructor /// @param d the texture dimensions - explicit Texture(ast::TextureDimension d); + explicit Texture(type::TextureDimension d); /// Copy constructor /// @param other the other type to copy Texture(const Texture& other); /// the texture dimensions - ast::TextureDimension const dims; + type::TextureDimension const dims; }; /// `texture_depth_D` type struct DepthTexture final : public Castable { /// Constructor /// @param d the texture dimensions - explicit DepthTexture(ast::TextureDimension d); + explicit DepthTexture(type::TextureDimension d); /// Copy constructor /// @param other the other type to copy @@ -365,7 +365,7 @@ struct DepthTexture final : public Castable { struct DepthMultisampledTexture final : public Castable { /// Constructor /// @param d the texture dimensions - explicit DepthMultisampledTexture(ast::TextureDimension d); + explicit DepthMultisampledTexture(type::TextureDimension d); /// Copy constructor /// @param other the other type to copy @@ -386,7 +386,7 @@ struct MultisampledTexture final : public Castable /// Constructor /// @param d the texture dimensions /// @param t the multisampled texture type - MultisampledTexture(ast::TextureDimension d, const Type* t); + MultisampledTexture(type::TextureDimension d, const Type* t); /// Copy constructor /// @param other the other type to copy @@ -410,7 +410,7 @@ struct SampledTexture final : public Castable { /// Constructor /// @param d the texture dimensions /// @param t the sampled texture type - SampledTexture(ast::TextureDimension d, const Type* t); + SampledTexture(type::TextureDimension d, const Type* t); /// Copy constructor /// @param other the other type to copy @@ -435,7 +435,7 @@ struct StorageTexture final : public Castable { /// @param d the texture dimensions /// @param f the storage image format /// @param a the access control - StorageTexture(ast::TextureDimension d, ast::TexelFormat f, ast::Access a); + StorageTexture(type::TextureDimension d, ast::TexelFormat f, ast::Access a); /// Copy constructor /// @param other the other type to copy @@ -595,27 +595,27 @@ class TypeManager { /// @param d the texture dimensions /// @return a DepthTexture type. Repeated calls with the same arguments will /// return the same pointer. - const spirv::DepthTexture* DepthTexture(ast::TextureDimension d); + const spirv::DepthTexture* DepthTexture(type::TextureDimension d); /// @param d the texture dimensions /// @return a DepthMultisampledTexture type. Repeated calls with the same /// arguments will return the same pointer. - const spirv::DepthMultisampledTexture* DepthMultisampledTexture(ast::TextureDimension d); + const spirv::DepthMultisampledTexture* DepthMultisampledTexture(type::TextureDimension d); /// @param d the texture dimensions /// @param t the multisampled texture type /// @return a MultisampledTexture type. Repeated calls with the same arguments /// will return the same pointer. - const spirv::MultisampledTexture* MultisampledTexture(ast::TextureDimension d, const Type* t); + const spirv::MultisampledTexture* MultisampledTexture(type::TextureDimension d, const Type* t); /// @param d the texture dimensions /// @param t the sampled texture type /// @return a SampledTexture type. Repeated calls with the same arguments will /// return the same pointer. - const spirv::SampledTexture* SampledTexture(ast::TextureDimension d, const Type* t); + const spirv::SampledTexture* SampledTexture(type::TextureDimension d, const Type* t); /// @param d the texture dimensions /// @param f the storage image format /// @param a the access control /// @return a StorageTexture type. Repeated calls with the same arguments will /// return the same pointer. - const spirv::StorageTexture* StorageTexture(ast::TextureDimension d, + const spirv::StorageTexture* StorageTexture(type::TextureDimension d, ast::TexelFormat f, ast::Access a); diff --git a/src/tint/reader/spirv/parser_type_test.cc b/src/tint/reader/spirv/parser_type_test.cc index 90a8da260c..392b637f90 100644 --- a/src/tint/reader/spirv/parser_type_test.cc +++ b/src/tint/reader/spirv/parser_type_test.cc @@ -15,6 +15,7 @@ #include "gtest/gtest.h" #include "src/tint/reader/spirv/parser_type.h" +#include "src/tint/type/texture_dimension.h" namespace tint::reader::spirv { namespace { @@ -36,15 +37,15 @@ TEST(SpvParserTypeTest, SameArgumentsGivesSamePointer) { EXPECT_EQ(ty.Alias(sym, ty.I32()), ty.Alias(sym, ty.I32())); EXPECT_EQ(ty.Struct(sym, {ty.I32()}), ty.Struct(sym, {ty.I32()})); EXPECT_EQ(ty.Sampler(ast::SamplerKind::kSampler), ty.Sampler(ast::SamplerKind::kSampler)); - EXPECT_EQ(ty.DepthTexture(ast::TextureDimension::k2d), - ty.DepthTexture(ast::TextureDimension::k2d)); - EXPECT_EQ(ty.MultisampledTexture(ast::TextureDimension::k2d, ty.I32()), - ty.MultisampledTexture(ast::TextureDimension::k2d, ty.I32())); - EXPECT_EQ(ty.SampledTexture(ast::TextureDimension::k2d, ty.I32()), - ty.SampledTexture(ast::TextureDimension::k2d, ty.I32())); - EXPECT_EQ(ty.StorageTexture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, + EXPECT_EQ(ty.DepthTexture(type::TextureDimension::k2d), + ty.DepthTexture(type::TextureDimension::k2d)); + EXPECT_EQ(ty.MultisampledTexture(type::TextureDimension::k2d, ty.I32()), + ty.MultisampledTexture(type::TextureDimension::k2d, ty.I32())); + EXPECT_EQ(ty.SampledTexture(type::TextureDimension::k2d, ty.I32()), + ty.SampledTexture(type::TextureDimension::k2d, ty.I32())); + EXPECT_EQ(ty.StorageTexture(type::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kRead), - ty.StorageTexture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, + ty.StorageTexture(type::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kRead)); } @@ -69,27 +70,27 @@ TEST(SpvParserTypeTest, DifferentArgumentsGivesDifferentPointer) { EXPECT_NE(ty.Struct(sym_a, {ty.I32()}), ty.Struct(sym_b, {ty.I32()})); EXPECT_NE(ty.Sampler(ast::SamplerKind::kSampler), ty.Sampler(ast::SamplerKind::kComparisonSampler)); - EXPECT_NE(ty.DepthTexture(ast::TextureDimension::k2d), - ty.DepthTexture(ast::TextureDimension::k1d)); - EXPECT_NE(ty.MultisampledTexture(ast::TextureDimension::k2d, ty.I32()), - ty.MultisampledTexture(ast::TextureDimension::k3d, ty.I32())); - EXPECT_NE(ty.MultisampledTexture(ast::TextureDimension::k2d, ty.I32()), - ty.MultisampledTexture(ast::TextureDimension::k2d, ty.U32())); - EXPECT_NE(ty.SampledTexture(ast::TextureDimension::k2d, ty.I32()), - ty.SampledTexture(ast::TextureDimension::k3d, ty.I32())); - EXPECT_NE(ty.SampledTexture(ast::TextureDimension::k2d, ty.I32()), - ty.SampledTexture(ast::TextureDimension::k2d, ty.U32())); - EXPECT_NE(ty.StorageTexture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, + EXPECT_NE(ty.DepthTexture(type::TextureDimension::k2d), + ty.DepthTexture(type::TextureDimension::k1d)); + EXPECT_NE(ty.MultisampledTexture(type::TextureDimension::k2d, ty.I32()), + ty.MultisampledTexture(type::TextureDimension::k3d, ty.I32())); + EXPECT_NE(ty.MultisampledTexture(type::TextureDimension::k2d, ty.I32()), + ty.MultisampledTexture(type::TextureDimension::k2d, ty.U32())); + EXPECT_NE(ty.SampledTexture(type::TextureDimension::k2d, ty.I32()), + ty.SampledTexture(type::TextureDimension::k3d, ty.I32())); + EXPECT_NE(ty.SampledTexture(type::TextureDimension::k2d, ty.I32()), + ty.SampledTexture(type::TextureDimension::k2d, ty.U32())); + EXPECT_NE(ty.StorageTexture(type::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kRead), - ty.StorageTexture(ast::TextureDimension::k3d, ast::TexelFormat::kR32Uint, + ty.StorageTexture(type::TextureDimension::k3d, ast::TexelFormat::kR32Uint, ast::Access::kRead)); - EXPECT_NE(ty.StorageTexture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, + EXPECT_NE(ty.StorageTexture(type::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kRead), - ty.StorageTexture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Sint, + ty.StorageTexture(type::TextureDimension::k2d, ast::TexelFormat::kR32Sint, ast::Access::kRead)); - EXPECT_NE(ty.StorageTexture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, + EXPECT_NE(ty.StorageTexture(type::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kRead), - ty.StorageTexture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, + ty.StorageTexture(type::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kWrite)); } diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index d35a87e826..132e29488b 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -43,6 +43,7 @@ #include "src/tint/type/external_texture.h" #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/reverse.h" #include "src/tint/utils/string.h" @@ -806,29 +807,29 @@ Maybe ParserImpl::sampler_type() { // | TEXTURE_SAMPLED_3D // | TEXTURE_SAMPLED_CUBE // | TEXTURE_SAMPLED_CUBE_ARRAY -Maybe ParserImpl::sampled_texture_type() { +Maybe ParserImpl::sampled_texture_type() { if (match(Token::Type::kTextureSampled1d)) { - return ast::TextureDimension::k1d; + return type::TextureDimension::k1d; } if (match(Token::Type::kTextureSampled2d)) { - return ast::TextureDimension::k2d; + return type::TextureDimension::k2d; } if (match(Token::Type::kTextureSampled2dArray)) { - return ast::TextureDimension::k2dArray; + return type::TextureDimension::k2dArray; } if (match(Token::Type::kTextureSampled3d)) { - return ast::TextureDimension::k3d; + return type::TextureDimension::k3d; } if (match(Token::Type::kTextureSampledCube)) { - return ast::TextureDimension::kCube; + return type::TextureDimension::kCube; } if (match(Token::Type::kTextureSampledCubeArray)) { - return ast::TextureDimension::kCubeArray; + return type::TextureDimension::kCubeArray; } return Failure::kNoMatch; @@ -847,9 +848,9 @@ Maybe ParserImpl::external_texture() { // multisampled_texture_type // : TEXTURE_MULTISAMPLED_2D -Maybe ParserImpl::multisampled_texture_type() { +Maybe ParserImpl::multisampled_texture_type() { if (match(Token::Type::kTextureMultisampled2d)) { - return ast::TextureDimension::k2d; + return type::TextureDimension::k2d; } return Failure::kNoMatch; @@ -860,18 +861,18 @@ Maybe ParserImpl::multisampled_texture_type() { // | TEXTURE_STORAGE_2D // | TEXTURE_STORAGE_2D_ARRAY // | TEXTURE_STORAGE_3D -Maybe ParserImpl::storage_texture_type() { +Maybe ParserImpl::storage_texture_type() { if (match(Token::Type::kTextureStorage1d)) { - return ast::TextureDimension::k1d; + return type::TextureDimension::k1d; } if (match(Token::Type::kTextureStorage2d)) { - return ast::TextureDimension::k2d; + return type::TextureDimension::k2d; } if (match(Token::Type::kTextureStorage2dArray)) { - return ast::TextureDimension::k2dArray; + return type::TextureDimension::k2dArray; } if (match(Token::Type::kTextureStorage3d)) { - return ast::TextureDimension::k3d; + return type::TextureDimension::k3d; } return Failure::kNoMatch; @@ -886,19 +887,19 @@ Maybe ParserImpl::storage_texture_type() { Maybe ParserImpl::depth_texture_type() { Source source; if (match(Token::Type::kTextureDepth2d, &source)) { - return builder_.ty.depth_texture(source, ast::TextureDimension::k2d); + return builder_.ty.depth_texture(source, type::TextureDimension::k2d); } if (match(Token::Type::kTextureDepth2dArray, &source)) { - return builder_.ty.depth_texture(source, ast::TextureDimension::k2dArray); + return builder_.ty.depth_texture(source, type::TextureDimension::k2dArray); } if (match(Token::Type::kTextureDepthCube, &source)) { - return builder_.ty.depth_texture(source, ast::TextureDimension::kCube); + return builder_.ty.depth_texture(source, type::TextureDimension::kCube); } if (match(Token::Type::kTextureDepthCubeArray, &source)) { - return builder_.ty.depth_texture(source, ast::TextureDimension::kCubeArray); + return builder_.ty.depth_texture(source, type::TextureDimension::kCubeArray); } if (match(Token::Type::kTextureDepthMultisampled2d, &source)) { - return builder_.ty.depth_multisampled_texture(source, ast::TextureDimension::k2d); + return builder_.ty.depth_multisampled_texture(source, type::TextureDimension::k2d); } return Failure::kNoMatch; } diff --git a/src/tint/reader/wgsl/parser_impl.h b/src/tint/reader/wgsl/parser_impl.h index 5f6485395e..23e74bfc77 100644 --- a/src/tint/reader/wgsl/parser_impl.h +++ b/src/tint/reader/wgsl/parser_impl.h @@ -27,6 +27,7 @@ #include "src/tint/reader/wgsl/parser_impl_detail.h" #include "src/tint/reader/wgsl/token.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::ast { class BreakStatement; @@ -486,14 +487,14 @@ class ParserImpl { /// Parses a `multisampled_texture_type` grammar element /// @returns returns the multisample texture dimension or kNone if none /// matched. - Maybe multisampled_texture_type(); + Maybe multisampled_texture_type(); /// Parses a `sampled_texture_type` grammar element /// @returns returns the sample texture dimension or kNone if none matched. - Maybe sampled_texture_type(); + Maybe sampled_texture_type(); /// Parses a `storage_texture_type` grammar element /// @returns returns the storage texture dimension. /// Returns kNone if none matched. - Maybe storage_texture_type(); + Maybe storage_texture_type(); /// Parses a `depth_texture_type` grammar element /// @returns the parsed Type or nullptr if none matched. Maybe depth_texture_type(); diff --git a/src/tint/reader/wgsl/parser_impl_depth_texture_test.cc b/src/tint/reader/wgsl/parser_impl_depth_texture_test.cc index fbd8ffb2ff..dc8ddbf3bd 100644 --- a/src/tint/reader/wgsl/parser_impl_depth_texture_test.cc +++ b/src/tint/reader/wgsl/parser_impl_depth_texture_test.cc @@ -14,6 +14,7 @@ #include "src/tint/reader/wgsl/parser_impl_test_helper.h" #include "src/tint/type/depth_texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::reader::wgsl { namespace { @@ -34,7 +35,7 @@ TEST_F(ParserImplTest, DepthTextureType_2d) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); + EXPECT_EQ(t->As()->dim, type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } @@ -47,7 +48,7 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2dArray); + EXPECT_EQ(t->As()->dim, type::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 23u}})); } @@ -60,7 +61,7 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::kCube); + EXPECT_EQ(t->As()->dim, type::TextureDimension::kCube); EXPECT_FALSE(p->has_error()); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } @@ -73,7 +74,7 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::kCubeArray); + EXPECT_EQ(t->As()->dim, type::TextureDimension::kCubeArray); EXPECT_FALSE(p->has_error()); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}})); } @@ -86,7 +87,7 @@ TEST_F(ParserImplTest, DepthTextureType_Multisampled2d) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); + EXPECT_EQ(t->As()->dim, type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 30u}})); } diff --git a/src/tint/reader/wgsl/parser_impl_sampled_texture_test.cc b/src/tint/reader/wgsl/parser_impl_sampled_texture_test.cc index 6aa1aab097..5a2d38ae9e 100644 --- a/src/tint/reader/wgsl/parser_impl_sampled_texture_test.cc +++ b/src/tint/reader/wgsl/parser_impl_sampled_texture_test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "src/tint/reader/wgsl/parser_impl_test_helper.h" +#include "src/tint/type/texture_dimension.h" namespace tint::reader::wgsl { namespace { @@ -30,7 +31,7 @@ TEST_F(ParserImplTest, SampledTextureType_1d) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::TextureDimension::k1d); + EXPECT_EQ(t.value, type::TextureDimension::k1d); EXPECT_FALSE(p->has_error()); } @@ -39,7 +40,7 @@ TEST_F(ParserImplTest, SampledTextureType_2d) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::TextureDimension::k2d); + EXPECT_EQ(t.value, type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); } @@ -48,7 +49,7 @@ TEST_F(ParserImplTest, SampledTextureType_2dArray) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::TextureDimension::k2dArray); + EXPECT_EQ(t.value, type::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); } @@ -57,7 +58,7 @@ TEST_F(ParserImplTest, SampledTextureType_3d) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::TextureDimension::k3d); + EXPECT_EQ(t.value, type::TextureDimension::k3d); EXPECT_FALSE(p->has_error()); } @@ -66,7 +67,7 @@ TEST_F(ParserImplTest, SampledTextureType_Cube) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::TextureDimension::kCube); + EXPECT_EQ(t.value, type::TextureDimension::kCube); EXPECT_FALSE(p->has_error()); } @@ -75,7 +76,7 @@ TEST_F(ParserImplTest, SampledTextureType_kCubeArray) { auto t = p->sampled_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::TextureDimension::kCubeArray); + EXPECT_EQ(t.value, type::TextureDimension::kCubeArray); EXPECT_FALSE(p->has_error()); } diff --git a/src/tint/reader/wgsl/parser_impl_storage_texture_test.cc b/src/tint/reader/wgsl/parser_impl_storage_texture_test.cc index 528f3a4e7c..e1c25b671d 100644 --- a/src/tint/reader/wgsl/parser_impl_storage_texture_test.cc +++ b/src/tint/reader/wgsl/parser_impl_storage_texture_test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "src/tint/reader/wgsl/parser_impl_test_helper.h" +#include "src/tint/type/texture_dimension.h" namespace tint::reader::wgsl { namespace { @@ -30,7 +31,7 @@ TEST_F(ParserImplTest, StorageTextureType_1d) { auto t = p->storage_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::TextureDimension::k1d); + EXPECT_EQ(t.value, type::TextureDimension::k1d); EXPECT_FALSE(p->has_error()); } @@ -39,7 +40,7 @@ TEST_F(ParserImplTest, StorageTextureType_2d) { auto t = p->storage_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::TextureDimension::k2d); + EXPECT_EQ(t.value, type::TextureDimension::k2d); EXPECT_FALSE(p->has_error()); } @@ -48,7 +49,7 @@ TEST_F(ParserImplTest, StorageTextureType_2dArray) { auto t = p->storage_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::TextureDimension::k2dArray); + EXPECT_EQ(t.value, type::TextureDimension::k2dArray); EXPECT_FALSE(p->has_error()); } @@ -57,7 +58,7 @@ TEST_F(ParserImplTest, StorageTextureType_3d) { auto t = p->storage_texture_type(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - EXPECT_EQ(t.value, ast::TextureDimension::k3d); + EXPECT_EQ(t.value, type::TextureDimension::k3d); EXPECT_FALSE(p->has_error()); } diff --git a/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc b/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc index 01a4241f79..41fab414b4 100644 --- a/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc +++ b/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc @@ -16,6 +16,7 @@ #include "src/tint/type/depth_texture.h" #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::reader::wgsl { namespace { @@ -62,7 +63,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); + EXPECT_EQ(t->As()->dim, type::TextureDimension::k2d); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } @@ -76,7 +77,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) { ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->As()->type->Is()); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::k1d); + EXPECT_EQ(t->As()->dim, type::TextureDimension::k1d); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); } @@ -90,7 +91,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->As()->type->Is()); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); + EXPECT_EQ(t->As()->dim, type::TextureDimension::k2d); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); } @@ -104,7 +105,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->As()->type->Is()); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::k3d); + EXPECT_EQ(t->As()->dim, type::TextureDimension::k3d); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); } @@ -148,7 +149,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) { ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->As()->type->Is()); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); + EXPECT_EQ(t->As()->dim, type::TextureDimension::k2d); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 29u}})); } @@ -192,7 +193,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dRg32Float) { ASSERT_TRUE(t->Is()); EXPECT_EQ(t->As()->format, ast::TexelFormat::kRg32Float); EXPECT_EQ(t->As()->access, ast::Access::kRead); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::k1d); + EXPECT_EQ(t->As()->dim, type::TextureDimension::k1d); EXPECT_EQ(t->source.range, (Source::Range{{1u, 1u}, {1u, 36u}})); } @@ -208,7 +209,7 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR32Uint) { ASSERT_TRUE(t->Is()); EXPECT_EQ(t->As()->format, ast::TexelFormat::kR32Uint); EXPECT_EQ(t->As()->access, ast::Access::kWrite); - EXPECT_EQ(t->As()->dim, ast::TextureDimension::k2d); + EXPECT_EQ(t->As()->dim, type::TextureDimension::k2d); EXPECT_EQ(t->source.range, (Source::Range{{1u, 1u}, {1u, 35u}})); } diff --git a/src/tint/resolver/assignment_validation_test.cc b/src/tint/resolver/assignment_validation_test.cc index ce8b31466a..d7ad48894f 100644 --- a/src/tint/resolver/assignment_validation_test.cc +++ b/src/tint/resolver/assignment_validation_test.cc @@ -17,6 +17,7 @@ #include "gmock/gmock.h" #include "src/tint/resolver/resolver_test_helper.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" using namespace tint::number_suffixes; // NOLINT @@ -230,7 +231,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignNonConstructible_Handle) { // a = b; auto make_type = [&] { - return ty.storage_texture(ast::TextureDimension::k1d, ast::TexelFormat::kRgba8Unorm, + return ty.storage_texture(type::TextureDimension::k1d, ast::TexelFormat::kRgba8Unorm, ast::Access::kWrite); }; @@ -360,7 +361,7 @@ TEST_F(ResolverAssignmentValidationTest, AssignToPhony_Pass) { auto* U = Structure("U", utils::Vector{ Member("i", ty.i32()), }); - GlobalVar("tex", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(0_a), + GlobalVar("tex", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(0_a), Binding(0_a)); GlobalVar("smp", ty.sampler(ast::SamplerKind::kSampler), Group(0_a), Binding(1_a)); GlobalVar("u", ty.Of(U), ast::AddressSpace::kUniform, Group(0_a), Binding(2_a)); diff --git a/src/tint/resolver/attribute_validation_test.cc b/src/tint/resolver/attribute_validation_test.cc index 762eea93d8..3c01f8672b 100644 --- a/src/tint/resolver/attribute_validation_test.cc +++ b/src/tint/resolver/attribute_validation_test.cc @@ -16,6 +16,7 @@ #include "src/tint/resolver/resolver.h" #include "src/tint/resolver/resolver_test_helper.h" #include "src/tint/transform/add_block_attribute.h" +#include "src/tint/type/texture_dimension.h" #include "gmock/gmock.h" @@ -1166,7 +1167,7 @@ TEST_F(ResourceAttributeTest, StorageBufferMissingBinding) { } TEST_F(ResourceAttributeTest, TextureMissingBinding) { - GlobalVar(Source{{12, 34}}, "G", ty.depth_texture(ast::TextureDimension::k2d)); + GlobalVar(Source{{12, 34}}, "G", ty.depth_texture(type::TextureDimension::k2d)); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -1198,9 +1199,9 @@ TEST_F(ResourceAttributeTest, BindingPairMissingGroup) { } TEST_F(ResourceAttributeTest, BindingPointUsedTwiceByEntryPoint) { - GlobalVar(Source{{12, 34}}, "A", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + GlobalVar(Source{{12, 34}}, "A", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(1_a), Group(2_a)); - GlobalVar(Source{{56, 78}}, "B", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + GlobalVar(Source{{56, 78}}, "B", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(1_a), Group(2_a)); Func("F", utils::Empty, ty.void_(), @@ -1220,9 +1221,9 @@ TEST_F(ResourceAttributeTest, BindingPointUsedTwiceByEntryPoint) { } TEST_F(ResourceAttributeTest, BindingPointUsedTwiceByDifferentEntryPoints) { - GlobalVar(Source{{12, 34}}, "A", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + GlobalVar(Source{{12, 34}}, "A", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(1_a), Group(2_a)); - GlobalVar(Source{{56, 78}}, "B", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + GlobalVar(Source{{56, 78}}, "B", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(1_a), Group(2_a)); Func("F_A", utils::Empty, ty.void_(), @@ -1582,7 +1583,7 @@ using GroupAndBindingTest = ResolverTest; TEST_F(GroupAndBindingTest, Const_I32) { GlobalConst("b", Expr(4_i)); GlobalConst("g", Expr(2_i)); - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Binding("b"), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding("b"), Group("g")); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1591,7 +1592,7 @@ TEST_F(GroupAndBindingTest, Const_I32) { TEST_F(GroupAndBindingTest, Const_U32) { GlobalConst("b", Expr(4_u)); GlobalConst("g", Expr(2_u)); - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Binding("b"), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding("b"), Group("g")); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1600,14 +1601,14 @@ TEST_F(GroupAndBindingTest, Const_U32) { TEST_F(GroupAndBindingTest, Const_AInt) { GlobalConst("b", Expr(4_a)); GlobalConst("g", Expr(2_a)); - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Binding("b"), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding("b"), Group("g")); EXPECT_TRUE(r()->Resolve()) << r()->error(); } TEST_F(GroupAndBindingTest, Binding_NonConstant) { - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(Construct(ty.u32(), Call(Source{{12, 34}}, "dpdx", 1_a))), Group(1_i)); EXPECT_FALSE(r()->Resolve()); @@ -1617,7 +1618,7 @@ TEST_F(GroupAndBindingTest, Binding_NonConstant) { } TEST_F(GroupAndBindingTest, Binding_Negative) { - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(Source{{12, 34}}, -2_i), Group(1_i)); EXPECT_FALSE(r()->Resolve()); @@ -1625,7 +1626,7 @@ TEST_F(GroupAndBindingTest, Binding_Negative) { } TEST_F(GroupAndBindingTest, Binding_F32) { - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(Source{{12, 34}}, 2.0_f), Group(1_u)); EXPECT_FALSE(r()->Resolve()); @@ -1633,7 +1634,7 @@ TEST_F(GroupAndBindingTest, Binding_F32) { } TEST_F(GroupAndBindingTest, Binding_AFloat) { - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(Source{{12, 34}}, 2.0_a), Group(1_u)); EXPECT_FALSE(r()->Resolve()); @@ -1641,7 +1642,7 @@ TEST_F(GroupAndBindingTest, Binding_AFloat) { } TEST_F(GroupAndBindingTest, Group_NonConstant) { - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Binding(2_u), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(2_u), Group(Construct(ty.u32(), Call(Source{{12, 34}}, "dpdx", 1_a)))); EXPECT_FALSE(r()->Resolve()); @@ -1651,7 +1652,7 @@ TEST_F(GroupAndBindingTest, Group_NonConstant) { } TEST_F(GroupAndBindingTest, Group_Negative) { - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Binding(2_u), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(2_u), Group(Source{{12, 34}}, -1_i)); EXPECT_FALSE(r()->Resolve()); @@ -1659,7 +1660,7 @@ TEST_F(GroupAndBindingTest, Group_Negative) { } TEST_F(GroupAndBindingTest, Group_F32) { - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Binding(2_u), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(2_u), Group(Source{{12, 34}}, 1.0_f)); EXPECT_FALSE(r()->Resolve()); @@ -1667,7 +1668,7 @@ TEST_F(GroupAndBindingTest, Group_F32) { } TEST_F(GroupAndBindingTest, Group_AFloat) { - GlobalVar("val", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Binding(2_u), + GlobalVar("val", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Binding(2_u), Group(Source{{12, 34}}, 1.0_a)); EXPECT_FALSE(r()->Resolve()); diff --git a/src/tint/resolver/builtin_test.cc b/src/tint/resolver/builtin_test.cc index 955b9458bc..b2b1e3091d 100644 --- a/src/tint/resolver/builtin_test.cc +++ b/src/tint/resolver/builtin_test.cc @@ -36,6 +36,7 @@ #include "src/tint/sem/variable.h" #include "src/tint/type/sampled_texture.h" #include "src/tint/type/test_helper.h" +#include "src/tint/type/texture_dimension.h" using ::testing::ElementsAre; using ::testing::HasSubstr; @@ -2102,7 +2103,7 @@ inline std::ostream& operator<<(std::ostream& out, Texture data) { } struct TextureTestParams { - ast::TextureDimension dim; + type::TextureDimension dim; Texture type = Texture::kF32; ast::TexelFormat format = ast::TexelFormat::kR32Float; }; @@ -2118,16 +2119,16 @@ class ResolverBuiltinTest_TextureOperation : public ResolverTestWithParam; @@ -2469,20 +2470,20 @@ TEST_P(ResolverBuiltinTest_Texture, Call) { switch (param.texture_dimension) { default: FAIL() << "invalid texture dimensions: " << param.texture_dimension; - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: EXPECT_TRUE(TypeOf(call)->Is()); break; - case ast::TextureDimension::k2d: - case ast::TextureDimension::k2dArray: - case ast::TextureDimension::kCube: - case ast::TextureDimension::kCubeArray: { + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: + case type::TextureDimension::kCube: + case type::TextureDimension::kCubeArray: { auto* vec = As(TypeOf(call)); ASSERT_NE(vec, nullptr); EXPECT_EQ(vec->Width(), 2u); EXPECT_TRUE(vec->type()->Is()); break; } - case ast::TextureDimension::k3d: { + case type::TextureDimension::k3d: { auto* vec = As(TypeOf(call)); ASSERT_NE(vec, nullptr); EXPECT_EQ(vec->Width(), 3u); diff --git a/src/tint/resolver/dependency_graph_test.cc b/src/tint/resolver/dependency_graph_test.cc index 81e79ff0d0..b73033c26d 100644 --- a/src/tint/resolver/dependency_graph_test.cc +++ b/src/tint/resolver/dependency_graph_test.cc @@ -19,6 +19,7 @@ #include "gmock/gmock.h" #include "src/tint/resolver/dependency_graph.h" #include "src/tint/resolver/resolver_test_helper.h" +#include "src/tint/type/texture_dimension.h" using namespace tint::number_suffixes; // NOLINT @@ -493,12 +494,12 @@ const ast::Node* SymbolTestHelper::Add(SymbolUseKind kind, Symbol symbol, Source } case SymbolUseKind::GlobalVarSampledTexElemType: { auto* node = b.ty.type_name(source, symbol); - b.GlobalVar(b.Sym(), b.ty.sampled_texture(ast::TextureDimension::k2d, node)); + b.GlobalVar(b.Sym(), b.ty.sampled_texture(type::TextureDimension::k2d, node)); return node; } case SymbolUseKind::GlobalVarMultisampledTexElemType: { auto* node = b.ty.type_name(source, symbol); - b.GlobalVar(b.Sym(), b.ty.multisampled_texture(ast::TextureDimension::k2d, node)); + b.GlobalVar(b.Sym(), b.ty.multisampled_texture(type::TextureDimension::k2d, node)); return node; } case SymbolUseKind::GlobalVarValue: { @@ -1290,12 +1291,12 @@ TEST_F(ResolverDependencyGraphTraversalTest, SymbolsReached) { GlobalVar(Sym(), ty.vec3(T)); GlobalVar(Sym(), ty.mat3x2(T)); GlobalVar(Sym(), ty.pointer(T, ast::AddressSpace::kPrivate)); - GlobalVar(Sym(), ty.sampled_texture(ast::TextureDimension::k2d, T)); - GlobalVar(Sym(), ty.depth_texture(ast::TextureDimension::k2d)); - GlobalVar(Sym(), ty.depth_multisampled_texture(ast::TextureDimension::k2d)); + GlobalVar(Sym(), ty.sampled_texture(type::TextureDimension::k2d, T)); + GlobalVar(Sym(), ty.depth_texture(type::TextureDimension::k2d)); + GlobalVar(Sym(), ty.depth_multisampled_texture(type::TextureDimension::k2d)); GlobalVar(Sym(), ty.external_texture()); - GlobalVar(Sym(), ty.multisampled_texture(ast::TextureDimension::k2d, T)); - GlobalVar(Sym(), ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Float, + GlobalVar(Sym(), ty.multisampled_texture(type::TextureDimension::k2d, T)); + GlobalVar(Sym(), ty.storage_texture(type::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kRead)); // GlobalVar(Sym(), ty.sampler(ast::SamplerKind::kSampler)); diff --git a/src/tint/resolver/intrinsic_table.cc b/src/tint/resolver/intrinsic_table.cc index 4b507b8db4..129fcc3171 100644 --- a/src/tint/resolver/intrinsic_table.cc +++ b/src/tint/resolver/intrinsic_table.cc @@ -34,6 +34,7 @@ #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/hash.h" #include "src/tint/utils/hashmap.h" #include "src/tint/utils/math.h" @@ -605,7 +606,7 @@ const type::Sampler* build_sampler_comparison(MatchState& state) { bool match_texture(MatchState&, const type::Type* ty, - ast::TextureDimension dim, + type::TextureDimension dim, const type::Type*& T) { if (ty->Is()) { T = ty; @@ -632,17 +633,17 @@ bool match_texture(MatchState&, return state.builder.create(dim, T); \ } -DECLARE_SAMPLED_TEXTURE(1d, ast::TextureDimension::k1d) -DECLARE_SAMPLED_TEXTURE(2d, ast::TextureDimension::k2d) -DECLARE_SAMPLED_TEXTURE(2d_array, ast::TextureDimension::k2dArray) -DECLARE_SAMPLED_TEXTURE(3d, ast::TextureDimension::k3d) -DECLARE_SAMPLED_TEXTURE(cube, ast::TextureDimension::kCube) -DECLARE_SAMPLED_TEXTURE(cube_array, ast::TextureDimension::kCubeArray) +DECLARE_SAMPLED_TEXTURE(1d, type::TextureDimension::k1d) +DECLARE_SAMPLED_TEXTURE(2d, type::TextureDimension::k2d) +DECLARE_SAMPLED_TEXTURE(2d_array, type::TextureDimension::k2dArray) +DECLARE_SAMPLED_TEXTURE(3d, type::TextureDimension::k3d) +DECLARE_SAMPLED_TEXTURE(cube, type::TextureDimension::kCube) +DECLARE_SAMPLED_TEXTURE(cube_array, type::TextureDimension::kCubeArray) #undef DECLARE_SAMPLED_TEXTURE bool match_texture_multisampled(MatchState&, const type::Type* ty, - ast::TextureDimension dim, + type::TextureDimension dim, const type::Type*& T) { if (ty->Is()) { T = ty; @@ -667,10 +668,10 @@ bool match_texture_multisampled(MatchState&, return state.builder.create(dim, T); \ } -DECLARE_MULTISAMPLED_TEXTURE(2d, ast::TextureDimension::k2d) +DECLARE_MULTISAMPLED_TEXTURE(2d, type::TextureDimension::k2d) #undef DECLARE_MULTISAMPLED_TEXTURE -bool match_texture_depth(MatchState&, const type::Type* ty, ast::TextureDimension dim) { +bool match_texture_depth(MatchState&, const type::Type* ty, type::TextureDimension dim) { if (ty->Is()) { return true; } @@ -685,10 +686,10 @@ bool match_texture_depth(MatchState&, const type::Type* ty, ast::TextureDimensio return state.builder.create(dim); \ } -DECLARE_DEPTH_TEXTURE(2d, ast::TextureDimension::k2d) -DECLARE_DEPTH_TEXTURE(2d_array, ast::TextureDimension::k2dArray) -DECLARE_DEPTH_TEXTURE(cube, ast::TextureDimension::kCube) -DECLARE_DEPTH_TEXTURE(cube_array, ast::TextureDimension::kCubeArray) +DECLARE_DEPTH_TEXTURE(2d, type::TextureDimension::k2d) +DECLARE_DEPTH_TEXTURE(2d_array, type::TextureDimension::k2dArray) +DECLARE_DEPTH_TEXTURE(cube, type::TextureDimension::kCube) +DECLARE_DEPTH_TEXTURE(cube_array, type::TextureDimension::kCubeArray) #undef DECLARE_DEPTH_TEXTURE bool match_texture_depth_multisampled_2d(MatchState&, const type::Type* ty) { @@ -696,17 +697,17 @@ bool match_texture_depth_multisampled_2d(MatchState&, const type::Type* ty) { return true; } return ty->Is([&](const type::DepthMultisampledTexture* t) { - return t->dim() == ast::TextureDimension::k2d; + return t->dim() == type::TextureDimension::k2d; }); } type::DepthMultisampledTexture* build_texture_depth_multisampled_2d(MatchState& state) { - return state.builder.create(ast::TextureDimension::k2d); + return state.builder.create(type::TextureDimension::k2d); } bool match_texture_storage(MatchState&, const type::Type* ty, - ast::TextureDimension dim, + type::TextureDimension dim, Number& F, Number& A) { if (ty->Is()) { @@ -737,10 +738,10 @@ bool match_texture_storage(MatchState&, return state.builder.create(dim, format, access, T); \ } -DECLARE_STORAGE_TEXTURE(1d, ast::TextureDimension::k1d) -DECLARE_STORAGE_TEXTURE(2d, ast::TextureDimension::k2d) -DECLARE_STORAGE_TEXTURE(2d_array, ast::TextureDimension::k2dArray) -DECLARE_STORAGE_TEXTURE(3d, ast::TextureDimension::k3d) +DECLARE_STORAGE_TEXTURE(1d, type::TextureDimension::k1d) +DECLARE_STORAGE_TEXTURE(2d, type::TextureDimension::k2d) +DECLARE_STORAGE_TEXTURE(2d_array, type::TextureDimension::k2dArray) +DECLARE_STORAGE_TEXTURE(3d, type::TextureDimension::k3d) #undef DECLARE_STORAGE_TEXTURE bool match_texture_external(MatchState&, const type::Type* ty) { diff --git a/src/tint/resolver/intrinsic_table_test.cc b/src/tint/resolver/intrinsic_table_test.cc index bb17baea93..fbd00afc65 100644 --- a/src/tint/resolver/intrinsic_table_test.cc +++ b/src/tint/resolver/intrinsic_table_test.cc @@ -30,6 +30,7 @@ #include "src/tint/type/sampled_texture.h" #include "src/tint/type/storage_texture.h" #include "src/tint/type/test_helper.h" +#include "src/tint/type/texture_dimension.h" namespace tint::resolver { namespace { @@ -97,7 +98,7 @@ TEST_F(IntrinsicTableTest, MatchI32) { auto* f32 = create(); auto* i32 = create(); auto* vec4_f32 = create(f32, 4u); - auto* tex = create(ast::TextureDimension::k1d, f32); + auto* tex = create(type::TextureDimension::k1d, f32); auto result = table->Lookup(BuiltinType::kTextureLoad, utils::Vector{tex, i32, i32}, sem::EvaluationStage::kConstant, Source{}); ASSERT_NE(result.sem, nullptr) << Diagnostics().str(); @@ -115,7 +116,7 @@ TEST_F(IntrinsicTableTest, MatchI32) { TEST_F(IntrinsicTableTest, MismatchI32) { auto* f32 = create(); - auto* tex = create(ast::TextureDimension::k1d, f32); + auto* tex = create(type::TextureDimension::k1d, f32); auto result = table->Lookup(BuiltinType::kTextureLoad, utils::Vector{tex, f32}, sem::EvaluationStage::kConstant, Source{}); ASSERT_EQ(result.sem, nullptr); @@ -280,7 +281,7 @@ TEST_F(IntrinsicTableTest, MatchSampler) { auto* f32 = create(); auto* vec2_f32 = create(f32, 2u); auto* vec4_f32 = create(f32, 4u); - auto* tex = create(ast::TextureDimension::k2d, f32); + auto* tex = create(type::TextureDimension::k2d, f32); auto* sampler = create(ast::SamplerKind::kSampler); auto result = table->Lookup(BuiltinType::kTextureSample, utils::Vector{tex, sampler, vec2_f32}, sem::EvaluationStage::kConstant, Source{}); @@ -300,7 +301,7 @@ TEST_F(IntrinsicTableTest, MatchSampler) { TEST_F(IntrinsicTableTest, MismatchSampler) { auto* f32 = create(); auto* vec2_f32 = create(f32, 2u); - auto* tex = create(ast::TextureDimension::k2d, f32); + auto* tex = create(type::TextureDimension::k2d, f32); auto result = table->Lookup(BuiltinType::kTextureSample, utils::Vector{tex, f32, vec2_f32}, sem::EvaluationStage::kConstant, Source{}); ASSERT_EQ(result.sem, nullptr); @@ -312,7 +313,7 @@ TEST_F(IntrinsicTableTest, MatchSampledTexture) { auto* f32 = create(); auto* vec2_i32 = create(i32, 2u); auto* vec4_f32 = create(f32, 4u); - auto* tex = create(ast::TextureDimension::k2d, f32); + auto* tex = create(type::TextureDimension::k2d, f32); auto result = table->Lookup(BuiltinType::kTextureLoad, utils::Vector{tex, vec2_i32, i32}, sem::EvaluationStage::kConstant, Source{}); ASSERT_NE(result.sem, nullptr) << Diagnostics().str(); @@ -333,7 +334,7 @@ TEST_F(IntrinsicTableTest, MatchMultisampledTexture) { auto* f32 = create(); auto* vec2_i32 = create(i32, 2u); auto* vec4_f32 = create(f32, 4u); - auto* tex = create(ast::TextureDimension::k2d, f32); + auto* tex = create(type::TextureDimension::k2d, f32); auto result = table->Lookup(BuiltinType::kTextureLoad, utils::Vector{tex, vec2_i32, i32}, sem::EvaluationStage::kConstant, Source{}); ASSERT_NE(result.sem, nullptr) << Diagnostics().str(); @@ -353,7 +354,7 @@ TEST_F(IntrinsicTableTest, MatchDepthTexture) { auto* f32 = create(); auto* i32 = create(); auto* vec2_i32 = create(i32, 2u); - auto* tex = create(ast::TextureDimension::k2d); + auto* tex = create(type::TextureDimension::k2d); auto result = table->Lookup(BuiltinType::kTextureLoad, utils::Vector{tex, vec2_i32, i32}, sem::EvaluationStage::kConstant, Source{}); ASSERT_NE(result.sem, nullptr) << Diagnostics().str(); @@ -373,7 +374,7 @@ TEST_F(IntrinsicTableTest, MatchDepthMultisampledTexture) { auto* f32 = create(); auto* i32 = create(); auto* vec2_i32 = create(i32, 2u); - auto* tex = create(ast::TextureDimension::k2d); + auto* tex = create(type::TextureDimension::k2d); auto result = table->Lookup(BuiltinType::kTextureLoad, utils::Vector{tex, vec2_i32, i32}, sem::EvaluationStage::kConstant, Source{}); ASSERT_NE(result.sem, nullptr) << Diagnostics().str(); @@ -415,7 +416,7 @@ TEST_F(IntrinsicTableTest, MatchWOStorageTexture) { auto* vec4_f32 = create(f32, 4u); auto* subtype = type::StorageTexture::SubtypeFor(ast::TexelFormat::kR32Float, Types()); auto* tex = create( - ast::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kWrite, subtype); + type::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kWrite, subtype); auto result = table->Lookup(BuiltinType::kTextureStore, utils::Vector{tex, vec2_i32, vec4_f32}, sem::EvaluationStage::kConstant, Source{}); @@ -629,7 +630,7 @@ TEST_F(IntrinsicTableTest, OverloadOrderByNumberOfParameters) { } TEST_F(IntrinsicTableTest, OverloadOrderByMatchingParameter) { - auto* tex = create(ast::TextureDimension::k2d); + auto* tex = create(type::TextureDimension::k2d); auto* bool_ = create(); table->Lookup(BuiltinType::kTextureDimensions, utils::Vector{tex, bool_}, sem::EvaluationStage::kConstant, Source{}); diff --git a/src/tint/resolver/load_test.cc b/src/tint/resolver/load_test.cc index fea60ff513..a97b011cee 100644 --- a/src/tint/resolver/load_test.cc +++ b/src/tint/resolver/load_test.cc @@ -12,14 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/sem/load.h" +#include "gmock/gmock.h" #include "src/tint/resolver/resolver.h" #include "src/tint/resolver/resolver_test_helper.h" #include "src/tint/sem/test_helper.h" - -#include "src/tint/sem/load.h" #include "src/tint/type/reference.h" - -#include "gmock/gmock.h" +#include "src/tint/type/texture_dimension.h" using namespace tint::number_suffixes; // NOLINT @@ -220,12 +219,12 @@ TEST_F(ResolverLoadTest, FunctionArg_Handles) { // return textureSampleLevel(tp, sp, vec2(), 0); // } // f(t, s); - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + GlobalVar("t", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), utils::Vector{Group(0_a), Binding(0_a)}); GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), utils::Vector{Group(0_a), Binding(1_a)}); Func("f", utils::Vector{ - Param("tp", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32())), + Param("tp", ty.sampled_texture(type::TextureDimension::k2d, ty.f32())), Param("sp", ty.sampler(ast::SamplerKind::kSampler)), }, ty.vec4(), diff --git a/src/tint/resolver/ptr_ref_validation_test.cc b/src/tint/resolver/ptr_ref_validation_test.cc index efd77a6b5c..a79a546349 100644 --- a/src/tint/resolver/ptr_ref_validation_test.cc +++ b/src/tint/resolver/ptr_ref_validation_test.cc @@ -12,12 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "gmock/gmock.h" #include "src/tint/ast/bitcast_expression.h" #include "src/tint/resolver/resolver.h" #include "src/tint/resolver/resolver_test_helper.h" #include "src/tint/type/reference.h" - -#include "gmock/gmock.h" +#include "src/tint/type/texture_dimension.h" using namespace tint::number_suffixes; // NOLINT @@ -54,7 +54,7 @@ TEST_F(ResolverPtrRefValidationTest, AddressOfLet) { TEST_F(ResolverPtrRefValidationTest, AddressOfHandle) { // @group(0) @binding(0) var t: texture_3d; // &t - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k3d, ty.f32()), Group(0_a), + GlobalVar("t", ty.sampled_texture(type::TextureDimension::k3d, ty.f32()), Group(0_a), Binding(0_a)); auto* expr = AddressOf(Expr(Source{{12, 34}}, "t")); WrapInFunction(expr); @@ -94,7 +94,7 @@ TEST_F(ResolverPtrRefValidationTest, AddressOfVectorComponent_IndexAccessor) { TEST_F(ResolverPtrRefValidationTest, IndirectOfAddressOfHandle) { // @group(0) @binding(0) var t: texture_3d; // *&t - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k3d, ty.f32()), Group(0_a), + GlobalVar("t", ty.sampled_texture(type::TextureDimension::k3d, ty.f32()), Group(0_a), Binding(0_a)); auto* expr = Deref(AddressOf(Expr(Source{{12, 34}}, "t"))); WrapInFunction(expr); diff --git a/src/tint/resolver/resolver_test.cc b/src/tint/resolver/resolver_test.cc index e5538c558e..a5a914852c 100644 --- a/src/tint/resolver/resolver_test.cc +++ b/src/tint/resolver/resolver_test.cc @@ -44,6 +44,7 @@ #include "src/tint/sem/variable.h" #include "src/tint/type/reference.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" using ::testing::ElementsAre; using ::testing::HasSubstr; @@ -1886,7 +1887,7 @@ TEST_F(ResolverTest, AddressSpace_SetForSampler) { } TEST_F(ResolverTest, AddressSpace_SetForTexture) { - auto* t = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* t = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); auto* var = GlobalVar("var", t, Binding(0_a), Group(0_a)); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -2123,7 +2124,7 @@ TEST_F(ResolverTest, UnaryOp_Negation) { } TEST_F(ResolverTest, TextureSampler_TextureSample) { - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1_a), + GlobalVar("t", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(1_a), Binding(1_a)); GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1_a), Binding(2_a)); @@ -2141,7 +2142,7 @@ TEST_F(ResolverTest, TextureSampler_TextureSample) { } TEST_F(ResolverTest, TextureSampler_TextureSampleInFunction) { - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1_a), + GlobalVar("t", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(1_a), Binding(1_a)); GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1_a), Binding(2_a)); @@ -2167,7 +2168,7 @@ TEST_F(ResolverTest, TextureSampler_TextureSampleInFunction) { } TEST_F(ResolverTest, TextureSampler_TextureSampleFunctionDiamondSameVariables) { - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1_a), + GlobalVar("t", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(1_a), Binding(1_a)); GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1_a), Binding(2_a)); @@ -2202,9 +2203,9 @@ TEST_F(ResolverTest, TextureSampler_TextureSampleFunctionDiamondSameVariables) { } TEST_F(ResolverTest, TextureSampler_TextureSampleFunctionDiamondDifferentVariables) { - GlobalVar("t1", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1_a), + GlobalVar("t1", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(1_a), Binding(1_a)); - GlobalVar("t2", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1_a), + GlobalVar("t2", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(1_a), Binding(2_a)); GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(1_a), Binding(3_a)); @@ -2241,7 +2242,7 @@ TEST_F(ResolverTest, TextureSampler_TextureSampleFunctionDiamondDifferentVariabl } TEST_F(ResolverTest, TextureSampler_TextureDimensions) { - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(1_a), + GlobalVar("t", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(1_a), Binding(2_a)); auto* call = Call("textureDimensions", "t"); @@ -2270,7 +2271,7 @@ TEST_F(ResolverTest, TextureSampler_Bug1715) { // crbug.com/tint/1715 // return textureSampleLevel(*tl, *sl, c, 0.0); // } GlobalVar("s", ty.sampler(ast::SamplerKind::kSampler), Group(0_a), Binding(0_a)); - GlobalVar("t", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(0_a), + GlobalVar("t", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(0_a), Binding(1_a)); GlobalVar("c", ty.vec2(), ast::AddressSpace::kUniform, Group(0_a), Binding(2_a)); @@ -2289,7 +2290,7 @@ TEST_F(ResolverTest, TextureSampler_Bug1715) { // crbug.com/tint/1715 utils::Vector{ Param("sl", ty.pointer(ty.sampler(ast::SamplerKind::kSampler), ast::AddressSpace::kFunction)), - Param("tl", ty.pointer(ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + Param("tl", ty.pointer(ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), ast::AddressSpace::kFunction)), }, ty.vec4(), diff --git a/src/tint/resolver/root_identifier_test.cc b/src/tint/resolver/root_identifier_test.cc index 934feaee75..adf92395fb 100644 --- a/src/tint/resolver/root_identifier_test.cc +++ b/src/tint/resolver/root_identifier_test.cc @@ -17,6 +17,7 @@ #include "src/tint/resolver/resolver_test_helper.h" #include "src/tint/sem/index_accessor_expression.h" #include "src/tint/sem/member_accessor_expression.h" +#include "src/tint/type/texture_dimension.h" using namespace tint::number_suffixes; // NOLINT @@ -70,7 +71,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalUniformVar) { } TEST_F(ResolverRootIdentifierTest, GlobalTextureVar) { - auto* a = GlobalVar("a", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), + auto* a = GlobalVar("a", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), ast::AddressSpace::kNone, Group(0_a), Binding(0_a)); auto* expr = Expr(a); WrapInFunction(Call("textureDimensions", expr)); diff --git a/src/tint/resolver/side_effects_test.cc b/src/tint/resolver/side_effects_test.cc index 826558607b..e3677149e9 100644 --- a/src/tint/resolver/side_effects_test.cc +++ b/src/tint/resolver/side_effects_test.cc @@ -19,6 +19,7 @@ #include "src/tint/sem/expression.h" #include "src/tint/sem/index_accessor_expression.h" #include "src/tint/sem/member_accessor_expression.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/vector.h" using namespace tint::number_suffixes; // NOLINT @@ -180,16 +181,16 @@ TEST_P(SideEffectsBuiltinTest, Test) { GlobalVar("a", ty.atomic(ty.i32()), ast::AddressSpace::kStorage, ast::Access::kReadWrite, Group(0_a), Binding(AInt(next_binding++))); if (c.pipeline_stage != ast::PipelineStage::kCompute) { - GlobalVar("t2d", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(0_a), + GlobalVar("t2d", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), Group(0_a), Binding(AInt(next_binding++))); - GlobalVar("tdepth2d", ty.depth_texture(ast::TextureDimension::k2d), Group(0_a), + GlobalVar("tdepth2d", ty.depth_texture(type::TextureDimension::k2d), Group(0_a), Binding(AInt(next_binding++))); - GlobalVar("t2d_arr", ty.sampled_texture(ast::TextureDimension::k2dArray, ty.f32()), + GlobalVar("t2d_arr", ty.sampled_texture(type::TextureDimension::k2dArray, ty.f32()), Group(0_a), Binding(AInt(next_binding++))); - GlobalVar("t2d_multi", ty.multisampled_texture(ast::TextureDimension::k2d, ty.f32()), + GlobalVar("t2d_multi", ty.multisampled_texture(type::TextureDimension::k2d, ty.f32()), Group(0_a), Binding(AInt(next_binding++))); GlobalVar("tstorage2d", - ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Float, + ty.storage_texture(type::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kWrite), Group(0_a), Binding(AInt(next_binding++))); GlobalVar("s2d", ty.sampler(ast::SamplerKind::kSampler), Group(0_a), diff --git a/src/tint/resolver/type_validation_test.cc b/src/tint/resolver/type_validation_test.cc index ebd40b04b2..bfc9d23a38 100644 --- a/src/tint/resolver/type_validation_test.cc +++ b/src/tint/resolver/type_validation_test.cc @@ -19,6 +19,7 @@ #include "src/tint/resolver/resolver_test_helper.h" #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" #include "gmock/gmock.h" @@ -856,7 +857,7 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsLast_Pass) { } TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableType) { - auto* tex_ty = ty.sampled_texture(Source{{12, 34}}, ast::TextureDimension::k2d, ty.f32()); + auto* tex_ty = ty.sampled_texture(Source{{12, 34}}, type::TextureDimension::k2d, ty.f32()); GlobalVar("arr", ty.array(tex_ty, 4_i), ast::AddressSpace::kPrivate); EXPECT_FALSE(r()->Resolve()); @@ -964,7 +965,7 @@ INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, CanonicalTest, testing::Val namespace SampledTextureTests { struct DimensionParams { - ast::TextureDimension dim; + type::TextureDimension dim; bool is_valid; }; @@ -979,12 +980,12 @@ TEST_P(SampledTextureDimensionTest, All) { INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, SampledTextureDimensionTest, testing::Values( // - DimensionParams{ast::TextureDimension::k1d, true}, - DimensionParams{ast::TextureDimension::k2d, true}, - DimensionParams{ast::TextureDimension::k2dArray, true}, - DimensionParams{ast::TextureDimension::k3d, true}, - DimensionParams{ast::TextureDimension::kCube, true}, - DimensionParams{ast::TextureDimension::kCubeArray, true})); + DimensionParams{type::TextureDimension::k1d, true}, + DimensionParams{type::TextureDimension::k2d, true}, + DimensionParams{type::TextureDimension::k2dArray, true}, + DimensionParams{type::TextureDimension::k3d, true}, + DimensionParams{type::TextureDimension::kCube, true}, + DimensionParams{type::TextureDimension::kCubeArray, true})); using MultisampledTextureDimensionTest = ResolverTestWithParam; TEST_P(MultisampledTextureDimensionTest, All) { @@ -1002,12 +1003,12 @@ TEST_P(MultisampledTextureDimensionTest, All) { INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, MultisampledTextureDimensionTest, testing::Values( // - DimensionParams{ast::TextureDimension::k1d, false}, - DimensionParams{ast::TextureDimension::k2d, true}, - DimensionParams{ast::TextureDimension::k2dArray, false}, - DimensionParams{ast::TextureDimension::k3d, false}, - DimensionParams{ast::TextureDimension::kCube, false}, - DimensionParams{ast::TextureDimension::kCubeArray, false})); + DimensionParams{type::TextureDimension::k1d, false}, + DimensionParams{type::TextureDimension::k2d, true}, + DimensionParams{type::TextureDimension::k2dArray, false}, + DimensionParams{type::TextureDimension::k3d, false}, + DimensionParams{type::TextureDimension::kCube, false}, + DimensionParams{type::TextureDimension::kCubeArray, false})); struct TypeParams { builder::ast_type_func_ptr type_func; @@ -1047,7 +1048,7 @@ TEST_P(SampledTextureTypeTest, All) { Enable(ast::Extension::kF16); GlobalVar( "a", - ty.sampled_texture(Source{{12, 34}}, ast::TextureDimension::k2d, params.type_func(*this)), + ty.sampled_texture(Source{{12, 34}}, type::TextureDimension::k2d, params.type_func(*this)), Group(0_a), Binding(0_a)); if (params.is_valid) { @@ -1066,7 +1067,7 @@ TEST_P(MultisampledTextureTypeTest, All) { auto& params = GetParam(); Enable(ast::Extension::kF16); GlobalVar("a", - ty.multisampled_texture(Source{{12, 34}}, ast::TextureDimension::k2d, + ty.multisampled_texture(Source{{12, 34}}, type::TextureDimension::k2d, params.type_func(*this)), Group(0_a), Binding(0_a)); @@ -1086,17 +1087,17 @@ INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, namespace StorageTextureTests { struct DimensionParams { - ast::TextureDimension dim; + type::TextureDimension dim; bool is_valid; }; static constexpr DimensionParams Dimension_cases[] = { - DimensionParams{ast::TextureDimension::k1d, true}, - DimensionParams{ast::TextureDimension::k2d, true}, - DimensionParams{ast::TextureDimension::k2dArray, true}, - DimensionParams{ast::TextureDimension::k3d, true}, - DimensionParams{ast::TextureDimension::kCube, false}, - DimensionParams{ast::TextureDimension::kCubeArray, false}}; + DimensionParams{type::TextureDimension::k1d, true}, + DimensionParams{type::TextureDimension::k2d, true}, + DimensionParams{type::TextureDimension::k2dArray, true}, + DimensionParams{type::TextureDimension::k3d, true}, + DimensionParams{type::TextureDimension::kCube, false}, + DimensionParams{type::TextureDimension::kCubeArray, false}}; using StorageTextureDimensionTest = ResolverTestWithParam; TEST_P(StorageTextureDimensionTest, All) { @@ -1156,18 +1157,20 @@ TEST_P(StorageTextureFormatTest, All) { // @group(0) @binding(3) // var d : texture_storage_3d<*, write>; - auto* st_a = ty.storage_texture(Source{{12, 34}}, ast::TextureDimension::k1d, params.format, + auto* st_a = ty.storage_texture(Source{{12, 34}}, type::TextureDimension::k1d, params.format, ast::Access::kWrite); GlobalVar("a", st_a, Group(0_a), Binding(0_a)); - auto* st_b = ty.storage_texture(ast::TextureDimension::k2d, params.format, ast::Access::kWrite); + auto* st_b = + ty.storage_texture(type::TextureDimension::k2d, params.format, ast::Access::kWrite); GlobalVar("b", st_b, Group(0_a), Binding(1_a)); auto* st_c = - ty.storage_texture(ast::TextureDimension::k2dArray, params.format, ast::Access::kWrite); + ty.storage_texture(type::TextureDimension::k2dArray, params.format, ast::Access::kWrite); GlobalVar("c", st_c, Group(0_a), Binding(2_a)); - auto* st_d = ty.storage_texture(ast::TextureDimension::k3d, params.format, ast::Access::kWrite); + auto* st_d = + ty.storage_texture(type::TextureDimension::k3d, params.format, ast::Access::kWrite); GlobalVar("d", st_d, Group(0_a), Binding(3_a)); if (params.is_valid) { @@ -1189,7 +1192,7 @@ TEST_F(StorageTextureAccessTest, MissingAccess_Fail) { // @group(0) @binding(0) // var a : texture_storage_1d; - auto* st = ty.storage_texture(Source{{12, 34}}, ast::TextureDimension::k1d, + auto* st = ty.storage_texture(Source{{12, 34}}, type::TextureDimension::k1d, ast::TexelFormat::kR32Uint, ast::Access::kUndefined); GlobalVar("a", st, Group(0_a), Binding(0_a)); @@ -1202,7 +1205,7 @@ TEST_F(StorageTextureAccessTest, RWAccess_Fail) { // @group(0) @binding(0) // var a : texture_storage_1d; - auto* st = ty.storage_texture(Source{{12, 34}}, ast::TextureDimension::k1d, + auto* st = ty.storage_texture(Source{{12, 34}}, type::TextureDimension::k1d, ast::TexelFormat::kR32Uint, ast::Access::kReadWrite); GlobalVar("a", st, Group(0_a), Binding(0_a)); @@ -1216,7 +1219,7 @@ TEST_F(StorageTextureAccessTest, ReadOnlyAccess_Fail) { // @group(0) @binding(0) // var a : texture_storage_1d; - auto* st = ty.storage_texture(Source{{12, 34}}, ast::TextureDimension::k1d, + auto* st = ty.storage_texture(Source{{12, 34}}, type::TextureDimension::k1d, ast::TexelFormat::kR32Uint, ast::Access::kRead); GlobalVar("a", st, Group(0_a), Binding(0_a)); @@ -1230,7 +1233,7 @@ TEST_F(StorageTextureAccessTest, WriteOnlyAccess_Pass) { // @group(0) @binding(0) // var a : texture_storage_1d; - auto* st = ty.storage_texture(ast::TextureDimension::k1d, ast::TexelFormat::kR32Uint, + auto* st = ty.storage_texture(type::TextureDimension::k1d, ast::TexelFormat::kR32Uint, ast::Access::kWrite); GlobalVar("a", st, Group(0_a), Binding(0_a)); diff --git a/src/tint/resolver/validation_test.cc b/src/tint/resolver/validation_test.cc index b47660271c..7f41be6a31 100644 --- a/src/tint/resolver/validation_test.cc +++ b/src/tint/resolver/validation_test.cc @@ -37,6 +37,7 @@ #include "src/tint/sem/statement.h" #include "src/tint/sem/variable.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" using ::testing::ElementsAre; using ::testing::HasSubstr; @@ -345,7 +346,7 @@ TEST_F(ResolverValidationTest, AddressSpace_SamplerExplicitAddressSpace) { } TEST_F(ResolverValidationTest, AddressSpace_TextureExplicitAddressSpace) { - auto* t = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* t = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); GlobalVar(Source{{12, 34}}, "var", t, ast::AddressSpace::kHandle, Binding(0_a), Group(0_a)); EXPECT_FALSE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc index c25129aafa..556350e825 100644 --- a/src/tint/resolver/validator.cc +++ b/src/tint/resolver/validator.cc @@ -73,6 +73,7 @@ #include "src/tint/type/sampled_texture.h" #include "src/tint/type/sampler.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/defer.h" #include "src/tint/utils/map.h" #include "src/tint/utils/math.h" @@ -84,12 +85,12 @@ namespace tint::resolver { namespace { -bool IsValidStorageTextureDimension(ast::TextureDimension dim) { +bool IsValidStorageTextureDimension(type::TextureDimension dim) { switch (dim) { - case ast::TextureDimension::k1d: - case ast::TextureDimension::k2d: - case ast::TextureDimension::k2dArray: - case ast::TextureDimension::k3d: + case type::TextureDimension::k1d: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: + case type::TextureDimension::k3d: return true; default: return false; @@ -331,7 +332,7 @@ bool Validator::SampledTexture(const type::SampledTexture* t, const Source& sour bool Validator::MultisampledTexture(const type::MultisampledTexture* t, const Source& source) const { - if (t->dim() != ast::TextureDimension::k2d) { + if (t->dim() != type::TextureDimension::k2d) { AddError("only 2d multisampled textures are supported", source); return false; } diff --git a/src/tint/resolver/variable_test.cc b/src/tint/resolver/variable_test.cc index 552ad08658..744fb998bf 100644 --- a/src/tint/resolver/variable_test.cc +++ b/src/tint/resolver/variable_test.cc @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "gmock/gmock.h" #include "src/tint/resolver/resolver.h" #include "src/tint/resolver/resolver_test_helper.h" #include "src/tint/type/reference.h" - -#include "gmock/gmock.h" +#include "src/tint/type/texture_dimension.h" namespace tint::resolver { namespace { @@ -1044,7 +1044,7 @@ TEST_F(ResolverVariableTest, GlobalVar_AddressSpace) { auto* storage = GlobalVar("sb", ty.Of(buf), ast::AddressSpace::kStorage, Binding(1_a), Group(0_a)); auto* handle = - GlobalVar("h", ty.depth_texture(ast::TextureDimension::k2d), Binding(2_a), Group(0_a)); + GlobalVar("h", ty.depth_texture(type::TextureDimension::k2d), Binding(2_a), Group(0_a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/variable_validation_test.cc b/src/tint/resolver/variable_validation_test.cc index cf35e4cbb6..c4232e25f2 100644 --- a/src/tint/resolver/variable_validation_test.cc +++ b/src/tint/resolver/variable_validation_test.cc @@ -12,10 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "gmock/gmock.h" #include "src/tint/resolver/resolver.h" #include "src/tint/resolver/resolver_test_helper.h" - -#include "gmock/gmock.h" +#include "src/tint/type/texture_dimension.h" using namespace tint::number_suffixes; // NOLINT @@ -123,8 +123,8 @@ TEST_F(ResolverVariableValidationTest, VarTypeNotConstructible) { TEST_F(ResolverVariableValidationTest, LetTypeNotConstructible) { // @group(0) @binding(0) var t1 : texture_2d; // let t2 : t1; - auto* t1 = GlobalVar("t1", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), Group(0_a), - Binding(0_a)); + auto* t1 = GlobalVar("t1", ty.sampled_texture(type::TextureDimension::k2d, ty.f32()), + Group(0_a), Binding(0_a)); auto* t2 = Let(Source{{56, 78}}, "t2", Expr(t1)); WrapInFunction(t2); diff --git a/src/tint/transform/builtin_polyfill.cc b/src/tint/transform/builtin_polyfill.cc index dbd6f6e677..2c0f2a9515 100644 --- a/src/tint/transform/builtin_polyfill.cc +++ b/src/tint/transform/builtin_polyfill.cc @@ -22,6 +22,7 @@ #include "src/tint/program_builder.h" #include "src/tint/sem/builtin.h" #include "src/tint/sem/call.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/map.h" using namespace tint::number_suffixes; // NOLINT @@ -638,7 +639,7 @@ struct BuiltinPolyfill::State { }; b.Func(name, utils::Vector{ - b.Param("t", b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32())), + b.Param("t", b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32())), b.Param("s", b.ty.sampler(ast::SamplerKind::kSampler)), b.Param("coord", b.ty.vec2()), }, diff --git a/src/tint/transform/multiplanar_external_texture.cc b/src/tint/transform/multiplanar_external_texture.cc index d81d1868eb..7a2200e4a9 100644 --- a/src/tint/transform/multiplanar_external_texture.cc +++ b/src/tint/transform/multiplanar_external_texture.cc @@ -22,6 +22,7 @@ #include "src/tint/sem/call.h" #include "src/tint/sem/function.h" #include "src/tint/sem/variable.h" +#include "src/tint/type/texture_dimension.h" TINT_INSTANTIATE_TYPEINFO(tint::transform::MultiplanarExternalTexture); TINT_INSTANTIATE_TYPEINFO(tint::transform::MultiplanarExternalTexture::NewBindingPoints); @@ -140,7 +141,7 @@ struct MultiplanarExternalTexture::State { auto& syms = new_binding_symbols[sem_var]; syms.plane_0 = ctx.Clone(global->symbol); syms.plane_1 = b.Symbols().New("ext_tex_plane_1"); - b.GlobalVar(syms.plane_1, b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32()), + b.GlobalVar(syms.plane_1, b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32()), b.Group(AInt(bps.plane_1.group)), b.Binding(AInt(bps.plane_1.binding))); syms.params = b.Symbols().New("ext_tex_params"); b.GlobalVar(syms.params, b.ty.type_name("ExternalTextureParams"), @@ -152,7 +153,7 @@ struct MultiplanarExternalTexture::State { const ast::Expression* cloned_initializer = ctx.Clone(global->initializer); auto* replacement = - b.Var(syms.plane_0, b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32()), + b.Var(syms.plane_0, b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32()), cloned_initializer, cloned_attributes); ctx.Replace(global, replacement); } @@ -178,7 +179,7 @@ struct MultiplanarExternalTexture::State { syms.plane_1 = b.Symbols().New("ext_tex_plane_1"); syms.params = b.Symbols().New("ext_tex_params"); auto tex2d_f32 = [&] { - return b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32()); + return b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32()); }; ctx.Replace(param, b.Param(syms.plane_0, tex2d_f32())); ctx.InsertAfter(fn->params, param, b.Param(syms.plane_1, tex2d_f32())); @@ -419,17 +420,18 @@ struct MultiplanarExternalTexture::State { texture_sample_external_sym = b.Symbols().New("textureSampleExternal"); // Emit the textureSampleExternal function. - b.Func( - texture_sample_external_sym, - utils::Vector{ - b.Param("plane0", b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32())), - b.Param("plane1", b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32())), - b.Param("smp", b.ty.sampler(ast::SamplerKind::kSampler)), - b.Param("coord", b.ty.vec2(b.ty.f32())), - b.Param("params", b.ty.type_name(params_struct_sym)), - }, - b.ty.vec4(b.ty.f32()), - buildTextureBuiltinBody(sem::BuiltinType::kTextureSampleBaseClampToEdge)); + b.Func(texture_sample_external_sym, + utils::Vector{ + b.Param("plane0", + b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32())), + b.Param("plane1", + b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32())), + b.Param("smp", b.ty.sampler(ast::SamplerKind::kSampler)), + b.Param("coord", b.ty.vec2(b.ty.f32())), + b.Param("params", b.ty.type_name(params_struct_sym)), + }, + b.ty.vec4(b.ty.f32()), + buildTextureBuiltinBody(sem::BuiltinType::kTextureSampleBaseClampToEdge)); } const ast::IdentifierExpression* exp = b.Expr(texture_sample_external_sym); @@ -467,16 +469,17 @@ struct MultiplanarExternalTexture::State { auto name = b.Symbols().New("textureLoadExternal"); // Emit the textureLoadExternal() function. - b.Func( - name, - utils::Vector{ - b.Param("plane0", b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32())), - b.Param("plane1", b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32())), - b.Param("coord", CreateASTTypeFor(ctx, coord_ty)), - b.Param("params", b.ty.type_name(params_struct_sym)), - }, - b.ty.vec4(b.ty.f32()), // - buildTextureBuiltinBody(sem::BuiltinType::kTextureLoad)); + b.Func(name, + utils::Vector{ + b.Param("plane0", + b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32())), + b.Param("plane1", + b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32())), + b.Param("coord", CreateASTTypeFor(ctx, coord_ty)), + b.Param("params", b.ty.type_name(params_struct_sym)), + }, + b.ty.vec4(b.ty.f32()), // + buildTextureBuiltinBody(sem::BuiltinType::kTextureLoad)); return name; }); diff --git a/src/tint/transform/texture_1d_to_2d.cc b/src/tint/transform/texture_1d_to_2d.cc index 85cd512aa9..4de61880c3 100644 --- a/src/tint/transform/texture_1d_to_2d.cc +++ b/src/tint/transform/texture_1d_to_2d.cc @@ -19,6 +19,7 @@ #include "src/tint/program_builder.h" #include "src/tint/sem/function.h" #include "src/tint/sem/statement.h" +#include "src/tint/type/texture_dimension.h" TINT_INSTANTIATE_TYPEINFO(tint::transform::Texture1DTo2D); @@ -36,7 +37,7 @@ bool ShouldRun(const Program* program) { auto texture = signature.Parameter(sem::ParameterUsage::kTexture); if (texture) { auto* tex = texture->Type()->As(); - if (tex->dim() == ast::TextureDimension::k1d) { + if (tex->dim() == type::TextureDimension::k1d) { return true; } } @@ -47,10 +48,10 @@ bool ShouldRun(const Program* program) { if (Switch( program->Sem().Get(var->type), [&](const type::SampledTexture* tex) { - return tex->dim() == ast::TextureDimension::k1d; + return tex->dim() == type::TextureDimension::k1d; }, [&](const type::StorageTexture* storage_tex) { - return storage_tex->dim() == ast::TextureDimension::k1d; + return storage_tex->dim() == type::TextureDimension::k1d; })) { return true; } @@ -94,18 +95,18 @@ struct Texture1DTo2D::State { const ast::Variable* r = Switch( sem.Get(v->type), [&](const type::SampledTexture* tex) -> const ast::Variable* { - if (tex->dim() == ast::TextureDimension::k1d) { + if (tex->dim() == type::TextureDimension::k1d) { auto* type = ctx.dst->create( - ast::TextureDimension::k2d, CreateASTTypeFor(ctx, tex->type())); + type::TextureDimension::k2d, CreateASTTypeFor(ctx, tex->type())); return create_var(v, type); } else { return nullptr; } }, [&](const type::StorageTexture* storage_tex) -> const ast::Variable* { - if (storage_tex->dim() == ast::TextureDimension::k1d) { + if (storage_tex->dim() == type::TextureDimension::k1d) { auto* type = ctx.dst->create( - ast::TextureDimension::k2d, storage_tex->texel_format(), + type::TextureDimension::k2d, storage_tex->texel_format(), CreateASTTypeFor(ctx, storage_tex->type()), storage_tex->access()); return create_var(v, type); } else { @@ -131,7 +132,7 @@ struct Texture1DTo2D::State { return nullptr; } auto* tex = texture->Type()->As(); - if (tex->dim() != ast::TextureDimension::k1d) { + if (tex->dim() != type::TextureDimension::k1d) { return nullptr; } diff --git a/src/tint/type/array.cc b/src/tint/type/array.cc index 6e1d297e66..dedf986aa1 100644 --- a/src/tint/type/array.cc +++ b/src/tint/type/array.cc @@ -16,10 +16,10 @@ #include -#include "src/tint/ast/variable.h" #include "src/tint/debug.h" #include "src/tint/symbol_table.h" #include "src/tint/type/manager.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/hash.h" TINT_INSTANTIATE_TYPEINFO(tint::type::Array); diff --git a/src/tint/type/depth_multisampled_texture.cc b/src/tint/type/depth_multisampled_texture.cc index 7e80eb1bd3..43d30a8d9c 100644 --- a/src/tint/type/depth_multisampled_texture.cc +++ b/src/tint/type/depth_multisampled_texture.cc @@ -15,6 +15,7 @@ #include "src/tint/type/depth_multisampled_texture.h" #include "src/tint/program_builder.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/hash.h" TINT_INSTANTIATE_TYPEINFO(tint::type::DepthMultisampledTexture); @@ -22,13 +23,13 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::DepthMultisampledTexture); namespace tint::type { namespace { -bool IsValidDepthDimension(ast::TextureDimension dim) { - return dim == ast::TextureDimension::k2d; +bool IsValidDepthDimension(TextureDimension dim) { + return dim == TextureDimension::k2d; } } // namespace -DepthMultisampledTexture::DepthMultisampledTexture(ast::TextureDimension dim) +DepthMultisampledTexture::DepthMultisampledTexture(TextureDimension dim) : Base(utils::Hash(TypeInfo::Of().full_hashcode, dim), dim) { TINT_ASSERT(Type, IsValidDepthDimension(dim)); } diff --git a/src/tint/type/depth_multisampled_texture.h b/src/tint/type/depth_multisampled_texture.h index d91b4638b3..31efaeb842 100644 --- a/src/tint/type/depth_multisampled_texture.h +++ b/src/tint/type/depth_multisampled_texture.h @@ -18,6 +18,7 @@ #include #include "src/tint/type/texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::type { @@ -26,7 +27,7 @@ class DepthMultisampledTexture final : public Castable(ast::TextureDimension::k2d); - auto* b = create(ast::TextureDimension::k2d); + auto* a = create(TextureDimension::k2d); + auto* b = create(TextureDimension::k2d); EXPECT_EQ(a, b); } TEST_F(DepthMultisampledTextureTest, Hash) { - auto* a = create(ast::TextureDimension::k2d); - auto* b = create(ast::TextureDimension::k2d); + auto* a = create(TextureDimension::k2d); + auto* b = create(TextureDimension::k2d); EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(DepthMultisampledTextureTest, Equals) { - auto* a = create(ast::TextureDimension::k2d); - auto* b = create(ast::TextureDimension::k2d); + auto* a = create(TextureDimension::k2d); + auto* b = create(TextureDimension::k2d); EXPECT_TRUE(a->Equals(*a)); EXPECT_TRUE(a->Equals(*b)); @@ -48,23 +49,23 @@ TEST_F(DepthMultisampledTextureTest, Equals) { } TEST_F(DepthMultisampledTextureTest, Dim) { - DepthMultisampledTexture d(ast::TextureDimension::k2d); - EXPECT_EQ(d.dim(), ast::TextureDimension::k2d); + DepthMultisampledTexture d(TextureDimension::k2d); + EXPECT_EQ(d.dim(), TextureDimension::k2d); } TEST_F(DepthMultisampledTextureTest, FriendlyName) { - DepthMultisampledTexture d(ast::TextureDimension::k2d); + DepthMultisampledTexture d(TextureDimension::k2d); EXPECT_EQ(d.FriendlyName(Symbols()), "texture_depth_multisampled_2d"); } TEST_F(DepthMultisampledTextureTest, Clone) { - auto* a = create(ast::TextureDimension::k2d); + auto* a = create(TextureDimension::k2d); type::Manager mgr; type::CloneContext ctx{{nullptr}, {nullptr, &mgr}}; auto* dt = a->Clone(ctx); - EXPECT_EQ(dt->dim(), ast::TextureDimension::k2d); + EXPECT_EQ(dt->dim(), TextureDimension::k2d); } } // namespace diff --git a/src/tint/type/depth_texture.cc b/src/tint/type/depth_texture.cc index 2295b39afb..214b407e3b 100644 --- a/src/tint/type/depth_texture.cc +++ b/src/tint/type/depth_texture.cc @@ -15,6 +15,7 @@ #include "src/tint/type/depth_texture.h" #include "src/tint/program_builder.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/hash.h" TINT_INSTANTIATE_TYPEINFO(tint::type::DepthTexture); @@ -22,14 +23,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::DepthTexture); namespace tint::type { namespace { -bool IsValidDepthDimension(ast::TextureDimension dim) { - return dim == ast::TextureDimension::k2d || dim == ast::TextureDimension::k2dArray || - dim == ast::TextureDimension::kCube || dim == ast::TextureDimension::kCubeArray; +bool IsValidDepthDimension(TextureDimension dim) { + return dim == TextureDimension::k2d || dim == TextureDimension::k2dArray || + dim == TextureDimension::kCube || dim == TextureDimension::kCubeArray; } } // namespace -DepthTexture::DepthTexture(ast::TextureDimension dim) +DepthTexture::DepthTexture(TextureDimension dim) : Base(utils::Hash(TypeInfo::Of().full_hashcode, dim), dim) { TINT_ASSERT(Type, IsValidDepthDimension(dim)); } diff --git a/src/tint/type/depth_texture.h b/src/tint/type/depth_texture.h index 21cd780d2d..70a0b736b1 100644 --- a/src/tint/type/depth_texture.h +++ b/src/tint/type/depth_texture.h @@ -18,6 +18,7 @@ #include #include "src/tint/type/texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::type { @@ -26,7 +27,7 @@ class DepthTexture final : public Castable { public: /// Constructor /// @param dim the dimensionality of the texture - explicit DepthTexture(ast::TextureDimension dim); + explicit DepthTexture(TextureDimension dim); /// Destructor ~DepthTexture() override; diff --git a/src/tint/type/depth_texture_test.cc b/src/tint/type/depth_texture_test.cc index 18dda3d365..4ff970a719 100644 --- a/src/tint/type/depth_texture_test.cc +++ b/src/tint/type/depth_texture_test.cc @@ -18,6 +18,7 @@ #include "src/tint/type/sampled_texture.h" #include "src/tint/type/storage_texture.h" #include "src/tint/type/test_helper.h" +#include "src/tint/type/texture_dimension.h" namespace tint::type { namespace { @@ -25,25 +26,25 @@ namespace { using DepthTextureTest = TestHelper; TEST_F(DepthTextureTest, Creation) { - auto* a = create(ast::TextureDimension::k2d); - auto* b = create(ast::TextureDimension::k2d); - auto* c = create(ast::TextureDimension::k2dArray); + auto* a = create(TextureDimension::k2d); + auto* b = create(TextureDimension::k2d); + auto* c = create(TextureDimension::k2dArray); EXPECT_EQ(a, b); EXPECT_NE(a, c); } TEST_F(DepthTextureTest, Hash) { - auto* a = create(ast::TextureDimension::k2d); - auto* b = create(ast::TextureDimension::k2d); + auto* a = create(TextureDimension::k2d); + auto* b = create(TextureDimension::k2d); EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(DepthTextureTest, Equals) { - auto* a = create(ast::TextureDimension::k2d); - auto* b = create(ast::TextureDimension::k2d); - auto* c = create(ast::TextureDimension::k2dArray); + auto* a = create(TextureDimension::k2d); + auto* b = create(TextureDimension::k2d); + auto* c = create(TextureDimension::k2dArray); EXPECT_TRUE(a->Equals(*b)); EXPECT_FALSE(a->Equals(*c)); @@ -51,7 +52,7 @@ TEST_F(DepthTextureTest, Equals) { } TEST_F(DepthTextureTest, IsTexture) { - DepthTexture d(ast::TextureDimension::kCube); + DepthTexture d(TextureDimension::kCube); Texture* ty = &d; EXPECT_TRUE(ty->Is()); EXPECT_FALSE(ty->Is()); @@ -60,23 +61,23 @@ TEST_F(DepthTextureTest, IsTexture) { } TEST_F(DepthTextureTest, Dim) { - DepthTexture d(ast::TextureDimension::kCube); - EXPECT_EQ(d.dim(), ast::TextureDimension::kCube); + DepthTexture d(TextureDimension::kCube); + EXPECT_EQ(d.dim(), TextureDimension::kCube); } TEST_F(DepthTextureTest, FriendlyName) { - DepthTexture d(ast::TextureDimension::kCube); + DepthTexture d(TextureDimension::kCube); EXPECT_EQ(d.FriendlyName(Symbols()), "texture_depth_cube"); } TEST_F(DepthTextureTest, Clone) { - auto* a = create(ast::TextureDimension::k2d); + auto* a = create(TextureDimension::k2d); type::Manager mgr; type::CloneContext ctx{{nullptr}, {nullptr, &mgr}}; auto* dt = a->Clone(ctx); - EXPECT_EQ(dt->dim(), ast::TextureDimension::k2d); + EXPECT_EQ(dt->dim(), TextureDimension::k2d); } } // namespace diff --git a/src/tint/type/external_texture.cc b/src/tint/type/external_texture.cc index 77ac5ba9bc..bfd2edc471 100644 --- a/src/tint/type/external_texture.cc +++ b/src/tint/type/external_texture.cc @@ -15,6 +15,7 @@ #include "src/tint/type/external_texture.h" #include "src/tint/program_builder.h" +#include "src/tint/type/texture_dimension.h" TINT_INSTANTIATE_TYPEINFO(tint::type::ExternalTexture); @@ -22,7 +23,7 @@ namespace tint::type { ExternalTexture::ExternalTexture() : Base(static_cast(TypeInfo::Of().full_hashcode), - ast::TextureDimension::k2d) {} + TextureDimension::k2d) {} ExternalTexture::~ExternalTexture() = default; diff --git a/src/tint/type/external_texture_test.cc b/src/tint/type/external_texture_test.cc index e9ea95dd78..0752590883 100644 --- a/src/tint/type/external_texture_test.cc +++ b/src/tint/type/external_texture_test.cc @@ -19,6 +19,7 @@ #include "src/tint/type/sampled_texture.h" #include "src/tint/type/storage_texture.h" #include "src/tint/type/test_helper.h" +#include "src/tint/type/texture_dimension.h" namespace tint::type { namespace { @@ -58,7 +59,7 @@ TEST_F(ExternalTextureTest, IsTexture) { TEST_F(ExternalTextureTest, Dim) { F32 f32; ExternalTexture s; - EXPECT_EQ(s.dim(), ast::TextureDimension::k2d); + EXPECT_EQ(s.dim(), TextureDimension::k2d); } TEST_F(ExternalTextureTest, FriendlyName) { diff --git a/src/tint/type/multisampled_texture.cc b/src/tint/type/multisampled_texture.cc index 47d3e210bd..801a891d58 100644 --- a/src/tint/type/multisampled_texture.cc +++ b/src/tint/type/multisampled_texture.cc @@ -15,13 +15,14 @@ #include "src/tint/type/multisampled_texture.h" #include "src/tint/program_builder.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/hash.h" TINT_INSTANTIATE_TYPEINFO(tint::type::MultisampledTexture); namespace tint::type { -MultisampledTexture::MultisampledTexture(ast::TextureDimension dim, const Type* type) +MultisampledTexture::MultisampledTexture(TextureDimension dim, const Type* type) : Base(utils::Hash(TypeInfo::Of().full_hashcode, dim, type), dim), type_(type) { TINT_ASSERT(Type, type_); diff --git a/src/tint/type/multisampled_texture.h b/src/tint/type/multisampled_texture.h index 3048590c3a..c5e66d73c1 100644 --- a/src/tint/type/multisampled_texture.h +++ b/src/tint/type/multisampled_texture.h @@ -18,6 +18,7 @@ #include #include "src/tint/type/texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::type { @@ -27,7 +28,7 @@ class MultisampledTexture final : public Castable /// Constructor /// @param dim the dimensionality of the texture /// @param type the data type of the multisampled texture - MultisampledTexture(ast::TextureDimension dim, const Type* type); + MultisampledTexture(TextureDimension dim, const Type* type); /// Destructor ~MultisampledTexture() override; diff --git a/src/tint/type/multisampled_texture_test.cc b/src/tint/type/multisampled_texture_test.cc index b3b671aed1..1a4c2b0aa6 100644 --- a/src/tint/type/multisampled_texture_test.cc +++ b/src/tint/type/multisampled_texture_test.cc @@ -19,6 +19,7 @@ #include "src/tint/type/sampled_texture.h" #include "src/tint/type/storage_texture.h" #include "src/tint/type/test_helper.h" +#include "src/tint/type/texture_dimension.h" namespace tint::type { namespace { @@ -26,26 +27,26 @@ namespace { using MultisampledTextureTest = TestHelper; TEST_F(MultisampledTextureTest, Creation) { - auto* a = create(ast::TextureDimension::k2d, create()); - auto* b = create(ast::TextureDimension::k2d, create()); - auto* c = create(ast::TextureDimension::k3d, create()); - auto* d = create(ast::TextureDimension::k2d, create()); + auto* a = create(TextureDimension::k2d, create()); + auto* b = create(TextureDimension::k2d, create()); + auto* c = create(TextureDimension::k3d, create()); + auto* d = create(TextureDimension::k2d, create()); EXPECT_EQ(a, b); EXPECT_NE(a, c); EXPECT_NE(a, d); } TEST_F(MultisampledTextureTest, Hash) { - auto* a = create(ast::TextureDimension::k2d, create()); - auto* b = create(ast::TextureDimension::k2d, create()); + auto* a = create(TextureDimension::k2d, create()); + auto* b = create(TextureDimension::k2d, create()); EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(MultisampledTextureTest, Equals) { - auto* a = create(ast::TextureDimension::k2d, create()); - auto* b = create(ast::TextureDimension::k2d, create()); - auto* c = create(ast::TextureDimension::k3d, create()); - auto* d = create(ast::TextureDimension::k2d, create()); + auto* a = create(TextureDimension::k2d, create()); + auto* b = create(TextureDimension::k2d, create()); + auto* c = create(TextureDimension::k3d, create()); + auto* d = create(TextureDimension::k2d, create()); EXPECT_TRUE(a->Equals(*b)); EXPECT_FALSE(a->Equals(*c)); EXPECT_FALSE(a->Equals(*d)); @@ -54,7 +55,7 @@ TEST_F(MultisampledTextureTest, Equals) { TEST_F(MultisampledTextureTest, IsTexture) { F32 f32; - MultisampledTexture s(ast::TextureDimension::kCube, &f32); + MultisampledTexture s(TextureDimension::kCube, &f32); Texture* ty = &s; EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); @@ -65,30 +66,30 @@ TEST_F(MultisampledTextureTest, IsTexture) { TEST_F(MultisampledTextureTest, Dim) { F32 f32; - MultisampledTexture s(ast::TextureDimension::k3d, &f32); - EXPECT_EQ(s.dim(), ast::TextureDimension::k3d); + MultisampledTexture s(TextureDimension::k3d, &f32); + EXPECT_EQ(s.dim(), TextureDimension::k3d); } TEST_F(MultisampledTextureTest, Type) { F32 f32; - MultisampledTexture s(ast::TextureDimension::k3d, &f32); + MultisampledTexture s(TextureDimension::k3d, &f32); EXPECT_EQ(s.type(), &f32); } TEST_F(MultisampledTextureTest, FriendlyName) { F32 f32; - MultisampledTexture s(ast::TextureDimension::k3d, &f32); + MultisampledTexture s(TextureDimension::k3d, &f32); EXPECT_EQ(s.FriendlyName(Symbols()), "texture_multisampled_3d"); } TEST_F(MultisampledTextureTest, Clone) { - auto* a = create(ast::TextureDimension::k2d, create()); + auto* a = create(TextureDimension::k2d, create()); type::Manager mgr; type::CloneContext ctx{{nullptr}, {nullptr, &mgr}}; auto* mt = a->Clone(ctx); - EXPECT_EQ(mt->dim(), ast::TextureDimension::k2d); + EXPECT_EQ(mt->dim(), TextureDimension::k2d); EXPECT_TRUE(mt->type()->Is()); } diff --git a/src/tint/type/sampled_texture.cc b/src/tint/type/sampled_texture.cc index 7651b410f6..323aaa46eb 100644 --- a/src/tint/type/sampled_texture.cc +++ b/src/tint/type/sampled_texture.cc @@ -15,13 +15,14 @@ #include "src/tint/type/sampled_texture.h" #include "src/tint/program_builder.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/hash.h" TINT_INSTANTIATE_TYPEINFO(tint::type::SampledTexture); namespace tint::type { -SampledTexture::SampledTexture(ast::TextureDimension dim, const Type* type) +SampledTexture::SampledTexture(TextureDimension dim, const Type* type) : Base(utils::Hash(TypeInfo::Of().full_hashcode, dim, type), dim), type_(type) { TINT_ASSERT(Type, type_); } diff --git a/src/tint/type/sampled_texture.h b/src/tint/type/sampled_texture.h index 1f3779084b..1a83165aca 100644 --- a/src/tint/type/sampled_texture.h +++ b/src/tint/type/sampled_texture.h @@ -18,6 +18,7 @@ #include #include "src/tint/type/texture.h" +#include "src/tint/type/texture_dimension.h" namespace tint::type { @@ -27,7 +28,7 @@ class SampledTexture final : public Castable { /// Constructor /// @param dim the dimensionality of the texture /// @param type the data type of the sampled texture - SampledTexture(ast::TextureDimension dim, const Type* type); + SampledTexture(TextureDimension dim, const Type* type); /// Destructor ~SampledTexture() override; diff --git a/src/tint/type/sampled_texture_test.cc b/src/tint/type/sampled_texture_test.cc index 78ab2d3477..23635410fb 100644 --- a/src/tint/type/sampled_texture_test.cc +++ b/src/tint/type/sampled_texture_test.cc @@ -18,6 +18,7 @@ #include "src/tint/type/external_texture.h" #include "src/tint/type/storage_texture.h" #include "src/tint/type/test_helper.h" +#include "src/tint/type/texture_dimension.h" namespace tint::type { namespace { @@ -25,13 +26,13 @@ namespace { using SampledTextureTest = TestHelper; TEST_F(SampledTextureTest, Creation) { - auto* a = create(ast::TextureDimension::kCube, create()); - auto* b = create(ast::TextureDimension::kCube, create()); - auto* c = create(ast::TextureDimension::k2d, create()); - auto* d = create(ast::TextureDimension::kCube, create()); + auto* a = create(TextureDimension::kCube, create()); + auto* b = create(TextureDimension::kCube, create()); + auto* c = create(TextureDimension::k2d, create()); + auto* d = create(TextureDimension::kCube, create()); EXPECT_TRUE(a->type()->Is()); - EXPECT_EQ(a->dim(), ast::TextureDimension::kCube); + EXPECT_EQ(a->dim(), TextureDimension::kCube); EXPECT_EQ(a, b); EXPECT_NE(a, c); @@ -39,17 +40,17 @@ TEST_F(SampledTextureTest, Creation) { } TEST_F(SampledTextureTest, Hash) { - auto* a = create(ast::TextureDimension::kCube, create()); - auto* b = create(ast::TextureDimension::kCube, create()); + auto* a = create(TextureDimension::kCube, create()); + auto* b = create(TextureDimension::kCube, create()); EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(SampledTextureTest, Equals) { - auto* a = create(ast::TextureDimension::kCube, create()); - auto* b = create(ast::TextureDimension::kCube, create()); - auto* c = create(ast::TextureDimension::k2d, create()); - auto* d = create(ast::TextureDimension::kCube, create()); + auto* a = create(TextureDimension::kCube, create()); + auto* b = create(TextureDimension::kCube, create()); + auto* c = create(TextureDimension::k2d, create()); + auto* d = create(TextureDimension::kCube, create()); EXPECT_TRUE(a->Equals(*b)); EXPECT_FALSE(a->Equals(*c)); @@ -59,7 +60,7 @@ TEST_F(SampledTextureTest, Equals) { TEST_F(SampledTextureTest, IsTexture) { F32 f32; - SampledTexture s(ast::TextureDimension::kCube, &f32); + SampledTexture s(TextureDimension::kCube, &f32); Texture* ty = &s; EXPECT_FALSE(ty->Is()); EXPECT_FALSE(ty->Is()); @@ -69,30 +70,30 @@ TEST_F(SampledTextureTest, IsTexture) { TEST_F(SampledTextureTest, Dim) { F32 f32; - SampledTexture s(ast::TextureDimension::k3d, &f32); - EXPECT_EQ(s.dim(), ast::TextureDimension::k3d); + SampledTexture s(TextureDimension::k3d, &f32); + EXPECT_EQ(s.dim(), TextureDimension::k3d); } TEST_F(SampledTextureTest, Type) { F32 f32; - SampledTexture s(ast::TextureDimension::k3d, &f32); + SampledTexture s(TextureDimension::k3d, &f32); EXPECT_EQ(s.type(), &f32); } TEST_F(SampledTextureTest, FriendlyName) { F32 f32; - SampledTexture s(ast::TextureDimension::k3d, &f32); + SampledTexture s(TextureDimension::k3d, &f32); EXPECT_EQ(s.FriendlyName(Symbols()), "texture_3d"); } TEST_F(SampledTextureTest, Clone) { - auto* a = create(ast::TextureDimension::kCube, create()); + auto* a = create(TextureDimension::kCube, create()); type::Manager mgr; type::CloneContext ctx{{nullptr}, {nullptr, &mgr}}; auto* mt = a->Clone(ctx); - EXPECT_EQ(mt->dim(), ast::TextureDimension::kCube); + EXPECT_EQ(mt->dim(), TextureDimension::kCube); EXPECT_TRUE(mt->type()->Is()); } diff --git a/src/tint/type/storage_texture.cc b/src/tint/type/storage_texture.cc index a47b094dfa..3742681fa0 100644 --- a/src/tint/type/storage_texture.cc +++ b/src/tint/type/storage_texture.cc @@ -21,7 +21,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::StorageTexture); namespace tint::type { -StorageTexture::StorageTexture(ast::TextureDimension dim, +StorageTexture::StorageTexture(TextureDimension dim, ast::TexelFormat format, ast::Access access, Type* subtype) diff --git a/src/tint/type/storage_texture.h b/src/tint/type/storage_texture.h index 276e045601..5c07bf9e4e 100644 --- a/src/tint/type/storage_texture.h +++ b/src/tint/type/storage_texture.h @@ -20,6 +20,7 @@ #include "src/tint/ast/access.h" #include "src/tint/ast/storage_texture.h" #include "src/tint/type/texture.h" +#include "src/tint/type/texture_dimension.h" // Forward declarations namespace tint::type { @@ -36,7 +37,7 @@ class StorageTexture final : public Castable { /// @param format the texel format of the texture /// @param access the access control type of the texture /// @param subtype the storage subtype. Use SubtypeFor() to calculate this. - StorageTexture(ast::TextureDimension dim, + StorageTexture(TextureDimension dim, ast::TexelFormat format, ast::Access access, Type* subtype); diff --git a/src/tint/type/storage_texture_test.cc b/src/tint/type/storage_texture_test.cc index ad8a975d8e..96d5d195d7 100644 --- a/src/tint/type/storage_texture_test.cc +++ b/src/tint/type/storage_texture_test.cc @@ -18,31 +18,30 @@ #include "src/tint/type/external_texture.h" #include "src/tint/type/sampled_texture.h" #include "src/tint/type/test_helper.h" +#include "src/tint/type/texture_dimension.h" namespace tint::type { namespace { struct StorageTextureTest : public TestHelper { - StorageTexture* Create(ast::TextureDimension dims, ast::TexelFormat fmt, ast::Access access) { + StorageTexture* Create(TextureDimension dims, ast::TexelFormat fmt, ast::Access access) { auto* subtype = StorageTexture::SubtypeFor(fmt, Types()); return create(dims, fmt, access, subtype); } }; TEST_F(StorageTextureTest, Creation) { - auto* a = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); - auto* b = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); + auto* a = + Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); + auto* b = + Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); auto* c = - Create(ast::TextureDimension::k2d, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); - auto* d = - Create(ast::TextureDimension::kCube, ast::TexelFormat::kR32Float, ast::Access::kReadWrite); - auto* e = - Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kRead); + Create(TextureDimension::k2d, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); + auto* d = Create(TextureDimension::kCube, ast::TexelFormat::kR32Float, ast::Access::kReadWrite); + auto* e = Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kRead); EXPECT_TRUE(a->type()->Is()); - EXPECT_EQ(a->dim(), ast::TextureDimension::kCube); + EXPECT_EQ(a->dim(), TextureDimension::kCube); EXPECT_EQ(a, b); EXPECT_NE(a, c); @@ -51,25 +50,23 @@ TEST_F(StorageTextureTest, Creation) { } TEST_F(StorageTextureTest, Hash) { - auto* a = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); - auto* b = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); + auto* a = + Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); + auto* b = + Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); EXPECT_EQ(a->unique_hash, b->unique_hash); } TEST_F(StorageTextureTest, Equals) { - auto* a = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); - auto* b = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); + auto* a = + Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); + auto* b = + Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); auto* c = - Create(ast::TextureDimension::k2d, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); - auto* d = - Create(ast::TextureDimension::kCube, ast::TexelFormat::kR32Float, ast::Access::kReadWrite); - auto* e = - Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kRead); + Create(TextureDimension::k2d, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); + auto* d = Create(TextureDimension::kCube, ast::TexelFormat::kR32Float, ast::Access::kReadWrite); + auto* e = Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kRead); EXPECT_TRUE(a->Equals(*b)); EXPECT_FALSE(a->Equals(*c)); @@ -79,26 +76,26 @@ TEST_F(StorageTextureTest, Equals) { } TEST_F(StorageTextureTest, Dim) { - auto* s = Create(ast::TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); - EXPECT_EQ(s->dim(), ast::TextureDimension::k2dArray); + auto* s = + Create(TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); + EXPECT_EQ(s->dim(), TextureDimension::k2dArray); } TEST_F(StorageTextureTest, Format) { - auto* s = Create(ast::TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); + auto* s = + Create(TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); EXPECT_EQ(s->texel_format(), ast::TexelFormat::kRgba32Float); } TEST_F(StorageTextureTest, FriendlyName) { - auto* s = Create(ast::TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); + auto* s = + Create(TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); EXPECT_EQ(s->FriendlyName(Symbols()), "texture_storage_2d_array"); } TEST_F(StorageTextureTest, F32) { - Type* s = Create(ast::TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); + Type* s = + Create(TextureDimension::k2dArray, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); auto program = Build(); @@ -110,7 +107,7 @@ TEST_F(StorageTextureTest, F32) { TEST_F(StorageTextureTest, U32) { auto* subtype = StorageTexture::SubtypeFor(ast::TexelFormat::kRg32Uint, Types()); - Type* s = create(ast::TextureDimension::k2dArray, ast::TexelFormat::kRg32Uint, + Type* s = create(TextureDimension::k2dArray, ast::TexelFormat::kRg32Uint, ast::Access::kReadWrite, subtype); auto program = Build(); @@ -123,7 +120,7 @@ TEST_F(StorageTextureTest, U32) { TEST_F(StorageTextureTest, I32) { auto* subtype = StorageTexture::SubtypeFor(ast::TexelFormat::kRgba32Sint, Types()); - Type* s = create(ast::TextureDimension::k2dArray, ast::TexelFormat::kRgba32Sint, + Type* s = create(TextureDimension::k2dArray, ast::TexelFormat::kRgba32Sint, ast::Access::kReadWrite, subtype); auto program = Build(); @@ -135,14 +132,14 @@ TEST_F(StorageTextureTest, I32) { } TEST_F(StorageTextureTest, Clone) { - auto* a = Create(ast::TextureDimension::kCube, ast::TexelFormat::kRgba32Float, - ast::Access::kReadWrite); + auto* a = + Create(TextureDimension::kCube, ast::TexelFormat::kRgba32Float, ast::Access::kReadWrite); type::Manager mgr; type::CloneContext ctx{{nullptr}, {nullptr, &mgr}}; auto* mt = a->Clone(ctx); - EXPECT_EQ(mt->dim(), ast::TextureDimension::kCube); + EXPECT_EQ(mt->dim(), TextureDimension::kCube); EXPECT_EQ(mt->texel_format(), ast::TexelFormat::kRgba32Float); EXPECT_TRUE(mt->type()->Is()); } diff --git a/src/tint/type/texture.cc b/src/tint/type/texture.cc index 57ce2650cf..717d63ae5d 100644 --- a/src/tint/type/texture.cc +++ b/src/tint/type/texture.cc @@ -18,7 +18,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::type::Texture); namespace tint::type { -Texture::Texture(size_t hash, ast::TextureDimension dim) : Base(hash, type::Flags{}), dim_(dim) {} +Texture::Texture(size_t hash, TextureDimension dim) : Base(hash, type::Flags{}), dim_(dim) {} Texture::~Texture() = default; diff --git a/src/tint/type/texture.h b/src/tint/type/texture.h index fc0f72da54..3205fd140d 100644 --- a/src/tint/type/texture.h +++ b/src/tint/type/texture.h @@ -16,6 +16,7 @@ #define SRC_TINT_TYPE_TEXTURE_H_ #include "src/tint/ast/texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/type/type.h" namespace tint::type { @@ -26,15 +27,15 @@ class Texture : public Castable { /// Constructor /// @param hash the unique hash of the node /// @param dim the dimensionality of the texture - Texture(size_t hash, ast::TextureDimension dim); + Texture(size_t hash, TextureDimension dim); /// Destructor ~Texture() override; /// @returns the texture dimension - ast::TextureDimension dim() const { return dim_; } + TextureDimension dim() const { return dim_; } private: - ast::TextureDimension const dim_; + TextureDimension const dim_; }; } // namespace tint::type diff --git a/src/tint/type/texture_dimension.cc b/src/tint/type/texture_dimension.cc new file mode 100644 index 0000000000..4b4fea966a --- /dev/null +++ b/src/tint/type/texture_dimension.cc @@ -0,0 +1,46 @@ +// Copyright 2023 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/tint/type/texture_dimension.h" + +namespace tint::type { + +std::ostream& operator<<(std::ostream& out, type::TextureDimension dim) { + switch (dim) { + case type::TextureDimension::kNone: + out << "None"; + break; + case type::TextureDimension::k1d: + out << "1d"; + break; + case type::TextureDimension::k2d: + out << "2d"; + break; + case type::TextureDimension::k2dArray: + out << "2d_array"; + break; + case type::TextureDimension::k3d: + out << "3d"; + break; + case type::TextureDimension::kCube: + out << "cube"; + break; + case type::TextureDimension::kCubeArray: + out << "cube_array"; + break; + } + return out; +} + +} // namespace tint::type diff --git a/src/tint/type/texture_dimension.h b/src/tint/type/texture_dimension.h new file mode 100644 index 0000000000..0da2b057a8 --- /dev/null +++ b/src/tint/type/texture_dimension.h @@ -0,0 +1,47 @@ +// Copyright 2023 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_TINT_TYPE_TEXTURE_DIMENSION_H_ +#define SRC_TINT_TYPE_TEXTURE_DIMENSION_H_ + +#include + +namespace tint::type { + +/// The dimensionality of the texture +enum class TextureDimension { + /// Invalid texture + kNone = -1, + /// 1 dimensional texture + k1d, + /// 2 dimensional texture + k2d, + /// 2 dimensional array texture + k2dArray, + /// 3 dimensional texture + k3d, + /// cube texture + kCube, + /// cube array texture + kCubeArray, +}; + +/// @param out the std::ostream to write to +/// @param dim the type::TextureDimension +/// @return the std::ostream so calls can be chained +std::ostream& operator<<(std::ostream& out, type::TextureDimension dim); + +} // namespace tint::type + +#endif // SRC_TINT_TYPE_TEXTURE_DIMENSION_H_ diff --git a/src/tint/type/texture_test.cc b/src/tint/type/texture_test.cc index ae223a121c..607fd4a18a 100644 --- a/src/tint/type/texture_test.cc +++ b/src/tint/type/texture_test.cc @@ -20,7 +20,7 @@ namespace tint::type { namespace { -using TextureTypeDimTest = TestParamHelper; +using TextureTypeDimTest = TestParamHelper; TEST_P(TextureTypeDimTest, DimMustMatch) { // Check that the dim() query returns the right dimensionality. @@ -33,12 +33,12 @@ TEST_P(TextureTypeDimTest, DimMustMatch) { INSTANTIATE_TEST_SUITE_P(Dimensions, TextureTypeDimTest, - ::testing::Values(ast::TextureDimension::k1d, - ast::TextureDimension::k2d, - ast::TextureDimension::k2dArray, - ast::TextureDimension::k3d, - ast::TextureDimension::kCube, - ast::TextureDimension::kCubeArray)); + ::testing::Values(TextureDimension::k1d, + TextureDimension::k2d, + TextureDimension::k2dArray, + TextureDimension::k3d, + TextureDimension::kCube, + TextureDimension::kCubeArray)); } // namespace } // namespace tint::type diff --git a/src/tint/writer/flatten_bindings_test.cc b/src/tint/writer/flatten_bindings_test.cc index 48d765f77c..ed929c54d5 100644 --- a/src/tint/writer/flatten_bindings_test.cc +++ b/src/tint/writer/flatten_bindings_test.cc @@ -19,6 +19,7 @@ #include "gtest/gtest.h" #include "src/tint/program_builder.h" #include "src/tint/sem/variable.h" +#include "src/tint/type/texture_dimension.h" namespace tint::writer { namespace { @@ -95,17 +96,17 @@ TEST_F(FlattenBindingsTest, NotFlat_MultipleNamespaces) { b.Binding(4_a)); const size_t num_textures = 6; - b.GlobalVar("texture1", b.ty.sampled_texture(ast::TextureDimension::k2d, b.ty.f32()), + b.GlobalVar("texture1", b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32()), b.Group(5_a), b.Binding(5_a)); - b.GlobalVar("texture2", b.ty.multisampled_texture(ast::TextureDimension::k2d, b.ty.f32()), + b.GlobalVar("texture2", b.ty.multisampled_texture(type::TextureDimension::k2d, b.ty.f32()), b.Group(6_a), b.Binding(6_a)); b.GlobalVar("texture3", - b.ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Float, + b.ty.storage_texture(type::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kWrite), b.Group(7_a), b.Binding(7_a)); - b.GlobalVar("texture4", b.ty.depth_texture(ast::TextureDimension::k2d), b.Group(8_a), + b.GlobalVar("texture4", b.ty.depth_texture(type::TextureDimension::k2d), b.Group(8_a), b.Binding(8_a)); - b.GlobalVar("texture5", b.ty.depth_multisampled_texture(ast::TextureDimension::k2d), + b.GlobalVar("texture5", b.ty.depth_multisampled_texture(type::TextureDimension::k2d), b.Group(9_a), b.Binding(9_a)); b.GlobalVar("texture6", b.ty.external_texture(), b.Group(10_a), b.Binding(10_a)); diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 720423ceda..2bd041d8f4 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -70,6 +70,7 @@ #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/defer.h" #include "src/tint/utils/map.h" #include "src/tint/utils/scoped_assignment.h" @@ -1406,8 +1407,8 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, out << ")"; // textureSize() on array samplers returns the array size in the // final component, so strip it out. - if (texture_type->dim() == ast::TextureDimension::k2dArray || - texture_type->dim() == ast::TextureDimension::kCubeArray) { + if (texture_type->dim() == type::TextureDimension::k2dArray || + texture_type->dim() == type::TextureDimension::kCubeArray) { out << ".xy"; } return true; @@ -1548,7 +1549,7 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, // GLSL requires Dref to be appended to the coordinates, *unless* it's // samplerCubeArrayShadow, in which case it will be handled as a separate // parameter. - if (texture_type->dim() == ast::TextureDimension::kCubeArray) { + if (texture_type->dim() == type::TextureDimension::kCubeArray) { append_depth_ref_to_coords = false; } @@ -2949,22 +2950,22 @@ bool GeneratorImpl::EmitType(std::ostream& out, out << (storage ? "image" : "sampler"); switch (tex->dim()) { - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: out << "1D"; break; - case ast::TextureDimension::k2d: + case type::TextureDimension::k2d: out << ((ms || depth_ms) ? "2DMS" : "2D"); break; - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: out << ((ms || depth_ms) ? "2DMSArray" : "2DArray"); break; - case ast::TextureDimension::k3d: + case type::TextureDimension::k3d: out << "3D"; break; - case ast::TextureDimension::kCube: + case type::TextureDimension::kCube: out << "Cube"; break; - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: out << "CubeArray"; break; default: diff --git a/src/tint/writer/glsl/generator_impl_type_test.cc b/src/tint/writer/glsl/generator_impl_type_test.cc index 9212dbf638..fc5b0cef57 100644 --- a/src/tint/writer/glsl/generator_impl_type_test.cc +++ b/src/tint/writer/glsl/generator_impl_type_test.cc @@ -20,6 +20,7 @@ #include "src/tint/type/sampled_texture.h" #include "src/tint/type/sampler.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/writer/glsl/test_helper.h" using ::testing::HasSubstr; @@ -299,7 +300,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitSamplerComparison) { } struct GlslDepthTextureData { - ast::TextureDimension dim; + type::TextureDimension dim; std::string result; }; inline std::ostream& operator<<(std::ostream& out, GlslDepthTextureData data) { @@ -331,14 +332,14 @@ INSTANTIATE_TEST_SUITE_P( GlslGeneratorImplTest_Type, GlslDepthTexturesTest, testing::Values( - GlslDepthTextureData{ast::TextureDimension::k2d, "sampler2DShadow tex;"}, - GlslDepthTextureData{ast::TextureDimension::k2dArray, "sampler2DArrayShadow tex;"}, - GlslDepthTextureData{ast::TextureDimension::kCube, "samplerCubeShadow tex;"}, - GlslDepthTextureData{ast::TextureDimension::kCubeArray, "samplerCubeArrayShadow tex;"})); + GlslDepthTextureData{type::TextureDimension::k2d, "sampler2DShadow tex;"}, + GlslDepthTextureData{type::TextureDimension::k2dArray, "sampler2DArrayShadow tex;"}, + GlslDepthTextureData{type::TextureDimension::kCube, "samplerCubeShadow tex;"}, + GlslDepthTextureData{type::TextureDimension::kCubeArray, "samplerCubeArrayShadow tex;"})); using GlslDepthMultisampledTexturesTest = TestHelper; TEST_F(GlslDepthMultisampledTexturesTest, Emit) { - auto* t = ty.depth_multisampled_texture(ast::TextureDimension::k2d); + auto* t = ty.depth_multisampled_texture(type::TextureDimension::k2d); GlobalVar("tex", t, Binding(1_a), Group(2_a)); @@ -358,7 +359,7 @@ TEST_F(GlslDepthMultisampledTexturesTest, Emit) { enum class TextureDataType { F32, U32, I32 }; struct GlslSampledTextureData { - ast::TextureDimension dim; + type::TextureDimension dim; TextureDataType datatype; std::string result; }; @@ -403,99 +404,99 @@ INSTANTIATE_TEST_SUITE_P(GlslGeneratorImplTest_Type, GlslSampledTexturesTest, testing::Values( GlslSampledTextureData{ - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::F32, "sampler1D tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::F32, "sampler2D tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::F32, "sampler2DArray tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::F32, "sampler3D tex;", }, GlslSampledTextureData{ - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::F32, "samplerCube tex;", }, GlslSampledTextureData{ - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::F32, "samplerCubeArray tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::U32, "usampler1D tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::U32, "usampler2D tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::U32, "usampler2DArray tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::U32, "usampler3D tex;", }, GlslSampledTextureData{ - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::U32, "usamplerCube tex;", }, GlslSampledTextureData{ - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::U32, "usamplerCubeArray tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::I32, "isampler1D tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::I32, "isampler2D tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::I32, "isampler2DArray tex;", }, GlslSampledTextureData{ - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::I32, "isampler3D tex;", }, GlslSampledTextureData{ - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::I32, "isamplerCube tex;", }, GlslSampledTextureData{ - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::I32, "isamplerCubeArray tex;", })); TEST_F(GlslGeneratorImplTest_Type, EmitMultisampledTexture) { auto* f32 = create(); - auto* s = create(ast::TextureDimension::k2d, f32); + auto* s = create(type::TextureDimension::k2d, f32); GeneratorImpl& gen = Build(); @@ -506,7 +507,7 @@ TEST_F(GlslGeneratorImplTest_Type, EmitMultisampledTexture) { } struct GlslStorageTextureData { - ast::TextureDimension dim; + type::TextureDimension dim; ast::TexelFormat imgfmt; std::string result; }; @@ -537,31 +538,31 @@ TEST_P(GlslStorageTexturesTest, Emit) { INSTANTIATE_TEST_SUITE_P( GlslGeneratorImplTest_Type, GlslStorageTexturesTest, - testing::Values(GlslStorageTextureData{ast::TextureDimension::k1d, + testing::Values(GlslStorageTextureData{type::TextureDimension::k1d, ast::TexelFormat::kRgba8Unorm, "image1D tex;"}, - GlslStorageTextureData{ast::TextureDimension::k2d, + GlslStorageTextureData{type::TextureDimension::k2d, ast::TexelFormat::kRgba16Float, "image2D tex;"}, - GlslStorageTextureData{ast::TextureDimension::k2dArray, + GlslStorageTextureData{type::TextureDimension::k2dArray, ast::TexelFormat::kR32Float, "image2DArray tex;"}, - GlslStorageTextureData{ast::TextureDimension::k3d, ast::TexelFormat::kRg32Float, - "image3D tex;"}, - GlslStorageTextureData{ast::TextureDimension::k1d, + GlslStorageTextureData{type::TextureDimension::k3d, + ast::TexelFormat::kRg32Float, "image3D tex;"}, + GlslStorageTextureData{type::TextureDimension::k1d, ast::TexelFormat::kRgba32Float, "image1D tex;"}, - GlslStorageTextureData{ast::TextureDimension::k2d, + GlslStorageTextureData{type::TextureDimension::k2d, ast::TexelFormat::kRgba16Uint, "image2D tex;"}, - GlslStorageTextureData{ast::TextureDimension::k2dArray, + GlslStorageTextureData{type::TextureDimension::k2dArray, ast::TexelFormat::kR32Uint, "image2DArray tex;"}, - GlslStorageTextureData{ast::TextureDimension::k3d, ast::TexelFormat::kRg32Uint, + GlslStorageTextureData{type::TextureDimension::k3d, ast::TexelFormat::kRg32Uint, "image3D tex;"}, - GlslStorageTextureData{ast::TextureDimension::k1d, + GlslStorageTextureData{type::TextureDimension::k1d, ast::TexelFormat::kRgba32Uint, "image1D tex;"}, - GlslStorageTextureData{ast::TextureDimension::k2d, + GlslStorageTextureData{type::TextureDimension::k2d, ast::TexelFormat::kRgba16Sint, "image2D tex;"}, - GlslStorageTextureData{ast::TextureDimension::k2dArray, + GlslStorageTextureData{type::TextureDimension::k2dArray, ast::TexelFormat::kR32Sint, "image2DArray tex;"}, - GlslStorageTextureData{ast::TextureDimension::k3d, ast::TexelFormat::kRg32Sint, + GlslStorageTextureData{type::TextureDimension::k3d, ast::TexelFormat::kRg32Sint, "image3D tex;"}, - GlslStorageTextureData{ast::TextureDimension::k1d, + GlslStorageTextureData{type::TextureDimension::k1d, ast::TexelFormat::kRgba32Sint, "image1D tex;"})); } // namespace diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc index 3bac389de7..f2b525eb09 100644 --- a/src/tint/writer/hlsl/generator_impl.cc +++ b/src/tint/writer/hlsl/generator_impl.cc @@ -69,6 +69,7 @@ #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/compiler_macros.h" #include "src/tint/utils/defer.h" #include "src/tint/utils/map.h" @@ -2312,27 +2313,27 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, switch (builtin->Type()) { case sem::BuiltinType::kTextureDimensions: switch (texture_type->dim()) { - case ast::TextureDimension::kNone: + case type::TextureDimension::kNone: TINT_ICE(Writer, diagnostics_) << "texture dimension is kNone"; return false; - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: num_dimensions = 1; break; - case ast::TextureDimension::k2d: + case type::TextureDimension::k2d: num_dimensions = is_ms ? 3 : 2; swizzle = is_ms ? ".xy" : ""; break; - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: num_dimensions = is_ms ? 4 : 3; swizzle = ".xy"; break; - case ast::TextureDimension::k3d: + case type::TextureDimension::k3d: num_dimensions = 3; break; - case ast::TextureDimension::kCube: + case type::TextureDimension::kCube: num_dimensions = 2; break; - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: num_dimensions = 3; swizzle = ".xy"; break; @@ -2343,11 +2344,11 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, default: TINT_ICE(Writer, diagnostics_) << "texture dimension is not arrayed"; return false; - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: num_dimensions = is_ms ? 4 : 3; swizzle = ".z"; break; - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: num_dimensions = 3; swizzle = ".z"; break; @@ -2359,18 +2360,18 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, TINT_ICE(Writer, diagnostics_) << "texture dimension does not support mips"; return false; - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: num_dimensions = 2; swizzle = ".y"; break; - case ast::TextureDimension::k2d: - case ast::TextureDimension::kCube: + case type::TextureDimension::k2d: + case type::TextureDimension::kCube: num_dimensions = 3; swizzle = ".z"; break; - case ast::TextureDimension::k2dArray: - case ast::TextureDimension::k3d: - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::k2dArray: + case type::TextureDimension::k3d: + case type::TextureDimension::kCubeArray: num_dimensions = 4; swizzle = ".w"; break; @@ -2382,11 +2383,11 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, TINT_ICE(Writer, diagnostics_) << "texture dimension does not support multisampling"; return false; - case ast::TextureDimension::k2d: + case type::TextureDimension::k2d: num_dimensions = 3; swizzle = ".z"; break; - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: num_dimensions = 4; swizzle = ".w"; break; @@ -4051,22 +4052,22 @@ bool GeneratorImpl::EmitType(std::ostream& out, out << "Texture"; switch (tex->dim()) { - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: out << "1D"; break; - case ast::TextureDimension::k2d: + case type::TextureDimension::k2d: out << ((ms || depth_ms) ? "2DMS" : "2D"); break; - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: out << ((ms || depth_ms) ? "2DMSArray" : "2DArray"); break; - case ast::TextureDimension::k3d: + case type::TextureDimension::k3d: out << "3D"; break; - case ast::TextureDimension::kCube: + case type::TextureDimension::kCube: out << "Cube"; break; - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: out << "CubeArray"; break; default: diff --git a/src/tint/writer/hlsl/generator_impl_type_test.cc b/src/tint/writer/hlsl/generator_impl_type_test.cc index 0b3b75edf3..715df9a9e3 100644 --- a/src/tint/writer/hlsl/generator_impl_type_test.cc +++ b/src/tint/writer/hlsl/generator_impl_type_test.cc @@ -20,6 +20,7 @@ #include "src/tint/type/sampled_texture.h" #include "src/tint/type/sampler.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/writer/hlsl/test_helper.h" using ::testing::HasSubstr; @@ -295,7 +296,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitSamplerComparison) { } struct HlslDepthTextureData { - ast::TextureDimension dim; + type::TextureDimension dim; std::string result; }; inline std::ostream& operator<<(std::ostream& out, HlslDepthTextureData data) { @@ -326,18 +327,18 @@ TEST_P(HlslDepthTexturesTest, Emit) { INSTANTIATE_TEST_SUITE_P( HlslGeneratorImplTest_Type, HlslDepthTexturesTest, - testing::Values(HlslDepthTextureData{ast::TextureDimension::k2d, + testing::Values(HlslDepthTextureData{type::TextureDimension::k2d, "Texture2D tex : register(t1, space2);"}, - HlslDepthTextureData{ast::TextureDimension::k2dArray, + HlslDepthTextureData{type::TextureDimension::k2dArray, "Texture2DArray tex : register(t1, space2);"}, - HlslDepthTextureData{ast::TextureDimension::kCube, + HlslDepthTextureData{type::TextureDimension::kCube, "TextureCube tex : register(t1, space2);"}, - HlslDepthTextureData{ast::TextureDimension::kCubeArray, + HlslDepthTextureData{type::TextureDimension::kCubeArray, "TextureCubeArray tex : register(t1, space2);"})); using HlslDepthMultisampledTexturesTest = TestHelper; TEST_F(HlslDepthMultisampledTexturesTest, Emit) { - auto* t = ty.depth_multisampled_texture(ast::TextureDimension::k2d); + auto* t = ty.depth_multisampled_texture(type::TextureDimension::k2d); GlobalVar("tex", t, Binding(1_a), Group(2_a)); @@ -357,7 +358,7 @@ TEST_F(HlslDepthMultisampledTexturesTest, Emit) { enum class TextureDataType { F32, U32, I32 }; struct HlslSampledTextureData { - ast::TextureDimension dim; + type::TextureDimension dim; TextureDataType datatype; std::string result; }; @@ -402,99 +403,99 @@ INSTANTIATE_TEST_SUITE_P(HlslGeneratorImplTest_Type, HlslSampledTexturesTest, testing::Values( HlslSampledTextureData{ - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::F32, "Texture1D tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::F32, "Texture2D tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::F32, "Texture2DArray tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::F32, "Texture3D tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::F32, "TextureCube tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::F32, "TextureCubeArray tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::U32, "Texture1D tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::U32, "Texture2D tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::U32, "Texture2DArray tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::U32, "Texture3D tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::U32, "TextureCube tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::U32, "TextureCubeArray tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k1d, + type::TextureDimension::k1d, TextureDataType::I32, "Texture1D tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k2d, + type::TextureDimension::k2d, TextureDataType::I32, "Texture2D tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k2dArray, + type::TextureDimension::k2dArray, TextureDataType::I32, "Texture2DArray tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::k3d, + type::TextureDimension::k3d, TextureDataType::I32, "Texture3D tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::kCube, + type::TextureDimension::kCube, TextureDataType::I32, "TextureCube tex : register(t1, space2);", }, HlslSampledTextureData{ - ast::TextureDimension::kCubeArray, + type::TextureDimension::kCubeArray, TextureDataType::I32, "TextureCubeArray tex : register(t1, space2);", })); TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) { auto* f32 = create(); - auto* s = create(ast::TextureDimension::k2d, f32); + auto* s = create(type::TextureDimension::k2d, f32); GeneratorImpl& gen = Build(); @@ -505,7 +506,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitMultisampledTexture) { } struct HlslStorageTextureData { - ast::TextureDimension dim; + type::TextureDimension dim; ast::TexelFormat imgfmt; std::string result; }; @@ -542,31 +543,31 @@ INSTANTIATE_TEST_SUITE_P( HlslGeneratorImplTest_Type, HlslStorageTexturesTest, testing::Values( - HlslStorageTextureData{ast::TextureDimension::k1d, ast::TexelFormat::kRgba8Unorm, + HlslStorageTextureData{type::TextureDimension::k1d, ast::TexelFormat::kRgba8Unorm, "RWTexture1D tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k2d, ast::TexelFormat::kRgba16Float, + HlslStorageTextureData{type::TextureDimension::k2d, ast::TexelFormat::kRgba16Float, "RWTexture2D tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k2dArray, ast::TexelFormat::kR32Float, + HlslStorageTextureData{type::TextureDimension::k2dArray, ast::TexelFormat::kR32Float, "RWTexture2DArray tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k3d, ast::TexelFormat::kRg32Float, + HlslStorageTextureData{type::TextureDimension::k3d, ast::TexelFormat::kRg32Float, "RWTexture3D tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k1d, ast::TexelFormat::kRgba32Float, + HlslStorageTextureData{type::TextureDimension::k1d, ast::TexelFormat::kRgba32Float, "RWTexture1D tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k2d, ast::TexelFormat::kRgba16Uint, + HlslStorageTextureData{type::TextureDimension::k2d, ast::TexelFormat::kRgba16Uint, "RWTexture2D tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k2dArray, ast::TexelFormat::kR32Uint, + HlslStorageTextureData{type::TextureDimension::k2dArray, ast::TexelFormat::kR32Uint, "RWTexture2DArray tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k3d, ast::TexelFormat::kRg32Uint, + HlslStorageTextureData{type::TextureDimension::k3d, ast::TexelFormat::kRg32Uint, "RWTexture3D tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k1d, ast::TexelFormat::kRgba32Uint, + HlslStorageTextureData{type::TextureDimension::k1d, ast::TexelFormat::kRgba32Uint, "RWTexture1D tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k2d, ast::TexelFormat::kRgba16Sint, + HlslStorageTextureData{type::TextureDimension::k2d, ast::TexelFormat::kRgba16Sint, "RWTexture2D tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k2dArray, ast::TexelFormat::kR32Sint, + HlslStorageTextureData{type::TextureDimension::k2dArray, ast::TexelFormat::kR32Sint, "RWTexture2DArray tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k3d, ast::TexelFormat::kRg32Sint, + HlslStorageTextureData{type::TextureDimension::k3d, ast::TexelFormat::kRg32Sint, "RWTexture3D tex : register(u1, space2);"}, - HlslStorageTextureData{ast::TextureDimension::k1d, ast::TexelFormat::kRgba32Sint, + HlslStorageTextureData{type::TextureDimension::k1d, ast::TexelFormat::kRgba32Sint, "RWTexture1D tex : register(u1, space2);"})); } // namespace diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc index 4889d7df91..771582a55a 100644 --- a/src/tint/writer/msl/generator_impl.cc +++ b/src/tint/writer/msl/generator_impl.cc @@ -72,6 +72,7 @@ #include "src/tint/type/reference.h" #include "src/tint/type/sampled_texture.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/type/u32.h" #include "src/tint/type/vector.h" #include "src/tint/type/void.h" @@ -1020,25 +1021,25 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, }; // MSL requires that `lod` is a constant 0 for 1D textures. - bool level_is_constant_zero = texture_type->dim() == ast::TextureDimension::k1d; + bool level_is_constant_zero = texture_type->dim() == type::TextureDimension::k1d; switch (builtin->Type()) { case sem::BuiltinType::kTextureDimensions: { std::vector dims; switch (texture_type->dim()) { - case ast::TextureDimension::kNone: + case type::TextureDimension::kNone: diagnostics_.add_error(diag::System::Writer, "texture dimension is kNone"); return false; - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: dims = {"width"}; break; - case ast::TextureDimension::k2d: - case ast::TextureDimension::k2dArray: - case ast::TextureDimension::kCube: - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: + case type::TextureDimension::kCube: + case type::TextureDimension::kCubeArray: dims = {"width", "height"}; break; - case ast::TextureDimension::k3d: + case type::TextureDimension::k3d: dims = {"width", "height", "depth"}; break; } @@ -1155,14 +1156,14 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, if (usage == Usage::kCoords && e->Type()->UnwrapRef()->is_integer_scalar_or_vector()) { casted = true; switch (texture_type->dim()) { - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: out << "uint("; break; - case ast::TextureDimension::k2d: - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: out << "uint2("; break; - case ast::TextureDimension::k3d: + case type::TextureDimension::k3d: out << "uint3("; break; default: @@ -1212,17 +1213,17 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, if (auto* ddx = arg(Usage::kDdx)) { auto dim = texture_type->dim(); switch (dim) { - case ast::TextureDimension::k2d: - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: maybe_write_comma(); out << "gradient2d("; break; - case ast::TextureDimension::k3d: + case type::TextureDimension::k3d: maybe_write_comma(); out << "gradient3d("; break; - case ast::TextureDimension::kCube: - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::kCube: + case type::TextureDimension::kCubeArray: maybe_write_comma(); out << "gradientcube("; break; @@ -1257,8 +1258,8 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out, if (!has_offset) { // offset argument may need to be provided if we have a component. switch (texture_type->dim()) { - case ast::TextureDimension::k2d: - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: out << "int2(0), "; break; default: @@ -2624,22 +2625,22 @@ bool GeneratorImpl::EmitType(std::ostream& out, } switch (tex->dim()) { - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: out << "1d"; break; - case ast::TextureDimension::k2d: + case type::TextureDimension::k2d: out << "2d"; break; - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: out << "2d_array"; break; - case ast::TextureDimension::k3d: + case type::TextureDimension::k3d: out << "3d"; break; - case ast::TextureDimension::kCube: + case type::TextureDimension::kCube: out << "cube"; break; - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: out << "cube_array"; break; default: diff --git a/src/tint/writer/msl/generator_impl_type_test.cc b/src/tint/writer/msl/generator_impl_type_test.cc index 3b63013440..ef3714828a 100644 --- a/src/tint/writer/msl/generator_impl_type_test.cc +++ b/src/tint/writer/msl/generator_impl_type_test.cc @@ -22,6 +22,7 @@ #include "src/tint/type/sampled_texture.h" #include "src/tint/type/sampler.h" #include "src/tint/type/storage_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/writer/msl/test_helper.h" using ::testing::HasSubstr; @@ -750,7 +751,7 @@ TEST_F(MslGeneratorImplTest, EmitType_SamplerComparison) { } struct MslDepthTextureData { - ast::TextureDimension dim; + type::TextureDimension dim; std::string result; }; inline std::ostream& operator<<(std::ostream& out, MslDepthTextureData data) { @@ -773,16 +774,16 @@ INSTANTIATE_TEST_SUITE_P( MslGeneratorImplTest, MslDepthTexturesTest, testing::Values( - MslDepthTextureData{ast::TextureDimension::k2d, "depth2d"}, - MslDepthTextureData{ast::TextureDimension::k2dArray, + MslDepthTextureData{type::TextureDimension::k2d, "depth2d"}, + MslDepthTextureData{type::TextureDimension::k2dArray, "depth2d_array"}, - MslDepthTextureData{ast::TextureDimension::kCube, "depthcube"}, - MslDepthTextureData{ast::TextureDimension::kCubeArray, + MslDepthTextureData{type::TextureDimension::kCube, "depthcube"}, + MslDepthTextureData{type::TextureDimension::kCubeArray, "depthcube_array"})); using MslDepthMultisampledTexturesTest = TestHelper; TEST_F(MslDepthMultisampledTexturesTest, Emit) { - type::DepthMultisampledTexture s(ast::TextureDimension::k2d); + type::DepthMultisampledTexture s(type::TextureDimension::k2d); GeneratorImpl& gen = Build(); @@ -792,7 +793,7 @@ TEST_F(MslDepthMultisampledTexturesTest, Emit) { } struct MslTextureData { - ast::TextureDimension dim; + type::TextureDimension dim; std::string result; }; inline std::ostream& operator<<(std::ostream& out, MslTextureData data) { @@ -816,17 +817,17 @@ INSTANTIATE_TEST_SUITE_P( MslGeneratorImplTest, MslSampledtexturesTest, testing::Values( - MslTextureData{ast::TextureDimension::k1d, "texture1d"}, - MslTextureData{ast::TextureDimension::k2d, "texture2d"}, - MslTextureData{ast::TextureDimension::k2dArray, "texture2d_array"}, - MslTextureData{ast::TextureDimension::k3d, "texture3d"}, - MslTextureData{ast::TextureDimension::kCube, "texturecube"}, - MslTextureData{ast::TextureDimension::kCubeArray, + MslTextureData{type::TextureDimension::k1d, "texture1d"}, + MslTextureData{type::TextureDimension::k2d, "texture2d"}, + MslTextureData{type::TextureDimension::k2dArray, "texture2d_array"}, + MslTextureData{type::TextureDimension::k3d, "texture3d"}, + MslTextureData{type::TextureDimension::kCube, "texturecube"}, + MslTextureData{type::TextureDimension::kCubeArray, "texturecube_array"})); TEST_F(MslGeneratorImplTest, Emit_TypeMultisampledTexture) { auto* u32 = create(); - auto* ms = create(ast::TextureDimension::k2d, u32); + auto* ms = create(type::TextureDimension::k2d, u32); GeneratorImpl& gen = Build(); @@ -836,7 +837,7 @@ TEST_F(MslGeneratorImplTest, Emit_TypeMultisampledTexture) { } struct MslStorageTextureData { - ast::TextureDimension dim; + type::TextureDimension dim; std::string result; }; inline std::ostream& operator<<(std::ostream& out, MslStorageTextureData data) { @@ -859,11 +860,11 @@ INSTANTIATE_TEST_SUITE_P( MslGeneratorImplTest, MslStorageTexturesTest, testing::Values( - MslStorageTextureData{ast::TextureDimension::k1d, "texture1d"}, - MslStorageTextureData{ast::TextureDimension::k2d, "texture2d"}, - MslStorageTextureData{ast::TextureDimension::k2dArray, + MslStorageTextureData{type::TextureDimension::k1d, "texture1d"}, + MslStorageTextureData{type::TextureDimension::k2d, "texture2d"}, + MslStorageTextureData{type::TextureDimension::k2dArray, "texture2d_array"}, - MslStorageTextureData{ast::TextureDimension::k3d, "texture3d"})); + MslStorageTextureData{type::TextureDimension::k3d, "texture3d"})); } // namespace } // namespace tint::writer::msl diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc index df5a2e3674..00901569db 100644 --- a/src/tint/writer/spirv/builder.cc +++ b/src/tint/writer/spirv/builder.cc @@ -44,6 +44,7 @@ #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/reference.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/type/vector.h" #include "src/tint/utils/compiler_macros.h" #include "src/tint/utils/defer.h" @@ -2785,16 +2786,16 @@ bool Builder::GenerateTextureBuiltin(const sem::Call* call, std::vector swizzle; uint32_t spirv_dims = 0; switch (texture_type->dim()) { - case ast::TextureDimension::kNone: + case type::TextureDimension::kNone: error_ = "texture dimension is kNone"; return false; - case ast::TextureDimension::k1d: - case ast::TextureDimension::k2d: - case ast::TextureDimension::k3d: - case ast::TextureDimension::kCube: + case type::TextureDimension::k1d: + case type::TextureDimension::k2d: + case type::TextureDimension::k3d: + case type::TextureDimension::kCube: break; // No swizzle needed - case ast::TextureDimension::kCubeArray: - case ast::TextureDimension::k2dArray: + case type::TextureDimension::kCubeArray: + case type::TextureDimension::k2dArray: swizzle = {0, 1}; // Strip array index spirv_dims = 3; // [width, height, array_count] break; @@ -2825,8 +2826,8 @@ bool Builder::GenerateTextureBuiltin(const sem::Call* call, default: error_ = "texture is not arrayed"; return false; - case ast::TextureDimension::k2dArray: - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::k2dArray: + case type::TextureDimension::kCubeArray: spirv_dims = 3; break; } @@ -3764,12 +3765,12 @@ bool Builder::GenerateTextureType(const type::Texture* texture, const Operand& r uint32_t array_literal = 0u; const auto dim = texture->dim(); - if (dim == ast::TextureDimension::k2dArray || dim == ast::TextureDimension::kCubeArray) { + if (dim == type::TextureDimension::k2dArray || dim == type::TextureDimension::kCubeArray) { array_literal = 1u; } uint32_t dim_literal = SpvDim2D; - if (dim == ast::TextureDimension::k1d) { + if (dim == type::TextureDimension::k1d) { dim_literal = SpvDim1D; if (texture->Is()) { push_capability(SpvCapabilitySampled1D); @@ -3777,10 +3778,10 @@ bool Builder::GenerateTextureType(const type::Texture* texture, const Operand& r push_capability(SpvCapabilityImage1D); } } - if (dim == ast::TextureDimension::k3d) { + if (dim == type::TextureDimension::k3d) { dim_literal = SpvDim3D; } - if (dim == ast::TextureDimension::kCube || dim == ast::TextureDimension::kCubeArray) { + if (dim == type::TextureDimension::kCube || dim == type::TextureDimension::kCubeArray) { dim_literal = SpvDimCube; } @@ -3800,7 +3801,7 @@ bool Builder::GenerateTextureType(const type::Texture* texture, const Operand& r sampled_literal = 1u; } - if (dim == ast::TextureDimension::kCubeArray) { + if (dim == type::TextureDimension::kCubeArray) { if (texture->IsAnyOf()) { push_capability(SpvCapabilitySampledCubeArray); } diff --git a/src/tint/writer/spirv/builder_builtin_test.cc b/src/tint/writer/spirv/builder_builtin_test.cc index 9b059805bb..3262b35fa5 100644 --- a/src/tint/writer/spirv/builder_builtin_test.cc +++ b/src/tint/writer/spirv/builder_builtin_test.cc @@ -15,6 +15,7 @@ #include "src/tint/ast/call_statement.h" #include "src/tint/ast/stage_attribute.h" #include "src/tint/type/depth_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/string.h" #include "src/tint/writer/spirv/spv_dump.h" #include "src/tint/writer/spirv/test_helper.h" @@ -41,7 +42,7 @@ inline std::ostream& operator<<(std::ostream& out, BuiltinData data) { // This tests that we do not push OpTypeSampledImage and float_0 type twice. TEST_F(BuiltinBuilderTest, Call_TextureSampleCompare_Twice) { auto* s = ty.sampler(ast::SamplerKind::kComparisonSampler); - auto* t = ty.depth_texture(ast::TextureDimension::k2d); + auto* t = ty.depth_texture(type::TextureDimension::k2d); auto* tex = GlobalVar("texture", t, Binding(0_a), Group(0_a)); auto* sampler = GlobalVar("sampler", s, Binding(1_a), Group(0_a)); diff --git a/src/tint/writer/spirv/builder_global_variable_test.cc b/src/tint/writer/spirv/builder_global_variable_test.cc index 7d3ec59c12..9732abb2d2 100644 --- a/src/tint/writer/spirv/builder_global_variable_test.cc +++ b/src/tint/writer/spirv/builder_global_variable_test.cc @@ -14,6 +14,7 @@ #include "src/tint/ast/id_attribute.h" #include "src/tint/ast/stage_attribute.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/writer/spirv/spv_dump.h" #include "src/tint/writer/spirv/test_helper.h" @@ -469,7 +470,7 @@ OpName %9 "unused_entry_point" TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) { // var a : texture_storage_2d; - auto* type = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, + auto* type = ty.storage_texture(type::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kWrite); auto* var_a = GlobalVar("a", type, Binding(0_a), Group(0_a)); diff --git a/src/tint/writer/spirv/builder_type_test.cc b/src/tint/writer/spirv/builder_type_test.cc index d698593840..e7cdd74beb 100644 --- a/src/tint/writer/spirv/builder_type_test.cc +++ b/src/tint/writer/spirv/builder_type_test.cc @@ -15,6 +15,7 @@ #include "src/tint/type/depth_texture.h" #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/writer/spirv/spv_dump.h" #include "src/tint/writer/spirv/test_helper.h" @@ -631,7 +632,7 @@ INSTANTIATE_TEST_SUITE_P( PtrData{ast::AddressSpace::kFunction, SpvStorageClassFunction})); TEST_F(BuilderTest_Type, DepthTexture_Generate_2d) { - auto* two_d = create(ast::TextureDimension::k2d); + auto* two_d = create(type::TextureDimension::k2d); spirv::Builder& b = Build(); @@ -645,7 +646,7 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_2d) { } TEST_F(BuilderTest_Type, DepthTexture_Generate_2dArray) { - auto* two_d_array = create(ast::TextureDimension::k2dArray); + auto* two_d_array = create(type::TextureDimension::k2dArray); spirv::Builder& b = Build(); @@ -659,7 +660,7 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_2dArray) { } TEST_F(BuilderTest_Type, DepthTexture_Generate_Cube) { - auto* cube = create(ast::TextureDimension::kCube); + auto* cube = create(type::TextureDimension::kCube); spirv::Builder& b = Build(); @@ -674,7 +675,7 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_Cube) { } TEST_F(BuilderTest_Type, DepthTexture_Generate_CubeArray) { - auto* cube_array = create(ast::TextureDimension::kCubeArray); + auto* cube_array = create(type::TextureDimension::kCubeArray); spirv::Builder& b = Build(); @@ -692,7 +693,7 @@ TEST_F(BuilderTest_Type, DepthTexture_Generate_CubeArray) { TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_i32) { auto* i32 = create(); - auto* ms = create(ast::TextureDimension::k2d, i32); + auto* ms = create(type::TextureDimension::k2d, i32); spirv::Builder& b = Build(); @@ -705,7 +706,7 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_i32) { TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_u32) { auto* u32 = create(); - auto* ms = create(ast::TextureDimension::k2d, u32); + auto* ms = create(type::TextureDimension::k2d, u32); spirv::Builder& b = Build(); @@ -719,7 +720,7 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_u32) { TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_f32) { auto* f32 = create(); - auto* ms = create(ast::TextureDimension::k2d, f32); + auto* ms = create(type::TextureDimension::k2d, f32); spirv::Builder& b = Build(); @@ -732,7 +733,7 @@ TEST_F(BuilderTest_Type, MultisampledTexture_Generate_2d_f32) { } TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_i32) { - auto* s = create(ast::TextureDimension::k1d, create()); + auto* s = create(type::TextureDimension::k1d, create()); spirv::Builder& b = Build(); @@ -750,7 +751,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_i32) { TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_u32) { auto* u32 = create(); - auto* s = create(ast::TextureDimension::k1d, u32); + auto* s = create(type::TextureDimension::k1d, u32); spirv::Builder& b = Build(); @@ -768,7 +769,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_u32) { TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_f32) { auto* f32 = create(); - auto* s = create(ast::TextureDimension::k1d, f32); + auto* s = create(type::TextureDimension::k1d, f32); spirv::Builder& b = Build(); @@ -786,7 +787,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_f32) { TEST_F(BuilderTest_Type, SampledTexture_Generate_2d) { auto* f32 = create(); - auto* s = create(ast::TextureDimension::k2d, f32); + auto* s = create(type::TextureDimension::k2d, f32); spirv::Builder& b = Build(); @@ -800,7 +801,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_2d) { TEST_F(BuilderTest_Type, SampledTexture_Generate_2d_array) { auto* f32 = create(); - auto* s = create(ast::TextureDimension::k2dArray, f32); + auto* s = create(type::TextureDimension::k2dArray, f32); spirv::Builder& b = Build(); @@ -814,7 +815,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_2d_array) { TEST_F(BuilderTest_Type, SampledTexture_Generate_3d) { auto* f32 = create(); - auto* s = create(ast::TextureDimension::k3d, f32); + auto* s = create(type::TextureDimension::k3d, f32); spirv::Builder& b = Build(); @@ -828,7 +829,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_3d) { TEST_F(BuilderTest_Type, SampledTexture_Generate_Cube) { auto* f32 = create(); - auto* s = create(ast::TextureDimension::kCube, f32); + auto* s = create(type::TextureDimension::kCube, f32); spirv::Builder& b = Build(); @@ -843,7 +844,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_Cube) { TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) { auto* f32 = create(); - auto* s = create(ast::TextureDimension::kCubeArray, f32); + auto* s = create(type::TextureDimension::kCubeArray, f32); spirv::Builder& b = Build(); @@ -859,7 +860,7 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) { - auto* s = ty.storage_texture(ast::TextureDimension::k1d, ast::TexelFormat::kR32Float, + auto* s = ty.storage_texture(type::TextureDimension::k1d, ast::TexelFormat::kR32Float, ast::Access::kWrite); GlobalVar("test_var", s, Binding(0_a), Group(0_a)); @@ -874,7 +875,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { - auto* s = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Float, + auto* s = ty.storage_texture(type::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kWrite); GlobalVar("test_var", s, Binding(0_a), Group(0_a)); @@ -889,7 +890,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { - auto* s = ty.storage_texture(ast::TextureDimension::k2dArray, ast::TexelFormat::kR32Float, + auto* s = ty.storage_texture(type::TextureDimension::k2dArray, ast::TexelFormat::kR32Float, ast::Access::kWrite); GlobalVar("test_var", s, Binding(0_a), Group(0_a)); @@ -904,7 +905,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { - auto* s = ty.storage_texture(ast::TextureDimension::k3d, ast::TexelFormat::kR32Float, + auto* s = ty.storage_texture(type::TextureDimension::k3d, ast::TexelFormat::kR32Float, ast::Access::kWrite); GlobalVar("test_var", s, Binding(0_a), Group(0_a)); @@ -919,7 +920,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeFloat_Format_r32float) { - auto* s = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Float, + auto* s = ty.storage_texture(type::TextureDimension::k2d, ast::TexelFormat::kR32Float, ast::Access::kWrite); GlobalVar("test_var", s, Binding(0_a), Group(0_a)); @@ -934,7 +935,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeFloat_Format_r32floa } TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeSint_Format_r32sint) { - auto* s = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Sint, + auto* s = ty.storage_texture(type::TextureDimension::k2d, ast::TexelFormat::kR32Sint, ast::Access::kWrite); GlobalVar("test_var", s, Binding(0_a), Group(0_a)); @@ -949,7 +950,7 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeSint_Format_r32sint) } TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeUint_Format_r32uint) { - auto* s = ty.storage_texture(ast::TextureDimension::k2d, ast::TexelFormat::kR32Uint, + auto* s = ty.storage_texture(type::TextureDimension::k2d, ast::TexelFormat::kR32Uint, ast::Access::kWrite); GlobalVar("test_var", s, Binding(0_a), Group(0_a)); diff --git a/src/tint/writer/wgsl/generator_impl.cc b/src/tint/writer/wgsl/generator_impl.cc index f02d96c2c9..a5156311fd 100644 --- a/src/tint/writer/wgsl/generator_impl.cc +++ b/src/tint/writer/wgsl/generator_impl.cc @@ -51,6 +51,7 @@ #include "src/tint/ast/workgroup_attribute.h" #include "src/tint/sem/struct.h" #include "src/tint/sem/switch_statement.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/utils/math.h" #include "src/tint/utils/scoped_assignment.h" #include "src/tint/writer/float_to_string.h" @@ -500,22 +501,22 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { } switch (texture->dim) { - case ast::TextureDimension::k1d: + case type::TextureDimension::k1d: out << "1d"; break; - case ast::TextureDimension::k2d: + case type::TextureDimension::k2d: out << "2d"; break; - case ast::TextureDimension::k2dArray: + case type::TextureDimension::k2dArray: out << "2d_array"; break; - case ast::TextureDimension::k3d: + case type::TextureDimension::k3d: out << "3d"; break; - case ast::TextureDimension::kCube: + case type::TextureDimension::kCube: out << "cube"; break; - case ast::TextureDimension::kCubeArray: + case type::TextureDimension::kCubeArray: out << "cube_array"; break; default: diff --git a/src/tint/writer/wgsl/generator_impl_global_decl_test.cc b/src/tint/writer/wgsl/generator_impl_global_decl_test.cc index 939b5b3919..cc331f01ac 100644 --- a/src/tint/writer/wgsl/generator_impl_global_decl_test.cc +++ b/src/tint/writer/wgsl/generator_impl_global_decl_test.cc @@ -15,6 +15,7 @@ #include "src/tint/ast/stage_attribute.h" #include "src/tint/ast/variable_decl_statement.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/writer/wgsl/test_helper.h" using namespace tint::number_suffixes; // NOLINT @@ -116,7 +117,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Global_Sampler) { } TEST_F(WgslGeneratorImplTest, Emit_Global_Texture) { - auto* st = ty.sampled_texture(ast::TextureDimension::k1d, ty.f32()); + auto* st = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); GlobalVar("t", st, Group(0_a), Binding(0_a)); GeneratorImpl& gen = Build(); diff --git a/src/tint/writer/wgsl/generator_impl_type_test.cc b/src/tint/writer/wgsl/generator_impl_type_test.cc index a1c350536d..0f0ab27cea 100644 --- a/src/tint/writer/wgsl/generator_impl_type_test.cc +++ b/src/tint/writer/wgsl/generator_impl_type_test.cc @@ -15,6 +15,7 @@ #include "src/tint/type/depth_texture.h" #include "src/tint/type/multisampled_texture.h" #include "src/tint/type/sampled_texture.h" +#include "src/tint/type/texture_dimension.h" #include "src/tint/writer/wgsl/test_helper.h" using namespace tint::number_suffixes; // NOLINT @@ -329,7 +330,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Vector_F16) { } struct TextureData { - ast::TextureDimension dim; + type::TextureDimension dim; const char* name; }; inline std::ostream& operator<<(std::ostream& out, TextureData data) { @@ -353,10 +354,10 @@ TEST_P(WgslGenerator_DepthTextureTest, EmitType_DepthTexture) { INSTANTIATE_TEST_SUITE_P( WgslGeneratorImplTest, WgslGenerator_DepthTextureTest, - testing::Values(TextureData{ast::TextureDimension::k2d, "texture_depth_2d"}, - TextureData{ast::TextureDimension::k2dArray, "texture_depth_2d_array"}, - TextureData{ast::TextureDimension::kCube, "texture_depth_cube"}, - TextureData{ast::TextureDimension::kCubeArray, "texture_depth_cube_array"})); + testing::Values(TextureData{type::TextureDimension::k2d, "texture_depth_2d"}, + TextureData{type::TextureDimension::k2dArray, "texture_depth_2d_array"}, + TextureData{type::TextureDimension::kCube, "texture_depth_cube"}, + TextureData{type::TextureDimension::kCubeArray, "texture_depth_cube_array"})); using WgslGenerator_SampledTextureTest = TestParamHelper; TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_F32) { @@ -400,12 +401,12 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_U32) { INSTANTIATE_TEST_SUITE_P( WgslGeneratorImplTest, WgslGenerator_SampledTextureTest, - testing::Values(TextureData{ast::TextureDimension::k1d, "texture_1d"}, - TextureData{ast::TextureDimension::k2d, "texture_2d"}, - TextureData{ast::TextureDimension::k2dArray, "texture_2d_array"}, - TextureData{ast::TextureDimension::k3d, "texture_3d"}, - TextureData{ast::TextureDimension::kCube, "texture_cube"}, - TextureData{ast::TextureDimension::kCubeArray, "texture_cube_array"})); + testing::Values(TextureData{type::TextureDimension::k1d, "texture_1d"}, + TextureData{type::TextureDimension::k2d, "texture_2d"}, + TextureData{type::TextureDimension::k2dArray, "texture_2d_array"}, + TextureData{type::TextureDimension::k3d, "texture_3d"}, + TextureData{type::TextureDimension::kCube, "texture_cube"}, + TextureData{type::TextureDimension::kCubeArray, "texture_cube_array"})); using WgslGenerator_MultiampledTextureTest = TestParamHelper; TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_F32) { @@ -448,12 +449,12 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_U32) { } INSTANTIATE_TEST_SUITE_P(WgslGeneratorImplTest, WgslGenerator_MultiampledTextureTest, - testing::Values(TextureData{ast::TextureDimension::k2d, + testing::Values(TextureData{type::TextureDimension::k2d, "texture_multisampled_2d"})); struct StorageTextureData { ast::TexelFormat fmt; - ast::TextureDimension dim; + type::TextureDimension dim; ast::Access access; const char* name; }; @@ -477,14 +478,14 @@ TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) { INSTANTIATE_TEST_SUITE_P( WgslGeneratorImplTest, WgslGenerator_StorageTextureTest, - testing::Values(StorageTextureData{ast::TexelFormat::kRgba8Sint, ast::TextureDimension::k1d, + testing::Values(StorageTextureData{ast::TexelFormat::kRgba8Sint, type::TextureDimension::k1d, ast::Access::kWrite, "texture_storage_1d"}, - StorageTextureData{ast::TexelFormat::kRgba8Sint, ast::TextureDimension::k2d, + StorageTextureData{ast::TexelFormat::kRgba8Sint, type::TextureDimension::k2d, ast::Access::kWrite, "texture_storage_2d"}, StorageTextureData{ast::TexelFormat::kRgba8Sint, - ast::TextureDimension::k2dArray, ast::Access::kWrite, + type::TextureDimension::k2dArray, ast::Access::kWrite, "texture_storage_2d_array"}, - StorageTextureData{ast::TexelFormat::kRgba8Sint, ast::TextureDimension::k3d, + StorageTextureData{ast::TexelFormat::kRgba8Sint, type::TextureDimension::k3d, ast::Access::kWrite, "texture_storage_3d"}));