fix wordcount of printf OpExtInstImport. Also refactor so OpString and other debug insts come before OpName and OpMemberName to fix spirv-val errors

This commit is contained in:
Frodo Baggins 2024-09-19 16:40:51 -07:00
parent b51af1a2ca
commit b0f30ba771
3 changed files with 16 additions and 11 deletions

View File

@ -1373,6 +1373,7 @@ private:
std::unique_ptr<Stream> entry_points;
std::unique_ptr<Stream> execution_modes;
std::unique_ptr<Stream> debug;
std::unique_ptr<Stream> debug_name;
std::unique_ptr<Stream> annotations;
std::unique_ptr<Declarations> declarations;
std::unique_ptr<Stream> global_variables;

View File

@ -12,14 +12,14 @@
namespace Sirit {
Id Module::Name(Id target, std::string_view name) {
debug->Reserve(3 + WordsInString(name));
*debug << spv::Op::OpName << target << name << EndOp{};
debug_name->Reserve(3 + WordsInString(name));
*debug_name << spv::Op::OpName << target << name << EndOp{};
return target;
}
Id Module::MemberName(Id type, u32 member, std::string_view name) {
debug->Reserve(4 + WordsInString(name));
*debug << spv::Op::OpMemberName << type << member << name << EndOp{};
debug_name->Reserve(4 + WordsInString(name));
*debug_name << spv::Op::OpMemberName << type << member << name << EndOp{};
return type;
}

View File

@ -21,7 +21,7 @@ Module::Module(u32 version_)
: version{version_}, ext_inst_imports{std::make_unique<Stream>(&bound)},
entry_points{std::make_unique<Stream>(&bound)},
execution_modes{std::make_unique<Stream>(&bound)}, debug{std::make_unique<Stream>(&bound)},
annotations{std::make_unique<Stream>(&bound)},
debug_name{std::make_unique<Stream>(&bound)}, annotations{std::make_unique<Stream>(&bound)},
declarations{std::make_unique<Declarations>(&bound)},
global_variables{std::make_unique<Stream>(&bound)}, code{std::make_unique<Stream>(&bound)} {}
@ -60,6 +60,7 @@ std::vector<u32> Module::Assemble() const {
insert(entry_points->Words());
insert(execution_modes->Words());
insert(debug->Words());
insert(debug_name->Words());
insert(annotations->Words());
insert(declarations->Words());
insert(global_variables->Words());
@ -131,19 +132,22 @@ Id Module::AddGlobalVariable(Id result_type, spv::StorageClass storage_class,
}
Id Module::GetGLSLstd450() {
const char* extname = "GLSL.std.450";
size_t len = WordsInString(extname);
if (!glsl_std_450) {
ext_inst_imports->Reserve(3 + 4);
glsl_std_450 = *ext_inst_imports << OpId{spv::Op::OpExtInstImport} << "GLSL.std.450"
<< EndOp{};
ext_inst_imports->Reserve(3 + len);
glsl_std_450 = *ext_inst_imports << OpId{spv::Op::OpExtInstImport} << extname << EndOp{};
}
return *glsl_std_450;
}
Id Module::GetNonSemanticDebugPrintf() {
const char* extname = "NonSemantic.DebugPrintf";
size_t len = WordsInString(extname);
if (!non_semantic_debug_printf) {
ext_inst_imports->Reserve(3 + 4);
non_semantic_debug_printf = *ext_inst_imports << OpId{spv::Op::OpExtInstImport}
<< "NonSemantic.DebugPrintf" << EndOp{};
ext_inst_imports->Reserve(3 + len);
non_semantic_debug_printf = *ext_inst_imports << OpId{spv::Op::OpExtInstImport} << extname
<< EndOp{};
}
return *non_semantic_debug_printf;
}