yuzu-android/src/video_core/macro/macro_interpreter.h

103 lines
3.2 KiB
C++
Raw Normal View History

2020-05-28 21:53:27 -07:00
// Copyright 2020 yuzu Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <array>
#include <optional>
2020-05-28 21:53:27 -07:00
#include <vector>
#include "common/bit_field.h"
#include "common/common_types.h"
2020-05-28 21:53:27 -07:00
#include "video_core/macro/macro.h"
namespace Tegra {
namespace Engines {
class Maxwell3D;
}
2020-05-28 21:53:27 -07:00
class MacroInterpreter final : public MacroEngine {
public:
explicit MacroInterpreter(Engines::Maxwell3D& maxwell3d);
2020-05-28 21:53:27 -07:00
protected:
std::unique_ptr<CachedMacro> Compile(const std::vector<u32>& code) override;
private:
2020-05-28 21:53:27 -07:00
Engines::Maxwell3D& maxwell3d;
};
2020-05-28 21:53:27 -07:00
class MacroInterpreterImpl : public CachedMacro {
public:
MacroInterpreterImpl(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& code);
2020-06-02 23:33:38 -07:00
void Execute(const std::vector<u32>& parameters, u32 method) override;
2020-05-28 21:53:27 -07:00
private:
/// 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.
* @param offset Offset to start execution at.
* @param is_delay_slot Whether the current step is being executed due to a delay slot in a
* previous instruction.
*/
2020-05-28 21:53:27 -07:00
bool Step(bool is_delay_slot);
/// Calculates the result of an ALU operation. src_a OP src_b;
2020-05-28 21:53:27 -07:00
u32 GetALUResult(Macro::ALUOperation operation, u32 src_a, u32 src_b);
/// Performs the result operation on the input result and stores it in the specified register
/// (if necessary).
2020-05-28 21:53:27 -07:00
void ProcessResult(Macro::ResultOperation operation, u32 reg, u32 result);
/// Evaluates the branch condition and returns whether the branch should be taken or not.
2020-05-28 21:53:27 -07:00
bool EvaluateBranchCondition(Macro::BranchCondition cond, u32 value) const;
/// Reads an opcode at the current program counter location.
2020-05-28 21:53:27 -07:00
Macro::Opcode GetOpcode() const;
/// 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;
/// Current program counter
u32 pc;
/// Program counter to execute at after the delay slot is executed.
std::optional<u32> delayed_pc;
/// General purpose macro registers.
2020-05-28 21:53:27 -07:00
std::array<u32, Macro::NUM_MACRO_REGISTERS> registers = {};
/// Method address to use for the next Send instruction.
2020-05-28 21:53:27 -07:00
Macro::MethodAddress method_address = {};
/// Input parameters of the current macro.
2019-08-24 21:08:35 -07:00
std::unique_ptr<u32[]> parameters;
std::size_t num_parameters = 0;
std::size_t parameters_capacity = 0;
/// Index of the next parameter that will be fetched by the 'parm' instruction.
u32 next_parameter_index = 0;
2019-08-24 21:08:35 -07:00
bool carry_flag = false;
2020-05-28 21:53:27 -07:00
const std::vector<u32>& code;
};
2020-05-28 21:53:27 -07:00
} // namespace Tegra