forked from ShuriZma/suyu
1
0
Fork 0

gl_shader_decompiler: Use GLSL scope on instructions unrelated to textures

This commit is contained in:
ReinUsesLisp 2018-11-28 02:44:15 -03:00
parent 78fc8f6b66
commit f4abebd731
1 changed files with 10 additions and 35 deletions

View File

@ -854,14 +854,12 @@ private:
} }
if (precise && stage != Maxwell3D::Regs::ShaderStage::Fragment) { if (precise && stage != Maxwell3D::Regs::ShaderStage::Fragment) {
shader.AddLine('{'); const auto scope = shader.Scope();
++shader.scope;
// This avoids optimizations of constant propagation and keeps the code as the original // This avoids optimizations of constant propagation and keeps the code as the original
// Sadly using the precise keyword causes "linking" errors on fragment shaders. // Sadly using the precise keyword causes "linking" errors on fragment shaders.
shader.AddLine("precise float tmp = " + src + ';'); shader.AddLine("precise float tmp = " + src + ';');
shader.AddLine(dest + " = tmp;"); shader.AddLine(dest + " = tmp;");
--shader.scope;
shader.AddLine('}');
} else { } else {
shader.AddLine(dest + " = " + src + ';'); shader.AddLine(dest + " = " + src + ';');
} }
@ -1382,12 +1380,10 @@ private:
* top. * top.
*/ */
void EmitPushToFlowStack(u32 target) { void EmitPushToFlowStack(u32 target) {
shader.AddLine('{'); const auto scope = shader.Scope();
++shader.scope;
shader.AddLine("flow_stack[flow_stack_top] = " + std::to_string(target) + "u;"); shader.AddLine("flow_stack[flow_stack_top] = " + std::to_string(target) + "u;");
shader.AddLine("flow_stack_top++;"); shader.AddLine("flow_stack_top++;");
--shader.scope;
shader.AddLine('}');
} }
/* /*
@ -1395,13 +1391,11 @@ private:
* popped address and decrementing the stack top. * popped address and decrementing the stack top.
*/ */
void EmitPopFromFlowStack() { void EmitPopFromFlowStack() {
shader.AddLine('{'); const auto scope = shader.Scope();
++shader.scope;
shader.AddLine("flow_stack_top--;"); shader.AddLine("flow_stack_top--;");
shader.AddLine("jmp_to = flow_stack[flow_stack_top];"); shader.AddLine("jmp_to = flow_stack[flow_stack_top];");
shader.AddLine("break;"); shader.AddLine("break;");
--shader.scope;
shader.AddLine('}');
} }
/// Writes the output values from a fragment shader to the corresponding GLSL output variables. /// Writes the output values from a fragment shader to the corresponding GLSL output variables.
@ -2313,8 +2307,7 @@ private:
UNIMPLEMENTED_IF(instr.conversion.selector); UNIMPLEMENTED_IF(instr.conversion.selector);
UNIMPLEMENTED_IF_MSG(instr.generates_cc, UNIMPLEMENTED_IF_MSG(instr.generates_cc,
"Condition codes generation in I2F is not implemented"); "Condition codes generation in I2F is not implemented");
std::string op_a;
std::string op_a{};
if (instr.is_b_gpr) { if (instr.is_b_gpr) {
op_a = op_a =
@ -2470,10 +2463,7 @@ private:
case OpCode::Id::LD_C: { case OpCode::Id::LD_C: {
UNIMPLEMENTED_IF(instr.ld_c.unknown != 0); UNIMPLEMENTED_IF(instr.ld_c.unknown != 0);
// Add an extra scope and declare the index register inside to prevent const auto scope = shader.Scope();
// overwriting it in case it is used as an output of the LD instruction.
shader.AddLine("{");
++shader.scope;
shader.AddLine("uint index = (" + regs.GetRegisterAsInteger(instr.gpr8, 0, false) + shader.AddLine("uint index = (" + regs.GetRegisterAsInteger(instr.gpr8, 0, false) +
" / 4) & (MAX_CONSTBUFFER_ELEMENTS - 1);"); " / 4) & (MAX_CONSTBUFFER_ELEMENTS - 1);");
@ -2499,19 +2489,13 @@ private:
UNIMPLEMENTED_MSG("Unhandled type: {}", UNIMPLEMENTED_MSG("Unhandled type: {}",
static_cast<unsigned>(instr.ld_c.type.Value())); static_cast<unsigned>(instr.ld_c.type.Value()));
} }
--shader.scope;
shader.AddLine("}");
break; break;
} }
case OpCode::Id::LD_L: { case OpCode::Id::LD_L: {
UNIMPLEMENTED_IF_MSG(instr.ld_l.unknown == 1, "LD_L Unhandled mode: {}", UNIMPLEMENTED_IF_MSG(instr.ld_l.unknown == 1, "LD_L Unhandled mode: {}",
static_cast<unsigned>(instr.ld_l.unknown.Value())); static_cast<unsigned>(instr.ld_l.unknown.Value()));
// Add an extra scope and declare the index register inside to prevent const auto scope = shader.Scope();
// overwriting it in case it is used as an output of the LD instruction.
shader.AddLine('{');
++shader.scope;
std::string op = '(' + regs.GetRegisterAsInteger(instr.gpr8, 0, false) + " + " + std::string op = '(' + regs.GetRegisterAsInteger(instr.gpr8, 0, false) + " + " +
std::to_string(instr.smem_imm.Value()) + ')'; std::to_string(instr.smem_imm.Value()) + ')';
@ -2528,9 +2512,6 @@ private:
UNIMPLEMENTED_MSG("LD_L Unhandled type: {}", UNIMPLEMENTED_MSG("LD_L Unhandled type: {}",
static_cast<unsigned>(instr.ldst_sl.type.Value())); static_cast<unsigned>(instr.ldst_sl.type.Value()));
} }
--shader.scope;
shader.AddLine('}');
break; break;
} }
case OpCode::Id::ST_A: { case OpCode::Id::ST_A: {
@ -2565,10 +2546,7 @@ private:
UNIMPLEMENTED_IF_MSG(instr.st_l.unknown == 0, "ST_L Unhandled mode: {}", UNIMPLEMENTED_IF_MSG(instr.st_l.unknown == 0, "ST_L Unhandled mode: {}",
static_cast<unsigned>(instr.st_l.unknown.Value())); static_cast<unsigned>(instr.st_l.unknown.Value()));
// Add an extra scope and declare the index register inside to prevent const auto scope = shader.Scope();
// overwriting it in case it is used as an output of the LD instruction.
shader.AddLine('{');
++shader.scope;
std::string op = '(' + regs.GetRegisterAsInteger(instr.gpr8, 0, false) + " + " + std::string op = '(' + regs.GetRegisterAsInteger(instr.gpr8, 0, false) + " + " +
std::to_string(instr.smem_imm.Value()) + ')'; std::to_string(instr.smem_imm.Value()) + ')';
@ -2583,9 +2561,6 @@ private:
UNIMPLEMENTED_MSG("ST_L Unhandled type: {}", UNIMPLEMENTED_MSG("ST_L Unhandled type: {}",
static_cast<unsigned>(instr.ldst_sl.type.Value())); static_cast<unsigned>(instr.ldst_sl.type.Value()));
} }
--shader.scope;
shader.AddLine('}');
break; break;
} }
case OpCode::Id::TEX: { case OpCode::Id::TEX: {