2013-06-24 20:58:35 +02:00
|
|
|
// Copyright (c) 2013- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "CommonTypes.h"
|
2017-05-20 20:19:08 -07:00
|
|
|
#include "GPU/Common/DrawEngineCommon.h"
|
2013-12-29 13:32:55 -08:00
|
|
|
#include "GPU/Common/GPUDebugInterface.h"
|
2022-01-22 22:41:41 -08:00
|
|
|
#include "GPU/Software/SoftGpu.h"
|
2013-12-30 10:49:05 +01:00
|
|
|
#include "GPU/Math3D.h"
|
2013-06-24 20:58:35 +02:00
|
|
|
|
2013-12-29 13:32:55 -08:00
|
|
|
using namespace Math3D;
|
|
|
|
|
2022-02-19 21:03:49 -08:00
|
|
|
static constexpr int32_t SCREEN_SCALE_FACTOR = 16;
|
|
|
|
|
2013-06-24 20:58:35 +02:00
|
|
|
typedef u16 u10; // TODO: erm... :/
|
|
|
|
|
|
|
|
typedef Vec3<float> ModelCoords;
|
|
|
|
typedef Vec3<float> WorldCoords;
|
|
|
|
typedef Vec3<float> ViewCoords;
|
|
|
|
typedef Vec4<float> ClipCoords; // Range: -w <= x/y/z <= w
|
|
|
|
|
2022-01-15 22:19:44 -08:00
|
|
|
class BinManager;
|
2022-01-16 15:01:07 -08:00
|
|
|
struct TransformState;
|
2022-01-16 11:24:27 -08:00
|
|
|
|
2022-09-11 21:14:47 -07:00
|
|
|
enum class CullType {
|
|
|
|
CW = 0,
|
|
|
|
CCW = 1,
|
|
|
|
OFF = 2,
|
|
|
|
};
|
|
|
|
|
2013-06-24 20:58:35 +02:00
|
|
|
struct ScreenCoords
|
|
|
|
{
|
2013-07-18 22:06:55 +02:00
|
|
|
ScreenCoords() {}
|
2017-04-15 19:52:17 -07:00
|
|
|
ScreenCoords(int x, int y, u16 z) : x(x), y(y), z(z) {}
|
2013-07-18 22:06:55 +02:00
|
|
|
|
2017-04-15 19:52:17 -07:00
|
|
|
int x;
|
|
|
|
int y;
|
2013-06-24 20:58:35 +02:00
|
|
|
u16 z;
|
2013-07-18 22:06:55 +02:00
|
|
|
|
2017-04-15 19:52:17 -07:00
|
|
|
Vec2<int> xy() const { return Vec2<int>(x, y); }
|
2013-07-29 00:30:47 +02:00
|
|
|
|
2013-07-18 22:06:55 +02:00
|
|
|
ScreenCoords operator * (const float t) const
|
|
|
|
{
|
2017-04-15 19:52:17 -07:00
|
|
|
return ScreenCoords((int)(x * t), (int)(y * t), (u16)(z * t));
|
2013-07-18 22:06:55 +02:00
|
|
|
}
|
|
|
|
|
2013-07-29 00:30:47 +02:00
|
|
|
ScreenCoords operator / (const int t) const
|
|
|
|
{
|
|
|
|
return ScreenCoords(x / t, y / t, z / t);
|
|
|
|
}
|
|
|
|
|
2013-07-18 22:06:55 +02:00
|
|
|
ScreenCoords operator + (const ScreenCoords& oth) const
|
|
|
|
{
|
|
|
|
return ScreenCoords(x + oth.x, y + oth.y, z + oth.z);
|
|
|
|
}
|
2013-06-24 20:58:35 +02:00
|
|
|
};
|
|
|
|
|
2022-01-15 15:38:56 -08:00
|
|
|
struct DrawingCoords {
|
2013-06-29 17:10:15 +02:00
|
|
|
DrawingCoords() {}
|
2022-01-15 15:38:56 -08:00
|
|
|
DrawingCoords(s16 x, s16 y) : x(x), y(y) {}
|
2013-06-29 17:10:15 +02:00
|
|
|
|
2017-05-13 17:28:38 -07:00
|
|
|
s16 x;
|
|
|
|
s16 y;
|
2013-06-29 17:10:15 +02:00
|
|
|
};
|
2013-06-24 20:58:35 +02:00
|
|
|
|
2022-09-26 16:50:40 -07:00
|
|
|
struct alignas(16) VertexData {
|
2022-09-26 17:13:14 -07:00
|
|
|
Vec3Packedf texturecoords;
|
|
|
|
float clipw;
|
2022-09-26 16:50:40 -07:00
|
|
|
uint32_t color0;
|
|
|
|
uint32_t color1;
|
|
|
|
ScreenCoords screenpos;
|
|
|
|
float fogdepth;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ClipVertexData {
|
|
|
|
void Lerp(float t, const ClipVertexData &a, const ClipVertexData &b) {
|
2013-07-18 22:06:55 +02:00
|
|
|
clippos = ::Lerp(a.clippos, b.clippos, t);
|
2022-01-14 20:36:09 -08:00
|
|
|
// Ignore screenpos because Lerp() is only used pre-calculation of screenpos.
|
2022-09-26 16:50:40 -07:00
|
|
|
v.texturecoords = ::Lerp(a.v.texturecoords, b.v.texturecoords, t);
|
|
|
|
v.fogdepth = ::Lerp(a.v.fogdepth, b.v.fogdepth, t);
|
2013-06-29 00:19:01 +02:00
|
|
|
|
2022-09-11 18:41:06 -07:00
|
|
|
u16 t_int = (u16)(t * 256);
|
2022-09-26 16:50:40 -07:00
|
|
|
v.color0 = LerpInt<Vec4<int>, 256>(Vec4<int>::FromRGBA(a.v.color0), Vec4<int>::FromRGBA(b.v.color0), t_int).ToRGBA();
|
|
|
|
v.color1 = LerpInt<Vec3<int>, 256>(Vec3<int>::FromRGB(a.v.color1), Vec3<int>::FromRGB(b.v.color1), t_int).ToRGB();
|
2013-06-25 23:17:59 +02:00
|
|
|
}
|
|
|
|
|
2022-09-17 17:19:34 -07:00
|
|
|
bool OutsideRange() const {
|
2022-09-26 16:50:40 -07:00
|
|
|
return v.screenpos.x == 0x7FFFFFFF;
|
2022-09-17 17:19:34 -07:00
|
|
|
}
|
|
|
|
|
2013-06-25 19:36:16 +02:00
|
|
|
ClipCoords clippos;
|
2022-09-26 16:50:40 -07:00
|
|
|
VertexData v;
|
2013-06-25 19:36:16 +02:00
|
|
|
};
|
|
|
|
|
2015-06-11 12:29:14 +02:00
|
|
|
class VertexReader;
|
|
|
|
|
2017-05-24 10:20:10 +02:00
|
|
|
class SoftwareDrawEngine;
|
2022-09-22 18:27:59 -07:00
|
|
|
class SoftwareVertexReader;
|
2017-05-24 10:20:10 +02:00
|
|
|
|
|
|
|
class TransformUnit {
|
2013-06-25 11:53:45 +02:00
|
|
|
public:
|
2017-05-24 10:20:10 +02:00
|
|
|
TransformUnit();
|
|
|
|
~TransformUnit();
|
2015-06-11 12:29:14 +02:00
|
|
|
|
2013-12-09 12:43:49 +01:00
|
|
|
static WorldCoords ModelToWorldNormal(const ModelCoords& coords);
|
2013-06-25 11:53:45 +02:00
|
|
|
static WorldCoords ModelToWorld(const ModelCoords& coords);
|
|
|
|
static ViewCoords WorldToView(const WorldCoords& coords);
|
|
|
|
static ClipCoords ViewToClip(const ViewCoords& coords);
|
|
|
|
static ScreenCoords ClipToScreen(const ClipCoords& coords);
|
2022-02-19 20:38:44 -08:00
|
|
|
static inline DrawingCoords ScreenToDrawing(int x, int y) {
|
2022-01-15 18:20:25 -08:00
|
|
|
DrawingCoords ret;
|
2022-02-19 20:38:44 -08:00
|
|
|
// When offset > coord, this is negative and force-scissors.
|
2022-02-19 21:03:49 -08:00
|
|
|
ret.x = x / SCREEN_SCALE_FACTOR;
|
|
|
|
ret.y = y / SCREEN_SCALE_FACTOR;
|
2022-01-15 18:20:25 -08:00
|
|
|
return ret;
|
|
|
|
}
|
2022-02-19 20:38:44 -08:00
|
|
|
static inline DrawingCoords ScreenToDrawing(const ScreenCoords &coords) {
|
|
|
|
return ScreenToDrawing(coords.x, coords.y);
|
2022-01-15 18:20:25 -08:00
|
|
|
}
|
2022-01-15 15:38:56 -08:00
|
|
|
static ScreenCoords DrawingToScreen(const DrawingCoords &coords, u16 z);
|
2013-06-25 15:58:59 +02:00
|
|
|
|
2022-07-20 12:40:22 +02:00
|
|
|
void SubmitPrimitive(const void* vertices, const void* indices, GEPrimitiveType prim_type, int vertex_count, u32 vertex_type, int *bytesRead, SoftwareDrawEngine *drawEngine);
|
2022-09-26 16:50:40 -07:00
|
|
|
void SubmitImmVertex(const ClipVertexData &vert, SoftwareDrawEngine *drawEngine);
|
2013-12-29 13:32:55 -08:00
|
|
|
|
2017-05-24 10:20:10 +02:00
|
|
|
bool GetCurrentSimpleVertices(int count, std::vector<GPUDebugVertex> &vertices, std::vector<u16> &indices);
|
2022-01-15 22:19:44 -08:00
|
|
|
|
2022-01-15 23:32:21 -08:00
|
|
|
void Flush(const char *reason);
|
2022-08-20 23:22:21 -07:00
|
|
|
void FlushIfOverlap(const char *reason, bool modifying, uint32_t addr, uint32_t stride, uint32_t w, uint32_t h);
|
2022-01-15 23:24:58 -08:00
|
|
|
void NotifyClutUpdate(const void *src);
|
2022-01-15 22:19:44 -08:00
|
|
|
|
2022-01-16 09:07:33 -08:00
|
|
|
void GetStats(char *buffer, size_t bufsize);
|
|
|
|
|
2022-01-22 22:41:41 -08:00
|
|
|
void SetDirty(SoftDirty flags);
|
|
|
|
SoftDirty GetDirty();
|
|
|
|
|
2022-01-15 22:19:44 -08:00
|
|
|
private:
|
2022-09-26 16:50:40 -07:00
|
|
|
ClipVertexData ReadVertex(VertexReader &vreader, const TransformState &state);
|
|
|
|
void SendTriangle(CullType cullType, const ClipVertexData *verts, int provoking = 2);
|
2014-06-15 09:00:13 -07:00
|
|
|
|
2022-01-15 22:19:44 -08:00
|
|
|
u8 *decoded_ = nullptr;
|
|
|
|
BinManager *binner_ = nullptr;
|
2022-09-11 08:54:34 -07:00
|
|
|
|
|
|
|
// Normally max verts per prim is 3, but we temporarily need 4 to detect rectangles from strips.
|
2022-09-26 16:50:40 -07:00
|
|
|
ClipVertexData data_[4];
|
2022-09-11 08:54:34 -07:00
|
|
|
// This is the index of the next vert in data (or higher, may need modulus.)
|
|
|
|
int data_index_ = 0;
|
|
|
|
GEPrimitiveType prev_prim_ = GE_PRIM_POINTS;
|
2022-09-17 16:28:15 -07:00
|
|
|
bool hasDraws_ = false;
|
2022-09-17 18:42:59 -07:00
|
|
|
bool isImmDraw_ = false;
|
2022-09-22 18:27:59 -07:00
|
|
|
|
|
|
|
friend SoftwareVertexReader;
|
2013-06-24 20:58:35 +02:00
|
|
|
};
|
2017-05-24 10:20:10 +02:00
|
|
|
|
|
|
|
class SoftwareDrawEngine : public DrawEngineCommon {
|
|
|
|
public:
|
|
|
|
SoftwareDrawEngine();
|
|
|
|
~SoftwareDrawEngine();
|
|
|
|
|
|
|
|
void DispatchFlush() override;
|
2022-07-20 12:40:22 +02:00
|
|
|
void DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int cullMode, int *bytesRead) override;
|
2022-09-17 20:15:40 -07:00
|
|
|
void DispatchSubmitImm(GEPrimitiveType prim, TransformedVertex *buffer, int vertexCount, int cullMode, bool continuation) override;
|
2017-05-24 10:20:10 +02:00
|
|
|
|
|
|
|
VertexDecoder *FindVertexDecoder(u32 vtype);
|
|
|
|
|
|
|
|
TransformUnit transformUnit;
|
2020-04-04 11:52:32 -07:00
|
|
|
|
2022-09-12 22:15:02 -07:00
|
|
|
#if PPSSPP_ARCH(32BIT)
|
2022-10-01 16:13:25 -07:00
|
|
|
#undef new
|
2022-09-12 22:15:02 -07:00
|
|
|
void *operator new(size_t s) {
|
|
|
|
return AllocateAlignedMemory(s, 16);
|
|
|
|
}
|
|
|
|
void operator delete(void *p) {
|
|
|
|
FreeAlignedMemory(p);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-04-04 11:52:32 -07:00
|
|
|
protected:
|
|
|
|
bool UpdateUseHWTessellation(bool enable) override { return false; }
|
2018-12-16 13:00:36 -08:00
|
|
|
};
|