Skip to content

Commit

Permalink
Latte: Add support for shader instructions MIN_UINT and MAX_UINT
Browse files Browse the repository at this point in the history
Seen in the eShop version of Fatal Frame
Also made some warnings less spammy since this game seems to trigger it a lot
  • Loading branch information
Exzap committed Nov 21, 2024
1 parent 2065ac5 commit c3e29fb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/Cafe/HW/Latte/LegacyShaderDecompiler/LatteDecompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,8 @@ bool LatteDecompiler_IsALUTransInstruction(bool isOP3, uint32 opcode)
opcode == ALU_OP2_INST_LSHR_INT ||
opcode == ALU_OP2_INST_MAX_INT ||
opcode == ALU_OP2_INST_MIN_INT ||
opcode == ALU_OP2_INST_MAX_UINT ||
opcode == ALU_OP2_INST_MIN_UINT ||
opcode == ALU_OP2_INST_MOVA_FLOOR ||
opcode == ALU_OP2_INST_MOVA_INT ||
opcode == ALU_OP2_INST_SETE_DX10 ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ bool _isIntegerInstruction(const LatteDecompilerALUInstruction& aluInstruction)
case ALU_OP2_INST_SUB_INT:
case ALU_OP2_INST_MAX_INT:
case ALU_OP2_INST_MIN_INT:
case ALU_OP2_INST_MAX_UINT:
case ALU_OP2_INST_MIN_UINT:
case ALU_OP2_INST_SETE_INT:
case ALU_OP2_INST_SETGT_INT:
case ALU_OP2_INST_SETGE_INT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1415,19 +1415,23 @@ void _emitALUOP2InstructionCode(LatteDecompilerShaderContext* shaderContext, Lat
}
else if( aluInstruction->opcode == ALU_OP2_INST_ADD_INT )
_emitALUOperationBinary<LATTE_DECOMPILER_DTYPE_SIGNED_INT>(shaderContext, aluInstruction, " + ");
else if( aluInstruction->opcode == ALU_OP2_INST_MAX_INT || aluInstruction->opcode == ALU_OP2_INST_MIN_INT )
else if( aluInstruction->opcode == ALU_OP2_INST_MAX_INT || aluInstruction->opcode == ALU_OP2_INST_MIN_INT ||
aluInstruction->opcode == ALU_OP2_INST_MAX_UINT || aluInstruction->opcode == ALU_OP2_INST_MIN_UINT)
{
// not verified
bool isUnsigned = aluInstruction->opcode == ALU_OP2_INST_MAX_UINT || aluInstruction->opcode == ALU_OP2_INST_MIN_UINT;
auto opType = isUnsigned ? LATTE_DECOMPILER_DTYPE_UNSIGNED_INT : LATTE_DECOMPILER_DTYPE_SIGNED_INT;
_emitInstructionOutputVariableName(shaderContext, aluInstruction);
if( aluInstruction->opcode == ALU_OP2_INST_MAX_INT )
src->add(" = max(");
src->add(" = ");
_emitTypeConversionPrefix(shaderContext, opType, outputType);
if( aluInstruction->opcode == ALU_OP2_INST_MAX_INT || aluInstruction->opcode == ALU_OP2_INST_MAX_UINT )
src->add("max(");
else
src->add(" = min(");
_emitTypeConversionPrefix(shaderContext, LATTE_DECOMPILER_DTYPE_SIGNED_INT, outputType);
_emitOperandInputCode(shaderContext, aluInstruction, 0, LATTE_DECOMPILER_DTYPE_SIGNED_INT);
src->add("min(");
_emitOperandInputCode(shaderContext, aluInstruction, 0, opType);
src->add(", ");
_emitOperandInputCode(shaderContext, aluInstruction, 1, LATTE_DECOMPILER_DTYPE_SIGNED_INT);
_emitTypeConversionSuffix(shaderContext, LATTE_DECOMPILER_DTYPE_SIGNED_INT, outputType);
_emitOperandInputCode(shaderContext, aluInstruction, 1, opType);
_emitTypeConversionSuffix(shaderContext, opType, outputType);
src->add(");" _CRLF);
}
else if( aluInstruction->opcode == ALU_OP2_INST_SUB_INT )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
#define ALU_OP2_INST_SUB_INT (0x035) // integer instruction
#define ALU_OP2_INST_MAX_INT (0x036) // integer instruction
#define ALU_OP2_INST_MIN_INT (0x037) // integer instruction
#define ALU_OP2_INST_MAX_UINT (0x038) // integer instruction
#define ALU_OP2_INST_MIN_UINT (0x039) // integer instruction
#define ALU_OP2_INST_SETE_INT (0x03A) // integer instruction
#define ALU_OP2_INST_SETGT_INT (0x03B) // integer instruction
#define ALU_OP2_INST_SETGE_INT (0x03C) // integer instruction
Expand Down
2 changes: 1 addition & 1 deletion src/Cafe/OS/libs/gx2/GX2_Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ namespace GX2
{
if(aluRegisterOffset&0x8000)
{
cemuLog_logDebug(LogType::Force, "_GX2SubmitUniformReg(): Unhandled loop const special case or invalid offset");
cemuLog_logDebugOnce(LogType::Force, "_GX2SubmitUniformReg(): Unhandled loop const special case or invalid offset");
return;
}
if((aluRegisterOffset+sizeInU32s) > 0x400)
Expand Down
2 changes: 1 addition & 1 deletion src/input/emulated/VPADController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ bool VPADController::push_rumble(uint8* pattern, uint8 length)
std::scoped_lock lock(m_rumble_mutex);
if (m_rumble_queue.size() >= 5)
{
cemuLog_logDebug(LogType::Force, "too many cmds");
cemuLog_logDebugOnce(LogType::Force, "VPADControlMotor(): Pattern too long");
return false;
}

Expand Down

0 comments on commit c3e29fb

Please sign in to comment.