2017-05-09 19:48:05 -07:00
|
|
|
// Copyright (c) 2017- 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
|
|
|
|
|
2017-05-10 17:31:34 -07:00
|
|
|
#include "ppsspp_config.h"
|
|
|
|
|
|
|
|
#include <unordered_map>
|
2017-05-09 19:48:05 -07:00
|
|
|
#include "GPU/Math3D.h"
|
2021-11-20 13:11:52 -08:00
|
|
|
#include "GPU/Software/FuncId.h"
|
2021-11-27 17:12:48 -08:00
|
|
|
#include "GPU/Software/RasterizerRegCache.h"
|
2017-05-10 17:31:34 -07:00
|
|
|
|
2017-05-09 19:48:05 -07:00
|
|
|
namespace Sampler {
|
|
|
|
|
2021-12-11 10:03:50 -08: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-12-04 13:57:58 -08:00
|
|
|
typedef Rasterizer::Vec4IntResult (SOFTRAST_CALL *NearestFunc)(int u, int v, const u8 *tptr, int bufw, int level);
|
2017-05-10 17:31:34 -07:00
|
|
|
NearestFunc GetNearestFunc();
|
|
|
|
|
2021-12-28 12:04:16 -08:00
|
|
|
typedef Rasterizer::Vec4IntResult (SOFTRAST_CALL *LinearFunc)(float s, float t, int x, int y, Rasterizer::Vec4IntArg prim_color, const u8 **tptr, const int *bufw, int level, int levelFrac);
|
2017-05-21 16:16:03 -07:00
|
|
|
LinearFunc GetLinearFunc();
|
|
|
|
|
|
|
|
struct Funcs {
|
|
|
|
NearestFunc nearest;
|
|
|
|
LinearFunc linear;
|
|
|
|
};
|
|
|
|
static inline Funcs GetFuncs() {
|
|
|
|
Funcs f;
|
|
|
|
f.nearest = GetNearestFunc();
|
|
|
|
f.linear = GetLinearFunc();
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2017-05-10 17:31:34 -07:00
|
|
|
void Init();
|
|
|
|
void Shutdown();
|
|
|
|
|
2017-05-10 20:36:09 -07:00
|
|
|
bool DescribeCodePtr(const u8 *ptr, std::string &name);
|
|
|
|
|
2021-11-27 17:12:48 -08:00
|
|
|
class SamplerJitCache : public Rasterizer::CodeBlock {
|
2017-05-10 17:31:34 -07:00
|
|
|
public:
|
|
|
|
SamplerJitCache();
|
|
|
|
|
2017-05-21 16:16:03 -07:00
|
|
|
void ComputeSamplerID(SamplerID *id_out, bool linear);
|
2017-05-10 17:31:34 -07:00
|
|
|
|
|
|
|
// Returns a pointer to the code to run.
|
2017-05-21 16:16:03 -07:00
|
|
|
NearestFunc GetNearest(const SamplerID &id);
|
|
|
|
LinearFunc GetLinear(const SamplerID &id);
|
2017-05-10 17:31:34 -07:00
|
|
|
void Clear();
|
|
|
|
|
2017-05-10 20:36:09 -07:00
|
|
|
std::string DescribeCodePtr(const u8 *ptr);
|
|
|
|
std::string DescribeSamplerID(const SamplerID &id);
|
|
|
|
|
2017-05-10 17:31:34 -07:00
|
|
|
private:
|
|
|
|
NearestFunc Compile(const SamplerID &id);
|
2017-05-21 16:16:03 -07:00
|
|
|
LinearFunc CompileLinear(const SamplerID &id);
|
2017-05-10 17:31:34 -07:00
|
|
|
|
2021-12-29 07:10:30 -08:00
|
|
|
void Describe(const std::string &message);
|
|
|
|
|
2021-12-28 15:37:25 -08:00
|
|
|
Rasterizer::RegCache::Reg GetZeroVec();
|
2021-12-28 17:52:17 -08:00
|
|
|
Rasterizer::RegCache::Reg GetGState();
|
2021-12-28 15:37:25 -08:00
|
|
|
|
2017-05-10 17:38:38 -07:00
|
|
|
bool Jit_ReadTextureFormat(const SamplerID &id);
|
2017-05-10 17:35:16 -07:00
|
|
|
bool Jit_GetTexData(const SamplerID &id, int bitsPerTexel);
|
2017-05-10 18:04:22 -07:00
|
|
|
bool Jit_GetTexDataSwizzled(const SamplerID &id, int bitsPerTexel);
|
2021-12-12 18:42:42 -08:00
|
|
|
bool Jit_GetTexDataSwizzled4(const SamplerID &id);
|
2017-05-10 17:35:16 -07:00
|
|
|
bool Jit_Decode5650();
|
|
|
|
bool Jit_Decode5551();
|
|
|
|
bool Jit_Decode4444();
|
2017-05-10 19:22:39 -07:00
|
|
|
bool Jit_TransformClutIndex(const SamplerID &id, int bitsPerIndex);
|
2017-05-10 17:35:16 -07:00
|
|
|
bool Jit_ReadClutColor(const SamplerID &id);
|
2021-09-12 13:57:28 -07:00
|
|
|
bool Jit_GetDXT1Color(const SamplerID &id, int blockSize, int alpha);
|
2021-09-12 14:53:55 -07:00
|
|
|
bool Jit_ApplyDXTAlpha(const SamplerID &id);
|
2017-05-10 17:35:16 -07:00
|
|
|
|
2021-12-28 09:56:51 -08:00
|
|
|
bool Jit_GetTexelCoordsQuad(const SamplerID &id);
|
2021-12-28 14:12:58 -08:00
|
|
|
bool Jit_PrepareDataOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg);
|
|
|
|
bool Jit_PrepareDataDirectOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, int bitsPerTexel);
|
|
|
|
bool Jit_PrepareDataSwizzledOffsets(const SamplerID &id, Rasterizer::RegCache::Reg uReg, Rasterizer::RegCache::Reg vReg, int bitsPerTexel);
|
2021-12-28 16:22:54 -08:00
|
|
|
bool Jit_BlendQuad(const SamplerID &id, bool level1);
|
2021-12-12 18:42:42 -08:00
|
|
|
|
2021-12-28 17:52:17 -08:00
|
|
|
bool Jit_ApplyTextureFunc(const SamplerID &id);
|
|
|
|
|
2017-05-10 17:31:34 -07:00
|
|
|
#if PPSSPP_ARCH(ARM64)
|
|
|
|
Arm64Gen::ARM64FloatEmitter fp;
|
2021-12-28 09:56:51 -08:00
|
|
|
#elif PPSSPP_ARCH(AMD64) || PPSSPP_ARCH(X86)
|
|
|
|
int stackArgPos_ = 0;
|
2021-12-28 14:12:58 -08:00
|
|
|
int stackFracUV1Offset_ = 0;
|
2017-05-10 17:31:34 -07:00
|
|
|
#endif
|
|
|
|
|
2021-12-28 09:56:51 -08:00
|
|
|
const u8 *constWidth256f_ = nullptr;
|
|
|
|
const u8 *constHeight256f_ = nullptr;
|
|
|
|
const u8 *constWidthMinus1i_ = nullptr;
|
|
|
|
const u8 *constHeightMinus1i_ = nullptr;
|
|
|
|
const u8 *constUNext_ = nullptr;
|
|
|
|
const u8 *constVNext_ = nullptr;
|
2021-12-28 17:52:17 -08:00
|
|
|
const u8 *constOnes32_ = nullptr;
|
|
|
|
const u8 *constOnes16_ = nullptr;
|
2021-12-30 15:23:48 -08:00
|
|
|
const u8 *const10All16_ = nullptr;
|
2021-12-28 15:37:25 -08:00
|
|
|
const u8 *const10Low_ = nullptr;
|
2021-12-30 15:23:48 -08:00
|
|
|
const u8 *const10All8_ = nullptr;
|
2021-12-28 09:56:51 -08:00
|
|
|
|
2017-05-10 17:31:34 -07:00
|
|
|
std::unordered_map<SamplerID, NearestFunc> cache_;
|
2017-05-21 16:16:03 -07:00
|
|
|
std::unordered_map<SamplerID, const u8 *> addresses_;
|
2021-12-29 07:10:30 -08:00
|
|
|
std::unordered_map<const u8 *, std::string> descriptions_;
|
2021-12-04 13:04:53 -08:00
|
|
|
Rasterizer::RegCache regCache_;
|
2017-05-10 17:31:34 -07:00
|
|
|
};
|
2017-05-09 19:48:05 -07:00
|
|
|
|
2021-12-11 10:03:50 -08:00
|
|
|
#if defined(__clang__) || defined(__GNUC__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
|
2017-05-09 19:48:05 -07:00
|
|
|
};
|