mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-14 23:56:16 +00:00
validation: Allow interpolate(flat) on integral IO
Produce a warning if the attribute is missing for integral vertex outputs or fragment inputs. This will become an error in the future, as per the WGSL spec. Add the attribute to E2E tests. Bug: tint:1224 Change-Id: Ia1f353f36cb7db516cf9e8b4877423dec3b3e711 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/67160 Auto-Submit: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Commit-Queue: James Price <jrprice@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
committed by
Tint LUCI CQ
parent
1aa98e62c0
commit
a41694e9a3
@@ -1286,6 +1286,58 @@ TEST_P(InterpolateParameterTest, All) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(InterpolateParameterTest, IntegerScalar) {
|
||||
auto& params = GetParam();
|
||||
|
||||
Func("main",
|
||||
ast::VariableList{Param(
|
||||
"a", ty.i32(),
|
||||
{Location(0),
|
||||
Interpolate(Source{{12, 34}}, params.type, params.sampling)})},
|
||||
ty.void_(), {},
|
||||
ast::DecorationList{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
if (params.type != ast::InterpolationType::kFlat) {
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 error: interpolation type must be 'flat' for integral "
|
||||
"user-defined IO types");
|
||||
} else if (params.should_pass) {
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
} else {
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 error: flat interpolation attribute must not have a "
|
||||
"sampling parameter");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_P(InterpolateParameterTest, IntegerVector) {
|
||||
auto& params = GetParam();
|
||||
|
||||
Func("main",
|
||||
ast::VariableList{Param(
|
||||
"a", ty.vec4<u32>(),
|
||||
{Location(0),
|
||||
Interpolate(Source{{12, 34}}, params.type, params.sampling)})},
|
||||
ty.void_(), {},
|
||||
ast::DecorationList{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
if (params.type != ast::InterpolationType::kFlat) {
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 error: interpolation type must be 'flat' for integral "
|
||||
"user-defined IO types");
|
||||
} else if (params.should_pass) {
|
||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
||||
} else {
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 error: flat interpolation attribute must not have a "
|
||||
"sampling parameter");
|
||||
}
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(
|
||||
ResolverDecorationValidationTest,
|
||||
InterpolateParameterTest,
|
||||
@@ -1315,33 +1367,35 @@ INSTANTIATE_TEST_SUITE_P(
|
||||
Params{ast::InterpolationType::kFlat,
|
||||
ast::InterpolationSampling::kSample, false}));
|
||||
|
||||
TEST_F(InterpolateTest, Parameter_NotFloatingPoint) {
|
||||
TEST_F(InterpolateTest, FragmentInput_Integer_MissingFlatInterpolation) {
|
||||
Func("main",
|
||||
ast::VariableList{
|
||||
Param("a", ty.i32(),
|
||||
{Location(0),
|
||||
Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
|
||||
ast::InterpolationSampling::kNone)})},
|
||||
ast::VariableList{Param(Source{{12, 34}}, "a", ty.i32(), {Location(0)})},
|
||||
ty.void_(), {},
|
||||
ast::DecorationList{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
// TODO(crbug.com/tint/1224): Make this an error.
|
||||
EXPECT_TRUE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 error: store type of interpolate attribute must be floating "
|
||||
"point scalar or vector");
|
||||
"12:34 warning: integral user-defined fragment inputs must have a "
|
||||
"flat interpolation attribute");
|
||||
}
|
||||
|
||||
TEST_F(InterpolateTest, ReturnType_NotFloatingPoint) {
|
||||
Func(
|
||||
"main", {}, ty.i32(), {Return(1)},
|
||||
ast::DecorationList{Stage(ast::PipelineStage::kFragment)},
|
||||
{Location(0), Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
|
||||
ast::InterpolationSampling::kNone)});
|
||||
TEST_F(InterpolateTest, VertexOutput_Integer_MissingFlatInterpolation) {
|
||||
auto* s = Structure(
|
||||
"S",
|
||||
{
|
||||
Member("pos", ty.vec4<f32>(), {Builtin(ast::Builtin::kPosition)}),
|
||||
Member(Source{{12, 34}}, "u", ty.u32(), {Location(0)}),
|
||||
},
|
||||
{});
|
||||
Func("main", {}, ty.Of(s), {Return(Construct(ty.Of(s)))},
|
||||
ast::DecorationList{Stage(ast::PipelineStage::kVertex)});
|
||||
|
||||
EXPECT_FALSE(r()->Resolve());
|
||||
// TODO(crbug.com/tint/1224): Make this an error.
|
||||
EXPECT_TRUE(r()->Resolve());
|
||||
EXPECT_EQ(r()->error(),
|
||||
"12:34 error: store type of interpolate attribute must be floating "
|
||||
"point scalar or vector");
|
||||
"12:34 warning: integral user-defined vertex outputs must have a "
|
||||
"flat interpolation attribute");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -764,8 +764,8 @@ TEST_F(LocationDecorationTests, Duplicate_input) {
|
||||
// [[stage(fragment)]]
|
||||
// fn main([[location(1)]] param_a : f32,
|
||||
// [[location(1)]] param_b : f32) {}
|
||||
auto* param_a = Param("param_a", ty.u32(), {Location(1)});
|
||||
auto* param_b = Param("param_b", ty.u32(), {Location(Source{{12, 34}}, 1)});
|
||||
auto* param_a = Param("param_a", ty.f32(), {Location(1)});
|
||||
auto* param_b = Param("param_b", ty.f32(), {Location(Source{{12, 34}}, 1)});
|
||||
Func(Source{{12, 34}}, "main", {param_a, param_b}, ty.void_(), {},
|
||||
{Stage(ast::PipelineStage::kFragment)});
|
||||
|
||||
|
||||
@@ -1389,10 +1389,10 @@ bool Resolver::ValidateInterpolateDecoration(
|
||||
const sem::Type* storage_type) {
|
||||
auto* type = storage_type->UnwrapRef();
|
||||
|
||||
if (!type->is_float_scalar_or_vector()) {
|
||||
if (type->is_integer_scalar_or_vector() &&
|
||||
deco->type != ast::InterpolationType::kFlat) {
|
||||
AddError(
|
||||
"store type of interpolate attribute must be floating point scalar or "
|
||||
"vector",
|
||||
"interpolation type must be 'flat' for integral user-defined IO types",
|
||||
deco->source);
|
||||
return false;
|
||||
}
|
||||
@@ -1519,6 +1519,7 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func,
|
||||
// Scan decorations for pipeline IO attributes.
|
||||
// Check for overlap with attributes that have been seen previously.
|
||||
const ast::Decoration* pipeline_io_attribute = nullptr;
|
||||
const ast::InterpolateDecoration* interpolate_attribute = nullptr;
|
||||
const ast::InvariantDecoration* invariant_attribute = nullptr;
|
||||
for (auto* deco : decos) {
|
||||
auto is_invalid_compute_shader_decoration = false;
|
||||
@@ -1566,6 +1567,7 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func,
|
||||
} else if (!ValidateInterpolateDecoration(interpolate, ty)) {
|
||||
return false;
|
||||
}
|
||||
interpolate_attribute = interpolate;
|
||||
} else if (auto* invariant = deco->As<ast::InvariantDecoration>()) {
|
||||
if (func->PipelineStage() == ast::PipelineStage::kCompute) {
|
||||
is_invalid_compute_shader_decoration = true;
|
||||
@@ -1600,6 +1602,28 @@ bool Resolver::ValidateEntryPoint(const ast::Function* func,
|
||||
return false;
|
||||
}
|
||||
|
||||
if (pipeline_io_attribute &&
|
||||
pipeline_io_attribute->Is<ast::LocationDecoration>()) {
|
||||
if (ty->is_integer_scalar_or_vector() && !interpolate_attribute) {
|
||||
// TODO(crbug.com/tint/1224): Make these errors once downstream
|
||||
// usages have caught up (no sooner than M99).
|
||||
if (func->PipelineStage() == ast::PipelineStage::kVertex &&
|
||||
param_or_ret == ParamOrRetType::kReturnType) {
|
||||
AddWarning(
|
||||
"integral user-defined vertex outputs must have a flat "
|
||||
"interpolation attribute",
|
||||
source);
|
||||
}
|
||||
if (func->PipelineStage() == ast::PipelineStage::kFragment &&
|
||||
param_or_ret == ParamOrRetType::kParameter) {
|
||||
AddWarning(
|
||||
"integral user-defined fragment inputs must have a flat "
|
||||
"interpolation attribute",
|
||||
source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (invariant_attribute) {
|
||||
bool has_position = false;
|
||||
if (pipeline_io_attribute) {
|
||||
|
||||
Reference in New Issue
Block a user