Shader_IR: Implement Injectable Custom Variables to the IR.

This commit is contained in:
Fernando Sahmkow 2020-01-07 14:53:46 -04:00 committed by FernandoS27
parent 2b02f29a2d
commit 3c34678627
5 changed files with 70 additions and 1 deletions

View file

@ -353,6 +353,7 @@ private:
DeclareFragment();
DeclareCompute();
DeclareRegisters();
DeclareCustomVariables();
DeclarePredicates();
DeclareLocalMemory();
DeclareSharedMemory();
@ -587,6 +588,15 @@ private:
}
}
void DeclareCustomVariables() {
const u32 cv_num = ir.GetCustomVariablesAmount();
for (u32 i = 0; i < cv_num; ++i) {
const Id id = OpVariable(t_prv_float, spv::StorageClass::Private, v_float_zero);
Name(id, fmt::format("custom_var_{}", i));
custom_variables.emplace(i, AddGlobalVariable(id));
}
}
void DeclarePredicates() {
for (const auto pred : ir.GetPredicates()) {
const Id id = OpVariable(t_prv_bool, spv::StorageClass::Private, v_false);
@ -974,6 +984,11 @@ private:
return {OpLoad(t_float, registers.at(index)), Type::Float};
}
if (const auto cv = std::get_if<CustomVarNode>(&*node)) {
const u32 index = cv->GetIndex();
return {OpLoad(t_float, custom_variables.at(index)), Type::Float};
}
if (const auto immediate = std::get_if<ImmediateNode>(&*node)) {
return {Constant(t_uint, immediate->GetValue()), Type::Uint};
}
@ -2505,6 +2520,7 @@ private:
Id out_vertex{};
Id in_vertex{};
std::map<u32, Id> registers;
std::map<u32, Id> custom_variables;
std::map<Tegra::Shader::Pred, Id> predicates;
std::map<u32, Id> flow_variables;
Id local_memory{};