Move InterpolationSampling and InterpolationType to builtin.

This CL moves the ast::InterpolateSampling and ast::InterpolationType to
builtin::

Change-Id: Iad9365ff629cbb7b3b03de6a4cd9355a21ce287e
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/120442
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair 2023-02-20 08:37:45 +00:00 committed by Dawn LUCI CQ
parent e4f947637a
commit 993a658af2
41 changed files with 806 additions and 557 deletions

View File

@ -708,6 +708,10 @@ libtint_source_set("libtint_builtins_src") {
"builtin/diagnostic_severity.h",
"builtin/extension.cc",
"builtin/extension.h",
"builtin/interpolation_sampling.cc",
"builtin/interpolation_sampling.h",
"builtin/interpolation_type.cc",
"builtin/interpolation_type.h",
"builtin/texel_format.cc",
"builtin/texel_format.h",
]
@ -1306,6 +1310,8 @@ if (tint_build_unittests) {
"builtin/diagnostic_rule_test.cc",
"builtin/diagnostic_severity_test.cc",
"builtin/extension_test.cc",
"builtin/interpolation_sampling_test.cc",
"builtin/interpolation_type_test.cc",
"builtin/texel_format_test.cc",
]
deps = [ ":libtint_builtins_src" ]

View File

@ -158,6 +158,8 @@ list(APPEND TINT_LIB_SRCS
ast/int_literal_expression.h
ast/internal_attribute.cc
ast/internal_attribute.h
ast/interpolate_attribute.cc
ast/interpolate_attribute.h
ast/invariant_attribute.cc
ast/invariant_attribute.h
ast/let.cc
@ -555,9 +557,10 @@ tint_generated(builtin/builtin_value BENCH TEST)
tint_generated(builtin/diagnostic_rule BENCH TEST)
tint_generated(builtin/diagnostic_severity BENCH TEST)
tint_generated(builtin/extension BENCH TEST)
tint_generated(builtin/interpolation_sampling BENCH TEST)
tint_generated(builtin/interpolation_type BENCH TEST)
tint_generated(builtin/texel_format BENCH TEST)
tint_generated(ast/diagnostic_control TEST)
tint_generated(ast/interpolate_attribute BENCH TEST)
tint_generated(resolver/init_conv_intrinsic)
tint_generated(sem/builtin_type)
tint_generated(sem/parameter_usage)
@ -826,6 +829,7 @@ if(TINT_BUILD_TESTS)
ast/increment_decrement_statement_test.cc
ast/index_accessor_expression_test.cc
ast/int_literal_expression_test.cc
ast/interpolate_attribute_test.cc
ast/invariant_attribute_test.cc
ast/location_attribute_test.cc
ast/loop_statement_test.cc

View File

@ -12,14 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/ast/interpolate_attribute.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/ast/interpolate_attribute.h"
#include <string>
@ -33,8 +25,8 @@ namespace tint::ast {
InterpolateAttribute::InterpolateAttribute(ProgramID pid,
NodeID nid,
const Source& src,
InterpolationType ty,
InterpolationSampling smpl)
builtin::InterpolationType ty,
builtin::InterpolationSampling smpl)
: Base(pid, nid, src), type(ty), sampling(smpl) {}
InterpolateAttribute::~InterpolateAttribute() = default;
@ -49,65 +41,4 @@ const InterpolateAttribute* InterpolateAttribute::Clone(CloneContext* ctx) const
return ctx->dst->create<InterpolateAttribute>(src, type, sampling);
}
/// ParseInterpolationType parses a InterpolationType from a string.
/// @param str the string to parse
/// @returns the parsed enum, or InterpolationType::kUndefined if the string could not be parsed.
InterpolationType ParseInterpolationType(std::string_view str) {
if (str == "flat") {
return InterpolationType::kFlat;
}
if (str == "linear") {
return InterpolationType::kLinear;
}
if (str == "perspective") {
return InterpolationType::kPerspective;
}
return InterpolationType::kUndefined;
}
std::ostream& operator<<(std::ostream& out, InterpolationType value) {
switch (value) {
case InterpolationType::kUndefined:
return out << "undefined";
case InterpolationType::kFlat:
return out << "flat";
case InterpolationType::kLinear:
return out << "linear";
case InterpolationType::kPerspective:
return out << "perspective";
}
return out << "<unknown>";
}
/// ParseInterpolationSampling parses a InterpolationSampling from a string.
/// @param str the string to parse
/// @returns the parsed enum, or InterpolationSampling::kUndefined if the string could not be
/// parsed.
InterpolationSampling ParseInterpolationSampling(std::string_view str) {
if (str == "center") {
return InterpolationSampling::kCenter;
}
if (str == "centroid") {
return InterpolationSampling::kCentroid;
}
if (str == "sample") {
return InterpolationSampling::kSample;
}
return InterpolationSampling::kUndefined;
}
std::ostream& operator<<(std::ostream& out, InterpolationSampling value) {
switch (value) {
case InterpolationSampling::kUndefined:
return out << "undefined";
case InterpolationSampling::kCenter:
return out << "center";
case InterpolationSampling::kCentroid:
return out << "centroid";
case InterpolationSampling::kSample:
return out << "sample";
}
return out << "<unknown>";
}
} // namespace tint::ast

View File

@ -1,50 +0,0 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate builtin_value.cc
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
#include "src/tint/ast/interpolate_attribute.h"
#include <string>
#include "src/tint/program_builder.h"
TINT_INSTANTIATE_TYPEINFO(tint::ast::InterpolateAttribute);
namespace tint::ast {
InterpolateAttribute::InterpolateAttribute(ProgramID pid,
NodeID nid,
const Source& src,
InterpolationType ty,
InterpolationSampling smpl)
: Base(pid, nid, src), type(ty), sampling(smpl) {}
InterpolateAttribute::~InterpolateAttribute() = default;
std::string InterpolateAttribute::Name() const {
return "interpolate";
}
const InterpolateAttribute* InterpolateAttribute::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering
auto src = ctx->Clone(source);
return ctx->dst->create<InterpolateAttribute>(src, type, sampling);
}
{{ Eval "ParseEnum" (Sem.Enum "interpolation_type")}}
{{ Eval "EnumOStream" (Sem.Enum "interpolation_type")}}
{{ Eval "ParseEnum" (Sem.Enum "interpolation_sampling")}}
{{ Eval "EnumOStream" (Sem.Enum "interpolation_sampling")}}
} // namespace tint::ast

View File

@ -12,14 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/ast/interpolate_attribute.h.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#ifndef SRC_TINT_AST_INTERPOLATE_ATTRIBUTE_H_
#define SRC_TINT_AST_INTERPOLATE_ATTRIBUTE_H_
@ -27,58 +19,11 @@
#include <string>
#include "src/tint/ast/attribute.h"
#include "src/tint/builtin/interpolation_sampling.h"
#include "src/tint/builtin/interpolation_type.h"
namespace tint::ast {
/// The interpolation type.
enum class InterpolationType {
kUndefined,
kFlat,
kLinear,
kPerspective,
};
/// @param out the std::ostream to write to
/// @param value the InterpolationType
/// @returns `out` so calls can be chained
std::ostream& operator<<(std::ostream& out, InterpolationType value);
/// ParseInterpolationType parses a InterpolationType from a string.
/// @param str the string to parse
/// @returns the parsed enum, or InterpolationType::kUndefined if the string could not be parsed.
InterpolationType ParseInterpolationType(std::string_view str);
constexpr const char* kInterpolationTypeStrings[] = {
"flat",
"linear",
"perspective",
};
/// The interpolation sampling.
enum class InterpolationSampling {
kUndefined,
kCenter,
kCentroid,
kSample,
};
/// @param out the std::ostream to write to
/// @param value the InterpolationSampling
/// @returns `out` so calls can be chained
std::ostream& operator<<(std::ostream& out, InterpolationSampling value);
/// ParseInterpolationSampling parses a InterpolationSampling from a string.
/// @param str the string to parse
/// @returns the parsed enum, or InterpolationSampling::kUndefined if the string could not be
/// parsed.
InterpolationSampling ParseInterpolationSampling(std::string_view str);
constexpr const char* kInterpolationSamplingStrings[] = {
"center",
"centroid",
"sample",
};
/// An interpolate attribute
class InterpolateAttribute final : public Castable<InterpolateAttribute, Attribute> {
public:
@ -91,8 +36,8 @@ class InterpolateAttribute final : public Castable<InterpolateAttribute, Attribu
InterpolateAttribute(ProgramID pid,
NodeID nid,
const Source& src,
InterpolationType type,
InterpolationSampling sampling);
builtin::InterpolationType type,
builtin::InterpolationSampling sampling);
~InterpolateAttribute() override;
/// @returns the WGSL name for the attribute
@ -105,10 +50,10 @@ class InterpolateAttribute final : public Castable<InterpolateAttribute, Attribu
const InterpolateAttribute* Clone(CloneContext* ctx) const override;
/// The interpolation type
const InterpolationType type;
const builtin::InterpolationType type;
/// The interpolation sampling
const InterpolationSampling sampling;
const builtin::InterpolationSampling sampling;
};
} // namespace tint::ast

View File

@ -1,63 +0,0 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate interpolate_attribute.h
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
#ifndef SRC_TINT_AST_INTERPOLATE_ATTRIBUTE_H_
#define SRC_TINT_AST_INTERPOLATE_ATTRIBUTE_H_
#include <ostream>
#include <string>
#include "src/tint/ast/attribute.h"
namespace tint::ast {
/// The interpolation type.
{{ Eval "DeclareEnum" (Sem.Enum "interpolation_type") }}
/// The interpolation sampling.
{{ Eval "DeclareEnum" (Sem.Enum "interpolation_sampling") }}
/// An interpolate attribute
class InterpolateAttribute final : public Castable<InterpolateAttribute, Attribute> {
public:
/// Create an interpolate attribute.
/// @param pid the identifier of the program that owns this node
/// @param nid the unique node identifier
/// @param src the source of this node
/// @param type the interpolation type
/// @param sampling the interpolation sampling
InterpolateAttribute(ProgramID pid,
NodeID nid,
const Source& src,
InterpolationType type,
InterpolationSampling sampling);
~InterpolateAttribute() override;
/// @returns the WGSL name for the attribute
std::string Name() const override;
/// Clones this node and all transitive child nodes using the `CloneContext`
/// `ctx`.
/// @param ctx the clone context
/// @return the newly cloned node
const InterpolateAttribute* Clone(CloneContext* ctx) const override;
/// The interpolation type
const InterpolationType type;
/// The interpolation sampling
const InterpolationSampling sampling;
};
} // namespace tint::ast
#endif // SRC_TINT_AST_INTERPOLATE_ATTRIBUTE_H_

View File

@ -12,14 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/ast/interpolate_attribute_test.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/ast/interpolate_attribute.h"
#include <string>
@ -33,123 +25,11 @@ namespace {
using InterpolateAttributeTest = TestHelper;
TEST_F(InterpolateAttributeTest, Creation) {
auto* d =
create<InterpolateAttribute>(InterpolationType::kLinear, InterpolationSampling::kCenter);
EXPECT_EQ(InterpolationType::kLinear, d->type);
EXPECT_EQ(InterpolationSampling::kCenter, d->sampling);
auto* d = create<InterpolateAttribute>(builtin::InterpolationType::kLinear,
builtin::InterpolationSampling::kCenter);
EXPECT_EQ(builtin::InterpolationType::kLinear, d->type);
EXPECT_EQ(builtin::InterpolationSampling::kCenter, d->sampling);
}
namespace interpolation_type_tests {
namespace parse_print_tests {
struct Case {
const char* string;
InterpolationType value;
};
inline std::ostream& operator<<(std::ostream& out, Case c) {
return out << "'" << std::string(c.string) << "'";
}
static constexpr Case kValidCases[] = {
{"flat", InterpolationType::kFlat},
{"linear", InterpolationType::kLinear},
{"perspective", InterpolationType::kPerspective},
};
static constexpr Case kInvalidCases[] = {
{"ccat", InterpolationType::kUndefined}, {"3", InterpolationType::kUndefined},
{"fVat", InterpolationType::kUndefined}, {"1inear", InterpolationType::kUndefined},
{"lnqqar", InterpolationType::kUndefined}, {"linell77", InterpolationType::kUndefined},
{"perppHqective", InterpolationType::kUndefined}, {"cespctve", InterpolationType::kUndefined},
{"ebGpective", InterpolationType::kUndefined},
};
using InterpolationTypeParseTest = testing::TestWithParam<Case>;
TEST_P(InterpolationTypeParseTest, Parse) {
const char* string = GetParam().string;
InterpolationType expect = GetParam().value;
EXPECT_EQ(expect, ParseInterpolationType(string));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, InterpolationTypeParseTest, testing::ValuesIn(kValidCases));
INSTANTIATE_TEST_SUITE_P(InvalidCases,
InterpolationTypeParseTest,
testing::ValuesIn(kInvalidCases));
using InterpolationTypePrintTest = testing::TestWithParam<Case>;
TEST_P(InterpolationTypePrintTest, Print) {
InterpolationType value = GetParam().value;
const char* expect = GetParam().string;
EXPECT_EQ(expect, utils::ToString(value));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, InterpolationTypePrintTest, testing::ValuesIn(kValidCases));
} // namespace parse_print_tests
} // namespace interpolation_type_tests
namespace interpolation_sampling_tests {
namespace parse_print_tests {
struct Case {
const char* string;
InterpolationSampling value;
};
inline std::ostream& operator<<(std::ostream& out, Case c) {
return out << "'" << std::string(c.string) << "'";
}
static constexpr Case kValidCases[] = {
{"center", InterpolationSampling::kCenter},
{"centroid", InterpolationSampling::kCentroid},
{"sample", InterpolationSampling::kSample},
};
static constexpr Case kInvalidCases[] = {
{"cevteii", InterpolationSampling::kUndefined}, {"ceWWt8r", InterpolationSampling::kUndefined},
{"xxentr", InterpolationSampling::kUndefined}, {"ceXggrid", InterpolationSampling::kUndefined},
{"ceXriu", InterpolationSampling::kUndefined}, {"centr3id", InterpolationSampling::kUndefined},
{"sEmple", InterpolationSampling::kUndefined}, {"amTTlPP", InterpolationSampling::kUndefined},
{"ddamxxl", InterpolationSampling::kUndefined},
};
using InterpolationSamplingParseTest = testing::TestWithParam<Case>;
TEST_P(InterpolationSamplingParseTest, Parse) {
const char* string = GetParam().string;
InterpolationSampling expect = GetParam().value;
EXPECT_EQ(expect, ParseInterpolationSampling(string));
}
INSTANTIATE_TEST_SUITE_P(ValidCases,
InterpolationSamplingParseTest,
testing::ValuesIn(kValidCases));
INSTANTIATE_TEST_SUITE_P(InvalidCases,
InterpolationSamplingParseTest,
testing::ValuesIn(kInvalidCases));
using InterpolationSamplingPrintTest = testing::TestWithParam<Case>;
TEST_P(InterpolationSamplingPrintTest, Print) {
InterpolationSampling value = GetParam().value;
const char* expect = GetParam().string;
EXPECT_EQ(expect, utils::ToString(value));
}
INSTANTIATE_TEST_SUITE_P(ValidCases,
InterpolationSamplingPrintTest,
testing::ValuesIn(kValidCases));
} // namespace parse_print_tests
} // namespace interpolation_sampling_tests
} // namespace
} // namespace tint::ast

View File

@ -0,0 +1,60 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/builtin/interpolation_sampling.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/builtin/interpolation_sampling.h"
#include <string>
namespace tint::builtin {
/// ParseInterpolationSampling parses a InterpolationSampling from a string.
/// @param str the string to parse
/// @returns the parsed enum, or InterpolationSampling::kUndefined if the string could not be
/// parsed.
InterpolationSampling ParseInterpolationSampling(std::string_view str) {
if (str == "center") {
return InterpolationSampling::kCenter;
}
if (str == "centroid") {
return InterpolationSampling::kCentroid;
}
if (str == "sample") {
return InterpolationSampling::kSample;
}
return InterpolationSampling::kUndefined;
}
std::ostream& operator<<(std::ostream& out, InterpolationSampling value) {
switch (value) {
case InterpolationSampling::kUndefined:
return out << "undefined";
case InterpolationSampling::kCenter:
return out << "center";
case InterpolationSampling::kCentroid:
return out << "centroid";
case InterpolationSampling::kSample:
return out << "sample";
}
return out << "<unknown>";
}
} // namespace tint::builtin

View File

@ -0,0 +1,23 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate builtin_value.cc
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
#include "src/tint/builtin/interpolation_sampling.h"
#include <string>
namespace tint::builtin {
{{ Eval "ParseEnum" (Sem.Enum "interpolation_sampling")}}
{{ Eval "EnumOStream" (Sem.Enum "interpolation_sampling")}}
} // namespace tint::builtin

View File

@ -0,0 +1,58 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/builtin/interpolation_sampling.h.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#ifndef SRC_TINT_BUILTIN_INTERPOLATION_SAMPLING_H_
#define SRC_TINT_BUILTIN_INTERPOLATION_SAMPLING_H_
#include <ostream>
#include <string>
namespace tint::builtin {
/// The interpolation sampling.
enum class InterpolationSampling {
kUndefined,
kCenter,
kCentroid,
kSample,
};
/// @param out the std::ostream to write to
/// @param value the InterpolationSampling
/// @returns `out` so calls can be chained
std::ostream& operator<<(std::ostream& out, InterpolationSampling value);
/// ParseInterpolationSampling parses a InterpolationSampling from a string.
/// @param str the string to parse
/// @returns the parsed enum, or InterpolationSampling::kUndefined if the string could not be
/// parsed.
InterpolationSampling ParseInterpolationSampling(std::string_view str);
constexpr const char* kInterpolationSamplingStrings[] = {
"center",
"centroid",
"sample",
};
} // namespace tint::builtin
#endif // SRC_TINT_BUILTIN_INTERPOLATION_SAMPLING_H_

View File

@ -0,0 +1,26 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate interpolate_attribute.h
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
#ifndef SRC_TINT_BUILTIN_INTERPOLATION_SAMPLING_H_
#define SRC_TINT_BUILTIN_INTERPOLATION_SAMPLING_H_
#include <ostream>
#include <string>
namespace tint::builtin {
/// The interpolation sampling.
{{ Eval "DeclareEnum" (Sem.Enum "interpolation_sampling") }}
} // namespace tint::builtin
#endif // SRC_TINT_BUILTIN_INTERPOLATION_SAMPLING_H_

View File

@ -0,0 +1,48 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/builtin/interpolation_sampling_bench.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include <array>
#include "benchmark/benchmark.h"
#include "src/tint/builtin/interpolation_sampling.h"
namespace tint::builtin {
namespace {
void InterpolationSamplingParser(::benchmark::State& state) {
const char* kStrings[] = {
"ccnter", "c3r", "centeV", "center", "1enter", "cnqqer", "centll77",
"qqenrppHid", "cntov", "cenGoid", "centroid", "ceviiroid", "ceWWtro8d", "cxxtMoid",
"saXggl", "Xmle", "sam3le", "sample", "sEmple", "amTTlPP", "ddamxxl",
};
for (auto _ : state) {
for (auto* str : kStrings) {
auto result = ParseInterpolationSampling(str);
benchmark::DoNotOptimize(result);
}
}
}
BENCHMARK(InterpolationSamplingParser);
} // namespace
} // namespace tint::builtin

View File

@ -10,18 +10,15 @@ See:
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
#include "src/tint/ast/interpolate_attribute.h"
#include <array>
#include "benchmark/benchmark.h"
#include "src/tint/builtin/interpolation_sampling.h"
namespace tint::ast {
namespace tint::builtin {
namespace {
{{ Eval "BenchmarkParseEnum" (Sem.Enum "interpolation_type")}}
{{ Eval "BenchmarkParseEnum" (Sem.Enum "interpolation_sampling")}}
} // namespace
} // namespace tint::ast
} // namespace tint::builtin

View File

@ -0,0 +1,96 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/builtin/interpolation_sampling_test.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/builtin/interpolation_sampling.h"
#include <gtest/gtest.h>
#include <string>
#include "src/tint/utils/string.h"
namespace tint::builtin {
namespace {
namespace interpolation_sampling_tests {
namespace parse_print_tests {
struct Case {
const char* string;
InterpolationSampling value;
};
inline std::ostream& operator<<(std::ostream& out, Case c) {
return out << "'" << std::string(c.string) << "'";
}
static constexpr Case kValidCases[] = {
{"center", InterpolationSampling::kCenter},
{"centroid", InterpolationSampling::kCentroid},
{"sample", InterpolationSampling::kSample},
};
static constexpr Case kInvalidCases[] = {
{"ccnter", InterpolationSampling::kUndefined},
{"c3r", InterpolationSampling::kUndefined},
{"centeV", InterpolationSampling::kUndefined},
{"1entroid", InterpolationSampling::kUndefined},
{"enJrqqid", InterpolationSampling::kUndefined},
{"llen77roid", InterpolationSampling::kUndefined},
{"sapppHHe", InterpolationSampling::kUndefined},
{"cam", InterpolationSampling::kUndefined},
{"sbGpl", InterpolationSampling::kUndefined},
};
using InterpolationSamplingParseTest = testing::TestWithParam<Case>;
TEST_P(InterpolationSamplingParseTest, Parse) {
const char* string = GetParam().string;
InterpolationSampling expect = GetParam().value;
EXPECT_EQ(expect, ParseInterpolationSampling(string));
}
INSTANTIATE_TEST_SUITE_P(ValidCases,
InterpolationSamplingParseTest,
testing::ValuesIn(kValidCases));
INSTANTIATE_TEST_SUITE_P(InvalidCases,
InterpolationSamplingParseTest,
testing::ValuesIn(kInvalidCases));
using InterpolationSamplingPrintTest = testing::TestWithParam<Case>;
TEST_P(InterpolationSamplingPrintTest, Print) {
InterpolationSampling value = GetParam().value;
const char* expect = GetParam().string;
EXPECT_EQ(expect, utils::ToString(value));
}
INSTANTIATE_TEST_SUITE_P(ValidCases,
InterpolationSamplingPrintTest,
testing::ValuesIn(kValidCases));
} // namespace parse_print_tests
} // namespace interpolation_sampling_tests
} // namespace
} // namespace tint::builtin

View File

@ -10,31 +10,16 @@ See:
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
#include "src/tint/ast/interpolate_attribute.h"
#include "src/tint/builtin/interpolation_sampling.h"
#include <gtest/gtest.h>
#include <string>
#include "src/tint/ast/test_helper.h"
#include "src/tint/utils/string.h"
namespace tint::ast {
namespace tint::builtin {
namespace {
using InterpolateAttributeTest = TestHelper;
TEST_F(InterpolateAttributeTest, Creation) {
auto* d =
create<InterpolateAttribute>(InterpolationType::kLinear, InterpolationSampling::kCenter);
EXPECT_EQ(InterpolationType::kLinear, d->type);
EXPECT_EQ(InterpolationSampling::kCenter, d->sampling);
}
namespace interpolation_type_tests {
{{ Eval "TestParsePrintEnum" (Sem.Enum "interpolation_type")}}
} // namespace interpolation_type_tests
namespace interpolation_sampling_tests {
{{ Eval "TestParsePrintEnum" (Sem.Enum "interpolation_sampling")}}
@ -42,4 +27,4 @@ namespace interpolation_sampling_tests {
} // namespace interpolation_sampling_tests
} // namespace
} // namespace tint::ast
} // namespace tint::builtin

View File

@ -0,0 +1,59 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/builtin/interpolation_type.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/builtin/interpolation_type.h"
#include <string>
namespace tint::builtin {
/// ParseInterpolationType parses a InterpolationType from a string.
/// @param str the string to parse
/// @returns the parsed enum, or InterpolationType::kUndefined if the string could not be parsed.
InterpolationType ParseInterpolationType(std::string_view str) {
if (str == "flat") {
return InterpolationType::kFlat;
}
if (str == "linear") {
return InterpolationType::kLinear;
}
if (str == "perspective") {
return InterpolationType::kPerspective;
}
return InterpolationType::kUndefined;
}
std::ostream& operator<<(std::ostream& out, InterpolationType value) {
switch (value) {
case InterpolationType::kUndefined:
return out << "undefined";
case InterpolationType::kFlat:
return out << "flat";
case InterpolationType::kLinear:
return out << "linear";
case InterpolationType::kPerspective:
return out << "perspective";
}
return out << "<unknown>";
}
} // namespace tint::builtin

View File

@ -0,0 +1,23 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate builtin_value.cc
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
#include "src/tint/builtin/interpolation_type.h"
#include <string>
namespace tint::builtin {
{{ Eval "ParseEnum" (Sem.Enum "interpolation_type")}}
{{ Eval "EnumOStream" (Sem.Enum "interpolation_type")}}
} // namespace tint::builtin

View File

@ -0,0 +1,57 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/builtin/interpolation_type.h.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#ifndef SRC_TINT_BUILTIN_INTERPOLATION_TYPE_H_
#define SRC_TINT_BUILTIN_INTERPOLATION_TYPE_H_
#include <ostream>
#include <string>
namespace tint::builtin {
/// The interpolation type.
enum class InterpolationType {
kUndefined,
kFlat,
kLinear,
kPerspective,
};
/// @param out the std::ostream to write to
/// @param value the InterpolationType
/// @returns `out` so calls can be chained
std::ostream& operator<<(std::ostream& out, InterpolationType value);
/// ParseInterpolationType parses a InterpolationType from a string.
/// @param str the string to parse
/// @returns the parsed enum, or InterpolationType::kUndefined if the string could not be parsed.
InterpolationType ParseInterpolationType(std::string_view str);
constexpr const char* kInterpolationTypeStrings[] = {
"flat",
"linear",
"perspective",
};
} // namespace tint::builtin
#endif // SRC_TINT_BUILTIN_INTERPOLATION_TYPE_H_

View File

@ -0,0 +1,26 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate interpolate_attribute.h
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
#ifndef SRC_TINT_BUILTIN_INTERPOLATION_TYPE_H_
#define SRC_TINT_BUILTIN_INTERPOLATION_TYPE_H_
#include <ostream>
#include <string>
namespace tint::builtin {
/// The interpolation type.
{{ Eval "DeclareEnum" (Sem.Enum "interpolation_type") }}
} // namespace tint::builtin
#endif // SRC_TINT_BUILTIN_INTERPOLATION_TYPE_H_

View File

@ -1,4 +1,4 @@
// Copyright 2022 The Tint Authors.
// 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.
@ -15,18 +15,18 @@
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/ast/interpolate_attribute_bench.cc.tmpl
// src/tint/builtin/interpolation_type_bench.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/ast/interpolate_attribute.h"
#include "src/tint/builtin/interpolation_type.h"
#include <array>
#include "benchmark/benchmark.h"
namespace tint::ast {
namespace tint::builtin {
namespace {
void InterpolationTypeParser(::benchmark::State& state) {
@ -47,21 +47,5 @@ void InterpolationTypeParser(::benchmark::State& state) {
BENCHMARK(InterpolationTypeParser);
void InterpolationSamplingParser(::benchmark::State& state) {
const char* kStrings[] = {
"44enter", "cSSVVter", "centRr", "center", "ent9r", "cente", "VentORr",
"cenyroi", "77errtrllnid", "04entroid", "centroid", "enooid", "centzzd", "ceiippr1i",
"saXXple", "55IImpnn99", "aHHrrmplSS", "sample", "kkle", "jagRR", "smbe",
};
for (auto _ : state) {
for (auto* str : kStrings) {
auto result = ParseInterpolationSampling(str);
benchmark::DoNotOptimize(result);
}
}
}
BENCHMARK(InterpolationSamplingParser);
} // namespace
} // namespace tint::ast
} // namespace tint::builtin

View File

@ -0,0 +1,25 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate interpolate_attribute_bench.cc
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
#include "src/tint/builtin/interpolation_type.h"
#include <array>
#include "benchmark/benchmark.h"
namespace tint::builtin {
namespace {
{{ Eval "BenchmarkParseEnum" (Sem.Enum "interpolation_type")}}
} // namespace
} // namespace tint::builtin

View File

@ -0,0 +1,88 @@
// 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.
////////////////////////////////////////////////////////////////////////////////
// File generated by tools/src/cmd/gen
// using the template:
// src/tint/builtin/interpolation_type_test.cc.tmpl
//
// Do not modify this file directly
////////////////////////////////////////////////////////////////////////////////
#include "src/tint/builtin/interpolation_type.h"
#include <gtest/gtest.h>
#include <string>
#include "src/tint/utils/string.h"
namespace tint::builtin {
namespace {
namespace interpolation_type_tests {
namespace parse_print_tests {
struct Case {
const char* string;
InterpolationType value;
};
inline std::ostream& operator<<(std::ostream& out, Case c) {
return out << "'" << std::string(c.string) << "'";
}
static constexpr Case kValidCases[] = {
{"flat", InterpolationType::kFlat},
{"linear", InterpolationType::kLinear},
{"perspective", InterpolationType::kPerspective},
};
static constexpr Case kInvalidCases[] = {
{"ccat", InterpolationType::kUndefined}, {"3", InterpolationType::kUndefined},
{"fVat", InterpolationType::kUndefined}, {"1inear", InterpolationType::kUndefined},
{"lnqqar", InterpolationType::kUndefined}, {"linell77", InterpolationType::kUndefined},
{"perppHqective", InterpolationType::kUndefined}, {"cespctve", InterpolationType::kUndefined},
{"ebGpective", InterpolationType::kUndefined},
};
using InterpolationTypeParseTest = testing::TestWithParam<Case>;
TEST_P(InterpolationTypeParseTest, Parse) {
const char* string = GetParam().string;
InterpolationType expect = GetParam().value;
EXPECT_EQ(expect, ParseInterpolationType(string));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, InterpolationTypeParseTest, testing::ValuesIn(kValidCases));
INSTANTIATE_TEST_SUITE_P(InvalidCases,
InterpolationTypeParseTest,
testing::ValuesIn(kInvalidCases));
using InterpolationTypePrintTest = testing::TestWithParam<Case>;
TEST_P(InterpolationTypePrintTest, Print) {
InterpolationType value = GetParam().value;
const char* expect = GetParam().string;
EXPECT_EQ(expect, utils::ToString(value));
}
INSTANTIATE_TEST_SUITE_P(ValidCases, InterpolationTypePrintTest, testing::ValuesIn(kValidCases));
} // namespace parse_print_tests
} // namespace interpolation_type_tests
} // namespace
} // namespace tint::builtin

View File

@ -0,0 +1,30 @@
{{- /*
--------------------------------------------------------------------------------
Template file for use with tools/src/cmd/gen to generate interpolate_attribute_test.cc
See:
* tools/src/cmd/gen for structures used by this template
* https://golang.org/pkg/text/template/ for documentation on the template syntax
--------------------------------------------------------------------------------
*/ -}}
{{- Import "src/tint/templates/enums.tmpl.inc" -}}
#include "src/tint/builtin/interpolation_type.h"
#include <gtest/gtest.h>
#include <string>
#include "src/tint/utils/string.h"
namespace tint::builtin {
namespace {
namespace interpolation_type_tests {
{{ Eval "TestParsePrintEnum" (Sem.Enum "interpolation_type")}}
} // namespace interpolation_type_tests
} // namespace
} // namespace tint::builtin

View File

@ -129,38 +129,38 @@ std::tuple<InterpolationType, InterpolationSampling> CalculateInterpolationData(
auto ast_interpolation_type = interpolation_attribute->type;
auto ast_sampling_type = interpolation_attribute->sampling;
if (ast_interpolation_type != ast::InterpolationType::kFlat &&
ast_sampling_type == ast::InterpolationSampling::kUndefined) {
ast_sampling_type = ast::InterpolationSampling::kCenter;
if (ast_interpolation_type != builtin::InterpolationType::kFlat &&
ast_sampling_type == builtin::InterpolationSampling::kUndefined) {
ast_sampling_type = builtin::InterpolationSampling::kCenter;
}
auto interpolation_type = InterpolationType::kUnknown;
switch (ast_interpolation_type) {
case ast::InterpolationType::kPerspective:
case builtin::InterpolationType::kPerspective:
interpolation_type = InterpolationType::kPerspective;
break;
case ast::InterpolationType::kLinear:
case builtin::InterpolationType::kLinear:
interpolation_type = InterpolationType::kLinear;
break;
case ast::InterpolationType::kFlat:
case builtin::InterpolationType::kFlat:
interpolation_type = InterpolationType::kFlat;
break;
case ast::InterpolationType::kUndefined:
case builtin::InterpolationType::kUndefined:
break;
}
auto sampling_type = InterpolationSampling::kUnknown;
switch (ast_sampling_type) {
case ast::InterpolationSampling::kUndefined:
case builtin::InterpolationSampling::kUndefined:
sampling_type = InterpolationSampling::kNone;
break;
case ast::InterpolationSampling::kCenter:
case builtin::InterpolationSampling::kCenter:
sampling_type = InterpolationSampling::kCenter;
break;
case ast::InterpolationSampling::kCentroid:
case builtin::InterpolationSampling::kCentroid:
sampling_type = InterpolationSampling::kCentroid;
break;
case ast::InterpolationSampling::kSample:
case builtin::InterpolationSampling::kSample:
sampling_type = InterpolationSampling::kSample;
break;
}

View File

@ -51,8 +51,8 @@ class InspectorGetEntryPointComponentAndCompositionTest
: public InspectorBuilder,
public testing::TestWithParam<InspectorGetEntryPointComponentAndCompositionTestParams> {};
struct InspectorGetEntryPointInterpolateTestParams {
ast::InterpolationType in_type;
ast::InterpolationSampling in_sampling;
builtin::InterpolationType in_type;
builtin::InterpolationSampling in_sampling;
inspector::InterpolationType out_type;
inspector::InterpolationSampling out_sampling;
};
@ -1436,31 +1436,31 @@ INSTANTIATE_TEST_SUITE_P(
InspectorGetEntryPointInterpolateTest,
testing::Values(
InspectorGetEntryPointInterpolateTestParams{
ast::InterpolationType::kPerspective, ast::InterpolationSampling::kCenter,
builtin::InterpolationType::kPerspective, builtin::InterpolationSampling::kCenter,
InterpolationType::kPerspective, InterpolationSampling::kCenter},
InspectorGetEntryPointInterpolateTestParams{
ast::InterpolationType::kPerspective, ast::InterpolationSampling::kCentroid,
builtin::InterpolationType::kPerspective, builtin::InterpolationSampling::kCentroid,
InterpolationType::kPerspective, InterpolationSampling::kCentroid},
InspectorGetEntryPointInterpolateTestParams{
ast::InterpolationType::kPerspective, ast::InterpolationSampling::kSample,
builtin::InterpolationType::kPerspective, builtin::InterpolationSampling::kSample,
InterpolationType::kPerspective, InterpolationSampling::kSample},
InspectorGetEntryPointInterpolateTestParams{
ast::InterpolationType::kPerspective, ast::InterpolationSampling::kUndefined,
builtin::InterpolationType::kPerspective, builtin::InterpolationSampling::kUndefined,
InterpolationType::kPerspective, InterpolationSampling::kCenter},
InspectorGetEntryPointInterpolateTestParams{
ast::InterpolationType::kLinear, ast::InterpolationSampling::kCenter,
builtin::InterpolationType::kLinear, builtin::InterpolationSampling::kCenter,
InterpolationType::kLinear, InterpolationSampling::kCenter},
InspectorGetEntryPointInterpolateTestParams{
ast::InterpolationType::kLinear, ast::InterpolationSampling::kCentroid,
builtin::InterpolationType::kLinear, builtin::InterpolationSampling::kCentroid,
InterpolationType::kLinear, InterpolationSampling::kCentroid},
InspectorGetEntryPointInterpolateTestParams{
ast::InterpolationType::kLinear, ast::InterpolationSampling::kSample,
builtin::InterpolationType::kLinear, builtin::InterpolationSampling::kSample,
InterpolationType::kLinear, InterpolationSampling::kSample},
InspectorGetEntryPointInterpolateTestParams{
ast::InterpolationType::kLinear, ast::InterpolationSampling::kUndefined,
builtin::InterpolationType::kLinear, builtin::InterpolationSampling::kUndefined,
InterpolationType::kLinear, InterpolationSampling::kCenter},
InspectorGetEntryPointInterpolateTestParams{
ast::InterpolationType::kFlat, ast::InterpolationSampling::kUndefined,
builtin::InterpolationType::kFlat, builtin::InterpolationSampling::kUndefined,
InterpolationType::kFlat, InterpolationSampling::kNone}));
TEST_F(InspectorGetOverrideDefaultValuesTest, Bool) {

View File

@ -3463,8 +3463,8 @@ class ProgramBuilder {
/// @returns the interpolate attribute pointer
const ast::InterpolateAttribute* Interpolate(
const Source& source,
ast::InterpolationType type,
ast::InterpolationSampling sampling = ast::InterpolationSampling::kUndefined) {
builtin::InterpolationType type,
builtin::InterpolationSampling sampling = builtin::InterpolationSampling::kUndefined) {
return create<ast::InterpolateAttribute>(source, type, sampling);
}
@ -3473,8 +3473,8 @@ class ProgramBuilder {
/// @param sampling the interpolation sampling
/// @returns the interpolate attribute pointer
const ast::InterpolateAttribute* Interpolate(
ast::InterpolationType type,
ast::InterpolationSampling sampling = ast::InterpolationSampling::kUndefined) {
builtin::InterpolationType type,
builtin::InterpolationSampling sampling = builtin::InterpolationSampling::kUndefined) {
return create<ast::InterpolateAttribute>(source_, type, sampling);
}
@ -3482,12 +3482,14 @@ class ProgramBuilder {
/// @param source the source information
/// @returns the interpolate attribute pointer
const ast::InterpolateAttribute* Flat(const Source& source) {
return Interpolate(source, ast::InterpolationType::kFlat);
return Interpolate(source, builtin::InterpolationType::kFlat);
}
/// Creates an ast::InterpolateAttribute using flat interpolation
/// @returns the interpolate attribute pointer
const ast::InterpolateAttribute* Flat() { return Interpolate(ast::InterpolationType::kFlat); }
const ast::InterpolateAttribute* Flat() {
return Interpolate(builtin::InterpolationType::kFlat);
}
/// Creates an ast::InvariantAttribute
/// @param source the source information

View File

@ -1775,8 +1775,8 @@ bool ParserImpl::ConvertPipelineDecorations(const Type* store_type,
const DecorationList& decorations,
AttributeList* attributes) {
// Vulkan defaults to perspective-correct interpolation.
ast::InterpolationType type = ast::InterpolationType::kPerspective;
ast::InterpolationSampling sampling = ast::InterpolationSampling::kUndefined;
builtin::InterpolationType type = builtin::InterpolationType::kPerspective;
builtin::InterpolationSampling sampling = builtin::InterpolationSampling::kUndefined;
for (const auto& deco : decorations) {
TINT_ASSERT(Reader, deco.size() > 0);
@ -1789,49 +1789,49 @@ bool ParserImpl::ConvertPipelineDecorations(const Type* store_type,
SetLocation(attributes, builder_.Location(AInt(deco[1])));
if (store_type->IsIntegerScalarOrVector()) {
// Default to flat interpolation for integral user-defined IO types.
type = ast::InterpolationType::kFlat;
type = builtin::InterpolationType::kFlat;
}
break;
case spv::Decoration::Flat:
type = ast::InterpolationType::kFlat;
type = builtin::InterpolationType::kFlat;
break;
case spv::Decoration::NoPerspective:
if (store_type->IsIntegerScalarOrVector()) {
// This doesn't capture the array or struct case.
return Fail() << "NoPerspective is invalid on integral IO";
}
type = ast::InterpolationType::kLinear;
type = builtin::InterpolationType::kLinear;
break;
case spv::Decoration::Centroid:
if (store_type->IsIntegerScalarOrVector()) {
// This doesn't capture the array or struct case.
return Fail() << "Centroid interpolation sampling is invalid on integral IO";
}
sampling = ast::InterpolationSampling::kCentroid;
sampling = builtin::InterpolationSampling::kCentroid;
break;
case spv::Decoration::Sample:
if (store_type->IsIntegerScalarOrVector()) {
// This doesn't capture the array or struct case.
return Fail() << "Sample interpolation sampling is invalid on integral IO";
}
sampling = ast::InterpolationSampling::kSample;
sampling = builtin::InterpolationSampling::kSample;
break;
default:
break;
}
}
if (type == ast::InterpolationType::kFlat &&
if (type == builtin::InterpolationType::kFlat &&
!ast::HasAttribute<ast::LocationAttribute>(*attributes)) {
// WGSL requires that '@interpolate(flat)' needs to be paired with '@location', however
// SPIR-V requires all fragment shader integer Inputs are 'flat'. If the decorations do not
// contain a spv::Decoration::Location, then make this perspective.
type = ast::InterpolationType::kPerspective;
type = builtin::InterpolationType::kPerspective;
}
// Apply interpolation.
if (type == ast::InterpolationType::kPerspective &&
sampling == ast::InterpolationSampling::kUndefined) {
if (type == builtin::InterpolationType::kPerspective &&
sampling == builtin::InterpolationSampling::kUndefined) {
// This is the default. Don't add a decoration.
} else {
attributes->Push(create<ast::InterpolateAttribute>(type, sampling));

View File

@ -1115,18 +1115,18 @@ Expect<const ast::Parameter*> ParserImpl::expect_param() {
// : 'center'
// | 'centroid'
// | 'sample'
Expect<ast::InterpolationSampling> ParserImpl::expect_interpolation_sample_name() {
return expect_enum("interpolation sampling", ast::ParseInterpolationSampling,
ast::kInterpolationSamplingStrings);
Expect<builtin::InterpolationSampling> ParserImpl::expect_interpolation_sample_name() {
return expect_enum("interpolation sampling", builtin::ParseInterpolationSampling,
builtin::kInterpolationSamplingStrings);
}
// interpolation_type_name
// : 'perspective'
// | 'linear'
// | 'flat'
Expect<ast::InterpolationType> ParserImpl::expect_interpolation_type_name() {
return expect_enum("interpolation type", ast::ParseInterpolationType,
ast::kInterpolationTypeStrings);
Expect<builtin::InterpolationType> ParserImpl::expect_interpolation_type_name() {
return expect_enum("interpolation type", builtin::ParseInterpolationType,
builtin::kInterpolationTypeStrings);
}
// builtin_value_name
@ -3091,7 +3091,7 @@ Maybe<const ast::Attribute*> ParserImpl::attribute() {
return Failure::kErrored;
}
ast::InterpolationSampling sampling = ast::InterpolationSampling::kUndefined;
builtin::InterpolationSampling sampling = builtin::InterpolationSampling::kUndefined;
if (match(Token::Type::kComma)) {
if (!peek_is(Token::Type::kParenRight)) {
auto sample = expect_interpolation_sample_name();

View File

@ -457,11 +457,11 @@ class ParserImpl {
/// Parses an interpolation sample name identifier, erroring if the next token does not match a
/// valid sample name.
/// @returns the parsed sample name.
Expect<ast::InterpolationSampling> expect_interpolation_sample_name();
Expect<builtin::InterpolationSampling> expect_interpolation_sample_name();
/// Parses an interpolation type name identifier, erroring if the next token does not match a
/// value type name.
/// @returns the parsed type name
Expect<ast::InterpolationType> expect_interpolation_type_name();
Expect<builtin::InterpolationType> expect_interpolation_type_name();
/// Parses a builtin identifier, erroring if the next token does not match a
/// valid builtin name.
/// @returns the parsed builtin.

View File

@ -352,8 +352,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Flat) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>();
EXPECT_EQ(interp->type, ast::InterpolationType::kFlat);
EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kUndefined);
EXPECT_EQ(interp->type, builtin::InterpolationType::kFlat);
EXPECT_EQ(interp->sampling, builtin::InterpolationSampling::kUndefined);
}
TEST_F(ParserImplTest, Attribute_Interpolate_Single_TrailingComma) {
@ -368,8 +368,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Single_TrailingComma) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>();
EXPECT_EQ(interp->type, ast::InterpolationType::kFlat);
EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kUndefined);
EXPECT_EQ(interp->type, builtin::InterpolationType::kFlat);
EXPECT_EQ(interp->sampling, builtin::InterpolationSampling::kUndefined);
}
TEST_F(ParserImplTest, Attribute_Interpolate_Single_DoubleTrailingComma) {
@ -395,8 +395,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Perspective_Center) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>();
EXPECT_EQ(interp->type, ast::InterpolationType::kPerspective);
EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kCenter);
EXPECT_EQ(interp->type, builtin::InterpolationType::kPerspective);
EXPECT_EQ(interp->sampling, builtin::InterpolationSampling::kCenter);
}
TEST_F(ParserImplTest, Attribute_Interpolate_Double_TrailingComma) {
@ -411,8 +411,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Double_TrailingComma) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>();
EXPECT_EQ(interp->type, ast::InterpolationType::kPerspective);
EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kCenter);
EXPECT_EQ(interp->type, builtin::InterpolationType::kPerspective);
EXPECT_EQ(interp->sampling, builtin::InterpolationSampling::kCenter);
}
TEST_F(ParserImplTest, Attribute_Interpolate_Perspective_Centroid) {
@ -427,8 +427,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Perspective_Centroid) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>();
EXPECT_EQ(interp->type, ast::InterpolationType::kPerspective);
EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kCentroid);
EXPECT_EQ(interp->type, builtin::InterpolationType::kPerspective);
EXPECT_EQ(interp->sampling, builtin::InterpolationSampling::kCentroid);
}
TEST_F(ParserImplTest, Attribute_Interpolate_Linear_Sample) {
@ -443,8 +443,8 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Linear_Sample) {
ASSERT_TRUE(var_attr->Is<ast::InterpolateAttribute>());
auto* interp = var_attr->As<ast::InterpolateAttribute>();
EXPECT_EQ(interp->type, ast::InterpolationType::kLinear);
EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kSample);
EXPECT_EQ(interp->type, builtin::InterpolationType::kLinear);
EXPECT_EQ(interp->sampling, builtin::InterpolationSampling::kSample);
}
TEST_F(ParserImplTest, Attribute_Interpolate_MissingLeftParen) {

View File

@ -104,8 +104,8 @@ static utils::Vector<const ast::Attribute*, 2> createAttributes(const Source& so
case AttributeKind::kId:
return {builder.Id(source, 0_a)};
case AttributeKind::kInterpolate:
return {builder.Interpolate(source, ast::InterpolationType::kLinear,
ast::InterpolationSampling::kCenter)};
return {builder.Interpolate(source, builtin::InterpolationType::kLinear,
builtin::InterpolationSampling::kCenter)};
case AttributeKind::kInvariant:
return {builder.Invariant(source)};
case AttributeKind::kLocation:
@ -1488,8 +1488,8 @@ namespace {
using InterpolateTest = ResolverTest;
struct Params {
ast::InterpolationType type;
ast::InterpolationSampling sampling;
builtin::InterpolationType type;
builtin::InterpolationSampling sampling;
bool should_pass;
};
@ -1538,7 +1538,7 @@ TEST_P(InterpolateParameterTest, IntegerScalar) {
Stage(ast::PipelineStage::kFragment),
});
if (params.type != ast::InterpolationType::kFlat) {
if (params.type != builtin::InterpolationType::kFlat) {
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: interpolation type must be 'flat' for integral "
@ -1569,7 +1569,7 @@ TEST_P(InterpolateParameterTest, IntegerVector) {
Stage(ast::PipelineStage::kFragment),
});
if (params.type != ast::InterpolationType::kFlat) {
if (params.type != builtin::InterpolationType::kFlat) {
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
"12:34 error: interpolation type must be 'flat' for integral "
@ -1588,19 +1588,25 @@ INSTANTIATE_TEST_SUITE_P(
ResolverAttributeValidationTest,
InterpolateParameterTest,
testing::Values(
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kUndefined, true},
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kCenter, true},
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kCentroid, true},
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kSample, true},
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kUndefined, true},
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kCenter, true},
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kCentroid, true},
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kSample, true},
Params{builtin::InterpolationType::kPerspective, builtin::InterpolationSampling::kUndefined,
true},
Params{builtin::InterpolationType::kPerspective, builtin::InterpolationSampling::kCenter,
true},
Params{builtin::InterpolationType::kPerspective, builtin::InterpolationSampling::kCentroid,
true},
Params{builtin::InterpolationType::kPerspective, builtin::InterpolationSampling::kSample,
true},
Params{builtin::InterpolationType::kLinear, builtin::InterpolationSampling::kUndefined,
true},
Params{builtin::InterpolationType::kLinear, builtin::InterpolationSampling::kCenter, true},
Params{builtin::InterpolationType::kLinear, builtin::InterpolationSampling::kCentroid,
true},
Params{builtin::InterpolationType::kLinear, builtin::InterpolationSampling::kSample, true},
// flat interpolation must not have a sampling type
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kUndefined, true},
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kCenter, false},
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kCentroid, false},
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kSample, false}));
Params{builtin::InterpolationType::kFlat, builtin::InterpolationSampling::kUndefined, true},
Params{builtin::InterpolationType::kFlat, builtin::InterpolationSampling::kCenter, false},
Params{builtin::InterpolationType::kFlat, builtin::InterpolationSampling::kCentroid, false},
Params{builtin::InterpolationType::kFlat, builtin::InterpolationSampling::kSample, false}));
TEST_F(InterpolateTest, FragmentInput_Integer_MissingFlatInterpolation) {
Func("main",
@ -1644,8 +1650,8 @@ TEST_F(InterpolateTest, MissingLocationAttribute_Parameter) {
Param("a", ty.vec4<f32>(),
utils::Vector{
Builtin(builtin::BuiltinValue::kPosition),
Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
ast::InterpolationSampling::kUndefined),
Interpolate(Source{{12, 34}}, builtin::InterpolationType::kFlat,
builtin::InterpolationSampling::kUndefined),
}),
},
ty.void_(), utils::Empty,
@ -1668,8 +1674,8 @@ TEST_F(InterpolateTest, MissingLocationAttribute_ReturnType) {
},
utils::Vector{
Builtin(builtin::BuiltinValue::kPosition),
Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
ast::InterpolationSampling::kUndefined),
Interpolate(Source{{12, 34}}, builtin::InterpolationType::kFlat,
builtin::InterpolationSampling::kUndefined),
});
EXPECT_FALSE(r()->Resolve());
@ -1678,11 +1684,12 @@ TEST_F(InterpolateTest, MissingLocationAttribute_ReturnType) {
}
TEST_F(InterpolateTest, MissingLocationAttribute_Struct) {
Structure("S",
Structure(
"S",
utils::Vector{
Member("a", ty.f32(),
utils::Vector{Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
ast::InterpolationSampling::kUndefined)}),
utils::Vector{Interpolate(Source{{12, 34}}, builtin::InterpolationType::kFlat,
builtin::InterpolationSampling::kUndefined)}),
});
EXPECT_FALSE(r()->Resolve());

View File

@ -973,14 +973,14 @@ bool Validator::InterpolateAttribute(const ast::InterpolateAttribute* attr,
const type::Type* storage_ty) const {
auto* type = storage_ty->UnwrapRef();
if (type->is_integer_scalar_or_vector() && attr->type != ast::InterpolationType::kFlat) {
if (type->is_integer_scalar_or_vector() && attr->type != builtin::InterpolationType::kFlat) {
AddError("interpolation type must be 'flat' for integral user-defined IO types",
attr->source);
return false;
}
if (attr->type == ast::InterpolationType::kFlat &&
attr->sampling != ast::InterpolationSampling::kUndefined) {
if (attr->type == builtin::InterpolationType::kFlat &&
attr->sampling != builtin::InterpolationSampling::kUndefined) {
AddError("flat interpolation attribute must not have a sampling parameter", attr->source);
return false;
}

View File

@ -222,8 +222,8 @@ struct CanonicalizeEntryPointIO::State {
!ast::HasAttribute<ast::InterpolateAttribute>(attributes) &&
(ast::HasAttribute<ast::LocationAttribute>(attributes) ||
cfg.shader_style == ShaderStyle::kSpirv)) {
attributes.Push(ctx.dst->Interpolate(ast::InterpolationType::kFlat,
ast::InterpolationSampling::kUndefined));
attributes.Push(ctx.dst->Interpolate(builtin::InterpolationType::kFlat,
builtin::InterpolationSampling::kUndefined));
}
// Disable validation for use of the `input` address space.
@ -291,8 +291,8 @@ struct CanonicalizeEntryPointIO::State {
type->is_integer_scalar_or_vector() &&
ast::HasAttribute<ast::LocationAttribute>(attributes) &&
!ast::HasAttribute<ast::InterpolateAttribute>(attributes)) {
attributes.Push(ctx.dst->Interpolate(ast::InterpolationType::kFlat,
ast::InterpolationSampling::kUndefined));
attributes.Push(ctx.dst->Interpolate(builtin::InterpolationType::kFlat,
builtin::InterpolationSampling::kUndefined));
}
// In GLSL, if it's a builtin, override the name with the

View File

@ -2191,21 +2191,21 @@ void GeneratorImpl::EmitInterpolationQualifiers(
for (auto* attr : attributes) {
if (auto* interpolate = attr->As<ast::InterpolateAttribute>()) {
switch (interpolate->type) {
case ast::InterpolationType::kPerspective:
case ast::InterpolationType::kLinear:
case ast::InterpolationType::kUndefined:
case builtin::InterpolationType::kPerspective:
case builtin::InterpolationType::kLinear:
case builtin::InterpolationType::kUndefined:
break;
case ast::InterpolationType::kFlat:
case builtin::InterpolationType::kFlat:
out << "flat ";
break;
}
switch (interpolate->sampling) {
case ast::InterpolationSampling::kCentroid:
case builtin::InterpolationSampling::kCentroid:
out << "centroid ";
break;
case ast::InterpolationSampling::kSample:
case ast::InterpolationSampling::kCenter:
case ast::InterpolationSampling::kUndefined:
case builtin::InterpolationSampling::kSample:
case builtin::InterpolationSampling::kCenter:
case builtin::InterpolationSampling::kUndefined:
break;
}
}

View File

@ -3187,31 +3187,32 @@ std::string GeneratorImpl::builtin_to_attribute(builtin::BuiltinValue builtin) c
return "";
}
std::string GeneratorImpl::interpolation_to_modifiers(ast::InterpolationType type,
ast::InterpolationSampling sampling) const {
std::string GeneratorImpl::interpolation_to_modifiers(
builtin::InterpolationType type,
builtin::InterpolationSampling sampling) const {
std::string modifiers;
switch (type) {
case ast::InterpolationType::kPerspective:
case builtin::InterpolationType::kPerspective:
modifiers += "linear ";
break;
case ast::InterpolationType::kLinear:
case builtin::InterpolationType::kLinear:
modifiers += "noperspective ";
break;
case ast::InterpolationType::kFlat:
case builtin::InterpolationType::kFlat:
modifiers += "nointerpolation ";
break;
case ast::InterpolationType::kUndefined:
case builtin::InterpolationType::kUndefined:
break;
}
switch (sampling) {
case ast::InterpolationSampling::kCentroid:
case builtin::InterpolationSampling::kCentroid:
modifiers += "centroid ";
break;
case ast::InterpolationSampling::kSample:
case builtin::InterpolationSampling::kSample:
modifiers += "sample ";
break;
case ast::InterpolationSampling::kCenter:
case ast::InterpolationSampling::kUndefined:
case builtin::InterpolationSampling::kCenter:
case builtin::InterpolationSampling::kUndefined:
break;
}
return modifiers;

View File

@ -501,8 +501,8 @@ class GeneratorImpl : public TextGenerator {
/// @param type the interpolation type
/// @param sampling the interpolation sampling
/// @returns the string name of the attribute or blank on error
std::string interpolation_to_modifiers(ast::InterpolationType type,
ast::InterpolationSampling sampling) const;
std::string interpolation_to_modifiers(builtin::InterpolationType type,
builtin::InterpolationSampling sampling) const;
private:
enum class VarType { kIn, kOut };

View File

@ -1939,33 +1939,34 @@ std::string GeneratorImpl::builtin_to_attribute(builtin::BuiltinValue builtin) c
return "";
}
std::string GeneratorImpl::interpolation_to_attribute(ast::InterpolationType type,
ast::InterpolationSampling sampling) const {
std::string GeneratorImpl::interpolation_to_attribute(
builtin::InterpolationType type,
builtin::InterpolationSampling sampling) const {
std::string attr;
switch (sampling) {
case ast::InterpolationSampling::kCenter:
case builtin::InterpolationSampling::kCenter:
attr = "center_";
break;
case ast::InterpolationSampling::kCentroid:
case builtin::InterpolationSampling::kCentroid:
attr = "centroid_";
break;
case ast::InterpolationSampling::kSample:
case builtin::InterpolationSampling::kSample:
attr = "sample_";
break;
case ast::InterpolationSampling::kUndefined:
case builtin::InterpolationSampling::kUndefined:
break;
}
switch (type) {
case ast::InterpolationType::kPerspective:
case builtin::InterpolationType::kPerspective:
attr += "perspective";
break;
case ast::InterpolationType::kLinear:
case builtin::InterpolationType::kLinear:
attr += "no_perspective";
break;
case ast::InterpolationType::kFlat:
case builtin::InterpolationType::kFlat:
attr += "flat";
break;
case ast::InterpolationType::kUndefined:
case builtin::InterpolationType::kUndefined:
break;
}
return attr;

View File

@ -366,8 +366,8 @@ class GeneratorImpl : public TextGenerator {
/// @param type the interpolation type
/// @param sampling the interpolation sampling
/// @returns the string name of the attribute or blank on error
std::string interpolation_to_attribute(ast::InterpolationType type,
ast::InterpolationSampling sampling) const;
std::string interpolation_to_attribute(builtin::InterpolationType type,
builtin::InterpolationSampling sampling) const;
private:
// A pair of byte size and alignment `uint32_t`s.

View File

@ -4047,29 +4047,29 @@ SpvBuiltIn Builder::ConvertBuiltin(builtin::BuiltinValue builtin, builtin::Addre
}
void Builder::AddInterpolationDecorations(uint32_t id,
ast::InterpolationType type,
ast::InterpolationSampling sampling) {
builtin::InterpolationType type,
builtin::InterpolationSampling sampling) {
switch (type) {
case ast::InterpolationType::kLinear:
case builtin::InterpolationType::kLinear:
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationNoPerspective)});
break;
case ast::InterpolationType::kFlat:
case builtin::InterpolationType::kFlat:
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationFlat)});
break;
case ast::InterpolationType::kPerspective:
case ast::InterpolationType::kUndefined:
case builtin::InterpolationType::kPerspective:
case builtin::InterpolationType::kUndefined:
break;
}
switch (sampling) {
case ast::InterpolationSampling::kCentroid:
case builtin::InterpolationSampling::kCentroid:
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationCentroid)});
break;
case ast::InterpolationSampling::kSample:
case builtin::InterpolationSampling::kSample:
push_capability(SpvCapabilitySampleRateShading);
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationSample)});
break;
case ast::InterpolationSampling::kCenter:
case ast::InterpolationSampling::kUndefined:
case builtin::InterpolationSampling::kCenter:
case builtin::InterpolationSampling::kUndefined:
break;
}
}

View File

@ -221,8 +221,8 @@ class Builder {
/// @param type the interpolation type
/// @param sampling the interpolation sampling
void AddInterpolationDecorations(uint32_t id,
ast::InterpolationType type,
ast::InterpolationSampling sampling);
builtin::InterpolationType type,
builtin::InterpolationSampling sampling);
/// Generates the enabling of an extension. Emits an error and returns false if the extension is
/// not supported.

View File

@ -572,7 +572,7 @@ bool GeneratorImpl::EmitAttributes(std::ostream& out,
},
[&](const ast::InterpolateAttribute* interpolate) {
out << "interpolate(" << interpolate->type;
if (interpolate->sampling != ast::InterpolationSampling::kUndefined) {
if (interpolate->sampling != builtin::InterpolationSampling::kUndefined) {
out << ", " << interpolate->sampling;
}
out << ")";