tint/ast: Generate interpolate_attribute.[h|cc]
Emits all the enum info from the single-source-of-truth `intrinsics.def` file Change-Id: Ie9deba9e64927945133027cf243777944119ea41 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/105327 Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
c1af0f5005
commit
f9ed9d3a63
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
namespace tint::ast {
|
namespace tint::ast {
|
||||||
|
|
||||||
/// Storage class of a given pointer.
|
/// Builtin value defined with `@builtin(<name>)`.
|
||||||
enum class BuiltinValue {
|
enum class BuiltinValue {
|
||||||
kInvalid,
|
kInvalid,
|
||||||
kFragDepth,
|
kFragDepth,
|
||||||
|
|
|
@ -18,7 +18,7 @@ See:
|
||||||
|
|
||||||
namespace tint::ast {
|
namespace tint::ast {
|
||||||
|
|
||||||
/// Storage class of a given pointer.
|
/// Builtin value defined with `@builtin(<name>)`.
|
||||||
{{ Eval "DeclareEnum" $enum}}
|
{{ Eval "DeclareEnum" $enum}}
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -12,6 +12,14 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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 "src/tint/ast/interpolate_attribute.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -41,44 +49,64 @@ const InterpolateAttribute* InterpolateAttribute::Clone(CloneContext* ctx) const
|
||||||
return ctx->dst->create<InterpolateAttribute>(src, type, sampling);
|
return ctx->dst->create<InterpolateAttribute>(src, type, sampling);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, InterpolationType type) {
|
/// ParseInterpolationType parses a InterpolationType from a string.
|
||||||
switch (type) {
|
/// @param str the string to parse
|
||||||
case InterpolationType::kPerspective: {
|
/// @returns the parsed enum, or InterpolationType::kInvalid if the string could not be parsed.
|
||||||
out << "perspective";
|
InterpolationType ParseInterpolationType(std::string_view str) {
|
||||||
break;
|
if (str == "flat") {
|
||||||
}
|
return InterpolationType::kFlat;
|
||||||
case InterpolationType::kLinear: {
|
|
||||||
out << "linear";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case InterpolationType::kFlat: {
|
|
||||||
out << "flat";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return out;
|
if (str == "linear") {
|
||||||
|
return InterpolationType::kLinear;
|
||||||
|
}
|
||||||
|
if (str == "perspective") {
|
||||||
|
return InterpolationType::kPerspective;
|
||||||
|
}
|
||||||
|
return InterpolationType::kInvalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& out, InterpolationSampling sampling) {
|
std::ostream& operator<<(std::ostream& out, InterpolationType value) {
|
||||||
switch (sampling) {
|
switch (value) {
|
||||||
case InterpolationSampling::kNone: {
|
case InterpolationType::kInvalid:
|
||||||
out << "none";
|
return out << "invalid";
|
||||||
break;
|
case InterpolationType::kFlat:
|
||||||
}
|
return out << "flat";
|
||||||
case InterpolationSampling::kCenter: {
|
case InterpolationType::kLinear:
|
||||||
out << "center";
|
return out << "linear";
|
||||||
break;
|
case InterpolationType::kPerspective:
|
||||||
}
|
return out << "perspective";
|
||||||
case InterpolationSampling::kCentroid: {
|
|
||||||
out << "centroid";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case InterpolationSampling::kSample: {
|
|
||||||
out << "sample";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return out;
|
return out << "<unknown>";
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ParseInterpolationSampling parses a InterpolationSampling from a string.
|
||||||
|
/// @param str the string to parse
|
||||||
|
/// @returns the parsed enum, or InterpolationSampling::kInvalid 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::kInvalid;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& out, InterpolationSampling value) {
|
||||||
|
switch (value) {
|
||||||
|
case InterpolationSampling::kInvalid:
|
||||||
|
return out << "invalid";
|
||||||
|
case InterpolationSampling::kCenter:
|
||||||
|
return out << "center";
|
||||||
|
case InterpolationSampling::kCentroid:
|
||||||
|
return out << "centroid";
|
||||||
|
case InterpolationSampling::kSample:
|
||||||
|
return out << "sample";
|
||||||
|
}
|
||||||
|
return out << "<unknown>";
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
{{- /*
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
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
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2021 The Tint Authors.
|
// Copyright 2022 The Tint Authors.
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
|
@ -12,6 +12,14 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// 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_
|
#ifndef SRC_TINT_AST_INTERPOLATE_ATTRIBUTE_H_
|
||||||
#define SRC_TINT_AST_INTERPOLATE_ATTRIBUTE_H_
|
#define SRC_TINT_AST_INTERPOLATE_ATTRIBUTE_H_
|
||||||
|
|
||||||
|
@ -23,10 +31,52 @@
|
||||||
namespace tint::ast {
|
namespace tint::ast {
|
||||||
|
|
||||||
/// The interpolation type.
|
/// The interpolation type.
|
||||||
enum class InterpolationType { kPerspective, kLinear, kFlat };
|
enum class InterpolationType {
|
||||||
|
kInvalid,
|
||||||
|
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::kInvalid if the string could not be parsed.
|
||||||
|
InterpolationType ParseInterpolationType(std::string_view str);
|
||||||
|
|
||||||
|
constexpr const char* kInterpolationTypeStrings[] = {
|
||||||
|
"flat",
|
||||||
|
"linear",
|
||||||
|
"perspective",
|
||||||
|
};
|
||||||
|
|
||||||
/// The interpolation sampling.
|
/// The interpolation sampling.
|
||||||
enum class InterpolationSampling { kNone = -1, kCenter, kCentroid, kSample };
|
enum class InterpolationSampling {
|
||||||
|
kInvalid,
|
||||||
|
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::kInvalid if the string could not be parsed.
|
||||||
|
InterpolationSampling ParseInterpolationSampling(std::string_view str);
|
||||||
|
|
||||||
|
constexpr const char* kInterpolationSamplingStrings[] = {
|
||||||
|
"center",
|
||||||
|
"centroid",
|
||||||
|
"sample",
|
||||||
|
};
|
||||||
|
|
||||||
/// An interpolate attribute
|
/// An interpolate attribute
|
||||||
class InterpolateAttribute final : public Castable<InterpolateAttribute, Attribute> {
|
class InterpolateAttribute final : public Castable<InterpolateAttribute, Attribute> {
|
||||||
|
@ -60,16 +110,6 @@ class InterpolateAttribute final : public Castable<InterpolateAttribute, Attribu
|
||||||
const InterpolationSampling sampling;
|
const InterpolationSampling sampling;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// @param out the std::ostream to write to
|
|
||||||
/// @param type the interpolation type
|
|
||||||
/// @return the std::ostream so calls can be chained
|
|
||||||
std::ostream& operator<<(std::ostream& out, InterpolationType type);
|
|
||||||
|
|
||||||
/// @param out the std::ostream to write to
|
|
||||||
/// @param sampling the interpolation sampling
|
|
||||||
/// @return the std::ostream so calls can be chained
|
|
||||||
std::ostream& operator<<(std::ostream& out, InterpolationSampling sampling);
|
|
||||||
|
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
|
||||||
#endif // SRC_TINT_AST_INTERPOLATE_ATTRIBUTE_H_
|
#endif // SRC_TINT_AST_INTERPOLATE_ATTRIBUTE_H_
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
{{- /*
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
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_
|
|
@ -35,32 +35,5 @@ EntryPoint::EntryPoint(EntryPoint&) = default;
|
||||||
EntryPoint::EntryPoint(EntryPoint&&) = default;
|
EntryPoint::EntryPoint(EntryPoint&&) = default;
|
||||||
EntryPoint::~EntryPoint() = default;
|
EntryPoint::~EntryPoint() = default;
|
||||||
|
|
||||||
InterpolationType ASTToInspectorInterpolationType(ast::InterpolationType ast_type) {
|
|
||||||
switch (ast_type) {
|
|
||||||
case ast::InterpolationType::kPerspective:
|
|
||||||
return InterpolationType::kPerspective;
|
|
||||||
case ast::InterpolationType::kLinear:
|
|
||||||
return InterpolationType::kLinear;
|
|
||||||
case ast::InterpolationType::kFlat:
|
|
||||||
return InterpolationType::kFlat;
|
|
||||||
}
|
|
||||||
|
|
||||||
return InterpolationType::kUnknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
InterpolationSampling ASTToInspectorInterpolationSampling(ast::InterpolationSampling sampling) {
|
|
||||||
switch (sampling) {
|
|
||||||
case ast::InterpolationSampling::kNone:
|
|
||||||
return InterpolationSampling::kNone;
|
|
||||||
case ast::InterpolationSampling::kCenter:
|
|
||||||
return InterpolationSampling::kCenter;
|
|
||||||
case ast::InterpolationSampling::kCentroid:
|
|
||||||
return InterpolationSampling::kCentroid;
|
|
||||||
case ast::InterpolationSampling::kSample:
|
|
||||||
return InterpolationSampling::kSample;
|
|
||||||
}
|
|
||||||
|
|
||||||
return InterpolationSampling::kUnknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace tint::inspector
|
} // namespace tint::inspector
|
||||||
|
|
|
@ -84,17 +84,6 @@ struct StageVariable {
|
||||||
InterpolationSampling interpolation_sampling = InterpolationSampling::kUnknown;
|
InterpolationSampling interpolation_sampling = InterpolationSampling::kUnknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Convert from internal ast::InterpolationType to public ::InterpolationType.
|
|
||||||
/// @param ast_type internal value to convert from
|
|
||||||
/// @returns the publicly visible equivalent
|
|
||||||
InterpolationType ASTToInspectorInterpolationType(ast::InterpolationType ast_type);
|
|
||||||
|
|
||||||
/// Convert from internal ast::InterpolationSampling to public
|
|
||||||
/// ::InterpolationSampling
|
|
||||||
/// @param sampling internal value to convert from
|
|
||||||
/// @returns the publicly visible equivalent
|
|
||||||
InterpolationSampling ASTToInspectorInterpolationSampling(ast::InterpolationSampling sampling);
|
|
||||||
|
|
||||||
/// Reflection data about an override variable referenced by an entry point
|
/// Reflection data about an override variable referenced by an entry point
|
||||||
struct Override {
|
struct Override {
|
||||||
/// Name of the override
|
/// Name of the override
|
||||||
|
|
|
@ -117,14 +117,45 @@ std::tuple<InterpolationType, InterpolationSampling> CalculateInterpolationData(
|
||||||
return {InterpolationType::kPerspective, InterpolationSampling::kCenter};
|
return {InterpolationType::kPerspective, InterpolationSampling::kCenter};
|
||||||
}
|
}
|
||||||
|
|
||||||
auto interpolation_type = interpolation_attribute->type;
|
auto ast_interpolation_type = interpolation_attribute->type;
|
||||||
auto sampling = interpolation_attribute->sampling;
|
auto ast_sampling_type = interpolation_attribute->sampling;
|
||||||
if (interpolation_type != ast::InterpolationType::kFlat &&
|
if (ast_interpolation_type != ast::InterpolationType::kFlat &&
|
||||||
sampling == ast::InterpolationSampling::kNone) {
|
ast_sampling_type == ast::InterpolationSampling::kInvalid) {
|
||||||
sampling = ast::InterpolationSampling::kCenter;
|
ast_sampling_type = ast::InterpolationSampling::kCenter;
|
||||||
}
|
}
|
||||||
return {ASTToInspectorInterpolationType(interpolation_type),
|
|
||||||
ASTToInspectorInterpolationSampling(sampling)};
|
auto interpolation_type = InterpolationType::kUnknown;
|
||||||
|
switch (ast_interpolation_type) {
|
||||||
|
case ast::InterpolationType::kPerspective:
|
||||||
|
interpolation_type = InterpolationType::kPerspective;
|
||||||
|
break;
|
||||||
|
case ast::InterpolationType::kLinear:
|
||||||
|
interpolation_type = InterpolationType::kLinear;
|
||||||
|
break;
|
||||||
|
case ast::InterpolationType::kFlat:
|
||||||
|
interpolation_type = InterpolationType::kFlat;
|
||||||
|
break;
|
||||||
|
case ast::InterpolationType::kInvalid:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto sampling_type = InterpolationSampling::kUnknown;
|
||||||
|
switch (ast_sampling_type) {
|
||||||
|
case ast::InterpolationSampling::kInvalid:
|
||||||
|
sampling_type = InterpolationSampling::kNone;
|
||||||
|
break;
|
||||||
|
case ast::InterpolationSampling::kCenter:
|
||||||
|
sampling_type = InterpolationSampling::kCenter;
|
||||||
|
break;
|
||||||
|
case ast::InterpolationSampling::kCentroid:
|
||||||
|
sampling_type = InterpolationSampling::kCentroid;
|
||||||
|
break;
|
||||||
|
case ast::InterpolationSampling::kSample:
|
||||||
|
sampling_type = InterpolationSampling::kSample;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {interpolation_type, sampling_type};
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -1250,7 +1250,7 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
ast::InterpolationType::kPerspective, ast::InterpolationSampling::kSample,
|
ast::InterpolationType::kPerspective, ast::InterpolationSampling::kSample,
|
||||||
InterpolationType::kPerspective, InterpolationSampling::kSample},
|
InterpolationType::kPerspective, InterpolationSampling::kSample},
|
||||||
InspectorGetEntryPointInterpolateTestParams{
|
InspectorGetEntryPointInterpolateTestParams{
|
||||||
ast::InterpolationType::kPerspective, ast::InterpolationSampling::kNone,
|
ast::InterpolationType::kPerspective, ast::InterpolationSampling::kInvalid,
|
||||||
InterpolationType::kPerspective, InterpolationSampling::kCenter},
|
InterpolationType::kPerspective, InterpolationSampling::kCenter},
|
||||||
InspectorGetEntryPointInterpolateTestParams{
|
InspectorGetEntryPointInterpolateTestParams{
|
||||||
ast::InterpolationType::kLinear, ast::InterpolationSampling::kCenter,
|
ast::InterpolationType::kLinear, ast::InterpolationSampling::kCenter,
|
||||||
|
@ -1262,10 +1262,10 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
ast::InterpolationType::kLinear, ast::InterpolationSampling::kSample,
|
ast::InterpolationType::kLinear, ast::InterpolationSampling::kSample,
|
||||||
InterpolationType::kLinear, InterpolationSampling::kSample},
|
InterpolationType::kLinear, InterpolationSampling::kSample},
|
||||||
InspectorGetEntryPointInterpolateTestParams{
|
InspectorGetEntryPointInterpolateTestParams{
|
||||||
ast::InterpolationType::kLinear, ast::InterpolationSampling::kNone,
|
ast::InterpolationType::kLinear, ast::InterpolationSampling::kInvalid,
|
||||||
InterpolationType::kLinear, InterpolationSampling::kCenter},
|
InterpolationType::kLinear, InterpolationSampling::kCenter},
|
||||||
InspectorGetEntryPointInterpolateTestParams{
|
InspectorGetEntryPointInterpolateTestParams{
|
||||||
ast::InterpolationType::kFlat, ast::InterpolationSampling::kNone,
|
ast::InterpolationType::kFlat, ast::InterpolationSampling::kInvalid,
|
||||||
InterpolationType::kFlat, InterpolationSampling::kNone}));
|
InterpolationType::kFlat, InterpolationSampling::kNone}));
|
||||||
|
|
||||||
TEST_F(InspectorGetOverrideDefaultValuesTest, Bool) {
|
TEST_F(InspectorGetOverrideDefaultValuesTest, Bool) {
|
||||||
|
|
|
@ -94,6 +94,20 @@ enum texel_format {
|
||||||
rgba32float
|
rgba32float
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://www.w3.org/TR/WGSL/#interpolation
|
||||||
|
enum interpolation_type {
|
||||||
|
perspective
|
||||||
|
linear
|
||||||
|
flat
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://www.w3.org/TR/WGSL/#interpolation
|
||||||
|
enum interpolation_sampling {
|
||||||
|
center
|
||||||
|
centroid
|
||||||
|
sample
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// WGSL primitive types //
|
// WGSL primitive types //
|
||||||
// Types may be decorated with @precedence(N) to prioritize which type //
|
// Types may be decorated with @precedence(N) to prioritize which type //
|
||||||
|
|
|
@ -2909,7 +2909,7 @@ class ProgramBuilder {
|
||||||
const ast::InterpolateAttribute* Interpolate(
|
const ast::InterpolateAttribute* Interpolate(
|
||||||
const Source& source,
|
const Source& source,
|
||||||
ast::InterpolationType type,
|
ast::InterpolationType type,
|
||||||
ast::InterpolationSampling sampling = ast::InterpolationSampling::kNone) {
|
ast::InterpolationSampling sampling = ast::InterpolationSampling::kInvalid) {
|
||||||
return create<ast::InterpolateAttribute>(source, type, sampling);
|
return create<ast::InterpolateAttribute>(source, type, sampling);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2919,7 +2919,7 @@ class ProgramBuilder {
|
||||||
/// @returns the interpolate attribute pointer
|
/// @returns the interpolate attribute pointer
|
||||||
const ast::InterpolateAttribute* Interpolate(
|
const ast::InterpolateAttribute* Interpolate(
|
||||||
ast::InterpolationType type,
|
ast::InterpolationType type,
|
||||||
ast::InterpolationSampling sampling = ast::InterpolationSampling::kNone) {
|
ast::InterpolationSampling sampling = ast::InterpolationSampling::kInvalid) {
|
||||||
return create<ast::InterpolateAttribute>(source_, type, sampling);
|
return create<ast::InterpolateAttribute>(source_, type, sampling);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1749,7 +1749,7 @@ bool ParserImpl::ConvertPipelineDecorations(const Type* store_type,
|
||||||
AttributeList* attributes) {
|
AttributeList* attributes) {
|
||||||
// Vulkan defaults to perspective-correct interpolation.
|
// Vulkan defaults to perspective-correct interpolation.
|
||||||
ast::InterpolationType type = ast::InterpolationType::kPerspective;
|
ast::InterpolationType type = ast::InterpolationType::kPerspective;
|
||||||
ast::InterpolationSampling sampling = ast::InterpolationSampling::kNone;
|
ast::InterpolationSampling sampling = ast::InterpolationSampling::kInvalid;
|
||||||
|
|
||||||
for (const auto& deco : decorations) {
|
for (const auto& deco : decorations) {
|
||||||
TINT_ASSERT(Reader, deco.size() > 0);
|
TINT_ASSERT(Reader, deco.size() > 0);
|
||||||
|
@ -1804,7 +1804,7 @@ bool ParserImpl::ConvertPipelineDecorations(const Type* store_type,
|
||||||
|
|
||||||
// Apply interpolation.
|
// Apply interpolation.
|
||||||
if (type == ast::InterpolationType::kPerspective &&
|
if (type == ast::InterpolationType::kPerspective &&
|
||||||
sampling == ast::InterpolationSampling::kNone) {
|
sampling == ast::InterpolationSampling::kInvalid) {
|
||||||
// This is the default. Don't add a decoration.
|
// This is the default. Don't add a decoration.
|
||||||
} else {
|
} else {
|
||||||
attributes->Push(create<ast::InterpolateAttribute>(type, sampling));
|
attributes->Push(create<ast::InterpolateAttribute>(type, sampling));
|
||||||
|
|
|
@ -3554,7 +3554,7 @@ Maybe<const ast::Attribute*> ParserImpl::attribute() {
|
||||||
return Failure::kErrored;
|
return Failure::kErrored;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast::InterpolationSampling sampling = ast::InterpolationSampling::kNone;
|
ast::InterpolationSampling sampling = ast::InterpolationSampling::kInvalid;
|
||||||
if (match(Token::Type::kComma)) {
|
if (match(Token::Type::kComma)) {
|
||||||
if (!peek_is(Token::Type::kParenRight)) {
|
if (!peek_is(Token::Type::kParenRight)) {
|
||||||
auto sample = expect_interpolation_sample_name();
|
auto sample = expect_interpolation_sample_name();
|
||||||
|
|
|
@ -227,7 +227,7 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Flat) {
|
||||||
|
|
||||||
auto* interp = var_attr->As<ast::InterpolateAttribute>();
|
auto* interp = var_attr->As<ast::InterpolateAttribute>();
|
||||||
EXPECT_EQ(interp->type, ast::InterpolationType::kFlat);
|
EXPECT_EQ(interp->type, ast::InterpolationType::kFlat);
|
||||||
EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kNone);
|
EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kInvalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, Attribute_Interpolate_Single_TrailingComma) {
|
TEST_F(ParserImplTest, Attribute_Interpolate_Single_TrailingComma) {
|
||||||
|
@ -243,7 +243,7 @@ TEST_F(ParserImplTest, Attribute_Interpolate_Single_TrailingComma) {
|
||||||
|
|
||||||
auto* interp = var_attr->As<ast::InterpolateAttribute>();
|
auto* interp = var_attr->As<ast::InterpolateAttribute>();
|
||||||
EXPECT_EQ(interp->type, ast::InterpolationType::kFlat);
|
EXPECT_EQ(interp->type, ast::InterpolationType::kFlat);
|
||||||
EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kNone);
|
EXPECT_EQ(interp->sampling, ast::InterpolationSampling::kInvalid);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserImplTest, Attribute_Interpolate_Single_DoubleTrailingComma) {
|
TEST_F(ParserImplTest, Attribute_Interpolate_Single_DoubleTrailingComma) {
|
||||||
|
|
|
@ -1386,16 +1386,16 @@ INSTANTIATE_TEST_SUITE_P(
|
||||||
ResolverAttributeValidationTest,
|
ResolverAttributeValidationTest,
|
||||||
InterpolateParameterTest,
|
InterpolateParameterTest,
|
||||||
testing::Values(
|
testing::Values(
|
||||||
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kNone, true},
|
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kInvalid, true},
|
||||||
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kCenter, true},
|
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kCenter, true},
|
||||||
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kCentroid, true},
|
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kCentroid, true},
|
||||||
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kSample, true},
|
Params{ast::InterpolationType::kPerspective, ast::InterpolationSampling::kSample, true},
|
||||||
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kNone, true},
|
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kInvalid, true},
|
||||||
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kCenter, true},
|
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kCenter, true},
|
||||||
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kCentroid, true},
|
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kCentroid, true},
|
||||||
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kSample, true},
|
Params{ast::InterpolationType::kLinear, ast::InterpolationSampling::kSample, true},
|
||||||
// flat interpolation must not have a sampling type
|
// flat interpolation must not have a sampling type
|
||||||
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kNone, true},
|
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kInvalid, true},
|
||||||
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kCenter, false},
|
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kCenter, false},
|
||||||
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kCentroid, false},
|
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kCentroid, false},
|
||||||
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kSample, false}));
|
Params{ast::InterpolationType::kFlat, ast::InterpolationSampling::kSample, false}));
|
||||||
|
@ -1443,7 +1443,7 @@ TEST_F(InterpolateTest, MissingLocationAttribute_Parameter) {
|
||||||
utils::Vector{
|
utils::Vector{
|
||||||
Builtin(ast::BuiltinValue::kPosition),
|
Builtin(ast::BuiltinValue::kPosition),
|
||||||
Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
|
Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
|
||||||
ast::InterpolationSampling::kNone),
|
ast::InterpolationSampling::kInvalid),
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
ty.void_(), utils::Empty,
|
ty.void_(), utils::Empty,
|
||||||
|
@ -1467,7 +1467,7 @@ TEST_F(InterpolateTest, MissingLocationAttribute_ReturnType) {
|
||||||
utils::Vector{
|
utils::Vector{
|
||||||
Builtin(ast::BuiltinValue::kPosition),
|
Builtin(ast::BuiltinValue::kPosition),
|
||||||
Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
|
Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
|
||||||
ast::InterpolationSampling::kNone),
|
ast::InterpolationSampling::kInvalid),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_FALSE(r()->Resolve());
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
@ -1480,7 +1480,7 @@ TEST_F(InterpolateTest, MissingLocationAttribute_Struct) {
|
||||||
utils::Vector{
|
utils::Vector{
|
||||||
Member("a", ty.f32(),
|
Member("a", ty.f32(),
|
||||||
utils::Vector{Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
|
utils::Vector{Interpolate(Source{{12, 34}}, ast::InterpolationType::kFlat,
|
||||||
ast::InterpolationSampling::kNone)}),
|
ast::InterpolationSampling::kInvalid)}),
|
||||||
});
|
});
|
||||||
|
|
||||||
EXPECT_FALSE(r()->Resolve());
|
EXPECT_FALSE(r()->Resolve());
|
||||||
|
|
|
@ -1026,7 +1026,7 @@ bool Validator::InterpolateAttribute(const ast::InterpolateAttribute* attr,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attr->type == ast::InterpolationType::kFlat &&
|
if (attr->type == ast::InterpolationType::kFlat &&
|
||||||
attr->sampling != ast::InterpolationSampling::kNone) {
|
attr->sampling != ast::InterpolationSampling::kInvalid) {
|
||||||
AddError("flat interpolation attribute must not have a sampling parameter", attr->source);
|
AddError("flat interpolation attribute must not have a sampling parameter", attr->source);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -223,7 +223,7 @@ struct CanonicalizeEntryPointIO::State {
|
||||||
(ast::HasAttribute<ast::LocationAttribute>(attributes) ||
|
(ast::HasAttribute<ast::LocationAttribute>(attributes) ||
|
||||||
cfg.shader_style == ShaderStyle::kSpirv)) {
|
cfg.shader_style == ShaderStyle::kSpirv)) {
|
||||||
attributes.Push(ctx.dst->Interpolate(ast::InterpolationType::kFlat,
|
attributes.Push(ctx.dst->Interpolate(ast::InterpolationType::kFlat,
|
||||||
ast::InterpolationSampling::kNone));
|
ast::InterpolationSampling::kInvalid));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable validation for use of the `input` address space.
|
// Disable validation for use of the `input` address space.
|
||||||
|
@ -292,7 +292,7 @@ struct CanonicalizeEntryPointIO::State {
|
||||||
ast::HasAttribute<ast::LocationAttribute>(attributes) &&
|
ast::HasAttribute<ast::LocationAttribute>(attributes) &&
|
||||||
!ast::HasAttribute<ast::InterpolateAttribute>(attributes)) {
|
!ast::HasAttribute<ast::InterpolateAttribute>(attributes)) {
|
||||||
attributes.Push(ctx.dst->Interpolate(ast::InterpolationType::kFlat,
|
attributes.Push(ctx.dst->Interpolate(ast::InterpolationType::kFlat,
|
||||||
ast::InterpolationSampling::kNone));
|
ast::InterpolationSampling::kInvalid));
|
||||||
}
|
}
|
||||||
|
|
||||||
// In GLSL, if it's a builtin, override the name with the
|
// In GLSL, if it's a builtin, override the name with the
|
||||||
|
|
|
@ -2049,6 +2049,7 @@ void GeneratorImpl::EmitInterpolationQualifiers(
|
||||||
switch (interpolate->type) {
|
switch (interpolate->type) {
|
||||||
case ast::InterpolationType::kPerspective:
|
case ast::InterpolationType::kPerspective:
|
||||||
case ast::InterpolationType::kLinear:
|
case ast::InterpolationType::kLinear:
|
||||||
|
case ast::InterpolationType::kInvalid:
|
||||||
break;
|
break;
|
||||||
case ast::InterpolationType::kFlat:
|
case ast::InterpolationType::kFlat:
|
||||||
out << "flat ";
|
out << "flat ";
|
||||||
|
@ -2060,7 +2061,7 @@ void GeneratorImpl::EmitInterpolationQualifiers(
|
||||||
break;
|
break;
|
||||||
case ast::InterpolationSampling::kSample:
|
case ast::InterpolationSampling::kSample:
|
||||||
case ast::InterpolationSampling::kCenter:
|
case ast::InterpolationSampling::kCenter:
|
||||||
case ast::InterpolationSampling::kNone:
|
case ast::InterpolationSampling::kInvalid:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3010,6 +3010,8 @@ std::string GeneratorImpl::interpolation_to_modifiers(ast::InterpolationType typ
|
||||||
case ast::InterpolationType::kFlat:
|
case ast::InterpolationType::kFlat:
|
||||||
modifiers += "nointerpolation ";
|
modifiers += "nointerpolation ";
|
||||||
break;
|
break;
|
||||||
|
case ast::InterpolationType::kInvalid:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
switch (sampling) {
|
switch (sampling) {
|
||||||
case ast::InterpolationSampling::kCentroid:
|
case ast::InterpolationSampling::kCentroid:
|
||||||
|
@ -3019,7 +3021,7 @@ std::string GeneratorImpl::interpolation_to_modifiers(ast::InterpolationType typ
|
||||||
modifiers += "sample ";
|
modifiers += "sample ";
|
||||||
break;
|
break;
|
||||||
case ast::InterpolationSampling::kCenter:
|
case ast::InterpolationSampling::kCenter:
|
||||||
case ast::InterpolationSampling::kNone:
|
case ast::InterpolationSampling::kInvalid:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return modifiers;
|
return modifiers;
|
||||||
|
|
|
@ -1947,7 +1947,7 @@ std::string GeneratorImpl::interpolation_to_attribute(ast::InterpolationType typ
|
||||||
case ast::InterpolationSampling::kSample:
|
case ast::InterpolationSampling::kSample:
|
||||||
attr = "sample_";
|
attr = "sample_";
|
||||||
break;
|
break;
|
||||||
case ast::InterpolationSampling::kNone:
|
case ast::InterpolationSampling::kInvalid:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
@ -1960,6 +1960,8 @@ std::string GeneratorImpl::interpolation_to_attribute(ast::InterpolationType typ
|
||||||
case ast::InterpolationType::kFlat:
|
case ast::InterpolationType::kFlat:
|
||||||
attr += "flat";
|
attr += "flat";
|
||||||
break;
|
break;
|
||||||
|
case ast::InterpolationType::kInvalid:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return attr;
|
return attr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4088,6 +4088,7 @@ void Builder::AddInterpolationDecorations(uint32_t id,
|
||||||
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationFlat)});
|
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationFlat)});
|
||||||
break;
|
break;
|
||||||
case ast::InterpolationType::kPerspective:
|
case ast::InterpolationType::kPerspective:
|
||||||
|
case ast::InterpolationType::kInvalid:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
switch (sampling) {
|
switch (sampling) {
|
||||||
|
@ -4099,7 +4100,7 @@ void Builder::AddInterpolationDecorations(uint32_t id,
|
||||||
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationSample)});
|
push_annot(spv::Op::OpDecorate, {Operand(id), U32Operand(SpvDecorationSample)});
|
||||||
break;
|
break;
|
||||||
case ast::InterpolationSampling::kCenter:
|
case ast::InterpolationSampling::kCenter:
|
||||||
case ast::InterpolationSampling::kNone:
|
case ast::InterpolationSampling::kInvalid:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -769,7 +769,7 @@ bool GeneratorImpl::EmitAttributes(std::ostream& out,
|
||||||
},
|
},
|
||||||
[&](const ast::InterpolateAttribute* interpolate) {
|
[&](const ast::InterpolateAttribute* interpolate) {
|
||||||
out << "interpolate(" << interpolate->type;
|
out << "interpolate(" << interpolate->type;
|
||||||
if (interpolate->sampling != ast::InterpolationSampling::kNone) {
|
if (interpolate->sampling != ast::InterpolationSampling::kInvalid) {
|
||||||
out << ", " << interpolate->sampling;
|
out << ", " << interpolate->sampling;
|
||||||
}
|
}
|
||||||
out << ")";
|
out << ")";
|
||||||
|
|
Loading…
Reference in New Issue