|
@@ -851,6 +851,17 @@ SpirvVariable *SpirvBuilder::addStageBuiltinVar(const SpirvType *type,
|
|
spv::StorageClass storageClass,
|
|
spv::StorageClass storageClass,
|
|
spv::BuiltIn builtin,
|
|
spv::BuiltIn builtin,
|
|
SourceLocation loc) {
|
|
SourceLocation loc) {
|
|
|
|
+ // If the built-in variable has already been added (via a built-in alias),
|
|
|
|
+ // return the existing variable.
|
|
|
|
+ auto found = std::find_if(
|
|
|
|
+ builtinVars.begin(), builtinVars.end(),
|
|
|
|
+ [storageClass, builtin](const BuiltInVarInfo &varInfo) {
|
|
|
|
+ return varInfo.sc == storageClass && varInfo.builtIn == builtin;
|
|
|
|
+ });
|
|
|
|
+ if (found != builtinVars.end()) {
|
|
|
|
+ return found->variable;
|
|
|
|
+ }
|
|
|
|
+
|
|
// Note: We store the underlying type in the variable, *not* the pointer type.
|
|
// Note: We store the underlying type in the variable, *not* the pointer type.
|
|
auto *var =
|
|
auto *var =
|
|
new (context) SpirvVariable(/*QualType*/ {}, /*id*/ 0, loc, storageClass);
|
|
new (context) SpirvVariable(/*QualType*/ {}, /*id*/ 0, loc, storageClass);
|
|
@@ -862,6 +873,9 @@ SpirvVariable *SpirvBuilder::addStageBuiltinVar(const SpirvType *type,
|
|
loc, var, spv::Decoration::BuiltIn, {static_cast<uint32_t>(builtin)});
|
|
loc, var, spv::Decoration::BuiltIn, {static_cast<uint32_t>(builtin)});
|
|
module->addDecoration(decor);
|
|
module->addDecoration(decor);
|
|
|
|
|
|
|
|
+ // Add variable to cache.
|
|
|
|
+ builtinVars.emplace_back(storageClass, builtin, var);
|
|
|
|
+
|
|
return var;
|
|
return var;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -869,6 +883,17 @@ SpirvVariable *SpirvBuilder::addStageBuiltinVar(QualType type,
|
|
spv::StorageClass storageClass,
|
|
spv::StorageClass storageClass,
|
|
spv::BuiltIn builtin,
|
|
spv::BuiltIn builtin,
|
|
SourceLocation loc) {
|
|
SourceLocation loc) {
|
|
|
|
+ // If the built-in variable has already been added (via a built-in alias),
|
|
|
|
+ // return the existing variable.
|
|
|
|
+ auto found = std::find_if(
|
|
|
|
+ builtinVars.begin(), builtinVars.end(),
|
|
|
|
+ [storageClass, builtin](const BuiltInVarInfo &varInfo) {
|
|
|
|
+ return varInfo.sc == storageClass && varInfo.builtIn == builtin;
|
|
|
|
+ });
|
|
|
|
+ if (found != builtinVars.end()) {
|
|
|
|
+ return found->variable;
|
|
|
|
+ }
|
|
|
|
+
|
|
// Note: We store the underlying type in the variable, *not* the pointer type.
|
|
// Note: We store the underlying type in the variable, *not* the pointer type.
|
|
auto *var = new (context) SpirvVariable(type, /*id*/ 0, loc, storageClass);
|
|
auto *var = new (context) SpirvVariable(type, /*id*/ 0, loc, storageClass);
|
|
module->addVariable(var);
|
|
module->addVariable(var);
|
|
@@ -878,6 +903,9 @@ SpirvVariable *SpirvBuilder::addStageBuiltinVar(QualType type,
|
|
loc, var, spv::Decoration::BuiltIn, {static_cast<uint32_t>(builtin)});
|
|
loc, var, spv::Decoration::BuiltIn, {static_cast<uint32_t>(builtin)});
|
|
module->addDecoration(decor);
|
|
module->addDecoration(decor);
|
|
|
|
|
|
|
|
+ // Add variable to cache.
|
|
|
|
+ builtinVars.emplace_back(storageClass, builtin, var);
|
|
|
|
+
|
|
return var;
|
|
return var;
|
|
}
|
|
}
|
|
|
|
|