[spirv-writer] Add a LocalSize execution mode.

In SPIR-V a compute entry point requires a WorkGroup Size constant or a
LocalSize execution mode. This CL adds a 1,1,1 execution mode as a
starting point.

Bug: tint:74
Change-Id: Ie5bf639472033dca9ffe333548e7f31d4d318768
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/21020
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-05-05 14:21:28 +00:00
parent 2287f33424
commit b1870eff04
2 changed files with 22 additions and 9 deletions

View File

@ -302,6 +302,11 @@ bool Builder::GenerateExecutionModes(ast::EntryPoint* ep) {
push_preamble(
spv::Op::OpExecutionMode,
{Operand::Int(id), Operand::Int(SpvExecutionModeOriginUpperLeft)});
} else if (ep->stage() == ast::PipelineStage::kCompute) {
// TODO(dsinclair): Support LocalSize other then (1, 1, 1)
push_preamble(spv::Op::OpExecutionMode,
{Operand::Int(id), Operand::Int(SpvExecutionModeLocalSize),
Operand::Int(1), Operand::Int(1), Operand::Int(1)});
}
return true;

View File

@ -39,9 +39,7 @@ TEST_F(BuilderTest, EntryPoint) {
b.set_func_name_to_id("frag_main", 2);
ASSERT_TRUE(b.GenerateEntryPoint(&ep));
auto preamble = b.preamble();
ASSERT_EQ(preamble.size(), 1u);
EXPECT_EQ(DumpInstruction(preamble[0]), R"(OpEntryPoint Fragment %2 "main"
EXPECT_EQ(DumpInstructions(b.preamble()), R"(OpEntryPoint Fragment %2 "main"
)");
}
@ -53,9 +51,7 @@ TEST_F(BuilderTest, EntryPoint_WithoutName) {
b.set_func_name_to_id("compute_main", 3);
ASSERT_TRUE(b.GenerateEntryPoint(&ep));
auto preamble = b.preamble();
ASSERT_EQ(preamble.size(), 1u);
EXPECT_EQ(DumpInstruction(preamble[0]),
EXPECT_EQ(DumpInstructions(b.preamble()),
R"(OpEntryPoint GLCompute %3 "compute_main"
)");
}
@ -153,9 +149,21 @@ TEST_F(BuilderTest, ExecutionModel_Fragment_OriginUpperLeft) {
b.set_func_name_to_id("frag_main", 2);
ASSERT_TRUE(b.GenerateExecutionModes(&ep));
auto preamble = b.preamble();
ASSERT_EQ(preamble.size(), 1u);
EXPECT_EQ(DumpInstruction(preamble[0]), R"(OpExecutionMode %2 OriginUpperLeft
EXPECT_EQ(DumpInstructions(b.preamble()),
R"(OpExecutionMode %2 OriginUpperLeft
)");
}
TEST_F(BuilderTest, ExecutionModel_Compute_LocalSize) {
ast::EntryPoint ep(ast::PipelineStage::kCompute, "main", "main");
ast::Module mod;
Builder b(&mod);
b.set_func_name_to_id("main", 2);
ASSERT_TRUE(b.GenerateExecutionModes(&ep));
EXPECT_EQ(DumpInstructions(b.preamble()),
R"(OpExecutionMode %2 LocalSize 1 1 1
)");
}