2020-05-29 04:53:27 +00:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
2018-03-28 20:14:47 +00:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <array>
|
2018-10-30 04:03:25 +00:00
|
|
|
#include <optional>
|
2020-05-29 04:53:27 +00:00
|
|
|
#include <vector>
|
2018-03-28 20:14:47 +00:00
|
|
|
#include "common/bit_field.h"
|
|
|
|
#include "common/common_types.h"
|
2020-05-29 04:53:27 +00:00
|
|
|
#include "video_core/macro/macro.h"
|
2018-03-28 20:14:47 +00:00
|
|
|
|
|
|
|
namespace Tegra {
|
|
|
|
namespace Engines {
|
|
|
|
class Maxwell3D;
|
|
|
|
}
|
|
|
|
|
2020-05-29 04:53:27 +00:00
|
|
|
class MacroInterpreter final : public MacroEngine {
|
2018-03-28 20:14:47 +00:00
|
|
|
public:
|
2020-12-04 19:39:12 +00:00
|
|
|
explicit MacroInterpreter(Engines::Maxwell3D& maxwell3d_);
|
2018-03-28 20:14:47 +00:00
|
|
|
|
2020-05-29 04:53:27 +00:00
|
|
|
protected:
|
|
|
|
std::unique_ptr<CachedMacro> Compile(const std::vector<u32>& code) override;
|
2018-03-28 20:14:47 +00:00
|
|
|
|
|
|
|
private:
|
2020-05-29 04:53:27 +00:00
|
|
|
Engines::Maxwell3D& maxwell3d;
|
|
|
|
};
|
2018-03-28 20:14:47 +00:00
|
|
|
|
2020-05-29 04:53:27 +00:00
|
|
|
class MacroInterpreterImpl : public CachedMacro {
|
|
|
|
public:
|
2020-12-04 19:39:12 +00:00
|
|
|
explicit MacroInterpreterImpl(Engines::Maxwell3D& maxwell3d_, const std::vector<u32>& code_);
|
|
|
|
void Execute(const std::vector<u32>& params, u32 method) override;
|
2018-03-28 20:14:47 +00:00
|
|
|
|
2020-05-29 04:53:27 +00:00
|
|
|
private:
|
2018-03-28 20:14:47 +00:00
|
|
|
/// Resets the execution engine state, zeroing registers, etc.
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Executes a single macro instruction located at the current program counter. Returns whether
|
|
|
|
* the interpreter should keep running.
|
2020-12-04 19:39:12 +00:00
|
|
|
*
|
2018-03-28 20:14:47 +00:00
|
|
|
* @param is_delay_slot Whether the current step is being executed due to a delay slot in a
|
2020-12-04 19:39:12 +00:00
|
|
|
* previous instruction.
|
2018-03-28 20:14:47 +00:00
|
|
|
*/
|
2020-05-29 04:53:27 +00:00
|
|
|
bool Step(bool is_delay_slot);
|
2018-03-28 20:14:47 +00:00
|
|
|
|
|
|
|
/// Calculates the result of an ALU operation. src_a OP src_b;
|
2020-05-29 04:53:27 +00:00
|
|
|
u32 GetALUResult(Macro::ALUOperation operation, u32 src_a, u32 src_b);
|
2018-03-28 20:14:47 +00:00
|
|
|
|
|
|
|
/// Performs the result operation on the input result and stores it in the specified register
|
|
|
|
/// (if necessary).
|
2020-05-29 04:53:27 +00:00
|
|
|
void ProcessResult(Macro::ResultOperation operation, u32 reg, u32 result);
|
2018-03-28 20:14:47 +00:00
|
|
|
|
|
|
|
/// Evaluates the branch condition and returns whether the branch should be taken or not.
|
2020-05-29 04:53:27 +00:00
|
|
|
bool EvaluateBranchCondition(Macro::BranchCondition cond, u32 value) const;
|
2018-03-28 20:14:47 +00:00
|
|
|
|
|
|
|
/// Reads an opcode at the current program counter location.
|
2020-05-29 04:53:27 +00:00
|
|
|
Macro::Opcode GetOpcode() const;
|
2018-03-28 20:14:47 +00:00
|
|
|
|
|
|
|
/// Returns the specified register's value. Register 0 is hardcoded to always return 0.
|
|
|
|
u32 GetRegister(u32 register_id) const;
|
|
|
|
|
|
|
|
/// Sets the register to the input value.
|
|
|
|
void SetRegister(u32 register_id, u32 value);
|
|
|
|
|
|
|
|
/// Sets the method address to use for the next Send instruction.
|
|
|
|
void SetMethodAddress(u32 address);
|
|
|
|
|
|
|
|
/// Calls a GPU Engine method with the input parameter.
|
|
|
|
void Send(u32 value);
|
|
|
|
|
|
|
|
/// Reads a GPU register located at the method address.
|
|
|
|
u32 Read(u32 method) const;
|
|
|
|
|
|
|
|
/// Returns the next parameter in the parameter queue.
|
|
|
|
u32 FetchParameter();
|
|
|
|
|
|
|
|
Engines::Maxwell3D& maxwell3d;
|
|
|
|
|
2019-10-15 21:36:15 +00:00
|
|
|
/// Current program counter
|
|
|
|
u32 pc;
|
|
|
|
/// Program counter to execute at after the delay slot is executed.
|
|
|
|
std::optional<u32> delayed_pc;
|
2018-03-28 20:14:47 +00:00
|
|
|
|
|
|
|
/// General purpose macro registers.
|
2020-05-29 04:53:27 +00:00
|
|
|
std::array<u32, Macro::NUM_MACRO_REGISTERS> registers = {};
|
2018-03-28 20:14:47 +00:00
|
|
|
|
|
|
|
/// Method address to use for the next Send instruction.
|
2020-05-29 04:53:27 +00:00
|
|
|
Macro::MethodAddress method_address = {};
|
2018-03-28 20:14:47 +00:00
|
|
|
|
|
|
|
/// Input parameters of the current macro.
|
2019-08-25 04:08:35 +00:00
|
|
|
std::unique_ptr<u32[]> parameters;
|
|
|
|
std::size_t num_parameters = 0;
|
|
|
|
std::size_t parameters_capacity = 0;
|
2018-03-28 20:14:47 +00:00
|
|
|
/// Index of the next parameter that will be fetched by the 'parm' instruction.
|
|
|
|
u32 next_parameter_index = 0;
|
2018-11-21 19:32:21 +00:00
|
|
|
|
2019-08-25 04:08:35 +00:00
|
|
|
bool carry_flag = false;
|
2020-05-29 04:53:27 +00:00
|
|
|
const std::vector<u32>& code;
|
2018-03-28 20:14:47 +00:00
|
|
|
};
|
2020-05-29 04:53:27 +00:00
|
|
|
|
2018-03-28 20:14:47 +00:00
|
|
|
} // namespace Tegra
|