2020-06-04 17:42:19 +02:00
|
|
|
// Copyright 2020 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2020-06-05 05:09:52 +02:00
|
|
|
#include <array>
|
2020-06-04 17:42:19 +02:00
|
|
|
#include <vector>
|
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2022-01-25 19:15:45 +01:00
|
|
|
#include "video_core/macro/macro.h"
|
2020-06-04 17:42:19 +02:00
|
|
|
#include "video_core/macro/macro_hle.h"
|
|
|
|
#include "video_core/rasterizer_interface.h"
|
|
|
|
|
|
|
|
namespace Tegra {
|
2020-06-24 04:18:33 +02:00
|
|
|
namespace {
|
2022-01-25 19:15:45 +01:00
|
|
|
|
|
|
|
using HLEFunction = void (*)(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& parameters);
|
|
|
|
|
2020-06-04 17:42:19 +02:00
|
|
|
// HLE'd functions
|
2020-07-17 04:01:45 +02:00
|
|
|
void HLE_771BB18C62444DA0(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& parameters) {
|
2020-06-04 17:42:19 +02:00
|
|
|
const u32 instance_count = parameters[2] & maxwell3d.GetRegisterValue(0xD1B);
|
|
|
|
|
|
|
|
maxwell3d.regs.draw.topology.Assign(
|
2020-07-17 04:16:08 +02:00
|
|
|
static_cast<Tegra::Engines::Maxwell3D::Regs::PrimitiveTopology>(parameters[0] & 0x3ffffff));
|
2020-06-04 17:42:19 +02:00
|
|
|
maxwell3d.regs.vb_base_instance = parameters[5];
|
|
|
|
maxwell3d.mme_draw.instance_count = instance_count;
|
|
|
|
maxwell3d.regs.vb_element_base = parameters[3];
|
|
|
|
maxwell3d.regs.index_array.count = parameters[1];
|
|
|
|
maxwell3d.regs.index_array.first = parameters[4];
|
|
|
|
|
|
|
|
if (maxwell3d.ShouldExecute()) {
|
2020-06-11 05:58:57 +02:00
|
|
|
maxwell3d.Rasterizer().Draw(true, true);
|
2020-06-04 17:42:19 +02:00
|
|
|
}
|
|
|
|
maxwell3d.regs.index_array.count = 0;
|
|
|
|
maxwell3d.mme_draw.instance_count = 0;
|
2020-06-05 06:00:00 +02:00
|
|
|
maxwell3d.mme_draw.current_mode = Engines::Maxwell3D::MMEDrawMode::Undefined;
|
2020-06-04 17:42:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-17 04:01:45 +02:00
|
|
|
void HLE_0D61FC9FAAC9FCAD(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& parameters) {
|
2020-06-04 17:42:19 +02:00
|
|
|
const u32 count = (maxwell3d.GetRegisterValue(0xD1B) & parameters[2]);
|
|
|
|
|
|
|
|
maxwell3d.regs.vertex_buffer.first = parameters[3];
|
|
|
|
maxwell3d.regs.vertex_buffer.count = parameters[1];
|
|
|
|
maxwell3d.regs.vb_base_instance = parameters[4];
|
|
|
|
maxwell3d.regs.draw.topology.Assign(
|
|
|
|
static_cast<Tegra::Engines::Maxwell3D::Regs::PrimitiveTopology>(parameters[0]));
|
|
|
|
maxwell3d.mme_draw.instance_count = count;
|
|
|
|
|
|
|
|
if (maxwell3d.ShouldExecute()) {
|
2020-06-11 05:58:57 +02:00
|
|
|
maxwell3d.Rasterizer().Draw(false, true);
|
2020-06-04 17:42:19 +02:00
|
|
|
}
|
|
|
|
maxwell3d.regs.vertex_buffer.count = 0;
|
|
|
|
maxwell3d.mme_draw.instance_count = 0;
|
2020-06-05 06:00:00 +02:00
|
|
|
maxwell3d.mme_draw.current_mode = Engines::Maxwell3D::MMEDrawMode::Undefined;
|
2020-06-04 17:42:19 +02:00
|
|
|
}
|
|
|
|
|
2020-07-17 04:01:45 +02:00
|
|
|
void HLE_0217920100488FF7(Engines::Maxwell3D& maxwell3d, const std::vector<u32>& parameters) {
|
2020-06-04 17:42:19 +02:00
|
|
|
const u32 instance_count = (maxwell3d.GetRegisterValue(0xD1B) & parameters[2]);
|
|
|
|
const u32 element_base = parameters[4];
|
|
|
|
const u32 base_instance = parameters[5];
|
|
|
|
maxwell3d.regs.index_array.first = parameters[3];
|
|
|
|
maxwell3d.regs.reg_array[0x446] = element_base; // vertex id base?
|
|
|
|
maxwell3d.regs.index_array.count = parameters[1];
|
|
|
|
maxwell3d.regs.vb_element_base = element_base;
|
|
|
|
maxwell3d.regs.vb_base_instance = base_instance;
|
|
|
|
maxwell3d.mme_draw.instance_count = instance_count;
|
2020-06-05 04:59:59 +02:00
|
|
|
maxwell3d.CallMethodFromMME(0x8e3, 0x640);
|
|
|
|
maxwell3d.CallMethodFromMME(0x8e4, element_base);
|
|
|
|
maxwell3d.CallMethodFromMME(0x8e5, base_instance);
|
2020-06-04 17:42:19 +02:00
|
|
|
maxwell3d.regs.draw.topology.Assign(
|
|
|
|
static_cast<Tegra::Engines::Maxwell3D::Regs::PrimitiveTopology>(parameters[0]));
|
|
|
|
if (maxwell3d.ShouldExecute()) {
|
2020-06-11 05:58:57 +02:00
|
|
|
maxwell3d.Rasterizer().Draw(true, true);
|
2020-06-04 17:42:19 +02:00
|
|
|
}
|
|
|
|
maxwell3d.regs.reg_array[0x446] = 0x0; // vertex id base?
|
|
|
|
maxwell3d.regs.index_array.count = 0;
|
|
|
|
maxwell3d.regs.vb_element_base = 0x0;
|
|
|
|
maxwell3d.regs.vb_base_instance = 0x0;
|
|
|
|
maxwell3d.mme_draw.instance_count = 0;
|
2020-06-05 04:59:59 +02:00
|
|
|
maxwell3d.CallMethodFromMME(0x8e3, 0x640);
|
|
|
|
maxwell3d.CallMethodFromMME(0x8e4, 0x0);
|
|
|
|
maxwell3d.CallMethodFromMME(0x8e5, 0x0);
|
2020-06-05 06:00:00 +02:00
|
|
|
maxwell3d.mme_draw.current_mode = Engines::Maxwell3D::MMEDrawMode::Undefined;
|
2020-06-04 17:42:19 +02:00
|
|
|
}
|
|
|
|
|
2020-06-24 04:18:33 +02:00
|
|
|
constexpr std::array<std::pair<u64, HLEFunction>, 3> hle_funcs{{
|
2020-07-17 03:59:23 +02:00
|
|
|
{0x771BB18C62444DA0, &HLE_771BB18C62444DA0},
|
|
|
|
{0x0D61FC9FAAC9FCAD, &HLE_0D61FC9FAAC9FCAD},
|
|
|
|
{0x0217920100488FF7, &HLE_0217920100488FF7},
|
2020-06-24 04:18:33 +02:00
|
|
|
}};
|
2020-06-04 17:42:19 +02:00
|
|
|
|
2022-01-25 19:15:45 +01:00
|
|
|
class HLEMacroImpl final : public CachedMacro {
|
|
|
|
public:
|
|
|
|
explicit HLEMacroImpl(Engines::Maxwell3D& maxwell3d_, HLEFunction func_)
|
|
|
|
: maxwell3d{maxwell3d_}, func{func_} {}
|
|
|
|
|
|
|
|
void Execute(const std::vector<u32>& parameters, u32 method) override {
|
|
|
|
func(maxwell3d, parameters);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Engines::Maxwell3D& maxwell3d;
|
|
|
|
HLEFunction func;
|
|
|
|
};
|
|
|
|
} // Anonymous namespace
|
|
|
|
|
2020-12-04 20:39:12 +01:00
|
|
|
HLEMacro::HLEMacro(Engines::Maxwell3D& maxwell3d_) : maxwell3d{maxwell3d_} {}
|
2020-06-04 17:42:19 +02:00
|
|
|
HLEMacro::~HLEMacro() = default;
|
|
|
|
|
2022-01-25 19:50:10 +01:00
|
|
|
std::unique_ptr<CachedMacro> HLEMacro::GetHLEProgram(u64 hash) const {
|
2020-06-24 04:18:33 +02:00
|
|
|
const auto it = std::find_if(hle_funcs.cbegin(), hle_funcs.cend(),
|
|
|
|
[hash](const auto& pair) { return pair.first == hash; });
|
2020-06-05 05:09:52 +02:00
|
|
|
if (it == hle_funcs.end()) {
|
2022-01-25 19:50:10 +01:00
|
|
|
return nullptr;
|
2020-06-04 17:42:19 +02:00
|
|
|
}
|
2020-06-05 05:09:52 +02:00
|
|
|
return std::make_unique<HLEMacroImpl>(maxwell3d, it->second);
|
2020-06-04 17:42:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Tegra
|