spirv-writer: refactor getting GLSLstd450 import

Change the GenerateGLSLStd450 method to GetGLSLStd450 and have it
return the import id.  That's the only interesting use.

Change-Id: I4fc70e702af160bc797680e5e75e9742e9e24f16
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/52421
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
David Neto 2021-05-31 15:01:20 +00:00 committed by Tint LUCI CQ
parent 8dd465a6f4
commit 34c58a932c
2 changed files with 12 additions and 13 deletions

View File

@ -1198,18 +1198,22 @@ uint32_t Builder::GenerateUnaryOpExpression(ast::UnaryOpExpression* expr) {
return result_id;
}
void Builder::GenerateGLSLstd450Import() {
if (import_name_to_id_.find(kGLSLstd450) != import_name_to_id_.end()) {
return;
uint32_t Builder::GetGLSLstd450Import() {
auto where = import_name_to_id_.find(kGLSLstd450);
if (where != import_name_to_id_.end()) {
return where->second;
}
// It doesn't exist yet. Generate it.
auto result = result_op();
auto id = result.to_i();
push_ext_import(spv::Op::OpExtInstImport,
{result, Operand::String(kGLSLstd450)});
// Remember it for later.
import_name_to_id_[kGLSLstd450] = id;
return id;
}
uint32_t Builder::GenerateConstructorExpression(
@ -2155,14 +2159,7 @@ uint32_t Builder::GenerateIntrinsic(ast::CallExpression* call,
op = spv::Op::OpSelect;
break;
default: {
GenerateGLSLstd450Import();
auto set_iter = import_name_to_id_.find(kGLSLstd450);
if (set_iter == import_name_to_id_.end()) {
error_ = std::string("unknown import ") + kGLSLstd450;
return 0;
}
auto set_id = set_iter->second;
auto set_id = GetGLSLstd450Import();
auto inst_id = intrinsic_to_glsl_method(intrinsic);
if (inst_id == 0) {
error_ = "unknown method " + std::string(intrinsic->str());

View File

@ -306,8 +306,10 @@ class Builder {
/// @param stmt the statement to generate
/// @returns true on success
bool GenerateIfStatement(ast::IfStatement* stmt);
/// Generates an import instruction
void GenerateGLSLstd450Import();
/// Generates an import instruction for the "GLSL.std.450" extended instruction
/// set, if one doesn't exist yet, and returns the import ID.
/// @returns the import ID, or 0 on error.
uint32_t GetGLSLstd450Import();
/// Generates a constructor expression
/// @param var the variable generated for, nullptr if no variable associated.
/// @param expr the expression to generate