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 <dsinclair@chromium.org>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Idan Raiter 2020-08-12 17:44:01 +00:00 committed by Commit Bot service account
parent ef6a4af7b5
commit eca0eaa006
3 changed files with 113 additions and 10 deletions

View File

@ -65,6 +65,10 @@ void VertexPullingTransform::SetEntryPoint(std::string entry_point) {
entry_point_name_ = std::move(entry_point); entry_point_name_ = std::move(entry_point);
} }
void VertexPullingTransform::SetPullingBufferBindingSet(uint32_t number) {
pulling_set_ = number;
}
bool VertexPullingTransform::Run() { bool VertexPullingTransform::Run() {
// Check SetVertexState was called // Check SetVertexState was called
if (vertex_state_ == nullptr) { if (vertex_state_ == nullptr) {
@ -75,7 +79,9 @@ bool VertexPullingTransform::Run() {
// Find entry point // Find entry point
EntryPoint* entry_point = nullptr; EntryPoint* entry_point = nullptr;
for (const auto& entry : mod_->entry_points()) { 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(); entry_point = entry.get();
break; break;
} }
@ -247,7 +253,7 @@ void VertexPullingTransform::AddVertexStorageBuffers() {
// Add decorations // Add decorations
VariableDecorationList decorations; VariableDecorationList decorations;
decorations.push_back(std::make_unique<BindingDecoration>(i)); decorations.push_back(std::make_unique<BindingDecoration>(i));
decorations.push_back(std::make_unique<SetDecoration>(0)); decorations.push_back(std::make_unique<SetDecoration>(pulling_set_));
var->set_decorations(std::move(decorations)); var->set_decorations(std::move(decorations));
mod_->AddGlobalVariable(std::move(var)); mod_->AddGlobalVariable(std::move(var));

View File

@ -145,6 +145,11 @@ class VertexPullingTransform {
/// @param entry_point the vertex stage entry point /// @param entry_point the vertex stage entry point
void SetEntryPoint(std::string 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 /// @returns true if the transformation was successful
bool Run(); bool Run();
@ -242,6 +247,9 @@ class VertexPullingTransform {
std::string vertex_index_name_; std::string vertex_index_name_;
std::string instance_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<uint32_t, Variable*> location_to_var_; std::unordered_map<uint32_t, Variable*> location_to_var_;
std::unique_ptr<VertexStateDescriptor> vertex_state_; std::unique_ptr<VertexStateDescriptor> vertex_state_;
}; };

View File

@ -121,6 +121,14 @@ TEST_F(VertexPullingTransformTest, BasicModule) {
EXPECT_TRUE(transform()->Run()); 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) { TEST_F(VertexPullingTransformTest, OneAttribute) {
InitBasicModule(); InitBasicModule();
@ -148,7 +156,7 @@ TEST_F(VertexPullingTransformTest, OneAttribute) {
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
BindingDecoration{0} BindingDecoration{0}
SetDecoration{0} SetDecoration{4}
} }
tint_pulling_vertex_buffer_0 tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
@ -229,7 +237,7 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) {
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
BindingDecoration{0} BindingDecoration{0}
SetDecoration{0} SetDecoration{4}
} }
tint_pulling_vertex_buffer_0 tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
@ -282,6 +290,87 @@ TEST_F(VertexPullingTransformTest, OneInstancedAttribute) {
mod()->to_str()); 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 // We expect the transform to use an existing builtin variables if it finds them
TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) { TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
InitBasicModule(); InitBasicModule();
@ -353,7 +442,7 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
BindingDecoration{0} BindingDecoration{0}
SetDecoration{0} SetDecoration{4}
} }
tint_pulling_vertex_buffer_0 tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
@ -362,7 +451,7 @@ TEST_F(VertexPullingTransformTest, ExistingVertexIndexAndInstanceIndex) {
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
BindingDecoration{1} BindingDecoration{1}
SetDecoration{0} SetDecoration{4}
} }
tint_pulling_vertex_buffer_1 tint_pulling_vertex_buffer_1
storage_buffer storage_buffer
@ -481,7 +570,7 @@ TEST_F(VertexPullingTransformTest, TwoAttributesSameBuffer) {
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
BindingDecoration{0} BindingDecoration{0}
SetDecoration{0} SetDecoration{4}
} }
tint_pulling_vertex_buffer_0 tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
@ -667,7 +756,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
BindingDecoration{0} BindingDecoration{0}
SetDecoration{0} SetDecoration{4}
} }
tint_pulling_vertex_buffer_0 tint_pulling_vertex_buffer_0
storage_buffer storage_buffer
@ -676,7 +765,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
BindingDecoration{1} BindingDecoration{1}
SetDecoration{0} SetDecoration{4}
} }
tint_pulling_vertex_buffer_1 tint_pulling_vertex_buffer_1
storage_buffer storage_buffer
@ -685,7 +774,7 @@ TEST_F(VertexPullingTransformTest, FloatVectorAttributes) {
DecoratedVariable{ DecoratedVariable{
Decorations{ Decorations{
BindingDecoration{2} BindingDecoration{2}
SetDecoration{0} SetDecoration{4}
} }
tint_pulling_vertex_buffer_2 tint_pulling_vertex_buffer_2
storage_buffer storage_buffer