2019-09-12 02:53:04 +00:00
|
|
|
#pragma once
|
|
|
|
#include "gpu.h"
|
2019-09-13 16:07:31 +00:00
|
|
|
#include <sstream>
|
2019-09-14 06:27:24 +00:00
|
|
|
#include <string>
|
2019-10-03 06:46:13 +00:00
|
|
|
#include <tuple>
|
2019-09-12 02:53:04 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class GPU_HW : public GPU
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GPU_HW();
|
|
|
|
virtual ~GPU_HW();
|
|
|
|
|
2019-10-04 10:33:37 +00:00
|
|
|
virtual void Reset() override;
|
|
|
|
|
2019-09-12 02:53:04 +00:00
|
|
|
protected:
|
|
|
|
struct HWVertex
|
|
|
|
{
|
|
|
|
s32 x;
|
|
|
|
s32 y;
|
|
|
|
u32 color;
|
2019-09-27 11:20:35 +00:00
|
|
|
u32 texpage;
|
2019-09-13 16:07:31 +00:00
|
|
|
u16 texcoord;
|
|
|
|
u16 padding;
|
2019-09-14 06:27:24 +00:00
|
|
|
|
2019-09-14 06:43:39 +00:00
|
|
|
static constexpr std::tuple<u8, u8> DecodeTexcoord(u16 texcoord)
|
2019-09-14 06:27:24 +00:00
|
|
|
{
|
|
|
|
return std::make_tuple(static_cast<u8>(texcoord), static_cast<u8>(texcoord >> 8));
|
|
|
|
}
|
2019-09-14 06:43:39 +00:00
|
|
|
static constexpr u16 EncodeTexcoord(u8 x, u8 y) { return ZeroExtend16(x) | (ZeroExtend16(y) << 8); }
|
2019-09-12 02:53:04 +00:00
|
|
|
};
|
|
|
|
|
2019-09-25 14:15:21 +00:00
|
|
|
struct HWRenderBatch
|
|
|
|
{
|
|
|
|
enum class Primitive : u8
|
|
|
|
{
|
|
|
|
Lines = 0,
|
2019-09-27 12:45:57 +00:00
|
|
|
LineStrip = 1,
|
|
|
|
Triangles = 2,
|
|
|
|
TriangleStrip = 3
|
2019-09-25 14:15:21 +00:00
|
|
|
};
|
|
|
|
|
2019-09-27 06:17:09 +00:00
|
|
|
u32 render_command_bits;
|
2019-09-25 14:15:21 +00:00
|
|
|
Primitive primitive;
|
|
|
|
bool transparency_enable;
|
|
|
|
bool texture_enable;
|
|
|
|
bool texture_blending_enable;
|
2019-09-26 13:33:20 +00:00
|
|
|
TextureColorMode texture_color_mode;
|
|
|
|
u32 texture_page_x;
|
|
|
|
u32 texture_page_y;
|
|
|
|
u32 texture_palette_x;
|
|
|
|
u32 texture_palette_y;
|
2019-09-25 14:15:21 +00:00
|
|
|
TransparencyMode transparency_mode;
|
|
|
|
|
|
|
|
std::vector<HWVertex> vertices;
|
|
|
|
};
|
|
|
|
|
2019-09-14 15:18:58 +00:00
|
|
|
static constexpr u32 VERTEX_BUFFER_SIZE = 1 * 1024 * 1024;
|
|
|
|
static constexpr u32 MAX_BATCH_VERTEX_COUNT = VERTEX_BUFFER_SIZE / sizeof(HWVertex);
|
2019-09-26 13:33:20 +00:00
|
|
|
static constexpr u32 TEXTURE_TILE_SIZE = 256;
|
|
|
|
static constexpr u32 TEXTURE_TILE_X_COUNT = VRAM_WIDTH / TEXTURE_TILE_SIZE;
|
|
|
|
static constexpr u32 TEXTURE_TILE_Y_COUNT = VRAM_HEIGHT / TEXTURE_TILE_SIZE;
|
|
|
|
static constexpr u32 TEXTURE_TILE_COUNT = TEXTURE_TILE_X_COUNT * TEXTURE_TILE_Y_COUNT;
|
2019-09-14 15:18:58 +00:00
|
|
|
|
2019-09-14 06:43:39 +00:00
|
|
|
static constexpr std::tuple<float, float, float, float> RGBA8ToFloat(u32 rgba)
|
|
|
|
{
|
|
|
|
return std::make_tuple(static_cast<float>(rgba & UINT32_C(0xFF)) * (1.0f / 255.0f),
|
|
|
|
static_cast<float>((rgba >> 16) & UINT32_C(0xFF)) * (1.0f / 255.0f),
|
|
|
|
static_cast<float>((rgba >> 8) & UINT32_C(0xFF)) * (1.0f / 255.0f),
|
|
|
|
static_cast<float>(rgba >> 24) * (1.0f / 255.0f));
|
|
|
|
}
|
|
|
|
|
2019-09-26 13:33:20 +00:00
|
|
|
virtual void InvalidateVRAMReadCache();
|
2019-09-13 16:07:31 +00:00
|
|
|
|
2019-09-25 14:15:21 +00:00
|
|
|
bool IsFlushed() const { return m_batch.vertices.empty(); }
|
2019-09-13 16:07:31 +00:00
|
|
|
|
|
|
|
void DispatchRenderCommand(RenderCommand rc, u32 num_vertices) override;
|
2019-09-12 02:53:04 +00:00
|
|
|
|
2019-09-12 14:18:13 +00:00
|
|
|
void CalcScissorRect(int* left, int* top, int* right, int* bottom);
|
|
|
|
|
2019-10-03 06:46:13 +00:00
|
|
|
std::tuple<s32, s32> ScaleVRAMCoordinates(s32 x, s32 y) const
|
|
|
|
{
|
|
|
|
return std::make_tuple(x * s32(m_resolution_scale), y * s32(m_resolution_scale));
|
|
|
|
}
|
|
|
|
|
2019-09-12 02:53:04 +00:00
|
|
|
std::string GenerateVertexShader(bool textured);
|
2019-10-03 06:46:13 +00:00
|
|
|
std::string GenerateFragmentShader(bool textured, bool blending, bool transparent,
|
|
|
|
TextureColorMode texture_color_mode);
|
2019-09-13 16:07:31 +00:00
|
|
|
std::string GenerateScreenQuadVertexShader();
|
2019-09-14 06:43:39 +00:00
|
|
|
std::string GenerateFillFragmentShader();
|
2019-09-12 02:53:04 +00:00
|
|
|
|
2019-10-03 06:46:13 +00:00
|
|
|
u32 m_resolution_scale = 1;
|
2019-09-25 14:15:21 +00:00
|
|
|
HWRenderBatch m_batch = {};
|
2019-09-13 16:07:31 +00:00
|
|
|
|
|
|
|
private:
|
2019-09-25 14:15:21 +00:00
|
|
|
static HWRenderBatch::Primitive GetPrimitiveForCommand(RenderCommand rc);
|
|
|
|
|
2019-09-13 16:07:31 +00:00
|
|
|
void GenerateShaderHeader(std::stringstream& ss);
|
|
|
|
|
|
|
|
void LoadVertices(RenderCommand rc, u32 num_vertices);
|
2019-09-12 02:53:04 +00:00
|
|
|
};
|