2021-11-21 07:20:19 -08:00
|
|
|
// Copyright (c) 2021- 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 "ppsspp_config.h"
|
|
|
|
|
|
|
|
#include <string>
|
2021-11-21 14:13:07 -08:00
|
|
|
#include <vector>
|
2021-11-21 07:20:19 -08:00
|
|
|
#include <unordered_map>
|
|
|
|
#if PPSSPP_ARCH(ARM)
|
|
|
|
#include "Common/ArmEmitter.h"
|
|
|
|
#elif PPSSPP_ARCH(ARM64)
|
|
|
|
#include "Common/Arm64Emitter.h"
|
|
|
|
#elif PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
|
|
|
|
#include "Common/x64Emitter.h"
|
|
|
|
#elif PPSSPP_ARCH(MIPS)
|
|
|
|
#include "Common/MipsEmitter.h"
|
|
|
|
#else
|
|
|
|
#include "Common/FakeEmitter.h"
|
|
|
|
#endif
|
|
|
|
#include "GPU/Math3D.h"
|
|
|
|
#include "GPU/Software/FuncId.h"
|
|
|
|
|
|
|
|
namespace Rasterizer {
|
|
|
|
|
2021-11-21 10:42:28 -08:00
|
|
|
#if PPSSPP_ARCH(AMD64) && PPSSPP_PLATFORM(WINDOWS) && (defined(_MSC_VER) || defined(__clang__))
|
|
|
|
#define SOFTPIXEL_CALL __vectorcall
|
|
|
|
#define SOFTPIXEL_VEC4I __m128i
|
|
|
|
#define SOFTPIXEL_TO_VEC4I(x) (x).ivec
|
|
|
|
#elif PPSSPP_ARCH(AMD64)
|
|
|
|
#define SOFTPIXEL_CALL
|
|
|
|
#define SOFTPIXEL_VEC4I __m128i
|
|
|
|
#define SOFTPIXEL_TO_VEC4I(x) (x).ivec
|
|
|
|
#else
|
|
|
|
#define SOFTPIXEL_CALL
|
|
|
|
#define SOFTPIXEL_VEC4I const Math3D::Vec4<int> &
|
|
|
|
#define SOFTPIXEL_TO_VEC4I(x) (x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef void (SOFTPIXEL_CALL *SingleFunc)(int x, int y, int z, int fog, SOFTPIXEL_VEC4I color_in, const PixelFuncID &pixelID);
|
2021-11-21 07:20:19 -08:00
|
|
|
SingleFunc GetSingleFunc(const PixelFuncID &id);
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
bool DescribeCodePtr(const u8 *ptr, std::string &name);
|
|
|
|
|
2021-11-21 14:13:07 -08:00
|
|
|
struct PixelRegCache {
|
|
|
|
enum Purpose {
|
2021-11-27 11:31:27 -08:00
|
|
|
FLAG_GEN = 0x0100,
|
|
|
|
FLAG_TEMP = 0x1000,
|
|
|
|
|
|
|
|
VEC_ZERO = 0x0000,
|
|
|
|
|
|
|
|
GEN_SRC_ALPHA = 0x0100,
|
|
|
|
GEN_GSTATE = 0x0101,
|
|
|
|
GEN_CONST_BASE = 0x0102,
|
|
|
|
GEN_STENCIL = 0x0103,
|
|
|
|
GEN_COLOR_OFF = 0x0104,
|
|
|
|
GEN_DEPTH_OFF = 0x0105,
|
|
|
|
|
|
|
|
GEN_ARG_X = 0x0180,
|
|
|
|
GEN_ARG_Y = 0x0181,
|
|
|
|
GEN_ARG_Z = 0x0182,
|
|
|
|
GEN_ARG_FOG = 0x0183,
|
|
|
|
VEC_ARG_COLOR = 0x0080,
|
|
|
|
VEC_ARG_MASK = 0x0081,
|
|
|
|
|
|
|
|
VEC_TEMP0 = 0x1000,
|
|
|
|
VEC_TEMP1 = 0x1001,
|
|
|
|
VEC_TEMP2 = 0x1002,
|
|
|
|
VEC_TEMP3 = 0x1003,
|
|
|
|
VEC_TEMP4 = 0x1004,
|
|
|
|
VEC_TEMP5 = 0x1005,
|
|
|
|
|
|
|
|
GEN_TEMP0 = 0x1100,
|
|
|
|
GEN_TEMP1 = 0x1101,
|
|
|
|
GEN_TEMP2 = 0x1102,
|
|
|
|
GEN_TEMP3 = 0x1103,
|
|
|
|
GEN_TEMP4 = 0x1104,
|
|
|
|
GEN_TEMP5 = 0x1105,
|
|
|
|
GEN_TEMP_HELPER = 0x1106,
|
|
|
|
|
|
|
|
VEC_INVALID = 0xFEFF,
|
|
|
|
GEN_INVALID = 0xFFFF,
|
2021-11-21 14:13:07 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
|
|
|
|
typedef Gen::X64Reg Reg;
|
2021-11-27 11:31:27 -08:00
|
|
|
static constexpr Reg REG_INVALID_VALUE = Gen::INVALID_REG;
|
2021-11-21 14:13:07 -08:00
|
|
|
#else
|
|
|
|
typedef int Reg;
|
2021-11-27 11:31:27 -08:00
|
|
|
static constexpr Reg REG_INVALID_VALUE = -1;
|
2021-11-21 14:13:07 -08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
struct RegStatus {
|
|
|
|
Reg reg;
|
|
|
|
Purpose purpose;
|
2021-11-21 17:01:38 -08:00
|
|
|
uint8_t locked = 0;
|
2021-11-27 11:31:27 -08:00
|
|
|
bool forceRetained = false;
|
2021-11-21 14:13:07 -08:00
|
|
|
};
|
|
|
|
|
2021-11-26 18:17:31 -08:00
|
|
|
void Reset(bool validate);
|
2021-11-27 11:31:27 -08:00
|
|
|
void Add(Reg r, Purpose p);
|
|
|
|
void Change(Purpose history, Purpose destiny);
|
2021-11-27 11:36:29 -08:00
|
|
|
void Release(Reg &r, Purpose p);
|
|
|
|
void Unlock(Reg &r, Purpose p);
|
2021-11-27 11:31:27 -08:00
|
|
|
bool Has(Purpose p);
|
|
|
|
Reg Find(Purpose p);
|
|
|
|
Reg Alloc(Purpose p);
|
|
|
|
void ForceRetain(Purpose p);
|
|
|
|
void ForceRelease(Purpose p);
|
2021-11-21 14:13:07 -08:00
|
|
|
|
2021-11-22 15:59:41 -08:00
|
|
|
// For getting a specific reg. WARNING: May return a locked reg, so you have to check.
|
2021-11-27 11:31:27 -08:00
|
|
|
void GrabReg(Reg r, Purpose p, bool &needsSwap, Reg swapReg, Purpose swapPurpose);
|
2021-11-22 15:59:41 -08:00
|
|
|
|
2021-11-21 14:13:07 -08:00
|
|
|
private:
|
2021-11-27 11:31:27 -08:00
|
|
|
RegStatus *FindReg(Reg r, Purpose p);
|
|
|
|
RegStatus *FindReg(Reg r, bool isGen);
|
2021-11-22 15:59:41 -08:00
|
|
|
|
2021-11-21 14:13:07 -08:00
|
|
|
std::vector<RegStatus> regs;
|
|
|
|
};
|
|
|
|
|
2021-11-25 20:22:41 -08:00
|
|
|
struct PixelBlendState {
|
|
|
|
bool usesFactors = false;
|
2021-11-26 07:59:48 -08:00
|
|
|
bool usesDstAlpha = false;
|
|
|
|
bool dstFactorIsInverse = false;
|
2021-11-25 20:22:41 -08:00
|
|
|
};
|
|
|
|
void ComputePixelBlendState(PixelBlendState &state, const PixelFuncID &id);
|
|
|
|
|
2021-11-21 08:46:15 -08:00
|
|
|
#if PPSSPP_ARCH(ARM)
|
|
|
|
class PixelJitCache : public ArmGen::ARMXCodeBlock {
|
|
|
|
#elif PPSSPP_ARCH(ARM64)
|
|
|
|
class PixelJitCache : public Arm64Gen::ARM64CodeBlock {
|
|
|
|
#elif PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
|
|
|
|
class PixelJitCache : public Gen::XCodeBlock {
|
|
|
|
#elif PPSSPP_ARCH(MIPS)
|
|
|
|
class PixelJitCache : public MIPSGen::MIPSCodeBlock {
|
|
|
|
#else
|
|
|
|
class PixelJitCache : public FakeGen::FakeXCodeBlock {
|
|
|
|
#endif
|
|
|
|
public:
|
|
|
|
PixelJitCache();
|
|
|
|
|
|
|
|
// Returns a pointer to the code to run.
|
|
|
|
SingleFunc GetSingle(const PixelFuncID &id);
|
2021-11-21 14:13:07 -08:00
|
|
|
SingleFunc GenericSingle(const PixelFuncID &id);
|
2021-11-21 08:46:15 -08:00
|
|
|
void Clear();
|
|
|
|
|
|
|
|
std::string DescribeCodePtr(const u8 *ptr);
|
|
|
|
|
|
|
|
private:
|
|
|
|
SingleFunc CompileSingle(const PixelFuncID &id);
|
|
|
|
|
|
|
|
#if PPSSPP_ARCH(ARM64)
|
|
|
|
Arm64Gen::ARM64FloatEmitter fp;
|
|
|
|
#endif
|
|
|
|
|
2021-11-21 14:13:07 -08:00
|
|
|
PixelRegCache::Reg GetGState();
|
|
|
|
PixelRegCache::Reg GetConstBase();
|
2021-11-26 06:50:31 -08:00
|
|
|
PixelRegCache::Reg GetZeroVec();
|
2021-11-21 17:02:26 -08:00
|
|
|
// Note: these may require a temporary reg.
|
|
|
|
PixelRegCache::Reg GetColorOff(const PixelFuncID &id);
|
|
|
|
PixelRegCache::Reg GetDepthOff(const PixelFuncID &id);
|
2021-11-22 05:59:08 -08:00
|
|
|
PixelRegCache::Reg GetDestStencil(const PixelFuncID &id);
|
2021-11-21 14:13:07 -08:00
|
|
|
|
2021-11-21 15:02:45 -08:00
|
|
|
bool Jit_ApplyDepthRange(const PixelFuncID &id);
|
|
|
|
bool Jit_AlphaTest(const PixelFuncID &id);
|
|
|
|
bool Jit_ApplyFog(const PixelFuncID &id);
|
2021-11-21 16:01:55 -08:00
|
|
|
bool Jit_ColorTest(const PixelFuncID &id);
|
2021-11-22 05:59:08 -08:00
|
|
|
bool Jit_StencilAndDepthTest(const PixelFuncID &id);
|
|
|
|
bool Jit_StencilTest(const PixelFuncID &id, PixelRegCache::Reg stencilReg, PixelRegCache::Reg maskedReg);
|
|
|
|
bool Jit_DepthTestForStencil(const PixelFuncID &id, PixelRegCache::Reg stencilReg);
|
|
|
|
bool Jit_ApplyStencilOp(const PixelFuncID &id, GEStencilOp op, PixelRegCache::Reg stencilReg);
|
|
|
|
bool Jit_WriteStencilOnly(const PixelFuncID &id, PixelRegCache::Reg stencilReg);
|
|
|
|
bool Jit_DepthTest(const PixelFuncID &id);
|
|
|
|
bool Jit_WriteDepth(const PixelFuncID &id);
|
2021-11-22 15:59:41 -08:00
|
|
|
bool Jit_AlphaBlend(const PixelFuncID &id);
|
2021-11-26 07:59:48 -08:00
|
|
|
bool Jit_BlendFactor(const PixelFuncID &id, PixelRegCache::Reg factorReg, PixelRegCache::Reg dstReg, GEBlendSrcFactor factor);
|
|
|
|
bool Jit_DstBlendFactor(const PixelFuncID &id, PixelRegCache::Reg srcFactorReg, PixelRegCache::Reg dstFactorReg, PixelRegCache::Reg dstReg);
|
2021-11-22 15:59:41 -08:00
|
|
|
bool Jit_Dither(const PixelFuncID &id);
|
2021-11-22 20:20:13 -08:00
|
|
|
bool Jit_WriteColor(const PixelFuncID &id);
|
2021-11-23 21:51:15 -08:00
|
|
|
bool Jit_ApplyLogicOp(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg maskReg);
|
2021-11-22 21:30:17 -08:00
|
|
|
bool Jit_ConvertTo565(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg);
|
|
|
|
bool Jit_ConvertTo5551(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg, bool keepAlpha);
|
|
|
|
bool Jit_ConvertTo4444(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg, bool keepAlpha);
|
2021-11-25 20:22:41 -08:00
|
|
|
bool Jit_ConvertFrom565(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg);
|
|
|
|
bool Jit_ConvertFrom5551(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg, bool keepAlpha);
|
|
|
|
bool Jit_ConvertFrom4444(const PixelFuncID &id, PixelRegCache::Reg colorReg, PixelRegCache::Reg temp1Reg, PixelRegCache::Reg temp2Reg, bool keepAlpha);
|
2021-11-21 15:02:45 -08:00
|
|
|
|
2021-11-21 08:46:15 -08:00
|
|
|
std::unordered_map<PixelFuncID, SingleFunc> cache_;
|
|
|
|
std::unordered_map<PixelFuncID, const u8 *> addresses_;
|
2021-11-21 14:13:07 -08:00
|
|
|
PixelRegCache regCache_;
|
2021-11-21 15:02:45 -08:00
|
|
|
|
|
|
|
#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
|
2021-11-22 05:59:08 -08:00
|
|
|
void Discard();
|
2021-11-21 15:02:45 -08:00
|
|
|
void Discard(Gen::CCFlags cc);
|
|
|
|
|
2021-11-23 21:51:15 -08:00
|
|
|
// Used for any test failure.
|
2021-11-21 15:02:45 -08:00
|
|
|
std::vector<Gen::FixupBranch> discards_;
|
2021-11-23 21:51:15 -08:00
|
|
|
// Used in Jit_ApplyLogicOp() to skip the standard MOV/OR write.
|
|
|
|
std::vector<Gen::FixupBranch> skipStandardWrites_;
|
2021-11-26 18:20:41 -08:00
|
|
|
int stackIDOffset_ = 0;
|
2021-11-26 08:13:35 -08:00
|
|
|
bool colorIs16Bit_ = false;
|
2021-11-21 15:02:45 -08:00
|
|
|
#endif
|
2021-11-21 08:46:15 -08:00
|
|
|
};
|
|
|
|
|
2021-11-21 07:20:19 -08:00
|
|
|
};
|