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-04-24 03:12:40 +02:00
|
|
|
#include <array>
|
2019-03-06 02:25:01 +01:00
|
|
|
#include <cstddef>
|
2018-04-24 05:14:08 +02:00
|
|
|
#include "common/bit_field.h"
|
2018-04-24 03:12:40 +02:00
|
|
|
#include "common/common_funcs.h"
|
2018-02-12 03:34:20 +01:00
|
|
|
#include "common/common_types.h"
|
2019-05-18 10:57:49 +02:00
|
|
|
#include "common/math_util.h"
|
2020-04-28 03:47:58 +02:00
|
|
|
#include "video_core/engines/engine_interface.h"
|
2018-04-24 05:14:08 +02:00
|
|
|
#include "video_core/gpu.h"
|
2019-04-06 00:21:15 +02:00
|
|
|
|
|
|
|
namespace Tegra {
|
|
|
|
class MemoryManager;
|
|
|
|
}
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2018-10-06 05:46:40 +02:00
|
|
|
namespace VideoCore {
|
|
|
|
class RasterizerInterface;
|
|
|
|
}
|
|
|
|
|
2018-07-21 00:14:17 +02:00
|
|
|
namespace Tegra::Engines {
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2019-04-23 14:44:52 +02:00
|
|
|
/**
|
|
|
|
* This Engine is known as G80_2D. Documentation can be found in:
|
|
|
|
* https://github.com/envytools/envytools/blob/master/rnndb/graph/g80_2d.xml
|
|
|
|
* https://cgit.freedesktop.org/mesa/mesa/tree/src/gallium/drivers/nouveau/nv50/nv50_2d.xml.h
|
|
|
|
*/
|
|
|
|
|
2018-04-24 03:12:40 +02:00
|
|
|
#define FERMI2D_REG_INDEX(field_name) \
|
|
|
|
(offsetof(Tegra::Engines::Fermi2D::Regs, field_name) / sizeof(u32))
|
|
|
|
|
2020-04-28 03:47:58 +02:00
|
|
|
class Fermi2D final : public EngineInterface {
|
2018-02-12 05:44:12 +01:00
|
|
|
public:
|
2020-06-11 05:58:57 +02:00
|
|
|
explicit Fermi2D();
|
|
|
|
~Fermi2D();
|
|
|
|
|
|
|
|
/// Binds a rasterizer to this engine.
|
|
|
|
void BindRasterizer(VideoCore::RasterizerInterface& rasterizer);
|
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.
|
2020-04-28 03:47:58 +02:00
|
|
|
void CallMethod(u32 method, u32 method_argument, bool is_last_call) override;
|
2018-04-24 03:12:40 +02:00
|
|
|
|
2020-04-20 08:16:56 +02:00
|
|
|
/// Write multiple values to the register identified by method.
|
2020-04-28 19:53:47 +02:00
|
|
|
void CallMultiMethod(u32 method, const u32* base_start, u32 amount,
|
|
|
|
u32 methods_pending) override;
|
2020-04-20 08:16:56 +02:00
|
|
|
|
2019-05-18 10:57:49 +02:00
|
|
|
enum class Origin : u32 {
|
|
|
|
Center = 0,
|
|
|
|
Corner = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Filter : u32 {
|
|
|
|
PointSample = 0, // Nearest
|
|
|
|
Linear = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Operation : u32 {
|
|
|
|
SrcCopyAnd = 0,
|
|
|
|
ROPAnd = 1,
|
|
|
|
Blend = 2,
|
|
|
|
SrcCopy = 3,
|
|
|
|
ROP = 4,
|
|
|
|
SrcCopyPremult = 5,
|
|
|
|
BlendPremult = 6,
|
|
|
|
};
|
|
|
|
|
2018-04-24 03:12:40 +02:00
|
|
|
struct Regs {
|
2018-09-15 15:21:06 +02:00
|
|
|
static constexpr std::size_t NUM_REGS = 0x258;
|
2018-04-24 03:12:40 +02:00
|
|
|
|
2018-04-24 05:14:08 +02:00
|
|
|
struct Surface {
|
|
|
|
RenderTargetFormat format;
|
|
|
|
BitField<0, 1, u32> linear;
|
|
|
|
union {
|
2018-10-08 20:34:55 +02:00
|
|
|
BitField<0, 4, u32> block_width;
|
2018-04-24 05:14:08 +02:00
|
|
|
BitField<4, 4, u32> block_height;
|
2018-10-08 20:34:55 +02:00
|
|
|
BitField<8, 4, u32> block_depth;
|
2018-04-24 05:14:08 +02:00
|
|
|
};
|
|
|
|
u32 depth;
|
|
|
|
u32 layer;
|
|
|
|
u32 pitch;
|
|
|
|
u32 width;
|
|
|
|
u32 height;
|
|
|
|
u32 address_high;
|
|
|
|
u32 address_low;
|
|
|
|
|
|
|
|
GPUVAddr Address() const {
|
|
|
|
return static_cast<GPUVAddr>((static_cast<GPUVAddr>(address_high) << 32) |
|
|
|
|
address_low);
|
|
|
|
}
|
2018-04-29 02:40:03 +02:00
|
|
|
|
2018-10-08 20:34:55 +02:00
|
|
|
u32 BlockWidth() const {
|
2019-06-13 22:41:16 +02:00
|
|
|
return block_width.Value();
|
2018-10-08 20:34:55 +02:00
|
|
|
}
|
|
|
|
|
2018-04-29 02:40:03 +02:00
|
|
|
u32 BlockHeight() const {
|
2019-06-13 22:41:16 +02:00
|
|
|
return block_height.Value();
|
2018-04-29 02:40:03 +02:00
|
|
|
}
|
2018-10-08 20:34:55 +02:00
|
|
|
|
|
|
|
u32 BlockDepth() const {
|
2019-06-13 22:41:16 +02:00
|
|
|
return block_depth.Value();
|
2018-10-08 20:34:55 +02:00
|
|
|
}
|
2018-04-24 05:14:08 +02:00
|
|
|
};
|
|
|
|
static_assert(sizeof(Surface) == 0x28, "Surface has incorrect size");
|
|
|
|
|
2018-04-24 03:12:40 +02:00
|
|
|
union {
|
|
|
|
struct {
|
2019-11-04 00:54:03 +01:00
|
|
|
INSERT_UNION_PADDING_WORDS(0x80);
|
2018-04-24 05:14:08 +02:00
|
|
|
|
|
|
|
Surface dst;
|
|
|
|
|
2019-11-04 00:54:03 +01:00
|
|
|
INSERT_UNION_PADDING_WORDS(2);
|
2018-04-24 05:14:08 +02:00
|
|
|
|
|
|
|
Surface src;
|
|
|
|
|
2019-11-04 00:54:03 +01:00
|
|
|
INSERT_UNION_PADDING_WORDS(0x15);
|
2018-04-24 05:14:08 +02:00
|
|
|
|
|
|
|
Operation operation;
|
|
|
|
|
2019-11-04 00:54:03 +01:00
|
|
|
INSERT_UNION_PADDING_WORDS(0x177);
|
2018-04-24 05:14:08 +02:00
|
|
|
|
2019-05-18 10:57:49 +02:00
|
|
|
union {
|
|
|
|
u32 raw;
|
|
|
|
BitField<0, 1, Origin> origin;
|
|
|
|
BitField<4, 1, Filter> filter;
|
|
|
|
} blit_control;
|
2018-04-24 05:14:08 +02:00
|
|
|
|
2019-11-04 00:54:03 +01:00
|
|
|
INSERT_UNION_PADDING_WORDS(0x8);
|
2018-12-15 06:20:00 +01:00
|
|
|
|
|
|
|
u32 blit_dst_x;
|
|
|
|
u32 blit_dst_y;
|
|
|
|
u32 blit_dst_width;
|
|
|
|
u32 blit_dst_height;
|
|
|
|
u64 blit_du_dx;
|
|
|
|
u64 blit_dv_dy;
|
|
|
|
u64 blit_src_x;
|
|
|
|
u64 blit_src_y;
|
|
|
|
|
2019-11-04 00:54:03 +01:00
|
|
|
INSERT_UNION_PADDING_WORDS(0x21);
|
2018-04-24 03:12:40 +02:00
|
|
|
};
|
|
|
|
std::array<u32, NUM_REGS> reg_array;
|
|
|
|
};
|
|
|
|
} regs{};
|
|
|
|
|
2019-05-18 10:57:49 +02:00
|
|
|
struct Config {
|
2020-09-18 19:55:18 +02:00
|
|
|
Operation operation{};
|
|
|
|
Filter filter{};
|
2019-05-18 10:57:49 +02:00
|
|
|
Common::Rectangle<u32> src_rect;
|
|
|
|
Common::Rectangle<u32> dst_rect;
|
|
|
|
};
|
|
|
|
|
2018-04-25 05:00:40 +02:00
|
|
|
private:
|
2020-06-11 05:58:57 +02:00
|
|
|
VideoCore::RasterizerInterface* rasterizer;
|
2018-10-06 05:46:40 +02:00
|
|
|
|
2018-04-25 05:00:40 +02:00
|
|
|
/// Performs the copy from the source surface to the destination surface as configured in the
|
|
|
|
/// registers.
|
|
|
|
void HandleSurfaceCopy();
|
2018-02-12 05:44:12 +01:00
|
|
|
};
|
2018-02-12 03:34:20 +01:00
|
|
|
|
2018-04-24 03:12:40 +02:00
|
|
|
#define ASSERT_REG_POSITION(field_name, position) \
|
|
|
|
static_assert(offsetof(Fermi2D::Regs, field_name) == position * 4, \
|
|
|
|
"Field " #field_name " has invalid position")
|
|
|
|
|
2018-04-24 05:14:08 +02:00
|
|
|
ASSERT_REG_POSITION(dst, 0x80);
|
|
|
|
ASSERT_REG_POSITION(src, 0x8C);
|
|
|
|
ASSERT_REG_POSITION(operation, 0xAB);
|
2018-12-15 06:20:00 +01:00
|
|
|
ASSERT_REG_POSITION(blit_control, 0x223);
|
|
|
|
ASSERT_REG_POSITION(blit_dst_x, 0x22c);
|
|
|
|
ASSERT_REG_POSITION(blit_dst_y, 0x22d);
|
|
|
|
ASSERT_REG_POSITION(blit_dst_width, 0x22e);
|
|
|
|
ASSERT_REG_POSITION(blit_dst_height, 0x22f);
|
|
|
|
ASSERT_REG_POSITION(blit_du_dx, 0x230);
|
|
|
|
ASSERT_REG_POSITION(blit_dv_dy, 0x232);
|
|
|
|
ASSERT_REG_POSITION(blit_src_x, 0x234);
|
|
|
|
ASSERT_REG_POSITION(blit_src_y, 0x236);
|
|
|
|
|
2018-04-24 03:12:40 +02:00
|
|
|
#undef ASSERT_REG_POSITION
|
|
|
|
|
2018-07-21 00:14:17 +02:00
|
|
|
} // namespace Tegra::Engines
|