From eca0eaa0066245a836d20bd268068195502acb5a Mon Sep 17 00:00:00 2001 From: Idan Raiter Date: Wed, 12 Aug 2020 17:44:01 +0000 Subject: [PATCH] Find un-named entry points, change set number Finds entry points, and uses set 4 intentionally as it is bigger than the maximum set for users. Bug: dawn:480 Change-Id: I24f01d770ba43796233aeb40b3b6b2ae9b3c3663 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/26520 Reviewed-by: dan sinclair Commit-Queue: dan sinclair --- src/ast/transform/vertex_pulling_transform.cc | 10 +- src/ast/transform/vertex_pulling_transform.h | 8 ++ .../vertex_pulling_transform_test.cc | 105 ++++++++++++++++-- 3 files changed, 113 insertions(+), 10 deletions(-) diff --git a/src/ast/transform/vertex_pulling_transform.cc b/src/ast/transform/vertex_pulling_transform.cc index 528c7e57f7..9f2fe3da2c 100644 --- a/src/ast/transform/vertex_pulling_transform.cc +++ b/src/ast/transform/vertex_pulling_transform.cc @@ -65,6 +65,10 @@ void VertexPullingTransform::SetEntryPoint(std::string entry_point) { entry_point_name_ = std::move(entry_point); } +void VertexPullingTransform::SetPullingBufferBindingSet(uint32_t number) { + pulling_set_ = number; +} + bool VertexPullingTransform::Run() { // Check SetVertexState was called if (vertex_state_ == nullptr) { @@ -75,7 +79,9 @@ bool VertexPullingTransform::Run() { // Find entry point EntryPoint* entry_point = nullptr; for (const auto& entry : mod_->entry_points()) { - if (entry->name() == entry_point_name_) { + if (entry->name() == entry_point_name_ || + (entry->name().empty() && + entry->function_name() == entry_point_name_)) { entry_point = entry.get(); break; } @@ -247,7 +253,7 @@ void VertexPullingTransform::AddVertexStorageBuffers() { // Add decorations VariableDecorationList decorations; decorations.push_back(std::make_unique(i)); - decorations.push_back(std::make_unique(0)); + decorations.push_back(std::make_unique(pulling_set_)); var->set_decorations(std::move(decorations)); mod_->AddGlobalVariable(std::move(var)); diff --git a/src/ast/transform/vertex_pulling_transform.h b/src/ast/transform/vertex_pulling_transform.h index 4ad6321381..d81b1cde81 100644 --- a/src/ast/transform/vertex_pulling_transform.h +++ b/src/ast/transform/vertex_pulling_transform.h @@ -145,6 +145,11 @@ class VertexPullingTransform { /// @param entry_point the vertex stage entry point void SetEntryPoint(std::string entry_point); + /// Sets the "set" we will put all our vertex buffers into (as storage + /// buffers) + /// @param number the set number we will use + void SetPullingBufferBindingSet(uint32_t number); + /// @returns true if the transformation was successful bool Run(); @@ -242,6 +247,9 @@ class VertexPullingTransform { std::string vertex_index_name_; std::string instance_index_name_; + // Default to 4 as it is past the limits of user-accessible sets + uint32_t pulling_set_ = 4u; + std::unordered_map location_to_var_; std::unique_ptr vertex_state_; }; diff --git a/src/ast/transform/vertex_pulling_transform_test.cc b/src/ast/transform/vertex_pulling_transform_test.cc index cafefda2ab..8f41ecf565 100644 --- a/src/ast/transform/vertex_pulling_transform_test.cc +++ b/src/ast/transform/vertex_pulling_transform_test.cc @@ -121,6 +121,14 @@ TEST_F(VertexPullingTransformTest, BasicModule) { EXPECT_TRUE(transform()->Run()); } +TEST_F(VertexPullingTransformTest, EntryPointUsingFunctionName) { + InitBasicModule(); + mod()->entry_points()[0]->set_name(""); + InitTransform({}); + transform()->SetEntryPoint("vtx_main"); + EXPECT_TRUE(transform()->Run()); +} + TEST_F(VertexPullingTransformTest, OneAttribute) { InitBasicModule(); @@ -148,7 +156,7 @@ TEST_F(VertexPullingTransformTest, OneAttribute) { DecoratedVariable{ Decorations{ BindingDecoration{0} - SetDecoration{0} + SetDecoration{4} } tint_pulling_vertex_buffer_0 storage_buffer @@ -229,7 +237,7 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) { DecoratedVariable{ Decorations{ BindingDecoration{0} - SetDecoration{0} + SetDecoration{4} } tint_pulling_vertex_buffer_0 storage_buffer @@ -282,6 +290,87 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) { mod()->to_str()); } +TEST_F(VertexPullingTransformTest, OneAttributeDifferentOutputSet) { + InitBasicModule(); + + type::F32Type f32; + AddVertexInputVariable(0, "var_a", &f32); + + InitTransform({{{4, InputStepMode::kVertex, {{VertexFormat::kF32, 0, 0}}}}}); + transform()->SetPullingBufferBindingSet(5); + + EXPECT_TRUE(transform()->Run()); + + EXPECT_EQ(R"(Module{ + Variable{ + var_a + private + __f32 + } + DecoratedVariable{ + Decorations{ + BuiltinDecoration{vertex_idx} + } + tint_pulling_vertex_index + in + __i32 + } + DecoratedVariable{ + Decorations{ + BindingDecoration{0} + SetDecoration{5} + } + tint_pulling_vertex_buffer_0 + storage_buffer + __struct_ + } + EntryPoint{vertex as main = vtx_main} + Function vtx_main -> __void + () + { + Block{ + VariableDeclStatement{ + Variable{ + tint_pulling_pos + function + __i32 + } + } + Assignment{ + Identifier{tint_pulling_pos} + Binary{ + Binary{ + Identifier{tint_pulling_vertex_index} + multiply + ScalarConstructor{4} + } + add + ScalarConstructor{0} + } + } + Assignment{ + Identifier{var_a} + As<__f32>{ + ArrayAccessor{ + MemberAccessor{ + Identifier{tint_pulling_vertex_buffer_0} + Identifier{data} + } + Binary{ + Identifier{tint_pulling_pos} + divide + ScalarConstructor{4} + } + } + } + } + } + } +} +)", + mod()->to_str()); +} + // We expect the transform to use an existing builtin variables if it finds them TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { InitBasicModule(); @@ -353,7 +442,7 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { DecoratedVariable{ Decorations{ BindingDecoration{0} - SetDecoration{0} + SetDecoration{4} } tint_pulling_vertex_buffer_0 storage_buffer @@ -362,7 +451,7 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { DecoratedVariable{ Decorations{ BindingDecoration{1} - SetDecoration{0} + SetDecoration{4} } tint_pulling_vertex_buffer_1 storage_buffer @@ -481,7 +570,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) { DecoratedVariable{ Decorations{ BindingDecoration{0} - SetDecoration{0} + SetDecoration{4} } tint_pulling_vertex_buffer_0 storage_buffer @@ -667,7 +756,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { DecoratedVariable{ Decorations{ BindingDecoration{0} - SetDecoration{0} + SetDecoration{4} } tint_pulling_vertex_buffer_0 storage_buffer @@ -676,7 +765,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { DecoratedVariable{ Decorations{ BindingDecoration{1} - SetDecoration{0} + SetDecoration{4} } tint_pulling_vertex_buffer_1 storage_buffer @@ -685,7 +774,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) { DecoratedVariable{ Decorations{ BindingDecoration{2} - SetDecoration{0} + SetDecoration{4} } tint_pulling_vertex_buffer_2 storage_buffer