gl_shader_decompiler: Move texture code generation into lambdas

master
ReinUsesLisp 2018-11-28 02:34:23 +07:00
parent ab13b628d0
commit 78fc8f6b66
1 changed files with 78 additions and 97 deletions

@ -2674,11 +2674,11 @@ private:
if (is_array) { if (is_array) {
depth_compare_extra = depth_compare; depth_compare_extra = depth_compare;
shader.AddLine("vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " + shader.AddLine("vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " +
array_elem + ");"); array_elem + ");");
} else { } else {
if (depth_compare) { if (depth_compare) {
shader.AddLine("vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " + shader.AddLine("vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " +
depth_value + ");"); depth_value + ");");
} else { } else {
shader.AddLine("vec3 coords = vec3(" + x + ", " + y + ", " + z + ");"); shader.AddLine("vec3 coords = vec3(" + x + ", " + y + ", " + z + ");");
} }
@ -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) { return "texture(" + sampler + ", coords, " + depth_value + ')';
texture = "texture(" + sampler + ", coords)"; }
} else { return "texture(" + sampler + ", coords)";
texture = "texture(" + sampler + ", coords, " + depth_value + ')'; case Tegra::Shader::TextureProcessMode::LZ:
if (depth_compare_extra) {
return "texture(" + sampler + ", coords, " + depth_value + ')';
}
return "textureLod(" + sampler + ", coords, 0.0)";
case Tegra::Shader::TextureProcessMode::LB:
case Tegra::Shader::TextureProcessMode::LBA:
// TODO: Figure if A suffix changes the equation at all.
if (depth_compare_extra) {
LOG_WARNING(
HW_GPU,
"OpenGL Limitation: can't set bias value along depth compare");
return "texture(" + sampler + ", coords, " + depth_value + ')';
}
return "texture(" + sampler + ", coords, " + lod_value + ')';
case Tegra::Shader::TextureProcessMode::LL:
case Tegra::Shader::TextureProcessMode::LLA:
// TODO: Figure if A suffix changes the equation at all.
if (depth_compare_extra) {
LOG_WARNING(
HW_GPU,
"OpenGL Limitation: can't set lod value along depth compare");
return "texture(" + sampler + ", coords, " + depth_value + ')';
}
return "textureLod(" + sampler + ", coords, " + lod_value + ')';
default:
UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
static_cast<u32>(instr.tex.GetTextureProcessMode()));
if (depth_compare_extra) {
return "texture(" + sampler + ", coords, " + depth_value + ')';
}
return "texture(" + sampler + ", coords)";
} }
break; }();
}
case Tegra::Shader::TextureProcessMode::LZ: {
if (!depth_compare_extra) {
texture = "textureLod(" + sampler + ", coords, 0.0)";
} else {
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
}
break;
}
case Tegra::Shader::TextureProcessMode::LB:
case Tegra::Shader::TextureProcessMode::LBA: {
// TODO: Figure if A suffix changes the equation at all.
if (!depth_compare_extra) {
texture = "texture(" + sampler + ", coords, " + lod_value + ')';
} else {
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
LOG_WARNING(HW_GPU,
"OpenGL Limitation: can't set bias value along depth compare");
}
break;
}
case Tegra::Shader::TextureProcessMode::LL:
case Tegra::Shader::TextureProcessMode::LLA: {
// TODO: Figure if A suffix changes the equation at all.
if (!depth_compare_extra) {
texture = "textureLod(" + sampler + ", coords, " + lod_value + ')';
} else {
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
LOG_WARNING(HW_GPU,
"OpenGL Limitation: can't set lod value along depth compare");
}
break;
}
default: {
if (!depth_compare_extra) {
texture = "texture(" + sampler + ", coords)";
} else {
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
}
UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
static_cast<u32>(instr.tex.GetTextureProcessMode()));
}
}
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:
} if (depth_compare && is_array) {
case Tegra::Shader::TextureProcessMode::LZ: { return "texture(" + sampler + ", coords)";
if (depth_compare && is_array) { } else {
texture = "texture(" + sampler + ", coords)"; return "textureLod(" + sampler + ", coords, 0.0)";
} else { }
texture = "textureLod(" + sampler + ", coords, 0.0)"; break;
case Tegra::Shader::TextureProcessMode::LL:
return "textureLod(" + sampler + ", coords, lod_value)";
default:
UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
static_cast<u32>(instr.texs.GetTextureProcessMode()));
return "texture(" + sampler + ", coords)";
} }
break; }();
}
case Tegra::Shader::TextureProcessMode::LL: {
texture = "textureLod(" + sampler + ", coords, lod_value)";
break;
}
default: {
texture = "texture(" + sampler + ", coords)";
UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
static_cast<u32>(instr.texs.GetTextureProcessMode()));
}
}
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)";
switch (instr.tlds.GetTextureProcessMode()) { const std::string texture = [&]() {
case Tegra::Shader::TextureProcessMode::LZ: { switch (instr.tlds.GetTextureProcessMode()) {
texture = "texelFetch(" + sampler + ", coords, 0)"; case Tegra::Shader::TextureProcessMode::LZ:
break; return "texelFetch(" + sampler + ", coords, 0)";
} 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) + ';'); return "texelFetch(" + sampler + ", coords, lod)";
texture = "texelFetch(" + sampler + ", coords, lod)"; default:
break; UNIMPLEMENTED_MSG("Unhandled texture process mode {}",
} static_cast<u32>(instr.tlds.GetTextureProcessMode()));
default: { return "texelFetch(" + sampler + ", coords, 0)";
texture = "texelFetch(" + sampler + ", coords, 0)"; }
UNIMPLEMENTED_MSG("Unhandled texture process mode {}", }();
static_cast<u32>(instr.tlds.GetTextureProcessMode()));
}
}
WriteTexsInstruction(instr, texture); WriteTexsInstruction(instr, texture);
break; break;
} }