Tint/Inspector: Add blend_src to entry points
This patch adds `blend_src` to the entry points for the validations
on the API side.
Bug: dawn:1709
Test: tint_unittests
Change-Id: I958020e43e26929a0a22485bb8600289c6906086
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/189100
Reviewed-by: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
diff --git a/src/tint/lang/wgsl/inspector/entry_point.h b/src/tint/lang/wgsl/inspector/entry_point.h
index 3709ade..3946e63 100644
--- a/src/tint/lang/wgsl/inspector/entry_point.h
+++ b/src/tint/lang/wgsl/inspector/entry_point.h
@@ -92,6 +92,8 @@
std::optional<uint32_t> location;
/// Value of the color attribute, if set.
std::optional<uint32_t> color;
+ /// Value of the blend_src attribute, if set.
+ std::optional<uint32_t> blend_src;
} attributes;
/// Scalar type that the variable is composed of.
ComponentType component_type = ComponentType::kUnknown;
diff --git a/src/tint/lang/wgsl/inspector/inspector.cc b/src/tint/lang/wgsl/inspector/inspector.cc
index d98ada7..9857271 100644
--- a/src/tint/lang/wgsl/inspector/inspector.cc
+++ b/src/tint/lang/wgsl/inspector/inspector.cc
@@ -49,6 +49,7 @@
#include "src/tint/lang/core/type/u32.h"
#include "src/tint/lang/core/type/vector.h"
#include "src/tint/lang/core/type/void.h"
+#include "src/tint/lang/wgsl/ast/blend_src_attribute.h"
#include "src/tint/lang/wgsl/ast/bool_literal_expression.h"
#include "src/tint/lang/wgsl/ast/call_expression.h"
#include "src/tint/lang/wgsl/ast/float_literal_expression.h"
@@ -613,6 +614,12 @@
std::tie(stage_variable.component_type, stage_variable.composition_type) =
CalculateComponentAndComposition(type);
+ if (auto* blend_src_attribute = ast::GetAttribute<ast::BlendSrcAttribute>(attributes)) {
+ TINT_ASSERT(blend_src_attribute->expr->Is<ast::IntLiteralExpression>());
+ stage_variable.attributes.blend_src = static_cast<uint32_t>(
+ blend_src_attribute->expr->As<ast::IntLiteralExpression>()->value);
+ }
+
stage_variable.attributes.location = location;
stage_variable.attributes.color = color;
diff --git a/src/tint/lang/wgsl/inspector/inspector_test.cc b/src/tint/lang/wgsl/inspector/inspector_test.cc
index 7468ccc..1a7c557 100644
--- a/src/tint/lang/wgsl/inspector/inspector_test.cc
+++ b/src/tint/lang/wgsl/inspector/inspector_test.cc
@@ -143,6 +143,8 @@
class InspectorGetEnableDirectivesTest : public InspectorRunner, public testing::Test {};
+class InspectorGetBlendSrcTest : public InspectorBuilder, public testing::Test {};
+
// This is a catch all for shaders that have demonstrated regressions/crashes in
// the wild.
class InspectorRegressionTest : public InspectorRunner, public testing::Test {};
@@ -4046,6 +4048,34 @@
}
}
+TEST_F(InspectorGetBlendSrcTest, Basic) {
+ Enable(wgsl::Extension::kChromiumInternalDualSourceBlending);
+
+ Structure("out_struct",
+ Vector{
+ Member("output_color", ty.vec4<f32>(), Vector{Location(0_u), BlendSrc(0_u)}),
+ Member("output_blend", ty.vec4<f32>(), Vector{Location(0_u), BlendSrc(1_u)}),
+ });
+
+ Func("ep_func", tint::Empty, ty("out_struct"),
+ Vector{
+ Decl(Var("out_var", ty("out_struct"))),
+ Return("out_var"),
+ },
+ Vector{
+ Stage(ast::PipelineStage::kFragment),
+ });
+
+ Inspector& inspector = Build();
+
+ auto result = inspector.GetEntryPoints();
+
+ ASSERT_EQ(1u, result.size());
+ ASSERT_EQ(2u, result[0].output_variables.size());
+ EXPECT_EQ(0u, result[0].output_variables[0].attributes.blend_src);
+ EXPECT_EQ(1u, result[0].output_variables[1].attributes.blend_src);
+}
+
} // namespace
static std::ostream& operator<<(std::ostream& out, const Inspector::TextureQueryType& ty) {