Fix OpExtension.

There were two issues:
- The word0 was omitted entirely.
- The word count didn't account for the nul terminator.
This commit is contained in:
comex 2020-11-24 18:24:28 -05:00 committed by Rodrigo Locatti
parent 13396c96ac
commit 63c5b548c5
2 changed files with 4 additions and 2 deletions

View file

@ -42,8 +42,10 @@ std::vector<u32> Module::Assemble() const {
}
for (const std::string_view extension_name : extensions) {
size_t count = WordsInString(extension_name);
words.push_back(MakeWord0(spv::Op::OpExtension, count + 1));
size_t insert_index = words.size();
words.resize(words.size() + WordsInString(extension_name));
words.resize(words.size() + count);
InsertStringView(words, insert_index, extension_name);
}

View file

@ -35,7 +35,7 @@ struct OpId {
struct EndOp {};
constexpr size_t WordsInString(std::string_view string) {
return string.size() / sizeof(u32);
return string.size() / sizeof(u32) + 1;
}
inline void InsertStringView(std::vector<u32>& words, size_t& insert_index,