2018-02-11 21:34:20 -05:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2018-03-19 19:00:29 -04:00
|
|
|
#include <cinttypes>
|
2018-10-25 23:42:39 -04:00
|
|
|
#include <cstring>
|
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"
|
2018-02-11 21:34:20 -05:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2019-11-18 16:35:21 -05:00
|
|
|
#include "video_core/engines/shader_type.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
|
|
|
|
2018-03-18 04:13:22 -04:00
|
|
|
/// First register id that is actually a Macro call.
|
|
|
|
constexpr u32 MacroRegistersStart = 0xE00;
|
|
|
|
|
2019-02-15 22:05:17 -05:00
|
|
|
Maxwell3D::Maxwell3D(Core::System& system, VideoCore::RasterizerInterface& rasterizer,
|
|
|
|
MemoryManager& memory_manager)
|
2019-04-22 19:27:36 -04:00
|
|
|
: system{system}, rasterizer{rasterizer}, memory_manager{memory_manager},
|
|
|
|
macro_interpreter{*this}, upload_state{memory_manager, regs.upload} {
|
2019-07-10 15:38:31 -04:00
|
|
|
InitDirtySettings();
|
2018-10-25 23:42:39 -04:00
|
|
|
InitializeRegisterDefaults();
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
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
|
|
|
|
regs.blend.equation_rgb = Regs::Blend::Equation::Add;
|
|
|
|
regs.blend.factor_source_rgb = Regs::Blend::Factor::One;
|
|
|
|
regs.blend.factor_dest_rgb = Regs::Blend::Factor::Zero;
|
|
|
|
regs.blend.equation_a = Regs::Blend::Equation::Add;
|
|
|
|
regs.blend.factor_source_a = Regs::Blend::Factor::One;
|
|
|
|
regs.blend.factor_dest_a = Regs::Blend::Factor::Zero;
|
2019-05-14 08:53:16 -04:00
|
|
|
for (auto& blend : regs.independent_blend) {
|
|
|
|
blend.equation_rgb = Regs::Blend::Equation::Add;
|
|
|
|
blend.factor_source_rgb = Regs::Blend::Factor::One;
|
|
|
|
blend.factor_dest_rgb = Regs::Blend::Factor::Zero;
|
|
|
|
blend.equation_a = Regs::Blend::Equation::Add;
|
|
|
|
blend.factor_source_a = Regs::Blend::Factor::One;
|
|
|
|
blend.factor_dest_a = Regs::Blend::Factor::Zero;
|
2018-11-01 23:21:25 -04:00
|
|
|
}
|
2018-11-06 22:27:12 -05:00
|
|
|
regs.stencil_front_op_fail = Regs::StencilOp::Keep;
|
|
|
|
regs.stencil_front_op_zfail = Regs::StencilOp::Keep;
|
|
|
|
regs.stencil_front_op_zpass = Regs::StencilOp::Keep;
|
|
|
|
regs.stencil_front_func_func = Regs::ComparisonOp::Always;
|
|
|
|
regs.stencil_front_func_mask = 0xFFFFFFFF;
|
|
|
|
regs.stencil_front_mask = 0xFFFFFFFF;
|
|
|
|
regs.stencil_two_side_enable = 1;
|
|
|
|
regs.stencil_back_op_fail = Regs::StencilOp::Keep;
|
|
|
|
regs.stencil_back_op_zfail = Regs::StencilOp::Keep;
|
|
|
|
regs.stencil_back_op_zpass = Regs::StencilOp::Keep;
|
|
|
|
regs.stencil_back_func_func = Regs::ComparisonOp::Always;
|
|
|
|
regs.stencil_back_func_mask = 0xFFFFFFFF;
|
|
|
|
regs.stencil_back_mask = 0xFFFFFFFF;
|
2019-01-22 02:14:29 -05:00
|
|
|
|
2019-07-17 19:37:01 -04:00
|
|
|
regs.depth_test_func = Regs::ComparisonOp::Always;
|
|
|
|
regs.cull.front_face = Regs::Cull::FrontFace::CounterClockWise;
|
|
|
|
regs.cull.cull_face = Regs::Cull::CullFace::Back;
|
|
|
|
|
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
|
|
|
|
2019-12-18 17:26:52 -05:00
|
|
|
// NVN games expect these values to be enabled at boot
|
|
|
|
regs.rasterize_enable = 1;
|
2019-01-22 02:14:29 -05:00
|
|
|
regs.rt_separate_frag_data = 1;
|
2019-09-03 00:05:23 -04:00
|
|
|
regs.framebuffer_srgb = 1;
|
2020-01-18 16:50:45 -05:00
|
|
|
regs.cull.front_face = Maxwell3D::Regs::Cull::FrontFace::ClockWise;
|
2019-12-18 17:26:52 -05:00
|
|
|
|
2019-09-15 11:48:54 -04:00
|
|
|
mme_inline[MAXWELL3D_REG_INDEX(draw.vertex_end_gl)] = true;
|
|
|
|
mme_inline[MAXWELL3D_REG_INDEX(draw.vertex_begin_gl)] = true;
|
|
|
|
mme_inline[MAXWELL3D_REG_INDEX(vertex_buffer.count)] = true;
|
|
|
|
mme_inline[MAXWELL3D_REG_INDEX(index_array.count)] = true;
|
2018-10-25 23:42:39 -04:00
|
|
|
}
|
2018-02-11 21:34:20 -05:00
|
|
|
|
2019-10-27 02:07:52 -04:00
|
|
|
#define DIRTY_REGS_POS(field_name) static_cast<u8>(offsetof(Maxwell3D::DirtyRegs, field_name))
|
2019-07-10 15:38:31 -04:00
|
|
|
|
|
|
|
void Maxwell3D::InitDirtySettings() {
|
2019-10-27 02:07:52 -04:00
|
|
|
const auto set_block = [this](std::size_t start, std::size_t range, u8 position) {
|
2019-07-15 10:24:01 -04:00
|
|
|
const auto start_itr = dirty_pointers.begin() + start;
|
|
|
|
const auto end_itr = start_itr + range;
|
|
|
|
std::fill(start_itr, end_itr, position);
|
2019-07-10 15:38:31 -04:00
|
|
|
};
|
2019-07-15 10:24:01 -04:00
|
|
|
dirty.regs.fill(true);
|
2019-07-10 15:38:31 -04:00
|
|
|
|
|
|
|
// Init Render Targets
|
|
|
|
constexpr u32 registers_per_rt = sizeof(regs.rt[0]) / sizeof(u32);
|
|
|
|
constexpr u32 rt_start_reg = MAXWELL3D_REG_INDEX(rt);
|
|
|
|
constexpr u32 rt_end_reg = rt_start_reg + registers_per_rt * 8;
|
2019-10-27 02:07:52 -04:00
|
|
|
u8 rt_dirty_reg = DIRTY_REGS_POS(render_target);
|
2019-07-10 15:38:31 -04:00
|
|
|
for (u32 rt_reg = rt_start_reg; rt_reg < rt_end_reg; rt_reg += registers_per_rt) {
|
|
|
|
set_block(rt_reg, registers_per_rt, rt_dirty_reg);
|
2019-10-27 02:07:52 -04:00
|
|
|
++rt_dirty_reg;
|
2019-07-10 15:38:31 -04:00
|
|
|
}
|
|
|
|
constexpr u32 depth_buffer_flag = DIRTY_REGS_POS(depth_buffer);
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(zeta_enable)] = depth_buffer_flag;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(zeta_width)] = depth_buffer_flag;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(zeta_height)] = depth_buffer_flag;
|
|
|
|
constexpr u32 registers_in_zeta = sizeof(regs.zeta) / sizeof(u32);
|
|
|
|
constexpr u32 zeta_reg = MAXWELL3D_REG_INDEX(zeta);
|
|
|
|
set_block(zeta_reg, registers_in_zeta, depth_buffer_flag);
|
|
|
|
|
|
|
|
// Init Vertex Arrays
|
|
|
|
constexpr u32 vertex_array_start = MAXWELL3D_REG_INDEX(vertex_array);
|
|
|
|
constexpr u32 vertex_array_size = sizeof(regs.vertex_array[0]) / sizeof(u32);
|
|
|
|
constexpr u32 vertex_array_end = vertex_array_start + vertex_array_size * Regs::NumVertexArrays;
|
2019-10-27 02:07:52 -04:00
|
|
|
u8 va_dirty_reg = DIRTY_REGS_POS(vertex_array);
|
|
|
|
u8 vi_dirty_reg = DIRTY_REGS_POS(vertex_instance);
|
2019-07-10 15:38:31 -04:00
|
|
|
for (u32 vertex_reg = vertex_array_start; vertex_reg < vertex_array_end;
|
|
|
|
vertex_reg += vertex_array_size) {
|
2019-10-27 02:07:52 -04:00
|
|
|
set_block(vertex_reg, 3, va_dirty_reg);
|
2019-07-10 15:38:31 -04:00
|
|
|
// The divisor concerns vertex array instances
|
2019-10-27 02:07:52 -04:00
|
|
|
dirty_pointers[static_cast<std::size_t>(vertex_reg) + 3] = vi_dirty_reg;
|
|
|
|
++va_dirty_reg;
|
|
|
|
++vi_dirty_reg;
|
2019-07-10 15:38:31 -04:00
|
|
|
}
|
|
|
|
constexpr u32 vertex_limit_start = MAXWELL3D_REG_INDEX(vertex_array_limit);
|
|
|
|
constexpr u32 vertex_limit_size = sizeof(regs.vertex_array_limit[0]) / sizeof(u32);
|
|
|
|
constexpr u32 vertex_limit_end = vertex_limit_start + vertex_limit_size * Regs::NumVertexArrays;
|
2019-10-27 02:07:52 -04:00
|
|
|
va_dirty_reg = DIRTY_REGS_POS(vertex_array);
|
2019-07-10 15:38:31 -04:00
|
|
|
for (u32 vertex_reg = vertex_limit_start; vertex_reg < vertex_limit_end;
|
|
|
|
vertex_reg += vertex_limit_size) {
|
2019-10-27 02:07:52 -04:00
|
|
|
set_block(vertex_reg, vertex_limit_size, va_dirty_reg);
|
|
|
|
va_dirty_reg++;
|
2019-07-10 15:38:31 -04:00
|
|
|
}
|
|
|
|
constexpr u32 vertex_instance_start = MAXWELL3D_REG_INDEX(instanced_arrays);
|
|
|
|
constexpr u32 vertex_instance_size =
|
|
|
|
sizeof(regs.instanced_arrays.is_instanced[0]) / sizeof(u32);
|
|
|
|
constexpr u32 vertex_instance_end =
|
|
|
|
vertex_instance_start + vertex_instance_size * Regs::NumVertexArrays;
|
2019-10-27 02:07:52 -04:00
|
|
|
vi_dirty_reg = DIRTY_REGS_POS(vertex_instance);
|
2019-07-10 15:38:31 -04:00
|
|
|
for (u32 vertex_reg = vertex_instance_start; vertex_reg < vertex_instance_end;
|
|
|
|
vertex_reg += vertex_instance_size) {
|
2019-10-27 02:07:52 -04:00
|
|
|
set_block(vertex_reg, vertex_instance_size, vi_dirty_reg);
|
|
|
|
vi_dirty_reg++;
|
2019-07-10 15:38:31 -04:00
|
|
|
}
|
|
|
|
set_block(MAXWELL3D_REG_INDEX(vertex_attrib_format), regs.vertex_attrib_format.size(),
|
|
|
|
DIRTY_REGS_POS(vertex_attrib_format));
|
|
|
|
|
|
|
|
// Init Shaders
|
|
|
|
constexpr u32 shader_registers_count =
|
|
|
|
sizeof(regs.shader_config[0]) * Regs::MaxShaderProgram / sizeof(u32);
|
|
|
|
set_block(MAXWELL3D_REG_INDEX(shader_config[0]), shader_registers_count,
|
|
|
|
DIRTY_REGS_POS(shaders));
|
2019-07-13 16:52:32 -04:00
|
|
|
|
|
|
|
// State
|
|
|
|
|
|
|
|
// Viewport
|
2019-10-27 02:07:52 -04:00
|
|
|
constexpr u8 viewport_dirty_reg = DIRTY_REGS_POS(viewport);
|
2019-07-13 16:52:32 -04:00
|
|
|
constexpr u32 viewport_start = MAXWELL3D_REG_INDEX(viewports);
|
|
|
|
constexpr u32 viewport_size = sizeof(regs.viewports) / sizeof(u32);
|
|
|
|
set_block(viewport_start, viewport_size, viewport_dirty_reg);
|
|
|
|
constexpr u32 view_volume_start = MAXWELL3D_REG_INDEX(view_volume_clip_control);
|
|
|
|
constexpr u32 view_volume_size = sizeof(regs.view_volume_clip_control) / sizeof(u32);
|
|
|
|
set_block(view_volume_start, view_volume_size, viewport_dirty_reg);
|
|
|
|
|
|
|
|
// Viewport transformation
|
|
|
|
constexpr u32 viewport_trans_start = MAXWELL3D_REG_INDEX(viewport_transform);
|
|
|
|
constexpr u32 viewport_trans_size = sizeof(regs.viewport_transform) / sizeof(u32);
|
|
|
|
set_block(viewport_trans_start, viewport_trans_size, DIRTY_REGS_POS(viewport_transform));
|
|
|
|
|
|
|
|
// Cullmode
|
|
|
|
constexpr u32 cull_mode_start = MAXWELL3D_REG_INDEX(cull);
|
|
|
|
constexpr u32 cull_mode_size = sizeof(regs.cull) / sizeof(u32);
|
|
|
|
set_block(cull_mode_start, cull_mode_size, DIRTY_REGS_POS(cull_mode));
|
|
|
|
|
|
|
|
// Screen y control
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(screen_y_control)] = DIRTY_REGS_POS(screen_y_control);
|
|
|
|
|
|
|
|
// Primitive Restart
|
|
|
|
constexpr u32 primitive_restart_start = MAXWELL3D_REG_INDEX(primitive_restart);
|
|
|
|
constexpr u32 primitive_restart_size = sizeof(regs.primitive_restart) / sizeof(u32);
|
|
|
|
set_block(primitive_restart_start, primitive_restart_size, DIRTY_REGS_POS(primitive_restart));
|
|
|
|
|
|
|
|
// Depth Test
|
2019-10-27 02:07:52 -04:00
|
|
|
constexpr u8 depth_test_dirty_reg = DIRTY_REGS_POS(depth_test);
|
2019-07-13 16:52:32 -04:00
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(depth_test_enable)] = depth_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(depth_write_enabled)] = depth_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(depth_test_func)] = depth_test_dirty_reg;
|
|
|
|
|
|
|
|
// Stencil Test
|
|
|
|
constexpr u32 stencil_test_dirty_reg = DIRTY_REGS_POS(stencil_test);
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_enable)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_front_func_func)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_front_func_ref)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_front_func_mask)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_front_op_fail)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_front_op_zfail)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_front_op_zpass)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_front_mask)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_two_side_enable)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_back_func_func)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_back_func_ref)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_back_func_mask)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_back_op_fail)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_back_op_zfail)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_back_op_zpass)] = stencil_test_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(stencil_back_mask)] = stencil_test_dirty_reg;
|
|
|
|
|
|
|
|
// Color Mask
|
2019-10-27 02:07:52 -04:00
|
|
|
constexpr u8 color_mask_dirty_reg = DIRTY_REGS_POS(color_mask);
|
2019-07-13 16:52:32 -04:00
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(color_mask_common)] = color_mask_dirty_reg;
|
|
|
|
set_block(MAXWELL3D_REG_INDEX(color_mask), sizeof(regs.color_mask) / sizeof(u32),
|
|
|
|
color_mask_dirty_reg);
|
|
|
|
// Blend State
|
2019-10-27 02:07:52 -04:00
|
|
|
constexpr u8 blend_state_dirty_reg = DIRTY_REGS_POS(blend_state);
|
2019-07-13 16:52:32 -04:00
|
|
|
set_block(MAXWELL3D_REG_INDEX(blend_color), sizeof(regs.blend_color) / sizeof(u32),
|
|
|
|
blend_state_dirty_reg);
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(independent_blend_enable)] = blend_state_dirty_reg;
|
|
|
|
set_block(MAXWELL3D_REG_INDEX(blend), sizeof(regs.blend) / sizeof(u32), blend_state_dirty_reg);
|
|
|
|
set_block(MAXWELL3D_REG_INDEX(independent_blend), sizeof(regs.independent_blend) / sizeof(u32),
|
|
|
|
blend_state_dirty_reg);
|
|
|
|
|
|
|
|
// Scissor State
|
2019-10-27 02:07:52 -04:00
|
|
|
constexpr u8 scissor_test_dirty_reg = DIRTY_REGS_POS(scissor_test);
|
2019-07-13 16:52:32 -04:00
|
|
|
set_block(MAXWELL3D_REG_INDEX(scissor_test), sizeof(regs.scissor_test) / sizeof(u32),
|
|
|
|
scissor_test_dirty_reg);
|
|
|
|
|
|
|
|
// Polygon Offset
|
2019-10-27 02:07:52 -04:00
|
|
|
constexpr u8 polygon_offset_dirty_reg = DIRTY_REGS_POS(polygon_offset);
|
2019-07-13 16:52:32 -04:00
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(polygon_offset_fill_enable)] = polygon_offset_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(polygon_offset_line_enable)] = polygon_offset_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(polygon_offset_point_enable)] = polygon_offset_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(polygon_offset_units)] = polygon_offset_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(polygon_offset_factor)] = polygon_offset_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(polygon_offset_clamp)] = polygon_offset_dirty_reg;
|
2019-09-29 19:45:12 -04:00
|
|
|
|
|
|
|
// Depth bounds
|
2019-10-27 02:07:52 -04:00
|
|
|
constexpr u8 depth_bounds_values_dirty_reg = DIRTY_REGS_POS(depth_bounds_values);
|
2019-09-29 19:45:12 -04:00
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(depth_bounds[0])] = depth_bounds_values_dirty_reg;
|
|
|
|
dirty_pointers[MAXWELL3D_REG_INDEX(depth_bounds[1])] = depth_bounds_values_dirty_reg;
|
2019-07-10 15:38:31 -04:00
|
|
|
}
|
|
|
|
|
2019-08-25 00:08:35 -04:00
|
|
|
void Maxwell3D::CallMacroMethod(u32 method, std::size_t num_parameters, const 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.
|
2019-08-25 00:08:35 -04:00
|
|
|
macro_interpreter.Execute(macro_positions[entry], num_parameters, parameters);
|
2019-09-22 07:23:13 -04:00
|
|
|
if (mme_draw.current_mode != MMEDrawMode::Undefined) {
|
2019-09-15 14:25:07 -04:00
|
|
|
FlushMMEInlineDraw();
|
|
|
|
}
|
2018-03-16 21:32:44 -04:00
|
|
|
}
|
|
|
|
|
2018-11-23 23:20:56 -05:00
|
|
|
void Maxwell3D::CallMethod(const GPU::MethodCall& method_call) {
|
2019-02-26 01:01:48 -05:00
|
|
|
const u32 method = method_call.method;
|
|
|
|
|
2019-07-12 09:25:47 -04:00
|
|
|
if (method == cb_data_state.current) {
|
|
|
|
regs.reg_array[method] = method_call.argument;
|
|
|
|
ProcessCBData(method_call.argument);
|
|
|
|
return;
|
|
|
|
} else if (cb_data_state.current != null_cb_data) {
|
|
|
|
FinishCBData();
|
|
|
|
}
|
|
|
|
|
2018-03-18 04:13:22 -04:00
|
|
|
// It is an error to write to a register other than the current macro's ARG register before it
|
|
|
|
// has finished execution.
|
|
|
|
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) {
|
2018-03-18 04:13:22 -04:00
|
|
|
// We're trying to execute a macro
|
|
|
|
if (executing_macro == 0) {
|
|
|
|
// A macro call must begin by writing the macro method's register, not its argument.
|
2019-02-26 01:01:48 -05:00
|
|
|
ASSERT_MSG((method % 2) == 0,
|
2018-03-18 04:13:22 -04:00
|
|
|
"Can't start macro execution by writing to the ARGS register");
|
2019-02-26 01:01:48 -05:00
|
|
|
executing_macro = method;
|
2018-03-18 04:13:22 -04:00
|
|
|
}
|
|
|
|
|
2018-11-23 23:20:56 -05:00
|
|
|
macro_params.push_back(method_call.argument);
|
2018-03-18 04:13:22 -04:00
|
|
|
|
2018-03-18 05:17:10 -04:00
|
|
|
// Call the macro when there are no more parameters in the command buffer
|
2018-11-23 23:20:56 -05:00
|
|
|
if (method_call.IsLastCall()) {
|
2019-08-25 00:08:35 -04:00
|
|
|
CallMacroMethod(executing_macro, macro_params.size(), macro_params.data());
|
|
|
|
macro_params.clear();
|
2018-03-18 05:17:10 -04:00
|
|
|
}
|
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");
|
|
|
|
|
2019-02-26 01:01:48 -05:00
|
|
|
if (regs.reg_array[method] != method_call.argument) {
|
|
|
|
regs.reg_array[method] = method_call.argument;
|
2019-07-15 10:24:01 -04:00
|
|
|
const std::size_t dirty_reg = dirty_pointers[method];
|
2019-07-10 15:38:31 -04:00
|
|
|
if (dirty_reg) {
|
|
|
|
dirty.regs[dirty_reg] = true;
|
|
|
|
if (dirty_reg >= DIRTY_REGS_POS(vertex_array) &&
|
|
|
|
dirty_reg < DIRTY_REGS_POS(vertex_array_buffers)) {
|
|
|
|
dirty.vertex_array_buffers = true;
|
|
|
|
} else if (dirty_reg >= DIRTY_REGS_POS(vertex_instance) &&
|
|
|
|
dirty_reg < DIRTY_REGS_POS(vertex_instances)) {
|
|
|
|
dirty.vertex_instances = true;
|
|
|
|
} else if (dirty_reg >= DIRTY_REGS_POS(render_target) &&
|
|
|
|
dirty_reg < DIRTY_REGS_POS(render_settings)) {
|
|
|
|
dirty.render_settings = true;
|
|
|
|
}
|
2018-11-06 15:26:27 -05:00
|
|
|
}
|
2018-11-06 13:15:44 -05:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:01:48 -05:00
|
|
|
switch (method) {
|
2018-04-23 21:01:29 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(macros.data): {
|
2018-11-23 23:20:56 -05:00
|
|
|
ProcessMacroUpload(method_call.argument);
|
2018-04-23 21:01:29 -04:00
|
|
|
break;
|
|
|
|
}
|
2018-10-29 23:36:03 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(macros.bind): {
|
2018-11-23 23:20:56 -05:00
|
|
|
ProcessMacroBind(method_call.argument);
|
2018-10-29 23:36:03 -04:00
|
|
|
break;
|
|
|
|
}
|
2019-08-31 16:43:19 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(firmware[4]): {
|
|
|
|
ProcessFirmwareCall4();
|
|
|
|
break;
|
|
|
|
}
|
2018-03-18 16:19:47 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[0]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[1]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[2]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[3]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[4]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[5]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[6]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[7]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[8]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[9]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[10]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[11]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[12]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[13]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[14]):
|
|
|
|
case MAXWELL3D_REG_INDEX(const_buffer.cb_data[15]): {
|
2019-07-12 09:25:47 -04:00
|
|
|
StartCBData(method);
|
2018-03-18 16:19:47 -04:00
|
|
|
break;
|
|
|
|
}
|
2019-11-18 16:35:21 -05:00
|
|
|
case MAXWELL3D_REG_INDEX(cb_bind[0]): {
|
|
|
|
ProcessCBBind(0);
|
2018-03-17 18:06:23 -04:00
|
|
|
break;
|
|
|
|
}
|
2019-11-18 16:35:21 -05:00
|
|
|
case MAXWELL3D_REG_INDEX(cb_bind[1]): {
|
|
|
|
ProcessCBBind(1);
|
2018-03-17 18:06:23 -04:00
|
|
|
break;
|
|
|
|
}
|
2019-11-18 16:35:21 -05:00
|
|
|
case MAXWELL3D_REG_INDEX(cb_bind[2]): {
|
|
|
|
ProcessCBBind(2);
|
2018-03-17 18:06:23 -04:00
|
|
|
break;
|
|
|
|
}
|
2019-11-18 16:35:21 -05:00
|
|
|
case MAXWELL3D_REG_INDEX(cb_bind[3]): {
|
|
|
|
ProcessCBBind(3);
|
2018-03-17 18:06:23 -04:00
|
|
|
break;
|
|
|
|
}
|
2019-11-18 16:35:21 -05:00
|
|
|
case MAXWELL3D_REG_INDEX(cb_bind[4]): {
|
|
|
|
ProcessCBBind(4);
|
2018-03-17 18:06:23 -04:00
|
|
|
break;
|
|
|
|
}
|
2018-03-04 19:13:15 -05:00
|
|
|
case MAXWELL3D_REG_INDEX(draw.vertex_end_gl): {
|
|
|
|
DrawArrays();
|
|
|
|
break;
|
|
|
|
}
|
2018-06-07 00:54:25 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(clear_buffers): {
|
|
|
|
ProcessClearBuffers();
|
|
|
|
break;
|
|
|
|
}
|
2018-02-12 12:34:41 -05:00
|
|
|
case MAXWELL3D_REG_INDEX(query.query_get): {
|
|
|
|
ProcessQueryGet();
|
|
|
|
break;
|
|
|
|
}
|
2019-06-30 22:21:28 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(condition.mode): {
|
|
|
|
ProcessQueryCondition();
|
|
|
|
break;
|
|
|
|
}
|
2019-04-02 11:46:00 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(sync_info): {
|
|
|
|
ProcessSyncPoint();
|
|
|
|
break;
|
|
|
|
}
|
2019-04-22 19:27:36 -04:00
|
|
|
case MAXWELL3D_REG_INDEX(exec_upload): {
|
|
|
|
upload_state.ProcessExec(regs.exec_upload.linear != 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MAXWELL3D_REG_INDEX(data_upload): {
|
2019-04-23 08:02:24 -04:00
|
|
|
const bool is_last_call = method_call.IsLastCall();
|
2019-04-22 19:27:36 -04:00
|
|
|
upload_state.ProcessData(method_call.argument, is_last_call);
|
|
|
|
if (is_last_call) {
|
2019-07-10 15:38:31 -04:00
|
|
|
dirty.OnMemoryWrite();
|
2019-04-22 19:27:36 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-02-12 12:34:41 -05:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-22 07:23:13 -04:00
|
|
|
void Maxwell3D::StepInstance(const MMEDrawMode expected_mode, const u32 count) {
|
|
|
|
if (mme_draw.current_mode == MMEDrawMode::Undefined) {
|
|
|
|
if (mme_draw.gl_begin_consume) {
|
|
|
|
mme_draw.current_mode = expected_mode;
|
|
|
|
mme_draw.current_count = count;
|
|
|
|
mme_draw.instance_count = 1;
|
|
|
|
mme_draw.gl_begin_consume = false;
|
|
|
|
mme_draw.gl_end_count = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (mme_draw.current_mode == expected_mode && count == mme_draw.current_count &&
|
|
|
|
mme_draw.instance_mode && mme_draw.gl_begin_consume) {
|
|
|
|
mme_draw.instance_count++;
|
|
|
|
mme_draw.gl_begin_consume = false;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
FlushMMEInlineDraw();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Tail call in case it needs to retry.
|
|
|
|
StepInstance(expected_mode, count);
|
|
|
|
}
|
|
|
|
|
2019-09-15 11:48:54 -04:00
|
|
|
void Maxwell3D::CallMethodFromMME(const GPU::MethodCall& method_call) {
|
|
|
|
const u32 method = method_call.method;
|
|
|
|
if (mme_inline[method]) {
|
|
|
|
regs.reg_array[method] = method_call.argument;
|
|
|
|
if (method == MAXWELL3D_REG_INDEX(vertex_buffer.count) ||
|
|
|
|
method == MAXWELL3D_REG_INDEX(index_array.count)) {
|
2019-09-22 07:23:13 -04:00
|
|
|
const MMEDrawMode expected_mode = method == MAXWELL3D_REG_INDEX(vertex_buffer.count)
|
|
|
|
? MMEDrawMode::Array
|
|
|
|
: MMEDrawMode::Indexed;
|
|
|
|
StepInstance(expected_mode, method_call.argument);
|
2019-09-15 14:25:07 -04:00
|
|
|
} else if (method == MAXWELL3D_REG_INDEX(draw.vertex_begin_gl)) {
|
|
|
|
mme_draw.instance_mode =
|
|
|
|
(regs.draw.instance_next != 0) || (regs.draw.instance_cont != 0);
|
|
|
|
mme_draw.gl_begin_consume = true;
|
|
|
|
} else {
|
|
|
|
mme_draw.gl_end_count++;
|
2019-09-15 11:48:54 -04:00
|
|
|
}
|
|
|
|
} else {
|
2019-09-22 07:23:13 -04:00
|
|
|
if (mme_draw.current_mode != MMEDrawMode::Undefined) {
|
2019-09-15 11:48:54 -04:00
|
|
|
FlushMMEInlineDraw();
|
|
|
|
}
|
|
|
|
CallMethod(method_call);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Maxwell3D::FlushMMEInlineDraw() {
|
2019-10-20 02:43:17 -04:00
|
|
|
LOG_TRACE(HW_GPU, "called, topology={}, count={}", static_cast<u32>(regs.draw.topology.Value()),
|
2019-09-15 11:48:54 -04:00
|
|
|
regs.vertex_buffer.count);
|
|
|
|
ASSERT_MSG(!(regs.index_array.count && regs.vertex_buffer.count), "Both indexed and direct?");
|
2019-09-15 14:25:07 -04:00
|
|
|
ASSERT(mme_draw.instance_count == mme_draw.gl_end_count);
|
2019-09-15 11:48:54 -04:00
|
|
|
|
|
|
|
// Both instance configuration registers can not be set at the same time.
|
|
|
|
ASSERT_MSG(!regs.draw.instance_next || !regs.draw.instance_cont,
|
|
|
|
"Illegal combination of instancing parameters");
|
|
|
|
|
2019-09-22 07:23:13 -04:00
|
|
|
const bool is_indexed = mme_draw.current_mode == MMEDrawMode::Indexed;
|
|
|
|
if (ShouldExecute()) {
|
|
|
|
rasterizer.DrawMultiBatch(is_indexed);
|
|
|
|
}
|
2019-09-15 11:48:54 -04:00
|
|
|
|
|
|
|
// TODO(bunnei): Below, we reset vertex count so that we can use these registers to determine if
|
|
|
|
// the game is trying to draw indexed or direct mode. This needs to be verified on HW still -
|
|
|
|
// it's possible that it is incorrect and that there is some other register used to specify the
|
|
|
|
// drawing mode.
|
|
|
|
if (is_indexed) {
|
|
|
|
regs.index_array.count = 0;
|
|
|
|
} else {
|
|
|
|
regs.vertex_buffer.count = 0;
|
|
|
|
}
|
2019-09-22 07:23:13 -04:00
|
|
|
mme_draw.current_mode = MMEDrawMode::Undefined;
|
2019-09-15 11:48:54 -04:00
|
|
|
mme_draw.current_count = 0;
|
|
|
|
mme_draw.instance_count = 0;
|
2019-09-15 14:25:07 -04:00
|
|
|
mme_draw.instance_mode = false;
|
|
|
|
mme_draw.gl_begin_consume = false;
|
|
|
|
mme_draw.gl_end_count = 0;
|
2019-09-15 11:48:54 -04:00
|
|
|
}
|
|
|
|
|
2018-04-23 21:01:29 -04:00
|
|
|
void Maxwell3D::ProcessMacroUpload(u32 data) {
|
2018-10-29 23:36:03 -04:00
|
|
|
ASSERT_MSG(regs.macros.upload_address < macro_memory.size(),
|
|
|
|
"upload_address exceeded macro_memory size!");
|
|
|
|
macro_memory[regs.macros.upload_address++] = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Maxwell3D::ProcessMacroBind(u32 data) {
|
2019-09-01 03:59:27 -04:00
|
|
|
macro_positions[regs.macros.entry++] = 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.
|
2019-08-31 16:43:19 -04:00
|
|
|
regs.reg_array[0xd00] = 1;
|
|
|
|
}
|
|
|
|
|
2020-01-27 21:48:15 -05:00
|
|
|
void Maxwell3D::StampQueryResult(u64 payload, bool long_query) {
|
|
|
|
struct LongQueryResult {
|
|
|
|
u64_le value;
|
|
|
|
u64_le timestamp;
|
|
|
|
};
|
|
|
|
static_assert(sizeof(LongQueryResult) == 16, "LongQueryResult has wrong size");
|
2019-02-24 00:15:35 -05:00
|
|
|
const GPUVAddr sequence_address{regs.query.QueryAddress()};
|
2020-01-27 21:48:15 -05:00
|
|
|
if (long_query) {
|
|
|
|
// Write the 128-bit result structure in long mode. Note: We emulate an infinitely fast
|
|
|
|
// GPU, this command may actually take a while to complete in real hardware due to GPU
|
|
|
|
// wait queues.
|
2020-02-13 17:16:07 -05:00
|
|
|
LongQueryResult query_result{payload, system.GPU().GetTicks()};
|
2020-01-27 21:48:15 -05:00
|
|
|
memory_manager.WriteBlock(sequence_address, &query_result, sizeof(query_result));
|
|
|
|
} 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.
|
|
|
|
ASSERT_MSG(regs.query.query_get.unit == Regs::QueryUnit::Crop,
|
|
|
|
"Units other than CROP are unimplemented");
|
|
|
|
|
2020-01-27 21:48:15 -05:00
|
|
|
switch (regs.query.query_get.operation) {
|
|
|
|
case Regs::QueryOperation::Release: {
|
2020-02-13 17:16:07 -05:00
|
|
|
const u64 result = regs.query.query_sequence;
|
2020-01-27 21:48:15 -05:00
|
|
|
StampQueryResult(result, regs.query.query_get.short_query == 0);
|
2018-04-23 18:06:57 -04:00
|
|
|
break;
|
|
|
|
}
|
2020-01-27 21:48:15 -05:00
|
|
|
case Regs::QueryOperation::Acquire: {
|
|
|
|
// Todo(Blinkhawk): Under this operation, the GPU waits for the CPU
|
|
|
|
// to write a value that matches the current payload.
|
|
|
|
UNIMPLEMENTED_MSG("Unimplemented query operation ACQUIRE");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Regs::QueryOperation::Counter: {
|
|
|
|
u64 result{};
|
|
|
|
switch (regs.query.query_get.select) {
|
|
|
|
case Regs::QuerySelect::Zero:
|
|
|
|
result = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = 1;
|
|
|
|
UNIMPLEMENTED_MSG("Unimplemented query select type {}",
|
|
|
|
static_cast<u32>(regs.query.query_get.select.Value()));
|
2018-06-03 20:17:31 -04:00
|
|
|
}
|
2020-01-27 21:48:15 -05:00
|
|
|
StampQueryResult(result, regs.query.query_get.short_query == 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Regs::QueryOperation::Trap: {
|
|
|
|
UNIMPLEMENTED_MSG("Unimplemented query operation TRAP");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
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() {
|
|
|
|
const GPUVAddr condition_address{regs.condition.Address()};
|
|
|
|
switch (regs.condition.mode) {
|
|
|
|
case Regs::ConditionMode::Always: {
|
|
|
|
execute_on = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Regs::ConditionMode::Never: {
|
|
|
|
execute_on = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Regs::ConditionMode::ResNonZero: {
|
|
|
|
Regs::QueryCompare cmp;
|
|
|
|
memory_manager.ReadBlockUnsafe(condition_address, &cmp, sizeof(cmp));
|
|
|
|
execute_on = cmp.initial_sequence != 0U && cmp.initial_mode != 0U;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Regs::ConditionMode::Equal: {
|
|
|
|
Regs::QueryCompare cmp;
|
|
|
|
memory_manager.ReadBlockUnsafe(condition_address, &cmp, sizeof(cmp));
|
|
|
|
execute_on =
|
|
|
|
cmp.initial_sequence == cmp.current_sequence && cmp.initial_mode == cmp.current_mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case Regs::ConditionMode::NotEqual: {
|
|
|
|
Regs::QueryCompare cmp;
|
|
|
|
memory_manager.ReadBlockUnsafe(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-04-02 11:46:00 -04:00
|
|
|
void Maxwell3D::ProcessSyncPoint() {
|
|
|
|
const u32 sync_point = regs.sync_info.sync_point.Value();
|
|
|
|
const u32 increment = regs.sync_info.increment.Value();
|
2019-08-30 14:08:00 -04:00
|
|
|
[[maybe_unused]] const u32 cache_flush = regs.sync_info.unknown.Value();
|
2019-06-07 12:56:30 -04:00
|
|
|
if (increment) {
|
|
|
|
system.GPU().IncrementSyncPoint(sync_point);
|
|
|
|
}
|
2019-04-02 11:46:00 -04:00
|
|
|
}
|
|
|
|
|
2018-03-04 19:13:15 -05:00
|
|
|
void Maxwell3D::DrawArrays() {
|
2019-09-21 01:43:58 -04:00
|
|
|
LOG_TRACE(HW_GPU, "called, topology={}, count={}", static_cast<u32>(regs.draw.topology.Value()),
|
2018-07-02 12:20:50 -04:00
|
|
|
regs.vertex_buffer.count);
|
2018-04-13 14:18:37 -04:00
|
|
|
ASSERT_MSG(!(regs.index_array.count && regs.vertex_buffer.count), "Both indexed and direct?");
|
2018-03-24 02:41:16 -04:00
|
|
|
|
2018-08-11 20:21:31 -04:00
|
|
|
// Both instance configuration registers can not be set at the same time.
|
|
|
|
ASSERT_MSG(!regs.draw.instance_next || !regs.draw.instance_cont,
|
|
|
|
"Illegal combination of instancing parameters");
|
|
|
|
|
|
|
|
if (regs.draw.instance_next) {
|
|
|
|
// Increment the current instance *before* drawing.
|
|
|
|
state.current_instance += 1;
|
|
|
|
} else if (!regs.draw.instance_cont) {
|
|
|
|
// Reset the current instance to 0.
|
|
|
|
state.current_instance = 0;
|
|
|
|
}
|
|
|
|
|
2018-04-13 14:18:37 -04:00
|
|
|
const bool is_indexed{regs.index_array.count && !regs.vertex_buffer.count};
|
2019-09-22 07:23:13 -04:00
|
|
|
if (ShouldExecute()) {
|
|
|
|
rasterizer.DrawBatch(is_indexed);
|
|
|
|
}
|
2018-04-29 16:23:31 -04:00
|
|
|
|
|
|
|
// TODO(bunnei): Below, we reset vertex count so that we can use these registers to determine if
|
|
|
|
// the game is trying to draw indexed or direct mode. This needs to be verified on HW still -
|
|
|
|
// it's possible that it is incorrect and that there is some other register used to specify the
|
|
|
|
// drawing mode.
|
|
|
|
if (is_indexed) {
|
|
|
|
regs.index_array.count = 0;
|
|
|
|
} else {
|
|
|
|
regs.vertex_buffer.count = 0;
|
|
|
|
}
|
2018-03-04 19:13:15 -05:00
|
|
|
}
|
|
|
|
|
2019-11-18 16:35:21 -05:00
|
|
|
void Maxwell3D::ProcessCBBind(std::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.
|
2019-11-18 16:35:21 -05:00
|
|
|
auto& shader = state.shader_stages[stage_index];
|
|
|
|
auto& bind_data = regs.cb_bind[stage_index];
|
2018-03-17 18:06:23 -04:00
|
|
|
|
2018-08-08 02:07:44 -04:00
|
|
|
ASSERT(bind_data.index < Regs::MaxConstBuffers);
|
2019-05-31 16:33:21 -04:00
|
|
|
auto& buffer = shader.const_buffers[bind_data.index];
|
2018-08-08 02:07:44 -04:00
|
|
|
|
2018-03-17 18:06:23 -04:00
|
|
|
buffer.enabled = bind_data.valid.Value() != 0;
|
|
|
|
buffer.address = regs.const_buffer.BufferAddress();
|
|
|
|
buffer.size = regs.const_buffer.cb_size;
|
2018-03-16 23:06:24 -04:00
|
|
|
}
|
2018-03-16 21:32:44 -04:00
|
|
|
|
2018-03-18 16:19:47 -04:00
|
|
|
void Maxwell3D::ProcessCBData(u32 value) {
|
2019-07-12 09:25:47 -04:00
|
|
|
const u32 id = cb_data_state.id;
|
2019-07-15 10:24:01 -04:00
|
|
|
cb_data_state.buffer[id][cb_data_state.counter] = value;
|
2019-07-12 09:25:47 -04:00
|
|
|
// Increment the current buffer position.
|
|
|
|
regs.const_buffer.cb_pos = regs.const_buffer.cb_pos + 4;
|
|
|
|
cb_data_state.counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Maxwell3D::StartCBData(u32 method) {
|
|
|
|
constexpr u32 first_cb_data = MAXWELL3D_REG_INDEX(const_buffer.cb_data[0]);
|
|
|
|
cb_data_state.start_pos = regs.const_buffer.cb_pos;
|
|
|
|
cb_data_state.id = method - first_cb_data;
|
|
|
|
cb_data_state.current = method;
|
|
|
|
cb_data_state.counter = 0;
|
|
|
|
ProcessCBData(regs.const_buffer.cb_data[cb_data_state.id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Maxwell3D::FinishCBData() {
|
2018-03-18 16:19:47 -04:00
|
|
|
// Write the input value to the current const buffer at the current position.
|
2019-01-22 01:47:56 -05:00
|
|
|
const GPUVAddr buffer_address = regs.const_buffer.BufferAddress();
|
2018-03-18 16:19:47 -04:00
|
|
|
ASSERT(buffer_address != 0);
|
|
|
|
|
|
|
|
// Don't allow writing past the end of the buffer.
|
2019-07-12 09:25:47 -04:00
|
|
|
ASSERT(regs.const_buffer.cb_pos <= regs.const_buffer.cb_size);
|
2018-03-18 16:19:47 -04:00
|
|
|
|
2019-07-12 09:25:47 -04:00
|
|
|
const GPUVAddr address{buffer_address + cb_data_state.start_pos};
|
|
|
|
const std::size_t size = regs.const_buffer.cb_pos - cb_data_state.start_pos;
|
2018-03-18 16:19:47 -04:00
|
|
|
|
2019-07-12 09:25:47 -04:00
|
|
|
const u32 id = cb_data_state.id;
|
2019-07-15 10:24:01 -04:00
|
|
|
memory_manager.WriteBlock(address, cb_data_state.buffer[id].data(), size);
|
2019-07-14 15:00:37 -04:00
|
|
|
dirty.OnMemoryWrite();
|
2019-02-18 20:58:32 -05:00
|
|
|
|
2019-07-12 09:25:47 -04:00
|
|
|
cb_data_state.id = null_cb_data;
|
|
|
|
cb_data_state.current = null_cb_data;
|
2018-03-18 16:19:47 -04:00
|
|
|
}
|
|
|
|
|
2018-03-26 16:46:49 -04:00
|
|
|
Texture::TICEntry Maxwell3D::GetTICEntry(u32 tic_index) const {
|
2019-02-24 00:15:35 -05:00
|
|
|
const GPUVAddr tic_address_gpu{regs.tic.TICAddress() + 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 {
|
2019-02-24 00:15:35 -05:00
|
|
|
const GPUVAddr tsc_address_gpu{regs.tsc.TSCAddress() + 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;
|
|
|
|
}
|
|
|
|
|
2019-10-20 03:03:33 -04:00
|
|
|
Texture::FullTextureInfo Maxwell3D::GetTextureInfo(Texture::TextureHandle tex_handle) const {
|
|
|
|
return Texture::FullTextureInfo{GetTICEntry(tex_handle.tic_id), GetTSCEntry(tex_handle.tsc_id)};
|
2018-06-06 13:58:16 -04:00
|
|
|
}
|
|
|
|
|
2019-11-18 16:35:21 -05:00
|
|
|
Texture::FullTextureInfo Maxwell3D::GetStageTexture(ShaderType stage, std::size_t offset) const {
|
|
|
|
const auto stage_index = static_cast<std::size_t>(stage);
|
|
|
|
const auto& shader = state.shader_stages[stage_index];
|
2019-04-07 08:30:26 -04:00
|
|
|
const auto& tex_info_buffer = shader.const_buffers[regs.tex_cb_index];
|
2019-03-26 18:18:54 -04:00
|
|
|
ASSERT(tex_info_buffer.enabled && tex_info_buffer.address != 0);
|
|
|
|
|
|
|
|
const GPUVAddr tex_info_address =
|
|
|
|
tex_info_buffer.address + offset * sizeof(Texture::TextureHandle);
|
|
|
|
|
|
|
|
ASSERT(tex_info_address < tex_info_buffer.address + tex_info_buffer.size);
|
|
|
|
|
|
|
|
const Texture::TextureHandle tex_handle{memory_manager.Read<u32>(tex_info_address)};
|
|
|
|
|
2019-10-20 03:03:33 -04:00
|
|
|
return GetTextureInfo(tex_handle);
|
2019-03-26 18:18:54 -04:00
|
|
|
}
|
|
|
|
|
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-06-07 00:54:25 -04:00
|
|
|
void Maxwell3D::ProcessClearBuffers() {
|
2018-07-02 20:09:03 -04:00
|
|
|
ASSERT(regs.clear_buffers.R == regs.clear_buffers.G &&
|
|
|
|
regs.clear_buffers.R == regs.clear_buffers.B &&
|
|
|
|
regs.clear_buffers.R == regs.clear_buffers.A);
|
2018-06-07 00:54:25 -04:00
|
|
|
|
2018-08-03 12:55:58 -04:00
|
|
|
rasterizer.Clear();
|
2018-06-07 00:54:25 -04:00
|
|
|
}
|
|
|
|
|
2019-09-23 14:02:02 -04:00
|
|
|
u32 Maxwell3D::AccessConstBuffer32(ShaderType stage, u64 const_buffer, u64 offset) const {
|
|
|
|
ASSERT(stage != ShaderType::Compute);
|
2019-04-07 08:30:26 -04:00
|
|
|
const auto& shader_stage = state.shader_stages[static_cast<std::size_t>(stage)];
|
|
|
|
const auto& buffer = shader_stage.const_buffers[const_buffer];
|
|
|
|
u32 result;
|
|
|
|
std::memcpy(&result, memory_manager.GetPointer(buffer.address + offset), sizeof(u32));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-09-25 09:53:18 -04:00
|
|
|
SamplerDescriptor Maxwell3D::AccessBoundSampler(ShaderType stage, u64 offset) const {
|
|
|
|
return AccessBindlessSampler(stage, regs.tex_cb_index, offset * sizeof(Texture::TextureHandle));
|
|
|
|
}
|
|
|
|
|
|
|
|
SamplerDescriptor Maxwell3D::AccessBindlessSampler(ShaderType stage, u64 const_buffer,
|
|
|
|
u64 offset) const {
|
|
|
|
ASSERT(stage != ShaderType::Compute);
|
|
|
|
const auto& shader = state.shader_stages[static_cast<std::size_t>(stage)];
|
|
|
|
const auto& tex_info_buffer = shader.const_buffers[const_buffer];
|
|
|
|
const GPUVAddr tex_info_address = tex_info_buffer.address + offset;
|
|
|
|
|
|
|
|
const Texture::TextureHandle tex_handle{memory_manager.Read<u32>(tex_info_address)};
|
2019-10-20 03:03:33 -04:00
|
|
|
const Texture::FullTextureInfo tex_info = GetTextureInfo(tex_handle);
|
2019-09-25 09:53:18 -04:00
|
|
|
SamplerDescriptor result = SamplerDescriptor::FromTicTexture(tex_info.tic.texture_type.Value());
|
|
|
|
result.is_shadow.Assign(tex_info.tsc.depth_compare_enabled.Value());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-01-03 15:16:29 -05:00
|
|
|
VideoCore::GuestDriverProfile& Maxwell3D::AccessGuestDriverProfile() {
|
|
|
|
return rasterizer.AccessGuestDriverProfile();
|
|
|
|
}
|
|
|
|
|
2020-01-08 09:28:29 -05:00
|
|
|
const VideoCore::GuestDriverProfile& Maxwell3D::AccessGuestDriverProfile() const {
|
|
|
|
return rasterizer.AccessGuestDriverProfile();
|
|
|
|
}
|
|
|
|
|
2018-10-20 15:58:06 -04:00
|
|
|
} // namespace Tegra::Engines
|