gl_shader_decompiler: Move texture code generation into lambdas

This commit is contained in:
ReinUsesLisp 2018-11-28 02:34:23 -03:00
parent ab13b628d0
commit 78fc8f6b66

View file

@ -2701,59 +2701,47 @@ private:
// Add an extra scope and declare the texture coords inside to prevent // Add an extra scope and declare the texture coords inside to prevent
// overwriting them in case they are used as outputs of the texs instruction. // overwriting them in case they are used as outputs of the texs instruction.
std::string texture; const std::string texture = [&]() {
switch (instr.tex.GetTextureProcessMode()) { switch (instr.tex.GetTextureProcessMode()) {
case Tegra::Shader::TextureProcessMode::None: { case Tegra::Shader::TextureProcessMode::None:
if (!depth_compare_extra) { if (depth_compare_extra) {
texture = "texture(" + sampler + ", coords)"; return "texture(" + sampler + ", coords, " + depth_value + ')';
} else {
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
} }
break; return "texture(" + sampler + ", coords)";
} case Tegra::Shader::TextureProcessMode::LZ:
case Tegra::Shader::TextureProcessMode::LZ: { if (depth_compare_extra) {
if (!depth_compare_extra) { return "texture(" + sampler + ", coords, " + depth_value + ')';
texture = "textureLod(" + sampler + ", coords, 0.0)";
} else {
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
}
break;
} }
return "textureLod(" + sampler + ", coords, 0.0)";
case Tegra::Shader::TextureProcessMode::LB: case Tegra::Shader::TextureProcessMode::LB:
case Tegra::Shader::TextureProcessMode::LBA: { case Tegra::Shader::TextureProcessMode::LBA:
// TODO: Figure if A suffix changes the equation at all. // TODO: Figure if A suffix changes the equation at all.
if (!depth_compare_extra) { if (depth_compare_extra) {
texture = "texture(" + sampler + ", coords, " + lod_value + ')'; LOG_WARNING(
} else { HW_GPU,
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
LOG_WARNING(HW_GPU,
"OpenGL Limitation: can't set bias value along depth compare"); "OpenGL Limitation: can't set bias value along depth compare");
return "texture(" + sampler + ", coords, " + depth_value + ')';
} }
break; return "texture(" + sampler + ", coords, " + lod_value + ')';
}
case Tegra::Shader::TextureProcessMode::LL: case Tegra::Shader::TextureProcessMode::LL:
case Tegra::Shader::TextureProcessMode::LLA: { case Tegra::Shader::TextureProcessMode::LLA:
// TODO: Figure if A suffix changes the equation at all. // TODO: Figure if A suffix changes the equation at all.
if (!depth_compare_extra) { if (depth_compare_extra) {
texture = "textureLod(" + sampler + ", coords, " + lod_value + ')'; LOG_WARNING(
} else { HW_GPU,
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
LOG_WARNING(HW_GPU,
"OpenGL Limitation: can't set lod value along depth compare"); "OpenGL Limitation: can't set lod value along depth compare");
return "texture(" + sampler + ", coords, " + depth_value + ')';
} }
break; return "textureLod(" + sampler + ", coords, " + lod_value + ')';
} default:
default: {
if (!depth_compare_extra) {
texture = "texture(" + sampler + ", coords)";
} else {
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
}
UNIMPLEMENTED_MSG("Unhandled texture process mode {}", UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
static_cast<u32>(instr.tex.GetTextureProcessMode())); static_cast<u32>(instr.tex.GetTextureProcessMode()));
if (depth_compare_extra) {
return "texture(" + sampler + ", coords, " + depth_value + ')';
} }
return "texture(" + sampler + ", coords)";
} }
}();
if (depth_compare) { if (depth_compare) {
regs.SetRegisterToFloat(instr.gpr0, 0, texture, 1, 1, false); regs.SetRegisterToFloat(instr.gpr0, 0, texture, 1, 1, false);
@ -2871,34 +2859,29 @@ private:
const std::string sampler = const std::string sampler =
GetSampler(instr.sampler, texture_type, is_array, depth_compare); GetSampler(instr.sampler, texture_type, is_array, depth_compare);
std::string texture; std::string texture = [&]() {
switch (process_mode) { switch (process_mode) {
case Tegra::Shader::TextureProcessMode::None: { case Tegra::Shader::TextureProcessMode::None:
texture = "texture(" + sampler + ", coords)"; return "texture(" + sampler + ", coords)";
break; case Tegra::Shader::TextureProcessMode::LZ:
}
case Tegra::Shader::TextureProcessMode::LZ: {
if (depth_compare && is_array) { if (depth_compare && is_array) {
texture = "texture(" + sampler + ", coords)"; return "texture(" + sampler + ", coords)";
} else { } else {
texture = "textureLod(" + sampler + ", coords, 0.0)"; return "textureLod(" + sampler + ", coords, 0.0)";
} }
break; break;
} case Tegra::Shader::TextureProcessMode::LL:
case Tegra::Shader::TextureProcessMode::LL: { return "textureLod(" + sampler + ", coords, lod_value)";
texture = "textureLod(" + sampler + ", coords, lod_value)"; default:
break;
}
default: {
texture = "texture(" + sampler + ", coords)";
UNIMPLEMENTED_MSG("Unhandled texture process mode {}", UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
static_cast<u32>(instr.texs.GetTextureProcessMode())); static_cast<u32>(instr.texs.GetTextureProcessMode()));
return "texture(" + sampler + ", coords)";
} }
} }();
if (depth_compare) { if (depth_compare) {
texture = "vec4(" + texture + ')'; texture = "vec4(" + texture + ')';
} }
WriteTexsInstruction(instr, texture); WriteTexsInstruction(instr, texture);
break; break;
} }
@ -2941,25 +2924,23 @@ private:
} }
const std::string sampler = const std::string sampler =
GetSampler(instr.sampler, texture_type, is_array, false); GetSampler(instr.sampler, texture_type, is_array, false);
std::string texture = "texelFetch(" + sampler + ", coords, 0)";
const std::string texture = [&]() {
switch (instr.tlds.GetTextureProcessMode()) { switch (instr.tlds.GetTextureProcessMode()) {
case Tegra::Shader::TextureProcessMode::LZ: { case Tegra::Shader::TextureProcessMode::LZ:
texture = "texelFetch(" + sampler + ", coords, 0)"; return "texelFetch(" + sampler + ", coords, 0)";
break; case Tegra::Shader::TextureProcessMode::LL:
}
case Tegra::Shader::TextureProcessMode::LL: {
shader.AddLine( shader.AddLine(
"float lod = " + "float lod = " +
regs.GetRegisterAsInteger(instr.gpr20.Value() + extra_op_offset) + ';'); regs.GetRegisterAsInteger(instr.gpr20.Value() + extra_op_offset) + ';');
texture = "texelFetch(" + sampler + ", coords, lod)"; return "texelFetch(" + sampler + ", coords, lod)";
break; default:
}
default: {
texture = "texelFetch(" + sampler + ", coords, 0)";
UNIMPLEMENTED_MSG("Unhandled texture process mode {}", UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
static_cast<u32>(instr.tlds.GetTextureProcessMode())); static_cast<u32>(instr.tlds.GetTextureProcessMode()));
return "texelFetch(" + sampler + ", coords, 0)";
} }
} }();
WriteTexsInstruction(instr, texture); WriteTexsInstruction(instr, texture);
break; break;
} }