[spirv-writer] Declare extension when using vulkan memory model

This fixes one validation error

Change-Id: I13ee67483ea211d394b51ed9ea29b6698af0acc5
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/20622
Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
David Neto 2020-04-30 01:16:21 +00:00 committed by dan sinclair
parent e3bf49a9cf
commit 1be8d7f0d1
2 changed files with 7 additions and 1 deletions

View File

@ -128,8 +128,12 @@ Builder::~Builder() = default;
bool Builder::Build() { bool Builder::Build() {
push_preamble(spv::Op::OpCapability, {Operand::Int(SpvCapabilityShader)}); push_preamble(spv::Op::OpCapability, {Operand::Int(SpvCapabilityShader)});
// TODO(dneto): Stop using the Vulkan memory model. crbug.com/tint/63
push_preamble(spv::Op::OpCapability, push_preamble(spv::Op::OpCapability,
{Operand::Int(SpvCapabilityVulkanMemoryModel)}); {Operand::Int(SpvCapabilityVulkanMemoryModel)});
push_preamble(spv::Op::OpExtension,
{Operand::String("SPV_KHR_vulkan_memory_model")});
for (const auto& imp : mod_->imports()) { for (const auto& imp : mod_->imports()) {
GenerateImport(imp.get()); GenerateImport(imp.get());

View File

@ -36,10 +36,11 @@ TEST_F(BuilderTest, InsertsPreambleWithImport) {
Builder b(&m); Builder b(&m);
ASSERT_TRUE(b.Build()); ASSERT_TRUE(b.Build());
ASSERT_EQ(b.preamble().size(), 4u); ASSERT_EQ(b.preamble().size(), 5u);
EXPECT_EQ(DumpBuilder(b), R"(OpCapability Shader EXPECT_EQ(DumpBuilder(b), R"(OpCapability Shader
OpCapability VulkanMemoryModel OpCapability VulkanMemoryModel
OpExtension "SPV_KHR_vulkan_memory_model"
%1 = OpExtInstImport "GLSL.std.450" %1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical Vulkan OpMemoryModel Logical Vulkan
)"); )");
@ -51,6 +52,7 @@ TEST_F(BuilderTest, InsertsPreambleWithoutImport) {
ASSERT_TRUE(b.Build()); ASSERT_TRUE(b.Build());
EXPECT_EQ(DumpBuilder(b), R"(OpCapability Shader EXPECT_EQ(DumpBuilder(b), R"(OpCapability Shader
OpCapability VulkanMemoryModel OpCapability VulkanMemoryModel
OpExtension "SPV_KHR_vulkan_memory_model"
OpMemoryModel Logical Vulkan OpMemoryModel Logical Vulkan
)"); )");
} }