yuzu-emu
/
yuzu
Archived
1
0
Fork 0

Corrected inputs indexing in TEX instruction

This commit is contained in:
FernandoS27 2018-11-21 21:04:43 -04:00
parent 69b3f98d3a
commit 487d805899
1 changed files with 85 additions and 66 deletions

View File

@ -2499,61 +2499,81 @@ private:
const bool depth_compare = const bool depth_compare =
instr.tex.UsesMiscMode(Tegra::Shader::TextureMiscMode::DC); instr.tex.UsesMiscMode(Tegra::Shader::TextureMiscMode::DC);
u32 num_coordinates = TextureCoordinates(texture_type); u32 num_coordinates = TextureCoordinates(texture_type);
if (depth_compare) u32 start_index = 0;
num_coordinates += 1; std::string array_elem;
if (is_array) {
array_elem = regs.GetRegisterAsInteger(instr.gpr8);
start_index = 1;
}
auto process_mode = instr.tex.GetTextureProcessMode();
u32 start_index_b = 0;
std::string lod_value;
if (process_mode != Tegra::Shader::TextureProcessMode::LZ &&
process_mode != Tegra::Shader::TextureProcessMode::None) {
start_index_b = 1;
lod_value = regs.GetRegisterAsFloat(instr.gpr20);
}
std::string depth_value;
if (depth_compare) {
depth_value = regs.GetRegisterAsFloat(instr.gpr20.Value() + start_index_b);
}
bool depth_compare_extra = false;
switch (num_coordinates) { switch (num_coordinates) {
case 1: { case 1: {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8.Value() + start_index);
if (is_array) { if (is_array) {
const std::string index = regs.GetRegisterAsInteger(instr.gpr8); if (depth_compare) {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1); coord = "vec3 coords = vec3(" + x + ", " + depth_value + ", " +
coord = "vec2 coords = vec2(" + x + ", " + index + ");"; array_elem + ");";
} else {
coord = "vec2 coords = vec2(" + x + ", " + array_elem + ");";
}
} else {
if (depth_compare) {
coord = "vec2 coords = vec2(" + x + ", " + depth_value + ");";
} else { } else {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8);
coord = "float coords = " + x + ';'; coord = "float coords = " + x + ';';
} }
}
break; break;
} }
case 2: { case 2: {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8.Value() + start_index);
const std::string y =
regs.GetRegisterAsFloat(instr.gpr8.Value() + start_index + 1);
if (is_array) { if (is_array) {
const std::string index = regs.GetRegisterAsInteger(instr.gpr8); if (depth_compare) {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1); coord = "vec4 coords = vec4(" + x + ", " + y + ", " + depth_value +
const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 2); ", " + array_elem + ");";
coord = "vec3 coords = vec3(" + x + ", " + y + ", " + index + ");"; } else {
coord = "vec3 coords = vec3(" + x + ", " + y + ", " + array_elem + ");";
}
} else {
if (depth_compare) {
coord =
"vec3 coords = vec3(" + x + ", " + y + ", " + depth_value + ");";
} else { } else {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8);
const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
coord = "vec2 coords = vec2(" + x + ", " + y + ");"; coord = "vec2 coords = vec2(" + x + ", " + y + ");";
} }
}
break; break;
} }
case 3: { case 3: {
if (depth_compare) {
if (is_array) {
const std::string index = regs.GetRegisterAsInteger(instr.gpr8);
const std::string x = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
const std::string y = regs.GetRegisterAsFloat(instr.gpr20);
const std::string z = regs.GetRegisterAsFloat(instr.gpr20.Value() + 1);
coord = "vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " + index +
");";
} else {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8);
const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
const std::string z = regs.GetRegisterAsFloat(instr.gpr20);
coord = "vec3 coords = vec3(" + x + ", " + y + ", " + z + ");";
}
} else {
if (is_array) {
const std::string index = regs.GetRegisterAsInteger(instr.gpr8);
const std::string x = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 2);
const std::string z = regs.GetRegisterAsFloat(instr.gpr8.Value() + 3);
coord = "vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " + index +
");";
} else {
const std::string x = regs.GetRegisterAsFloat(instr.gpr8); const std::string x = regs.GetRegisterAsFloat(instr.gpr8);
const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1); const std::string y = regs.GetRegisterAsFloat(instr.gpr8.Value() + 1);
const std::string z = regs.GetRegisterAsFloat(instr.gpr8.Value() + 2); const std::string z = regs.GetRegisterAsFloat(instr.gpr8.Value() + 2);
if (is_array) {
depth_compare_extra = depth_compare;
coord = "vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " +
array_elem + ");";
} else {
if (depth_compare) {
coord = "vec4 coords = vec4(" + x + ", " + y + ", " + z + ", " +
depth_value + ");";
} else {
coord = "vec3 coords = vec3(" + x + ", " + y + ", " + z + ");"; coord = "vec3 coords = vec3(" + x + ", " + y + ", " + z + ");";
} }
} }
@ -2569,8 +2589,6 @@ private:
coord = "vec2 coords = vec2(" + x + ", " + y + ");"; coord = "vec2 coords = vec2(" + x + ", " + y + ");";
texture_type = Tegra::Shader::TextureType::Texture2D; texture_type = Tegra::Shader::TextureType::Texture2D;
} }
// TODO: make sure coordinates are always indexed to gpr8 and gpr20 is always bias
// or lod.
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);
@ -2584,48 +2602,49 @@ private:
switch (instr.tex.GetTextureProcessMode()) { switch (instr.tex.GetTextureProcessMode()) {
case Tegra::Shader::TextureProcessMode::None: { case Tegra::Shader::TextureProcessMode::None: {
if (!depth_compare_extra) {
texture = "texture(" + sampler + ", coords)"; texture = "texture(" + sampler + ", coords)";
} else {
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
}
break; break;
} }
case Tegra::Shader::TextureProcessMode::LZ: { case Tegra::Shader::TextureProcessMode::LZ: {
if (!depth_compare_extra) {
texture = "textureLod(" + sampler + ", coords, 0.0)"; texture = "textureLod(" + sampler + ", coords, 0.0)";
} else {
texture = "texture(" + sampler + ", coords, " + depth_value + ')';
}
break; break;
} }
case Tegra::Shader::TextureProcessMode::LB: case Tegra::Shader::TextureProcessMode::LB:
case Tegra::Shader::TextureProcessMode::LBA: { case Tegra::Shader::TextureProcessMode::LBA: {
const std::string bias = [&]() {
if (depth_compare) {
if (is_array)
return regs.GetRegisterAsFloat(instr.gpr20.Value() + 2);
else
return regs.GetRegisterAsFloat(instr.gpr20.Value() + 1);
} else {
return regs.GetRegisterAsFloat(instr.gpr20);
}
}();
shader.AddLine("float bias = " + bias + ';');
// TODO: Figure if A suffix changes the equation at all. // TODO: Figure if A suffix changes the equation at all.
texture = "texture(" + sampler + ", coords, bias)"; 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; break;
} }
case Tegra::Shader::TextureProcessMode::LL: case Tegra::Shader::TextureProcessMode::LL:
case Tegra::Shader::TextureProcessMode::LLA: { case Tegra::Shader::TextureProcessMode::LLA: {
const std::string lod = [&]() {
if (num_coordinates <= 2) {
return regs.GetRegisterAsFloat(instr.gpr20);
} else {
return regs.GetRegisterAsFloat(instr.gpr20.Value() + 1);
}
}();
shader.AddLine("float lod = " + lod + ';');
// TODO: Figure if A suffix changes the equation at all. // TODO: Figure if A suffix changes the equation at all.
texture = "textureLod(" + sampler + ", coords, lod)"; 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; break;
} }
default: { default: {
if (!depth_compare_extra) {
texture = "texture(" + sampler + ", coords)"; 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()));
} }