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

@ -391,6 +391,7 @@ public:
DeclareVertex();
DeclareGeometry();
DeclareRegisters();
DeclareCustomVariables();
DeclarePredicates();
DeclareLocalMemory();
DeclareInternalFlags();
@ -503,6 +504,16 @@ private:
}
}
void DeclareCustomVariables() {
const u32 cv_num = ir.GetCustomVariablesAmount();
for (u32 i = 0; i < cv_num; ++i) {
code.AddLine("float {} = 0.0f;", GetCustomVariable(i));
}
if (cv_num > 0) {
code.AddNewLine();
}
}
void DeclarePredicates() {
const auto& predicates = ir.GetPredicates();
for (const auto pred : predicates) {
@ -780,6 +791,11 @@ private:
return {GetRegister(index), Type::Float};
}
if (const auto cv = std::get_if<CustomVarNode>(&*node)) {
const u32 index = cv->GetIndex();
return {GetCustomVariable(index), Type::Float};
}
if (const auto immediate = std::get_if<ImmediateNode>(&*node)) {
const u32 value = immediate->GetValue();
if (value < 10) {
@ -2250,6 +2266,10 @@ private:
return GetDeclarationWithSuffix(index, "gpr");
}
std::string GetCustomVariable(u32 index) const {
return GetDeclarationWithSuffix(index, "custom_var");
}
std::string GetPredicate(Tegra::Shader::Pred pred) const {
return GetDeclarationWithSuffix(static_cast<u32>(pred), "pred");
}