2022-04-23 04:59:50 -04:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-02-11 21:34:20 -05:00
|
|
|
|
2018-10-25 23:42:39 -04:00
|
|
|
#include <cstring>
|
2019-11-28 00:15:34 -05:00
|
|
|
#include <optional>
|
2018-02-12 12:34:41 -05:00
|
|
|
#include "common/assert.h"
|
2018-03-25 00:35:06 -04:00
|
|
|
#include "core/core.h"
|
2018-08-31 23:25:18 -04:00
|
|
|
#include "core/core_timing.h"
|
2022-03-11 08:47:01 -05:00
|
|
|
#include "video_core/dirty_flags.h"
|
2022-12-06 00:45:26 -05:00
|
|
|
#include "video_core/engines/draw_manager.h"
|
2018-02-11 21:34:20 -05:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2020-02-10 09:32:51 -05:00
|
|
|
#include "video_core/gpu.h"
|
2019-04-05 18:21:15 -04:00
|
|
|
#include "video_core/memory_manager.h"
|
2018-03-24 02:41:16 -04:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2018-03-19 19:00:29 -04:00
|
|
|
#include "video_core/textures/texture.h"
|
2018-02-11 21:34:20 -05:00
|
|
|
|
2018-10-20 15:58:06 -04:00
|
|
|
namespace Tegra::Engines {
|
2018-02-11 21:34:20 -05:00
|
|
|
|
2019-11-28 00:15:34 -05:00
|
|
|
using VideoCore::QueryType;
|
|
|
|
|
2018-03-18 04:13:22 -04:00
|
|
|
/// First register id that is actually a Macro call.
|
|
|
|
constexpr u32 MacroRegistersStart = 0xE00;
|
|
|
|
|
2020-06-10 23:58:57 -04:00
|
|
|
Maxwell3D::Maxwell3D(Core::System& system_, MemoryManager& memory_manager_)
|
2022-12-06 00:45:26 -05:00
|
|
|
: draw_manager{std::make_unique<DrawManager>(this)}, system{system_},
|
|
|
|
memory_manager{memory_manager_}, macro_engine{GetMacroEngine(*this)}, upload_state{
|
|
|
|
memory_manager,
|
|
|
|
regs.upload} {
|
2019-12-26 20:14:10 -05:00
|
|
|
dirty.flags.flip();
|
2018-10-25 23:42:39 -04:00
|
|
|
InitializeRegisterDefaults();
|
|
|
|
}
|
|
|
|
|
2020-06-10 23:58:57 -04:00
|
|
|
Maxwell3D::~Maxwell3D() = default;
|
|
|
|
|
2021-01-05 02:09:39 -05:00
|
|
|
void Maxwell3D::BindRasterizer(VideoCore::RasterizerInterface* rasterizer_) {
|
|
|
|
rasterizer = rasterizer_;
|
2022-01-29 16:00:49 -05:00
|
|
|
upload_state.BindRasterizer(rasterizer_);
|
2020-06-10 23:58:57 -04:00
|
|
|
}
|
|
|
|
|
2018-10-25 23:42:39 -04:00
|
|
|
void Maxwell3D::InitializeRegisterDefaults() {
|
|
|
|
// Initializes registers to their default values - what games expect them to be at boot. This is
|
|
|
|
// for certain registers that may not be explicitly set by games.
|
|
|
|
|
|
|
|
// Reset all registers to zero
|
|
|
|
std::memset(®s, 0, sizeof(regs));
|
|
|
|
|
|
|
|
// Depth range near/far is not always set, but is expected to be the default 0.0f, 1.0f. This is
|
|
|
|
// needed for ARMS.
|
2019-05-14 08:53:16 -04:00
|
|
|
for (auto& viewport : regs.viewports) {
|
|
|
|
viewport.depth_range_near = 0.0f;
|
|
|
|
viewport.depth_range_far = 1.0f;
|
2018-10-25 23:42:39 -04:00
|
|
|
}
|
2020-05-04 16:49:48 -04:00
|
|
|
for (auto& viewport : regs.viewport_transform) {
|
|
|
|
viewport.swizzle.x.Assign(Regs::ViewportSwizzle::PositiveX);
|
|
|
|
viewport.swizzle.y.Assign(Regs::ViewportSwizzle::PositiveY);
|
|
|
|
viewport.swizzle.z.Assign(Regs::ViewportSwizzle::PositiveZ);
|
|
|
|
viewport.swizzle.w.Assign(Regs::ViewportSwizzle::PositiveW);
|
|
|
|
}
|
2019-01-22 02:14:29 -05:00
|
|
|
|
2018-11-01 23:21:25 -04:00
|
|
|
// Doom and Bomberman seems to use the uninitialized registers and just enable blend
|
|
|
|
// so initialize blend registers with sane values
|
2022-08-12 05:58:09 -04:00
|
|
|
regs.blend.color_op = Regs::Blend::Equation::Add_D3D;
|
|
|
|
regs.blend.color_source = Regs::Blend::Factor::One_D3D;
|
|
|
|
regs.blend.color_dest = Regs::Blend::Factor::Zero_D3D;
|
|
|
|
regs.blend.alpha_op = Regs::Blend::Equation::Add_D3D;
|
|
|
|
regs.blend.alpha_source = Regs::Blend::Factor::One_D3D;
|
|
|
|
regs.blend.alpha_dest = Regs::Blend::Factor::Zero_D3D;
|
|
|
|
for (auto& blend : regs.blend_per_target) {
|
|
|
|
blend.color_op = Regs::Blend::Equation::Add_D3D;
|
|
|
|
blend.color_source = Regs::Blend::Factor::One_D3D;
|
|
|
|
blend.color_dest = Regs::Blend::Factor::Zero_D3D;
|
|
|
|
blend.alpha_op = Regs::Blend::Equation::Add_D3D;
|
|
|
|
blend.alpha_source = Regs::Blend::Factor::One_D3D;
|
|
|
|
blend.alpha_dest = Regs::Blend::Factor::Zero_D3D;
|
|
|
|
}
|
|
|
|
regs.stencil_front_op.fail = Regs::StencilOp::Op::Keep_D3D;
|
|
|
|
regs.stencil_front_op.zfail = Regs::StencilOp::Op::Keep_D3D;
|
|
|
|
regs.stencil_front_op.zpass = Regs::StencilOp::Op::Keep_D3D;
|
|
|
|
regs.stencil_front_op.func = Regs::ComparisonOp::Always_GL;
|
2022-10-10 15:32:38 -04:00
|
|
|
regs.stencil_front_func_mask = 0xFFFFFFFF;
|
|
|
|
regs.stencil_front_mask = 0xFFFFFFFF;
|
2018-11-06 22:27:12 -05:00
|
|
|
regs.stencil_two_side_enable = 1;
|
2022-08-12 05:58:09 -04:00
|
|
|
regs.stencil_back_op.fail = Regs::StencilOp::Op::Keep_D3D;
|
|
|
|
regs.stencil_back_op.zfail = Regs::StencilOp::Op::Keep_D3D;
|
|
|
|
regs.stencil_back_op.zpass = Regs::StencilOp::Op::Keep_D3D;
|
|
|
|
regs.stencil_back_op.func = Regs::ComparisonOp::Always_GL;
|
2022-10-10 15:32:38 -04:00
|
|
|
regs.stencil_back_func_mask = 0xFFFFFFFF;
|
|
|
|
regs.stencil_back_mask = 0xFFFFFFFF;
|
2019-01-22 02:14:29 -05:00
|
|
|
|
2022-08-12 05:58:09 -04:00
|
|
|
regs.depth_test_func = Regs::ComparisonOp::Always_GL;
|
|
|
|
regs.gl_front_face = Regs::FrontFace::CounterClockWise;
|
|
|
|
regs.gl_cull_face = Regs::CullFace::Back;
|
2019-07-17 19:37:01 -04:00
|
|
|
|
2018-11-13 18:15:13 -05:00
|
|
|
// TODO(Rodrigo): Most games do not set a point size. I think this is a case of a
|
|
|
|
// register carrying a default value. Assume it's OpenGL's default (1).
|
|
|
|
regs.point_size = 1.0f;
|
2018-11-20 19:57:20 -05:00
|
|
|
|
|
|
|
// TODO(bunnei): Some games do not initialize the color masks (e.g. Sonic Mania). Assuming a
|
|
|
|
// default of enabled fixes rendering here.
|
2019-05-14 08:53:16 -04:00
|
|
|
for (auto& color_mask : regs.color_mask) {
|
|
|
|
color_mask.R.Assign(1);
|
|
|
|
color_mask.G.Assign(1);
|
|
|
|
color_mask.B.Assign(1);
|
|
|
|
color_mask.A.Assign(1);
|
2018-11-20 19:57:20 -05:00
|
|
|
}
|
2019-01-22 02:14:29 -05:00
|
|
|
|
2020-04-16 20:15:07 -04:00
|
|
|
for (auto& format : regs.vertex_attrib_format) {
|
|
|
|
format.constant.Assign(1);
|
|
|
|
}
|
|
|
|
|
2019-12-18 17:26:52 -05:00
|
|
|
// NVN games expect these values to be enabled at boot
|
|
|
|
regs.rasterize_enable = 1;
|
2022-08-12 05:58:09 -04:00
|
|
|
regs.color_target_mrt_enable = 1;
|
2019-09-03 00:05:23 -04:00
|
|
|
regs.framebuffer_srgb = 1;
|
2020-05-20 00:13:40 -04:00
|
|
|
regs.line_width_aliased = 1.0f;
|
|
|
|
regs.line_width_smooth = 1.0f;
|
2022-08-12 05:58:09 -04:00
|
|
|
regs.gl_front_face = Maxwell3D::Regs::FrontFace::ClockWise;
|
2020-05-19 21:01:25 -04:00
|
|
|
regs.polygon_mode_back = Maxwell3D::Regs::PolygonMode::Fill;
|
|
|
|
regs.polygon_mode_front = Maxwell3D::Regs::PolygonMode::Fill;
|
2019-12-18 17:26:52 -05:00
|
|
|
|
2020-03-22 02:35:11 -04:00
|
|
|
shadow_state = regs;
|
2018-10-25 23:42:39 -04:00
|
|
|
}
|
2018-02-11 21:34:20 -05:00
|
|
|
|
2020-07-12 04:03:05 -04:00
|
|
|
void Maxwell3D::ProcessMacro(u32 method, const u32* base_start, u32 amount, bool is_last_call) {
|
|
|
|
if (executing_macro == 0) {
|
|
|
|
// A macro call must begin by writing the macro method's register, not its argument.
|
|
|
|
ASSERT_MSG((method % 2) == 0,
|
|
|
|
"Can't start macro execution by writing to the ARGS register");
|
|
|
|
executing_macro = method;
|
|
|
|
}
|
|
|
|
|
2020-07-12 04:05:04 -04:00
|
|
|
macro_params.insert(macro_params.end(), base_start, base_start + amount);
|
2022-02-09 09:39:40 -05:00
|
|
|
for (size_t i = 0; i < amount; i++) {
|
|
|
|
macro_addresses.push_back(current_dma_segment + i * sizeof(u32));
|
|
|
|
}
|
2022-03-05 02:01:13 -05:00
|
|
|
macro_segments.emplace_back(current_dma_segment, amount);
|
2020-07-12 04:03:05 -04:00
|
|
|
|
|
|
|
// Call the macro when there are no more parameters in the command buffer
|
|
|
|
if (is_last_call) {
|
|
|
|
CallMacroMethod(executing_macro, macro_params);
|
|
|
|
macro_params.clear();
|
2022-02-09 09:39:40 -05:00
|
|
|
macro_addresses.clear();
|
2022-03-05 02:01:13 -05:00
|
|
|
macro_segments.clear();
|
2020-07-12 04:03:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-05 02:01:13 -05:00
|
|
|
void Maxwell3D::RefreshParameters() {
|
|
|
|
size_t current_index = 0;
|
|
|
|
for (auto& segment : macro_segments) {
|
|
|
|
if (segment.first == 0) {
|
|
|
|
current_index += segment.second;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
memory_manager.ReadBlock(segment.first, ¯o_params[current_index],
|
|
|
|
sizeof(u32) * segment.second);
|
|
|
|
current_index += segment.second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 Maxwell3D::GetMaxCurrentVertices() {
|
|
|
|
u32 num_vertices = 0;
|
|
|
|
for (size_t index = 0; index < Regs::NumVertexArrays; ++index) {
|
|
|
|
const auto& array = regs.vertex_streams[index];
|
|
|
|
if (array.enable == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const auto& attribute = regs.vertex_attrib_format[index];
|
|
|
|
if (attribute.constant) {
|
|
|
|
num_vertices = std::max(num_vertices, 1U);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const auto& limit = regs.vertex_stream_limits[index];
|
|
|
|
const GPUVAddr gpu_addr_begin = array.Address();
|
|
|
|
const GPUVAddr gpu_addr_end = limit.Address() + 1;
|
|
|
|
const u32 address_size = static_cast<u32>(gpu_addr_end - gpu_addr_begin);
|
|
|
|
num_vertices = std::max(
|
|
|
|
num_vertices, address_size / std::max(attribute.SizeInBytes(), array.stride.Value()));
|
|
|
|
}
|
|
|
|
return num_vertices;
|
|
|
|
}
|
|
|
|
|
2022-10-20 19:46:51 -04:00
|
|
|
size_t Maxwell3D::EstimateIndexBufferSize() {
|
|
|
|
GPUVAddr start_address = regs.index_buffer.StartAddress();
|
|
|
|
GPUVAddr end_address = regs.index_buffer.EndAddress();
|
|
|
|
return std::min<size_t>(memory_manager.GetMemoryLayoutSize(start_address),
|
|
|
|
static_cast<size_t>(end_address - start_address));
|
|
|
|
}
|
|
|
|
|
2020-07-12 04:03:05 -04:00
|
|
|
u32 Maxwell3D::ProcessShadowRam(u32 method, u32 argument) {
|
|
|
|
// Keep track of the register value in shadow_state when requested.
|
|
|
|
const auto control = shadow_state.shadow_ram_control;
|
|
|
|
if (control == Regs::ShadowRamControl::Track ||
|
|
|
|
control == Regs::ShadowRamControl::TrackWithFilter) {
|
|
|
|
shadow_state.reg_array[method] = argument;
|
|
|
|
return argument;
|
|
|
|
}
|
|
|
|
if (control == Regs::ShadowRamControl::Replay) {
|
|
|
|
return shadow_state.reg_array[method];
|
|
|
|
}
|
|
|
|
return argument;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Maxwell3D::ProcessDirtyRegisters(u32 method, u32 argument) {
|
|
|
|
if (regs.reg_array[method] == argument) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
regs.reg_array[method] = argument;
|
|
|
|
|
|
|
|
for (const auto& table : dirty.tables) {
|
|
|
|
dirty.flags[table[method]] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Maxwell3D::ProcessMethodCall(u32 method, u32 argument, u32 nonshadow_argument,
|
|
|
|
bool is_last_call) {
|
|
|
|
switch (method) {
|
|
|
|
case MAXWELL3D_REG_INDEX(wait_for_idle):
|
|
|
|
return rasterizer->WaitForIdle();
|
|
|
|
case MAXWELL3D_REG_INDEX(shadow_ram_control):
|
|
|
|
shadow_state.shadow_ram_control = static_cast<Regs::ShadowRamControl>(nonshadow_argument);
|
|
|
|
return;
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(load_mme.instruction_ptr):
|
|
|
|
return macro_engine->ClearCode(regs.load_mme.instruction_ptr);
|
|
|
|
case MAXWELL3D_REG_INDEX(load_mme.instruction):
|
|
|
|
return macro_engine->AddCode(regs.load_mme.instruction_ptr, argument);
|
|
|
|
case MAXWELL3D_REG_INDEX(load_mme.start_address):
|
2020-07-12 04:03:05 -04:00
|
|
|
return ProcessMacroBind(argument);
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(falcon[4]):
|
2020-07-12 04:03:05 -04:00
|
|
|
return ProcessFirmwareCall4();
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 1:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 2:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 3:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 4:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 5:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 6:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 7:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 8:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 9:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 10:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 11:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 12:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 13:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 14:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 15:
|
2022-03-14 19:11:41 -04:00
|
|
|
return ProcessCBData(argument);
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(bind_groups[0].raw_config):
|
2020-07-12 04:03:05 -04:00
|
|
|
return ProcessCBBind(0);
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(bind_groups[1].raw_config):
|
2020-07-12 04:03:05 -04:00
|
|
|
return ProcessCBBind(1);
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(bind_groups[2].raw_config):
|
2020-07-12 04:03:05 -04:00
|
|
|
return ProcessCBBind(2);
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(bind_groups[3].raw_config):
|
2020-07-12 04:03:05 -04:00
|
|
|
return ProcessCBBind(3);
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(bind_groups[4].raw_config):
|
2020-07-12 04:03:05 -04:00
|
|
|
return ProcessCBBind(4);
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(report_semaphore.query):
|
2020-07-12 04:03:05 -04:00
|
|
|
return ProcessQueryGet();
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(render_enable.mode):
|
2020-07-12 04:03:05 -04:00
|
|
|
return ProcessQueryCondition();
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(clear_report_value):
|
2020-07-12 04:03:05 -04:00
|
|
|
return ProcessCounterReset();
|
|
|
|
case MAXWELL3D_REG_INDEX(sync_info):
|
|
|
|
return ProcessSyncPoint();
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(launch_dma):
|
|
|
|
return upload_state.ProcessExec(regs.launch_dma.memory_layout.Value() ==
|
|
|
|
Regs::LaunchDMA::Layout::Pitch);
|
|
|
|
case MAXWELL3D_REG_INDEX(inline_data):
|
2020-07-12 04:03:05 -04:00
|
|
|
upload_state.ProcessData(argument, is_last_call);
|
|
|
|
return;
|
2020-12-30 00:25:23 -05:00
|
|
|
case MAXWELL3D_REG_INDEX(fragment_barrier):
|
|
|
|
return rasterizer->FragmentBarrier();
|
2022-11-10 22:24:03 -05:00
|
|
|
case MAXWELL3D_REG_INDEX(tiled_cache_barrier):
|
|
|
|
return rasterizer->TiledCacheBarrier();
|
2022-12-06 00:45:26 -05:00
|
|
|
default:
|
|
|
|
draw_manager->ProcessMethodCall(method, argument);
|
|
|
|
break;
|
2020-07-12 04:03:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-03 02:33:38 -04:00
|
|
|
void Maxwell3D::CallMacroMethod(u32 method, const std::vector<u32>& parameters) {
|
2018-08-08 23:22:45 -04:00
|
|
|
// Reset the current macro.
|
|
|
|
executing_macro = 0;
|
|
|
|
|
2018-10-29 23:36:03 -04:00
|
|
|
// Lookup the macro offset
|
2019-11-08 15:08:07 -05:00
|
|
|
const u32 entry =
|
|
|
|
((method - MacroRegistersStart) >> 1) % static_cast<u32>(macro_positions.size());
|
2018-03-18 04:13:22 -04:00
|
|
|
|
2018-08-08 23:22:45 -04:00
|
|
|
// Execute the current macro.
|
2022-01-25 13:41:35 -05:00
|
|
|
macro_engine->Execute(macro_positions[entry], parameters);
|
2022-10-21 03:38:50 -04:00
|
|
|
|
2022-12-06 00:45:26 -05:00
|
|
|
draw_manager->DrawDeferred();
|
2018-03-16 21:32:44 -04:00
|
|
|
}
|
|
|
|
|
2020-04-27 21:47:58 -04:00
|
|
|
void Maxwell3D::CallMethod(u32 method, u32 method_argument, bool is_last_call) {
|
2022-10-21 03:38:50 -04:00
|
|
|
// It is an error to write to a register other than the current macro's ARG register before
|
|
|
|
// it has finished execution.
|
2018-03-18 04:13:22 -04:00
|
|
|
if (executing_macro != 0) {
|
2019-02-26 01:01:48 -05:00
|
|
|
ASSERT(method == executing_macro + 1);
|
2018-03-18 04:13:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Methods after 0xE00 are special, they're actually triggers for some microcode that was
|
|
|
|
// uploaded to the GPU during initialization.
|
2019-02-26 01:01:48 -05:00
|
|
|
if (method >= MacroRegistersStart) {
|
2020-07-12 04:03:05 -04:00
|
|
|
ProcessMacro(method, &method_argument, 1, is_last_call);
|
2018-03-18 04:13:22 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-02-26 01:01:48 -05:00
|
|
|
ASSERT_MSG(method < Regs::NUM_REGS,
|
2018-04-23 21:03:50 -04:00
|
|
|
"Invalid Maxwell3D register, increase the size of the Regs structure");
|
|
|
|
|
2022-11-21 10:38:37 -05:00
|
|
|
const u32 argument = ProcessShadowRam(method, method_argument);
|
|
|
|
ProcessDirtyRegisters(method, argument);
|
|
|
|
|
2022-12-06 00:45:26 -05:00
|
|
|
ProcessMethodCall(method, argument, method_argument, is_last_call);
|
2018-02-12 12:34:41 -05:00
|
|
|
}
|
|
|
|
|
2020-04-20 12:27:57 -04:00
|
|
|
void Maxwell3D::CallMultiMethod(u32 method, const u32* base_start, u32 amount,
|
|
|
|
u32 methods_pending) {
|
|
|
|
// Methods after 0xE00 are special, they're actually triggers for some microcode that was
|
|
|
|
// uploaded to the GPU during initialization.
|
|
|
|
if (method >= MacroRegistersStart) {
|
2020-07-12 04:03:05 -04:00
|
|
|
ProcessMacro(method, base_start, amount, amount == methods_pending);
|
2020-04-20 12:27:57 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (method) {
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 1:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 2:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 3:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 4:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 5:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 6:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 7:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 8:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 9:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 10:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 11:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 12:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 13:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 14:
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.buffer) + 15:
|
2022-03-14 19:11:41 -04:00
|
|
|
ProcessCBMultiData(base_start, amount);
|
2020-04-20 12:27:57 -04:00
|
|
|
break;
|
2022-08-12 05:58:09 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(inline_data):
|
2022-11-29 08:04:40 -05:00
|
|
|
upload_state.ProcessData(base_start, amount);
|
2022-08-14 05:36:36 -04:00
|
|
|
return;
|
2020-07-12 04:03:05 -04:00
|
|
|
default:
|
2022-11-29 08:04:40 -05:00
|
|
|
for (u32 i = 0; i < amount; i++) {
|
|
|
|
CallMethod(method, base_start[i], methods_pending - i <= 1);
|
2020-04-20 12:27:57 -04:00
|
|
|
}
|
2020-07-12 04:03:05 -04:00
|
|
|
break;
|
2020-04-20 12:27:57 -04:00
|
|
|
}
|
2020-04-20 02:16:56 -04:00
|
|
|
}
|
|
|
|
|
2018-04-23 21:01:29 -04:00
|
|
|
void Maxwell3D::ProcessMacroUpload(u32 data) {
|
2022-08-12 05:58:09 -04:00
|
|
|
macro_engine->AddCode(regs.load_mme.instruction_ptr++, data);
|
2018-10-29 23:36:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Maxwell3D::ProcessMacroBind(u32 data) {
|
2022-08-12 05:58:09 -04:00
|
|
|
macro_positions[regs.load_mme.start_address_ptr++] = data;
|
2018-04-23 21:01:29 -04:00
|
|
|
}
|
|
|
|
|
2019-08-31 16:43:19 -04:00
|
|
|
void Maxwell3D::ProcessFirmwareCall4() {
|
|
|
|
LOG_WARNING(HW_GPU, "(STUBBED) called");
|
|
|
|
|
2019-09-14 21:51:18 -04:00
|
|
|
// Firmware call 4 is a blob that changes some registers depending on its parameters.
|
|
|
|
// These registers don't affect emulation and so are stubbed by setting 0xd00 to 1.
|
2022-08-12 05:58:09 -04:00
|
|
|
regs.shadow_scratch[0] = 1;
|
2019-08-31 16:43:19 -04:00
|
|
|
}
|
|
|
|
|
2020-01-27 21:48:15 -05:00
|
|
|
void Maxwell3D::StampQueryResult(u64 payload, bool long_query) {
|
2022-08-12 05:58:09 -04:00
|
|
|
const GPUVAddr sequence_address{regs.report_semaphore.Address()};
|
2020-01-27 21:48:15 -05:00
|
|
|
if (long_query) {
|
2022-02-07 01:52:04 -05:00
|
|
|
memory_manager.Write<u64>(sequence_address + sizeof(u64), system.GPU().GetTicks());
|
|
|
|
memory_manager.Write<u64>(sequence_address, payload);
|
2020-01-27 21:48:15 -05:00
|
|
|
} else {
|
|
|
|
memory_manager.Write<u32>(sequence_address, static_cast<u32>(payload));
|
|
|
|
}
|
|
|
|
}
|
2018-02-12 12:34:41 -05:00
|
|
|
|
2020-01-27 21:48:15 -05:00
|
|
|
void Maxwell3D::ProcessQueryGet() {
|
2018-04-23 18:06:57 -04:00
|
|
|
// TODO(Subv): Support the other query units.
|
2022-08-12 05:58:09 -04:00
|
|
|
if (regs.report_semaphore.query.location != Regs::ReportSemaphore::Location::All) {
|
|
|
|
LOG_DEBUG(HW_GPU, "Locations other than ALL are unimplemented");
|
2020-05-28 17:23:25 -04:00
|
|
|
}
|
2018-04-23 18:06:57 -04:00
|
|
|
|
2022-08-12 05:58:09 -04:00
|
|
|
switch (regs.report_semaphore.query.operation) {
|
|
|
|
case Regs::ReportSemaphore::Operation::Release:
|
2022-10-19 00:21:51 -04:00
|
|
|
if (regs.report_semaphore.query.short_query != 0) {
|
2022-08-12 05:58:09 -04:00
|
|
|
const GPUVAddr sequence_address{regs.report_semaphore.Address()};
|
|
|
|
const u32 payload = regs.report_semaphore.payload;
|
2022-02-05 19:16:11 -05:00
|
|
|
std::function<void()> operation([this, sequence_address, payload] {
|
|
|
|
memory_manager.Write<u32>(sequence_address, payload);
|
|
|
|
});
|
|
|
|
rasterizer->SignalFence(std::move(operation));
|
2020-02-17 17:10:23 -05:00
|
|
|
} else {
|
2022-02-05 19:16:11 -05:00
|
|
|
struct LongQueryResult {
|
|
|
|
u64_le value;
|
|
|
|
u64_le timestamp;
|
|
|
|
};
|
2022-08-12 05:58:09 -04:00
|
|
|
const GPUVAddr sequence_address{regs.report_semaphore.Address()};
|
|
|
|
const u32 payload = regs.report_semaphore.payload;
|
2022-10-19 00:21:51 -04:00
|
|
|
[this, sequence_address, payload] {
|
2022-02-07 01:52:04 -05:00
|
|
|
memory_manager.Write<u64>(sequence_address + sizeof(u64), system.GPU().GetTicks());
|
|
|
|
memory_manager.Write<u64>(sequence_address, payload);
|
2022-10-19 00:21:51 -04:00
|
|
|
}();
|
2020-02-17 17:10:23 -05:00
|
|
|
}
|
2018-04-23 18:06:57 -04:00
|
|
|
break;
|
2022-08-12 05:58:09 -04:00
|
|
|
case Regs::ReportSemaphore::Operation::Acquire:
|
2019-07-27 18:40:10 -04:00
|
|
|
// TODO(Blinkhawk): Under this operation, the GPU waits for the CPU to write a value that
|
|
|
|
// matches the current payload.
|
2020-01-27 21:48:15 -05:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented query operation ACQUIRE");
|
|
|
|
break;
|
2022-08-12 05:58:09 -04:00
|
|
|
case Regs::ReportSemaphore::Operation::ReportOnly:
|
2019-11-26 16:52:15 -05:00
|
|
|
if (const std::optional<u64> result = GetQueryResult()) {
|
|
|
|
// If the query returns an empty optional it means it's cached and deferred.
|
|
|
|
// In this case we have a non-empty result, so we stamp it immediately.
|
2022-08-12 05:58:09 -04:00
|
|
|
StampQueryResult(*result, regs.report_semaphore.query.short_query == 0);
|
2018-06-03 20:17:31 -04:00
|
|
|
}
|
2020-01-27 21:48:15 -05:00
|
|
|
break;
|
2022-08-12 05:58:09 -04:00
|
|
|
case Regs::ReportSemaphore::Operation::Trap:
|
2020-01-27 21:48:15 -05:00
|
|
|
UNIMPLEMENTED_MSG("Unimplemented query operation TRAP");
|
|
|
|
break;
|
2019-07-27 18:40:10 -04:00
|
|
|
default:
|
2020-01-27 21:48:15 -05:00
|
|
|
UNIMPLEMENTED_MSG("Unknown query operation");
|
2018-02-12 12:34:41 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-03-04 19:13:15 -05:00
|
|
|
|
2019-06-30 22:21:28 -04:00
|
|
|
void Maxwell3D::ProcessQueryCondition() {
|
2022-08-12 05:58:09 -04:00
|
|
|
const GPUVAddr condition_address{regs.render_enable.Address()};
|
2022-11-29 20:43:36 -05:00
|
|
|
switch (regs.render_enable_override) {
|
|
|
|
case Regs::RenderEnable::Override::AlwaysRender:
|
2019-06-30 22:21:28 -04:00
|
|
|
execute_on = true;
|
|
|
|
break;
|
2022-11-29 20:43:36 -05:00
|
|
|
case Regs::RenderEnable::Override::NeverRender:
|
2019-06-30 22:21:28 -04:00
|
|
|
execute_on = false;
|
|
|
|
break;
|
2022-11-29 20:43:36 -05:00
|
|
|
case Regs::RenderEnable::Override::UseRenderEnable:
|
|
|
|
switch (regs.render_enable.mode) {
|
|
|
|
case Regs::RenderEnable::Mode::True: {
|
|
|
|
execute_on = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Regs::RenderEnable::Mode::False: {
|
|
|
|
execute_on = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Regs::RenderEnable::Mode::Conditional: {
|
|
|
|
Regs::ReportSemaphore::Compare cmp;
|
|
|
|
memory_manager.ReadBlock(condition_address, &cmp, sizeof(cmp));
|
|
|
|
execute_on = cmp.initial_sequence != 0U && cmp.initial_mode != 0U;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Regs::RenderEnable::Mode::IfEqual: {
|
|
|
|
Regs::ReportSemaphore::Compare cmp;
|
|
|
|
memory_manager.ReadBlock(condition_address, &cmp, sizeof(cmp));
|
|
|
|
execute_on = cmp.initial_sequence == cmp.current_sequence &&
|
|
|
|
cmp.initial_mode == cmp.current_mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Regs::RenderEnable::Mode::IfNotEqual: {
|
|
|
|
Regs::ReportSemaphore::Compare cmp;
|
|
|
|
memory_manager.ReadBlock(condition_address, &cmp, sizeof(cmp));
|
|
|
|
execute_on = cmp.initial_sequence != cmp.current_sequence ||
|
|
|
|
cmp.initial_mode != cmp.current_mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
UNIMPLEMENTED_MSG("Uninplemented Condition Mode!");
|
|
|
|
execute_on = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-06-30 22:21:28 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-27 18:40:10 -04:00
|
|
|
void Maxwell3D::ProcessCounterReset() {
|
2022-08-12 05:58:09 -04:00
|
|
|
switch (regs.clear_report_value) {
|
|
|
|
case Regs::ClearReport::ZPassPixelCount:
|
2020-06-10 23:58:57 -04:00
|
|
|
rasterizer->ResetCounter(QueryType::SamplesPassed);
|
2019-07-27 18:40:10 -04:00
|
|
|
break;
|
|
|
|
default:
|
2022-08-12 05:58:09 -04:00
|
|
|
LOG_DEBUG(Render_OpenGL, "Unimplemented counter reset={}", regs.clear_report_value);
|
2019-07-27 18:40:10 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-02 11:46:00 -04:00
|
|
|
void Maxwell3D::ProcessSyncPoint() {
|
|
|
|
const u32 sync_point = regs.sync_info.sync_point.Value();
|
2022-11-24 08:02:58 -05:00
|
|
|
[[maybe_unused]] const u32 cache_flush = regs.sync_info.clean_l2.Value();
|
2022-10-19 00:21:51 -04:00
|
|
|
rasterizer->SignalSyncPoint(sync_point);
|
2019-04-02 11:46:00 -04:00
|
|
|
}
|
|
|
|
|
2019-11-26 16:52:15 -05:00
|
|
|
std::optional<u64> Maxwell3D::GetQueryResult() {
|
2022-08-12 05:58:09 -04:00
|
|
|
switch (regs.report_semaphore.query.report) {
|
|
|
|
case Regs::ReportSemaphore::Report::Payload:
|
|
|
|
return regs.report_semaphore.payload;
|
|
|
|
case Regs::ReportSemaphore::Report::ZPassPixelCount64:
|
2019-11-26 16:52:15 -05:00
|
|
|
// Deferred.
|
2022-08-12 05:58:09 -04:00
|
|
|
rasterizer->Query(regs.report_semaphore.Address(), QueryType::SamplesPassed,
|
2020-06-10 23:58:57 -04:00
|
|
|
system.GPU().GetTicks());
|
2020-09-22 17:31:53 -04:00
|
|
|
return std::nullopt;
|
2019-11-26 16:52:15 -05:00
|
|
|
default:
|
2022-08-12 05:58:09 -04:00
|
|
|
LOG_DEBUG(HW_GPU, "Unimplemented query report type {}",
|
|
|
|
regs.report_semaphore.query.report.Value());
|
2019-11-26 16:52:15 -05:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-16 18:48:58 -05:00
|
|
|
void Maxwell3D::ProcessCBBind(size_t stage_index) {
|
2018-03-17 18:06:23 -04:00
|
|
|
// Bind the buffer currently in CB_ADDRESS to the specified index in the desired shader stage.
|
2022-08-12 05:58:09 -04:00
|
|
|
const auto& bind_data = regs.bind_groups[stage_index];
|
|
|
|
auto& buffer = state.shader_stages[stage_index].const_buffers[bind_data.shader_slot];
|
2018-03-17 18:06:23 -04:00
|
|
|
buffer.enabled = bind_data.valid.Value() != 0;
|
2022-08-12 05:58:09 -04:00
|
|
|
buffer.address = regs.const_buffer.Address();
|
|
|
|
buffer.size = regs.const_buffer.size;
|
2021-01-16 18:48:58 -05:00
|
|
|
|
|
|
|
const bool is_enabled = bind_data.valid.Value() != 0;
|
2021-06-01 13:26:43 -04:00
|
|
|
if (!is_enabled) {
|
2022-08-12 05:58:09 -04:00
|
|
|
rasterizer->DisableGraphicsUniformBuffer(stage_index, bind_data.shader_slot);
|
2021-06-01 13:26:43 -04:00
|
|
|
return;
|
|
|
|
}
|
2022-08-12 05:58:09 -04:00
|
|
|
const GPUVAddr gpu_addr = regs.const_buffer.Address();
|
|
|
|
const u32 size = regs.const_buffer.size;
|
|
|
|
rasterizer->BindGraphicsUniformBuffer(stage_index, bind_data.shader_slot, gpu_addr, size);
|
2018-03-16 23:06:24 -04:00
|
|
|
}
|
2018-03-16 21:32:44 -04:00
|
|
|
|
2022-03-14 19:11:41 -04:00
|
|
|
void Maxwell3D::ProcessCBMultiData(const u32* start_base, u32 amount) {
|
2018-03-18 16:19:47 -04:00
|
|
|
// Write the input value to the current const buffer at the current position.
|
2022-08-12 05:58:09 -04:00
|
|
|
const GPUVAddr buffer_address = regs.const_buffer.Address();
|
2018-03-18 16:19:47 -04:00
|
|
|
ASSERT(buffer_address != 0);
|
|
|
|
|
|
|
|
// Don't allow writing past the end of the buffer.
|
2022-08-12 05:58:09 -04:00
|
|
|
ASSERT(regs.const_buffer.offset <= regs.const_buffer.size);
|
2018-03-18 16:19:47 -04:00
|
|
|
|
2022-08-12 05:58:09 -04:00
|
|
|
const GPUVAddr address{buffer_address + regs.const_buffer.offset};
|
2022-03-14 19:11:41 -04:00
|
|
|
const size_t copy_size = amount * sizeof(u32);
|
|
|
|
memory_manager.WriteBlock(address, start_base, copy_size);
|
2018-03-18 16:19:47 -04:00
|
|
|
|
2022-03-14 19:11:41 -04:00
|
|
|
// Increment the current buffer position.
|
2022-08-12 05:58:09 -04:00
|
|
|
regs.const_buffer.offset += static_cast<u32>(copy_size);
|
2022-03-14 19:11:41 -04:00
|
|
|
}
|
2019-02-18 20:58:32 -05:00
|
|
|
|
2022-03-14 19:11:41 -04:00
|
|
|
void Maxwell3D::ProcessCBData(u32 value) {
|
|
|
|
ProcessCBMultiData(&value, 1);
|
2018-03-18 16:19:47 -04:00
|
|
|
}
|
|
|
|
|
2018-03-26 16:46:49 -04:00
|
|
|
Texture::TICEntry Maxwell3D::GetTICEntry(u32 tic_index) const {
|
2022-08-12 05:58:09 -04:00
|
|
|
const GPUVAddr tic_address_gpu{regs.tex_header.Address() +
|
|
|
|
tic_index * sizeof(Texture::TICEntry)};
|
2018-03-26 16:46:49 -04:00
|
|
|
|
|
|
|
Texture::TICEntry tic_entry;
|
2019-04-15 23:05:05 -04:00
|
|
|
memory_manager.ReadBlockUnsafe(tic_address_gpu, &tic_entry, sizeof(Texture::TICEntry));
|
2018-03-26 16:46:49 -04:00
|
|
|
|
|
|
|
return tic_entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
Texture::TSCEntry Maxwell3D::GetTSCEntry(u32 tsc_index) const {
|
2022-08-12 05:58:09 -04:00
|
|
|
const GPUVAddr tsc_address_gpu{regs.tex_sampler.Address() +
|
|
|
|
tsc_index * sizeof(Texture::TSCEntry)};
|
2018-03-26 16:46:49 -04:00
|
|
|
|
|
|
|
Texture::TSCEntry tsc_entry;
|
2019-04-15 23:05:05 -04:00
|
|
|
memory_manager.ReadBlockUnsafe(tsc_address_gpu, &tsc_entry, sizeof(Texture::TSCEntry));
|
2018-03-26 16:46:49 -04:00
|
|
|
return tsc_entry;
|
|
|
|
}
|
|
|
|
|
2018-03-28 16:14:47 -04:00
|
|
|
u32 Maxwell3D::GetRegisterValue(u32 method) const {
|
|
|
|
ASSERT_MSG(method < Regs::NUM_REGS, "Invalid Maxwell3D register");
|
|
|
|
return regs.reg_array[method];
|
|
|
|
}
|
|
|
|
|
2018-10-20 15:58:06 -04:00
|
|
|
} // namespace Tegra::Engines
|