2021-11-21 15:20:19 +00: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 22:13:07 +00:00
|
|
|
#include <vector>
|
2021-11-21 15:20:19 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
#include "GPU/Math3D.h"
|
|
|
|
#include "GPU/Software/FuncId.h"
|
2021-11-28 00:36:14 +00:00
|
|
|
#include "GPU/Software/RasterizerRegCache.h"
|
2021-11-21 15:20:19 +00:00
|
|
|
|
|
|
|
namespace Rasterizer {
|
|
|
|
|
2021-12-11 18:03:50 +00:00
|
|
|
// Our std::unordered_map argument will ignore the alignment attribute, but that doesn't matter.
|
|
|
|
// We'll still have and want it for the actual function call, to keep the args in vector registers.
|
|
|
|
#if defined(__clang__) || defined(__GNUC__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wignored-attributes"
|
|
|
|
#endif
|
|
|
|
|
2021-11-28 01:12:48 +00:00
|
|
|
typedef void (SOFTRAST_CALL *SingleFunc)(int x, int y, int z, int fog, Vec4IntArg color_in, const PixelFuncID &pixelID);
|
2021-11-21 15:20:19 +00:00
|
|
|
SingleFunc GetSingleFunc(const PixelFuncID &id);
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
bool DescribeCodePtr(const u8 *ptr, std::string &name);
|
|
|
|
|
2021-11-26 04:22:41 +00:00
|
|
|
struct PixelBlendState {
|
|
|
|
bool usesFactors = false;
|
2021-11-26 15:59:48 +00:00
|
|
|
bool usesDstAlpha = false;
|
|
|
|
bool dstFactorIsInverse = false;
|
2022-01-02 04:40:28 +00:00
|
|
|
bool srcColorAsFactor = false;
|
|
|
|
bool dstColorAsFactor = false;
|
2021-11-26 04:22:41 +00:00
|
|
|
};
|
|
|
|
void ComputePixelBlendState(PixelBlendState &state, const PixelFuncID &id);
|
|
|
|
|
2021-11-28 01:12:48 +00:00
|
|
|
class PixelJitCache : public Rasterizer::CodeBlock {
|
2021-11-21 16:46:15 +00:00
|
|
|
public:
|
|
|
|
PixelJitCache();
|
|
|
|
|
|
|
|
// Returns a pointer to the code to run.
|
|
|
|
SingleFunc GetSingle(const PixelFuncID &id);
|
2021-11-21 22:13:07 +00:00
|
|
|
SingleFunc GenericSingle(const PixelFuncID &id);
|
2021-11-21 16:46:15 +00:00
|
|
|
void Clear();
|
|
|
|
|
|
|
|
std::string DescribeCodePtr(const u8 *ptr);
|
|
|
|
|
|
|
|
private:
|
|
|
|
SingleFunc CompileSingle(const PixelFuncID &id);
|
|
|
|
|
2022-01-03 04:04:37 +00:00
|
|
|
void Describe(const std::string &message);
|
|
|
|
|
2021-11-21 16:46:15 +00:00
|
|
|
#if PPSSPP_ARCH(ARM64)
|
|
|
|
Arm64Gen::ARM64FloatEmitter fp;
|
|
|
|
#endif
|
|
|
|
|
2022-01-15 18:32:15 +00:00
|
|
|
RegCache::Reg GetPixelID();
|
|
|
|
void UnlockPixelID(RegCache::Reg &r);
|
2021-11-28 00:36:14 +00:00
|
|
|
RegCache::Reg GetConstBase();
|
|
|
|
RegCache::Reg GetZeroVec();
|
2021-11-22 01:02:26 +00:00
|
|
|
// Note: these may require a temporary reg.
|
2021-11-28 00:36:14 +00:00
|
|
|
RegCache::Reg GetColorOff(const PixelFuncID &id);
|
|
|
|
RegCache::Reg GetDepthOff(const PixelFuncID &id);
|
|
|
|
RegCache::Reg GetDestStencil(const PixelFuncID &id);
|
2021-11-21 22:13:07 +00:00
|
|
|
|
2021-11-21 23:02:45 +00:00
|
|
|
bool Jit_ApplyDepthRange(const PixelFuncID &id);
|
|
|
|
bool Jit_AlphaTest(const PixelFuncID &id);
|
|
|
|
bool Jit_ApplyFog(const PixelFuncID &id);
|
2021-11-22 00:01:55 +00:00
|
|
|
bool Jit_ColorTest(const PixelFuncID &id);
|
2021-11-22 13:59:08 +00:00
|
|
|
bool Jit_StencilAndDepthTest(const PixelFuncID &id);
|
2021-11-28 00:36:14 +00:00
|
|
|
bool Jit_StencilTest(const PixelFuncID &id, RegCache::Reg stencilReg, RegCache::Reg maskedReg);
|
|
|
|
bool Jit_DepthTestForStencil(const PixelFuncID &id, RegCache::Reg stencilReg);
|
|
|
|
bool Jit_ApplyStencilOp(const PixelFuncID &id, GEStencilOp op, RegCache::Reg stencilReg);
|
|
|
|
bool Jit_WriteStencilOnly(const PixelFuncID &id, RegCache::Reg stencilReg);
|
2021-11-22 13:59:08 +00:00
|
|
|
bool Jit_DepthTest(const PixelFuncID &id);
|
|
|
|
bool Jit_WriteDepth(const PixelFuncID &id);
|
2021-11-22 23:59:41 +00:00
|
|
|
bool Jit_AlphaBlend(const PixelFuncID &id);
|
2022-01-02 04:40:28 +00:00
|
|
|
bool Jit_BlendFactor(const PixelFuncID &id, RegCache::Reg factorReg, RegCache::Reg dstReg, PixelBlendFactor factor);
|
2021-11-28 00:36:14 +00:00
|
|
|
bool Jit_DstBlendFactor(const PixelFuncID &id, RegCache::Reg srcFactorReg, RegCache::Reg dstFactorReg, RegCache::Reg dstReg);
|
2021-11-22 23:59:41 +00:00
|
|
|
bool Jit_Dither(const PixelFuncID &id);
|
2021-11-23 04:20:13 +00:00
|
|
|
bool Jit_WriteColor(const PixelFuncID &id);
|
2021-11-28 00:36:14 +00:00
|
|
|
bool Jit_ApplyLogicOp(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg maskReg);
|
|
|
|
bool Jit_ConvertTo565(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg);
|
|
|
|
bool Jit_ConvertTo5551(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
|
|
|
|
bool Jit_ConvertTo4444(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
|
|
|
|
bool Jit_ConvertFrom565(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg);
|
|
|
|
bool Jit_ConvertFrom5551(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
|
|
|
|
bool Jit_ConvertFrom4444(const PixelFuncID &id, RegCache::Reg colorReg, RegCache::Reg temp1Reg, RegCache::Reg temp2Reg, bool keepAlpha);
|
2021-11-21 23:02:45 +00:00
|
|
|
|
2021-11-21 16:46:15 +00:00
|
|
|
std::unordered_map<PixelFuncID, SingleFunc> cache_;
|
|
|
|
std::unordered_map<PixelFuncID, const u8 *> addresses_;
|
2022-01-03 04:04:37 +00:00
|
|
|
std::unordered_map<const u8 *, std::string> descriptions_;
|
2021-11-28 00:36:14 +00:00
|
|
|
RegCache regCache_;
|
2021-11-21 23:02:45 +00:00
|
|
|
|
|
|
|
#if PPSSPP_ARCH(X86) || PPSSPP_ARCH(AMD64)
|
2021-11-22 13:59:08 +00:00
|
|
|
void Discard();
|
2021-11-21 23:02:45 +00:00
|
|
|
void Discard(Gen::CCFlags cc);
|
|
|
|
|
2021-11-24 05:51:15 +00:00
|
|
|
// Used for any test failure.
|
2021-11-21 23:02:45 +00:00
|
|
|
std::vector<Gen::FixupBranch> discards_;
|
2021-11-24 05:51:15 +00:00
|
|
|
// Used in Jit_ApplyLogicOp() to skip the standard MOV/OR write.
|
|
|
|
std::vector<Gen::FixupBranch> skipStandardWrites_;
|
2021-11-27 02:20:41 +00:00
|
|
|
int stackIDOffset_ = 0;
|
2021-11-26 16:13:35 +00:00
|
|
|
bool colorIs16Bit_ = false;
|
2021-11-21 23:02:45 +00:00
|
|
|
#endif
|
2021-11-21 16:46:15 +00:00
|
|
|
};
|
|
|
|
|
2021-12-11 18:03:50 +00:00
|
|
|
#if defined(__clang__) || defined(__GNUC__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2021-11-21 15:20:19 +00:00
|
|
|
};
|