2018-02-12 03:34:20 +01:00
|
|
|
// Copyright 2018 yuzu Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-03-17 04:06:24 +01:00
|
|
|
#include <array>
|
2018-03-17 02:32:44 +01:00
|
|
|
#include <unordered_map>
|
|
|
|
#include <vector>
|
2018-02-12 18:34:41 +01:00
|
|
|
#include "common/bit_field.h"
|
|
|
|
#include "common/common_funcs.h"
|
2018-02-12 03:34:20 +01:00
|
|
|
#include "common/common_types.h"
|
2018-02-12 18:34:41 +01:00
|
|
|
#include "video_core/memory_manager.h"
|
2018-02-12 03:34:20 +01:00
|
|
|
|
|
|
|
namespace Tegra {
|
|
|
|
namespace Engines {
|
|
|
|
|
2018-02-12 05:44:12 +01:00
|
|
|
class Maxwell3D final {
|
|
|
|
public:
|
2018-02-14 05:47:51 +01:00
|
|
|
explicit Maxwell3D(MemoryManager& memory_manager);
|
2018-02-12 05:44:12 +01:00
|
|
|
~Maxwell3D() = default;
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2018-02-12 05:44:12 +01:00
|
|
|
/// Write the value to the register identified by method.
|
|
|
|
void WriteReg(u32 method, u32 value);
|
2018-02-12 18:34:41 +01:00
|
|
|
|
2018-03-17 02:32:44 +01:00
|
|
|
/**
|
|
|
|
* Handles a method call to this engine.
|
|
|
|
* @param method Method to call
|
|
|
|
* @param parameters Arguments to the method call
|
|
|
|
*/
|
|
|
|
void CallMethod(u32 method, const std::vector<u32>& parameters);
|
|
|
|
|
2018-02-12 18:34:41 +01:00
|
|
|
/// Register structure of the Maxwell3D engine.
|
|
|
|
/// TODO(Subv): This structure will need to be made bigger as more registers are discovered.
|
|
|
|
struct Regs {
|
|
|
|
static constexpr size_t NUM_REGS = 0xE36;
|
|
|
|
|
2018-03-17 22:17:45 +01:00
|
|
|
static constexpr size_t NumCBData = 16;
|
2018-03-17 04:47:45 +01:00
|
|
|
static constexpr size_t NumVertexArrays = 32;
|
|
|
|
static constexpr size_t MaxShaderProgram = 6;
|
2018-03-17 22:17:45 +01:00
|
|
|
static constexpr size_t MaxShaderType = 5;
|
2018-03-17 04:47:45 +01:00
|
|
|
|
2018-02-12 18:34:41 +01:00
|
|
|
enum class QueryMode : u32 {
|
|
|
|
Write = 0,
|
|
|
|
Sync = 1,
|
|
|
|
};
|
|
|
|
|
2018-03-17 01:23:11 +01:00
|
|
|
enum class ShaderProgram : u32 {
|
|
|
|
VertexA = 0,
|
|
|
|
VertexB = 1,
|
|
|
|
TesselationControl = 2,
|
|
|
|
TesselationEval = 3,
|
|
|
|
Geometry = 4,
|
|
|
|
Fragment = 5,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class ShaderType : u32 {
|
|
|
|
Vertex = 0,
|
|
|
|
TesselationControl = 1,
|
|
|
|
TesselationEval = 2,
|
|
|
|
Geometry = 3,
|
|
|
|
Fragment = 4,
|
|
|
|
};
|
|
|
|
|
2018-02-12 18:34:41 +01:00
|
|
|
union {
|
|
|
|
struct {
|
2018-03-17 01:23:11 +01:00
|
|
|
INSERT_PADDING_WORDS(0x582);
|
|
|
|
struct {
|
|
|
|
u32 code_address_high;
|
|
|
|
u32 code_address_low;
|
|
|
|
|
|
|
|
GPUVAddr CodeAddress() const {
|
|
|
|
return static_cast<GPUVAddr>(
|
|
|
|
(static_cast<GPUVAddr>(code_address_high) << 32) | code_address_low);
|
|
|
|
}
|
|
|
|
} code_address;
|
|
|
|
INSERT_PADDING_WORDS(1);
|
2018-03-05 01:13:15 +01:00
|
|
|
struct {
|
|
|
|
u32 vertex_end_gl;
|
|
|
|
u32 vertex_begin_gl;
|
|
|
|
} draw;
|
|
|
|
INSERT_PADDING_WORDS(0x139);
|
2018-02-12 18:34:41 +01:00
|
|
|
struct {
|
|
|
|
u32 query_address_high;
|
|
|
|
u32 query_address_low;
|
|
|
|
u32 query_sequence;
|
|
|
|
union {
|
|
|
|
u32 raw;
|
|
|
|
BitField<0, 2, QueryMode> mode;
|
|
|
|
BitField<4, 1, u32> fence;
|
|
|
|
BitField<12, 4, u32> unit;
|
|
|
|
} query_get;
|
|
|
|
|
|
|
|
GPUVAddr QueryAddress() const {
|
|
|
|
return static_cast<GPUVAddr>(
|
|
|
|
(static_cast<GPUVAddr>(query_address_high) << 32) | query_address_low);
|
|
|
|
}
|
|
|
|
} query;
|
2018-03-17 01:23:11 +01:00
|
|
|
|
2018-03-17 04:47:45 +01:00
|
|
|
INSERT_PADDING_WORDS(0x3C);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
union {
|
|
|
|
BitField<0, 12, u32> stride;
|
|
|
|
BitField<12, 1, u32> enable;
|
|
|
|
};
|
|
|
|
u32 start_high;
|
|
|
|
u32 start_low;
|
|
|
|
u32 divisor;
|
|
|
|
|
|
|
|
GPUVAddr StartAddress() const {
|
|
|
|
return static_cast<GPUVAddr>((static_cast<GPUVAddr>(start_high) << 32) |
|
|
|
|
start_low);
|
|
|
|
}
|
|
|
|
} vertex_array[NumVertexArrays];
|
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x40);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u32 limit_high;
|
|
|
|
u32 limit_low;
|
|
|
|
|
|
|
|
GPUVAddr LimitAddress() const {
|
|
|
|
return static_cast<GPUVAddr>((static_cast<GPUVAddr>(limit_high) << 32) |
|
|
|
|
limit_low);
|
|
|
|
}
|
|
|
|
} vertex_array_limit[NumVertexArrays];
|
2018-03-17 01:23:11 +01:00
|
|
|
|
|
|
|
struct {
|
|
|
|
union {
|
|
|
|
BitField<0, 1, u32> enable;
|
|
|
|
BitField<4, 4, ShaderProgram> program;
|
|
|
|
};
|
|
|
|
u32 start_id;
|
|
|
|
INSERT_PADDING_WORDS(1);
|
|
|
|
u32 gpr_alloc;
|
|
|
|
ShaderType type;
|
|
|
|
INSERT_PADDING_WORDS(9);
|
2018-03-17 04:06:24 +01:00
|
|
|
} shader_config[MaxShaderProgram];
|
2018-03-17 01:23:11 +01:00
|
|
|
|
2018-03-17 22:17:45 +01:00
|
|
|
INSERT_PADDING_WORDS(0x8C);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u32 cb_size;
|
|
|
|
u32 cb_address_high;
|
|
|
|
u32 cb_address_low;
|
|
|
|
u32 cb_pos;
|
|
|
|
u32 cb_data[NumCBData];
|
|
|
|
} const_buffer;
|
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x74);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
union {
|
|
|
|
BitField<0, 1, u32> valid;
|
|
|
|
BitField<4, 5, u32> index;
|
|
|
|
};
|
|
|
|
INSERT_PADDING_WORDS(7);
|
|
|
|
} cb_bind[MaxShaderType];
|
|
|
|
|
|
|
|
INSERT_PADDING_WORDS(0x494);
|
2018-03-17 01:23:11 +01:00
|
|
|
|
|
|
|
struct {
|
2018-03-17 19:55:42 +01:00
|
|
|
u32 set_shader_call;
|
|
|
|
u32 set_shader_args;
|
|
|
|
} set_shader;
|
2018-03-17 01:23:11 +01:00
|
|
|
INSERT_PADDING_WORDS(0x10);
|
2018-02-12 18:34:41 +01:00
|
|
|
};
|
|
|
|
std::array<u32, NUM_REGS> reg_array;
|
|
|
|
};
|
|
|
|
} regs{};
|
|
|
|
|
|
|
|
static_assert(sizeof(Regs) == Regs::NUM_REGS * sizeof(u32), "Maxwell3D Regs has wrong size");
|
|
|
|
|
2018-03-17 04:06:24 +01:00
|
|
|
struct State {
|
|
|
|
struct ShaderInfo {
|
|
|
|
Regs::ShaderType type;
|
|
|
|
Regs::ShaderProgram program;
|
2018-03-17 19:55:42 +01:00
|
|
|
GPUVAddr address;
|
|
|
|
GPUVAddr cb_address;
|
2018-03-17 04:06:24 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
std::array<ShaderInfo, Regs::MaxShaderProgram> shaders;
|
|
|
|
};
|
|
|
|
|
2018-03-17 22:17:45 +01:00
|
|
|
State state{};
|
2018-03-17 04:06:24 +01:00
|
|
|
|
2018-02-12 18:34:41 +01:00
|
|
|
private:
|
2018-03-17 02:32:44 +01:00
|
|
|
MemoryManager& memory_manager;
|
|
|
|
|
2018-02-12 18:34:41 +01:00
|
|
|
/// Handles a write to the QUERY_GET register.
|
|
|
|
void ProcessQueryGet();
|
|
|
|
|
2018-03-05 01:13:15 +01:00
|
|
|
/// Handles a write to the VERTEX_END_GL register, triggering a draw.
|
|
|
|
void DrawArrays();
|
|
|
|
|
2018-03-17 02:32:44 +01:00
|
|
|
/// Method call handlers
|
2018-03-17 04:06:24 +01:00
|
|
|
void SetShader(const std::vector<u32>& parameters);
|
2018-03-17 02:32:44 +01:00
|
|
|
|
|
|
|
struct MethodInfo {
|
|
|
|
const char* name;
|
|
|
|
u32 arguments;
|
|
|
|
void (Maxwell3D::*handler)(const std::vector<u32>& parameters);
|
|
|
|
};
|
|
|
|
|
|
|
|
static const std::unordered_map<u32, MethodInfo> method_handlers;
|
2018-02-12 05:44:12 +01:00
|
|
|
};
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2018-02-12 18:34:41 +01:00
|
|
|
#define ASSERT_REG_POSITION(field_name, position) \
|
|
|
|
static_assert(offsetof(Maxwell3D::Regs, field_name) == position * 4, \
|
|
|
|
"Field " #field_name " has invalid position")
|
|
|
|
|
2018-03-17 01:23:11 +01:00
|
|
|
ASSERT_REG_POSITION(code_address, 0x582);
|
|
|
|
ASSERT_REG_POSITION(draw, 0x585);
|
2018-02-12 18:34:41 +01:00
|
|
|
ASSERT_REG_POSITION(query, 0x6C0);
|
2018-03-17 04:47:45 +01:00
|
|
|
ASSERT_REG_POSITION(vertex_array[0], 0x700);
|
|
|
|
ASSERT_REG_POSITION(vertex_array_limit[0], 0x7C0);
|
2018-03-17 01:23:11 +01:00
|
|
|
ASSERT_REG_POSITION(shader_config[0], 0x800);
|
2018-03-17 22:17:45 +01:00
|
|
|
ASSERT_REG_POSITION(const_buffer, 0x8E0);
|
2018-03-17 19:55:42 +01:00
|
|
|
ASSERT_REG_POSITION(set_shader, 0xE24);
|
2018-02-12 18:34:41 +01:00
|
|
|
|
|
|
|
#undef ASSERT_REG_POSITION
|
|
|
|
|
2018-02-12 03:34:20 +01:00
|
|
|
} // namespace Engines
|
|
|
|
} // namespace Tegra
|