tint: Validate that sampled texture type must be f32, i32, or u32
Bug: chromium:1322954 Change-Id: Ibc1eab3de8fad78a08c8588492c1bdb04bfe256e Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90720 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
parent
ba2b7fc9b1
commit
5ff7d67bf3
|
@ -737,19 +737,29 @@ INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, CanonicalTest, testing::Val
|
||||||
|
|
||||||
} // namespace GetCanonicalTests
|
} // namespace GetCanonicalTests
|
||||||
|
|
||||||
namespace MultisampledTextureTests {
|
namespace SampledTextureTests {
|
||||||
struct DimensionParams {
|
struct DimensionParams {
|
||||||
ast::TextureDimension dim;
|
ast::TextureDimension dim;
|
||||||
bool is_valid;
|
bool is_valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr DimensionParams dimension_cases[] = {
|
using SampledTextureDimensionTest = ResolverTestWithParam<DimensionParams>;
|
||||||
DimensionParams{ast::TextureDimension::k1d, false},
|
TEST_P(SampledTextureDimensionTest, All) {
|
||||||
|
auto& params = GetParam();
|
||||||
|
Global(Source{{12, 34}}, "a", ty.sampled_texture(params.dim, ty.i32()),
|
||||||
|
ast::StorageClass::kNone, nullptr, ast::AttributeList{GroupAndBinding(0, 0)});
|
||||||
|
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
}
|
||||||
|
INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest,
|
||||||
|
SampledTextureDimensionTest,
|
||||||
|
testing::Values( //
|
||||||
|
DimensionParams{ast::TextureDimension::k1d, true},
|
||||||
DimensionParams{ast::TextureDimension::k2d, true},
|
DimensionParams{ast::TextureDimension::k2d, true},
|
||||||
DimensionParams{ast::TextureDimension::k2dArray, false},
|
DimensionParams{ast::TextureDimension::k2dArray, true},
|
||||||
DimensionParams{ast::TextureDimension::k3d, false},
|
DimensionParams{ast::TextureDimension::k3d, true},
|
||||||
DimensionParams{ast::TextureDimension::kCube, false},
|
DimensionParams{ast::TextureDimension::kCube, true},
|
||||||
DimensionParams{ast::TextureDimension::kCubeArray, false}};
|
DimensionParams{ast::TextureDimension::kCubeArray, true}));
|
||||||
|
|
||||||
using MultisampledTextureDimensionTest = ResolverTestWithParam<DimensionParams>;
|
using MultisampledTextureDimensionTest = ResolverTestWithParam<DimensionParams>;
|
||||||
TEST_P(MultisampledTextureDimensionTest, All) {
|
TEST_P(MultisampledTextureDimensionTest, All) {
|
||||||
|
@ -766,7 +776,13 @@ TEST_P(MultisampledTextureDimensionTest, All) {
|
||||||
}
|
}
|
||||||
INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest,
|
INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest,
|
||||||
MultisampledTextureDimensionTest,
|
MultisampledTextureDimensionTest,
|
||||||
testing::ValuesIn(dimension_cases));
|
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}));
|
||||||
|
|
||||||
struct TypeParams {
|
struct TypeParams {
|
||||||
builder::ast_type_func_ptr type_func;
|
builder::ast_type_func_ptr type_func;
|
||||||
|
@ -796,6 +812,26 @@ static constexpr TypeParams type_cases[] = {
|
||||||
TypeParamsFor<alias<mat3x3<f32>>>(false),
|
TypeParamsFor<alias<mat3x3<f32>>>(false),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using SampledTextureTypeTest = ResolverTestWithParam<TypeParams>;
|
||||||
|
TEST_P(SampledTextureTypeTest, All) {
|
||||||
|
auto& params = GetParam();
|
||||||
|
Global(Source{{12, 34}}, "a",
|
||||||
|
ty.sampled_texture(ast::TextureDimension::k2d, params.type_func(*this)),
|
||||||
|
ast::StorageClass::kNone, nullptr, ast::AttributeList{GroupAndBinding(0, 0)});
|
||||||
|
|
||||||
|
if (params.is_valid) {
|
||||||
|
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||||
|
} else {
|
||||||
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
EXPECT_EQ(r()->error(),
|
||||||
|
"12:34 error: texture_2d<type>: type must be f32, "
|
||||||
|
"i32 or u32");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest,
|
||||||
|
SampledTextureTypeTest,
|
||||||
|
testing::ValuesIn(type_cases));
|
||||||
|
|
||||||
using MultisampledTextureTypeTest = ResolverTestWithParam<TypeParams>;
|
using MultisampledTextureTypeTest = ResolverTestWithParam<TypeParams>;
|
||||||
TEST_P(MultisampledTextureTypeTest, All) {
|
TEST_P(MultisampledTextureTypeTest, All) {
|
||||||
auto& params = GetParam();
|
auto& params = GetParam();
|
||||||
|
@ -816,7 +852,7 @@ INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest,
|
||||||
MultisampledTextureTypeTest,
|
MultisampledTextureTypeTest,
|
||||||
testing::ValuesIn(type_cases));
|
testing::ValuesIn(type_cases));
|
||||||
|
|
||||||
} // namespace MultisampledTextureTests
|
} // namespace SampledTextureTests
|
||||||
|
|
||||||
namespace StorageTextureTests {
|
namespace StorageTextureTests {
|
||||||
struct DimensionParams {
|
struct DimensionParams {
|
||||||
|
|
|
@ -652,6 +652,13 @@ bool Validator::Variable(const sem::Variable* var) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auto* r = storage_ty->As<sem::SampledTexture>()) {
|
||||||
|
if (!r->type()->UnwrapRef()->is_numeric_scalar()) {
|
||||||
|
AddError("texture_2d<type>: type must be f32, i32 or u32", decl->source);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (auto* r = storage_ty->As<sem::MultisampledTexture>()) {
|
if (auto* r = storage_ty->As<sem::MultisampledTexture>()) {
|
||||||
if (r->dim() != ast::TextureDimension::k2d) {
|
if (r->dim() != ast::TextureDimension::k2d) {
|
||||||
AddError("only 2d multisampled textures are supported", decl->source);
|
AddError("only 2d multisampled textures are supported", decl->source);
|
||||||
|
|
Loading…
Reference in New Issue